Skip to content

Shady Parts: Parsing and formatting functions #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 18, 2020

Conversation

aomarks
Copy link
Contributor

@aomarks aomarks commented May 11, 2020

Start with some the parsing and formatting functions for shadow parts support in ShadyCSS.

(Note this is merging into the shady-parts branch, not master).

See #306 for design.

Part of #252 and #311.

@aomarks aomarks force-pushed the shady-parts-parsing-formatting branch from dee6d36 to 671373b Compare May 11, 2020 21:05
inner = split[0];
outer = split[1];
} else {
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

When will this happen? If the string is poorly formatted? Add comment.

Copy link
Contributor Author

@aomarks aomarks May 18, 2020

Choose a reason for hiding this comment

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

Yep, if there are >2 colons. Matches Chrome native behavior. Comment added.

* parsePartSelector for description of pieces.
* [0 ][1 ][2 ] [3 ] [4 ]
*/
const PART_REGEX = /(.*?)([a-z]+-\w+)([^\s]*?)::part\((.*)?\)(::.*)?/;
Copy link
Collaborator

Choose a reason for hiding this comment

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

pseudo-classes are written with a single : so this regex won't catch them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, oops. Need to match both pseudo-classes and pseudo-elements, so now it matches ::?.

test("all components", () => {
assert.deepEqual(
shadowParts.parsePartSelector(
"#parent > my-button.fancy::part(foo bar)::hover"
Copy link
Collaborator

Choose a reason for hiding this comment

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

pseudo-classes like hover are written with a single :.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@aomarks aomarks merged commit c38faa2 into shady-parts May 18, 2020
@aomarks aomarks deleted the shady-parts-parsing-formatting branch May 18, 2020 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants