-
Notifications
You must be signed in to change notification settings - Fork 18
Fixed incorrect parsing/stringifying for nested tagged template literals #17
Conversation
cb2939a
to
9d93fcd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a tremendous work! Thank you for fixing this!
${(props) => css` | ||
color: #b02d00; | ||
`} | ||
${(props2) => css` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that in every test there is css
function before nested template literal. Will this work without it? E. g.
import styled, { css } from 'styled-components';
const Message = styled.p`
padding: 10px;
${(props) => `
color: #b02d00;
`}
${(props2) => `
border-color: red;
`}
`;
Could you add a test for this, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @hudochenkov.
I have added your requested test case.
https://github.com/stylelint/postcss-css-in-js/pull/17/files#diff-afcadaa7a1aaa2ea2d86507936d47fba
But this case doesn't parse the template literal inside as CSS. The inside template literal is converted to a literal
node with no child nodes.
TaggedTemplateExpression
is required to parse as CSS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
I think it's totally ok, because it impossible to know what inside template literal without the tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work!
Excellent stuff. Am I right in thinking that this will fix stylelint/stylelint#4119, and therefore we'll need to remove the corresponding workaround? Once #19 is merged, let's rebase this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic.
In my opinion, there is no need for a workaround, as it fixes the problem that toString breaks. However, changes to the AST might cause unexpected and incorrect reports. |
refs gucong3000#53
I solved the nested template problem by making the nested template literal a child node.