Skip to content

Commit d37368e

Browse files
Report error on asterisk token.
1 parent 5b539f0 commit d37368e

22 files changed

+78
-86
lines changed

Diff for: src/compiler/parser.ts

+36-44
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,15 @@ module ts {
11551155
return false;
11561156
}
11571157

1158+
function parseOptionalToken(t: SyntaxKind): Node {
1159+
if (token === t) {
1160+
var node = createNode(t);
1161+
nextToken();
1162+
return finishNode(node);
1163+
}
1164+
return undefined;
1165+
}
1166+
11581167
function canParseSemicolon() {
11591168
// If there's a real semicolon, then we can always parse it out.
11601169
if (token === SyntaxKind.SemicolonToken) {
@@ -2202,10 +2211,7 @@ module ts {
22022211

22032212
if (!scanner.hasPrecedingLineBreak() &&
22042213
(token === SyntaxKind.AsteriskToken || isStartOfExpression())) {
2205-
if (parseOptional(SyntaxKind.AsteriskToken)) {
2206-
node.flags = NodeFlags.YieldStar;
2207-
}
2208-
2214+
node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
22092215
node.expression = parseAssignmentExpression();
22102216
return finishNode(node);
22112217
}
@@ -2255,7 +2261,7 @@ module ts {
22552261
}
22562262
else {
22572263
// If not, we're probably better off bailing out and returning a bogus function expression.
2258-
return makeFunctionExpression(SyntaxKind.ArrowFunction, pos, /* name */ undefined, sig, createMissingNode());
2264+
return makeFunctionExpression(SyntaxKind.ArrowFunction, pos, /*asteriskToken:*/ undefined, /*name:*/ undefined, sig, createMissingNode());
22592265
}
22602266
}
22612267

@@ -2395,7 +2401,7 @@ module ts {
23952401
body = parseAssignmentExpression();
23962402
}
23972403

2398-
return makeFunctionExpression(SyntaxKind.ArrowFunction, pos, /* name */ undefined, sig, body);
2404+
return makeFunctionExpression(SyntaxKind.ArrowFunction, pos, /*asteriskToken:*/ undefined, /*name:*/ undefined, sig, body);
23992405
}
24002406

24012407
function parseConditionalExpression(): Expression {
@@ -2731,26 +2737,23 @@ module ts {
27312737

27322738
function parsePropertyAssignment(): Declaration {
27332739
var nodePos = scanner.getStartPos();
2734-
var isGenerator = parseOptional(SyntaxKind.AsteriskToken);
2740+
var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
27352741
var tokenIsIdentifier = isIdentifier();
27362742
var nameToken = token;
27372743
var propertyName = parsePropertyName();
27382744
var node: Declaration;
2739-
if (isGenerator || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
2745+
if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
27402746
node = <PropertyDeclaration>createNode(SyntaxKind.PropertyAssignment, nodePos);
27412747
node.name = propertyName;
2742-
if (isGenerator) {
2743-
node.flags |= NodeFlags.Generator;
2744-
}
2745-
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ isGenerator);
2748+
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken);
27462749

2747-
var body = parseFunctionBlock(isGenerator, /* ignoreMissingOpenBrace */ false);
2750+
var body = parseFunctionBlock(!!asteriskToken, /* ignoreMissingOpenBrace */ false);
27482751
// do not propagate property name as name for function expression
27492752
// for scenarios like
27502753
// var x = 1;
27512754
// var y = { x() { } }
27522755
// otherwise this will bring y.x into the scope of x which is incorrect
2753-
(<PropertyDeclaration>node).initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, undefined, sig, body);
2756+
(<PropertyDeclaration>node).initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, asteriskToken, undefined, sig, body);
27542757
return finishNode(node);
27552758
}
27562759

@@ -2808,24 +2811,21 @@ module ts {
28082811

28092812
var pos = getNodePos();
28102813
parseExpected(SyntaxKind.FunctionKeyword);
2811-
var isGenerator = parseOptional(SyntaxKind.AsteriskToken);
2812-
var name = isGenerator ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier();
2813-
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ isGenerator);
2814+
var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
2815+
var name = asteriskToken ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier();
2816+
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken);
28142817

2815-
var body = parseFunctionBlock(/*allowYield:*/ isGenerator, /* ignoreMissingOpenBrace */ false);
2816-
return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, name, sig, body, isGenerator ? NodeFlags.Generator : undefined);
2818+
var body = parseFunctionBlock(/*allowYield:*/ !!asteriskToken, /* ignoreMissingOpenBrace */ false);
2819+
return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, asteriskToken, name, sig, body);
28172820
}
28182821

28192822
function parseOptionalIdentifier() {
28202823
return isIdentifier() ? parseIdentifier() : undefined;
28212824
}
28222825

2823-
function makeFunctionExpression(kind: SyntaxKind, pos: number, name: Identifier, sig: ParsedSignature, body: Node, flags?: NodeFlags): FunctionExpression {
2826+
function makeFunctionExpression(kind: SyntaxKind, pos: number, asteriskToken: Node, name: Identifier, sig: ParsedSignature, body: Node): FunctionExpression {
28242827
var node = <FunctionExpression>createNode(kind, pos);
2825-
if (flags) {
2826-
node.flags = flags;
2827-
}
2828-
2828+
node.asteriskToken = asteriskToken;
28292829
node.name = name;
28302830
node.typeParameters = sig.typeParameters;
28312831
node.parameters = sig.parameters;
@@ -3292,14 +3292,10 @@ module ts {
32923292
var node = <FunctionLikeDeclaration>createNode(SyntaxKind.FunctionDeclaration, fullStart);
32933293
setModifiers(node, modifiers);
32943294
parseExpected(SyntaxKind.FunctionKeyword);
3295-
var isGenerator = parseOptional(SyntaxKind.AsteriskToken);
3296-
if (isGenerator) {
3297-
node.flags |= NodeFlags.Generator;
3298-
}
3299-
3295+
node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
33003296
node.name = parseIdentifier();
3301-
fillSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ isGenerator, node);
3302-
node.body = parseFunctionBlockOrSemicolon(isGenerator);
3297+
fillSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ !!node.asteriskToken, node);
3298+
node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken);
33033299
return finishNode(node);
33043300
}
33053301

@@ -3314,27 +3310,24 @@ module ts {
33143310

33153311
function parsePropertyMemberDeclaration(fullStart: number, modifiers: ModifiersArray): Declaration {
33163312
var flags = modifiers ? modifiers.flags : 0;
3317-
var isGenerator = parseOptional(SyntaxKind.AsteriskToken);
3318-
if (isGenerator) {
3319-
flags |= NodeFlags.Generator;
3320-
}
3321-
3313+
var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
33223314
var name = parsePropertyName();
33233315
if (parseOptional(SyntaxKind.QuestionToken)) {
33243316
// Note: this is not legal as per the grammar. But we allow it in the parser and
33253317
// report an error in the grammar checker.
33263318
flags |= NodeFlags.QuestionMark;
33273319
}
33283320

3329-
if (isGenerator || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
3321+
if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
33303322
var method = <MethodDeclaration>createNode(SyntaxKind.Method, fullStart);
33313323
setModifiers(method, modifiers);
33323324
if (flags) {
33333325
method.flags = flags;
33343326
}
3327+
method.asteriskToken = asteriskToken;
33353328
method.name = name;
3336-
fillSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ isGenerator, method);
3337-
method.body = parseFunctionBlockOrSemicolon(isGenerator);
3329+
fillSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, method);
3330+
method.body = parseFunctionBlockOrSemicolon(!!asteriskToken);
33383331
return finishNode(method);
33393332
}
33403333
else {
@@ -4306,9 +4299,9 @@ module ts {
43064299
checkForGenerator(node);
43074300
}
43084301

4309-
function checkForGenerator(node: Node) {
4310-
if (node.flags & NodeFlags.Generator) {
4311-
return grammarErrorOnFirstToken(node, Diagnostics.generators_are_not_currently_supported);
4302+
function checkForGenerator(node: FunctionLikeDeclaration) {
4303+
if (node.asteriskToken) {
4304+
return grammarErrorOnNode(node.asteriskToken, Diagnostics.generators_are_not_currently_supported);
43124305
}
43134306
}
43144307

@@ -4741,8 +4734,7 @@ module ts {
47414734
}
47424735

47434736
function checkPropertyAssignment(node: PropertyDeclaration) {
4744-
return checkForInvalidQuestionMark(node, Diagnostics.An_object_member_cannot_be_declared_optional) ||
4745-
checkForGenerator(node);
4737+
return checkForInvalidQuestionMark(node, Diagnostics.An_object_member_cannot_be_declared_optional);
47464738
}
47474739

47484740
function checkForInvalidQuestionMark(node: Declaration, message: DiagnosticMessage) {

Diff for: src/compiler/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ module ts {
271271
Let = 0x00000800, // Variable declaration
272272
Const = 0x00001000, // Variable declaration
273273
OctalLiteral = 0x00002000,
274-
Generator = 0x00004000,
275-
YieldStar = 0x00008000,
276274

277275
Modifier = Export | Ambient | Public | Private | Protected | Static,
278276
AccessibilityModifier = Public | Private | Protected,
@@ -377,6 +375,7 @@ module ts {
377375
* FunctionExpression
378376
*/
379377
export interface FunctionLikeDeclaration extends Declaration, ParsedSignature {
378+
asteriskToken?: Node;
380379
body?: Block | Expression;
381380
}
382381

@@ -442,6 +441,7 @@ module ts {
442441
}
443442

444443
export interface YieldExpression extends Expression {
444+
asteriskToken?: Node;
445445
expression: Expression;
446446
}
447447

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,10): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (1 errors) ====
55
function * foo(a = yield => yield) {
6-
~~~~~~~~
6+
~
77
!!! error TS9001: 'generators' are not currently supported.
88
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts(1,10): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts (1 errors) ====
55
function * yield() {
6-
~~~~~~~~
6+
~
77
!!! error TS9001: 'generators' are not currently supported.
88
}

Diff for: tests/baselines/reference/FunctionDeclaration13_es6.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts(1,10): error TS9001: 'generators' are not currently supported.
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() {
7-
~~~~~~~~
7+
~
88
!!! error TS9001: 'generators' are not currently supported.
99
// Legal to use 'yield' in a type context.
1010
var v: yield;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts(1,10): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts (1 errors) ====
55
function * foo() {
6-
~~~~~~~~
6+
~
77
!!! error TS9001: 'generators' are not currently supported.
88
}

Diff for: tests/baselines/reference/FunctionDeclaration6_es6.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,9): error TS9001: 'generators' are not currently supported.
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) {
7-
~~~~~~~~
7+
~
88
!!! error TS9001: 'generators' are not currently supported.
99
~~~~~
1010
!!! error TS2304: Cannot find name 'yield'.

Diff for: tests/baselines/reference/FunctionDeclaration7_es6.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(1,9): error TS9001: 'generators' are not currently supported.
22
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,20): error TS2304: Cannot find name 'yield'.
33

44

55
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts (2 errors) ====
66
function*bar() {
7-
~~~~~~~~
7+
~
88
!!! error TS9001: 'generators' are not currently supported.
99
// 'yield' here is an identifier, and not a yield expression.
1010
function*foo(a = yield) {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts(1,9): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts(1,18): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts (1 errors) ====
55
var v = function * () { }
6-
~~~~~~~~
6+
~
77
!!! error TS9001: 'generators' are not currently supported.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts(1,9): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts(1,18): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts (1 errors) ====
55
var v = function * foo() { }
6-
~~~~~~~~
6+
~
77
!!! error TS9001: 'generators' are not currently supported.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts(2,4): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts(2,11): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts (1 errors) ====
55
class C {
66
public * foo() { }
7-
~~~~~~
7+
~
88
!!! error TS9001: 'generators' are not currently supported.
99
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts(1,9): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts (1 errors) ====
55
function* foo() { yield }
6-
~~~~~~~~
6+
~
77
!!! error TS9001: 'generators' are not currently supported.

Diff for: tests/baselines/reference/YieldExpression16_es6.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts(1,9): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts (1 errors) ====
55
function* foo() {
6-
~~~~~~~~
6+
~
77
!!! error TS9001: 'generators' are not currently supported.
88
function bar() {
99
yield foo;

Diff for: tests/baselines/reference/YieldExpression19_es6.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(1,9): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts (1 errors) ====
55
function*foo() {
6-
~~~~~~~~
6+
~
77
!!! error TS9001: 'generators' are not currently supported.
88
function bar() {
99
function* quux() {

Diff for: tests/baselines/reference/YieldExpression3_es6.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts(1,9): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts (1 errors) ====
55
function* foo() {
6-
~~~~~~~~
6+
~
77
!!! error TS9001: 'generators' are not currently supported.
88
yield
99
yield

Diff for: tests/baselines/reference/YieldExpression4_es6.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts(1,9): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts (1 errors) ====
55
function* foo() {
6-
~~~~~~~~
6+
~
77
!!! error TS9001: 'generators' are not currently supported.
88
yield;
99
yield;
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts(1,1): error TS9001: 'generators' are not currently supported.
1+
tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts(1,9): error TS9001: 'generators' are not currently supported.
22

33

44
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts (1 errors) ====
55
function* foo() {
6-
~~~~~~~~
6+
~
77
!!! error TS9001: 'generators' are not currently supported.
88
yield*foo
99
}

0 commit comments

Comments
 (0)