Skip to content

Fixes bug #6673 #6741

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 1 commit into from
Feb 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ namespace ts {
// Export assignment in some sort of block construct
bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node));
}
else if (boundExpression.kind === SyntaxKind.Identifier) {
else if (boundExpression.kind === SyntaxKind.Identifier && node.kind === SyntaxKind.ExportAssignment) {
// An export default clause with an identifier exports all meanings of that identifier
declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes);
}
Expand Down Expand Up @@ -1444,8 +1444,16 @@ namespace ts {

// Look up the function in the local scope, since prototype assignments should
// follow the function declaration
const classId = <Identifier>(<PropertyAccessExpression>(<PropertyAccessExpression>node.left).expression).expression;
const funcSymbol = container.locals[classId.text];
const leftSideOfAssignment = node.left as PropertyAccessExpression;
const classPrototype = leftSideOfAssignment.expression as PropertyAccessExpression;
const constructorFunction = classPrototype.expression as Identifier;

// Fix up parent pointers since we're going to use these nodes before we bind into them
leftSideOfAssignment.parent = node;
constructorFunction.parent = classPrototype;
classPrototype.parent = leftSideOfAssignment;

const funcSymbol = container.locals[constructorFunction.text];
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function)) {
return;
}
Expand All @@ -1456,7 +1464,7 @@ namespace ts {
}

// Declare the method/property
declareSymbol(funcSymbol.members, funcSymbol, <PropertyAccessExpression>node.left, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
}

function bindCallExpression(node: CallExpression) {
Expand Down
4 changes: 3 additions & 1 deletion tests/cases/fourslash/javaScriptModules13.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ verify.completionListContains('y');
verify.not.completionListContains('invisible');

edit.insert('x.');
verify.completionListContains('a');
verify.memberListContains('a', undefined, undefined, 'property');
edit.insert('a.');
verify.memberListContains('toFixed', undefined, undefined, 'method');
26 changes: 26 additions & 0 deletions tests/cases/fourslash/javaScriptModules19.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
///<reference path="fourslash.ts" />

// Assignments to 'module.exports' create an external module

// @allowJs: true
// @Filename: myMod.js
//// var x = { a: 10 };
//// module.exports = x;

// @Filename: isGlobal.js
//// var y = 10;

// @Filename: consumer.js
//// var x = require('myMod');
//// /**/;

goTo.file('consumer.js');
goTo.marker();

verify.completionListContains('y');
verify.not.completionListContains('invisible');

edit.insert('x.');
verify.memberListContains('a', undefined, undefined, 'property');
edit.insert('a.');
verify.memberListContains('toFixed', undefined, undefined, 'method');