@react-native/babel-plugin-codegen 0.77.0-nightly-20240916-7bd4a5496 → 0.77.0-nightly-20240918-bebd6531b

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.
Files changed (2) hide show
  1. package/index.js +24 -7
  2. 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
- this.defaultExport.replaceWithMultiple(
172
- parse(viewConfig, {
173
- babelrc: false,
174
- browserslistConfigFile: false,
175
- configFile: false,
176
- }).program.body,
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-20240916-7bd4a5496",
3
+ "version": "0.77.0-nightly-20240918-bebd6531b",
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
- "@react-native/codegen": "0.77.0-nightly-20240916-7bd4a5496"
28
+ "@babel/traverse": "^7.25.3",
29
+ "@react-native/codegen": "0.77.0-nightly-20240918-bebd6531b"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@babel/core": "^7.25.2"