babel-preset-expo 12.1.0-canary-20241211-61c49bd → 12.1.0-canary-20250131-5c4e588

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
- // TODO: this is cacheable, no need to recompute
105
- const programBody = moduleScope.path.get('body');
106
- const lastImportPath = findLast(Array.isArray(programBody) ? programBody : [programBody], (stmt) => stmt.isImportDeclaration());
107
- const [inserted] = lastImportPath.insertAfter(functionDeclaration);
108
- moduleScope.registerBinding(bindingKind, inserted);
109
- inserted.addComment('leading', ' hoisted action: ' + (getFnPathName(path) ?? '<anonymous>'), true);
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.id.name;
556
+ return path.isArrowFunctionExpression() ? undefined : path.node?.id?.name;
514
557
  };
515
558
  const isChildScope = ({ root, parent, child, }) => {
516
559
  let curScope = child;
@@ -13,15 +13,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  // use `this.foo = bar` instead of `this.defineProperty('foo', ...)`
14
14
  const loose = true;
15
15
  const defaultPlugins = [
16
- [require('@babel/plugin-syntax-flow')],
16
+ // This is required for parsing React Native with RSC enabled :/
17
+ [require('babel-plugin-syntax-hermes-parser'), { parseLangTypes: 'flow' }],
18
+ //
17
19
  [require('babel-plugin-transform-flow-enums')],
18
20
  [require('@babel/plugin-transform-private-methods'), { loose }],
19
21
  [require('@babel/plugin-transform-private-property-in-object'), { loose }],
20
- // [require('@babel/plugin-syntax-dynamic-import')],
21
22
  [require('@babel/plugin-syntax-export-default-from')],
22
- // [require('@babel/plugin-syntax-nullish-coalescing-operator')],
23
- // [require('@babel/plugin-syntax-optional-chaining')],
24
- // [require('@babel/plugin-transform-unicode-regex')],
25
23
  ];
26
24
  module.exports = function (babel, options) {
27
25
  const extraPlugins = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-preset-expo",
3
- "version": "12.1.0-canary-20241211-61c49bd",
3
+ "version": "12.1.0-canary-20250131-5c4e588",
4
4
  "description": "The Babel preset for Expo projects",
5
5
  "main": "build/index.js",
6
6
  "files": [
@@ -49,6 +49,7 @@
49
49
  "@babel/preset-typescript": "^7.23.0",
50
50
  "@react-native/babel-preset": "0.76.3",
51
51
  "babel-plugin-react-native-web": "~0.19.13",
52
+ "babel-plugin-syntax-hermes-parser": "0.25.1",
52
53
  "react-refresh": "^0.14.2"
53
54
  },
54
55
  "peerDependencies": {
@@ -66,7 +67,7 @@
66
67
  "devDependencies": {
67
68
  "@babel/core": "^7.20.0",
68
69
  "babel-plugin-react-compiler": "^19.0.0-beta-9ee70a1-20241017",
69
- "expo-module-scripts": "4.0.3-canary-20241211-61c49bd",
70
+ "expo-module-scripts": "4.0.4-canary-20250131-5c4e588",
70
71
  "jest": "^29.2.1",
71
72
  "react-compiler-runtime": "^19.0.0-beta-8a03594-20241020"
72
73
  }