MCPcopy Create free account
hub / github.com/davidkingzyb/SCAST / parseSubscripts

Function parseSubscripts

lib/filbert.js:2089–2167  ·  view source on GitHub ↗
(base, noCalls)

Source from the content-addressed store, hash-verified

2087 // Parse call, dot, and `[]`-subscript expressions.
2088
2089 function parseSubscripts(base, noCalls) {
2090 var node = startNodeFrom(base);
2091 if (eat(_dot)) {
2092 var id = parseIdent(true);
2093 if (pythonRuntime.imports[base.name] && pythonRuntime.imports[base.name][id.name]) {
2094 // Calling a Python import function
2095 // TODO: Unpack parameters into JavaScript-friendly parameters
2096 var runtimeId = nc.createNodeSpan(base, base, "Identifier", { name: options.runtimeParamName });
2097 var importsId = nc.createNodeSpan(base, base, "Identifier", { name: "imports" });
2098 var runtimeMember = nc.createNodeSpan(base, base, "MemberExpression", { object: runtimeId, property: importsId, computed: false });
2099 node.object = nc.createNodeSpan(base, base, "MemberExpression", { object: runtimeMember, property: base, computed: false });
2100 } else if (base.name && base.name === scope.getThisReplace()) {
2101 node.object = nc.createNodeSpan(base, base, "ThisExpression");
2102 } else node.object = base;
2103 node.property = id;
2104 node.computed = false;
2105 return parseSubscripts(finishNode(node, "MemberExpression"), noCalls);
2106 } else if (eat(_bracketL)) {
2107 var expr, isSlice = false;
2108 if (eat(_colon)) isSlice = true;
2109 else expr = parseExpression();
2110 if (!isSlice && eat(_colon)) isSlice = true;
2111 if (isSlice) return parseSlice(node, base, expr, noCalls);
2112 var subscriptCall = nc.createNodeSpan(expr, expr, "CallExpression");
2113 subscriptCall.callee = nc.createNodeOpsCallee(expr, "subscriptIndex");
2114 subscriptCall.arguments = [base, expr];
2115 node.object = base;
2116 node.property = subscriptCall;
2117 node.computed = true;
2118 expect(_bracketR);
2119 return parseSubscripts(finishNode(node, "MemberExpression"), noCalls);
2120 } else if (!noCalls && eat(_parenL)) {
2121 if (scope.isUserFunction(base.name)) {
2122 // Unpack parameters into JavaScript-friendly parameters, further processed at runtime
2123 var pl = parseParamsList();
2124
2125 var args = [];
2126 var other = [];
2127 for ( var i = 0; i < pl.length; ++i ) {
2128 if ( pl[i].isntFormal ) other.push(pl[i]);
2129 else args.push(pl[i]);
2130 }
2131
2132 if ( other.length > 0 ) {
2133 var createParamsCall = nc.createNodeRuntimeCall(node, 'utils', 'createParamsObj', other);
2134 args.push(createParamsCall);
2135 }
2136
2137 node.arguments = args;
2138 } else node.arguments = parseExprList(_parenR, false);
2139
2140
2141 if ( base.name === 'len' && node.arguments.length === 1 ) {
2142 node.type = "MemberExpression",
2143 node.object = node.arguments[0];
2144 node.property = nc.createNodeSpan(base, base, "Identifier", { name: "length"}),
2145 node.computed = false;
2146 delete node.arguments;

Callers 2

parseMaybeUnaryFunction · 0.85
parseSliceFunction · 0.85

Calls 10

startNodeFromFunction · 0.85
eatFunction · 0.85
parseIdentFunction · 0.85
finishNodeFunction · 0.85
parseExpressionFunction · 0.85
parseSliceFunction · 0.85
expectFunction · 0.85
parseParamsListFunction · 0.85
parseExprListFunction · 0.85
unexpectedFunction · 0.70

Tested by

no test coverage detected