Skip to content

Commit a255d9a

Browse files
committed
Merge branch 'master' into typesVersions
2 parents e726e4c + f8b6a8f commit a255d9a

File tree

679 files changed

+22406
-12974
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

679 files changed

+22406
-12974
lines changed

src/compiler/binder.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ namespace ts {
236236
if (symbolFlags & SymbolFlags.Value) {
237237
const { valueDeclaration } = symbol;
238238
if (!valueDeclaration ||
239+
(isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) ||
239240
(valueDeclaration.kind !== node.kind && isEffectiveModuleDeclaration(valueDeclaration))) {
240-
// other kinds of value declarations take precedence over modules
241+
// other kinds of value declarations take precedence over modules and assignment declarations
241242
symbol.valueDeclaration = node;
242243
}
243244
}
@@ -373,7 +374,8 @@ namespace ts {
373374
// prototype symbols like methods.
374375
symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name));
375376
}
376-
else {
377+
else if (!(includes & SymbolFlags.Variable && symbol.flags & SymbolFlags.JSContainer)) {
378+
// JSContainers are allowed to merge with variables, no matter what other flags they have.
377379
if (isNamedDeclaration(node)) {
378380
node.name.parent = node;
379381
}
@@ -733,6 +735,8 @@ namespace ts {
733735
return isNarrowingBinaryExpression(<BinaryExpression>expr);
734736
case SyntaxKind.PrefixUnaryExpression:
735737
return (<PrefixUnaryExpression>expr).operator === SyntaxKind.ExclamationToken && isNarrowingExpression((<PrefixUnaryExpression>expr).operand);
738+
case SyntaxKind.TypeOfExpression:
739+
return isNarrowingExpression((<TypeOfExpression>expr).expression);
736740
}
737741
return false;
738742
}
@@ -1729,10 +1733,6 @@ namespace ts {
17291733
}
17301734
}
17311735

1732-
function bindBlockScopedVariableDeclaration(node: Declaration) {
1733-
bindBlockScopedDeclaration(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes);
1734-
}
1735-
17361736
function delayedBindJSDocTypedefTag() {
17371737
if (!delayedTypeAliases) {
17381738
return;
@@ -2078,8 +2078,8 @@ namespace ts {
20782078
if (isInJavaScriptFile(node) &&
20792079
file.commonJsModuleIndicator &&
20802080
isModuleExportsPropertyAccessExpression(node as PropertyAccessExpression) &&
2081-
!lookupSymbolForNameWorker(container, "module" as __String)) {
2082-
declareSymbol(container.locals!, /*parent*/ undefined, (node as PropertyAccessExpression).expression as Identifier,
2081+
!lookupSymbolForNameWorker(blockScopeContainer, "module" as __String)) {
2082+
declareSymbol(file.locals!, /*parent*/ undefined, (node as PropertyAccessExpression).expression as Identifier,
20832083
SymbolFlags.FunctionScopedVariable | SymbolFlags.ModuleExports, SymbolFlags.FunctionScopedVariableExcludes);
20842084
}
20852085
break;
@@ -2510,11 +2510,10 @@ namespace ts {
25102510

25112511
function bindPropertyAssignment(name: EntityNameExpression, propertyAccess: PropertyAccessEntityNameExpression, isPrototypeProperty: boolean) {
25122512
let namespaceSymbol = lookupSymbolForPropertyAccess(name);
2513-
const isToplevelNamespaceableInitializer = isBinaryExpression(propertyAccess.parent)
2514-
? getParentOfBinaryExpression(propertyAccess.parent).parent.kind === SyntaxKind.SourceFile &&
2515-
!!getJavascriptInitializer(getInitializerOfBinaryExpression(propertyAccess.parent), isPrototypeAccess(propertyAccess.parent.left))
2513+
const isToplevel = isBinaryExpression(propertyAccess.parent)
2514+
? getParentOfBinaryExpression(propertyAccess.parent).parent.kind === SyntaxKind.SourceFile
25162515
: propertyAccess.parent.parent.kind === SyntaxKind.SourceFile;
2517-
if (!isPrototypeProperty && (!namespaceSymbol || !(namespaceSymbol.flags & SymbolFlags.Namespace)) && isToplevelNamespaceableInitializer) {
2516+
if (!isPrototypeProperty && (!namespaceSymbol || !(namespaceSymbol.flags & SymbolFlags.Namespace)) && isToplevel) {
25182517
// make symbols or add declarations for intermediate containers
25192518
const flags = SymbolFlags.Module | SymbolFlags.JSContainer;
25202519
const excludeFlags = SymbolFlags.ValueModuleExcludes & ~SymbolFlags.JSContainer;
@@ -2537,12 +2536,10 @@ namespace ts {
25372536
(namespaceSymbol.members || (namespaceSymbol.members = createSymbolTable())) :
25382537
(namespaceSymbol.exports || (namespaceSymbol.exports = createSymbolTable()));
25392538

2540-
// Declare the method/property
2541-
const jsContainerFlag = isToplevelNamespaceableInitializer ? SymbolFlags.JSContainer : 0;
25422539
const isMethod = isFunctionLikeDeclaration(getAssignedJavascriptInitializer(propertyAccess)!);
2543-
const symbolFlags = (isMethod ? SymbolFlags.Method : SymbolFlags.Property) | jsContainerFlag;
2544-
const symbolExcludes = (isMethod ? SymbolFlags.MethodExcludes : SymbolFlags.PropertyExcludes) & ~jsContainerFlag;
2545-
declareSymbol(symbolTable, namespaceSymbol, propertyAccess, symbolFlags, symbolExcludes);
2540+
const includes = isMethod ? SymbolFlags.Method : SymbolFlags.Property;
2541+
const excludes = isMethod ? SymbolFlags.MethodExcludes : SymbolFlags.PropertyExcludes;
2542+
declareSymbol(symbolTable, namespaceSymbol, propertyAccess, includes | SymbolFlags.JSContainer, excludes & ~SymbolFlags.JSContainer);
25462543
}
25472544

25482545
/**
@@ -2573,7 +2570,7 @@ namespace ts {
25732570
return false;
25742571
}
25752572

2576-
function getParentOfBinaryExpression(expr: BinaryExpression) {
2573+
function getParentOfBinaryExpression(expr: Node) {
25772574
while (isBinaryExpression(expr.parent)) {
25782575
expr = expr.parent;
25792576
}
@@ -2660,8 +2657,11 @@ namespace ts {
26602657
}
26612658

26622659
if (!isBindingPattern(node.name)) {
2660+
const isEnum = !!getJSDocEnumTag(node);
2661+
const enumFlags = (isEnum ? SymbolFlags.RegularEnum : SymbolFlags.None);
2662+
const enumExcludes = (isEnum ? SymbolFlags.RegularEnumExcludes : SymbolFlags.None);
26632663
if (isBlockOrCatchScoped(node)) {
2664-
bindBlockScopedVariableDeclaration(node);
2664+
bindBlockScopedDeclaration(node, SymbolFlags.BlockScopedVariable | enumFlags, SymbolFlags.BlockScopedVariableExcludes | enumExcludes);
26652665
}
26662666
else if (isParameterDeclaration(node)) {
26672667
// It is safe to walk up parent chain to find whether the node is a destructuring parameter declaration
@@ -2676,7 +2676,7 @@ namespace ts {
26762676
declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes);
26772677
}
26782678
else {
2679-
declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes);
2679+
declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable | enumFlags, SymbolFlags.FunctionScopedVariableExcludes | enumExcludes);
26802680
}
26812681
}
26822682
}
@@ -2804,9 +2804,7 @@ namespace ts {
28042804
// report error on class declarations
28052805
node.kind === SyntaxKind.ClassDeclaration ||
28062806
// report error on instantiated modules or const-enums only modules if preserveConstEnums is set
2807-
(node.kind === SyntaxKind.ModuleDeclaration && shouldReportErrorOnModuleDeclaration(<ModuleDeclaration>node)) ||
2808-
// report error on regular enums and const enums if preserveConstEnums is set
2809-
(isEnumDeclaration(node) && (!isEnumConst(node) || options.preserveConstEnums));
2807+
(node.kind === SyntaxKind.ModuleDeclaration && shouldReportErrorOnModuleDeclaration(<ModuleDeclaration>node));
28102808

28112809
if (reportError) {
28122810
currentFlow = reportedUnreachableFlow;
@@ -2851,7 +2849,7 @@ namespace ts {
28512849
// As opposed to a pure declaration like an `interface`
28522850
function isExecutableStatement(s: Statement): boolean {
28532851
// Don't remove statements that can validly be used before they appear.
2854-
return !isFunctionDeclaration(s) && !isPurelyTypeDeclaration(s) &&
2852+
return !isFunctionDeclaration(s) && !isPurelyTypeDeclaration(s) && !isEnumDeclaration(s) &&
28552853
// `var x;` may declare a variable used above
28562854
!(isVariableStatement(s) && !(getCombinedNodeFlags(s) & (NodeFlags.Let | NodeFlags.Const)) && s.declarationList.declarations.some(d => !d.initializer));
28572855
}

0 commit comments

Comments
 (0)