Skip to content

Commit

Permalink
Fix endInterpolant not being captured
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
xzyfer committed Dec 3, 2018
1 parent 97063c8 commit 144cd32
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 7 deletions.
234 changes: 234 additions & 0 deletions __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,
],
]
`;
3 changes: 3 additions & 0 deletions __tests__/fixture/interpolant/decimal.scss
@@ -0,0 +1,3 @@
#{1.0}
#{10.00}
#{.100}
2 changes: 2 additions & 0 deletions __tests__/fixture/interpolant/number.scss
@@ -0,0 +1,2 @@
#{1}
#{123}
1 change: 1 addition & 0 deletions __tests__/fixture/interpolant/quoted-string.scss
@@ -0,0 +1 @@
#{"hello world!"}
1 change: 1 addition & 0 deletions __tests__/fixture/interpolant/unquoted-string.scss
@@ -0,0 +1 @@
#{hello world}
31 changes: 31 additions & 0 deletions __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();
});
});
9 changes: 2 additions & 7 deletions src/tokenize-interpolant.js
Expand Up @@ -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]);
Expand Down

0 comments on commit 144cd32

Please sign in to comment.