This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 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
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,62 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2016 The Polymer Project Authors. All rights reserved. | ||
* This code may only be used under the BSD style license found at | ||
* http://polymer.github.io/LICENSE.txt | ||
* The complete set of authors may be found at | ||
* http://polymer.github.io/AUTHORS.txt | ||
* The complete set of contributors may be found at | ||
* http://polymer.github.io/CONTRIBUTORS.txt | ||
* Code distributed by Google as part of the polymer project is also | ||
* subject to an additional IP rights grant found at | ||
* http://polymer.github.io/PATENTS.txt | ||
*/ | ||
|
||
import * as dom5 from 'dom5'; | ||
import * as parse5 from 'parse5'; | ||
import {ParsedHtmlDocument} from 'polymer-analyzer/lib/html/html-document'; | ||
import * as stripIndent from 'strip-indent'; | ||
|
||
import {registry} from '../registry'; | ||
|
||
import {HtmlUpgradePass} from './html-pass'; | ||
|
||
const p = dom5.predicates; | ||
|
||
class CustomStyleDoesntUseIs extends HtmlUpgradePass { | ||
code = 'custom-style-no-is'; | ||
description = stripIndent(` | ||
Transforms: | ||
<style is="custom-style">...</style> | ||
Into: | ||
<custom-style> | ||
<style>...</style> | ||
</custom-style> | ||
Because Polymer v2 is dropping support for is="" for the time being. | ||
`); | ||
constructor() { super(); } | ||
|
||
upgrade(document: ParsedHtmlDocument) { | ||
const isBadCustomStyle = | ||
p.AND(p.hasTagName('style'), p.hasAttrValue('is', 'custom-style')); | ||
for (const style of dom5.nodeWalkAll(document.ast, isBadCustomStyle)) { | ||
const customStyle = | ||
parse5.treeAdapters.default.createElement('custom-style', '', []); | ||
dom5.replace(style, customStyle); | ||
dom5.append(customStyle, style); | ||
|
||
dom5.removeAttribute(style, 'is'); | ||
const include = dom5.getAttribute(style, 'include'); | ||
if (include != null) { | ||
dom5.setAttribute(customStyle, 'include', include); | ||
dom5.removeAttribute(style, 'include'); | ||
} | ||
} | ||
} | ||
} | ||
|
||
registry.register(new CustomStyleDoesntUseIs()); |
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,17 @@ | ||
<head><custom-style><style> | ||
body { | ||
color: var(--clown-nose, #440000); | ||
} | ||
</style></custom-style> | ||
|
||
<custom-style include="foo"><style> | ||
body { | ||
color: var(--clown-nose, #440000); | ||
} | ||
</style></custom-style> | ||
|
||
<!-- | ||
Output is messy, will be fixed by | ||
https://github.com/Polymer/polymer-analyzer/pull/316 | ||
--> | ||
</head><body></body> |
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,16 @@ | ||
<style is="custom-style"> | ||
body { | ||
color: var(--clown-nose, #440000); | ||
} | ||
</style> | ||
|
||
<style is="custom-style" include="foo"> | ||
body { | ||
color: var(--clown-nose, #440000); | ||
} | ||
</style> | ||
|
||
<!-- | ||
Output is messy, will be fixed by | ||
https://github.com/Polymer/polymer-analyzer/pull/316 | ||
--> |