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.
Transform
@apply(--foo)
to @apply --foo
- Loading branch information
Showing
4 changed files
with
60 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,53 @@ | ||
/** | ||
* @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 {ParsedCssDocument} from 'polymer-analyzer/lib/css/css-document'; | ||
import * as shadyCss from 'shady-css-parser'; | ||
import * as stripIndent from 'strip-indent'; | ||
|
||
import {registry} from '../registry'; | ||
|
||
import {CssUpgradePass} from './css-pass'; | ||
|
||
|
||
class FixAtApplyWithInvalidParens extends CssUpgradePass { | ||
code = 'at-apply-not-function'; | ||
description = stripIndent(` | ||
Transforms the invalid expression: | ||
@apply(--foo) | ||
Into the valid: | ||
@apply --foo; | ||
`); | ||
|
||
constructor() { super(); } | ||
|
||
upgrade(document: ParsedCssDocument) { | ||
document.visit([{ | ||
visit(node: shadyCss.Node, _path: shadyCss.Node[]) { | ||
if (node.type === 'atRule' && node.name === 'apply') { | ||
const badApplyMatcher = /^\s*\((.*)\)\s*$/; | ||
const match = node.parameters.match(badApplyMatcher); | ||
if (match) { | ||
node.parameters = `${match[1]}`; | ||
} | ||
} | ||
} | ||
}]); | ||
} | ||
} | ||
|
||
registry.register(new FixAtApplyWithInvalidParens()); |
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,3 @@ | ||
body { | ||
@apply --erratic-jumping; | ||
} |
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,3 @@ | ||
body { | ||
@apply(--erratic-jumping) | ||
} |