From c6bfbf65b557c64245397f48101190899194be9d Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Fri, 18 Nov 2016 14:40:35 +0000 Subject: [PATCH 1/2] [sass] Improve URI node --- src/sass/parse.js | 300 +++++++++++++++++++++++++++--------- src/sass/tokenizer.js | 3 +- test/sass/uri/3.json | 22 ++- test/sass/uri/3.sass | 2 +- test/sass/uri/4.json | 107 +++++++++++++ test/sass/uri/4.sass | 1 + test/sass/uri/5.json | 93 +++++++++++ test/sass/uri/5.sass | 1 + test/sass/uri/6.json | 93 +++++++++++ test/sass/uri/6.sass | 1 + test/sass/uri/7.json | 106 +++++++++++++ test/sass/uri/7.sass | 1 + test/sass/uri/8.json | 120 +++++++++++++++ test/sass/uri/8.sass | 1 + test/sass/uri/9.json | 133 ++++++++++++++++ test/sass/uri/9.sass | 1 + test/sass/uri/c.0.json | 53 +++++++ test/sass/uri/c.0.sass | 1 + test/sass/uri/c.1.json | 53 +++++++ test/sass/uri/c.1.sass | 1 + test/sass/uri/interp.0.json | 27 ++++ test/sass/uri/interp.0.sass | 1 + test/sass/uri/interp.1.json | 55 +++++++ test/sass/uri/interp.1.sass | 1 + test/sass/uri/interp.2.json | 68 ++++++++ test/sass/uri/interp.2.sass | 1 + test/sass/uri/interp.3.json | 68 ++++++++ test/sass/uri/interp.3.sass | 1 + test/sass/uri/interp.4.json | 121 +++++++++++++++ test/sass/uri/interp.4.sass | 1 + test/sass/uri/interp.5.json | 107 +++++++++++++ test/sass/uri/interp.5.sass | 1 + test/sass/uri/test.coffee | 15 ++ 33 files changed, 1479 insertions(+), 81 deletions(-) create mode 100644 test/sass/uri/4.json create mode 100644 test/sass/uri/4.sass create mode 100644 test/sass/uri/5.json create mode 100644 test/sass/uri/5.sass create mode 100644 test/sass/uri/6.json create mode 100644 test/sass/uri/6.sass create mode 100644 test/sass/uri/7.json create mode 100644 test/sass/uri/7.sass create mode 100644 test/sass/uri/8.json create mode 100644 test/sass/uri/8.sass create mode 100644 test/sass/uri/9.json create mode 100644 test/sass/uri/9.sass create mode 100644 test/sass/uri/c.0.json create mode 100644 test/sass/uri/c.0.sass create mode 100644 test/sass/uri/c.1.json create mode 100644 test/sass/uri/c.1.sass create mode 100644 test/sass/uri/interp.0.json create mode 100644 test/sass/uri/interp.0.sass create mode 100644 test/sass/uri/interp.1.json create mode 100644 test/sass/uri/interp.1.sass create mode 100644 test/sass/uri/interp.2.json create mode 100644 test/sass/uri/interp.2.sass create mode 100644 test/sass/uri/interp.3.json create mode 100644 test/sass/uri/interp.3.sass create mode 100644 test/sass/uri/interp.4.json create mode 100644 test/sass/uri/interp.4.sass create mode 100644 test/sass/uri/interp.5.json create mode 100644 test/sass/uri/interp.5.sass diff --git a/src/sass/parse.js b/src/sass/parse.js index 4734fc82..ac2e11c8 100644 --- a/src/sass/parse.js +++ b/src/sass/parse.js @@ -187,21 +187,6 @@ function throwError(opt_i) { throw {line: ln, syntax: 'sass'}; } -/** - * @param {!Object} exclude - * @param {number} i Token's index number - * @return {number} - */ -function checkExcluding(exclude, i) { - var start = i; - - while (i < tokensLength) { - if (exclude[tokens[i++].type]) break; - } - - return i - start - 2; -} - /** * @param {number} start * @param {number} finish @@ -4776,106 +4761,271 @@ function _checkUnicodeWildcard(i) { } /** - * Check if token is part of URI (e.g. `url('/css/styles.css')`) + * Check if token is part of URI, e.g. `url('/css/styles.css')` * @param {number} i Token's index number - * @return {number} Length of URI + * @returns {number} Length of URI */ function checkUri(i) { - var start = i; + const start = i; + let l; - if (i >= tokensLength || tokens[i++].value !== 'url' || - i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) - return 0; + if (i >= tokensLength || tokens[i].value !== 'url') return 0; - return tokens[i].right - start + 1; + // Skip `url` + i++; + + if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) + return 0; + + // Store the opening parenthesis token as we will reference it's `right` + // property to determine when the parentheses close + const leftParenthesis = tokens[i]; + + // Skip `(` + i++; + + // Determine the type of URI + while (i < leftParenthesis.right) { + if (l = checkUri1(i)) { + i += l; + tokens[start].uriType = 1; // Raw based URI (without quotes) + } else if (l = checkUri2(i)) { + i += l; + tokens[start].uriType = 2; // Non-raw based URI (with quotes) + } else return 0; + } + + return i - start; } /** - * Get node with URI - * @return {Array} `['uri', x]` where `x` is URI's nodes (without `url` - * and braces, e.g. `['string', ''/css/styles.css'']`). + * Get specific type of URI node + * @return {Node} Specific type of URI node */ function getUri() { - let startPos = pos; - let uriExcluding = {}; - let uri; - let token; + const uriType = tokens[pos].uriType; + + if (uriType === 1) return getUri1(); + if (uriType === 2) return getUri2(); +} + +/** + * Check if token type is valid URI character + * @param {number} i Token's index number + * @return {number} Length of raw node + */ +function checkUriRawCharacters(i) { + const start = i; let l; - let raw; - pos += 2; + if (l = checkIdent(i)) i += l; + else if (l = checkNumber(i)) i += l; + else { + switch (tokens[i].type) { + case TokenType.ExclamationMark: + case TokenType.NumberSign: + case TokenType.DollarSign: + case TokenType.PercentSign: + case TokenType.Ampersand: + case TokenType.Asterisk: + case TokenType.PlusSign: + case TokenType.Comma: + case TokenType.HyphenMinus: + case TokenType.FullStop: + case TokenType.Solidus: + case TokenType.Colon: + case TokenType.Semicolon: + case TokenType.LessThanSign: + case TokenType.EqualsSign: + case TokenType.GreaterThanSign: + case TokenType.QuotationMark: + case TokenType.CommercialAt: + case TokenType.LeftSquareBracket: + case TokenType.RightSquareBracket: + case TokenType.CircumflexAccent: + case TokenType.LowLine: + case TokenType.LeftCurlyBracket: + case TokenType.VerticalLine: + case TokenType.RightCurlyBracket: + case TokenType.Tilde: + i += 1; + break; + + default: + return 0; + } + } - uriExcluding[TokenType.Space] = 1; - uriExcluding[TokenType.Tab] = 1; - uriExcluding[TokenType.Newline] = 1; - uriExcluding[TokenType.LeftParenthesis] = 1; - uriExcluding[TokenType.RightParenthesis] = 1; - - if (checkUriContent(pos)) { - uri = [] - .concat(getSC()) - .concat(getUriContent()) - .concat(getSC()); - } else { - uri = [].concat(getSC()); - l = checkExcluding(uriExcluding, pos); - token = tokens[pos]; - raw = newNode(NodeType.RawType, joinValues(pos, pos + l), token.ln, - token.col); + return i - start; +} + +/** + * Check if content of URI can be contained within a raw node + * @param {number} i Token's index number + * @return {number} Length of raw node + */ +function checkUriRaw(i) { + const start = i; + let l; - uri.push(raw); + while (i < tokensLength) { + if (checkInterpolation(i) || checkVariable(i)) break; + else if (l = checkUriRawCharacters(i)) i += l; + else break; + } - pos += l + 1; + tokens[start].uri_raw_end = i; - uri = uri.concat(getSC()); + return i - start; +} + +/** + * Get a raw node + * @return {Node} + */ +function getUriRaw() { + const startPos = pos; + const type = NodeType.RawType; + const token = tokens[startPos]; + const line = token.ln; + const column = token.col; + let content = []; + let l; + + while (pos < tokens[startPos].uri_raw_end) { + if (checkInterpolation(pos) || checkVariable(pos)) break; + else if (l = checkUriRawCharacters(pos)) pos += l; + else break; } - token = tokens[startPos]; - var line = token.ln; - var column = token.col; - var end = getLastPosition(uri, line, column, 1); - pos++; + content = joinValues(startPos, pos - 1); - return newNode(NodeType.UriType, uri, token.ln, token.col, end); + return newNode(type, content, line, column); } /** + * Check for a raw (without quotes) URI + * (1) http://foo.com/bar.png + * (2) http://foo.com/#{$bar}.png + * (3) #{$foo}/bar.png + * (4) #{$foo} * @param {number} i Token's index number - * @return {number} + * @return {number} Length of URI node */ -function checkUriContent(i) { - return checkUri1(i) || - checkFunction(i); +function checkUri1(i) { + const start = i; + let l; + + if (l = checkSC(i)) i += l; + + while (i < tokensLength) { + if (l = checkInterpolation(i) || checkUriRaw(i)) i += l; + else break; + } + + if (l = checkSC(i)) i += l; + + // Check that we are at the end of the uri + if (i < tokens[start - 1].right) return 0; + + tokens[start].uri_end = i; + + return i - start; } /** - * @return {Array} + * Get a raw (without quotes) URI + node + * @return {Node} */ -function getUriContent() { - if (checkUri1(pos)) return getString(); - else if (checkFunction(pos)) return getFunction(); +function getUri1() { + const startPos = pos; + const type = NodeType.UriType; + const token = tokens[startPos]; + const line = token.ln; + const column = token.col; + let content = []; + let end; + + // Skip `url` and `(` + pos += 2; + + if (checkSC(pos)) content = content.concat(getSC()); + + while (pos < tokens[startPos + 2].uri_end) { + if (checkInterpolation(pos)) content.push(getInterpolation()); + else if (checkUriRaw(pos)) content.push(getUriRaw()); + else break; + } + + if (checkSC(pos)) content = content.concat(getSC()); + + // Check that we are at the end of the uri + if (pos < tokens[startPos + 1].right) return 0; + + end = getLastPosition(content, line, column, 1); + + // Skip `)` + pos++; + + return newNode(type, content, line, column, end); } /** + * Check for a non-raw (with quotes) URI + * (1) 'http://foo.com/bar.png' + * (2) 'http://foo.com/'#{$bar}.png + * (3) #{$foo}'/bar.png' * @param {number} i Token's index number - * @return {number} + * @return {number} Length of URI node */ -function checkUri1(i) { - let start = i; +function checkUri2(i) { + const start = i; let l; - if (i >= tokensLength) return 0; + while (i < tokensLength) { + if (l = checkSC(i)) i += l; + else if (l = checkString(i)) i += l; + else if (l = checkFunction(i)) i += l; + else if (l = checkUnary(i)) i += l; + else if (l = checkIdentOrInterpolation(i)) i += l; + else if (l = checkVariable(i)) i += l; + else break; + } - if (l = checkSC(i)) i += l; + tokens[start].uri_end = i; - if (tokens[i].type !== TokenType.StringDQ && - tokens[i].type !== TokenType.StringSQ) return 0; + return i - start; +} - i++; +/** + * Get a non-raw (with quotes) URI node + * @return {Node} + */ +function getUri2() { + const startPos = pos; + const token = tokens[startPos]; + const line = token.ln; + const column = token.col; + let content = []; + let end; - if (l = checkSC(i)) i += l; + // Skip `url` and `(` + pos += 2; - return i - start; + while (pos < tokens[startPos + 2].uri_end) { + if (checkSC(pos)) content = content.concat(getSC()); + else if (checkUnary(pos)) content.push(getUnary()); + else if (_checkValue(pos)) content.push(_getValue()); + else break; + } + + end = getLastPosition(content, line, column, 1); + + // Skip `)` + pos++; + + return newNode(NodeType.UriType, content, line, column, end); } /** diff --git a/src/sass/tokenizer.js b/src/sass/tokenizer.js index 0af77633..eaa84938 100644 --- a/src/sass/tokenizer.js +++ b/src/sass/tokenizer.js @@ -48,7 +48,8 @@ module.exports = function(css, tabSize) { '{': TokenType.LeftCurlyBracket, '|': TokenType.VerticalLine, '}': TokenType.RightCurlyBracket, - '~': TokenType.Tilde + '~': TokenType.Tilde, + '`': TokenType.Backtick }; /** diff --git a/test/sass/uri/3.json b/test/sass/uri/3.json index 05c8b251..0cb94e7e 100644 --- a/test/sass/uri/3.json +++ b/test/sass/uri/3.json @@ -2,8 +2,22 @@ "type": "uri", "content": [ { - "type": "raw", - "content": "$v1", + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "sass", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + } + ], "syntax": "sass", "start": { "line": 1, @@ -11,7 +25,7 @@ }, "end": { "line": 1, - "column": 7 + "column": 8 } } ], @@ -22,6 +36,6 @@ }, "end": { "line": 1, - "column": 8 + "column": 9 } } diff --git a/test/sass/uri/3.sass b/test/sass/uri/3.sass index 7d1093c4..b0d71c24 100644 --- a/test/sass/uri/3.sass +++ b/test/sass/uri/3.sass @@ -1 +1 @@ -url($v1) +url($foo) diff --git a/test/sass/uri/4.json b/test/sass/uri/4.json new file mode 100644 index 00000000..36d62d48 --- /dev/null +++ b/test/sass/uri/4.json @@ -0,0 +1,107 @@ +{ + "type": "uri", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "sass", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 9 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "sass", + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "sass", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 15 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 16 + } +} diff --git a/test/sass/uri/4.sass b/test/sass/uri/4.sass new file mode 100644 index 00000000..29c7d9f6 --- /dev/null +++ b/test/sass/uri/4.sass @@ -0,0 +1 @@ +url($foo + $bar) diff --git a/test/sass/uri/5.json b/test/sass/uri/5.json new file mode 100644 index 00000000..570523f0 --- /dev/null +++ b/test/sass/uri/5.json @@ -0,0 +1,93 @@ +{ + "type": "uri", + "content": [ + { + "type": "string", + "content": "'foo/'", + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "sass", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 13 + } + }, + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "sass", + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 17 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 18 + } +} diff --git a/test/sass/uri/5.sass b/test/sass/uri/5.sass new file mode 100644 index 00000000..bcbb2593 --- /dev/null +++ b/test/sass/uri/5.sass @@ -0,0 +1 @@ +url('foo/' + $bar) diff --git a/test/sass/uri/6.json b/test/sass/uri/6.json new file mode 100644 index 00000000..2397be47 --- /dev/null +++ b/test/sass/uri/6.json @@ -0,0 +1,93 @@ +{ + "type": "uri", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "sass", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 9 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "sass", + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "string", + "content": "'bar.png'", + "syntax": "sass", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 20 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 21 + } +} diff --git a/test/sass/uri/6.sass b/test/sass/uri/6.sass new file mode 100644 index 00000000..be40e1f5 --- /dev/null +++ b/test/sass/uri/6.sass @@ -0,0 +1 @@ +url($foo + 'bar.png') diff --git a/test/sass/uri/7.json b/test/sass/uri/7.json new file mode 100644 index 00000000..1f43fd17 --- /dev/null +++ b/test/sass/uri/7.json @@ -0,0 +1,106 @@ +{ + "type": "uri", + "content": [ + { + "type": "string", + "content": "'foo/'", + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "sass", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 13 + } + }, + { + "type": "function", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "sass", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + { + "syntax": "sass", + "type": "arguments", + "content": [], + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 19 + } +} diff --git a/test/sass/uri/7.sass b/test/sass/uri/7.sass new file mode 100644 index 00000000..7de232cb --- /dev/null +++ b/test/sass/uri/7.sass @@ -0,0 +1 @@ +url('foo/' + bar()) diff --git a/test/sass/uri/8.json b/test/sass/uri/8.json new file mode 100644 index 00000000..a9f6f01b --- /dev/null +++ b/test/sass/uri/8.json @@ -0,0 +1,120 @@ +{ + "type": "uri", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "sass", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 9 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "sass", + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "function", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "sass", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + { + "syntax": "sass", + "type": "arguments", + "content": [], + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 16 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 17 + } +} diff --git a/test/sass/uri/8.sass b/test/sass/uri/8.sass new file mode 100644 index 00000000..a1c2aa59 --- /dev/null +++ b/test/sass/uri/8.sass @@ -0,0 +1 @@ +url($foo + bar()) diff --git a/test/sass/uri/9.json b/test/sass/uri/9.json new file mode 100644 index 00000000..32526482 --- /dev/null +++ b/test/sass/uri/9.json @@ -0,0 +1,133 @@ +{ + "type": "uri", + "content": [ + { + "type": "function", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 7 + } + }, + { + "syntax": "sass", + "type": "arguments", + "content": [], + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 9 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "sass", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "function", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "sass", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + { + "syntax": "sass", + "type": "arguments", + "content": [], + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 17 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 18 + } +} diff --git a/test/sass/uri/9.sass b/test/sass/uri/9.sass new file mode 100644 index 00000000..947acea7 --- /dev/null +++ b/test/sass/uri/9.sass @@ -0,0 +1 @@ +url(foo() + bar()) diff --git a/test/sass/uri/c.0.json b/test/sass/uri/c.0.json new file mode 100644 index 00000000..e333c9aa --- /dev/null +++ b/test/sass/uri/c.0.json @@ -0,0 +1,53 @@ +{ + "type": "uri", + "content": [ + { + "type": "multilineComment", + "content": "test", + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "string", + "content": "'http://test.com'", + "syntax": "sass", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 29 + } + }, + { + "type": "multilineComment", + "content": "test", + "syntax": "sass", + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 37 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 38 + } +} \ No newline at end of file diff --git a/test/sass/uri/c.0.sass b/test/sass/uri/c.0.sass new file mode 100644 index 00000000..73354ccd --- /dev/null +++ b/test/sass/uri/c.0.sass @@ -0,0 +1 @@ +url(/*test*/'http://test.com'/*test*/) diff --git a/test/sass/uri/c.1.json b/test/sass/uri/c.1.json new file mode 100644 index 00000000..71fae1e5 --- /dev/null +++ b/test/sass/uri/c.1.json @@ -0,0 +1,53 @@ +{ + "type": "uri", + "content": [ + { + "type": "multilineComment", + "content": "test", + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "raw", + "content": "http://test.com", + "syntax": "sass", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 27 + } + }, + { + "type": "multilineComment", + "content": "test", + "syntax": "sass", + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 35 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 36 + } +} diff --git a/test/sass/uri/c.1.sass b/test/sass/uri/c.1.sass new file mode 100644 index 00000000..015ba6db --- /dev/null +++ b/test/sass/uri/c.1.sass @@ -0,0 +1 @@ +url(/*test*/http://test.com/*test*/) diff --git a/test/sass/uri/interp.0.json b/test/sass/uri/interp.0.json new file mode 100644 index 00000000..07b69ce6 --- /dev/null +++ b/test/sass/uri/interp.0.json @@ -0,0 +1,27 @@ +{ + "type": "uri", + "content": [ + { + "type": "string", + "content": "'#{$foo}'", + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 13 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 14 + } +} diff --git a/test/sass/uri/interp.0.sass b/test/sass/uri/interp.0.sass new file mode 100644 index 00000000..8baf2f97 --- /dev/null +++ b/test/sass/uri/interp.0.sass @@ -0,0 +1 @@ +url('#{$foo}') diff --git a/test/sass/uri/interp.1.json b/test/sass/uri/interp.1.json new file mode 100644 index 00000000..738a52a2 --- /dev/null +++ b/test/sass/uri/interp.1.json @@ -0,0 +1,55 @@ +{ + "type": "uri", + "content": [ + { + "type": "interpolation", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "sass", + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 11 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 12 + } +} diff --git a/test/sass/uri/interp.1.sass b/test/sass/uri/interp.1.sass new file mode 100644 index 00000000..b18014d2 --- /dev/null +++ b/test/sass/uri/interp.1.sass @@ -0,0 +1 @@ +url(#{$foo}) diff --git a/test/sass/uri/interp.2.json b/test/sass/uri/interp.2.json new file mode 100644 index 00000000..892e8631 --- /dev/null +++ b/test/sass/uri/interp.2.json @@ -0,0 +1,68 @@ +{ + "type": "uri", + "content": [ + { + "type": "interpolation", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "sass", + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "raw", + "content": "/bar.png", + "syntax": "sass", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 19 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 20 + } +} diff --git a/test/sass/uri/interp.2.sass b/test/sass/uri/interp.2.sass new file mode 100644 index 00000000..5f514714 --- /dev/null +++ b/test/sass/uri/interp.2.sass @@ -0,0 +1 @@ +url(#{$foo}/bar.png) diff --git a/test/sass/uri/interp.3.json b/test/sass/uri/interp.3.json new file mode 100644 index 00000000..a29829a4 --- /dev/null +++ b/test/sass/uri/interp.3.json @@ -0,0 +1,68 @@ +{ + "type": "uri", + "content": [ + { + "type": "raw", + "content": "foo/", + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + { + "type": "interpolation", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "sass", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 15 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 16 + } +} diff --git a/test/sass/uri/interp.3.sass b/test/sass/uri/interp.3.sass new file mode 100644 index 00000000..1274f4fa --- /dev/null +++ b/test/sass/uri/interp.3.sass @@ -0,0 +1 @@ +url(foo/#{$bar}) diff --git a/test/sass/uri/interp.4.json b/test/sass/uri/interp.4.json new file mode 100644 index 00000000..4d82a002 --- /dev/null +++ b/test/sass/uri/interp.4.json @@ -0,0 +1,121 @@ +{ + "type": "uri", + "content": [ + { + "type": "interpolation", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "sass", + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "sass", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 13 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 14 + } + }, + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "sass", + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 18 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 19 + } +} diff --git a/test/sass/uri/interp.4.sass b/test/sass/uri/interp.4.sass new file mode 100644 index 00000000..4d5b5735 --- /dev/null +++ b/test/sass/uri/interp.4.sass @@ -0,0 +1 @@ +url(#{$foo} + $bar) diff --git a/test/sass/uri/interp.5.json b/test/sass/uri/interp.5.json new file mode 100644 index 00000000..5ef4bd59 --- /dev/null +++ b/test/sass/uri/interp.5.json @@ -0,0 +1,107 @@ +{ + "type": "uri", + "content": [ + { + "type": "string", + "content": "'foo/'", + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "sass", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 13 + } + }, + { + "type": "interpolation", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "sass", + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 19 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 20 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 21 + } +} diff --git a/test/sass/uri/interp.5.sass b/test/sass/uri/interp.5.sass new file mode 100644 index 00000000..28ef7842 --- /dev/null +++ b/test/sass/uri/interp.5.sass @@ -0,0 +1 @@ +url('foo/' + #{$bar}) diff --git a/test/sass/uri/test.coffee b/test/sass/uri/test.coffee index 17c1daa9..c0a641fc 100644 --- a/test/sass/uri/test.coffee +++ b/test/sass/uri/test.coffee @@ -4,6 +4,21 @@ describe 'sass/uri >>', -> it '1', -> this.shouldBeOk() it '2', -> this.shouldBeOk() it '3', -> this.shouldBeOk() + it '4', -> this.shouldBeOk() + it '5', -> this.shouldBeOk() + it '6', -> this.shouldBeOk() + it '7', -> this.shouldBeOk() + it '8', -> this.shouldBeOk() + + it 'interp.0', -> this.shouldBeOk() + it 'interp.1', -> this.shouldBeOk() + it 'interp.2', -> this.shouldBeOk() + it 'interp.3', -> this.shouldBeOk() + it 'interp.4', -> this.shouldBeOk() + it 'interp.5', -> this.shouldBeOk() + + it 'c.0', -> this.shouldBeOk() + it 'c.1', -> this.shouldBeOk() it 's.0', -> this.shouldBeOk() it 's.1', -> this.shouldBeOk() From ca347950a4b7575c4a1590bc3d92ecf6c3042193 Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Fri, 18 Nov 2016 14:40:55 +0000 Subject: [PATCH 2/2] [scss] Improve URI node --- src/scss/parse.js | 308 +++++++++++++++++++++++++++--------- src/scss/tokenizer.js | 3 +- test/scss/uri/3.json | 22 ++- test/scss/uri/3.scss | 2 +- test/scss/uri/4.json | 107 +++++++++++++ test/scss/uri/4.scss | 1 + test/scss/uri/5.json | 93 +++++++++++ test/scss/uri/5.scss | 1 + test/scss/uri/6.json | 93 +++++++++++ test/scss/uri/6.scss | 1 + test/scss/uri/7.json | 106 +++++++++++++ test/scss/uri/7.scss | 1 + test/scss/uri/8.json | 120 ++++++++++++++ test/scss/uri/8.scss | 1 + test/scss/uri/9.json | 133 ++++++++++++++++ test/scss/uri/9.scss | 1 + test/scss/uri/c.1.json | 17 +- test/scss/uri/interp.0.json | 27 ++++ test/scss/uri/interp.0.scss | 1 + test/scss/uri/interp.1.json | 55 +++++++ test/scss/uri/interp.1.scss | 1 + test/scss/uri/interp.2.json | 68 ++++++++ test/scss/uri/interp.2.scss | 1 + test/scss/uri/interp.3.json | 68 ++++++++ test/scss/uri/interp.3.scss | 1 + test/scss/uri/interp.4.json | 121 ++++++++++++++ test/scss/uri/interp.4.scss | 1 + test/scss/uri/interp.5.json | 107 +++++++++++++ test/scss/uri/interp.5.scss | 1 + test/scss/uri/s.1.json-e | 33 ---- test/scss/uri/s.2.json | 53 +++++++ test/scss/uri/s.2.scss | 3 + test/scss/uri/s.3.json | 53 +++++++ test/scss/uri/s.3.scss | 3 + test/scss/uri/test.coffee | 14 ++ 35 files changed, 1502 insertions(+), 119 deletions(-) create mode 100644 test/scss/uri/4.json create mode 100644 test/scss/uri/4.scss create mode 100644 test/scss/uri/5.json create mode 100644 test/scss/uri/5.scss create mode 100644 test/scss/uri/6.json create mode 100644 test/scss/uri/6.scss create mode 100644 test/scss/uri/7.json create mode 100644 test/scss/uri/7.scss create mode 100644 test/scss/uri/8.json create mode 100644 test/scss/uri/8.scss create mode 100644 test/scss/uri/9.json create mode 100644 test/scss/uri/9.scss create mode 100644 test/scss/uri/interp.0.json create mode 100644 test/scss/uri/interp.0.scss create mode 100644 test/scss/uri/interp.1.json create mode 100644 test/scss/uri/interp.1.scss create mode 100644 test/scss/uri/interp.2.json create mode 100644 test/scss/uri/interp.2.scss create mode 100644 test/scss/uri/interp.3.json create mode 100644 test/scss/uri/interp.3.scss create mode 100644 test/scss/uri/interp.4.json create mode 100644 test/scss/uri/interp.4.scss create mode 100644 test/scss/uri/interp.5.json create mode 100644 test/scss/uri/interp.5.scss delete mode 100644 test/scss/uri/s.1.json-e create mode 100644 test/scss/uri/s.2.json create mode 100644 test/scss/uri/s.2.scss create mode 100644 test/scss/uri/s.3.json create mode 100644 test/scss/uri/s.3.scss diff --git a/src/scss/parse.js b/src/scss/parse.js index 244f29c8..4a7c662e 100644 --- a/src/scss/parse.js +++ b/src/scss/parse.js @@ -186,21 +186,6 @@ function throwError(i) { throw {line: ln, syntax: 'scss'}; } -/** - * @param {Object} exclude - * @param {Number} i Token's index number - * @returns {Number} - */ -function checkExcluding(exclude, i) { - var start = i; - - while (i < tokensLength) { - if (exclude[tokens[i++].type]) break; - } - - return i - start - 2; -} - /** * @param {Number} start * @param {Number} finish @@ -4140,110 +4125,277 @@ function _checkUnicodeWildcard(i) { else break; } + tokens[start].uri_raw_end = i; + return i - start; } /** - * Check if token is part of URI (e.g. `url('/css/styles.css')`) - * @param {Number} i Token's index number - * @returns {Number} Length of URI + * Check if token is part of URI, e.g. `url('/css/styles.css')` + * @param {number} i Token's index number + * @returns {number} Length of URI */ function checkUri(i) { - var start = i; + const start = i; + let l; - if (i >= tokensLength || tokens[i++].value !== 'url' || - i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) - return 0; + if (i >= tokensLength || tokens[i].value !== 'url') return 0; - return tokens[i].right - start + 1; + // Skip `url` + i++; + + if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) + return 0; + + // Store the opening parenthesis token as we will reference it's `right` + // property to determine when the parentheses close + const leftParenthesis = tokens[i]; + + // Skip `(` + i++; + + // Determine the type of URI + while (i < leftParenthesis.right) { + if (l = checkUri1(i)) { + i += l; + tokens[start].uriType = 1; // Raw based URI (without quotes) + } else if (l = checkUri2(i)) { + i += l; + tokens[start].uriType = 2; // Non-raw based URI (with quotes) + } else return 0; + } + + return i - start; } /** - * Get node with URI - * @returns {Array} `['uri', x]` where `x` is URI's nodes (without `url` - * and braces, e.g. `['string', ''/css/styles.css'']`). + * Get specific type of URI node + * @return {Node} Specific type of URI node */ function getUri() { - let startPos = pos; - let uriExcluding = {}; - let uri; - let token; + const uriType = tokens[pos].uriType; + + if (uriType === 1) return getUri1(); + if (uriType === 2) return getUri2(); +} + +/** + * Check if token type is valid URI character + * @param {number} i Token's index number + * @return {number} Length of raw node + */ +function checkUriRawCharacters(i) { + const start = i; let l; - let raw; - pos += 2; + if (l = checkIdent(i)) i += l; + else if (l = checkNumber(i)) i += l; + else { + switch (tokens[i].type) { + case TokenType.ExclamationMark: + case TokenType.NumberSign: + case TokenType.DollarSign: + case TokenType.PercentSign: + case TokenType.Ampersand: + case TokenType.Asterisk: + case TokenType.PlusSign: + case TokenType.Comma: + case TokenType.HyphenMinus: + case TokenType.FullStop: + case TokenType.Solidus: + case TokenType.Colon: + case TokenType.Semicolon: + case TokenType.LessThanSign: + case TokenType.EqualsSign: + case TokenType.GreaterThanSign: + case TokenType.QuotationMark: + case TokenType.CommercialAt: + case TokenType.LeftSquareBracket: + case TokenType.RightSquareBracket: + case TokenType.CircumflexAccent: + case TokenType.LowLine: + case TokenType.LeftCurlyBracket: + case TokenType.VerticalLine: + case TokenType.RightCurlyBracket: + case TokenType.Tilde: + i += 1; + break; + + default: + return 0; + } + } - uriExcluding[TokenType.Space] = 1; - uriExcluding[TokenType.Tab] = 1; - uriExcluding[TokenType.Newline] = 1; - uriExcluding[TokenType.LeftParenthesis] = 1; - uriExcluding[TokenType.RightParenthesis] = 1; - - if (checkUriContent(pos)) { - uri = [] - .concat(getSC()) - .concat(getUriContent()) - .concat(getSC()); - } else { - uri = [].concat(getSC()); - l = checkExcluding(uriExcluding, pos); - token = tokens[pos]; - raw = newNode(NodeType.RawType, joinValues(pos, pos + l), token.ln, - token.col); + return i - start; +} - uri.push(raw); +/** + * Check if content of URI can be contained within a raw node + * @param {number} i Token's index number + * @return {number} Length of raw node + */ +function checkUriRaw(i) { + const start = i; + let l; - pos += l + 1; + while (i < tokensLength) { + if (checkInterpolation(i) || checkVariable(i)) break; + else if (l = checkUriRawCharacters(i)) i += l; + else break; + } + + tokens[start].uri_raw_end = i; - uri = uri.concat(getSC()); + return i - start; +} + +/** + * Get a raw node + * @return {Node} + */ +function getUriRaw() { + const startPos = pos; + const type = NodeType.RawType; + const token = tokens[startPos]; + const line = token.ln; + const column = token.col; + let content = []; + let l; + + while (pos < tokens[startPos].uri_raw_end) { + if (checkInterpolation(pos) || checkVariable(pos)) break; + else if (l = checkUriRawCharacters(pos)) pos += l; + else break; } - token = tokens[startPos]; - var line = token.ln; - var column = token.col; - var end = getLastPosition(uri, line, column, 1); - pos++; + content = joinValues(startPos, pos - 1); - return newNode(NodeType.UriType, uri, token.ln, token.col, end); + return newNode(type, content, line, column); } /** - * @param {Number} i Token's index number - * @returns {Number} + * Check for a raw (without quotes) URI + * (1) http://foo.com/bar.png + * (2) http://foo.com/#{$bar}.png + * (3) #{$foo}/bar.png + * (4) #{$foo} + * @param {number} i Token's index number + * @return {number} Length of URI node */ -function checkUriContent(i) { - return checkUri1(i) || - checkFunction(i); +function checkUri1(i) { + const start = i; + let l; + + if (l = checkSC(i)) i += l; + + while (i < tokensLength) { + if (l = checkInterpolation(i) || checkUriRaw(i)) i += l; + else break; + } + + if (l = checkSC(i)) i += l; + + // Check that we are at the end of the uri + if (i < tokens[start - 1].right) return 0; + + tokens[start].uri_end = i; + + return i - start; } /** - * @returns {Array} + * Get a raw (without quotes) URI + node + * @return {Node} */ -function getUriContent() { - if (checkUri1(pos)) return getString(); - else if (checkFunction(pos)) return getFunction(); +function getUri1() { + const startPos = pos; + const type = NodeType.UriType; + const token = tokens[startPos]; + const line = token.ln; + const column = token.col; + let content = []; + let end; + + // Skip `url` and `(` + pos += 2; + + if (checkSC(pos)) content = content.concat(getSC()); + + while (pos < tokens[startPos + 2].uri_end) { + if (checkInterpolation(pos)) content.push(getInterpolation()); + else if (checkUriRaw(pos)) content.push(getUriRaw()); + else break; + } + + if (checkSC(pos)) content = content.concat(getSC()); + + // Check that we are at the end of the uri + if (pos < tokens[startPos + 1].right) return 0; + + end = getLastPosition(content, line, column, 1); + + // Skip `)` + pos++; + + return newNode(type, content, line, column, end); } /** - * @param {Number} i Token's index number - * @returns {Number} + * Check for a non-raw (with quotes) URI + * (1) 'http://foo.com/bar.png' + * (2) 'http://foo.com/'#{$bar}.png + * (3) #{$foo}'/bar.png' + * @param {number} i Token's index number + * @return {number} Length of URI node */ -function checkUri1(i) { - let start = i; +function checkUri2(i) { + const start = i; let l; - if (i >= tokensLength) return 0; + while (i < tokensLength) { + if (l = checkSC(i)) i += l; + else if (l = checkString(i)) i += l; + else if (l = checkFunction(i)) i += l; + else if (l = checkUnary(i)) i += l; + else if (l = checkIdentOrInterpolation(i)) i += l; + else if (l = checkVariable(i)) i += l; + else break; + } - if (l = checkSC(i)) i += l; + tokens[start].uri_end = i; - if (tokens[i].type !== TokenType.StringDQ && - tokens[i].type !== TokenType.StringSQ) return 0; + return i - start; +} - i++; +/** + * Get a non-raw (with quotes) URI node + * @return {Node} + */ +function getUri2() { + const startPos = pos; + const token = tokens[startPos]; + const line = token.ln; + const column = token.col; + let content = []; + let end; - if (l = checkSC(i)) i += l; + // Skip `url` and `(` + pos += 2; - return i - start; + while (pos < tokens[startPos + 2].uri_end) { + if (checkSC(pos)) content = content.concat(getSC()); + else if (checkUnary(pos)) content.push(getUnary()); + else if (_checkValue(pos)) content.push(_getValue()); + else break; + } + + end = getLastPosition(content, line, column, 1); + + // Skip `)` + pos++; + + return newNode(NodeType.UriType, content, line, column, end); } /** diff --git a/src/scss/tokenizer.js b/src/scss/tokenizer.js index 7cdb7499..01d7b60d 100644 --- a/src/scss/tokenizer.js +++ b/src/scss/tokenizer.js @@ -48,7 +48,8 @@ module.exports = function(css, tabSize) { '{': TokenType.LeftCurlyBracket, '|': TokenType.VerticalLine, '}': TokenType.RightCurlyBracket, - '~': TokenType.Tilde + '~': TokenType.Tilde, + '`': TokenType.Backtick }; /** diff --git a/test/scss/uri/3.json b/test/scss/uri/3.json index f050e080..96f23967 100644 --- a/test/scss/uri/3.json +++ b/test/scss/uri/3.json @@ -2,8 +2,22 @@ "type": "uri", "content": [ { - "type": "raw", - "content": "$v1", + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "scss", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + } + ], "syntax": "scss", "start": { "line": 1, @@ -11,7 +25,7 @@ }, "end": { "line": 1, - "column": 7 + "column": 8 } } ], @@ -22,6 +36,6 @@ }, "end": { "line": 1, - "column": 8 + "column": 9 } } diff --git a/test/scss/uri/3.scss b/test/scss/uri/3.scss index 7d1093c4..b0d71c24 100644 --- a/test/scss/uri/3.scss +++ b/test/scss/uri/3.scss @@ -1 +1 @@ -url($v1) +url($foo) diff --git a/test/scss/uri/4.json b/test/scss/uri/4.json new file mode 100644 index 00000000..ee07af67 --- /dev/null +++ b/test/scss/uri/4.json @@ -0,0 +1,107 @@ +{ + "type": "uri", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "scss", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 9 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "scss", + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "scss", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 15 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 16 + } +} diff --git a/test/scss/uri/4.scss b/test/scss/uri/4.scss new file mode 100644 index 00000000..29c7d9f6 --- /dev/null +++ b/test/scss/uri/4.scss @@ -0,0 +1 @@ +url($foo + $bar) diff --git a/test/scss/uri/5.json b/test/scss/uri/5.json new file mode 100644 index 00000000..2151d777 --- /dev/null +++ b/test/scss/uri/5.json @@ -0,0 +1,93 @@ +{ + "type": "uri", + "content": [ + { + "type": "string", + "content": "'foo/'", + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "scss", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 13 + } + }, + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "scss", + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 17 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 18 + } +} diff --git a/test/scss/uri/5.scss b/test/scss/uri/5.scss new file mode 100644 index 00000000..bcbb2593 --- /dev/null +++ b/test/scss/uri/5.scss @@ -0,0 +1 @@ +url('foo/' + $bar) diff --git a/test/scss/uri/6.json b/test/scss/uri/6.json new file mode 100644 index 00000000..655e8982 --- /dev/null +++ b/test/scss/uri/6.json @@ -0,0 +1,93 @@ +{ + "type": "uri", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "scss", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 9 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "scss", + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "string", + "content": "'bar.png'", + "syntax": "scss", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 20 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 21 + } +} diff --git a/test/scss/uri/6.scss b/test/scss/uri/6.scss new file mode 100644 index 00000000..be40e1f5 --- /dev/null +++ b/test/scss/uri/6.scss @@ -0,0 +1 @@ +url($foo + 'bar.png') diff --git a/test/scss/uri/7.json b/test/scss/uri/7.json new file mode 100644 index 00000000..3ae8ca14 --- /dev/null +++ b/test/scss/uri/7.json @@ -0,0 +1,106 @@ +{ + "type": "uri", + "content": [ + { + "type": "string", + "content": "'foo/'", + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "scss", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 13 + } + }, + { + "type": "function", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "scss", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + { + "syntax": "scss", + "type": "arguments", + "content": [], + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 19 + } +} diff --git a/test/scss/uri/7.scss b/test/scss/uri/7.scss new file mode 100644 index 00000000..7de232cb --- /dev/null +++ b/test/scss/uri/7.scss @@ -0,0 +1 @@ +url('foo/' + bar()) diff --git a/test/scss/uri/8.json b/test/scss/uri/8.json new file mode 100644 index 00000000..d8005596 --- /dev/null +++ b/test/scss/uri/8.json @@ -0,0 +1,120 @@ +{ + "type": "uri", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "scss", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 9 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "scss", + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "function", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "scss", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + { + "syntax": "scss", + "type": "arguments", + "content": [], + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 16 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 17 + } +} diff --git a/test/scss/uri/8.scss b/test/scss/uri/8.scss new file mode 100644 index 00000000..a1c2aa59 --- /dev/null +++ b/test/scss/uri/8.scss @@ -0,0 +1 @@ +url($foo + bar()) diff --git a/test/scss/uri/9.json b/test/scss/uri/9.json new file mode 100644 index 00000000..d121b919 --- /dev/null +++ b/test/scss/uri/9.json @@ -0,0 +1,133 @@ +{ + "type": "uri", + "content": [ + { + "type": "function", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 7 + } + }, + { + "syntax": "scss", + "type": "arguments", + "content": [], + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 9 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "scss", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "function", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "scss", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + { + "syntax": "scss", + "type": "arguments", + "content": [], + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 17 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 18 + } +} diff --git a/test/scss/uri/9.scss b/test/scss/uri/9.scss new file mode 100644 index 00000000..947acea7 --- /dev/null +++ b/test/scss/uri/9.scss @@ -0,0 +1 @@ +url(foo() + bar()) diff --git a/test/scss/uri/c.1.json b/test/scss/uri/c.1.json index 01a57f04..d09ad887 100644 --- a/test/scss/uri/c.1.json +++ b/test/scss/uri/c.1.json @@ -16,12 +16,25 @@ }, { "type": "raw", - "content": "http://test.com/*test*/", + "content": "http://test.com", "syntax": "scss", "start": { "line": 1, "column": 13 }, + "end": { + "line": 1, + "column": 27 + } + }, + { + "type": "multilineComment", + "content": "test", + "syntax": "scss", + "start": { + "line": 1, + "column": 28 + }, "end": { "line": 1, "column": 35 @@ -37,4 +50,4 @@ "line": 1, "column": 36 } -} \ No newline at end of file +} diff --git a/test/scss/uri/interp.0.json b/test/scss/uri/interp.0.json new file mode 100644 index 00000000..93a03c4c --- /dev/null +++ b/test/scss/uri/interp.0.json @@ -0,0 +1,27 @@ +{ + "type": "uri", + "content": [ + { + "type": "string", + "content": "'#{$foo}'", + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 13 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 14 + } +} diff --git a/test/scss/uri/interp.0.scss b/test/scss/uri/interp.0.scss new file mode 100644 index 00000000..8baf2f97 --- /dev/null +++ b/test/scss/uri/interp.0.scss @@ -0,0 +1 @@ +url('#{$foo}') diff --git a/test/scss/uri/interp.1.json b/test/scss/uri/interp.1.json new file mode 100644 index 00000000..ebf8ce56 --- /dev/null +++ b/test/scss/uri/interp.1.json @@ -0,0 +1,55 @@ +{ + "type": "uri", + "content": [ + { + "type": "interpolation", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "scss", + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 11 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 12 + } +} diff --git a/test/scss/uri/interp.1.scss b/test/scss/uri/interp.1.scss new file mode 100644 index 00000000..b18014d2 --- /dev/null +++ b/test/scss/uri/interp.1.scss @@ -0,0 +1 @@ +url(#{$foo}) diff --git a/test/scss/uri/interp.2.json b/test/scss/uri/interp.2.json new file mode 100644 index 00000000..814b8791 --- /dev/null +++ b/test/scss/uri/interp.2.json @@ -0,0 +1,68 @@ +{ + "type": "uri", + "content": [ + { + "type": "interpolation", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "scss", + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "raw", + "content": "/bar.png", + "syntax": "scss", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 19 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 20 + } +} diff --git a/test/scss/uri/interp.2.scss b/test/scss/uri/interp.2.scss new file mode 100644 index 00000000..5f514714 --- /dev/null +++ b/test/scss/uri/interp.2.scss @@ -0,0 +1 @@ +url(#{$foo}/bar.png) diff --git a/test/scss/uri/interp.3.json b/test/scss/uri/interp.3.json new file mode 100644 index 00000000..4b0134dd --- /dev/null +++ b/test/scss/uri/interp.3.json @@ -0,0 +1,68 @@ +{ + "type": "uri", + "content": [ + { + "type": "raw", + "content": "foo/", + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + { + "type": "interpolation", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "scss", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 15 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 16 + } +} diff --git a/test/scss/uri/interp.3.scss b/test/scss/uri/interp.3.scss new file mode 100644 index 00000000..1274f4fa --- /dev/null +++ b/test/scss/uri/interp.3.scss @@ -0,0 +1 @@ +url(foo/#{$bar}) diff --git a/test/scss/uri/interp.4.json b/test/scss/uri/interp.4.json new file mode 100644 index 00000000..63bc5d49 --- /dev/null +++ b/test/scss/uri/interp.4.json @@ -0,0 +1,121 @@ +{ + "type": "uri", + "content": [ + { + "type": "interpolation", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "scss", + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "scss", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 13 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 14 + } + }, + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "scss", + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 18 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 19 + } +} diff --git a/test/scss/uri/interp.4.scss b/test/scss/uri/interp.4.scss new file mode 100644 index 00000000..4d5b5735 --- /dev/null +++ b/test/scss/uri/interp.4.scss @@ -0,0 +1 @@ +url(#{$foo} + $bar) diff --git a/test/scss/uri/interp.5.json b/test/scss/uri/interp.5.json new file mode 100644 index 00000000..a767a17e --- /dev/null +++ b/test/scss/uri/interp.5.json @@ -0,0 +1,107 @@ +{ + "type": "uri", + "content": [ + { + "type": "string", + "content": "'foo/'", + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 11 + } + }, + { + "type": "operator", + "content": "+", + "syntax": "scss", + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 13 + } + }, + { + "type": "interpolation", + "content": [ + { + "type": "variable", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "scss", + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 19 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 20 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 21 + } +} diff --git a/test/scss/uri/interp.5.scss b/test/scss/uri/interp.5.scss new file mode 100644 index 00000000..28ef7842 --- /dev/null +++ b/test/scss/uri/interp.5.scss @@ -0,0 +1 @@ +url('foo/' + #{$bar}) diff --git a/test/scss/uri/s.1.json-e b/test/scss/uri/s.1.json-e deleted file mode 100644 index 2de12296..00000000 --- a/test/scss/uri/s.1.json-e +++ /dev/null @@ -1,33 +0,0 @@ -{ - "type": "uri", - "content": [ - { - "type": "s", - "content": " ", - "start": { - "line": 1, - "column": 5 - } - }, - { - "type": "raw", - "content": "http://test.com", - "start": { - "line": 1, - "column": 7 - } - }, - { - "type": "s", - "content": " ", - "start": { - "line": 1, - "column": 22 - } - } - ], - "start": { - "line": 1, - "column": 1 - } -} diff --git a/test/scss/uri/s.2.json b/test/scss/uri/s.2.json new file mode 100644 index 00000000..af316ed6 --- /dev/null +++ b/test/scss/uri/s.2.json @@ -0,0 +1,53 @@ +{ + "type": "uri", + "content": [ + { + "type": "space", + "content": "\n ", + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 2 + } + }, + { + "type": "string", + "content": "'http://test.com'", + "syntax": "scss", + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 19 + } + }, + { + "type": "space", + "content": "\n", + "syntax": "scss", + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 20 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 3, + "column": 1 + } +} diff --git a/test/scss/uri/s.2.scss b/test/scss/uri/s.2.scss new file mode 100644 index 00000000..f744977a --- /dev/null +++ b/test/scss/uri/s.2.scss @@ -0,0 +1,3 @@ +url( + 'http://test.com' +) diff --git a/test/scss/uri/s.3.json b/test/scss/uri/s.3.json new file mode 100644 index 00000000..815d926e --- /dev/null +++ b/test/scss/uri/s.3.json @@ -0,0 +1,53 @@ +{ + "type": "uri", + "content": [ + { + "type": "space", + "content": "\n ", + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 2 + } + }, + { + "type": "raw", + "content": "http://test.com", + "syntax": "scss", + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 17 + } + }, + { + "type": "space", + "content": "\n", + "syntax": "scss", + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 18 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 3, + "column": 1 + } +} diff --git a/test/scss/uri/s.3.scss b/test/scss/uri/s.3.scss new file mode 100644 index 00000000..3094943d --- /dev/null +++ b/test/scss/uri/s.3.scss @@ -0,0 +1,3 @@ +url( + http://test.com +) diff --git a/test/scss/uri/test.coffee b/test/scss/uri/test.coffee index a84b8561..aac927ef 100644 --- a/test/scss/uri/test.coffee +++ b/test/scss/uri/test.coffee @@ -4,9 +4,23 @@ describe 'scss/uri >>', -> it '1', -> this.shouldBeOk() it '2', -> this.shouldBeOk() it '3', -> this.shouldBeOk() + it '4', -> this.shouldBeOk() + it '5', -> this.shouldBeOk() + it '6', -> this.shouldBeOk() + it '7', -> this.shouldBeOk() + it '8', -> this.shouldBeOk() + + it 'interp.0', -> this.shouldBeOk() + it 'interp.1', -> this.shouldBeOk() + it 'interp.2', -> this.shouldBeOk() + it 'interp.3', -> this.shouldBeOk() + it 'interp.4', -> this.shouldBeOk() + it 'interp.5', -> this.shouldBeOk() it 'c.0', -> this.shouldBeOk() it 'c.1', -> this.shouldBeOk() it 's.0', -> this.shouldBeOk() it 's.1', -> this.shouldBeOk() + it 's.2', -> this.shouldBeOk() + it 's.3', -> this.shouldBeOk()