MCPcopy Index your code
hub / github.com/ptmt/react-native-macos / transformCode

Function transformCode

packager/src/JSTransformer/worker/worker.js:65–138  ·  view source on GitHub ↗
(
  transformer: Transformer,
  filename: string,
  sourceCode: string,
  options: Options,
  callback: Callback,
)

Source from the content-addressed store, hash-verified

63) => mixed;
64
65function transformCode(
66 transformer: Transformer,
67 filename: string,
68 sourceCode: string,
69 options: Options,
70 callback: Callback,
71) {
72 invariant(
73 !options.minify || options.transform.generateSourceMaps,
74 'Minifying source code requires the `generateSourceMaps` option to be `true`',
75 );
76
77 const isJson = filename.endsWith('.json');
78 if (isJson) {
79 sourceCode = 'module.exports=' + sourceCode;
80 }
81
82 const transformFileStartLogEntry = {
83 action_name: 'Transforming file',
84 action_phase: 'start',
85 file_name: filename,
86 log_entry_label: 'Transforming file',
87 start_timestamp: process.hrtime(),
88 };
89
90 let transformed;
91 try {
92 transformed = transformer.transform(sourceCode, filename, options.transform);
93 } catch (error) {
94 callback(error);
95 return;
96 }
97
98 invariant(
99 transformed != null,
100 'Missing transform results despite having no error.',
101 );
102
103 var code, map;
104 if (options.minify) {
105 ({code, map} =
106 constantFolding(filename, inline(filename, transformed, options)));
107 invariant(code != null, 'Missing code from constant-folding transform.');
108 } else {
109 ({code, map} = transformed);
110 }
111
112 if (isJson) {
113 code = code.replace(/^\w+\.exports=/, '');
114 } else {
115 // Remove shebang
116 code = code.replace(/^#!.*/, '');
117 }
118
119 const depsResult = isJson
120 ? {dependencies: [], dependencyOffsets: []}
121 : extractDependencies(code);
122

Callers 2

worker.jsFile · 0.85
worker-test.jsFile · 0.85

Calls 6

invariantFunction · 0.85
constantFoldingFunction · 0.85
extractDependenciesFunction · 0.85
replaceMethod · 0.80
inlineFunction · 0.70
callbackFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…