@marko/language-tools 2.4.7 → 2.5.0

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
@@ -388,9 +388,18 @@ var Builder = class {
388
388
  case "source":
389
389
  case "track":
390
390
  case "wbr":
391
+ case "const":
392
+ case "debug":
393
+ case "id":
394
+ case "let":
395
+ case "lifecycle":
396
+ case "log":
397
+ case "return":
391
398
  bodyType = import_htmljs_parser.TagType.void;
392
399
  break;
393
400
  case "html-comment":
401
+ case "html-script":
402
+ case "html-style":
394
403
  case "script":
395
404
  case "textarea":
396
405
  bodyType = import_htmljs_parser.TagType.text;
@@ -1176,7 +1185,22 @@ function crawlProgramScope(parsed, scriptParser) {
1176
1185
  }
1177
1186
  }
1178
1187
  }
1179
- visit(child.body, bodyScope);
1188
+ if (child.nameText === "script" && child.body) {
1189
+ checkForMutations(
1190
+ parentScope,
1191
+ scriptParser.expressionAt(
1192
+ child.body[0].start - "()=>{\n".length,
1193
+ `()=>{
1194
+ ${read({
1195
+ start: child.body[0].start,
1196
+ end: child.body[child.body.length - 1].end
1197
+ })}
1198
+ }`
1199
+ )
1200
+ );
1201
+ } else {
1202
+ visit(child.body, bodyScope);
1203
+ }
1180
1204
  Scopes.set(child.body, bodyScope);
1181
1205
  }
1182
1206
  if (child.attrs) {
@@ -2649,9 +2673,12 @@ const attrTags = ${varShared(
2649
2673
  if (this.#writeAttrs(tag)) {
2650
2674
  hasInput = true;
2651
2675
  }
2652
- const body = this.#processBody(tag);
2676
+ const isScript = tag.nameText === "script";
2677
+ const body = !isScript ? this.#processBody(tag) : void 0;
2653
2678
  let hasRenderBody = false;
2654
- if (body) {
2679
+ if (isScript) {
2680
+ hasRenderBody = !!tag.body;
2681
+ } else if (body) {
2655
2682
  hasInput = true;
2656
2683
  this.#writeAttrTags(body, false, nestedTagType);
2657
2684
  hasRenderBody = body.renderBody !== void 0;
@@ -2672,15 +2699,25 @@ const attrTags = ${varShared(
2672
2699
  this.#extractor.write(`(() => {
2673
2700
  `);
2674
2701
  }
2675
- const localBindings = getHoistSources(tag);
2676
- const didReturn = (body == null ? void 0 : body.renderBody) && this.#writeChildren(tag, body.renderBody);
2702
+ let didReturn = false;
2703
+ if (isScript) {
2704
+ if (tag.body) {
2705
+ this.#copyWithMutationsReplaced({
2706
+ start: tag.body[0].start,
2707
+ end: tag.body[tag.body.length - 1].end
2708
+ });
2709
+ didReturn = this.#writeChildren(tag, []);
2710
+ }
2711
+ } else if (body == null ? void 0 : body.renderBody) {
2712
+ didReturn = this.#writeChildren(tag, body.renderBody);
2713
+ }
2677
2714
  if (!tag.params) {
2678
2715
  this.#extractor.write(`return () => {
2679
2716
  `);
2680
2717
  }
2681
2718
  this.#writeReturn(
2682
2719
  didReturn ? `${varLocal("return")}.return` : void 0,
2683
- localBindings
2720
+ getHoistSources(tag)
2684
2721
  );
2685
2722
  if (tag.params) {
2686
2723
  this.#extractor.write("})");
package/dist/index.mjs CHANGED
@@ -349,9 +349,18 @@ var Builder = class {
349
349
  case "source":
350
350
  case "track":
351
351
  case "wbr":
352
+ case "const":
353
+ case "debug":
354
+ case "id":
355
+ case "let":
356
+ case "lifecycle":
357
+ case "log":
358
+ case "return":
352
359
  bodyType = TagType.void;
353
360
  break;
354
361
  case "html-comment":
362
+ case "html-script":
363
+ case "html-style":
355
364
  case "script":
356
365
  case "textarea":
357
366
  bodyType = TagType.text;
@@ -1137,7 +1146,22 @@ function crawlProgramScope(parsed, scriptParser) {
1137
1146
  }
1138
1147
  }
1139
1148
  }
1140
- visit(child.body, bodyScope);
1149
+ if (child.nameText === "script" && child.body) {
1150
+ checkForMutations(
1151
+ parentScope,
1152
+ scriptParser.expressionAt(
1153
+ child.body[0].start - "()=>{\n".length,
1154
+ `()=>{
1155
+ ${read({
1156
+ start: child.body[0].start,
1157
+ end: child.body[child.body.length - 1].end
1158
+ })}
1159
+ }`
1160
+ )
1161
+ );
1162
+ } else {
1163
+ visit(child.body, bodyScope);
1164
+ }
1141
1165
  Scopes.set(child.body, bodyScope);
1142
1166
  }
1143
1167
  if (child.attrs) {
@@ -2613,9 +2637,12 @@ const attrTags = ${varShared(
2613
2637
  if (this.#writeAttrs(tag)) {
2614
2638
  hasInput = true;
2615
2639
  }
2616
- const body = this.#processBody(tag);
2640
+ const isScript = tag.nameText === "script";
2641
+ const body = !isScript ? this.#processBody(tag) : void 0;
2617
2642
  let hasRenderBody = false;
2618
- if (body) {
2643
+ if (isScript) {
2644
+ hasRenderBody = !!tag.body;
2645
+ } else if (body) {
2619
2646
  hasInput = true;
2620
2647
  this.#writeAttrTags(body, false, nestedTagType);
2621
2648
  hasRenderBody = body.renderBody !== void 0;
@@ -2636,15 +2663,25 @@ const attrTags = ${varShared(
2636
2663
  this.#extractor.write(`(() => {
2637
2664
  `);
2638
2665
  }
2639
- const localBindings = getHoistSources(tag);
2640
- const didReturn = (body == null ? void 0 : body.renderBody) && this.#writeChildren(tag, body.renderBody);
2666
+ let didReturn = false;
2667
+ if (isScript) {
2668
+ if (tag.body) {
2669
+ this.#copyWithMutationsReplaced({
2670
+ start: tag.body[0].start,
2671
+ end: tag.body[tag.body.length - 1].end
2672
+ });
2673
+ didReturn = this.#writeChildren(tag, []);
2674
+ }
2675
+ } else if (body == null ? void 0 : body.renderBody) {
2676
+ didReturn = this.#writeChildren(tag, body.renderBody);
2677
+ }
2641
2678
  if (!tag.params) {
2642
2679
  this.#extractor.write(`return () => {
2643
2680
  `);
2644
2681
  }
2645
2682
  this.#writeReturn(
2646
2683
  didReturn ? `${varLocal("return")}.return` : void 0,
2647
- localBindings
2684
+ getHoistSources(tag)
2648
2685
  );
2649
2686
  if (tag.params) {
2650
2687
  this.#extractor.write("})");
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.4.7",
4
+ "version": "2.5.0",
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"