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

The parser confuses TS constrained mixins with JSX #58

Open
fcrozatier opened this issue Jun 17, 2024 · 0 comments
Open

The parser confuses TS constrained mixins with JSX #58

fcrozatier opened this issue Jun 17, 2024 · 0 comments

Comments

@fcrozatier
Copy link

Here's a minimal reproduction code:

export const Triggerable = <C extends HTMLElement = HTMLElement>(superClass: C) => {
  return class extends superClass {
    initTriggerable(options) {
      this.#options = options;
	}
    };
};

This is just a standard ts mixin

Trying to parse a file containing this code yields an error

> const options = { sourceType: 'module', ecmaVersion: 'latest', locations: true };
> const code = 'export const Triggerable = <C extends HTMLElement = HTMLElement>(superClass: C) => {\n' +
  '\treturn class extends superClass {\n' +
  '\t\tinitTriggerable(options) {\n' +
  '\t\t\tthis.#options = options;\n' +
  '\t\t}\n' +
  '\t};\n' +
  '};\n'
> parser.parse(code, options)
Uncaught:
[SyntaxError: JSX value should be either an expression or a quoted JSX text (1:52)
] {
  pos: 52,
  loc: Position { line: 1, column: 52 },
  raisedAt: 63
}

This prevents me from using acorn-typescript for parsing some ts files

@fcrozatier fcrozatier changed the title The parser confuses TS constrained mixins for JSX The parser confuses TS constrained mixins with JSX Jun 18, 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

1 participant