Modern JavaScript
See original GitHub issueI think it is time to move to modern JavaScript in the source code.
IMPORTANT: This is not a proposal to drop support for some Browser!
JavaScript evolved a lot in the last years. This Repro is (except for esModules that are handled by rollup) written in es3 way. This is JavaScript of 1999.
good:
- No transpiler needed
- Runs in all Browsers
bad:
- Bundle is bigger for all browsers with code they will never use
- Development is more complex as you have to check if you are allowed to use specific features.
Proposal
Write source code in a modern syntax and transpile it down to differnet levels. I suggest transpiling for es3 and es2017. es2017 is supported by all evergreen Browsers (95% combined useage) and can be transpiled down as needed by the developer of a webpage.
We can provide more tragets as needed. The idea is not to add any breaking changes. So default entry file would still be the es3 version but developers can manualy change that. (Docs should be added how to to this in webpack, rollup, esbuild, …)
What changes in the source should happen
- Better build with transpile to es3
- Class Syntax to es6 classes (see #7614 - includes transpiling to es5)
- Instead of most Util functions use the native ones (transpiler handles the rest)
- Use modern syntax for example rest Arguments:
(a, b, ...rest) => {/* ... */}
What about typescript?
I think typescript is great but I think we should do one step at a time so if this issue is resolved in a positive way we can talk about typescript. If the above is done you can rewrite all code to ts in no time.
See also #7591
Issue Analytics
- State:
- Created 2 years ago
- Reactions:34
- Comments:8 (1 by maintainers)
Top GitHub Comments
As @IvanSanchez said something dropping support for IE 10 this is not needed at all to go to es5 (just to clarify).
If you DROP: IE 7-8 (<0.05%) Frefox 2-3.6 (0.02%) Chrome 4-18 (0.1%) Safari 5-5.1 (<0.03%) Android Browser: 2.2-3 (0%)
= Drop support for 0.2% useage. We would have complete es5 with 2 small caveats (strict mode; parseInt not like spec with 0 at start).
And note that class syntax is es6.
see https://caniuse.com/es5
@IvanSanchez
So maybe it is time for leaflet 2.0? There is a versioning, also the modern web requires a lot more and has also wider capabilities - 3d rendering, webgl, more details. Nowdays apps are more interactive than just showing marker on the static map and let the user to click on it.
IMHO, if you want to handle the compability with IE10 or IE11, you can leave leaflet 1.x on it path, and apply only critical fixes, which would be not necessary - personaly I still use 1.5 because of some stuff which did not allow me to migrate at my time, and since then… I did not see any bigger reason to update.
And others would use new features, performance etc. Really, I though a couple times to migrate to some newer lib. Seriosuly, what is a percentage of IE10 users now? and why can’t they just ose the old version?
BTW does it not look strange to you that Volodymyr Agafonkin is using mapbox on this webgl demo? https://blog.mapbox.com/how-i-built-a-wind-map-with-webgl-b63022b5537f