@fluixi/compiler 1.0.0-alpha.92 → 1.0.0-alpha.93
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/analyze/intrinsics.cjs +18 -0
- package/dist/analyze/intrinsics.d.ts.map +1 -1
- package/dist/analyze/intrinsics.js +18 -0
- package/dist/analyze/intrinsics.mjs +18 -0
- package/dist/analyze/reactive-bindings.cjs +18 -0
- package/dist/analyze/reactive-bindings.mjs +18 -0
- package/dist/analyze/static-graph.cjs +22 -4
- package/dist/analyze/static-graph.d.ts.map +1 -1
- package/dist/analyze/static-graph.js +6 -4
- package/dist/analyze/static-graph.mjs +22 -4
- package/dist/{babel-GI375YZ2.mjs → babel-RJHJQVEM.mjs} +4 -4
- package/dist/{chunk-QZ4CJPYP.mjs → chunk-56QSOVVL.mjs} +1 -1
- package/dist/{chunk-XJ5H2MXY.mjs → chunk-OD53TMER.mjs} +19 -1
- package/dist/{chunk-DWNWN5RH.mjs → chunk-R7PPFBCL.mjs} +1 -1
- package/dist/{chunk-VOUI6XPV.mjs → chunk-TJIH7TLX.mjs} +1 -1
- package/dist/{chunk-VC6X44FS.mjs → chunk-U7HCFLZ2.mjs} +153 -48
- package/dist/codegen/backends/imperative.cjs +24 -6
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +19 -4
- package/dist/codegen/backends/imperative.mjs +24 -6
- package/dist/frontend/babel/build-ir-lit.cjs +120 -43
- package/dist/frontend/babel/build-ir-lit.mjs +120 -43
- package/dist/frontend/babel/build-ir.cjs +120 -43
- package/dist/frontend/babel/build-ir.mjs +120 -43
- package/dist/frontend/babel/index.cjs +121 -44
- package/dist/frontend/babel/index.mjs +121 -44
- package/dist/frontend/babel/lower-template.cjs +120 -43
- package/dist/frontend/babel/lower-template.mjs +120 -43
- package/dist/frontend/babel/plugin.cjs +120 -43
- package/dist/frontend/babel/plugin.mjs +120 -43
- package/dist/index.cjs +41 -38
- package/dist/index.mjs +41 -38
- package/dist/integrations.cjs +176 -52
- package/dist/integrations.mjs +8 -8
- package/dist/lower/compile-template.cjs +41 -38
- package/dist/lower/compile-template.mjs +41 -38
- package/dist/lower/jsx.cjs +509 -6
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +114 -6
- package/dist/lower/jsx.mjs +509 -6
- package/dist/lower/template.cjs +40 -37
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +22 -30
- package/dist/lower/template.mjs +40 -37
- package/dist/resolve/builtins.cjs +1 -1
- package/dist/resolve/builtins.mjs +1 -1
- package/dist/resolve/component-globals.cjs +14 -0
- package/dist/resolve/component-globals.mjs +14 -0
- package/dist/resolve/write-globals.cjs +14 -0
- package/dist/resolve/write-globals.mjs +14 -0
- package/dist/{server-fns-BBZRZUPP.mjs → server-fns-ZFRDIQ2X.mjs} +4 -4
- package/dist/{server-functions-VEGLIFCE.mjs → server-functions-CTDXX67X.mjs} +3 -3
- package/dist/transform/index.cjs +170 -47
- package/dist/transform/index.mjs +170 -47
- package/dist/transform/intrinsics.cjs +18 -0
- package/dist/transform/intrinsics.mjs +18 -0
- package/dist/transform/source-locations.cjs +64 -3
- package/dist/transform/source-locations.d.cts +7 -2
- package/dist/transform/source-locations.d.ts +7 -2
- package/dist/transform/source-locations.d.ts.map +1 -1
- package/dist/transform/source-locations.js +68 -3
- package/dist/transform/source-locations.mjs +64 -3
- package/dist/transform/templates.cjs +169 -46
- package/dist/transform/templates.js +2 -2
- package/dist/transform/templates.mjs +169 -46
- package/dist/{transform-UWZ7ZGJ2.mjs → transform-QWWQDCXE.mjs} +7 -7
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +9 -3
|
@@ -12,6 +12,11 @@ export interface SourceLocationsResult {
|
|
|
12
12
|
export declare const SOURCE_MARKER = "__fx_source";
|
|
13
13
|
/** Where a component was declared. Keyed by name, since that is all the runtime carries. */
|
|
14
14
|
export declare const COMPONENT_MARKER = "__fx_component";
|
|
15
|
+
/**
|
|
16
|
+
* Where a class that extends another was declared, keyed by the class itself: a custom
|
|
17
|
+
* element's definition, which the runtime can only reach through `element.constructor`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const CLASS_MARKER = "__fx_class";
|
|
15
20
|
/**
|
|
16
21
|
* Where one reactive hole was written. This one wraps: the position has to travel with the
|
|
17
22
|
* accessor to wherever the dom wires it up. A template is emitted as one overwrite, so the
|
|
@@ -38,7 +43,7 @@ export declare const markHole: (accessor: string, line: number, column: number,
|
|
|
38
43
|
export declare const PROPS_MARKER = "__fx_props";
|
|
39
44
|
/** `_({ get a() {…} }, {"a":[9,25]})`, or the object untouched when nothing is watching. */
|
|
40
45
|
export declare const markProps: (object: string, at: Record<string, [number, number]>) => string;
|
|
41
|
-
/** Cheap enough to run before parsing. */
|
|
42
|
-
export declare function
|
|
46
|
+
/** Whether a module has anything to mark: a primitive call or a subclass. Cheap enough to run before parsing. */
|
|
47
|
+
export declare function mayHaveSourceMarks(code: string): boolean;
|
|
43
48
|
export declare function collectSourceEdits(program: unknown, filename: string): SourceLocationsResult;
|
|
44
49
|
//# sourceMappingURL=source-locations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-locations.d.ts","sourceRoot":"","sources":["../../src/transform/source-locations.ts"],"names":[],"mappings":"AA6BA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,gEAAgE;AAChE,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAE3C,4FAA4F;AAC5F,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,cAAc,CAAC;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GACnB,UAAU,MAAM,EAChB,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,OAAO,MAAM,KACZ,MAGE,CAAC;AAEN;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,eAAe,CAAC;AAEzC,4FAA4F;AAC5F,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,EAAE,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,KAAG,MACF,CAAC;AAQhF,
|
|
1
|
+
{"version":3,"file":"source-locations.d.ts","sourceRoot":"","sources":["../../src/transform/source-locations.ts"],"names":[],"mappings":"AA6BA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,gEAAgE;AAChE,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAE3C,4FAA4F;AAC5F,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,YAAY,eAAe,CAAC;AAEzC;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,cAAc,CAAC;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GACnB,UAAU,MAAM,EAChB,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,OAAO,MAAM,KACZ,MAGE,CAAC;AAEN;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,eAAe,CAAC;AAEzC,4FAA4F;AAC5F,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,EAAE,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,KAAG,MACF,CAAC;AAQhF,iHAAiH;AACjH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOxD;AAmFD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,qBAAqB,CA6J5F"}
|
|
@@ -22,6 +22,11 @@ import { resolveReactiveBindings } from '../analyze/reactive-bindings.js';
|
|
|
22
22
|
export const SOURCE_MARKER = '__fx_source';
|
|
23
23
|
/** Where a component was declared. Keyed by name, since that is all the runtime carries. */
|
|
24
24
|
export const COMPONENT_MARKER = '__fx_component';
|
|
25
|
+
/**
|
|
26
|
+
* Where a class that extends another was declared, keyed by the class itself: a custom
|
|
27
|
+
* element's definition, which the runtime can only reach through `element.constructor`.
|
|
28
|
+
*/
|
|
29
|
+
export const CLASS_MARKER = '__fx_class';
|
|
25
30
|
/**
|
|
26
31
|
* Where one reactive hole was written. This one wraps: the position has to travel with the
|
|
27
32
|
* accessor to wherever the dom wires it up. A template is emitted as one overwrite, so the
|
|
@@ -53,13 +58,16 @@ const RUNTIME_PRIMITIVES = new Set([
|
|
|
53
58
|
'signal', 'memo', 'effect', 'store', 'resource', 'watch',
|
|
54
59
|
'createSignal', 'createMemo', 'createEffect', 'createStore', 'createResource',
|
|
55
60
|
]);
|
|
56
|
-
/** Cheap enough to run before parsing. */
|
|
57
|
-
export function
|
|
61
|
+
/** Whether a module has anything to mark: a primitive call or a subclass. Cheap enough to run before parsing. */
|
|
62
|
+
export function mayHaveSourceMarks(code) {
|
|
58
63
|
for (const name of RUNTIME_PRIMITIVES) {
|
|
59
64
|
if (code.includes(name))
|
|
60
65
|
return true;
|
|
61
66
|
}
|
|
62
|
-
|
|
67
|
+
if (code.includes('$signal') || code.includes('$memo') || code.includes('$effect') || code.includes('$store'))
|
|
68
|
+
return true;
|
|
69
|
+
// A subclass gets a declaration mark, so an element with no signal of its own is still found.
|
|
70
|
+
return /\bclass\b[^{;]*\bextends\b/.test(code);
|
|
63
71
|
}
|
|
64
72
|
/** Positions where the grammar allows exactly one statement, so a second one changes it. */
|
|
65
73
|
const SINGLE_STATEMENT_PARENTS = new Set([
|
|
@@ -74,6 +82,8 @@ function isLoneBranch(statement, parent) {
|
|
|
74
82
|
function isExport(node) {
|
|
75
83
|
return node.type === 'ExportNamedDeclaration' || node.type === 'ExportDefaultDeclaration';
|
|
76
84
|
}
|
|
85
|
+
/** Where a class holds a per-instance initializer: the value of a field. */
|
|
86
|
+
const CLASS_FIELDS = new Set(['PropertyDefinition', 'ClassProperty', 'ClassPrivateProperty', 'AccessorProperty']);
|
|
77
87
|
function isStatement(node) {
|
|
78
88
|
return node.type.endsWith('Statement') || node.type === 'VariableDeclaration';
|
|
79
89
|
}
|
|
@@ -103,6 +113,15 @@ function walk(node, visit, stack = []) {
|
|
|
103
113
|
*/
|
|
104
114
|
function nameFor(stack) {
|
|
105
115
|
const declarator = stack[stack.length - 1];
|
|
116
|
+
// `#count = signal(0)` and `count = signal(0)`: the field's name, without the `#`.
|
|
117
|
+
if (declarator && CLASS_FIELDS.has(declarator.type)) {
|
|
118
|
+
const key = declarator.key;
|
|
119
|
+
if (key?.type === 'Identifier' || key?.type === 'PrivateIdentifier' || key?.type === 'PrivateName') {
|
|
120
|
+
const name = (key.name ?? key.id?.name);
|
|
121
|
+
return name;
|
|
122
|
+
}
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
106
125
|
if (declarator?.type !== 'VariableDeclarator')
|
|
107
126
|
return undefined;
|
|
108
127
|
const id = declarator.id;
|
|
@@ -170,6 +189,20 @@ export function collectSourceEdits(program, filename) {
|
|
|
170
189
|
});
|
|
171
190
|
}
|
|
172
191
|
}
|
|
192
|
+
// A static block at the top of the body runs once, when the class is defined, with `this`
|
|
193
|
+
// bound to the class. Only a subclass: that covers every custom element and keeps the mark
|
|
194
|
+
// off plain classes. An ambient `declare class` has no body to run.
|
|
195
|
+
if ((node.type === 'ClassDeclaration' || node.type === 'ClassExpression') && node.superClass && !node.declare) {
|
|
196
|
+
const at = node.loc?.start;
|
|
197
|
+
const body = node.body;
|
|
198
|
+
if (at && body) {
|
|
199
|
+
edits.push({
|
|
200
|
+
start: body.start + 1,
|
|
201
|
+
end: body.start + 1,
|
|
202
|
+
code: `static{globalThis.${CLASS_MARKER}?.(this,${JSON.stringify(filename)},${at.line},${at.column});}`,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
173
206
|
if (node.type !== 'CallExpression')
|
|
174
207
|
return;
|
|
175
208
|
const callee = node.callee;
|
|
@@ -186,6 +219,38 @@ export function collectSourceEdits(program, filename) {
|
|
|
186
219
|
const position = node.loc?.start;
|
|
187
220
|
if (!position)
|
|
188
221
|
return;
|
|
222
|
+
// A class field (`#count = signal(0)`) runs once per instance, and the class body has no
|
|
223
|
+
// statement to put the mark in front of. Hoisting it before the class runs it once, at
|
|
224
|
+
// definition, and the next node created anywhere took its name and line; inside a function
|
|
225
|
+
// (a mixin) the nearest statement was the function's body block, and the mark landed in
|
|
226
|
+
// front of the `{`. The call itself carries the mark instead, so it runs right before the
|
|
227
|
+
// node it describes.
|
|
228
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
229
|
+
const up = stack[i];
|
|
230
|
+
if (isStatement(up))
|
|
231
|
+
break;
|
|
232
|
+
if (CLASS_FIELDS.has(up.type)) {
|
|
233
|
+
if (claimed.has(node.start))
|
|
234
|
+
return;
|
|
235
|
+
claimed.add(node.start);
|
|
236
|
+
const label = nameFor(stack);
|
|
237
|
+
// An instance field also hands over `this`: the constructor runs before a custom
|
|
238
|
+
// element opens its scope, and the instance is what ties the node to it later.
|
|
239
|
+
const own = !up.static;
|
|
240
|
+
const args = [
|
|
241
|
+
JSON.stringify(filename),
|
|
242
|
+
String(position.line),
|
|
243
|
+
String(position.column),
|
|
244
|
+
label ? JSON.stringify(label) : own ? 'undefined' : undefined,
|
|
245
|
+
own ? 'this' : undefined,
|
|
246
|
+
]
|
|
247
|
+
.filter((a) => a !== undefined)
|
|
248
|
+
.join(',');
|
|
249
|
+
edits.push({ start: node.start, end: node.start, code: `(globalThis.${SOURCE_MARKER}?.(${args}),` });
|
|
250
|
+
edits.push({ start: node.end, end: node.end, code: ')' });
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
189
254
|
// The mark goes in front of the statement, clear of any span another pass rewrites.
|
|
190
255
|
let statement;
|
|
191
256
|
let parent;
|
|
@@ -6,6 +6,7 @@ var INTRINSICS = {
|
|
|
6
6
|
$effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
|
|
7
7
|
$store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
|
|
8
8
|
$resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
|
|
9
|
+
$cachedResource: { export: "cachedResource", module: "@fluixi/reactive/cached-resource", returns: "resource-handle" },
|
|
9
10
|
// No short runtime form for these yet, so the intrinsic stands for the `create*`
|
|
10
11
|
// name. Still worth having: no import to write, and when a shorter form is
|
|
11
12
|
// designed, the change is this line rather than a compiler pass.
|
|
@@ -16,6 +17,19 @@ var INTRINSICS = {
|
|
|
16
17
|
// dependency analysis must not guess at.
|
|
17
18
|
$untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
|
|
18
19
|
$untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" },
|
|
20
|
+
// Scopes, scheduling and lifecycle: no value to classify, but the same authoring promise,
|
|
21
|
+
// no import to write. `$cleanup` registers a callback on the current owner (`onCleanup`).
|
|
22
|
+
$batch: { export: "batch", module: REACTIVE_MODULE, returns: "plain" },
|
|
23
|
+
$cleanup: { export: "onCleanup", module: REACTIVE_MODULE, returns: "plain" },
|
|
24
|
+
$root: { export: "root", module: REACTIVE_MODULE, returns: "plain" },
|
|
25
|
+
$context: { export: "context", module: REACTIVE_MODULE, returns: "plain" },
|
|
26
|
+
$renderEffect: { export: "renderEffect", module: REACTIVE_MODULE, returns: "effect" },
|
|
27
|
+
$computed: { export: "computed", module: REACTIVE_MODULE, returns: "effect" },
|
|
28
|
+
// Storage for where the code runs, and a signal kept in it. `$persisted` is a signal
|
|
29
|
+
// handle as far as reads go: the same accessor with `set` on it.
|
|
30
|
+
$storage: { export: "useStorage", module: "@fluixi/core/storage", returns: "plain" },
|
|
31
|
+
$asyncStorage: { export: "useAsyncStorage", module: "@fluixi/core/storage", returns: "plain" },
|
|
32
|
+
$persisted: { export: "persisted", module: "@fluixi/core/storage", returns: "signal-handle" },
|
|
19
33
|
// An environment variable, public or server-only; the browser build refuses a secret.
|
|
20
34
|
$env: { export: "env", module: "@fluixi/start/env", returns: "plain" }
|
|
21
35
|
};
|
|
@@ -28,8 +42,11 @@ var RUNTIME_PRIMITIVES = {
|
|
|
28
42
|
createMemo: "memo-accessor",
|
|
29
43
|
createEffect: "effect",
|
|
30
44
|
createRenderEffect: "effect",
|
|
45
|
+
renderEffect: "effect",
|
|
46
|
+
computed: "effect",
|
|
31
47
|
createStore: "reactive-object",
|
|
32
48
|
resource: "resource-handle",
|
|
49
|
+
cachedResource: "resource-handle",
|
|
33
50
|
createResource: "reactive-object",
|
|
34
51
|
createSelector: "memo-accessor",
|
|
35
52
|
createDeferred: "memo-accessor"
|
|
@@ -38,6 +55,7 @@ var PRIMITIVE_MODULES = [
|
|
|
38
55
|
"@fluixi/reactive",
|
|
39
56
|
"@fluixi/reactive/signal",
|
|
40
57
|
"@fluixi/reactive/store",
|
|
58
|
+
"@fluixi/reactive/cached-resource",
|
|
41
59
|
"@fluixi/core"
|
|
42
60
|
];
|
|
43
61
|
var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
|
|
@@ -141,6 +159,7 @@ function resolveReactiveBindings(program) {
|
|
|
141
159
|
// src/transform/source-locations.ts
|
|
142
160
|
var SOURCE_MARKER = "__fx_source";
|
|
143
161
|
var COMPONENT_MARKER = "__fx_component";
|
|
162
|
+
var CLASS_MARKER = "__fx_class";
|
|
144
163
|
var HOLE_MARKER = "__fx_hole";
|
|
145
164
|
var markHole = (accessor, line, column, name) => `(globalThis.${HOLE_MARKER} ?? ((f) => f))(${accessor},${line},${column}${name === void 0 ? "" : `,${JSON.stringify(name)}`})`;
|
|
146
165
|
var PROPS_MARKER = "__fx_props";
|
|
@@ -158,11 +177,12 @@ var RUNTIME_PRIMITIVES2 = /* @__PURE__ */ new Set([
|
|
|
158
177
|
"createStore",
|
|
159
178
|
"createResource"
|
|
160
179
|
]);
|
|
161
|
-
function
|
|
180
|
+
function mayHaveSourceMarks(code) {
|
|
162
181
|
for (const name of RUNTIME_PRIMITIVES2) {
|
|
163
182
|
if (code.includes(name)) return true;
|
|
164
183
|
}
|
|
165
|
-
|
|
184
|
+
if (code.includes("$signal") || code.includes("$memo") || code.includes("$effect") || code.includes("$store")) return true;
|
|
185
|
+
return /\bclass\b[^{;]*\bextends\b/.test(code);
|
|
166
186
|
}
|
|
167
187
|
var SINGLE_STATEMENT_PARENTS = /* @__PURE__ */ new Set([
|
|
168
188
|
"IfStatement",
|
|
@@ -181,6 +201,7 @@ function isLoneBranch(statement, parent) {
|
|
|
181
201
|
function isExport(node) {
|
|
182
202
|
return node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration";
|
|
183
203
|
}
|
|
204
|
+
var CLASS_FIELDS = /* @__PURE__ */ new Set(["PropertyDefinition", "ClassProperty", "ClassPrivateProperty", "AccessorProperty"]);
|
|
184
205
|
function isStatement(node) {
|
|
185
206
|
return node.type.endsWith("Statement") || node.type === "VariableDeclaration";
|
|
186
207
|
}
|
|
@@ -201,6 +222,14 @@ function walk2(node, visit, stack = []) {
|
|
|
201
222
|
}
|
|
202
223
|
function nameFor(stack) {
|
|
203
224
|
const declarator = stack[stack.length - 1];
|
|
225
|
+
if (declarator && CLASS_FIELDS.has(declarator.type)) {
|
|
226
|
+
const key = declarator.key;
|
|
227
|
+
if (key?.type === "Identifier" || key?.type === "PrivateIdentifier" || key?.type === "PrivateName") {
|
|
228
|
+
const name = key.name ?? key.id?.name;
|
|
229
|
+
return name;
|
|
230
|
+
}
|
|
231
|
+
return void 0;
|
|
232
|
+
}
|
|
204
233
|
if (declarator?.type !== "VariableDeclarator") return void 0;
|
|
205
234
|
const id = declarator.id;
|
|
206
235
|
if (id?.type === "Identifier") return id.name;
|
|
@@ -249,6 +278,17 @@ function collectSourceEdits(program, filename) {
|
|
|
249
278
|
});
|
|
250
279
|
}
|
|
251
280
|
}
|
|
281
|
+
if ((node.type === "ClassDeclaration" || node.type === "ClassExpression") && node.superClass && !node.declare) {
|
|
282
|
+
const at = node.loc?.start;
|
|
283
|
+
const body = node.body;
|
|
284
|
+
if (at && body) {
|
|
285
|
+
edits.push({
|
|
286
|
+
start: body.start + 1,
|
|
287
|
+
end: body.start + 1,
|
|
288
|
+
code: `static{globalThis.${CLASS_MARKER}?.(this,${JSON.stringify(filename)},${at.line},${at.column});}`
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
252
292
|
if (node.type !== "CallExpression") return;
|
|
253
293
|
const callee = node.callee;
|
|
254
294
|
if (callee?.type !== "Identifier") return;
|
|
@@ -258,6 +298,26 @@ function collectSourceEdits(program, filename) {
|
|
|
258
298
|
if (!intrinsic && !imported) return;
|
|
259
299
|
const position = node.loc?.start;
|
|
260
300
|
if (!position) return;
|
|
301
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
302
|
+
const up = stack[i];
|
|
303
|
+
if (isStatement(up)) break;
|
|
304
|
+
if (CLASS_FIELDS.has(up.type)) {
|
|
305
|
+
if (claimed.has(node.start)) return;
|
|
306
|
+
claimed.add(node.start);
|
|
307
|
+
const label2 = nameFor(stack);
|
|
308
|
+
const own = !up.static;
|
|
309
|
+
const args2 = [
|
|
310
|
+
JSON.stringify(filename),
|
|
311
|
+
String(position.line),
|
|
312
|
+
String(position.column),
|
|
313
|
+
label2 ? JSON.stringify(label2) : own ? "undefined" : void 0,
|
|
314
|
+
own ? "this" : void 0
|
|
315
|
+
].filter((a) => a !== void 0).join(",");
|
|
316
|
+
edits.push({ start: node.start, end: node.start, code: `(globalThis.${SOURCE_MARKER}?.(${args2}),` });
|
|
317
|
+
edits.push({ start: node.end, end: node.end, code: ")" });
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
261
321
|
let statement;
|
|
262
322
|
let parent;
|
|
263
323
|
let index = -1;
|
|
@@ -298,6 +358,7 @@ function collectSourceEdits(program, filename) {
|
|
|
298
358
|
return { edits, marked: edits.length };
|
|
299
359
|
}
|
|
300
360
|
export {
|
|
361
|
+
CLASS_MARKER,
|
|
301
362
|
COMPONENT_MARKER,
|
|
302
363
|
HOLE_MARKER,
|
|
303
364
|
PROPS_MARKER,
|
|
@@ -305,5 +366,5 @@ export {
|
|
|
305
366
|
collectSourceEdits,
|
|
306
367
|
markHole,
|
|
307
368
|
markProps,
|
|
308
|
-
|
|
369
|
+
mayHaveSourceMarks
|
|
309
370
|
};
|