@@ -23289,22 +23289,34 @@ namespace ts {
23289
23289
const uninstantiatedType = checkExpressionWorker(node, checkMode, forceTuple);
23290
23290
const type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, checkMode);
23291
23291
if (isConstEnumObjectType(type)) {
23292
- // enum object type for const enums are only permitted in:
23293
- // - 'left' in property access
23294
- // - 'object' in indexed access
23295
- // - target in rhs of import statement
23296
- const ok =
23297
- (node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).expression === node) ||
23298
- (node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).expression === node) ||
23299
- ((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) && isInRightSideOfImportOrExportAssignment(<Identifier>node) ||
23292
+ checkConstEnumAccess(node, type);
23293
+ }
23294
+ currentNode = saveCurrentNode;
23295
+ return type;
23296
+ }
23297
+
23298
+ function checkConstEnumAccess(node: Expression | QualifiedName, type: Type) {
23299
+ // enum object type for const enums are only permitted in:
23300
+ // - 'left' in property access
23301
+ // - 'object' in indexed access
23302
+ // - target in rhs of import statement
23303
+ const ok =
23304
+ (node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).expression === node) ||
23305
+ (node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).expression === node) ||
23306
+ ((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) && isInRightSideOfImportOrExportAssignment(<Identifier>node) ||
23300
23307
(node.parent.kind === SyntaxKind.TypeQuery && (<TypeQueryNode>node.parent).exprName === node));
23301
23308
23302
- if (!ok) {
23303
- error(node, Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment_or_type_query);
23309
+ if (!ok) {
23310
+ error(node, Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment_or_type_query);
23311
+ }
23312
+
23313
+ if (compilerOptions.isolatedModules) {
23314
+ Debug.assert(!!(type.symbol.flags & SymbolFlags.ConstEnum));
23315
+ const constEnumDeclaration = type.symbol.valueDeclaration as EnumDeclaration;
23316
+ if (constEnumDeclaration.flags & NodeFlags.Ambient) {
23317
+ error(node, Diagnostics.Cannot_access_ambient_const_enums_when_the_isolatedModules_flag_is_provided);
23304
23318
}
23305
23319
}
23306
- currentNode = saveCurrentNode;
23307
- return type;
23308
23320
}
23309
23321
23310
23322
function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type {
@@ -27484,11 +27496,6 @@ namespace ts {
27484
27496
27485
27497
computeEnumMemberValues(node);
27486
27498
27487
- const enumIsConst = isEnumConst(node);
27488
- if (compilerOptions.isolatedModules && enumIsConst && node.flags & NodeFlags.Ambient) {
27489
- error(node.name, Diagnostics.Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided);
27490
- }
27491
-
27492
27499
// Spec 2014 - Section 9.3:
27493
27500
// It isn't possible for one enum declaration to continue the automatic numbering sequence of another,
27494
27501
// and when an enum type has multiple declarations, only one declaration is permitted to omit a value
@@ -27499,6 +27506,7 @@ namespace ts {
27499
27506
const firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind);
27500
27507
if (node === firstDeclaration) {
27501
27508
if (enumSymbol.declarations.length > 1) {
27509
+ const enumIsConst = isEnumConst(node);
27502
27510
// check that const is placed\omitted on all enum declarations
27503
27511
forEach(enumSymbol.declarations, decl => {
27504
27512
if (isEnumDeclaration(decl) && isEnumConst(decl) !== enumIsConst) {
0 commit comments