@react-native/babel-plugin-codegen 0.82.0-nightly-20250821-0ef21bf8a → 0.82.0-nightly-20250822-646945c2f

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 +58 -6
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -102,6 +102,58 @@ function isCodegenDeclaration(declaration) {
102
102
  return false;
103
103
  }
104
104
 
105
+ function isCodegenNativeCommandsDeclaration(declaration) {
106
+ if (!declaration) {
107
+ return false;
108
+ }
109
+
110
+ // Handle direct calls: codegenNativeCommands()
111
+ if (
112
+ declaration.type === 'CallExpression' &&
113
+ declaration.callee &&
114
+ declaration.callee.type === 'Identifier' &&
115
+ declaration.callee.name === 'codegenNativeCommands'
116
+ ) {
117
+ return true;
118
+ }
119
+
120
+ // Handle coverage instrumentation: (cov_xxx().s[0]++, codegenNativeCommands())
121
+ if (declaration.type === 'SequenceExpression' && declaration.expressions) {
122
+ // Get the last expression in the sequence (the actual function call)
123
+ const lastExpression =
124
+ declaration.expressions[declaration.expressions.length - 1];
125
+ // Recursively check if the last expression is a valid codegenNativeCommands call
126
+ return isCodegenNativeCommandsDeclaration(lastExpression);
127
+ }
128
+
129
+ // Handle Flow type casts: (codegenNativeCommands(): NativeCommands)
130
+ if (
131
+ (declaration.type === 'TypeCastExpression' ||
132
+ declaration.type === 'AsExpression') &&
133
+ declaration.expression &&
134
+ declaration.expression.type === 'CallExpression' &&
135
+ declaration.expression.callee &&
136
+ declaration.expression.callee.type === 'Identifier' &&
137
+ declaration.expression.callee.name === 'codegenNativeCommands'
138
+ ) {
139
+ return true;
140
+ }
141
+
142
+ // Handle TypeScript assertions: codegenNativeCommands() as NativeCommands
143
+ if (
144
+ declaration.type === 'TSAsExpression' &&
145
+ declaration.expression &&
146
+ declaration.expression.type === 'CallExpression' &&
147
+ declaration.expression.callee &&
148
+ declaration.expression.callee.type === 'Identifier' &&
149
+ declaration.expression.callee.name === 'codegenNativeCommands'
150
+ ) {
151
+ return true;
152
+ }
153
+
154
+ return false;
155
+ }
156
+
105
157
  module.exports = function ({parse, types: t}) {
106
158
  return {
107
159
  pre(state) {
@@ -125,12 +177,12 @@ module.exports = function ({parse, types: t}) {
125
177
  const firstDeclaration = path.node.declaration.declarations[0];
126
178
 
127
179
  if (firstDeclaration.type === 'VariableDeclarator') {
128
- if (
129
- firstDeclaration.init &&
130
- firstDeclaration.init.type === 'CallExpression' &&
131
- firstDeclaration.init.callee.type === 'Identifier' &&
132
- firstDeclaration.init.callee.name === 'codegenNativeCommands'
133
- ) {
180
+ // Check if this is a valid codegenNativeCommands call, handling type annotations
181
+ const isValidCommandsExport = isCodegenNativeCommandsDeclaration(
182
+ firstDeclaration.init,
183
+ );
184
+
185
+ if (isValidCommandsExport) {
134
186
  if (
135
187
  firstDeclaration.id.type === 'Identifier' &&
136
188
  firstDeclaration.id.name !== 'Commands'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native/babel-plugin-codegen",
3
- "version": "0.82.0-nightly-20250821-0ef21bf8a",
3
+ "version": "0.82.0-nightly-20250822-646945c2f",
4
4
  "description": "Babel plugin to generate native module and view manager code for React Native.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@babel/traverse": "^7.25.3",
29
- "@react-native/codegen": "0.82.0-nightly-20250821-0ef21bf8a"
29
+ "@react-native/codegen": "0.82.0-nightly-20250822-646945c2f"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@babel/core": "^7.25.2"