src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java

Print this page

        

@@ -75,11 +75,13 @@
 import jdk.nashorn.internal.ir.BreakNode;
 import jdk.nashorn.internal.ir.CallNode;
 import jdk.nashorn.internal.ir.CaseNode;
 import jdk.nashorn.internal.ir.CatchNode;
 import jdk.nashorn.internal.ir.ContinueNode;
+import jdk.nashorn.internal.ir.DebuggerNode;
 import jdk.nashorn.internal.ir.EmptyNode;
+import jdk.nashorn.internal.ir.ErrorNode;
 import jdk.nashorn.internal.ir.Expression;
 import jdk.nashorn.internal.ir.ExpressionStatement;
 import jdk.nashorn.internal.ir.ForNode;
 import jdk.nashorn.internal.ir.FunctionNode;
 import jdk.nashorn.internal.ir.FunctionNode.CompilationState;

@@ -824,12 +826,17 @@
                                 }
                             }
                         }
                     }
                 } catch (final Exception e) {
+                    final int errorLine = line;
+                    final long errorToken = token;
                     //recover parsing
                     recover(e);
+                    final ErrorNode errorExpr = new ErrorNode(errorToken, finish);
+                    final ExpressionStatement expressionStatement = new ExpressionStatement(errorLine, errorToken, finish, errorExpr);
+                    appendStatement(expressionStatement);
                 }
 
                 // No backtracking from here on.
                 stream.commit(k);
             }

@@ -982,11 +989,11 @@
      * see 12.1
      *
      * Parse a statement block.
      */
     private void block() {
-        appendStatement(new BlockStatement(line, getBlock(true)));
+        appendStatement(new BlockStatement(line, getBlock(true), false));
     }
 
     /**
      * StatementList :
      *      Statement

@@ -1337,11 +1344,11 @@
         if (outer != null) {
             restoreBlock(outer);
             appendStatement(new BlockStatement(startLine, new Block(
                     outer.getToken(),
                     body.getFinish(),
-                    outer.getStatements())));
+                    outer.getStatements()), true));
         }
     }
 
     /**
      * ...IterationStatement :

@@ -1881,11 +1888,11 @@
             appendStatement(tryNode);
         } finally {
             restoreBlock(outer);
         }
 
-        appendStatement(new BlockStatement(startLine, new Block(tryToken, finish, outer.getFlags(), outer.getStatements())));
+        appendStatement(new BlockStatement(startLine, new Block(tryToken, finish, outer.getFlags(), outer.getStatements()), true));
     }
 
     /**
      * DebuggerStatement :
      *      debugger ;

@@ -1899,11 +1906,11 @@
         final int  debuggerLine  = line;
         final long debuggerToken = token;
         // DEBUGGER tested in caller.
         next();
         endOfLine();
-        appendStatement(new ExpressionStatement(debuggerLine, debuggerToken, finish, new RuntimeNode(debuggerToken, finish, RuntimeNode.Request.DEBUGGER, Collections.<Expression>emptyList())));
+        appendStatement(new DebuggerNode(debuggerLine, debuggerToken, finish));
     }
 
     /**
      * PrimaryExpression :
      *      this