MCPcopy
hub / github.com/jquery/esprima / parseUpdateExpression

Method parseUpdateExpression

src/parser.ts:1350–1388  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1348 // https://tc39.github.io/ecma262/#sec-update-expressions
1349
1350 parseUpdateExpression(): Node.Expression {
1351 let expr;
1352 const startToken = this.lookahead;
1353
1354 if (this.match('++') || this.match('--')) {
1355 const node = this.startNode(startToken);
1356 const token = this.nextToken();
1357 expr = this.inheritCoverGrammar(this.parseUnaryExpression);
1358 if (this.context.strict && expr.type === Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
1359 this.tolerateError(Messages.StrictLHSPrefix);
1360 }
1361 if (!this.context.isAssignmentTarget) {
1362 this.tolerateError(Messages.InvalidLHSInAssignment);
1363 }
1364 const prefix = true;
1365 expr = this.finalize(node, new Node.UpdateExpression(token.value, expr, prefix));
1366 this.context.isAssignmentTarget = false;
1367 this.context.isBindingElement = false;
1368 } else {
1369 expr = this.inheritCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
1370 if (!this.hasLineTerminator && this.lookahead.type === Token.Punctuator) {
1371 if (this.match('++') || this.match('--')) {
1372 if (this.context.strict && expr.type === Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
1373 this.tolerateError(Messages.StrictLHSPostfix);
1374 }
1375 if (!this.context.isAssignmentTarget) {
1376 this.tolerateError(Messages.InvalidLHSInAssignment);
1377 }
1378 this.context.isAssignmentTarget = false;
1379 this.context.isBindingElement = false;
1380 const operator = this.nextToken().value;
1381 const prefix = false;
1382 expr = this.finalize(this.startNode(startToken), new Node.UpdateExpression(operator, expr, prefix));
1383 }
1384 }
1385 }
1386
1387 return expr;
1388 }
1389
1390 // https://tc39.github.io/ecma262/#sec-unary-operators
1391

Callers 1

parseUnaryExpressionMethod · 0.95

Calls 7

matchMethod · 0.95
startNodeMethod · 0.95
nextTokenMethod · 0.95
inheritCoverGrammarMethod · 0.95
tolerateErrorMethod · 0.95
finalizeMethod · 0.95
isRestrictedWordMethod · 0.80

Tested by

no test coverage detected