@vxrn/compiler 2.0.0-beta.33.1 → 2.0.0-beta.45.1
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.
- package/dist/cjs/cache.cjs +112 -109
- package/dist/cjs/configure.cjs +26 -28
- package/dist/cjs/constants.cjs +56 -60
- package/dist/cjs/index.cjs +420 -438
- package/dist/cjs/reactNativeCodegen.cjs +105 -114
- package/dist/cjs/reactNativeViewConfig.cjs +362 -381
- package/dist/cjs/refresh-runtime.cjs +390 -397
- package/dist/cjs/transformBabel.cjs +278 -218
- package/dist/cjs/transformHermesAsync.cjs +36 -47
- package/dist/cjs/transformHermesLoops.cjs +279 -281
- package/dist/cjs/transformSWC.cjs +183 -200
- package/dist/cjs/transformWorklets.cjs +107 -95
- package/dist/cjs/types.cjs +9 -11
- package/dist/cjs/worklets/autoworklet.cjs +277 -222
- package/dist/cjs/worklets/globals.cjs +124 -60
- package/dist/cjs/worklets/hash.cjs +23 -27
- package/dist/cjs/worklets/scope.cjs +338 -359
- package/dist/cjs/worklets/serialize.cjs +73 -75
- package/dist/cjs/worklets/transform.cjs +217 -222
- package/dist/cjs/worklets/types.cjs +9 -11
- package/dist/esm/cache.mjs +96 -89
- package/dist/esm/cache.mjs.map +1 -1
- package/dist/esm/configure.mjs +11 -10
- package/dist/esm/configure.mjs.map +1 -1
- package/dist/esm/constants.mjs +41 -41
- package/dist/esm/constants.mjs.map +1 -1
- package/dist/esm/index.js +417 -420
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +417 -420
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/reactNativeCodegen.mjs +90 -88
- package/dist/esm/reactNativeCodegen.mjs.map +1 -1
- package/dist/esm/reactNativeViewConfig.mjs +347 -362
- package/dist/esm/reactNativeViewConfig.mjs.map +1 -1
- package/dist/esm/refresh-runtime.mjs +372 -376
- package/dist/esm/refresh-runtime.mjs.map +1 -1
- package/dist/esm/transformBabel.mjs +261 -194
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/dist/esm/transformHermesAsync.mjs +20 -21
- package/dist/esm/transformHermesAsync.mjs.map +1 -1
- package/dist/esm/transformHermesLoops.mjs +264 -255
- package/dist/esm/transformHermesLoops.mjs.map +1 -1
- package/dist/esm/transformSWC.mjs +163 -171
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/dist/esm/transformWorklets.mjs +89 -69
- package/dist/esm/transformWorklets.mjs.map +1 -1
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/worklets/autoworklet.mjs +258 -200
- package/dist/esm/worklets/autoworklet.mjs.map +1 -1
- package/dist/esm/worklets/globals.mjs +109 -42
- package/dist/esm/worklets/globals.mjs.map +1 -1
- package/dist/esm/worklets/hash.mjs +10 -9
- package/dist/esm/worklets/hash.mjs.map +1 -1
- package/dist/esm/worklets/scope.mjs +325 -341
- package/dist/esm/worklets/scope.mjs.map +1 -1
- package/dist/esm/worklets/serialize.mjs +60 -58
- package/dist/esm/worklets/serialize.mjs.map +1 -1
- package/dist/esm/worklets/transform.mjs +201 -197
- package/dist/esm/worklets/transform.mjs.map +1 -1
- package/dist/esm/worklets/types.mjs +0 -2
- package/package.json +7 -6
- package/src/cache.ts +37 -7
- package/src/index.ts +33 -18
- package/src/transformBabel.test.ts +311 -1
- package/src/transformBabel.ts +110 -13
- package/types/cache.d.ts +2 -2
- package/types/cache.d.ts.map +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/transformBabel.d.ts +16 -1
- package/types/transformBabel.d.ts.map +1 -1
- package/types/transformSWC.d.ts +1 -4
- package/types/transformSWC.d.ts.map +1 -1
- package/dist/cjs/transformBabel.test.cjs +0 -360
- package/dist/cjs/transformHermesLoops.test.cjs +0 -257
- package/dist/cjs/transformSWC.test.cjs +0 -117
- package/dist/cjs/transformWorklets.test.cjs +0 -604
- package/dist/esm/transformBabel.test.mjs +0 -337
- package/dist/esm/transformBabel.test.mjs.map +0 -1
- package/dist/esm/transformHermesLoops.test.mjs +0 -234
- package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
- package/dist/esm/transformSWC.test.mjs +0 -118
- package/dist/esm/transformSWC.test.mjs.map +0 -1
- package/dist/esm/transformWorklets.test.mjs +0 -581
- package/dist/esm/transformWorklets.test.mjs.map +0 -1
- package/dist/esm/types.mjs.map +0 -1
- package/dist/esm/worklets/types.mjs.map +0 -1
- package/types/transformBabel.test.d.ts +0 -2
- package/types/transformBabel.test.d.ts.map +0 -1
- package/types/transformHermesLoops.test.d.ts +0 -2
- package/types/transformHermesLoops.test.d.ts.map +0 -1
- package/types/transformSWC.test.d.ts +0 -2
- package/types/transformSWC.test.d.ts.map +0 -1
- package/types/transformWorklets.test.d.ts +0 -2
- package/types/transformWorklets.test.d.ts.map +0 -1
|
@@ -5,40 +5,33 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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 transformSWC_exports = {};
|
|
35
28
|
__export(transformSWC_exports, {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
shouldSourceMap: () => shouldSourceMap,
|
|
30
|
+
shouldStripFlow: () => shouldStripFlow,
|
|
31
|
+
transformOxc: () => transformOxc,
|
|
32
|
+
transformOxcStripJSX: () => transformOxcStripJSX,
|
|
33
|
+
transformSWC: () => transformSWC,
|
|
34
|
+
transformSWCStripJSX: () => transformSWCStripJSX
|
|
42
35
|
});
|
|
43
36
|
module.exports = __toCommonJS(transformSWC_exports);
|
|
44
37
|
var import_node_path = require("node:path");
|
|
@@ -47,127 +40,123 @@ var import_configure = require("./configure.cjs");
|
|
|
47
40
|
var import_constants = require("./constants.cjs");
|
|
48
41
|
const ignoreId = /node_modules\/(\.vite|vite)\//;
|
|
49
42
|
function shouldStripFlow(id, code) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
const filename = id.split("?")[0];
|
|
44
|
+
if (!/\.jsx?$/.test(filename)) return false;
|
|
45
|
+
if (/node_modules[\\/](?:react-native|@react-native)[\\/].*\.js$/.test(filename)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
const header = code.match(/^(?:#![^\r\n]*(?:\r?\n|$))?(?:\s|\/\*[\s\S]*?\*\/|\/\/[^\r\n]*)*/)?.[0] || "";
|
|
49
|
+
return /@flow\b/.test(header) || /\b(?:import|export)\s+type\b/.test(code);
|
|
57
50
|
}
|
|
58
51
|
async function transformSWC(id, code, options, swcOptions) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
(0, import_constants.debug)?.(`transformSWC (oxc) ${id} using options:
|
|
52
|
+
id = (0, import_vite.normalizePath)(id.split("?")[0]).replace((0, import_vite.normalizePath)(process.cwd()), "");
|
|
53
|
+
if (ignoreId.test(id)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (id === import_constants.runtimePublicPath) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const lang = getLang(id, options.forceJSX);
|
|
60
|
+
if (!lang) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const refresh = options.environment !== "ssr" && !options.production && !options.noHMR && !options.forceJSX && !id.includes("node_modules");
|
|
64
|
+
const importSource = import_configure.configuration.enableNativewind && !id.includes("node_modules") ? "nativewind" : "react";
|
|
65
|
+
const shouldEs5Transform = options.es5 || !process.env.VXRN_USE_BABEL_FOR_GENERATORS && import_constants.asyncGeneratorRegex.test(code);
|
|
66
|
+
const target = shouldEs5Transform ? "es2015" : "es2020";
|
|
67
|
+
const sourceMaps = swcOptions?.sourceMaps !== void 0 ? Boolean(swcOptions.sourceMaps) : shouldSourceMap();
|
|
68
|
+
const oxcOptions = {
|
|
69
|
+
lang,
|
|
70
|
+
target,
|
|
71
|
+
assumptions: {
|
|
72
|
+
setPublicClassFields: true,
|
|
73
|
+
...swcOptions?.assumptions || {}
|
|
74
|
+
},
|
|
75
|
+
sourcemap: sourceMaps,
|
|
76
|
+
jsx: {
|
|
77
|
+
runtime: "automatic",
|
|
78
|
+
development: !options.forceJSX && !options.production,
|
|
79
|
+
refresh: Boolean(refresh),
|
|
80
|
+
importSource
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const { transformSync } = await import("oxc-transform");
|
|
84
|
+
const result = (() => {
|
|
85
|
+
try {
|
|
86
|
+
(0, import_constants.debug)?.(`transformSWC (oxc) ${id} using options:
|
|
96
87
|
${JSON.stringify(oxcOptions, null, 2)}`);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
88
|
+
const res = transformSync(id, code, oxcOptions);
|
|
89
|
+
if (res.errors?.length) {
|
|
90
|
+
const err = res.errors[0];
|
|
91
|
+
const error = new Error(err.message + (err.codeframe ? `
|
|
101
92
|
${err.codeframe}` : ""));
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
93
|
+
if (err.labels?.[0]) {
|
|
94
|
+
error.start = err.labels[0].start;
|
|
95
|
+
error.end = err.labels[0].end;
|
|
96
|
+
}
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
code: res.code,
|
|
101
|
+
map: res.map
|
|
102
|
+
};
|
|
103
|
+
} catch (e) {
|
|
104
|
+
throw e;
|
|
105
|
+
}
|
|
106
|
+
})();
|
|
107
|
+
if (import_configure.configuration.enableNativeCSS) {
|
|
108
|
+
if (result.code.includes(`createInteropElement(`)) {
|
|
109
|
+
result.code = `import { createInteropElement, Fragment as _InteropFragment } from 'react-native-css-interop/jsx-dev-runtime'
|
|
119
110
|
${result.code}`;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const hasRefreshRuntime = refresh && refreshContentRE.test(result.code);
|
|
114
|
+
if (options.fixNonTypeSpecificImports || id.includes("node_modules") && (lang === "ts" || lang === "tsx")) {
|
|
115
|
+
const typeExportsMatch = code.match(/^\s*export\s+type\s+([^\s]+)/gi);
|
|
116
|
+
if (typeExportsMatch) {
|
|
117
|
+
for (const typeExport of Array.from(typeExportsMatch)) {
|
|
118
|
+
const [_export, _type, name] = typeExport.split(/\s+/);
|
|
119
|
+
if (name.startsWith("{")) continue;
|
|
120
|
+
if (name.includes("<")) continue;
|
|
121
|
+
const alreadyExported = new RegExp(`export (const|let|class|function) ${name}\\s+`).test(result.code);
|
|
122
|
+
if (!alreadyExported) {
|
|
123
|
+
const fakeExport = `export let ${name} = {};`;
|
|
124
|
+
console.info(` \u26A0\uFE0F Fixing non-type-specific import in node_module, this should be fixed upstream: ${fakeExport} in ${id}`);
|
|
125
|
+
result.code += `
|
|
135
126
|
${fakeExport}
|
|
136
127
|
`;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (result && !options.production && !options.noHMR) {
|
|
133
|
+
return wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime);
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
145
136
|
}
|
|
146
137
|
const transformOxc = transformSWC;
|
|
147
138
|
function wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
139
|
+
if (options.environment === "ssr") {
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
if (options.environment === "client") {
|
|
143
|
+
return wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime);
|
|
144
|
+
}
|
|
145
|
+
return wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime);
|
|
155
146
|
}
|
|
156
147
|
function wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
result.code = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
|
|
148
|
+
const sourceMap = result.map ? typeof result.map === "string" ? JSON.parse(result.map) : { ...result.map } : void 0;
|
|
149
|
+
if (sourceMap) {
|
|
150
|
+
sourceMap.mappings = ";;" + sourceMap.mappings;
|
|
151
|
+
}
|
|
152
|
+
result.code = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
|
|
164
153
|
|
|
165
154
|
${result.code}`;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
155
|
+
if (hasRefreshRuntime) {
|
|
156
|
+
if (sourceMap) {
|
|
157
|
+
sourceMap.mappings = ";;;;;;" + sourceMap.mappings;
|
|
158
|
+
}
|
|
159
|
+
result.code = `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
|
|
171
160
|
const prevRefreshReg = window.$RefreshReg$;
|
|
172
161
|
const prevRefreshSig = window.$RefreshSig$;
|
|
173
162
|
window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
|
|
@@ -178,8 +167,8 @@ ${result.code}
|
|
|
178
167
|
window.$RefreshReg$ = prevRefreshReg;
|
|
179
168
|
window.$RefreshSig$ = prevRefreshSig;
|
|
180
169
|
`;
|
|
181
|
-
|
|
182
|
-
|
|
170
|
+
}
|
|
171
|
+
result.code += `
|
|
183
172
|
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
184
173
|
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
|
|
185
174
|
import.meta.hot.accept((nextExports) => {
|
|
@@ -189,21 +178,21 @@ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
|
189
178
|
});
|
|
190
179
|
});
|
|
191
180
|
`;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
181
|
+
return {
|
|
182
|
+
code: result.code,
|
|
183
|
+
map: sourceMap
|
|
184
|
+
};
|
|
196
185
|
}
|
|
197
186
|
function wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime) {
|
|
198
|
-
|
|
187
|
+
const postfixCode = `if (module.hot) {
|
|
199
188
|
if (module.hot.accept) {
|
|
200
189
|
module.hot.accept((nextExports) => {
|
|
201
190
|
RefreshRuntime.performReactRefresh()
|
|
202
191
|
});
|
|
203
192
|
}
|
|
204
193
|
}`;
|
|
205
|
-
|
|
206
|
-
|
|
194
|
+
if (hasRefreshRuntime) {
|
|
195
|
+
const prefixCode = `const RefreshRuntime = __cachedModules["react-refresh/cjs/react-refresh-runtime.development"];
|
|
207
196
|
const prevRefreshReg = globalThis.$RefreshReg$;
|
|
208
197
|
const prevRefreshSig = globalThis.$RefreshSig$ || (() => {
|
|
209
198
|
console.info("no react refresh setup!")
|
|
@@ -213,15 +202,13 @@ globalThis.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, "${id}" +
|
|
|
213
202
|
globalThis.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
214
203
|
module.url = '${id}'
|
|
215
204
|
module.hot = createHotContext(module.url)`;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return {
|
|
224
|
-
code: `${prefixCode}
|
|
205
|
+
const sourceMap = result.map ? typeof result.map === "string" ? JSON.parse(result.map) : { ...result.map } : void 0;
|
|
206
|
+
if (sourceMap) {
|
|
207
|
+
const prefixLen = prefixCode.split("\n").length + 1;
|
|
208
|
+
sourceMap.mappings = new Array(prefixLen).fill(";").join("") + sourceMap.mappings;
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
code: `${prefixCode}
|
|
225
212
|
${result.code}
|
|
226
213
|
|
|
227
214
|
if (module.hot) {
|
|
@@ -232,59 +219,55 @@ if (module.hot) {
|
|
|
232
219
|
|
|
233
220
|
${postfixCode}
|
|
234
221
|
`,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
222
|
+
map: sourceMap
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
result.code += postfixCode;
|
|
226
|
+
return result;
|
|
240
227
|
}
|
|
241
228
|
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
242
229
|
function shouldSourceMap() {
|
|
243
|
-
|
|
230
|
+
return process.env.VXRN_ENABLE_SOURCE_MAP === "1";
|
|
244
231
|
}
|
|
245
232
|
function getLang(id, forceJSX = false) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
233
|
+
if (id.endsWith("one-entry-native")) {
|
|
234
|
+
return "tsx";
|
|
235
|
+
}
|
|
236
|
+
const extension = (0, import_node_path.extname)(id);
|
|
237
|
+
if (extension === ".tsx") return "tsx";
|
|
238
|
+
if (extension === ".ts") return "ts";
|
|
239
|
+
if (extension === ".jsx" || extension === ".mdx") return "jsx";
|
|
240
|
+
if (extension === ".js" || extension === ".mjs" || extension === ".cjs") {
|
|
241
|
+
return "jsx";
|
|
242
|
+
}
|
|
243
|
+
if (!extension) {
|
|
244
|
+
return forceJSX ? "jsx" : "js";
|
|
245
|
+
}
|
|
246
|
+
return void 0;
|
|
260
247
|
}
|
|
261
248
|
const transformSWCStripJSX = async (id, code) => {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
});
|
|
280
|
-
if (res.errors?.length) {
|
|
281
|
-
const err = res.errors[0];
|
|
282
|
-
throw new Error(err.message + (err.codeframe ? `
|
|
249
|
+
const lang = getLang(id);
|
|
250
|
+
if (!lang) return;
|
|
251
|
+
const { transformSync } = await import("oxc-transform");
|
|
252
|
+
const res = transformSync(id, code, {
|
|
253
|
+
lang,
|
|
254
|
+
target: "es2020",
|
|
255
|
+
assumptions: { setPublicClassFields: true },
|
|
256
|
+
sourcemap: shouldSourceMap(),
|
|
257
|
+
jsx: {
|
|
258
|
+
runtime: "automatic",
|
|
259
|
+
development: true,
|
|
260
|
+
refresh: false
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
if (res.errors?.length) {
|
|
264
|
+
const err = res.errors[0];
|
|
265
|
+
throw new Error(err.message + (err.codeframe ? `
|
|
283
266
|
${err.codeframe}` : ""));
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
code: res.code,
|
|
270
|
+
map: res.map
|
|
271
|
+
};
|
|
289
272
|
};
|
|
290
|
-
const transformOxcStripJSX = transformSWCStripJSX;
|
|
273
|
+
const transformOxcStripJSX = transformSWCStripJSX;
|