diff --git a/src/sass/parse.js b/src/sass/parse.js index ecbed155..2efec27b 100644 --- a/src/sass/parse.js +++ b/src/sass/parse.js @@ -5364,10 +5364,29 @@ function checkUri(i) { * @return {Node} Specific type of URI node */ function getUri() { - const uriType = tokens[pos].uriType; + const startPos = pos; + const type = NodeType.UriType; + const token = tokens[startPos]; + const line = token.ln; + const column = token.col; + let content = []; + let end; + + const uriType = tokens[startPos].uriType; + + // Skip `url` and `(`. + pos += 2; + + if (uriType === 1) content = content.concat(getUri1()); + else if (uriType === 2) content = content.concat(getUri2()); + else end = getLastPosition(content, line, column, 4); + + if (!end) end = getLastPosition(content, line, column, 1); - if (uriType === 1) return getUri1(); - if (uriType === 2) return getUri2(); + // Skip `)`. + pos++; + + return newNode(type, content, line, column, end); } /** @@ -5497,22 +5516,15 @@ function checkUri1(i) { /** * Get a raw (without quotes) URI node - * @return {Node} + * @return {Array} */ function getUri1() { const startPos = pos; - const type = NodeType.UriType; - const token = tokens[startPos]; - const line = token.ln; - const column = token.col; let content = []; - // Skip `url` and `(` - pos += 2; - if (checkSC(pos)) content = content.concat(getSC()); - while (pos < tokens[startPos + 2].uri_end) { + while (pos < tokens[startPos].uri_end) { if (checkInterpolation(pos)) content.push(getInterpolation()); else if (checkUriRaw(pos)) content.push(getUriRaw()); else break; @@ -5520,15 +5532,7 @@ function getUri1() { 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; - - const end = getLastPosition(content, line, column, 1); - - // Skip `)` - pos++; - - return newNode(type, content, line, column, end); + return content; } /** @@ -5553,6 +5557,9 @@ function checkUri2(i) { else break; } + // 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; @@ -5560,31 +5567,20 @@ function checkUri2(i) { /** * Get a non-raw (with quotes) URI node - * @return {Node} + * @return {Array} */ function getUri2() { const startPos = pos; - const token = tokens[startPos]; - const line = token.ln; - const column = token.col; let content = []; - // Skip `url` and `(` - pos += 2; - - while (pos < tokens[startPos + 2].uri_end) { + while (pos < tokens[startPos].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; } - const end = getLastPosition(content, line, column, 1); - - // Skip `)` - pos++; - - return newNode(NodeType.UriType, content, line, column, end); + return content; } /** diff --git a/src/scss/parse.js b/src/scss/parse.js index d6204a18..924ff4bc 100644 --- a/src/scss/parse.js +++ b/src/scss/parse.js @@ -4715,10 +4715,29 @@ function checkUri(i) { * @return {Node} Specific type of URI node */ function getUri() { - const uriType = tokens[pos].uriType; + const startPos = pos; + const type = NodeType.UriType; + const token = tokens[startPos]; + const line = token.ln; + const column = token.col; + let content = []; + let end; + + const uriType = tokens[startPos].uriType; + + // Skip `url` and `(`. + pos += 2; + + if (uriType === 1) content = content.concat(getUri1()); + else if (uriType === 2) content = content.concat(getUri2()); + else end = getLastPosition(content, line, column, 4); + + if (!end) end = getLastPosition(content, line, column, 1); - if (uriType === 1) return getUri1(); - if (uriType === 2) return getUri2(); + // Skip `)`. + pos++; + + return newNode(type, content, line, column, end); } /** @@ -4848,22 +4867,15 @@ function checkUri1(i) { /** * Get a raw (without quotes) URI node - * @return {Node} + * @return {Array} */ function getUri1() { const startPos = pos; - const type = NodeType.UriType; - const token = tokens[startPos]; - const line = token.ln; - const column = token.col; let content = []; - // Skip `url` and `(` - pos += 2; - if (checkSC(pos)) content = content.concat(getSC()); - while (pos < tokens[startPos + 2].uri_end) { + while (pos < tokens[startPos].uri_end) { if (checkInterpolation(pos)) content.push(getInterpolation()); else if (checkUriRaw(pos)) content.push(getUriRaw()); else break; @@ -4871,15 +4883,7 @@ function getUri1() { 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; - - const end = getLastPosition(content, line, column, 1); - - // Skip `)` - pos++; - - return newNode(type, content, line, column, end); + return content; } /** @@ -4904,6 +4908,9 @@ function checkUri2(i) { else break; } + // 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; @@ -4911,31 +4918,20 @@ function checkUri2(i) { /** * Get a non-raw (with quotes) URI node - * @return {Node} + * @return {Array} */ function getUri2() { const startPos = pos; - const token = tokens[startPos]; - const line = token.ln; - const column = token.col; let content = []; - // Skip `url` and `(` - pos += 2; - - while (pos < tokens[startPos + 2].uri_end) { + while (pos < tokens[startPos].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; } - const end = getLastPosition(content, line, column, 1); - - // Skip `)` - pos++; - - return newNode(NodeType.UriType, content, line, column, end); + return content; } /** diff --git a/test/sass/uri/10.json b/test/sass/uri/10.json new file mode 100644 index 00000000..ea1b2c7c --- /dev/null +++ b/test/sass/uri/10.json @@ -0,0 +1,13 @@ +{ + "type": "uri", + "content": [], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 5 + } +} diff --git a/test/sass/uri/10.sass b/test/sass/uri/10.sass new file mode 100644 index 00000000..82abd36c --- /dev/null +++ b/test/sass/uri/10.sass @@ -0,0 +1 @@ +url() diff --git a/test/sass/uri/test.coffee b/test/sass/uri/test.coffee index c0a641fc..8154e55e 100644 --- a/test/sass/uri/test.coffee +++ b/test/sass/uri/test.coffee @@ -9,6 +9,8 @@ describe 'sass/uri >>', -> it '6', -> this.shouldBeOk() it '7', -> this.shouldBeOk() it '8', -> this.shouldBeOk() + it '9', -> this.shouldBeOk() + it '10', -> this.shouldBeOk() it 'interp.0', -> this.shouldBeOk() it 'interp.1', -> this.shouldBeOk() diff --git a/test/scss/uri/10.json b/test/scss/uri/10.json new file mode 100644 index 00000000..7066e379 --- /dev/null +++ b/test/scss/uri/10.json @@ -0,0 +1,13 @@ +{ + "type": "uri", + "content": [], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 5 + } +} diff --git a/test/scss/uri/10.scss b/test/scss/uri/10.scss new file mode 100644 index 00000000..82abd36c --- /dev/null +++ b/test/scss/uri/10.scss @@ -0,0 +1 @@ +url() diff --git a/test/scss/uri/test.coffee b/test/scss/uri/test.coffee index aac927ef..7fdc692a 100644 --- a/test/scss/uri/test.coffee +++ b/test/scss/uri/test.coffee @@ -9,6 +9,8 @@ describe 'scss/uri >>', -> it '6', -> this.shouldBeOk() it '7', -> this.shouldBeOk() it '8', -> this.shouldBeOk() + it '9', -> this.shouldBeOk() + it '10', -> this.shouldBeOk() it 'interp.0', -> this.shouldBeOk() it 'interp.1', -> this.shouldBeOk()