@marko/language-tools 2.5.58 → 2.5.60

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.d.ts CHANGED
@@ -6,4 +6,5 @@ export * as Processors from "./processors";
6
6
  export { type Extracted } from "./util/extractor";
7
7
  export { getExt } from "./util/get-ext";
8
8
  export { isDefinitionFile } from "./util/is-definition-file";
9
+ export { normalizePath } from "./util/normalize-path";
9
10
  export * as Project from "./util/project";
package/dist/index.js CHANGED
@@ -44,6 +44,7 @@ __export(index_exports, {
44
44
  getPosition: () => import_htmljs_parser2.getPosition,
45
45
  isControlFlowTag: () => isControlFlowTag,
46
46
  isDefinitionFile: () => isDefinitionFile,
47
+ normalizePath: () => normalizePath,
47
48
  parse: () => parse
48
49
  });
49
50
  module.exports = __toCommonJS(index_exports);
@@ -132,6 +133,11 @@ function childAtOffset(offset, children) {
132
133
  return offset > child.start && offset <= child.end ? child : void 0;
133
134
  }
134
135
 
136
+ // src/util/normalize-path.ts
137
+ var import_path = __toESM(require("path"));
138
+ var sepReg = /\//g;
139
+ var normalizePath = import_path.default.sep === "/" ? (filename) => filename : (filename) => filename.replace(sepReg, import_path.default.sep);
140
+
135
141
  // src/parser.ts
136
142
  var import_htmljs_parser2 = require("htmljs-parser");
137
143
  var styleBlockReg = /((?:\.[^\s\\/:*?"<>|({]+)*)\s*\{/y;
@@ -178,7 +184,7 @@ function parse(code, filename = "index.marko") {
178
184
  locationAt: parser.locationAt,
179
185
  positionAt: parser.positionAt,
180
186
  nodeAt: (offset) => getNodeAtOffset(offset, program),
181
- filename,
187
+ filename: normalizePath(filename),
182
188
  program,
183
189
  code
184
190
  };
@@ -730,6 +736,7 @@ var Extracted = class {
730
736
  );
731
737
  }
732
738
  }
739
+ parsed;
733
740
  #generated;
734
741
  #sourceToGenerated;
735
742
  #generatedToSource;
@@ -1065,6 +1072,205 @@ var import_relative_import_path = require("relative-import-path");
1065
1072
 
1066
1073
  // src/extractors/script/util/attach-scopes.ts
1067
1074
  var import_compiler = require("@marko/compiler");
1075
+
1076
+ // src/extractors/script/util/script-parser.ts
1077
+ var import_babel = require("@marko/compiler/internal/babel");
1078
+
1079
+ // src/extractors/script/util/is-text-only-script.ts
1080
+ function isTextOnlyScript(tag) {
1081
+ if (tag.nameText !== "script" || tag.args || tag.attrs || !tag.body) {
1082
+ return false;
1083
+ }
1084
+ for (const child of tag.body) {
1085
+ if (child.type !== 17 /* Text */) {
1086
+ return false;
1087
+ }
1088
+ }
1089
+ return true;
1090
+ }
1091
+
1092
+ // src/extractors/script/util/script-parser.ts
1093
+ var plugins = ["exportDefaultFrom", "importAssertions", "typescript"];
1094
+ var ScriptParser = class {
1095
+ #parsed;
1096
+ #cache = /* @__PURE__ */ new Map();
1097
+ constructor(parsed) {
1098
+ this.#parsed = parsed;
1099
+ }
1100
+ tagName(name) {
1101
+ return this.#templateExpressions(name);
1102
+ }
1103
+ tagShorthandId(shorthandId) {
1104
+ return this.#templateExpressions(shorthandId);
1105
+ }
1106
+ tagShorthandClassName(node) {
1107
+ return this.#templateExpressions(node);
1108
+ }
1109
+ tagVar(node) {
1110
+ const start = node.value.start - 1;
1111
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1112
+ if (expr) {
1113
+ return expr.params[0];
1114
+ }
1115
+ }
1116
+ tagParams(node) {
1117
+ const start = node.start;
1118
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1119
+ if (expr) {
1120
+ return expr.params;
1121
+ }
1122
+ }
1123
+ tagTypeParams(node) {
1124
+ const start = node.value.start - 1;
1125
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `<${this.#parsed.read(node.value)}>()=>0`);
1126
+ if (expr) {
1127
+ return expr.typeParameters;
1128
+ }
1129
+ }
1130
+ tagArgs(node) {
1131
+ const start = node.value.start - 2;
1132
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_(${this.#parsed.read(node.value)})`);
1133
+ if (expr) {
1134
+ return expr.arguments;
1135
+ }
1136
+ }
1137
+ tagTypeArgs(node) {
1138
+ const start = node.value.start - 2;
1139
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_<${this.#parsed.read(node.value)}>()`);
1140
+ if (expr) {
1141
+ return expr.typeParameters;
1142
+ }
1143
+ }
1144
+ attrValue(node) {
1145
+ const start = node.value.start;
1146
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1147
+ }
1148
+ attrSpread(node) {
1149
+ const start = node.value.start;
1150
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1151
+ }
1152
+ attrMethod(node) {
1153
+ const start = node.params.start - 2;
1154
+ const expr = this.#cache.get(start) ?? this.#expressionAt(
1155
+ start,
1156
+ `{_${this.#parsed.read({ start: node.params.start, end: node.body.end })}}`
1157
+ );
1158
+ if (expr) {
1159
+ return expr.properties[0];
1160
+ }
1161
+ }
1162
+ attrArgs(node) {
1163
+ const start = node.value.start;
1164
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1165
+ }
1166
+ placeholder(node) {
1167
+ const start = node.value.start;
1168
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1169
+ }
1170
+ scriptBody(node) {
1171
+ if (!isTextOnlyScript(node)) return;
1172
+ const start = node.body[0].start;
1173
+ const statements = this.#cache.get(start) ?? this.#statementsAt(
1174
+ start,
1175
+ this.#parsed.read({ start, end: node.body[node.body.length - 1].end })
1176
+ );
1177
+ if (statements) {
1178
+ return statements;
1179
+ }
1180
+ }
1181
+ scriptlet(node) {
1182
+ const start = node.value.start;
1183
+ const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read(node.value));
1184
+ if (statements) {
1185
+ return statements;
1186
+ }
1187
+ }
1188
+ import(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
+ export(node) {
1195
+ const statements = this.#cache.get(node.start) ?? this.#statementsAt(node.start, this.#parsed.read(node));
1196
+ if (statements) {
1197
+ return statements[0];
1198
+ }
1199
+ }
1200
+ class(node) {
1201
+ const expr = this.#cache.get(node.start) ?? this.#expressionAt(node.start, this.#parsed.read(node));
1202
+ return expr || void 0;
1203
+ }
1204
+ static(node) {
1205
+ const start = node.start + "static ".length;
1206
+ const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read({ start, end: node.end }));
1207
+ if (statements) {
1208
+ return statements;
1209
+ }
1210
+ }
1211
+ #templateExpressions(template) {
1212
+ const { expressions } = template;
1213
+ if (!expressions.length) return;
1214
+ const result = [];
1215
+ for (const expr of expressions) {
1216
+ const start = expr.value.start;
1217
+ const parsed = this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(expr.value));
1218
+ if (!parsed) return;
1219
+ result.push(parsed);
1220
+ }
1221
+ if (result.length) return result;
1222
+ }
1223
+ #statementsAt(startIndex, src) {
1224
+ try {
1225
+ const pos = this.#parsed.positionAt(startIndex);
1226
+ const result = (0, import_babel.parse)(src, {
1227
+ plugins,
1228
+ startIndex,
1229
+ startLine: pos.line + 1,
1230
+ startColumn: pos.character,
1231
+ strictMode: true,
1232
+ errorRecovery: true,
1233
+ sourceType: "module",
1234
+ allowUndeclaredExports: true,
1235
+ allowSuperOutsideMethod: true,
1236
+ allowAwaitOutsideFunction: true,
1237
+ allowReturnOutsideFunction: true,
1238
+ sourceFilename: this.#parsed.filename
1239
+ }).program.body;
1240
+ if (result.length) {
1241
+ this.#cache.set(startIndex, result);
1242
+ return result;
1243
+ }
1244
+ } catch {
1245
+ }
1246
+ this.#cache.set(startIndex, false);
1247
+ }
1248
+ #expressionAt(startIndex, src) {
1249
+ try {
1250
+ const pos = this.#parsed.positionAt(startIndex);
1251
+ const result = (0, import_babel.parseExpression)(src, {
1252
+ plugins,
1253
+ startIndex,
1254
+ startLine: pos.line + 1,
1255
+ startColumn: pos.character,
1256
+ strictMode: true,
1257
+ errorRecovery: true,
1258
+ sourceType: "module",
1259
+ allowUndeclaredExports: true,
1260
+ allowSuperOutsideMethod: true,
1261
+ allowAwaitOutsideFunction: true,
1262
+ allowReturnOutsideFunction: true,
1263
+ sourceFilename: this.#parsed.filename
1264
+ });
1265
+ this.#cache.set(startIndex, result);
1266
+ return result;
1267
+ } catch {
1268
+ this.#cache.set(startIndex, false);
1269
+ }
1270
+ }
1271
+ };
1272
+
1273
+ // src/extractors/script/util/attach-scopes.ts
1068
1274
  var VISITOR_KEYS = import_compiler.types.VISITOR_KEYS;
1069
1275
  var ATTR_UNNAMED = "value";
1070
1276
  var Scopes = /* @__PURE__ */ new WeakMap();
@@ -1616,10 +1822,10 @@ function byStart(a, b) {
1616
1822
 
1617
1823
  // src/extractors/script/util/get-component-filename.ts
1618
1824
  var import_fs = __toESM(require("fs"));
1619
- var import_path = __toESM(require("path"));
1825
+ var import_path2 = __toESM(require("path"));
1620
1826
  function getComponentFilename(from) {
1621
- const dir = import_path.default.dirname(from);
1622
- let nameNoExt = import_path.default.basename(from, ".marko");
1827
+ const dir = import_path2.default.dirname(from);
1828
+ let nameNoExt = import_path2.default.basename(from, ".marko");
1623
1829
  if (nameNoExt.endsWith(".d")) {
1624
1830
  nameNoExt = nameNoExt.slice(0, -2);
1625
1831
  }
@@ -1630,7 +1836,7 @@ function getComponentFilename(from) {
1630
1836
  );
1631
1837
  for (const entry of tryReaddirSync(dir)) {
1632
1838
  if (componentMatch.test(entry)) {
1633
- return import_path.default.join(dir, entry);
1839
+ return import_path2.default.join(dir, entry);
1634
1840
  }
1635
1841
  }
1636
1842
  }
@@ -1772,19 +1978,6 @@ function detectAPIFromTag(parsed, tag) {
1772
1978
  return detectAPIFromBody(parsed, tag.body);
1773
1979
  }
1774
1980
 
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
1981
  // src/extractors/script/util/jsdoc-input-type.ts
1789
1982
  var MaybeInputTypedefReg = /@typedef\b[\s\S]*\bInput\b/;
1790
1983
  function getJSDocInputType(comment, ts) {
@@ -1894,188 +2087,6 @@ function getRuntimeOverrides(api, runtimeTypes, generics, applyGenerics, returnT
1894
2087
  return result;
1895
2088
  }
1896
2089
 
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
2090
  // src/extractors/script/index.ts
2080
2091
  var SEP_EMPTY = "";
2081
2092
  var SEP_SPACE = " ";
@@ -3456,17 +3467,17 @@ ${isMutatedVar(tag.parent, valueLiteral) ? varLocal(`change__${valueLiteral}.`)
3456
3467
  return ((_a = this.#lookup.getTag(nameText)) == null ? void 0 : _a.targetProperty) || nameText.slice(nameText.lastIndexOf(":") + 1);
3457
3468
  }
3458
3469
  #getAttrTagPath(tag) {
3459
- let path4 = `"${this.#getAttrTagName(tag)}"`;
3470
+ let path5 = `"${this.#getAttrTagName(tag)}"`;
3460
3471
  let curTag = tag.parent;
3461
3472
  while (curTag) {
3462
3473
  if (curTag.type === 16 /* AttrTag */) {
3463
- path4 = `"${this.#getAttrTagName(curTag)}",${path4}`;
3474
+ path5 = `"${this.#getAttrTagName(curTag)}",${path5}`;
3464
3475
  } else if (!isControlFlowTag(curTag)) {
3465
3476
  break;
3466
3477
  }
3467
3478
  curTag = curTag.parent;
3468
3479
  }
3469
- return path4;
3480
+ return path5;
3470
3481
  }
3471
3482
  #getTagInputType(tag) {
3472
3483
  if (tag.type === 16 /* AttrTag */) {
@@ -3602,7 +3613,7 @@ function isValueAttribute(attr) {
3602
3613
  function resolveTagImport(from, def) {
3603
3614
  const filename = resolveTagFile(def);
3604
3615
  if (filename) {
3605
- return from ? (0, import_relative_import_path.relativeImportPath)(from, filename) : filename;
3616
+ return from ? (0, import_relative_import_path.relativeImportPath)(from, normalizePath(filename)) : filename;
3606
3617
  }
3607
3618
  }
3608
3619
  function resolveTagFile(def) {
@@ -3713,7 +3724,7 @@ function getExt(fileName) {
3713
3724
  }
3714
3725
 
3715
3726
  // src/processors/marko.ts
3716
- var import_path3 = __toESM(require("path"));
3727
+ var import_path4 = __toESM(require("path"));
3717
3728
 
3718
3729
  // src/util/project.ts
3719
3730
  var project_exports = {};
@@ -3730,7 +3741,7 @@ __export(project_exports, {
3730
3741
  });
3731
3742
  var import_strip_json_comments = require("@luxass/strip-json-comments");
3732
3743
  var import_module = require("module");
3733
- var import_path2 = __toESM(require("path"));
3744
+ var import_path3 = __toESM(require("path"));
3734
3745
  var defaultTypeLibs = {};
3735
3746
  var defaultMeta;
3736
3747
  var ignoreErrors = (_err) => {
@@ -3757,11 +3768,11 @@ function getTypeLibs(rootDir, ts, host) {
3757
3768
  const resolveTypeCompilerOptions = {
3758
3769
  moduleResolution: ts.ModuleResolutionKind.Bundler
3759
3770
  };
3760
- const markoRunGeneratedTypesFile = import_path2.default.join(
3771
+ const markoRunGeneratedTypesFile = import_path3.default.join(
3761
3772
  rootDir,
3762
3773
  ".marko-run/routes.d.ts"
3763
3774
  );
3764
- const resolveFromFile = import_path2.default.join(rootDir, "_.d.ts");
3775
+ const resolveFromFile = import_path3.default.join(rootDir, "_.d.ts");
3765
3776
  const internalTypesFile = defaultTypeLibs.internalTypesFile || ((_a = ts.resolveTypeReferenceDirective(
3766
3777
  "@marko/language-tools/marko.internal.d.ts",
3767
3778
  resolveFromFile,
@@ -3799,7 +3810,7 @@ function getTypeLibs(rootDir, ts, host) {
3799
3810
  }
3800
3811
  function getScriptLang(fileName, defaultScriptLang, ts, host) {
3801
3812
  if (fileName.endsWith(".d.marko")) return "ts" /* ts */;
3802
- const dir = import_path2.default.dirname(fileName);
3813
+ const dir = import_path3.default.dirname(fileName);
3803
3814
  const config = getConfig(dir);
3804
3815
  const cache = config.cache.get(getScriptLang);
3805
3816
  let scriptLang = cache == null ? void 0 : cache.get(dir);
@@ -3883,7 +3894,7 @@ function getMeta(dir) {
3883
3894
  function loadMeta(dir) {
3884
3895
  let cached = metaByDir.get(dir);
3885
3896
  if (!cached) {
3886
- const require2 = (0, import_module.createRequire)(import_path2.default.join(dir, "_.js"));
3897
+ const require2 = (0, import_module.createRequire)(import_path3.default.join(dir, "_.js"));
3887
3898
  const configPath = (() => {
3888
3899
  try {
3889
3900
  return require2.resolve("@marko/compiler/config");
@@ -3897,7 +3908,7 @@ function loadMeta(dir) {
3897
3908
  const translatorPath = require2.resolve(config.translator);
3898
3909
  cached = metaByTranslator.get(translatorPath);
3899
3910
  if (!cached) {
3900
- const compiler = require2(import_path2.default.dirname(configPath));
3911
+ const compiler = require2(import_path3.default.dirname(configPath));
3901
3912
  cached = {
3902
3913
  compiler,
3903
3914
  config: {
@@ -3958,13 +3969,13 @@ var marko_default = {
3958
3969
  extension: ".marko",
3959
3970
  create({ ts, host, configFile }) {
3960
3971
  const currentDirectory = host.getCurrentDirectory ? host.getCurrentDirectory() : ts.sys.getCurrentDirectory();
3961
- const defaultScriptLang = configFile && /tsconfig/g.test(configFile) ? "ts" /* ts */ : "js" /* js */;
3972
+ const defaultScriptLang = configFile && /tsconfig/.test(configFile) ? "ts" /* ts */ : "js" /* js */;
3962
3973
  const runtimeTypes = getTypeLibs(currentDirectory, ts, host);
3963
3974
  const rootNames = [
3964
3975
  runtimeTypes.internalTypesFile,
3965
3976
  runtimeTypes.markoTypesFile
3966
3977
  ];
3967
- const getJSFileIfTSExists = (source, importer) => host.fileExists(import_path3.default.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3978
+ const getJSFileIfTSExists = (source, importer) => host.fileExists(import_path4.default.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3968
3979
  const compileConfig = {
3969
3980
  output: "source",
3970
3981
  stripTypes: true,
@@ -4020,8 +4031,8 @@ var marko_default = {
4020
4031
  return getScriptLang(fileName, defaultScriptLang, ts, host) === "ts" /* ts */ ? ts.ScriptKind.TS : ts.ScriptKind.JS;
4021
4032
  },
4022
4033
  extract(fileName, code) {
4023
- const dir = import_path3.default.dirname(fileName);
4024
4034
  const parsed = parse(code, fileName);
4035
+ const dir = import_path4.default.dirname(parsed.filename);
4025
4036
  return extractScript({
4026
4037
  ts,
4027
4038
  parsed,
@@ -4038,7 +4049,7 @@ var marko_default = {
4038
4049
  },
4039
4050
  print({ extracted: { parsed } }) {
4040
4051
  const { code, map } = getCompiler(
4041
- import_path3.default.dirname(parsed.filename)
4052
+ import_path4.default.dirname(parsed.filename)
4042
4053
  ).compileSync(parsed.code, parsed.filename, compileConfig);
4043
4054
  return { code, map };
4044
4055
  },
@@ -4183,5 +4194,6 @@ function isDefinitionFile(fileName) {
4183
4194
  getPosition,
4184
4195
  isControlFlowTag,
4185
4196
  isDefinitionFile,
4197
+ normalizePath,
4186
4198
  parse
4187
4199
  });
package/dist/index.mjs CHANGED
@@ -88,6 +88,11 @@ function childAtOffset(offset, children) {
88
88
  return offset > child.start && offset <= child.end ? child : void 0;
89
89
  }
90
90
 
91
+ // src/util/normalize-path.ts
92
+ import path from "path";
93
+ var sepReg = /\//g;
94
+ var normalizePath = path.sep === "/" ? (filename) => filename : (filename) => filename.replace(sepReg, path.sep);
95
+
91
96
  // src/parser.ts
92
97
  import {
93
98
  getLines,
@@ -138,7 +143,7 @@ function parse(code, filename = "index.marko") {
138
143
  locationAt: parser.locationAt,
139
144
  positionAt: parser.positionAt,
140
145
  nodeAt: (offset) => getNodeAtOffset(offset, program),
141
- filename,
146
+ filename: normalizePath(filename),
142
147
  program,
143
148
  code
144
149
  };
@@ -690,6 +695,7 @@ var Extracted = class {
690
695
  );
691
696
  }
692
697
  }
698
+ parsed;
693
699
  #generated;
694
700
  #sourceToGenerated;
695
701
  #generatedToSource;
@@ -1025,6 +1031,208 @@ import { relativeImportPath } from "relative-import-path";
1025
1031
 
1026
1032
  // src/extractors/script/util/attach-scopes.ts
1027
1033
  import { types as t } from "@marko/compiler";
1034
+
1035
+ // src/extractors/script/util/script-parser.ts
1036
+ import {
1037
+ parse as parseStatement,
1038
+ parseExpression
1039
+ } from "@marko/compiler/internal/babel";
1040
+
1041
+ // src/extractors/script/util/is-text-only-script.ts
1042
+ function isTextOnlyScript(tag) {
1043
+ if (tag.nameText !== "script" || tag.args || tag.attrs || !tag.body) {
1044
+ return false;
1045
+ }
1046
+ for (const child of tag.body) {
1047
+ if (child.type !== 17 /* Text */) {
1048
+ return false;
1049
+ }
1050
+ }
1051
+ return true;
1052
+ }
1053
+
1054
+ // src/extractors/script/util/script-parser.ts
1055
+ var plugins = ["exportDefaultFrom", "importAssertions", "typescript"];
1056
+ var ScriptParser = class {
1057
+ #parsed;
1058
+ #cache = /* @__PURE__ */ new Map();
1059
+ constructor(parsed) {
1060
+ this.#parsed = parsed;
1061
+ }
1062
+ tagName(name) {
1063
+ return this.#templateExpressions(name);
1064
+ }
1065
+ tagShorthandId(shorthandId) {
1066
+ return this.#templateExpressions(shorthandId);
1067
+ }
1068
+ tagShorthandClassName(node) {
1069
+ return this.#templateExpressions(node);
1070
+ }
1071
+ tagVar(node) {
1072
+ const start = node.value.start - 1;
1073
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1074
+ if (expr) {
1075
+ return expr.params[0];
1076
+ }
1077
+ }
1078
+ tagParams(node) {
1079
+ const start = node.start;
1080
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `(${this.#parsed.read(node.value)})=>0`);
1081
+ if (expr) {
1082
+ return expr.params;
1083
+ }
1084
+ }
1085
+ tagTypeParams(node) {
1086
+ const start = node.value.start - 1;
1087
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `<${this.#parsed.read(node.value)}>()=>0`);
1088
+ if (expr) {
1089
+ return expr.typeParameters;
1090
+ }
1091
+ }
1092
+ tagArgs(node) {
1093
+ const start = node.value.start - 2;
1094
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_(${this.#parsed.read(node.value)})`);
1095
+ if (expr) {
1096
+ return expr.arguments;
1097
+ }
1098
+ }
1099
+ tagTypeArgs(node) {
1100
+ const start = node.value.start - 2;
1101
+ const expr = this.#cache.get(start) ?? this.#expressionAt(start, `_<${this.#parsed.read(node.value)}>()`);
1102
+ if (expr) {
1103
+ return expr.typeParameters;
1104
+ }
1105
+ }
1106
+ attrValue(node) {
1107
+ const start = node.value.start;
1108
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1109
+ }
1110
+ attrSpread(node) {
1111
+ const start = node.value.start;
1112
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1113
+ }
1114
+ attrMethod(node) {
1115
+ const start = node.params.start - 2;
1116
+ const expr = this.#cache.get(start) ?? this.#expressionAt(
1117
+ start,
1118
+ `{_${this.#parsed.read({ start: node.params.start, end: node.body.end })}}`
1119
+ );
1120
+ if (expr) {
1121
+ return expr.properties[0];
1122
+ }
1123
+ }
1124
+ attrArgs(node) {
1125
+ const start = node.value.start;
1126
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1127
+ }
1128
+ placeholder(node) {
1129
+ const start = node.value.start;
1130
+ return (this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(node.value))) || void 0;
1131
+ }
1132
+ scriptBody(node) {
1133
+ if (!isTextOnlyScript(node)) return;
1134
+ const start = node.body[0].start;
1135
+ const statements = this.#cache.get(start) ?? this.#statementsAt(
1136
+ start,
1137
+ this.#parsed.read({ start, end: node.body[node.body.length - 1].end })
1138
+ );
1139
+ if (statements) {
1140
+ return statements;
1141
+ }
1142
+ }
1143
+ scriptlet(node) {
1144
+ const start = node.value.start;
1145
+ const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read(node.value));
1146
+ if (statements) {
1147
+ return statements;
1148
+ }
1149
+ }
1150
+ import(node) {
1151
+ const statements = this.#cache.get(node.start) ?? this.#statementsAt(node.start, this.#parsed.read(node));
1152
+ if (statements) {
1153
+ return statements[0];
1154
+ }
1155
+ }
1156
+ export(node) {
1157
+ const statements = this.#cache.get(node.start) ?? this.#statementsAt(node.start, this.#parsed.read(node));
1158
+ if (statements) {
1159
+ return statements[0];
1160
+ }
1161
+ }
1162
+ class(node) {
1163
+ const expr = this.#cache.get(node.start) ?? this.#expressionAt(node.start, this.#parsed.read(node));
1164
+ return expr || void 0;
1165
+ }
1166
+ static(node) {
1167
+ const start = node.start + "static ".length;
1168
+ const statements = this.#cache.get(start) ?? this.#statementsAt(start, this.#parsed.read({ start, end: node.end }));
1169
+ if (statements) {
1170
+ return statements;
1171
+ }
1172
+ }
1173
+ #templateExpressions(template) {
1174
+ const { expressions } = template;
1175
+ if (!expressions.length) return;
1176
+ const result = [];
1177
+ for (const expr of expressions) {
1178
+ const start = expr.value.start;
1179
+ const parsed = this.#cache.get(start) ?? this.#expressionAt(start, this.#parsed.read(expr.value));
1180
+ if (!parsed) return;
1181
+ result.push(parsed);
1182
+ }
1183
+ if (result.length) return result;
1184
+ }
1185
+ #statementsAt(startIndex, src) {
1186
+ try {
1187
+ const pos = this.#parsed.positionAt(startIndex);
1188
+ const result = parseStatement(src, {
1189
+ plugins,
1190
+ startIndex,
1191
+ startLine: pos.line + 1,
1192
+ startColumn: pos.character,
1193
+ strictMode: true,
1194
+ errorRecovery: true,
1195
+ sourceType: "module",
1196
+ allowUndeclaredExports: true,
1197
+ allowSuperOutsideMethod: true,
1198
+ allowAwaitOutsideFunction: true,
1199
+ allowReturnOutsideFunction: true,
1200
+ sourceFilename: this.#parsed.filename
1201
+ }).program.body;
1202
+ if (result.length) {
1203
+ this.#cache.set(startIndex, result);
1204
+ return result;
1205
+ }
1206
+ } catch {
1207
+ }
1208
+ this.#cache.set(startIndex, false);
1209
+ }
1210
+ #expressionAt(startIndex, src) {
1211
+ try {
1212
+ const pos = this.#parsed.positionAt(startIndex);
1213
+ const result = parseExpression(src, {
1214
+ plugins,
1215
+ startIndex,
1216
+ startLine: pos.line + 1,
1217
+ startColumn: pos.character,
1218
+ strictMode: true,
1219
+ errorRecovery: true,
1220
+ sourceType: "module",
1221
+ allowUndeclaredExports: true,
1222
+ allowSuperOutsideMethod: true,
1223
+ allowAwaitOutsideFunction: true,
1224
+ allowReturnOutsideFunction: true,
1225
+ sourceFilename: this.#parsed.filename
1226
+ });
1227
+ this.#cache.set(startIndex, result);
1228
+ return result;
1229
+ } catch {
1230
+ this.#cache.set(startIndex, false);
1231
+ }
1232
+ }
1233
+ };
1234
+
1235
+ // src/extractors/script/util/attach-scopes.ts
1028
1236
  var VISITOR_KEYS = t.VISITOR_KEYS;
1029
1237
  var ATTR_UNNAMED = "value";
1030
1238
  var Scopes = /* @__PURE__ */ new WeakMap();
@@ -1576,10 +1784,10 @@ function byStart(a, b) {
1576
1784
 
1577
1785
  // src/extractors/script/util/get-component-filename.ts
1578
1786
  import fs from "fs";
1579
- import path from "path";
1787
+ import path2 from "path";
1580
1788
  function getComponentFilename(from) {
1581
- const dir = path.dirname(from);
1582
- let nameNoExt = path.basename(from, ".marko");
1789
+ const dir = path2.dirname(from);
1790
+ let nameNoExt = path2.basename(from, ".marko");
1583
1791
  if (nameNoExt.endsWith(".d")) {
1584
1792
  nameNoExt = nameNoExt.slice(0, -2);
1585
1793
  }
@@ -1590,7 +1798,7 @@ function getComponentFilename(from) {
1590
1798
  );
1591
1799
  for (const entry of tryReaddirSync(dir)) {
1592
1800
  if (componentMatch.test(entry)) {
1593
- return path.join(dir, entry);
1801
+ return path2.join(dir, entry);
1594
1802
  }
1595
1803
  }
1596
1804
  }
@@ -1732,19 +1940,6 @@ function detectAPIFromTag(parsed, tag) {
1732
1940
  return detectAPIFromBody(parsed, tag.body);
1733
1941
  }
1734
1942
 
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
1943
  // src/extractors/script/util/jsdoc-input-type.ts
1749
1944
  var MaybeInputTypedefReg = /@typedef\b[\s\S]*\bInput\b/;
1750
1945
  function getJSDocInputType(comment, ts) {
@@ -1854,191 +2049,6 @@ function getRuntimeOverrides(api, runtimeTypes, generics, applyGenerics, returnT
1854
2049
  return result;
1855
2050
  }
1856
2051
 
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
2052
  // src/extractors/script/index.ts
2043
2053
  var SEP_EMPTY = "";
2044
2054
  var SEP_SPACE = " ";
@@ -3419,17 +3429,17 @@ ${isMutatedVar(tag.parent, valueLiteral) ? varLocal(`change__${valueLiteral}.`)
3419
3429
  return ((_a = this.#lookup.getTag(nameText)) == null ? void 0 : _a.targetProperty) || nameText.slice(nameText.lastIndexOf(":") + 1);
3420
3430
  }
3421
3431
  #getAttrTagPath(tag) {
3422
- let path4 = `"${this.#getAttrTagName(tag)}"`;
3432
+ let path5 = `"${this.#getAttrTagName(tag)}"`;
3423
3433
  let curTag = tag.parent;
3424
3434
  while (curTag) {
3425
3435
  if (curTag.type === 16 /* AttrTag */) {
3426
- path4 = `"${this.#getAttrTagName(curTag)}",${path4}`;
3436
+ path5 = `"${this.#getAttrTagName(curTag)}",${path5}`;
3427
3437
  } else if (!isControlFlowTag(curTag)) {
3428
3438
  break;
3429
3439
  }
3430
3440
  curTag = curTag.parent;
3431
3441
  }
3432
- return path4;
3442
+ return path5;
3433
3443
  }
3434
3444
  #getTagInputType(tag) {
3435
3445
  if (tag.type === 16 /* AttrTag */) {
@@ -3565,7 +3575,7 @@ function isValueAttribute(attr) {
3565
3575
  function resolveTagImport(from, def) {
3566
3576
  const filename = resolveTagFile(def);
3567
3577
  if (filename) {
3568
- return from ? relativeImportPath(from, filename) : filename;
3578
+ return from ? relativeImportPath(from, normalizePath(filename)) : filename;
3569
3579
  }
3570
3580
  }
3571
3581
  function resolveTagFile(def) {
@@ -3676,7 +3686,7 @@ function getExt(fileName) {
3676
3686
  }
3677
3687
 
3678
3688
  // src/processors/marko.ts
3679
- import path3 from "path";
3689
+ import path4 from "path";
3680
3690
 
3681
3691
  // src/util/project.ts
3682
3692
  var project_exports = {};
@@ -3693,7 +3703,7 @@ __export(project_exports, {
3693
3703
  });
3694
3704
  import { strip as stripJSONComments } from "@luxass/strip-json-comments";
3695
3705
  import { createRequire } from "module";
3696
- import path2 from "path";
3706
+ import path3 from "path";
3697
3707
  var defaultTypeLibs = {};
3698
3708
  var defaultMeta;
3699
3709
  var ignoreErrors = (_err) => {
@@ -3720,11 +3730,11 @@ function getTypeLibs(rootDir, ts, host) {
3720
3730
  const resolveTypeCompilerOptions = {
3721
3731
  moduleResolution: ts.ModuleResolutionKind.Bundler
3722
3732
  };
3723
- const markoRunGeneratedTypesFile = path2.join(
3733
+ const markoRunGeneratedTypesFile = path3.join(
3724
3734
  rootDir,
3725
3735
  ".marko-run/routes.d.ts"
3726
3736
  );
3727
- const resolveFromFile = path2.join(rootDir, "_.d.ts");
3737
+ const resolveFromFile = path3.join(rootDir, "_.d.ts");
3728
3738
  const internalTypesFile = defaultTypeLibs.internalTypesFile || ((_a = ts.resolveTypeReferenceDirective(
3729
3739
  "@marko/language-tools/marko.internal.d.ts",
3730
3740
  resolveFromFile,
@@ -3762,7 +3772,7 @@ function getTypeLibs(rootDir, ts, host) {
3762
3772
  }
3763
3773
  function getScriptLang(fileName, defaultScriptLang, ts, host) {
3764
3774
  if (fileName.endsWith(".d.marko")) return "ts" /* ts */;
3765
- const dir = path2.dirname(fileName);
3775
+ const dir = path3.dirname(fileName);
3766
3776
  const config = getConfig(dir);
3767
3777
  const cache = config.cache.get(getScriptLang);
3768
3778
  let scriptLang = cache == null ? void 0 : cache.get(dir);
@@ -3846,7 +3856,7 @@ function getMeta(dir) {
3846
3856
  function loadMeta(dir) {
3847
3857
  let cached = metaByDir.get(dir);
3848
3858
  if (!cached) {
3849
- const require2 = createRequire(path2.join(dir, "_.js"));
3859
+ const require2 = createRequire(path3.join(dir, "_.js"));
3850
3860
  const configPath = (() => {
3851
3861
  try {
3852
3862
  return require2.resolve("@marko/compiler/config");
@@ -3860,7 +3870,7 @@ function loadMeta(dir) {
3860
3870
  const translatorPath = require2.resolve(config.translator);
3861
3871
  cached = metaByTranslator.get(translatorPath);
3862
3872
  if (!cached) {
3863
- const compiler = require2(path2.dirname(configPath));
3873
+ const compiler = require2(path3.dirname(configPath));
3864
3874
  cached = {
3865
3875
  compiler,
3866
3876
  config: {
@@ -3921,13 +3931,13 @@ var marko_default = {
3921
3931
  extension: ".marko",
3922
3932
  create({ ts, host, configFile }) {
3923
3933
  const currentDirectory = host.getCurrentDirectory ? host.getCurrentDirectory() : ts.sys.getCurrentDirectory();
3924
- const defaultScriptLang = configFile && /tsconfig/g.test(configFile) ? "ts" /* ts */ : "js" /* js */;
3934
+ const defaultScriptLang = configFile && /tsconfig/.test(configFile) ? "ts" /* ts */ : "js" /* js */;
3925
3935
  const runtimeTypes = getTypeLibs(currentDirectory, ts, host);
3926
3936
  const rootNames = [
3927
3937
  runtimeTypes.internalTypesFile,
3928
3938
  runtimeTypes.markoTypesFile
3929
3939
  ];
3930
- const getJSFileIfTSExists = (source, importer) => host.fileExists(path3.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3940
+ const getJSFileIfTSExists = (source, importer) => host.fileExists(path4.join(importer, "..", `${source}.ts`)) && `${source}.js`;
3931
3941
  const compileConfig = {
3932
3942
  output: "source",
3933
3943
  stripTypes: true,
@@ -3983,8 +3993,8 @@ var marko_default = {
3983
3993
  return getScriptLang(fileName, defaultScriptLang, ts, host) === "ts" /* ts */ ? ts.ScriptKind.TS : ts.ScriptKind.JS;
3984
3994
  },
3985
3995
  extract(fileName, code) {
3986
- const dir = path3.dirname(fileName);
3987
3996
  const parsed = parse(code, fileName);
3997
+ const dir = path4.dirname(parsed.filename);
3988
3998
  return extractScript({
3989
3999
  ts,
3990
4000
  parsed,
@@ -4001,7 +4011,7 @@ var marko_default = {
4001
4011
  },
4002
4012
  print({ extracted: { parsed } }) {
4003
4013
  const { code, map } = getCompiler(
4004
- path3.dirname(parsed.filename)
4014
+ path4.dirname(parsed.filename)
4005
4015
  ).compileSync(parsed.code, parsed.filename, compileConfig);
4006
4016
  return { code, map };
4007
4017
  },
@@ -4145,5 +4155,6 @@ export {
4145
4155
  getPosition,
4146
4156
  isControlFlowTag,
4147
4157
  isDefinitionFile,
4158
+ normalizePath,
4148
4159
  parse
4149
4160
  };
@@ -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;
@@ -0,0 +1 @@
1
+ export declare const normalizePath: (filename: string) => string;
@@ -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.60",
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
  }