transform() — react Function Reference
Architecture documentation for the transform() function in transform-test-gate-pragma.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 17ba2705_b3e4_6204_1a73_580da2420884["transform()"] 808c8c36_3564_6a12_e90b_9f172bde0e83["transform-test-gate-pragma.js"] 17ba2705_b3e4_6204_1a73_580da2420884 -->|defined in| 808c8c36_3564_6a12_e90b_9f172bde0e83 style 17ba2705_b3e4_6204_1a73_580da2420884 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
scripts/babel/transform-test-gate-pragma.js lines 7–334
function transform(babel) {
const {types: t} = babel;
// A very stupid subset of pseudo-JavaScript, used to run tests conditionally
// based on the environment.
//
// Input:
// @gate a && (b || c)
// test('some test', () => {/*...*/})
//
// Output:
// @gate a && (b || c)
// _test_gate(ctx => ctx.a && (ctx.b || ctx.c), 'some test', () => {/*...*/});
//
// expression → binary ( ( "||" | "&&" ) binary)* ;
// binary → unary ( ( "==" | "!=" | "===" | "!==" ) unary )* ;
// unary → "!" primary
// | primary ;
// primary → NAME | STRING | BOOLEAN
// | "(" expression ")" ;
function tokenize(code) {
const tokens = [];
let i = 0;
while (i < code.length) {
let char = code[i];
// Double quoted strings
if (char === '"') {
let string = '';
i++;
do {
if (i > code.length) {
throw Error('Missing a closing quote');
}
char = code[i++];
if (char === '"') {
break;
}
string += char;
} while (true);
tokens.push({type: 'string', value: string});
continue;
}
// Single quoted strings
if (char === "'") {
let string = '';
i++;
do {
if (i > code.length) {
throw Error('Missing a closing quote');
}
char = code[i++];
if (char === "'") {
break;
}
string += char;
} while (true);
tokens.push({type: 'string', value: string});
continue;
}
// Whitespace
if (/\s/.test(char)) {
if (char === '\n') {
return tokens;
}
i++;
continue;
}
const next3 = code.slice(i, i + 3);
if (next3 === '===') {
tokens.push({type: '=='});
i += 3;
continue;
}
if (next3 === '!==') {
tokens.push({type: '!='});
i += 3;
continue;
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does transform() do?
transform() is a function in the react codebase, defined in scripts/babel/transform-test-gate-pragma.js.
Where is transform() defined?
transform() is defined in scripts/babel/transform-test-gate-pragma.js at line 7.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free