@marko/language-server 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +193 -369
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +186 -360
- package/dist/index.mjs.map +4 -4
- package/dist/ts-plugin/host.d.ts +4 -4
- package/dist/utils/file.d.ts +0 -2
- package/package.json +9 -8
- package/dist/utils/get-component-filename.d.ts +0 -1
- package/dist/utils/get-runtime-types.d.ts +0 -10
- package/dist/utils/get-script-lang.d.ts +0 -4
- package/dist/utils/project.d.ts +0 -11
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 Project5 } from "@marko/language-tools";
|
|
102
17
|
|
|
103
18
|
// src/utils/file.ts
|
|
104
|
-
import
|
|
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 &&
|
|
115
|
-
const
|
|
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 =
|
|
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 &&
|
|
143
|
-
const
|
|
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
|
|
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 === "." ?
|
|
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
|
|
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 ?
|
|
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
|
|
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
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
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
|
|
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 (!
|
|
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
|
|
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,120 @@ import { URI as URI6 } from "vscode-uri";
|
|
|
1265
1177
|
import * as prettier2 from "prettier";
|
|
1266
1178
|
import {
|
|
1267
1179
|
NodeType as NodeType9,
|
|
1268
|
-
|
|
1269
|
-
|
|
1180
|
+
Project as Project4,
|
|
1181
|
+
ScriptLang,
|
|
1182
|
+
extractScript
|
|
1270
1183
|
} from "@marko/language-tools";
|
|
1271
1184
|
|
|
1272
1185
|
// src/ts-plugin/host.ts
|
|
1273
|
-
import
|
|
1186
|
+
import path6 from "path";
|
|
1274
1187
|
import {
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1188
|
+
Processors,
|
|
1189
|
+
Project as Project3,
|
|
1190
|
+
getExt,
|
|
1191
|
+
isDefinitionFile
|
|
1278
1192
|
} 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
1193
|
var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
|
|
1372
|
-
|
|
1194
|
+
var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
|
|
1195
|
+
Project3.setDefaultTypePaths({
|
|
1196
|
+
internalTypesFile: path6.join(__dirname, "marko.internal.d.ts"),
|
|
1197
|
+
markoTypesFile: path6.join(__dirname, "marko.runtime.d.ts")
|
|
1198
|
+
});
|
|
1199
|
+
function patch(ts2, configFile, extractCache2, resolutionCache, host, ps) {
|
|
1373
1200
|
var _a, _b, _c;
|
|
1374
|
-
const
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
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;
|
|
1201
|
+
const processors = Processors.create({
|
|
1202
|
+
ts: ts2,
|
|
1203
|
+
host,
|
|
1204
|
+
configFile
|
|
1205
|
+
});
|
|
1206
|
+
const rootNames = Object.values(processors).map((processor) => {
|
|
1207
|
+
var _a2;
|
|
1208
|
+
return (_a2 = processor.getRootNames) == null ? void 0 : _a2.call(processor);
|
|
1209
|
+
}).flat().filter(Boolean);
|
|
1392
1210
|
const getScriptFileNames = host.getScriptFileNames.bind(host);
|
|
1393
1211
|
host.getScriptFileNames = () => [
|
|
1394
|
-
...new Set(
|
|
1212
|
+
...new Set(rootNames.concat(getScriptFileNames()))
|
|
1395
1213
|
];
|
|
1396
1214
|
const getScriptKind = (_a = host.getScriptKind) == null ? void 0 : _a.bind(host);
|
|
1397
1215
|
if (getScriptKind) {
|
|
1398
1216
|
host.getScriptKind = (fileName) => {
|
|
1399
|
-
|
|
1217
|
+
const processor = getProcessor(fileName);
|
|
1218
|
+
if (processor)
|
|
1219
|
+
return processor.getScriptKind(fileName);
|
|
1220
|
+
return getScriptKind(fileName);
|
|
1400
1221
|
};
|
|
1401
1222
|
}
|
|
1402
1223
|
const getScriptSnapshot = host.getScriptSnapshot.bind(host);
|
|
1403
|
-
host.getScriptSnapshot = (
|
|
1404
|
-
|
|
1405
|
-
|
|
1224
|
+
host.getScriptSnapshot = (fileName) => {
|
|
1225
|
+
const processor = getProcessor(fileName);
|
|
1226
|
+
if (processor) {
|
|
1227
|
+
let cached = extractCache2.get(fileName);
|
|
1406
1228
|
if (!cached) {
|
|
1407
|
-
const code = host.readFile(
|
|
1408
|
-
const dir = path9.dirname(filename);
|
|
1229
|
+
const code = host.readFile(fileName, "utf-8") || "";
|
|
1409
1230
|
try {
|
|
1410
|
-
|
|
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
|
-
});
|
|
1231
|
+
cached = processor.extract(fileName, code);
|
|
1419
1232
|
cached.snapshot = ts2.ScriptSnapshot.fromString(cached.toString());
|
|
1420
1233
|
} catch {
|
|
1421
1234
|
cached = { snapshot: ts2.ScriptSnapshot.fromString("") };
|
|
1422
1235
|
}
|
|
1423
1236
|
ps == null ? void 0 : ps.getOrCreateScriptInfoForNormalizedPath(
|
|
1424
|
-
|
|
1425
|
-
|
|
1237
|
+
fileName,
|
|
1238
|
+
true,
|
|
1426
1239
|
void 0,
|
|
1427
1240
|
ts2.ScriptKind.Deferred,
|
|
1428
1241
|
false,
|
|
1429
1242
|
host
|
|
1430
1243
|
);
|
|
1431
|
-
|
|
1244
|
+
extractCache2.set(fileName, cached);
|
|
1432
1245
|
}
|
|
1433
1246
|
return cached.snapshot;
|
|
1434
1247
|
}
|
|
1435
|
-
return getScriptSnapshot(
|
|
1248
|
+
return getScriptSnapshot(fileName);
|
|
1436
1249
|
};
|
|
1437
1250
|
if (host.getProjectVersion) {
|
|
1438
1251
|
const getScriptVersion = host.getScriptVersion.bind(host);
|
|
1439
|
-
host.getScriptVersion = (
|
|
1440
|
-
|
|
1252
|
+
host.getScriptVersion = (fileName) => {
|
|
1253
|
+
const processor = getProcessor(fileName);
|
|
1254
|
+
if (processor)
|
|
1441
1255
|
return host.getProjectVersion();
|
|
1442
|
-
|
|
1443
|
-
return getScriptVersion(filename);
|
|
1256
|
+
return getScriptVersion(fileName);
|
|
1444
1257
|
};
|
|
1445
1258
|
}
|
|
1446
1259
|
const readDirectory2 = (_b = host.readDirectory) == null ? void 0 : _b.bind(host);
|
|
1447
1260
|
if (readDirectory2) {
|
|
1448
|
-
host.readDirectory = (
|
|
1261
|
+
host.readDirectory = (path8, extensions, exclude, include, depth) => {
|
|
1449
1262
|
return readDirectory2(
|
|
1450
|
-
|
|
1451
|
-
extensions == null ? void 0 : extensions.concat(
|
|
1263
|
+
path8,
|
|
1264
|
+
extensions == null ? void 0 : extensions.concat(Processors.extensions),
|
|
1452
1265
|
exclude,
|
|
1453
1266
|
include,
|
|
1454
1267
|
depth
|
|
1455
1268
|
);
|
|
1456
1269
|
};
|
|
1457
1270
|
}
|
|
1458
|
-
const
|
|
1459
|
-
if (
|
|
1460
|
-
host.
|
|
1461
|
-
let
|
|
1271
|
+
const resolveModuleNameLiterals = (_c = host.resolveModuleNameLiterals) == null ? void 0 : _c.bind(host);
|
|
1272
|
+
if (resolveModuleNameLiterals) {
|
|
1273
|
+
host.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) => {
|
|
1274
|
+
let normalModuleLiterals = moduleLiterals;
|
|
1462
1275
|
let resolvedModules;
|
|
1463
|
-
for (let i = 0; i <
|
|
1464
|
-
const moduleName =
|
|
1465
|
-
const
|
|
1466
|
-
if (
|
|
1276
|
+
for (let i = 0; i < moduleLiterals.length; i++) {
|
|
1277
|
+
const moduleName = moduleLiterals[i].text;
|
|
1278
|
+
const processor = moduleName[0] !== "*" ? getProcessor(moduleName) : void 0;
|
|
1279
|
+
if (processor) {
|
|
1467
1280
|
let resolvedFileName;
|
|
1468
1281
|
if (fsPathReg.test(moduleName)) {
|
|
1469
|
-
resolvedFileName =
|
|
1282
|
+
resolvedFileName = path6.resolve(containingFile, "..", moduleName);
|
|
1470
1283
|
} else {
|
|
1471
1284
|
const [, nodeModuleName, relativeModulePath] = modulePartsReg.exec(moduleName);
|
|
1472
|
-
const { resolvedModule } = ts2.
|
|
1285
|
+
const { resolvedModule } = ts2.bundlerModuleNameResolver(
|
|
1473
1286
|
`${nodeModuleName}/package.json`,
|
|
1474
1287
|
containingFile,
|
|
1475
1288
|
options,
|
|
1476
|
-
host
|
|
1289
|
+
host,
|
|
1290
|
+
resolutionCache
|
|
1477
1291
|
);
|
|
1478
1292
|
if (resolvedModule) {
|
|
1479
|
-
resolvedFileName =
|
|
1293
|
+
resolvedFileName = path6.join(
|
|
1480
1294
|
resolvedModule.resolvedFileName,
|
|
1481
1295
|
"..",
|
|
1482
1296
|
relativeModulePath
|
|
@@ -1485,47 +1299,54 @@ function patch(ts2, scriptLang, cache, host, ps) {
|
|
|
1485
1299
|
}
|
|
1486
1300
|
if (!resolvedModules) {
|
|
1487
1301
|
resolvedModules = [];
|
|
1488
|
-
|
|
1302
|
+
normalModuleLiterals = [];
|
|
1489
1303
|
for (let j = 0; j < i; j++) {
|
|
1490
1304
|
resolvedModules.push(void 0);
|
|
1491
|
-
|
|
1305
|
+
normalModuleLiterals.push(moduleLiterals[j]);
|
|
1492
1306
|
}
|
|
1493
1307
|
}
|
|
1494
|
-
|
|
1495
|
-
|
|
1308
|
+
if (resolvedFileName) {
|
|
1309
|
+
if (isDefinitionFile(resolvedFileName)) {
|
|
1310
|
+
if (!host.fileExists(resolvedFileName)) {
|
|
1311
|
+
resolvedFileName = void 0;
|
|
1312
|
+
}
|
|
1313
|
+
} else {
|
|
1314
|
+
const ext = getExt(resolvedFileName);
|
|
1315
|
+
const definitionFile = `${resolvedFileName.slice(
|
|
1316
|
+
0,
|
|
1317
|
+
-ext.length
|
|
1318
|
+
)}.d${ext}`;
|
|
1319
|
+
if (host.fileExists(definitionFile)) {
|
|
1320
|
+
resolvedFileName = definitionFile;
|
|
1321
|
+
} else if (!host.fileExists(resolvedFileName)) {
|
|
1322
|
+
resolvedFileName = void 0;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
resolvedModules.push({
|
|
1327
|
+
resolvedModule: resolvedFileName ? {
|
|
1496
1328
|
resolvedFileName,
|
|
1497
|
-
extension:
|
|
1329
|
+
extension: processor.getScriptExtension(resolvedFileName),
|
|
1498
1330
|
isExternalLibraryImport: false
|
|
1499
|
-
} :
|
|
1500
|
-
);
|
|
1331
|
+
} : void 0
|
|
1332
|
+
});
|
|
1501
1333
|
} else if (resolvedModules) {
|
|
1502
1334
|
resolvedModules.push(void 0);
|
|
1503
1335
|
}
|
|
1504
1336
|
}
|
|
1505
|
-
const normalResolvedModules =
|
|
1506
|
-
|
|
1337
|
+
const normalResolvedModules = normalModuleLiterals.length ? resolveModuleNameLiterals(
|
|
1338
|
+
normalModuleLiterals,
|
|
1507
1339
|
containingFile,
|
|
1508
|
-
reusedNames,
|
|
1509
1340
|
redirectedReference,
|
|
1510
1341
|
options,
|
|
1511
|
-
|
|
1342
|
+
containingSourceFile,
|
|
1343
|
+
reusedNames
|
|
1512
1344
|
) : void 0;
|
|
1513
1345
|
if (resolvedModules) {
|
|
1514
1346
|
if (normalResolvedModules) {
|
|
1515
1347
|
for (let i = 0, j = 0; i < resolvedModules.length; i++) {
|
|
1516
|
-
|
|
1517
|
-
|
|
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;
|
|
1348
|
+
if (!resolvedModules[i]) {
|
|
1349
|
+
resolvedModules[i] = normalResolvedModules[j++];
|
|
1529
1350
|
}
|
|
1530
1351
|
}
|
|
1531
1352
|
}
|
|
@@ -1536,6 +1357,10 @@ function patch(ts2, scriptLang, cache, host, ps) {
|
|
|
1536
1357
|
};
|
|
1537
1358
|
}
|
|
1538
1359
|
return host;
|
|
1360
|
+
function getProcessor(fileName) {
|
|
1361
|
+
const ext = getExt(fileName);
|
|
1362
|
+
return ext ? processors[ext] : void 0;
|
|
1363
|
+
}
|
|
1539
1364
|
}
|
|
1540
1365
|
|
|
1541
1366
|
// src/service/script/index.ts
|
|
@@ -1551,12 +1376,13 @@ var colorModifierReg = /\bcolor\b/;
|
|
|
1551
1376
|
var localInternalsPrefix = "__marko_internal_";
|
|
1552
1377
|
var requiredTSCompilerOptions = {
|
|
1553
1378
|
module: ts.ModuleKind.ESNext,
|
|
1554
|
-
moduleResolution: ts.ModuleResolutionKind.
|
|
1379
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
1555
1380
|
noEmit: true,
|
|
1556
1381
|
allowJs: true,
|
|
1557
1382
|
composite: false,
|
|
1558
1383
|
declaration: false,
|
|
1559
1384
|
skipLibCheck: true,
|
|
1385
|
+
importHelpers: false,
|
|
1560
1386
|
isolatedModules: true,
|
|
1561
1387
|
resolveJsonModule: true,
|
|
1562
1388
|
skipDefaultLibCheck: true,
|
|
@@ -1586,26 +1412,26 @@ var ScriptService = {
|
|
|
1586
1412
|
const filename = getFSPath(doc);
|
|
1587
1413
|
if (!filename)
|
|
1588
1414
|
return;
|
|
1589
|
-
const
|
|
1590
|
-
const extracted = processScript(doc,
|
|
1591
|
-
const lang = getScriptLang(
|
|
1415
|
+
const tsProject = getTSProject(filename);
|
|
1416
|
+
const extracted = processScript(doc, tsProject);
|
|
1417
|
+
const lang = Project4.getScriptLang(
|
|
1592
1418
|
filename,
|
|
1419
|
+
tsProject.markoScriptLang,
|
|
1593
1420
|
ts,
|
|
1594
|
-
|
|
1595
|
-
project.markoScriptLang
|
|
1421
|
+
tsProject.host
|
|
1596
1422
|
);
|
|
1597
1423
|
const generated = extracted.toString();
|
|
1598
1424
|
const content = (() => {
|
|
1599
1425
|
try {
|
|
1600
1426
|
return prettier2.format(generated, {
|
|
1601
|
-
parser: lang ===
|
|
1427
|
+
parser: lang === ScriptLang.ts ? "typescript" : "babel"
|
|
1602
1428
|
});
|
|
1603
1429
|
} catch {
|
|
1604
1430
|
return generated;
|
|
1605
1431
|
}
|
|
1606
1432
|
})();
|
|
1607
1433
|
return {
|
|
1608
|
-
language: lang ===
|
|
1434
|
+
language: lang === ScriptLang.ts ? "typescript" : "javascript",
|
|
1609
1435
|
content
|
|
1610
1436
|
};
|
|
1611
1437
|
}
|
|
@@ -1661,7 +1487,7 @@ var ScriptService = {
|
|
|
1661
1487
|
let source = completion.source;
|
|
1662
1488
|
if (source && completion.hasAction) {
|
|
1663
1489
|
if (source[0] === ".") {
|
|
1664
|
-
source =
|
|
1490
|
+
source = path7.resolve(fileName, "..", source);
|
|
1665
1491
|
}
|
|
1666
1492
|
detail = relativeImportPath(fileName, source);
|
|
1667
1493
|
sortText = `\uFFFF${sortText}`;
|
|
@@ -1965,26 +1791,17 @@ ${documentation}`;
|
|
|
1965
1791
|
}
|
|
1966
1792
|
};
|
|
1967
1793
|
function processScript(doc, tsProject) {
|
|
1968
|
-
return processDoc(
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
tsProject.rootDir,
|
|
1980
|
-
markoProject,
|
|
1981
|
-
ts,
|
|
1982
|
-
host
|
|
1983
|
-
)) == null ? void 0 : _a.markoTypesCode,
|
|
1984
|
-
componentFilename: getComponentFilename(filename)
|
|
1985
|
-
});
|
|
1986
|
-
}
|
|
1987
|
-
);
|
|
1794
|
+
return processDoc(doc, ({ filename, parsed, lookup }) => {
|
|
1795
|
+
var _a;
|
|
1796
|
+
const { host, markoScriptLang } = tsProject;
|
|
1797
|
+
return extractScript({
|
|
1798
|
+
ts,
|
|
1799
|
+
parsed,
|
|
1800
|
+
lookup,
|
|
1801
|
+
scriptLang: Project4.getScriptLang(filename, markoScriptLang, ts, host),
|
|
1802
|
+
runtimeTypesCode: (_a = Project4.getTypeLibs(tsProject.rootDir, ts, host)) == null ? void 0 : _a.markoTypesCode
|
|
1803
|
+
});
|
|
1804
|
+
});
|
|
1988
1805
|
}
|
|
1989
1806
|
function getInsertModuleStatementOffset(parsed) {
|
|
1990
1807
|
const { program } = parsed;
|
|
@@ -2035,27 +1852,27 @@ function docLocationAtTextSpan(doc, { start, length }) {
|
|
|
2035
1852
|
}
|
|
2036
1853
|
function getTSProject(docFsPath) {
|
|
2037
1854
|
var _a;
|
|
2038
|
-
let
|
|
2039
|
-
let markoScriptLang =
|
|
1855
|
+
let configFile;
|
|
1856
|
+
let markoScriptLang = ScriptLang.js;
|
|
2040
1857
|
if (docFsPath) {
|
|
2041
|
-
|
|
1858
|
+
configFile = ts.findConfigFile(
|
|
2042
1859
|
docFsPath,
|
|
2043
1860
|
ts.sys.fileExists,
|
|
2044
1861
|
"tsconfig.json"
|
|
2045
1862
|
);
|
|
2046
|
-
if (
|
|
2047
|
-
markoScriptLang =
|
|
1863
|
+
if (configFile) {
|
|
1864
|
+
markoScriptLang = ScriptLang.ts;
|
|
2048
1865
|
} else {
|
|
2049
|
-
|
|
1866
|
+
configFile = ts.findConfigFile(
|
|
2050
1867
|
docFsPath,
|
|
2051
1868
|
ts.sys.fileExists,
|
|
2052
1869
|
"jsconfig.json"
|
|
2053
1870
|
);
|
|
2054
1871
|
}
|
|
2055
1872
|
}
|
|
2056
|
-
const rootDir =
|
|
2057
|
-
const
|
|
2058
|
-
let projectCache =
|
|
1873
|
+
const rootDir = configFile && path7.dirname(configFile) || process.cwd();
|
|
1874
|
+
const cache = Project4.getCache(configFile && rootDir);
|
|
1875
|
+
let projectCache = cache.get(getTSProject);
|
|
2059
1876
|
let cached;
|
|
2060
1877
|
if (projectCache) {
|
|
2061
1878
|
cached = projectCache.get(rootDir);
|
|
@@ -2063,14 +1880,14 @@ function getTSProject(docFsPath) {
|
|
|
2063
1880
|
return cached;
|
|
2064
1881
|
} else {
|
|
2065
1882
|
projectCache = /* @__PURE__ */ new Map();
|
|
2066
|
-
|
|
1883
|
+
cache.set(getTSProject, projectCache);
|
|
2067
1884
|
}
|
|
2068
1885
|
const { fileNames, options, projectReferences } = ts.parseJsonConfigFileContent(
|
|
2069
|
-
|
|
1886
|
+
configFile && ts.readConfigFile(configFile, ts.sys.readFile).config || defaultTSConfig,
|
|
2070
1887
|
ts.sys,
|
|
2071
1888
|
rootDir,
|
|
2072
1889
|
requiredTSCompilerOptions,
|
|
2073
|
-
|
|
1890
|
+
configFile,
|
|
2074
1891
|
void 0,
|
|
2075
1892
|
extraTSCompilerExtensions
|
|
2076
1893
|
);
|
|
@@ -2078,15 +1895,21 @@ function getTSProject(docFsPath) {
|
|
|
2078
1895
|
const potentialGlobalFiles = new Set(
|
|
2079
1896
|
fileNames.filter((file) => /\.[cm]?ts$/.test(file))
|
|
2080
1897
|
);
|
|
2081
|
-
const tsPkgFile =
|
|
2082
|
-
const defaultLibFile =
|
|
2083
|
-
tsPkgFile ?
|
|
1898
|
+
const tsPkgFile = configFile && ((_a = ts.resolveModuleName("typescript/package.json", configFile, options, ts.sys).resolvedModule) == null ? void 0 : _a.resolvedFileName);
|
|
1899
|
+
const defaultLibFile = path7.join(
|
|
1900
|
+
tsPkgFile ? path7.join(tsPkgFile, "../lib") : __dirname,
|
|
2084
1901
|
ts.getDefaultLibFileName(options)
|
|
2085
1902
|
);
|
|
1903
|
+
const resolutionCache = ts.createModuleResolutionCache(
|
|
1904
|
+
rootDir,
|
|
1905
|
+
getCanonicalFileName,
|
|
1906
|
+
options
|
|
1907
|
+
);
|
|
2086
1908
|
const host = patch(
|
|
2087
1909
|
ts,
|
|
2088
|
-
|
|
1910
|
+
configFile,
|
|
2089
1911
|
extractCache,
|
|
1912
|
+
resolutionCache,
|
|
2090
1913
|
{
|
|
2091
1914
|
getNewLine() {
|
|
2092
1915
|
return ts.sys.newLine;
|
|
@@ -2109,9 +1932,16 @@ function getTSProject(docFsPath) {
|
|
|
2109
1932
|
getProjectReferences() {
|
|
2110
1933
|
return projectReferences;
|
|
2111
1934
|
},
|
|
2112
|
-
|
|
2113
|
-
return
|
|
2114
|
-
return ts.
|
|
1935
|
+
resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options2, _containingSourceFile, _reusedNames) {
|
|
1936
|
+
return moduleLiterals.map((moduleLiteral) => {
|
|
1937
|
+
return ts.bundlerModuleNameResolver(
|
|
1938
|
+
moduleLiteral.text,
|
|
1939
|
+
containingFile,
|
|
1940
|
+
options2,
|
|
1941
|
+
host,
|
|
1942
|
+
resolutionCache,
|
|
1943
|
+
redirectedReference
|
|
1944
|
+
);
|
|
2115
1945
|
});
|
|
2116
1946
|
},
|
|
2117
1947
|
readDirectory: ts.sys.readDirectory,
|
|
@@ -2134,7 +1964,7 @@ function getTSProject(docFsPath) {
|
|
|
2134
1964
|
return `${((_a2 = get(filenameToURI(filename))) == null ? void 0 : _a2.version) ?? -1}`;
|
|
2135
1965
|
},
|
|
2136
1966
|
getScriptKind(filename) {
|
|
2137
|
-
switch (
|
|
1967
|
+
switch (path7.extname(filename)) {
|
|
2138
1968
|
case ts.Extension.Js:
|
|
2139
1969
|
case ts.Extension.Cjs:
|
|
2140
1970
|
case ts.Extension.Mjs:
|
|
@@ -2170,14 +2000,7 @@ function getTSProject(docFsPath) {
|
|
|
2170
2000
|
host,
|
|
2171
2001
|
rootDir: options.rootDir,
|
|
2172
2002
|
service: ts.createLanguageService(host),
|
|
2173
|
-
|
|
2174
|
-
markoScriptLang,
|
|
2175
|
-
markoProjectTypeLibs: getProjectTypeLibs(
|
|
2176
|
-
options.rootDir,
|
|
2177
|
-
markoProject,
|
|
2178
|
-
ts,
|
|
2179
|
-
host
|
|
2180
|
-
)
|
|
2003
|
+
markoScriptLang
|
|
2181
2004
|
};
|
|
2182
2005
|
projectCache.set(rootDir, tsProject);
|
|
2183
2006
|
return tsProject;
|
|
@@ -2187,7 +2010,7 @@ function filenameToURI(filename) {
|
|
|
2187
2010
|
}
|
|
2188
2011
|
async function getPreferences(scriptLang) {
|
|
2189
2012
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2190
|
-
const configName = scriptLang ===
|
|
2013
|
+
const configName = scriptLang === ScriptLang.js ? "javascript" : "typescript";
|
|
2191
2014
|
const [preferencesConfig, suggestConfig, inlayHintsConfig] = await Promise.all([
|
|
2192
2015
|
getConfig(`${configName}.preferences`),
|
|
2193
2016
|
getConfig(`${configName}.suggest`),
|
|
@@ -2335,6 +2158,9 @@ function getTSTriggerChar(char) {
|
|
|
2335
2158
|
if (char && tsTriggerChars.has(char))
|
|
2336
2159
|
return char;
|
|
2337
2160
|
}
|
|
2161
|
+
function getCanonicalFileName(fileName) {
|
|
2162
|
+
return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
|
2163
|
+
}
|
|
2338
2164
|
|
|
2339
2165
|
// src/service/style/index.ts
|
|
2340
2166
|
import {
|
|
@@ -3225,7 +3051,7 @@ for (const command in service.commands) {
|
|
|
3225
3051
|
}
|
|
3226
3052
|
function validateDocs() {
|
|
3227
3053
|
queueDiagnostic();
|
|
3228
|
-
|
|
3054
|
+
Project5.clearCaches();
|
|
3229
3055
|
}
|
|
3230
3056
|
function queueDiagnostic() {
|
|
3231
3057
|
clearTimeout(diagnosticTimeout);
|