-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tree traversal of flat tree (#1547)
* Fix tree traversal of flat tree * Remove unused import * Extract API --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1bb0273
commit 3b683ee
Showing
9 changed files
with
106 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@siteimprove/alfa-dom": patch | ||
--- | ||
|
||
**Fixed:** Parents of `Comment` inside a shadow tree now correctly skip over the shadow root when traversing the flat tree. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { None } from "@siteimprove/alfa-option"; | ||
import { test } from "@siteimprove/alfa-test"; | ||
|
||
import { h, Comment, Node } from "../src"; | ||
|
||
const targets = [<span />, h.text("hello"), Comment.of("world")]; | ||
const shadow = h.shadow(targets); | ||
const div = <div>{shadow}</div>; | ||
|
||
// Start with no flag. | ||
// For each of the three flags, duplicate existing list and add the flag to one side. | ||
// This ends up giving the eight possible options. | ||
const flags = [ | ||
Node.Traversal.composed, | ||
Node.Traversal.flattened, | ||
Node.Traversal.nested, | ||
].reduce( | ||
(old, cur) => old.flatMap((flag) => [flag, flag.add(cur)]), | ||
[Node.Traversal.of(Node.Traversal.none)], | ||
); | ||
|
||
test(".parent() of a shadow host returns None in composed traversal, the shadow root otherwise", (t) => { | ||
for (const traversal of flags) { | ||
if (traversal.has(Node.Traversal.composed)) { | ||
t.deepEqual(shadow.parent(traversal).getUnsafe(), div); | ||
} else { | ||
t.deepEqual(shadow.parent(traversal), None); | ||
} | ||
} | ||
}); | ||
|
||
test(".parent() of the children of a shadow root returns the shadow host in flat traversal, the shadow root otherwise", (t) => { | ||
for (const target of targets) { | ||
for (const traversal of flags) { | ||
if (traversal.has(Node.Traversal.flattened)) { | ||
t.deepEqual(target.parent(traversal).getUnsafe(), div); | ||
} else { | ||
t.deepEqual(target.parent(traversal).getUnsafe(), shadow); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
test(".parent() of a slottable child of a shadow host returns the slot's parent in flat traversal, the light parent otherwise", (t) => { | ||
const target = <span slot="foo" />; | ||
const shadowDiv = ( | ||
<div> | ||
<slot name="foo"></slot> | ||
</div> | ||
); | ||
const shadow = h.shadow([shadowDiv]); | ||
const lightDiv = ( | ||
<div> | ||
{shadow} | ||
{target} | ||
</div> | ||
); | ||
|
||
for (const traversal of flags) { | ||
if (traversal.has(Node.Traversal.flattened)) { | ||
t.deepEqual(target.parent(traversal).getUnsafe(), shadowDiv); | ||
} else { | ||
t.deepEqual(target.parent(traversal).getUnsafe(), lightDiv); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters