@vxrn/compiler 1.27.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.
Files changed (89) hide show
  1. package/dist/cjs/cache.cjs +106 -117
  2. package/dist/cjs/configure.cjs +26 -28
  3. package/dist/cjs/constants.cjs +56 -60
  4. package/dist/cjs/index.cjs +420 -443
  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 -263
  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 +90 -97
  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 -425
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/index.mjs +417 -425
  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 -237
  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/transformBabel.test.ts +77 -17
  63. package/src/transformBabel.ts +28 -12
  64. package/types/transformBabel.d.ts +12 -0
  65. package/types/transformBabel.d.ts.map +1 -1
  66. package/types/transformSWC.d.ts +1 -4
  67. package/types/transformSWC.d.ts.map +1 -1
  68. package/dist/cjs/transformBabel.test.cjs +0 -652
  69. package/dist/cjs/transformHermesLoops.test.cjs +0 -257
  70. package/dist/cjs/transformSWC.test.cjs +0 -117
  71. package/dist/cjs/transformWorklets.test.cjs +0 -604
  72. package/dist/esm/transformBabel.test.mjs +0 -629
  73. package/dist/esm/transformBabel.test.mjs.map +0 -1
  74. package/dist/esm/transformHermesLoops.test.mjs +0 -234
  75. package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
  76. package/dist/esm/transformSWC.test.mjs +0 -118
  77. package/dist/esm/transformSWC.test.mjs.map +0 -1
  78. package/dist/esm/transformWorklets.test.mjs +0 -581
  79. package/dist/esm/transformWorklets.test.mjs.map +0 -1
  80. package/dist/esm/types.mjs.map +0 -1
  81. package/dist/esm/worklets/types.mjs.map +0 -1
  82. package/types/transformBabel.test.d.ts +0 -2
  83. package/types/transformBabel.test.d.ts.map +0 -1
  84. package/types/transformHermesLoops.test.d.ts +0 -2
  85. package/types/transformHermesLoops.test.d.ts.map +0 -1
  86. package/types/transformSWC.test.d.ts +0 -2
  87. package/types/transformSWC.test.d.ts.map +0 -1
  88. package/types/transformWorklets.test.d.ts +0 -2
  89. package/types/transformWorklets.test.d.ts.map +0 -1
@@ -1,257 +0,0 @@
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,117 +0,0 @@
1
- var import_vitest = require("vitest");
2
- var import_node_vm = require("node:vm");
3
- var import_rolldown = require("rolldown");
4
- var import_transformSWC = require("./transformSWC.cjs");
5
- (0, import_vitest.describe)("transformSWC / transformOxc with oxc-transform for Hermes lowering", () => {
6
- (0, import_vitest.it)("preserves unbraced for-await bodies and early returns", async () => {
7
- const result = await (0, import_transformSWC.transformSWC)("AsyncIterable.js", `
8
- async function collect(it) {
9
- const values = []
10
- for await (const value of it) values.push(value)
11
- return values
12
- }
13
- async function first(it) {
14
- for await (const value of it) return value
15
- return null
16
- }
17
- globalThis.result = Promise.all([collect([11, 22]), first([11, 22])])
18
- `, {
19
- environment: "ios",
20
- mode: "build",
21
- production: true
22
- });
23
- (0, import_vitest.expect)(result).toBeDefined();
24
- const bundle = await (0, import_rolldown.rolldown)({
25
- input: "virtual:async-iterable.js",
26
- plugins: [{
27
- name: "async-iterable-fixture",
28
- resolveId(id) {
29
- if (id === "virtual:async-iterable.js") return id;
30
- },
31
- load(id) {
32
- if (id === "virtual:async-iterable.js") return result.code;
33
- }
34
- }]
35
- });
36
- try {
37
- const output = await bundle.generate({
38
- format: "iife"
39
- });
40
- const context = {};
41
- (0, import_node_vm.runInNewContext)(output.output[0].code, context);
42
- await (0, import_vitest.expect)(context.result).resolves.toEqual([[11, 22], 11]);
43
- } finally {
44
- await bundle.close();
45
- }
46
- });
47
- (0, import_vitest.it)("lowers class fields, private fields, and static blocks with Hermes target and assumptions", async () => {
48
- const input = `
49
- class Sample {
50
- #secret = 42
51
- publicField = 100
52
- static {
53
- Sample.initialized = true
54
- }
55
- getSecret() {
56
- return this.#secret
57
- }
58
- }
59
- `;
60
- const res = await (0, import_transformSWC.transformSWC)("Sample.ts", input, {
61
- environment: "ios",
62
- mode: "build"
63
- });
64
- (0, import_vitest.expect)(res).toBeDefined();
65
- (0, import_vitest.expect)(res.code).not.toContain("#secret");
66
- (0, import_vitest.expect)(res.code).not.toMatch(/^\s*publicField\s*=/m);
67
- (0, import_vitest.expect)(res.code).not.toContain("static {");
68
- (0, import_vitest.expect)(res.code).toContain("this.publicField = 100");
69
- });
70
- import_vitest.it.each(["MyComponent.tsx", "MyComponent.js", "MyComponent.mjs", "MyComponent.cjs"])("lowers JSX in %s to react automatic runtime calls", async filename => {
71
- const input = `
72
- export function MyComponent() {
73
- return <div className="test"><span>Hello</span></div>
74
- }
75
- `;
76
- const res = await (0, import_transformSWC.transformSWC)(filename, input, {
77
- environment: "client",
78
- mode: "build"
79
- });
80
- (0, import_vitest.expect)(res).toBeDefined();
81
- (0, import_vitest.expect)(res.code).not.toContain("<div");
82
- (0, import_vitest.expect)(res.code).not.toContain("<span>");
83
- (0, import_vitest.expect)(res.code).toContain("_jsx");
84
- });
85
- (0, import_vitest.it)("respects sourcemaps option", async () => {
86
- const input = `
87
- class Sample {
88
- val = 1
89
- }
90
- `;
91
- const resWithoutMap = await (0, import_transformSWC.transformSWC)("Sample.ts", input, {
92
- environment: "ios",
93
- mode: "build"
94
- }, {
95
- sourceMaps: false
96
- });
97
- (0, import_vitest.expect)(resWithoutMap?.map).toBeUndefined();
98
- const resWithMap = await (0, import_transformSWC.transformSWC)("Sample.ts", input, {
99
- environment: "ios",
100
- mode: "build"
101
- }, {
102
- sourceMaps: true
103
- });
104
- (0, import_vitest.expect)(resWithMap?.map).toBeDefined();
105
- (0, import_vitest.expect)(resWithMap?.map.mappings).toBeDefined();
106
- });
107
- (0, import_vitest.it)("provides transformOxc alias", () => {
108
- (0, import_vitest.expect)(import_transformSWC.transformOxc).toBe(import_transformSWC.transformSWC);
109
- });
110
- (0, import_vitest.it)("strips JSX using transformSWCStripJSX", async () => {
111
- const input = `export const el = <div>Hello</div>`;
112
- const res = await (0, import_transformSWC.transformSWCStripJSX)("el.tsx", input);
113
- (0, import_vitest.expect)(res).toBeDefined();
114
- (0, import_vitest.expect)(res.code).not.toContain("<div>");
115
- (0, import_vitest.expect)(res.code).toContain("_jsx");
116
- });
117
- });