-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
exempt strings from being treated as known booleans unless empty or equal to name #46
Conversation
…y or equal to name
@wooorm here you go, I've added a TODO comment above an existing test as it appears to me that the behavior in question is not justified and it necessitates additional logic that could otherwise be dropped. |
test/attribute.js
Outdated
@@ -140,6 +140,7 @@ test('`element` attributes', async (t) => { | |||
} | |||
) | |||
|
|||
// TODO: why? "hidden" is a valid value for the `hidden` attribute |
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.
Because hidden
looks better? Because hidden="hidden"
is longer and superfluous? Because it’s how people often write HTML?
This package is also used in combination of minifiers / pritifyers. So it’s not solely about what “works”.
🤔 I’d say this comment can be removed?
The thing is, why would it explicitly be disallowed?
Sure, people write hidden without value and that's still allowed and
possible.
But explicitly writing 'hidden="hidden"' is currently automatically
minified. Now, if I choose to create a custom element that has different
semantics I might rely on that value being present and with this util it's
automatically removed/"minified".
…On Mon, Dec 9, 2024, 12:28 Titus ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/attribute.js
<#46 (comment)>
:
> @@ -140,6 +140,7 @@ test('`element` attributes', async (t) => {
}
)
+ // TODO: why? "hidden" is a valid value for the `hidden` attribute
Because hidden looks better? Because hidden="hidden" is longer and
superfluous? Because it’s how people often write HTML?
This package is also used in combination of minifiers / pritifyers. So
it’s not solely about what “works”.
🤔 I’d say this comment can be removed?
—
Reply to this email directly, view it on GitHub
<#46 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACOHZTRRIP5GKTNTUWPY2ML2EV5ENAVCNFSM6AAAAABTHFSK3CVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDIOBYGUZDAMBRGI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
On why: because the tools are all made to help people that work with ASTs (plugins). There’s a line between CSTs and ASTs. ASTs are easier to work with. You could argue that it doesn’t need to happen here, we can have that conversation: there might indeed be no need. But this specific argument about differentiating between |
Hmm, in the case of If a CE author attaches different semantics to well known attributes (that are not defined as global) transforming that correctly requires a context (namely the context of the CE) which a CST util would care about, but an AST transformer does not because it sort of does not care about other leafs and branches of the tree? If so, then why does this AST transformer care about property information at all? Shouldn't it just take the given value and attach it unchanged? Anyway, I'll remove the comment so this can be merged, would be happy to learn more about this though, if you have any pointers or such. |
So a CST cares about everything. const d = document.createElement('div')
d.innerHTML = '<div hidden="asd">'
d.children[0].getAttribute('hidden') // 'asd'
d.children[0].hidden // true
d.innerHTML // '<div hidden="asd"></div>'
d.innerHTML = '<d-v hidden="asd">'
d.children[0].getAttribute('hidden') // 'asd'
d.children[0].hidden // true
d.innerHTML // '<d-v hidden="asd"></d-v>' Some parts of HTML persist things, some don’t. Persist all information makes it rather hard to work with. Dropping info makes it easier to work with. Dropping whether an original HTML author wrote A JS user could differentiate with |
This comment has been minimized.
This comment has been minimized.
Thanks, released in |
Initial checklist
Description of changes
This change prevents treating string attributes whose name is a well known boolean (or overloaded boolean) as a boolean if their values are
This is done to enable e.g. custom element to re-use those well known names with values that differ from their well known counterparts.
closes #45