Skip to content

Commit baef3a4

Browse files
committed
Fix endInterpolant not being captured
Fixes #20
1 parent c80ffe2 commit baef3a4

File tree

7 files changed

+274
-7
lines changed

7 files changed

+274
-7
lines changed
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`interpolant should tokenize interpolant decimal 1`] = `
4+
Array [
5+
Array [
6+
"startInterpolant",
7+
"#{",
8+
1,
9+
2,
10+
],
11+
Array [
12+
"number",
13+
"1.0",
14+
1,
15+
3,
16+
1,
17+
5,
18+
],
19+
Array [
20+
"endInterpolant",
21+
"}",
22+
1,
23+
6,
24+
],
25+
Array [
26+
"newline",
27+
"
28+
",
29+
2,
30+
0,
31+
],
32+
Array [
33+
"startInterpolant",
34+
"#{",
35+
2,
36+
2,
37+
],
38+
Array [
39+
"number",
40+
"10.00",
41+
2,
42+
10,
43+
2,
44+
14,
45+
],
46+
Array [
47+
"endInterpolant",
48+
"}",
49+
2,
50+
15,
51+
],
52+
Array [
53+
"newline",
54+
"
55+
",
56+
3,
57+
0,
58+
],
59+
Array [
60+
"startInterpolant",
61+
"#{",
62+
3,
63+
2,
64+
],
65+
Array [
66+
"number",
67+
".100",
68+
3,
69+
19,
70+
3,
71+
22,
72+
],
73+
Array [
74+
"endInterpolant",
75+
"}",
76+
3,
77+
23,
78+
],
79+
Array [
80+
"newline",
81+
"
82+
",
83+
4,
84+
0,
85+
],
86+
]
87+
`;
88+
89+
exports[`interpolant should tokenize interpolant number 1`] = `
90+
Array [
91+
Array [
92+
"startInterpolant",
93+
"#{",
94+
1,
95+
2,
96+
],
97+
Array [
98+
"number",
99+
"1",
100+
1,
101+
3,
102+
1,
103+
3,
104+
],
105+
Array [
106+
"endInterpolant",
107+
"}",
108+
1,
109+
4,
110+
],
111+
Array [
112+
"newline",
113+
"
114+
",
115+
2,
116+
0,
117+
],
118+
Array [
119+
"startInterpolant",
120+
"#{",
121+
2,
122+
2,
123+
],
124+
Array [
125+
"number",
126+
"123",
127+
2,
128+
8,
129+
2,
130+
10,
131+
],
132+
Array [
133+
"endInterpolant",
134+
"}",
135+
2,
136+
11,
137+
],
138+
Array [
139+
"newline",
140+
"
141+
",
142+
3,
143+
0,
144+
],
145+
]
146+
`;
147+
148+
exports[`interpolant should tokenize interpolant quoted-string 1`] = `
149+
Array [
150+
Array [
151+
"startInterpolant",
152+
"#{",
153+
1,
154+
2,
155+
],
156+
Array [
157+
"\\"",
158+
"\\"",
159+
1,
160+
3,
161+
],
162+
Array [
163+
"string",
164+
"hello world!",
165+
1,
166+
4,
167+
1,
168+
15,
169+
],
170+
Array [
171+
"\\"",
172+
"\\"",
173+
1,
174+
16,
175+
],
176+
Array [
177+
"endInterpolant",
178+
"}",
179+
1,
180+
17,
181+
],
182+
Array [
183+
"newline",
184+
"
185+
",
186+
2,
187+
0,
188+
],
189+
]
190+
`;
191+
192+
exports[`interpolant should tokenize interpolant unquoted-string 1`] = `
193+
Array [
194+
Array [
195+
"startInterpolant",
196+
"#{",
197+
1,
198+
2,
199+
],
200+
Array [
201+
"ident",
202+
"hello",
203+
1,
204+
3,
205+
1,
206+
7,
207+
],
208+
Array [
209+
"space",
210+
" ",
211+
],
212+
Array [
213+
"ident",
214+
"world",
215+
1,
216+
9,
217+
1,
218+
13,
219+
],
220+
Array [
221+
"endInterpolant",
222+
"}",
223+
1,
224+
14,
225+
],
226+
Array [
227+
"newline",
228+
"
229+
",
230+
2,
231+
0,
232+
],
233+
]
234+
`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#{1.0}
2+
#{10.00}
3+
#{.100}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#{1}
2+
#{123}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#{"hello world!"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#{hello world}

__tests__/interpolant.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var scss = require('..');
2+
var fs = require('fs');
3+
var path = require('path');
4+
5+
var fixture = function(name) {
6+
return fs.readFileSync(
7+
path.join(__dirname, 'fixture', name)
8+
);
9+
}
10+
11+
describe('interpolant', function() {
12+
it('should tokenize interpolant decimal', function() {
13+
const tree = scss.tokenize(fixture('interpolant/decimal.scss'));
14+
expect(tree).toMatchSnapshot();
15+
});
16+
17+
it('should tokenize interpolant number', function() {
18+
const tree = scss.tokenize(fixture('interpolant/number.scss'));
19+
expect(tree).toMatchSnapshot();
20+
});
21+
22+
it('should tokenize interpolant quoted-string', function() {
23+
const tree = scss.tokenize(fixture('interpolant/quoted-string.scss'));
24+
expect(tree).toMatchSnapshot();
25+
});
26+
27+
it('should tokenize interpolant unquoted-string', function() {
28+
const tree = scss.tokenize(fixture('interpolant/unquoted-string.scss'));
29+
expect(tree).toMatchSnapshot();
30+
});
31+
});

src/tokenize-interpolant.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,8 @@ export default function tokenize(input, l, p) {
102102
break;
103103

104104
case closeCurly:
105-
if (inInterpolant) {
106-
inInterpolant = false;
107-
tokens.push(['endInterpolant', '}', line, pos - offset]);
108-
} else {
109-
break loop;
110-
}
111-
break;
105+
tokens.push(['endInterpolant', '}', line, pos - offset]);
106+
break loop;
112107

113108
case comma:
114109
tokens.push([',', ',', line, pos - offset]);

0 commit comments

Comments
 (0)