dollarshaveclub / es-check

Checks the version of ES in JavaScript files with simple shell commands 🏆
https://github.com/yowainwright/es-check
MIT License
459 stars 38 forks source link

Allowing validating ES5 code with module=true #70

Open amitdahan opened 6 years ago

amitdahan commented 6 years ago

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 commented 6 years ago

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

amitdahan commented 6 years ago

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

yowainwright commented 6 years ago

@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 commented 6 years ago

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

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

amitdahan commented 6 years ago

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 commented 6 years ago
  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 commented 6 years ago

https://github.com/acornjs/acorn/issues/459