vue-tsc 0.33.2 → 0.33.4

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,
@@ -13,10 +12,9 @@ function register(ts, { vueDocuments, templateTsLsRaw, scriptTsLsRaw, templateTs
13
12
  getBindAndCheckDiagnostics,
14
13
  };
15
14
  function getRootFileNames() {
16
- var _a, _b, _c, _d;
17
15
  const set = new Set([
18
- ...(_b = (_a = getProgram('script')) === null || _a === void 0 ? void 0 : _a.getRootFileNames().filter(fileName => { var _a; return (_a = scriptTsHost.fileExists) === null || _a === void 0 ? void 0 : _a.call(scriptTsHost, fileName); })) !== null && _b !== void 0 ? _b : [],
19
- ...(_d = (_c = getProgram('template')) === null || _c === void 0 ? void 0 : _c.getRootFileNames().filter(fileName => { var _a; return (_a = templateTsHost === null || templateTsHost === void 0 ? void 0 : templateTsHost.fileExists) === null || _a === void 0 ? void 0 : _a.call(templateTsHost, fileName); })) !== null && _d !== void 0 ? _d : [],
16
+ ...getProgram('script')?.getRootFileNames().filter(fileName => context.getTsLsHost('script').fileExists?.(fileName)) ?? [],
17
+ ...getProgram('template')?.getRootFileNames().filter(fileName => context.getTsLsHost('template')?.fileExists?.(fileName)) ?? [],
20
18
  ]);
21
19
  return [...set.values()];
22
20
  }
@@ -33,76 +31,71 @@ function register(ts, { vueDocuments, templateTsLsRaw, scriptTsLsRaw, templateTs
33
31
  }
34
32
  function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
35
33
  if (sourceFile) {
36
- const sourceMap = vueDocuments.fromEmbeddedDocumentUri('script', shared.fsPathToUri(sourceFile.fileName));
37
- const vueDocument = sourceMap ? vueDocuments.get(sourceMap.sourceDocument.uri) : undefined;
38
- if (vueDocument) {
34
+ const maped = context.vueFiles.fromEmbeddedFileName('script', sourceFile.fileName);
35
+ if (maped) {
39
36
  let results = [];
40
- const sourceMaps = vueDocument.getSourceMaps();
41
- for (const sourceMap of sourceMaps) {
42
- 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)
43
40
  continue;
44
- const program = getProgram(sourceMap.lsType);
45
- const embeddedSourceFile = program === null || program === void 0 ? void 0 : program.getSourceFile(shared.uriToFsPath(sourceMap.mappedDocument.uri));
41
+ const program = getProgram(embedded.file.lsType);
42
+ const embeddedSourceFile = program?.getSourceFile(embedded.file.fileName);
46
43
  if (embeddedSourceFile) {
47
- const errors = transformDiagnostics(sourceMap.lsType, program[api](embeddedSourceFile, cancellationToken));
44
+ const errors = transformDiagnostics(embedded.file.lsType, program?.[api](embeddedSourceFile, cancellationToken) ?? []);
48
45
  results = results.concat(errors);
49
46
  }
50
47
  }
51
48
  return results;
52
49
  }
53
50
  else {
54
- return getProgram('script')[api](sourceFile, cancellationToken);
51
+ return getProgram('script')?.[api](sourceFile, cancellationToken) ?? [];
55
52
  }
56
53
  }
57
- 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();
58
55
  }
59
56
  function getGlobalDiagnostics(cancellationToken) {
60
- return lsTypes.map(lsType => { var _a, _b; return transformDiagnostics(lsType, (_b = (_a = getProgram(lsType)) === null || _a === void 0 ? void 0 : _a.getGlobalDiagnostics(cancellationToken)) !== null && _b !== void 0 ? _b : []); }).flat();
57
+ return lsTypes.map(lsType => transformDiagnostics(lsType, getProgram(lsType)?.getGlobalDiagnostics(cancellationToken) ?? [])).flat();
61
58
  }
62
59
  function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
63
- var _a, _b, _c;
64
- const scriptResult = getProgram('script').emit(targetSourceFile, ((_a = vueHost.writeFile) !== null && _a !== void 0 ? _a : ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
65
- const templateResult = (_b = getProgram('template')) === null || _b === void 0 ? void 0 : _b.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);
66
62
  return {
67
63
  emitSkipped: scriptResult.emitSkipped,
68
64
  emittedFiles: scriptResult.emittedFiles,
69
65
  diagnostics: [
70
66
  ...transformDiagnostics('script', scriptResult.diagnostics),
71
- ...transformDiagnostics('template', (_c = templateResult === null || templateResult === void 0 ? void 0 : templateResult.diagnostics) !== null && _c !== void 0 ? _c : []),
67
+ ...transformDiagnostics('template', templateResult?.diagnostics ?? []),
72
68
  ],
73
69
  };
74
70
  }
75
71
  function getProgram(lsType) {
76
- var _a;
77
- return (_a = (lsType === 'script' ? scriptTsLsRaw : templateTsLsRaw)) === null || _a === void 0 ? void 0 : _a.getProgram();
72
+ return context.getTsLs(lsType)?.getProgram();
78
73
  }
79
74
  // transform
80
75
  function transformDiagnostics(lsType, diagnostics) {
81
- var _a, _b;
82
76
  const result = [];
83
77
  for (const diagnostic of diagnostics) {
84
78
  if (diagnostic.file !== undefined
85
79
  && diagnostic.start !== undefined
86
80
  && diagnostic.length !== undefined) {
87
- const fileName = shared.normalizeFileName(diagnostic.file.fileName);
88
- for (const tsOrVueLoc of vueDocuments.fromEmbeddedLocation(lsType, shared.fsPathToUri(fileName), diagnostic.start, diagnostic.start + diagnostic.length, data => !!data.capabilities.diagnostic)) {
89
- 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))
90
83
  continue;
91
- if (tsOrVueLoc.type === 'source-ts' && lsType !== 'script')
84
+ if (!tsOrVueLoc.maped && lsType !== 'script')
92
85
  continue;
93
- let file = shared.uriToFsPath(tsOrVueLoc.uri) === fileName
86
+ let file = tsOrVueLoc.fileName === diagnostic.file.fileName
94
87
  ? diagnostic.file
95
88
  : undefined;
96
89
  if (!file) {
97
- let docText = (_b = tsOrVueLoc.sourceMap) === null || _b === void 0 ? void 0 : _b.sourceDocument.getText();
90
+ let docText = tsOrVueLoc.maped?.vueFile.getContent();
98
91
  if (docText === undefined) {
99
- const snapshot = vueHost.getScriptSnapshot(shared.uriToFsPath(tsOrVueLoc.uri));
92
+ const snapshot = context.vueLsHost.getScriptSnapshot(tsOrVueLoc.fileName);
100
93
  if (snapshot) {
101
94
  docText = snapshot.getText(0, snapshot.getLength());
102
95
  }
103
96
  }
104
- if (docText !== undefined) {
105
- 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);
106
99
  }
107
100
  }
108
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.2",
3
+ "version": "0.33.4",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "bin",
@@ -16,11 +16,10 @@
16
16
  "vue-tsc": "./bin/vue-tsc.js"
17
17
  },
18
18
  "dependencies": {
19
- "@volar/shared": "0.33.2",
20
- "@volar/vue-typescript": "0.33.2"
19
+ "@volar/vue-typescript": "0.33.4"
21
20
  },
22
21
  "peerDependencies": {
23
22
  "typescript": "*"
24
23
  },
25
- "gitHead": "31edc9e4c229643fd0594896c6ec63a64a9c1e30"
24
+ "gitHead": "6e3d7e0db6ff17435b3cabc0d590e75899ef353c"
26
25
  }