Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix endInterpolant not being captured #21

Merged
merged 1 commit into from Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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