Browse Source

Well-known variables must be exempt of 'globally undefined'.

This stops recompilation in CLI. Moreover, we have two
platforms: jQuery and window are known in one, but
process and global are known in the second. That means some methods
would always be uncompilable (but question is in which platform).
This is not normal.

There should be a pragma for "this is known variable".
I would propose `<var knownVar>`.
Herbert Vojčík 12 năm trước cách đây
mục cha
commit
15e126964e
3 tập tin đã thay đổi với 15 bổ sung6 xóa
  1. 5 1
      js/Compiler-Semantic.deploy.js
  2. 7 3
      js/Compiler-Semantic.js
  3. 3 2
      st/Compiler-Semantic.st

+ 5 - 1
js/Compiler-Semantic.deploy.js

@@ -922,7 +922,11 @@ selector: "errorUnknownVariable:",
 fn: function (aNode){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3;
-$1=_st(self)._isVariableGloballyUndefined_(_st(aNode)._value());
+$ctx1.locals.identifier=nil;
+$ctx1.locals.identifier=_st(aNode)._value();
+$1=_st(_st(_st(["jQuery", "window", "process", "global"])._includes_($ctx1.locals.identifier))._not())._and_((function(){
+return smalltalk.withContext(function($ctx2) { 
return _st(self)._isVariableGloballyUndefined_($ctx1.locals.identifier);
+})}));
 if(smalltalk.assert($1)){
 $2=_st((smalltalk.UnknownVariableError || UnknownVariableError))._new();
 _st($2)._variableName_(_st(aNode)._value());

+ 7 - 3
js/Compiler-Semantic.js

@@ -1254,7 +1254,11 @@ category: 'error handling',
 fn: function (aNode){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3;
-$1=_st(self)._isVariableGloballyUndefined_(_st(aNode)._value());
+$ctx1.locals.identifier=nil;
+$ctx1.locals.identifier=_st(aNode)._value();
+$1=_st(_st(_st(["jQuery", "window", "process", "global"])._includes_($ctx1.locals.identifier))._not())._and_((function(){
+return smalltalk.withContext(function($ctx2) { 
return _st(self)._isVariableGloballyUndefined_($ctx1.locals.identifier);
+})}));
 if(smalltalk.assert($1)){
 $2=_st((smalltalk.UnknownVariableError || UnknownVariableError))._new();
 _st($2)._variableName_(_st(aNode)._value());
@@ -1265,8 +1269,8 @@ _st(_st(_st(self["@currentScope"])._methodScope())._unknownVariables())._add_(_s
 };
 return self}, self, "errorUnknownVariable:", [aNode], smalltalk.SemanticAnalyzer)},
 args: ["aNode"],
-source: "errorUnknownVariable: aNode\x0a\x09\x22Throw an error if the variable is undeclared in the global JS scope (i.e. window)\x22\x0a\x0a\x09(self isVariableGloballyUndefined: aNode value)\x0a\x09\x09ifTrue: [ \x0a\x09\x09\x09UnknownVariableError new\x0a\x09\x09\x09\x09variableName: aNode value;\x0a\x09\x09\x09\x09signal ]\x0a\x09\x09ifFalse: [\x0a\x09\x09\x09currentScope methodScope unknownVariables add: aNode value. ]",
-messageSends: ["ifTrue:ifFalse:", "variableName:", "value", "new", "signal", "add:", "unknownVariables", "methodScope", "isVariableGloballyUndefined:"],
+source: "errorUnknownVariable: aNode\x0a\x09\x22Throw an error if the variable is undeclared in the global JS scope (i.e. window)\x22\x0a\x0a\x09| identifier |\x0a    identifier := aNode value.\x0a\x09((#('jQuery' 'window' 'process' 'global') includes: identifier) not and: [ self isVariableGloballyUndefined: identifier ]) ifTrue: [\x0a\x09\x09\x09UnknownVariableError new\x0a\x09\x09\x09\x09variableName: aNode value;\x0a\x09\x09\x09\x09signal ]\x0a\x09\x09ifFalse: [\x0a\x09\x09\x09currentScope methodScope unknownVariables add: aNode value. ]",
+messageSends: ["value", "ifTrue:ifFalse:", "variableName:", "new", "signal", "add:", "unknownVariables", "methodScope", "and:", "isVariableGloballyUndefined:", "not", "includes:"],
 referencedClasses: ["UnknownVariableError"]
 }),
 smalltalk.SemanticAnalyzer);

+ 3 - 2
st/Compiler-Semantic.st

@@ -420,8 +420,9 @@ errorShadowingVariable: aString
 errorUnknownVariable: aNode
 	"Throw an error if the variable is undeclared in the global JS scope (i.e. window)"
 
-	(self isVariableGloballyUndefined: aNode value)
-		ifTrue: [ 
+	| identifier |
+    identifier := aNode value.
+	((#('jQuery' 'window' 'process' 'global') includes: identifier) not and: [ self isVariableGloballyUndefined: identifier ]) ifTrue: [
 			UnknownVariableError new
 				variableName: aNode value;
 				signal ]