Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove experimentalTemplateCompilerOptions #1991

Merged
merged 1 commit into from Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}