MCPcopy Index your code
hub / github.com/nodejs/node / parseBinaryExpressionRest

Function parseBinaryExpressionRest

test/fixtures/snapshot/typescript.js:34818–34873  ·  view source on GitHub ↗
(precedence, leftOperand, pos)

Source from the content-addressed store, hash-verified

34816 return t === 101 /* SyntaxKind.InKeyword */ || t === 160 /* SyntaxKind.OfKeyword */;
34817 }
34818 function parseBinaryExpressionRest(precedence, leftOperand, pos) {
34819 while (true) {
34820 // We either have a binary operator here, or we're finished. We call
34821 // reScanGreaterToken so that we merge token sequences like > and = into >=
34822 reScanGreaterToken();
34823 var newPrecedence = ts.getBinaryOperatorPrecedence(token());
34824 // Check the precedence to see if we should "take" this operator
34825 // - For left associative operator (all operator but **), consume the operator,
34826 // recursively call the function below, and parse binaryExpression as a rightOperand
34827 // of the caller if the new precedence of the operator is greater then or equal to the current precedence.
34828 // For example:
34829 // a - b - c;
34830 // ^token; leftOperand = b. Return b to the caller as a rightOperand
34831 // a * b - c
34832 // ^token; leftOperand = b. Return b to the caller as a rightOperand
34833 // a - b * c;
34834 // ^token; leftOperand = b. Return b * c to the caller as a rightOperand
34835 // - For right associative operator (**), consume the operator, recursively call the function
34836 // and parse binaryExpression as a rightOperand of the caller if the new precedence of
34837 // the operator is strictly grater than the current precedence
34838 // For example:
34839 // a ** b ** c;
34840 // ^^token; leftOperand = b. Return b ** c to the caller as a rightOperand
34841 // a - b ** c;
34842 // ^^token; leftOperand = b. Return b ** c to the caller as a rightOperand
34843 // a ** b - c
34844 // ^token; leftOperand = b. Return b to the caller as a rightOperand
34845 var consumeCurrentOperator = token() === 42 /* SyntaxKind.AsteriskAsteriskToken */ ?
34846 newPrecedence >= precedence :
34847 newPrecedence > precedence;
34848 if (!consumeCurrentOperator) {
34849 break;
34850 }
34851 if (token() === 101 /* SyntaxKind.InKeyword */ && inDisallowInContext()) {
34852 break;
34853 }
34854 if (token() === 127 /* SyntaxKind.AsKeyword */) {
34855 // Make sure we *do* perform ASI for constructs like this:
34856 // var x = foo
34857 // as (Bar)
34858 // This should be parsed as an initialized variable, followed
34859 // by a function call to 'as' with the argument 'Bar'
34860 if (scanner.hasPrecedingLineBreak()) {
34861 break;
34862 }
34863 else {
34864 nextToken();
34865 leftOperand = makeAsExpression(leftOperand, parseType());
34866 }
34867 }
34868 else {
34869 leftOperand = makeBinaryExpression(leftOperand, parseTokenNode(), parseBinaryExpressionOrHigher(newPrecedence), pos);
34870 }
34871 }
34872 return leftOperand;
34873 }
34874 function isBinaryOperator() {
34875 if (inDisallowInContext() && token() === 101 /* SyntaxKind.InKeyword */) {

Callers 2

Calls 9

reScanGreaterTokenFunction · 0.85
inDisallowInContextFunction · 0.85
nextTokenFunction · 0.85
makeAsExpressionFunction · 0.85
parseTypeFunction · 0.85
makeBinaryExpressionFunction · 0.85
parseTokenNodeFunction · 0.85
tokenFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…