@marko/language-tools 2.5.44 → 2.5.45
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/extractors/script/util/attach-scopes.d.ts +7 -5
- package/dist/index.js +132 -150
- package/dist/index.mjs +132 -150
- package/marko.internal.d.ts +19 -13
- package/package.json +1 -1
|
@@ -9,13 +9,11 @@ export interface ProgramScope {
|
|
|
9
9
|
parent: undefined;
|
|
10
10
|
hoists: false;
|
|
11
11
|
bindings: Bindings;
|
|
12
|
-
mutatedBindings: undefined | Set<VarBinding>;
|
|
13
12
|
}
|
|
14
13
|
export interface TagScope {
|
|
15
14
|
parent: Scope;
|
|
16
15
|
hoists: boolean;
|
|
17
16
|
bindings: undefined | Bindings;
|
|
18
|
-
mutatedBindings: undefined | Set<VarBinding>;
|
|
19
17
|
}
|
|
20
18
|
export type Binding = VarBinding | ParamBinding | HoistedBinding;
|
|
21
19
|
export interface VarBinding {
|
|
@@ -46,22 +44,26 @@ export declare enum BindingType {
|
|
|
46
44
|
param = 1,
|
|
47
45
|
hoisted = 2
|
|
48
46
|
}
|
|
47
|
+
export interface Mutation {
|
|
48
|
+
start: number;
|
|
49
|
+
binding: VarBinding;
|
|
50
|
+
}
|
|
49
51
|
type Bindings = {
|
|
50
52
|
[name: string]: Binding;
|
|
51
53
|
};
|
|
52
54
|
/**
|
|
53
55
|
* Traverses the Marko tree and analyzes the bindings.
|
|
54
56
|
*/
|
|
55
|
-
export declare function crawlProgramScope(parsed: Parsed, scriptParser: ScriptParser): [
|
|
57
|
+
export declare function crawlProgramScope(parsed: Parsed, scriptParser: ScriptParser): [Mutation, ...Mutation[]] | [...Mutation[], Mutation] | undefined;
|
|
56
58
|
export declare function getProgramBindings(node: Node.Program): {
|
|
57
59
|
all: Repeated<string>;
|
|
58
60
|
vars: Repeatable<string>;
|
|
59
61
|
hoists: Repeatable<string>;
|
|
60
62
|
} | undefined;
|
|
63
|
+
export declare function getMutatedVars(tag: Node.Tag): Repeatable<VarBinding>;
|
|
61
64
|
export declare function getHoistSources(body: Node.ParentNode["body"]): Repeatable<string>;
|
|
62
|
-
export declare function getMutatedVars(node: Node.ParentNode): Set<VarBinding> | undefined;
|
|
63
65
|
export declare function isMutatedVar(node: Node.ParentNode, name: string): boolean;
|
|
64
|
-
export declare function hasHoists(node: Node.
|
|
66
|
+
export declare function hasHoists(node: Node.Tag): boolean;
|
|
65
67
|
export declare function getBoundAttrRange(value: Node.AttrValue): {
|
|
66
68
|
value: Range;
|
|
67
69
|
types: undefined | Range;
|
package/dist/index.js
CHANGED
|
@@ -1089,8 +1089,7 @@ function crawlProgramScope(parsed, scriptParser) {
|
|
|
1089
1089
|
const programScope = {
|
|
1090
1090
|
parent: void 0,
|
|
1091
1091
|
hoists: false,
|
|
1092
|
-
bindings: {}
|
|
1093
|
-
mutatedBindings: void 0
|
|
1092
|
+
bindings: {}
|
|
1094
1093
|
};
|
|
1095
1094
|
programScope.bindings.input = {
|
|
1096
1095
|
type: 1 /* param */,
|
|
@@ -1140,7 +1139,7 @@ function crawlProgramScope(parsed, scriptParser) {
|
|
|
1140
1139
|
}
|
|
1141
1140
|
}
|
|
1142
1141
|
if (mutations.length) {
|
|
1143
|
-
return mutations.sort(
|
|
1142
|
+
return mutations.sort(byStart);
|
|
1144
1143
|
}
|
|
1145
1144
|
function visit(body, parentScope) {
|
|
1146
1145
|
var _a2;
|
|
@@ -1182,8 +1181,7 @@ function crawlProgramScope(parsed, scriptParser) {
|
|
|
1182
1181
|
const bodyScope = {
|
|
1183
1182
|
parent: parentScope,
|
|
1184
1183
|
hoists: false,
|
|
1185
|
-
bindings: {}
|
|
1186
|
-
mutatedBindings: void 0
|
|
1184
|
+
bindings: {}
|
|
1187
1185
|
};
|
|
1188
1186
|
if (child.params) {
|
|
1189
1187
|
bodyScope.bindings ??= {};
|
|
@@ -1263,9 +1261,6 @@ ${read({
|
|
|
1263
1261
|
);
|
|
1264
1262
|
if (binding) {
|
|
1265
1263
|
binding.mutated = true;
|
|
1266
|
-
(parentScope.mutatedBindings ||= /* @__PURE__ */ new Set()).add(
|
|
1267
|
-
binding
|
|
1268
|
-
);
|
|
1269
1264
|
}
|
|
1270
1265
|
BoundAttrValueRange.set(attr.value, {
|
|
1271
1266
|
types,
|
|
@@ -1358,6 +1353,21 @@ function getProgramBindings(node) {
|
|
|
1358
1353
|
};
|
|
1359
1354
|
}
|
|
1360
1355
|
}
|
|
1356
|
+
function getMutatedVars(tag) {
|
|
1357
|
+
const { bindings } = Scopes.get(tag.parent.body);
|
|
1358
|
+
let vars;
|
|
1359
|
+
for (const key in bindings) {
|
|
1360
|
+
const binding = bindings[key];
|
|
1361
|
+
if (binding.type == 0 /* var */ && binding.node === tag && binding.mutated) {
|
|
1362
|
+
if (vars) {
|
|
1363
|
+
vars.push(binding);
|
|
1364
|
+
} else {
|
|
1365
|
+
vars = [binding];
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
return vars;
|
|
1370
|
+
}
|
|
1361
1371
|
function getHoistSources(body) {
|
|
1362
1372
|
let result;
|
|
1363
1373
|
if (body) {
|
|
@@ -1374,17 +1384,10 @@ function getHoistSources(body) {
|
|
|
1374
1384
|
}
|
|
1375
1385
|
return result;
|
|
1376
1386
|
}
|
|
1377
|
-
function getMutatedVars(node) {
|
|
1378
|
-
return Scopes.get(node.body).mutatedBindings;
|
|
1379
|
-
}
|
|
1380
1387
|
function isMutatedVar(node, name) {
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
if (binding.name === name) return true;
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
return false;
|
|
1388
|
+
var _a;
|
|
1389
|
+
const binding = (_a = Scopes.get(node.body).bindings) == null ? void 0 : _a[name];
|
|
1390
|
+
return (binding == null ? void 0 : binding.type) === 0 /* var */ && binding.mutated;
|
|
1388
1391
|
}
|
|
1389
1392
|
function hasHoists(node) {
|
|
1390
1393
|
return node.body ? Scopes.get(node.body).hoists : false;
|
|
@@ -1629,12 +1632,11 @@ function trackMutations(node, scope, mutations, parentBlock, parentBlockShadows,
|
|
|
1629
1632
|
}
|
|
1630
1633
|
if (block !== parentBlock && blockMutations.length) {
|
|
1631
1634
|
for (const { name, start } of blockMutations) {
|
|
1632
|
-
if (blockShadows.has(name)) continue;
|
|
1635
|
+
if (start == null || blockShadows.has(name)) continue;
|
|
1633
1636
|
const binding = resolveWritableVar(scope, name);
|
|
1634
1637
|
if (binding) {
|
|
1635
1638
|
binding.mutated = true;
|
|
1636
|
-
mutations.push(start);
|
|
1637
|
-
(scope.mutatedBindings ||= /* @__PURE__ */ new Set()).add(binding);
|
|
1639
|
+
mutations.push({ start, binding });
|
|
1638
1640
|
}
|
|
1639
1641
|
}
|
|
1640
1642
|
}
|
|
@@ -1660,6 +1662,9 @@ function traverse(node, enter) {
|
|
|
1660
1662
|
}
|
|
1661
1663
|
}
|
|
1662
1664
|
}
|
|
1665
|
+
function byStart(a, b) {
|
|
1666
|
+
return a.start - b.start;
|
|
1667
|
+
}
|
|
1663
1668
|
|
|
1664
1669
|
// src/extractors/script/util/get-component-filename.ts
|
|
1665
1670
|
var import_fs = __toESM(require("fs"));
|
|
@@ -2002,6 +2007,9 @@ var REG_OBJECT_PROPERTY = /^[_$a-z][_$a-z0-9]*$/i;
|
|
|
2002
2007
|
var REG_COMMENT_PRAGMA = /\/\/(?:\s*@ts-|\/\s*<)/y;
|
|
2003
2008
|
var REG_TAG_NAME_IDENTIFIER = /^[A-Z][a-zA-Z0-9_$]+$/;
|
|
2004
2009
|
var IF_TAG_ALTERNATES = /* @__PURE__ */ new WeakMap();
|
|
2010
|
+
var TAG_ID = /* @__PURE__ */ new WeakMap();
|
|
2011
|
+
var RENDER_VAR = /* @__PURE__ */ new WeakMap();
|
|
2012
|
+
var TEMPLATE_VAR = /* @__PURE__ */ new WeakMap();
|
|
2005
2013
|
var WROTE_COMMENT = /* @__PURE__ */ new WeakSet();
|
|
2006
2014
|
var START_OF_FILE = { start: 0, end: 0 };
|
|
2007
2015
|
var ScriptLang = /* @__PURE__ */ ((ScriptLang2) => {
|
|
@@ -2022,14 +2030,11 @@ var ScriptExtractor = class {
|
|
|
2022
2030
|
#scriptParser;
|
|
2023
2031
|
#read;
|
|
2024
2032
|
#lookup;
|
|
2025
|
-
#tagIds = /* @__PURE__ */ new Map();
|
|
2026
|
-
#renderIds = /* @__PURE__ */ new Map();
|
|
2027
2033
|
#scriptLang;
|
|
2028
2034
|
#ts;
|
|
2029
2035
|
#runtimeTypes;
|
|
2030
|
-
#
|
|
2036
|
+
#mutations;
|
|
2031
2037
|
#tagId = 1;
|
|
2032
|
-
#renderId = 1;
|
|
2033
2038
|
#closeBrackets = [0];
|
|
2034
2039
|
constructor(opts) {
|
|
2035
2040
|
const { parsed, lookup, scriptLang } = opts;
|
|
@@ -2050,7 +2055,7 @@ var ScriptExtractor = class {
|
|
|
2050
2055
|
this.#extractor = new Extractor(parsed);
|
|
2051
2056
|
this.#scriptParser = new ScriptParser(parsed);
|
|
2052
2057
|
this.#read = parsed.read.bind(parsed);
|
|
2053
|
-
this.#
|
|
2058
|
+
this.#mutations = crawlProgramScope(this.#parsed, this.#scriptParser);
|
|
2054
2059
|
this.#writeProgram(parsed.program);
|
|
2055
2060
|
}
|
|
2056
2061
|
end() {
|
|
@@ -2231,7 +2236,7 @@ function ${templateName}() {
|
|
|
2231
2236
|
}
|
|
2232
2237
|
}
|
|
2233
2238
|
if (body == null ? void 0 : body.content) {
|
|
2234
|
-
this.#writeChildren(
|
|
2239
|
+
this.#writeChildren(body.content);
|
|
2235
2240
|
if (bindings) {
|
|
2236
2241
|
if (bindings.vars) {
|
|
2237
2242
|
for (const name of bindings.vars) {
|
|
@@ -2255,7 +2260,7 @@ function ${templateName}() {
|
|
|
2255
2260
|
`
|
|
2256
2261
|
);
|
|
2257
2262
|
if (didReturn) {
|
|
2258
|
-
this.#extractor.write(`return ${varLocal("return")}
|
|
2263
|
+
this.#extractor.write(`return ${varLocal("return")};
|
|
2259
2264
|
}
|
|
2260
2265
|
`);
|
|
2261
2266
|
} else {
|
|
@@ -2360,7 +2365,7 @@ constructor(_?: Return) {}
|
|
|
2360
2365
|
this.#extractor.copy(returned);
|
|
2361
2366
|
this.#extractor.write(");\n");
|
|
2362
2367
|
}
|
|
2363
|
-
#writeChildren(
|
|
2368
|
+
#writeChildren(children, skipRenderId = false) {
|
|
2364
2369
|
var _a, _b;
|
|
2365
2370
|
const last = children.length - 1;
|
|
2366
2371
|
let returnTag;
|
|
@@ -2376,21 +2381,19 @@ constructor(_?: Return) {}
|
|
|
2376
2381
|
break;
|
|
2377
2382
|
case "if": {
|
|
2378
2383
|
const alternates = IF_TAG_ALTERNATES.get(child);
|
|
2379
|
-
let
|
|
2384
|
+
let didHoist = false;
|
|
2380
2385
|
if (!skipRenderId) {
|
|
2381
|
-
|
|
2382
|
-
if (!
|
|
2386
|
+
didHoist = hasHoists(child);
|
|
2387
|
+
if (!didHoist && alternates) {
|
|
2383
2388
|
for (const { node } of alternates) {
|
|
2384
|
-
if (
|
|
2385
|
-
this.#renderIds.set(child, renderId);
|
|
2386
|
-
this.#renderIds.delete(node);
|
|
2389
|
+
if (didHoist = hasHoists(node)) {
|
|
2387
2390
|
break;
|
|
2388
2391
|
}
|
|
2389
2392
|
}
|
|
2390
2393
|
}
|
|
2391
|
-
if (
|
|
2394
|
+
if (didHoist) {
|
|
2392
2395
|
this.#extractor.write(
|
|
2393
|
-
`const ${
|
|
2396
|
+
`const ${this.#getRenderVar(child, true)} = (() => {
|
|
2394
2397
|
`
|
|
2395
2398
|
);
|
|
2396
2399
|
}
|
|
@@ -2401,7 +2404,7 @@ constructor(_?: Return) {}
|
|
|
2401
2404
|
).write(") {\n");
|
|
2402
2405
|
const ifBody = this.#processBody(child);
|
|
2403
2406
|
if (ifBody == null ? void 0 : ifBody.content) {
|
|
2404
|
-
this.#writeChildren(
|
|
2407
|
+
this.#writeChildren(ifBody.content, true);
|
|
2405
2408
|
const scopeExpr = this.#getScopeExpression(child.body);
|
|
2406
2409
|
if (scopeExpr) {
|
|
2407
2410
|
this.#extractor.write(`return {
|
|
@@ -2425,7 +2428,7 @@ scope: ${scopeExpr}
|
|
|
2425
2428
|
}
|
|
2426
2429
|
const alternateBody = this.#processBody(node);
|
|
2427
2430
|
if (alternateBody == null ? void 0 : alternateBody.content) {
|
|
2428
|
-
this.#writeChildren(
|
|
2431
|
+
this.#writeChildren(alternateBody.content, true);
|
|
2429
2432
|
const scopeExpr = this.#getScopeExpression(node.body);
|
|
2430
2433
|
if (scopeExpr) {
|
|
2431
2434
|
this.#extractor.write(
|
|
@@ -2439,21 +2442,20 @@ scope: ${scopeExpr}
|
|
|
2439
2442
|
}
|
|
2440
2443
|
}
|
|
2441
2444
|
}
|
|
2442
|
-
if (needsAlternate &&
|
|
2445
|
+
if (needsAlternate && didHoist) {
|
|
2443
2446
|
this.#extractor.write("\n} else {\nreturn undefined;\n}\n");
|
|
2444
2447
|
} else {
|
|
2445
2448
|
this.#extractor.write("\n}\n");
|
|
2446
2449
|
}
|
|
2447
|
-
if (
|
|
2450
|
+
if (didHoist) {
|
|
2448
2451
|
this.#extractor.write("\n})();\n");
|
|
2449
2452
|
}
|
|
2450
2453
|
break;
|
|
2451
2454
|
}
|
|
2452
2455
|
case "for": {
|
|
2453
|
-
|
|
2454
|
-
if (renderId) {
|
|
2456
|
+
if (hasHoists(child)) {
|
|
2455
2457
|
this.#extractor.write(
|
|
2456
|
-
`const ${
|
|
2458
|
+
`const ${this.#getRenderVar(child, true)} = `
|
|
2457
2459
|
);
|
|
2458
2460
|
}
|
|
2459
2461
|
this.#extractor.write(
|
|
@@ -2470,7 +2472,7 @@ scope: ${scopeExpr}
|
|
|
2470
2472
|
this.#extractor.write("\n) => {\n");
|
|
2471
2473
|
const body = this.#processBody(child);
|
|
2472
2474
|
if (body == null ? void 0 : body.content) {
|
|
2473
|
-
this.#writeChildren(
|
|
2475
|
+
this.#writeChildren(body.content);
|
|
2474
2476
|
}
|
|
2475
2477
|
this.#writeReturn(void 0, (body == null ? void 0 : body.content) && child.body);
|
|
2476
2478
|
if (body == null ? void 0 : body.content) {
|
|
@@ -2486,7 +2488,7 @@ scope: ${scopeExpr}
|
|
|
2486
2488
|
).write("\n) {\n");
|
|
2487
2489
|
const body = this.#processBody(child);
|
|
2488
2490
|
if (body == null ? void 0 : body.content) {
|
|
2489
|
-
this.#writeChildren(
|
|
2491
|
+
this.#writeChildren(body.content);
|
|
2490
2492
|
this.#endChildren();
|
|
2491
2493
|
}
|
|
2492
2494
|
this.#extractor.write("\n}\n");
|
|
@@ -2505,59 +2507,29 @@ scope: ${scopeExpr}
|
|
|
2505
2507
|
break;
|
|
2506
2508
|
}
|
|
2507
2509
|
}
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
this.#writeTagInputObject(returnTag);
|
|
2515
|
-
this.#extractor.write(")");
|
|
2516
|
-
if (mutatedVars) {
|
|
2517
|
-
this.#extractor.write(",\n");
|
|
2518
|
-
}
|
|
2519
|
-
}
|
|
2520
|
-
if (mutatedVars) {
|
|
2521
|
-
this.#extractor.write(`mutate: ${varShared("mutable")}([
|
|
2522
|
-
`);
|
|
2523
|
-
for (const binding of mutatedVars) {
|
|
2524
|
-
this.#extractor.write(
|
|
2525
|
-
`${// TODO use a different format to avoid const annotation.
|
|
2526
|
-
this.#scriptLang === "js" /* js */ ? "/** @type {const} */" : ""}[${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${varLocal(
|
|
2527
|
-
"rendered_" + this.#getRenderId(binding.node)
|
|
2528
|
-
)}.return${binding.objectPath || ""}]${SEP_COMMA_NEW_LINE}`
|
|
2529
|
-
);
|
|
2530
|
-
}
|
|
2531
|
-
this.#extractor.write(
|
|
2532
|
-
`]${this.#scriptLang === "ts" /* ts */ ? " as const" : ""})`
|
|
2533
|
-
);
|
|
2534
|
-
}
|
|
2535
|
-
this.#extractor.write("\n};\n");
|
|
2536
|
-
if (mutatedVars) {
|
|
2537
|
-
this.#extractor.write(`${varShared("noop")}({
|
|
2538
|
-
`);
|
|
2539
|
-
for (const binding of mutatedVars) {
|
|
2540
|
-
this.#extractor.write(binding.name + SEP_COMMA_NEW_LINE);
|
|
2541
|
-
}
|
|
2542
|
-
this.#extractor.write("});\n");
|
|
2543
|
-
}
|
|
2510
|
+
if (returnTag) {
|
|
2511
|
+
this.#extractor.write(
|
|
2512
|
+
`var ${varLocal("return")} = ${varShared("returnTag")}(`
|
|
2513
|
+
);
|
|
2514
|
+
this.#writeTagInputObject(returnTag);
|
|
2515
|
+
this.#extractor.write(");\n");
|
|
2544
2516
|
}
|
|
2545
2517
|
return returnTag !== void 0;
|
|
2546
2518
|
}
|
|
2547
2519
|
#writeTag(tag) {
|
|
2548
2520
|
const tagName = tag.nameText;
|
|
2549
|
-
const renderId = this.#getRenderId(tag);
|
|
2550
2521
|
const def = tagName ? this.#lookup.getTag(tagName) : void 0;
|
|
2551
2522
|
const importPath = resolveTagImport(this.#filename, def);
|
|
2552
2523
|
const isHTML = !importPath && (def == null ? void 0 : def.html);
|
|
2553
|
-
let tagIdentifier;
|
|
2554
2524
|
let isTemplate = false;
|
|
2525
|
+
let renderVar;
|
|
2526
|
+
let templateVar;
|
|
2555
2527
|
if (!def || importPath) {
|
|
2556
2528
|
const isIdentifier = tagName && REG_TAG_NAME_IDENTIFIER.test(tagName);
|
|
2557
2529
|
const isMarkoFile = importPath == null ? void 0 : importPath.endsWith(".marko");
|
|
2558
2530
|
if (isIdentifier || isMarkoFile || !importPath) {
|
|
2559
|
-
|
|
2560
|
-
this.#extractor.write(`const ${
|
|
2531
|
+
templateVar = this.#getTemplateVar(tag, true);
|
|
2532
|
+
this.#extractor.write(`const ${templateVar} = (
|
|
2561
2533
|
`);
|
|
2562
2534
|
if (isIdentifier) {
|
|
2563
2535
|
if (importPath) {
|
|
@@ -2577,22 +2549,23 @@ scope: ${scopeExpr}
|
|
|
2577
2549
|
}
|
|
2578
2550
|
this.#extractor.write("\n);\n");
|
|
2579
2551
|
} else {
|
|
2580
|
-
|
|
2552
|
+
templateVar = varShared("missingTag");
|
|
2581
2553
|
}
|
|
2582
2554
|
const attrTagTree = this.#getAttrTagTree(tag);
|
|
2583
2555
|
if (attrTagTree) {
|
|
2584
|
-
this.#writeAttrTagTree(attrTagTree,
|
|
2556
|
+
this.#writeAttrTagTree(attrTagTree, templateVar);
|
|
2585
2557
|
this.#extractor.write(";\n");
|
|
2586
2558
|
}
|
|
2587
2559
|
}
|
|
2588
|
-
if (
|
|
2589
|
-
this.#
|
|
2560
|
+
if (!isHTML && tag.var || hasHoists(tag)) {
|
|
2561
|
+
renderVar = this.#getRenderVar(tag, true);
|
|
2562
|
+
this.#extractor.write(`const ${renderVar} = `);
|
|
2590
2563
|
}
|
|
2591
2564
|
if (isHTML) {
|
|
2592
2565
|
this.#extractor.write(`${varShared("renderNativeTag")}("`).copy(isEmptyRange2(tag.name) ? tagName : tag.name).write('")');
|
|
2593
|
-
} else if (
|
|
2566
|
+
} else if (templateVar) {
|
|
2594
2567
|
this.#extractor.write(
|
|
2595
|
-
`${varShared(isTemplate ? "renderTemplate" : "renderDynamicTag")}(${
|
|
2568
|
+
`${varShared(isTemplate ? "renderTemplate" : "renderDynamicTag")}(${templateVar})`
|
|
2596
2569
|
);
|
|
2597
2570
|
} else {
|
|
2598
2571
|
this.#extractor.write(varShared("missingTag"));
|
|
@@ -2604,14 +2577,26 @@ scope: ${scopeExpr}
|
|
|
2604
2577
|
}
|
|
2605
2578
|
this.#writeTagInputObject(tag);
|
|
2606
2579
|
this.#extractor.write(");\n");
|
|
2607
|
-
if (
|
|
2580
|
+
if (tag.var) {
|
|
2608
2581
|
this.#extractor.write(`{const `);
|
|
2609
2582
|
this.#closeBrackets[this.#closeBrackets.length - 1]++;
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2583
|
+
if (renderVar) {
|
|
2584
|
+
const mutatedVars = getMutatedVars(tag);
|
|
2585
|
+
this.#copyWithMutationsReplaced(tag.var.value);
|
|
2586
|
+
this.#extractor.write(` = ${renderVar}.return.${ATTR_UNAMED2};
|
|
2587
|
+
`);
|
|
2588
|
+
if (mutatedVars) {
|
|
2589
|
+
for (const binding of mutatedVars) {
|
|
2590
|
+
this.#extractor.write(
|
|
2591
|
+
`const ${varLocal(`change__${binding.name}`)} = ${varShared("change")}(${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${renderVar}.return${binding.objectPath || ""});
|
|
2613
2592
|
`
|
|
2614
|
-
|
|
2593
|
+
);
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
} else if (isHTML) {
|
|
2597
|
+
this.#extractor.copy(tag.var.value).write(` = ${varShared("el")}(${JSON.stringify(def.name)});
|
|
2598
|
+
`);
|
|
2599
|
+
}
|
|
2615
2600
|
}
|
|
2616
2601
|
}
|
|
2617
2602
|
#endChildren() {
|
|
@@ -2710,7 +2695,7 @@ scope: ${scopeExpr}
|
|
|
2710
2695
|
`Change"(
|
|
2711
2696
|
// @ts-ignore
|
|
2712
2697
|
_${valueLiteral}) {
|
|
2713
|
-
${isMutatedVar(tag.parent, valueLiteral) ?
|
|
2698
|
+
${isMutatedVar(tag.parent, valueLiteral) ? varLocal(`change__${valueLiteral}.`) : ""}`
|
|
2714
2699
|
).copy(boundRange.value).write(`= _${valueLiteral};
|
|
2715
2700
|
}`);
|
|
2716
2701
|
} else if (boundRange.member.computed) {
|
|
@@ -2826,8 +2811,8 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2826
2811
|
this.#writeTagNameComment(firstAttrTag);
|
|
2827
2812
|
this.#extractor.write("]: ");
|
|
2828
2813
|
if (isRepeated) {
|
|
2829
|
-
const
|
|
2830
|
-
if (
|
|
2814
|
+
const templateVar = this.#getTemplateVar(firstAttrTag.owner);
|
|
2815
|
+
if (templateVar) {
|
|
2831
2816
|
let accessor = `"${name}"`;
|
|
2832
2817
|
let curTag = firstAttrTag.parent;
|
|
2833
2818
|
while (curTag) {
|
|
@@ -2839,7 +2824,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2839
2824
|
curTag = curTag.parent;
|
|
2840
2825
|
}
|
|
2841
2826
|
this.#extractor.write(
|
|
2842
|
-
`${varShared("attrTagFor")}(${
|
|
2827
|
+
`${varShared("attrTagFor")}(${templateVar},${accessor})([`
|
|
2843
2828
|
);
|
|
2844
2829
|
} else {
|
|
2845
2830
|
this.#extractor.write(`${varShared("attrTag")}([`);
|
|
@@ -2963,13 +2948,11 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2963
2948
|
if (tag.params || hasBodyContent) {
|
|
2964
2949
|
this.#extractor.write("[");
|
|
2965
2950
|
if (this.#interop) {
|
|
2966
|
-
const
|
|
2951
|
+
const templateVar = this.#getTemplateVar(
|
|
2967
2952
|
tag.type === 16 /* AttrTag */ ? tag.owner : tag
|
|
2968
2953
|
);
|
|
2969
|
-
if (
|
|
2970
|
-
this.#extractor.write(
|
|
2971
|
-
`${varShared("contentFor")}(${varLocal("tag_" + tagId)})`
|
|
2972
|
-
);
|
|
2954
|
+
if (templateVar) {
|
|
2955
|
+
this.#extractor.write(`${varShared("contentFor")}(${templateVar})`);
|
|
2973
2956
|
} else {
|
|
2974
2957
|
this.#extractor.write(varShared("content"));
|
|
2975
2958
|
}
|
|
@@ -2990,16 +2973,13 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2990
2973
|
}
|
|
2991
2974
|
let didReturn = false;
|
|
2992
2975
|
if (body == null ? void 0 : body.content) {
|
|
2993
|
-
didReturn = this.#writeChildren(
|
|
2976
|
+
didReturn = this.#writeChildren(body.content);
|
|
2994
2977
|
}
|
|
2995
2978
|
if (!tag.params) {
|
|
2996
2979
|
this.#extractor.write(`return () => {
|
|
2997
2980
|
`);
|
|
2998
2981
|
}
|
|
2999
|
-
this.#writeReturn(
|
|
3000
|
-
didReturn ? `${varLocal("return")}.return` : void 0,
|
|
3001
|
-
tag.body
|
|
3002
|
-
);
|
|
2982
|
+
this.#writeReturn(didReturn ? varLocal("return") : void 0, tag.body);
|
|
3003
2983
|
if (body == null ? void 0 : body.content) {
|
|
3004
2984
|
this.#endChildren();
|
|
3005
2985
|
}
|
|
@@ -3024,7 +3004,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
3024
3004
|
return this.#scriptLang === "ts" /* ts */ ? `${varShared("any")} as ${type}` : `/** @type {${type}} */(${varShared("any")})`;
|
|
3025
3005
|
}
|
|
3026
3006
|
#copyWithMutationsReplaced(range) {
|
|
3027
|
-
const mutations = this.#
|
|
3007
|
+
const mutations = this.#mutations;
|
|
3028
3008
|
if (!mutations) return this.#extractor.copy(range);
|
|
3029
3009
|
const len = mutations.length;
|
|
3030
3010
|
let curOffset = range.start;
|
|
@@ -3033,23 +3013,23 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
3033
3013
|
let maxIndex = len;
|
|
3034
3014
|
while (minIndex < maxIndex) {
|
|
3035
3015
|
const midIndex = minIndex + maxIndex >>> 1;
|
|
3036
|
-
if (mutations[midIndex] >= curOffset) {
|
|
3016
|
+
if (mutations[midIndex].start >= curOffset) {
|
|
3037
3017
|
maxIndex = midIndex;
|
|
3038
3018
|
} else {
|
|
3039
3019
|
minIndex = midIndex + 1;
|
|
3040
3020
|
}
|
|
3041
3021
|
}
|
|
3042
|
-
const
|
|
3043
|
-
if (
|
|
3022
|
+
const mutation = maxIndex !== len && mutations[maxIndex];
|
|
3023
|
+
if (!mutation || mutation.start >= range.end) {
|
|
3044
3024
|
this.#extractor.copy({
|
|
3045
3025
|
start: curOffset,
|
|
3046
3026
|
end: range.end
|
|
3047
3027
|
});
|
|
3048
3028
|
return;
|
|
3049
3029
|
}
|
|
3050
|
-
this.#extractor.copy({ start: curOffset, end:
|
|
3051
|
-
this.#extractor.write(`${varLocal(
|
|
3052
|
-
curOffset =
|
|
3030
|
+
this.#extractor.copy({ start: curOffset, end: mutation.start });
|
|
3031
|
+
this.#extractor.write(`${varLocal(`change__${mutation.binding.name}`)}.`);
|
|
3032
|
+
curOffset = mutation.start;
|
|
3053
3033
|
minIndex = maxIndex + 1;
|
|
3054
3034
|
} while (true);
|
|
3055
3035
|
}
|
|
@@ -3201,7 +3181,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
3201
3181
|
if (body) {
|
|
3202
3182
|
if (body.content) {
|
|
3203
3183
|
this.#extractor.write("(() => {\n");
|
|
3204
|
-
this.#writeChildren(
|
|
3184
|
+
this.#writeChildren(body.content);
|
|
3205
3185
|
this.#extractor.write("return ");
|
|
3206
3186
|
}
|
|
3207
3187
|
this.#extractor.write("{\n");
|
|
@@ -3303,13 +3283,27 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
3303
3283
|
return tag.name.expressions[0].value;
|
|
3304
3284
|
}
|
|
3305
3285
|
}
|
|
3306
|
-
#
|
|
3307
|
-
let
|
|
3308
|
-
if (!
|
|
3309
|
-
|
|
3310
|
-
|
|
3286
|
+
#getRenderVar(tag, declared = false) {
|
|
3287
|
+
let id = RENDER_VAR.get(tag);
|
|
3288
|
+
if (!id && declared) {
|
|
3289
|
+
RENDER_VAR.set(tag, id = varLocal("rendered_" + this.#getTagId(tag)));
|
|
3290
|
+
}
|
|
3291
|
+
return id;
|
|
3292
|
+
}
|
|
3293
|
+
#getTemplateVar(tag, declared = false) {
|
|
3294
|
+
let id = TEMPLATE_VAR.get(tag);
|
|
3295
|
+
if (!id && declared) {
|
|
3296
|
+
TEMPLATE_VAR.set(tag, id = varLocal("tag_" + this.#getTagId(tag)));
|
|
3297
|
+
}
|
|
3298
|
+
return id;
|
|
3299
|
+
}
|
|
3300
|
+
#getTagId(tag) {
|
|
3301
|
+
let id = TAG_ID.get(tag);
|
|
3302
|
+
if (id === void 0) {
|
|
3303
|
+
id = this.#tagId++;
|
|
3304
|
+
TAG_ID.set(tag, id);
|
|
3311
3305
|
}
|
|
3312
|
-
return
|
|
3306
|
+
return id;
|
|
3313
3307
|
}
|
|
3314
3308
|
#getScopeExpression(body) {
|
|
3315
3309
|
const sources = getHoistSources(body);
|
|
@@ -3317,39 +3311,27 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
3317
3311
|
return sources ? `{ ${hoists ? `...${hoists}, ` : ""}${sources.join(SEP_COMMA_SPACE)} }` : hoists;
|
|
3318
3312
|
}
|
|
3319
3313
|
#getBodyHoistScopeExpression(body) {
|
|
3320
|
-
let
|
|
3314
|
+
let hoistVars;
|
|
3321
3315
|
if (body) {
|
|
3322
3316
|
for (const child of body) {
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
if (
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3317
|
+
if (child.type === 1 /* Tag */) {
|
|
3318
|
+
const renderVar = this.#getRenderVar(child);
|
|
3319
|
+
if (renderVar && (!child.var || hasHoists(child))) {
|
|
3320
|
+
if (hoistVars) {
|
|
3321
|
+
hoistVars.push(renderVar);
|
|
3322
|
+
} else {
|
|
3323
|
+
hoistVars = [renderVar];
|
|
3324
|
+
}
|
|
3329
3325
|
}
|
|
3330
3326
|
}
|
|
3331
3327
|
}
|
|
3332
3328
|
}
|
|
3333
|
-
if (
|
|
3334
|
-
if (
|
|
3335
|
-
return `${varShared("readScope")}(${
|
|
3329
|
+
if (hoistVars) {
|
|
3330
|
+
if (hoistVars.length === 1) {
|
|
3331
|
+
return `${varShared("readScope")}(${hoistVars[0]})`;
|
|
3336
3332
|
}
|
|
3337
|
-
|
|
3338
|
-
let sep = "";
|
|
3339
|
-
for (const renderId of hoistIds) {
|
|
3340
|
-
result += sep + `${varLocal("rendered_" + renderId)}`;
|
|
3341
|
-
sep = SEP_COMMA_SPACE;
|
|
3342
|
-
}
|
|
3343
|
-
return result + " })";
|
|
3344
|
-
}
|
|
3345
|
-
}
|
|
3346
|
-
#ensureTagId(tag) {
|
|
3347
|
-
let tagId = this.#tagIds.get(tag);
|
|
3348
|
-
if (!tagId) {
|
|
3349
|
-
tagId = this.#tagId++;
|
|
3350
|
-
this.#tagIds.set(tag, tagId);
|
|
3333
|
+
return `${varShared("readScopes")}({ ${hoistVars.join(SEP_COMMA_SPACE)} })`;
|
|
3351
3334
|
}
|
|
3352
|
-
return tagId;
|
|
3353
3335
|
}
|
|
3354
3336
|
#getNamedAttrModifierIndex(attr) {
|
|
3355
3337
|
const start = attr.name.start + 1;
|
package/dist/index.mjs
CHANGED
|
@@ -1049,8 +1049,7 @@ function crawlProgramScope(parsed, scriptParser) {
|
|
|
1049
1049
|
const programScope = {
|
|
1050
1050
|
parent: void 0,
|
|
1051
1051
|
hoists: false,
|
|
1052
|
-
bindings: {}
|
|
1053
|
-
mutatedBindings: void 0
|
|
1052
|
+
bindings: {}
|
|
1054
1053
|
};
|
|
1055
1054
|
programScope.bindings.input = {
|
|
1056
1055
|
type: 1 /* param */,
|
|
@@ -1100,7 +1099,7 @@ function crawlProgramScope(parsed, scriptParser) {
|
|
|
1100
1099
|
}
|
|
1101
1100
|
}
|
|
1102
1101
|
if (mutations.length) {
|
|
1103
|
-
return mutations.sort(
|
|
1102
|
+
return mutations.sort(byStart);
|
|
1104
1103
|
}
|
|
1105
1104
|
function visit(body, parentScope) {
|
|
1106
1105
|
var _a2;
|
|
@@ -1142,8 +1141,7 @@ function crawlProgramScope(parsed, scriptParser) {
|
|
|
1142
1141
|
const bodyScope = {
|
|
1143
1142
|
parent: parentScope,
|
|
1144
1143
|
hoists: false,
|
|
1145
|
-
bindings: {}
|
|
1146
|
-
mutatedBindings: void 0
|
|
1144
|
+
bindings: {}
|
|
1147
1145
|
};
|
|
1148
1146
|
if (child.params) {
|
|
1149
1147
|
bodyScope.bindings ??= {};
|
|
@@ -1223,9 +1221,6 @@ ${read({
|
|
|
1223
1221
|
);
|
|
1224
1222
|
if (binding) {
|
|
1225
1223
|
binding.mutated = true;
|
|
1226
|
-
(parentScope.mutatedBindings ||= /* @__PURE__ */ new Set()).add(
|
|
1227
|
-
binding
|
|
1228
|
-
);
|
|
1229
1224
|
}
|
|
1230
1225
|
BoundAttrValueRange.set(attr.value, {
|
|
1231
1226
|
types,
|
|
@@ -1318,6 +1313,21 @@ function getProgramBindings(node) {
|
|
|
1318
1313
|
};
|
|
1319
1314
|
}
|
|
1320
1315
|
}
|
|
1316
|
+
function getMutatedVars(tag) {
|
|
1317
|
+
const { bindings } = Scopes.get(tag.parent.body);
|
|
1318
|
+
let vars;
|
|
1319
|
+
for (const key in bindings) {
|
|
1320
|
+
const binding = bindings[key];
|
|
1321
|
+
if (binding.type == 0 /* var */ && binding.node === tag && binding.mutated) {
|
|
1322
|
+
if (vars) {
|
|
1323
|
+
vars.push(binding);
|
|
1324
|
+
} else {
|
|
1325
|
+
vars = [binding];
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
return vars;
|
|
1330
|
+
}
|
|
1321
1331
|
function getHoistSources(body) {
|
|
1322
1332
|
let result;
|
|
1323
1333
|
if (body) {
|
|
@@ -1334,17 +1344,10 @@ function getHoistSources(body) {
|
|
|
1334
1344
|
}
|
|
1335
1345
|
return result;
|
|
1336
1346
|
}
|
|
1337
|
-
function getMutatedVars(node) {
|
|
1338
|
-
return Scopes.get(node.body).mutatedBindings;
|
|
1339
|
-
}
|
|
1340
1347
|
function isMutatedVar(node, name) {
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
if (binding.name === name) return true;
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
return false;
|
|
1348
|
+
var _a;
|
|
1349
|
+
const binding = (_a = Scopes.get(node.body).bindings) == null ? void 0 : _a[name];
|
|
1350
|
+
return (binding == null ? void 0 : binding.type) === 0 /* var */ && binding.mutated;
|
|
1348
1351
|
}
|
|
1349
1352
|
function hasHoists(node) {
|
|
1350
1353
|
return node.body ? Scopes.get(node.body).hoists : false;
|
|
@@ -1589,12 +1592,11 @@ function trackMutations(node, scope, mutations, parentBlock, parentBlockShadows,
|
|
|
1589
1592
|
}
|
|
1590
1593
|
if (block !== parentBlock && blockMutations.length) {
|
|
1591
1594
|
for (const { name, start } of blockMutations) {
|
|
1592
|
-
if (blockShadows.has(name)) continue;
|
|
1595
|
+
if (start == null || blockShadows.has(name)) continue;
|
|
1593
1596
|
const binding = resolveWritableVar(scope, name);
|
|
1594
1597
|
if (binding) {
|
|
1595
1598
|
binding.mutated = true;
|
|
1596
|
-
mutations.push(start);
|
|
1597
|
-
(scope.mutatedBindings ||= /* @__PURE__ */ new Set()).add(binding);
|
|
1599
|
+
mutations.push({ start, binding });
|
|
1598
1600
|
}
|
|
1599
1601
|
}
|
|
1600
1602
|
}
|
|
@@ -1620,6 +1622,9 @@ function traverse(node, enter) {
|
|
|
1620
1622
|
}
|
|
1621
1623
|
}
|
|
1622
1624
|
}
|
|
1625
|
+
function byStart(a, b) {
|
|
1626
|
+
return a.start - b.start;
|
|
1627
|
+
}
|
|
1623
1628
|
|
|
1624
1629
|
// src/extractors/script/util/get-component-filename.ts
|
|
1625
1630
|
import fs from "fs";
|
|
@@ -1965,6 +1970,9 @@ var REG_OBJECT_PROPERTY = /^[_$a-z][_$a-z0-9]*$/i;
|
|
|
1965
1970
|
var REG_COMMENT_PRAGMA = /\/\/(?:\s*@ts-|\/\s*<)/y;
|
|
1966
1971
|
var REG_TAG_NAME_IDENTIFIER = /^[A-Z][a-zA-Z0-9_$]+$/;
|
|
1967
1972
|
var IF_TAG_ALTERNATES = /* @__PURE__ */ new WeakMap();
|
|
1973
|
+
var TAG_ID = /* @__PURE__ */ new WeakMap();
|
|
1974
|
+
var RENDER_VAR = /* @__PURE__ */ new WeakMap();
|
|
1975
|
+
var TEMPLATE_VAR = /* @__PURE__ */ new WeakMap();
|
|
1968
1976
|
var WROTE_COMMENT = /* @__PURE__ */ new WeakSet();
|
|
1969
1977
|
var START_OF_FILE = { start: 0, end: 0 };
|
|
1970
1978
|
var ScriptLang = /* @__PURE__ */ ((ScriptLang2) => {
|
|
@@ -1985,14 +1993,11 @@ var ScriptExtractor = class {
|
|
|
1985
1993
|
#scriptParser;
|
|
1986
1994
|
#read;
|
|
1987
1995
|
#lookup;
|
|
1988
|
-
#tagIds = /* @__PURE__ */ new Map();
|
|
1989
|
-
#renderIds = /* @__PURE__ */ new Map();
|
|
1990
1996
|
#scriptLang;
|
|
1991
1997
|
#ts;
|
|
1992
1998
|
#runtimeTypes;
|
|
1993
|
-
#
|
|
1999
|
+
#mutations;
|
|
1994
2000
|
#tagId = 1;
|
|
1995
|
-
#renderId = 1;
|
|
1996
2001
|
#closeBrackets = [0];
|
|
1997
2002
|
constructor(opts) {
|
|
1998
2003
|
const { parsed, lookup, scriptLang } = opts;
|
|
@@ -2013,7 +2018,7 @@ var ScriptExtractor = class {
|
|
|
2013
2018
|
this.#extractor = new Extractor(parsed);
|
|
2014
2019
|
this.#scriptParser = new ScriptParser(parsed);
|
|
2015
2020
|
this.#read = parsed.read.bind(parsed);
|
|
2016
|
-
this.#
|
|
2021
|
+
this.#mutations = crawlProgramScope(this.#parsed, this.#scriptParser);
|
|
2017
2022
|
this.#writeProgram(parsed.program);
|
|
2018
2023
|
}
|
|
2019
2024
|
end() {
|
|
@@ -2194,7 +2199,7 @@ function ${templateName}() {
|
|
|
2194
2199
|
}
|
|
2195
2200
|
}
|
|
2196
2201
|
if (body == null ? void 0 : body.content) {
|
|
2197
|
-
this.#writeChildren(
|
|
2202
|
+
this.#writeChildren(body.content);
|
|
2198
2203
|
if (bindings) {
|
|
2199
2204
|
if (bindings.vars) {
|
|
2200
2205
|
for (const name of bindings.vars) {
|
|
@@ -2218,7 +2223,7 @@ function ${templateName}() {
|
|
|
2218
2223
|
`
|
|
2219
2224
|
);
|
|
2220
2225
|
if (didReturn) {
|
|
2221
|
-
this.#extractor.write(`return ${varLocal("return")}
|
|
2226
|
+
this.#extractor.write(`return ${varLocal("return")};
|
|
2222
2227
|
}
|
|
2223
2228
|
`);
|
|
2224
2229
|
} else {
|
|
@@ -2323,7 +2328,7 @@ constructor(_?: Return) {}
|
|
|
2323
2328
|
this.#extractor.copy(returned);
|
|
2324
2329
|
this.#extractor.write(");\n");
|
|
2325
2330
|
}
|
|
2326
|
-
#writeChildren(
|
|
2331
|
+
#writeChildren(children, skipRenderId = false) {
|
|
2327
2332
|
var _a, _b;
|
|
2328
2333
|
const last = children.length - 1;
|
|
2329
2334
|
let returnTag;
|
|
@@ -2339,21 +2344,19 @@ constructor(_?: Return) {}
|
|
|
2339
2344
|
break;
|
|
2340
2345
|
case "if": {
|
|
2341
2346
|
const alternates = IF_TAG_ALTERNATES.get(child);
|
|
2342
|
-
let
|
|
2347
|
+
let didHoist = false;
|
|
2343
2348
|
if (!skipRenderId) {
|
|
2344
|
-
|
|
2345
|
-
if (!
|
|
2349
|
+
didHoist = hasHoists(child);
|
|
2350
|
+
if (!didHoist && alternates) {
|
|
2346
2351
|
for (const { node } of alternates) {
|
|
2347
|
-
if (
|
|
2348
|
-
this.#renderIds.set(child, renderId);
|
|
2349
|
-
this.#renderIds.delete(node);
|
|
2352
|
+
if (didHoist = hasHoists(node)) {
|
|
2350
2353
|
break;
|
|
2351
2354
|
}
|
|
2352
2355
|
}
|
|
2353
2356
|
}
|
|
2354
|
-
if (
|
|
2357
|
+
if (didHoist) {
|
|
2355
2358
|
this.#extractor.write(
|
|
2356
|
-
`const ${
|
|
2359
|
+
`const ${this.#getRenderVar(child, true)} = (() => {
|
|
2357
2360
|
`
|
|
2358
2361
|
);
|
|
2359
2362
|
}
|
|
@@ -2364,7 +2367,7 @@ constructor(_?: Return) {}
|
|
|
2364
2367
|
).write(") {\n");
|
|
2365
2368
|
const ifBody = this.#processBody(child);
|
|
2366
2369
|
if (ifBody == null ? void 0 : ifBody.content) {
|
|
2367
|
-
this.#writeChildren(
|
|
2370
|
+
this.#writeChildren(ifBody.content, true);
|
|
2368
2371
|
const scopeExpr = this.#getScopeExpression(child.body);
|
|
2369
2372
|
if (scopeExpr) {
|
|
2370
2373
|
this.#extractor.write(`return {
|
|
@@ -2388,7 +2391,7 @@ scope: ${scopeExpr}
|
|
|
2388
2391
|
}
|
|
2389
2392
|
const alternateBody = this.#processBody(node);
|
|
2390
2393
|
if (alternateBody == null ? void 0 : alternateBody.content) {
|
|
2391
|
-
this.#writeChildren(
|
|
2394
|
+
this.#writeChildren(alternateBody.content, true);
|
|
2392
2395
|
const scopeExpr = this.#getScopeExpression(node.body);
|
|
2393
2396
|
if (scopeExpr) {
|
|
2394
2397
|
this.#extractor.write(
|
|
@@ -2402,21 +2405,20 @@ scope: ${scopeExpr}
|
|
|
2402
2405
|
}
|
|
2403
2406
|
}
|
|
2404
2407
|
}
|
|
2405
|
-
if (needsAlternate &&
|
|
2408
|
+
if (needsAlternate && didHoist) {
|
|
2406
2409
|
this.#extractor.write("\n} else {\nreturn undefined;\n}\n");
|
|
2407
2410
|
} else {
|
|
2408
2411
|
this.#extractor.write("\n}\n");
|
|
2409
2412
|
}
|
|
2410
|
-
if (
|
|
2413
|
+
if (didHoist) {
|
|
2411
2414
|
this.#extractor.write("\n})();\n");
|
|
2412
2415
|
}
|
|
2413
2416
|
break;
|
|
2414
2417
|
}
|
|
2415
2418
|
case "for": {
|
|
2416
|
-
|
|
2417
|
-
if (renderId) {
|
|
2419
|
+
if (hasHoists(child)) {
|
|
2418
2420
|
this.#extractor.write(
|
|
2419
|
-
`const ${
|
|
2421
|
+
`const ${this.#getRenderVar(child, true)} = `
|
|
2420
2422
|
);
|
|
2421
2423
|
}
|
|
2422
2424
|
this.#extractor.write(
|
|
@@ -2433,7 +2435,7 @@ scope: ${scopeExpr}
|
|
|
2433
2435
|
this.#extractor.write("\n) => {\n");
|
|
2434
2436
|
const body = this.#processBody(child);
|
|
2435
2437
|
if (body == null ? void 0 : body.content) {
|
|
2436
|
-
this.#writeChildren(
|
|
2438
|
+
this.#writeChildren(body.content);
|
|
2437
2439
|
}
|
|
2438
2440
|
this.#writeReturn(void 0, (body == null ? void 0 : body.content) && child.body);
|
|
2439
2441
|
if (body == null ? void 0 : body.content) {
|
|
@@ -2449,7 +2451,7 @@ scope: ${scopeExpr}
|
|
|
2449
2451
|
).write("\n) {\n");
|
|
2450
2452
|
const body = this.#processBody(child);
|
|
2451
2453
|
if (body == null ? void 0 : body.content) {
|
|
2452
|
-
this.#writeChildren(
|
|
2454
|
+
this.#writeChildren(body.content);
|
|
2453
2455
|
this.#endChildren();
|
|
2454
2456
|
}
|
|
2455
2457
|
this.#extractor.write("\n}\n");
|
|
@@ -2468,59 +2470,29 @@ scope: ${scopeExpr}
|
|
|
2468
2470
|
break;
|
|
2469
2471
|
}
|
|
2470
2472
|
}
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
this.#writeTagInputObject(returnTag);
|
|
2478
|
-
this.#extractor.write(")");
|
|
2479
|
-
if (mutatedVars) {
|
|
2480
|
-
this.#extractor.write(",\n");
|
|
2481
|
-
}
|
|
2482
|
-
}
|
|
2483
|
-
if (mutatedVars) {
|
|
2484
|
-
this.#extractor.write(`mutate: ${varShared("mutable")}([
|
|
2485
|
-
`);
|
|
2486
|
-
for (const binding of mutatedVars) {
|
|
2487
|
-
this.#extractor.write(
|
|
2488
|
-
`${// TODO use a different format to avoid const annotation.
|
|
2489
|
-
this.#scriptLang === "js" /* js */ ? "/** @type {const} */" : ""}[${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${varLocal(
|
|
2490
|
-
"rendered_" + this.#getRenderId(binding.node)
|
|
2491
|
-
)}.return${binding.objectPath || ""}]${SEP_COMMA_NEW_LINE}`
|
|
2492
|
-
);
|
|
2493
|
-
}
|
|
2494
|
-
this.#extractor.write(
|
|
2495
|
-
`]${this.#scriptLang === "ts" /* ts */ ? " as const" : ""})`
|
|
2496
|
-
);
|
|
2497
|
-
}
|
|
2498
|
-
this.#extractor.write("\n};\n");
|
|
2499
|
-
if (mutatedVars) {
|
|
2500
|
-
this.#extractor.write(`${varShared("noop")}({
|
|
2501
|
-
`);
|
|
2502
|
-
for (const binding of mutatedVars) {
|
|
2503
|
-
this.#extractor.write(binding.name + SEP_COMMA_NEW_LINE);
|
|
2504
|
-
}
|
|
2505
|
-
this.#extractor.write("});\n");
|
|
2506
|
-
}
|
|
2473
|
+
if (returnTag) {
|
|
2474
|
+
this.#extractor.write(
|
|
2475
|
+
`var ${varLocal("return")} = ${varShared("returnTag")}(`
|
|
2476
|
+
);
|
|
2477
|
+
this.#writeTagInputObject(returnTag);
|
|
2478
|
+
this.#extractor.write(");\n");
|
|
2507
2479
|
}
|
|
2508
2480
|
return returnTag !== void 0;
|
|
2509
2481
|
}
|
|
2510
2482
|
#writeTag(tag) {
|
|
2511
2483
|
const tagName = tag.nameText;
|
|
2512
|
-
const renderId = this.#getRenderId(tag);
|
|
2513
2484
|
const def = tagName ? this.#lookup.getTag(tagName) : void 0;
|
|
2514
2485
|
const importPath = resolveTagImport(this.#filename, def);
|
|
2515
2486
|
const isHTML = !importPath && (def == null ? void 0 : def.html);
|
|
2516
|
-
let tagIdentifier;
|
|
2517
2487
|
let isTemplate = false;
|
|
2488
|
+
let renderVar;
|
|
2489
|
+
let templateVar;
|
|
2518
2490
|
if (!def || importPath) {
|
|
2519
2491
|
const isIdentifier = tagName && REG_TAG_NAME_IDENTIFIER.test(tagName);
|
|
2520
2492
|
const isMarkoFile = importPath == null ? void 0 : importPath.endsWith(".marko");
|
|
2521
2493
|
if (isIdentifier || isMarkoFile || !importPath) {
|
|
2522
|
-
|
|
2523
|
-
this.#extractor.write(`const ${
|
|
2494
|
+
templateVar = this.#getTemplateVar(tag, true);
|
|
2495
|
+
this.#extractor.write(`const ${templateVar} = (
|
|
2524
2496
|
`);
|
|
2525
2497
|
if (isIdentifier) {
|
|
2526
2498
|
if (importPath) {
|
|
@@ -2540,22 +2512,23 @@ scope: ${scopeExpr}
|
|
|
2540
2512
|
}
|
|
2541
2513
|
this.#extractor.write("\n);\n");
|
|
2542
2514
|
} else {
|
|
2543
|
-
|
|
2515
|
+
templateVar = varShared("missingTag");
|
|
2544
2516
|
}
|
|
2545
2517
|
const attrTagTree = this.#getAttrTagTree(tag);
|
|
2546
2518
|
if (attrTagTree) {
|
|
2547
|
-
this.#writeAttrTagTree(attrTagTree,
|
|
2519
|
+
this.#writeAttrTagTree(attrTagTree, templateVar);
|
|
2548
2520
|
this.#extractor.write(";\n");
|
|
2549
2521
|
}
|
|
2550
2522
|
}
|
|
2551
|
-
if (
|
|
2552
|
-
this.#
|
|
2523
|
+
if (!isHTML && tag.var || hasHoists(tag)) {
|
|
2524
|
+
renderVar = this.#getRenderVar(tag, true);
|
|
2525
|
+
this.#extractor.write(`const ${renderVar} = `);
|
|
2553
2526
|
}
|
|
2554
2527
|
if (isHTML) {
|
|
2555
2528
|
this.#extractor.write(`${varShared("renderNativeTag")}("`).copy(isEmptyRange2(tag.name) ? tagName : tag.name).write('")');
|
|
2556
|
-
} else if (
|
|
2529
|
+
} else if (templateVar) {
|
|
2557
2530
|
this.#extractor.write(
|
|
2558
|
-
`${varShared(isTemplate ? "renderTemplate" : "renderDynamicTag")}(${
|
|
2531
|
+
`${varShared(isTemplate ? "renderTemplate" : "renderDynamicTag")}(${templateVar})`
|
|
2559
2532
|
);
|
|
2560
2533
|
} else {
|
|
2561
2534
|
this.#extractor.write(varShared("missingTag"));
|
|
@@ -2567,14 +2540,26 @@ scope: ${scopeExpr}
|
|
|
2567
2540
|
}
|
|
2568
2541
|
this.#writeTagInputObject(tag);
|
|
2569
2542
|
this.#extractor.write(");\n");
|
|
2570
|
-
if (
|
|
2543
|
+
if (tag.var) {
|
|
2571
2544
|
this.#extractor.write(`{const `);
|
|
2572
2545
|
this.#closeBrackets[this.#closeBrackets.length - 1]++;
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2546
|
+
if (renderVar) {
|
|
2547
|
+
const mutatedVars = getMutatedVars(tag);
|
|
2548
|
+
this.#copyWithMutationsReplaced(tag.var.value);
|
|
2549
|
+
this.#extractor.write(` = ${renderVar}.return.${ATTR_UNAMED2};
|
|
2550
|
+
`);
|
|
2551
|
+
if (mutatedVars) {
|
|
2552
|
+
for (const binding of mutatedVars) {
|
|
2553
|
+
this.#extractor.write(
|
|
2554
|
+
`const ${varLocal(`change__${binding.name}`)} = ${varShared("change")}(${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${renderVar}.return${binding.objectPath || ""});
|
|
2576
2555
|
`
|
|
2577
|
-
|
|
2556
|
+
);
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
} else if (isHTML) {
|
|
2560
|
+
this.#extractor.copy(tag.var.value).write(` = ${varShared("el")}(${JSON.stringify(def.name)});
|
|
2561
|
+
`);
|
|
2562
|
+
}
|
|
2578
2563
|
}
|
|
2579
2564
|
}
|
|
2580
2565
|
#endChildren() {
|
|
@@ -2673,7 +2658,7 @@ scope: ${scopeExpr}
|
|
|
2673
2658
|
`Change"(
|
|
2674
2659
|
// @ts-ignore
|
|
2675
2660
|
_${valueLiteral}) {
|
|
2676
|
-
${isMutatedVar(tag.parent, valueLiteral) ?
|
|
2661
|
+
${isMutatedVar(tag.parent, valueLiteral) ? varLocal(`change__${valueLiteral}.`) : ""}`
|
|
2677
2662
|
).copy(boundRange.value).write(`= _${valueLiteral};
|
|
2678
2663
|
}`);
|
|
2679
2664
|
} else if (boundRange.member.computed) {
|
|
@@ -2789,8 +2774,8 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2789
2774
|
this.#writeTagNameComment(firstAttrTag);
|
|
2790
2775
|
this.#extractor.write("]: ");
|
|
2791
2776
|
if (isRepeated) {
|
|
2792
|
-
const
|
|
2793
|
-
if (
|
|
2777
|
+
const templateVar = this.#getTemplateVar(firstAttrTag.owner);
|
|
2778
|
+
if (templateVar) {
|
|
2794
2779
|
let accessor = `"${name}"`;
|
|
2795
2780
|
let curTag = firstAttrTag.parent;
|
|
2796
2781
|
while (curTag) {
|
|
@@ -2802,7 +2787,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2802
2787
|
curTag = curTag.parent;
|
|
2803
2788
|
}
|
|
2804
2789
|
this.#extractor.write(
|
|
2805
|
-
`${varShared("attrTagFor")}(${
|
|
2790
|
+
`${varShared("attrTagFor")}(${templateVar},${accessor})([`
|
|
2806
2791
|
);
|
|
2807
2792
|
} else {
|
|
2808
2793
|
this.#extractor.write(`${varShared("attrTag")}([`);
|
|
@@ -2926,13 +2911,11 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2926
2911
|
if (tag.params || hasBodyContent) {
|
|
2927
2912
|
this.#extractor.write("[");
|
|
2928
2913
|
if (this.#interop) {
|
|
2929
|
-
const
|
|
2914
|
+
const templateVar = this.#getTemplateVar(
|
|
2930
2915
|
tag.type === 16 /* AttrTag */ ? tag.owner : tag
|
|
2931
2916
|
);
|
|
2932
|
-
if (
|
|
2933
|
-
this.#extractor.write(
|
|
2934
|
-
`${varShared("contentFor")}(${varLocal("tag_" + tagId)})`
|
|
2935
|
-
);
|
|
2917
|
+
if (templateVar) {
|
|
2918
|
+
this.#extractor.write(`${varShared("contentFor")}(${templateVar})`);
|
|
2936
2919
|
} else {
|
|
2937
2920
|
this.#extractor.write(varShared("content"));
|
|
2938
2921
|
}
|
|
@@ -2953,16 +2936,13 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2953
2936
|
}
|
|
2954
2937
|
let didReturn = false;
|
|
2955
2938
|
if (body == null ? void 0 : body.content) {
|
|
2956
|
-
didReturn = this.#writeChildren(
|
|
2939
|
+
didReturn = this.#writeChildren(body.content);
|
|
2957
2940
|
}
|
|
2958
2941
|
if (!tag.params) {
|
|
2959
2942
|
this.#extractor.write(`return () => {
|
|
2960
2943
|
`);
|
|
2961
2944
|
}
|
|
2962
|
-
this.#writeReturn(
|
|
2963
|
-
didReturn ? `${varLocal("return")}.return` : void 0,
|
|
2964
|
-
tag.body
|
|
2965
|
-
);
|
|
2945
|
+
this.#writeReturn(didReturn ? varLocal("return") : void 0, tag.body);
|
|
2966
2946
|
if (body == null ? void 0 : body.content) {
|
|
2967
2947
|
this.#endChildren();
|
|
2968
2948
|
}
|
|
@@ -2987,7 +2967,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2987
2967
|
return this.#scriptLang === "ts" /* ts */ ? `${varShared("any")} as ${type}` : `/** @type {${type}} */(${varShared("any")})`;
|
|
2988
2968
|
}
|
|
2989
2969
|
#copyWithMutationsReplaced(range) {
|
|
2990
|
-
const mutations = this.#
|
|
2970
|
+
const mutations = this.#mutations;
|
|
2991
2971
|
if (!mutations) return this.#extractor.copy(range);
|
|
2992
2972
|
const len = mutations.length;
|
|
2993
2973
|
let curOffset = range.start;
|
|
@@ -2996,23 +2976,23 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2996
2976
|
let maxIndex = len;
|
|
2997
2977
|
while (minIndex < maxIndex) {
|
|
2998
2978
|
const midIndex = minIndex + maxIndex >>> 1;
|
|
2999
|
-
if (mutations[midIndex] >= curOffset) {
|
|
2979
|
+
if (mutations[midIndex].start >= curOffset) {
|
|
3000
2980
|
maxIndex = midIndex;
|
|
3001
2981
|
} else {
|
|
3002
2982
|
minIndex = midIndex + 1;
|
|
3003
2983
|
}
|
|
3004
2984
|
}
|
|
3005
|
-
const
|
|
3006
|
-
if (
|
|
2985
|
+
const mutation = maxIndex !== len && mutations[maxIndex];
|
|
2986
|
+
if (!mutation || mutation.start >= range.end) {
|
|
3007
2987
|
this.#extractor.copy({
|
|
3008
2988
|
start: curOffset,
|
|
3009
2989
|
end: range.end
|
|
3010
2990
|
});
|
|
3011
2991
|
return;
|
|
3012
2992
|
}
|
|
3013
|
-
this.#extractor.copy({ start: curOffset, end:
|
|
3014
|
-
this.#extractor.write(`${varLocal(
|
|
3015
|
-
curOffset =
|
|
2993
|
+
this.#extractor.copy({ start: curOffset, end: mutation.start });
|
|
2994
|
+
this.#extractor.write(`${varLocal(`change__${mutation.binding.name}`)}.`);
|
|
2995
|
+
curOffset = mutation.start;
|
|
3016
2996
|
minIndex = maxIndex + 1;
|
|
3017
2997
|
} while (true);
|
|
3018
2998
|
}
|
|
@@ -3164,7 +3144,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
3164
3144
|
if (body) {
|
|
3165
3145
|
if (body.content) {
|
|
3166
3146
|
this.#extractor.write("(() => {\n");
|
|
3167
|
-
this.#writeChildren(
|
|
3147
|
+
this.#writeChildren(body.content);
|
|
3168
3148
|
this.#extractor.write("return ");
|
|
3169
3149
|
}
|
|
3170
3150
|
this.#extractor.write("{\n");
|
|
@@ -3266,13 +3246,27 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
3266
3246
|
return tag.name.expressions[0].value;
|
|
3267
3247
|
}
|
|
3268
3248
|
}
|
|
3269
|
-
#
|
|
3270
|
-
let
|
|
3271
|
-
if (!
|
|
3272
|
-
|
|
3273
|
-
|
|
3249
|
+
#getRenderVar(tag, declared = false) {
|
|
3250
|
+
let id = RENDER_VAR.get(tag);
|
|
3251
|
+
if (!id && declared) {
|
|
3252
|
+
RENDER_VAR.set(tag, id = varLocal("rendered_" + this.#getTagId(tag)));
|
|
3253
|
+
}
|
|
3254
|
+
return id;
|
|
3255
|
+
}
|
|
3256
|
+
#getTemplateVar(tag, declared = false) {
|
|
3257
|
+
let id = TEMPLATE_VAR.get(tag);
|
|
3258
|
+
if (!id && declared) {
|
|
3259
|
+
TEMPLATE_VAR.set(tag, id = varLocal("tag_" + this.#getTagId(tag)));
|
|
3260
|
+
}
|
|
3261
|
+
return id;
|
|
3262
|
+
}
|
|
3263
|
+
#getTagId(tag) {
|
|
3264
|
+
let id = TAG_ID.get(tag);
|
|
3265
|
+
if (id === void 0) {
|
|
3266
|
+
id = this.#tagId++;
|
|
3267
|
+
TAG_ID.set(tag, id);
|
|
3274
3268
|
}
|
|
3275
|
-
return
|
|
3269
|
+
return id;
|
|
3276
3270
|
}
|
|
3277
3271
|
#getScopeExpression(body) {
|
|
3278
3272
|
const sources = getHoistSources(body);
|
|
@@ -3280,39 +3274,27 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
3280
3274
|
return sources ? `{ ${hoists ? `...${hoists}, ` : ""}${sources.join(SEP_COMMA_SPACE)} }` : hoists;
|
|
3281
3275
|
}
|
|
3282
3276
|
#getBodyHoistScopeExpression(body) {
|
|
3283
|
-
let
|
|
3277
|
+
let hoistVars;
|
|
3284
3278
|
if (body) {
|
|
3285
3279
|
for (const child of body) {
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
if (
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3280
|
+
if (child.type === 1 /* Tag */) {
|
|
3281
|
+
const renderVar = this.#getRenderVar(child);
|
|
3282
|
+
if (renderVar && (!child.var || hasHoists(child))) {
|
|
3283
|
+
if (hoistVars) {
|
|
3284
|
+
hoistVars.push(renderVar);
|
|
3285
|
+
} else {
|
|
3286
|
+
hoistVars = [renderVar];
|
|
3287
|
+
}
|
|
3292
3288
|
}
|
|
3293
3289
|
}
|
|
3294
3290
|
}
|
|
3295
3291
|
}
|
|
3296
|
-
if (
|
|
3297
|
-
if (
|
|
3298
|
-
return `${varShared("readScope")}(${
|
|
3292
|
+
if (hoistVars) {
|
|
3293
|
+
if (hoistVars.length === 1) {
|
|
3294
|
+
return `${varShared("readScope")}(${hoistVars[0]})`;
|
|
3299
3295
|
}
|
|
3300
|
-
|
|
3301
|
-
let sep = "";
|
|
3302
|
-
for (const renderId of hoistIds) {
|
|
3303
|
-
result += sep + `${varLocal("rendered_" + renderId)}`;
|
|
3304
|
-
sep = SEP_COMMA_SPACE;
|
|
3305
|
-
}
|
|
3306
|
-
return result + " })";
|
|
3307
|
-
}
|
|
3308
|
-
}
|
|
3309
|
-
#ensureTagId(tag) {
|
|
3310
|
-
let tagId = this.#tagIds.get(tag);
|
|
3311
|
-
if (!tagId) {
|
|
3312
|
-
tagId = this.#tagId++;
|
|
3313
|
-
this.#tagIds.set(tag, tagId);
|
|
3296
|
+
return `${varShared("readScopes")}({ ${hoistVars.join(SEP_COMMA_SPACE)} })`;
|
|
3314
3297
|
}
|
|
3315
|
-
return tagId;
|
|
3316
3298
|
}
|
|
3317
3299
|
#getNamedAttrModifierIndex(attr) {
|
|
3318
3300
|
const start = attr.name.start + 1;
|
package/marko.internal.d.ts
CHANGED
|
@@ -41,6 +41,10 @@ declare global {
|
|
|
41
41
|
|
|
42
42
|
export const content: DefaultBodyContentKey;
|
|
43
43
|
|
|
44
|
+
export function el<Name extends string>(
|
|
45
|
+
name: Name,
|
|
46
|
+
): Marko.NativeTags[Name]["return"]["value"];
|
|
47
|
+
|
|
44
48
|
export function contentFor<Name>(
|
|
45
49
|
tag: Name,
|
|
46
50
|
): [0] extends [1 & Name]
|
|
@@ -122,19 +126,21 @@ declare global {
|
|
|
122
126
|
: never
|
|
123
127
|
>;
|
|
124
128
|
|
|
125
|
-
export function
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
export function change<const Item>(...item: Item): UnionToIntersection<
|
|
130
|
+
Item extends
|
|
131
|
+
| readonly [infer LocalName extends string, infer Data]
|
|
132
|
+
| readonly [
|
|
133
|
+
infer LocalName extends string,
|
|
134
|
+
infer SourceName,
|
|
135
|
+
infer Data,
|
|
136
|
+
]
|
|
137
|
+
? Data extends {
|
|
138
|
+
[K in `${SourceName extends string
|
|
139
|
+
? SourceName
|
|
140
|
+
: LocalName}Change`]: (value: infer V, ...args: any[]) => any;
|
|
141
|
+
}
|
|
142
|
+
? { [K in LocalName]: V }
|
|
143
|
+
: { readonly [K in LocalName]: unknown }
|
|
138
144
|
: never
|
|
139
145
|
>;
|
|
140
146
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/language-tools",
|
|
3
3
|
"description": "Marko Language Tools",
|
|
4
|
-
"version": "2.5.
|
|
4
|
+
"version": "2.5.45",
|
|
5
5
|
"bugs": "https://github.com/marko-js/language-server/issues/new?template=Bug_report.md",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@marko/compiler": "^5.28.4"
|