@marko/language-tools 2.5.15 → 2.5.17

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/index.js CHANGED
@@ -2151,11 +2151,19 @@ function ${templateName}() {
2151
2151
  if (hoists) {
2152
2152
  this.#extractor.write("const ");
2153
2153
  this.#writeObjectKeys(hoists);
2154
- this.#extractor.write(
2155
- ` = ${varShared("readScopes")}(${varShared("rendered")});
2156
- `
2157
- );
2158
- this.#extractor.write(`${varShared("noop")}(`);
2154
+ this.#extractor.write(` = ${varShared("readScopes")}({`);
2155
+ for (const child of program.body) {
2156
+ if (child.type === 1 /* Tag */) {
2157
+ const renderId = this.#renderIds.get(child);
2158
+ if (renderId !== void 0) {
2159
+ this.#extractor.write(
2160
+ `${varLocal("rendered_" + renderId)}${SEP_COMMA_SPACE}`
2161
+ );
2162
+ }
2163
+ }
2164
+ }
2165
+ this.#extractor.write(`});
2166
+ ${varShared("noop")}(`);
2159
2167
  this.#writeObjectKeys(hoists);
2160
2168
  this.#extractor.write(");\n");
2161
2169
  }
@@ -2271,9 +2279,7 @@ constructor(_?: Return) {}
2271
2279
  }
2272
2280
  if (renderId) {
2273
2281
  this.#extractor.write(
2274
- `${varShared("assertRendered")}(${varShared(
2275
- "rendered"
2276
- )}, ${renderId}, (() => {
2282
+ `const ${varLocal("rendered_" + renderId)} = (() => {
2277
2283
  `
2278
2284
  );
2279
2285
  }
@@ -2322,7 +2328,7 @@ constructor(_?: Return) {}
2322
2328
  this.#extractor.write("\n}\n");
2323
2329
  }
2324
2330
  if (renderId) {
2325
- this.#extractor.write("\n})())\n");
2331
+ this.#extractor.write("\n})()\n");
2326
2332
  }
2327
2333
  break;
2328
2334
  }
@@ -2330,9 +2336,7 @@ constructor(_?: Return) {}
2330
2336
  const renderId = this.#getRenderId(child);
2331
2337
  if (renderId) {
2332
2338
  this.#extractor.write(
2333
- `${varShared("assertRendered")}(${varShared(
2334
- "rendered"
2335
- )}, ${renderId}, `
2339
+ `const ${varLocal("rendered_" + renderId)} = `
2336
2340
  );
2337
2341
  }
2338
2342
  this.#extractor.write(
@@ -2355,11 +2359,7 @@ constructor(_?: Return) {}
2355
2359
  void 0,
2356
2360
  (body == null ? void 0 : body.content) ? getHoistSources(child) : void 0
2357
2361
  );
2358
- if (renderId) {
2359
- this.#extractor.write("\n}));\n");
2360
- } else {
2361
- this.#extractor.write("\n});\n");
2362
- }
2362
+ this.#extractor.write("\n});\n");
2363
2363
  break;
2364
2364
  }
2365
2365
  case "while": {
@@ -2405,9 +2405,9 @@ constructor(_?: Return) {}
2405
2405
  for (const binding of mutatedVars) {
2406
2406
  this.#extractor.write(
2407
2407
  `${// TODO use a different format to avoid const annotation.
2408
- this.#scriptLang === "js" /* js */ ? "/** @type {const} */" : ""}[${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${varShared("rendered")}.returns[${this.#getRenderId(
2409
- binding.node
2410
- )}]${binding.objectPath || ""}]${SEP_COMMA_NEW_LINE}`
2408
+ this.#scriptLang === "js" /* js */ ? "/** @type {const} */" : ""}[${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${varLocal(
2409
+ "rendered_" + this.#getRenderId(binding.node)
2410
+ )}.return${binding.objectPath || ""}]${SEP_COMMA_NEW_LINE}`
2411
2411
  );
2412
2412
  }
2413
2413
  this.#extractor.write(
@@ -2431,31 +2431,36 @@ constructor(_?: Return) {}
2431
2431
  const renderId = this.#getRenderId(tag);
2432
2432
  const def = tagName ? this.#lookup.getTag(tagName) : void 0;
2433
2433
  const isHTML = def == null ? void 0 : def.html;
2434
- const importPath = !isHTML && resolveTagImport(this.#filename, def);
2434
+ const importPath = !isHTML ? resolveTagImport(this.#filename, def) : void 0;
2435
2435
  let tagIdentifier;
2436
2436
  let isTemplate = false;
2437
2437
  if (!isHTML && (!def || importPath)) {
2438
- const tagId = this.#ensureTagId(tag);
2439
- tagIdentifier = varLocal("tag_" + tagId);
2440
- this.#extractor.write(`const ${tagIdentifier} = (
2438
+ const isIdentifier = tagName && REG_TAG_NAME_IDENTIFIER.test(tagName);
2439
+ const isMarkoFile = importPath == null ? void 0 : importPath.endsWith(".marko");
2440
+ if (isIdentifier || isMarkoFile || !importPath) {
2441
+ tagIdentifier = varLocal("tag_" + this.#ensureTagId(tag));
2442
+ this.#extractor.write(`const ${tagIdentifier} = (
2441
2443
  `);
2442
- if (tagName && REG_TAG_NAME_IDENTIFIER.test(tagName)) {
2443
- if (importPath) {
2444
+ if (isIdentifier) {
2445
+ if (importPath) {
2446
+ this.#extractor.write(
2447
+ `${varShared("fallbackTemplate")}(${tagName},${isMarkoFile ? `import("${importPath}")` : varShared("any")})`
2448
+ );
2449
+ } else {
2450
+ this.#extractor.copy(tag.name);
2451
+ }
2452
+ } else if (isMarkoFile) {
2453
+ isTemplate = true;
2444
2454
  this.#extractor.write(
2445
- `${varShared("fallbackTemplate")}(${tagName},import("${importPath}"))`
2455
+ `${varShared("resolveTemplate")}(import("${importPath}"))`
2446
2456
  );
2447
2457
  } else {
2448
- this.#extractor.copy(tag.name);
2458
+ this.#writeDynamicTagName(tag);
2449
2459
  }
2450
- } else if (importPath) {
2451
- isTemplate = importPath.endsWith(".marko");
2452
- this.#extractor.write(
2453
- `${varShared("resolveTemplate")}(import("${importPath}"))`
2454
- );
2460
+ this.#extractor.write("\n);\n");
2455
2461
  } else {
2456
- this.#writeDynamicTagName(tag);
2462
+ tagIdentifier = varShared("missingTag");
2457
2463
  }
2458
- this.#extractor.write("\n);\n");
2459
2464
  const attrTagTree = this.#getAttrTagTree(tag);
2460
2465
  if (attrTagTree) {
2461
2466
  this.#writeAttrTagTree(attrTagTree, tagIdentifier);
@@ -2463,9 +2468,7 @@ constructor(_?: Return) {}
2463
2468
  }
2464
2469
  }
2465
2470
  if (renderId) {
2466
- this.#extractor.write(
2467
- `${varShared("assertRendered")}(${varShared("rendered")},${renderId},`
2468
- );
2471
+ this.#extractor.write(`const ${varLocal("rendered_" + renderId)} = `);
2469
2472
  }
2470
2473
  if (isHTML) {
2471
2474
  this.#extractor.write(`${varShared("renderNativeTag")}("`).copy(tag.name).write('")');
@@ -2482,15 +2485,12 @@ constructor(_?: Return) {}
2482
2485
  this.#extractor.write("()()(");
2483
2486
  }
2484
2487
  this.#writeTagInputObject(tag);
2485
- if (renderId) {
2486
- this.#extractor.write(`)`);
2487
- }
2488
2488
  this.#extractor.write(");\n");
2489
2489
  if (renderId && tag.var) {
2490
2490
  this.#extractor.write(`const `);
2491
2491
  this.#copyWithMutationsReplaced(tag.var.value);
2492
2492
  this.#extractor.write(
2493
- ` = ${varShared("rendered")}.returns[${renderId}].${ATTR_UNAMED2};
2493
+ ` = ${varLocal("rendered_" + renderId)}.return.${ATTR_UNAMED2};
2494
2494
  `
2495
2495
  );
2496
2496
  }
package/dist/index.mjs CHANGED
@@ -2114,11 +2114,19 @@ function ${templateName}() {
2114
2114
  if (hoists) {
2115
2115
  this.#extractor.write("const ");
2116
2116
  this.#writeObjectKeys(hoists);
2117
- this.#extractor.write(
2118
- ` = ${varShared("readScopes")}(${varShared("rendered")});
2119
- `
2120
- );
2121
- this.#extractor.write(`${varShared("noop")}(`);
2117
+ this.#extractor.write(` = ${varShared("readScopes")}({`);
2118
+ for (const child of program.body) {
2119
+ if (child.type === 1 /* Tag */) {
2120
+ const renderId = this.#renderIds.get(child);
2121
+ if (renderId !== void 0) {
2122
+ this.#extractor.write(
2123
+ `${varLocal("rendered_" + renderId)}${SEP_COMMA_SPACE}`
2124
+ );
2125
+ }
2126
+ }
2127
+ }
2128
+ this.#extractor.write(`});
2129
+ ${varShared("noop")}(`);
2122
2130
  this.#writeObjectKeys(hoists);
2123
2131
  this.#extractor.write(");\n");
2124
2132
  }
@@ -2234,9 +2242,7 @@ constructor(_?: Return) {}
2234
2242
  }
2235
2243
  if (renderId) {
2236
2244
  this.#extractor.write(
2237
- `${varShared("assertRendered")}(${varShared(
2238
- "rendered"
2239
- )}, ${renderId}, (() => {
2245
+ `const ${varLocal("rendered_" + renderId)} = (() => {
2240
2246
  `
2241
2247
  );
2242
2248
  }
@@ -2285,7 +2291,7 @@ constructor(_?: Return) {}
2285
2291
  this.#extractor.write("\n}\n");
2286
2292
  }
2287
2293
  if (renderId) {
2288
- this.#extractor.write("\n})())\n");
2294
+ this.#extractor.write("\n})()\n");
2289
2295
  }
2290
2296
  break;
2291
2297
  }
@@ -2293,9 +2299,7 @@ constructor(_?: Return) {}
2293
2299
  const renderId = this.#getRenderId(child);
2294
2300
  if (renderId) {
2295
2301
  this.#extractor.write(
2296
- `${varShared("assertRendered")}(${varShared(
2297
- "rendered"
2298
- )}, ${renderId}, `
2302
+ `const ${varLocal("rendered_" + renderId)} = `
2299
2303
  );
2300
2304
  }
2301
2305
  this.#extractor.write(
@@ -2318,11 +2322,7 @@ constructor(_?: Return) {}
2318
2322
  void 0,
2319
2323
  (body == null ? void 0 : body.content) ? getHoistSources(child) : void 0
2320
2324
  );
2321
- if (renderId) {
2322
- this.#extractor.write("\n}));\n");
2323
- } else {
2324
- this.#extractor.write("\n});\n");
2325
- }
2325
+ this.#extractor.write("\n});\n");
2326
2326
  break;
2327
2327
  }
2328
2328
  case "while": {
@@ -2368,9 +2368,9 @@ constructor(_?: Return) {}
2368
2368
  for (const binding of mutatedVars) {
2369
2369
  this.#extractor.write(
2370
2370
  `${// TODO use a different format to avoid const annotation.
2371
- this.#scriptLang === "js" /* js */ ? "/** @type {const} */" : ""}[${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${varShared("rendered")}.returns[${this.#getRenderId(
2372
- binding.node
2373
- )}]${binding.objectPath || ""}]${SEP_COMMA_NEW_LINE}`
2371
+ this.#scriptLang === "js" /* js */ ? "/** @type {const} */" : ""}[${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${varLocal(
2372
+ "rendered_" + this.#getRenderId(binding.node)
2373
+ )}.return${binding.objectPath || ""}]${SEP_COMMA_NEW_LINE}`
2374
2374
  );
2375
2375
  }
2376
2376
  this.#extractor.write(
@@ -2394,31 +2394,36 @@ constructor(_?: Return) {}
2394
2394
  const renderId = this.#getRenderId(tag);
2395
2395
  const def = tagName ? this.#lookup.getTag(tagName) : void 0;
2396
2396
  const isHTML = def == null ? void 0 : def.html;
2397
- const importPath = !isHTML && resolveTagImport(this.#filename, def);
2397
+ const importPath = !isHTML ? resolveTagImport(this.#filename, def) : void 0;
2398
2398
  let tagIdentifier;
2399
2399
  let isTemplate = false;
2400
2400
  if (!isHTML && (!def || importPath)) {
2401
- const tagId = this.#ensureTagId(tag);
2402
- tagIdentifier = varLocal("tag_" + tagId);
2403
- this.#extractor.write(`const ${tagIdentifier} = (
2401
+ const isIdentifier = tagName && REG_TAG_NAME_IDENTIFIER.test(tagName);
2402
+ const isMarkoFile = importPath == null ? void 0 : importPath.endsWith(".marko");
2403
+ if (isIdentifier || isMarkoFile || !importPath) {
2404
+ tagIdentifier = varLocal("tag_" + this.#ensureTagId(tag));
2405
+ this.#extractor.write(`const ${tagIdentifier} = (
2404
2406
  `);
2405
- if (tagName && REG_TAG_NAME_IDENTIFIER.test(tagName)) {
2406
- if (importPath) {
2407
+ if (isIdentifier) {
2408
+ if (importPath) {
2409
+ this.#extractor.write(
2410
+ `${varShared("fallbackTemplate")}(${tagName},${isMarkoFile ? `import("${importPath}")` : varShared("any")})`
2411
+ );
2412
+ } else {
2413
+ this.#extractor.copy(tag.name);
2414
+ }
2415
+ } else if (isMarkoFile) {
2416
+ isTemplate = true;
2407
2417
  this.#extractor.write(
2408
- `${varShared("fallbackTemplate")}(${tagName},import("${importPath}"))`
2418
+ `${varShared("resolveTemplate")}(import("${importPath}"))`
2409
2419
  );
2410
2420
  } else {
2411
- this.#extractor.copy(tag.name);
2421
+ this.#writeDynamicTagName(tag);
2412
2422
  }
2413
- } else if (importPath) {
2414
- isTemplate = importPath.endsWith(".marko");
2415
- this.#extractor.write(
2416
- `${varShared("resolveTemplate")}(import("${importPath}"))`
2417
- );
2423
+ this.#extractor.write("\n);\n");
2418
2424
  } else {
2419
- this.#writeDynamicTagName(tag);
2425
+ tagIdentifier = varShared("missingTag");
2420
2426
  }
2421
- this.#extractor.write("\n);\n");
2422
2427
  const attrTagTree = this.#getAttrTagTree(tag);
2423
2428
  if (attrTagTree) {
2424
2429
  this.#writeAttrTagTree(attrTagTree, tagIdentifier);
@@ -2426,9 +2431,7 @@ constructor(_?: Return) {}
2426
2431
  }
2427
2432
  }
2428
2433
  if (renderId) {
2429
- this.#extractor.write(
2430
- `${varShared("assertRendered")}(${varShared("rendered")},${renderId},`
2431
- );
2434
+ this.#extractor.write(`const ${varLocal("rendered_" + renderId)} = `);
2432
2435
  }
2433
2436
  if (isHTML) {
2434
2437
  this.#extractor.write(`${varShared("renderNativeTag")}("`).copy(tag.name).write('")');
@@ -2445,15 +2448,12 @@ constructor(_?: Return) {}
2445
2448
  this.#extractor.write("()()(");
2446
2449
  }
2447
2450
  this.#writeTagInputObject(tag);
2448
- if (renderId) {
2449
- this.#extractor.write(`)`);
2450
- }
2451
2451
  this.#extractor.write(");\n");
2452
2452
  if (renderId && tag.var) {
2453
2453
  this.#extractor.write(`const `);
2454
2454
  this.#copyWithMutationsReplaced(tag.var.value);
2455
2455
  this.#extractor.write(
2456
- ` = ${varShared("rendered")}.returns[${renderId}].${ATTR_UNAMED2};
2456
+ ` = ${varLocal("rendered_" + renderId)}.return.${ATTR_UNAMED2};
2457
2457
  `
2458
2458
  );
2459
2459
  }
@@ -34,12 +34,6 @@ declare global {
34
34
  fn: (input: AttrTagNames<Input>) => void,
35
35
  ): void;
36
36
 
37
- export const rendered: {
38
- scopes: Record<number, never>;
39
- returns: Record<number, never>;
40
- };
41
-
42
- export const tags: Record<number, unknown>;
43
37
  export const content: DefaultBodyContentKey;
44
38
 
45
39
  export function contentFor<Name>(
@@ -87,35 +81,19 @@ declare global {
87
81
  ? Instance
88
82
  : never;
89
83
 
90
- export function readScopes<Rendered>(
91
- rendered: Rendered,
92
- ): MergeScopes<
93
- Rendered extends { scopes: Record<any, infer Scope> } ? Scope : never
94
- > &
95
- Record<any, never>;
96
-
97
- export function assertTag<Index extends number, Tags, Tag>(
98
- tags: Tags,
99
- index: Index,
100
- tag: Tag,
101
- ): asserts tags is Tags &
102
- Record<Index, [0] extends [1 & Tag] ? any : Tag>;
103
-
104
- export function assertRendered<Index extends number, Rendered, Result>(
105
- rendered: Rendered,
106
- index: Index,
107
- result: Result,
108
- ): asserts rendered is Rendered & {
109
- scopes: Record<
110
- Index,
111
- MergeOptionalScopes<
112
- Result extends { scope: infer Scope } ? Scope : undefined
113
- >
114
- >;
115
- returns: Result extends { return?: infer Return }
116
- ? Record<Index, Return>
117
- : Record<Index, never>;
118
- };
84
+ export function readScopes<Rendered>(rendered: Rendered): MergeScopes<
85
+ {
86
+ [K in keyof Rendered]: Rendered[K] extends infer Value
87
+ ? undefined extends Value
88
+ ? Value extends { scope: infer Scope }
89
+ ? Partial<Scope>
90
+ : never
91
+ : Value extends { scope: infer Scope }
92
+ ? Scope
93
+ : never
94
+ : never;
95
+ }[keyof Rendered]
96
+ >;
119
97
 
120
98
  export function mutable<Lookup>(lookup: Lookup): UnionToIntersection<
121
99
  Lookup extends readonly (infer Item)[]
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.15",
4
+ "version": "2.5.17",
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"