Browse Source

fix: Add missing line information for repeatUntil and switch..case

Lucas de Souza 2 years ago
parent
commit
74632352b4
2 changed files with 12 additions and 4 deletions
  1. 11 4
      js/ast/ivprogParser.js
  2. 1 0
      js/util/parseFromVisual.js

+ 11 - 4
js/ast/ivprogParser.js

@@ -277,7 +277,6 @@ export class IVProgParser {
     }
     this.definedFuncsNameList.push(id);
   }
-
   checkVariableDuplicate (variableID, sourceInfo) {
     const index = this.getCurrentVariableStack().indexOf(variableID);
     if (index !== -1) {
@@ -970,6 +969,7 @@ export class IVProgParser {
   }
 
   parseSwitchCase () {
+    const token = this.getToken();
     this.pushScope(IVProgParser.BREAKABLE);
     this.pos++;
     this.checkOpenParenthesis();
@@ -990,10 +990,13 @@ export class IVProgParser {
     this.consumeNewLines();
 
     this.popScope();
-    return new Commands.Switch(exp, casesList);
+    const command = new Commands.Switch(exp, casesList);
+    command.sourceInfo = SourceInfo.createSourceInfo(token);
+    return command;
   }
 
   parseRepeatUntil () {
+    const token = this.getToken();
     this.pos++;
     this.consumeNewLines();
     this.pushScope(IVProgParser.BREAKABLE);
@@ -1016,7 +1019,9 @@ export class IVProgParser {
     this.pos++;
     this.checkEOS();
     this.popScope();
-    return new Commands.RepeatUntil(condition, commandsBlock);
+    const command = new Commands.RepeatUntil(condition, commandsBlock);
+    command.sourceInfo = SourceInfo.createSourceInfo(token);
+    return command;
   }
 
   parseIfThenElse () {
@@ -1134,7 +1139,7 @@ export class IVProgParser {
       this.checkEOS();
     }
     this.pos++;
-    const returnCommand =  new Commands.Return(exp);
+    const returnCommand = new Commands.Return(exp);
     returnCommand.sourceInfo = SourceInfo.createSourceInfo(token);
     return returnCommand;
   }
@@ -1276,6 +1281,7 @@ export class IVProgParser {
       this.consumeNewLines();
       const block = this.parseCommandBlock(true);
       const defaultCase = new Commands.Case(null);
+      defaultCase.sourceInfo = SourceInfo.createSourceInfo(token);
       defaultCase.setCommands(block.commands);
       return [defaultCase];
     } else {
@@ -1288,6 +1294,7 @@ export class IVProgParser {
       this.consumeNewLines();
       const block = this.parseCommandBlock(true);
       const aCase = new Commands.Case(exp);
+      aCase.sourceInfo = SourceInfo.createSourceInfo(token);
       aCase.setCommands(block.commands);
       const caseToken = this.getToken();
       if (caseToken.type === this.ruleNames.RK_CASE) {

+ 1 - 0
js/util/parseFromVisual.js

@@ -63,6 +63,7 @@ function switchCaseWalker (switchCase) {
     : expressionWalker(switchCase.expression);
   return {
     type: "switchcase",
+    line: switchCase.sourceInfo.line,
     expression,
     commands,
   };