Skip to content

Commit

Permalink
feat: allow passing array to experimentalModelPropName ignore setting
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Oct 13, 2022
1 parent 01610bb commit d2b50d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
38 changes: 25 additions & 13 deletions vue-language-tools/vue-language-core/src/generators/template.ts
Expand Up @@ -1779,22 +1779,34 @@ function getModelValuePropName(node: CompilerDOM.ElementNode, vueVersion: number
const tags = vueCompilerOptions.experimentalModelPropName[modelName];
for (const tag in tags) {
if (node.tag === tag || node.tag === hyphenate(tag)) {
const attrs = tags[tag];
if (typeof attrs === 'object') {
let failed = false;
for (const attr in attrs) {
const attrNode = node.props.find(prop => prop.type === CompilerDOM.NodeTypes.ATTRIBUTE && prop.name === attr) as CompilerDOM.AttributeNode | undefined;
if (!attrNode || attrNode.value?.content !== attrs[attr]) {
failed = true;
break;
const v = tags[tag];
if (typeof v === 'object') {
const arr = Array.isArray(v) ? v : [v];
for (const attrs of arr) {
let failed = false;
for (const attr in attrs) {
const attrNode = node.props.find(prop => prop.type === CompilerDOM.NodeTypes.ATTRIBUTE && prop.name === attr) as CompilerDOM.AttributeNode | undefined;
if (!attrNode || attrNode.value?.content !== attrs[attr]) {
failed = true;
break;
}
}
if (!failed) {
// all match
return modelName || undefined;
}
}
if (!failed) {
// all match
return modelName || undefined;
}
}
else if (attrs === true) {
}
}
}

for (const modelName in vueCompilerOptions.experimentalModelPropName) {
const tags = vueCompilerOptions.experimentalModelPropName[modelName];
for (const tag in tags) {
if (node.tag === tag || node.tag === hyphenate(tag)) {
const attrs = tags[tag];
if (attrs === true) {
return modelName || undefined;
}
}
Expand Down
2 changes: 1 addition & 1 deletion vue-language-tools/vue-language-core/src/types.ts
Expand Up @@ -29,7 +29,7 @@ export interface ResolvedVueCompilerOptions {
experimentalRuntimeMode: 'runtime-dom' | 'runtime-uni-app';
experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
experimentalRfc436: boolean;
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string>>>;
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
}

export type VueLanguagePlugin = (ctx: {
Expand Down

0 comments on commit d2b50d2

Please sign in to comment.