Skip to content

Commit 825945a

Browse files
refactor(html): decode the script type without guarding on the reference
`decodeEntities` opens with the same `indexOf("&")` early-out, so the guard scanned for the ampersand twice on a value that has one and saved only a call on a value that does not. The printer's attribute loop keeps its guard because `hasReference` is computed once and reused by several decisions there; these two sites have no such reuse.
1 parent 2a65a95 commit 825945a

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

‎lib/html/syntax.js‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10068,9 +10068,9 @@ const _isRedundantAttribute = (markers, defaults, tagName, name, value) => {
1006810068
// `<script type>`: only a spelling that names JavaScript, which is what the
1006910069
// element already runs. `module` and the empty spelling say something.
1007010070
if (tagName === "script" && name === "type") {
10071-
const type = value.includes("&")
10072-
? _asciiLowerCase(_asciiTrim(decodeEntities(value, true)))
10073-
: lowered;
10071+
// Read the way `_scriptType` reads it, or the two disagree about which
10072+
// `<script>` this is and the body's handler and this one part ways.
10073+
const type = _asciiLowerCase(_asciiTrim(decodeEntities(value, true)));
1007410074
return (
1007510075
type !== "" && type !== "module" && JAVASCRIPT_SCRIPT_TYPES.has(type)
1007610076
);
@@ -10450,12 +10450,9 @@ const _rewriteAttributeValue = (element, name, raw, viewport, enumeratedOn) => {
1045010450
const _scriptType = (path, element) => {
1045110451
for (const attribute of path.attributes(element)) {
1045210452
if (attribute.name === "type") {
10453-
const raw = attribute.value;
1045410453
// The value the spec matches is the one the parser read, so a reference
1045510454
// is decoded first: `text&#47;javascript` runs, it is not a data block.
10456-
return _asciiLowerCase(
10457-
_asciiTrim(raw.includes("&") ? decodeEntities(raw, true) : raw)
10458-
);
10455+
return _asciiLowerCase(_asciiTrim(decodeEntities(attribute.value, true)));
1045910456
}
1046010457
}
1046110458
return "";

0 commit comments

Comments
 (0)