@@ -1907,8 +1907,9 @@ namespace ts {
1907
1907
* Extends one symbol table with another while collecting information on name collisions for error message generation into the `lookupTable` argument
1908
1908
* Not passing `lookupTable` and `exportNode` disables this collection, and just extends the tables
1909
1909
*/
1910
- function extendExportSymbols(target: SymbolTable, source: SymbolTable, lookupTable?: ExportCollisionTrackerTable, exportNode?: ExportDeclaration) {
1911
- source && source.forEach((sourceSymbol, id) => {
1910
+ function extendExportSymbols(target: SymbolTable, source: SymbolTable | undefined, lookupTable?: ExportCollisionTrackerTable, exportNode?: ExportDeclaration) {
1911
+ if (!source) return;
1912
+ source.forEach((sourceSymbol, id) => {
1912
1913
if (id === "default") return;
1913
1914
1914
1915
const targetSymbol = target.get(id);
@@ -16989,8 +16990,7 @@ namespace ts {
16989
16990
* @returns On success, the expression's signature's return type. On failure, anyType.
16990
16991
*/
16991
16992
function checkCallExpression(node: CallExpression | NewExpression): Type {
16992
- // Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true
16993
- checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node.arguments);
16993
+ if (!checkGrammarTypeArguments(node, node.typeArguments)) checkGrammarArguments(node.arguments);
16994
16994
16995
16995
const signature = getResolvedSignature(node);
16996
16996
@@ -17037,7 +17037,7 @@ namespace ts {
17037
17037
17038
17038
function checkImportCallExpression(node: ImportCall): Type {
17039
17039
// Check grammar of dynamic import
17040
- checkGrammarArguments(node.arguments) || checkGrammarImportCallExpression(node);
17040
+ if (! checkGrammarArguments(node.arguments)) checkGrammarImportCallExpression(node);
17041
17041
17042
17042
if (node.arguments.length === 0) {
17043
17043
return createPromiseReturnType(node, anyType);
@@ -18712,9 +18712,7 @@ namespace ts {
18712
18712
// It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the
18713
18713
// Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code
18714
18714
// or if its FunctionBody is strict code(11.1.5).
18715
-
18716
- // Grammar checking
18717
- checkGrammarDecorators(node) || checkGrammarModifiers(node);
18715
+ checkGrammarDecoratorsAndModifiers(node);
18718
18716
18719
18717
checkVariableLikeDeclaration(node);
18720
18718
const func = getContainingFunction(node);
@@ -19104,14 +19102,13 @@ namespace ts {
19104
19102
19105
19103
function checkPropertyDeclaration(node: PropertyDeclaration) {
19106
19104
// Grammar checking
19107
- checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name);
19108
-
19105
+ if (!checkGrammarDecoratorsAndModifiers(node) && !checkGrammarProperty(node)) checkGrammarComputedPropertyName(node.name);
19109
19106
checkVariableLikeDeclaration(node);
19110
19107
}
19111
19108
19112
19109
function checkMethodDeclaration(node: MethodDeclaration) {
19113
19110
// Grammar checking
19114
- checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name);
19111
+ if (! checkGrammarMethod(node)) checkGrammarComputedPropertyName(node.name);
19115
19112
19116
19113
// Grammar checking for modifiers is done inside the function checkGrammarFunctionLikeDeclaration
19117
19114
checkFunctionOrMethodDeclaration(node);
@@ -19127,7 +19124,7 @@ namespace ts {
19127
19124
// Grammar check on signature of constructor and modifier of the constructor is done in checkSignatureDeclaration function.
19128
19125
checkSignatureDeclaration(node);
19129
19126
// Grammar check for checking only related to constructorDeclaration
19130
- checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node);
19127
+ if (! checkGrammarConstructorTypeParameters(node)) checkGrammarConstructorTypeAnnotation(node);
19131
19128
19132
19129
checkSourceElement(node.body);
19133
19130
registerForUnusedIdentifiersCheck(node);
@@ -19224,7 +19221,7 @@ namespace ts {
19224
19221
function checkAccessorDeclaration(node: AccessorDeclaration) {
19225
19222
if (produceDiagnostics) {
19226
19223
// Grammar checking accessors
19227
- checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name);
19224
+ if (!( checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node))) checkGrammarComputedPropertyName(node.name);
19228
19225
19229
19226
checkDecorators(node);
19230
19227
checkSignatureDeclaration(node);
@@ -20987,8 +20984,7 @@ namespace ts {
20987
20984
20988
20985
function checkVariableStatement(node: VariableStatement) {
20989
20986
// Grammar checking
20990
- checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node);
20991
-
20987
+ if (!checkGrammarDecoratorsAndModifiers(node) && !checkGrammarVariableDeclarationList(node.declarationList)) checkGrammarForDisallowedLetOrConstStatement(node);
20992
20988
forEach(node.declarationList.declarations, checkSourceElement);
20993
20989
}
20994
20990
@@ -21496,7 +21492,7 @@ namespace ts {
21496
21492
21497
21493
function checkBreakOrContinueStatement(node: BreakOrContinueStatement) {
21498
21494
// Grammar checking
21499
- checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node);
21495
+ if (! checkGrammarStatementInAmbientContext(node)) checkGrammarBreakOrContinueStatement(node);
21500
21496
21501
21497
// TODO: Check that target label is valid
21502
21498
}
@@ -22177,7 +22173,7 @@ namespace ts {
22177
22173
22178
22174
function checkInterfaceDeclaration(node: InterfaceDeclaration) {
22179
22175
// Grammar checking
22180
- checkGrammarDecorators(node) || checkGrammarModifiers( node) || checkGrammarInterfaceDeclaration(node);
22176
+ if (!checkGrammarDecoratorsAndModifiers( node)) checkGrammarInterfaceDeclaration(node);
22181
22177
22182
22178
checkTypeParameters(node.typeParameters);
22183
22179
if (produceDiagnostics) {
@@ -22219,7 +22215,7 @@ namespace ts {
22219
22215
22220
22216
function checkTypeAliasDeclaration(node: TypeAliasDeclaration) {
22221
22217
// Grammar checking
22222
- checkGrammarDecorators(node) || checkGrammarModifiers (node);
22218
+ checkGrammarDecoratorsAndModifiers (node);
22223
22219
22224
22220
checkTypeNameIsReserved(node.name, Diagnostics.Type_alias_name_cannot_be_0);
22225
22221
checkTypeParameters(node.typeParameters);
@@ -22389,7 +22385,7 @@ namespace ts {
22389
22385
}
22390
22386
22391
22387
// Grammar checking
22392
- checkGrammarDecorators(node) || checkGrammarModifiers (node);
22388
+ checkGrammarDecoratorsAndModifiers (node);
22393
22389
22394
22390
checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0);
22395
22391
checkCollisionWithCapturedThisVariable(node, node.name);
@@ -22492,7 +22488,7 @@ namespace ts {
22492
22488
return;
22493
22489
}
22494
22490
22495
- if (!checkGrammarDecorators(node) && !checkGrammarModifiers (node)) {
22491
+ if (!checkGrammarDecoratorsAndModifiers (node)) {
22496
22492
if (!inAmbientContext && node.name.kind === SyntaxKind.StringLiteral) {
22497
22493
grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names);
22498
22494
}
@@ -22715,7 +22711,7 @@ namespace ts {
22715
22711
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
22716
22712
return;
22717
22713
}
22718
- if (!checkGrammarDecorators(node) && !checkGrammarModifiers (node) && hasModifiers(node)) {
22714
+ if (!checkGrammarDecoratorsAndModifiers (node) && hasModifiers(node)) {
22719
22715
grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers);
22720
22716
}
22721
22717
if (checkExternalImportOrExportDeclaration(node)) {
@@ -22742,7 +22738,7 @@ namespace ts {
22742
22738
return;
22743
22739
}
22744
22740
22745
- checkGrammarDecorators(node) || checkGrammarModifiers (node);
22741
+ checkGrammarDecoratorsAndModifiers (node);
22746
22742
if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) {
22747
22743
checkImportBinding(node);
22748
22744
if (hasModifier(node, ModifierFlags.Export)) {
@@ -22778,7 +22774,7 @@ namespace ts {
22778
22774
return;
22779
22775
}
22780
22776
22781
- if (!checkGrammarDecorators(node) && !checkGrammarModifiers (node) && hasModifiers(node)) {
22777
+ if (!checkGrammarDecoratorsAndModifiers (node) && hasModifiers(node)) {
22782
22778
grammarErrorOnFirstToken(node, Diagnostics.An_export_declaration_cannot_have_modifiers);
22783
22779
}
22784
22780
@@ -22851,7 +22847,7 @@ namespace ts {
22851
22847
return;
22852
22848
}
22853
22849
// Grammar checking
22854
- if (!checkGrammarDecorators(node) && !checkGrammarModifiers (node) && hasModifiers(node)) {
22850
+ if (!checkGrammarDecoratorsAndModifiers (node) && hasModifiers(node)) {
22855
22851
grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers);
22856
22852
}
22857
22853
if (node.expression.kind === SyntaxKind.Identifier) {
@@ -22896,29 +22892,31 @@ namespace ts {
22896
22892
}
22897
22893
// Checks for export * conflicts
22898
22894
const exports = getExportsOfModule(moduleSymbol);
22899
- exports && exports.forEach(({ declarations, flags }, id) => {
22900
- if (id === "__export") {
22901
- return;
22902
- }
22903
- // ECMA262: 15.2.1.1 It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries.
22904
- // (TS Exceptions: namespaces, function overloads, enums, and interfaces)
22905
- if (flags & (SymbolFlags.Namespace | SymbolFlags.Interface | SymbolFlags.Enum)) {
22906
- return;
22907
- }
22908
- const exportedDeclarationsCount = countWhere(declarations, isNotOverloadAndNotAccessor);
22909
- if (flags & SymbolFlags.TypeAlias && exportedDeclarationsCount <= 2) {
22910
- // it is legal to merge type alias with other values
22911
- // so count should be either 1 (just type alias) or 2 (type alias + merged value)
22912
- return;
22913
- }
22914
- if (exportedDeclarationsCount > 1) {
22915
- for (const declaration of declarations) {
22916
- if (isNotOverload(declaration)) {
22917
- diagnostics.add(createDiagnosticForNode(declaration, Diagnostics.Cannot_redeclare_exported_variable_0, unescapeLeadingUnderscores(id)));
22895
+ if (exports) {
22896
+ exports.forEach(({ declarations, flags }, id) => {
22897
+ if (id === "__export") {
22898
+ return;
22899
+ }
22900
+ // ECMA262: 15.2.1.1 It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries.
22901
+ // (TS Exceptions: namespaces, function overloads, enums, and interfaces)
22902
+ if (flags & (SymbolFlags.Namespace | SymbolFlags.Interface | SymbolFlags.Enum)) {
22903
+ return;
22904
+ }
22905
+ const exportedDeclarationsCount = countWhere(declarations, isNotOverloadAndNotAccessor);
22906
+ if (flags & SymbolFlags.TypeAlias && exportedDeclarationsCount <= 2) {
22907
+ // it is legal to merge type alias with other values
22908
+ // so count should be either 1 (just type alias) or 2 (type alias + merged value)
22909
+ return;
22910
+ }
22911
+ if (exportedDeclarationsCount > 1) {
22912
+ for (const declaration of declarations) {
22913
+ if (isNotOverload(declaration)) {
22914
+ diagnostics.add(createDiagnosticForNode(declaration, Diagnostics.Cannot_redeclare_exported_variable_0, unescapeLeadingUnderscores(id)));
22915
+ }
22918
22916
}
22919
22917
}
22920
- }
22921
- });
22918
+ });
22919
+ }
22922
22920
links.exportsChecked = true;
22923
22921
}
22924
22922
}
@@ -24551,12 +24549,16 @@ namespace ts {
24551
24549
}
24552
24550
24553
24551
// GRAMMAR CHECKING
24552
+ function checkGrammarDecoratorsAndModifiers(node: Node): boolean {
24553
+ return checkGrammarDecorators(node) || checkGrammarModifiers(node);
24554
+ }
24555
+
24554
24556
function checkGrammarDecorators(node: Node): boolean {
24555
24557
if (!node.decorators) {
24556
24558
return false;
24557
24559
}
24558
24560
if (!nodeCanBeDecorated(node)) {
24559
- if (node.kind === SyntaxKind.MethodDeclaration && !ts. nodeIsPresent((<MethodDeclaration>node).body)) {
24561
+ if (node.kind === SyntaxKind.MethodDeclaration && !nodeIsPresent((<MethodDeclaration>node).body)) {
24560
24562
return grammarErrorOnFirstToken(node, Diagnostics.A_decorator_can_only_decorate_a_method_implementation_not_an_overload);
24561
24563
}
24562
24564
else {
@@ -24906,7 +24908,7 @@ namespace ts {
24906
24908
function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean {
24907
24909
// Prevent cascading error by short-circuit
24908
24910
const file = getSourceFileOfNode(node);
24909
- return checkGrammarDecorators(node) || checkGrammarModifiers (node) || checkGrammarTypeParameterList(node.typeParameters, file) ||
24911
+ return checkGrammarDecoratorsAndModifiers (node) || checkGrammarTypeParameterList(node.typeParameters, file) ||
24910
24912
checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file);
24911
24913
}
24912
24914
@@ -24962,7 +24964,7 @@ namespace ts {
24962
24964
24963
24965
function checkGrammarIndexSignature(node: SignatureDeclaration) {
24964
24966
// Prevent cascading error by short-circuit
24965
- return checkGrammarDecorators(node) || checkGrammarModifiers (node) || checkGrammarIndexSignatureParameters(node);
24967
+ return checkGrammarDecoratorsAndModifiers (node) || checkGrammarIndexSignatureParameters(node);
24966
24968
}
24967
24969
24968
24970
function checkGrammarForAtLeastOneTypeArgument(node: Node, typeArguments: NodeArray<TypeNode>): boolean {
@@ -25013,7 +25015,7 @@ namespace ts {
25013
25015
let seenExtendsClause = false;
25014
25016
let seenImplementsClause = false;
25015
25017
25016
- if (!checkGrammarDecorators(node) && !checkGrammarModifiers (node) && node.heritageClauses) {
25018
+ if (!checkGrammarDecoratorsAndModifiers (node) && node.heritageClauses) {
25017
25019
for (const heritageClause of node.heritageClauses) {
25018
25020
if (heritageClause.token === SyntaxKind.ExtendsKeyword) {
25019
25021
if (seenExtendsClause) {
0 commit comments