@marko/language-tools 2.5.0 → 2.5.2

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.
@@ -0,0 +1,7 @@
1
+ import { type Node, Repeated } from "../../../parser";
2
+ export declare function isTextOnlyScript(tag: Node.ParentTag): tag is Node.Tag & {
3
+ nameText: "script";
4
+ args: undefined;
5
+ attrs: undefined;
6
+ body: Repeated<Node.Text>;
7
+ };
package/dist/index.js CHANGED
@@ -883,9 +883,9 @@ function getAttributeValueType(value) {
883
883
  }
884
884
  if (
885
885
  // double quote string
886
- /^"(?:[^"\\]+|\\.)*"$/.test(value) || // single quote string
887
- /^'(?:[^'\\]+|\\.)*'$/.test(value) || // template literal without any interpolations
888
- /^`(?:[^`\\$]+|\\.|\$(?!\{))*`$/.test(value)
886
+ /^"(?:[^"\\]|\\.)*"$/.test(value) || // single quote string
887
+ /^'(?:[^'\\]|\\.)*'$/.test(value) || // template literal without any interpolations
888
+ /^`(?:[^`\\$]|\\.|\$(?!\{))*`$/.test(value)
889
889
  ) {
890
890
  return 2 /* QuotedString */;
891
891
  } else if (
@@ -1055,6 +1055,21 @@ var import_relative_import_path = require("relative-import-path");
1055
1055
 
1056
1056
  // src/extractors/script/util/attach-scopes.ts
1057
1057
  var t = __toESM(require("@babel/types"));
1058
+
1059
+ // src/extractors/script/util/is-text-only-script.ts
1060
+ function isTextOnlyScript(tag) {
1061
+ if (tag.nameText !== "script" || tag.args || tag.attrs || !tag.body) {
1062
+ return false;
1063
+ }
1064
+ for (const child of tag.body) {
1065
+ if (child.type !== 17 /* Text */) {
1066
+ return false;
1067
+ }
1068
+ }
1069
+ return true;
1070
+ }
1071
+
1072
+ // src/extractors/script/util/attach-scopes.ts
1058
1073
  var ATTR_UNAMED = "value";
1059
1074
  var Scopes = /* @__PURE__ */ new WeakMap();
1060
1075
  var BoundAttrMemberExpressionStartOffsets = /* @__PURE__ */ new WeakMap();
@@ -1185,7 +1200,7 @@ function crawlProgramScope(parsed, scriptParser) {
1185
1200
  }
1186
1201
  }
1187
1202
  }
1188
- if (child.nameText === "script" && child.body) {
1203
+ if (isTextOnlyScript(child)) {
1189
1204
  checkForMutations(
1190
1205
  parentScope,
1191
1206
  scriptParser.expressionAt(
@@ -1691,7 +1706,7 @@ function isTemplateTag(ts, tag) {
1691
1706
 
1692
1707
  // src/extractors/script/util/runtime-overrides.ts
1693
1708
  var RuntimeOverloads = /* @__PURE__ */ new Map();
1694
- var commentsReg = /\/\*(?:[^*]+|\*[^/])*\*\//gm;
1709
+ var commentsReg = /\/\*(?:[^*]|\*[^/])*\*\//gm;
1695
1710
  var replaceTokensReg = /\babstract\s+(\w+)|Marko\.(TemplateInput(?:<[^>]+>)?|Component)/gm;
1696
1711
  var overrideBlockReg = /\/\*[*\s]*@marko-overload-start[*\s]*\*\/([\s\S]+)\/\*[*\s]*@marko-overload-end[*\s]*\*\//g;
1697
1712
  function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
@@ -1743,7 +1758,7 @@ function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
1743
1758
  }
1744
1759
 
1745
1760
  // src/extractors/script/util/script-parser.ts
1746
- var import_parser5 = require("@babel/parser");
1761
+ var import_parser6 = require("@babel/parser");
1747
1762
  var plugins = [
1748
1763
  "exportDefaultFrom",
1749
1764
  "importAssertions",
@@ -1757,7 +1772,7 @@ var ScriptParser = class {
1757
1772
  statementAt(startIndex, src) {
1758
1773
  const pos = this.#parsed.positionAt(startIndex);
1759
1774
  try {
1760
- return (0, import_parser5.parse)(src, {
1775
+ return (0, import_parser6.parse)(src, {
1761
1776
  plugins,
1762
1777
  startIndex,
1763
1778
  startLine: pos.line + 1,
@@ -1778,7 +1793,7 @@ var ScriptParser = class {
1778
1793
  expressionAt(startIndex, src) {
1779
1794
  const pos = this.#parsed.positionAt(startIndex);
1780
1795
  try {
1781
- return (0, import_parser5.parseExpression)(src, {
1796
+ return (0, import_parser6.parseExpression)(src, {
1782
1797
  plugins,
1783
1798
  startIndex,
1784
1799
  startLine: pos.line + 1,
@@ -1809,7 +1824,7 @@ var ATTR_UNAMED2 = "value";
1809
1824
  var REG_EXT = /(?<=[/\\][^/\\]+)\.[^.]+$/;
1810
1825
  var REG_BLOCK = /\s*{/y;
1811
1826
  var REG_NEW_LINE = /^|(\r?\n)/g;
1812
- var REG_ATTR_ARG_LITERAL = /(?<=\s*)(["'])((?:[^"'\\]+|\\.|(?!\1))*)\1\s*([,)])/my;
1827
+ var REG_ATTR_ARG_LITERAL = /(?<=\s*)(["'])((?:[^"'\\]|\\.|(?!\1))*)\1\s*([,)])/my;
1813
1828
  var REG_TAG_IMPORT = /(?<=(['"]))<([^'">]+)>(?=\1)/;
1814
1829
  var REG_INPUT_TYPE = /\s*(interface|type)\s+Input\b/y;
1815
1830
  var REG_OBJECT_PROPERTY = /^[_$a-z][_$a-z0-9]*$/i;
@@ -2673,17 +2688,25 @@ const attrTags = ${varShared(
2673
2688
  if (this.#writeAttrs(tag)) {
2674
2689
  hasInput = true;
2675
2690
  }
2676
- const isScript = tag.nameText === "script";
2677
- const body = !isScript ? this.#processBody(tag) : void 0;
2691
+ const isScript = isTextOnlyScript(tag);
2678
2692
  let hasRenderBody = false;
2693
+ let body;
2679
2694
  if (isScript) {
2680
- hasRenderBody = !!tag.body;
2681
- } else if (body) {
2682
- hasInput = true;
2683
- this.#writeAttrTags(body, false, nestedTagType);
2684
- hasRenderBody = body.renderBody !== void 0;
2685
- } else if (tag.close) {
2686
- hasRenderBody = true;
2695
+ this.#extractor.write("value(){");
2696
+ this.#copyWithMutationsReplaced({
2697
+ start: tag.body[0].start,
2698
+ end: tag.body[tag.body.length - 1].end
2699
+ });
2700
+ this.#extractor.write(`}${SEP_COMMA_NEW_LINE}`);
2701
+ } else {
2702
+ body = this.#processBody(tag);
2703
+ if (body) {
2704
+ hasInput = true;
2705
+ this.#writeAttrTags(body, false, nestedTagType);
2706
+ hasRenderBody = body.renderBody !== void 0;
2707
+ } else if (tag.close) {
2708
+ hasRenderBody = true;
2709
+ }
2687
2710
  }
2688
2711
  if (tag.params || hasRenderBody) {
2689
2712
  this.#extractor.write('["renderBody"');
@@ -2700,15 +2723,7 @@ const attrTags = ${varShared(
2700
2723
  `);
2701
2724
  }
2702
2725
  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) {
2726
+ if (body == null ? void 0 : body.renderBody) {
2712
2727
  didReturn = this.#writeChildren(tag, body.renderBody);
2713
2728
  }
2714
2729
  if (!tag.params) {
package/dist/index.mjs CHANGED
@@ -844,9 +844,9 @@ function getAttributeValueType(value) {
844
844
  }
845
845
  if (
846
846
  // double quote string
847
- /^"(?:[^"\\]+|\\.)*"$/.test(value) || // single quote string
848
- /^'(?:[^'\\]+|\\.)*'$/.test(value) || // template literal without any interpolations
849
- /^`(?:[^`\\$]+|\\.|\$(?!\{))*`$/.test(value)
847
+ /^"(?:[^"\\]|\\.)*"$/.test(value) || // single quote string
848
+ /^'(?:[^'\\]|\\.)*'$/.test(value) || // template literal without any interpolations
849
+ /^`(?:[^`\\$]|\\.|\$(?!\{))*`$/.test(value)
850
850
  ) {
851
851
  return 2 /* QuotedString */;
852
852
  } else if (
@@ -1016,6 +1016,21 @@ import { relativeImportPath } from "relative-import-path";
1016
1016
 
1017
1017
  // src/extractors/script/util/attach-scopes.ts
1018
1018
  import * as t from "@babel/types";
1019
+
1020
+ // src/extractors/script/util/is-text-only-script.ts
1021
+ function isTextOnlyScript(tag) {
1022
+ if (tag.nameText !== "script" || tag.args || tag.attrs || !tag.body) {
1023
+ return false;
1024
+ }
1025
+ for (const child of tag.body) {
1026
+ if (child.type !== 17 /* Text */) {
1027
+ return false;
1028
+ }
1029
+ }
1030
+ return true;
1031
+ }
1032
+
1033
+ // src/extractors/script/util/attach-scopes.ts
1019
1034
  var ATTR_UNAMED = "value";
1020
1035
  var Scopes = /* @__PURE__ */ new WeakMap();
1021
1036
  var BoundAttrMemberExpressionStartOffsets = /* @__PURE__ */ new WeakMap();
@@ -1146,7 +1161,7 @@ function crawlProgramScope(parsed, scriptParser) {
1146
1161
  }
1147
1162
  }
1148
1163
  }
1149
- if (child.nameText === "script" && child.body) {
1164
+ if (isTextOnlyScript(child)) {
1150
1165
  checkForMutations(
1151
1166
  parentScope,
1152
1167
  scriptParser.expressionAt(
@@ -1652,7 +1667,7 @@ function isTemplateTag(ts, tag) {
1652
1667
 
1653
1668
  // src/extractors/script/util/runtime-overrides.ts
1654
1669
  var RuntimeOverloads = /* @__PURE__ */ new Map();
1655
- var commentsReg = /\/\*(?:[^*]+|\*[^/])*\*\//gm;
1670
+ var commentsReg = /\/\*(?:[^*]|\*[^/])*\*\//gm;
1656
1671
  var replaceTokensReg = /\babstract\s+(\w+)|Marko\.(TemplateInput(?:<[^>]+>)?|Component)/gm;
1657
1672
  var overrideBlockReg = /\/\*[*\s]*@marko-overload-start[*\s]*\*\/([\s\S]+)\/\*[*\s]*@marko-overload-end[*\s]*\*\//g;
1658
1673
  function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
@@ -1773,7 +1788,7 @@ var ATTR_UNAMED2 = "value";
1773
1788
  var REG_EXT = /(?<=[/\\][^/\\]+)\.[^.]+$/;
1774
1789
  var REG_BLOCK = /\s*{/y;
1775
1790
  var REG_NEW_LINE = /^|(\r?\n)/g;
1776
- var REG_ATTR_ARG_LITERAL = /(?<=\s*)(["'])((?:[^"'\\]+|\\.|(?!\1))*)\1\s*([,)])/my;
1791
+ var REG_ATTR_ARG_LITERAL = /(?<=\s*)(["'])((?:[^"'\\]|\\.|(?!\1))*)\1\s*([,)])/my;
1777
1792
  var REG_TAG_IMPORT = /(?<=(['"]))<([^'">]+)>(?=\1)/;
1778
1793
  var REG_INPUT_TYPE = /\s*(interface|type)\s+Input\b/y;
1779
1794
  var REG_OBJECT_PROPERTY = /^[_$a-z][_$a-z0-9]*$/i;
@@ -2637,17 +2652,25 @@ const attrTags = ${varShared(
2637
2652
  if (this.#writeAttrs(tag)) {
2638
2653
  hasInput = true;
2639
2654
  }
2640
- const isScript = tag.nameText === "script";
2641
- const body = !isScript ? this.#processBody(tag) : void 0;
2655
+ const isScript = isTextOnlyScript(tag);
2642
2656
  let hasRenderBody = false;
2657
+ let body;
2643
2658
  if (isScript) {
2644
- hasRenderBody = !!tag.body;
2645
- } else if (body) {
2646
- hasInput = true;
2647
- this.#writeAttrTags(body, false, nestedTagType);
2648
- hasRenderBody = body.renderBody !== void 0;
2649
- } else if (tag.close) {
2650
- hasRenderBody = true;
2659
+ this.#extractor.write("value(){");
2660
+ this.#copyWithMutationsReplaced({
2661
+ start: tag.body[0].start,
2662
+ end: tag.body[tag.body.length - 1].end
2663
+ });
2664
+ this.#extractor.write(`}${SEP_COMMA_NEW_LINE}`);
2665
+ } else {
2666
+ body = this.#processBody(tag);
2667
+ if (body) {
2668
+ hasInput = true;
2669
+ this.#writeAttrTags(body, false, nestedTagType);
2670
+ hasRenderBody = body.renderBody !== void 0;
2671
+ } else if (tag.close) {
2672
+ hasRenderBody = true;
2673
+ }
2651
2674
  }
2652
2675
  if (tag.params || hasRenderBody) {
2653
2676
  this.#extractor.write('["renderBody"');
@@ -2664,15 +2687,7 @@ const attrTags = ${varShared(
2664
2687
  `);
2665
2688
  }
2666
2689
  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) {
2690
+ if (body == null ? void 0 : body.renderBody) {
2676
2691
  didReturn = this.#writeChildren(tag, body.renderBody);
2677
2692
  }
2678
2693
  if (!tag.params) {
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@marko/language-tools",
3
3
  "description": "Marko Language Tools",
4
- "version": "2.5.0",
4
+ "version": "2.5.2",
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"
8
8
  },
9
9
  "dependencies": {
10
- "@babel/parser": "^7.26.2",
10
+ "@babel/parser": "^7.26.3",
11
11
  "@luxass/strip-json-comments": "^1.3.2",
12
12
  "htmljs-parser": "^5.5.3",
13
13
  "relative-import-path": "^1.0.0"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@babel/code-frame": "^7.26.2",
17
- "@marko/compiler": "^5.38.0",
18
- "@marko/translator-default": "^6.1.0",
17
+ "@marko/compiler": "^5.38.3",
18
+ "@marko/translator-default": "^6.1.2",
19
19
  "@types/babel__code-frame": "^7.0.6",
20
20
  "@typescript/vfs": "^1.6.0",
21
- "marko": "^5.36.0",
22
- "mitata": "^1.0.16",
21
+ "marko": "^5.36.3",
22
+ "mitata": "^1.0.20",
23
23
  "tsx": "^4.19.2"
24
24
  },
25
25
  "exports": {