Skip to content

styled-jsx invokes the minifier on typescript code #10944

@lukesandberg

Description

@lukesandberg

Describe the bug

https://github.com/swc-project/plugins/blame/bd98a2e3acd94025755c25521218dc430075bc3f/packages/styled-jsx/transform/src/visitor.rs#L555

Invokes the evaluator to check if an expression is a constant or not, however when run on a TSX file this triggers a debug_unreachable statement deep in the Compressor

thread 'styled_tsx_fixture_swc_tests__fixture__tsx_expressions__input_tsx' panicked at /Users/lukesandberg/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/swc_ecma_visit-14.0.0/src/lib.rs:618:9:
internal error: entered unreachable code: This visitor does not support TypeScript. This method fails for optimization purposes. Encountered in unreachable visitor: visit_ts_interface_decl
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Context: Decl(TsInterface(TsInterfaceDecl { span: 3..40, id: Ident { span: 13..18, ctxt: #2, sym: "Props", optional: false }, declare: false, type_params: None, extends: [], body: TsInterfaceBody { span: 19..40, body: [TsPropertySignature(TsPropertySignature { span: 25..38, readonly: false, key: Ident(Ident { span: 25..30, ctxt: #0, sym: "color", optional: false }), computed: false, optional: false, type_ann: Some(TsTypeAnn { span: 30..38, type_ann: TsKeywordType(TsKeywordType { span: 32..38, kind: TsStringKeyword }) }) })] } }))

lukesandberg/plugins#1 provides a simple repro

Not sure if i should file here or against styled-jsx, they do the exact same thing in babel

https://github.com/vercel/styled-jsx/blob/d7a59379134d73afaeb98177387cd62d54d746be/src/_utils.js#L230

So perhaps the compressor should just ignore typescript code rather than crash? or perhaps there is a different API the plugin should be using?

Input code

interface Props {
    color: string
}

export default (p:Props) => (
  <div>
    <p>test</p>
    <style jsx>{`
      span {
        color: ${p.color};
      }
    `}</style>
  </div>
);

Config

Link to the code that reproduces this issue

lukesandberg/plugins#1

SWC Info output

No response

Expected behavior

i would expect the program not to crash

Actual behavior

No response

Version

34

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions