Skip to content

Commit

Permalink
refactor: remove experimentalTemplateCompilerOptions (#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Oct 11, 2022
1 parent 079e9ba commit 935f53b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 49 deletions.
Expand Up @@ -75,14 +75,6 @@
],
"markdownDescription": "Run app in browser or uni-app"
},
"experimentalTemplateCompilerOptions": {
"type": "object",
"markdownDescription": "https://github.com/johnsoncodehk/volar/issues/576"
},
"experimentalTemplateCompilerOptionsRequirePath": {
"type": "string",
"markdownDescription": "https://github.com/johnsoncodehk/volar/issues/698"
},
"experimentalResolveStyleCssClasses": {
"enum": [
"scoped",
Expand Down
Expand Up @@ -8,19 +8,12 @@ interface Loc {
}
type Node = CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.ExpressionNode | CompilerDOM.AttributeNode | CompilerDOM.DirectiveNode;

const plugin: VueLanguagePlugin = ({ modules, vueCompilerOptions }) => {
const plugin: VueLanguagePlugin = ({ modules }) => {

return {

version: 1,

resolveTemplateCompilerOptions(options) {
return {
...options,
...vueCompilerOptions.experimentalTemplateCompilerOptions,
};
},

compileSFCTemplate(lang, template, options) {

if (lang === 'html') {
Expand Down
2 changes: 0 additions & 2 deletions vue-language-tools/vue-language-core/src/types.ts
Expand Up @@ -27,8 +27,6 @@ export interface ResolvedVueCompilerOptions {

// experimental
experimentalRuntimeMode: 'runtime-dom' | 'runtime-uni-app';
experimentalTemplateCompilerOptions: any;
experimentalTemplateCompilerOptionsRequirePath: string | undefined;
experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
experimentalRfc436: boolean;
}
Expand Down
34 changes: 3 additions & 31 deletions vue-language-tools/vue-language-core/src/utils/ts.ts
Expand Up @@ -47,7 +47,7 @@ function createParsedCommandLineBase(
extendsSet: Set<string>,
): ParsedCommandLine {

let baseVueOptions = {};
let vueOptions = {};
const folder = path.dirname(tsConfigPath);

extendsSet.add(tsConfigPath);
Expand All @@ -56,7 +56,7 @@ function createParsedCommandLineBase(
try {
const extendsPath = require.resolve(content.raw.extends, { paths: [folder] });
if (!extendsSet.has(extendsPath)) {
baseVueOptions = createParsedCommandLine(ts, parseConfigHost, extendsPath, extraFileExtensions, extendsSet).vueOptions;
vueOptions = createParsedCommandLine(ts, parseConfigHost, extendsPath, extraFileExtensions, extendsSet).vueOptions;
}
}
catch (error) {
Expand All @@ -66,10 +66,7 @@ function createParsedCommandLineBase(

return {
...content,
vueOptions: {
...baseVueOptions,
...resolveVueCompilerOptionsWorker(content.raw.vueCompilerOptions ?? {}, folder),
},
vueOptions,
};
}

Expand All @@ -95,32 +92,7 @@ export function resolveVueCompilerOptions(vueOptions: VueCompilerOptions): Resol

// experimental
experimentalRuntimeMode: vueOptions.experimentalRuntimeMode ?? 'runtime-dom',
experimentalTemplateCompilerOptions: vueOptions.experimentalTemplateCompilerOptions ?? {},
experimentalTemplateCompilerOptionsRequirePath: vueOptions.experimentalTemplateCompilerOptionsRequirePath ?? undefined,
experimentalResolveStyleCssClasses: vueOptions.experimentalResolveStyleCssClasses ?? 'scoped',
experimentalRfc436: vueOptions.experimentalRfc436 ?? false,
};
}

function resolveVueCompilerOptionsWorker(rawOptions: {
[key: string]: any,
experimentalTemplateCompilerOptionsRequirePath?: string,
}, rootPath: string) {

const result = { ...rawOptions };

let templateOptionsPath = rawOptions.experimentalTemplateCompilerOptionsRequirePath;
if (templateOptionsPath) {
if (!path.isAbsolute(templateOptionsPath)) {
templateOptionsPath = require.resolve(templateOptionsPath, { paths: [rootPath] });
}
try {
result.experimentalTemplateCompilerOptions = require(templateOptionsPath).default;
} catch (error) {
console.warn('Failed to require "experimentalTemplateCompilerOptionsRequirePath":', templateOptionsPath);
console.error(error);
}
}

return result;
}

0 comments on commit 935f53b

Please sign in to comment.