-
Bug
-
Resolution: Fixed
-
P3
-
9
-
b56
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8085619 | emb-9 | Sundararajan Athijegannathan | P3 | Resolved | Fixed | team |
The following is from an email by Remi to nashorn-dev list:
--------------- email starts here ----------------------------------------------
Hi guys, Hi Sundar,
it seems that the parser groups all the function declarations before all the statements
instead of following the order of the file.
[forax@localhost jsjs]$ cat bug_parser.js
var File = Java.type("java.io.File");
var Parser = Java.type("jdk.nashorn.api.tree.Parser");
var Tree = Java.type("jdk.nashorn.api.tree.Tree");
// do we have a script file passed? if not, use current script
var sourceName = arguments.length == 0? __FILE__ : arguments[0];
var parser = Parser.create("-scripting");
// parse script to get CompilationUnitTree of it
var ast = parser.parse(new File(sourceName), null);
for each(element in ast.getSourceElements()) {
print(element.getClass());
}
[forax@localhost jsjs]$ cat test/test5.js
var hello = "hello jsjs";
function print_hello() {
print(hello);
}
var hello = "hello jsjs 2";
[forax@localhost jsjs]$ jjs bug_parser.js -- test/test5.js
class jdk.nashorn.api.tree.FunctionDeclarationTreeImpl
class jdk.nashorn.api.tree.VariableTreeImpl
class jdk.nashorn.api.tree.VariableTreeImpl
the correct output should be:
class jdk.nashorn.api.tree.VariableTreeImpl
class jdk.nashorn.api.tree.FunctionDeclarationTreeImpl
class jdk.nashorn.api.tree.VariableTreeImpl
regards,
Rémi
------------------------------------ email ends here ------------------------------------------
--------------- email starts here ----------------------------------------------
Hi guys, Hi Sundar,
it seems that the parser groups all the function declarations before all the statements
instead of following the order of the file.
[forax@localhost jsjs]$ cat bug_parser.js
var File = Java.type("java.io.File");
var Parser = Java.type("jdk.nashorn.api.tree.Parser");
var Tree = Java.type("jdk.nashorn.api.tree.Tree");
// do we have a script file passed? if not, use current script
var sourceName = arguments.length == 0? __FILE__ : arguments[0];
var parser = Parser.create("-scripting");
// parse script to get CompilationUnitTree of it
var ast = parser.parse(new File(sourceName), null);
for each(element in ast.getSourceElements()) {
print(element.getClass());
}
[forax@localhost jsjs]$ cat test/test5.js
var hello = "hello jsjs";
function print_hello() {
print(hello);
}
var hello = "hello jsjs 2";
[forax@localhost jsjs]$ jjs bug_parser.js -- test/test5.js
class jdk.nashorn.api.tree.FunctionDeclarationTreeImpl
class jdk.nashorn.api.tree.VariableTreeImpl
class jdk.nashorn.api.tree.VariableTreeImpl
the correct output should be:
class jdk.nashorn.api.tree.VariableTreeImpl
class jdk.nashorn.api.tree.FunctionDeclarationTreeImpl
class jdk.nashorn.api.tree.VariableTreeImpl
regards,
Rémi
------------------------------------ email ends here ------------------------------------------
- backported by
-
JDK-8085619 Nashorn parser API returns StatementTree objects in out of order
-
- Resolved
-