vue-tsc 0.35.2 → 0.37.0

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/bin/vue-tsc.js CHANGED
@@ -12,15 +12,15 @@ fs.readFileSync = (...args) => {
12
12
  // add *.vue files to allow extensions
13
13
  tsc = tsc.replace(
14
14
  `ts.supportedTSExtensions = [[".ts", ".tsx", ".d.ts"], [".cts", ".d.cts"], [".mts", ".d.mts"]];`,
15
- `ts.supportedTSExtensions = [[".ts", ".tsx", ".d.ts"], [".cts", ".d.cts"], [".mts", ".d.mts"], [".vue"]];`,
15
+ `ts.supportedTSExtensions = [[".ts", ".tsx", ".d.ts"], [".cts", ".d.cts"], [".mts", ".d.mts"], [".vue", ".md"]];`,
16
16
  );
17
17
  tsc = tsc.replace(
18
18
  `ts.supportedJSExtensions = [[".js", ".jsx"], [".mjs"], [".cjs"]];`,
19
- `ts.supportedJSExtensions = [[".js", ".jsx"], [".mjs"], [".cjs"], [".vue"]];`,
19
+ `ts.supportedJSExtensions = [[".js", ".jsx"], [".mjs"], [".cjs"], [".vue", ".md"]];`,
20
20
  );
21
21
  tsc = tsc.replace(
22
22
  `var allSupportedExtensions = [[".ts", ".tsx", ".d.ts", ".js", ".jsx"], [".cts", ".d.cts", ".cjs"], [".mts", ".d.mts", ".mjs"]];`,
23
- `var allSupportedExtensions = [[".ts", ".tsx", ".d.ts", ".js", ".jsx"], [".cts", ".d.cts", ".cjs"], [".mts", ".d.mts", ".mjs"], [".vue"]];`,
23
+ `var allSupportedExtensions = [[".ts", ".tsx", ".d.ts", ".js", ".jsx"], [".cts", ".d.cts", ".cjs"], [".mts", ".d.mts", ".mjs"], [".vue", ".md"]];`,
24
24
  );
25
25
 
26
26
  // proxy createProgram apis
@@ -32,6 +32,18 @@ fs.readFileSync = (...args) => {
32
32
  `function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) {`,
33
33
  `function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) { return require(${JSON.stringify(proxyPath)}).createProgramProxy(...arguments);`,
34
34
  );
35
+
36
+ // proxy tracing
37
+ tsc = tsc.replace(
38
+ `ts.startTracing = tracingEnabled.startTracing;`,
39
+ `ts.startTracing = require(${JSON.stringify(proxyPath)}).loadTsLib().startTracing;`,
40
+ );
41
+
42
+ tsc = tsc.replace(
43
+ `ts.dumpTracingLegend = tracingEnabled.dumpLegend;`,
44
+ `ts.dumpTracingLegend = require(${JSON.stringify(proxyPath)}).loadTsLib().dumpTracingLegend;`,
45
+ );
46
+
35
47
  return tsc;
36
48
  }
37
49
  return readFileSync(...args);
package/out/apis.js CHANGED
@@ -56,37 +56,38 @@ function register(ts, context) {
56
56
  }
57
57
  // transform
58
58
  function transformDiagnostics(diagnostics) {
59
- var _a, _b, _c;
59
+ var _a, _b, _c, _d, _e, _f, _g, _h;
60
60
  const result = [];
61
61
  for (const diagnostic of diagnostics) {
62
62
  if (diagnostic.file !== undefined
63
63
  && diagnostic.start !== undefined
64
64
  && diagnostic.length !== undefined) {
65
+ let founded = false;
65
66
  for (const tsOrVueLoc of context.vueFiles.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, data => !!data.capabilities.diagnostic)) {
66
67
  if (!((_b = (_a = context.vueLsHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, tsOrVueLoc.fileName)))
67
68
  continue;
68
- let file = tsOrVueLoc.fileName === diagnostic.file.fileName
69
- ? diagnostic.file
70
- : undefined;
71
- if (!file) {
72
- let docText = (_c = tsOrVueLoc.mapped) === null || _c === void 0 ? void 0 : _c.vueFile.getContent();
73
- if (docText === undefined) {
74
- const snapshot = context.vueLsHost.getScriptSnapshot(tsOrVueLoc.fileName);
75
- if (snapshot) {
76
- docText = snapshot.getText(0, snapshot.getLength());
77
- }
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;
78
86
  }
79
- else {
80
- file = ts.createSourceFile(tsOrVueLoc.fileName, docText, tsOrVueLoc.fileName.endsWith('.vue') ? ts.ScriptTarget.JSON : ts.ScriptTarget.Latest);
87
+ if (founded) {
88
+ break;
81
89
  }
82
90
  }
83
- const newDiagnostic = Object.assign(Object.assign({}, diagnostic), { file, start: tsOrVueLoc.range.start, length: tsOrVueLoc.range.end - tsOrVueLoc.range.start });
84
- const relatedInformation = diagnostic.relatedInformation;
85
- if (relatedInformation) {
86
- newDiagnostic.relatedInformation = transformDiagnostics(relatedInformation);
87
- }
88
- result.push(newDiagnostic);
89
- break;
90
91
  }
91
92
  }
92
93
  else if (diagnostic.file === undefined) {
@@ -94,6 +95,29 @@ function register(ts, context) {
94
95
  }
95
96
  }
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') || fileName.endsWith('.md') ? 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
+ }
97
121
  }
98
122
  }
99
123
  exports.register = register;
package/out/proxy.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import * as ts from 'typescript/lib/tsserverlibrary';
2
2
  export declare function createProgramProxy(options: ts.CreateProgramOptions, // rootNamesOrOptions: readonly string[] | CreateProgramOptions,
3
3
  _options?: ts.CompilerOptions, _host?: ts.CompilerHost, _oldProgram?: ts.Program, _configFileParsingDiagnostics?: readonly ts.Diagnostic[]): void | ts.Program;
4
+ export declare function loadTsLib(): typeof ts;
package/out/proxy.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createProgramProxy = void 0;
3
+ exports.loadTsLib = exports.createProgramProxy = void 0;
4
4
  const ts = require("typescript/lib/tsserverlibrary");
5
5
  const apis = require("./apis");
6
6
  const vue_typescript_1 = require("@volar/vue-typescript");
@@ -29,20 +29,18 @@ _options, _host, _oldProgram, _configFileParsingDiagnostics) {
29
29
  }, getProjectReferences: () => options.projectReferences });
30
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
31
  typescript: ts,
32
- baseCssModuleType: 'any',
33
- getCssClasses: () => ({}),
34
32
  vueLsHost: vueLsHost,
35
33
  isVueTsc: true,
36
34
  });
37
35
  tsRuntime.update(); // must update before getProgram() to update virtual scripts
38
- const tsProgram = tsRuntime.getTsLs().getProgram();
39
- if (!tsProgram)
40
- throw '!tsProgram';
41
36
  const proxyApis = apis.register(ts, tsRuntime);
42
- const program = new Proxy(tsProgram, {
43
- get: (target, property) => {
37
+ const program = new Proxy({}, {
38
+ get: (_, property) => {
44
39
  tsRuntime.update();
45
- return proxyApis[property] || target[property];
40
+ if (property in proxyApis) {
41
+ return proxyApis[property];
42
+ }
43
+ return tsRuntime.getTsLs().getProgram()[property];
46
44
  },
47
45
  });
48
46
  program.__VLS_tsRuntime = tsRuntime;
@@ -92,6 +90,10 @@ _options, _host, _oldProgram, _configFileParsingDiagnostics) {
92
90
  }
93
91
  }
94
92
  exports.createProgramProxy = createProgramProxy;
93
+ function loadTsLib() {
94
+ return ts;
95
+ }
96
+ exports.loadTsLib = loadTsLib;
95
97
  function doThrow(msg) {
96
98
  console.error(msg);
97
99
  throw msg;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-tsc",
3
- "version": "0.35.2",
3
+ "version": "0.37.0",
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.35.2"
19
+ "@volar/vue-typescript": "0.37.0"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "typescript": "*"
23
23
  },
24
- "gitHead": "6cfa0323e56daa20ddd38b9b396aa4d027c7bfc1"
24
+ "gitHead": "e72a5db00ee63b1ebe239b22733cfc93e304fae6"
25
25
  }