Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
feat(core/dfn): add support for task source types (speced#3717)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres authored Jul 29, 2021
1 parent 769abf5 commit dcbebf9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/dfn.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ function computeType(dfn, linkingText) {
case slotRegex.test(linkingText):
type = processAsInternalSlot(linkingText, dfn);
break;

// A definition that ends with "task source" is a "task-source"...
case /\b task source$/i.test(linkingText):
type = "task-source";
processAsTaskSource(dfn);
break;
}

// Derive closest type
Expand All @@ -108,6 +114,13 @@ function computeType(dfn, linkingText) {
// But other modules may end up adding a type (e.g., the WebIDL module)
}

function processAsTaskSource(dfn) {
// Task sources are exported by default.
if (!dfn.matches(".no-export, [data-noexport]")) {
dfn.dataset.export = "";
}
}

// Deal with export/no export
function computeExport(dfn) {
switch (true) {
Expand Down
53 changes: 53 additions & 0 deletions tests/spec/core/dfn-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,59 @@ describe("Core — Definitions", () => {
}
});

it("automatically identifies task sources and exports them by default", async () => {
const body = `
<section>
<h2>Task sources</h2>
<p>
<!-- valid for export -->
<dfn id="task-1">I'm a
task
source
</dfn>
<!-- Won't match, because no name -->
<dfn id="task-2">
task source
</dfn>
<!-- explicit no export -->
<dfn id="task-3" data-noexport="">
secret
task source
</dfn>
<dfn class="no-export" id="task-4" data-dfn-type="custom-type">
Custom task source
</dfn>
</p>
</section>
`;
const ops = makeStandardOps(null, body);
const doc = await makeRSDoc(ops);

const dfn = doc.getElementById("task-1");
expect(dfn.dataset.dfnFor).toBeUndefined();
expect(dfn.dataset.export).toBe("");
expect(dfn.dataset.dfnType).toBe("task-source");

const dfn2 = doc.getElementById("task-2");
expect(dfn2.dataset.dfnFor).toBeUndefined();
expect(dfn2.dataset.export).toBeUndefined();
expect(dfn2.dataset.dfnType).toBe("dfn");

const dfn3 = doc.getElementById("task-3");
expect(dfn3.dataset.dfnFor).toBeUndefined();
expect(dfn3.dataset.export).toBeUndefined();
expect(dfn3.dataset.dfnType).toBe("task-source");
expect(dfn3.dataset.noexport).toBe("");

const dfn4 = doc.getElementById("task-4");
expect(dfn4.dataset.dfnFor).toBeUndefined();
expect(dfn4.dataset.export).toBeUndefined();
expect(dfn4.dataset.dfnType).toBe("custom-type");
expect(dfn4.dataset.noexport).toBe("");
});

describe("internal slot definitions", () => {
const body = `
<section data-dfn-for="Test" data-cite="HTML">
Expand Down

0 comments on commit dcbebf9

Please sign in to comment.