vue-tsc 0.33.6 → 0.34.0
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/out/apis.d.ts +1 -1
- package/out/apis.js +22 -29
- package/out/proxy.js +40 -18
- package/package.json +3 -3
package/out/apis.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import type { TypeScriptRuntime } from '@volar/vue-typescript';
|
|
3
3
|
export declare function register(ts: typeof import('typescript/lib/tsserverlibrary'), context: TypeScriptRuntime): {
|
|
4
|
-
getRootFileNames: () => string[];
|
|
4
|
+
getRootFileNames: () => string[] | undefined;
|
|
5
5
|
emit: (targetSourceFile?: ts.SourceFile | undefined, _writeFile?: ts.WriteFileCallback | undefined, cancellationToken?: ts.CancellationToken | undefined, emitOnlyDtsFiles?: boolean | undefined, customTransformers?: ts.CustomTransformers | undefined) => ts.EmitResult;
|
|
6
6
|
getSyntacticDiagnostics: (sourceFile?: ts.SourceFile | undefined, cancellationToken?: ts.CancellationToken | undefined) => readonly ts.DiagnosticWithLocation[] | readonly ts.Diagnostic[];
|
|
7
7
|
getSemanticDiagnostics: (sourceFile?: ts.SourceFile | undefined, cancellationToken?: ts.CancellationToken | undefined) => readonly ts.DiagnosticWithLocation[] | readonly ts.Diagnostic[];
|
package/out/apis.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.register = void 0;
|
|
4
|
-
const lsTypes = ['script', 'template'];
|
|
5
4
|
function register(ts, context) {
|
|
6
5
|
return {
|
|
7
6
|
getRootFileNames,
|
|
@@ -12,11 +11,7 @@ function register(ts, context) {
|
|
|
12
11
|
getBindAndCheckDiagnostics,
|
|
13
12
|
};
|
|
14
13
|
function getRootFileNames() {
|
|
15
|
-
|
|
16
|
-
...getProgram('script')?.getRootFileNames().filter(fileName => context.getTsLsHost('script').fileExists?.(fileName)) ?? [],
|
|
17
|
-
...getProgram('template')?.getRootFileNames().filter(fileName => context.getTsLsHost('template')?.fileExists?.(fileName)) ?? [],
|
|
18
|
-
]);
|
|
19
|
-
return [...set.values()];
|
|
14
|
+
return getProgram()?.getRootFileNames().filter(fileName => context.getTsLsHost().fileExists?.(fileName));
|
|
20
15
|
}
|
|
21
16
|
// for vue-tsc --noEmit --watch
|
|
22
17
|
function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
|
|
@@ -31,63 +26,61 @@ function register(ts, context) {
|
|
|
31
26
|
}
|
|
32
27
|
function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
|
|
33
28
|
if (sourceFile) {
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
29
|
+
const mapped = context.vueFiles.fromEmbeddedFileName(sourceFile.fileName);
|
|
30
|
+
if (mapped) {
|
|
36
31
|
let results = [];
|
|
37
|
-
const embeddeds =
|
|
32
|
+
const embeddeds = mapped.vueFile.getAllEmbeddeds();
|
|
38
33
|
for (const embedded of embeddeds) {
|
|
39
|
-
|
|
34
|
+
const isTsFile = embedded.file.fileName.endsWith('.js') ||
|
|
35
|
+
embedded.file.fileName.endsWith('.ts') ||
|
|
36
|
+
embedded.file.fileName.endsWith('.jsx') ||
|
|
37
|
+
embedded.file.fileName.endsWith('.tsx');
|
|
38
|
+
if (!isTsFile || !embedded.file.capabilities.diagnostics)
|
|
40
39
|
continue;
|
|
41
|
-
const program = getProgram(
|
|
40
|
+
const program = getProgram();
|
|
42
41
|
const embeddedSourceFile = program?.getSourceFile(embedded.file.fileName);
|
|
43
42
|
if (embeddedSourceFile) {
|
|
44
|
-
const errors = transformDiagnostics(
|
|
43
|
+
const errors = transformDiagnostics(program?.[api](embeddedSourceFile, cancellationToken) ?? []);
|
|
45
44
|
results = results.concat(errors);
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
return results;
|
|
49
48
|
}
|
|
50
49
|
else {
|
|
51
|
-
return getProgram(
|
|
50
|
+
return getProgram()?.[api](sourceFile, cancellationToken) ?? [];
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
|
-
return
|
|
53
|
+
return transformDiagnostics(getProgram()?.[api](sourceFile, cancellationToken) ?? []);
|
|
55
54
|
}
|
|
56
55
|
function getGlobalDiagnostics(cancellationToken) {
|
|
57
|
-
return
|
|
56
|
+
return transformDiagnostics(getProgram()?.getGlobalDiagnostics(cancellationToken) ?? []);
|
|
58
57
|
}
|
|
59
58
|
function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
|
|
60
|
-
const scriptResult = getProgram(
|
|
61
|
-
const templateResult = getProgram('template')?.emit(targetSourceFile, undefined, cancellationToken, emitOnlyDtsFiles, customTransformers);
|
|
59
|
+
const scriptResult = getProgram().emit(targetSourceFile, (context.vueLsHost.writeFile ?? ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
|
|
62
60
|
return {
|
|
63
61
|
emitSkipped: scriptResult.emitSkipped,
|
|
64
62
|
emittedFiles: scriptResult.emittedFiles,
|
|
65
|
-
diagnostics:
|
|
66
|
-
...transformDiagnostics('script', scriptResult.diagnostics),
|
|
67
|
-
...transformDiagnostics('template', templateResult?.diagnostics ?? []),
|
|
68
|
-
],
|
|
63
|
+
diagnostics: transformDiagnostics(scriptResult.diagnostics),
|
|
69
64
|
};
|
|
70
65
|
}
|
|
71
|
-
function getProgram(
|
|
72
|
-
return context.getTsLs(
|
|
66
|
+
function getProgram() {
|
|
67
|
+
return context.getTsLs().getProgram();
|
|
73
68
|
}
|
|
74
69
|
// transform
|
|
75
|
-
function transformDiagnostics(
|
|
70
|
+
function transformDiagnostics(diagnostics) {
|
|
76
71
|
const result = [];
|
|
77
72
|
for (const diagnostic of diagnostics) {
|
|
78
73
|
if (diagnostic.file !== undefined
|
|
79
74
|
&& diagnostic.start !== undefined
|
|
80
75
|
&& diagnostic.length !== undefined) {
|
|
81
|
-
for (const tsOrVueLoc of context.vueFiles.fromEmbeddedLocation(
|
|
76
|
+
for (const tsOrVueLoc of context.vueFiles.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, data => !!data.capabilities.diagnostic)) {
|
|
82
77
|
if (!context.vueLsHost.fileExists?.(tsOrVueLoc.fileName))
|
|
83
78
|
continue;
|
|
84
|
-
if (!tsOrVueLoc.maped && lsType !== 'script')
|
|
85
|
-
continue;
|
|
86
79
|
let file = tsOrVueLoc.fileName === diagnostic.file.fileName
|
|
87
80
|
? diagnostic.file
|
|
88
81
|
: undefined;
|
|
89
82
|
if (!file) {
|
|
90
|
-
let docText = tsOrVueLoc.
|
|
83
|
+
let docText = tsOrVueLoc.mapped?.vueFile.getContent();
|
|
91
84
|
if (docText === undefined) {
|
|
92
85
|
const snapshot = context.vueLsHost.getScriptSnapshot(tsOrVueLoc.fileName);
|
|
93
86
|
if (snapshot) {
|
|
@@ -106,7 +99,7 @@ function register(ts, context) {
|
|
|
106
99
|
};
|
|
107
100
|
const relatedInformation = diagnostic.relatedInformation;
|
|
108
101
|
if (relatedInformation) {
|
|
109
|
-
newDiagnostic.relatedInformation = transformDiagnostics(
|
|
102
|
+
newDiagnostic.relatedInformation = transformDiagnostics(relatedInformation);
|
|
110
103
|
}
|
|
111
104
|
result.push(newDiagnostic);
|
|
112
105
|
}
|
package/out/proxy.js
CHANGED
|
@@ -5,12 +5,14 @@ const ts = require("typescript/lib/tsserverlibrary");
|
|
|
5
5
|
const apis = require("./apis");
|
|
6
6
|
const vue_typescript_1 = require("@volar/vue-typescript");
|
|
7
7
|
const vue_typescript_2 = require("@volar/vue-typescript");
|
|
8
|
+
let projectVersion = 0;
|
|
8
9
|
function createProgramProxy(options, // rootNamesOrOptions: readonly string[] | CreateProgramOptions,
|
|
9
10
|
_options, _host, _oldProgram, _configFileParsingDiagnostics) {
|
|
10
11
|
if (!options.options.noEmit && !options.options.emitDeclarationOnly)
|
|
11
12
|
return doThrow('js emit is not support');
|
|
12
13
|
if (!options.host)
|
|
13
14
|
return doThrow('!options.host');
|
|
15
|
+
projectVersion++;
|
|
14
16
|
const host = options.host;
|
|
15
17
|
const vueCompilerOptions = getVueCompilerOptions();
|
|
16
18
|
const scripts = new Map();
|
|
@@ -20,14 +22,20 @@ _options, _host, _oldProgram, _configFileParsingDiagnostics) {
|
|
|
20
22
|
writeFile: undefined,
|
|
21
23
|
getCompilationSettings: () => options.options,
|
|
22
24
|
getVueCompilationSettings: () => vueCompilerOptions,
|
|
23
|
-
getScriptFileNames: () =>
|
|
24
|
-
|
|
25
|
+
getScriptFileNames: () => {
|
|
26
|
+
return options.rootNames;
|
|
27
|
+
},
|
|
28
|
+
getScriptVersion,
|
|
25
29
|
getScriptSnapshot,
|
|
26
|
-
getProjectVersion: () =>
|
|
27
|
-
|
|
30
|
+
getProjectVersion: () => {
|
|
31
|
+
return projectVersion.toString();
|
|
32
|
+
},
|
|
33
|
+
getVueProjectVersion: () => {
|
|
34
|
+
return projectVersion.toString();
|
|
35
|
+
},
|
|
28
36
|
getProjectReferences: () => options.projectReferences,
|
|
29
37
|
};
|
|
30
|
-
const tsRuntime = (0, vue_typescript_1.createTypeScriptRuntime)({
|
|
38
|
+
const tsRuntime = options.oldProgram?.__VLS_tsRuntime ?? (0, vue_typescript_1.createTypeScriptRuntime)({
|
|
31
39
|
typescript: ts,
|
|
32
40
|
baseCssModuleType: 'any',
|
|
33
41
|
getCssClasses: () => ({}),
|
|
@@ -35,21 +43,23 @@ _options, _host, _oldProgram, _configFileParsingDiagnostics) {
|
|
|
35
43
|
vueLsHost: vueLsHost,
|
|
36
44
|
isVueTsc: true,
|
|
37
45
|
});
|
|
38
|
-
|
|
46
|
+
tsRuntime.update(true); // must update before getProgram() to update virtual scripts
|
|
47
|
+
const tsProgram = tsRuntime.getTsLs().getProgram();
|
|
39
48
|
if (!tsProgram)
|
|
40
49
|
throw '!tsProgram';
|
|
41
|
-
const
|
|
42
|
-
const
|
|
50
|
+
const proxyApis = apis.register(ts, tsRuntime);
|
|
51
|
+
const program = new Proxy(tsProgram, {
|
|
43
52
|
get: (target, property) => {
|
|
44
53
|
tsRuntime.update(true);
|
|
45
|
-
return
|
|
54
|
+
return proxyApis[property] || target[property];
|
|
46
55
|
},
|
|
47
56
|
});
|
|
57
|
+
program.__VLS_tsRuntime = tsRuntime;
|
|
48
58
|
for (const rootName of options.rootNames) {
|
|
49
59
|
// register file watchers
|
|
50
60
|
host.getSourceFile(rootName, ts.ScriptTarget.ESNext);
|
|
51
61
|
}
|
|
52
|
-
return
|
|
62
|
+
return program;
|
|
53
63
|
function getVueCompilerOptions() {
|
|
54
64
|
const tsConfig = options.options.configFilePath;
|
|
55
65
|
if (typeof tsConfig === 'string') {
|
|
@@ -57,20 +67,32 @@ _options, _host, _oldProgram, _configFileParsingDiagnostics) {
|
|
|
57
67
|
}
|
|
58
68
|
return {};
|
|
59
69
|
}
|
|
70
|
+
function getScriptVersion(fileName) {
|
|
71
|
+
return getScript(fileName)?.version ?? '';
|
|
72
|
+
}
|
|
60
73
|
function getScriptSnapshot(fileName) {
|
|
74
|
+
return getScript(fileName)?.scriptSnapshot;
|
|
75
|
+
}
|
|
76
|
+
function getScript(fileName) {
|
|
61
77
|
const script = scripts.get(fileName);
|
|
62
|
-
if (script) {
|
|
63
|
-
return script
|
|
78
|
+
if (script?.projectVersion === projectVersion) {
|
|
79
|
+
return script;
|
|
80
|
+
}
|
|
81
|
+
const modifiedTime = ts.sys.getModifiedTime?.(fileName)?.valueOf() ?? 0;
|
|
82
|
+
if (script?.modifiedTime === modifiedTime) {
|
|
83
|
+
return script;
|
|
64
84
|
}
|
|
65
85
|
if (host.fileExists(fileName)) {
|
|
66
86
|
const fileContent = host.readFile(fileName);
|
|
67
87
|
if (fileContent !== undefined) {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
const script = {
|
|
89
|
+
projectVersion,
|
|
90
|
+
modifiedTime,
|
|
91
|
+
scriptSnapshot: ts.ScriptSnapshot.fromString(fileContent),
|
|
92
|
+
version: host.createHash?.(fileContent) ?? fileContent,
|
|
93
|
+
};
|
|
94
|
+
scripts.set(fileName, script);
|
|
95
|
+
return script;
|
|
74
96
|
}
|
|
75
97
|
}
|
|
76
98
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-tsc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"bin",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"vue-tsc": "./bin/vue-tsc.js"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@volar/vue-typescript": "0.
|
|
19
|
+
"@volar/vue-typescript": "0.34.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"typescript": "*"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "1a70119c77eca70c56d5a99da0322c087a6cb33b"
|
|
25
25
|
}
|