@marko/language-tools 2.0.4 → 2.0.6

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
@@ -2259,9 +2259,13 @@ ${varShared(renderer)})`);
2259
2259
  break;
2260
2260
  case 10 /* AttrNamed */: {
2261
2261
  const isDefault = isEmptyRange(attr.name);
2262
- const name = isDefault ? ATTR_UNAMED2 : attr.name;
2263
2262
  const value = attr.value;
2263
+ const modifierIndex = !isDefault && (!value || value.type === 13 /* AttrValue */) && this.#getNamedAttrModifierIndex(attr);
2264
2264
  const defaultMapPosition = isDefault ? attr.name : void 0;
2265
+ let name = isDefault ? ATTR_UNAMED2 : attr.name;
2266
+ if (modifierIndex !== false) {
2267
+ name = { start: attr.name.start, end: modifierIndex };
2268
+ }
2265
2269
  if (value) {
2266
2270
  switch (value.type) {
2267
2271
  case 14 /* AttrMethod */:
@@ -2342,7 +2346,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
2342
2346
  `).copy(attr.args.value).write("\n)");
2343
2347
  }
2344
2348
  } else {
2345
- this.#extractor.write('"').copy(defaultMapPosition).copy(name).write('": true');
2349
+ this.#extractor.write('"').copy(defaultMapPosition).copy(name).write(`": ${modifierIndex === false ? "true" : '""'}`);
2346
2350
  }
2347
2351
  break;
2348
2352
  }
@@ -2434,11 +2438,7 @@ const attrTags = ${varShared(
2434
2438
  this.#extractor.write("((\n").copy(
2435
2439
  ((_a = tag.args) == null ? void 0 : _a.value) || this.#getAttrValue(tag, ATTR_UNAMED2) || "undefined"
2436
2440
  ).write("\n) ? ");
2437
- this.#extractor.write("{\n");
2438
- const body = this.#processBody(tag);
2439
- if (body)
2440
- this.#writeAttrTags(body, true);
2441
- this.#extractor.write("\n} ");
2441
+ this.#writeDynamicAttrTagBody(tag);
2442
2442
  let needsAlternate = true;
2443
2443
  if (alternates) {
2444
2444
  for (const { node, condition } of alternates) {
@@ -2451,14 +2451,7 @@ const attrTags = ${varShared(
2451
2451
  } else {
2452
2452
  this.#extractor.write(": undefined ? ");
2453
2453
  }
2454
- const body2 = this.#processBody(tag);
2455
- if (body2) {
2456
- this.#extractor.write("{\n");
2457
- this.#writeAttrTags(body2, true);
2458
- this.#extractor.write("}");
2459
- } else {
2460
- this.#extractor.write("{}");
2461
- }
2454
+ this.#writeDynamicAttrTagBody(node);
2462
2455
  }
2463
2456
  }
2464
2457
  if (needsAlternate) {
@@ -2474,20 +2467,17 @@ const attrTags = ${varShared(
2474
2467
  this.#writeTagNameComment(tag);
2475
2468
  this.#extractor.write("}, \n");
2476
2469
  this.#writeComments(tag);
2477
- this.#extractor.copy(tag.typeParams).write("(\n").copy((_b = tag.params) == null ? void 0 : _b.value).write("\n) => ({\n");
2478
- const body = this.#processBody(tag);
2479
- if (body)
2480
- this.#writeAttrTags(body, true);
2481
- this.#extractor.write("}))");
2470
+ this.#extractor.copy(tag.typeParams).write("(\n").copy((_b = tag.params) == null ? void 0 : _b.value).write("\n) => (");
2471
+ this.#writeDynamicAttrTagBody(tag);
2472
+ this.#extractor.write("))");
2482
2473
  break;
2483
2474
  }
2484
2475
  case "while": {
2485
2476
  this.#writeComments(tag);
2486
2477
  this.#extractor.write(`${varShared("mergeAttrTags")}((
2487
- `).copy(((_c = tag.args) == null ? void 0 : _c.value) || "undefined").write("\n) ? [{\n");
2488
- const body = this.#processBody(tag);
2489
- this.#writeAttrTags(body, true);
2490
- this.#extractor.write("}] : [])");
2478
+ `).copy(((_c = tag.args) == null ? void 0 : _c.value) || "undefined").write("\n) ? [");
2479
+ this.#writeDynamicAttrTagBody(tag);
2480
+ this.#extractor.write("] : [])");
2491
2481
  break;
2492
2482
  }
2493
2483
  }
@@ -2746,6 +2736,24 @@ const attrTags = ${varShared(
2746
2736
  return { renderBody, staticAttrTags, dynamicAttrTagParents };
2747
2737
  }
2748
2738
  }
2739
+ #writeDynamicAttrTagBody(tag) {
2740
+ const body = this.#processBody(tag);
2741
+ if (body) {
2742
+ if (body.renderBody) {
2743
+ this.#extractor.write("(() => {\n");
2744
+ this.#writeChildren(tag, body.renderBody);
2745
+ this.#extractor.write("return ");
2746
+ }
2747
+ this.#extractor.write("{\n");
2748
+ this.#writeAttrTags(body, true);
2749
+ this.#extractor.write("}");
2750
+ if (body.renderBody) {
2751
+ this.#extractor.write(";\n})()");
2752
+ }
2753
+ } else {
2754
+ this.#extractor.write("{}");
2755
+ }
2756
+ }
2749
2757
  #getAttrValue(tag, name) {
2750
2758
  if (tag.attrs) {
2751
2759
  for (const attr of tag.attrs) {
@@ -2828,6 +2836,15 @@ const attrTags = ${varShared(
2828
2836
  }
2829
2837
  return renderId;
2830
2838
  }
2839
+ #getNamedAttrModifierIndex(attr) {
2840
+ const start = attr.name.start + 1;
2841
+ const end = attr.name.end - 1;
2842
+ for (let i = end; i-- > start; ) {
2843
+ if (this.#code.charAt(i) === ":")
2844
+ return i;
2845
+ }
2846
+ return false;
2847
+ }
2831
2848
  #testAtIndex(reg, index) {
2832
2849
  reg.lastIndex = index;
2833
2850
  return reg.test(this.#code);
package/dist/index.mjs CHANGED
@@ -2228,9 +2228,13 @@ ${varShared(renderer)})`);
2228
2228
  break;
2229
2229
  case 10 /* AttrNamed */: {
2230
2230
  const isDefault = isEmptyRange(attr.name);
2231
- const name = isDefault ? ATTR_UNAMED2 : attr.name;
2232
2231
  const value = attr.value;
2232
+ const modifierIndex = !isDefault && (!value || value.type === 13 /* AttrValue */) && this.#getNamedAttrModifierIndex(attr);
2233
2233
  const defaultMapPosition = isDefault ? attr.name : void 0;
2234
+ let name = isDefault ? ATTR_UNAMED2 : attr.name;
2235
+ if (modifierIndex !== false) {
2236
+ name = { start: attr.name.start, end: modifierIndex };
2237
+ }
2234
2238
  if (value) {
2235
2239
  switch (value.type) {
2236
2240
  case 14 /* AttrMethod */:
@@ -2311,7 +2315,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
2311
2315
  `).copy(attr.args.value).write("\n)");
2312
2316
  }
2313
2317
  } else {
2314
- this.#extractor.write('"').copy(defaultMapPosition).copy(name).write('": true');
2318
+ this.#extractor.write('"').copy(defaultMapPosition).copy(name).write(`": ${modifierIndex === false ? "true" : '""'}`);
2315
2319
  }
2316
2320
  break;
2317
2321
  }
@@ -2403,11 +2407,7 @@ const attrTags = ${varShared(
2403
2407
  this.#extractor.write("((\n").copy(
2404
2408
  ((_a = tag.args) == null ? void 0 : _a.value) || this.#getAttrValue(tag, ATTR_UNAMED2) || "undefined"
2405
2409
  ).write("\n) ? ");
2406
- this.#extractor.write("{\n");
2407
- const body = this.#processBody(tag);
2408
- if (body)
2409
- this.#writeAttrTags(body, true);
2410
- this.#extractor.write("\n} ");
2410
+ this.#writeDynamicAttrTagBody(tag);
2411
2411
  let needsAlternate = true;
2412
2412
  if (alternates) {
2413
2413
  for (const { node, condition } of alternates) {
@@ -2420,14 +2420,7 @@ const attrTags = ${varShared(
2420
2420
  } else {
2421
2421
  this.#extractor.write(": undefined ? ");
2422
2422
  }
2423
- const body2 = this.#processBody(tag);
2424
- if (body2) {
2425
- this.#extractor.write("{\n");
2426
- this.#writeAttrTags(body2, true);
2427
- this.#extractor.write("}");
2428
- } else {
2429
- this.#extractor.write("{}");
2430
- }
2423
+ this.#writeDynamicAttrTagBody(node);
2431
2424
  }
2432
2425
  }
2433
2426
  if (needsAlternate) {
@@ -2443,20 +2436,17 @@ const attrTags = ${varShared(
2443
2436
  this.#writeTagNameComment(tag);
2444
2437
  this.#extractor.write("}, \n");
2445
2438
  this.#writeComments(tag);
2446
- this.#extractor.copy(tag.typeParams).write("(\n").copy((_b = tag.params) == null ? void 0 : _b.value).write("\n) => ({\n");
2447
- const body = this.#processBody(tag);
2448
- if (body)
2449
- this.#writeAttrTags(body, true);
2450
- this.#extractor.write("}))");
2439
+ this.#extractor.copy(tag.typeParams).write("(\n").copy((_b = tag.params) == null ? void 0 : _b.value).write("\n) => (");
2440
+ this.#writeDynamicAttrTagBody(tag);
2441
+ this.#extractor.write("))");
2451
2442
  break;
2452
2443
  }
2453
2444
  case "while": {
2454
2445
  this.#writeComments(tag);
2455
2446
  this.#extractor.write(`${varShared("mergeAttrTags")}((
2456
- `).copy(((_c = tag.args) == null ? void 0 : _c.value) || "undefined").write("\n) ? [{\n");
2457
- const body = this.#processBody(tag);
2458
- this.#writeAttrTags(body, true);
2459
- this.#extractor.write("}] : [])");
2447
+ `).copy(((_c = tag.args) == null ? void 0 : _c.value) || "undefined").write("\n) ? [");
2448
+ this.#writeDynamicAttrTagBody(tag);
2449
+ this.#extractor.write("] : [])");
2460
2450
  break;
2461
2451
  }
2462
2452
  }
@@ -2715,6 +2705,24 @@ const attrTags = ${varShared(
2715
2705
  return { renderBody, staticAttrTags, dynamicAttrTagParents };
2716
2706
  }
2717
2707
  }
2708
+ #writeDynamicAttrTagBody(tag) {
2709
+ const body = this.#processBody(tag);
2710
+ if (body) {
2711
+ if (body.renderBody) {
2712
+ this.#extractor.write("(() => {\n");
2713
+ this.#writeChildren(tag, body.renderBody);
2714
+ this.#extractor.write("return ");
2715
+ }
2716
+ this.#extractor.write("{\n");
2717
+ this.#writeAttrTags(body, true);
2718
+ this.#extractor.write("}");
2719
+ if (body.renderBody) {
2720
+ this.#extractor.write(";\n})()");
2721
+ }
2722
+ } else {
2723
+ this.#extractor.write("{}");
2724
+ }
2725
+ }
2718
2726
  #getAttrValue(tag, name) {
2719
2727
  if (tag.attrs) {
2720
2728
  for (const attr of tag.attrs) {
@@ -2797,6 +2805,15 @@ const attrTags = ${varShared(
2797
2805
  }
2798
2806
  return renderId;
2799
2807
  }
2808
+ #getNamedAttrModifierIndex(attr) {
2809
+ const start = attr.name.start + 1;
2810
+ const end = attr.name.end - 1;
2811
+ for (let i = end; i-- > start; ) {
2812
+ if (this.#code.charAt(i) === ":")
2813
+ return i;
2814
+ }
2815
+ return false;
2816
+ }
2800
2817
  #testAtIndex(reg, index) {
2801
2818
  reg.lastIndex = index;
2802
2819
  return reg.test(this.#code);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@marko/language-tools",
3
3
  "description": "Marko Language Tools",
4
- "version": "2.0.4",
4
+ "version": "2.0.6",
5
5
  "bugs": "https://github.com/marko-js/language-server/issues/new?template=Bug_report.md",
6
6
  "dependencies": {
7
7
  "@babel/helper-validator-identifier": "^7.19.1",
8
- "@babel/parser": "^7.21.4",
8
+ "@babel/parser": "^7.21.8",
9
9
  "@marko/compiler": "5.27.7",
10
10
  "@marko/translator-default": "5.25.7",
11
11
  "htmljs-parser": "^5.4.3",
@@ -13,13 +13,13 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "@babel/code-frame": "^7.21.4",
16
- "@marko/compiler": "^5.27.6",
16
+ "@marko/compiler": "^5.27.7",
17
17
  "@types/babel__code-frame": "^7.0.3",
18
18
  "@types/babel__helper-validator-identifier": "^7.15.0",
19
19
  "@typescript/vfs": "^1.4.0",
20
- "marko": "^5.25.6",
20
+ "marko": "^5.25.11",
21
21
  "mitata": "^0.1.6",
22
- "tsx": "^3.12.6"
22
+ "tsx": "^3.12.7"
23
23
  },
24
24
  "exports": {
25
25
  ".": {