Skip to content

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

Merged
merged 17 commits into from
Nov 16, 2016
Merged

Streamline destructuring #12250

merged 17 commits into from
Nov 16, 2016

Conversation

rbuckton
Copy link
Member

@rbuckton rbuckton commented Nov 15, 2016

This PR cleans up some of our destructuring transform to be more consistent, along with a few additional changes:

  • Converges flattening of binding pattern and assignment patterns to follow the same code paths.
  • Adds to NodeArray a transformFlags 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.
  • Consolidates a few TransformFlags enum members to free up some space
  • Added ContainsObjectRest/ContainsObjectSpread to allow us to more accurately detect esnext features.
  • Changes the type check for Object rest assignment to allow any valid lref via a call to checkReferenceExpression to align with the spec proposal.
  • Fixes a few cases where we unnecessarily emit the rval for a DestructuringAssignment that goes unused.
  • Cleans up esnext.ts to remove dependencies on es2015 transformations.
  • Moves es2015 transformations added to factory.ts back into es2015.ts

@rbuckton
Copy link
Member Author

// cc: @sandersn, @mhegazy

Copy link
Member

@sandersn sandersn left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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 {
Copy link
Member

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

Copy link
Member Author

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 + ""`
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Member

@sandersn sandersn left a 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.");
Copy link
Member

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.

Copy link
Member

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;
Copy link
Member

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.
Copy link
Member

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,
Copy link
Member

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;
}
}

/**
Copy link
Member

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.

@rbuckton rbuckton merged commit 3110f40 into master Nov 16, 2016
@rbuckton rbuckton deleted the streamlineDestructuring branch November 16, 2016 18:10
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants