Hi,

Thanks for reporting this issue. I filed a bug https://bugs.openjdk.java.net/browse/JDK-8075207

Thanks,
-Sundar

On Sunday 15 March 2015 09:41 PM, Remi Forax wrote:
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



Reply via email to