Skip to content

The parser confuses TS constrained mixins with JSX #58

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

Open
fcrozatier opened this issue Jun 17, 2024 · 2 comments · Fixed by sveltejs/acorn-typescript#1
Open

The parser confuses TS constrained mixins with JSX #58

fcrozatier opened this issue Jun 17, 2024 · 2 comments · Fixed by sveltejs/acorn-typescript#1

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
dummdidumm added a commit to sveltejs/acorn-typescript that referenced this issue Feb 26, 2025
Does so by not parsing as JSX by default (this is a breaking change if you would switch to this parser from acorn-typescript)

Fixes sveltejs/svelte#13179
Fixes TyrealHu/acorn-typescript#58
@dummdidumm
Copy link

FYI even after the fix the code snippet will throw, since #options is not defined

@fcrozatier
Copy link
Author

Hey Simon, thanks for working on this in sveltejs/acorn-typescript#1! Yes I realized afterwards that my snippet wasn't self-contained but didn't update as this repo seems abandonned... Hopefully you got the gist of it for your tests

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

Successfully merging a pull request may close this issue.

2 participants