@react-native/babel-plugin-codegen 0.77.0-nightly-20240915-afb40e9f2 → 0.77.0-nightly-20240917-51673e41a
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/index.js +24 -7
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
let FlowParser, TypeScriptParser, RNCodegen;
|
|
13
13
|
|
|
14
14
|
const {basename} = require('path');
|
|
15
|
+
const {cheap: traverseCheap} = require('@babel/traverse').default;
|
|
15
16
|
|
|
16
17
|
try {
|
|
17
18
|
FlowParser =
|
|
@@ -168,16 +169,32 @@ module.exports = function ({parse, types: t}) {
|
|
|
168
169
|
exit(path) {
|
|
169
170
|
if (this.defaultExport) {
|
|
170
171
|
const viewConfig = generateViewConfig(this.filename, this.code);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
172
|
+
|
|
173
|
+
const ast = parse(viewConfig, {
|
|
174
|
+
babelrc: false,
|
|
175
|
+
browserslistConfigFile: false,
|
|
176
|
+
configFile: false,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Almost the whole file is replaced with the viewConfig generated code that doesn't
|
|
180
|
+
// have a clear equivalent code on the source file when the user debugs, so we point
|
|
181
|
+
// it to the location of the default export that in that file, which is the closest
|
|
182
|
+
// to representing the code that is being generated.
|
|
183
|
+
// This is mostly useful when that generated code throws an error.
|
|
184
|
+
traverseCheap(ast, node => {
|
|
185
|
+
if (node?.loc) {
|
|
186
|
+
node.loc = this.defaultExport.node.loc;
|
|
187
|
+
node.start = this.defaultExport.node.start;
|
|
188
|
+
node.end = this.defaultExport.node.end;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
this.defaultExport.replaceWithMultiple(ast.program.body);
|
|
193
|
+
|
|
178
194
|
if (this.commandsExport != null) {
|
|
179
195
|
this.commandsExport.remove();
|
|
180
196
|
}
|
|
197
|
+
|
|
181
198
|
this.codeInserted = true;
|
|
182
199
|
}
|
|
183
200
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/babel-plugin-codegen",
|
|
3
|
-
"version": "0.77.0-nightly-
|
|
3
|
+
"version": "0.77.0-nightly-20240917-51673e41a",
|
|
4
4
|
"description": "Babel plugin to generate native module and view manager code for React Native.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"index.js"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@
|
|
28
|
+
"@babel/traverse": "^7.25.3",
|
|
29
|
+
"@react-native/codegen": "0.77.0-nightly-20240917-51673e41a"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@babel/core": "^7.25.2"
|