686 * SourceElements? 687 * 688 * See 14 689 * 690 * Parse the top level script. 691 */ 692 private FunctionNode program(final String scriptName, final boolean allowPropertyFunction) { 693 // Make a pseudo-token for the script holding its start and length. 694 final long functionToken = Token.toDesc(FUNCTION, Token.descPosition(Token.withDelimiter(token)), source.getLength()); 695 final int functionLine = line; 696 697 final IdentNode ident = new IdentNode(functionToken, Token.descPosition(functionToken), scriptName); 698 final ParserContextFunctionNode script = createParserContextFunctionNode( 699 ident, 700 functionToken, 701 FunctionNode.Kind.SCRIPT, 702 functionLine, 703 Collections.<IdentNode>emptyList()); 704 lc.push(script); 705 final ParserContextBlockNode body = newBlock(); 706 // If ES6 block scope is enabled add a per-script block for top-level LET and CONST declarations. 707 final int startLine = start; 708 final ParserContextBlockNode outer = useBlockScope() ? newBlock() : null; 709 functionDeclarations = new ArrayList<>(); 710 711 try { 712 sourceElements(allowPropertyFunction); 713 addFunctionDeclarations(script); 714 } finally { 715 if (outer != null) { 716 restoreBlock(outer); 717 appendStatement(new BlockStatement( 718 startLine, 719 new Block( 720 functionToken, 721 startLine, outer.getFlags(), 722 outer.getStatements()))); 723 } 724 } 725 functionDeclarations = null; 726 restoreBlock(body); 727 body.setFlag(Block.NEEDS_SCOPE); 728 final Block programBody = new Block(functionToken, functionLine, body.getFlags(), body.getStatements()); 729 lc.pop(script); 730 script.setLastToken(token); 731 732 expect(EOF); 733 734 return createFunctionNode(script, functionToken, ident, Collections.<IdentNode>emptyList(), FunctionNode.Kind.SCRIPT, functionLine, programBody); 735 } 736 737 /** 738 * Directive value or null if statement is not a directive. 739 * 740 * @param stmt Statement to be checked 741 * @return Directive value if the given statement is a directive 742 */ 743 private String getDirective(final Node stmt) { 744 if (stmt instanceof ExpressionStatement) { 745 final Node expr = ((ExpressionStatement)stmt).getExpression(); | 686 * SourceElements? 687 * 688 * See 14 689 * 690 * Parse the top level script. 691 */ 692 private FunctionNode program(final String scriptName, final boolean allowPropertyFunction) { 693 // Make a pseudo-token for the script holding its start and length. 694 final long functionToken = Token.toDesc(FUNCTION, Token.descPosition(Token.withDelimiter(token)), source.getLength()); 695 final int functionLine = line; 696 697 final IdentNode ident = new IdentNode(functionToken, Token.descPosition(functionToken), scriptName); 698 final ParserContextFunctionNode script = createParserContextFunctionNode( 699 ident, 700 functionToken, 701 FunctionNode.Kind.SCRIPT, 702 functionLine, 703 Collections.<IdentNode>emptyList()); 704 lc.push(script); 705 final ParserContextBlockNode body = newBlock(); 706 707 functionDeclarations = new ArrayList<>(); 708 sourceElements(allowPropertyFunction); 709 addFunctionDeclarations(script); 710 functionDeclarations = null; 711 712 restoreBlock(body); 713 body.setFlag(Block.NEEDS_SCOPE); 714 final Block programBody = new Block(functionToken, functionLine, body.getFlags(), body.getStatements()); 715 lc.pop(script); 716 script.setLastToken(token); 717 718 expect(EOF); 719 720 return createFunctionNode(script, functionToken, ident, Collections.<IdentNode>emptyList(), FunctionNode.Kind.SCRIPT, functionLine, programBody); 721 } 722 723 /** 724 * Directive value or null if statement is not a directive. 725 * 726 * @param stmt Statement to be checked 727 * @return Directive value if the given statement is a directive 728 */ 729 private String getDirective(final Node stmt) { 730 if (stmt instanceof ExpressionStatement) { 731 final Node expr = ((ExpressionStatement)stmt).getExpression(); |