@marko/language-tools 2.5.58 → 2.5.59

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.
@@ -1,6 +1,6 @@
1
- import { Parsed } from "../../parser";
1
+ import { type Parsed } from "../../parser";
2
2
  export declare function extractHTML(parsed: Parsed): {
3
- extracted: import("../../util/extractor").Extracted;
3
+ extracted: import("../..").Extracted;
4
4
  nodeDetails: {
5
5
  [id: string]: {
6
6
  hasDynamicAttrs: boolean;
@@ -17,4 +17,4 @@ export interface ExtractScriptOptions {
17
17
  runtimeTypesCode?: string;
18
18
  translator: Meta["config"]["translator"];
19
19
  }
20
- export declare function extractScript(opts: ExtractScriptOptions): import("../../util/extractor").Extracted;
20
+ export declare function extractScript(opts: ExtractScriptOptions): import("../..").Extracted;
@@ -1,4 +1,4 @@
1
- import { type Node, Parsed, type Range, Repeatable, Repeated } from "../../../parser";
1
+ import { type Node, type Parsed, type Range, type Repeatable, type Repeated } from "../../../parser";
2
2
  import { ScriptParser } from "./script-parser";
3
3
  export type Scope = ProgramScope | TagScope;
4
4
  export interface ProgramScope {
@@ -1,5 +1,5 @@
1
1
  import type { TaglibLookup } from "@marko/compiler/babel-utils";
2
- import { Parsed } from "../../../parser";
2
+ import { type Parsed } from "../../../parser";
3
3
  export type RuntimeAPI = (typeof RuntimeAPI)[keyof typeof RuntimeAPI];
4
4
  export declare const RuntimeAPI: {
5
5
  readonly tags: "tags";
@@ -1,4 +1,4 @@
1
- import { type Node, Repeated } from "../../../parser";
1
+ import { type Node, type Repeated } from "../../../parser";
2
2
  export declare function isTextOnlyScript(tag: Node.ParentTag): tag is Node.Tag & {
3
3
  nameText: "script";
4
4
  args: undefined;
package/dist/index.js CHANGED
@@ -730,6 +730,7 @@ var Extracted = class {
730
730
  );
731
731
  }
732
732
  }
733
+ parsed;
733
734
  #generated;
734
735
  #sourceToGenerated;
735
736
  #generatedToSource;
@@ -1065,6 +1066,205 @@ var import_relative_import_path = require("relative-import-path");
1065
1066
 
1066
1067
  // src/extractors/script/util/attach-scopes.ts
1067
1068
  var import_compiler = require("@marko/compiler");
1069
+
1070
+ // src/extractors/script/util/script-parser.ts
1071
+ var import_babel = require("@marko/compiler/internal/babel");
1072
+
1073
+ // src/extractors/script/util/is-text-only-script.ts
1074
+ function isTextOnlyScript(tag) {
1075
+ if (tag.nameText !== "script" || tag.args || tag.attrs || !tag.body) {
1076
+ return false;
1077
+ }
1078
+ for (const child of tag.body) {
1079
+ if (child.type !== 17 /* Text */) {
1080
+ return false;
1081
+ }
1082
+ }
1083
+ return true;
1084
+ }
1085
+
1086
+ // src/extractors/script/util/script-parser.ts
1087
+ var plugins = ["exportDefaultFrom", "importAssertions", "typescript"];
1088
+ var ScriptParser = class {
1089
+ #parsed;
1090
+ #cache = /* @__PURE__ */ new Map();
1091
+ constructor(parsed) {
1092
+ this.#parsed = parsed;
1093
+ }
1094
+ tagName(name) {
1095
+ return this.#templateExpressions(name);
1096
+ }
1097
+ tagShorthandId(shorthandId) {
1098
+ return this.#templateExpressions(shorthandId);
1099
+ }
1100
+ tagShorthandClassName(node) {
1101
+ return this.#templateExpressions(node);
1102
+ }
1103
+ tagVar(node) {
1104
+ const start = node.value.start - 1;
1105
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1106
+ if (expr) {
1107
+ return expr.params[0];
1108
+ }
1109
+ }
1110
+ tagParams(node) {
1111
+ const start = node.start;
1112
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1113
+ if (expr) {
1114
+ return expr.params;
1115
+ }
1116
+ }
1117
+ tagTypeParams(node) {
1118
+ const start = node.value.start - 1;
1119
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `<${this.#parsed.read(node.value)}>()=>0`);
1120
+ if (expr) {
1121
+ return expr.typeParameters;
1122
+ }
1123
+ }
1124
+ tagArgs(node) {
1125
+ const start = node.value.start - 2;
1126
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_(${this.#parsed.read(node.value)})`);
1127
+ if (expr) {
1128
+ return expr.arguments;
1129
+ }
1130
+ }
1131
+ tagTypeArgs(node) {
1132
+ const start = node.value.start - 2;
1133
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_<${this.#parsed.read(node.value)}>()`);
1134
+ if (expr) {
1135
+ return expr.typeParameters;
1136
+ }
1137
+ }
1138
+ attrValue(node) {
1139
+ const start = node.value.start;
1140
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1141
+ }
1142
+ attrSpread(node) {
1143
+ const start = node.value.start;
1144
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1145
+ }
1146
+ attrMethod(node) {
1147
+ const start = node.params.start - 2;
1148
+ const expr = this.#cache.get(start) ?? this.#expressionAt(
1149
+ start,
1150
+ `{_${this.#parsed.read({ start: node.params.start, end: node.body.end })}}`
1151
+ );
1152
+ if (expr) {
1153
+ return expr.properties[0];
1154
+ }
1155
+ }
1156
+ attrArgs(node) {
1157
+ const start = node.value.start;
1158
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1159
+ }
1160
+ placeholder(node) {
1161
+ const start = node.value.start;
1162
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1163
+ }
1164
+ scriptBody(node) {
1165
+ if (!isTextOnlyScript(node)) return;
1166
+ const start = node.body[0].start;
1167
+ const statements = this.#cache.get(start) ?? this.#statementsAt(
1168
+ start,
1169
+ this.#parsed.read({ start, end: node.body[node.body.length - 1].end })
1170
+ );
1171
+ if (statements) {
1172
+ return statements;
1173
+ }
1174
+ }
1175
+ scriptlet(node) {
1176
+ const start = node.value.start;
1177
+ const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read(node.value));
1178
+ if (statements) {
1179
+ return statements;
1180
+ }
1181
+ }
1182
+ import(node) {
1183
+ const statements = this.#cache.get(node.start) ?? this.#statementsAt(node.start, this.#parsed.read(node));
1184
+ if (statements) {
1185
+ return statements[0];
1186
+ }
1187
+ }
1188
+ export(node) {
1189
+ const statements = this.#cache.get(node.start) ?? this.#statementsAt(node.start, this.#parsed.read(node));
1190
+ if (statements) {
1191
+ return statements[0];
1192
+ }
1193
+ }
1194
+ class(node) {
1195
+ const expr = this.#cache.get(node.start) ?? this.#expressionAt(node.start, this.#parsed.read(node));
1196
+ return expr || void 0;
1197
+ }
1198
+ static(node) {
1199
+ const start = node.start + "static ".length;
1200
+ const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read({ start, end: node.end }));
1201
+ if (statements) {
1202
+ return statements;
1203
+ }
1204
+ }
1205
+ #templateExpressions(template) {
1206
+ const { expressions } = template;
1207
+ if (!expressions.length) return;
1208
+ const result = [];
1209
+ for (const expr of expressions) {
1210
+ const start = expr.value.start;
1211
+ const parsed = this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(expr.value));
1212
+ if (!parsed) return;
1213
+ result.push(parsed);
1214
+ }
1215
+ if (result.length) return result;
1216
+ }
1217
+ #statementsAt(startIndex, src) {
1218
+ try {
1219
+ const pos = this.#parsed.positionAt(startIndex);
1220
+ const result = (0, import_babel.parse)(src, {
1221
+ plugins,
1222
+ startIndex,
1223
+ startLine: pos.line + 1,
1224
+ startColumn: pos.character,
1225
+ strictMode: true,
1226
+ errorRecovery: true,
1227
+ sourceType: "module",
1228
+ allowUndeclaredExports: true,
1229
+ allowSuperOutsideMethod: true,
1230
+ allowAwaitOutsideFunction: true,
1231
+ allowReturnOutsideFunction: true,
1232
+ sourceFilename: this.#parsed.filename
1233
+ }).program.body;
1234
+ if (result.length) {
1235
+ this.#cache.set(startIndex, result);
1236
+ return result;
1237
+ }
1238
+ } catch {
1239
+ }
1240
+ this.#cache.set(startIndex, false);
1241
+ }
1242
+ #expressionAt(startIndex, src) {
1243
+ try {
1244
+ const pos = this.#parsed.positionAt(startIndex);
1245
+ const result = (0, import_babel.parseExpression)(src, {
1246
+ plugins,
1247
+ startIndex,
1248
+ startLine: pos.line + 1,
1249
+ startColumn: pos.character,
1250
+ strictMode: true,
1251
+ errorRecovery: true,
1252
+ sourceType: "module",
1253
+ allowUndeclaredExports: true,
1254
+ allowSuperOutsideMethod: true,
1255
+ allowAwaitOutsideFunction: true,
1256
+ allowReturnOutsideFunction: true,
1257
+ sourceFilename: this.#parsed.filename
1258
+ });
1259
+ this.#cache.set(startIndex, result);
1260
+ return result;
1261
+ } catch {
1262
+ this.#cache.set(startIndex, false);
1263
+ }
1264
+ }
1265
+ };
1266
+
1267
+ // src/extractors/script/util/attach-scopes.ts
1068
1268
  var VISITOR_KEYS = import_compiler.types.VISITOR_KEYS;
1069
1269
  var ATTR_UNNAMED = "value";
1070
1270
  var Scopes = /* @__PURE__ */ new WeakMap();
@@ -1772,19 +1972,6 @@ function detectAPIFromTag(parsed, tag) {
1772
1972
  return detectAPIFromBody(parsed, tag.body);
1773
1973
  }
1774
1974
 
1775
- // src/extractors/script/util/is-text-only-script.ts
1776
- function isTextOnlyScript(tag) {
1777
- if (tag.nameText !== "script" || tag.args || tag.attrs || !tag.body) {
1778
- return false;
1779
- }
1780
- for (const child of tag.body) {
1781
- if (child.type !== 17 /* Text */) {
1782
- return false;
1783
- }
1784
- }
1785
- return true;
1786
- }
1787
-
1788
1975
  // src/extractors/script/util/jsdoc-input-type.ts
1789
1976
  var MaybeInputTypedefReg = /@typedef\b[\s\S]*\bInput\b/;
1790
1977
  function getJSDocInputType(comment, ts) {
@@ -1894,188 +2081,6 @@ function getRuntimeOverrides(api, runtimeTypes, generics, applyGenerics, returnT
1894
2081
  return result;
1895
2082
  }
1896
2083
 
1897
- // src/extractors/script/util/script-parser.ts
1898
- var import_babel = require("@marko/compiler/internal/babel");
1899
- var plugins = ["exportDefaultFrom", "importAssertions", "typescript"];
1900
- var ScriptParser = class {
1901
- #parsed;
1902
- #cache = /* @__PURE__ */ new Map();
1903
- constructor(parsed) {
1904
- this.#parsed = parsed;
1905
- }
1906
- tagName(name) {
1907
- return this.#templateExpressions(name);
1908
- }
1909
- tagShorthandId(shorthandId) {
1910
- return this.#templateExpressions(shorthandId);
1911
- }
1912
- tagShorthandClassName(node) {
1913
- return this.#templateExpressions(node);
1914
- }
1915
- tagVar(node) {
1916
- const start = node.value.start - 1;
1917
- const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1918
- if (expr) {
1919
- return expr.params[0];
1920
- }
1921
- }
1922
- tagParams(node) {
1923
- const start = node.start;
1924
- const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1925
- if (expr) {
1926
- return expr.params;
1927
- }
1928
- }
1929
- tagTypeParams(node) {
1930
- const start = node.value.start - 1;
1931
- const expr = this.#cache.get(start) ?? this.#expressionAt(start, `<${this.#parsed.read(node.value)}>()=>0`);
1932
- if (expr) {
1933
- return expr.typeParameters;
1934
- }
1935
- }
1936
- tagArgs(node) {
1937
- const start = node.value.start - 2;
1938
- const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_(${this.#parsed.read(node.value)})`);
1939
- if (expr) {
1940
- return expr.arguments;
1941
- }
1942
- }
1943
- tagTypeArgs(node) {
1944
- const start = node.value.start - 2;
1945
- const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_<${this.#parsed.read(node.value)}>()`);
1946
- if (expr) {
1947
- return expr.typeParameters;
1948
- }
1949
- }
1950
- attrValue(node) {
1951
- const start = node.value.start;
1952
- return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1953
- }
1954
- attrSpread(node) {
1955
- const start = node.value.start;
1956
- return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1957
- }
1958
- attrMethod(node) {
1959
- const start = node.params.start - 2;
1960
- const expr = this.#cache.get(start) ?? this.#expressionAt(
1961
- start,
1962
- `{_${this.#parsed.read({ start: node.params.start, end: node.body.end })}}`
1963
- );
1964
- if (expr) {
1965
- return expr.properties[0];
1966
- }
1967
- }
1968
- attrArgs(node) {
1969
- const start = node.value.start;
1970
- return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1971
- }
1972
- placeholder(node) {
1973
- const start = node.value.start;
1974
- return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1975
- }
1976
- scriptBody(node) {
1977
- if (!isTextOnlyScript(node)) return;
1978
- const start = node.body[0].start;
1979
- const statements = this.#cache.get(start) ?? this.#statementsAt(
1980
- start,
1981
- this.#parsed.read({ start, end: node.body[node.body.length - 1].end })
1982
- );
1983
- if (statements) {
1984
- return statements;
1985
- }
1986
- }
1987
- scriptlet(node) {
1988
- const start = node.value.start;
1989
- const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read(node.value));
1990
- if (statements) {
1991
- return statements;
1992
- }
1993
- }
1994
- import(node) {
1995
- const statements = this.#cache.get(node.start) ?? this.#statementsAt(node.start, this.#parsed.read(node));
1996
- if (statements) {
1997
- return statements[0];
1998
- }
1999
- }
2000
- export(node) {
2001
- const statements = this.#cache.get(node.start) ?? this.#statementsAt(node.start, this.#parsed.read(node));
2002
- if (statements) {
2003
- return statements[0];
2004
- }
2005
- }
2006
- class(node) {
2007
- const expr = this.#cache.get(node.start) ?? this.#expressionAt(node.start, this.#parsed.read(node));
2008
- return expr || void 0;
2009
- }
2010
- static(node) {
2011
- const start = node.start + "static ".length;
2012
- const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read({ start, end: node.end }));
2013
- if (statements) {
2014
- return statements;
2015
- }
2016
- }
2017
- #templateExpressions(template) {
2018
- const { expressions } = template;
2019
- if (!expressions.length) return;
2020
- const result = [];
2021
- for (const expr of expressions) {
2022
- const start = expr.value.start;
2023
- const parsed = this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(expr.value));
2024
- if (!parsed) return;
2025
- result.push(parsed);
2026
- }
2027
- if (result.length) return result;
2028
- }
2029
- #statementsAt(startIndex, src) {
2030
- try {
2031
- const pos = this.#parsed.positionAt(startIndex);
2032
- const result = (0, import_babel.parse)(src, {
2033
- plugins,
2034
- startIndex,
2035
- startLine: pos.line + 1,
2036
- startColumn: pos.character,
2037
- strictMode: true,
2038
- errorRecovery: true,
2039
- sourceType: "module",
2040
- allowUndeclaredExports: true,
2041
- allowSuperOutsideMethod: true,
2042
- allowAwaitOutsideFunction: true,
2043
- allowReturnOutsideFunction: true,
2044
- sourceFilename: this.#parsed.filename
2045
- }).program.body;
2046
- if (result.length) {
2047
- this.#cache.set(startIndex, result);
2048
- return result;
2049
- }
2050
- } catch {
2051
- }
2052
- this.#cache.set(startIndex, false);
2053
- }
2054
- #expressionAt(startIndex, src) {
2055
- try {
2056
- const pos = this.#parsed.positionAt(startIndex);
2057
- const result = (0, import_babel.parseExpression)(src, {
2058
- plugins,
2059
- startIndex,
2060
- startLine: pos.line + 1,
2061
- startColumn: pos.character,
2062
- strictMode: true,
2063
- errorRecovery: true,
2064
- sourceType: "module",
2065
- allowUndeclaredExports: true,
2066
- allowSuperOutsideMethod: true,
2067
- allowAwaitOutsideFunction: true,
2068
- allowReturnOutsideFunction: true,
2069
- sourceFilename: this.#parsed.filename
2070
- });
2071
- this.#cache.set(startIndex, result);
2072
- return result;
2073
- } catch {
2074
- this.#cache.set(startIndex, false);
2075
- }
2076
- }
2077
- };
2078
-
2079
2084
  // src/extractors/script/index.ts
2080
2085
  var SEP_EMPTY = "";
2081
2086
  var SEP_SPACE = " ";
package/dist/index.mjs CHANGED
@@ -690,6 +690,7 @@ var Extracted = class {
690
690
  );
691
691
  }
692
692
  }
693
+ parsed;
693
694
  #generated;
694
695
  #sourceToGenerated;
695
696
  #generatedToSource;
@@ -1025,6 +1026,208 @@ import { relativeImportPath } from "relative-import-path";
1025
1026
 
1026
1027
  // src/extractors/script/util/attach-scopes.ts
1027
1028
  import { types as t } from "@marko/compiler";
1029
+
1030
+ // src/extractors/script/util/script-parser.ts
1031
+ import {
1032
+ parse as parseStatement,
1033
+ parseExpression
1034
+ } from "@marko/compiler/internal/babel";
1035
+
1036
+ // src/extractors/script/util/is-text-only-script.ts
1037
+ function isTextOnlyScript(tag) {
1038
+ if (tag.nameText !== "script" || tag.args || tag.attrs || !tag.body) {
1039
+ return false;
1040
+ }
1041
+ for (const child of tag.body) {
1042
+ if (child.type !== 17 /* Text */) {
1043
+ return false;
1044
+ }
1045
+ }
1046
+ return true;
1047
+ }
1048
+
1049
+ // src/extractors/script/util/script-parser.ts
1050
+ var plugins = ["exportDefaultFrom", "importAssertions", "typescript"];
1051
+ var ScriptParser = class {
1052
+ #parsed;
1053
+ #cache = /* @__PURE__ */ new Map();
1054
+ constructor(parsed) {
1055
+ this.#parsed = parsed;
1056
+ }
1057
+ tagName(name) {
1058
+ return this.#templateExpressions(name);
1059
+ }
1060
+ tagShorthandId(shorthandId) {
1061
+ return this.#templateExpressions(shorthandId);
1062
+ }
1063
+ tagShorthandClassName(node) {
1064
+ return this.#templateExpressions(node);
1065
+ }
1066
+ tagVar(node) {
1067
+ const start = node.value.start - 1;
1068
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1069
+ if (expr) {
1070
+ return expr.params[0];
1071
+ }
1072
+ }
1073
+ tagParams(node) {
1074
+ const start = node.start;
1075
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1076
+ if (expr) {
1077
+ return expr.params;
1078
+ }
1079
+ }
1080
+ tagTypeParams(node) {
1081
+ const start = node.value.start - 1;
1082
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `<${this.#parsed.read(node.value)}>()=>0`);
1083
+ if (expr) {
1084
+ return expr.typeParameters;
1085
+ }
1086
+ }
1087
+ tagArgs(node) {
1088
+ const start = node.value.start - 2;
1089
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_(${this.#parsed.read(node.value)})`);
1090
+ if (expr) {
1091
+ return expr.arguments;
1092
+ }
1093
+ }
1094
+ tagTypeArgs(node) {
1095
+ const start = node.value.start - 2;
1096
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_<${this.#parsed.read(node.value)}>()`);
1097
+ if (expr) {
1098
+ return expr.typeParameters;
1099
+ }
1100
+ }
1101
+ attrValue(node) {
1102
+ const start = node.value.start;
1103
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1104
+ }
1105
+ attrSpread(node) {
1106
+ const start = node.value.start;
1107
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1108
+ }
1109
+ attrMethod(node) {
1110
+ const start = node.params.start - 2;
1111
+ const expr = this.#cache.get(start) ?? this.#expressionAt(
1112
+ start,
1113
+ `{_${this.#parsed.read({ start: node.params.start, end: node.body.end })}}`
1114
+ );
1115
+ if (expr) {
1116
+ return expr.properties[0];
1117
+ }
1118
+ }
1119
+ attrArgs(node) {
1120
+ const start = node.value.start;
1121
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1122
+ }
1123
+ placeholder(node) {
1124
+ const start = node.value.start;
1125
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1126
+ }
1127
+ scriptBody(node) {
1128
+ if (!isTextOnlyScript(node)) return;
1129
+ const start = node.body[0].start;
1130
+ const statements = this.#cache.get(start) ?? this.#statementsAt(
1131
+ start,
1132
+ this.#parsed.read({ start, end: node.body[node.body.length - 1].end })
1133
+ );
1134
+ if (statements) {
1135
+ return statements;
1136
+ }
1137
+ }
1138
+ scriptlet(node) {
1139
+ const start = node.value.start;
1140
+ const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read(node.value));
1141
+ if (statements) {
1142
+ return statements;
1143
+ }
1144
+ }
1145
+ import(node) {
1146
+ const statements = this.#cache.get(node.start) ?? this.#statementsAt(node.start, this.#parsed.read(node));
1147
+ if (statements) {
1148
+ return statements[0];
1149
+ }
1150
+ }
1151
+ export(node) {
1152
+ const statements = this.#cache.get(node.start) ?? this.#statementsAt(node.start, this.#parsed.read(node));
1153
+ if (statements) {
1154
+ return statements[0];
1155
+ }
1156
+ }
1157
+ class(node) {
1158
+ const expr = this.#cache.get(node.start) ?? this.#expressionAt(node.start, this.#parsed.read(node));
1159
+ return expr || void 0;
1160
+ }
1161
+ static(node) {
1162
+ const start = node.start + "static ".length;
1163
+ const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read({ start, end: node.end }));
1164
+ if (statements) {
1165
+ return statements;
1166
+ }
1167
+ }
1168
+ #templateExpressions(template) {
1169
+ const { expressions } = template;
1170
+ if (!expressions.length) return;
1171
+ const result = [];
1172
+ for (const expr of expressions) {
1173
+ const start = expr.value.start;
1174
+ const parsed = this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(expr.value));
1175
+ if (!parsed) return;
1176
+ result.push(parsed);
1177
+ }
1178
+ if (result.length) return result;
1179
+ }
1180
+ #statementsAt(startIndex, src) {
1181
+ try {
1182
+ const pos = this.#parsed.positionAt(startIndex);
1183
+ const result = parseStatement(src, {
1184
+ plugins,
1185
+ startIndex,
1186
+ startLine: pos.line + 1,
1187
+ startColumn: pos.character,
1188
+ strictMode: true,
1189
+ errorRecovery: true,
1190
+ sourceType: "module",
1191
+ allowUndeclaredExports: true,
1192
+ allowSuperOutsideMethod: true,
1193
+ allowAwaitOutsideFunction: true,
1194
+ allowReturnOutsideFunction: true,
1195
+ sourceFilename: this.#parsed.filename
1196
+ }).program.body;
1197
+ if (result.length) {
1198
+ this.#cache.set(startIndex, result);
1199
+ return result;
1200
+ }
1201
+ } catch {
1202
+ }
1203
+ this.#cache.set(startIndex, false);
1204
+ }
1205
+ #expressionAt(startIndex, src) {
1206
+ try {
1207
+ const pos = this.#parsed.positionAt(startIndex);
1208
+ const result = parseExpression(src, {
1209
+ plugins,
1210
+ startIndex,
1211
+ startLine: pos.line + 1,
1212
+ startColumn: pos.character,
1213
+ strictMode: true,
1214
+ errorRecovery: true,
1215
+ sourceType: "module",
1216
+ allowUndeclaredExports: true,
1217
+ allowSuperOutsideMethod: true,
1218
+ allowAwaitOutsideFunction: true,
1219
+ allowReturnOutsideFunction: true,
1220
+ sourceFilename: this.#parsed.filename
1221
+ });
1222
+ this.#cache.set(startIndex, result);
1223
+ return result;
1224
+ } catch {
1225
+ this.#cache.set(startIndex, false);
1226
+ }
1227
+ }
1228
+ };
1229
+
1230
+ // src/extractors/script/util/attach-scopes.ts
1028
1231
  var VISITOR_KEYS = t.VISITOR_KEYS;
1029
1232
  var ATTR_UNNAMED = "value";
1030
1233
  var Scopes = /* @__PURE__ */ new WeakMap();
@@ -1732,19 +1935,6 @@ function detectAPIFromTag(parsed, tag) {
1732
1935
  return detectAPIFromBody(parsed, tag.body);
1733
1936
  }
1734
1937
 
1735
- // src/extractors/script/util/is-text-only-script.ts
1736
- function isTextOnlyScript(tag) {
1737
- if (tag.nameText !== "script" || tag.args || tag.attrs || !tag.body) {
1738
- return false;
1739
- }
1740
- for (const child of tag.body) {
1741
- if (child.type !== 17 /* Text */) {
1742
- return false;
1743
- }
1744
- }
1745
- return true;
1746
- }
1747
-
1748
1938
  // src/extractors/script/util/jsdoc-input-type.ts
1749
1939
  var MaybeInputTypedefReg = /@typedef\b[\s\S]*\bInput\b/;
1750
1940
  function getJSDocInputType(comment, ts) {
@@ -1854,191 +2044,6 @@ function getRuntimeOverrides(api, runtimeTypes, generics, applyGenerics, returnT
1854
2044
  return result;
1855
2045
  }
1856
2046
 
1857
- // src/extractors/script/util/script-parser.ts
1858
- import {
1859
- parse as parseStatement,
1860
- parseExpression
1861
- } from "@marko/compiler/internal/babel";
1862
- var plugins = ["exportDefaultFrom", "importAssertions", "typescript"];
1863
- var ScriptParser = class {
1864
- #parsed;
1865
- #cache = /* @__PURE__ */ new Map();
1866
- constructor(parsed) {
1867
- this.#parsed = parsed;
1868
- }
1869
- tagName(name) {
1870
- return this.#templateExpressions(name);
1871
- }
1872
- tagShorthandId(shorthandId) {
1873
- return this.#templateExpressions(shorthandId);
1874
- }
1875
- tagShorthandClassName(node) {
1876
- return this.#templateExpressions(node);
1877
- }
1878
- tagVar(node) {
1879
- const start = node.value.start - 1;
1880
- const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1881
- if (expr) {
1882
- return expr.params[0];
1883
- }
1884
- }
1885
- tagParams(node) {
1886
- const start = node.start;
1887
- const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1888
- if (expr) {
1889
- return expr.params;
1890
- }
1891
- }
1892
- tagTypeParams(node) {
1893
- const start = node.value.start - 1;
1894
- const expr = this.#cache.get(start) ?? this.#expressionAt(start, `<${this.#parsed.read(node.value)}>()=>0`);
1895
- if (expr) {
1896
- return expr.typeParameters;
1897
- }
1898
- }
1899
- tagArgs(node) {
1900
- const start = node.value.start - 2;
1901
- const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_(${this.#parsed.read(node.value)})`);
1902
- if (expr) {
1903
- return expr.arguments;
1904
- }
1905
- }
1906
- tagTypeArgs(node) {
1907
- const start = node.value.start - 2;
1908
- const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_<${this.#parsed.read(node.value)}>()`);
1909
- if (expr) {
1910
- return expr.typeParameters;
1911
- }
1912
- }
1913
- attrValue(node) {
1914
- const start = node.value.start;
1915
- return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1916
- }
1917
- attrSpread(node) {
1918
- const start = node.value.start;
1919
- return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1920
- }
1921
- attrMethod(node) {
1922
- const start = node.params.start - 2;
1923
- const expr = this.#cache.get(start) ?? this.#expressionAt(
1924
- start,
1925
- `{_${this.#parsed.read({ start: node.params.start, end: node.body.end })}}`
1926
- );
1927
- if (expr) {
1928
- return expr.properties[0];
1929
- }
1930
- }
1931
- attrArgs(node) {
1932
- const start = node.value.start;
1933
- return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1934
- }
1935
- placeholder(node) {
1936
- const start = node.value.start;
1937
- return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1938
- }
1939
- scriptBody(node) {
1940
- if (!isTextOnlyScript(node)) return;
1941
- const start = node.body[0].start;
1942
- const statements = this.#cache.get(start) ?? this.#statementsAt(
1943
- start,
1944
- this.#parsed.read({ start, end: node.body[node.body.length - 1].end })
1945
- );
1946
- if (statements) {
1947
- return statements;
1948
- }
1949
- }
1950
- scriptlet(node) {
1951
- const start = node.value.start;
1952
- const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read(node.value));
1953
- if (statements) {
1954
- return statements;
1955
- }
1956
- }
1957
- import(node) {
1958
- const statements = this.#cache.get(node.start) ?? this.#statementsAt(node.start, this.#parsed.read(node));
1959
- if (statements) {
1960
- return statements[0];
1961
- }
1962
- }
1963
- export(node) {
1964
- const statements = this.#cache.get(node.start) ?? this.#statementsAt(node.start, this.#parsed.read(node));
1965
- if (statements) {
1966
- return statements[0];
1967
- }
1968
- }
1969
- class(node) {
1970
- const expr = this.#cache.get(node.start) ?? this.#expressionAt(node.start, this.#parsed.read(node));
1971
- return expr || void 0;
1972
- }
1973
- static(node) {
1974
- const start = node.start + "static ".length;
1975
- const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read({ start, end: node.end }));
1976
- if (statements) {
1977
- return statements;
1978
- }
1979
- }
1980
- #templateExpressions(template) {
1981
- const { expressions } = template;
1982
- if (!expressions.length) return;
1983
- const result = [];
1984
- for (const expr of expressions) {
1985
- const start = expr.value.start;
1986
- const parsed = this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(expr.value));
1987
- if (!parsed) return;
1988
- result.push(parsed);
1989
- }
1990
- if (result.length) return result;
1991
- }
1992
- #statementsAt(startIndex, src) {
1993
- try {
1994
- const pos = this.#parsed.positionAt(startIndex);
1995
- const result = parseStatement(src, {
1996
- plugins,
1997
- startIndex,
1998
- startLine: pos.line + 1,
1999
- startColumn: pos.character,
2000
- strictMode: true,
2001
- errorRecovery: true,
2002
- sourceType: "module",
2003
- allowUndeclaredExports: true,
2004
- allowSuperOutsideMethod: true,
2005
- allowAwaitOutsideFunction: true,
2006
- allowReturnOutsideFunction: true,
2007
- sourceFilename: this.#parsed.filename
2008
- }).program.body;
2009
- if (result.length) {
2010
- this.#cache.set(startIndex, result);
2011
- return result;
2012
- }
2013
- } catch {
2014
- }
2015
- this.#cache.set(startIndex, false);
2016
- }
2017
- #expressionAt(startIndex, src) {
2018
- try {
2019
- const pos = this.#parsed.positionAt(startIndex);
2020
- const result = parseExpression(src, {
2021
- plugins,
2022
- startIndex,
2023
- startLine: pos.line + 1,
2024
- startColumn: pos.character,
2025
- strictMode: true,
2026
- errorRecovery: true,
2027
- sourceType: "module",
2028
- allowUndeclaredExports: true,
2029
- allowSuperOutsideMethod: true,
2030
- allowAwaitOutsideFunction: true,
2031
- allowReturnOutsideFunction: true,
2032
- sourceFilename: this.#parsed.filename
2033
- });
2034
- this.#cache.set(startIndex, result);
2035
- return result;
2036
- } catch {
2037
- this.#cache.set(startIndex, false);
2038
- }
2039
- }
2040
- };
2041
-
2042
2047
  // src/extractors/script/index.ts
2043
2048
  var SEP_EMPTY = "";
2044
2049
  var SEP_SPACE = " ";
@@ -1,2 +1,2 @@
1
- import { Node } from "../parser";
1
+ import { type Node } from "../parser";
2
2
  export declare function getNodeAtOffset(offset: number, program: Node.Program): Node.AnyNode;
@@ -439,24 +439,24 @@ declare global {
439
439
  ...attrTags: AttrTags
440
440
  ) => AttrTagsToAttrTag<Name, AttrTags>;
441
441
 
442
- // TODO: this could be improved.
443
- // currently falls back to DefaultRenderer too eagerly.
444
442
  export type DynamicRenderer<Name> = [0] extends [1 & Name]
445
443
  ? DefaultRenderer
446
- : [Name] extends [Marko.Template<any, any>]
447
- ? TemplateRenderer<Name>
448
- : [Name] extends [string]
449
- ? NativeTagRenderer<Name>
450
- : [Name] extends [AnyMarkoBody]
451
- ? BodyRenderer<Name>
452
- : [Name] extends [
453
- {
454
- [BodyContentKey in DefaultBodyContentKey]?: infer BodyValue extends
455
- AnyMarkoBody;
456
- },
457
- ]
458
- ? BodyRenderer<BodyValue>
459
- : DefaultRenderer;
444
+ : [Name] extends [Marko.Template<any, any> | string]
445
+ ? {
446
+ (): () => <Input extends Marko.Input<Name>>(
447
+ input: Marko.Directives & Input,
448
+ ) => ReturnAndScope<Scopes<Input>, Marko.Return<Name>>;
449
+ }
450
+ : [Name] extends [AnyMarkoBody]
451
+ ? BodyRenderer<Name>
452
+ : [Name] extends [
453
+ {
454
+ [BodyContentKey in DefaultBodyContentKey]?: infer BodyValue extends
455
+ AnyMarkoBody;
456
+ },
457
+ ]
458
+ ? BodyRenderer<BodyValue>
459
+ : DefaultRenderer;
460
460
 
461
461
  export type TemplateRenderer<Template> = Template extends {
462
462
  _: infer Renderer;
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@marko/language-tools",
3
+ "version": "2.5.59",
3
4
  "description": "Marko Language Tools",
4
- "version": "2.5.58",
5
- "bugs": "https://github.com/marko-js/language-server/issues/new?template=Bug_report.md",
6
- "dependencies": {
7
- "@marko/compiler": "^5.39.61",
8
- "@luxass/strip-json-comments": "^1.4.0",
9
- "htmljs-parser": "^5.10.2",
10
- "relative-import-path": "^1.0.0"
11
- },
12
- "devDependencies": {
13
- "@types/babel__code-frame": "^7.27.0",
14
- "@typescript/vfs": "^1.6.4",
15
- "marko": "^5.38.31",
16
- "mitata": "^1.0.34",
17
- "tsx": "^4.21.0"
5
+ "keywords": [
6
+ "analysis",
7
+ "analyze",
8
+ "language",
9
+ "marko",
10
+ "tools"
11
+ ],
12
+ "homepage": "https://github.com/marko-js/language-server/tree/main/packages/language-tools/README.md",
13
+ "bugs": "https://github.com/marko-js/language-server/issues/new?template=bug-report.yml",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/marko-js/language-server/tree/main/packages/language-tools"
18
17
  },
18
+ "license": "MIT",
19
19
  "exports": {
20
20
  ".": {
21
21
  "import": "./dist/index.mjs",
@@ -23,29 +23,29 @@
23
23
  },
24
24
  "./marko.internal.d.ts": "./marko.internal.d.ts"
25
25
  },
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.mjs",
26
28
  "files": [
27
29
  "dist",
28
30
  "!**/__tests__",
29
31
  "!**/*.tsbuildinfo",
30
32
  "marko.internal.d.ts"
31
33
  ],
32
- "homepage": "https://github.com/marko-js/language-server/tree/main/packages/language-tools/README.md",
33
- "keywords": [
34
- "analysis",
35
- "analyze",
36
- "language",
37
- "marko",
38
- "tools"
39
- ],
40
- "license": "MIT",
41
- "main": "./dist/index.js",
42
- "module": "./dist/index.mjs",
43
- "repository": {
44
- "type": "git",
45
- "url": "https://github.com/marko-js/language-server/tree/main/packages/language-tools"
46
- },
47
34
  "scripts": {
48
35
  "bench": "BENCH=1 mocha './src/**/__tests__/*.test.ts'",
49
- "build": "tsc -b && tsx build.mts"
36
+ "build": "tsx build.mts"
37
+ },
38
+ "dependencies": {
39
+ "@luxass/strip-json-comments": "^1.4.0",
40
+ "@marko/compiler": "^5.39.63",
41
+ "htmljs-parser": "^5.10.2",
42
+ "relative-import-path": "^1.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/babel__code-frame": "^7.27.0",
46
+ "@typescript/vfs": "^1.6.4",
47
+ "marko": "^5.38.36",
48
+ "mitata": "^1.0.34",
49
+ "tsx": "^4.21.0"
50
50
  }
51
51
  }