|
| 1 | +diff --git a/node_modules/metro/src/ModuleGraph/worker/JsFileWrapping.js b/node_modules/metro/src/ModuleGraph/worker/JsFileWrapping.js |
| 2 | +index 48a1409..ef185c9 100644 |
| 3 | +--- a/node_modules/metro/src/ModuleGraph/worker/JsFileWrapping.js |
| 4 | ++++ b/node_modules/metro/src/ModuleGraph/worker/JsFileWrapping.js |
| 5 | +@@ -70,14 +70,19 @@ function wrapModule( |
| 6 | + importDefaultName, |
| 7 | + importAllName, |
| 8 | + dependencyMapName, |
| 9 | +- globalPrefix |
| 10 | ++ globalPrefix, |
| 11 | ++ moduleFactoryName |
| 12 | + ) { |
| 13 | + const params = buildParameters( |
| 14 | + importDefaultName, |
| 15 | + importAllName, |
| 16 | + dependencyMapName |
| 17 | + ); |
| 18 | +- const factory = functionFromProgram(fileAst.program, params); |
| 19 | ++ const factory = functionFromProgram( |
| 20 | ++ fileAst.program, |
| 21 | ++ params, |
| 22 | ++ moduleFactoryName |
| 23 | ++ ); |
| 24 | + const def = t.callExpression(t.identifier(`${globalPrefix}__d`), [factory]); |
| 25 | + const ast = t.file(t.program([t.expressionStatement(def)])); |
| 26 | + const requireName = renameRequires(ast); |
| 27 | +@@ -107,7 +112,16 @@ function wrapJson(source, globalPrefix) { |
| 28 | + "});", |
| 29 | + ].join("\n"); |
| 30 | + } |
| 31 | +-function functionFromProgram(program, parameters) { |
| 32 | ++const JS_INVALID_IDENT_RE = /[^a-zA-Z0-9$_]/g; |
| 33 | ++function functionFromProgram(program, parameters, moduleFactoryName) { |
| 34 | ++ let identifier; |
| 35 | ++ if (typeof moduleFactoryName === "string" && moduleFactoryName !== "") { |
| 36 | ++ // Keep the name readable so it shows up in profiler traces. |
| 37 | ++ // Add an unlikely suffix to avoid collisions with the module code. |
| 38 | ++ identifier = t.identifier( |
| 39 | ++ `${moduleFactoryName.replace(JS_INVALID_IDENT_RE, "_")}__module_factory__` |
| 40 | ++ ); |
| 41 | ++ } |
| 42 | + return t.functionExpression( |
| 43 | + undefined, |
| 44 | + parameters.map(makeIdentifier), |
0 commit comments