Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support some TSTypes in the inferrer (#14393)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
- Loading branch information
1 parent
1261051
commit 2f459ff
Showing
30 changed files
with
690 additions
and
178 deletions.
There are no files selected for viewing
This file contains 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
3 changes: 2 additions & 1 deletion
3
packages/babel-plugin-transform-for-of/test/fixtures/opt/options.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"plugins": ["transform-for-of", "transform-flow-strip-types"] | ||
"plugins": ["transform-for-of"], | ||
"presets": ["typescript"] | ||
} |
4 changes: 4 additions & 0 deletions
4
...babel-plugin-transform-for-of/test/fixtures/opt/type-annotation-array-flow-deopt/input.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This won't be optimize because when `for-of` is handled, the b's type annotation has been removed by the Flow plugin | ||
function a(b: Array<any>) { | ||
for (const y of b) {} | ||
} |
3 changes: 3 additions & 0 deletions
3
...l-plugin-transform-for-of/test/fixtures/opt/type-annotation-array-flow-deopt/options.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["transform-for-of", "transform-flow-strip-types"] | ||
} |
15 changes: 15 additions & 0 deletions
15
...abel-plugin-transform-for-of/test/fixtures/opt/type-annotation-array-flow-deopt/output.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// This won't be optimize because when `for-of` is handled, the b's type annotation has been removed by the Flow plugin | ||
function a(b) { | ||
var _iterator = babelHelpers.createForOfIteratorHelper(b), | ||
_step; | ||
|
||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
const y = _step.value; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-for-of/test/fixtures/opt/type-annotation-array-flow/input.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
for (const y of (b: Array<any>)) {} |
3 changes: 3 additions & 0 deletions
3
...s/babel-plugin-transform-for-of/test/fixtures/opt/type-annotation-array-flow/options.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["transform-for-of", "transform-flow-strip-types"] | ||
} |
3 changes: 3 additions & 0 deletions
3
...ages/babel-plugin-transform-for-of/test/fixtures/opt/type-annotation-array-flow/output.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
for (var _i = 0, _arr = b; _i < _arr.length; _i++) { | ||
const y = _arr[_i]; | ||
} |
4 changes: 4 additions & 0 deletions
4
...s/babel-plugin-transform-for-of/test/fixtures/opt/type-annotation-array-ts-deopt/input.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This won't be optimize because when `for-of` is handled, the b's type annotation has been removed by the TS plugin | ||
function a(b: Array<any>) { | ||
for (const y of b) {} | ||
} |
4 changes: 4 additions & 0 deletions
4
...bel-plugin-transform-for-of/test/fixtures/opt/type-annotation-array-ts-deopt/options.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["transform-for-of"], | ||
"presets": ["typescript"] | ||
} |
5 changes: 1 addition & 4 deletions
5
...est/fixtures/opt/typeannotation/output.js → .../type-annotation-array-ts-deopt/output.js
This file contains 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
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-for-of/test/fixtures/opt/type-annotation-array-ts/input.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
for (const y of (b as Array<any>)) {} |
4 changes: 4 additions & 0 deletions
4
...ges/babel-plugin-transform-for-of/test/fixtures/opt/type-annotation-array-ts/options.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["transform-for-of"], | ||
"presets": ["typescript"] | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-transform-for-of/test/fixtures/opt/type-annotation-array-ts/output.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
for (var _i = 0, _arr = b; _i < _arr.length; _i++) { | ||
const y = _arr[_i]; | ||
} |
4 changes: 0 additions & 4 deletions
4
packages/babel-plugin-transform-for-of/test/fixtures/opt/typeannotation/input.js
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
packages/babel-plugin-transform-spread/test/fixtures/spread/type-reference-flow/input.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function foo() { | ||
const x = 1 ? a() : b(); | ||
const y = a() || b(); | ||
|
||
return [...x, ...y]; | ||
} | ||
|
||
function a(): Array<number> { | ||
return []; | ||
} | ||
|
||
function b(): Array<number> { | ||
return []; | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-plugin-transform-spread/test/fixtures/spread/type-reference-flow/options.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["transform-spread"], | ||
"presets": ["flow"] | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/babel-plugin-transform-spread/test/fixtures/spread/type-reference-flow/output.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function foo() { | ||
const x = 1 ? a() : b(); | ||
const y = a() || b(); | ||
return [].concat(x, y); | ||
} | ||
|
||
function a() { | ||
return []; | ||
} | ||
|
||
function b() { | ||
return []; | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/babel-plugin-transform-spread/test/fixtures/spread/type-reference-ts/input.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function foo() { | ||
const x = 1 ? a() : b(); | ||
const y = a() || b(); | ||
|
||
return [...x, ...y]; | ||
} | ||
|
||
function a(): Array<number> { | ||
return []; | ||
} | ||
|
||
function b(): Array<number> { | ||
return []; | ||
} |
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
packages/babel-plugin-transform-spread/test/fixtures/spread/type-reference-ts/output.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function foo() { | ||
const x = 1 ? a() : b(); | ||
const y = a() || b(); | ||
return [].concat(x, y); | ||
} | ||
|
||
function a() { | ||
return []; | ||
} | ||
|
||
function b() { | ||
return []; | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.