Skip to content

Commit

Permalink
fix: pierce selectors should be generated using :scope (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Jul 17, 2023
1 parent 42775d1 commit e8abd93
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions __snapshots__/SchemaUtils.test.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ exports[
] = `
::-p-xpath(//*[@id=\\"id\\"])
`;

exports[
'SchemaUtils Selectors selectorToPElementSelector should convert pierce/#id 1'
] = `
:scope >>> #id
`;

exports[
'SchemaUtils Selectors selectorToPElementSelector should convert pierce/#inner 1'
] = `
:scope >>> #inner
`;
2 changes: 1 addition & 1 deletion src/SchemaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ export function selectorToPElementSelector(selector: string[] | string) {
s.substring(SelectorType.XPath.length + 1)
)})`;
case SelectorType.Pierce:
return `::-p-pierce(${s.substring(SelectorType.Pierce.length + 1)})`;
return `:scope >>> ${s.substring(SelectorType.Pierce.length + 1)}`;
case SelectorType.Text:
return `::-p-text(${escape(
s.substring(SelectorType.Text.length + 1)
Expand Down
15 changes: 15 additions & 0 deletions test/SchemaUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,21 @@ describe('SchemaUtils', () => {
selector: '.cls > div #id',
content: '<div class="cls"><div><div id="id">test',
},
{
selector: 'pierce/#id',
content: '<div class="cls"><div><div id="id">test',
},
{
selector: 'pierce/#inner',
content: `<div class="cls">
<div>
<host-element id="id">
<template shadowrootmode="open">
<div class="cls"><div><div id="inner">test
</template>
</host-element>
`,
},
{
selector: ['.cls > div #id', '.cls > div #id'],
content: `<div class="cls">
Expand Down

1 comment on commit e8abd93

@AlecoDigitalCreator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.