vue-tsc 0.33.7 → 0.34.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.
Files changed (3) hide show
  1. package/out/apis.js +18 -40
  2. package/out/proxy.js +40 -18
  3. package/package.json +3 -3
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
- 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()];
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,46 @@ function register(ts, context) {
31
26
  }
32
27
  function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
33
28
  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) ?? [];
29
+ const mapped = context.vueFiles.fromEmbeddedFileName(sourceFile.fileName);
30
+ if (mapped) {
31
+ if (!mapped.embedded.file.capabilities.diagnostics)
32
+ return [];
33
+ const program = getProgram();
34
+ const errors = transformDiagnostics(program?.[api](sourceFile, cancellationToken) ?? []);
35
+ return errors;
52
36
  }
53
37
  }
54
- return lsTypes.map(lsType => transformDiagnostics(lsType, getProgram(lsType)?.[api](sourceFile, cancellationToken) ?? [])).flat();
38
+ return transformDiagnostics(getProgram()[api](sourceFile, cancellationToken) ?? []);
55
39
  }
56
40
  function getGlobalDiagnostics(cancellationToken) {
57
- return lsTypes.map(lsType => transformDiagnostics(lsType, getProgram(lsType)?.getGlobalDiagnostics(cancellationToken) ?? [])).flat();
41
+ return transformDiagnostics(getProgram().getGlobalDiagnostics(cancellationToken) ?? []);
58
42
  }
59
43
  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);
44
+ const scriptResult = getProgram().emit(targetSourceFile, (context.vueLsHost.writeFile ?? ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
62
45
  return {
63
46
  emitSkipped: scriptResult.emitSkipped,
64
47
  emittedFiles: scriptResult.emittedFiles,
65
- diagnostics: [
66
- ...transformDiagnostics('script', scriptResult.diagnostics),
67
- ...transformDiagnostics('template', templateResult?.diagnostics ?? []),
68
- ],
48
+ diagnostics: transformDiagnostics(scriptResult.diagnostics),
69
49
  };
70
50
  }
71
- function getProgram(lsType) {
72
- return context.getTsLs(lsType)?.getProgram();
51
+ function getProgram() {
52
+ return context.getTsLs().getProgram();
73
53
  }
74
54
  // transform
75
- function transformDiagnostics(lsType, diagnostics) {
55
+ function transformDiagnostics(diagnostics) {
76
56
  const result = [];
77
57
  for (const diagnostic of diagnostics) {
78
58
  if (diagnostic.file !== undefined
79
59
  && diagnostic.start !== undefined
80
60
  && 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)) {
61
+ for (const tsOrVueLoc of context.vueFiles.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, data => !!data.capabilities.diagnostic)) {
82
62
  if (!context.vueLsHost.fileExists?.(tsOrVueLoc.fileName))
83
63
  continue;
84
- if (!tsOrVueLoc.maped && lsType !== 'script')
85
- continue;
86
64
  let file = tsOrVueLoc.fileName === diagnostic.file.fileName
87
65
  ? diagnostic.file
88
66
  : undefined;
89
67
  if (!file) {
90
- let docText = tsOrVueLoc.maped?.vueFile.getContent();
68
+ let docText = tsOrVueLoc.mapped?.vueFile.getContent();
91
69
  if (docText === undefined) {
92
70
  const snapshot = context.vueLsHost.getScriptSnapshot(tsOrVueLoc.fileName);
93
71
  if (snapshot) {
@@ -106,7 +84,7 @@ function register(ts, context) {
106
84
  };
107
85
  const relatedInformation = diagnostic.relatedInformation;
108
86
  if (relatedInformation) {
109
- newDiagnostic.relatedInformation = transformDiagnostics(lsType, relatedInformation);
87
+ newDiagnostic.relatedInformation = transformDiagnostics(relatedInformation);
110
88
  }
111
89
  result.push(newDiagnostic);
112
90
  }
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: () => options.rootNames,
24
- getScriptVersion: (fileName) => scripts.get(fileName)?.version ?? '',
25
+ getScriptFileNames: () => {
26
+ return options.rootNames;
27
+ },
28
+ getScriptVersion,
25
29
  getScriptSnapshot,
26
- getProjectVersion: () => '',
27
- getVueProjectVersion: () => '',
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
- const tsProgram = tsRuntime.getTsLs('script').getProgram();
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 tsProgramApis_2 = apis.register(ts, tsRuntime);
42
- const tsProgramProxy = new Proxy(tsProgram, {
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 tsProgramApis_2[property] || target[property];
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 tsProgramProxy;
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.scriptSnapshot;
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 scriptSnapshot = ts.ScriptSnapshot.fromString(fileContent);
69
- scripts.set(fileName, {
70
- scriptSnapshot: scriptSnapshot,
71
- version: ts.sys.createHash?.(fileContent) ?? fileContent,
72
- });
73
- return scriptSnapshot;
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.33.7",
3
+ "version": "0.34.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.33.7"
19
+ "@volar/vue-typescript": "0.34.1"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "typescript": "*"
23
23
  },
24
- "gitHead": "1b89d4dc2fb0fa5b7c17aa9dbff4b0fc62a108f4"
24
+ "gitHead": "a7204b361e21774a2067c723415d988898a8b014"
25
25
  }