Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

New: Replace :root selectors #168

Merged
merged 12 commits into from
Mar 7, 2018
Merged

Conversation

stramel
Copy link
Contributor

@stramel stramel commented Mar 4, 2018

  • CHANGELOG.md has been updated

Relates to #142

/cc @rictic


This change is Reviewable

@stramel
Copy link
Contributor Author

stramel commented Mar 4, 2018

Looking for help in naming of rule code and warning message.

code: this.code,
severity: Severity.WARNING, sourceRange,
message: stripWhitespace(`
Root should no longer be used
Copy link
Contributor

Choose a reason for hiding this comment

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

Root -> The :root selector

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😆 Yeah... I really had no idea what to make this message

message: stripWhitespace(`
Root should no longer be used
`),
fix: [{range: sourceRange, replacementText}]
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to replace just the :root part, so I think we'll want to get the replacementText via a regex replace of :root with the passed in replacementText

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean on this

Copy link
Contributor

Choose a reason for hiding this comment

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

How does this handle a selector like :root foo?

I think it would turn it into either html or :host > * but (I think) we want it to emit html foo or :host > * foo

...this.generateWarnings(
document, isCustomStyle, 'html'), // Check custom styles
...this.generateWarnings(
document, isElementStyle, ':host > *'), // Check element styles
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's a dom-module without an element then it might be a style which is intended for inclusion with include, in which case we want to convert it to both html and :host. See, e.g. https://github.com/PolymerElements/paper-styles/blob/master/element-styles/paper-material-styles.html#L37

If there's other parts of the selector (does that make sense in this context? I'm not sure), we also need to preserve them, so that :root foo becomes :host > * foo, html foo

Copy link
Contributor Author

@stramel stramel Mar 5, 2018

Choose a reason for hiding this comment

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

hmmmm good call on the dom-module part, I will see if I can get that fixed as well.

As far as the addition parts to the selector, I'm not sure if it makes sense or not. I have only ever seen it in the context of :root { https://www.polymer-project.org/2.0/docs/upgrade#replace-root-selectors

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, let's not fix except in the very simple case of just :root

@stramel
Copy link
Contributor Author

stramel commented Mar 6, 2018

Working on handling style modules

@stramel
Copy link
Contributor Author

stramel commented Mar 6, 2018

@rictic This should be all good for review again

@@ -123,14 +123,20 @@ class RootSelectorToHtml extends Rule {
const sourceRange = containingDoc.sourceRangeForShadyRange(
{start, end: start + match[0].length});

// Only fix plain `:root` selectors
let fix: Replacement[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be instead:

let fix: undefined|Replacement[] = undefined;
if (node.selector.match(/^:root$/) !== null) {
  fix = [{range: sourceRange, replacementText}];
}

Otherwise I think we tell the user that the warning could be fixed / was fixed even when we can't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, for some reason, I thought I saw something like this elsewhere. I will make that change.

@rictic
Copy link
Contributor

rictic commented Mar 7, 2018

Arg github, don't hide that comment…

@stramel
Copy link
Contributor Author

stramel commented Mar 7, 2018

-.- Fixing

@rictic
Copy link
Contributor

rictic commented Mar 7, 2018

Great work!

@rictic rictic merged commit a9b7b0e into Polymer:master Mar 7, 2018
@stramel stramel deleted the ms/convert-root-selector branch March 7, 2018 01:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants