Disallow generators in an ambient context

This commit is contained in:
Jason Freeman 2015-04-22 16:35:45 -07:00
parent 124fdb6048
commit d52c224697
21 changed files with 142 additions and 0 deletions

View File

@ -12550,6 +12550,9 @@ module ts {
node.kind === SyntaxKind.FunctionDeclaration ||
node.kind === SyntaxKind.FunctionExpression ||
node.kind === SyntaxKind.MethodDeclaration);
if (isInAmbientContext(node)) {
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_not_allowed_in_an_ambient_context);
}
if (languageVersion < ScriptTarget.ES6) {
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher);
}

View File

@ -175,6 +175,7 @@ module ts {
Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1219, category: DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." },
Generators_are_not_allowed_in_an_ambient_context: { code: 1220, category: DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." },
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

@ -687,6 +687,10 @@
"category": "Error",
"code": 1219
},
"Generators are not allowed in an ambient context.": {
"category": "Error",
"code": 1220
},
"Duplicate identifier '{0}'.": {

View File

@ -0,0 +1,9 @@
tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext1.ts(2,5): error TS1219: Generators are not allowed in an ambient context.
==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext1.ts (1 errors) ====
declare class C {
*generator(): any;
~
!!! error TS1219: Generators are not allowed in an ambient context.
}

View File

@ -0,0 +1,6 @@
//// [generatorInAmbientContext1.ts]
declare class C {
*generator(): any;
}
//// [generatorInAmbientContext1.js]

View File

@ -0,0 +1,9 @@
tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext2.ts(2,14): error TS1219: Generators are not allowed in an ambient context.
==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext2.ts (1 errors) ====
declare module M {
function *generator(): any;
~
!!! error TS1219: Generators are not allowed in an ambient context.
}

View File

@ -0,0 +1,6 @@
//// [generatorInAmbientContext2.ts]
declare module M {
function *generator(): any;
}
//// [generatorInAmbientContext2.js]

View File

@ -0,0 +1,9 @@
tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext3.d.ts(2,5): error TS1219: Generators are not allowed in an ambient context.
==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext3.d.ts (1 errors) ====
declare class C {
*generator(): any;
~
!!! error TS1219: Generators are not allowed in an ambient context.
}

View File

@ -0,0 +1,9 @@
tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext4.d.ts(2,14): error TS1219: Generators are not allowed in an ambient context.
==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext4.d.ts (1 errors) ====
declare module M {
function *generator(): any;
~
!!! error TS1219: Generators are not allowed in an ambient context.
}

View File

@ -0,0 +1,15 @@
//// [generatorInAmbientContext5.ts]
class C {
*generator(): any { }
}
//// [generatorInAmbientContext5.js]
class C {
*generator() { }
}
//// [generatorInAmbientContext5.d.ts]
declare class C {
generator(): any;
}

View File

@ -0,0 +1,7 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext5.ts ===
class C {
>C : Symbol(C, Decl(generatorInAmbientContext5.ts, 0, 0))
*generator(): any { }
>generator : Symbol(generator, Decl(generatorInAmbientContext5.ts, 0, 9))
}

View File

@ -0,0 +1,7 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext5.ts ===
class C {
>C : C
*generator(): any { }
>generator : () => any
}

View File

@ -0,0 +1,17 @@
//// [generatorInAmbientContext6.ts]
module M {
export function *generator(): any { }
}
//// [generatorInAmbientContext6.js]
var M;
(function (M) {
function* generator() { }
M.generator = generator;
})(M || (M = {}));
//// [generatorInAmbientContext6.d.ts]
declare module M {
function generator(): any;
}

View File

@ -0,0 +1,7 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext6.ts ===
module M {
>M : Symbol(M, Decl(generatorInAmbientContext6.ts, 0, 0))
export function *generator(): any { }
>generator : Symbol(generator, Decl(generatorInAmbientContext6.ts, 0, 10))
}

View File

@ -0,0 +1,7 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext6.ts ===
module M {
>M : typeof M
export function *generator(): any { }
>generator : () => any
}

View File

@ -0,0 +1,4 @@
//@target: ES6
declare class C {
*generator(): any;
}

View File

@ -0,0 +1,4 @@
//@target: ES6
declare module M {
function *generator(): any;
}

View File

@ -0,0 +1,4 @@
//@target: ES6
declare class C {
*generator(): any;
}

View File

@ -0,0 +1,4 @@
//@target: ES6
declare module M {
function *generator(): any;
}

View File

@ -0,0 +1,5 @@
//@target: ES6
//@declaration: true
class C {
*generator(): any { }
}

View File

@ -0,0 +1,5 @@
//@target: ES6
//@declaration: true
module M {
export function *generator(): any { }
}