@vxrn/compiler 1.25.5 → 1.25.7

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 (38) hide show
  1. package/dist/cjs/cache.cjs +132 -0
  2. package/dist/cjs/configure.cjs +37 -0
  3. package/dist/cjs/constants.cjs +77 -0
  4. package/dist/cjs/index.cjs +429 -0
  5. package/dist/cjs/refresh-runtime.cjs +452 -0
  6. package/dist/cjs/transformBabel.cjs +269 -0
  7. package/dist/cjs/transformBabel.test.cjs +88 -0
  8. package/dist/cjs/transformSWC.cjs +318 -0
  9. package/dist/cjs/types.cjs +18 -0
  10. package/dist/esm/cache.mjs +104 -0
  11. package/dist/esm/cache.mjs.map +1 -0
  12. package/dist/esm/configure.mjs +11 -0
  13. package/dist/esm/configure.mjs.map +1 -0
  14. package/dist/esm/constants.mjs +48 -0
  15. package/dist/esm/constants.mjs.map +1 -0
  16. package/dist/esm/index.js +402 -0
  17. package/dist/esm/index.js.map +1 -0
  18. package/dist/esm/index.mjs +402 -0
  19. package/dist/esm/index.mjs.map +1 -0
  20. package/dist/esm/refresh-runtime.mjs +421 -0
  21. package/dist/esm/refresh-runtime.mjs.map +1 -0
  22. package/dist/esm/transformBabel.mjs +231 -0
  23. package/dist/esm/transformBabel.mjs.map +1 -0
  24. package/dist/esm/transformBabel.test.mjs +65 -0
  25. package/dist/esm/transformBabel.test.mjs.map +1 -0
  26. package/dist/esm/transformSWC.mjs +292 -0
  27. package/dist/esm/transformSWC.mjs.map +1 -0
  28. package/dist/esm/types.mjs +2 -0
  29. package/dist/esm/types.mjs.map +1 -0
  30. package/package.json +3 -3
  31. package/types/cache.d.ts.map +1 -0
  32. package/types/configure.d.ts.map +1 -0
  33. package/types/constants.d.ts.map +1 -0
  34. package/types/index.d.ts.map +1 -0
  35. package/types/transformBabel.d.ts.map +1 -0
  36. package/types/transformBabel.test.d.ts.map +1 -0
  37. package/types/transformSWC.d.ts.map +1 -0
  38. package/types/types.d.ts.map +1 -0
@@ -0,0 +1,269 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
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;
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
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
34
+ var transformBabel_exports = {};
35
+ __export(transformBabel_exports, {
36
+ getBabelOptions: () => getBabelOptions,
37
+ transformBabel: () => transformBabel,
38
+ transformOxcReactCompiler: () => transformOxcReactCompiler
39
+ });
40
+ module.exports = __toCommonJS(transformBabel_exports);
41
+ var import_node_path = require("node:path");
42
+ var import_core = __toESM(require("@babel/core"), 1);
43
+ var import_utils = require("@vxrn/utils");
44
+ var import_babel_plugin_syntax_hermes_parser = __toESM(require("babel-plugin-syntax-hermes-parser"), 1);
45
+ var import_vite = require("vite");
46
+ var import_configure = require("./configure.cjs");
47
+ var import_constants = require("./constants.cjs");
48
+ function getBabelOptions(props) {
49
+ props = {
50
+ ...props,
51
+ id: (0, import_vite.normalizePath)(props.id.split("?")[0])
52
+ };
53
+ if (props.userSetting === "babel") {
54
+ return getOptions(props, true);
55
+ }
56
+ if (typeof props.userSetting === "undefined" || typeof props.userSetting === "object" && props.userSetting.transform === "babel") {
57
+ if (props.userSetting?.excludeDefaultPlugins) {
58
+ return props.userSetting;
59
+ }
60
+ return getOptions(props);
61
+ }
62
+ return null;
63
+ }
64
+ const getOptions = (props, force = false) => {
65
+ let plugins = [];
66
+ if (force || shouldBabelGenerators(props)) {
67
+ plugins = getBasePlugins(props);
68
+ }
69
+ const enableNativewind = import_configure.configuration.enableNativewind && (props.environment === "ios" || props.environment === "android") &&
70
+ // if reanimated gets wrapped in transform it causes circular dep issues
71
+ !/node_modules/.test(props.id) &&
72
+ // only needed for createElement calls, so be a bit conservative
73
+ props.code.includes("createElement");
74
+ if (enableNativewind) {
75
+ if (!props.id.includes("node_modules")) {
76
+ plugins.push((0, import_utils.resolvePath)("react-native-css-interop/dist/babel-plugin.js"));
77
+ }
78
+ }
79
+ if (enableNativewind || shouldBabelReanimated(props)) {
80
+ (0, import_constants.debug)?.(`Using babel worklets on file ${props.id}`);
81
+ plugins.push((0, import_utils.resolvePath)("react-native-worklets/plugin", props.projectRoot));
82
+ }
83
+ if (shouldBabelReactCompiler(props)) {
84
+ (0, import_constants.debug)?.(`Using babel react compiler on file`);
85
+ plugins.push(getBabelReactCompilerPlugin(props));
86
+ }
87
+ if (shouldBabelReactNativeCodegen(props)) {
88
+ (0, import_constants.debug)?.(`Using babel @react-native/babel-plugin-codegen on file`);
89
+ plugins.push("@react-native/babel-plugin-codegen");
90
+ }
91
+ if (plugins.length) {
92
+ return {
93
+ plugins
94
+ };
95
+ }
96
+ return null;
97
+ };
98
+ async function transformOxcReactCompiler(id, code, target) {
99
+ const {
100
+ transform
101
+ } = await import("oxc-transform-react");
102
+ const result = await transform(id, code, {
103
+ jsx: "preserve",
104
+ reactCompiler: {
105
+ target
106
+ }
107
+ });
108
+ if (result.fatal) {
109
+ throw new Error(`[vxrn:compiler] oxc react compiler failed on ${id}: ${(result.errors ?? []).map(e => e.message ?? String(e)).join(", ")}`);
110
+ }
111
+ if (result.errors?.length) {
112
+ (0, import_constants.debug)?.(`[compiler/bailout] ${id}: ${result.errors.map(e => e.message ?? String(e)).join(", ")}`);
113
+ }
114
+ return {
115
+ code: result.code,
116
+ map: void 0
117
+ };
118
+ }
119
+ async function transformBabel(id, code, options) {
120
+ const extension = (0, import_node_path.extname)(id);
121
+ const isTSX = extension === ".tsx";
122
+ const isTS = isTSX || extension === ".ts";
123
+ const babelOptions = {
124
+ filename: id,
125
+ compact: false,
126
+ babelrc: false,
127
+ configFile: false,
128
+ sourceMaps: false,
129
+ minified: false,
130
+ ...options,
131
+ presets: [isTS ? ["@babel/preset-typescript", {
132
+ isTSX,
133
+ allExtensions: isTSX
134
+ }] : "", ...(options.presets || [])].filter(Boolean),
135
+ // non-TS files use React Native's Flow dialect. RN's own component specs are
136
+ // Flow `.js` (`import type`, `codegenNativeComponent<T>(…)`, `(expr: Type)` casts).
137
+ // enable Hermes Flow parsing + stripping, mirroring the TypeScript preset above
138
+ // (`@react-native/babel-preset` uses the same parser for JS). without it babel
139
+ // can't parse current RN Flow syntax such as `call<T>(...) as HostComponent<T>`, so
140
+ // plugins like
141
+ // @react-native/babel-plugin-codegen silently fail on RN specs and the runtime
142
+ // "Codegen didn't run" warning fires. TS path is byte-identical (empty slice).
143
+ plugins: [...(isTS ? [] : [[import_babel_plugin_syntax_hermes_parser.default, {
144
+ parseLangTypes: "flow",
145
+ reactRuntimeTarget: "19"
146
+ }]]), ...(options.plugins || []), ...(isTS ? [] : ["@babel/plugin-transform-flow-strip-types"])]
147
+ };
148
+ try {
149
+ const out = await new Promise((res, rej) => {
150
+ import_core.default.transform(code, babelOptions, (err, result) => {
151
+ if (!result || err) {
152
+ return rej(err || "no res");
153
+ }
154
+ res(result);
155
+ });
156
+ });
157
+ return out;
158
+ } catch (err) {
159
+ if (err?.message?.includes("Could not find component config")) {
160
+ return;
161
+ }
162
+ console.error(`[vxrn:compiler] babel transform error`, err, `with options`, babelOptions);
163
+ console.error("code", code);
164
+ console.error("id", id);
165
+ }
166
+ }
167
+ const getBasePlugins = ({
168
+ development
169
+ }) => [["@babel/plugin-transform-destructuring"], ["@babel/plugin-transform-react-jsx", {
170
+ development
171
+ }], ["@babel/plugin-transform-async-generator-functions"], ["@babel/plugin-transform-async-to-generator"], ["@babel/plugin-transform-runtime", {
172
+ helpers: true,
173
+ // NOTE THIS WAS SPELLED WRONG BEFOER THIS COMMIT MAYBE IT WAS UNINTENTIONALLY WORKING
174
+ regenerator: false
175
+ }]];
176
+ const NATIVE_COMPONENT_RE = /NativeComponent\.[jt]sx?$/;
177
+ const SPEC_FILE_RE = /[/\\]specs?[/\\]/;
178
+ const shouldBabelReactNativeCodegen = ({
179
+ id,
180
+ environment
181
+ }) => {
182
+ return (environment === "ios" || environment === "android") && (NATIVE_COMPONENT_RE.test(id) || SPEC_FILE_RE.test(id));
183
+ };
184
+ const shouldBabelReactCompiler = props => {
185
+ if (props.environment === "ssr") {
186
+ return false;
187
+ }
188
+ if (!import_configure.configuration.enableCompiler) {
189
+ return false;
190
+ }
191
+ const {
192
+ enableCompiler
193
+ } = import_configure.configuration;
194
+ if (typeof enableCompiler === "object" && !Array.isArray(enableCompiler) && !(enableCompiler instanceof RegExp)) {
195
+ const isNative = props.environment === "ios" || props.environment === "android";
196
+ const filter = isNative ? enableCompiler.native : enableCompiler.web;
197
+ if (!filter) return false;
198
+ return applyCompilerFilter(filter, props);
199
+ }
200
+ if (typeof enableCompiler === "function") {
201
+ return enableCompiler(props.id, props.environment);
202
+ }
203
+ if (enableCompiler instanceof RegExp) {
204
+ return enableCompiler.test(props.id);
205
+ }
206
+ if (Array.isArray(enableCompiler)) {
207
+ if (!enableCompiler.includes(props.environment)) {
208
+ return false;
209
+ }
210
+ }
211
+ return applyDefaultFilters(props);
212
+ };
213
+ function applyCompilerFilter(filter, props) {
214
+ if (typeof filter === "function") {
215
+ return filter(props.id, props.environment);
216
+ }
217
+ if (filter instanceof RegExp) {
218
+ return filter.test(props.id);
219
+ }
220
+ if (filter === true) {
221
+ return applyDefaultFilters(props);
222
+ }
223
+ return false;
224
+ }
225
+ function applyDefaultFilters(props) {
226
+ if (!/(\.tsx?)$/.test(props.id)) return false;
227
+ if (props.id.includes("node_modules")) return false;
228
+ if (props.id.includes("+api.")) return false;
229
+ if (props.code.startsWith("// disable-compiler")) return false;
230
+ return true;
231
+ }
232
+ const getBabelReactCompilerPlugin = props => {
233
+ const target = props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19";
234
+ return ["babel-plugin-react-compiler", {
235
+ target
236
+ }];
237
+ };
238
+ function shouldBabelGenerators({
239
+ code
240
+ }) {
241
+ if (process.env.VXRN_USE_BABEL_FOR_GENERATORS) {
242
+ return import_constants.asyncGeneratorRegex.test(code);
243
+ }
244
+ }
245
+ const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = ["worklet", "useAnimatedGestureHandler", "useAnimatedScrollHandler", "useFrameCallback", "useAnimatedStyle", "useAnimatedProps", "createAnimatedPropAdapter", "useDerivedValue", "useAnimatedReaction", "useWorkletCallback", "withTiming", "withSpring", "withDecay", "withRepeat", "runOnUI", "executeOnUIRuntimeSync"];
246
+ const REANIMATED_REGEX = new RegExp(REANIMATED_AUTOWORKLETIZATION_KEYWORDS.join("|"));
247
+ const REANIMATED_IGNORED_PATHS = [
248
+ // Prebuilt/vendored react-native that shouldn't be transformed
249
+ "react-native-prebuilt", "node_modules/.vxrn/react-native",
250
+ // Known false positives - they mention worklet keywords in comments/strings but don't use them
251
+ "node_modules/react/", "node_modules/react-dom/", "node_modules/react-native/", "node_modules/react-native-web/"];
252
+ const REANIMATED_IGNORED_PATHS_REGEX = new RegExp(REANIMATED_IGNORED_PATHS.join("|"));
253
+ function shouldBabelReanimated({
254
+ code,
255
+ id
256
+ }) {
257
+ if (!import_configure.configuration.enableReanimated) {
258
+ return false;
259
+ }
260
+ if (REANIMATED_IGNORED_PATHS_REGEX.test(id)) {
261
+ return false;
262
+ }
263
+ if (REANIMATED_REGEX.test(code)) {
264
+ const location = id.includes("node_modules") ? "node_modules" : "user-code";
265
+ (0, import_constants.debug)?.(` \u{1FA84} [reanimated/${location}] ${(0, import_node_path.relative)(process.cwd(), id)}`);
266
+ return true;
267
+ }
268
+ return false;
269
+ }
@@ -0,0 +1,88 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
10
+ get: () => from[key],
11
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
12
+ });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
+ value: mod,
23
+ enumerable: true
24
+ }) : target, mod));
25
+ var import_node_fs = __toESM(require("node:fs"), 1);
26
+ var import_node_os = __toESM(require("node:os"), 1);
27
+ var import_node_path = __toESM(require("node:path"), 1);
28
+ var import_vitest = require("vitest");
29
+ var import_configure = require("./configure.cjs");
30
+ var import_transformBabel = require("./transformBabel.cjs");
31
+ (0, import_vitest.afterEach)(() => {
32
+ (0, import_configure.configureVXRNCompilerPlugin)({
33
+ enableReanimated: false
34
+ });
35
+ });
36
+ (0, import_vitest.describe)("getBabelOptions Worklets resolution", () => {
37
+ (0, import_vitest.it)("uses the app-installed Worklets Babel plugin", () => {
38
+ const projectRoot = import_node_fs.default.realpathSync(import_node_fs.default.mkdtempSync(import_node_path.default.join(import_node_os.default.tmpdir(), "vxrn-worklets-")));
39
+ const packageRoot = import_node_path.default.join(projectRoot, "node_modules", "react-native-worklets");
40
+ const pluginPath = import_node_path.default.join(packageRoot, "plugin.js");
41
+ import_node_fs.default.mkdirSync(packageRoot, {
42
+ recursive: true
43
+ });
44
+ import_node_fs.default.writeFileSync(import_node_path.default.join(packageRoot, "package.json"), JSON.stringify({
45
+ name: "react-native-worklets",
46
+ version: "99.0.0"
47
+ }));
48
+ import_node_fs.default.writeFileSync(pluginPath, "module.exports = () => ({ visitor: {} })");
49
+ try {
50
+ (0, import_configure.configureVXRNCompilerPlugin)({
51
+ enableReanimated: true
52
+ });
53
+ const options = (0, import_transformBabel.getBabelOptions)({
54
+ id: import_node_path.default.join(projectRoot, "input.ts"),
55
+ code: `export const worklet = () => {
56
+ 'worklet'
57
+ }`,
58
+ development: true,
59
+ environment: "ios",
60
+ reactForRNVersion: "19",
61
+ projectRoot
62
+ });
63
+ (0, import_vitest.expect)(options?.plugins).toContain(pluginPath);
64
+ } finally {
65
+ import_node_fs.default.rmSync(projectRoot, {
66
+ recursive: true,
67
+ force: true
68
+ });
69
+ }
70
+ });
71
+ });
72
+ (0, import_vitest.describe)("transformBabel Flow parsing", () => {
73
+ (0, import_vitest.it)("parses and strips React Native Flow as-casts", async () => {
74
+ const result = await (0, import_transformBabel.transformBabel)("/project/VirtualViewNativeComponent.js", `
75
+ // @flow strict-local
76
+ import type { HostComponent } from './HostComponent'
77
+ import codegenNativeComponent from './codegenNativeComponent'
78
+
79
+ type Props = $ReadOnly<{ enabled?: boolean }>
80
+
81
+ export default codegenNativeComponent<Props>('VirtualView') as HostComponent<Props>
82
+ `, {
83
+ plugins: []
84
+ });
85
+ (0, import_vitest.expect)(result?.code).toContain("codegenNativeComponent('VirtualView')");
86
+ (0, import_vitest.expect)(result?.code).not.toContain("HostComponent");
87
+ });
88
+ });
@@ -0,0 +1,318 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var transformSWC_exports = {};
24
+ __export(transformSWC_exports, {
25
+ transformSWC: () => transformSWC,
26
+ transformSWCStripJSX: () => transformSWCStripJSX
27
+ });
28
+ module.exports = __toCommonJS(transformSWC_exports);
29
+ var import_node_path = require("node:path");
30
+ var import_core = require("@swc/core");
31
+ var import_ts_deepmerge = require("ts-deepmerge");
32
+ var import_vite = require("vite");
33
+ var import_configure = require("./configure.cjs");
34
+ var import_constants = require("./constants.cjs");
35
+ const ignoreId = /node_modules\/(\.vite|vite)\//;
36
+ async function transformSWC(id, code, options, swcOptions) {
37
+ id = (0, import_vite.normalizePath)(id.split("?")[0]).replace((0, import_vite.normalizePath)(process.cwd()), "");
38
+ if (ignoreId.test(id)) {
39
+ return;
40
+ }
41
+ if (id === import_constants.runtimePublicPath) {
42
+ return;
43
+ }
44
+ const parser = getParser(id, options.forceJSX);
45
+ if (!parser) {
46
+ return;
47
+ }
48
+ const refresh = options.environment !== "ssr" && !options.production && !options.noHMR && !options.forceJSX && !id.includes("node_modules");
49
+ const reactConfig = {
50
+ refresh,
51
+ development: !options.forceJSX && !options.production,
52
+ runtime: "automatic",
53
+ importSource: "react",
54
+ ...(import_configure.configuration.enableNativewind && !id.includes("node_modules") ? {
55
+ importSource: "nativewind"
56
+ // pragma: 'createInteropElement',
57
+ // pragmaFrag: '_InteropFragment',
58
+ // swc doesnt actually change the import right
59
+ // runtime: 'classic',
60
+ } : {})
61
+ };
62
+ const transformOptions = (() => {
63
+ if (options.environment === "client" || options.environment === "ssr") {
64
+ return {
65
+ sourceMaps: shouldSourceMap(),
66
+ jsc: {
67
+ target: "es2020",
68
+ parser,
69
+ transform: {
70
+ useDefineForClassFields: true,
71
+ react: reactConfig
72
+ }
73
+ }
74
+ };
75
+ }
76
+ const shouldEs5Transform = options.es5 || !process.env.VXRN_USE_BABEL_FOR_GENERATORS && import_constants.asyncGeneratorRegex.test(code);
77
+ const opts = shouldEs5Transform ? {
78
+ jsc: {
79
+ parser,
80
+ target: "es5",
81
+ transform: {
82
+ useDefineForClassFields: true,
83
+ react: reactConfig
84
+ }
85
+ }
86
+ } : {
87
+ ...(!options.forceJSX && {
88
+ env: SWC_ENV
89
+ }),
90
+ jsc: {
91
+ ...(options.forceJSX && {
92
+ target: "esnext"
93
+ }),
94
+ parser,
95
+ transform: {
96
+ useDefineForClassFields: true,
97
+ react: reactConfig
98
+ }
99
+ }
100
+ };
101
+ return {
102
+ sourceMaps: shouldSourceMap(),
103
+ module: {
104
+ importInterop: "none",
105
+ type: "nodenext"
106
+ },
107
+ ...(options.mode === "serve-cjs" && {
108
+ module: {
109
+ importInterop: "none",
110
+ type: "commonjs",
111
+ strict: true
112
+ }
113
+ }),
114
+ ...opts
115
+ };
116
+ })();
117
+ const finalOptions = (0, import_ts_deepmerge.merge)({
118
+ filename: id,
119
+ swcrc: false,
120
+ configFile: false,
121
+ ...transformOptions
122
+ }, swcOptions || {});
123
+ const result = await (async () => {
124
+ try {
125
+ (0, import_constants.debug)?.(`transformSWC ${id} using options:
126
+ ${JSON.stringify(finalOptions, null, 2)}`);
127
+ return await (0, import_core.transform)(code, finalOptions);
128
+ } catch (e) {
129
+ const message = e.message;
130
+ const fileStartIndex = message.indexOf("\u256D\u2500[");
131
+ if (fileStartIndex !== -1) {
132
+ const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)]/);
133
+ if (match) {
134
+ e.line = match[1];
135
+ e.column = match[2];
136
+ }
137
+ }
138
+ throw e;
139
+ }
140
+ })();
141
+ if (import_configure.configuration.enableNativeCSS) {
142
+ if (result.code.includes(`createInteropElement(`)) {
143
+ result.code = `import { createInteropElement, Fragment as _InteropFragment } from 'react-native-css-interop/jsx-dev-runtime'
144
+ ${result.code}`;
145
+ }
146
+ }
147
+ const hasRefreshRuntime = refresh && refreshContentRE.test(result.code);
148
+ if (options.fixNonTypeSpecificImports || id.includes("node_modules") && parser.syntax === "typescript") {
149
+ const typeExportsMatch = code.match(/^\s*export\s+type\s+([^\s]+)/gi);
150
+ if (typeExportsMatch) {
151
+ for (const typeExport of Array.from(typeExportsMatch)) {
152
+ const [_export, _type, name] = typeExport.split(/\s+/);
153
+ if (name.startsWith("{")) continue;
154
+ if (name.includes("<")) continue;
155
+ const alreadyExported = new RegExp(`export (const|let|class|function) ${name}\\s+`).test(result.code);
156
+ if (!alreadyExported) {
157
+ const fakeExport = `export let ${name} = {};`;
158
+ console.info(` \u26A0\uFE0F Fixing non-type-specific import in node_module, this should be fixed upstream: ${fakeExport} in ${id}`);
159
+ result.code += `
160
+ ${fakeExport}
161
+ `;
162
+ }
163
+ }
164
+ }
165
+ }
166
+ if (result && !options.production && !options.noHMR) {
167
+ return wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime);
168
+ }
169
+ return result;
170
+ }
171
+ function wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime) {
172
+ if (options.environment === "ssr") {
173
+ return result;
174
+ }
175
+ if (options.environment === "client") {
176
+ return wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime);
177
+ }
178
+ return wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime);
179
+ }
180
+ function wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime) {
181
+ const sourceMap = result.map ? JSON.parse(result.map) : void 0;
182
+ if (sourceMap) {
183
+ sourceMap.mappings = ";;" + sourceMap.mappings;
184
+ }
185
+ result.code = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
186
+
187
+ ${result.code}`;
188
+ if (hasRefreshRuntime) {
189
+ if (sourceMap) {
190
+ sourceMap.mappings = ";;;;;;" + sourceMap.mappings;
191
+ }
192
+ result.code = `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
193
+ const prevRefreshReg = window.$RefreshReg$;
194
+ const prevRefreshSig = window.$RefreshSig$;
195
+ window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
196
+ window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
197
+
198
+ ${result.code}
199
+
200
+ window.$RefreshReg$ = prevRefreshReg;
201
+ window.$RefreshSig$ = prevRefreshSig;
202
+ `;
203
+ }
204
+ result.code += `
205
+ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
206
+ RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
207
+ import.meta.hot.accept((nextExports) => {
208
+ if (!nextExports) return;
209
+ const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate("${id}", currentExports, nextExports);
210
+ if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
211
+ });
212
+ });
213
+ `;
214
+ return {
215
+ code: result.code,
216
+ map: sourceMap
217
+ };
218
+ }
219
+ function wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime) {
220
+ const postfixCode = `if (module.hot) {
221
+ if (module.hot.accept) {
222
+ module.hot.accept((nextExports) => {
223
+ RefreshRuntime.performReactRefresh()
224
+ });
225
+ }
226
+ }`;
227
+ if (hasRefreshRuntime) {
228
+ const prefixCode = `const RefreshRuntime = __cachedModules["react-refresh/cjs/react-refresh-runtime.development"];
229
+ const prevRefreshReg = globalThis.$RefreshReg$;
230
+ const prevRefreshSig = globalThis.$RefreshSig$ || (() => {
231
+ console.info("no react refresh setup!")
232
+ return (x) => x
233
+ });
234
+ globalThis.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, "${id}" + " " + id);
235
+ globalThis.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
236
+ module.url = '${id}'
237
+ module.hot = createHotContext(module.url)`;
238
+ const sourceMap = result.map ? JSON.parse(result.map) : void 0;
239
+ if (sourceMap) {
240
+ const prefixLen = prefixCode.split("\n").length + 1;
241
+ sourceMap.mappings = new Array(prefixLen).fill(";").join("") + sourceMap.mappings;
242
+ }
243
+ return {
244
+ code: `${prefixCode}
245
+ ${result.code}
246
+
247
+ if (module.hot) {
248
+ globalThis.$RefreshReg$ = prevRefreshReg;
249
+ globalThis.$RefreshSig$ = prevRefreshSig;
250
+ globalThis['lastHmrExports'] = JSON.stringify(Object.keys(exports))
251
+ }
252
+
253
+ ${postfixCode}
254
+ `,
255
+ map: sourceMap
256
+ };
257
+ }
258
+ result.code += postfixCode;
259
+ return result;
260
+ }
261
+ const SWC_ENV = {
262
+ targets: {
263
+ node: "4"
264
+ },
265
+ // debug: true,
266
+ include: [],
267
+ // this breaks the uniswap app for any file with a ...spread
268
+ exclude: ["transform-spread", "transform-destructuring", "transform-object-rest-spread",
269
+ // `transform-async-to-generator` is relying on `transform-destructuring`.
270
+ // If we exclude `transform-destructuring` but not `transform-async-to-generator`, the SWC binary will panic
271
+ // with error: `called `Option::unwrap()` on a `None` value`.
272
+ // See: https://github.com/swc-project/swc/blob/v1.7.14/crates/swc_ecma_compat_es2015/src/generator.rs#L703-L705
273
+ "transform-async-to-generator", "transform-regenerator"
274
+ // Similar to above
275
+ ]
276
+ };
277
+ const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
278
+ function shouldSourceMap() {
279
+ return process.env.VXRN_ENABLE_SOURCE_MAP === "1";
280
+ }
281
+ function getParser(id, forceJSX = false) {
282
+ if (id.endsWith("one-entry-native")) {
283
+ return import_constants.parsers[".tsx"];
284
+ }
285
+ const extension = (0, import_node_path.extname)(id);
286
+ let parser = !extension ? import_constants.parsers[".js"] : import_constants.parsers[extension];
287
+ if (extension === ".js" || extension === ".mjs") {
288
+ if (forceJSX) {
289
+ parser = import_constants.parsers[".jsx"];
290
+ }
291
+ if (id.includes("expo-modules-core")) {
292
+ parser = import_constants.parsers[".jsx"];
293
+ }
294
+ }
295
+ return parser;
296
+ }
297
+ const transformSWCStripJSX = async (id, code) => {
298
+ const parser = getParser(id);
299
+ if (!parser) return;
300
+ return await (0, import_core.transform)(code, {
301
+ filename: id,
302
+ swcrc: false,
303
+ configFile: false,
304
+ sourceMaps: shouldSourceMap(),
305
+ jsc: {
306
+ target: "es2019",
307
+ parser,
308
+ transform: {
309
+ useDefineForClassFields: true,
310
+ react: {
311
+ development: true,
312
+ runtime: "automatic",
313
+ refresh: false
314
+ }
315
+ }
316
+ }
317
+ });
318
+ };
@@ -0,0 +1,18 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
8
+ get: () => from[key],
9
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
10
+ });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
15
+ value: true
16
+ }), mod);
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);