Types: Convert Cartesian2-4.js to ES6 classes#13168
Conversation
|
Thank you for the pull request, @donmccurdy! ✅ We can confirm we have a CLA on file for you. |
|
Personally, I would recommend using a script to uniformly convert all js files, just like converting from AMD to ES6 syntax before. I used Babel to parse the expression tree of JavaScript, then tried to convert it into an ES6 class. Currently, most of the conversion work has been completed, but there are still some issues that need to be addressed when running it. |
b078626 to
3ee211d
Compare
|
Hi @Hiwen! This PR was generated with the script from #13125. Internally my script uses lebab and espree. So far the script seems to do well — it fails for a few files (not in this PR) but at least alerts us to the files it cannot safely convert, so we can handle them manually. Would you be interested in opening a PR or two helping to convert some remaining source files in |
This suggests a certain "rigurousness"(?) of the language. There are no structures. There are no contracts. There is no meaning. JavaScript receives its meaning by execution. So maybe, in some ways, JavaScript is the origin of the phrase "It is what it is", because "duck typing" is one aspect of all that. And now there are adventurous things like , and I think that this could be considered to be a "child class" ofCartesian3 - at least, it is declared to be a Cartesian3 in the normal getter. I won't argue. I'm just wondering.
|
@donmccurdy Thank you very much for your invitation. I still need to do some research to further verify the feasibility of batch conversion. However, if batch conversion is carried out, it will be a huge PR, and it will be very difficult to complete the review within an hour! |
|
@javagl yes, that's fair. I'm aiming to provide a rule that's clear and legible enough to help us make progress safely and stay well clear of more time-consuming issues. Duck-typing is not a problem. But mixing ES6 class syntax with prototypal inheritance can be a problem, if a child class needs to invoke the constructor of a parent class, and only the parent is using ES6 class syntax. This came up for three.js in mrdoob/three.js#17425, with symptoms as shown in this JSFiddle: https://jsfiddle.net/w2xfb6eg/. Not a hard-and-fast rule, but will reduce the number of things we need to worry about and test, if we can avoid mixed the two in the same inheritance chain. @Hiwen thank you! Please note #13125 — it contains a bulk conversion of most of |
jjspace
left a comment
There was a problem hiding this comment.
Thanks @donmccurdy, these changes look good to me. I did do a quick check of the docs and generated TS files and those look correct too.
Did you want to turn on type checking for these files in this PR? It seems like it should work well with the new classes and that was the thing that spurred this on correct?
We actually just recently ran into this limitation in another PR. It's really annoying that Thanks for the changes @donmccurdy |
|
Thanks @jjspace! Attempting the TypedArray alias here: |
@donmccurdy I tested your script and I think it works really well. Sorry I didn't notice it before. |


Description
Converts Cartesian2, Cartesian3, and Cartesian3 to ES6 classes. The changes are very easy to make semi-automatically (see steps below) but not entirely trivial to review. So I'm inclined to do a few "small" PRs like this first and build up confidence, then attempt bigger batches.
Steps
new Cartesian+\.[a-z], and remove 'new' in each case.node ./lebab-batch.js "packages/engine/Source/Core/Cartesian*.js". If the script outputs warnings, decide whether to skip these files or to manually resolve them, considering (1) above. In this PR, no errors were encountered.Reviewing
Review is much easier with GitHub's split view, and whitespace changes hidden (
?diff=split&w=1). Lebab shouldn't change the order of class members unnecessarily.Issue number and link
Testing plan
Unit test coverage and ESLint should give us pretty good confidence on a mechanical change like this — but if there are other specific concerns let's take a look. On a visual check the API documentation looks identical.
Author checklist
CONTRIBUTORS.mdI have updatedCHANGES.mdwith a short summary of my changePR Dependency Tree
This tree was auto-generated by Charcoal