This project has moved. For the latest updates, please go here.

Parser

Feb 8, 2011 at 8:35 PM
Hi!
It looks as great project.
I'm trying using for parse js and do own AST modifications.
But i can't understand why parser generate empty statement for 'function isDefined(value){ return value!==undefined;}'???
var text = new StringScriptSource("function isDefined(value){ return value!==undefined;}");

var scriptEngine = new ScriptEngine();
scriptEngine.CompatibilityMode = CompatibilityMode.Latest;
scriptEngine.ForceStrictMode = false;
scriptEngine.EnableDebugging = true;
var lexer = new Lexer(scriptEngine, text);
var compilerOptions = new CompilerOptions();
compilerOptions.ForceStrictMode = scriptEngine.ForceStrictMode;
compilerOptions.EnableDebugging = scriptEngine.EnableDebugging;
var parser = new Parser(scriptEngine, lexer, scriptEngine.CreateGlobalScope(), compilerOptions, CodeContext.Global);
 
Statement statement = parser.Parse();


Feb 8, 2011 at 8:36 PM

Oh, forget: i'm using latest version from repository,

Coordinator
Feb 8, 2011 at 9:04 PM

Yes, this is a special case.  Function declarations are not executed in-line with the rest of the code, they are executed at the top of the scope.  Since code generation is a straight-forward translation of the AST, my solution was to move the function declaration into the Scope and replace it with an empty statement.  In hind-sight, this is confusing and inconsistant, but since all the Jurassic.Compiler classes are intended to be non-public, I have little motivation to fix it.

Feb 8, 2011 at 9:56 PM

Thanks. Understood.

It is not a problem, while i no have plans generate human-readable code, so function reordering is looks as applicable.