MCPcopy
hub / github.com/facebook/react / parse

Function parse

scripts/babel/transform-test-gate-pragma.js:141–239  ·  view source on GitHub ↗
(code, ctxIdentifier)

Source from the content-addressed store, hash-verified

139 }
140
141 function parse(code, ctxIdentifier) {
142 const tokens = tokenize(code);
143
144 let i = 0;
145 function parseExpression() {
146 let left = parseBinary();
147 while (true) {
148 const token = tokens[i];
149 if (token !== undefined) {
150 switch (token.type) {
151 case '||':
152 case '&&': {
153 i++;
154 const right = parseBinary();
155 if (right === null) {
156 throw Error('Missing expression after ' + token.type);
157 }
158 left = t.logicalExpression(token.type, left, right);
159 continue;
160 }
161 }
162 }
163 break;
164 }
165 return left;
166 }
167
168 function parseBinary() {
169 let left = parseUnary();
170 while (true) {
171 const token = tokens[i];
172 if (token !== undefined) {
173 switch (token.type) {
174 case '==':
175 case '!=': {
176 i++;
177 const right = parseUnary();
178 if (right === null) {
179 throw Error('Missing expression after ' + token.type);
180 }
181 left = t.binaryExpression(token.type, left, right);
182 continue;
183 }
184 }
185 }
186 break;
187 }
188 return left;
189 }
190
191 function parseUnary() {
192 const token = tokens[i];
193 if (token !== undefined) {
194 if (token.type === '!') {
195 i++;
196 const argument = parseUnary();
197 return t.unaryExpression('!', argument);
198 }

Callers 11

buildGateConditionFunction · 0.70
guessEditorFunction · 0.50
parseSourceASTFunction · 0.50
compileFunction · 0.50
transformFunction · 0.50
constructorMethod · 0.50
handleVersionChangeMethod · 0.50
TestCase.jsFile · 0.50

Calls 2

tokenizeFunction · 0.85
parseExpressionFunction · 0.85

Tested by 1

compileFunction · 0.40