Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Allowing validating ES5 code with module=true #70

Open
amitdahan opened this issue Sep 13, 2018 · 7 comments
Open

Allowing validating ES5 code with module=true #70

amitdahan opened this issue Sep 13, 2018 · 7 comments

Comments

@amitdahan
Copy link

Requested Update

Allow validating code written in ES5 EXCEPT module imports/exports.

Why Is This Update Needed?

We're transpiling our code to ES5 but still use ES modules to allow for tree-shaking.
We wanted to make sure our generated code is ES5 with the exception of the module syntax which will be handled by webpack in consuming projects (talking about an internal lib).

We need to somehow ignore import/export syntax while still ES5-check our code, if possible/makes sense to you guys.

Thanks a bunch!

@yowainwright
Copy link
Contributor

@amitdahan does this work es-check es5 --modules true '<files to be checked>'?

@amitdahan
Copy link
Author

No unfortunately that fails when it encounters the import/export token :(

@yowainwright
Copy link
Contributor

@amitdahan hmmm...could you paste a code sample of what the transpiled code we're discussing looks like? Also, could you paste what transpiling config—like a babelrc or tsconfig?

To provide you with more context, here's a link to Acorn's Parser README.

@amitdahan
Copy link
Author

https://gist.github.com/amitdahan/0a571323da388668d1b88649c2b9d435

Simple enough, use TypeScript to target ES5 with the exception of modules.

@amitdahan
Copy link
Author

Tried using acorn --ecma5 --module dist/index.js also and got basically the same result, so I'm guessing this is a limitation of acorn?

@yowainwright
Copy link
Contributor

yowainwright commented Sep 17, 2018

  1. Thanks for the gist!
  2. "limitation of acorn" yes, sort of 😃...I don't know if import/export was a thing when es5 was initially released (?). When es5 was released, I believe there was commonjs (which supports treeshaking). In the company projects I work on, I use commonjs instead of esnext and transpile to es5 and do treeshaking. That is a note, not a how-to. I'm curious what we can do to resolve this sort of issue in es-check, though.

@brandonocasey
Copy link
Contributor

acornjs/acorn#459

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

No branches or pull requests

3 participants