vue-tsc 0.35.1 → 0.36.1
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 +10 -0
- package/out/apis.js +124 -0
- package/out/proxy.d.ts +3 -0
- package/out/proxy.js +99 -0
- package/package.json +3 -3
package/out/apis.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import type { TypeScriptRuntime } from '@volar/vue-typescript';
|
|
3
|
+
export declare function register(ts: typeof import('typescript/lib/tsserverlibrary'), context: TypeScriptRuntime): {
|
|
4
|
+
getRootFileNames: () => string[];
|
|
5
|
+
emit: (targetSourceFile?: ts.SourceFile, _writeFile?: ts.WriteFileCallback, cancellationToken?: ts.CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: ts.CustomTransformers) => ts.EmitResult;
|
|
6
|
+
getSyntacticDiagnostics: (sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken) => readonly ts.DiagnosticWithLocation[] | readonly ts.Diagnostic[];
|
|
7
|
+
getSemanticDiagnostics: (sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken) => readonly ts.DiagnosticWithLocation[] | readonly ts.Diagnostic[];
|
|
8
|
+
getGlobalDiagnostics: (cancellationToken?: ts.CancellationToken) => readonly ts.Diagnostic[];
|
|
9
|
+
getBindAndCheckDiagnostics: (sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken) => readonly ts.DiagnosticWithLocation[] | readonly ts.Diagnostic[];
|
|
10
|
+
};
|
package/out/apis.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
function register(ts, context) {
|
|
5
|
+
return {
|
|
6
|
+
getRootFileNames,
|
|
7
|
+
emit,
|
|
8
|
+
getSyntacticDiagnostics,
|
|
9
|
+
getSemanticDiagnostics,
|
|
10
|
+
getGlobalDiagnostics,
|
|
11
|
+
getBindAndCheckDiagnostics,
|
|
12
|
+
};
|
|
13
|
+
function getRootFileNames() {
|
|
14
|
+
return getProgram().getRootFileNames().filter(fileName => { var _a, _b; return (_b = (_a = context.getTsLsHost()).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, fileName); });
|
|
15
|
+
}
|
|
16
|
+
// for vue-tsc --noEmit --watch
|
|
17
|
+
function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
|
|
18
|
+
return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getBindAndCheckDiagnostics');
|
|
19
|
+
}
|
|
20
|
+
// for vue-tsc --noEmit
|
|
21
|
+
function getSyntacticDiagnostics(sourceFile, cancellationToken) {
|
|
22
|
+
return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSyntacticDiagnostics');
|
|
23
|
+
}
|
|
24
|
+
function getSemanticDiagnostics(sourceFile, cancellationToken) {
|
|
25
|
+
return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSemanticDiagnostics');
|
|
26
|
+
}
|
|
27
|
+
function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
if (sourceFile) {
|
|
30
|
+
const mapped = context.vueFiles.fromEmbeddedFileName(sourceFile.fileName);
|
|
31
|
+
if (mapped) {
|
|
32
|
+
if (!mapped.embedded.file.capabilities.diagnostics)
|
|
33
|
+
return [];
|
|
34
|
+
const program = getProgram();
|
|
35
|
+
const errors = transformDiagnostics((_a = program === null || program === void 0 ? void 0 : program[api](sourceFile, cancellationToken)) !== null && _a !== void 0 ? _a : []);
|
|
36
|
+
return errors;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return transformDiagnostics((_b = getProgram()[api](sourceFile, cancellationToken)) !== null && _b !== void 0 ? _b : []);
|
|
40
|
+
}
|
|
41
|
+
function getGlobalDiagnostics(cancellationToken) {
|
|
42
|
+
var _a;
|
|
43
|
+
return transformDiagnostics((_a = getProgram().getGlobalDiagnostics(cancellationToken)) !== null && _a !== void 0 ? _a : []);
|
|
44
|
+
}
|
|
45
|
+
function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
|
|
46
|
+
var _a;
|
|
47
|
+
const scriptResult = getProgram().emit(targetSourceFile, ((_a = context.vueLsHost.writeFile) !== null && _a !== void 0 ? _a : ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
|
|
48
|
+
return {
|
|
49
|
+
emitSkipped: scriptResult.emitSkipped,
|
|
50
|
+
emittedFiles: scriptResult.emittedFiles,
|
|
51
|
+
diagnostics: transformDiagnostics(scriptResult.diagnostics),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function getProgram() {
|
|
55
|
+
return context.getTsLs().getProgram();
|
|
56
|
+
}
|
|
57
|
+
// transform
|
|
58
|
+
function transformDiagnostics(diagnostics) {
|
|
59
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
60
|
+
const result = [];
|
|
61
|
+
for (const diagnostic of diagnostics) {
|
|
62
|
+
if (diagnostic.file !== undefined
|
|
63
|
+
&& diagnostic.start !== undefined
|
|
64
|
+
&& diagnostic.length !== undefined) {
|
|
65
|
+
let founded = false;
|
|
66
|
+
for (const tsOrVueLoc of context.vueFiles.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, data => !!data.capabilities.diagnostic)) {
|
|
67
|
+
if (!((_b = (_a = context.vueLsHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, tsOrVueLoc.fileName)))
|
|
68
|
+
continue;
|
|
69
|
+
onMapping(diagnostic, tsOrVueLoc.fileName, tsOrVueLoc.range.start, tsOrVueLoc.range.end, (_c = tsOrVueLoc.mapped) === null || _c === void 0 ? void 0 : _c.vueFile.getContent());
|
|
70
|
+
founded = true;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
// fix https://github.com/johnsoncodehk/volar/issues/1372
|
|
74
|
+
if (!founded) {
|
|
75
|
+
for (const start of context.vueFiles.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start, diagnostic.start, data => !!data.capabilities.diagnostic)) {
|
|
76
|
+
if (!((_e = (_d = context.vueLsHost).fileExists) === null || _e === void 0 ? void 0 : _e.call(_d, start.fileName)))
|
|
77
|
+
continue;
|
|
78
|
+
for (const end of context.vueFiles.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start + diagnostic.length, diagnostic.start + diagnostic.length, data => !!data.capabilities.diagnostic)) {
|
|
79
|
+
if (!((_g = (_f = context.vueLsHost).fileExists) === null || _g === void 0 ? void 0 : _g.call(_f, end.fileName)))
|
|
80
|
+
continue;
|
|
81
|
+
if (start.fileName !== end.fileName)
|
|
82
|
+
continue;
|
|
83
|
+
onMapping(diagnostic, start.fileName, start.range.start, end.range.end, (_h = start.mapped) === null || _h === void 0 ? void 0 : _h.vueFile.getContent());
|
|
84
|
+
founded = true;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (founded) {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (diagnostic.file === undefined) {
|
|
94
|
+
result.push(diagnostic);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
function onMapping(diagnostic, fileName, start, end, docText) {
|
|
99
|
+
var _a;
|
|
100
|
+
let file = fileName === ((_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.fileName)
|
|
101
|
+
? diagnostic.file
|
|
102
|
+
: undefined;
|
|
103
|
+
if (!file) {
|
|
104
|
+
if (docText === undefined) {
|
|
105
|
+
const snapshot = context.vueLsHost.getScriptSnapshot(fileName);
|
|
106
|
+
if (snapshot) {
|
|
107
|
+
docText = snapshot.getText(0, snapshot.getLength());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
file = ts.createSourceFile(fileName, docText, fileName.endsWith('.vue') ? ts.ScriptTarget.JSON : ts.ScriptTarget.Latest);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const newDiagnostic = Object.assign(Object.assign({}, diagnostic), { file, start: start, length: end - start });
|
|
115
|
+
const relatedInformation = diagnostic.relatedInformation;
|
|
116
|
+
if (relatedInformation) {
|
|
117
|
+
newDiagnostic.relatedInformation = transformDiagnostics(relatedInformation);
|
|
118
|
+
}
|
|
119
|
+
result.push(newDiagnostic);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.register = register;
|
|
124
|
+
//# sourceMappingURL=apis.js.map
|
package/out/proxy.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
export declare function createProgramProxy(options: ts.CreateProgramOptions, // rootNamesOrOptions: readonly string[] | CreateProgramOptions,
|
|
3
|
+
_options?: ts.CompilerOptions, _host?: ts.CompilerHost, _oldProgram?: ts.Program, _configFileParsingDiagnostics?: readonly ts.Diagnostic[]): void | ts.Program;
|
package/out/proxy.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProgramProxy = void 0;
|
|
4
|
+
const ts = require("typescript/lib/tsserverlibrary");
|
|
5
|
+
const apis = require("./apis");
|
|
6
|
+
const vue_typescript_1 = require("@volar/vue-typescript");
|
|
7
|
+
const vue_typescript_2 = require("@volar/vue-typescript");
|
|
8
|
+
let projectVersion = 0;
|
|
9
|
+
function createProgramProxy(options, // rootNamesOrOptions: readonly string[] | CreateProgramOptions,
|
|
10
|
+
_options, _host, _oldProgram, _configFileParsingDiagnostics) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
if (!options.options.noEmit && !options.options.emitDeclarationOnly)
|
|
13
|
+
return doThrow('js emit is not support');
|
|
14
|
+
if (!options.host)
|
|
15
|
+
return doThrow('!options.host');
|
|
16
|
+
projectVersion++;
|
|
17
|
+
const host = options.host;
|
|
18
|
+
const vueCompilerOptions = getVueCompilerOptions();
|
|
19
|
+
const scripts = new Map();
|
|
20
|
+
const vueLsHost = Object.assign(Object.assign({}, host), { resolveModuleNames: undefined, writeFile: (fileName, content) => {
|
|
21
|
+
if (fileName.indexOf('__VLS_') === -1) {
|
|
22
|
+
host.writeFile(fileName, content, false);
|
|
23
|
+
}
|
|
24
|
+
}, getCompilationSettings: () => options.options, getVueCompilationSettings: () => vueCompilerOptions, getScriptFileNames: () => {
|
|
25
|
+
return options.rootNames;
|
|
26
|
+
}, getScriptVersion,
|
|
27
|
+
getScriptSnapshot, getProjectVersion: () => {
|
|
28
|
+
return projectVersion.toString();
|
|
29
|
+
}, getProjectReferences: () => options.projectReferences });
|
|
30
|
+
const tsRuntime = (_b = (_a = options.oldProgram) === null || _a === void 0 ? void 0 : _a.__VLS_tsRuntime) !== null && _b !== void 0 ? _b : (0, vue_typescript_1.createTypeScriptRuntime)({
|
|
31
|
+
typescript: ts,
|
|
32
|
+
baseCssModuleType: 'any',
|
|
33
|
+
getCssClasses: () => ({}),
|
|
34
|
+
vueLsHost: vueLsHost,
|
|
35
|
+
isVueTsc: true,
|
|
36
|
+
});
|
|
37
|
+
tsRuntime.update(); // must update before getProgram() to update virtual scripts
|
|
38
|
+
const proxyApis = apis.register(ts, tsRuntime);
|
|
39
|
+
const program = new Proxy({}, {
|
|
40
|
+
get: (_, property) => {
|
|
41
|
+
tsRuntime.update();
|
|
42
|
+
if (property in proxyApis) {
|
|
43
|
+
return proxyApis[property];
|
|
44
|
+
}
|
|
45
|
+
return tsRuntime.getTsLs().getProgram()[property];
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
program.__VLS_tsRuntime = tsRuntime;
|
|
49
|
+
for (const rootName of options.rootNames) {
|
|
50
|
+
// register file watchers
|
|
51
|
+
host.getSourceFile(rootName, ts.ScriptTarget.ESNext);
|
|
52
|
+
}
|
|
53
|
+
return program;
|
|
54
|
+
function getVueCompilerOptions() {
|
|
55
|
+
const tsConfig = options.options.configFilePath;
|
|
56
|
+
if (typeof tsConfig === 'string') {
|
|
57
|
+
return vue_typescript_2.tsShared.createParsedCommandLine(ts, ts.sys, tsConfig).vueOptions;
|
|
58
|
+
}
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
function getScriptVersion(fileName) {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
return (_b = (_a = getScript(fileName)) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : '';
|
|
64
|
+
}
|
|
65
|
+
function getScriptSnapshot(fileName) {
|
|
66
|
+
var _a;
|
|
67
|
+
return (_a = getScript(fileName)) === null || _a === void 0 ? void 0 : _a.scriptSnapshot;
|
|
68
|
+
}
|
|
69
|
+
function getScript(fileName) {
|
|
70
|
+
var _a, _b, _c, _d, _e, _f;
|
|
71
|
+
const script = scripts.get(fileName);
|
|
72
|
+
if ((script === null || script === void 0 ? void 0 : script.projectVersion) === projectVersion) {
|
|
73
|
+
return script;
|
|
74
|
+
}
|
|
75
|
+
const modifiedTime = (_d = (_c = (_b = (_a = ts.sys).getModifiedTime) === null || _b === void 0 ? void 0 : _b.call(_a, fileName)) === null || _c === void 0 ? void 0 : _c.valueOf()) !== null && _d !== void 0 ? _d : 0;
|
|
76
|
+
if ((script === null || script === void 0 ? void 0 : script.modifiedTime) === modifiedTime) {
|
|
77
|
+
return script;
|
|
78
|
+
}
|
|
79
|
+
if (host.fileExists(fileName)) {
|
|
80
|
+
const fileContent = host.readFile(fileName);
|
|
81
|
+
if (fileContent !== undefined) {
|
|
82
|
+
const script = {
|
|
83
|
+
projectVersion,
|
|
84
|
+
modifiedTime,
|
|
85
|
+
scriptSnapshot: ts.ScriptSnapshot.fromString(fileContent),
|
|
86
|
+
version: (_f = (_e = host.createHash) === null || _e === void 0 ? void 0 : _e.call(host, fileContent)) !== null && _f !== void 0 ? _f : fileContent,
|
|
87
|
+
};
|
|
88
|
+
scripts.set(fileName, script);
|
|
89
|
+
return script;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.createProgramProxy = createProgramProxy;
|
|
95
|
+
function doThrow(msg) {
|
|
96
|
+
console.error(msg);
|
|
97
|
+
throw msg;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=proxy.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-tsc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.1",
|
|
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.36.1"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"typescript": "*"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "d0e4dbd21d1c0f28d0015c96390cca535c85bf24"
|
|
25
25
|
}
|