MCPcopy Index your code
hub / github.com/BloombergGraphics/whatiscode / parsePrimaryExpression

Function parsePrimaryExpression

scripts/libs/esprima.js:2624–2684  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2622 // 11.1 Primary Expressions
2623
2624 function parsePrimaryExpression() {
2625 var type, token, expr, node;
2626
2627 if (match('(')) {
2628 return parseGroupExpression();
2629 }
2630
2631 if (match('[')) {
2632 return parseArrayInitialiser();
2633 }
2634
2635 if (match('{')) {
2636 return parseObjectInitialiser();
2637 }
2638
2639 type = lookahead.type;
2640 node = new Node();
2641
2642 if (type === Token.Identifier) {
2643 expr = node.finishIdentifier(lex().value);
2644 } else if (type === Token.StringLiteral || type === Token.NumericLiteral) {
2645 if (strict && lookahead.octal) {
2646 tolerateUnexpectedToken(lookahead, Messages.StrictOctalLiteral);
2647 }
2648 expr = node.finishLiteral(lex());
2649 } else if (type === Token.Keyword) {
2650 if (matchKeyword('function')) {
2651 return parseFunctionExpression();
2652 }
2653 if (matchKeyword('this')) {
2654 lex();
2655 return node.finishThisExpression();
2656 }
2657 if (matchKeyword('class')) {
2658 return parseClassExpression();
2659 }
2660 throwUnexpectedToken(lex());
2661 } else if (type === Token.BooleanLiteral) {
2662 token = lex();
2663 token.value = (token.value === 'true');
2664 expr = node.finishLiteral(token);
2665 } else if (type === Token.NullLiteral) {
2666 token = lex();
2667 token.value = null;
2668 expr = node.finishLiteral(token);
2669 } else if (match('/') || match('/=')) {
2670 index = startIndex;
2671
2672 if (typeof extra.tokens !== 'undefined') {
2673 token = collectRegex();
2674 } else {
2675 token = scanRegExp();
2676 }
2677 lex();
2678 expr = node.finishLiteral(token);
2679 } else {
2680 throwUnexpectedToken(lex());
2681 }

Calls 12

matchFunction · 0.85
parseGroupExpressionFunction · 0.85
parseArrayInitialiserFunction · 0.85
parseObjectInitialiserFunction · 0.85
lexFunction · 0.85
tolerateUnexpectedTokenFunction · 0.85
matchKeywordFunction · 0.85
parseFunctionExpressionFunction · 0.85
parseClassExpressionFunction · 0.85
throwUnexpectedTokenFunction · 0.85
collectRegexFunction · 0.85
scanRegExpFunction · 0.85

Tested by

no test coverage detected