@@ -1904,8 +1904,9 @@ namespace ts {
1904
1904
* Extends one symbol table with another while collecting information on name collisions for error message generation into the `lookupTable` argument
1905
1905
* Not passing `lookupTable` and `exportNode` disables this collection, and just extends the tables
1906
1906
*/
1907
- function extendExportSymbols(target: SymbolTable, source: SymbolTable, lookupTable?: ExportCollisionTrackerTable, exportNode?: ExportDeclaration) {
1908
- source && source.forEach((sourceSymbol, id) => {
1907
+ function extendExportSymbols(target: SymbolTable, source: SymbolTable | undefined, lookupTable?: ExportCollisionTrackerTable, exportNode?: ExportDeclaration) {
1908
+ if (!source) return;
1909
+ source.forEach((sourceSymbol, id) => {
1909
1910
if (id === "default") return;
1910
1911
1911
1912
const targetSymbol = target.get(id);
@@ -17016,8 +17017,7 @@ namespace ts {
17016
17017
* @returns On success, the expression's signature's return type. On failure, anyType.
17017
17018
*/
17018
17019
function checkCallExpression(node: CallExpression | NewExpression): Type {
17019
- // Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true
17020
- checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node.arguments);
17020
+ if (!checkGrammarTypeArguments(node, node.typeArguments)) checkGrammarArguments(node.arguments);
17021
17021
17022
17022
const signature = getResolvedSignature(node);
17023
17023
@@ -17064,7 +17064,7 @@ namespace ts {
17064
17064
17065
17065
function checkImportCallExpression(node: ImportCall): Type {
17066
17066
// Check grammar of dynamic import
17067
- checkGrammarArguments(node.arguments) || checkGrammarImportCallExpression(node);
17067
+ if (! checkGrammarArguments(node.arguments)) checkGrammarImportCallExpression(node);
17068
17068
17069
17069
if (node.arguments.length === 0) {
17070
17070
return createPromiseReturnType(node, anyType);
@@ -18739,9 +18739,7 @@ namespace ts {
18739
18739
// It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the
18740
18740
// Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code
18741
18741
// or if its FunctionBody is strict code(11.1.5).
18742
-
18743
- // Grammar checking
18744
- checkGrammarDecorators(node) || checkGrammarModifiers(node);
18742
+ checkGrammarDecoratorsAndModifiers(node);
18745
18743
18746
18744
checkVariableLikeDeclaration(node);
18747
18745
const func = getContainingFunction(node);
@@ -19131,14 +19129,13 @@ namespace ts {
19131
19129
19132
19130
function checkPropertyDeclaration(node: PropertyDeclaration) {
19133
19131
// Grammar checking
19134
- checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name);
19135
-
19132
+ if (!checkGrammarDecoratorsAndModifiers(node) && !checkGrammarProperty(node)) checkGrammarComputedPropertyName(node.name);
19136
19133
checkVariableLikeDeclaration(node);
19137
19134
}
19138
19135
19139
19136
function checkMethodDeclaration(node: MethodDeclaration) {
19140
19137
// Grammar checking
19141
- checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name);
19138
+ if (! checkGrammarMethod(node)) checkGrammarComputedPropertyName(node.name);
19142
19139
19143
19140
// Grammar checking for modifiers is done inside the function checkGrammarFunctionLikeDeclaration
19144
19141
checkFunctionOrMethodDeclaration(node);
@@ -19154,7 +19151,7 @@ namespace ts {
19154
19151
// Grammar check on signature of constructor and modifier of the constructor is done in checkSignatureDeclaration function.
19155
19152
checkSignatureDeclaration(node);
19156
19153
// Grammar check for checking only related to constructorDeclaration
19157
- checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node);
19154
+ if (! checkGrammarConstructorTypeParameters(node)) checkGrammarConstructorTypeAnnotation(node);
19158
19155
19159
19156
checkSourceElement(node.body);
19160
19157
registerForUnusedIdentifiersCheck(node);
@@ -19251,7 +19248,7 @@ namespace ts {
19251
19248
function checkAccessorDeclaration(node: AccessorDeclaration) {
19252
19249
if (produceDiagnostics) {
19253
19250
// Grammar checking accessors
19254
- checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name);
19251
+ if (! checkGrammarFunctionLikeDeclaration(node) && ! checkGrammarAccessor(node)) checkGrammarComputedPropertyName(node.name);
19255
19252
19256
19253
checkDecorators(node);
19257
19254
checkSignatureDeclaration(node);
@@ -21013,8 +21010,7 @@ namespace ts {
21013
21010
21014
21011
function checkVariableStatement(node: VariableStatement) {
21015
21012
// Grammar checking
21016
- checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node);
21017
-
21013
+ if (!checkGrammarDecoratorsAndModifiers(node) && !checkGrammarVariableDeclarationList(node.declarationList)) checkGrammarForDisallowedLetOrConstStatement(node);
21018
21014
forEach(node.declarationList.declarations, checkSourceElement);
21019
21015
}
21020
21016
@@ -21522,7 +21518,7 @@ namespace ts {
21522
21518
21523
21519
function checkBreakOrContinueStatement(node: BreakOrContinueStatement) {
21524
21520
// Grammar checking
21525
- checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node);
21521
+ if (! checkGrammarStatementInAmbientContext(node)) checkGrammarBreakOrContinueStatement(node);
21526
21522
21527
21523
// TODO: Check that target label is valid
21528
21524
}
@@ -22203,7 +22199,7 @@ namespace ts {
22203
22199
22204
22200
function checkInterfaceDeclaration(node: InterfaceDeclaration) {
22205
22201
// Grammar checking
22206
- checkGrammarDecorators(node) || checkGrammarModifiers( node) || checkGrammarInterfaceDeclaration(node);
22202
+ if (!checkGrammarDecoratorsAndModifiers( node)) checkGrammarInterfaceDeclaration(node);
22207
22203
22208
22204
checkTypeParameters(node.typeParameters);
22209
22205
if (produceDiagnostics) {
@@ -22245,7 +22241,7 @@ namespace ts {
22245
22241
22246
22242
function checkTypeAliasDeclaration(node: TypeAliasDeclaration) {
22247
22243
// Grammar checking
22248
- checkGrammarDecorators(node) || checkGrammarModifiers (node);
22244
+ checkGrammarDecoratorsAndModifiers (node);
22249
22245
22250
22246
checkTypeNameIsReserved(node.name, Diagnostics.Type_alias_name_cannot_be_0);
22251
22247
checkTypeParameters(node.typeParameters);
@@ -22415,7 +22411,7 @@ namespace ts {
22415
22411
}
22416
22412
22417
22413
// Grammar checking
22418
- checkGrammarDecorators(node) || checkGrammarModifiers (node);
22414
+ checkGrammarDecoratorsAndModifiers (node);
22419
22415
22420
22416
checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0);
22421
22417
checkCollisionWithCapturedThisVariable(node, node.name);
@@ -22518,7 +22514,7 @@ namespace ts {
22518
22514
return;
22519
22515
}
22520
22516
22521
- if (!checkGrammarDecorators(node) && !checkGrammarModifiers (node)) {
22517
+ if (!checkGrammarDecoratorsAndModifiers (node)) {
22522
22518
if (!inAmbientContext && node.name.kind === SyntaxKind.StringLiteral) {
22523
22519
grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names);
22524
22520
}
@@ -22741,7 +22737,7 @@ namespace ts {
22741
22737
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
22742
22738
return;
22743
22739
}
22744
- if (!checkGrammarDecorators(node) && !checkGrammarModifiers (node) && hasModifiers(node)) {
22740
+ if (!checkGrammarDecoratorsAndModifiers (node) && hasModifiers(node)) {
22745
22741
grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers);
22746
22742
}
22747
22743
if (checkExternalImportOrExportDeclaration(node)) {
@@ -22768,7 +22764,7 @@ namespace ts {
22768
22764
return;
22769
22765
}
22770
22766
22771
- checkGrammarDecorators(node) || checkGrammarModifiers (node);
22767
+ checkGrammarDecoratorsAndModifiers (node);
22772
22768
if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) {
22773
22769
checkImportBinding(node);
22774
22770
if (hasModifier(node, ModifierFlags.Export)) {
@@ -22804,7 +22800,7 @@ namespace ts {
22804
22800
return;
22805
22801
}
22806
22802
22807
- if (!checkGrammarDecorators(node) && !checkGrammarModifiers (node) && hasModifiers(node)) {
22803
+ if (!checkGrammarDecoratorsAndModifiers (node) && hasModifiers(node)) {
22808
22804
grammarErrorOnFirstToken(node, Diagnostics.An_export_declaration_cannot_have_modifiers);
22809
22805
}
22810
22806
@@ -22877,7 +22873,7 @@ namespace ts {
22877
22873
return;
22878
22874
}
22879
22875
// Grammar checking
22880
- if (!checkGrammarDecorators(node) && !checkGrammarModifiers (node) && hasModifiers(node)) {
22876
+ if (!checkGrammarDecoratorsAndModifiers (node) && hasModifiers(node)) {
22881
22877
grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers);
22882
22878
}
22883
22879
if (node.expression.kind === SyntaxKind.Identifier) {
@@ -22922,29 +22918,31 @@ namespace ts {
22922
22918
}
22923
22919
// Checks for export * conflicts
22924
22920
const exports = getExportsOfModule(moduleSymbol);
22925
- exports && exports.forEach(({ declarations, flags }, id) => {
22926
- if (id === "__export") {
22927
- return;
22928
- }
22929
- // ECMA262: 15.2.1.1 It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries.
22930
- // (TS Exceptions: namespaces, function overloads, enums, and interfaces)
22931
- if (flags & (SymbolFlags.Namespace | SymbolFlags.Interface | SymbolFlags.Enum)) {
22932
- return;
22933
- }
22934
- const exportedDeclarationsCount = countWhere(declarations, isNotOverloadAndNotAccessor);
22935
- if (flags & SymbolFlags.TypeAlias && exportedDeclarationsCount <= 2) {
22936
- // it is legal to merge type alias with other values
22937
- // so count should be either 1 (just type alias) or 2 (type alias + merged value)
22938
- return;
22939
- }
22940
- if (exportedDeclarationsCount > 1) {
22941
- for (const declaration of declarations) {
22942
- if (isNotOverload(declaration)) {
22943
- diagnostics.add(createDiagnosticForNode(declaration, Diagnostics.Cannot_redeclare_exported_variable_0, unescapeLeadingUnderscores(id)));
22921
+ if (exports) {
22922
+ exports.forEach(({ declarations, flags }, id) => {
22923
+ if (id === "__export") {
22924
+ return;
22925
+ }
22926
+ // ECMA262: 15.2.1.1 It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries.
22927
+ // (TS Exceptions: namespaces, function overloads, enums, and interfaces)
22928
+ if (flags & (SymbolFlags.Namespace | SymbolFlags.Interface | SymbolFlags.Enum)) {
22929
+ return;
22930
+ }
22931
+ const exportedDeclarationsCount = countWhere(declarations, isNotOverloadAndNotAccessor);
22932
+ if (flags & SymbolFlags.TypeAlias && exportedDeclarationsCount <= 2) {
22933
+ // it is legal to merge type alias with other values
22934
+ // so count should be either 1 (just type alias) or 2 (type alias + merged value)
22935
+ return;
22936
+ }
22937
+ if (exportedDeclarationsCount > 1) {
22938
+ for (const declaration of declarations) {
22939
+ if (isNotOverload(declaration)) {
22940
+ diagnostics.add(createDiagnosticForNode(declaration, Diagnostics.Cannot_redeclare_exported_variable_0, unescapeLeadingUnderscores(id)));
22941
+ }
22944
22942
}
22945
22943
}
22946
- }
22947
- });
22944
+ });
22945
+ }
22948
22946
links.exportsChecked = true;
22949
22947
}
22950
22948
}
@@ -24577,12 +24575,16 @@ namespace ts {
24577
24575
}
24578
24576
24579
24577
// GRAMMAR CHECKING
24578
+ function checkGrammarDecoratorsAndModifiers(node: Node): boolean {
24579
+ return checkGrammarDecorators(node) || checkGrammarModifiers(node);
24580
+ }
24581
+
24580
24582
function checkGrammarDecorators(node: Node): boolean {
24581
24583
if (!node.decorators) {
24582
24584
return false;
24583
24585
}
24584
24586
if (!nodeCanBeDecorated(node)) {
24585
- if (node.kind === SyntaxKind.MethodDeclaration && !ts. nodeIsPresent((<MethodDeclaration>node).body)) {
24587
+ if (node.kind === SyntaxKind.MethodDeclaration && !nodeIsPresent((<MethodDeclaration>node).body)) {
24586
24588
return grammarErrorOnFirstToken(node, Diagnostics.A_decorator_can_only_decorate_a_method_implementation_not_an_overload);
24587
24589
}
24588
24590
else {
@@ -24932,7 +24934,7 @@ namespace ts {
24932
24934
function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean {
24933
24935
// Prevent cascading error by short-circuit
24934
24936
const file = getSourceFileOfNode(node);
24935
- return checkGrammarDecorators(node) || checkGrammarModifiers (node) || checkGrammarTypeParameterList(node.typeParameters, file) ||
24937
+ return checkGrammarDecoratorsAndModifiers (node) || checkGrammarTypeParameterList(node.typeParameters, file) ||
24936
24938
checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file);
24937
24939
}
24938
24940
@@ -24988,7 +24990,7 @@ namespace ts {
24988
24990
24989
24991
function checkGrammarIndexSignature(node: SignatureDeclaration) {
24990
24992
// Prevent cascading error by short-circuit
24991
- return checkGrammarDecorators(node) || checkGrammarModifiers (node) || checkGrammarIndexSignatureParameters(node);
24993
+ return checkGrammarDecoratorsAndModifiers (node) || checkGrammarIndexSignatureParameters(node);
24992
24994
}
24993
24995
24994
24996
function checkGrammarForAtLeastOneTypeArgument(node: Node, typeArguments: NodeArray<TypeNode>): boolean {
@@ -25039,7 +25041,7 @@ namespace ts {
25039
25041
let seenExtendsClause = false;
25040
25042
let seenImplementsClause = false;
25041
25043
25042
- if (!checkGrammarDecorators(node) && !checkGrammarModifiers (node) && node.heritageClauses) {
25044
+ if (!checkGrammarDecoratorsAndModifiers (node) && node.heritageClauses) {
25043
25045
for (const heritageClause of node.heritageClauses) {
25044
25046
if (heritageClause.token === SyntaxKind.ExtendsKeyword) {
25045
25047
if (seenExtendsClause) {
0 commit comments