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

CSF files support: TypeScript and ECMAScript Next support #1748

Closed
sapegin opened this issue Feb 28, 2021 · 4 comments
Closed

CSF files support: TypeScript and ECMAScript Next support #1748

sapegin opened this issue Feb 28, 2021 · 4 comments

Comments

@sapegin
Copy link
Member

sapegin commented Feb 28, 2021

CSF support (#1497) is being implemented as part of switching internals to Mdx (#1712) in #1720.

This issue is my quick research on how to support TypeScript and ECMAScript Next (optional chaining and that kind of stuff) in CSF files.

Here are the options I can think of so far:

  • Acorn (current option but updated to the latest version): solves ECMAScript Next but no TS support.
  • Sucrase + Acorn: nope, Sucrase supports TS but transpiles too much (JSX and new syntax, for example), so we can't use its output in the examples.
  • Acorn-loose: it's parsing the code but the AST is all wrong.
  • Babel (I haven’t tried it yet): should be the most bulletproof way but we’ll need to migrate all the code to it, and we use Acorn on the client because of its small size and probably should continue doing so.

The last option seems to be the only solution.

@okonet
Copy link
Member

okonet commented Mar 1, 2021

Quickly scanning trough the https://astexplorer.net available parser options I found the following parser to be working with TS basic example:

but only the last two having TS specific AST (TSTypeAnnotation)

@sapegin
Copy link
Member Author

sapegin commented Mar 17, 2021

@babel/parser works too but we need to enable typescript plugin (and disable flow plugin since they don't work together). I don't think we need data about types in the AST but @babel/parser has that too.

@sapegin
Copy link
Member Author

sapegin commented Mar 18, 2021

The @babel/parser seems to work:

image

@stale
Copy link

stale bot commented Jun 22, 2021

😴 This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week without any further activity. Consider opening a pull request if you still have this issue or want this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@okonet @sapegin and others