babel-preset-expo 12.0.7-canary-20250124-42fe332 → 12.1.0-canary-20250122-166c2cb

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.
@@ -14,7 +14,6 @@ const url_1 = __importDefault(require("url"));
14
14
  const common_1 = require("./common");
15
15
  function expoUseDomDirectivePlugin(api) {
16
16
  const { types: t } = api;
17
- // TODO: Is exporting
18
17
  const isProduction = api.caller(common_1.getIsProd);
19
18
  const platform = api.caller((caller) => caller?.platform);
20
19
  const projectRoot = api.caller(common_1.getPossibleProjectRoot);
@@ -37,6 +36,7 @@ function expoUseDomDirectivePlugin(api) {
37
36
  // Do nothing for code that isn't marked as a dom component.
38
37
  return;
39
38
  }
39
+ let displayName = 'Component';
40
40
  // Assert that a default export must exist and that no other exports should be present.
41
41
  // NOTE: In the future we could support other exports with extraction.
42
42
  let hasDefaultExport = false;
@@ -53,8 +53,11 @@ function expoUseDomDirectivePlugin(api) {
53
53
  }
54
54
  throw path.buildCodeFrameError('Modules with the "use dom" directive only support a single default export.');
55
55
  },
56
- ExportDefaultDeclaration() {
56
+ ExportDefaultDeclaration(path) {
57
57
  hasDefaultExport = true;
58
+ if (t.isFunctionDeclaration(path.node.declaration) && path.node.declaration.id) {
59
+ displayName = path.node.declaration.id.name;
60
+ }
58
61
  },
59
62
  });
60
63
  if (!hasDefaultExport) {
@@ -78,38 +81,42 @@ function expoUseDomDirectivePlugin(api) {
78
81
  }
79
82
  }
80
83
  const outputKey = url_1.default.pathToFileURL(filePath).href;
81
- const proxyModule = [
82
- `import React from 'react';`,
83
- `import { WebView } from 'expo/dom/internal';`,
84
- ];
85
- if (isProduction) {
86
- // MUST MATCH THE EXPORT COMMAND!
87
- const hash = crypto_1.default.createHash('sha1').update(outputKey).digest('hex');
88
- proxyModule.push(`const filePath = "${hash}.html";`);
89
- }
90
- else {
91
- proxyModule.push(
92
- // Add the basename to improve the Safari debug preview option.
93
- `const filePath = "${fileBasename}?file=" + ${JSON.stringify(outputKey)};`);
94
- }
95
- proxyModule.push(`
96
- export default React.forwardRef((props, ref) => {
97
- return React.createElement(WebView, { ref, ...props, filePath });
98
- });`);
99
84
  // Removes all imports using babel API, that will disconnect import bindings from the program.
100
85
  // plugin-transform-typescript TSX uses the bindings to remove type imports.
101
86
  // If the DOM component has `import React from 'react';`,
102
87
  // the plugin-transform-typescript treats it as an typed import and removes it.
103
- // That will futher cause undefined `React` error.
88
+ // That will further cause undefined `React` error.
104
89
  path.traverse({
105
90
  ImportDeclaration(path) {
106
91
  path.remove();
107
92
  },
108
93
  });
109
- // Clear the body
110
94
  path.node.body = [];
111
95
  path.node.directives = [];
112
- path.pushContainer('body', core_1.template.ast(proxyModule.join('\n')));
96
+ // Create template with declaration first
97
+ const proxyModuleTemplate = `
98
+ import React from 'react';
99
+ import { WebView } from 'expo/dom/internal';
100
+ ${isProduction
101
+ ? `const filePath = "${crypto_1.default.createHash('sha1').update(outputKey).digest('hex')}.html";`
102
+ : `const filePath = "${fileBasename}?file=" + ${JSON.stringify(outputKey)};`}
103
+ const _Expo_DOMProxyComponent = React.forwardRef((props, ref) => {
104
+ return React.createElement(WebView, { ref, ...props, filePath });
105
+ });
106
+ if (__DEV__) _Expo_DOMProxyComponent.displayName = ${JSON.stringify(`DOM(${displayName})`)};
107
+ export default _Expo_DOMProxyComponent;
108
+ `;
109
+ // Convert template to AST and push to body
110
+ const ast = core_1.template.ast(proxyModuleTemplate);
111
+ const results = path.pushContainer('body', ast);
112
+ // Find and register the component declaration
113
+ results.forEach((nodePath) => {
114
+ if (t.isVariableDeclaration(nodePath.node) &&
115
+ 'name' in nodePath.node.declarations[0]?.id &&
116
+ nodePath.node.declarations[0].id.name === '_Expo_DOMProxyComponent') {
117
+ path.scope.registerDeclaration(nodePath);
118
+ }
119
+ });
113
120
  assertExpoMetadata(state.file.metadata);
114
121
  // Save the client reference in the metadata.
115
122
  state.file.metadata.expoDomComponentReference = outputKey;
@@ -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.0.7-canary-20250124-42fe332",
3
+ "version": "12.1.0-canary-20250122-166c2cb",
4
4
  "description": "The Babel preset for Expo projects",
5
5
  "main": "build/index.js",
6
6
  "files": [
@@ -47,8 +47,9 @@
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.6",
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,9 +67,8 @@
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.4-canary-20250124-42fe332",
70
+ "expo-module-scripts": "4.0.4-canary-20250122-166c2cb",
70
71
  "jest": "^29.2.1",
71
72
  "react-compiler-runtime": "^19.0.0-beta-8a03594-20241020"
72
- },
73
- "gitHead": "42fe3321395867f7bacba1ea4dc90db1692f119e"
73
+ }
74
74
  }