@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
|
@@ -3,99 +3,97 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
10
|
};
|
|
11
11
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
19
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
21
|
var serialize_exports = {};
|
|
24
22
|
__export(serialize_exports, {
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
buildLocalFunction: () => buildLocalFunction,
|
|
24
|
+
serializeWorkletForUI: () => serializeWorkletForUI
|
|
27
25
|
});
|
|
28
26
|
module.exports = __toCommonJS(serialize_exports);
|
|
29
27
|
var import_oxc_transform = require("oxc-transform");
|
|
30
28
|
var import_autoworklet = require("./autoworklet.cjs");
|
|
31
29
|
function assertTransformed(transformed, name, what) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
const error = transformed.errors?.[0];
|
|
31
|
+
if (error) {
|
|
32
|
+
throw new Error(`[worklets] failed to build ${what} code for ${name || "anonymous worklet"}: ${error.message || error}`);
|
|
33
|
+
}
|
|
34
|
+
if (!transformed.code.trim()) {
|
|
35
|
+
throw new Error(`[worklets] built empty ${what} code for ${name || "anonymous worklet"}`);
|
|
36
|
+
}
|
|
39
37
|
}
|
|
40
38
|
function serializeWorkletForUI(fnNode, code, name, closureVars) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
let rawParams = "";
|
|
40
|
+
if (fnNode.params && fnNode.params.length > 0) {
|
|
41
|
+
const pStart = fnNode.params[0].start;
|
|
42
|
+
const pEnd = fnNode.params[fnNode.params.length - 1].end;
|
|
43
|
+
rawParams = code.slice(pStart, pEnd);
|
|
44
|
+
}
|
|
45
|
+
let rawBody = "";
|
|
46
|
+
if (fnNode.body.type === "BlockStatement") {
|
|
47
|
+
const bodyStart = (0, import_autoworklet.bodyStartAfterDirectives)(fnNode, code);
|
|
48
|
+
const bodyEnd = fnNode.body.end - 1;
|
|
49
|
+
rawBody = code.slice(bodyStart, bodyEnd);
|
|
50
|
+
} else {
|
|
51
|
+
rawBody = `return ${code.slice(fnNode.body.start, fnNode.body.end)};`;
|
|
52
|
+
}
|
|
53
|
+
const unpacker = closureVars.length > 0 ? `const { ${closureVars.join(", ")} } = this.__closure ?? this._closure;
|
|
56
54
|
` : "";
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
const asyncPrefix = fnNode.async ? "async " : "";
|
|
56
|
+
const genPrefix = fnNode.generator ? "*" : "";
|
|
57
|
+
const fnName = name || "_worklet";
|
|
58
|
+
const fullFn = `${asyncPrefix}function${genPrefix} ${fnName}(${rawParams}) {
|
|
61
59
|
${unpacker}${rawBody}
|
|
62
60
|
}`;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
const transformed = (0, import_oxc_transform.transformSync)("worklet.ts", fullFn);
|
|
62
|
+
assertTransformed(transformed, name, "serialized");
|
|
63
|
+
return transformed.code.trim();
|
|
66
64
|
}
|
|
67
65
|
function buildLocalFunction(fnNode, code, name) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
66
|
+
let rawParams = "";
|
|
67
|
+
if (fnNode.params && fnNode.params.length > 0) {
|
|
68
|
+
const pStart = fnNode.params[0].start;
|
|
69
|
+
const pEnd = fnNode.params[fnNode.params.length - 1].end;
|
|
70
|
+
rawParams = code.slice(pStart, pEnd);
|
|
71
|
+
}
|
|
72
|
+
let rawBody = "";
|
|
73
|
+
if (fnNode.body.type === "BlockStatement") {
|
|
74
|
+
const bodyStart = (0, import_autoworklet.bodyStartAfterDirectives)(fnNode, code);
|
|
75
|
+
const bodyEnd = fnNode.body.end - 1;
|
|
76
|
+
rawBody = code.slice(bodyStart, bodyEnd);
|
|
77
|
+
} else {
|
|
78
|
+
rawBody = code.slice(fnNode.body.start, fnNode.body.end);
|
|
79
|
+
}
|
|
80
|
+
let rawFn = "";
|
|
81
|
+
const asyncPrefix = fnNode.async ? "async " : "";
|
|
82
|
+
const genPrefix = fnNode.generator ? "*" : "";
|
|
83
|
+
if (fnNode.type === "ArrowFunctionExpression") {
|
|
84
|
+
if (fnNode.body.type === "BlockStatement") {
|
|
85
|
+
rawFn = `${asyncPrefix}(${rawParams}) => {
|
|
88
86
|
${rawBody}
|
|
89
87
|
}`;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
} else {
|
|
89
|
+
rawFn = `${asyncPrefix}(${rawParams}) => (${rawBody})`;
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
rawFn = `${asyncPrefix}function${genPrefix} ${name || "_worklet"}(${rawParams}) {
|
|
95
93
|
${rawBody}
|
|
96
94
|
}`;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
95
|
+
}
|
|
96
|
+
const transformed = (0, import_oxc_transform.transformSync)("local.ts", rawFn);
|
|
97
|
+
assertTransformed(transformed, name, "local");
|
|
98
|
+
return transformed.code.trim().replace(/;$/, "");
|
|
99
|
+
}
|
|
@@ -5,36 +5,29 @@ 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 transform_exports = {};
|
|
35
28
|
__export(transform_exports, {
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
executeWorkletTransform: () => executeWorkletTransform,
|
|
30
|
+
prepareWorkletsForReactCompiler: () => prepareWorkletsForReactCompiler
|
|
38
31
|
});
|
|
39
32
|
module.exports = __toCommonJS(transform_exports);
|
|
40
33
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
@@ -46,151 +39,153 @@ var import_globals = require("./globals.cjs");
|
|
|
46
39
|
var import_hash = require("./hash.cjs");
|
|
47
40
|
var import_scope = require("./scope.cjs");
|
|
48
41
|
var import_serialize = require("./serialize.cjs");
|
|
49
|
-
const FUNCTION_TYPES = /* @__PURE__ */new Set([
|
|
42
|
+
const FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
43
|
+
"FunctionDeclaration",
|
|
44
|
+
"FunctionExpression",
|
|
45
|
+
"ArrowFunctionExpression"
|
|
46
|
+
]);
|
|
50
47
|
function prepareWorkletsForReactCompiler(id, code, sourceMaps = false) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}) : void 0
|
|
81
|
-
};
|
|
48
|
+
const cleanId = id.split("?")[0];
|
|
49
|
+
const parsed = (0, import_oxc_parser.parseSync)(cleanId, code, {
|
|
50
|
+
sourceType: "module",
|
|
51
|
+
lang: /\.[cm]?ts$/.test(cleanId) ? "ts" : cleanId.endsWith(".tsx") ? "tsx" : "jsx"
|
|
52
|
+
});
|
|
53
|
+
if (parsed.errors.length) {
|
|
54
|
+
const error = parsed.errors[0];
|
|
55
|
+
throw new Error(error.codeframe || error.message || "Syntax Error while parsing worklet");
|
|
56
|
+
}
|
|
57
|
+
const candidates = (0, import_autoworklet.findWorkletCandidates)(parsed.program).filter((candidate) => candidate.isAutoWorklet && !(0, import_autoworklet.hasDirective)(candidate.fnNode, "worklet"));
|
|
58
|
+
if (!candidates.length) return null;
|
|
59
|
+
const output = new import_magic_string.default(code);
|
|
60
|
+
for (const { fnNode } of candidates) {
|
|
61
|
+
const body = fnNode.body;
|
|
62
|
+
if (body.type === "BlockStatement") {
|
|
63
|
+
output.appendLeft(body.start + 1, "'worklet';");
|
|
64
|
+
} else {
|
|
65
|
+
output.appendLeft(body.start, "{ 'worklet'; return (");
|
|
66
|
+
output.appendLeft(body.end, "); }");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
code: output.toString(),
|
|
71
|
+
map: sourceMaps ? output.generateMap({
|
|
72
|
+
source: cleanId,
|
|
73
|
+
hires: true,
|
|
74
|
+
includeContent: true
|
|
75
|
+
}) : void 0
|
|
76
|
+
};
|
|
82
77
|
}
|
|
83
78
|
function findEnclosingFunction(program, node) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
79
|
+
let best = void 0;
|
|
80
|
+
const walk = (n) => {
|
|
81
|
+
if (!n || typeof n !== "object") return;
|
|
82
|
+
if (Array.isArray(n)) {
|
|
83
|
+
for (const c of n) walk(c);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (typeof n.type !== "string") return;
|
|
87
|
+
if (typeof n.start === "number" && (n.start > node.start || n.end < node.end)) return;
|
|
88
|
+
if (FUNCTION_TYPES.has(n.type) && n !== node && n.body?.type === "BlockStatement" && n.body.start < node.start && n.body.end > node.end && (!best || n.body.start > best.body.start)) {
|
|
89
|
+
best = n;
|
|
90
|
+
}
|
|
91
|
+
for (const key in n) {
|
|
92
|
+
if (key === "parent") continue;
|
|
93
|
+
walk(n[key]);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
walk(program);
|
|
97
|
+
return best;
|
|
103
98
|
}
|
|
104
99
|
function executeWorkletTransform(id, code, sourceMaps = false, options, resolveVersionFn) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
100
|
+
const cleanId = id.split("?")[0];
|
|
101
|
+
const lang = /\.[cm]?ts$/.test(cleanId) ? "ts" : cleanId.endsWith(".tsx") ? "tsx" : "jsx";
|
|
102
|
+
const initialParse = (0, import_oxc_parser.parseSync)(cleanId, code, {
|
|
103
|
+
sourceType: "module",
|
|
104
|
+
lang
|
|
105
|
+
});
|
|
106
|
+
if (initialParse.errors && initialParse.errors.length > 0) {
|
|
107
|
+
const err = initialParse.errors[0];
|
|
108
|
+
throw new Error(err.codeframe || err.message || "Syntax Error while parsing worklet");
|
|
109
|
+
}
|
|
110
|
+
const initialCandidates = (0, import_autoworklet.findWorkletCandidates)(initialParse.program);
|
|
111
|
+
if (initialCandidates.length === 0) {
|
|
112
|
+
let map2 = void 0;
|
|
113
|
+
if (sourceMaps) {
|
|
114
|
+
const ms = new import_magic_string.default(code);
|
|
115
|
+
map2 = ms.generateMap({
|
|
116
|
+
source: cleanId,
|
|
117
|
+
file: cleanId,
|
|
118
|
+
hires: true,
|
|
119
|
+
includeContent: true
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
code,
|
|
124
|
+
map: map2
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const pluginVersion = options?.pluginVersion || (resolveVersionFn ? resolveVersionFn(options?.projectRoot, cleanId) : "0.0.0");
|
|
128
|
+
const globals = (0, import_globals.createGlobalsSet)(options?.globals, options?.strictGlobal);
|
|
129
|
+
let location = cleanId;
|
|
130
|
+
if (options?.relativeSourceLocation && options?.projectRoot) {
|
|
131
|
+
location = import_node_path.default.relative(options.projectRoot, cleanId).replace(/\\/g, "/");
|
|
132
|
+
}
|
|
133
|
+
let currentCode = code;
|
|
134
|
+
const initDataDefs = /* @__PURE__ */ new Map();
|
|
135
|
+
const passMaps = [];
|
|
136
|
+
let remainingPassBudget = 100;
|
|
137
|
+
while (remainingPassBudget-- > 0) {
|
|
138
|
+
const parseResult = (0, import_oxc_parser.parseSync)(cleanId, currentCode, {
|
|
139
|
+
sourceType: "module",
|
|
140
|
+
lang
|
|
141
|
+
});
|
|
142
|
+
if (parseResult.errors && parseResult.errors.length > 0) {
|
|
143
|
+
const err = parseResult.errors[0];
|
|
144
|
+
throw new Error(err.codeframe || err.message || "Syntax Error while parsing worklet");
|
|
145
|
+
}
|
|
146
|
+
const candidates = (0, import_autoworklet.findWorkletCandidates)(parseResult.program);
|
|
147
|
+
if (candidates.length === 0) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
const innermostCandidates = candidates.filter((c) => {
|
|
151
|
+
return !candidates.some((other) => other !== c && other.fnNode.start >= c.fnNode.start && other.fnNode.end <= c.fnNode.end);
|
|
152
|
+
});
|
|
153
|
+
if (innermostCandidates.length === 0) {
|
|
154
|
+
throw new Error(`[worklets] Cyclic or unresolvable worklet nesting detected in ${cleanId}`);
|
|
155
|
+
}
|
|
156
|
+
const ms = new import_magic_string.default(currentCode);
|
|
157
|
+
const inlinedInitData = /* @__PURE__ */ new Map();
|
|
158
|
+
for (const candidate of innermostCandidates) {
|
|
159
|
+
const closureVars = (0, import_autoworklet.hasDirective)(candidate.fnNode, "no-worklet-closure") ? [] : (0, import_scope.getClosureVariables)(candidate.fnNode, globals);
|
|
160
|
+
const fnName = candidate.name;
|
|
161
|
+
const serializedCode = (0, import_serialize.serializeWorkletForUI)(candidate.fnNode, currentCode, fnName, closureVars);
|
|
162
|
+
const workletHash = (0, import_hash.calculateWorkletHash)(serializedCode);
|
|
163
|
+
const initDataVar = `_worklet_${workletHash}_init_data`;
|
|
164
|
+
const initDataDecl = `var ${initDataVar} = {
|
|
170
165
|
code: ${JSON.stringify(serializedCode)},
|
|
171
166
|
location: ${JSON.stringify(location)}
|
|
172
167
|
};`;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
168
|
+
const enclosingFn = (0, import_autoworklet.hasDirective)(candidate.fnNode, "limit-init-data-hoisting") ? findEnclosingFunction(parseResult.program, candidate.fnNode) : void 0;
|
|
169
|
+
if (enclosingFn) {
|
|
170
|
+
const insertAt = (0, import_autoworklet.bodyStartAfterDirectives)(enclosingFn, currentCode);
|
|
171
|
+
let declared = inlinedInitData.get(insertAt);
|
|
172
|
+
if (!declared) {
|
|
173
|
+
declared = /* @__PURE__ */ new Set();
|
|
174
|
+
inlinedInitData.set(insertAt, declared);
|
|
175
|
+
}
|
|
176
|
+
if (!declared.has(initDataVar)) {
|
|
177
|
+
declared.add(initDataVar);
|
|
178
|
+
ms.appendLeft(insertAt, `
|
|
184
179
|
${initDataDecl}
|
|
185
180
|
`);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
181
|
+
}
|
|
182
|
+
} else if (!initDataDefs.has(initDataVar)) {
|
|
183
|
+
initDataDefs.set(initDataVar, initDataDecl);
|
|
184
|
+
}
|
|
185
|
+
const localFnCode = (0, import_serialize.buildLocalFunction)(candidate.fnNode, currentCode, fnName);
|
|
186
|
+
const localName = fnName || "_worklet";
|
|
187
|
+
const closureProps = closureVars.map((v) => `${v}: ${v}`).join(", ");
|
|
188
|
+
const iife = `(function () {
|
|
194
189
|
var _e = [new (typeof global !== 'undefined' ? global : globalThis).Error(), 1, -27];
|
|
195
190
|
var ${localName} = ${localFnCode};
|
|
196
191
|
${localName}.__closure = { ${closureProps} };
|
|
@@ -200,67 +195,67 @@ ${initDataDecl}
|
|
|
200
195
|
${localName}.__stackDetails = _e;
|
|
201
196
|
return ${localName};
|
|
202
197
|
})()`;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
198
|
+
if (candidate.kind === "function_declaration") {
|
|
199
|
+
if (candidate.parent?.type === "ExportNamedDeclaration") {
|
|
200
|
+
ms.overwrite(candidate.parent.start, candidate.parent.end, `export var ${candidate.name} = ${iife};`);
|
|
201
|
+
} else if (candidate.parent?.type === "ExportDefaultDeclaration") {
|
|
202
|
+
ms.overwrite(candidate.parent.start, candidate.parent.end, `var ${candidate.name || "_defaultWorklet"} = ${iife};
|
|
208
203
|
export default ${candidate.name || "_defaultWorklet"};`);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
204
|
+
} else {
|
|
205
|
+
ms.overwrite(candidate.node.start, candidate.node.end, `var ${candidate.name} = ${iife};`);
|
|
206
|
+
}
|
|
207
|
+
} else if (candidate.kind === "object_method") {
|
|
208
|
+
ms.overwrite(candidate.node.start, candidate.node.end, `${candidate.name}: ${iife}`);
|
|
209
|
+
} else {
|
|
210
|
+
ms.overwrite(candidate.node.start, candidate.node.end, iife);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (sourceMaps) {
|
|
214
|
+
passMaps.push(ms.generateMap({
|
|
215
|
+
source: cleanId,
|
|
216
|
+
file: cleanId,
|
|
217
|
+
hires: true,
|
|
218
|
+
includeContent: true
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
currentCode = ms.toString();
|
|
222
|
+
}
|
|
223
|
+
const finalCheck = (0, import_oxc_parser.parseSync)(cleanId, currentCode, {
|
|
224
|
+
sourceType: "module",
|
|
225
|
+
lang
|
|
226
|
+
});
|
|
227
|
+
const remaining = (0, import_autoworklet.findWorkletCandidates)(finalCheck.program);
|
|
228
|
+
if (remaining.length > 0) {
|
|
229
|
+
throw new Error(`[worklets] Exceeded maximum pass budget while transforming worklets in ${cleanId}. ${remaining.length} worklet(s) remained untransformed.`);
|
|
230
|
+
}
|
|
231
|
+
if (initDataDefs.size > 0) {
|
|
232
|
+
const initDataCode = Array.from(initDataDefs.values()).join("\n") + "\n";
|
|
233
|
+
const msPrepend = new import_magic_string.default(currentCode);
|
|
234
|
+
msPrepend.prepend(initDataCode);
|
|
235
|
+
if (sourceMaps) {
|
|
236
|
+
passMaps.push(msPrepend.generateMap({
|
|
237
|
+
source: cleanId,
|
|
238
|
+
file: cleanId,
|
|
239
|
+
hires: true,
|
|
240
|
+
includeContent: true
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
currentCode = msPrepend.toString();
|
|
244
|
+
}
|
|
245
|
+
let map = void 0;
|
|
246
|
+
if (sourceMaps && passMaps.length > 0) {
|
|
247
|
+
if (passMaps.length === 1) {
|
|
248
|
+
map = passMaps[0];
|
|
249
|
+
} else {
|
|
250
|
+
map = (0, import_remapping.default)(passMaps.slice().reverse(), () => null);
|
|
251
|
+
}
|
|
252
|
+
if (map) {
|
|
253
|
+
map.sources = [cleanId];
|
|
254
|
+
map.file = cleanId;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
code: currentCode,
|
|
259
|
+
map
|
|
260
|
+
};
|
|
261
|
+
}
|