Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion 14 packages/compiler/src/shadow_css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const animationKeywords = new Set([
in comments in lieu of the next selector when running under polyfill.
*/
export class ShadowCss {
// TODO: Is never re-assigned, could be removed.
Copy link
Member Author

Choose a reason for hiding this comment

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

Any insights if this could be safely removed ?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah yeah good spot 🤔 , by looking at the git history I think it might have been added initially to keep the code in this file close to the original webcomponents.js implementation, even initially this was already used but not re-assigned: d67f029#diff-8100ed7347ea0eb1cd98948f17ca578cfc288fc0d58538e3a83db9dac133276b

I bet that the file has strained a lot from the original webcomponents.js code, I wonder if there's still have any value in keeping this in 🤔

strictStyling: boolean = true;

/*
Expand Down Expand Up @@ -729,6 +730,15 @@ export class ShadowCss {
while ((res = sep.exec(selector)) !== null) {
const separator = res[1];
const part = selector.slice(startIndex, res.index).trim();

// A space following an escaped hex value and followed by another hex character
// (ie: ".\fc ber" for ".über") is not a separator between 2 selectors
// also keep in mind that backslashes are replaced by a placeholder by SafeSelector
// These escaped selectors happen for example when esbuild runs with optimization.minify.
if (part.match(_placeholderRe) && selector[res.index + 1]?.match(/[a-fA-F\d]/)) {
continue;
}

shouldScope = shouldScope || part.indexOf(_polyfillHostNoCombinator) > -1;
const scopedPart = shouldScope ? _scopeSelectorPart(part) : part;
scopedSelector += `${scopedPart} ${separator} `;
Expand Down Expand Up @@ -777,7 +787,7 @@ class SafeSelector {
}

restore(content: string): string {
return content.replace(/__ph-(\d+)__/g, (_ph, index) => this.placeholders[+index]);
return content.replace(_placeholderRe, (_ph, index) => this.placeholders[+index]);
}

content(): string {
Expand Down Expand Up @@ -833,6 +843,8 @@ const _colonHostContextRe = /:host-context/gim;

const _commentRe = /\/\*[\s\S]*?\*\//g;

const _placeholderRe = /__ph-(\d+)__/g;

function stripComments(input: string): string {
return input.replace(_commentRe, '');
}
Expand Down
9 changes: 9 additions & 0 deletions 9 packages/compiler/test/shadow_css/shadow_css_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ describe('ShadowCss', () => {
.toEqualCss('.one\\:two[contenta] .three\\:four[contenta] {}');
});

it('should handle escaped selector with space (if followed by a hex char)', () => {
// When esbuild runs with optimization.minify
// selectors are escaped: .über becomes .\fc ber.
// The space here isn't a separator between 2 selectors
expect(shim('.\\fc ber {}', 'contenta')).toEqual('.\\fc ber[contenta] {}');
expect(shim('.\\fc ker {}', 'contenta')).toEqual('.\\fc[contenta] ker[contenta] {}');
expect(shim('.pr\\fc fung {}', 'contenta')).toEqual('.pr\\fc fung[contenta] {}');
});

it('should handle ::shadow', () => {
const css = shim('x::shadow > y {}', 'contenta');
expect(css).toEqualCss('x[contenta] > y[contenta] {}');
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.