Skip to content

Commit

Permalink
fix(css-in-js): do not duplicate comments (#5416)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Nov 10, 2018
1 parent d4c248b commit cc6899e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/language-css/printer-postcss.js
Expand Up @@ -207,8 +207,11 @@ function genericPrint(path, options, print) {
? concat([
isDetachedRulesetCallNode(node)
? ""
: isTemplatePlaceholderNode(node)
? node.raws.afterName
: isTemplatePlaceholderNode(node) &&
/^\s*\n/.test(node.raws.afterName)
? /^\s*\n\s*\n/.test(node.raws.afterName)
? concat([hardline, hardline])
: hardline
: " ",
path.call(print, "params")
])
Expand Down
38 changes: 38 additions & 0 deletions tests/multiparser_js_css/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -140,6 +140,25 @@ styled.a\`
margin: 0;
}
\`
const StyledComponent = styled.div\`
\${anInterpolation}
/* a comment */
.aRule {
color: red
}
\`;
const StyledComponent = styled.div\`
\${anInterpolation}
/* a comment */
.aRule {
color: red
}
\`;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const ListItem = styled.li\`\`;
Expand Down Expand Up @@ -282,4 +301,23 @@ styled.a\`
}
\`;
const StyledComponent = styled.div\`
\${anInterpolation}
/* a comment */
.aRule {
color: red;
}
\`;
const StyledComponent = styled.div\`
\${anInterpolation}
/* a comment */
.aRule {
color: red;
}
\`;
`;
19 changes: 19 additions & 0 deletions tests/multiparser_js_css/styled-components.js
Expand Up @@ -137,3 +137,22 @@ styled.a`
margin: 0;
}
`

const StyledComponent = styled.div`
${anInterpolation}
/* a comment */
.aRule {
color: red
}
`;

const StyledComponent = styled.div`
${anInterpolation}
/* a comment */
.aRule {
color: red
}
`;

0 comments on commit cc6899e

Please sign in to comment.