-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Streamline destructuring #12250
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
Streamline destructuring #12250
Conversation
I missed these before, so emit was incorrect for object rest in a method or accessor parameter.
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.
The code change looks good although I still need to look at the tests. Glancing over them, though, it looks like it's just improvements.
visitor, | ||
/*recordTempVariable*/ undefined, | ||
/*skipInitializer*/ false, | ||
/*recordTempVariablesInLine*/ true, | ||
convertObjectRest |
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.
same here
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 not an issue now that I've merged in the work from isolateObjectSpread
.
temp, | ||
/*skipInitializer*/ convertObjectRest, | ||
/*recordTempVariablesInLine*/ true, | ||
convertObjectRest |
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 not make the enum a parameter to this function instead of handling the boolean?
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 not an issue now that I've merged in the work from isolateObjectSpread
.
convertObjectRest | ||
? FlattenLevel.ObjectRest |
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.
same here
@@ -3,626 +3,377 @@ | |||
|
|||
/*@internal*/ | |||
namespace ts { | |||
interface FlattenHost { |
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.
probably FlattenContext
is a better 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.
Works for me.
const propertyName = getPropertyNameOfBindingOrAssignmentElement(elements[i]); | ||
if (propertyName) { | ||
if (isComputedPropertyName(propertyName)) { | ||
// get the temp name and put that in there instead, like `_tmp + ""` |
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.
can you update this to just give the emit: typeof _tmp === "symbol" ? _tmp : _tmp + ""
? The comment I wrote is wordy and out of date to boot.
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.
Sure
…accessor-parameters' into streamlineDestructuring
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.
Looks good except for some typos.
@@ -283,26 +287,26 @@ namespace ts { | |||
* Records a hoisted variable declaration for the provided name within a lexical environment. | |||
*/ | |||
function hoistVariableDeclaration(name: Identifier): void { | |||
Debug.assert(!lexicalEnvironmentDisabled, "Cannot modify the lexical environment during the print phase."); | |||
Debug.assert(!scopeModificationDisabled, "Cannot modify the lexical environment during the print phase."); |
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.
Probably should update the assert message.
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.
Or maybe this is still correct. I can't tell.
context: TransformationContext; | ||
level: FlattenLevel; | ||
recordTempVariablesInLine: boolean; | ||
doNotRecordTempVariablesInLine: boolean; |
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.
Minor, but is there a positive way to express doNotRecordInline? Hoist? Extrapose? Prepend?
* @param boundValue The value bound to the declaration. | ||
* @param recordTempVariablesInLine Indicates whether temporary variables should be recored in-line. | ||
* @param skipInitializer A value indicating whether to ignore the initializer of `node`. | ||
* @param doNotRecordTempVariablesInLine Indicates whether temporary variables should not be recored in-line. |
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.
Typo:recorded
boundValue: Expression | undefined, | ||
flattenContext: FlattenContext, | ||
element: BindingOrAssignmentElement, | ||
value: Expression | undefined, |
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.
I like the shorter names
} | ||
return temp; | ||
} | ||
} | ||
|
||
/** |
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.
These 3-line jsdoc are low-value in my opinion. They just restate in English what the signature already says.
This PR cleans up some of our destructuring transform to be more consistent, along with a few additional changes:
NodeArray
atransformFlags
property which consists of the transform flags of each node in the array without exclusions. This allows us to query the transform flags of each node in a node array without the need to traverse the array.TransformFlags
enum members to free up some spaceContainsObjectRest
/ContainsObjectSpread
to allow us to more accurately detect esnext features.checkReferenceExpression
to align with the spec proposal.DestructuringAssignment
that goes unused.esnext.ts
to remove dependencies ones2015
transformations.es2015
transformations added tofactory.ts
back intoes2015.ts