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

[feat] improve attributes transform semantics to match hbs AST #695

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lifeart
Copy link

@lifeart lifeart commented Jan 23, 2024

Handlebars AST attribute representation: (array of elements)

image

In scope of this PR we matching attributes to hbs semantics, where it's represented as array of key-value pairs, instead of record. It gives us more flexibility in syntaxes and reduce potential fail-cases because attribute name is explicitly string.

And getting rid of An object literal cannot have multiple properties with the same name typescript error.

- export declare function applyAttributes(element: Element, attrs: Record<string, AttrValue>): void;
+ export declare function applyAttributes(element: Element, attrs: Array<[string, AttrValue]>): void;

Resolves: #693

Note, we not getting DX worse, because template-lint has rule to warn about duplicated attributes: https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-duplicate-attributes.md


Sidenote:

It seems we could have autocomoplete/attibutes validation if replace

export declare function applyAttributes(element: Element, attrs: Array<[string, AttrValue]>): void;

With

export declare function applyAttributes<T extends Element, K extends keyof T>(element: T, attrs: Array<[K, T[K] | SafeString]>): void;
image image

ts playground

@lifeart lifeart changed the title [feat] improve attributes ast semantics to match hbs [feat] improve attributes transform semantics to match hbs AST Jan 23, 2024
@lifeart lifeart force-pushed the allow-hbs-like-attributes-semantics branch from 040d6ed to 2ec5e13 Compare January 23, 2024 04:29
@patricklx
Copy link
Contributor

patricklx commented Jan 29, 2024

this is also beeing worked on in #663, i mean the attributes autocomoplete/validation

@lifeart lifeart force-pushed the allow-hbs-like-attributes-semantics branch 5 times, most recently from 4682ce9 to eef8d4b Compare February 2, 2024 13:29
@lifeart lifeart force-pushed the allow-hbs-like-attributes-semantics branch from eef8d4b to a0be4c7 Compare February 21, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow attributes duplication on element
2 participants