Skip to content
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

Fixes rename for destructuring, named imports and default imports #7945

Merged
merged 17 commits into from
Apr 13, 2016

Conversation

sheetalkamat
Copy link
Member

Fixes #6312, #7708 and #7024

@sheetalkamat sheetalkamat changed the title Fixes rename for destructuring and named imports Fixes rename for destructuring, named imports and default imports Apr 8, 2016
@@ -5624,8 +5624,34 @@ namespace ts {
};
}

function isImportSpecifierSymbol(symbol: Symbol) {
return (symbol.flags & SymbolFlags.Alias) && !!getDeclarationOfKind(symbol, SyntaxKind.ImportSpecifier);
function getImportOrExportSpecifierPropertyNameSymbolSpecifier(symbol: Symbol, location: Node): ImportOrExportSpecifier {
Copy link
Member

Choose a reason for hiding this comment

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

getImportOrExportSpecifierForPropertyNameSymbol?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@DanielRosenwasser
Copy link
Member

Is there a way to open the scope of this for object assignment patterns?

interface I {
    x: number;
}

var a: I;
var x;

({ /*renameHere*/x: x } = a);

@sheetalkamat
Copy link
Member Author

That eg. gets handled by ad916ab. I added the test case for it just now.

function checkArrayLiteralDestructuringElementAssignment(node: ArrayLiteralExpression, sourceType: Type,
element: Expression, index: number, elementType: Type, contextualMapper?: TypeMapper) {
const elements = node.elements;
if (element.kind !== SyntaxKind.OmittedExpression) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this implicitly return undefined? Invert the conditions here to reduce nesting and make the returns explicit.


// If the reference location is in an object literal, try to get the contextual type for the
// object literal, lookup the property symbol in the contextual type, and use this symbol to
// compare to our searchSymbol
if (isNameOfPropertyAssignment(referenceLocation)) {
return forEach(getPropertySymbolsFromContextualType(referenceLocation), contextualSymbol => {
const contexualSymbol = forEach(getPropertySymbolsFromContextualType(referenceLocation), contextualSymbol => {
Copy link
Member

Choose a reason for hiding this comment

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

contextualSymbol

Copy link
Member Author

Choose a reason for hiding this comment

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

ahh! thanks for catching this

/// <reference path='fourslash.ts' />

////interface I {
//// property1: number;
Copy link
Member

Choose a reason for hiding this comment

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

So why exactly wouldn't property1 cascade to this declaration?

Copy link
Member Author

Choose a reason for hiding this comment

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

Becauyse you are finding ref on var property1 which is different from property property1

Copy link
Member

Choose a reason for hiding this comment

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

We should fix that at some point, but not 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.

Don't think you want to combine that.. Just because you happen to rename the name of variable (say so it contains all types of properties at various instances) doesn't mean you want to rename the properties. So current behavior is what you want there

Copy link
Member

Choose a reason for hiding this comment

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

Potentially, but then you end up breaking code in at least one other place.

Copy link
Member Author

Choose a reason for hiding this comment

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

Which would need intentional rename which is good. that is either user has to intentionally rename other variuable or use as clause

…to getPropertySymbolOfObjectBindingPatternWithoutPropertyName
@@ -23,6 +23,7 @@ let ranges = test.ranges();
for (let range of ranges) {
goTo.position(range.start);

debugger;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

//// export {a as somethingElse}
//// We want the *local* declaration of 'a' as declared in the import,
//// *not* as declared within "mod" (or farther)
const importOrExportSpecifier = getImportOrExportSpecifierForPropertyNameSymbol(symbol, location);
Copy link
Contributor

Choose a reason for hiding this comment

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

i would push this logic in getImportOrExportSpecifierForPropertyNameSymbol instead of duplicating it twice

@mhegazy
Copy link
Contributor

mhegazy commented Apr 13, 2016

👍

@sheetalkamat sheetalkamat merged commit 41c1a5b into master Apr 13, 2016
@sheetalkamat sheetalkamat deleted the renameAndFindRef branch April 13, 2016 22:46
@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.

4 participants