Skip to content

Commit 124fdb6

Browse files
committed
Allow yield expressions, and allow generators only in ES6 and higher
1 parent 8dac1bf commit 124fdb6

File tree

53 files changed

+216
-230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+216
-230
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7899,9 +7899,6 @@ module ts {
78997899
if (!(node.parserContextFlags & ParserContextFlags.Yield)) {
79007900
grammarErrorOnFirstToken(node, Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_declaration);
79017901
}
7902-
else {
7903-
grammarErrorOnFirstToken(node, Diagnostics.yield_expressions_are_not_currently_supported);
7904-
}
79057902
}
79067903

79077904
function checkConditionalExpression(node: ConditionalExpression, contextualMapper?: TypeMapper): Type {
@@ -12549,7 +12546,13 @@ module ts {
1254912546

1255012547
function checkGrammarForGenerator(node: FunctionLikeDeclaration) {
1255112548
if (node.asteriskToken) {
12552-
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_not_currently_supported);
12549+
Debug.assert(
12550+
node.kind === SyntaxKind.FunctionDeclaration ||
12551+
node.kind === SyntaxKind.FunctionExpression ||
12552+
node.kind === SyntaxKind.MethodDeclaration);
12553+
if (languageVersion < ScriptTarget.ES6) {
12554+
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher);
12555+
}
1255312556
}
1255412557
}
1255512558

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ module ts {
174174
Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" },
175175
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." },
176176
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'." },
177+
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." },
177178
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
178179
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." },
179180
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
@@ -539,8 +540,6 @@ module ts {
539540
enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." },
540541
type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." },
541542
decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." },
542-
yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." },
543-
Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." },
544543
Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." },
545544
class_expressions_are_not_currently_supported: { code: 9003, category: DiagnosticCategory.Error, key: "'class' expressions are not currently supported." },
546545
class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration: { code: 9004, category: DiagnosticCategory.Error, key: "'class' declarations are only supported directly inside a module or as a top level declaration." },

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,13 @@
682682
"Export assignment is not supported when '--module' flag is 'system'.": {
683683
"category": "Error",
684684
"code": 1218
685+
},
686+
"Generators are only available when targeting ECMAScript 6 or higher.": {
687+
"category": "Error",
688+
"code": 1219
685689
},
686690

691+
687692
"Duplicate identifier '{0}'.": {
688693
"category": "Error",
689694
"code": 2300
@@ -2149,14 +2154,6 @@
21492154
"code": 8017
21502155
},
21512156

2152-
"'yield' expressions are not currently supported.": {
2153-
"category": "Error",
2154-
"code": 9000
2155-
},
2156-
"Generators are not currently supported.": {
2157-
"category": "Error",
2158-
"code": 9001
2159-
},
21602157
"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses.": {
21612158
"category": "Error",
21622159
"code": 9002
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,10): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,10): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22

33

44
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (1 errors) ====
55
function * foo(a = yield => yield) {
66
~
7-
!!! error TS9001: Generators are not currently supported.
7+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts(1,10): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts(1,10): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22

33

44
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts (1 errors) ====
55
function * yield() {
66
~
7-
!!! error TS9001: Generators are not currently supported.
7+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
88
}

tests/baselines/reference/FunctionDeclaration13_es6.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts(1,10): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts(1,10): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts(3,11): error TS2304: Cannot find name 'yield'.
33

44

55
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts (2 errors) ====
66
function * foo() {
77
~
8-
!!! error TS9001: Generators are not currently supported.
8+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
99
// Legal to use 'yield' in a type context.
1010
var v: yield;
1111
~~~~~
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts(1,10): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts(1,10): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22

33

44
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts (1 errors) ====
55
function * foo() {
66
~
7-
!!! error TS9001: Generators are not currently supported.
7+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,9): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,9): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,18): error TS2304: Cannot find name 'yield'.
33

44

55
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts (2 errors) ====
66
function*foo(a = yield) {
77
~
8-
!!! error TS9001: Generators are not currently supported.
8+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
99
~~~~~
1010
!!! error TS2304: Cannot find name 'yield'.
1111
}

tests/baselines/reference/FunctionDeclaration7_es6.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(1,9): error TS9001: Generators are not currently supported.
2-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,11): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(1,9): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
2+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,11): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
33
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,20): error TS2304: Cannot find name 'yield'.
44

55

66
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts (3 errors) ====
77
function*bar() {
88
~
9-
!!! error TS9001: Generators are not currently supported.
9+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
1010
// 'yield' here is an identifier, and not a yield expression.
1111
function*foo(a = yield) {
1212
~
13-
!!! error TS9001: Generators are not currently supported.
13+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
1414
~~~~~
1515
!!! error TS2304: Cannot find name 'yield'.
1616
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(1,10): error TS9001: Generators are not currently supported.
2-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,14): error TS9000: 'yield' expressions are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(1,10): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
32

43

5-
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (2 errors) ====
4+
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (1 errors) ====
65
function * foo() {
76
~
8-
!!! error TS9001: Generators are not currently supported.
7+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
98
var v = { [yield]: foo }
10-
~~~~~
11-
!!! error TS9000: 'yield' expressions are not currently supported.
129
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts(1,18): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts(1,18): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22

33

44
==== tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts (1 errors) ====
55
var v = function * () { }
66
~
7-
!!! error TS9001: Generators are not currently supported.
7+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts(1,18): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts(1,18): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22

33

44
==== tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts (1 errors) ====
55
var v = function * foo() { }
66
~
7-
!!! error TS9001: Generators are not currently supported.
7+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments1_es6.ts(1,11): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments1_es6.ts(1,11): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22

33

44
==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments1_es6.ts (1 errors) ====
55
var v = { *foo() { } }
66
~
7-
!!! error TS9001: Generators are not currently supported.
7+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,13): error TS2304: Cannot find name 'foo'.
33

44

55
==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (2 errors) ====
66
var v = { *[foo()]() { } }
77
~
8-
!!! error TS9001: Generators are not currently supported.
8+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
99
~~~
1010
!!! error TS2304: Cannot find name 'foo'.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration1_es6.ts(2,4): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration1_es6.ts(2,4): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22

33

44
==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration1_es6.ts (1 errors) ====
55
class C {
66
*foo() { }
77
~
8-
!!! error TS9001: Generators are not currently supported.
8+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
99
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts(2,11): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts(2,11): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22

33

44
==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts (1 errors) ====
55
class C {
66
public * foo() { }
77
~
8-
!!! error TS9001: Generators are not currently supported.
8+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
99
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,4): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,4): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,6): error TS2304: Cannot find name 'foo'.
33

44

55
==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts (2 errors) ====
66
class C {
77
*[foo]() { }
88
~
9-
!!! error TS9001: Generators are not currently supported.
9+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
1010
~~~
1111
!!! error TS2304: Cannot find name 'foo'.
1212
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration7_es6.ts(2,4): error TS9001: Generators are not currently supported.
1+
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration7_es6.ts(2,4): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
22

33

44
==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration7_es6.ts (1 errors) ====
55
class C {
66
*foo<T>() { }
77
~
8-
!!! error TS9001: Generators are not currently supported.
8+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
99
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts(1,11): error TS9001: Generators are not currently supported.
2-
tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts(2,5): error TS9000: 'yield' expressions are not currently supported.
1+
tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts(1,11): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
32

43

5-
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts (2 errors) ====
4+
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts (1 errors) ====
65
var v = { * foo() {
76
~
8-
!!! error TS9001: Generators are not currently supported.
7+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
98
yield(foo);
10-
~~~~~
11-
!!! error TS9000: 'yield' expressions are not currently supported.
129
}
1310
}
1411

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts(2,3): error TS9001: Generators are not currently supported.
2-
tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts(3,5): error TS9000: 'yield' expressions are not currently supported.
1+
tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts(2,3): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
32

43

5-
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts (2 errors) ====
4+
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts (1 errors) ====
65
class C {
76
*foo() {
87
~
9-
!!! error TS9001: Generators are not currently supported.
8+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
109
yield(foo);
11-
~~~~~
12-
!!! error TS9000: 'yield' expressions are not currently supported.
1310
}
1411
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts(1,9): error TS9001: Generators are not currently supported.
2-
tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts(1,19): error TS9000: 'yield' expressions are not currently supported.
1+
tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts(1,9): error TS1218: Generators are only available when targeting ECMAScript 6 or higher.
32

43

5-
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts (2 errors) ====
4+
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts (1 errors) ====
65
function* foo() { yield }
76
~
8-
!!! error TS9001: Generators are not currently supported.
9-
~~~~~
10-
!!! error TS9000: 'yield' expressions are not currently supported.
7+
!!! error TS1218: Generators are only available when targeting ECMAScript 6 or higher.

0 commit comments

Comments
 (0)