vue-tsc 0.33.3 → 0.33.6

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