babel-preset-expo 12.0.4 → 12.0.6
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.
|
@@ -101,13 +101,58 @@ function reactServerActionsPlugin(api) {
|
|
|
101
101
|
const functionDeclaration = t.exportNamedDeclaration(t.variableDeclaration(bindingKind, [
|
|
102
102
|
t.variableDeclarator(extractedIdentifier, extractedFunctionExpr),
|
|
103
103
|
]));
|
|
104
|
-
//
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
// Insert the declaration as close to the original declaration as possible.
|
|
105
|
+
const isPathFunctionInTopLevel = path.find((p) => p.isProgram()) === path;
|
|
106
|
+
const decl = isPathFunctionInTopLevel ? path : findImmediatelyEnclosingDeclaration(path);
|
|
107
|
+
let inserted;
|
|
108
|
+
const canInsertExportNextToPath = (decl) => {
|
|
109
|
+
if (!decl) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
if (decl.parentPath?.isProgram()) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
};
|
|
117
|
+
const findNearestPathThatSupportsInsertBefore = (decl) => {
|
|
118
|
+
let current = decl;
|
|
119
|
+
// Check if current scope is suitable for `export` insertion
|
|
120
|
+
while (current && !current.isProgram()) {
|
|
121
|
+
if (canInsertExportNextToPath(current)) {
|
|
122
|
+
return current;
|
|
123
|
+
}
|
|
124
|
+
const parentPath = current.parentPath;
|
|
125
|
+
if (!parentPath) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
current = parentPath;
|
|
129
|
+
}
|
|
130
|
+
if (current.isFunction()) {
|
|
131
|
+
// Don't insert exports inside functions
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
return current;
|
|
135
|
+
};
|
|
136
|
+
const topLevelDecl = decl ? findNearestPathThatSupportsInsertBefore(decl) : null;
|
|
137
|
+
if (topLevelDecl) {
|
|
138
|
+
// If it's a variable declaration, insert before its parent statement to avoid syntax errors
|
|
139
|
+
const targetPath = topLevelDecl.isVariableDeclarator()
|
|
140
|
+
? topLevelDecl.parentPath
|
|
141
|
+
: topLevelDecl;
|
|
142
|
+
[inserted] = targetPath.insertBefore(functionDeclaration);
|
|
143
|
+
moduleScope.registerBinding(bindingKind, inserted);
|
|
144
|
+
inserted.addComment('leading', ' hoisted action: ' + (getFnPathName(path) ?? '<anonymous>'), true);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
// Fallback to inserting after the last import if no enclosing declaration is found
|
|
148
|
+
const programBody = moduleScope.path.get('body');
|
|
149
|
+
const lastImportPath = findLast(Array.isArray(programBody) ? programBody : [programBody], (stmt) => stmt.isImportDeclaration());
|
|
150
|
+
[inserted] = lastImportPath.insertAfter(functionDeclaration);
|
|
151
|
+
moduleScope.registerBinding(bindingKind, inserted);
|
|
152
|
+
inserted.addComment('leading', ' hoisted action: ' + (getFnPathName(path) ?? '<anonymous>'), true);
|
|
153
|
+
}
|
|
110
154
|
return {
|
|
155
|
+
inserted,
|
|
111
156
|
extractedIdentifier,
|
|
112
157
|
getReplacement: () => getInlineActionReplacement({
|
|
113
158
|
id: extractedIdentifier,
|
|
@@ -211,8 +256,6 @@ function reactServerActionsPlugin(api) {
|
|
|
211
256
|
// so we can't just remove this node.
|
|
212
257
|
// replace the function decl with a (hopefully) equivalent var declaration
|
|
213
258
|
// `var [name] = $$INLINE_ACTION_{N}`
|
|
214
|
-
// TODO: this'll almost certainly break when using default exports,
|
|
215
|
-
// but tangle's build doesn't support those anyway
|
|
216
259
|
const bindingKind = 'var';
|
|
217
260
|
const [inserted] = path.replaceWith(t.variableDeclaration(bindingKind, [t.variableDeclarator(fnId, extractedIdentifier)]));
|
|
218
261
|
tlb.scope.registerBinding(bindingKind, inserted);
|
|
@@ -510,7 +553,7 @@ const getFreeVariables = (path) => {
|
|
|
510
553
|
return [...freeVariablesSet].sort();
|
|
511
554
|
};
|
|
512
555
|
const getFnPathName = (path) => {
|
|
513
|
-
return path.isArrowFunctionExpression() ? undefined : path.node
|
|
556
|
+
return path.isArrowFunctionExpression() ? undefined : path.node?.id?.name;
|
|
514
557
|
};
|
|
515
558
|
const isChildScope = ({ root, parent, child, }) => {
|
|
516
559
|
let curScope = child;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-preset-expo",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.6",
|
|
4
4
|
"description": "The Babel preset for Expo projects",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"files": [
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@babel/plugin-transform-parameters": "^7.22.15",
|
|
48
48
|
"@babel/preset-react": "^7.22.15",
|
|
49
49
|
"@babel/preset-typescript": "^7.23.0",
|
|
50
|
-
"@react-native/babel-preset": "0.76.
|
|
50
|
+
"@react-native/babel-preset": "0.76.6",
|
|
51
51
|
"babel-plugin-react-native-web": "~0.19.13",
|
|
52
52
|
"react-refresh": "^0.14.2"
|
|
53
53
|
},
|
|
@@ -66,9 +66,9 @@
|
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@babel/core": "^7.20.0",
|
|
68
68
|
"babel-plugin-react-compiler": "^19.0.0-beta-9ee70a1-20241017",
|
|
69
|
-
"expo-module-scripts": "^4.0.
|
|
69
|
+
"expo-module-scripts": "^4.0.3",
|
|
70
70
|
"jest": "^29.2.1",
|
|
71
71
|
"react-compiler-runtime": "^19.0.0-beta-8a03594-20241020"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "986a4689b91f3efc527f7178a320b987c0005842"
|
|
74
74
|
}
|