babel-preset-expo 11.0.8 → 11.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -25,34 +25,96 @@ function reactClientReferencesPlugin() {
|
|
|
25
25
|
// This can happen in tests or systems that use Babel standalone.
|
|
26
26
|
throw new Error('[Babel] Expected a filename to be set in the state');
|
|
27
27
|
}
|
|
28
|
-
const outputKey = url_1.default.pathToFileURL(filePath).href;
|
|
29
28
|
// File starts with "use client" directive.
|
|
30
|
-
if (!isUseClient
|
|
29
|
+
if (!isUseClient) {
|
|
31
30
|
// Do nothing for code that isn't marked as a client component.
|
|
32
31
|
return;
|
|
33
32
|
}
|
|
33
|
+
const outputKey = url_1.default.pathToFileURL(filePath).href;
|
|
34
|
+
// We need to add all of the exports to support `export * from './module'` which iterates the keys of the module.
|
|
35
|
+
const proxyModule = [
|
|
36
|
+
`const proxy = /*@__PURE__*/ require("react-server-dom-webpack/server").createClientModuleProxy(${JSON.stringify(outputKey)});`,
|
|
37
|
+
`module.exports = proxy;`,
|
|
38
|
+
];
|
|
39
|
+
const getProxy = (exportName) => {
|
|
40
|
+
return `(/*@__PURE__*/ proxy[${JSON.stringify(exportName)}])`;
|
|
41
|
+
};
|
|
42
|
+
const proxyExports = new Set();
|
|
43
|
+
const pushProxy = (exportName) => {
|
|
44
|
+
proxyExports.add(exportName);
|
|
45
|
+
if (exportName === 'default') {
|
|
46
|
+
proxyModule.push(`export default ${getProxy(exportName)};`);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
proxyModule.push(`export const ${exportName} = ${getProxy(exportName)};`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
// Collect all of the exports
|
|
53
|
+
path.traverse({
|
|
54
|
+
ExportNamedDeclaration(exportPath) {
|
|
55
|
+
if (exportPath.node.declaration) {
|
|
56
|
+
if (exportPath.node.declaration.type === 'VariableDeclaration') {
|
|
57
|
+
exportPath.node.declaration.declarations.forEach((declaration) => {
|
|
58
|
+
if (declaration.id.type === 'Identifier') {
|
|
59
|
+
const exportName = declaration.id.name;
|
|
60
|
+
pushProxy(exportName);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else if (exportPath.node.declaration.type === 'FunctionDeclaration') {
|
|
65
|
+
const exportName = exportPath.node.declaration.id?.name;
|
|
66
|
+
if (exportName) {
|
|
67
|
+
pushProxy(exportName);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (exportPath.node.declaration.type === 'ClassDeclaration') {
|
|
71
|
+
const exportName = exportPath.node.declaration.id?.name;
|
|
72
|
+
if (exportName) {
|
|
73
|
+
pushProxy(exportName);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (!['InterfaceDeclaration', 'TypeAlias'].includes(exportPath.node.declaration.type)) {
|
|
77
|
+
// TODO: What is this type?
|
|
78
|
+
console.warn('[babel-preset-expo] Unsupported export specifier for "use client":', exportPath.node.declaration.type);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
exportPath.node.specifiers.forEach((specifier) => {
|
|
83
|
+
if (core_1.types.isIdentifier(specifier.exported)) {
|
|
84
|
+
const exportName = specifier.exported.name;
|
|
85
|
+
pushProxy(exportName);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// TODO: What is this type?
|
|
89
|
+
console.warn('[babel-preset-expo] Unsupported export specifier for "use client":', specifier);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
ExportDefaultDeclaration() {
|
|
95
|
+
pushProxy('default');
|
|
96
|
+
},
|
|
97
|
+
});
|
|
34
98
|
// Clear the body
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
;(() => {
|
|
43
|
-
if (typeof module.exports === 'function') {
|
|
44
|
-
require('react-server-dom-webpack/server').registerServerReference(module.exports, ${JSON.stringify(outputKey)}, null);
|
|
45
|
-
} else {
|
|
46
|
-
for (const key in module.exports) {
|
|
47
|
-
if (typeof module.exports[key] === 'function') {
|
|
48
|
-
require('react-server-dom-webpack/server').registerServerReference(module.exports[key], ${JSON.stringify(outputKey)}, key);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
})()`);
|
|
99
|
+
path.node.body = [];
|
|
100
|
+
path.node.directives = [];
|
|
101
|
+
path.pushContainer('body', core_1.template.ast(proxyModule.join('\n')));
|
|
102
|
+
assertExpoMetadata(state.file.metadata);
|
|
103
|
+
// Save the client reference in the metadata.
|
|
104
|
+
if (!state.file.metadata.clientReferences) {
|
|
105
|
+
state.file.metadata.clientReferences ??= [];
|
|
53
106
|
}
|
|
107
|
+
state.file.metadata.clientReferences.push(outputKey);
|
|
108
|
+
// Store the proxy export names for testing purposes.
|
|
109
|
+
state.file.metadata.proxyExports = [...proxyExports];
|
|
54
110
|
},
|
|
55
111
|
},
|
|
56
112
|
};
|
|
57
113
|
}
|
|
58
114
|
exports.reactClientReferencesPlugin = reactClientReferencesPlugin;
|
|
115
|
+
function assertExpoMetadata(metadata) {
|
|
116
|
+
if (metadata && typeof metadata === 'object') {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
throw new Error('Expected Babel state.file.metadata to be an object');
|
|
120
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-preset-expo",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.10",
|
|
4
4
|
"description": "The Babel preset for Expo projects",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"files": [
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"expo-module-scripts": "^3.3.0",
|
|
57
57
|
"jest": "^29.2.1"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "6f609a05a2d4dac7fd281bcc502575440c5af7c9"
|
|
60
60
|
}
|