Skip to content

Commit f9c78a6

Browse files
committed
Merge branch 'master' into logical_assignment
2 parents db66585 + 7b9ca8a commit f9c78a6

File tree

240 files changed

+3412
-813
lines changed

Some content is hidden

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

240 files changed

+3412
-813
lines changed

src/compiler/binder.ts

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace ts {
5050
// 3. non-exported import declarations
5151
case SyntaxKind.ImportDeclaration:
5252
case SyntaxKind.ImportEqualsDeclaration:
53-
if (!(hasModifier(node, ModifierFlags.Export))) {
53+
if (!(hasSyntacticModifier(node, ModifierFlags.Export))) {
5454
return ModuleInstanceState.NonInstantiated;
5555
}
5656
break;
@@ -413,7 +413,7 @@ namespace ts {
413413
function declareSymbol(symbolTable: SymbolTable, parent: Symbol | undefined, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags, isReplaceableByMethod?: boolean): Symbol {
414414
Debug.assert(!hasDynamicName(node));
415415

416-
const isDefaultExport = hasModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && node.name.escapedText === "default";
416+
const isDefaultExport = hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && node.name.escapedText === "default";
417417

418418
// The exported symbol for an export default function/class node is always named "default"
419419
const name = isDefaultExport && parent ? InternalSymbolName.Default : getDeclarationName(node);
@@ -508,7 +508,7 @@ namespace ts {
508508
}
509509

510510
const relatedInformation: DiagnosticRelatedInformation[] = [];
511-
if (isTypeAliasDeclaration(node) && nodeIsMissing(node.type) && hasModifier(node, ModifierFlags.Export) && symbol.flags & (SymbolFlags.Alias | SymbolFlags.Type | SymbolFlags.Namespace)) {
511+
if (isTypeAliasDeclaration(node) && nodeIsMissing(node.type) && hasSyntacticModifier(node, ModifierFlags.Export) && symbol.flags & (SymbolFlags.Alias | SymbolFlags.Type | SymbolFlags.Namespace)) {
512512
// export type T; - may have meant export type { T }?
513513
relatedInformation.push(createDiagnosticForNode(node, Diagnostics.Did_you_mean_0, `export type { ${unescapeLeadingUnderscores(node.name.escapedText)} }`));
514514
}
@@ -572,7 +572,7 @@ namespace ts {
572572
// and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
573573
if (isJSDocTypeAlias(node)) Debug.assert(isInJSFile(node)); // We shouldn't add symbols for JSDoc nodes if not in a JS file.
574574
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypeAlias(node)) {
575-
if (!container.locals || (hasModifier(node, ModifierFlags.Default) && !getDeclarationName(node))) {
575+
if (!container.locals || (hasSyntacticModifier(node, ModifierFlags.Default) && !getDeclarationName(node))) {
576576
return declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes); // No local symbol for an unnamed default!
577577
}
578578
const exportKind = symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0;
@@ -637,7 +637,7 @@ namespace ts {
637637
const saveExceptionTarget = currentExceptionTarget;
638638
const saveActiveLabelList = activeLabelList;
639639
const saveHasExplicitReturn = hasExplicitReturn;
640-
const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !hasModifier(node, ModifierFlags.Async) &&
640+
const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !hasSyntacticModifier(node, ModifierFlags.Async) &&
641641
!(<FunctionLikeDeclaration>node).asteriskToken && !!getImmediatelyInvokedFunctionExpression(node);
642642
// A non-async, non-generator IIFE is considered part of the containing control flow. Return statements behave
643643
// similarly to break statements that exit to a label just past the statement body.
@@ -1926,7 +1926,7 @@ namespace ts {
19261926
}
19271927

19281928
function declareClassMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) {
1929-
return hasModifier(node, ModifierFlags.Static)
1929+
return hasSyntacticModifier(node, ModifierFlags.Static)
19301930
? declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes)
19311931
: declareSymbol(container.symbol.members!, container.symbol, node, symbolFlags, symbolExcludes);
19321932
}
@@ -1956,7 +1956,7 @@ namespace ts {
19561956
function bindModuleDeclaration(node: ModuleDeclaration) {
19571957
setExportContextFlag(node);
19581958
if (isAmbientModule(node)) {
1959-
if (hasModifier(node, ModifierFlags.Export)) {
1959+
if (hasSyntacticModifier(node, ModifierFlags.Export)) {
19601960
errorOnFirstToken(node, Diagnostics.export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible);
19611961
}
19621962
if (isModuleAugmentationExternal(node)) {
@@ -2889,7 +2889,7 @@ namespace ts {
28892889
// this.foo assignment in a JavaScript class
28902890
// Bind this property to the containing class
28912891
const containingClass = thisContainer.parent;
2892-
const symbolTable = hasModifier(thisContainer, ModifierFlags.Static) ? containingClass.symbol.exports! : containingClass.symbol.members!;
2892+
const symbolTable = hasSyntacticModifier(thisContainer, ModifierFlags.Static) ? containingClass.symbol.exports! : containingClass.symbol.members!;
28932893
if (hasDynamicName(node)) {
28942894
bindDynamicallyNamedThisPropertyAssignment(node, containingClass.symbol);
28952895
}
@@ -2997,23 +2997,22 @@ namespace ts {
29972997
// util.property = function ...
29982998
bindExportsPropertyAssignment(node as BindableStaticPropertyAssignmentExpression);
29992999
}
3000+
else if (hasDynamicName(node)) {
3001+
bindAnonymousDeclaration(node, SymbolFlags.Property | SymbolFlags.Assignment, InternalSymbolName.Computed);
3002+
const sym = bindPotentiallyMissingNamespaces(parentSymbol, node.left.expression, isTopLevelNamespaceAssignment(node.left), /*isPrototype*/ false, /*containerIsClass*/ false);
3003+
addLateBoundAssignmentDeclarationToSymbol(node, sym);
3004+
}
30003005
else {
3001-
if (hasDynamicName(node)) {
3002-
bindAnonymousDeclaration(node, SymbolFlags.Property | SymbolFlags.Assignment, InternalSymbolName.Computed);
3003-
const sym = bindPotentiallyMissingNamespaces(parentSymbol, node.left.expression, isTopLevelNamespaceAssignment(node.left), /*isPrototype*/ false, /*containerIsClass*/ false);
3004-
addLateBoundAssignmentDeclarationToSymbol(node, sym);
3005-
}
3006-
else {
3007-
bindStaticPropertyAssignment(cast(node.left, isBindableStaticAccessExpression));
3008-
}
3006+
bindStaticPropertyAssignment(cast(node.left, isBindableStaticNameExpression));
30093007
}
30103008
}
30113009

30123010
/**
30133011
* For nodes like `x.y = z`, declare a member 'y' on 'x' if x is a function (or IIFE) or class or {}, or not declared.
30143012
* Also works for expression statements preceded by JSDoc, like / ** @type number * / x.y;
30153013
*/
3016-
function bindStaticPropertyAssignment(node: BindableStaticAccessExpression) {
3014+
function bindStaticPropertyAssignment(node: BindableStaticNameExpression) {
3015+
Debug.assert(!isIdentifier(node));
30173016
node.expression.parent = node;
30183017
bindPropertyAssignment(node.expression, node, /*isPrototypeProperty*/ false, /*containerIsClass*/ false);
30193018
}
@@ -3423,7 +3422,7 @@ namespace ts {
34233422
case SyntaxKind.ModuleDeclaration:
34243423
return getModuleInstanceState(s as ModuleDeclaration) !== ModuleInstanceState.Instantiated;
34253424
case SyntaxKind.EnumDeclaration:
3426-
return hasModifier(s, ModifierFlags.Const);
3425+
return hasSyntacticModifier(s, ModifierFlags.Const);
34273426
default:
34283427
return false;
34293428
}
@@ -3660,7 +3659,7 @@ namespace ts {
36603659
}
36613660

36623661
// If a parameter has an accessibility modifier, then it is TypeScript syntax.
3663-
if (hasModifier(node, ModifierFlags.ParameterPropertyModifier)) {
3662+
if (hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) {
36643663
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.ContainsTypeScriptClassSyntax;
36653664
}
36663665

@@ -3699,7 +3698,7 @@ namespace ts {
36993698
function computeClassDeclaration(node: ClassDeclaration, subtreeFlags: TransformFlags) {
37003699
let transformFlags: TransformFlags;
37013700

3702-
if (hasModifier(node, ModifierFlags.Ambient)) {
3701+
if (hasSyntacticModifier(node, ModifierFlags.Ambient)) {
37033702
// An ambient declaration is TypeScript syntax.
37043703
transformFlags = TransformFlags.AssertTypeScript;
37053704
}
@@ -3790,7 +3789,7 @@ namespace ts {
37903789
let transformFlags = subtreeFlags;
37913790

37923791
// TypeScript-specific modifiers and overloads are TypeScript syntax
3793-
if (hasModifier(node, ModifierFlags.TypeScriptModifier)
3792+
if (hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier)
37943793
|| !node.body) {
37953794
transformFlags |= TransformFlags.AssertTypeScript;
37963795
}
@@ -3811,7 +3810,7 @@ namespace ts {
38113810
// Decorators, TypeScript-specific modifiers, type parameters, type annotations, and
38123811
// overloads are TypeScript syntax.
38133812
if (node.decorators
3814-
|| hasModifier(node, ModifierFlags.TypeScriptModifier)
3813+
|| hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier)
38153814
|| node.typeParameters
38163815
|| node.type
38173816
|| !node.body
@@ -3825,7 +3824,7 @@ namespace ts {
38253824
}
38263825

38273826
// An async method declaration is ES2017 syntax.
3828-
if (hasModifier(node, ModifierFlags.Async)) {
3827+
if (hasSyntacticModifier(node, ModifierFlags.Async)) {
38293828
transformFlags |= node.asteriskToken ? TransformFlags.AssertES2018 : TransformFlags.AssertES2017;
38303829
}
38313830

@@ -3843,7 +3842,7 @@ namespace ts {
38433842
// Decorators, TypeScript-specific modifiers, type annotations, and overloads are
38443843
// TypeScript syntax.
38453844
if (node.decorators
3846-
|| hasModifier(node, ModifierFlags.TypeScriptModifier)
3845+
|| hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier)
38473846
|| node.type
38483847
|| !node.body) {
38493848
transformFlags |= TransformFlags.AssertTypeScript;
@@ -3862,7 +3861,7 @@ namespace ts {
38623861
let transformFlags = subtreeFlags | TransformFlags.ContainsClassFields;
38633862

38643863
// Decorators, TypeScript-specific modifiers, and type annotations are TypeScript syntax.
3865-
if (some(node.decorators) || hasModifier(node, ModifierFlags.TypeScriptModifier) || node.type || node.questionToken || node.exclamationToken) {
3864+
if (some(node.decorators) || hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier) || node.type || node.questionToken || node.exclamationToken) {
38663865
transformFlags |= TransformFlags.AssertTypeScript;
38673866
}
38683867

@@ -3877,7 +3876,7 @@ namespace ts {
38773876

38783877
function computeFunctionDeclaration(node: FunctionDeclaration, subtreeFlags: TransformFlags) {
38793878
let transformFlags: TransformFlags;
3880-
const modifierFlags = getModifierFlags(node);
3879+
const modifierFlags = getSyntacticModifierFlags(node);
38813880
const body = node.body;
38823881

38833882
if (!body || (modifierFlags & ModifierFlags.Ambient)) {
@@ -3925,14 +3924,14 @@ namespace ts {
39253924

39263925
// TypeScript-specific modifiers, type parameters, and type annotations are TypeScript
39273926
// syntax.
3928-
if (hasModifier(node, ModifierFlags.TypeScriptModifier)
3927+
if (hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier)
39293928
|| node.typeParameters
39303929
|| node.type) {
39313930
transformFlags |= TransformFlags.AssertTypeScript;
39323931
}
39333932

39343933
// An async function expression is ES2017 syntax.
3935-
if (hasModifier(node, ModifierFlags.Async)) {
3934+
if (hasSyntacticModifier(node, ModifierFlags.Async)) {
39363935
transformFlags |= node.asteriskToken ? TransformFlags.AssertES2018 : TransformFlags.AssertES2017;
39373936
}
39383937

@@ -3958,14 +3957,14 @@ namespace ts {
39583957

39593958
// TypeScript-specific modifiers, type parameters, and type annotations are TypeScript
39603959
// syntax.
3961-
if (hasModifier(node, ModifierFlags.TypeScriptModifier)
3960+
if (hasSyntacticModifier(node, ModifierFlags.TypeScriptModifier)
39623961
|| node.typeParameters
39633962
|| node.type) {
39643963
transformFlags |= TransformFlags.AssertTypeScript;
39653964
}
39663965

39673966
// An async arrow function is ES2017 syntax.
3968-
if (hasModifier(node, ModifierFlags.Async)) {
3967+
if (hasSyntacticModifier(node, ModifierFlags.Async)) {
39693968
transformFlags |= TransformFlags.AssertES2017;
39703969
}
39713970

@@ -4039,7 +4038,7 @@ namespace ts {
40394038
const declarationListTransformFlags = node.declarationList.transformFlags;
40404039

40414040
// An ambient declaration is TypeScript syntax.
4042-
if (hasModifier(node, ModifierFlags.Ambient)) {
4041+
if (hasSyntacticModifier(node, ModifierFlags.Ambient)) {
40434042
transformFlags = TransformFlags.AssertTypeScript;
40444043
}
40454044
else {
@@ -4087,7 +4086,7 @@ namespace ts {
40874086

40884087
function computeModuleDeclaration(node: ModuleDeclaration, subtreeFlags: TransformFlags) {
40894088
let transformFlags = TransformFlags.AssertTypeScript;
4090-
const modifierFlags = getModifierFlags(node);
4089+
const modifierFlags = getSyntacticModifierFlags(node);
40914090

40924091
if ((modifierFlags & ModifierFlags.Ambient) === 0) {
40934092
transformFlags |= subtreeFlags;

0 commit comments

Comments
 (0)