Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8075207

Nashorn parser API returns StatementTree objects in out of order

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 9
    • 9
    • core-libs
    • b56
    • generic
    • generic
    • Verified

    Backports

      Description

        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 ------------------------------------------

        Attachments

          Issue Links

            Activity

              People

                sundar Sundararajan Athijegannathan
                sundar Sundararajan Athijegannathan
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: