diff --git a/__tests__/__snapshots__/interpolant.js.snap b/__tests__/__snapshots__/interpolant.js.snap new file mode 100644 index 0000000..71165e6 --- /dev/null +++ b/__tests__/__snapshots__/interpolant.js.snap @@ -0,0 +1,234 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`interpolant should tokenize interpolant decimal 1`] = ` +Array [ + Array [ + "startInterpolant", + "#{", + 1, + 2, + ], + Array [ + "number", + "1.0", + 1, + 3, + 1, + 5, + ], + Array [ + "endInterpolant", + "}", + 1, + 6, + ], + Array [ + "newline", + " +", + 2, + 0, + ], + Array [ + "startInterpolant", + "#{", + 2, + 2, + ], + Array [ + "number", + "10.00", + 2, + 10, + 2, + 14, + ], + Array [ + "endInterpolant", + "}", + 2, + 15, + ], + Array [ + "newline", + " +", + 3, + 0, + ], + Array [ + "startInterpolant", + "#{", + 3, + 2, + ], + Array [ + "number", + ".100", + 3, + 19, + 3, + 22, + ], + Array [ + "endInterpolant", + "}", + 3, + 23, + ], + Array [ + "newline", + " +", + 4, + 0, + ], +] +`; + +exports[`interpolant should tokenize interpolant number 1`] = ` +Array [ + Array [ + "startInterpolant", + "#{", + 1, + 2, + ], + Array [ + "number", + "1", + 1, + 3, + 1, + 3, + ], + Array [ + "endInterpolant", + "}", + 1, + 4, + ], + Array [ + "newline", + " +", + 2, + 0, + ], + Array [ + "startInterpolant", + "#{", + 2, + 2, + ], + Array [ + "number", + "123", + 2, + 8, + 2, + 10, + ], + Array [ + "endInterpolant", + "}", + 2, + 11, + ], + Array [ + "newline", + " +", + 3, + 0, + ], +] +`; + +exports[`interpolant should tokenize interpolant quoted-string 1`] = ` +Array [ + Array [ + "startInterpolant", + "#{", + 1, + 2, + ], + Array [ + "\\"", + "\\"", + 1, + 3, + ], + Array [ + "string", + "hello world!", + 1, + 4, + 1, + 15, + ], + Array [ + "\\"", + "\\"", + 1, + 16, + ], + Array [ + "endInterpolant", + "}", + 1, + 17, + ], + Array [ + "newline", + " +", + 2, + 0, + ], +] +`; + +exports[`interpolant should tokenize interpolant unquoted-string 1`] = ` +Array [ + Array [ + "startInterpolant", + "#{", + 1, + 2, + ], + Array [ + "ident", + "hello", + 1, + 3, + 1, + 7, + ], + Array [ + "space", + " ", + ], + Array [ + "ident", + "world", + 1, + 9, + 1, + 13, + ], + Array [ + "endInterpolant", + "}", + 1, + 14, + ], + Array [ + "newline", + " +", + 2, + 0, + ], +] +`; diff --git a/__tests__/fixture/interpolant/decimal.scss b/__tests__/fixture/interpolant/decimal.scss new file mode 100644 index 0000000..6f281b1 --- /dev/null +++ b/__tests__/fixture/interpolant/decimal.scss @@ -0,0 +1,3 @@ +#{1.0} +#{10.00} +#{.100} diff --git a/__tests__/fixture/interpolant/number.scss b/__tests__/fixture/interpolant/number.scss new file mode 100644 index 0000000..d23de16 --- /dev/null +++ b/__tests__/fixture/interpolant/number.scss @@ -0,0 +1,2 @@ +#{1} +#{123} diff --git a/__tests__/fixture/interpolant/quoted-string.scss b/__tests__/fixture/interpolant/quoted-string.scss new file mode 100644 index 0000000..5cb1d7e --- /dev/null +++ b/__tests__/fixture/interpolant/quoted-string.scss @@ -0,0 +1 @@ +#{"hello world!"} diff --git a/__tests__/fixture/interpolant/unquoted-string.scss b/__tests__/fixture/interpolant/unquoted-string.scss new file mode 100644 index 0000000..30df72f --- /dev/null +++ b/__tests__/fixture/interpolant/unquoted-string.scss @@ -0,0 +1 @@ +#{hello world} diff --git a/__tests__/interpolant.js b/__tests__/interpolant.js new file mode 100644 index 0000000..7a7b46a --- /dev/null +++ b/__tests__/interpolant.js @@ -0,0 +1,31 @@ +var scss = require('..'); +var fs = require('fs'); +var path = require('path'); + +var fixture = function(name) { + return fs.readFileSync( + path.join(__dirname, 'fixture', name) + ); +} + +describe('interpolant', function() { + it('should tokenize interpolant decimal', function() { + const tree = scss.tokenize(fixture('interpolant/decimal.scss')); + expect(tree).toMatchSnapshot(); + }); + + it('should tokenize interpolant number', function() { + const tree = scss.tokenize(fixture('interpolant/number.scss')); + expect(tree).toMatchSnapshot(); + }); + + it('should tokenize interpolant quoted-string', function() { + const tree = scss.tokenize(fixture('interpolant/quoted-string.scss')); + expect(tree).toMatchSnapshot(); + }); + + it('should tokenize interpolant unquoted-string', function() { + const tree = scss.tokenize(fixture('interpolant/unquoted-string.scss')); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/src/tokenize-interpolant.js b/src/tokenize-interpolant.js index 2533c91..be9ba95 100644 --- a/src/tokenize-interpolant.js +++ b/src/tokenize-interpolant.js @@ -102,13 +102,8 @@ export default function tokenize(input, l, p) { break; case closeCurly: - if (inInterpolant) { - inInterpolant = false; - tokens.push(['endInterpolant', '}', line, pos - offset]); - } else { - break loop; - } - break; + tokens.push(['endInterpolant', '}', line, pos - offset]); + break loop; case comma: tokens.push([',', ',', line, pos - offset]);