@vxrn/compiler 1.12.3 → 1.12.4

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.
@@ -1,246 +0,0 @@
1
- import { extname, sep } from "node:path";
2
- import {
3
- transform
4
- } from "@swc/core";
5
- import { merge } from "ts-deepmerge";
6
- import { configuration } from "./configure";
7
- import { asyncGeneratorRegex, debug, parsers, runtimePublicPath } from "./constants";
8
- const ignoreId = new RegExp(`node_modules\\${sep}(\\.vite|vite)\\${sep}`);
9
- async function transformSWC(id, code, options, swcOptions) {
10
- if (ignoreId.test(id) || (id = id.split("?")[0].replace(process.cwd(), ""), id === runtimePublicPath))
11
- return;
12
- const parser = getParser(id, options.forceJSX);
13
- if (!parser)
14
- return;
15
- const refresh = options.environment !== "ssr" && !options.production && !options.noHMR && !options.forceJSX && !id.includes("node_modules"), reactConfig = {
16
- refresh,
17
- development: !options.forceJSX && !options.production,
18
- runtime: "automatic",
19
- importSource: "react",
20
- ...configuration.enableNativewind && !id.includes("node_modules") ? {
21
- importSource: "nativewind"
22
- // pragma: 'createInteropElement',
23
- // pragmaFrag: '_InteropFragment',
24
- // swc doesnt actually change the import right
25
- // runtime: 'classic',
26
- } : {}
27
- }, transformOptions = (() => {
28
- if (options.environment === "client" || options.environment === "ssr")
29
- return {
30
- sourceMaps: shouldSourceMap(),
31
- jsc: {
32
- target: "es2020",
33
- parser,
34
- transform: {
35
- useDefineForClassFields: !0,
36
- react: reactConfig
37
- }
38
- }
39
- };
40
- const opts = options.es5 || !process.env.VXRN_USE_BABEL_FOR_GENERATORS && asyncGeneratorRegex.test(code) ? {
41
- jsc: {
42
- parser,
43
- target: "es5",
44
- transform: {
45
- useDefineForClassFields: !0,
46
- react: reactConfig
47
- }
48
- }
49
- } : {
50
- ...!options.forceJSX && { env: SWC_ENV },
51
- jsc: {
52
- ...options.forceJSX && { target: "esnext" },
53
- parser,
54
- transform: {
55
- useDefineForClassFields: !0,
56
- react: reactConfig
57
- }
58
- }
59
- };
60
- return {
61
- sourceMaps: shouldSourceMap(),
62
- module: {
63
- importInterop: "none",
64
- type: "nodenext"
65
- },
66
- ...options.mode === "serve-cjs" && {
67
- module: {
68
- importInterop: "none",
69
- type: "commonjs",
70
- strict: !0
71
- }
72
- },
73
- ...opts
74
- };
75
- })(), finalOptions = merge(
76
- {
77
- filename: id,
78
- swcrc: !1,
79
- configFile: !1,
80
- ...transformOptions
81
- },
82
- swcOptions || {}
83
- ), result = await (async () => {
84
- try {
85
- return debug?.(
86
- `transformSWC ${id} using options:
87
- ${JSON.stringify(finalOptions, null, 2)}`
88
- ), await transform(code, finalOptions);
89
- } catch (e) {
90
- const message = e.message, fileStartIndex = message.indexOf("\u256D\u2500[");
91
- if (fileStartIndex !== -1) {
92
- const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)]/);
93
- match && (e.line = match[1], e.column = match[2]);
94
- }
95
- throw e;
96
- }
97
- })();
98
- configuration.enableNativeCSS && result.code.includes("createInteropElement(") && (result.code = `import { createInteropElement, Fragment as _InteropFragment } from 'react-native-css-interop/jsx-dev-runtime'
99
- ${result.code}`);
100
- const hasRefreshRuntime = refresh && refreshContentRE.test(result.code);
101
- if (options.fixNonTypeSpecificImports || id.includes("node_modules") && parser.syntax === "typescript") {
102
- const typeExportsMatch = code.match(/^\s*export\s+type\s+([^\s]+)/gi);
103
- if (typeExportsMatch)
104
- for (const typeExport of Array.from(typeExportsMatch)) {
105
- const [_export, _type, name] = typeExport.split(/\s+/);
106
- if (name.startsWith("{") || name.includes("<")) continue;
107
- if (!new RegExp(
108
- `export (const|let|class|function) ${name}\\s+`
109
- ).test(result.code)) {
110
- const fakeExport = `export let ${name} = {};`;
111
- console.info(
112
- ` \u26A0\uFE0F Fixing non-type-specific import in node_module, this should be fixed upstream: ${fakeExport} in ${id}`
113
- ), result.code += `
114
- ${fakeExport}
115
- `;
116
- }
117
- }
118
- }
119
- return result && !options.production && !options.noHMR ? wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime) : result;
120
- }
121
- function wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime) {
122
- return options.environment === "ssr" ? result : options.environment === "client" ? wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime) : wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime);
123
- }
124
- function wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime) {
125
- const sourceMap = result.map ? JSON.parse(result.map) : void 0;
126
- return sourceMap && (sourceMap.mappings = ";;" + sourceMap.mappings), result.code = `import * as RefreshRuntime from "${runtimePublicPath}";
127
-
128
- ${result.code}`, hasRefreshRuntime && (sourceMap && (sourceMap.mappings = ";;;;;;" + sourceMap.mappings), result.code = `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
129
- const prevRefreshReg = window.$RefreshReg$;
130
- const prevRefreshSig = window.$RefreshSig$;
131
- window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
132
- window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
133
-
134
- ${result.code}
135
-
136
- window.$RefreshReg$ = prevRefreshReg;
137
- window.$RefreshSig$ = prevRefreshSig;
138
- `), result.code += `
139
- RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
140
- RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
141
- import.meta.hot.accept((nextExports) => {
142
- if (!nextExports) return;
143
- const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate("${id}", currentExports, nextExports);
144
- if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
145
- });
146
- });
147
- `, { code: result.code, map: sourceMap };
148
- }
149
- function wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime) {
150
- const postfixCode = `if (module.hot) {
151
- if (module.hot.accept) {
152
- module.hot.accept((nextExports) => {
153
- RefreshRuntime.performReactRefresh()
154
- });
155
- }
156
- }`;
157
- if (hasRefreshRuntime) {
158
- const prefixCode = `const RefreshRuntime = __cachedModules["react-refresh/cjs/react-refresh-runtime.development"];
159
- const prevRefreshReg = globalThis.$RefreshReg$;
160
- const prevRefreshSig = globalThis.$RefreshSig$ || (() => {
161
- console.info("no react refresh setup!")
162
- return (x) => x
163
- });
164
- globalThis.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, "${id}" + " " + id);
165
- globalThis.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
166
- module.url = '${id}'
167
- module.hot = createHotContext(module.url)`, sourceMap = result.map ? JSON.parse(result.map) : void 0;
168
- if (sourceMap) {
169
- const prefixLen = prefixCode.split(`
170
- `).length + 1;
171
- sourceMap.mappings = new Array(prefixLen).fill(";").join("") + sourceMap.mappings;
172
- }
173
- return {
174
- code: `${prefixCode}
175
- ${result.code}
176
-
177
- if (module.hot) {
178
- globalThis.$RefreshReg$ = prevRefreshReg;
179
- globalThis.$RefreshSig$ = prevRefreshSig;
180
- globalThis['lastHmrExports'] = JSON.stringify(Object.keys(exports))
181
- }
182
-
183
- ${postfixCode}
184
- `,
185
- map: sourceMap
186
- };
187
- }
188
- return result.code += postfixCode, result;
189
- }
190
- const SWC_ENV = {
191
- targets: {
192
- node: "4"
193
- },
194
- // debug: true,
195
- include: [],
196
- // this breaks the uniswap app for any file with a ...spread
197
- exclude: [
198
- "transform-spread",
199
- "transform-destructuring",
200
- "transform-object-rest-spread",
201
- // `transform-async-to-generator` is relying on `transform-destructuring`.
202
- // If we exclude `transform-destructuring` but not `transform-async-to-generator`, the SWC binary will panic
203
- // with error: `called `Option::unwrap()` on a `None` value`.
204
- // See: https://github.com/swc-project/swc/blob/v1.7.14/crates/swc_ecma_compat_es2015/src/generator.rs#L703-L705
205
- "transform-async-to-generator",
206
- "transform-regenerator"
207
- // Similar to above
208
- ]
209
- }, refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
210
- function shouldSourceMap() {
211
- return process.env.VXRN_ENABLE_SOURCE_MAP === "1";
212
- }
213
- function getParser(id, forceJSX = !1) {
214
- if (id.endsWith("one-entry-native"))
215
- return parsers[".tsx"];
216
- const extension = extname(id);
217
- let parser = extension ? parsers[extension] : parsers[".js"];
218
- return (extension === ".js" || extension === ".mjs") && (forceJSX && (parser = parsers[".jsx"]), id.includes("expo-modules-core") && (parser = parsers[".jsx"])), parser;
219
- }
220
- const transformSWCStripJSX = async (id, code) => {
221
- const parser = getParser(id);
222
- if (parser)
223
- return await transform(code, {
224
- filename: id,
225
- swcrc: !1,
226
- configFile: !1,
227
- sourceMaps: shouldSourceMap(),
228
- jsc: {
229
- target: "es2019",
230
- parser,
231
- transform: {
232
- useDefineForClassFields: !0,
233
- react: {
234
- development: !0,
235
- runtime: "automatic",
236
- refresh: !1
237
- }
238
- }
239
- }
240
- });
241
- };
242
- export {
243
- transformSWC,
244
- transformSWCStripJSX
245
- };
246
- //# sourceMappingURL=transformSWC.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/transformSWC.ts"],
4
- "mappings": "AAAA,SAAS,SAAS,WAAW;AAC7B;AAAA,EAKE;AAAA,OACK;AACP,SAAS,aAAa;AACtB,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB,OAAO,SAAS,yBAAyB;AAGvE,MAAM,WAAW,IAAI,OAAO,iBAAiB,GAAG,mBAAmB,GAAG,EAAE;AAExE,eAAsB,aACpB,IACA,MACA,SACA,YACA;AAUA,MATI,SAAS,KAAK,EAAE,MAIpB,KAAK,GACF,MAAM,GAAG,EAAE,CAAC,EAEZ,QAAQ,QAAQ,IAAI,GAAG,EAAE,GAExB,OAAO;AACT;AAGF,QAAM,SAAS,UAAU,IAAI,QAAQ,QAAQ;AAE7C,MAAI,CAAC;AACH;AAGF,QAAM,UACJ,QAAQ,gBAAgB,SACxB,CAAC,QAAQ,cACT,CAAC,QAAQ,SACT,CAAC,QAAQ,YACT,CAAC,GAAG,SAAS,cAAc,GAEvB,cAAc;AAAA,IAClB;AAAA,IACA,aAAa,CAAC,QAAQ,YAAY,C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ED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "mappings": "",
5
- "names": []
6
- }