-
Notifications
You must be signed in to change notification settings - Fork 394
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
fix(ssr-compiler): define setters for reflected attributes #4611
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,20 +172,29 @@ export class LightningElement implements PropsAvailableAtConstruction { | |
return (this.__classList = new ClassList(this)); | ||
} | ||
|
||
getAttribute(attrName: string): string | null { | ||
return this.__attrs[attrName] ?? null; | ||
#setAttribute(attrName: string, attrValue: string | null): void { | ||
ekashida marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.__attrs[attrName] = attrValue; | ||
} | ||
|
||
setAttribute(attrName: string, value: string | null): void { | ||
this.__attrs[attrName] = String(value); | ||
setAttribute(attrName: string, attrValue: unknown): void { | ||
this.#setAttribute(attrName, String(attrValue)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit confusing to have two methods named |
||
} | ||
|
||
hasAttribute(attrName: string): boolean { | ||
return Boolean(this.__attrs && attrName in this.__attrs); | ||
getAttribute(attrName: unknown): string | null { | ||
if (this.hasAttribute(attrName)) { | ||
return this.__attrs[attrName as string]; | ||
} | ||
return null; | ||
} | ||
|
||
hasAttribute(attrName: unknown): boolean { | ||
return typeof attrName === 'string' && typeof this.__attrs[attrName] === 'string'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fact that we have to check for strings here because we don't ensure that the values in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, so the reason for this is that we can't call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
removeAttribute(attrName: string): void { | ||
this.__attrs[attrName] = null; | ||
if (this.hasAttribute(attrName)) { | ||
this.#setAttribute(attrName, null); | ||
ekashida marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
addEventListener( | ||
|
@@ -299,11 +308,12 @@ export function* renderAttrs(attrs: Attributes) { | |
if (!attrs) { | ||
return; | ||
} | ||
for (const [key, val] of Object.entries(attrs)) { | ||
if (typeof val === 'string') { | ||
yield val === '' ? ` ${key}` : ` ${key}="${escapeAttrVal(val)}"`; | ||
} else if (val === null) { | ||
return ''; | ||
for (const attrName in attrs) { | ||
ekashida marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const attrVal = attrs[attrName]; | ||
if (typeof attrVal === 'string') { | ||
yield attrVal === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrVal)}"`; | ||
} else if (attrVal === null) { | ||
yield ''; | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would benefit from a code comment showing an example output. ASTs are hard to read...