From df9a14c52e0d3e533cfe14d6bd796b4974af1004 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Mon, 19 Oct 2015 16:03:43 +0300 Subject: [PATCH 1/5] Added sourceIndex to space node --- lib/parse.js | 7 +++--- test/index.js | 2 +- test/parse.js | 70 +++++++++++++++++++++++++-------------------------- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index a577a22..42fff28 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -32,7 +32,6 @@ module.exports = function (input) { code = value.charCodeAt(next); } while (code <= 32); token = value.slice(pos, next); - pos = next; prev = tokens[tokens.length - 1]; if (code === closeParentheses && balanced) { @@ -42,9 +41,11 @@ module.exports = function (input) { } else if (code === slash || code === comma || code === colon) { before = token; } else { - tokens.push({ type: 'space', value: token }); + tokens.push({ type: 'space', value: token, sourceIndex: pos }); } + pos = next; + // Quotes } else if (code === singleQuote || code === doubleQuote) { next = pos; @@ -116,7 +117,7 @@ module.exports = function (input) { token.nodes = [{ type: 'word', value: value.slice(pos, whitespacePos + 1) }]; if (token.unclosed && whitespacePos + 1 !== next) { token.after = ''; - token.nodes.push({ type: 'space', value: value.slice(whitespacePos + 1, next) }); + token.nodes.push({ type: 'space', value: value.slice(whitespacePos + 1, next), sourceIndex: whitespacePos + 1 }); } else { token.after = value.slice(whitespacePos + 1, next); } diff --git a/test/index.js b/test/index.js index b7afad5..6bee28a 100644 --- a/test/index.js +++ b/test/index.js @@ -66,7 +66,7 @@ test('ValueParser', function (t) { t.deepEqual(result, [ { type: 'function', value: 'fn', before: ' ', after: '', nodes: [] }, - { type: 'space', value: ' '}, + { type: 'space', sourceIndex: 5, value: ' '}, { type: 'word', value: 'fn2', before: ' ', after: '', nodes: [ { type: 'function', value: 'fn3', before: '', after: '', nodes: [] } ] }, diff --git a/test/parse.js b/test/parse.js index 01f5d57..f7ad7d9 100644 --- a/test/parse.js +++ b/test/parse.js @@ -28,7 +28,7 @@ var tests = [{ fixture: '\\( \\)', expected: [ { type: 'word', value: '\\(' }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 2, value: ' ' }, { type: 'word', value: '\\)' } ] }, { @@ -36,7 +36,7 @@ var tests = [{ fixture: '() )wo)rd)', expected: [ { type: 'function', value: '', before: '', after: '', nodes: [] }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 2, value: ' ' }, { type: 'word', value: ')wo)rd)' } ] }, { @@ -185,37 +185,37 @@ var tests = [{ message: 'should process quoted strings and spaces', fixture: ' "string" ', expected: [ - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 0, value: ' ' }, { type: 'string', value: 'string', quote: '"' }, - { type: 'space', value: ' ' } + { type: 'space', sourceIndex: 9, value: ' ' } ] }, { message: 'should process escaped symbols as words', fixture: ' \\"word\\\'\\ \\\t ', expected: [ - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 0, value: ' ' }, { type: 'word', value: '\\"word\\\'\\ \\\t'}, - { type: 'space', value: ' ' } + { type: 'space', sourceIndex: 13, value: ' ' } ] }, { message: 'should correctly proceess font value', fixture: 'bold italic 12px \t /3 \'Open Sans\', Arial, "Helvetica Neue", sans-serif', expected: [ - { type: 'word', value: 'bold' }, - { type: 'space', value: ' ' }, - { type: 'word', value: 'italic' }, - { type: 'space', value: ' ' }, - { type: 'word', value: '12px' }, - { type: 'div', value: '/' , before: ' \t ', after: '' }, - { type: 'word', value: '3' }, - { type: 'space', value: ' ' }, + { type: 'word', value: 'bold' }, + { type: 'space', sourceIndex: 4, value: ' ' }, + { type: 'word', value: 'italic' }, + { type: 'space', sourceIndex: 11, value: ' ' }, + { type: 'word', value: '12px' }, + { type: 'div', value: '/' , before: ' \t ', after: '' }, + { type: 'word', value: '3' }, + { type: 'space', sourceIndex: 21, value: ' ' }, { type: 'string', value: 'Open Sans', quote: '\'' }, - { type: 'div', value: ',', before: '', after: ' ' }, - { type: 'word', value: 'Arial' }, - { type: 'div', value: ',', before: '', after: ' ' }, + { type: 'div', value: ',', before: '', after: ' ' }, + { type: 'word', value: 'Arial' }, + { type: 'div', value: ',', before: '', after: ' ' }, { type: 'string', value: 'Helvetica Neue', quote: '"' }, - { type: 'div', value: ',', before: '', after: ' ' }, - { type: 'word', value: 'sans-serif' }, + { type: 'div', value: ',', before: '', after: ' ' }, + { type: 'word', value: 'sans-serif' }, ] }, { message: 'should correctly proceess color value', @@ -243,7 +243,7 @@ var tests = [{ expected: [ { type: 'function', value: 'url', before: ' ', after: '', unclosed: true, nodes: [ { type: 'word', value: '/gfx/img/bg.jpg' }, - { type: 'space', value: ' ' } + { type: 'space', sourceIndex: 20, value: ' ' } ] } ] }, { @@ -252,7 +252,7 @@ var tests = [{ expected: [ { type: 'function', value: 'url', before: ' ', after: ' ', nodes: [ { type: 'string', quote: '"', value: '/gfx/img/bg.jpg' }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 22, value: ' ' }, { type: 'word', value: 'hello' } ] } ] @@ -264,17 +264,17 @@ var tests = [{ { type: 'function', value: '', before: '', after: '', nodes: [ { type: 'function', value: '', before: '', after: '', nodes: [ { type: 'word', value: '768px' }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 12, value: ' ' }, { type: 'word', value: '-' }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 14, value: ' ' }, { type: 'word', value: '100vw' } ] }, { type: 'div', value: '/', before: ' ', after: ' ' }, { type: 'word', value: '2' } ] }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 26, value: ' ' }, { type: 'word', value: '-' }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 28, value: ' ' }, { type: 'word', value: '15px' } ] } ] @@ -287,9 +287,9 @@ var tests = [{ { type: 'div', value: ':', before: '', after: ' ' }, { type: 'word', value: '700px' } ] }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 18, value: ' ' }, { type: 'word', value: 'and' }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 22, value: ' ' }, { type: 'function', value: '', before: '', after: '', nodes: [ { type: 'word', value: 'orientation' }, { type: 'div', value: ':', before: '', after: ' ' }, @@ -334,11 +334,11 @@ var tests = [{ expected: [ { type: 'function', value: '', before: '', after: '', unclosed: true, nodes: [ { type: 'word', value: '0' }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 2, value: ' ' }, { type: 'word', value: '32' }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 5, value: ' ' }, { type: 'word', value: 'word' }, - { type: 'space', value: ' ' } + { type: 'space', sourceIndex: 10, value: ' ' } ] } ] }, { @@ -348,7 +348,7 @@ var tests = [{ { type: 'function', value: '', before: ' ', after: '', unclosed: true, nodes: [ { type: 'function', value: '', before: ' ', after: '', unclosed: true, nodes: [ { type: 'function', value: '', before: ' ', after: '', nodes: [] }, - { type: 'space', value: ' ' } + { type: 'space', sourceIndex: 7, value: ' ' } ] } ] } ] @@ -357,13 +357,13 @@ var tests = [{ fixture: '0 32 word ) ', expected: [ { type: 'word', value: '0' }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 1, value: ' ' }, { type: 'word', value: '32' }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 4, value: ' ' }, { type: 'word', value: 'word' }, - { type: 'space', value: ' ' }, + { type: 'space', sourceIndex: 9, value: ' ' }, { type: 'word', value: ')' }, - { type: 'space', value: ' ' } + { type: 'space', sourceIndex: 11, value: ' ' } ] }, { message: 'should process escaped spaces as word in fonts', From b434edde32fea949099676ad18a21ef3a1340de4 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Mon, 19 Oct 2015 11:53:30 +0300 Subject: [PATCH 2/5] Added sourceIndex to string node --- lib/parse.js | 2 +- test/parse.js | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index 42fff28..3527398 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -50,7 +50,7 @@ module.exports = function (input) { } else if (code === singleQuote || code === doubleQuote) { next = pos; quote = code === singleQuote ? '\'' : '"'; - token = { type: 'string', quote: quote }; + token = { type: 'string', sourceIndex: pos, quote: quote }; do { escape = false; next = value.indexOf(quote, next + 1); diff --git a/test/parse.js b/test/parse.js index f7ad7d9..34553cb 100644 --- a/test/parse.js +++ b/test/parse.js @@ -123,62 +123,62 @@ var tests = [{ message: 'should process empty quoted strings (")', fixture: '""', expected: [ - { type: 'string', value: '', quote: '"' } + { type: 'string', sourceIndex: 0, value: '', quote: '"' } ] }, { message: 'should process empty quoted strings (\')', fixture: '\'\'', expected: [ - { type: 'string', value: '', quote: '\'' } + { type: 'string', sourceIndex: 0, value: '', quote: '\'' } ] }, { message: 'should process escaped quotes (\')', fixture: '\'word\\\'word\'', expected: [ - { type: 'string', value: 'word\\\'word', quote: '\'' } + { type: 'string', sourceIndex: 0, value: 'word\\\'word', quote: '\'' } ] }, { message: 'should process escaped quotes (\')', fixture: '"word\\"word"', expected: [ - { type: 'string', value: 'word\\"word', quote: '"' } + { type: 'string', sourceIndex: 0, value: 'word\\"word', quote: '"' } ] }, { message: 'should process single quotes inside double quotes (\')', fixture: '"word\'word"', expected: [ - { type: 'string', value: 'word\'word', quote: '"' } + { type: 'string', sourceIndex: 0, value: 'word\'word', quote: '"' } ] }, { message: 'should process double quotes inside single quotes (\')', fixture: '\'word"word\'', expected: [ - { type: 'string', value: 'word"word', quote: '\'' } + { type: 'string', sourceIndex: 0, value: 'word"word', quote: '\'' } ] }, { message: 'should process unclosed quotes', fixture: '"word', expected: [ - { type: 'string', value: 'word', quote: '"', unclosed: true } + { type: 'string', sourceIndex: 0, value: 'word', quote: '"', unclosed: true } ] }, { message: 'should process unclosed quotes with ended backslash', fixture: '"word\\', expected: [ - { type: 'string', value: 'word\\', quote: '"', unclosed: true } + { type: 'string', sourceIndex: 0, value: 'word\\', quote: '"', unclosed: true } ] }, { message: 'should process quoted strings', fixture: '"string"', expected: [ - { type: 'string', value: 'string', quote: '"' } + { type: 'string', sourceIndex: 0, value: 'string', quote: '"' } ] }, { message: 'should process quoted strings and words', fixture: 'word1"string"word2', expected: [ { type: 'word', value: 'word1' }, - { type: 'string', value: 'string', quote: '"' }, + { type: 'string', sourceIndex: 5, value: 'string', quote: '"' }, { type: 'word', value: 'word2' } ] }, { @@ -186,7 +186,7 @@ var tests = [{ fixture: ' "string" ', expected: [ { type: 'space', sourceIndex: 0, value: ' ' }, - { type: 'string', value: 'string', quote: '"' }, + { type: 'string', sourceIndex: 1, value: 'string', quote: '"' }, { type: 'space', sourceIndex: 9, value: ' ' } ] }, { @@ -209,11 +209,11 @@ var tests = [{ { type: 'div', value: '/' , before: ' \t ', after: '' }, { type: 'word', value: '3' }, { type: 'space', sourceIndex: 21, value: ' ' }, - { type: 'string', value: 'Open Sans', quote: '\'' }, + { type: 'string', sourceIndex: 22, value: 'Open Sans', quote: '\'' }, { type: 'div', value: ',', before: '', after: ' ' }, { type: 'word', value: 'Arial' }, { type: 'div', value: ',', before: '', after: ' ' }, - { type: 'string', value: 'Helvetica Neue', quote: '"' }, + { type: 'string', sourceIndex: 42, value: 'Helvetica Neue', quote: '"' }, { type: 'div', value: ',', before: '', after: ' ' }, { type: 'word', value: 'sans-serif' }, ] @@ -251,7 +251,7 @@ var tests = [{ fixture: 'url( "/gfx/img/bg.jpg" hello )', expected: [ { type: 'function', value: 'url', before: ' ', after: ' ', nodes: [ - { type: 'string', quote: '"', value: '/gfx/img/bg.jpg' }, + { type: 'string', sourceIndex: 5, quote: '"', value: '/gfx/img/bg.jpg' }, { type: 'space', sourceIndex: 22, value: ' ' }, { type: 'word', value: 'hello' } ] } From 238c43585b91fdc935ad248f6088f3e42e9dc0e1 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Mon, 19 Oct 2015 12:08:18 +0300 Subject: [PATCH 3/5] Added sourceIndex to word node --- lib/parse.js | 11 +++--- test/parse.js | 104 +++++++++++++++++++++++++------------------------- 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index 3527398..686acd8 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -41,7 +41,7 @@ module.exports = function (input) { } else if (code === slash || code === comma || code === colon) { before = token; } else { - tokens.push({ type: 'space', value: token, sourceIndex: pos }); + tokens.push({ type: 'space', sourceIndex: pos, value: token }); } pos = next; @@ -114,10 +114,10 @@ module.exports = function (input) { whitespacePos -= 1; code = value.charCodeAt(whitespacePos); } while (code <= 32); - token.nodes = [{ type: 'word', value: value.slice(pos, whitespacePos + 1) }]; + token.nodes = [{ type: 'word', sourceIndex: pos, value: value.slice(pos, whitespacePos + 1) }]; if (token.unclosed && whitespacePos + 1 !== next) { token.after = ''; - token.nodes.push({ type: 'space', value: value.slice(whitespacePos + 1, next), sourceIndex: whitespacePos + 1 }); + token.nodes.push({ type: 'space', sourceIndex: whitespacePos + 1, value: value.slice(whitespacePos + 1, next) }); } else { token.after = value.slice(whitespacePos + 1, next); } @@ -162,13 +162,14 @@ module.exports = function (input) { code === openParentheses || code === closeParentheses && balanced )); token = value.slice(pos, next); - pos = next; if (openParentheses === code) { name = token; } else { - tokens.push({ type: 'word', value: token }); + tokens.push({ type: 'word', sourceIndex: pos, value: token }); } + + pos = next; } } diff --git a/test/parse.js b/test/parse.js index 34553cb..c451062 100644 --- a/test/parse.js +++ b/test/parse.js @@ -9,27 +9,27 @@ var tests = [{ message: 'should process escaped parentheses (open)', fixture: '\\(', expected: [ - { type: 'word', value: '\\(' } + { type: 'word', sourceIndex: 0, value: '\\(' } ] }, { message: 'should process escaped parentheses (close)', fixture: '\\)', expected: [ - { type: 'word', value: '\\)' } + { type: 'word', sourceIndex: 0, value: '\\)' } ] }, { message: 'should process escaped parentheses (both)', fixture: '\\(\\)', expected: [ - { type: 'word', value: '\\(\\)' } + { type: 'word', sourceIndex: 0, value: '\\(\\)' } ] }, { message: 'should process escaped parentheses (both)', fixture: '\\( \\)', expected: [ - { type: 'word', value: '\\(' }, + { type: 'word', sourceIndex: 0, value: '\\(' }, { type: 'space', sourceIndex: 2, value: ' ' }, - { type: 'word', value: '\\)' } + { type: 'word', sourceIndex: 3, value: '\\)' } ] }, { message: 'should process unopened parentheses as word', @@ -37,7 +37,7 @@ var tests = [{ expected: [ { type: 'function', value: '', before: '', after: '', nodes: [] }, { type: 'space', sourceIndex: 2, value: ' ' }, - { type: 'word', value: ')wo)rd)' } + { type: 'word', sourceIndex: 3, value: ')wo)rd)' } ] }, { message: 'should add before prop', @@ -50,7 +50,7 @@ var tests = [{ fixture: '( | )', expected: [ { type: 'function', value: '', before: ' ', after: ' ', nodes: [ - { type: 'word', value: '|' } + { type: 'word', sourceIndex: 2, value: '|' } ] } ] }, { @@ -78,7 +78,7 @@ var tests = [{ { type: 'function', value: '', before: ' ', after: '', nodes: [] } ] } ] }, - { type: 'word', value: 'word' } + { type: 'word', sourceIndex: 13, value: 'word' } ] }, { message: 'should process divider (/)', @@ -177,9 +177,9 @@ var tests = [{ message: 'should process quoted strings and words', fixture: 'word1"string"word2', expected: [ - { type: 'word', value: 'word1' }, + { type: 'word', sourceIndex: 0, value: 'word1' }, { type: 'string', sourceIndex: 5, value: 'string', quote: '"' }, - { type: 'word', value: 'word2' } + { type: 'word', sourceIndex: 13, value: 'word2' } ] }, { message: 'should process quoted strings and spaces', @@ -194,39 +194,39 @@ var tests = [{ fixture: ' \\"word\\\'\\ \\\t ', expected: [ { type: 'space', sourceIndex: 0, value: ' ' }, - { type: 'word', value: '\\"word\\\'\\ \\\t'}, + { type: 'word', sourceIndex: 1, value: '\\"word\\\'\\ \\\t'}, { type: 'space', sourceIndex: 13, value: ' ' } ] }, { message: 'should correctly proceess font value', fixture: 'bold italic 12px \t /3 \'Open Sans\', Arial, "Helvetica Neue", sans-serif', expected: [ - { type: 'word', value: 'bold' }, + { type: 'word', sourceIndex: 0, value: 'bold' }, { type: 'space', sourceIndex: 4, value: ' ' }, - { type: 'word', value: 'italic' }, + { type: 'word', sourceIndex: 5, value: 'italic' }, { type: 'space', sourceIndex: 11, value: ' ' }, - { type: 'word', value: '12px' }, + { type: 'word', sourceIndex: 12, value: '12px' }, { type: 'div', value: '/' , before: ' \t ', after: '' }, - { type: 'word', value: '3' }, + { type: 'word', sourceIndex: 20, value: '3' }, { type: 'space', sourceIndex: 21, value: ' ' }, { type: 'string', sourceIndex: 22, value: 'Open Sans', quote: '\'' }, { type: 'div', value: ',', before: '', after: ' ' }, - { type: 'word', value: 'Arial' }, + { type: 'word', sourceIndex: 35, value: 'Arial' }, { type: 'div', value: ',', before: '', after: ' ' }, { type: 'string', sourceIndex: 42, value: 'Helvetica Neue', quote: '"' }, { type: 'div', value: ',', before: '', after: ' ' }, - { type: 'word', value: 'sans-serif' }, + { type: 'word', sourceIndex: 60, value: 'sans-serif' }, ] }, { message: 'should correctly proceess color value', fixture: 'rgba( 29, 439 , 29 )', expected: [ { type: 'function', value: 'rgba', before: ' ', after: ' ', nodes: [ - { type: 'word', value: '29' }, - { type: 'div', value: ',', before: '', after: ' ' }, - { type: 'word', value: '439' }, - { type: 'div', value: ',', before: ' ', after: ' ' }, - { type: 'word', value: '29' }, + { type: 'word', sourceIndex: 6, value: '29' }, + { type: 'div', value: ',', before: '', after: ' ' }, + { type: 'word', sourceIndex: 10, value: '439' }, + { type: 'div', value: ',', before: ' ', after: ' ' }, + { type: 'word', sourceIndex: 16, value: '29' }, ] } ] }, { @@ -234,7 +234,7 @@ var tests = [{ fixture: 'url( /gfx/img/bg.jpg )', expected: [ { type: 'function', value: 'url', before: ' ', after: ' ', nodes: [ - { type: 'word', value: '/gfx/img/bg.jpg' } + { type: 'word', sourceIndex: 5, value: '/gfx/img/bg.jpg' } ] } ] }, { @@ -242,7 +242,7 @@ var tests = [{ fixture: 'url( /gfx/img/bg.jpg ', expected: [ { type: 'function', value: 'url', before: ' ', after: '', unclosed: true, nodes: [ - { type: 'word', value: '/gfx/img/bg.jpg' }, + { type: 'word', sourceIndex: 5, value: '/gfx/img/bg.jpg' }, { type: 'space', sourceIndex: 20, value: ' ' } ] } ] @@ -253,7 +253,7 @@ var tests = [{ { type: 'function', value: 'url', before: ' ', after: ' ', nodes: [ { type: 'string', sourceIndex: 5, quote: '"', value: '/gfx/img/bg.jpg' }, { type: 'space', sourceIndex: 22, value: ' ' }, - { type: 'word', value: 'hello' } + { type: 'word', sourceIndex: 23, value: 'hello' } ] } ] }, { @@ -263,19 +263,19 @@ var tests = [{ {type: 'function', value: 'calc', before: '', after: '', nodes: [ { type: 'function', value: '', before: '', after: '', nodes: [ { type: 'function', value: '', before: '', after: '', nodes: [ - { type: 'word', value: '768px' }, + { type: 'word', sourceIndex: 7, value: '768px' }, { type: 'space', sourceIndex: 12, value: ' ' }, - { type: 'word', value: '-' }, + { type: 'word', sourceIndex: 13, value: '-' }, { type: 'space', sourceIndex: 14, value: ' ' }, - { type: 'word', value: '100vw' } + { type: 'word', sourceIndex: 15, value: '100vw' } ] }, { type: 'div', value: '/', before: ' ', after: ' ' }, - { type: 'word', value: '2' } + { type: 'word', sourceIndex: 24, value: '2' } ] }, { type: 'space', sourceIndex: 26, value: ' ' }, - { type: 'word', value: '-' }, + { type: 'word', sourceIndex: 27, value: '-' }, { type: 'space', sourceIndex: 28, value: ' ' }, - { type: 'word', value: '15px' } + { type: 'word', sourceIndex: 29, value: '15px' } ] } ] }, { @@ -283,17 +283,17 @@ var tests = [{ fixture: '(min-width: 700px) and (orientation: \\$landscape)', expected: [ { type: 'function', value: '', before: '', after: '', nodes: [ - { type: 'word', value: 'min-width' }, + { type: 'word', sourceIndex: 1, value: 'min-width' }, { type: 'div', value: ':', before: '', after: ' ' }, - { type: 'word', value: '700px' } + { type: 'word', sourceIndex: 12, value: '700px' } ] }, { type: 'space', sourceIndex: 18, value: ' ' }, - { type: 'word', value: 'and' }, + { type: 'word', sourceIndex: 19, value: 'and' }, { type: 'space', sourceIndex: 22, value: ' ' }, { type: 'function', value: '', before: '', after: '', nodes: [ - { type: 'word', value: 'orientation' }, + { type: 'word', sourceIndex: 24, value: 'orientation' }, { type: 'div', value: ':', before: '', after: ' ' }, - { type: 'word', value: '\\$landscape' } + { type: 'word', sourceIndex: 37, value: '\\$landscape' } ] } ] }, { @@ -301,7 +301,7 @@ var tests = [{ fixture: 'url( http://website.com/assets\\)_test )', expected: [ { type: 'function', value: 'url', before: ' ', after: ' ', nodes: [ - { type: 'word', value: 'http://website.com/assets\\)_test' } + { type: 'word', sourceIndex: 5, value: 'http://website.com/assets\\)_test' } ] } ] }, { @@ -310,22 +310,22 @@ var tests = [{ expected: [ { type: 'function', value: 'fn1', before: '', after: '', nodes: [ { type: 'function', value: 'fn2', before: '', after: '', nodes: [ - { type: 'word', value: '255' } + { type: 'word', sourceIndex: 8, value: '255' } ] }, { type: 'div', value: ',', before: '', after: ' ' }, { type: 'function', value: 'fn3', before: '', after: '', nodes: [ - { type: 'word', value: '.2' } + { type: 'word', sourceIndex: 18, value: '.2' } ] }, ] }, { type: 'div', value: ',', before: '', after: ' ' }, { type: 'function', value: 'fn4', before: '', after: '', nodes: [ { type: 'function', value: 'fn5', before: '', after: '', nodes: [ - { type: 'word', value: '255' }, + { type: 'word', sourceIndex: 32, value: '255' }, { type: 'div', value: ',', before: '', after: '' }, - { type: 'word', value: '.2' } + { type: 'word', sourceIndex: 36, value: '.2' } ] }, { type: 'div', value: ',', before: '', after: ' '}, - { type: 'word', value: 'fn6' } + { type: 'word', sourceIndex: 41, value: 'fn6' } ] } ] }, { @@ -333,11 +333,11 @@ var tests = [{ fixture: '(0 32 word ', expected: [ { type: 'function', value: '', before: '', after: '', unclosed: true, nodes: [ - { type: 'word', value: '0' }, + { type: 'word', sourceIndex: 1, value: '0' }, { type: 'space', sourceIndex: 2, value: ' ' }, - { type: 'word', value: '32' }, + { type: 'word', sourceIndex: 3, value: '32' }, { type: 'space', sourceIndex: 5, value: ' ' }, - { type: 'word', value: 'word' }, + { type: 'word', sourceIndex: 6, value: 'word' }, { type: 'space', sourceIndex: 10, value: ' ' } ] } ] @@ -356,31 +356,31 @@ var tests = [{ message: 'shouldn\'t throw an error on unopened function', fixture: '0 32 word ) ', expected: [ - { type: 'word', value: '0' }, + { type: 'word', sourceIndex: 0, value: '0' }, { type: 'space', sourceIndex: 1, value: ' ' }, - { type: 'word', value: '32' }, + { type: 'word', sourceIndex: 2, value: '32' }, { type: 'space', sourceIndex: 4, value: ' ' }, - { type: 'word', value: 'word' }, + { type: 'word', sourceIndex: 5, value: 'word' }, { type: 'space', sourceIndex: 9, value: ' ' }, - { type: 'word', value: ')' }, + { type: 'word', sourceIndex: 10, value: ')' }, { type: 'space', sourceIndex: 11, value: ' ' } ] }, { message: 'should process escaped spaces as word in fonts', fixture: 'Bond\\ 007', expected: [ - { type: 'word', value: 'Bond\\ 007' } + { type: 'word', sourceIndex: 0, value: 'Bond\\ 007' } ] }, { message: 'should parse double url and comma', fixture: 'url(foo/bar.jpg), url(http://website.com/img.jpg)', expected: [ { type: 'function', value: 'url', before: '', after: '', nodes: [ - { type: 'word', value: 'foo/bar.jpg' } + { type: 'word', sourceIndex: 4, value: 'foo/bar.jpg' } ] }, { type: 'div', value: ',', before: '', after: ' ' }, { type: 'function', value: 'url', before: '', after: '', nodes: [ - { type: 'word', value: 'http://website.com/img.jpg' } + { type: 'word', sourceIndex: 22, value: 'http://website.com/img.jpg' } ] }, ] }]; From e8a4aa0ca6aca8f21a16857c886a9db1a349da32 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Mon, 19 Oct 2015 12:41:43 +0300 Subject: [PATCH 4/5] Added sourceIndex to function node --- lib/parse.js | 2 +- test/index.js | 26 ++++++++++----------- test/parse.js | 64 +++++++++++++++++++++++++-------------------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index 686acd8..47a7274 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -89,7 +89,7 @@ module.exports = function (input) { next += 1; code = value.charCodeAt(next); } while (code <= 32); - token = { type: 'function', value: name, before: value.slice(pos + 1, next) }; + token = { type: 'function', sourceIndex: pos - name.length, value: name, before: value.slice(pos + 1, next) }; pos = next; if (name === 'url' && code !== singleQuote && code !== doubleQuote) { diff --git a/test/index.js b/test/index.js index 6bee28a..cba2523 100644 --- a/test/index.js +++ b/test/index.js @@ -28,11 +28,11 @@ test('ValueParser', function (t) { }); t.deepEqual(result, [ - { type: 'function', value: 'fn', before: ' ', after: '', nodes: [] }, - { type: 'function', value: 'fn2', before: ' ', after: '', nodes: [ - { type: 'function', value: 'fn3', before: '', after: '', nodes: [] } + { type: 'function', sourceIndex: 0, value: 'fn', before: ' ', after: '', nodes: [] }, + { type: 'function', sourceIndex: 6, value: 'fn2', before: ' ', after: '', nodes: [ + { type: 'function', sourceIndex: 11, value: 'fn3', before: '', after: '', nodes: [] } ] }, - { type: 'function', value: 'fn3', before: '', after: '', nodes: [] }, + { type: 'function', sourceIndex: 11, value: 'fn3', before: '', after: '', nodes: [] }, ], 'should process all functions'); @@ -48,9 +48,9 @@ test('ValueParser', function (t) { }); t.deepEqual(result, [ - { type: 'function', value: 'fn', before: ' ', after: '', nodes: [] }, - { type: 'function', value: 'fn2', before: ' ', after: '', nodes: [ - { type: 'function', value: 'fn3', before: '', after: '', nodes: [] } + { type: 'function', sourceIndex: 0, value: 'fn', before: ' ', after: '', nodes: [] }, + { type: 'function', sourceIndex: 6, value: 'fn2', before: ' ', after: '', nodes: [ + { type: 'function', sourceIndex: 11, value: 'fn3', before: '', after: '', nodes: [] } ] }, ], 'shouldn\'t process functions after falsy callback'); @@ -65,10 +65,10 @@ test('ValueParser', function (t) { }); t.deepEqual(result, [ - { type: 'function', value: 'fn', before: ' ', after: '', nodes: [] }, + { type: 'function', sourceIndex: 0, value: 'fn', before: ' ', after: '', nodes: [] }, { type: 'space', sourceIndex: 5, value: ' '}, - { type: 'word', value: 'fn2', before: ' ', after: '', nodes: [ - { type: 'function', value: 'fn3', before: '', after: '', nodes: [] } + { type: 'word', sourceIndex: 6, value: 'fn2', before: ' ', after: '', nodes: [ + { type: 'function', sourceIndex: 11, value: 'fn3', before: '', after: '', nodes: [] } ] }, ], 'shouldn\'t process nodes with defined non-function type'); @@ -82,9 +82,9 @@ test('ValueParser', function (t) { }, true); t.deepEqual(result, [ - { type: 'function', value: 'fn3', before: '', after: '', nodes: [] }, - { type: 'function', value: 'fn2', before: ' ', after: '', nodes: [ - { type: 'function', value: 'fn3', before: '', after: '', nodes: [] } + { type: 'function', sourceIndex: 5, value: 'fn3', before: '', after: '', nodes: [] }, + { type: 'function', sourceIndex: 0, value: 'fn2', before: ' ', after: '', nodes: [ + { type: 'function', sourceIndex: 5, value: 'fn3', before: '', after: '', nodes: [] } ] }, ], 'should process all functions with reverse mode'); }); diff --git a/test/parse.js b/test/parse.js index c451062..ac2f0df 100644 --- a/test/parse.js +++ b/test/parse.js @@ -35,7 +35,7 @@ var tests = [{ message: 'should process unopened parentheses as word', fixture: '() )wo)rd)', expected: [ - { type: 'function', value: '', before: '', after: '', nodes: [] }, + { type: 'function', sourceIndex: 0, value: '', before: '', after: '', nodes: [] }, { type: 'space', sourceIndex: 2, value: ' ' }, { type: 'word', sourceIndex: 3, value: ')wo)rd)' } ] @@ -43,13 +43,13 @@ var tests = [{ message: 'should add before prop', fixture: '( )', expected: [ - { type: 'function', value: '', before: ' ', after: '', nodes: [] } + { type: 'function', sourceIndex: 0, value: '', before: ' ', after: '', nodes: [] } ] }, { message: 'should add before and after prop', fixture: '( | )', expected: [ - { type: 'function', value: '', before: ' ', after: ' ', nodes: [ + { type: 'function', sourceIndex: 0, value: '', before: ' ', after: ' ', nodes: [ { type: 'word', sourceIndex: 2, value: '|' } ] } ] @@ -57,15 +57,15 @@ var tests = [{ message: 'should add value prop', fixture: 'name()', expected: [ - { type: 'function', value: 'name', before: '', after: '', nodes: [] } + { type: 'function', sourceIndex: 0, value: 'name', before: '', after: '', nodes: [] } ] }, { message: 'should process nested functions', fixture: '((()))', expected: [ - { type: 'function', value: '', before: '', after: '', nodes: [ - { type: 'function', value: '', before: '', after: '', nodes: [ - { type: 'function', value: '', before: '', after: '', nodes: [] } + { type: 'function', sourceIndex: 0, value: '', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 1, value: '', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 2, value: '', before: '', after: '', nodes: [] } ] } ] } ] @@ -73,9 +73,9 @@ var tests = [{ message: 'should process advanced nested functions', fixture: '( calc(( ) ))word', expected: [ - { type: 'function', value: '', before: ' ', after: '', nodes: [ - { type: 'function', value: 'calc', before: '', after: ' ', nodes: [ - { type: 'function', value: '', before: ' ', after: '', nodes: [] } + { type: 'function', sourceIndex: 0, value: '', before: ' ', after: '', nodes: [ + { type: 'function', sourceIndex: 2, value: 'calc', before: '', after: ' ', nodes: [ + { type: 'function', sourceIndex: 7, value: '', before: ' ', after: '', nodes: [] } ] } ] }, { type: 'word', sourceIndex: 13, value: 'word' } @@ -108,7 +108,7 @@ var tests = [{ message: 'should process divider in function', fixture: '( , )', expected: [ - { type: 'function', value: '', before: ' ', after: ' ', nodes: [ + { type: 'function', sourceIndex: 0, value: '', before: ' ', after: ' ', nodes: [ { type: 'div', value: ',', before: '', after: '' } ] } ] @@ -221,7 +221,7 @@ var tests = [{ message: 'should correctly proceess color value', fixture: 'rgba( 29, 439 , 29 )', expected: [ - { type: 'function', value: 'rgba', before: ' ', after: ' ', nodes: [ + { type: 'function', sourceIndex: 0, value: 'rgba', before: ' ', after: ' ', nodes: [ { type: 'word', sourceIndex: 6, value: '29' }, { type: 'div', value: ',', before: '', after: ' ' }, { type: 'word', sourceIndex: 10, value: '439' }, @@ -233,7 +233,7 @@ var tests = [{ message: 'should correctly process url function', fixture: 'url( /gfx/img/bg.jpg )', expected: [ - { type: 'function', value: 'url', before: ' ', after: ' ', nodes: [ + { type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [ { type: 'word', sourceIndex: 5, value: '/gfx/img/bg.jpg' } ] } ] @@ -241,7 +241,7 @@ var tests = [{ message: 'should add unclosed: true prop for url function', fixture: 'url( /gfx/img/bg.jpg ', expected: [ - { type: 'function', value: 'url', before: ' ', after: '', unclosed: true, nodes: [ + { type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: '', unclosed: true, nodes: [ { type: 'word', sourceIndex: 5, value: '/gfx/img/bg.jpg' }, { type: 'space', sourceIndex: 20, value: ' ' } ] } @@ -250,7 +250,7 @@ var tests = [{ message: 'should correctly process url function with quoted first argument', fixture: 'url( "/gfx/img/bg.jpg" hello )', expected: [ - { type: 'function', value: 'url', before: ' ', after: ' ', nodes: [ + { type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [ { type: 'string', sourceIndex: 5, quote: '"', value: '/gfx/img/bg.jpg' }, { type: 'space', sourceIndex: 22, value: ' ' }, { type: 'word', sourceIndex: 23, value: 'hello' } @@ -260,9 +260,9 @@ var tests = [{ message: 'should correctly process nested calc functions', fixture: 'calc(((768px - 100vw) / 2) - 15px)', expected: [ - {type: 'function', value: 'calc', before: '', after: '', nodes: [ - { type: 'function', value: '', before: '', after: '', nodes: [ - { type: 'function', value: '', before: '', after: '', nodes: [ + {type: 'function', sourceIndex: 0, value: 'calc', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 5, value: '', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 6, value: '', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 7, value: '768px' }, { type: 'space', sourceIndex: 12, value: ' ' }, { type: 'word', sourceIndex: 13, value: '-' }, @@ -282,7 +282,7 @@ var tests = [{ message: 'should process colons with params', fixture: '(min-width: 700px) and (orientation: \\$landscape)', expected: [ - { type: 'function', value: '', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 0, value: '', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 1, value: 'min-width' }, { type: 'div', value: ':', before: '', after: ' ' }, { type: 'word', sourceIndex: 12, value: '700px' } @@ -290,7 +290,7 @@ var tests = [{ { type: 'space', sourceIndex: 18, value: ' ' }, { type: 'word', sourceIndex: 19, value: 'and' }, { type: 'space', sourceIndex: 22, value: ' ' }, - { type: 'function', value: '', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 23, value: '', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 24, value: 'orientation' }, { type: 'div', value: ':', before: '', after: ' ' }, { type: 'word', sourceIndex: 37, value: '\\$landscape' } @@ -300,7 +300,7 @@ var tests = [{ message: 'should escape parentheses with backslash', fixture: 'url( http://website.com/assets\\)_test )', expected: [ - { type: 'function', value: 'url', before: ' ', after: ' ', nodes: [ + { type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [ { type: 'word', sourceIndex: 5, value: 'http://website.com/assets\\)_test' } ] } ] @@ -308,18 +308,18 @@ var tests = [{ message: 'should parse parentheses correctly', fixture: 'fn1(fn2(255), fn3(.2)), fn4(fn5(255,.2), fn6)', expected: [ - { type: 'function', value: 'fn1', before: '', after: '', nodes: [ - { type: 'function', value: 'fn2', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 0, value: 'fn1', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 4, value: 'fn2', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 8, value: '255' } ] }, { type: 'div', value: ',', before: '', after: ' ' }, - { type: 'function', value: 'fn3', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 14, value: 'fn3', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 18, value: '.2' } ] }, ] }, { type: 'div', value: ',', before: '', after: ' ' }, - { type: 'function', value: 'fn4', before: '', after: '', nodes: [ - { type: 'function', value: 'fn5', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 24, value: 'fn4', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 28, value: 'fn5', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 32, value: '255' }, { type: 'div', value: ',', before: '', after: '' }, { type: 'word', sourceIndex: 36, value: '.2' } @@ -332,7 +332,7 @@ var tests = [{ message: 'shouldn\'t throw an error on unclosed function', fixture: '(0 32 word ', expected: [ - { type: 'function', value: '', before: '', after: '', unclosed: true, nodes: [ + { type: 'function', sourceIndex: 0, value: '', before: '', after: '', unclosed: true, nodes: [ { type: 'word', sourceIndex: 1, value: '0' }, { type: 'space', sourceIndex: 2, value: ' ' }, { type: 'word', sourceIndex: 3, value: '32' }, @@ -345,9 +345,9 @@ var tests = [{ message: 'should add unclosed: true prop for every unclosed function', fixture: '( ( ( ) ', expected: [ - { type: 'function', value: '', before: ' ', after: '', unclosed: true, nodes: [ - { type: 'function', value: '', before: ' ', after: '', unclosed: true, nodes: [ - { type: 'function', value: '', before: ' ', after: '', nodes: [] }, + { type: 'function', sourceIndex: 0, value: '', before: ' ', after: '', unclosed: true, nodes: [ + { type: 'function', sourceIndex: 2, value: '', before: ' ', after: '', unclosed: true, nodes: [ + { type: 'function', sourceIndex: 4, value: '', before: ' ', after: '', nodes: [] }, { type: 'space', sourceIndex: 7, value: ' ' } ] } ] } @@ -375,11 +375,11 @@ var tests = [{ message: 'should parse double url and comma', fixture: 'url(foo/bar.jpg), url(http://website.com/img.jpg)', expected: [ - { type: 'function', value: 'url', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 0, value: 'url', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 4, value: 'foo/bar.jpg' } ] }, { type: 'div', value: ',', before: '', after: ' ' }, - { type: 'function', value: 'url', before: '', after: '', nodes: [ + { type: 'function', sourceIndex: 18, value: 'url', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 22, value: 'http://website.com/img.jpg' } ] }, ] From 68bf8dff4541307749b610e735c8fb123bd9ede9 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Mon, 19 Oct 2015 15:49:22 +0300 Subject: [PATCH 5/5] Added sourceIndex to div node --- lib/parse.js | 7 ++++--- test/parse.js | 42 +++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index 47a7274..6fca2e0 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -75,12 +75,13 @@ module.exports = function (input) { // Dividers } else if (code === slash || code === comma || code === colon) { token = value[pos]; - pos += 1; - code = value.charCodeAt(pos); - tokens.push({ type: 'div', value: token, before: before, after: '' }); + tokens.push({ type: 'div', sourceIndex: pos - before.length, value: token, before: before, after: '' }); before = ''; + pos += 1; + code = value.charCodeAt(pos); + // Open parentheses } else if (openParentheses === code) { // Whitespaces after open parentheses diff --git a/test/parse.js b/test/parse.js index ac2f0df..5989448 100644 --- a/test/parse.js +++ b/test/parse.js @@ -84,40 +84,40 @@ var tests = [{ message: 'should process divider (/)', fixture: '/', expected: [ - { type: 'div', value: '/', before: '', after: '' } + { type: 'div', sourceIndex: 0, value: '/', before: '', after: '' } ] }, { message: 'should process divider (:)', fixture: ':', expected: [ - { type: 'div', value: ':', before: '', after: '' } + { type: 'div', sourceIndex: 0, value: ':', before: '', after: '' } ] }, { message: 'should process divider (,)', fixture: ',', expected: [ - { type: 'div', value: ',', before: '', after: '' } + { type: 'div', sourceIndex: 0, value: ',', before: '', after: '' } ] }, { message: 'should process complex divider', fixture: ' , ', expected: [ - { type: 'div', value: ',', before: ' ', after: ' ' } + { type: 'div', sourceIndex: 0, value: ',', before: ' ', after: ' ' } ] }, { message: 'should process divider in function', fixture: '( , )', expected: [ { type: 'function', sourceIndex: 0, value: '', before: ' ', after: ' ', nodes: [ - { type: 'div', value: ',', before: '', after: '' } + { type: 'div', sourceIndex: 2, value: ',', before: '', after: '' } ] } ] }, { message: 'should process two spaced divider', fixture: ' , : ', expected: [ - { type: 'div', value: ',', before: ' ', after: ' ' }, - { type: 'div', value: ':', before: '', after: ' ' } + { type: 'div', sourceIndex: 0, value: ',', before: ' ', after: ' ' }, + { type: 'div', sourceIndex: 3, value: ':', before: '', after: ' ' } ] }, { message: 'should process empty quoted strings (")', @@ -206,15 +206,15 @@ var tests = [{ { type: 'word', sourceIndex: 5, value: 'italic' }, { type: 'space', sourceIndex: 11, value: ' ' }, { type: 'word', sourceIndex: 12, value: '12px' }, - { type: 'div', value: '/' , before: ' \t ', after: '' }, + { type: 'div', sourceIndex: 16, value: '/' , before: ' \t ', after: '' }, { type: 'word', sourceIndex: 20, value: '3' }, { type: 'space', sourceIndex: 21, value: ' ' }, { type: 'string', sourceIndex: 22, value: 'Open Sans', quote: '\'' }, - { type: 'div', value: ',', before: '', after: ' ' }, + { type: 'div', sourceIndex: 33, value: ',', before: '', after: ' ' }, { type: 'word', sourceIndex: 35, value: 'Arial' }, - { type: 'div', value: ',', before: '', after: ' ' }, + { type: 'div', sourceIndex: 40, value: ',', before: '', after: ' ' }, { type: 'string', sourceIndex: 42, value: 'Helvetica Neue', quote: '"' }, - { type: 'div', value: ',', before: '', after: ' ' }, + { type: 'div', sourceIndex: 58, value: ',', before: '', after: ' ' }, { type: 'word', sourceIndex: 60, value: 'sans-serif' }, ] }, { @@ -223,9 +223,9 @@ var tests = [{ expected: [ { type: 'function', sourceIndex: 0, value: 'rgba', before: ' ', after: ' ', nodes: [ { type: 'word', sourceIndex: 6, value: '29' }, - { type: 'div', value: ',', before: '', after: ' ' }, + { type: 'div', sourceIndex: 8, value: ',', before: '', after: ' ' }, { type: 'word', sourceIndex: 10, value: '439' }, - { type: 'div', value: ',', before: ' ', after: ' ' }, + { type: 'div', sourceIndex: 13, value: ',', before: ' ', after: ' ' }, { type: 'word', sourceIndex: 16, value: '29' }, ] } ] @@ -269,7 +269,7 @@ var tests = [{ { type: 'space', sourceIndex: 14, value: ' ' }, { type: 'word', sourceIndex: 15, value: '100vw' } ] }, - { type: 'div', value: '/', before: ' ', after: ' ' }, + { type: 'div', sourceIndex: 21, value: '/', before: ' ', after: ' ' }, { type: 'word', sourceIndex: 24, value: '2' } ] }, { type: 'space', sourceIndex: 26, value: ' ' }, @@ -284,7 +284,7 @@ var tests = [{ expected: [ { type: 'function', sourceIndex: 0, value: '', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 1, value: 'min-width' }, - { type: 'div', value: ':', before: '', after: ' ' }, + { type: 'div', sourceIndex: 10, value: ':', before: '', after: ' ' }, { type: 'word', sourceIndex: 12, value: '700px' } ] }, { type: 'space', sourceIndex: 18, value: ' ' }, @@ -292,7 +292,7 @@ var tests = [{ { type: 'space', sourceIndex: 22, value: ' ' }, { type: 'function', sourceIndex: 23, value: '', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 24, value: 'orientation' }, - { type: 'div', value: ':', before: '', after: ' ' }, + { type: 'div', sourceIndex: 35, value: ':', before: '', after: ' ' }, { type: 'word', sourceIndex: 37, value: '\\$landscape' } ] } ] @@ -312,19 +312,19 @@ var tests = [{ { type: 'function', sourceIndex: 4, value: 'fn2', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 8, value: '255' } ] }, - { type: 'div', value: ',', before: '', after: ' ' }, + { type: 'div', sourceIndex: 12, value: ',', before: '', after: ' ' }, { type: 'function', sourceIndex: 14, value: 'fn3', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 18, value: '.2' } ] }, ] }, - { type: 'div', value: ',', before: '', after: ' ' }, + { type: 'div', sourceIndex: 22, value: ',', before: '', after: ' ' }, { type: 'function', sourceIndex: 24, value: 'fn4', before: '', after: '', nodes: [ { type: 'function', sourceIndex: 28, value: 'fn5', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 32, value: '255' }, - { type: 'div', value: ',', before: '', after: '' }, + { type: 'div', sourceIndex: 35, value: ',', before: '', after: '' }, { type: 'word', sourceIndex: 36, value: '.2' } ] }, - { type: 'div', value: ',', before: '', after: ' '}, + { type: 'div', sourceIndex: 39, value: ',', before: '', after: ' '}, { type: 'word', sourceIndex: 41, value: 'fn6' } ] } ] @@ -378,7 +378,7 @@ var tests = [{ { type: 'function', sourceIndex: 0, value: 'url', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 4, value: 'foo/bar.jpg' } ] }, - { type: 'div', value: ',', before: '', after: ' ' }, + { type: 'div', sourceIndex: 16, value: ',', before: '', after: ' ' }, { type: 'function', sourceIndex: 18, value: 'url', before: '', after: '', nodes: [ { type: 'word', sourceIndex: 22, value: 'http://website.com/img.jpg' } ] },