Skip to content

styled-jsx parsing doesn't handle interpolation braces correctly in some cases #9506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fmmoret opened this issue Aug 27, 2024 · 3 comments
Closed
Labels

Comments

@fmmoret
Copy link

fmmoret commented Aug 27, 2024

Describe the bug

styled-jsx parsing doesn't handle interpolation braces correctly in some cases

Input code

const SomeStyle = `
      font-weight: 600;
    
      
      font-family: 'NeueKabel', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    
      font-size: 36px;
      letter-spacing: -0.022em;
      line-height: 120%;
`;

const Component = () => {
  return (
    <div>
       <div> Hello world! </div>
       <style jsx={true}>{`
         .heading-container {
           ${SomeStyle}
          }
          * {
            color: blue;
          }
       `}</style>
     </div>
  );
}

Config

None -- using next.js

Playground link (or link to the minimal reproduction)

swc-project/plugins#340

SWC Info output

Using:

"@swc/cli": "0.4.0",
"@swc/core": "1.7.18",
"@swc/helpers": "0.5.12",

Expected behavior

Styles below

         .heading-container {
           ${SomeStyle}
          }

should continue to work.
It appears that the } at ${SomeStyle} is being captured by some kind of grammar in the parser.

It works fine if you update the style to:

         .heading-container {
           ${SomeStyle}}
          }

Or if you do something like

         .heading-container {
           ${SomeStyle}
           padding: 1px;
          }

Actual behavior

An extra curly brace is injected into the css -- subsequent styles get lost or parsed incorrectly.

Version

1.7.18

Additional context

I'm upgrading from an old version of swc (
"@swc/cli": "0.1.62",
"@swc/core": "1.3.37",
"@swc/helpers": "0.4.14",
) -- it used to work fine.

@fmmoret fmmoret added the C-bug label Aug 27, 2024
@kdy1
Copy link
Member

kdy1 commented Aug 27, 2024

Duplicate of swc-project/plugins#340

@kdy1 kdy1 marked this as a duplicate of swc-project/plugins#340 Aug 27, 2024
@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2024
@fmmoret
Copy link
Author

fmmoret commented Aug 28, 2024

KK -- wasn't sure which project you wanted the issue filed under 👍

@swc-bot
Copy link
Collaborator

swc-bot commented Sep 27, 2024

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Sep 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants