Skip to content

Commit b17aa81

Browse files
committed
Fix unexpected property error for referenced components
Fixes microsoft#74
1 parent c8da56d commit b17aa81

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

e2e/tests/errors.js

+15
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,19 @@ describe('Errors', () => {
376376
assert.isTrue(errorResponse.success);
377377
assert.strictEqual(errorResponse.body.length, 0);
378378
});
379+
380+
it('should not return an error (#74)', async () => {
381+
const errorResponse = await getSemanticDiagnosticsForFile(
382+
`let css: any = {};
383+
const ListNoteItem = 'bla';
384+
const ListNoteTitle = css.span\`
385+
font-weight: bold;
386+
color: \${props => props.theme.primaryColor};
387+
\${ListNoteItem}:hover & {
388+
text-decoration: underline;
389+
}
390+
\`;`);
391+
assert.isTrue(errorResponse.success);
392+
assert.strictEqual(errorResponse.body.length, 0);
393+
});
379394
});

src/_substituter.ts

+12
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ function getSubstitution(
8383
return '$a' + result.slice(2);
8484
}
8585

86+
// Placeholder for component
87+
//
88+
// styled.x`
89+
// ${'button'}:hover & {
90+
// color: red
91+
// }
92+
// `
93+
// Replace with fake selector
94+
if (context.post.match(/^\s*[:].+?[\{&]/)) {
95+
return '&' + ' '.repeat(result.length - 1);
96+
}
97+
8698
// Placeholder used as hex value:
8799
//
88100
// styled.x`

src/test/substituter.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describe('substituter', () => {
171171
[
172172
'position: relative;',
173173
'',
174-
'xxxxxxxxxxxxxxxx:hover & {',
174+
'& :hover & {',
175175
' transform: rotateY(180deg);',
176176
'}',
177177
].join('\n')

0 commit comments

Comments
 (0)