From 5256a99c54cd083b44414679f2204569059c5745 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 20 Oct 2014 19:04:20 +0400 Subject: [PATCH] JS parser: added insideFunction flag --- js/js.parser/src/com/google/gwt/dev/js/JsParser.java | 8 ++++---- .../src/com/google/gwt/dev/js/rhino/Parser.java | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/js/js.parser/src/com/google/gwt/dev/js/JsParser.java b/js/js.parser/src/com/google/gwt/dev/js/JsParser.java index b2ea66471d9..4aa75ab0bee 100644 --- a/js/js.parser/src/com/google/gwt/dev/js/JsParser.java +++ b/js/js.parser/src/com/google/gwt/dev/js/JsParser.java @@ -33,9 +33,9 @@ public class JsParser { public static List parse( SourceInfo rootSourceInfo, - JsScope scope, Reader r + JsScope scope, Reader r, boolean insideFunction ) throws IOException, JsParserException { - return new JsParser().parseImpl(rootSourceInfo, scope, r); + return new JsParser().parseImpl(rootSourceInfo, scope, r, insideFunction); } private final Stack scopeStack = new Stack(); @@ -50,7 +50,7 @@ public class JsParser { List parseImpl( final SourceInfo rootSourceInfo, JsScope scope, - Reader r + Reader r, boolean insideFunction ) throws JsParserException, IOException { // Create a custom error handler so that we can throw our own exceptions. Context.enter().setErrorReporter(new ErrorReporter() { @@ -79,7 +79,7 @@ public class JsParser { // Parse using the Rhino parser. // TokenStream ts = new TokenStream(r, sourceNameStub, rootSourceInfo.getLine()); - Parser parser = new Parser(new IRFactory(ts)); + Parser parser = new Parser(new IRFactory(ts), insideFunction); Node topNode = (Node) parser.parse(ts); // Map the Rhino AST to ours. diff --git a/js/js.parser/src/com/google/gwt/dev/js/rhino/Parser.java b/js/js.parser/src/com/google/gwt/dev/js/rhino/Parser.java index 24238a609fc..1121d58d84c 100644 --- a/js/js.parser/src/com/google/gwt/dev/js/rhino/Parser.java +++ b/js/js.parser/src/com/google/gwt/dev/js/rhino/Parser.java @@ -52,9 +52,9 @@ import java.io.IOException; */ public class Parser { - - public Parser(IRFactory nf) { - this.nf = nf; + public Parser(IRFactory nf, boolean insideFunction) { + this.nf = nf; + this.insideFunction = insideFunction; } private void mustMatchToken(TokenStream ts, int toMatch, String messageId) @@ -729,8 +729,9 @@ public class Parser { sourceAdd((char) ts.RETURN); // bail if we're not in a (toplevel) function - if ((ts.flags & ts.TSF_FUNCTION) == 0) - reportError(ts, "msg.bad.return"); + if ((!insideFunction) && ((ts.flags & ts.TSF_FUNCTION) == 0)) { + reportError(ts, "msg.bad.return"); + } /* This is ugly, but we don't want to require a semicolon. */ ts.flags |= ts.TSF_REGEXP; @@ -1516,4 +1517,5 @@ public class Parser { private char[] sourceBuffer = new char[128]; private int sourceTop; private int functionNumber; + private final boolean insideFunction; }