Skip to content

Commit

Permalink
fix: component props completion order incorrect
Browse files Browse the repository at this point in the history
close #1972
  • Loading branch information
johnsoncodehk committed Oct 11, 2022
1 parent 761f386 commit 9cfd79e
Showing 1 changed file with 10 additions and 8 deletions.
Expand Up @@ -477,20 +477,21 @@ export default function useVueTemplateLanguagePlugin<T extends ReturnType<typeof
provideAttributes: (tag) => {

const globalProps = checkGlobalAttrs(context.typescript.module, context.typescript.languageService, vueSourceFile.fileName);
const props = checkPropsOfTag(context.typescript.module, context.typescript.languageService, vueSourceFile, tag);
const props = new Set(checkPropsOfTag(context.typescript.module, context.typescript.languageService, vueSourceFile, tag));
const events = checkEventsOfTag(context.typescript.module, context.typescript.languageService, vueSourceFile, tag);
const attributes: html.IAttributeData[] = [];

for (const prop of [...props, ...globalProps]) {

const isGlobal = !props.has(prop);
const name = attrNameCasing === AttrNameCasing.Camel ? prop : hyphenate(prop);

if (hyphenate(name).startsWith('on-')) {

const propNameBase = name.startsWith('on-')
? name.slice('on-'.length)
: (name['on'.length].toLowerCase() + name.slice('onX'.length));
const propKey = createInternalItemId('componentEvent', [tag, propNameBase]);
const propKey = createInternalItemId('componentEvent', [isGlobal ? '*' : tag, propNameBase]);

attributes.push(
{
Expand All @@ -506,7 +507,7 @@ export default function useVueTemplateLanguagePlugin<T extends ReturnType<typeof
else {

const propName = name;
const propKey = createInternalItemId('componentProp', [tag, propName]);
const propKey = createInternalItemId('componentProp', [isGlobal ? '*' : tag, propName]);

attributes.push(
{
Expand Down Expand Up @@ -540,23 +541,24 @@ export default function useVueTemplateLanguagePlugin<T extends ReturnType<typeof
});
}

const models: string[] = [];
const models: [boolean, string][] = [];

for (const prop of [...props, ...globalProps]) {
if (prop.startsWith('onUpdate:')) {
models.push(prop.substring('onUpdate:'.length));
const isGlobal = !props.has(prop);
models.push([isGlobal, prop.substring('onUpdate:'.length)]);
}
}
for (const event of events) {
if (event.startsWith('update:')) {
models.push(event.substring('update:'.length));
models.push([false, event.substring('update:'.length)]);
}
}

for (const model of models) {
for (const [isGlobal, model] of models) {

const name = attrNameCasing === AttrNameCasing.Camel ? model : hyphenate(model);
const propKey = createInternalItemId('componentProp', [tag, name]);
const propKey = createInternalItemId('componentProp', [isGlobal ? '*' : tag, name]);

attributes.push({
name: 'v-model:' + name,
Expand Down

0 comments on commit 9cfd79e

Please sign in to comment.