Skip to content

Commit

Permalink
fix: prevent detection of CSS objects within style/styled API
Browse files Browse the repository at this point in the history
  • Loading branch information
sastan committed Mar 23, 2021
1 parent 5227b39 commit f076a81
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/source-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const getSourceMatchers = (
kind: [SyntaxKind.Identifier, SyntaxKind.StringLiteral],
text: 'base',
},
// Do not match CSS objects: `base: { color: 'blue' }`
initializer: (node: ts.Node) => node.kind != SyntaxKind.ObjectLiteralExpression,
// https://github.com/microsoft/typescript-template-language-service-decorator/blob/main/src/nodes.ts#L62
// TODO styled.button, styled()
Expand All @@ -74,6 +75,8 @@ export const getSourceMatchers = (
kind: [SyntaxKind.Identifier, SyntaxKind.StringLiteral],
text: 'use',
},
// Do not match CSS objects: `use: { color: 'blue' }`
initializer: (node: ts.Node) => node.kind !== SyntaxKind.ObjectLiteralExpression,
parent: {
kind: SyntaxKind.ObjectLiteralExpression,
parent: {
Expand Down Expand Up @@ -103,6 +106,8 @@ export const getSourceMatchers = (
// style({ variants: { [...]: { [...]: '...' }} })
{
kind: SyntaxKind.PropertyAssignment,
// Do not match CSS objects
initializer: (node: ts.Node) => node.kind != SyntaxKind.ObjectLiteralExpression,
parent: {
kind: SyntaxKind.ObjectLiteralExpression,
parent: {
Expand Down

0 comments on commit f076a81

Please sign in to comment.