vue-tsc 0.33.1 → 0.33.3-patch.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import type * as ts from 'typescript/lib/tsserverlibrary';
2
- import type { TypeScriptFeaturesRuntimeContext } from '@volar/vue-typescript';
3
- export declare function register(ts: typeof import('typescript/lib/tsserverlibrary'), { vueDocuments, templateTsLsRaw, scriptTsLsRaw, templateTsHost, scriptTsHost, vueHost }: TypeScriptFeaturesRuntimeContext): {
2
+ import type { TypeScriptRuntime } from '@volar/vue-typescript';
3
+ export declare function register(ts: typeof import('typescript/lib/tsserverlibrary'), context: TypeScriptRuntime): {
4
4
  getRootFileNames: () => string[];
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[];
package/out/apis.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.register = void 0;
4
- const shared = require("@volar/shared");
5
4
  const lsTypes = ['script', 'template'];
6
- function register(ts, { vueDocuments, templateTsLsRaw, scriptTsLsRaw, templateTsHost, scriptTsHost, vueHost }) {
5
+ function register(ts, context) {
7
6
  return {
8
7
  getRootFileNames,
9
8
  emit,
@@ -14,8 +13,8 @@ function register(ts, { vueDocuments, templateTsLsRaw, scriptTsLsRaw, templateTs
14
13
  };
15
14
  function getRootFileNames() {
16
15
  const set = new Set([
17
- ...getProgram('script').getRootFileNames().filter(fileName => { var _a; return (_a = scriptTsHost.fileExists) === null || _a === void 0 ? void 0 : _a.call(scriptTsHost, fileName); }),
18
- ...getProgram('template').getRootFileNames().filter(fileName => { var _a; return (_a = templateTsHost.fileExists) === null || _a === void 0 ? void 0 : _a.call(templateTsHost, fileName); }),
16
+ ...getProgram('script')?.getRootFileNames().filter(fileName => context.getTsLsHost('script').fileExists?.(fileName)) ?? [],
17
+ ...getProgram('template')?.getRootFileNames().filter(fileName => context.getTsLsHost('template')?.fileExists?.(fileName)) ?? [],
19
18
  ]);
20
19
  return [...set.values()];
21
20
  }
@@ -32,78 +31,71 @@ function register(ts, { vueDocuments, templateTsLsRaw, scriptTsLsRaw, templateTs
32
31
  }
33
32
  function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
34
33
  if (sourceFile) {
35
- const sourceMap = vueDocuments.fromEmbeddedDocumentUri('script', shared.fsPathToUri(sourceFile.fileName));
36
- const vueDocument = sourceMap ? vueDocuments.get(sourceMap.sourceDocument.uri) : undefined;
37
- if (vueDocument) {
34
+ const maped = context.vueFiles.fromEmbeddedFileName('script', sourceFile.fileName);
35
+ if (maped) {
38
36
  let results = [];
39
- const sourceMaps = vueDocument.getSourceMaps();
40
- for (const sourceMap of sourceMaps) {
41
- if (sourceMap.lsType === 'nonTs' || !sourceMap.capabilities.diagnostics)
37
+ const embeddeds = maped.vueFile.getAllEmbeddeds();
38
+ for (const embedded of embeddeds) {
39
+ if (embedded.file.lsType === 'nonTs' || !embedded.file.capabilities.diagnostics)
42
40
  continue;
43
- const program = getProgram(sourceMap.lsType);
44
- const embeddedSourceFile = program.getSourceFile(shared.uriToFsPath(sourceMap.mappedDocument.uri));
41
+ const program = getProgram(embedded.file.lsType);
42
+ const embeddedSourceFile = program?.getSourceFile(embedded.file.fileName);
45
43
  if (embeddedSourceFile) {
46
- const errors = transformDiagnostics(sourceMap.lsType, program[api](embeddedSourceFile, cancellationToken));
44
+ const errors = transformDiagnostics(embedded.file.lsType, program?.[api](embeddedSourceFile, cancellationToken) ?? []);
47
45
  results = results.concat(errors);
48
46
  }
49
47
  }
50
48
  return results;
51
49
  }
52
50
  else {
53
- return getProgram('script')[api](sourceFile, cancellationToken);
51
+ return getProgram('script')?.[api](sourceFile, cancellationToken) ?? [];
54
52
  }
55
53
  }
56
- return lsTypes.map(lsType => transformDiagnostics(lsType, getProgram(lsType)[api](sourceFile, cancellationToken))).flat();
54
+ return lsTypes.map(lsType => transformDiagnostics(lsType, getProgram(lsType)?.[api](sourceFile, cancellationToken) ?? [])).flat();
57
55
  }
58
56
  function getGlobalDiagnostics(cancellationToken) {
59
- return lsTypes.map(lsType => transformDiagnostics(lsType, getProgram(lsType).getGlobalDiagnostics(cancellationToken))).flat();
57
+ return lsTypes.map(lsType => transformDiagnostics(lsType, getProgram(lsType)?.getGlobalDiagnostics(cancellationToken) ?? [])).flat();
60
58
  }
61
59
  function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
62
- var _a;
63
- const scriptResult = getProgram('script').emit(targetSourceFile, ((_a = vueHost.writeFile) !== null && _a !== void 0 ? _a : ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
64
- const templateResult = getProgram('template').emit(targetSourceFile, undefined, 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);
65
62
  return {
66
63
  emitSkipped: scriptResult.emitSkipped,
67
64
  emittedFiles: scriptResult.emittedFiles,
68
65
  diagnostics: [
69
66
  ...transformDiagnostics('script', scriptResult.diagnostics),
70
- ...transformDiagnostics('template', templateResult.diagnostics),
67
+ ...transformDiagnostics('template', templateResult?.diagnostics ?? []),
71
68
  ],
72
69
  };
73
70
  }
74
71
  function getProgram(lsType) {
75
- const program = (lsType === 'script' ? scriptTsLsRaw : templateTsLsRaw).getProgram();
76
- if (!program)
77
- throw '!program';
78
- return program;
72
+ return context.getTsLs(lsType)?.getProgram();
79
73
  }
80
74
  // transform
81
75
  function transformDiagnostics(lsType, diagnostics) {
82
- var _a, _b;
83
76
  const result = [];
84
77
  for (const diagnostic of diagnostics) {
85
78
  if (diagnostic.file !== undefined
86
79
  && diagnostic.start !== undefined
87
80
  && diagnostic.length !== undefined) {
88
- const fileName = shared.normalizeFileName(diagnostic.file.fileName);
89
- for (const tsOrVueLoc of vueDocuments.fromEmbeddedLocation(lsType, shared.fsPathToUri(fileName), diagnostic.start, diagnostic.start + diagnostic.length, data => !!data.capabilities.diagnostic)) {
90
- if (!((_a = vueHost.fileExists) === null || _a === void 0 ? void 0 : _a.call(vueHost, shared.uriToFsPath(tsOrVueLoc.uri))))
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))
91
83
  continue;
92
- if (tsOrVueLoc.type === 'source-ts' && lsType !== 'script')
84
+ if (!tsOrVueLoc.maped && lsType !== 'script')
93
85
  continue;
94
- let file = shared.uriToFsPath(tsOrVueLoc.uri) === fileName
86
+ let file = tsOrVueLoc.fileName === diagnostic.file.fileName
95
87
  ? diagnostic.file
96
88
  : undefined;
97
89
  if (!file) {
98
- let docText = (_b = tsOrVueLoc.sourceMap) === null || _b === void 0 ? void 0 : _b.sourceDocument.getText();
90
+ let docText = tsOrVueLoc.maped?.vueFile.getContent();
99
91
  if (docText === undefined) {
100
- const snapshot = vueHost.getScriptSnapshot(shared.uriToFsPath(tsOrVueLoc.uri));
92
+ const snapshot = context.vueLsHost.getScriptSnapshot(tsOrVueLoc.fileName);
101
93
  if (snapshot) {
102
94
  docText = snapshot.getText(0, snapshot.getLength());
103
95
  }
104
96
  }
105
- if (docText !== undefined) {
106
- file = ts.createSourceFile(shared.uriToFsPath(tsOrVueLoc.uri), docText, tsOrVueLoc.uri.endsWith('.vue') ? ts.ScriptTarget.JSON : ts.ScriptTarget.Latest);
97
+ else {
98
+ file = ts.createSourceFile(tsOrVueLoc.fileName, docText, tsOrVueLoc.fileName.endsWith('.vue') ? ts.ScriptTarget.JSON : ts.ScriptTarget.Latest);
107
99
  }
108
100
  }
109
101
  const newDiagnostic = {
package/out/proxy.js CHANGED
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createProgramProxy = void 0;
4
4
  const ts = require("typescript/lib/tsserverlibrary");
5
- const shared = require("@volar/shared");
6
5
  const apis = require("./apis");
7
6
  const vue_typescript_1 = require("@volar/vue-typescript");
7
+ const vue_typescript_2 = require("@volar/vue-typescript");
8
8
  function createProgramProxy(options, // rootNamesOrOptions: readonly string[] | CreateProgramOptions,
9
9
  _options, _host, _oldProgram, _configFileParsingDiagnostics) {
10
10
  if (!options.options.noEmit && !options.options.emitDeclarationOnly)
@@ -21,18 +21,24 @@ _options, _host, _oldProgram, _configFileParsingDiagnostics) {
21
21
  getCompilationSettings: () => options.options,
22
22
  getVueCompilationSettings: () => vueCompilerOptions,
23
23
  getScriptFileNames: () => options.rootNames,
24
- getScriptVersion: (fileName) => { var _a, _b; return (_b = (_a = scripts.get(fileName)) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : ''; },
24
+ getScriptVersion: (fileName) => scripts.get(fileName)?.version ?? '',
25
25
  getScriptSnapshot,
26
26
  getProjectVersion: () => '',
27
27
  getVueProjectVersion: () => '',
28
28
  getProjectReferences: () => options.projectReferences,
29
29
  };
30
- const services = (0, vue_typescript_1.createBasicRuntime)();
31
- const tsRuntime = (0, vue_typescript_1.createTypeScriptRuntime)({ typescript: ts, ...services, compilerOptions: vueCompilerOptions }, vueLsHost, false);
32
- const tsProgram = tsRuntime.context.scriptTsLsRaw.getProgram(); // TODO: handle template ls?
30
+ const tsRuntime = (0, vue_typescript_1.createTypeScriptRuntime)({
31
+ typescript: ts,
32
+ getCssClasses: () => ({}),
33
+ getCssVBindRanges: () => [],
34
+ vueCompilerOptions,
35
+ vueLsHost: vueLsHost,
36
+ isVueTsc: true,
37
+ });
38
+ const tsProgram = tsRuntime.getTsLs('script').getProgram();
33
39
  if (!tsProgram)
34
40
  throw '!tsProgram';
35
- const tsProgramApis_2 = apis.register(ts, tsRuntime.context);
41
+ const tsProgramApis_2 = apis.register(ts, tsRuntime);
36
42
  const tsProgramProxy = new Proxy(tsProgram, {
37
43
  get: (target, property) => {
38
44
  tsRuntime.update(true);
@@ -47,12 +53,11 @@ _options, _host, _oldProgram, _configFileParsingDiagnostics) {
47
53
  function getVueCompilerOptions() {
48
54
  const tsConfig = options.options.configFilePath;
49
55
  if (typeof tsConfig === 'string') {
50
- return shared.createParsedCommandLine(ts, ts.sys, tsConfig).vueOptions;
56
+ return vue_typescript_2.tsShared.createParsedCommandLine(ts, ts.sys, tsConfig).vueOptions;
51
57
  }
52
58
  return {};
53
59
  }
54
60
  function getScriptSnapshot(fileName) {
55
- var _a, _b, _c;
56
61
  const script = scripts.get(fileName);
57
62
  if (script) {
58
63
  return script.scriptSnapshot;
@@ -63,7 +68,7 @@ _options, _host, _oldProgram, _configFileParsingDiagnostics) {
63
68
  const scriptSnapshot = ts.ScriptSnapshot.fromString(fileContent);
64
69
  scripts.set(fileName, {
65
70
  scriptSnapshot: scriptSnapshot,
66
- version: (_c = (_b = (_a = ts.sys).createHash) === null || _b === void 0 ? void 0 : _b.call(_a, fileContent)) !== null && _c !== void 0 ? _c : fileContent,
71
+ version: ts.sys.createHash?.(fileContent) ?? fileContent,
67
72
  });
68
73
  return scriptSnapshot;
69
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-tsc",
3
- "version": "0.33.1",
3
+ "version": "0.33.3-patch.1",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "bin",
@@ -16,11 +16,9 @@
16
16
  "vue-tsc": "./bin/vue-tsc.js"
17
17
  },
18
18
  "dependencies": {
19
- "@volar/shared": "0.33.1",
20
- "@volar/vue-typescript": "0.33.1"
19
+ "@volar/vue-typescript": "0.33.3"
21
20
  },
22
21
  "peerDependencies": {
23
22
  "typescript": "*"
24
- },
25
- "gitHead": "03eaf26e0b1259ffa2b5690168a2d6a8baa81cbc"
23
+ }
26
24
  }