Skip to content

Commit 73a8ace

Browse files
RyanCavanaughbillti
authored andcommitted
Fixes bug #6673
#6673 (cherry picked from commit f89ebb8)
1 parent 54bc98b commit 73a8ace

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

src/compiler/binder.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ namespace ts {
13841384
// Export assignment in some sort of block construct
13851385
bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node));
13861386
}
1387-
else if (boundExpression.kind === SyntaxKind.Identifier) {
1387+
else if (boundExpression.kind === SyntaxKind.Identifier && node.kind === SyntaxKind.ExportAssignment) {
13881388
// An export default clause with an identifier exports all meanings of that identifier
13891389
declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes);
13901390
}
@@ -1445,8 +1445,16 @@ namespace ts {
14451445

14461446
// Look up the function in the local scope, since prototype assignments should
14471447
// follow the function declaration
1448-
const classId = <Identifier>(<PropertyAccessExpression>(<PropertyAccessExpression>node.left).expression).expression;
1449-
const funcSymbol = container.locals[classId.text];
1448+
const leftSideOfAssignment = node.left as PropertyAccessExpression;
1449+
const classPrototype = leftSideOfAssignment.expression as PropertyAccessExpression;
1450+
const constructorFunction = classPrototype.expression as Identifier;
1451+
1452+
// Fix up parent pointers since we're going to use these nodes before we bind into them
1453+
leftSideOfAssignment.parent = node;
1454+
constructorFunction.parent = classPrototype;
1455+
classPrototype.parent = leftSideOfAssignment;
1456+
1457+
const funcSymbol = container.locals[constructorFunction.text];
14501458
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function)) {
14511459
return;
14521460
}
@@ -1457,7 +1465,7 @@ namespace ts {
14571465
}
14581466

14591467
// Declare the method/property
1460-
declareSymbol(funcSymbol.members, funcSymbol, <PropertyAccessExpression>node.left, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
1468+
declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
14611469
}
14621470

14631471
function bindCallExpression(node: CallExpression) {

tests/cases/fourslash/javaScriptModules13.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ verify.completionListContains('y');
2323
verify.not.completionListContains('invisible');
2424

2525
edit.insert('x.');
26-
verify.completionListContains('a');
26+
verify.memberListContains('a', undefined, undefined, 'property');
27+
edit.insert('a.');
28+
verify.memberListContains('toFixed', undefined, undefined, 'method');
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
///<reference path="fourslash.ts" />
2+
3+
// Assignments to 'module.exports' create an external module
4+
5+
// @allowJs: true
6+
// @Filename: myMod.js
7+
//// var x = { a: 10 };
8+
//// module.exports = x;
9+
10+
// @Filename: isGlobal.js
11+
//// var y = 10;
12+
13+
// @Filename: consumer.js
14+
//// var x = require('myMod');
15+
//// /**/;
16+
17+
goTo.file('consumer.js');
18+
goTo.marker();
19+
20+
verify.completionListContains('y');
21+
verify.not.completionListContains('invisible');
22+
23+
edit.insert('x.');
24+
verify.memberListContains('a', undefined, undefined, 'property');
25+
edit.insert('a.');
26+
verify.memberListContains('toFixed', undefined, undefined, 'method');

0 commit comments

Comments
 (0)