MCPcopy Create free account
hub / github.com/mozilla/rhino / returnOrYield

Method returnOrYield

rhino/src/main/java/org/mozilla/javascript/Parser.java:2263–2338  ·  view source on GitHub ↗
(int tt, boolean exprContext)

Source from the content-addressed store, hash-verified

2261 }
2262
2263 private AstNode returnOrYield(int tt, boolean exprContext) throws IOException {
2264 if (!insideFunctionBody()) {
2265 reportError(tt == Token.RETURN ? "msg.bad.return" : "msg.bad.yield");
2266 }
2267 consumeToken();
2268 int lineno = lineNumber(), column = columnNumber(), pos = ts.tokenBeg, end = ts.tokenEnd;
2269
2270 boolean yieldStar = false;
2271 if ((tt == Token.YIELD)
2272 && (compilerEnv.getLanguageVersion() >= Context.VERSION_ES6)
2273 && (peekToken() == Token.MUL)) {
2274 yieldStar = true;
2275 consumeToken();
2276 }
2277
2278 AstNode e = null;
2279 // This is ugly, but we don't want to require a semicolon.
2280 switch (peekTokenOrEOL()) {
2281 case Token.SEMI:
2282 case Token.RC:
2283 case Token.RB:
2284 case Token.RP:
2285 case Token.EOF:
2286 case Token.EOL:
2287 case Token.ERROR:
2288 break;
2289 case Token.YIELD:
2290 if (compilerEnv.getLanguageVersion() < Context.VERSION_ES6) {
2291 // Take extra care to preserve language compatibility
2292 break;
2293 }
2294 // fallthrough
2295 default:
2296 e = expr(false);
2297 end = getNodeEnd(e);
2298 }
2299
2300 int before = endFlags;
2301 AstNode ret;
2302
2303 if (tt == Token.RETURN) {
2304 endFlags |= e == null ? Node.END_RETURNS : Node.END_RETURNS_VALUE;
2305 ret = new ReturnStatement(pos, end - pos, e);
2306
2307 // see if we need a strict mode warning
2308 if (nowAllSet(before, endFlags, Node.END_RETURNS | Node.END_RETURNS_VALUE))
2309 addStrictWarning("msg.return.inconsistent", "", pos, end - pos);
2310 } else {
2311 if (!insideFunctionBody()) reportError("msg.bad.yield");
2312 endFlags |= Node.END_YIELDS;
2313 ret = new Yield(pos, end - pos, e, yieldStar);
2314 setRequiresActivation();
2315 setIsGenerator();
2316 if (!exprContext) {
2317 ret.setLineColumnNumber(lineno, column);
2318 ret = new ExpressionStatement(ret);
2319 }
2320 }

Callers 2

statementHelperMethod · 0.95
assignExprMethod · 0.95

Calls 15

insideFunctionBodyMethod · 0.95
reportErrorMethod · 0.95
consumeTokenMethod · 0.95
lineNumberMethod · 0.95
columnNumberMethod · 0.95
peekTokenMethod · 0.95
peekTokenOrEOLMethod · 0.95
exprMethod · 0.95
getNodeEndMethod · 0.95
nowAllSetMethod · 0.95
addStrictWarningMethod · 0.95
setRequiresActivationMethod · 0.95

Tested by

no test coverage detected