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

Function transform

scripts/print-warnings/print-warnings.js:21–66  ·  view source on GitHub ↗
(file, enc, cb)

Source from the content-addressed store, hash-verified

19const warnings = new Set();
20
21function transform(file, enc, cb) {
22 fs.readFile(file.path, 'utf8', function (err, source) {
23 if (err) {
24 cb(err);
25 return;
26 }
27
28 let ast;
29 try {
30 ast = parse(source);
31 } catch (error) {
32 console.error('Failed to parse source file:', file.path);
33 throw error;
34 }
35
36 traverse(ast, {
37 enter() {},
38 leave(node) {
39 if (node.type !== 'CallExpression') {
40 return;
41 }
42 const callee = node.callee;
43 if (
44 callee.type === 'MemberExpression' &&
45 callee.object.type === 'Identifier' &&
46 callee.object.name === 'console' &&
47 callee.property.type === 'Identifier' &&
48 (callee.property.name === 'warn' || callee.property.name === 'error')
49 ) {
50 // warning messages can be concatenated (`+`) at runtime, so here's
51 // a trivial partial evaluator that interprets the literal value
52 try {
53 const warningMsgLiteral = evalStringConcat(node.arguments[0]);
54 warnings.add(warningMsgLiteral);
55 } catch {
56 // Silently skip over this call. We have a lint rule to enforce
57 // that all calls are extractable, so if this one fails, assume
58 // it's intentional.
59 }
60 }
61 },
62 });
63
64 cb(null);
65 });
66}
67
68gs([
69 'packages/**/*.js',

Callers

nothing calls this directly

Calls 4

traverseFunction · 0.85
errorMethod · 0.65
cbFunction · 0.50
parseFunction · 0.50

Tested by

no test coverage detected