@vxrn/compiler 1.25.16 → 1.26.0
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 +4 -2
- package/dist/cjs/configure.cjs +9 -1
- package/dist/cjs/index.cjs +87 -5
- package/dist/cjs/reactNativeCodegen.cjs +140 -0
- package/dist/cjs/reactNativeViewConfig.cjs +489 -0
- package/dist/cjs/transformBabel.cjs +15 -20
- package/dist/cjs/transformBabel.test.cjs +260 -0
- package/dist/cjs/transformHermesAsync.cjs +61 -0
- package/dist/cjs/transformHermesLoops.cjs +319 -0
- package/dist/cjs/transformHermesLoops.test.cjs +257 -0
- package/dist/cjs/transformSWC.cjs +110 -138
- package/dist/cjs/transformSWC.test.cjs +117 -0
- package/dist/cjs/transformWorklets.cjs +123 -0
- package/dist/cjs/transformWorklets.test.cjs +604 -0
- package/dist/cjs/worklets/autoworklet.cjs +265 -0
- package/dist/cjs/worklets/globals.cjs +73 -0
- package/dist/cjs/worklets/hash.cjs +38 -0
- package/dist/cjs/worklets/scope.cjs +370 -0
- package/dist/cjs/worklets/serialize.cjs +101 -0
- package/dist/cjs/worklets/transform.cjs +266 -0
- package/dist/cjs/worklets/types.cjs +18 -0
- package/dist/esm/cache.mjs +5 -3
- package/dist/esm/cache.mjs.map +1 -1
- package/dist/esm/configure.mjs +8 -1
- package/dist/esm/configure.mjs.map +1 -1
- package/dist/esm/index.js +75 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +75 -6
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/reactNativeCodegen.mjs +104 -0
- package/dist/esm/reactNativeCodegen.mjs.map +1 -0
- package/dist/esm/reactNativeViewConfig.mjs +460 -0
- package/dist/esm/reactNativeViewConfig.mjs.map +1 -0
- package/dist/esm/transformBabel.mjs +14 -19
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/dist/esm/transformBabel.test.mjs +261 -1
- package/dist/esm/transformBabel.test.mjs.map +1 -1
- package/dist/esm/transformHermesAsync.mjs +25 -0
- package/dist/esm/transformHermesAsync.mjs.map +1 -0
- package/dist/esm/transformHermesLoops.mjs +283 -0
- package/dist/esm/transformHermesLoops.mjs.map +1 -0
- package/dist/esm/transformHermesLoops.test.mjs +234 -0
- package/dist/esm/transformHermesLoops.test.mjs.map +1 -0
- package/dist/esm/transformSWC.mjs +96 -139
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/dist/esm/transformSWC.test.mjs +118 -0
- package/dist/esm/transformSWC.test.mjs.map +1 -0
- package/dist/esm/transformWorklets.mjs +82 -0
- package/dist/esm/transformWorklets.mjs.map +1 -0
- package/dist/esm/transformWorklets.test.mjs +581 -0
- package/dist/esm/transformWorklets.test.mjs.map +1 -0
- package/dist/esm/worklets/autoworklet.mjs +234 -0
- package/dist/esm/worklets/autoworklet.mjs.map +1 -0
- package/dist/esm/worklets/globals.mjs +46 -0
- package/dist/esm/worklets/globals.mjs.map +1 -0
- package/dist/esm/worklets/hash.mjs +13 -0
- package/dist/esm/worklets/hash.mjs.map +1 -0
- package/dist/esm/worklets/scope.mjs +345 -0
- package/dist/esm/worklets/scope.mjs.map +1 -0
- package/dist/esm/worklets/serialize.mjs +75 -0
- package/dist/esm/worklets/serialize.mjs.map +1 -0
- package/dist/esm/worklets/transform.mjs +229 -0
- package/dist/esm/worklets/transform.mjs.map +1 -0
- package/dist/esm/worklets/types.mjs +2 -0
- package/dist/esm/worklets/types.mjs.map +1 -0
- package/package.json +11 -6
- package/src/cache.ts +10 -3
- package/src/configure.ts +12 -0
- package/src/index.ts +96 -13
- package/src/reactNativeCodegen.ts +181 -0
- package/src/reactNativeViewConfig.ts +593 -0
- package/src/transformBabel.test.ts +268 -1
- package/src/transformBabel.ts +21 -31
- package/src/transformHermesAsync.ts +30 -0
- package/src/transformHermesLoops.test.ts +341 -0
- package/src/transformHermesLoops.ts +435 -0
- package/src/transformSWC.test.ts +132 -0
- package/src/transformSWC.ts +121 -161
- package/src/transformWorklets.test.ts +708 -0
- package/src/transformWorklets.ts +160 -0
- package/src/types.ts +4 -4
- package/src/worklets/autoworklet.ts +391 -0
- package/src/worklets/globals.ts +129 -0
- package/src/worklets/hash.ts +14 -0
- package/src/worklets/scope.ts +401 -0
- package/src/worklets/serialize.ts +114 -0
- package/src/worklets/transform.ts +319 -0
- package/src/worklets/types.ts +26 -0
- package/types/cache.d.ts +1 -0
- package/types/cache.d.ts.map +1 -1
- package/types/configure.d.ts +2 -0
- package/types/configure.d.ts.map +1 -1
- package/types/index.d.ts +6 -0
- package/types/index.d.ts.map +1 -1
- package/types/reactNativeCodegen.d.ts +5 -0
- package/types/reactNativeCodegen.d.ts.map +1 -0
- package/types/reactNativeViewConfig.d.ts +35 -0
- package/types/reactNativeViewConfig.d.ts.map +1 -0
- package/types/transformBabel.d.ts +3 -3
- package/types/transformBabel.d.ts.map +1 -1
- package/types/transformHermesAsync.d.ts +5 -0
- package/types/transformHermesAsync.d.ts.map +1 -0
- package/types/transformHermesLoops.d.ts +5 -0
- package/types/transformHermesLoops.d.ts.map +1 -0
- package/types/transformHermesLoops.test.d.ts +2 -0
- package/types/transformHermesLoops.test.d.ts.map +1 -0
- package/types/transformSWC.d.ts +13 -3
- package/types/transformSWC.d.ts.map +1 -1
- package/types/transformSWC.test.d.ts +2 -0
- package/types/transformSWC.test.d.ts.map +1 -0
- package/types/transformWorklets.d.ts +23 -0
- package/types/transformWorklets.d.ts.map +1 -0
- package/types/transformWorklets.test.d.ts +2 -0
- package/types/transformWorklets.test.d.ts.map +1 -0
- package/types/types.d.ts +4 -4
- package/types/types.d.ts.map +1 -1
- package/types/worklets/autoworklet.d.ts +14 -0
- package/types/worklets/autoworklet.d.ts.map +1 -0
- package/types/worklets/globals.d.ts +4 -0
- package/types/worklets/globals.d.ts.map +1 -0
- package/types/worklets/hash.d.ts +5 -0
- package/types/worklets/hash.d.ts.map +1 -0
- package/types/worklets/scope.d.ts +7 -0
- package/types/worklets/scope.d.ts.map +1 -0
- package/types/worklets/serialize.d.ts +12 -0
- package/types/worklets/serialize.d.ts.map +1 -0
- package/types/worklets/transform.d.ts +10 -0
- package/types/worklets/transform.d.ts.map +1 -0
- package/types/worklets/types.d.ts +21 -0
- package/types/worklets/types.d.ts.map +1 -0
|
@@ -0,0 +1,257 @@
|
|
|
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_vitest = require("vitest");
|
|
26
|
+
var vm = __toESM(require("node:vm"), 1);
|
|
27
|
+
var import_transformHermesLoops = require("./transformHermesLoops.cjs");
|
|
28
|
+
function runAsHermes(code) {
|
|
29
|
+
const asHermesWouldSeeIt = code.replace(/\b(?:let|const)\b/g, "var");
|
|
30
|
+
const sandbox = {
|
|
31
|
+
result: void 0,
|
|
32
|
+
console
|
|
33
|
+
};
|
|
34
|
+
vm.runInNewContext(asHermesWouldSeeIt, sandbox);
|
|
35
|
+
return sandbox.result;
|
|
36
|
+
}
|
|
37
|
+
function run(source) {
|
|
38
|
+
const out = (0, import_transformHermesLoops.transformHermesLoops)(source, "test.js");
|
|
39
|
+
return runAsHermes(out ? out.code : source);
|
|
40
|
+
}
|
|
41
|
+
(0, import_vitest.describe)("transformHermesLoops", () => {
|
|
42
|
+
import_vitest.it.each([["if (false)", []], ["if (true)", [1, 2]], ["for (var pass = 0; pass < 2; pass++)", [1, 2, 1, 2]], ["while (passes++ < 2)", [1, 2, 1, 2]]])("keeps a captured loop inside a single-statement %s body", (parent, expected) => {
|
|
43
|
+
(0, import_vitest.expect)(run(`
|
|
44
|
+
var fns = []
|
|
45
|
+
var passes = 0
|
|
46
|
+
${parent} for (const n of [1, 2]) fns.push(() => n)
|
|
47
|
+
result = fns.map((f) => f())
|
|
48
|
+
`)).toEqual(expected);
|
|
49
|
+
});
|
|
50
|
+
import_vitest.it.each([true, false])("preserves if/else selection when the condition is %s", condition => {
|
|
51
|
+
(0, import_vitest.expect)(run(`
|
|
52
|
+
var fns = []
|
|
53
|
+
if (${condition}) for (const n of [1, 2]) fns.push(() => n)
|
|
54
|
+
else for (const n of [3, 4]) fns.push(() => n)
|
|
55
|
+
result = fns.map((f) => f())
|
|
56
|
+
`)).toEqual(condition ? [1, 2] : [3, 4]);
|
|
57
|
+
});
|
|
58
|
+
(0, import_vitest.it)("preserves a do/while with a single-statement loop body", () => {
|
|
59
|
+
(0, import_vitest.expect)(run(`
|
|
60
|
+
var fns = []
|
|
61
|
+
var passes = 0
|
|
62
|
+
do for (const n of [1, 2]) fns.push(() => n)
|
|
63
|
+
while (passes++ < 1)
|
|
64
|
+
result = fns.map((f) => f())
|
|
65
|
+
`)).toEqual([1, 2, 1, 2]);
|
|
66
|
+
});
|
|
67
|
+
(0, import_vitest.it)("guards optional Zero query patches through nested loop transforms", () => {
|
|
68
|
+
(0, import_vitest.expect)(run(`
|
|
69
|
+
var fns = []
|
|
70
|
+
var parts = [{}, { desiredQueriesPatches: { a: ['x', 'y'], b: ['z'] } }]
|
|
71
|
+
for (const part of parts) {
|
|
72
|
+
if (part.desiredQueriesPatches)
|
|
73
|
+
for (const [clientID, queriesPatch] of Object.entries(part.desiredQueriesPatches))
|
|
74
|
+
for (const op of queriesPatch) fns.push(() => clientID + ':' + op)
|
|
75
|
+
}
|
|
76
|
+
result = fns.map((f) => f())
|
|
77
|
+
`)).toEqual(["a:x", "a:y", "b:z"]);
|
|
78
|
+
});
|
|
79
|
+
(0, import_vitest.it)("gives a C-style loop a per-iteration binding", () => {
|
|
80
|
+
(0, import_vitest.expect)(run(`
|
|
81
|
+
var fns = []
|
|
82
|
+
for (let i = 0; i < 3; i++) fns.push(() => i)
|
|
83
|
+
result = fns.map((f) => f())
|
|
84
|
+
`)).toEqual([0, 1, 2]);
|
|
85
|
+
});
|
|
86
|
+
(0, import_vitest.it)("gives for-of and for-in per-iteration bindings", () => {
|
|
87
|
+
(0, import_vitest.expect)(run(`
|
|
88
|
+
var fns = []
|
|
89
|
+
for (const label of ['a', 'b']) fns.push(() => label)
|
|
90
|
+
for (const key in { x: 1, y: 2 }) fns.push(() => key)
|
|
91
|
+
result = fns.map((f) => f())
|
|
92
|
+
`)).toEqual(["a", "b", "x", "y"]);
|
|
93
|
+
});
|
|
94
|
+
(0, import_vitest.it)("preserves break", () => {
|
|
95
|
+
(0, import_vitest.expect)(run(`
|
|
96
|
+
var fns = []
|
|
97
|
+
for (let i = 0; i < 10; i++) {
|
|
98
|
+
if (i === 3) break
|
|
99
|
+
fns.push(() => i)
|
|
100
|
+
}
|
|
101
|
+
result = fns.map((f) => f())
|
|
102
|
+
`)).toEqual([0, 1, 2]);
|
|
103
|
+
});
|
|
104
|
+
(0, import_vitest.it)("preserves continue", () => {
|
|
105
|
+
(0, import_vitest.expect)(run(`
|
|
106
|
+
var fns = []
|
|
107
|
+
for (let i = 0; i < 5; i++) {
|
|
108
|
+
if (i % 2 === 0) continue
|
|
109
|
+
fns.push(() => i)
|
|
110
|
+
}
|
|
111
|
+
result = fns.map((f) => f())
|
|
112
|
+
`)).toEqual([1, 3]);
|
|
113
|
+
});
|
|
114
|
+
(0, import_vitest.it)("preserves return out of the enclosing function", () => {
|
|
115
|
+
(0, import_vitest.expect)(run(`
|
|
116
|
+
function find() {
|
|
117
|
+
for (const n of [1, 2, 3]) {
|
|
118
|
+
const get = () => n
|
|
119
|
+
if (n === 2) return get()
|
|
120
|
+
}
|
|
121
|
+
return 'none'
|
|
122
|
+
}
|
|
123
|
+
result = find()
|
|
124
|
+
`)).toBe(2);
|
|
125
|
+
});
|
|
126
|
+
(0, import_vitest.it)("preserves a bare return", () => {
|
|
127
|
+
(0, import_vitest.expect)(run(`
|
|
128
|
+
var fns = []
|
|
129
|
+
function go() {
|
|
130
|
+
for (let i = 0; i < 5; i++) {
|
|
131
|
+
if (i === 2) return
|
|
132
|
+
fns.push(() => i)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
go()
|
|
136
|
+
result = fns.map((f) => f())
|
|
137
|
+
`)).toEqual([0, 1]);
|
|
138
|
+
});
|
|
139
|
+
(0, import_vitest.it)("leaves break and continue belonging to a nested loop alone", () => {
|
|
140
|
+
(0, import_vitest.expect)(run(`
|
|
141
|
+
var fns = []
|
|
142
|
+
for (let i = 0; i < 2; i++) {
|
|
143
|
+
for (var j = 0; j < 5; j++) {
|
|
144
|
+
if (j > 0) break
|
|
145
|
+
}
|
|
146
|
+
fns.push(() => i)
|
|
147
|
+
}
|
|
148
|
+
result = fns.map((f) => f())
|
|
149
|
+
`)).toEqual([0, 1]);
|
|
150
|
+
});
|
|
151
|
+
(0, import_vitest.it)("handles nested capturing loops", () => {
|
|
152
|
+
(0, import_vitest.expect)(run(`
|
|
153
|
+
var fns = []
|
|
154
|
+
for (let i = 0; i < 2; i++) {
|
|
155
|
+
for (let j = 0; j < 2; j++) {
|
|
156
|
+
fns.push(() => i + ':' + j)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
result = fns.map((f) => f())
|
|
160
|
+
`)).toEqual(["0:0", "0:1", "1:0", "1:1"]);
|
|
161
|
+
});
|
|
162
|
+
(0, import_vitest.it)("handles await in the loop body", async () => {
|
|
163
|
+
const out = (0, import_transformHermesLoops.transformHermesLoops)(`
|
|
164
|
+
var fns = []
|
|
165
|
+
async function go() {
|
|
166
|
+
for (const n of [1, 2]) {
|
|
167
|
+
await Promise.resolve()
|
|
168
|
+
fns.push(() => n)
|
|
169
|
+
}
|
|
170
|
+
return fns.map((f) => f())
|
|
171
|
+
}
|
|
172
|
+
result = go()
|
|
173
|
+
`, "test.js");
|
|
174
|
+
(0, import_vitest.expect)(out).not.toBeNull();
|
|
175
|
+
await (0, import_vitest.expect)(runAsHermes(out.code)).resolves.toEqual([1, 2]);
|
|
176
|
+
});
|
|
177
|
+
(0, import_vitest.it)("destructures a for-of binding per iteration", () => {
|
|
178
|
+
(0, import_vitest.expect)(run(`
|
|
179
|
+
var fns = []
|
|
180
|
+
for (const { id } of [{ id: 'a' }, { id: 'b' }]) fns.push(() => id)
|
|
181
|
+
result = fns.map((f) => f())
|
|
182
|
+
`)).toEqual(["a", "b"]);
|
|
183
|
+
});
|
|
184
|
+
(0, import_vitest.it)("rewrites the esbuild interop helper that broke every multi-export module", () => {
|
|
185
|
+
(0, import_vitest.expect)(run(`
|
|
186
|
+
var __defProp = Object.defineProperty
|
|
187
|
+
var __getOwnPropNames = Object.getOwnPropertyNames
|
|
188
|
+
var from = { a: 1, b: 2 }
|
|
189
|
+
var to = {}
|
|
190
|
+
for (let key of __getOwnPropNames(from)) {
|
|
191
|
+
__defProp(to, key, { get: () => from[key], enumerable: true })
|
|
192
|
+
}
|
|
193
|
+
result = [to.a, to.b]
|
|
194
|
+
`)).toEqual([1, 2]);
|
|
195
|
+
});
|
|
196
|
+
(0, import_vitest.it)("leaves loops that never capture their binding untouched", () => {
|
|
197
|
+
(0, import_vitest.expect)((0, import_transformHermesLoops.transformHermesLoops)("for (let i = 0; i < 3; i++) sum += i", "test.js")).toBeNull();
|
|
198
|
+
});
|
|
199
|
+
(0, import_vitest.it)("gives a binding declared in the loop body a per-iteration copy", () => {
|
|
200
|
+
(0, import_vitest.expect)(run(`
|
|
201
|
+
var names = ['createAnimatedNode', 'addListener', 'removeListener']
|
|
202
|
+
var wrappers = {}
|
|
203
|
+
for (var ii = 0; ii < names.length; ii++) {
|
|
204
|
+
const methodName = names[ii]
|
|
205
|
+
wrappers[methodName] = () => methodName
|
|
206
|
+
}
|
|
207
|
+
result = names.map((n) => wrappers[n]())
|
|
208
|
+
`)).toEqual(["createAnimatedNode", "addListener", "removeListener"]);
|
|
209
|
+
});
|
|
210
|
+
(0, import_vitest.it)("gives a binding declared in a nested block of the loop body a per-iteration copy", () => {
|
|
211
|
+
(0, import_vitest.expect)(run(`
|
|
212
|
+
var fns = []
|
|
213
|
+
for (var i = 0; i < 3; i++) {
|
|
214
|
+
if (i >= 0) {
|
|
215
|
+
const doubled = i * 2
|
|
216
|
+
fns.push(() => doubled)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
result = fns.map((f) => f())
|
|
220
|
+
`)).toEqual([0, 2, 4]);
|
|
221
|
+
});
|
|
222
|
+
(0, import_vitest.it)("keeps `this` and `arguments` meaning what they meant outside the loop", () => {
|
|
223
|
+
(0, import_vitest.expect)(run(`
|
|
224
|
+
class PropsFilter {
|
|
225
|
+
constructor() { this._map = { a: 'A', b: 'B' } }
|
|
226
|
+
filter(props) {
|
|
227
|
+
var out = []
|
|
228
|
+
for (const key in props) {
|
|
229
|
+
const label = key
|
|
230
|
+
out.push(() => this._map[label] + arguments.length)
|
|
231
|
+
}
|
|
232
|
+
return out
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
result = new PropsFilter().filter({ a: 1, b: 2 }).map((f) => f())
|
|
236
|
+
`)).toEqual(["A1", "B1"]);
|
|
237
|
+
});
|
|
238
|
+
(0, import_vitest.it)("leaves a loop with no lexical binding untouched", () => {
|
|
239
|
+
(0, import_vitest.expect)((0, import_transformHermesLoops.transformHermesLoops)("for (var i = 0; i < 3; i++) fns.push(() => i)", "test.js")).toBeNull();
|
|
240
|
+
});
|
|
241
|
+
(0, import_vitest.it)("leaves the head declaration alone so it cannot collide with a sibling", () => {
|
|
242
|
+
const out = (0, import_transformHermesLoops.transformHermesLoops)(`function build(gestures) {
|
|
243
|
+
var handlers = []
|
|
244
|
+
for (const gesture of gestures) { handlers.push(() => gesture) }
|
|
245
|
+
const gesture = gestures[0]
|
|
246
|
+
return gesture
|
|
247
|
+
}`, "Pressable.js");
|
|
248
|
+
(0, import_vitest.expect)(() => new vm.Script(out.code)).not.toThrow();
|
|
249
|
+
});
|
|
250
|
+
(0, import_vitest.it)("rewrites a loop in a .js file that still contains jsx", () => {
|
|
251
|
+
const out = (0, import_transformHermesLoops.transformHermesLoops)("for (const c of items) rows.push(() => <Row key={c} />)", "Rows.js");
|
|
252
|
+
(0, import_vitest.expect)(out?.code).toContain("_hermesLoop0");
|
|
253
|
+
});
|
|
254
|
+
(0, import_vitest.it)("does not rewrite a loop that reassigns its own binding", () => {
|
|
255
|
+
(0, import_vitest.expect)((0, import_transformHermesLoops.transformHermesLoops)("for (let i = 0; i < 3; i++) { i += 1; fns.push(() => i) }", "test.js")).toBeNull();
|
|
256
|
+
});
|
|
257
|
+
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all) __defProp(target, name, {
|
|
@@ -17,22 +19,42 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
19
|
}
|
|
18
20
|
return to;
|
|
19
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));
|
|
20
31
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
32
|
value: true
|
|
22
33
|
}), mod);
|
|
23
34
|
var transformSWC_exports = {};
|
|
24
35
|
__export(transformSWC_exports, {
|
|
36
|
+
shouldSourceMap: () => shouldSourceMap,
|
|
37
|
+
shouldStripFlow: () => shouldStripFlow,
|
|
38
|
+
transformOxc: () => transformOxc,
|
|
39
|
+
transformOxcStripJSX: () => transformOxcStripJSX,
|
|
25
40
|
transformSWC: () => transformSWC,
|
|
26
41
|
transformSWCStripJSX: () => transformSWCStripJSX
|
|
27
42
|
});
|
|
28
43
|
module.exports = __toCommonJS(transformSWC_exports);
|
|
29
44
|
var import_node_path = require("node:path");
|
|
30
|
-
var import_core = require("@swc/core");
|
|
31
|
-
var import_ts_deepmerge = require("ts-deepmerge");
|
|
32
45
|
var import_vite = require("vite");
|
|
33
46
|
var import_configure = require("./configure.cjs");
|
|
34
47
|
var import_constants = require("./constants.cjs");
|
|
35
48
|
const ignoreId = /node_modules\/(\.vite|vite)\//;
|
|
49
|
+
function shouldStripFlow(id, code) {
|
|
50
|
+
const filename = id.split("?")[0];
|
|
51
|
+
if (!/\.jsx?$/.test(filename)) return false;
|
|
52
|
+
if (/node_modules[\\/](?:react-native|@react-native)[\\/].*\.js$/.test(filename)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
const header = code.match(/^(?:#![^\r\n]*(?:\r?\n|$))?(?:\s|\/\*[\s\S]*?\*\/|\/\/[^\r\n]*)*/)?.[0] || "";
|
|
56
|
+
return /@flow\b/.test(header) || /\b(?:import|export)\s+type\b/.test(code);
|
|
57
|
+
}
|
|
36
58
|
async function transformSWC(id, code, options, swcOptions) {
|
|
37
59
|
id = (0, import_vite.normalizePath)(id.split("?")[0]).replace((0, import_vite.normalizePath)(process.cwd()), "");
|
|
38
60
|
if (ignoreId.test(id)) {
|
|
@@ -41,100 +63,53 @@ async function transformSWC(id, code, options, swcOptions) {
|
|
|
41
63
|
if (id === import_constants.runtimePublicPath) {
|
|
42
64
|
return;
|
|
43
65
|
}
|
|
44
|
-
const
|
|
45
|
-
if (!
|
|
66
|
+
const lang = getLang(id, options.forceJSX);
|
|
67
|
+
if (!lang) {
|
|
46
68
|
return;
|
|
47
69
|
}
|
|
48
70
|
const refresh = options.environment !== "ssr" && !options.production && !options.noHMR && !options.forceJSX && !id.includes("node_modules");
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
jsc: {
|
|
67
|
-
target: "es2020",
|
|
68
|
-
parser,
|
|
69
|
-
transform: {
|
|
70
|
-
useDefineForClassFields: true,
|
|
71
|
-
react: reactConfig
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
71
|
+
const importSource = import_configure.configuration.enableNativewind && !id.includes("node_modules") ? "nativewind" : "react";
|
|
72
|
+
const shouldEs5Transform = options.es5 || !process.env.VXRN_USE_BABEL_FOR_GENERATORS && import_constants.asyncGeneratorRegex.test(code);
|
|
73
|
+
const target = shouldEs5Transform ? "es2015" : "es2020";
|
|
74
|
+
const sourceMaps = swcOptions?.sourceMaps !== void 0 ? Boolean(swcOptions.sourceMaps) : shouldSourceMap();
|
|
75
|
+
const oxcOptions = {
|
|
76
|
+
lang,
|
|
77
|
+
target,
|
|
78
|
+
assumptions: {
|
|
79
|
+
setPublicClassFields: true,
|
|
80
|
+
...(swcOptions?.assumptions || {})
|
|
81
|
+
},
|
|
82
|
+
sourcemap: sourceMaps,
|
|
83
|
+
jsx: {
|
|
84
|
+
runtime: "automatic",
|
|
85
|
+
development: !options.forceJSX && !options.production,
|
|
86
|
+
refresh: Boolean(refresh),
|
|
87
|
+
importSource
|
|
75
88
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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 () => {
|
|
89
|
+
};
|
|
90
|
+
const {
|
|
91
|
+
transformSync
|
|
92
|
+
} = await import("oxc-transform");
|
|
93
|
+
const result = (() => {
|
|
124
94
|
try {
|
|
125
|
-
(0, import_constants.debug)?.(`transformSWC ${id} using options:
|
|
126
|
-
${JSON.stringify(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
e.column = match[2];
|
|
95
|
+
(0, import_constants.debug)?.(`transformSWC (oxc) ${id} using options:
|
|
96
|
+
${JSON.stringify(oxcOptions, null, 2)}`);
|
|
97
|
+
const res = transformSync(id, code, oxcOptions);
|
|
98
|
+
if (res.errors?.length) {
|
|
99
|
+
const err = res.errors[0];
|
|
100
|
+
const error = new Error(err.message + (err.codeframe ? `
|
|
101
|
+
${err.codeframe}` : ""));
|
|
102
|
+
if (err.labels?.[0]) {
|
|
103
|
+
error.start = err.labels[0].start;
|
|
104
|
+
error.end = err.labels[0].end;
|
|
136
105
|
}
|
|
106
|
+
throw error;
|
|
137
107
|
}
|
|
108
|
+
return {
|
|
109
|
+
code: res.code,
|
|
110
|
+
map: res.map
|
|
111
|
+
};
|
|
112
|
+
} catch (e) {
|
|
138
113
|
throw e;
|
|
139
114
|
}
|
|
140
115
|
})();
|
|
@@ -145,7 +120,7 @@ ${result.code}`;
|
|
|
145
120
|
}
|
|
146
121
|
}
|
|
147
122
|
const hasRefreshRuntime = refresh && refreshContentRE.test(result.code);
|
|
148
|
-
if (options.fixNonTypeSpecificImports || id.includes("node_modules") &&
|
|
123
|
+
if (options.fixNonTypeSpecificImports || id.includes("node_modules") && (lang === "ts" || lang === "tsx")) {
|
|
149
124
|
const typeExportsMatch = code.match(/^\s*export\s+type\s+([^\s]+)/gi);
|
|
150
125
|
if (typeExportsMatch) {
|
|
151
126
|
for (const typeExport of Array.from(typeExportsMatch)) {
|
|
@@ -168,6 +143,7 @@ ${fakeExport}
|
|
|
168
143
|
}
|
|
169
144
|
return result;
|
|
170
145
|
}
|
|
146
|
+
const transformOxc = transformSWC;
|
|
171
147
|
function wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime) {
|
|
172
148
|
if (options.environment === "ssr") {
|
|
173
149
|
return result;
|
|
@@ -178,7 +154,9 @@ function wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime) {
|
|
|
178
154
|
return wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime);
|
|
179
155
|
}
|
|
180
156
|
function wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime) {
|
|
181
|
-
const sourceMap = result.map ? JSON.parse(result.map) :
|
|
157
|
+
const sourceMap = result.map ? typeof result.map === "string" ? JSON.parse(result.map) : {
|
|
158
|
+
...result.map
|
|
159
|
+
} : void 0;
|
|
182
160
|
if (sourceMap) {
|
|
183
161
|
sourceMap.mappings = ";;" + sourceMap.mappings;
|
|
184
162
|
}
|
|
@@ -235,7 +213,9 @@ globalThis.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, "${id}" +
|
|
|
235
213
|
globalThis.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
236
214
|
module.url = '${id}'
|
|
237
215
|
module.hot = createHotContext(module.url)`;
|
|
238
|
-
const sourceMap = result.map ? JSON.parse(result.map) :
|
|
216
|
+
const sourceMap = result.map ? typeof result.map === "string" ? JSON.parse(result.map) : {
|
|
217
|
+
...result.map
|
|
218
|
+
} : void 0;
|
|
239
219
|
if (sourceMap) {
|
|
240
220
|
const prefixLen = prefixCode.split("\n").length + 1;
|
|
241
221
|
sourceMap.mappings = new Array(prefixLen).fill(";").join("") + sourceMap.mappings;
|
|
@@ -258,61 +238,53 @@ ${postfixCode}
|
|
|
258
238
|
result.code += postfixCode;
|
|
259
239
|
return result;
|
|
260
240
|
}
|
|
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
241
|
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
278
242
|
function shouldSourceMap() {
|
|
279
243
|
return process.env.VXRN_ENABLE_SOURCE_MAP === "1";
|
|
280
244
|
}
|
|
281
|
-
function
|
|
245
|
+
function getLang(id, forceJSX = false) {
|
|
282
246
|
if (id.endsWith("one-entry-native")) {
|
|
283
|
-
return
|
|
247
|
+
return "tsx";
|
|
284
248
|
}
|
|
285
249
|
const extension = (0, import_node_path.extname)(id);
|
|
286
|
-
|
|
287
|
-
if (extension === ".
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
if (id.includes("expo-modules-core")) {
|
|
292
|
-
parser = import_constants.parsers[".jsx"];
|
|
293
|
-
}
|
|
250
|
+
if (extension === ".tsx") return "tsx";
|
|
251
|
+
if (extension === ".ts") return "ts";
|
|
252
|
+
if (extension === ".jsx" || extension === ".mdx") return "jsx";
|
|
253
|
+
if (extension === ".js" || extension === ".mjs" || extension === ".cjs") {
|
|
254
|
+
return "jsx";
|
|
294
255
|
}
|
|
295
|
-
|
|
256
|
+
if (!extension) {
|
|
257
|
+
return forceJSX ? "jsx" : "js";
|
|
258
|
+
}
|
|
259
|
+
return void 0;
|
|
296
260
|
}
|
|
297
261
|
const transformSWCStripJSX = async (id, code) => {
|
|
298
|
-
const
|
|
299
|
-
if (!
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
}
|
|
262
|
+
const lang = getLang(id);
|
|
263
|
+
if (!lang) return;
|
|
264
|
+
const {
|
|
265
|
+
transformSync
|
|
266
|
+
} = await import("oxc-transform");
|
|
267
|
+
const res = transformSync(id, code, {
|
|
268
|
+
lang,
|
|
269
|
+
target: "es2020",
|
|
270
|
+
assumptions: {
|
|
271
|
+
setPublicClassFields: true
|
|
272
|
+
},
|
|
273
|
+
sourcemap: shouldSourceMap(),
|
|
274
|
+
jsx: {
|
|
275
|
+
runtime: "automatic",
|
|
276
|
+
development: true,
|
|
277
|
+
refresh: false
|
|
316
278
|
}
|
|
317
279
|
});
|
|
318
|
-
|
|
280
|
+
if (res.errors?.length) {
|
|
281
|
+
const err = res.errors[0];
|
|
282
|
+
throw new Error(err.message + (err.codeframe ? `
|
|
283
|
+
${err.codeframe}` : ""));
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
code: res.code,
|
|
287
|
+
map: res.map
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
const transformOxcStripJSX = transformSWCStripJSX;
|