Răsfoiți Sursa

resolve possible conflict between varialbe 'Math' and standard JAvaScript class in generated code.

Vladislav Folts 11 ani în urmă
părinte
comite
cfc98769d7
3 a modificat fișierele cu 8 adăugiri și 2 ștergeri
  1. 3 1
      src/lexer.js
  2. 3 1
      test/expected/abs.js
  3. 2 0
      test/input/abs.ob

+ 3 - 1
src/lexer.js

@@ -71,7 +71,9 @@ var jsReservedWords
     = ["break", "case", "catch", "continue", "debugger", "default", "delete",
        "do", "else", "finally", "for", "function", "if", "in", "instanceof",
        "new", "return", "switch", "this", "throw", "try", "typeof", "var",
-       "void", "while", "with"];
+       "void", "while", "with",
+       "Math" // Math is used in generated code for some functions so it is reserved word from code generator standpoint
+       ];
 
 exports.ident = function(stream, context){
     if (!isLetter(stream.peekChar()))

+ 3 - 1
test/expected/abs.js

@@ -1,4 +1,6 @@
 var m = function (){
 var i = 0;
+var Math$ = 0;
 i = Math.abs(i);
-}();
+Math$ = Math.abs(Math$);
+}();

+ 2 - 0
test/input/abs.ob

@@ -1,7 +1,9 @@
 MODULE m;
 
 VAR i: INTEGER;
+	Math: REAL; (* the same name as standard JavaScript class used in generated code *)
 
 BEGIN
     i := ABS(i);
+	Math := ABS(Math);
 END m.