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

Analyzer (stencil): default values not being represented in attributes #285

Open
2 tasks done
Kai-Richardson opened this issue Dec 5, 2024 · 2 comments · May be fixed by #286
Open
2 tasks done

Analyzer (stencil): default values not being represented in attributes #285

Kai-Richardson opened this issue Dec 5, 2024 · 2 comments · May be fixed by #286

Comments

@Kai-Richardson
Copy link

Checklist

  • Did you run the analyzer with the --dev flag to get more information?
  • Did you create a minimal reproduction in the playground?

Reproduction Link

Expected behavior
Essentially, the linked attributes to a member are missing the default field when in the stencil mode.
This is allowed per schema (see below), presents in other modes, and is used by some toolings (storybook).

For example, in the reproduction link above, we have the following for @Prop() hasDefault: boolean = false;

image image

This is not the case for other modes, such as litelement (the default reproduction):
image

Relevant Schema

Attributes:

image

image

Members:

image

image

@thepassle
Copy link
Member

Would you be willing to create a PR to fix this? It should be straightforward enough to do, you can find the logic for it here:

const fieldName = property?.name?.text;
const attrNameFromDecorator = property?.modifiers?.[0]?.expression?.arguments?.[0]?.properties?.find(prop => prop?.name?.getText() === 'attribute')?.initializer?.text;
const attrName = attrNameFromDecorator || toKebabCase(property?.name?.text);
const reflects = property?.modifiers?.[0]?.expression?.arguments?.[0]?.properties?.find(prop => prop?.name?.getText() === 'reflects')?.initializer?.getText?.() === 'true';
const member = currClass?.members?.find(mem => mem?.name === fieldName);
if(reflects) {
member.reflects = true;
member.attribute = attrName;
}
if(!currClass.attributes) currClass.attributes = [];
const hasType = !!property?.type?.getText?.();
currClass.attributes.push({
name: attrName,
fieldName,
...(hasType ? {
type: { text: property?.type?.getText?.() }
} : {})
})
});

and you should be able to reuse the handleDefaultValue function from here:

export function handleDefaultValue(doc, node, expression) {

@Kai-Richardson
Copy link
Author

@thepassle: Would you be willing to create a PR to fix this?

I've made the PR @ #286.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants