Skip to content

Commit ffe5214

Browse files
committed
Fix false error when placeholder used as part of a rule
Fixes microsoft#59
1 parent 313ecbb commit ffe5214

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

e2e/tests/errors.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,26 @@ describe('Errors', () => {
257257

258258
it('should not return an error for a placeholder as the declaration name (#52)', () => {
259259
return getSemanticDiagnosticsForFile(
260-
`function css(strings, ...) { return ""; }; const value = 1; const q = css\`
260+
`function css(strings, ...) { return ""; }; const q = css\`
261261
$\{'width'}: 1px;
262262
\``
263263
).then(errorResponse => {
264264
assert.isTrue(errorResponse.success);
265265
assert.strictEqual(errorResponse.body.length, 0);
266266
});
267267
});
268+
269+
it('should not return an error for a placeholder as part of a rule (#59)', () => {
270+
return getSemanticDiagnosticsForFile(
271+
`function css(strings, ...) { return ""; }; const q = css\`
272+
$\{'a'}, \${'button'} {
273+
width: 1px;
274+
}
275+
\``
276+
).then(errorResponse => {
277+
assert.isTrue(errorResponse.success);
278+
assert.strictEqual(errorResponse.body.length, 0);
279+
});
280+
});
268281
});
269282

src/substituter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function getReplacementCharacter(
7373
post: string
7474
) {
7575
if (pre.match(/(^|\n)\s*$/g)) {
76-
if (!post.match(/^\s*[\{\:]/)) { // ${'button'} {
76+
if (!post.match(/^\s*[{:,]/)) { // ${'button'} {
7777
return ' ';
7878
}
7979
}

src/test/substituter.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ describe('substituter', () => {
8787
].join('\n')
8888
);
8989
});
90+
91+
it('should insert x for placeholder used as part of a rule (#59)', () => {
92+
assert.deepEqual(
93+
performSubstitutions([
94+
'${"button"}, ${"a"} {',
95+
'color: ${"red"};',
96+
'}',
97+
].join('\n')),
98+
[
99+
'xxxxxxxxxxx, xxxxxx {',
100+
'color: xxxxxxxx;',
101+
'}',
102+
].join('\n')
103+
);
104+
});
90105
});
91106

92107
function performSubstitutions(value: string) {

0 commit comments

Comments
 (0)