From 6b2653de3f7702c678f050fd08201b9f673bd7a4 Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Sun, 19 Apr 2026 02:36:23 +1000 Subject: [PATCH] fix(core/utils): register unquoted form for quoted enum-value dfns Authors sometimes write "value" with surrounding quotes to mirror WebIDL syntax. getDfnTitles() now also registers the unquoted form so webidl.js lookup and inline {{ EnumType/"value" }} refs can resolve to the user-provided dfn instead of auto-generating a duplicate. Closes #4615 --- src/core/utils.js | 12 +++++++ tests/spec/core/webidl-spec.js | 57 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/src/core/utils.js b/src/core/utils.js index d5e5914f7e..6f42efa33d 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -535,6 +535,18 @@ export function getDfnTitles(elem) { titleSet.add(normText); titleSet.delete(""); + // For enum-value dfns, authors often write "value" with surrounding + // quotes (mirroring WebIDL syntax). Register the unquoted form as well so that + // WebIDL lookups and {{ EnumType/"value" }} inline refs can find the dfn. + if ( + elem.dataset.dfnType === "enum-value" && + normText.startsWith('"') && + normText.endsWith('"') && + normText.length > 2 + ) { + titleSet.add(normText.slice(1, -1)); + } + // We could have done this with @data-lt (as the logic is same), but if // @data-lt was not present, we would end up using @data-local-lt as element's // id (in other words, we prefer textContent over @data-local-lt for dfn id) diff --git a/tests/spec/core/webidl-spec.js b/tests/spec/core/webidl-spec.js index 916d5c78ee..389ff41fe3 100644 --- a/tests/spec/core/webidl-spec.js +++ b/tests/spec/core/webidl-spec.js @@ -1048,6 +1048,63 @@ enum EnumBasic { ); expect(doc.getElementById("idl-def-enumbasic")).toBeTruthy(); }); + + it("links quoted enum value definitions to IDL", async () => { + // Authors sometimes write "value" with surrounding quotes to + // mirror WebIDL syntax. ReSpec must still match these dfns to the IDL + // enum member (which webidl2 reports without quotes). + const body = ` +
+          enum QuotedEnum {
+            "alpha",
+            "beta with spaces"
+          };
+        
+

+ "alpha" + "beta with spaces" +

+ + `; + const ops = makeStandardOps(null, body); + const doc = await makeRSDoc(ops); + + // The IDL should link to the user-provided dfns (no extra auto-generated dfns). + const alphaDfn = doc.getElementById("dom-quotedenum-alpha"); + expect(alphaDfn).withContext("dfn for alpha must exist").toBeTruthy(); + expect(alphaDfn.dataset.dfnType) + .withContext("dfn type must be enum-value") + .toBe("enum-value"); + + const betaDfn = doc.getElementById("dom-quotedenum-beta-with-spaces"); + expect(betaDfn) + .withContext("dfn for beta with spaces must exist") + .toBeTruthy(); + + // The IDL block must link to the user-provided dfns. + const idlBlock = doc.querySelector("pre.idl code"); + expect(idlBlock.querySelector("a[href='#dom-quotedenum-alpha']")) + .withContext("IDL block links alpha to user dfn") + .toBeTruthy(); + expect( + idlBlock.querySelector("a[href='#dom-quotedenum-beta-with-spaces']") + ) + .withContext("IDL block links beta-with-spaces to user dfn") + .toBeTruthy(); + + // Inline links should resolve too. + const linkTest = doc.getElementById("link-test"); + expect(linkTest.querySelector("a[href='#dom-quotedenum-alpha']")) + .withContext("inline link to alpha resolves") + .toBeTruthy(); + expect( + linkTest.querySelector("a[href='#dom-quotedenum-beta-with-spaces']") + ) + .withContext("inline link to beta with spaces resolves") + .toBeTruthy(); + }); }); it("should handle enumeration value definitions", () => {