New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support some TSTypes in the inferrer #14393
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52401/ |
@@ -1,13 +0,0 @@ | |||
function foo() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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" }) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is moved to the CallExpression
handler.
@@ -47,7 +55,27 @@ export default function removeTypeDuplicates( | |||
continue; | |||
} | |||
|
|||
// TODO: add generic types | |||
// todo: support merging tuples: number[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a follow-up to #11378.
for (const y of (b: Array<any>)) {} | ||
function a(b: Array<any>) { | ||
for (const y of b) {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make sure that generics
has a null prototype, otherwise this risks reading things from Object.prototype
.
9f4a46c
to
25fa840
Compare
* 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
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.