babel-preset-expo
Advanced tools
Comparing version 12.0.4 to 12.1.0-canary-20241211-61c49bd
@@ -17,3 +17,2 @@ "use strict"; | ||
const { types: t } = api; | ||
// TODO: Is exporting | ||
const isProduction = api.caller(common_1.getIsProd); | ||
@@ -41,2 +40,3 @@ const platform = api.caller((caller) => caller?.platform); | ||
} | ||
let displayName = 'Component'; | ||
// Assert that a default export must exist and that no other exports should be present. | ||
@@ -58,4 +58,7 @@ // NOTE: In the future we could support other exports with extraction. | ||
}, | ||
ExportDefaultDeclaration() { | ||
ExportDefaultDeclaration(path) { | ||
hasDefaultExport = true; | ||
if (t.isFunctionDeclaration(path.node.declaration) && path.node.declaration.id) { | ||
displayName = path.node.declaration.id.name; | ||
} | ||
}, | ||
@@ -84,20 +87,2 @@ }); | ||
const outputKey = url_1.default.pathToFileURL(filePath).href; | ||
const proxyModule = [ | ||
`import React from 'react';`, | ||
`import { WebView } from 'expo/dom/internal';`, | ||
]; | ||
if (isProduction) { | ||
// MUST MATCH THE EXPORT COMMAND! | ||
const hash = crypto_1.default.createHash('sha1').update(outputKey).digest('hex'); | ||
proxyModule.push(`const filePath = "${hash}.html";`); | ||
} | ||
else { | ||
proxyModule.push( | ||
// Add the basename to improve the Safari debug preview option. | ||
`const filePath = "${fileBasename}?file=" + ${JSON.stringify(outputKey)};`); | ||
} | ||
proxyModule.push(` | ||
export default React.forwardRef((props, ref) => { | ||
return React.createElement(WebView, { ref, ...props, filePath }); | ||
});`); | ||
// Removes all imports using babel API, that will disconnect import bindings from the program. | ||
@@ -107,3 +92,3 @@ // plugin-transform-typescript TSX uses the bindings to remove type imports. | ||
// the plugin-transform-typescript treats it as an typed import and removes it. | ||
// That will futher cause undefined `React` error. | ||
// That will further cause undefined `React` error. | ||
path.traverse({ | ||
@@ -114,6 +99,28 @@ ImportDeclaration(path) { | ||
}); | ||
// Clear the body | ||
path.node.body = []; | ||
path.node.directives = []; | ||
path.pushContainer('body', core_1.template.ast(proxyModule.join('\n'))); | ||
// Create template with declaration first | ||
const proxyModuleTemplate = ` | ||
import React from 'react'; | ||
import { WebView } from 'expo/dom/internal'; | ||
${isProduction | ||
? `const filePath = "${crypto_1.default.createHash('sha1').update(outputKey).digest('hex')}.html";` | ||
: `const filePath = "${fileBasename}?file=" + ${JSON.stringify(outputKey)};`} | ||
const _Expo_DOMProxyComponent = React.forwardRef((props, ref) => { | ||
return React.createElement(WebView, { ref, ...props, filePath }); | ||
}); | ||
if (__DEV__) _Expo_DOMProxyComponent.displayName = ${JSON.stringify(`DOM(${displayName})`)}; | ||
export default _Expo_DOMProxyComponent; | ||
`; | ||
// Convert template to AST and push to body | ||
const ast = core_1.template.ast(proxyModuleTemplate); | ||
const results = path.pushContainer('body', ast); | ||
// Find and register the component declaration | ||
results.forEach((nodePath) => { | ||
if (t.isVariableDeclaration(nodePath.node) && | ||
'name' in nodePath.node.declarations[0]?.id && | ||
nodePath.node.declarations[0].id.name === '_Expo_DOMProxyComponent') { | ||
path.scope.registerDeclaration(nodePath); | ||
} | ||
}); | ||
assertExpoMetadata(state.file.metadata); | ||
@@ -120,0 +127,0 @@ // Save the client reference in the metadata. |
{ | ||
"name": "babel-preset-expo", | ||
"version": "12.0.4", | ||
"version": "12.1.0-canary-20241211-61c49bd", | ||
"description": "The Babel preset for Expo projects", | ||
@@ -50,3 +50,3 @@ "main": "build/index.js", | ||
"@babel/preset-typescript": "^7.23.0", | ||
"@react-native/babel-preset": "0.76.5", | ||
"@react-native/babel-preset": "0.76.3", | ||
"babel-plugin-react-native-web": "~0.19.13", | ||
@@ -70,7 +70,6 @@ "react-refresh": "^0.14.2" | ||
"babel-plugin-react-compiler": "^19.0.0-beta-9ee70a1-20241017", | ||
"expo-module-scripts": "^4.0.0", | ||
"expo-module-scripts": "4.0.3-canary-20241211-61c49bd", | ||
"jest": "^29.2.1", | ||
"react-compiler-runtime": "^19.0.0-beta-8a03594-20241020" | ||
}, | ||
"gitHead": "1faceb8d22bebee4571ef3a2f9578bec33dc26b1" | ||
} | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
124805
2345
1
+ Added@react-native/babel-plugin-codegen@0.76.3(transitive)
+ Added@react-native/babel-preset@0.76.3(transitive)
+ Added@react-native/codegen@0.76.3(transitive)
- Removed@react-native/babel-plugin-codegen@0.76.5(transitive)
- Removed@react-native/babel-preset@0.76.5(transitive)
- Removed@react-native/codegen@0.76.5(transitive)