Skip to content
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

Syntax error incorrectly reported #431

Open
major-mann opened this issue Aug 9, 2023 · 1 comment
Open

Syntax error incorrectly reported #431

major-mann opened this issue Aug 9, 2023 · 1 comment
Labels

Comments

@major-mann
Copy link

import styled from "styled-components";

const rad = `100px`;

const Fails = styled.div`
    border-radius:
        ${rad}
        ${rad}
        ${rad}
        ${rad};
`;

const Succeeds = styled.div`
    border-radius:
        ${rad}
        ${rad}
        ${rad}
        0px;
`;

const Workaround = styled.div`
    border-radius:
        ${rad}
        ${rad}
        ${rad}
        ${rad}\t;
`;

The first example underlines the r of the last ${rad} is underlined in red with the error: semi-colon expected ts-styled-plugin(9999), and the semicolon after the CSS is underlined with the error: at-rule or selector expected ts-styled-plugin(9999)

This error shows whenever the CSS rule value has a newline in it, and the final row contains only a template replacement.

Screenshot of red underline
Screenshot 2023-08-09 at 19 55 06

To Reproduce
Paste code above into a javascript (or typescript) editor. See the error displayed on the r.

Expected behavior
There is no syntax error reported

  • OS: OSXx
  • VSCode Version: 1.81.0
  • Extension Version 1.7.8
@major-mann major-mann added the bug label Aug 9, 2023
@codingcss
Copy link

I apologize for any confusion. It appears that the TypeScript styled-plugin is misinterpreting your code. To work around this issue, you can modify the template literals to see if it resolves the reported error. Here's an alternative approach:

import styled from "styled-components";

const rad = `100px`;

const Fails = styled.div`
    border-radius: ${rad} ${rad} ${rad} ${rad};
`;

const Succeeds = styled.div`
    border-radius: ${rad} ${rad} ${rad} 0px;
`;

const Workaround = styled.div`
    border-radius: ${rad} ${rad} ${rad} ${rad}; /* No trailing space or tabs */
`;

In the Workaround component, I've removed the trailing tab and space after the last ${rad}. This might help the TypeScript styled-plugin to interpret the code correctly.

If the issue persists, it might be worth checking if there are any updates to the TypeScript styled-plugin or styled-components that address this specific problem. Alternatively, you can consider suppressing the error if it doesn't impact the functionality of your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants