Browse Source

Compiler class >> eval:

Convenience not to `Compiler new eval: ...`.
Herbert Vojčík 1 year ago
parent
commit
6edba6242a

+ 2 - 0
API-CHANGES.txt

@@ -8,6 +8,8 @@
 + AmberBootstrapInitialization class >>
   + run
   + initializeClasses
++ Compiler class >>
+  + eval:
 + JavaScriptException >>
   + shouldBeStubbed
   + wrap

+ 23 - 0
src/Compiler-Core.js

@@ -939,6 +939,29 @@ $globals.Compiler);
 
 $core.addMethod(
 $core.method({
+selector: "eval:",
+protocol: "evaluating",
+fn: function (aString){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($self._new())._eval_(aString);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString},$globals.Compiler.a$cls)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aString"],
+source: "eval: aString\x0a\x09^ self new eval: aString",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["eval:", "new"]
+}),
+$globals.Compiler.a$cls);
+
+$core.addMethod(
+$core.method({
 selector: "recompile:",
 protocol: "compiling",
 fn: function (aClass){

+ 6 - 0
src/Compiler-Core.st

@@ -245,6 +245,12 @@ recompileAll
 		self recompile: each ]
 ! !
 
+!Compiler class methodsFor: 'evaluating'!
+
+eval: aString
+	^ self new eval: aString
+! !
+
 Error subclass: #CompilerError
 	instanceVariableNames: ''
 	package: 'Compiler-Core'!

File diff suppressed because it is too large
+ 3 - 3
src/Compiler-Interpreter.js


+ 1 - 1
src/Compiler-Interpreter.st

@@ -723,7 +723,7 @@ eval: aString
 			nextPutAll: aString;
 			nextPutAll: '})()})' ].
 			
-	function := Compiler new eval: source.
+	function := Compiler eval: source.
 	
 	^ function valueWithPossibleArguments: self context locals values
 !

+ 5 - 6
src/Compiler-Semantic.js

@@ -1919,7 +1919,7 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$3,$receiver;
+var $1,$2,$receiver;
 if(($receiver = aPackage) == null || $receiver.a$nil){
 aPackage;
 } else {
@@ -1931,22 +1931,21 @@ if($core.assert($1)){
 return false;
 }
 }
-$2=$recv($globals.Compiler)._new();
-$3=$recv("typeof ".__comma(aString)).__comma(" == \x22undefined\x22");
+$2=$recv("typeof ".__comma(aString)).__comma(" === \x22undefined\x22");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx[","]=1;
 //>>excludeEnd("ctx");
-return $recv($2)._eval_($3);
+return $recv($globals.Compiler)._eval_($2);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"isVariableUndefined:inPackage:",{aString:aString,aPackage:aPackage},$globals.SemanticAnalyzer)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aString", "aPackage"],
-source: "isVariableUndefined: aString inPackage: aPackage\x0a\x09aPackage ifNotNil: [\x0a\x09\x09| packageKnownVars |\x0a\x09\x09packageKnownVars := (aPackage imports\x0a\x09\x09\x09reject: #isString)\x0a\x09\x09\x09collect: #key.\x0a\x09\x09(packageKnownVars includes: aString) ifTrue: [ ^ false ]].\x0a\x09^ Compiler new\x0a\x09\x09eval: 'typeof ', aString, ' == \x22undefined\x22'",
+source: "isVariableUndefined: aString inPackage: aPackage\x0a\x09aPackage ifNotNil: [\x0a\x09\x09| packageKnownVars |\x0a\x09\x09packageKnownVars := (aPackage imports\x0a\x09\x09\x09reject: #isString)\x0a\x09\x09\x09collect: #key.\x0a\x09\x09(packageKnownVars includes: aString) ifTrue: [ ^ false ]].\x0a\x09^ Compiler eval: 'typeof ', aString, ' === \x22undefined\x22'",
 referencedClasses: ["Compiler"],
 //>>excludeEnd("ide");
-messageSends: ["ifNotNil:", "collect:", "reject:", "imports", "ifTrue:", "includes:", "eval:", "new", ","]
+messageSends: ["ifNotNil:", "collect:", "reject:", "imports", "ifTrue:", "includes:", "eval:", ","]
 }),
 $globals.SemanticAnalyzer);
 

+ 1 - 2
src/Compiler-Semantic.st

@@ -540,8 +540,7 @@ isVariableUndefined: aString inPackage: aPackage
 			reject: #isString)
 			collect: #key.
 		(packageKnownVars includes: aString) ifTrue: [ ^ false ]].
-	^ Compiler new
-		eval: 'typeof ', aString, ' == "undefined"'
+	^ Compiler eval: 'typeof ', aString, ' === "undefined"'
 ! !
 
 !SemanticAnalyzer methodsFor: 'visiting'!