babel-preset-expo 13.0.0 → 13.1.0-canary-20250408-7f0ab53
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.
package/README.md
CHANGED
|
@@ -148,6 +148,12 @@ If `undefined` (default), this will be set automatically via `caller.supportsSta
|
|
|
148
148
|
|
|
149
149
|
Changes the engine preset in `@react-native/babel-preset` based on the JavaScript engine that is being targeted. In Expo SDK 50 and greater, this is automatically set based on the [`jsEngine`](https://docs.expo.dev/versions/latest/config/app/#jsengine) option in your `app.json`.
|
|
150
150
|
|
|
151
|
+
### `unstable_transformImportMeta`
|
|
152
|
+
|
|
153
|
+
Enable that transform that converts `import.meta` to `globalThis.__ExpoImportMetaRegistry`, defaults to `false`.
|
|
154
|
+
|
|
155
|
+
> **Note:** Use this option at your own risk. If the JavaScript engine supports `import.meta` natively, this transformation may interfere with the native implementation.
|
|
156
|
+
|
|
151
157
|
### `enableBabelRuntime`
|
|
152
158
|
|
|
153
159
|
Passed to `@react-native/babel-preset`.
|
|
@@ -22,7 +22,7 @@ function reactClientReferencesPlugin(api) {
|
|
|
22
22
|
// TODO: use server can be added to scopes inside of the file. https://github.com/facebook/react/blob/29fbf6f62625c4262035f931681c7b7822ca9843/packages/react-server-dom-webpack/src/ReactFlightWebpackNodeRegister.js#L55
|
|
23
23
|
const isUseServer = path.node.directives.some((directive) => directive.value.value === 'use server');
|
|
24
24
|
if (isUseClient && isUseServer) {
|
|
25
|
-
throw path.buildCodeFrameError(
|
|
25
|
+
throw path.buildCodeFrameError('It\'s not possible to have both "use client" and "use server" directives in the same file.');
|
|
26
26
|
}
|
|
27
27
|
if (!isUseClient && !isUseServer) {
|
|
28
28
|
return;
|
|
@@ -44,7 +44,7 @@ function reactClientReferencesPlugin(api) {
|
|
|
44
44
|
if (declaration.id.type === 'Identifier') {
|
|
45
45
|
const exportName = declaration.id.name;
|
|
46
46
|
exportNames.add(exportName);
|
|
47
|
-
callback(exportName);
|
|
47
|
+
callback(exportName, exportPath);
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
}
|
|
@@ -52,14 +52,14 @@ function reactClientReferencesPlugin(api) {
|
|
|
52
52
|
const exportName = exportPath.node.declaration.id?.name;
|
|
53
53
|
if (exportName) {
|
|
54
54
|
exportNames.add(exportName);
|
|
55
|
-
callback(exportName);
|
|
55
|
+
callback(exportName, exportPath);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
else if (exportPath.node.declaration.type === 'ClassDeclaration') {
|
|
59
59
|
const exportName = exportPath.node.declaration.id?.name;
|
|
60
60
|
if (exportName) {
|
|
61
61
|
exportNames.add(exportName);
|
|
62
|
-
callback(exportName);
|
|
62
|
+
callback(exportName, exportPath);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
else if (![
|
|
@@ -77,7 +77,7 @@ function reactClientReferencesPlugin(api) {
|
|
|
77
77
|
if (core_1.types.isIdentifier(specifier.exported)) {
|
|
78
78
|
const exportName = specifier.exported.name;
|
|
79
79
|
exportNames.add(exportName);
|
|
80
|
-
callback(exportName);
|
|
80
|
+
callback(exportName, exportPath);
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
83
|
// TODO: What is this type?
|
|
@@ -86,9 +86,15 @@ function reactClientReferencesPlugin(api) {
|
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
},
|
|
89
|
-
ExportDefaultDeclaration() {
|
|
89
|
+
ExportDefaultDeclaration(path) {
|
|
90
90
|
exportNames.add('default');
|
|
91
|
-
callback('default');
|
|
91
|
+
callback('default', path);
|
|
92
|
+
},
|
|
93
|
+
ExportAllDeclaration(exportPath) {
|
|
94
|
+
if (exportPath.node.source) {
|
|
95
|
+
// exportNames.add('*');
|
|
96
|
+
callback('*', exportPath);
|
|
97
|
+
}
|
|
92
98
|
},
|
|
93
99
|
});
|
|
94
100
|
return exportNames;
|
|
@@ -99,6 +105,28 @@ function reactClientReferencesPlugin(api) {
|
|
|
99
105
|
// The "use server" transform for react-server is in a different plugin.
|
|
100
106
|
return;
|
|
101
107
|
}
|
|
108
|
+
// Assert that assignment to `module.exports` or `exports` is not allowed.
|
|
109
|
+
path.traverse({
|
|
110
|
+
AssignmentExpression(path) {
|
|
111
|
+
if (core_1.types.isMemberExpression(path.node.left) &&
|
|
112
|
+
'name' in path.node.left.object &&
|
|
113
|
+
(path.node.left.object.name === 'module' ||
|
|
114
|
+
path.node.left.object.name === 'exports')) {
|
|
115
|
+
throw path.buildCodeFrameError('Assignment to `module.exports` or `exports` is not allowed in a "use server" file. Only async functions can be exported.');
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
// Also check Object.assign
|
|
119
|
+
CallExpression(path) {
|
|
120
|
+
if (core_1.types.isMemberExpression(path.node.callee) &&
|
|
121
|
+
'name' in path.node.callee.property &&
|
|
122
|
+
'name' in path.node.callee.object &&
|
|
123
|
+
path.node.callee.property.name === 'assign' &&
|
|
124
|
+
(path.node.callee.object.name === 'Object' ||
|
|
125
|
+
path.node.callee.object.name === 'exports')) {
|
|
126
|
+
throw path.buildCodeFrameError('Assignment to `module.exports` or `exports` is not allowed in a "use server" file. Only async functions can be exported.');
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
});
|
|
102
130
|
// Handle "use server" in the client.
|
|
103
131
|
const proxyModule = [
|
|
104
132
|
`import { createServerReference } from 'react-server-dom-webpack/client';`,
|
|
@@ -107,10 +135,13 @@ function reactClientReferencesPlugin(api) {
|
|
|
107
135
|
const getProxy = (exportName) => {
|
|
108
136
|
return `createServerReference(${JSON.stringify(`${outputKey}#${exportName}`)}, callServerRSC)`;
|
|
109
137
|
};
|
|
110
|
-
const pushProxy = (exportName) => {
|
|
138
|
+
const pushProxy = (exportName, path) => {
|
|
111
139
|
if (exportName === 'default') {
|
|
112
140
|
proxyModule.push(`export default ${getProxy(exportName)};`);
|
|
113
141
|
}
|
|
142
|
+
else if (exportName === '*') {
|
|
143
|
+
throw path.buildCodeFrameError('Re-exporting all modules is not supported in a "use server" file. Only async functions can be exported.');
|
|
144
|
+
}
|
|
114
145
|
else {
|
|
115
146
|
proxyModule.push(`export const ${exportName} = ${getProxy(exportName)};`);
|
|
116
147
|
}
|
|
@@ -146,17 +177,27 @@ function reactClientReferencesPlugin(api) {
|
|
|
146
177
|
`const proxy = /*@__PURE__*/ require("react-server-dom-webpack/server").createClientModuleProxy(${JSON.stringify(outputKey)});`,
|
|
147
178
|
`module.exports = proxy;`,
|
|
148
179
|
];
|
|
149
|
-
const getProxy = (exportName) => {
|
|
150
|
-
return `(/*@__PURE__*/ proxy[${JSON.stringify(exportName)}])`;
|
|
151
|
-
};
|
|
152
180
|
const pushProxy = (exportName) => {
|
|
153
181
|
if (exportName === 'default') {
|
|
154
|
-
proxyModule.push(`export default
|
|
182
|
+
proxyModule.push(`export default require("react-server-dom-webpack/server").registerClientReference(function () {
|
|
183
|
+
throw new Error(${JSON.stringify(`Attempted to call the default export of ${filePath} from the server but it's on the client. ` +
|
|
184
|
+
`It's not possible to invoke a client function from the server, it can ` +
|
|
185
|
+
`only be rendered as a Component or passed to props of a Client Component.`)});
|
|
186
|
+
}, ${JSON.stringify(outputKey)}, ${JSON.stringify(exportName)});`);
|
|
187
|
+
}
|
|
188
|
+
else if (exportName === '*') {
|
|
189
|
+
// Do nothing because we have the top-level hack to inject module.exports.
|
|
155
190
|
}
|
|
156
191
|
else {
|
|
157
|
-
proxyModule.push(`export const ${exportName} =
|
|
192
|
+
proxyModule.push(`export const ${exportName} = require("react-server-dom-webpack/server").registerClientReference(function () {
|
|
193
|
+
throw new Error(${JSON.stringify(`Attempted to call ${exportName}() of ${filePath} from the server but ${exportName} is on the client. ` +
|
|
194
|
+
`It's not possible to invoke a client function from the server, it can ` +
|
|
195
|
+
`only be rendered as a Component or passed to props of a Client Component.`)});
|
|
196
|
+
}, ${JSON.stringify(outputKey)}, ${JSON.stringify(exportName)});`);
|
|
158
197
|
}
|
|
159
198
|
};
|
|
199
|
+
// TODO: How to handle `export * from './module'`?
|
|
200
|
+
// TODO: How to handle module.exports, do we just assert that it isn't supported with server components?
|
|
160
201
|
// Collect all of the exports
|
|
161
202
|
const proxyExports = iterateExports(pushProxy, 'client');
|
|
162
203
|
// Clear the body
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2015-present 650 Industries. All rights reserved.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.expoImportMetaTransformPlugin = void 0;
|
|
5
|
+
function expoImportMetaTransformPlugin(api) {
|
|
6
|
+
const { types: t } = api;
|
|
7
|
+
return {
|
|
8
|
+
name: 'expo-import-meta-transform',
|
|
9
|
+
visitor: {
|
|
10
|
+
MetaProperty(path) {
|
|
11
|
+
const { node } = path;
|
|
12
|
+
if (node.meta.name === 'import' && node.property.name === 'meta') {
|
|
13
|
+
const replacement = t.memberExpression(t.identifier('globalThis'), t.identifier('__ExpoImportMetaRegistry'));
|
|
14
|
+
path.replaceWith(replacement);
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.expoImportMetaTransformPlugin = expoImportMetaTransformPlugin;
|
package/build/index.d.ts
CHANGED
|
@@ -67,6 +67,14 @@ type BabelPresetExpoPlatformOptions = {
|
|
|
67
67
|
};
|
|
68
68
|
/** Enable `typeof window` runtime checks. The default behavior is to minify `typeof window` on web clients to `"object"` and `"undefined"` on servers. */
|
|
69
69
|
minifyTypeofWindow?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Enable that transform that converts `import.meta` to `globalThis.__ExpoImportMetaRegistry`.
|
|
72
|
+
*
|
|
73
|
+
* > **Note:** Use this option at your own risk. If the JavaScript engine supports `import.meta` natively, this transformation may interfere with the native implementation.
|
|
74
|
+
*
|
|
75
|
+
* @default `false`
|
|
76
|
+
*/
|
|
77
|
+
unstable_transformImportMeta?: boolean;
|
|
70
78
|
};
|
|
71
79
|
export type BabelPresetExpoOptions = BabelPresetExpoPlatformOptions & {
|
|
72
80
|
/** Web-specific settings. */
|
package/build/index.js
CHANGED
|
@@ -181,6 +181,9 @@ function babelPresetExpo(api, options = {}) {
|
|
|
181
181
|
if (platformOptions.disableImportExportTransform) {
|
|
182
182
|
extraPlugins.push([require('./detect-dynamic-exports').detectDynamicExports]);
|
|
183
183
|
}
|
|
184
|
+
if (platformOptions.unstable_transformImportMeta === true) {
|
|
185
|
+
extraPlugins.push(require('./import-meta-transform-plugin').expoImportMetaTransformPlugin);
|
|
186
|
+
}
|
|
184
187
|
return {
|
|
185
188
|
presets: [
|
|
186
189
|
(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-preset-expo",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.1.0-canary-20250408-7f0ab53",
|
|
4
4
|
"description": "The Babel preset for Expo projects",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"files": [
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@babel/plugin-transform-parameters": "^7.24.7",
|
|
56
56
|
"@babel/preset-react": "^7.22.15",
|
|
57
57
|
"@babel/preset-typescript": "^7.23.0",
|
|
58
|
-
"@react-native/babel-preset": "0.79.0
|
|
58
|
+
"@react-native/babel-preset": "0.79.0",
|
|
59
59
|
"babel-plugin-react-native-web": "~0.19.13",
|
|
60
60
|
"babel-plugin-transform-flow-enums": "^0.0.2",
|
|
61
61
|
"babel-plugin-syntax-hermes-parser": "^0.25.1",
|
|
@@ -80,9 +80,8 @@
|
|
|
80
80
|
"@babel/traverse": "^7.9.0",
|
|
81
81
|
"@babel/types": "^7.9.0",
|
|
82
82
|
"babel-plugin-react-compiler": "^19.0.0-beta-9ee70a1-20241017",
|
|
83
|
-
"expo-module-scripts": "
|
|
83
|
+
"expo-module-scripts": "4.1.1-canary-20250408-7f0ab53",
|
|
84
84
|
"jest": "^29.2.1",
|
|
85
85
|
"react-compiler-runtime": "^19.0.0-beta-8a03594-20241020"
|
|
86
|
-
}
|
|
87
|
-
"gitHead": "68b8233002dc678934ba40cbade7fbc80e71aeff"
|
|
86
|
+
}
|
|
88
87
|
}
|