hoist source level class declarations, fix error message

This commit is contained in:
Vladimir Matveev
2015-04-11 06:14:19 -07:00
parent 8c80792fe2
commit 442addecf5
4 changed files with 23 additions and 10 deletions

View File

@@ -10623,7 +10623,7 @@ module ts {
}
else if (compilerOptions.module === ModuleKind.System) {
// system modules does not support export assignment
grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_with_module_flag_is_system);
grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
}
}
}

View File

@@ -169,7 +169,7 @@ module ts {
Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." },
Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." },
A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" },
Export_assignment_is_not_supported_with_module_flag_is_system: { code: 1212, category: DiagnosticCategory.Error, key: "Export assignment is not supported with '--module' flag is 'system'." },
Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1212, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

View File

@@ -667,7 +667,7 @@
"category": "Error",
"code": 1211
},
"Export assignment is not supported with '--module' flag is 'system'.": {
"Export assignment is not supported when '--module' flag is 'system'.": {
"category": "Error",
"code": 1212
},

View File

@@ -3818,7 +3818,9 @@ var __param = this.__param || function(index, decorator) { return function (targ
function emitClassLikeDeclarationBelowES6(node: ClassLikeDeclaration) {
if (node.kind === SyntaxKind.ClassDeclaration) {
write("var ");
if (!currentFileIsEmittedAsSystemModule() || !isSourceFileLevelDeclaration(node)) {
write("var ");
}
emitDeclarationName(node);
write(" = ");
}
@@ -4827,20 +4829,25 @@ var __param = this.__param || function(index, decorator) { return function (targ
}
function hoistTopLevelVariableAndFunctionDeclarations(node: SourceFile): void {
let hoistedLocals: Identifier[];
let hoistedVars: (Identifier | ClassDeclaration)[];
let hoistedFunctionDeclarations: FunctionDeclaration[];
visit(node);
if (hoistedLocals) {
if (hoistedVars) {
writeLine();
write("var ");
for (let i = 0; i < hoistedLocals.length; ++i) {
let local = hoistedLocals[i];
for (let i = 0; i < hoistedVars.length; ++i) {
let local = hoistedVars[i];
if (i !== 0) {
write(", ");
}
emit(local);
if (local.kind === SyntaxKind.ClassDeclaration) {
emitDeclarationName(<ClassDeclaration>local);
}
else {
emit(local);
}
}
write(";")
}
@@ -4858,11 +4865,17 @@ var __param = this.__param || function(index, decorator) { return function (targ
return;
}
if (node.kind === SyntaxKind.ClassDeclaration) {
// TODO: rename block scoped classes
(hoistedVars || (hoistedVars = [])).push(<ClassDeclaration>node);
return;
}
if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) {
let name = (<VariableDeclaration | BindingElement>node).name;
if (name.kind === SyntaxKind.Identifier) {
renameNonTopLevelLetAndConst(name);
(hoistedLocals || (hoistedLocals = [])).push(<Identifier>name);
(hoistedVars || (hoistedVars = [])).push(<Identifier>name);
}
else {
forEachChild(name, visit);