Skip to content

Commit

Permalink
feat(vue-tsc): support for TS v5
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Nov 8, 2022
1 parent 019417a commit fd3017a
Showing 1 changed file with 19 additions and 33 deletions.
52 changes: 19 additions & 33 deletions vue-language-tools/vue-tsc/bin/vue-tsc.js
Expand Up @@ -9,41 +9,27 @@ fs.readFileSync = (...args) => {
if (args[0] === tscPath) {
let tsc = readFileSync(...args);

// add *.vue files to allow extensions
tsc = tsc.replace(
`ts.supportedTSExtensions = [[".ts", ".tsx", ".d.ts"], [".cts", ".d.cts"], [".mts", ".d.mts"]];`,
// `ts.supportedTSExtensions = [[".ts", ".tsx", ".d.ts"], [".cts", ".d.cts"], [".mts", ".d.mts"], [".vue", ".md", ".html"]];`,
`ts.supportedTSExtensions = [[".ts", ".tsx", ".d.ts"], [".cts", ".d.cts"], [".mts", ".d.mts"], [".vue"]];`,
);
tsc = tsc.replace(
`ts.supportedJSExtensions = [[".js", ".jsx"], [".mjs"], [".cjs"]];`,
// `ts.supportedJSExtensions = [[".js", ".jsx"], [".mjs"], [".cjs"], [".vue", ".md", ".html"]];`,
`ts.supportedJSExtensions = [[".js", ".jsx"], [".mjs"], [".cjs"], [".vue"]];`,
);
tsc = tsc.replace(
`var allSupportedExtensions = [[".ts", ".tsx", ".d.ts", ".js", ".jsx"], [".cts", ".d.cts", ".cjs"], [".mts", ".d.mts", ".mjs"]];`,
// `var allSupportedExtensions = [[".ts", ".tsx", ".d.ts", ".js", ".jsx"], [".cts", ".d.cts", ".cjs"], [".mts", ".d.mts", ".mjs"], [".vue", ".md", ".html"]];`,
`var allSupportedExtensions = [[".ts", ".tsx", ".d.ts", ".js", ".jsx"], [".cts", ".d.cts", ".cjs"], [".mts", ".d.mts", ".mjs"], [".vue"]];`,
);

// proxy createProgram apis
tsc = tsc.replace(
`function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) {`,
`function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) { return require(${JSON.stringify(proxyPath)}).createProgramProxy(...arguments);`,
);

// proxy tracing
tsc = tsc.replace(
`ts.startTracing = tracingEnabled.startTracing;`,
`ts.startTracing = require(${JSON.stringify(proxyPath)}).loadTsLib().startTracing;`,
);

tsc = tsc.replace(
`ts.dumpTracingLegend = tracingEnabled.dumpLegend;`,
`ts.dumpTracingLegend = require(${JSON.stringify(proxyPath)}).loadTsLib().dumpTracingLegend;`,
);
// add *.vue files to allow extensions
tryReplace(/supportedTSExtensions = .*(?=;)/, s => s + '.concat([[".vue"]])');
tryReplace(/supportedJSExtensions = .*(?=;)/, s => s + '.concat([[".vue"]])');
tryReplace(/allSupportedExtensions = .*(?=;)/, s => s + '.concat([[".vue"]])');

// proxy startTracing, dumpTracingLegend
tryReplace(/ = tracingEnabled\./g, ` = require(${JSON.stringify(proxyPath)}).loadTsLib().`);

// proxy createProgram apis
tryReplace(/function createProgram\(.+\) {/, s => s + ` return require(${JSON.stringify(proxyPath)}).createProgramProxy(...arguments);`);

return tsc;

function tryReplace(search, replace) {
const before = tsc;
tsc = tsc.replace(search, replace);
const after = tsc;
if (after === before) {
throw 'Search string not found: ' + JSON.stringify(search.toString());
}
}
}
return readFileSync(...args);
};
Expand Down

0 comments on commit fd3017a

Please sign in to comment.