diff --git a/lib/ValuesParser.js b/lib/ValuesParser.js index b7a036c..f7e3bb9 100644 --- a/lib/ValuesParser.js +++ b/lib/ValuesParser.js @@ -52,6 +52,7 @@ module.exports = class ValuesParser extends Parser { const inline = Comment.testInline(token); const node = this.lastNode; node.inline = inline; + Object.setPrototypeOf(node, Comment.prototype); } fromFirst(tokens, Constructor) { diff --git a/lib/ValuesStringifier.js b/lib/ValuesStringifier.js index 06b4c77..2728d04 100644 --- a/lib/ValuesStringifier.js +++ b/lib/ValuesStringifier.js @@ -1,6 +1,11 @@ const Stringifier = require('postcss/lib/stringifier'); -module.exports = class LessStringifier extends Stringifier { +module.exports = class ValuesStringifier extends Stringifier { + static stringify(node, builder) { + const stringifier = new ValuesStringifier(builder); + stringifier.stringify(node); + } + basic(node, value) { const print = value || node.value; const after = node.raws.after ? this.raw(node, 'after') || '' : ''; diff --git a/lib/index.js b/lib/index.js index 6f74a68..c8cf4ac 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,7 +11,7 @@ const Input = require('postcss/lib/input'); const Parser = require('./ValuesParser'); -const Stringifier = require('./ValuesStringifier'); +const { stringify } = require('./ValuesStringifier'); module.exports = { parse(css, options) { @@ -20,13 +20,19 @@ module.exports = { parser.parse(); + const { root } = parser; + const ogToString = root.toString; + + function toString(stringifier) { + return ogToString.bind(root)(stringifier || module.exports.stringify); + } + + root.toString = toString.bind(root); + return parser.root; }, - stringify(node, builder) { - const stringifier = new Stringifier(builder); - stringifier.stringify(node); - }, + stringify, nodeToString(node) { let result = ''; diff --git a/lib/nodes/AtWord.js b/lib/nodes/AtWord.js index e3ef52f..4f9ee18 100644 --- a/lib/nodes/AtWord.js +++ b/lib/nodes/AtWord.js @@ -12,10 +12,11 @@ const AtRule = require('postcss/lib/node'); const { registerWalker } = require('../walker'); +const { stringify } = require('../ValuesStringifier'); + class AtWord extends AtRule { - constructor(options) { - super(options); - this.type = 'atword'; + toString(stringifier = stringify) { + return super.toString(stringifier); } } diff --git a/lib/nodes/Comment.js b/lib/nodes/Comment.js index b99f319..2a9b52e 100644 --- a/lib/nodes/Comment.js +++ b/lib/nodes/Comment.js @@ -8,61 +8,71 @@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of this Source Code Form. */ -const Comment = require('postcss/lib/comment'); +const PostCssComment = require('postcss/lib/comment'); + +const { stringify } = require('../ValuesStringifier'); const inlineRegex = /(\/\/)/; -Comment.testInline = (token) => inlineRegex.test(token[1]); +class Comment extends PostCssComment { + static testInline(token) { + return inlineRegex.test(token[1]); + } -Comment.tokenizeNext = (tokens, parser) => { - const [first] = tokens; - const newlineIndex = tokens.findIndex((t) => /\n/.test(t[1])); - let bits = tokens; - let rest = []; + static tokenizeNext(tokens, parser) { + const [first] = tokens; + const newlineIndex = tokens.findIndex((t) => /\n/.test(t[1])); + let bits = tokens; + let rest = []; - if (newlineIndex >= 0) { - bits = tokens.slice(0, newlineIndex); - rest = tokens.slice(newlineIndex); - } + if (newlineIndex >= 0) { + bits = tokens.slice(0, newlineIndex); + rest = tokens.slice(newlineIndex); + } + + bits = bits.map((t) => t[1]); - bits = bits.map((t) => t[1]); + // see tilde comment in tokenizeInline + const text = bits.concat('~~').join(''); + const last = bits[bits.length - 1]; + const newToken = ['comment', text, first[2], first[3], last[2], last[3]]; - // see tilde comment in tokenizeInline - const text = bits.concat('~~').join(''); - const last = bits[bits.length - 1]; - const newToken = ['comment', text, first[2], first[3], last[2], last[3]]; + parser.back([newToken, ...rest]); + } - parser.back([newToken, ...rest]); -}; + static tokenizeInline(tokens, parser) { + const [first, ...rest] = tokens; + const bits = first[1].split(/(\/\/.+)/).filter((t) => !!t); + const newTokens = []; + const [, , startLine, , endLine] = first; + let [, , , startChar, , endChar] = first; -Comment.tokenizeInline = (tokens, parser) => { - const [first, ...rest] = tokens; - const bits = first[1].split(/(\/\/.+)/).filter((t) => !!t); - const newTokens = []; - const [, , startLine, , endLine] = first; - let [, , , startChar, , endChar] = first; + for (let bit of bits) { + const comment = bit.slice(0, 2) === '//'; + const type = comment ? 'comment' : 'word'; - for (let bit of bits) { - const comment = bit.slice(0, 2) === '//'; - const type = comment ? 'comment' : 'word'; + if (comment) { + // the Parser base comment() method trims the last two characters when creating the node + // these tildes are added to counter that. it's hacky, but it works, and we don't have to + // re-implement the method + bit += '~~'; + } - if (comment) { - // the Parser base comment() method trims the last two characters when creating the node - // these tildes are added to counter that. it's hacky, but it works, and we don't have to - // re-implement the method - bit += '~~'; - } + if (bit !== bits[0]) { + startChar = endChar + 1; + } - if (bit !== bits[0]) { - startChar = endChar + 1; - } + endChar = startChar + bit.length - 1; - endChar = startChar + bit.length - 1; + newTokens.push([type, bit, startLine, startChar, endLine, endChar]); + } - newTokens.push([type, bit, startLine, startChar, endLine, endChar]); + parser.back(newTokens.concat(rest)); } - parser.back(newTokens.concat(rest)); -}; + toString(stringifier = stringify) { + return super.toString(stringifier); + } +} module.exports = Comment; diff --git a/lib/nodes/Container.js b/lib/nodes/Container.js new file mode 100644 index 0000000..5c618ac --- /dev/null +++ b/lib/nodes/Container.js @@ -0,0 +1,21 @@ +/* + Copyright © 2018 Andrew Powell + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of this Source Code Form. +*/ +const PostCssContainer = require('postcss/lib/container'); + +const { stringify } = require('../ValuesStringifier'); + +class Container extends PostCssContainer { + toString(stringifier = stringify) { + return super.toString(stringifier); + } +} + +module.exports = Container; diff --git a/lib/nodes/Func.js b/lib/nodes/Func.js index 945cc87..1989b6f 100644 --- a/lib/nodes/Func.js +++ b/lib/nodes/Func.js @@ -8,10 +8,10 @@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of this Source Code Form. */ -const Container = require('postcss/lib/container'); - const { registerWalker } = require('../walker'); +const Container = require('./Container'); + const colorFunctions = ['hsl', 'hsla', 'rgb', 'rgba']; class Func extends Container { diff --git a/lib/nodes/Interpolation.js b/lib/nodes/Interpolation.js index d65420f..4f81edd 100644 --- a/lib/nodes/Interpolation.js +++ b/lib/nodes/Interpolation.js @@ -8,10 +8,10 @@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of this Source Code Form. */ -const Container = require('postcss/lib/container'); - const { registerWalker } = require('../walker'); +const Container = require('./Container'); + class Interpolation extends Container { constructor(options = {}) { super(options); diff --git a/lib/nodes/Node.js b/lib/nodes/Node.js new file mode 100644 index 0000000..483a458 --- /dev/null +++ b/lib/nodes/Node.js @@ -0,0 +1,21 @@ +/* + Copyright © 2018 Andrew Powell + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of this Source Code Form. +*/ +const PostCssNode = require('postcss/lib/node'); + +const { stringify } = require('../ValuesStringifier'); + +class Node extends PostCssNode { + toString(stringifier = stringify) { + return super.toString(stringifier || {}); + } +} + +module.exports = Node; diff --git a/lib/nodes/Numeric.js b/lib/nodes/Numeric.js index eb02857..ce7c4c0 100644 --- a/lib/nodes/Numeric.js +++ b/lib/nodes/Numeric.js @@ -9,10 +9,11 @@ included in all copies or substantial portions of this Source Code Form. */ const isNumber = require('is-number'); -const Node = require('postcss/lib/node'); const { registerWalker } = require('../walker'); +const Node = require('./Node'); + const unitRegex = /%|ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw$/i; class Numeric extends Node { diff --git a/lib/nodes/Operator.js b/lib/nodes/Operator.js index 456e393..46e9dd4 100644 --- a/lib/nodes/Operator.js +++ b/lib/nodes/Operator.js @@ -8,10 +8,10 @@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of this Source Code Form. */ -const Node = require('postcss/lib/node'); - const { registerWalker } = require('../walker'); +const Node = require('./Node'); + const operators = ['+', '-', '/', '*', '%']; const operRegex = new RegExp(`([/|*}])`); diff --git a/lib/nodes/Punctuation.js b/lib/nodes/Punctuation.js index 20090e1..db4d99d 100644 --- a/lib/nodes/Punctuation.js +++ b/lib/nodes/Punctuation.js @@ -8,11 +8,11 @@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of this Source Code Form. */ -const Node = require('postcss/lib/node'); - const { getTokens } = require('../tokenize'); const { registerWalker } = require('../walker'); +const Node = require('./Node'); + /** * @desc Punctuation nodes can contain: * , : ( ) { } [ ] diff --git a/lib/nodes/Quoted.js b/lib/nodes/Quoted.js index 0b47753..ead39f2 100644 --- a/lib/nodes/Quoted.js +++ b/lib/nodes/Quoted.js @@ -8,10 +8,10 @@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of this Source Code Form. */ -const Node = require('postcss/lib/node'); - const { registerWalker } = require('../walker'); +const Node = require('./Node'); + class Quoted extends Node { constructor(options) { super(options); diff --git a/lib/nodes/UnicodeRange.js b/lib/nodes/UnicodeRange.js index fac5663..e1b273c 100644 --- a/lib/nodes/UnicodeRange.js +++ b/lib/nodes/UnicodeRange.js @@ -8,10 +8,10 @@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of this Source Code Form. */ -const Node = require('postcss/lib/node'); - const { registerWalker } = require('../walker'); +const Node = require('./Node'); + class UnicodeRange extends Node { constructor(options) { super(options); diff --git a/lib/nodes/Word.js b/lib/nodes/Word.js index 8e8bde5..bdadbda 100644 --- a/lib/nodes/Word.js +++ b/lib/nodes/Word.js @@ -10,10 +10,11 @@ */ const colors = require('color-name'); const isUrl = require('is-url-superb'); -const Node = require('postcss/lib/node'); const { registerWalker } = require('../walker'); +const Node = require('./Node'); + const escapeRegex = /^\\(.+)/; const hexRegex = /^#(.+)/; const colorRegex = /^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i; diff --git a/test/atword.test.js b/test/atword.test.js index 80939b0..f6d9068 100644 --- a/test/atword.test.js +++ b/test/atword.test.js @@ -24,6 +24,8 @@ for (const fixture of snapshot) { const string = nodeToString(root); t.is(string, fixture); + t.is(fixture, root.toString()); + t.snapshot(root.first.toString()); t.snapshot(string); t.snapshot(nodes); }); diff --git a/test/comment.test.js b/test/comment.test.js index 7ea340a..408b088 100644 --- a/test/comment.test.js +++ b/test/comment.test.js @@ -24,6 +24,8 @@ for (const fixture of snapshot) { const string = nodeToString(root); t.is(string, fixture); + t.is(fixture, root.toString()); + t.snapshot(root.first.toString()); t.snapshot(string); t.snapshot(nodes); }); diff --git a/test/fixtures/interpolation.js b/test/fixtures/interpolation.js index 278338a..e959108 100644 --- a/test/fixtures/interpolation.js +++ b/test/fixtures/interpolation.js @@ -12,5 +12,6 @@ module.exports = { options: { interpolation: { prefix: '#' } }, - snapshot: ['#{batman}', '#{2px}', '#{2 * 2px}'] + snapshot: ['#{batman}', '#{2px}', '#{2 * 2px}'], + throws: ['#{batman'] }; diff --git a/test/func.test.js b/test/func.test.js index e69682d..75f20ce 100644 --- a/test/func.test.js +++ b/test/func.test.js @@ -24,6 +24,8 @@ for (const fixture of snapshot) { const string = nodeToString(root); t.is(string, fixture); + t.is(fixture, root.toString()); + t.snapshot(root.first.toString()); t.snapshot(string); t.snapshot(nodes); }); diff --git a/test/interpolation.test.js b/test/interpolation.test.js index 9254cb2..40388d7 100644 --- a/test/interpolation.test.js +++ b/test/interpolation.test.js @@ -12,7 +12,7 @@ const test = require('ava'); const { nodeToString, parse } = require('../lib'); -const { options, snapshot } = require('./fixtures/interpolation'); +const { options, snapshot, throws } = require('./fixtures/interpolation'); for (const fixture of snapshot) { test(fixture, (t) => { @@ -24,7 +24,15 @@ for (const fixture of snapshot) { const string = nodeToString(root); t.is(string, fixture); + t.is(fixture, root.toString()); + t.snapshot(root.first.toString()); t.snapshot(string); t.snapshot(nodes); }); } + +for (const fixture of throws) { + test(fixture, (t) => { + t.throws(() => parse(fixture)); + }); +} diff --git a/test/numeric.test.js b/test/numeric.test.js index 1f9e781..913c202 100644 --- a/test/numeric.test.js +++ b/test/numeric.test.js @@ -24,6 +24,8 @@ for (const fixture of snapshot) { const string = nodeToString(root); t.is(string, fixture); + t.is(fixture, root.toString()); + t.snapshot(root.first.toString()); t.snapshot(string); t.snapshot(nodes); }); diff --git a/test/operator.test.js b/test/operator.test.js index f715cb1..102d989 100644 --- a/test/operator.test.js +++ b/test/operator.test.js @@ -24,6 +24,8 @@ for (const fixture of snapshot) { const string = nodeToString(root); t.is(string, fixture); + t.is(fixture, root.toString()); + t.snapshot(root.first.toString()); t.snapshot(string); t.snapshot(nodes); }); diff --git a/test/punctuation.test.js b/test/punctuation.test.js index 46b7eab..7066471 100644 --- a/test/punctuation.test.js +++ b/test/punctuation.test.js @@ -24,6 +24,8 @@ for (const fixture of snapshot) { const string = nodeToString(root); t.is(string, fixture); + t.is(fixture, root.toString()); + t.snapshot(root.first.toString()); t.snapshot(string); t.snapshot(nodes); }); diff --git a/test/snapshots/atword.test.js.md b/test/snapshots/atword.test.js.md index 64bd4ef..e5c8980 100644 --- a/test/snapshots/atword.test.js.md +++ b/test/snapshots/atword.test.js.md @@ -8,10 +8,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - ' @word ' + '@word ' > Snapshot 2 + ' @word ' + +> Snapshot 3 + [ AtWord { name: 'word', diff --git a/test/snapshots/atword.test.js.snap b/test/snapshots/atword.test.js.snap index 0a67966..10ac237 100644 Binary files a/test/snapshots/atword.test.js.snap and b/test/snapshots/atword.test.js.snap differ diff --git a/test/snapshots/comment.test.js.md b/test/snapshots/comment.test.js.md index 007cb82..1d77c3e 100644 --- a/test/snapshots/comment.test.js.md +++ b/test/snapshots/comment.test.js.md @@ -12,6 +12,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '/**/' + +> Snapshot 3 + [ Comment { inline: false, @@ -46,11 +50,15 @@ Generated by [AVA](https://ava.li). > Snapshot 1 + '/*before*/' + +> Snapshot 2 + `/*before*/␊ //between␊ /*after*/` -> Snapshot 2 +> Snapshot 3 [ Comment { @@ -142,10 +150,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '/*before*/ 1px /*between*/ 1px /*after*/' + '/*before*/' > Snapshot 2 + '/*before*/ 1px /*between*/ 1px /*after*/' + +> Snapshot 3 + [ Comment { inline: false, @@ -280,6 +292,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '//' + +> Snapshot 3 + [ Comment { inline: true, @@ -313,10 +329,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 + '//' + +> Snapshot 2 + `//␊ ` -> Snapshot 2 +> Snapshot 3 [ Comment { @@ -354,12 +374,16 @@ Generated by [AVA](https://ava.li). > Snapshot 1 + '//before' + +> Snapshot 2 + `//before␊ 1px //between␊ 1px //after␊ ` -> Snapshot 2 +> Snapshot 3 [ Comment { @@ -510,11 +534,15 @@ Generated by [AVA](https://ava.li). > Snapshot 1 + '//before' + +> Snapshot 2 + `//before␊ /*between*/␊ //after` -> Snapshot 2 +> Snapshot 3 [ Comment { diff --git a/test/snapshots/comment.test.js.snap b/test/snapshots/comment.test.js.snap index 7814884..502064a 100644 Binary files a/test/snapshots/comment.test.js.snap and b/test/snapshots/comment.test.js.snap differ diff --git a/test/snapshots/func.test.js.md b/test/snapshots/func.test.js.md index d0d5c88..28d0fda 100644 --- a/test/snapshots/func.test.js.md +++ b/test/snapshots/func.test.js.md @@ -12,6 +12,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '-webkit-linear-gradient(0)' + +> Snapshot 3 + [ Func { isColor: false, @@ -76,6 +80,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'RGBA( 29, 439 , 29 )' + +> Snapshot 3 + [ Func { isColor: true, @@ -238,6 +246,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'RgBa( 29, 439 , 29 )' + +> Snapshot 3 + [ Func { isColor: true, @@ -400,6 +412,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'bar(baz(black, 10%), 10%)' + +> Snapshot 3 + [ Func { isColor: false, @@ -594,6 +610,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'calc(((768px - 100vw) / 2) - 15px)' + +> Snapshot 3 + [ Func { isColor: false, @@ -901,6 +921,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'calc(-0.5 * var(foo))' + +> Snapshot 3 + [ Func { isColor: false, @@ -1046,6 +1070,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'calc(1px + -2vw - 4px)' + +> Snapshot 3 + [ Func { isColor: false, @@ -1208,6 +1236,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'rgba( 29, 439 , 29 )' + +> Snapshot 3 + [ Func { isColor: true, @@ -1370,6 +1402,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'url( "/gfx/img/bg.jpg" )' + +> Snapshot 3 + [ Func { isColor: false, @@ -1434,6 +1470,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'url( "http://domain.com/gfx/img/bg.jpg" )' + +> Snapshot 3 + [ Func { isColor: false, @@ -1498,6 +1538,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'url( \'/gfx/img/bg.jpg\' )' + +> Snapshot 3 + [ Func { isColor: false, @@ -1562,6 +1606,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'url( \'http://domain.com/gfx/img/bg.jpg\' )' + +> Snapshot 3 + [ Func { isColor: false, @@ -1626,6 +1674,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'url( /gfx/img/bg.jpg )' + +> Snapshot 3 + [ Func { isColor: false, @@ -1821,6 +1873,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'url("/gfx/img/bg.jpg" hello )' + +> Snapshot 3 + [ Func { isColor: false, @@ -1913,6 +1969,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'url("http://domain.com/gfx/img/bg.jpg" hello )' + +> Snapshot 3 + [ Func { isColor: false, @@ -2005,6 +2065,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'url()' + +> Snapshot 3 + [ Func { isColor: false, @@ -2038,10 +2102,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - 'url() foo bar baz' + 'url()' > Snapshot 2 + 'url() foo bar baz' + +> Snapshot 3 + [ Func { isColor: false, @@ -2160,6 +2228,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'url(//123.example.com)' + +> Snapshot 3 + [ Func { isColor: false, @@ -2227,6 +2299,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'url(http://123.example.com)' + +> Snapshot 3 + [ Func { isColor: false, @@ -2346,6 +2422,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'url(var(foo))' + +> Snapshot 3 + [ Func { isColor: false, diff --git a/test/snapshots/func.test.js.snap b/test/snapshots/func.test.js.snap index ba5e040..a715830 100644 Binary files a/test/snapshots/func.test.js.snap and b/test/snapshots/func.test.js.snap differ diff --git a/test/snapshots/interpolation.test.js.md b/test/snapshots/interpolation.test.js.md index 47e77a1..b5bb0cb 100644 --- a/test/snapshots/interpolation.test.js.md +++ b/test/snapshots/interpolation.test.js.md @@ -12,6 +12,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '#{2 * 2px}' + +> Snapshot 3 + [ Interpolation { nodes: [ @@ -124,6 +128,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '#{2px}' + +> Snapshot 3 + [ Interpolation { nodes: [ @@ -187,6 +195,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '#{batman}' + +> Snapshot 3 + [ Interpolation { nodes: [ diff --git a/test/snapshots/interpolation.test.js.snap b/test/snapshots/interpolation.test.js.snap index dd973d4..2c88906 100644 Binary files a/test/snapshots/interpolation.test.js.snap and b/test/snapshots/interpolation.test.js.snap differ diff --git a/test/snapshots/numeric.test.js.md b/test/snapshots/numeric.test.js.md index 2970a5f..185310d 100644 --- a/test/snapshots/numeric.test.js.md +++ b/test/snapshots/numeric.test.js.md @@ -12,6 +12,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '+2' + +> Snapshot 3 + [ Numeric { raws: { @@ -47,6 +51,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '-.567800E-0012780em' + +> Snapshot 3 + [ Numeric { raws: { @@ -82,6 +90,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '-0.5' + +> Snapshot 3 + [ Numeric { raws: { @@ -117,6 +129,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '-16px' + +> Snapshot 3 + [ Numeric { raws: { @@ -148,10 +164,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '-16px -1px -1px -16px' + '-16px' > Snapshot 2 + '-16px -1px -1px -16px' + +> Snapshot 3 + [ Numeric { raws: { @@ -259,6 +279,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '-2' + +> Snapshot 3 + [ Numeric { raws: { @@ -294,6 +318,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '-2px' + +> Snapshot 3 + [ Numeric { raws: { @@ -329,6 +357,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '.1E+10' + +> Snapshot 3 + [ Numeric { raws: { @@ -364,6 +396,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '.1E-10' + +> Snapshot 3 + [ Numeric { raws: { @@ -399,6 +435,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '.23rem' + +> Snapshot 3 + [ Numeric { raws: { @@ -434,6 +474,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '0.5' + +> Snapshot 3 + [ Numeric { raws: { @@ -469,6 +513,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '1E+10' + +> Snapshot 3 + [ Numeric { raws: { @@ -504,6 +552,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '1E-10' + +> Snapshot 3 + [ Numeric { raws: { @@ -539,6 +591,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '1E10' + +> Snapshot 3 + [ Numeric { raws: { @@ -574,6 +630,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '1e+10' + +> Snapshot 3 + [ Numeric { raws: { @@ -609,6 +669,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '1e-10' + +> Snapshot 3 + [ Numeric { raws: { @@ -644,6 +708,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '1e10' + +> Snapshot 3 + [ Numeric { raws: { @@ -679,6 +747,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '2.' + +> Snapshot 3 + [ Numeric { raws: { @@ -710,10 +782,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '5 + 5' + '5' > Snapshot 2 + '5 + 5' + +> Snapshot 3 + [ Numeric { raws: { @@ -792,10 +868,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '5 +5' + '5' > Snapshot 2 + '5 +5' + +> Snapshot 3 + [ Numeric { raws: { @@ -851,10 +931,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '5/5' + '5' > Snapshot 2 + '5/5' + +> Snapshot 3 + [ Numeric { raws: { diff --git a/test/snapshots/numeric.test.js.snap b/test/snapshots/numeric.test.js.snap index 79b6f89..0f0136b 100644 Binary files a/test/snapshots/numeric.test.js.snap and b/test/snapshots/numeric.test.js.snap differ diff --git a/test/snapshots/operator.test.js.md b/test/snapshots/operator.test.js.md index 470aeee..7590e21 100644 --- a/test/snapshots/operator.test.js.md +++ b/test/snapshots/operator.test.js.md @@ -8,10 +8,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '10 % modulo' + '10' > Snapshot 2 + '10 % modulo' + +> Snapshot 3 + [ Numeric { raws: { @@ -93,10 +97,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '2 * 10' + '2' > Snapshot 2 + '2 * 10' + +> Snapshot 3 + [ Numeric { raws: { @@ -175,10 +183,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '2 / 10' + '2' > Snapshot 2 + '2 / 10' + +> Snapshot 3 + [ Numeric { raws: { diff --git a/test/snapshots/operator.test.js.snap b/test/snapshots/operator.test.js.snap index 467770a..4ba6574 100644 Binary files a/test/snapshots/operator.test.js.snap and b/test/snapshots/operator.test.js.snap differ diff --git a/test/snapshots/punctuation.test.js.md b/test/snapshots/punctuation.test.js.md index 25d2002..6403a37 100644 --- a/test/snapshots/punctuation.test.js.md +++ b/test/snapshots/punctuation.test.js.md @@ -8,10 +8,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '(1,2)' + '(' > Snapshot 2 + '(1,2)' + +> Snapshot 3 + [ Punctuation { raws: { @@ -140,6 +144,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + ')' + +> Snapshot 3 + [ Punctuation { raws: { @@ -174,6 +182,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + ',' + +> Snapshot 3 + [ Punctuation { raws: { @@ -204,10 +216,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - ', : ( ) { } [ ]' + ',' > Snapshot 2 + ', : ( ) { } [ ]' + +> Snapshot 3 + [ Punctuation { raws: { @@ -399,10 +415,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '5,6,7,8' + '5' > Snapshot 2 + '5,6,7,8' + +> Snapshot 3 + [ Numeric { raws: { @@ -579,6 +599,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + ':' + +> Snapshot 3 + [ Punctuation { raws: { @@ -613,6 +637,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + ']' + +> Snapshot 3 + [ Punctuation { raws: { @@ -647,6 +675,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '{' + +> Snapshot 3 + [ Punctuation { raws: { @@ -681,6 +713,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '}' + +> Snapshot 3 + [ Punctuation { raws: { diff --git a/test/snapshots/punctuation.test.js.snap b/test/snapshots/punctuation.test.js.snap index c85e0de..13c830b 100644 Binary files a/test/snapshots/punctuation.test.js.snap and b/test/snapshots/punctuation.test.js.snap differ diff --git a/test/snapshots/unicode-range.test.js.md b/test/snapshots/unicode-range.test.js.md index 0e3f645..300d794 100644 --- a/test/snapshots/unicode-range.test.js.md +++ b/test/snapshots/unicode-range.test.js.md @@ -12,6 +12,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'U+0-7F' + +> Snapshot 3 + [ UnicodeRange { raws: { @@ -46,6 +50,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'U+0025-00FF' + +> Snapshot 3 + [ UnicodeRange { raws: { @@ -76,10 +84,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - 'U+0025-00FF, U+4??' + 'U+0025-00FF' > Snapshot 2 + 'U+0025-00FF, U+4??' + +> Snapshot 3 + [ UnicodeRange { raws: { @@ -160,6 +172,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'U+26' + +> Snapshot 3 + [ UnicodeRange { raws: { @@ -194,6 +210,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'U+4??' + +> Snapshot 3 + [ UnicodeRange { raws: { diff --git a/test/snapshots/unicode-range.test.js.snap b/test/snapshots/unicode-range.test.js.snap index 1e4326f..73ea8ed 100644 Binary files a/test/snapshots/unicode-range.test.js.snap and b/test/snapshots/unicode-range.test.js.snap differ diff --git a/test/snapshots/variable.test.js.md b/test/snapshots/variable.test.js.md index f7361c3..8f0848f 100644 --- a/test/snapshots/variable.test.js.md +++ b/test/snapshots/variable.test.js.md @@ -12,6 +12,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '$batman' + +> Snapshot 3 + [ Word { isColor: false, @@ -50,6 +54,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '$main-bg-color' + +> Snapshot 3 + [ Word { isColor: false, @@ -88,6 +96,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '--batman' + +> Snapshot 3 + [ Word { isColor: false, @@ -126,6 +138,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '--main-bg-color' + +> Snapshot 3 + [ Word { isColor: false, diff --git a/test/snapshots/variable.test.js.snap b/test/snapshots/variable.test.js.snap index 2f37720..022e8ab 100644 Binary files a/test/snapshots/variable.test.js.snap and b/test/snapshots/variable.test.js.snap differ diff --git a/test/snapshots/word.test.js.md b/test/snapshots/word.test.js.md index c12a235..973d83b 100644 --- a/test/snapshots/word.test.js.md +++ b/test/snapshots/word.test.js.md @@ -8,10 +8,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - ' \\"word\\" \\s ' + '\\"' > Snapshot 2 + ' \\"word\\" \\s ' + +> Snapshot 3 + [ Word { isColor: false, @@ -127,10 +131,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '#123 #f09f #abcdef #a2b3c4d5' + '#123' > Snapshot 2 + '#123 #f09f #abcdef #a2b3c4d5' + +> Snapshot 3 + [ Word { isColor: true, @@ -250,6 +258,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '#fff' + +> Snapshot 3 + [ Word { isColor: true, @@ -284,10 +296,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - '(min-width: 700px) and (orientation: \\$landscape)' + '(' > Snapshot 2 + '(min-width: 700px) and (orientation: \\$landscape)' + +> Snapshot 3 + [ Punctuation { raws: { @@ -596,6 +612,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '--color' + +> Snapshot 3 + [ Word { isColor: false, @@ -634,6 +654,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + '-webkit-transition' + +> Snapshot 3 + [ Word { isColor: false, @@ -672,6 +696,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'BLANCHEDALMOND' + +> Snapshot 3 + [ Word { isColor: true, @@ -710,6 +738,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'blAncHedaLmoNd' + +> Snapshot 3 + [ Word { isColor: true, @@ -748,6 +780,10 @@ Generated by [AVA](https://ava.li). > Snapshot 2 + 'blanchedalmond' + +> Snapshot 3 + [ Word { isColor: true, @@ -782,10 +818,14 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - 'bold italic 12px /3 \'Open Sans\', Arial, "Helvetica Neue", sans-serif' + 'bold' > Snapshot 2 + 'bold italic 12px /3 \'Open Sans\', Arial, "Helvetica Neue", sans-serif' + +> Snapshot 3 + [ Word { isColor: false, diff --git a/test/snapshots/word.test.js.snap b/test/snapshots/word.test.js.snap index 18e03c1..facc8a4 100644 Binary files a/test/snapshots/word.test.js.snap and b/test/snapshots/word.test.js.snap differ diff --git a/test/unicode-range.test.js b/test/unicode-range.test.js index 73dbd49..aea2edd 100644 --- a/test/unicode-range.test.js +++ b/test/unicode-range.test.js @@ -24,6 +24,8 @@ for (const fixture of snapshot) { const string = nodeToString(root); t.is(string, fixture); + t.is(fixture, root.toString()); + t.snapshot(root.first.toString()); t.snapshot(string); t.snapshot(nodes); }); diff --git a/test/variable.test.js b/test/variable.test.js index 6307917..7d04c97 100644 --- a/test/variable.test.js +++ b/test/variable.test.js @@ -24,6 +24,8 @@ for (const fixture of snapshot) { const string = nodeToString(root); t.is(string, fixture); + t.is(fixture, root.toString()); + t.snapshot(root.first.toString()); t.snapshot(string); t.snapshot(nodes); }); diff --git a/test/word.test.js b/test/word.test.js index 2aac854..bd24ce4 100644 --- a/test/word.test.js +++ b/test/word.test.js @@ -24,6 +24,8 @@ for (const fixture of snapshot) { const string = nodeToString(root); t.is(string, fixture); + t.is(fixture, root.toString()); + t.snapshot(root.first.toString()); t.snapshot(string); t.snapshot(nodes); });