-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Object spread #11150
Merged
Merged
Object spread #11150
Changes from 74 commits
Commits
Show all changes
103 commits
Select commit
Hold shift + click to select a range
a3ffe6f
Parse, bind and check spread types and elements
sandersn 7004652
Declaration emit spread types and downlevel spread
sandersn bf866ce
Update build files
sandersn 0fea59f
Add spread tests
sandersn c8db211
Update baselines
sandersn 3938559
Move interfaceSpread to correct location
sandersn 63f8c99
Object.assign uses spread types now
sandersn a0db197
Rename Spread[Element]Expression
sandersn 9a7ebb0
Change new file to use CRLF
sandersn cfdf751
Make index signatures work on spread types
sandersn d6e414c
Test spread type index signatures
sandersn 429b0d9
Union multiple spread index signatures
sandersn 78420ad
Test object spread index signatures
sandersn 7e7a26a
Spreads w/a single type parameter assignable to that type parameter
sandersn 0f773c5
Add object spread scenario tests
sandersn 484e66f
Merge branch 'master' into object-spread
sandersn 62c5bda
isDeclaredProperty: Use optional-boolean idiom
sandersn 05ef9dd
Merge branch 'master' into object-spread
sandersn b9af986
Update object spread scenarios test
sandersn d4e910f
Merge branch 'master' into object-spread
sandersn 57850ec
Add more generic assignability cases
sandersn cec3a37
Merge branch 'master' into object-spread
sandersn d770c56
Switch spread types to a binary representation.
sandersn 9872075
Spread type:new assignability+simplification tests
sandersn df73579
Update baselines
sandersn 0d3f567
Merge branch 'master' into object-spread
sandersn 4eedfea
Support unions/intersections in spread types
sandersn 0dd1f0c
Add tests and update baselines.
sandersn 4ee4b6b
Merge branch 'master' into object-spread
sandersn 1b3b35f
Type inference for spread types
sandersn 4bc4a00
Test spread type inference+more index signature tests
sandersn 7417af6
Update baselines
sandersn ce373d9
Revert lib.d.ts error message baseline (unrelated)
sandersn 97dda6e
Remove emacs-added newline at end of baseline
sandersn c5228d3
Remove space at end of line in baseline
sandersn 5a037ad
Add numeric indexer to strings and remove lint
sandersn 1728ae1
Update baselines with spread string's numeric indexers
sandersn ab1b2bb
Reset baseline line number to the locally incorrect value
sandersn 3a85312
Remove trailing newline from baseline again
sandersn dceebcd
Refactor getTypeFromTypeLiteral, from PR comments
sandersn ce84cee
Fix lint
sandersn b6819dc
Merge branch 'master' into object-spread
sandersn f9fe01a
Merge branch 'master' into object-spread
sandersn 18c692a
Remove type inference for spread types
sandersn 62c1868
Update inference test for spread types
sandersn a909053
Make spread assignability and apparent type stricter
sandersn ad10ec5
Update tests w/spread assignability+apparent type
sandersn 76d1944
Spread no longer distributes intersections
sandersn d9afa34
Update spread w/intersection tests
sandersn 7d05ccb
Merge branch 'master' into object-spread
sandersn 3cbac65
Merge branch 'master' into object-spread
sandersn ce61b34
Resolve all-object intersections inside spreads
sandersn 422f73b
Update and improve spread intersection tests
sandersn fdfb159
Simplify expression in resolveObjectIntersection
sandersn ff92afd
Update baselines with new index signature rules
sandersn 510ab1c
Move n-ary spread handling into separate function.
sandersn 485e249
Move multiple-spread handling out of getSpreadType
sandersn 16dfdc4
Clean up and reorder getSpreadType body
sandersn 66d4798
Error for call/construct signatures in spread type
sandersn 2430093
Update baselines with new spread type index errors
sandersn a94fb2f
Explain writeSpreadType a little better
sandersn 35be8c3
Add more commentary to getSpreadType
sandersn 8f59993
Merge branch 'master' into object-spread
sandersn 32af046
Merge branch 'master' into object-spread
sandersn 58ffb4e
Merge branch 'master' into object-spread
sandersn 39b9163
Rename Experimental transform to ESNext
sandersn 988bf1f
Rename TransformFlags.Experimental -> ESNext
sandersn 2ae6ecc
Merge branch 'master' into object-spread
sandersn f2d739f
Spread types handle nested index [access] types
sandersn f65dd21
Test index [access] types inside spread types
sandersn a7c1836
Parse, bind and check rest elements
sandersn e3a08ed
Downlevel emit of rest elements
sandersn ac20b46
Add rest tests
sandersn 9d4ddb6
Update baselines
sandersn 334820c
Remove spread types, leaving spread syntax/emit
sandersn a632020
Fix lint
sandersn a077fd1
Remove spread type tests from spread tests
sandersn 7a2c7ad
Spread handles index signatures from singleton spreads
sandersn 7ff8876
Merge branch 'object-spread' into object-rest-syntax
sandersn 7ed5204
Update objectRestAssignment test and baselines
sandersn 14f8b99
Update objectRestAssignment test
sandersn c9c5f49
Improve readability of ES next destructuring emit
sandersn 71f3157
Address PR comments
sandersn cc342d1
Move convertForOf to factory for esnext and es2015
sandersn 4337369
Update improved baselines
sandersn 4c365bd
Move transformFunctionBody to factory
sandersn a55ed26
Spread any types to any
sandersn a84c7ae
Rename SpreadElementExpression -> SpreadAssignment
sandersn 6a82ae4
Add SpreadAssignment to visitors
sandersn 7b9a42f
Add --target esnext
sandersn d4a5b08
Add --target esnext tests and update baselines
sandersn 83e95d4
Revert unneeded change and comments per PR
sandersn f03fecb
Merge branch 'master' into object-spread
sandersn 609cd00
Merge branch 'object-spread' into object-rest
sandersn 9977936
Do not emit __rest for --target esnext
sandersn 567f563
Create spread property types eagerly
sandersn bd5ce28
Set spread type symbols in checkObjectLiteral
sandersn e1c50e1
Address more PR comments
sandersn 214ce38
Downlevel array destructuring to ES6 in object rest
sandersn 0196947
Improve nested destructuring test for ESNext emit
sandersn fcf32c4
Treat `| undefined` like optionality in spread type
sandersn 9b1f43b
Add strictNullChecks test for object spread
sandersn 25462c9
Merge pull request #12028 from Microsoft/object-rest
sandersn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -1138,8 +1138,8 @@ namespace ts { | |
} | ||
else if (node.kind === SyntaxKind.ArrayLiteralExpression) { | ||
for (const e of (<ArrayLiteralExpression>node).elements) { | ||
if (e.kind === SyntaxKind.SpreadElementExpression) { | ||
bindAssignmentTargetFlow((<SpreadElementExpression>e).expression); | ||
if (e.kind === SyntaxKind.SpreadExpression) { | ||
bindAssignmentTargetFlow((<SpreadExpression>e).expression); | ||
} | ||
else { | ||
bindDestructuringTargetFlow(e); | ||
|
@@ -1154,6 +1154,9 @@ namespace ts { | |
else if (p.kind === SyntaxKind.ShorthandPropertyAssignment) { | ||
bindAssignmentTargetFlow((<ShorthandPropertyAssignment>p).name); | ||
} | ||
else if (p.kind === SyntaxKind.SpreadElementExpression) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been debating renaming this to remove the "Expression" part, since the node itself is not an Expression, and can only be used in an array literal, argument list, or binding pattern. |
||
bindAssignmentTargetFlow((<SpreadElementExpression>p).expression); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -1926,8 +1929,9 @@ namespace ts { | |
case SyntaxKind.EnumMember: | ||
return bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes); | ||
|
||
case SyntaxKind.SpreadElementExpression: | ||
case SyntaxKind.JsxSpreadAttribute: | ||
emitFlags |= NodeFlags.HasJsxSpreadAttributes; | ||
emitFlags |= NodeFlags.HasSpreadAttribute; | ||
return; | ||
|
||
case SyntaxKind.CallSignature: | ||
|
@@ -2492,9 +2496,9 @@ namespace ts { | |
transformFlags |= TransformFlags.AssertTypeScript; | ||
} | ||
|
||
if (subtreeFlags & TransformFlags.ContainsSpreadElementExpression | ||
if (subtreeFlags & TransformFlags.ContainsSpreadExpression | ||
|| isSuperOrSuperProperty(expression, expressionKind)) { | ||
// If the this node contains a SpreadElementExpression, or is a super call, then it is an ES6 | ||
// If the this node contains a SpreadExpression, or is a super call, then it is an ES6 | ||
// node. | ||
transformFlags |= TransformFlags.AssertES2015; | ||
} | ||
|
@@ -2523,7 +2527,7 @@ namespace ts { | |
if (node.typeArguments) { | ||
transformFlags |= TransformFlags.AssertTypeScript; | ||
} | ||
if (subtreeFlags & TransformFlags.ContainsSpreadElementExpression) { | ||
if (subtreeFlags & TransformFlags.ContainsSpreadExpression) { | ||
// If the this node contains a SpreadElementExpression then it is an ES6 | ||
// node. | ||
transformFlags |= TransformFlags.AssertES2015; | ||
|
@@ -3123,9 +3127,10 @@ namespace ts { | |
} | ||
break; | ||
|
||
case SyntaxKind.SpreadExpression: | ||
case SyntaxKind.SpreadElementExpression: | ||
// This node is ES6 syntax, but is handled by a containing node. | ||
transformFlags |= TransformFlags.ContainsSpreadElementExpression; | ||
// This node is ES6 or ES future syntax, but is handled by a containing node. | ||
transformFlags |= TransformFlags.ContainsSpreadExpression; | ||
break; | ||
|
||
case SyntaxKind.SuperKeyword: | ||
|
@@ -3163,13 +3168,19 @@ namespace ts { | |
transformFlags |= TransformFlags.ContainsLexicalThis; | ||
} | ||
|
||
if (subtreeFlags & TransformFlags.ContainsSpreadExpression) { | ||
// If an ObjectLiteralExpression contains a spread element, then it | ||
// is an ES next node. | ||
transformFlags |= TransformFlags.AssertESNext; | ||
} | ||
|
||
break; | ||
|
||
case SyntaxKind.ArrayLiteralExpression: | ||
case SyntaxKind.NewExpression: | ||
excludeFlags = TransformFlags.ArrayLiteralOrCallOrNewExcludes; | ||
if (subtreeFlags & TransformFlags.ContainsSpreadElementExpression) { | ||
// If the this node contains a SpreadElementExpression, then it is an ES6 | ||
if (subtreeFlags & TransformFlags.ContainsSpreadExpression) { | ||
// If the this node contains a SpreadExpression, then it is an ES6 | ||
// node. | ||
transformFlags |= TransformFlags.AssertES2015; | ||
} | ||
|
Oops, something went wrong.
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.
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.
Why
SpreadExpression
here, butSpreadElementExpression
on 1157?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.
[ x, ...y]
produces aSpreadExpression
(nowSpreadElement
) for...y
.{ x: 1, ...y }
producesSpreadElementExpression
(nowSpreadAssignment
) for...y
. So the nodes are actually different for arrays vs objects.