Forbid class fields to fix transpilation errors with Vite/ESBuild #12658
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.
Closes #12656, an issue where v2.14 broke building GL JS in some setups involving ESBuild / Vite. The issue was accidentally introduced in #12588 by adding a class field in one place in the source code. In some project setups, this class field introduced a helper method (
__publicField
), which obviously broke our dynamic main thread / worker bundling setup, where helper functions aren't included in the worker code.The helper function in turn only appears because of subtle inconsistencies between TypeScript class fields and later developed ECMAScript class fields, defined by the
useDefineForClassFields
option. This option is turned on by default in Vite, so when GL JS is a part of a bundle with Vite (or ESBuild with this option set), and the target is anything belowes2022
, it produces a broken bundle.For now, I'm introducing an ESLint rule to make sure we don't accidentally introduce class fields in our source code, but in the future, we'll need to think of a way to deal with similar problems related to bundling and new syntax.
Launch Checklist
mapbox-gl-js
changelog:<changelog>Fix transpilation issues with some setups involving Vite or ESBuild</changelog>