@marko/language-server 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -13,96 +13,11 @@ import {
13
13
  TextDocumentSyncKind,
14
14
  createConnection
15
15
  } from "vscode-languageserver/node";
16
-
17
- // src/utils/project.ts
18
- import path from "path";
19
- import { createRequire } from "module";
20
- import * as defaultCompiler from "@marko/compiler";
21
- import * as defaultTranslator from "@marko/translator-default";
22
- var ignoreErrors = (_err) => {
23
- };
24
- var projectsByDir = /* @__PURE__ */ new Map();
25
- var projectsByCompiler = /* @__PURE__ */ new Map();
26
- var defaultProject = {
27
- cache: /* @__PURE__ */ new Map(),
28
- compiler: defaultCompiler,
29
- translator: defaultTranslator,
30
- getLookup(dir) {
31
- const key = `taglib:${dir}`;
32
- let lookup = defaultProject.cache.get(key);
33
- if (!lookup) {
34
- defaultProject.cache.set(
35
- key,
36
- lookup = defaultCompiler.taglib.buildLookup(
37
- dir,
38
- defaultTranslator,
39
- ignoreErrors
40
- )
41
- );
42
- }
43
- return lookup;
44
- }
45
- };
46
- defaultCompiler.configure({ translator: defaultTranslator });
47
- function getMarkoProject(dir) {
48
- if (!dir)
49
- return defaultProject;
50
- let project = projectsByDir.get(dir);
51
- if (!project) {
52
- project = loadProject(dir);
53
- projectsByDir.set(dir, project);
54
- }
55
- return project;
56
- }
57
- function getMarkoProjects() {
58
- return projectsByCompiler.values();
59
- }
60
- function clearMarkoProjectCaches() {
61
- for (const project of getMarkoProjects()) {
62
- project.cache.clear();
63
- project.compiler.taglib.clearCaches();
64
- }
65
- }
66
- function loadProject(dir) {
67
- try {
68
- const require2 = createRequire(dir);
69
- const compilerConfigPath = require2.resolve("@marko/compiler/config");
70
- const cachedProject = projectsByCompiler.get(compilerConfigPath);
71
- if (cachedProject)
72
- return cachedProject;
73
- const compiler = require2(path.join(compilerConfigPath, ".."));
74
- const translator = require2(interopDefault(require2(compilerConfigPath)).translator);
75
- const project = {
76
- cache: /* @__PURE__ */ new Map(),
77
- compiler,
78
- translator,
79
- getLookup(dir2) {
80
- const key = `taglib:${dir2}`;
81
- let lookup = project.cache.get(key);
82
- if (lookup === void 0) {
83
- try {
84
- lookup = compiler.taglib.buildLookup(dir2, translator, ignoreErrors);
85
- } catch {
86
- lookup = defaultProject.getLookup(dir2);
87
- }
88
- project.cache.set(key, lookup);
89
- }
90
- return lookup;
91
- }
92
- };
93
- projectsByCompiler.set(compilerConfigPath, project);
94
- return project;
95
- } catch {
96
- return defaultProject;
97
- }
98
- }
99
- function interopDefault(mod) {
100
- return mod.default || mod;
101
- }
16
+ import { Project as Project4 } from "@marko/language-tools";
102
17
 
103
18
  // src/utils/file.ts
104
- import path2 from "path";
105
- import { parse } from "@marko/language-tools";
19
+ import path from "path";
20
+ import { Project, parse } from "@marko/language-tools";
106
21
  import { URI } from "vscode-uri";
107
22
  var processorCaches = /* @__PURE__ */ new WeakMap();
108
23
  function getFSPath(doc) {
@@ -111,19 +26,17 @@ function getFSPath(doc) {
111
26
  function getMarkoFile(doc) {
112
27
  const { uri } = doc;
113
28
  const { fsPath: filename, scheme } = URI.parse(uri);
114
- const dirname = filename && path2.dirname(filename);
115
- const project = getMarkoProject(dirname);
116
- const cache = project.cache;
29
+ const dirname = filename && path.dirname(filename);
30
+ const cache = Project.getCache(dirname);
117
31
  let file = cache.get(doc);
118
32
  if (!file) {
119
33
  const { version } = doc;
120
34
  const code = doc.getText();
121
35
  const parsed = parse(code, filename);
122
- const lookup = project.getLookup(dirname);
36
+ const lookup = Project.getTagLookup(dirname);
123
37
  cache.set(
124
38
  doc,
125
39
  file = {
126
- project,
127
40
  uri,
128
41
  scheme,
129
42
  version,
@@ -139,9 +52,8 @@ function getMarkoFile(doc) {
139
52
  }
140
53
  function clearMarkoCacheForFile(doc) {
141
54
  const { fsPath: filename } = URI.parse(doc.uri);
142
- const dirname = filename && path2.dirname(filename);
143
- const project = getMarkoProject(dirname);
144
- const cache = project.cache;
55
+ const dirname = filename && path.dirname(filename);
56
+ const cache = Project.getCache(dirname);
145
57
  cache.delete(doc);
146
58
  }
147
59
  function processDoc(doc, process2) {
@@ -474,7 +386,7 @@ function isExternalModule(file) {
474
386
  }
475
387
 
476
388
  // src/service/marko/complete/AttrValue.ts
477
- import path3 from "path";
389
+ import path2 from "path";
478
390
  import {
479
391
  CompletionItemKind as CompletionItemKind2,
480
392
  TextEdit as TextEdit2
@@ -587,7 +499,7 @@ async function AttrValue({
587
499
  const resolved = resolveUrl(req, uri);
588
500
  if (resolved) {
589
501
  const result = [];
590
- const curFile = req === "." ? path3.basename(uri) : void 0;
502
+ const curFile = req === "." ? path2.basename(uri) : void 0;
591
503
  const replaceRange = parsed.locationAt({
592
504
  start: start + segmentStart + 1,
593
505
  end: start + rawValue.length
@@ -620,7 +532,7 @@ async function AttrValue({
620
532
  import { TextEdit as TextEdit4 } from "vscode-languageserver";
621
533
 
622
534
  // src/service/marko/util/get-tag-name-completion.ts
623
- import path4 from "path";
535
+ import path3 from "path";
624
536
  import {
625
537
  CompletionItemKind as CompletionItemKind3,
626
538
  CompletionItemTag,
@@ -649,7 +561,7 @@ function getTagNameCompletion({
649
561
  kind: MarkupKind2.Markdown,
650
562
  value: tag.html ? `Built in [<${tag.name}>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/${tag.name}) HTML tag.` : isCoreTag ? `Core Marko <${tag.name}> tag.` : nodeModuleName ? `Custom Marko tag discovered from the ["${nodeModuleName}"](${fileURIForTag}) npm package.` : `Custom Marko tag discovered from:
651
563
 
652
- [${importer ? path4.relative(importer, fileForTag) : fileForTag}](${fileURIForTag})`
564
+ [${importer ? path3.relative(importer, fileForTag) : fileForTag}](${fileURIForTag})`
653
565
  };
654
566
  if (tag.description) {
655
567
  documentation.value += `
@@ -839,32 +751,32 @@ var doComplete = async (doc, params) => {
839
751
  };
840
752
 
841
753
  // src/service/marko/validate.ts
842
- import path5 from "path";
754
+ import path4 from "path";
755
+ import { Project as Project2 } from "@marko/language-tools";
843
756
  import { DiagnosticSeverity } from "vscode-languageserver";
844
757
  var markoErrorRegExp = /^(.+?)\.marko(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
845
758
  var doValidate = (doc) => {
846
759
  const filename = getFSPath(doc);
847
760
  const diagnostics = [];
848
- const { compiler, translator, cache } = getMarkoProject(
849
- filename && path5.dirname(filename)
850
- );
851
761
  try {
852
- compiler.compileSync(doc.getText(), filename || "untitled.marko", {
853
- cache,
854
- translator,
855
- code: false,
856
- output: "source",
857
- sourceMaps: false,
858
- babelConfig: {
859
- caller: {
860
- name: "@marko/language-server",
861
- supportsStaticESM: true,
862
- supportsDynamicImport: true,
863
- supportsTopLevelAwait: true,
864
- supportsExportNamespaceFrom: true
762
+ Project2.getCompiler(filename && path4.dirname(filename)).compileSync(
763
+ doc.getText(),
764
+ filename || "untitled.marko",
765
+ {
766
+ code: false,
767
+ output: "source",
768
+ sourceMaps: false,
769
+ babelConfig: {
770
+ caller: {
771
+ name: "@marko/language-server",
772
+ supportsStaticESM: true,
773
+ supportsDynamicImport: true,
774
+ supportsTopLevelAwait: true,
775
+ supportsExportNamespaceFrom: true
776
+ }
865
777
  }
866
778
  }
867
- });
779
+ );
868
780
  } catch (e) {
869
781
  let match;
870
782
  while (match = markoErrorRegExp.exec(e.message)) {
@@ -1013,7 +925,7 @@ function AttrName2({
1013
925
 
1014
926
  // src/service/marko/definition/OpenTagName.ts
1015
927
  import fs4 from "fs";
1016
- import path6 from "path";
928
+ import path5 from "path";
1017
929
  import { URI as URI5 } from "vscode-uri";
1018
930
  import {
1019
931
  NodeType as NodeType5,
@@ -1039,7 +951,7 @@ function OpenTagName3({
1039
951
  return;
1040
952
  }
1041
953
  const tagEntryFile = tagDef.template || tagDef.renderer || tagDef.filePath;
1042
- if (!path6.isAbsolute(tagEntryFile)) {
954
+ if (!path5.isAbsolute(tagEntryFile)) {
1043
955
  return;
1044
956
  }
1045
957
  if (/\/marko(?:-tag)?\.json$/.test(tagEntryFile)) {
@@ -1251,7 +1163,7 @@ var marko_default = {
1251
1163
  };
1252
1164
 
1253
1165
  // src/service/script/index.ts
1254
- import path10 from "path";
1166
+ import path7 from "path";
1255
1167
  import { relativeImportPath } from "relative-import-path";
1256
1168
  import ts from "typescript/lib/tsserverlibrary";
1257
1169
  import {
@@ -1265,218 +1177,115 @@ import { URI as URI6 } from "vscode-uri";
1265
1177
  import * as prettier2 from "prettier";
1266
1178
  import {
1267
1179
  NodeType as NodeType9,
1268
- ScriptLang as ScriptLang3,
1269
- extractScript as extractScript2
1180
+ Project as Project3,
1181
+ ScriptLang,
1182
+ extractScript
1270
1183
  } from "@marko/language-tools";
1271
1184
 
1272
1185
  // src/ts-plugin/host.ts
1273
- import path9 from "path";
1186
+ import path6 from "path";
1274
1187
  import {
1275
- ScriptLang as ScriptLang2,
1276
- extractScript,
1277
- parse as parse2
1188
+ Processors,
1189
+ getExt,
1190
+ isDefinitionFile
1278
1191
  } from "@marko/language-tools";
1279
-
1280
- // src/utils/get-runtime-types.ts
1281
- import path7 from "path";
1282
- var internalTypesFile = path7.join(__dirname, "marko.internal.d.ts");
1283
- var defaultMarkoTypesFile = path7.join(__dirname, "marko.runtime.d.ts");
1284
- function getProjectTypeLibs(rootDir, project, ts2, host) {
1285
- let cached = project.cache.get(getProjectTypeLibs);
1286
- if (cached === void 0) {
1287
- const markoRunGeneratedTypesFile = path7.join(
1288
- rootDir,
1289
- ".marko-run/routes.d.ts"
1290
- );
1291
- const resolveFromFile = path7.join(host.getCurrentDirectory(), "_.d.ts");
1292
- const compilerOptions = host.getCompilationSettings();
1293
- const { resolvedTypeReferenceDirective: resolvedMarkoTypes } = ts2.resolveTypeReferenceDirective(
1294
- project.translator.runtimeTypes || "marko",
1295
- resolveFromFile,
1296
- compilerOptions,
1297
- host
1298
- );
1299
- const { resolvedTypeReferenceDirective: resolvedMarkoRunTypes } = ts2.resolveTypeReferenceDirective(
1300
- "@marko/run",
1301
- resolveFromFile,
1302
- compilerOptions,
1303
- host
1304
- );
1305
- const markoTypesFile = (resolvedMarkoTypes == null ? void 0 : resolvedMarkoTypes.resolvedFileName) || defaultMarkoTypesFile;
1306
- const markoRunTypesFile = resolvedMarkoRunTypes == null ? void 0 : resolvedMarkoRunTypes.resolvedFileName;
1307
- cached = {
1308
- internalTypesFile,
1309
- markoTypesFile,
1310
- markoTypesCode: host.readFile(markoTypesFile, "utf-8") || "",
1311
- markoRunTypesFile,
1312
- markoRunGeneratedTypesFile: host.fileExists(markoRunGeneratedTypesFile) ? markoRunGeneratedTypesFile : void 0
1313
- };
1314
- project.cache.set(getProjectTypeLibs, cached);
1315
- }
1316
- return cached;
1317
- }
1318
-
1319
- // src/utils/get-script-lang.ts
1320
- import { ScriptLang } from "@marko/language-tools";
1321
- function getScriptLang(filename, ts2, host, projectScriptLang) {
1322
- const configPath = ts2.findConfigFile(
1323
- filename,
1324
- host.fileExists.bind(host),
1325
- "marko.json"
1326
- );
1327
- if (configPath) {
1328
- try {
1329
- const markoConfig = JSON.parse(
1330
- host.readFile(configPath, "utf-8") || "{}"
1331
- );
1332
- const scriptLang = markoConfig["script-lang"] || markoConfig.scriptLang;
1333
- if (scriptLang !== void 0) {
1334
- return scriptLang === ScriptLang.ts ? ScriptLang.ts : ScriptLang.js;
1335
- }
1336
- } catch {
1337
- }
1338
- }
1339
- return /[/\\]node_modules[/\\]/.test(filename) ? ScriptLang.js : projectScriptLang;
1340
- }
1341
-
1342
- // src/utils/get-component-filename.ts
1343
- import fs5 from "fs";
1344
- import path8 from "path";
1345
- function getComponentFilename(from) {
1346
- const dir = path8.dirname(from);
1347
- const nameNoExt = path8.basename(from, ".marko");
1348
- const isEntry = nameNoExt === "index";
1349
- const componentFull = `${nameNoExt}.component.`;
1350
- const componentBrowserFull = `${nameNoExt}.component-browser.`;
1351
- const componentPartial = isEntry ? "component." : void 0;
1352
- const componentBrowserPartial = isEntry ? "component-browser." : void 0;
1353
- for (const entry of tryReaddirSync(dir)) {
1354
- if (entry !== from && (isEntry && entry.startsWith(componentBrowserPartial) || entry.startsWith(componentPartial)) || entry.startsWith(componentBrowserFull) || entry.startsWith(componentFull)) {
1355
- return path8.join(dir, entry);
1356
- }
1357
- }
1358
- }
1359
- function tryReaddirSync(dir) {
1360
- try {
1361
- return fs5.readdirSync(dir);
1362
- } catch {
1363
- return [];
1364
- }
1365
- }
1366
-
1367
- // src/ts-plugin/host.ts
1368
- var markoExt = ".marko";
1369
- var markoExtReg = /\.marko$/;
1370
- var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
1371
1192
  var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
1372
- function patch(ts2, scriptLang, cache, host, ps) {
1193
+ var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
1194
+ function patch(ts2, configFile, extractCache2, resolutionCache, host, ps) {
1373
1195
  var _a, _b, _c;
1374
- const rootDir = host.getCurrentDirectory();
1375
- const projectTypeLibs = getProjectTypeLibs(
1376
- rootDir,
1377
- getMarkoProject(rootDir),
1378
- ts2,
1379
- host
1380
- );
1381
- const projectTypeLibsFiles = [
1382
- projectTypeLibs.internalTypesFile,
1383
- projectTypeLibs.markoTypesFile
1384
- ];
1385
- if (projectTypeLibs.markoRunTypesFile) {
1386
- projectTypeLibsFiles.push(projectTypeLibs.markoRunTypesFile);
1387
- }
1388
- if (projectTypeLibs.markoRunGeneratedTypesFile) {
1389
- projectTypeLibsFiles.push(projectTypeLibs.markoRunGeneratedTypesFile);
1390
- }
1391
- const isMarkoTSFile = (fileName) => getScriptLang(fileName, ts2, host, scriptLang) === ScriptLang2.ts;
1196
+ const processors = Processors.create({
1197
+ ts: ts2,
1198
+ host,
1199
+ configFile
1200
+ });
1201
+ const rootNames = Object.values(processors).map((processor) => {
1202
+ var _a2;
1203
+ return (_a2 = processor.getRootNames) == null ? void 0 : _a2.call(processor);
1204
+ }).flat().filter(Boolean);
1392
1205
  const getScriptFileNames = host.getScriptFileNames.bind(host);
1393
1206
  host.getScriptFileNames = () => [
1394
- ...new Set(projectTypeLibsFiles.concat(getScriptFileNames()))
1207
+ ...new Set(rootNames.concat(getScriptFileNames()))
1395
1208
  ];
1396
1209
  const getScriptKind = (_a = host.getScriptKind) == null ? void 0 : _a.bind(host);
1397
1210
  if (getScriptKind) {
1398
1211
  host.getScriptKind = (fileName) => {
1399
- return markoExtReg.test(fileName) ? isMarkoTSFile(fileName) ? ts2.ScriptKind.TS : ts2.ScriptKind.JS : getScriptKind(fileName);
1212
+ const processor = getProcessor(fileName);
1213
+ if (processor)
1214
+ return processor.getScriptKind(fileName);
1215
+ return getScriptKind(fileName);
1400
1216
  };
1401
1217
  }
1402
1218
  const getScriptSnapshot = host.getScriptSnapshot.bind(host);
1403
- host.getScriptSnapshot = (filename) => {
1404
- if (markoExtReg.test(filename)) {
1405
- let cached = cache.get(filename);
1219
+ host.getScriptSnapshot = (fileName) => {
1220
+ const processor = getProcessor(fileName);
1221
+ if (processor) {
1222
+ let cached = extractCache2.get(fileName);
1406
1223
  if (!cached) {
1407
- const code = host.readFile(filename, "utf-8") || "";
1408
- const dir = path9.dirname(filename);
1224
+ const code = host.readFile(fileName, "utf-8") || "";
1409
1225
  try {
1410
- const markoProject = getMarkoProject(dir);
1411
- cached = extractScript({
1412
- ts: ts2,
1413
- parsed: parse2(code, filename),
1414
- lookup: markoProject.getLookup(dir),
1415
- scriptLang: getScriptLang(filename, ts2, host, scriptLang),
1416
- runtimeTypesCode: projectTypeLibs.markoTypesCode,
1417
- componentFilename: getComponentFilename(filename)
1418
- });
1226
+ cached = processor.extract(fileName, code);
1419
1227
  cached.snapshot = ts2.ScriptSnapshot.fromString(cached.toString());
1420
1228
  } catch {
1421
1229
  cached = { snapshot: ts2.ScriptSnapshot.fromString("") };
1422
1230
  }
1423
1231
  ps == null ? void 0 : ps.getOrCreateScriptInfoForNormalizedPath(
1424
- filename,
1232
+ fileName,
1425
1233
  false,
1426
1234
  void 0,
1427
1235
  ts2.ScriptKind.Deferred,
1428
1236
  false,
1429
1237
  host
1430
1238
  );
1431
- cache.set(filename, cached);
1239
+ extractCache2.set(fileName, cached);
1432
1240
  }
1433
1241
  return cached.snapshot;
1434
1242
  }
1435
- return getScriptSnapshot(filename);
1243
+ return getScriptSnapshot(fileName);
1436
1244
  };
1437
1245
  if (host.getProjectVersion) {
1438
1246
  const getScriptVersion = host.getScriptVersion.bind(host);
1439
- host.getScriptVersion = (filename) => {
1440
- if (markoExtReg.test(filename)) {
1247
+ host.getScriptVersion = (fileName) => {
1248
+ const processor = getProcessor(fileName);
1249
+ if (processor)
1441
1250
  return host.getProjectVersion();
1442
- }
1443
- return getScriptVersion(filename);
1251
+ return getScriptVersion(fileName);
1444
1252
  };
1445
1253
  }
1446
1254
  const readDirectory2 = (_b = host.readDirectory) == null ? void 0 : _b.bind(host);
1447
1255
  if (readDirectory2) {
1448
- host.readDirectory = (path11, extensions, exclude, include, depth) => {
1256
+ host.readDirectory = (path8, extensions, exclude, include, depth) => {
1449
1257
  return readDirectory2(
1450
- path11,
1451
- extensions == null ? void 0 : extensions.concat(markoExt),
1258
+ path8,
1259
+ extensions == null ? void 0 : extensions.concat(Processors.extensions),
1452
1260
  exclude,
1453
1261
  include,
1454
1262
  depth
1455
1263
  );
1456
1264
  };
1457
1265
  }
1458
- const resolveModuleNames = (_c = host.resolveModuleNames) == null ? void 0 : _c.bind(host);
1459
- if (resolveModuleNames) {
1460
- host.resolveModuleNames = (moduleNames, containingFile, reusedNames, redirectedReference, options, sourceFile) => {
1461
- let normalModuleNames = moduleNames;
1266
+ const resolveModuleNameLiterals = (_c = host.resolveModuleNameLiterals) == null ? void 0 : _c.bind(host);
1267
+ if (resolveModuleNameLiterals) {
1268
+ host.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) => {
1269
+ let normalModuleLiterals = moduleLiterals;
1462
1270
  let resolvedModules;
1463
- for (let i = 0; i < moduleNames.length; i++) {
1464
- const moduleName = moduleNames[i];
1465
- const shouldProcess = moduleName[0] !== "*" ? markoExtReg.test(moduleName) : void 0;
1466
- if (shouldProcess) {
1271
+ for (let i = 0; i < moduleLiterals.length; i++) {
1272
+ const moduleName = moduleLiterals[i].text;
1273
+ const processor = moduleName[0] !== "*" ? getProcessor(moduleName) : void 0;
1274
+ if (processor) {
1467
1275
  let resolvedFileName;
1468
1276
  if (fsPathReg.test(moduleName)) {
1469
- resolvedFileName = path9.resolve(containingFile, "..", moduleName);
1277
+ resolvedFileName = path6.resolve(containingFile, "..", moduleName);
1470
1278
  } else {
1471
1279
  const [, nodeModuleName, relativeModulePath] = modulePartsReg.exec(moduleName);
1472
- const { resolvedModule } = ts2.resolveModuleName(
1280
+ const { resolvedModule } = ts2.bundlerModuleNameResolver(
1473
1281
  `${nodeModuleName}/package.json`,
1474
1282
  containingFile,
1475
1283
  options,
1476
- host
1284
+ host,
1285
+ resolutionCache
1477
1286
  );
1478
1287
  if (resolvedModule) {
1479
- resolvedFileName = path9.join(
1288
+ resolvedFileName = path6.join(
1480
1289
  resolvedModule.resolvedFileName,
1481
1290
  "..",
1482
1291
  relativeModulePath
@@ -1485,47 +1294,54 @@ function patch(ts2, scriptLang, cache, host, ps) {
1485
1294
  }
1486
1295
  if (!resolvedModules) {
1487
1296
  resolvedModules = [];
1488
- normalModuleNames = [];
1297
+ normalModuleLiterals = [];
1489
1298
  for (let j = 0; j < i; j++) {
1490
1299
  resolvedModules.push(void 0);
1491
- normalModuleNames.push(moduleNames[j]);
1300
+ normalModuleLiterals.push(moduleLiterals[j]);
1301
+ }
1302
+ }
1303
+ if (resolvedFileName) {
1304
+ if (isDefinitionFile(resolvedFileName)) {
1305
+ if (!host.fileExists(resolvedFileName)) {
1306
+ resolvedFileName = void 0;
1307
+ }
1308
+ } else {
1309
+ const ext = getExt(resolvedFileName);
1310
+ const definitionFile = `${resolvedFileName.slice(
1311
+ 0,
1312
+ -ext.length
1313
+ )}.d${ext}`;
1314
+ if (host.fileExists(definitionFile)) {
1315
+ resolvedFileName = definitionFile;
1316
+ } else if (!host.fileExists(resolvedFileName)) {
1317
+ resolvedFileName = void 0;
1318
+ }
1492
1319
  }
1493
1320
  }
1494
- resolvedModules.push(
1495
- resolvedFileName && host.fileExists(resolvedFileName) ? {
1321
+ resolvedModules.push({
1322
+ resolvedModule: resolvedFileName ? {
1496
1323
  resolvedFileName,
1497
- extension: isMarkoTSFile(resolvedFileName) ? ts2.Extension.Ts : ts2.Extension.Js,
1324
+ extension: processor.getScriptExtension(resolvedFileName),
1498
1325
  isExternalLibraryImport: false
1499
- } : null
1500
- );
1326
+ } : void 0
1327
+ });
1501
1328
  } else if (resolvedModules) {
1502
1329
  resolvedModules.push(void 0);
1503
1330
  }
1504
1331
  }
1505
- const normalResolvedModules = normalModuleNames.length ? resolveModuleNames(
1506
- normalModuleNames,
1332
+ const normalResolvedModules = normalModuleLiterals.length ? resolveModuleNameLiterals(
1333
+ normalModuleLiterals,
1507
1334
  containingFile,
1508
- reusedNames,
1509
1335
  redirectedReference,
1510
1336
  options,
1511
- sourceFile
1337
+ containingSourceFile,
1338
+ reusedNames
1512
1339
  ) : void 0;
1513
1340
  if (resolvedModules) {
1514
1341
  if (normalResolvedModules) {
1515
1342
  for (let i = 0, j = 0; i < resolvedModules.length; i++) {
1516
- switch (resolvedModules[i]) {
1517
- case void 0:
1518
- resolvedModules[i] = normalResolvedModules[j++];
1519
- break;
1520
- case null:
1521
- resolvedModules[i] = void 0;
1522
- break;
1523
- }
1524
- }
1525
- } else {
1526
- for (let i = resolvedModules.length; i--; ) {
1527
- if (resolvedModules[i] === null) {
1528
- resolvedModules[i] = void 0;
1343
+ if (!resolvedModules[i]) {
1344
+ resolvedModules[i] = normalResolvedModules[j++];
1529
1345
  }
1530
1346
  }
1531
1347
  }
@@ -1536,6 +1352,10 @@ function patch(ts2, scriptLang, cache, host, ps) {
1536
1352
  };
1537
1353
  }
1538
1354
  return host;
1355
+ function getProcessor(fileName) {
1356
+ const ext = getExt(fileName);
1357
+ return ext ? processors[ext] : void 0;
1358
+ }
1539
1359
  }
1540
1360
 
1541
1361
  // src/service/script/index.ts
@@ -1551,12 +1371,13 @@ var colorModifierReg = /\bcolor\b/;
1551
1371
  var localInternalsPrefix = "__marko_internal_";
1552
1372
  var requiredTSCompilerOptions = {
1553
1373
  module: ts.ModuleKind.ESNext,
1554
- moduleResolution: ts.ModuleResolutionKind.NodeJs,
1374
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
1555
1375
  noEmit: true,
1556
1376
  allowJs: true,
1557
1377
  composite: false,
1558
1378
  declaration: false,
1559
1379
  skipLibCheck: true,
1380
+ importHelpers: false,
1560
1381
  isolatedModules: true,
1561
1382
  resolveJsonModule: true,
1562
1383
  skipDefaultLibCheck: true,
@@ -1586,26 +1407,26 @@ var ScriptService = {
1586
1407
  const filename = getFSPath(doc);
1587
1408
  if (!filename)
1588
1409
  return;
1589
- const project = getTSProject(filename);
1590
- const extracted = processScript(doc, project);
1591
- const lang = getScriptLang(
1410
+ const tsProject = getTSProject(filename);
1411
+ const extracted = processScript(doc, tsProject);
1412
+ const lang = Project3.getScriptLang(
1592
1413
  filename,
1414
+ tsProject.markoScriptLang,
1593
1415
  ts,
1594
- project.host,
1595
- project.markoScriptLang
1416
+ tsProject.host
1596
1417
  );
1597
1418
  const generated = extracted.toString();
1598
1419
  const content = (() => {
1599
1420
  try {
1600
1421
  return prettier2.format(generated, {
1601
- parser: lang === ScriptLang3.ts ? "typescript" : "babel"
1422
+ parser: lang === ScriptLang.ts ? "typescript" : "babel"
1602
1423
  });
1603
1424
  } catch {
1604
1425
  return generated;
1605
1426
  }
1606
1427
  })();
1607
1428
  return {
1608
- language: lang === ScriptLang3.ts ? "typescript" : "javascript",
1429
+ language: lang === ScriptLang.ts ? "typescript" : "javascript",
1609
1430
  content
1610
1431
  };
1611
1432
  }
@@ -1661,7 +1482,7 @@ var ScriptService = {
1661
1482
  let source = completion.source;
1662
1483
  if (source && completion.hasAction) {
1663
1484
  if (source[0] === ".") {
1664
- source = path10.resolve(fileName, "..", source);
1485
+ source = path7.resolve(fileName, "..", source);
1665
1486
  }
1666
1487
  detail = relativeImportPath(fileName, source);
1667
1488
  sortText = `\uFFFF${sortText}`;
@@ -1965,26 +1786,17 @@ ${documentation}`;
1965
1786
  }
1966
1787
  };
1967
1788
  function processScript(doc, tsProject) {
1968
- return processDoc(
1969
- doc,
1970
- ({ filename, parsed, lookup, project: markoProject }) => {
1971
- var _a;
1972
- const { host, markoScriptLang } = tsProject;
1973
- return extractScript2({
1974
- ts,
1975
- parsed,
1976
- lookup,
1977
- scriptLang: getScriptLang(filename, ts, host, markoScriptLang),
1978
- runtimeTypesCode: (_a = getProjectTypeLibs(
1979
- tsProject.rootDir,
1980
- markoProject,
1981
- ts,
1982
- host
1983
- )) == null ? void 0 : _a.markoTypesCode,
1984
- componentFilename: getComponentFilename(filename)
1985
- });
1986
- }
1987
- );
1789
+ return processDoc(doc, ({ filename, parsed, lookup }) => {
1790
+ var _a;
1791
+ const { host, markoScriptLang } = tsProject;
1792
+ return extractScript({
1793
+ ts,
1794
+ parsed,
1795
+ lookup,
1796
+ scriptLang: Project3.getScriptLang(filename, markoScriptLang, ts, host),
1797
+ runtimeTypesCode: (_a = Project3.getTypeLibs(tsProject.rootDir, ts, host)) == null ? void 0 : _a.markoTypesCode
1798
+ });
1799
+ });
1988
1800
  }
1989
1801
  function getInsertModuleStatementOffset(parsed) {
1990
1802
  const { program } = parsed;
@@ -2035,27 +1847,27 @@ function docLocationAtTextSpan(doc, { start, length }) {
2035
1847
  }
2036
1848
  function getTSProject(docFsPath) {
2037
1849
  var _a;
2038
- let configPath;
2039
- let markoScriptLang = ScriptLang3.js;
1850
+ let configFile;
1851
+ let markoScriptLang = ScriptLang.js;
2040
1852
  if (docFsPath) {
2041
- configPath = ts.findConfigFile(
1853
+ configFile = ts.findConfigFile(
2042
1854
  docFsPath,
2043
1855
  ts.sys.fileExists,
2044
1856
  "tsconfig.json"
2045
1857
  );
2046
- if (configPath) {
2047
- markoScriptLang = ScriptLang3.ts;
1858
+ if (configFile) {
1859
+ markoScriptLang = ScriptLang.ts;
2048
1860
  } else {
2049
- configPath = ts.findConfigFile(
1861
+ configFile = ts.findConfigFile(
2050
1862
  docFsPath,
2051
1863
  ts.sys.fileExists,
2052
1864
  "jsconfig.json"
2053
1865
  );
2054
1866
  }
2055
1867
  }
2056
- const rootDir = configPath && path10.dirname(configPath) || process.cwd();
2057
- const markoProject = getMarkoProject(configPath && rootDir);
2058
- let projectCache = markoProject.cache.get(getTSProject);
1868
+ const rootDir = configFile && path7.dirname(configFile) || process.cwd();
1869
+ const cache = Project3.getCache(configFile && rootDir);
1870
+ let projectCache = cache.get(getTSProject);
2059
1871
  let cached;
2060
1872
  if (projectCache) {
2061
1873
  cached = projectCache.get(rootDir);
@@ -2063,14 +1875,14 @@ function getTSProject(docFsPath) {
2063
1875
  return cached;
2064
1876
  } else {
2065
1877
  projectCache = /* @__PURE__ */ new Map();
2066
- markoProject.cache.set(getTSProject, projectCache);
1878
+ cache.set(getTSProject, projectCache);
2067
1879
  }
2068
1880
  const { fileNames, options, projectReferences } = ts.parseJsonConfigFileContent(
2069
- configPath && ts.readConfigFile(configPath, ts.sys.readFile).config || defaultTSConfig,
1881
+ configFile && ts.readConfigFile(configFile, ts.sys.readFile).config || defaultTSConfig,
2070
1882
  ts.sys,
2071
1883
  rootDir,
2072
1884
  requiredTSCompilerOptions,
2073
- configPath,
1885
+ configFile,
2074
1886
  void 0,
2075
1887
  extraTSCompilerExtensions
2076
1888
  );
@@ -2078,15 +1890,21 @@ function getTSProject(docFsPath) {
2078
1890
  const potentialGlobalFiles = new Set(
2079
1891
  fileNames.filter((file) => /\.[cm]?ts$/.test(file))
2080
1892
  );
2081
- const tsPkgFile = configPath && ((_a = ts.resolveModuleName("typescript/package.json", configPath, options, ts.sys).resolvedModule) == null ? void 0 : _a.resolvedFileName);
2082
- const defaultLibFile = path10.join(
2083
- tsPkgFile ? path10.join(tsPkgFile, "../lib") : __dirname,
1893
+ const tsPkgFile = configFile && ((_a = ts.resolveModuleName("typescript/package.json", configFile, options, ts.sys).resolvedModule) == null ? void 0 : _a.resolvedFileName);
1894
+ const defaultLibFile = path7.join(
1895
+ tsPkgFile ? path7.join(tsPkgFile, "../lib") : __dirname,
2084
1896
  ts.getDefaultLibFileName(options)
2085
1897
  );
1898
+ const resolutionCache = ts.createModuleResolutionCache(
1899
+ rootDir,
1900
+ getCanonicalFileName,
1901
+ options
1902
+ );
2086
1903
  const host = patch(
2087
1904
  ts,
2088
- markoScriptLang,
1905
+ configFile,
2089
1906
  extractCache,
1907
+ resolutionCache,
2090
1908
  {
2091
1909
  getNewLine() {
2092
1910
  return ts.sys.newLine;
@@ -2109,9 +1927,16 @@ function getTSProject(docFsPath) {
2109
1927
  getProjectReferences() {
2110
1928
  return projectReferences;
2111
1929
  },
2112
- resolveModuleNames(moduleNames, containingFile) {
2113
- return moduleNames.map((moduleName) => {
2114
- return ts.resolveModuleName(moduleName, containingFile, options, host).resolvedModule;
1930
+ resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options2, _containingSourceFile, _reusedNames) {
1931
+ return moduleLiterals.map((moduleLiteral) => {
1932
+ return ts.bundlerModuleNameResolver(
1933
+ moduleLiteral.text,
1934
+ containingFile,
1935
+ options2,
1936
+ host,
1937
+ resolutionCache,
1938
+ redirectedReference
1939
+ );
2115
1940
  });
2116
1941
  },
2117
1942
  readDirectory: ts.sys.readDirectory,
@@ -2134,7 +1959,7 @@ function getTSProject(docFsPath) {
2134
1959
  return `${((_a2 = get(filenameToURI(filename))) == null ? void 0 : _a2.version) ?? -1}`;
2135
1960
  },
2136
1961
  getScriptKind(filename) {
2137
- switch (path10.extname(filename)) {
1962
+ switch (path7.extname(filename)) {
2138
1963
  case ts.Extension.Js:
2139
1964
  case ts.Extension.Cjs:
2140
1965
  case ts.Extension.Mjs:
@@ -2170,14 +1995,7 @@ function getTSProject(docFsPath) {
2170
1995
  host,
2171
1996
  rootDir: options.rootDir,
2172
1997
  service: ts.createLanguageService(host),
2173
- markoProject,
2174
- markoScriptLang,
2175
- markoProjectTypeLibs: getProjectTypeLibs(
2176
- options.rootDir,
2177
- markoProject,
2178
- ts,
2179
- host
2180
- )
1998
+ markoScriptLang
2181
1999
  };
2182
2000
  projectCache.set(rootDir, tsProject);
2183
2001
  return tsProject;
@@ -2187,7 +2005,7 @@ function filenameToURI(filename) {
2187
2005
  }
2188
2006
  async function getPreferences(scriptLang) {
2189
2007
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2190
- const configName = scriptLang === ScriptLang3.js ? "javascript" : "typescript";
2008
+ const configName = scriptLang === ScriptLang.js ? "javascript" : "typescript";
2191
2009
  const [preferencesConfig, suggestConfig, inlayHintsConfig] = await Promise.all([
2192
2010
  getConfig(`${configName}.preferences`),
2193
2011
  getConfig(`${configName}.suggest`),
@@ -2335,6 +2153,9 @@ function getTSTriggerChar(char) {
2335
2153
  if (char && tsTriggerChars.has(char))
2336
2154
  return char;
2337
2155
  }
2156
+ function getCanonicalFileName(fileName) {
2157
+ return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
2158
+ }
2338
2159
 
2339
2160
  // src/service/style/index.ts
2340
2161
  import {
@@ -3225,7 +3046,7 @@ for (const command in service.commands) {
3225
3046
  }
3226
3047
  function validateDocs() {
3227
3048
  queueDiagnostic();
3228
- clearMarkoProjectCaches();
3049
+ Project4.clearCaches();
3229
3050
  }
3230
3051
  function queueDiagnostic() {
3231
3052
  clearTimeout(diagnosticTimeout);