@vxrn/compiler 1.27.0 → 1.27.1-1789509973946

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 (95) hide show
  1. package/dist/cjs/cache.cjs +112 -109
  2. package/dist/cjs/configure.cjs +26 -28
  3. package/dist/cjs/constants.cjs +56 -60
  4. package/dist/cjs/index.cjs +420 -442
  5. package/dist/cjs/reactNativeCodegen.cjs +105 -114
  6. package/dist/cjs/reactNativeViewConfig.cjs +362 -381
  7. package/dist/cjs/refresh-runtime.cjs +390 -397
  8. package/dist/cjs/transformBabel.cjs +273 -259
  9. package/dist/cjs/transformHermesAsync.cjs +36 -47
  10. package/dist/cjs/transformHermesLoops.cjs +279 -281
  11. package/dist/cjs/transformSWC.cjs +183 -200
  12. package/dist/cjs/transformWorklets.cjs +107 -95
  13. package/dist/cjs/types.cjs +9 -11
  14. package/dist/cjs/worklets/autoworklet.cjs +277 -222
  15. package/dist/cjs/worklets/globals.cjs +124 -60
  16. package/dist/cjs/worklets/hash.cjs +23 -27
  17. package/dist/cjs/worklets/scope.cjs +338 -359
  18. package/dist/cjs/worklets/serialize.cjs +73 -75
  19. package/dist/cjs/worklets/transform.cjs +217 -222
  20. package/dist/cjs/worklets/types.cjs +9 -11
  21. package/dist/esm/cache.mjs +96 -89
  22. package/dist/esm/cache.mjs.map +1 -1
  23. package/dist/esm/configure.mjs +11 -10
  24. package/dist/esm/configure.mjs.map +1 -1
  25. package/dist/esm/constants.mjs +41 -41
  26. package/dist/esm/constants.mjs.map +1 -1
  27. package/dist/esm/index.js +417 -424
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/index.mjs +417 -424
  30. package/dist/esm/index.mjs.map +1 -1
  31. package/dist/esm/reactNativeCodegen.mjs +90 -88
  32. package/dist/esm/reactNativeCodegen.mjs.map +1 -1
  33. package/dist/esm/reactNativeViewConfig.mjs +347 -362
  34. package/dist/esm/reactNativeViewConfig.mjs.map +1 -1
  35. package/dist/esm/refresh-runtime.mjs +372 -376
  36. package/dist/esm/refresh-runtime.mjs.map +1 -1
  37. package/dist/esm/transformBabel.mjs +255 -233
  38. package/dist/esm/transformBabel.mjs.map +1 -1
  39. package/dist/esm/transformHermesAsync.mjs +20 -21
  40. package/dist/esm/transformHermesAsync.mjs.map +1 -1
  41. package/dist/esm/transformHermesLoops.mjs +264 -255
  42. package/dist/esm/transformHermesLoops.mjs.map +1 -1
  43. package/dist/esm/transformSWC.mjs +163 -171
  44. package/dist/esm/transformSWC.mjs.map +1 -1
  45. package/dist/esm/transformWorklets.mjs +89 -69
  46. package/dist/esm/transformWorklets.mjs.map +1 -1
  47. package/dist/esm/types.mjs +0 -2
  48. package/dist/esm/worklets/autoworklet.mjs +258 -200
  49. package/dist/esm/worklets/autoworklet.mjs.map +1 -1
  50. package/dist/esm/worklets/globals.mjs +109 -42
  51. package/dist/esm/worklets/globals.mjs.map +1 -1
  52. package/dist/esm/worklets/hash.mjs +10 -9
  53. package/dist/esm/worklets/hash.mjs.map +1 -1
  54. package/dist/esm/worklets/scope.mjs +325 -341
  55. package/dist/esm/worklets/scope.mjs.map +1 -1
  56. package/dist/esm/worklets/serialize.mjs +60 -58
  57. package/dist/esm/worklets/serialize.mjs.map +1 -1
  58. package/dist/esm/worklets/transform.mjs +201 -197
  59. package/dist/esm/worklets/transform.mjs.map +1 -1
  60. package/dist/esm/worklets/types.mjs +0 -2
  61. package/package.json +7 -6
  62. package/src/cache.ts +37 -7
  63. package/src/index.ts +7 -3
  64. package/src/transformBabel.test.ts +209 -9
  65. package/src/transformBabel.ts +41 -12
  66. package/src/transformWorklets.test.ts +7 -1
  67. package/types/cache.d.ts +2 -2
  68. package/types/cache.d.ts.map +1 -1
  69. package/types/index.d.ts.map +1 -1
  70. package/types/transformBabel.d.ts +12 -0
  71. package/types/transformBabel.d.ts.map +1 -1
  72. package/types/transformSWC.d.ts +1 -4
  73. package/types/transformSWC.d.ts.map +1 -1
  74. package/dist/cjs/transformBabel.test.cjs +0 -448
  75. package/dist/cjs/transformHermesLoops.test.cjs +0 -257
  76. package/dist/cjs/transformSWC.test.cjs +0 -117
  77. package/dist/cjs/transformWorklets.test.cjs +0 -604
  78. package/dist/esm/transformBabel.test.mjs +0 -425
  79. package/dist/esm/transformBabel.test.mjs.map +0 -1
  80. package/dist/esm/transformHermesLoops.test.mjs +0 -234
  81. package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
  82. package/dist/esm/transformSWC.test.mjs +0 -118
  83. package/dist/esm/transformSWC.test.mjs.map +0 -1
  84. package/dist/esm/transformWorklets.test.mjs +0 -581
  85. package/dist/esm/transformWorklets.test.mjs.map +0 -1
  86. package/dist/esm/types.mjs.map +0 -1
  87. package/dist/esm/worklets/types.mjs.map +0 -1
  88. package/types/transformBabel.test.d.ts +0 -2
  89. package/types/transformBabel.test.d.ts.map +0 -1
  90. package/types/transformHermesLoops.test.d.ts +0 -2
  91. package/types/transformHermesLoops.test.d.ts.map +0 -1
  92. package/types/transformSWC.test.d.ts +0 -2
  93. package/types/transformSWC.test.d.ts.map +0 -1
  94. package/types/transformWorklets.test.d.ts +0 -2
  95. package/types/transformWorklets.test.d.ts.map +0 -1
@@ -5,38 +5,32 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
21
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
30
25
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
27
  var transformBabel_exports = {};
35
28
  __export(transformBabel_exports, {
36
- findUserBabelConfig: () => findUserBabelConfig,
37
- getBabelOptions: () => getBabelOptions,
38
- transformBabel: () => transformBabel,
39
- transformOxcReactCompiler: () => transformOxcReactCompiler
29
+ findUserBabelConfig: () => findUserBabelConfig,
30
+ getBabelOptions: () => getBabelOptions,
31
+ stripFlowTypes: () => stripFlowTypes,
32
+ transformBabel: () => transformBabel,
33
+ transformOxcReactCompiler: () => transformOxcReactCompiler
40
34
  });
41
35
  module.exports = __toCommonJS(transformBabel_exports);
42
36
  var import_node_fs = require("node:fs");
@@ -45,256 +39,276 @@ var import_utils = require("@vxrn/utils");
45
39
  var import_vite = require("vite");
46
40
  var import_configure = require("./configure.cjs");
47
41
  var import_constants = require("./constants.cjs");
48
- const USER_BABEL_CONFIG_FILES = ["babel.config.js", "babel.config.cjs", "babel.config.mjs", "babel.config.json", ".babelrc", ".babelrc.js", ".babelrc.json"];
49
- const ONE_GENERATED_MARKER = "@one-generated";
42
+ const USER_BABEL_CONFIG_FILES = [
43
+ "babel.config.js",
44
+ "babel.config.cjs",
45
+ "babel.config.mjs",
46
+ "babel.config.json",
47
+ ".babelrc",
48
+ ".babelrc.js",
49
+ ".babelrc.json"
50
+ ];
51
+ const ONE_GENERATED_MARKER = "@one/generated bundler-config";
50
52
  function findUserBabelConfig(projectRoot) {
51
- if (!projectRoot) return null;
52
- for (const name of USER_BABEL_CONFIG_FILES) {
53
- const fullPath = (0, import_node_path.join)(projectRoot, name);
54
- if ((0, import_node_fs.existsSync)(fullPath)) {
55
- try {
56
- const content = (0, import_node_fs.readFileSync)(fullPath, "utf8");
57
- if (content.includes(ONE_GENERATED_MARKER)) {
58
- continue;
59
- }
60
- } catch {
61
- continue;
62
- }
63
- return fullPath;
64
- }
65
- }
66
- return null;
53
+ if (!projectRoot) return null;
54
+ for (const name of USER_BABEL_CONFIG_FILES) {
55
+ const fullPath = (0, import_node_path.join)(projectRoot, name);
56
+ if ((0, import_node_fs.existsSync)(fullPath)) {
57
+ try {
58
+ const content = (0, import_node_fs.readFileSync)(fullPath, "utf8");
59
+ if (content.includes(ONE_GENERATED_MARKER)) {
60
+ continue;
61
+ }
62
+ } catch {
63
+ continue;
64
+ }
65
+ return fullPath;
66
+ }
67
+ }
68
+ return null;
67
69
  }
68
70
  function getBabelOptions(props) {
69
- props = {
70
- ...props,
71
- id: (0, import_vite.normalizePath)(props.id.split("?")[0])
72
- };
73
- const isProjectFile = !props.id.includes("node_modules");
74
- const userBabelConfig = isProjectFile && props.projectRoot ? findUserBabelConfig(props.projectRoot) : null;
75
- if (props.userSetting === "babel") {
76
- return getOptions(props, true, userBabelConfig);
77
- }
78
- if (typeof props.userSetting === "undefined" || typeof props.userSetting === "object" && props.userSetting.transform === "babel") {
79
- if (props.userSetting?.excludeDefaultPlugins) {
80
- return {
81
- ...props.userSetting,
82
- ...(userBabelConfig ? {
83
- configFile: userBabelConfig,
84
- babelrc: true
85
- } : {})
86
- };
87
- }
88
- return getOptions(props, false, userBabelConfig);
89
- }
90
- if (userBabelConfig) {
91
- return getOptions(props, false, userBabelConfig);
92
- }
93
- return null;
71
+ props = {
72
+ ...props,
73
+ id: (0, import_vite.normalizePath)(props.id.split("?")[0])
74
+ };
75
+ const isProjectFile = !props.id.includes("node_modules");
76
+ const userBabelConfig = isProjectFile && props.projectRoot ? findUserBabelConfig(props.projectRoot) : null;
77
+ if (props.userSetting === "babel") {
78
+ return getOptions(props, true, userBabelConfig);
79
+ }
80
+ if (typeof props.userSetting === "undefined" || typeof props.userSetting === "object" && props.userSetting.transform === "babel") {
81
+ if (props.userSetting?.excludeDefaultPlugins) {
82
+ return {
83
+ ...props.userSetting,
84
+ ...userBabelConfig ? {
85
+ configFile: userBabelConfig,
86
+ babelrc: true
87
+ } : {}
88
+ };
89
+ }
90
+ return getOptions(props, false, userBabelConfig);
91
+ }
92
+ const userSetting = props.userSetting;
93
+ if (userSetting === "swc" || userSetting === "oxc" || userSetting === false || typeof userSetting === "object" && userSetting !== null && (userSetting.transform === "swc" || userSetting.transform === "oxc")) {
94
+ return null;
95
+ }
96
+ if (userBabelConfig) {
97
+ return getOptions(props, false, userBabelConfig);
98
+ }
99
+ return null;
94
100
  }
95
101
  const getOptions = (props, force = false, userBabelConfig = null) => {
96
- let plugins = [];
97
- if (force || shouldBabelGenerators(props)) {
98
- plugins = getBasePlugins(props);
99
- }
100
- const enableNativewind = import_configure.configuration.enableNativewind && (props.environment === "ios" || props.environment === "android") &&
101
- // if reanimated gets wrapped in transform it causes circular dep issues
102
- !/node_modules/.test(props.id) &&
103
- // only needed for createElement calls, so be a bit conservative
104
- props.code.includes("createElement");
105
- if (enableNativewind) {
106
- if (!props.id.includes("node_modules")) {
107
- plugins.push((0, import_utils.resolvePath)("react-native-css-interop/dist/babel-plugin.js"));
108
- }
109
- }
110
- if (enableNativewind || shouldBabelReanimated(props)) {
111
- try {
112
- const workletsPlugin = (0, import_utils.resolvePath)("react-native-worklets/plugin", props.projectRoot);
113
- (0, import_constants.debug)?.(`Using babel worklets on file ${props.id}`);
114
- plugins.push(workletsPlugin);
115
- } catch {}
116
- }
117
- if (shouldBabelReactCompiler(props)) {
118
- (0, import_constants.debug)?.(`Using babel react compiler on file`);
119
- plugins.push(getBabelReactCompilerPlugin(props));
120
- }
121
- if (plugins.length || userBabelConfig) {
122
- return {
123
- plugins,
124
- ...(userBabelConfig ? {
125
- configFile: userBabelConfig,
126
- babelrc: true
127
- } : {})
128
- };
129
- }
130
- return null;
102
+ let plugins = [];
103
+ if (force || shouldBabelGenerators(props)) {
104
+ plugins = getBasePlugins(props);
105
+ }
106
+ const enableNativewind = import_configure.configuration.enableNativewind && (props.environment === "ios" || props.environment === "android") && !/node_modules/.test(props.id) && props.code.includes("createElement");
107
+ if (enableNativewind) {
108
+ if (!props.id.includes("node_modules")) {
109
+ plugins.push((0, import_utils.resolvePath)("react-native-css-interop/dist/babel-plugin.js"));
110
+ }
111
+ }
112
+ if (enableNativewind || shouldBabelReanimated(props)) {
113
+ try {
114
+ const workletsPlugin = (0, import_utils.resolvePath)("react-native-worklets/plugin", props.projectRoot);
115
+ (0, import_constants.debug)?.(`Using babel worklets on file ${props.id}`);
116
+ plugins.push(workletsPlugin);
117
+ } catch {}
118
+ }
119
+ if (shouldBabelReactCompiler(props)) {
120
+ (0, import_constants.debug)?.(`Using babel react compiler on file`);
121
+ plugins.push(getBabelReactCompilerPlugin(props));
122
+ }
123
+ if (plugins.length || userBabelConfig) {
124
+ return {
125
+ plugins,
126
+ ...userBabelConfig ? {
127
+ configFile: userBabelConfig,
128
+ babelrc: true
129
+ } : {}
130
+ };
131
+ }
132
+ return null;
131
133
  };
132
134
  async function transformOxcReactCompiler(id, code, optionsOrTarget = "19", sourceMap = false) {
133
- const {
134
- transform
135
- } = await import("oxc-transform-react");
136
- const compilerOptions = typeof optionsOrTarget === "string" ? {
137
- target: optionsOrTarget
138
- } : optionsOrTarget || {};
139
- const target = compilerOptions.target ?? "19";
140
- const result = await transform(id, code, {
141
- jsx: "preserve",
142
- sourcemap: sourceMap,
143
- reactCompiler: {
144
- target,
145
- ...compilerOptions,
146
- environment: {
147
- enableCustomTypeDefinitionForReanimated: true,
148
- ...compilerOptions.environment
149
- }
150
- }
151
- });
152
- if (result.fatal) {
153
- throw new Error(`[vxrn:compiler] oxc react compiler failed on ${id}: ${(result.errors ?? []).map(e => e.message ?? String(e)).join(", ")}`);
154
- }
155
- if (result.errors?.length) {
156
- (0, import_constants.debug)?.(`[compiler/bailout] ${id}: ${result.errors.map(e => e.message ?? String(e)).join(", ")}`);
157
- }
158
- return {
159
- code: result.code,
160
- map: sourceMap ? result.map : void 0
161
- };
135
+ const { transform } = await import("oxc-transform-react");
136
+ const compilerOptions = typeof optionsOrTarget === "string" ? { target: optionsOrTarget } : optionsOrTarget || {};
137
+ const target = compilerOptions.target ?? "19";
138
+ const result = await transform(id, code, {
139
+ jsx: "preserve",
140
+ sourcemap: sourceMap,
141
+ reactCompiler: {
142
+ target,
143
+ ...compilerOptions,
144
+ environment: {
145
+ enableCustomTypeDefinitionForReanimated: true,
146
+ ...compilerOptions.environment
147
+ }
148
+ }
149
+ });
150
+ if (result.fatal) {
151
+ throw new Error(`[vxrn:compiler] oxc react compiler failed on ${id}: ${(result.errors ?? []).map((e) => e.message ?? String(e)).join(", ")}`);
152
+ }
153
+ if (result.errors?.length) {
154
+ (0, import_constants.debug)?.(`[compiler/bailout] ${id}: ${result.errors.map((e) => e.message ?? String(e)).join(", ")}`);
155
+ }
156
+ return {
157
+ code: result.code,
158
+ map: sourceMap ? result.map : void 0
159
+ };
162
160
  }
163
161
  async function transformBabel(id, code, options) {
164
- const [{
165
- default: babelCore
166
- }, {
167
- default: hermesParserPlugin
168
- }] = await Promise.all([import("@babel/core"), import("babel-plugin-syntax-hermes-parser")]);
169
- const extension = (0, import_node_path.extname)(id);
170
- const isTSX = extension === ".tsx";
171
- const isTS = isTSX || extension === ".ts";
172
- const babelOptions = {
173
- filename: id,
174
- compact: false,
175
- babelrc: options.babelrc ?? false,
176
- configFile: options.configFile ?? false,
177
- sourceMaps: false,
178
- minified: false,
179
- ...options,
180
- presets: [isTS ? ["@babel/preset-typescript", {
181
- isTSX,
182
- allExtensions: isTSX
183
- }] : "", ...(options.presets || [])].filter(Boolean),
184
- // non-TS files use React Native's Flow dialect. RN's own component specs are
185
- // Flow `.js` (`import type`, `codegenNativeComponent<T>(…)`, `(expr: Type)` casts).
186
- // enable Hermes Flow parsing + stripping, mirroring the TypeScript preset above
187
- // (`@react-native/babel-preset` uses the same parser for JS). without it babel
188
- // can't parse current RN Flow syntax such as `call<T>(...) as HostComponent<T>`, so
189
- // plugins like
190
- // @react-native/babel-plugin-codegen silently fail on RN specs and the runtime
191
- // "Codegen didn't run" warning fires. TS path is byte-identical (empty slice).
192
- plugins: [...(isTS ? [] : [[hermesParserPlugin, {
193
- parseLangTypes: "flow",
194
- reactRuntimeTarget: "19"
195
- }]]), ...(options.plugins || []), ...(isTS ? [] : ["@babel/plugin-transform-flow-strip-types"])]
196
- };
197
- return await new Promise((res, rej) => {
198
- babelCore.transform(code, babelOptions, (err, result) => {
199
- if (!result || err) {
200
- return rej(err || new Error(`[vxrn:compiler] babel returned no result for ${id}`));
201
- }
202
- res(result);
203
- });
204
- });
162
+ const [{ default: babelCore }, { default: hermesParserPlugin }] = await Promise.all([import("@babel/core"), import("babel-plugin-syntax-hermes-parser")]);
163
+ const extension = (0, import_node_path.extname)(id);
164
+ const isTSX = extension === ".tsx";
165
+ const isTS = isTSX || extension === ".ts";
166
+ const babelOptions = {
167
+ filename: id,
168
+ compact: false,
169
+ babelrc: options.babelrc ?? false,
170
+ configFile: options.configFile ?? false,
171
+ sourceMaps: false,
172
+ minified: false,
173
+ ...options,
174
+ caller: {
175
+ name: "vxrn",
176
+ supportsStaticESM: true,
177
+ supportsDynamicImport: true
178
+ },
179
+ presets: [isTS ? ["@babel/preset-typescript", {
180
+ isTSX,
181
+ allExtensions: isTSX
182
+ }] : "", ...options.presets || []].filter(Boolean),
183
+ plugins: [
184
+ ...isTS ? [] : [[hermesParserPlugin, {
185
+ parseLangTypes: "flow",
186
+ reactRuntimeTarget: "19"
187
+ }], "babel-plugin-transform-flow-enums"],
188
+ ...options.plugins || [],
189
+ ...isTS ? [] : ["@babel/plugin-transform-flow-strip-types"]
190
+ ]
191
+ };
192
+ return await new Promise((res, rej) => {
193
+ babelCore.transform(code, babelOptions, (err, result) => {
194
+ if (!result || err) {
195
+ return rej(err || new Error(`[vxrn:compiler] babel returned no result for ${id}`));
196
+ }
197
+ res(result);
198
+ });
199
+ });
205
200
  }
206
- const getBasePlugins = ({
207
- development
208
- }) => [["@babel/plugin-transform-destructuring"], ["@babel/plugin-transform-react-jsx", {
209
- development
210
- }], ["@babel/plugin-transform-async-generator-functions"], ["@babel/plugin-transform-async-to-generator"], ["@babel/plugin-transform-runtime", {
211
- helpers: true,
212
- // NOTE THIS WAS SPELLED WRONG BEFOER THIS COMMIT MAYBE IT WAS UNINTENTIONALLY WORKING
213
- regenerator: false
214
- }]];
215
- const shouldBabelReactCompiler = props => {
216
- if (props.environment === "ssr") {
217
- return false;
218
- }
219
- if (!import_configure.configuration.enableCompiler) {
220
- return false;
221
- }
222
- const {
223
- enableCompiler
224
- } = import_configure.configuration;
225
- if (typeof enableCompiler === "object" && !Array.isArray(enableCompiler) && !(enableCompiler instanceof RegExp)) {
226
- const isNative = props.environment === "ios" || props.environment === "android";
227
- const filter = isNative ? enableCompiler.native : enableCompiler.web;
228
- if (!filter) return false;
229
- return applyCompilerFilter(filter, props);
230
- }
231
- if (typeof enableCompiler === "function") {
232
- return enableCompiler(props.id, props.environment);
233
- }
234
- if (enableCompiler instanceof RegExp) {
235
- return enableCompiler.test(props.id);
236
- }
237
- if (Array.isArray(enableCompiler)) {
238
- if (!enableCompiler.includes(props.environment)) {
239
- return false;
240
- }
241
- }
242
- return applyDefaultFilters(props);
201
+ async function stripFlowTypes(id, code, sourceMaps = true) {
202
+ const result = await transformBabel(id, code, { sourceMaps });
203
+ return {
204
+ code: result.code,
205
+ map: result.map
206
+ };
207
+ }
208
+ const getBasePlugins = ({ development }) => [
209
+ ["@babel/plugin-transform-destructuring"],
210
+ ["@babel/plugin-transform-react-jsx", { development }],
211
+ ["@babel/plugin-transform-async-generator-functions"],
212
+ ["@babel/plugin-transform-async-to-generator"],
213
+ ["@babel/plugin-transform-runtime", {
214
+ helpers: true,
215
+ regenerator: false
216
+ }]
217
+ ];
218
+ const shouldBabelReactCompiler = (props) => {
219
+ if (props.environment === "ssr") {
220
+ return false;
221
+ }
222
+ if (!import_configure.configuration.enableCompiler) {
223
+ return false;
224
+ }
225
+ const { enableCompiler } = import_configure.configuration;
226
+ if (typeof enableCompiler === "object" && !Array.isArray(enableCompiler) && !(enableCompiler instanceof RegExp)) {
227
+ const isNative = props.environment === "ios" || props.environment === "android";
228
+ const filter = isNative ? enableCompiler.native : enableCompiler.web;
229
+ if (!filter) return false;
230
+ return applyCompilerFilter(filter, props);
231
+ }
232
+ if (typeof enableCompiler === "function") {
233
+ return enableCompiler(props.id, props.environment);
234
+ }
235
+ if (enableCompiler instanceof RegExp) {
236
+ return enableCompiler.test(props.id);
237
+ }
238
+ if (Array.isArray(enableCompiler)) {
239
+ if (!enableCompiler.includes(props.environment)) {
240
+ return false;
241
+ }
242
+ }
243
+ return applyDefaultFilters(props);
243
244
  };
244
245
  function applyCompilerFilter(filter, props) {
245
- if (typeof filter === "function") {
246
- return filter(props.id, props.environment);
247
- }
248
- if (filter instanceof RegExp) {
249
- return filter.test(props.id);
250
- }
251
- if (filter === true) {
252
- return applyDefaultFilters(props);
253
- }
254
- return false;
246
+ if (typeof filter === "function") {
247
+ return filter(props.id, props.environment);
248
+ }
249
+ if (filter instanceof RegExp) {
250
+ return filter.test(props.id);
251
+ }
252
+ if (filter === true) {
253
+ return applyDefaultFilters(props);
254
+ }
255
+ return false;
255
256
  }
256
257
  function applyDefaultFilters(props) {
257
- if (!/(\.tsx?)$/.test(props.id)) return false;
258
- if (props.id.includes("node_modules")) return false;
259
- if (props.id.includes("+api.")) return false;
260
- if (props.code.startsWith("// disable-compiler")) return false;
261
- return true;
258
+ if (!/(\.tsx?)$/.test(props.id)) return false;
259
+ if (props.id.includes("node_modules")) return false;
260
+ if (props.id.includes("+api.")) return false;
261
+ if (props.code.startsWith("// disable-compiler")) return false;
262
+ return true;
262
263
  }
263
- const getBabelReactCompilerPlugin = props => {
264
- const target = props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19";
265
- return ["babel-plugin-react-compiler", {
266
- target
267
- }];
264
+ const getBabelReactCompilerPlugin = (props) => {
265
+ const target = props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19";
266
+ return ["babel-plugin-react-compiler", { target }];
268
267
  };
269
- function shouldBabelGenerators({
270
- code
271
- }) {
272
- if (process.env.VXRN_USE_BABEL_FOR_GENERATORS) {
273
- return import_constants.asyncGeneratorRegex.test(code);
274
- }
268
+ function shouldBabelGenerators({ code }) {
269
+ if (process.env.VXRN_USE_BABEL_FOR_GENERATORS) {
270
+ return import_constants.asyncGeneratorRegex.test(code);
271
+ }
275
272
  }
276
- const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = ["worklet", "useAnimatedGestureHandler", "useAnimatedScrollHandler", "useFrameCallback", "useAnimatedStyle", "useAnimatedProps", "createAnimatedPropAdapter", "useDerivedValue", "useAnimatedReaction", "useWorkletCallback", "withTiming", "withSpring", "withDecay", "withRepeat", "runOnUI", "executeOnUIRuntimeSync"];
273
+ const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = [
274
+ "worklet",
275
+ "useAnimatedGestureHandler",
276
+ "useAnimatedScrollHandler",
277
+ "useFrameCallback",
278
+ "useAnimatedStyle",
279
+ "useAnimatedProps",
280
+ "createAnimatedPropAdapter",
281
+ "useDerivedValue",
282
+ "useAnimatedReaction",
283
+ "useWorkletCallback",
284
+ "withTiming",
285
+ "withSpring",
286
+ "withDecay",
287
+ "withRepeat",
288
+ "runOnUI",
289
+ "executeOnUIRuntimeSync"
290
+ ];
277
291
  const REANIMATED_REGEX = new RegExp(REANIMATED_AUTOWORKLETIZATION_KEYWORDS.join("|"));
278
292
  const REANIMATED_IGNORED_PATHS = [
279
- // Prebuilt/vendored react-native that shouldn't be transformed
280
- "react-native-prebuilt", "node_modules/.vxrn/react-native",
281
- // Known false positives - they mention worklet keywords in comments/strings but don't use them
282
- "node_modules/react/", "node_modules/react-dom/", "node_modules/react-native/", "node_modules/react-native-web/"];
293
+ "react-native-prebuilt",
294
+ "node_modules/.vxrn/react-native",
295
+ "node_modules/react/",
296
+ "node_modules/react-dom/",
297
+ "node_modules/react-native/",
298
+ "node_modules/react-native-web/"
299
+ ];
283
300
  const REANIMATED_IGNORED_PATHS_REGEX = new RegExp(REANIMATED_IGNORED_PATHS.join("|"));
284
- function shouldBabelReanimated({
285
- code,
286
- id
287
- }) {
288
- if (!import_configure.configuration.enableReanimated) {
289
- return false;
290
- }
291
- if (REANIMATED_IGNORED_PATHS_REGEX.test(id)) {
292
- return false;
293
- }
294
- if (REANIMATED_REGEX.test(code)) {
295
- const location = id.includes("node_modules") ? "node_modules" : "user-code";
296
- (0, import_constants.debug)?.(` \u{1FA84} [reanimated/${location}] ${(0, import_node_path.relative)(process.cwd(), id)}`);
297
- return true;
298
- }
299
- return false;
300
- }
301
+ function shouldBabelReanimated({ code, id }) {
302
+ if (!import_configure.configuration.enableReanimated) {
303
+ return false;
304
+ }
305
+ if (REANIMATED_IGNORED_PATHS_REGEX.test(id)) {
306
+ return false;
307
+ }
308
+ if (REANIMATED_REGEX.test(code)) {
309
+ const location = id.includes("node_modules") ? "node_modules" : "user-code";
310
+ (0, import_constants.debug)?.(` \u{1FA84} [reanimated/${location}] ${(0, import_node_path.relative)(process.cwd(), id)}`);
311
+ return true;
312
+ }
313
+ return false;
314
+ }