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

【Help】Using the export keyword between a decorator and a class is not allowed. Please use export @dec class instead #3

Closed
fanksy opened this issue Jun 9, 2024 · 10 comments

Comments

@fanksy
Copy link

fanksy commented Jun 9, 2024

Swc4jTranspileOptions options = new Swc4jTranspileOptions()
                .setCaptureAst(true)
                .setUseTsDecorators(true)
                .setUseDecoratorsProposal(true)
                .setEmitMetadata(false)
                .setMediaType(getMediaType(path));

请问该如何设置才能正常解析

有一个相关的issue:babel/babel-eslint#662

解决方式:

"parserOptions": {
    "ecmaFeatures": {
      "legacyDecotators": true
    }
  }

这个在Options里面没有对应的选项

@caoccao
Copy link
Owner

caoccao commented Jun 9, 2024

Please leave the complete code so that it can be reproduced.

caoccao added a commit that referenced this issue Jun 10, 2024
@caoccao
Copy link
Owner

caoccao commented Jun 10, 2024

I fail to see there's anything wrong. Please check this commit out.

@fanksy
Copy link
Author

fanksy commented Jun 10, 2024

I fail to see there's anything wrong. Please check this commit out.

import React from 'react';
import { connect } from 'react-redux';

const ConditionModal = loadable(() => import('components/ConditionModal'));

@connect((state) => {

  return {
  };
})
export default class MyComponent extends React.Component {
  componentDidMount() {}

  render() {
    const {
      visible,
    } = this.props;
    return (
      <>
        {!!visible && (true)}
        {true && <ConditionModal />}
      </>
    );
  }
}

@fanksy
Copy link
Author

fanksy commented Jun 10, 2024

Swc4jTranspileOptions options = new Swc4jTranspileOptions()
.setCaptureAst(true)
.setMediaType(Swc4jMediaType.Jsx);

@fanksy
Copy link
Author

fanksy commented Jun 10, 2024

Swc4jParseOutput parseOutput = swc4j.parse(script, options);
Swc4jAstModule module = (Swc4jAstModule) parseOutput.getProgram();

@fanksy
Copy link
Author

fanksy commented Jun 10, 2024

com.caoccao.javet.swc4j.exceptions.Swc4jCoreException: Using the export keyword between a decorator and a class is not allowed. Please use export @dec class instead. at file:///main.js:14:1

@connect((state) => {


~
...
})
~~

  at com.caoccao.javet.swc4j.exceptions.Swc4jCoreException.parseError(Swc4jCoreException.java:54)
  at com.caoccao.javet.swc4j.Swc4jNative.coreParse(Native Method)
  at com.caoccao.javet.swc4j.Swc4j.parse(Swc4j.java:80)

@fanksy
Copy link
Author

fanksy commented Jun 10, 2024

I hope this can help you to figure it out.

@caoccao
Copy link
Owner

caoccao commented Jun 11, 2024

Please set the media type to Tsx and try again.

@fanksy
Copy link
Author

fanksy commented Jun 11, 2024

Please set the media type to Tsx and try again.

测试OK

Tsx完全兼容Jsx ?

Jsx都可以用Tsx来解析?

@caoccao
Copy link
Owner

caoccao commented Jun 11, 2024

I think it's your decision to parse the templates as Jsx or Tsx.

@caoccao caoccao closed this as completed Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants