Fix: Workaround for transpilation failure with create-react-app #9093
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.
Description of change
Users using
create-react-app
+ PixiJS are continuously facing problem with transpilation (#8733, #8824 and #9064). Let me explain the details.In #8698 I added code below in
ImageBitmapResource.constructor
:pixijs/packages/core/src/textures/resources/ImageBitmapResource.ts
Lines 62 to 73 in 2f12f4e
This looks good, and when releasing it will be transpiled by
esbuild
:(Source code of related logic in esbuild here.)
Until then, everything is fine, but users usually need to do their own transpilation, and here is where it can cause problems. Noticing that
__super = (...args) => { super(...args); }
is an arrow function with railing comma in parameters, and have asuper
call in its body. Unfortunately, due to limitation of transpilation, it is impossible to transpile it without transpiling the whole class (using polyfills like_createClass
in Babel instead of native ES6 classes).This situation can happen when using the default setting of
create-react-app
, or@babel/preset-env
with targetsince 2017
. Previously Babel wrongly transpiles this into:This will lead to infinite recursion. So I opened issue babel/babel#15148 and PR babel/babel#15163 to fix this bug in Babel. Now it will report error when transpiling:
Users will get an explicit error instead of a confusing infinite recursion, but it is still quite annoying. So in this PR I just move
super()
out ofif()
, solving this issue.Pre-Merge Checklist
npm run lint
)npm run test
)