Support some TSTypes in the inferrer#14393
Merged
nicolo-ribaudo merged 1 commit intobabel:mainfrom Jun 29, 2022
Merged
Conversation
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52401/ |
JLHwung
commented
Mar 25, 2022
| @@ -1,13 +0,0 @@ | |||
| function foo() { | |||
Contributor
Author
There was a problem hiding this comment.
This test has incorrect layout (should be one-folder deeper) so it is never run. I moved it to the spread plugin.
| // Detect "var foo = Array()" calls so we can optimize for arrays vs iterables. | ||
| if ( | ||
| init.isCallExpression() && | ||
| init.get("callee").isIdentifier({ name: "Array" }) && |
Contributor
Author
There was a problem hiding this comment.
This is moved to the CallExpression handler.
| } | ||
|
|
||
| // TODO: add generic types | ||
| // todo: support merging tuples: number[] |
| for (const y of (b: Array<any>)) {} | ||
| function a(b: Array<any>) { | ||
| for (const y of b) {} | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This test is split to two tests because the former will be optimized but not the latter, which is very confusing.
| if (isTSTypeReference(node) && node.typeParameters) { | ||
| const name = getQualifiedName(node.typeName); | ||
|
|
||
| if (generics[name]) { |
Member
There was a problem hiding this comment.
We should make sure that generics has a null prototype, otherwise this risks reading things from Object.prototype.
9f4a46c to
25fa840
Compare
nicolo-ribaudo
approved these changes
Jun 24, 2022
liuxingbaoyu
approved these changes
Jun 26, 2022
* add ts inferer tests
* fix: support some TSTypes in inferrer
* Update packages/babel-plugin-transform-for-of/src/index.ts
* fix typing errors
* fix(inferer): allow {} prototype name in generics
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2f64c19 to
02c1da1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The inferrer is used by the spread transform and for-of transform to determine whether the argument / rhs is an array from its type annotations or static structure. This PR begins by adding TS tests to the inferrer and fixing bugs caught by the new test.