Skip to content

Commit 082802e

Browse files
committed
JS:Treat type-annotated uninitialised vars as declarations
Currently only applies to property accesses, but maybe should apply to everything.
1 parent 1d1a7d8 commit 082802e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/compiler/binder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,9 @@ namespace ts {
20062006
if (currentFlow && isNarrowableReference(<Expression>node)) {
20072007
node.flowNode = currentFlow;
20082008
}
2009+
if (isSpecialPropertyDeclaration(node as PropertyAccessExpression)) {
2010+
bindThisPropertyAssignment(node as PropertyAccessExpression);
2011+
}
20092012
break;
20102013
case SyntaxKind.BinaryExpression:
20112014
const specialKind = getSpecialPropertyAssignmentKind(node as BinaryExpression);
@@ -2314,7 +2317,7 @@ namespace ts {
23142317
declareSymbol(file.symbol.exports, file.symbol, node, SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.ValueModule, SymbolFlags.None);
23152318
}
23162319

2317-
function bindThisPropertyAssignment(node: BinaryExpression) {
2320+
function bindThisPropertyAssignment(node: BinaryExpression | PropertyAccessExpression) {
23182321
Debug.assert(isInJavaScriptFile(node));
23192322
const container = getThisContainer(node, /*includeArrowFunctions*/ false);
23202323
switch (container.kind) {

src/compiler/utilities.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,12 @@ namespace ts {
15081508
return SpecialPropertyAssignmentKind.None;
15091509
}
15101510

1511+
export function isSpecialPropertyDeclaration(expr: ts.PropertyAccessExpression): boolean {
1512+
return isInJavaScriptFile(expr) &&
1513+
expr.parent && expr.parent.kind === SyntaxKind.ExpressionStatement &&
1514+
!!getJSDocTypeTag(expr.parent);
1515+
}
1516+
15111517
export function getExternalModuleName(node: Node): Expression {
15121518
if (node.kind === SyntaxKind.ImportDeclaration) {
15131519
return (<ImportDeclaration>node).moduleSpecifier;

0 commit comments

Comments
 (0)