fix(commonjs): Support JSX and TypeScript #971
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rollup Plugin Name:
commonjs
This PR contains:
Are tests included?
Breaking Changes?
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers: #622
Description
It is written in the documentation that the commonjs plugin goes before the babel plugin.
It works fine for most cases. But in some cases, like using TypeScript or JSX; this won't work as the parsing of the source will fail.
One workaround is to do the babel transpilation before, the risk with this approach though is that babel adds helpers (using
import
) and breaks the module detection ofcommonjs
The only safe approach would be to make sure that any syntax close enough to EcmaScript is parsed properly and re-output them identically;
acorn-loose
allows to do this.Downside of this solution:
acorn-loose
will make a valid AST even from the most broken code. So syntax that shouldn't be valid at all will parse correctly. Is it a problem ? in my opinion no, I think projects use linters or other tools to ensure their code is valid and this shouldn't happen too often.Alternatives considered: