Skip to content

Commit

Permalink
refactor(vue-tsc): experimentalTscProgramCallbacks -> hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Dec 18, 2022
1 parent 1acf23c commit a66ee36
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
Expand Up @@ -107,7 +107,7 @@
},
"markdownDescription": "https://github.com/johnsoncodehk/volar/issues/1969"
},
"experimentalTscProgramCallbacks": {
"hooks": {
"type": "array",
"markdownDescription": "https://github.com/johnsoncodehk/volar/pull/2217"
}
Expand Down
1 change: 1 addition & 0 deletions vue-language-tools/vue-language-core/src/types.ts
Expand Up @@ -24,6 +24,7 @@ export interface ResolvedVueCompilerOptions {
htmlAttributes: string[];
optionsWrapper: [string, string] | [];
plugins: string[];
hooks: string[];
narrowingTypesInInlineHandlers: boolean;

// experimental
Expand Down
1 change: 1 addition & 0 deletions vue-language-tools/vue-language-core/src/utils/ts.ts
Expand Up @@ -135,6 +135,7 @@ export function resolveVueCompilerOptions(vueOptions: VueCompilerOptions): Resol
),
narrowingTypesInInlineHandlers: vueOptions.narrowingTypesInInlineHandlers ?? false,
plugins: vueOptions.plugins ?? [],
hooks: vueOptions.hooks ?? [],

// experimental
experimentalResolveStyleCssClasses: vueOptions.experimentalResolveStyleCssClasses ?? 'scoped',
Expand Down
2 changes: 1 addition & 1 deletion vue-language-tools/vue-tsc/bin/vue-tsc.js
Expand Up @@ -39,7 +39,7 @@ fs.readFileSync = (...args) => {
require(tscPath);
}
catch (err) {
if (err === 'tscProgramCallback') {
if (err === 'hook') {
state.lastTscProgramCallback.worker.then(main);
}
else {
Expand Down
8 changes: 4 additions & 4 deletions vue-language-tools/vue-tsc/src/index.ts
Expand Up @@ -135,18 +135,18 @@ export function createProgram(
}

const vueCompilerOptions = program.__vue.languageServiceHost.getVueCompilationSettings();
if (vueCompilerOptions.experimentalTscProgramCallbacks) {
if (vueCompilerOptions.hooks) {
const index = (state.lastTscProgramCallback?.index ?? -1) + 1;
if (index < vueCompilerOptions.experimentalTscProgramCallbacks.length) {
const cbPath = vueCompilerOptions.experimentalTscProgramCallbacks[index];
if (index < vueCompilerOptions.hooks.length) {
const cbPath = vueCompilerOptions.hooks[index];
const dir = program.__vue.languageServiceHost.getCurrentDirectory();
const cb = require(require.resolve(cbPath, { paths: [dir] }));
state.lastTscProgramCallback = {
program,
index,
worker: (async () => await cb(program))(),
};
throw 'tscProgramCallback';
throw 'hook';
}
}

Expand Down

0 comments on commit a66ee36

Please sign in to comment.