caoccao / swc4j

swc4j (SWC for Java) is an ultra-fast JavaScript and TypeScript compilation and bundling tool on JVM.
Apache License 2.0
42 stars 1 forks source link

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

Closed fanksy closed 3 months ago

fanksy commented 3 months ago
Swc4jTranspileOptions options = new Swc4jTranspileOptions()
                .setCaptureAst(true)
                .setUseTsDecorators(true)
                .setUseDecoratorsProposal(true)
                .setEmitMetadata(false)
                .setMediaType(getMediaType(path));

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

有一个相关的issue:https://github.com/babel/babel-eslint/issues/662

解决方式:

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

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

caoccao commented 3 months ago

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

caoccao commented 3 months ago

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

fanksy commented 3 months ago

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 commented 3 months ago

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

fanksy commented 3 months ago

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

fanksy commented 3 months ago

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 commented 3 months ago

I hope this can help you to figure it out.

caoccao commented 3 months ago

Please set the media type to Tsx and try again.

fanksy commented 3 months ago

Please set the media type to Tsx and try again.

测试OK

Tsx完全兼容Jsx ?

Jsx都可以用Tsx来解析?

caoccao commented 3 months ago

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