43081j / 43081j/postcss-styled-components

Autofix generates invalid code with nested style blocks

Ouverte
#9 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
TypeScript
Étoiles
12
Forks
1
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

Test case 1:

```tsx
const Div = styled.div`
${css`
color: blue;
`}
`;
```

This code yields the error `Skipping template… as it included either invalid syntax or complex expressions the plugin could not interpret`, as described at #7.

Test case 2:

```tsx
const Div = styled.div`
${css`
color: blue;
`}

div {
position: absolute;
}
`;
```

This yields the error `Unexpected unknown type selector "POSTCSS_styled-components_0" (selector-type-no-unknown)` on the `${}` line. But what's really strange is what happens if you run stylelint with `--fix`. The output is this invalid code:

```tsx
const Div = styled.div`
${css`
color: blue;
`}

div {
position: absolute;
}
color: blue;
`}

div {
position: absolute;
}
`;
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Look at the parser in src/syntax.js and the transformer in src/transformer.js. The bug occurs when nested template literals with css blocks are processed. Start by reproducing the error with the given test cases, then trace how the plugin handles interpolation and nested style blocks. Check the output after autofix to see where duplication happens.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
developer-experience, tooling
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
55/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.