-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parsing of
theme()
inside calc()
when there are no spaces aro…
…und operators (#11157) * Refactor * Don’t resolve functions for anything not using theme or screen * Normalize math operators inside calc when handling functions * Inline postcss-value-parser * Treat all functions the same as calc * Remove workaround for calc + operators without spaces * Remove `postcss-value-parser` dependency * Update lockfile * Update sourcemaps * Update changelog * Update `value-parser` formatting * Stop prettier from complaining
- Loading branch information
1 parent
cdca9cb
commit 960cb40
Showing
17 changed files
with
893 additions
and
145 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,22 @@ | ||
Copyright (c) Bogdan Chadkin <trysound@yandex.ru> | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
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 @@ | ||
# postcss-value-parser (forked + inlined) | ||
|
||
This is a customized version of of [PostCSS Value Parser](https://github.com/TrySound/postcss-value-parser) to fix some bugs around parsing CSS functions. |
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,177 @@ | ||
declare namespace postcssValueParser { | ||
interface BaseNode { | ||
/** | ||
* The offset, inclusive, inside the CSS value at which the node starts. | ||
*/ | ||
sourceIndex: number | ||
|
||
/** | ||
* The offset, exclusive, inside the CSS value at which the node ends. | ||
*/ | ||
sourceEndIndex: number | ||
|
||
/** | ||
* The node's characteristic value | ||
*/ | ||
value: string | ||
} | ||
|
||
interface ClosableNode { | ||
/** | ||
* Whether the parsed CSS value ended before the node was properly closed | ||
*/ | ||
unclosed?: true | ||
} | ||
|
||
interface AdjacentAwareNode { | ||
/** | ||
* The token at the start of the node | ||
*/ | ||
before: string | ||
|
||
/** | ||
* The token at the end of the node | ||
*/ | ||
after: string | ||
} | ||
|
||
interface CommentNode extends BaseNode, ClosableNode { | ||
type: 'comment' | ||
} | ||
|
||
interface DivNode extends BaseNode, AdjacentAwareNode { | ||
type: 'div' | ||
} | ||
|
||
interface FunctionNode extends BaseNode, ClosableNode, AdjacentAwareNode { | ||
type: 'function' | ||
|
||
/** | ||
* Nodes inside the function | ||
*/ | ||
nodes: Node[] | ||
} | ||
|
||
interface SpaceNode extends BaseNode { | ||
type: 'space' | ||
} | ||
|
||
interface StringNode extends BaseNode, ClosableNode { | ||
type: 'string' | ||
|
||
/** | ||
* The quote type delimiting the string | ||
*/ | ||
quote: '"' | "'" | ||
} | ||
|
||
interface UnicodeRangeNode extends BaseNode { | ||
type: 'unicode-range' | ||
} | ||
|
||
interface WordNode extends BaseNode { | ||
type: 'word' | ||
} | ||
|
||
/** | ||
* Any node parsed from a CSS value | ||
*/ | ||
type Node = | ||
| CommentNode | ||
| DivNode | ||
| FunctionNode | ||
| SpaceNode | ||
| StringNode | ||
| UnicodeRangeNode | ||
| WordNode | ||
|
||
interface CustomStringifierCallback { | ||
/** | ||
* @param node The node to stringify | ||
* @returns The serialized CSS representation of the node | ||
*/ | ||
(nodes: Node): string | undefined | ||
} | ||
|
||
interface WalkCallback { | ||
/** | ||
* @param node The currently visited node | ||
* @param index The index of the node in the series of parsed nodes | ||
* @param nodes The series of parsed nodes | ||
* @returns Returning `false` will prevent traversal of descendant nodes (only applies if `bubble` was set to `true` in the `walk()` call) | ||
*/ | ||
(node: Node, index: number, nodes: Node[]): void | boolean | ||
} | ||
|
||
/** | ||
* A CSS dimension, decomposed into its numeric and unit parts | ||
*/ | ||
interface Dimension { | ||
number: string | ||
unit: string | ||
} | ||
|
||
/** | ||
* A wrapper around a parsed CSS value that allows for inspecting and walking nodes | ||
*/ | ||
interface ParsedValue { | ||
/** | ||
* The series of parsed nodes | ||
*/ | ||
nodes: Node[] | ||
|
||
/** | ||
* Walk all parsed nodes, applying a callback | ||
* | ||
* @param callback A visitor callback that will be executed for each node | ||
* @param bubble When set to `true`, walking will be done inside-out instead of outside-in | ||
*/ | ||
walk(callback: WalkCallback, bubble?: boolean): this | ||
} | ||
|
||
interface ValueParser { | ||
/** | ||
* Decompose a CSS dimension into its numeric and unit part | ||
* | ||
* @param value The dimension to decompose | ||
* @returns An object representing `number` and `unit` part of the dimension or `false` if the decomposing fails | ||
*/ | ||
unit(value: string): Dimension | false | ||
|
||
/** | ||
* Serialize a series of nodes into a CSS value | ||
* | ||
* @param nodes The nodes to stringify | ||
* @param custom A custom stringifier callback | ||
* @returns The generated CSS value | ||
*/ | ||
stringify(nodes: Node | Node[], custom?: CustomStringifierCallback): string | ||
|
||
/** | ||
* Walk a series of nodes, applying a callback | ||
* | ||
* @param nodes The nodes to walk | ||
* @param callback A visitor callback that will be executed for each node | ||
* @param bubble When set to `true`, walking will be done inside-out instead of outside-in | ||
*/ | ||
walk(nodes: Node[], callback: WalkCallback, bubble?: boolean): void | ||
|
||
/** | ||
* Parse a CSS value into a series of nodes to operate on | ||
* | ||
* @param value The value to parse | ||
*/ | ||
new (value: string): ParsedValue | ||
|
||
/** | ||
* Parse a CSS value into a series of nodes to operate on | ||
* | ||
* @param value The value to parse | ||
*/ | ||
(value: string): ParsedValue | ||
} | ||
} | ||
|
||
declare const postcssValueParser: postcssValueParser.ValueParser | ||
|
||
export = postcssValueParser |
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,28 @@ | ||
var parse = require('./parse') | ||
var walk = require('./walk') | ||
var stringify = require('./stringify') | ||
|
||
function ValueParser(value) { | ||
if (this instanceof ValueParser) { | ||
this.nodes = parse(value) | ||
return this | ||
} | ||
return new ValueParser(value) | ||
} | ||
|
||
ValueParser.prototype.toString = function () { | ||
return Array.isArray(this.nodes) ? stringify(this.nodes) : '' | ||
} | ||
|
||
ValueParser.prototype.walk = function (cb, bubble) { | ||
walk(this.nodes, cb, bubble) | ||
return this | ||
} | ||
|
||
ValueParser.unit = require('./unit') | ||
|
||
ValueParser.walk = walk | ||
|
||
ValueParser.stringify = stringify | ||
|
||
module.exports = ValueParser |
Oops, something went wrong.