@@ -1056,9 +1056,9 @@ namespace ts {
1056
1056
// block-scoped variable and namespace module. However, only when we
1057
1057
// try to resolve name in /*1*/ which is used in variable position,
1058
1058
// we want to check for block-scoped
1059
- if (meaning & SymbolFlags.BlockScopedVariable) {
1059
+ if (meaning & SymbolFlags.BlockScopedVariable || (meaning & SymbolFlags.Class && (meaning & SymbolFlags.Value) === SymbolFlags.Value) ) {
1060
1060
const exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result);
1061
- if (exportOrLocalSymbol.flags & SymbolFlags.BlockScopedVariable) {
1061
+ if (exportOrLocalSymbol.flags & SymbolFlags.BlockScopedVariable || exportOrLocalSymbol.flags & SymbolFlags.Class ) {
1062
1062
checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation);
1063
1063
}
1064
1064
}
@@ -1171,14 +1171,19 @@ namespace ts {
1171
1171
}
1172
1172
1173
1173
function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void {
1174
- Debug.assert((result.flags & SymbolFlags.BlockScopedVariable) !== 0 );
1174
+ Debug.assert(!! (result.flags & SymbolFlags.BlockScopedVariable || result.flags & SymbolFlags.Class) );
1175
1175
// Block-scoped variables cannot be used before their definition
1176
- const declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) ? d : undefined);
1176
+ const declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) || isClassLike(d) ? d : undefined);
1177
1177
1178
1178
Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
1179
1179
1180
1180
if (!isInAmbientContext(declaration) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
1181
- error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(declaration.name));
1181
+ if (result.flags & SymbolFlags.BlockScopedVariable) {
1182
+ error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(declaration.name));
1183
+ }
1184
+ else {
1185
+ error(errorLocation, Diagnostics.Class_0_used_before_its_declaration, declarationNameToString(declaration.name));
1186
+ }
1182
1187
}
1183
1188
}
1184
1189
@@ -13171,10 +13176,17 @@ namespace ts {
13171
13176
}
13172
13177
return unknownType;
13173
13178
}
13174
- if (prop.valueDeclaration &&
13175
- isInPropertyInitializer(node) &&
13176
- !isBlockScopedNameDeclaredBeforeUse(prop.valueDeclaration, right)) {
13177
- error(right, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, right.text);
13179
+ if (prop.valueDeclaration) {
13180
+ if (isInPropertyInitializer(node) &&
13181
+ !isBlockScopedNameDeclaredBeforeUse(prop.valueDeclaration, right)) {
13182
+ error(right, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, right.text);
13183
+ }
13184
+ if (prop.valueDeclaration.kind === SyntaxKind.ClassDeclaration &&
13185
+ node.parent && node.parent.kind !== SyntaxKind.TypeReference &&
13186
+ !isInAmbientContext(prop.valueDeclaration) &&
13187
+ !isBlockScopedNameDeclaredBeforeUse(prop.valueDeclaration, right)) {
13188
+ error(right, Diagnostics.Class_0_used_before_its_declaration, right.text);
13189
+ }
13178
13190
}
13179
13191
13180
13192
markPropertyAsReferenced(prop);
@@ -19421,14 +19433,6 @@ namespace ts {
19421
19433
error(node.name || node, Diagnostics.A_mixin_class_must_have_a_constructor_with_a_single_rest_parameter_of_type_any);
19422
19434
}
19423
19435
19424
- if (baseType.symbol && baseType.symbol.valueDeclaration &&
19425
- !isInAmbientContext(baseType.symbol.valueDeclaration) &&
19426
- baseType.symbol.valueDeclaration.kind === SyntaxKind.ClassDeclaration) {
19427
- if (!isBlockScopedNameDeclaredBeforeUse(baseType.symbol.valueDeclaration, node)) {
19428
- error(baseTypeNode, Diagnostics.A_class_must_be_declared_after_its_base_class);
19429
- }
19430
- }
19431
-
19432
19436
if (!(staticBaseType.symbol && staticBaseType.symbol.flags & SymbolFlags.Class) && !(baseConstructorType.flags & TypeFlags.TypeVariable)) {
19433
19437
// When the static base type is a "class-like" constructor function (but not actually a class), we verify
19434
19438
// that all instantiated base constructor signatures return the same type. We can simply compare the type
0 commit comments