mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Remove generatorParameter and asyncParameter contexts.
This commit is contained in:
parent
9a57e6ff17
commit
f1c99f3397
@ -6083,6 +6083,18 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isInParameterInitializerBeforeContainingFunction(node: Node) {
|
||||
while (node.parent && !isFunctionLike(node.parent)) {
|
||||
if (node.parent.kind === SyntaxKind.Parameter && (<ParameterDeclaration>node.parent).initializer === node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getContextualReturnType(functionDecl: FunctionLikeDeclaration): Type {
|
||||
// If the containing function has a return type annotation, is a constructor, or is a get accessor whose
|
||||
// corresponding set accessor has a type annotation, return statements in the function are contextually typed
|
||||
@ -8031,8 +8043,14 @@ namespace ts {
|
||||
|
||||
function checkAwaitExpression(node: AwaitExpression): Type {
|
||||
// Grammar checking
|
||||
if (!(node.parserContextFlags & ParserContextFlags.Await)) {
|
||||
grammarErrorOnFirstToken(node, Diagnostics.await_expression_is_only_allowed_within_an_async_function);
|
||||
if (produceDiagnostics) {
|
||||
if (!(node.parserContextFlags & ParserContextFlags.Await)) {
|
||||
grammarErrorOnFirstToken(node, Diagnostics.await_expression_is_only_allowed_within_an_async_function);
|
||||
}
|
||||
|
||||
if (isInParameterInitializerBeforeContainingFunction(node)) {
|
||||
error(node, Diagnostics.await_expressions_cannot_be_used_in_a_parameter_initializer);
|
||||
}
|
||||
}
|
||||
|
||||
let operandType = checkExpression(node.expression);
|
||||
@ -8465,8 +8483,14 @@ namespace ts {
|
||||
|
||||
function checkYieldExpression(node: YieldExpression): Type {
|
||||
// Grammar checking
|
||||
if (!(node.parserContextFlags & ParserContextFlags.Yield) || isYieldExpressionInClass(node)) {
|
||||
grammarErrorOnFirstToken(node, Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
|
||||
if (produceDiagnostics) {
|
||||
if (!(node.parserContextFlags & ParserContextFlags.Yield) || isYieldExpressionInClass(node)) {
|
||||
grammarErrorOnFirstToken(node, Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
|
||||
}
|
||||
|
||||
if (isInParameterInitializerBeforeContainingFunction(node)) {
|
||||
error(node, Diagnostics.yield_expressions_cannot_be_used_in_a_parameter_initializer);
|
||||
}
|
||||
}
|
||||
|
||||
if (node.expression) {
|
||||
|
||||
@ -398,6 +398,8 @@ namespace ts {
|
||||
Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." },
|
||||
Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." },
|
||||
The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression: { code: 2522, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression." },
|
||||
yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." },
|
||||
await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." },
|
||||
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
|
||||
|
||||
@ -1570,7 +1570,6 @@
|
||||
"category": "Error",
|
||||
"code": 2505
|
||||
},
|
||||
|
||||
"Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": {
|
||||
"category": "Error",
|
||||
"code": 2520
|
||||
@ -1583,6 +1582,14 @@
|
||||
"category": "Error",
|
||||
"code": 2522
|
||||
},
|
||||
"'yield' expressions cannot be used in a parameter initializer.": {
|
||||
"category": "Error",
|
||||
"code": 2523
|
||||
},
|
||||
"'await' expressions cannot be used in a parameter initializer.": {
|
||||
"category": "Error",
|
||||
"code": 2524
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
@ -661,10 +661,6 @@ namespace ts {
|
||||
setContextFlag(val, ParserContextFlags.Yield);
|
||||
}
|
||||
|
||||
function setGeneratorParameterContext(val: boolean) {
|
||||
setContextFlag(val, ParserContextFlags.GeneratorParameter);
|
||||
}
|
||||
|
||||
function setDecoratorContext(val: boolean) {
|
||||
setContextFlag(val, ParserContextFlags.Decorator);
|
||||
}
|
||||
@ -672,11 +668,7 @@ namespace ts {
|
||||
function setAwaitContext(val: boolean) {
|
||||
setContextFlag(val, ParserContextFlags.Await);
|
||||
}
|
||||
|
||||
function setAsyncParameterContext(val: boolean) {
|
||||
setContextFlag(val, ParserContextFlags.AsyncParameter);
|
||||
}
|
||||
|
||||
|
||||
function doOutsideOfContext<T>(context: ParserContextFlags, func: () => T): T {
|
||||
// contextFlagsToClear will contain only the context flags that are
|
||||
// currently set that we need to temporarily clear
|
||||
@ -767,10 +759,6 @@ namespace ts {
|
||||
return inContext(ParserContextFlags.StrictMode);
|
||||
}
|
||||
|
||||
function inGeneratorParameterContext() {
|
||||
return inContext(ParserContextFlags.GeneratorParameter);
|
||||
}
|
||||
|
||||
function inDisallowInContext() {
|
||||
return inContext(ParserContextFlags.DisallowIn);
|
||||
}
|
||||
@ -782,15 +770,7 @@ namespace ts {
|
||||
function inAwaitContext() {
|
||||
return inContext(ParserContextFlags.Await);
|
||||
}
|
||||
|
||||
function inAsyncParameterContext() {
|
||||
return inContext(ParserContextFlags.AsyncParameter);
|
||||
}
|
||||
|
||||
function inGeneratorParameterOrAsyncParameterContext() {
|
||||
return inContext(ParserContextFlags.GeneratorParameter | ParserContextFlags.AsyncParameter);
|
||||
}
|
||||
|
||||
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void {
|
||||
let start = scanner.getTokenPos();
|
||||
let length = scanner.getTextPos() - start;
|
||||
@ -1083,24 +1063,16 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseComputedPropertyName(): ComputedPropertyName {
|
||||
// PropertyName[Yield,GeneratorParameter] :
|
||||
// LiteralPropertyName
|
||||
// [+GeneratorParameter] ComputedPropertyName
|
||||
// [+AsyncParameter] ComputedPropertyName
|
||||
// [~GeneratorParameter,~AsyncParameter] ComputedPropertyName[?Yield,?Await]
|
||||
//
|
||||
// ComputedPropertyName[Yield] :
|
||||
// [ AssignmentExpression[In, ?Yield] ]
|
||||
//
|
||||
// PropertyName [Yield]:
|
||||
// LiteralPropertyName
|
||||
// ComputedPropertyName[?Yield]
|
||||
let node = <ComputedPropertyName>createNode(SyntaxKind.ComputedPropertyName);
|
||||
parseExpected(SyntaxKind.OpenBracketToken);
|
||||
|
||||
// We parse any expression (including a comma expression). But the grammar
|
||||
// says that only an assignment expression is allowed, so the grammar checker
|
||||
// will error if it sees a comma expression.
|
||||
node.expression = inGeneratorParameterOrAsyncParameterContext()
|
||||
? doOutsideOfYieldAndAwaitContext(allowInAndParseExpression)
|
||||
: allowInAnd(parseExpression);
|
||||
node.expression = allowInAnd(parseExpression);
|
||||
|
||||
parseExpected(SyntaxKind.CloseBracketToken);
|
||||
return finishNode(node);
|
||||
@ -1991,8 +1963,8 @@ namespace ts {
|
||||
node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
|
||||
setModifiers(node, parseModifiers());
|
||||
|
||||
// FormalParameter[Yield,GeneratorParameter,Await,AsyncParameter] : (Modified) See 14.1
|
||||
// BindingElement[?Yield,?GeneratorParameter,?Await,?AsyncParameter]
|
||||
// FormalParameter [Yield,Await]:
|
||||
// BindingElement[?Yield,?Await]
|
||||
|
||||
node.name = parseIdentifierOrPattern();
|
||||
|
||||
@ -2024,18 +1996,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseBindingElementInitializer(inParameter: boolean) {
|
||||
// BindingElement[Yield,GeneratorParameter,Await,AsyncParameter] :
|
||||
// [+GeneratorParameter] BindingPattern[?Yield,?Await,?AsyncParameter,GeneratorParameter] Initializer[In]opt
|
||||
// [+AsyncParameter] BindingPattern[?Yield,?GeneratorParameter,?Await,AsyncParameter] Initializer[In]opt
|
||||
// [~GeneratorParameter,~AsyncParameter] BindingPattern[?Yield,?Await] Initializer[In,?Yield,?Await]opt
|
||||
// SingleNameBinding[Yield,GeneratorParameter,Await,AsyncParameter] :
|
||||
// [+GeneratorParameter] BindingIdentifier[Yield, ?Await] Initializer[In]opt
|
||||
// [+AsyncParameter] BindingIdentifier[Await, ?Yield] Initializer[In]opt
|
||||
// [~GeneratorParameter,~AsyncParameter] BindingIdentifier[?Yield,?Await] Initializer[In,?Yield,?Await]opt
|
||||
let parseInitializer = inParameter ? parseParameterInitializer : parseNonParameterInitializer;
|
||||
return inGeneratorParameterOrAsyncParameterContext()
|
||||
? doOutsideOfYieldAndAwaitContext(parseInitializer)
|
||||
: parseInitializer();
|
||||
return inParameter ? parseParameterInitializer() : parseNonParameterInitializer();
|
||||
}
|
||||
|
||||
function parseParameterInitializer() {
|
||||
@ -2043,14 +2004,15 @@ namespace ts {
|
||||
}
|
||||
|
||||
function fillSignature(
|
||||
returnToken: SyntaxKind,
|
||||
yieldAndGeneratorParameterContext: boolean,
|
||||
awaitAndAsyncParameterContext: boolean,
|
||||
requireCompleteParameterList: boolean,
|
||||
signature: SignatureDeclaration): void {
|
||||
returnToken: SyntaxKind,
|
||||
yieldContext: boolean,
|
||||
awaitContext: boolean,
|
||||
requireCompleteParameterList: boolean,
|
||||
signature: SignatureDeclaration): void {
|
||||
|
||||
let returnTokenRequired = returnToken === SyntaxKind.EqualsGreaterThanToken;
|
||||
signature.typeParameters = parseTypeParameters();
|
||||
signature.parameters = parseParameterList(yieldAndGeneratorParameterContext, awaitAndAsyncParameterContext, requireCompleteParameterList);
|
||||
signature.parameters = parseParameterList(yieldContext, awaitContext, requireCompleteParameterList);
|
||||
|
||||
if (returnTokenRequired) {
|
||||
parseExpected(returnToken);
|
||||
@ -2061,44 +2023,31 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
// Note: after careful analysis of the grammar, it does not appear to be possible to
|
||||
// have 'Yield' And 'GeneratorParameter' not in sync. i.e. any production calling
|
||||
// this FormalParameters production either always sets both to true, or always sets
|
||||
// both to false. As such we only have a single parameter to represent both.
|
||||
function parseParameterList(yieldAndGeneratorParameterContext: boolean, awaitAndAsyncParameterContext: boolean, requireCompleteParameterList: boolean) {
|
||||
// FormalParameters[Yield,GeneratorParameter,Await,AsyncParameter] : (Modified)
|
||||
// ...
|
||||
function parseParameterList(yieldContext: boolean, awaitContext: boolean, requireCompleteParameterList: boolean) {
|
||||
// FormalParameters [Yield,Await]: (modified)
|
||||
// [empty]
|
||||
// FormalParameterList[?Yield,Await]
|
||||
//
|
||||
// FormalParameter[Yield,GeneratorParameter,Await,AsyncParameter] : (Modified)
|
||||
// BindingElement[?Yield,?GeneratorParameter,?Await,?AsyncParameter]
|
||||
// FormalParameter[Yield,Await]: (modified)
|
||||
// BindingElement[?Yield,Await]
|
||||
//
|
||||
// BindingElement[Yield,GeneratorParameter,Await,AsyncParameter] : (Modified) See 13.2.3
|
||||
// SingleNameBinding[?Yield,?GeneratorParameter,?Await,?AsyncParameter]
|
||||
// [+GeneratorParameter]BindingPattern[?Yield,?Await,?AsyncParameter,GeneratorParameter] Initializer[In]opt
|
||||
// [+AsyncParameter]BindingPattern[?Yield,?Await,?GeneratorParameter,AsyncParameter] Initializer[In]opt
|
||||
// [~GeneratorParameter,~AsyncParameter]BindingPattern[?Yield,?Await]Initializer[In,?Yield,?Await]opt
|
||||
// BindingElement [Yield,Await]: (modified)
|
||||
// SingleNameBinding[?Yield,?Await]
|
||||
// BindingPattern[?Yield,?Await]Initializer [In, ?Yield,?Await] opt
|
||||
//
|
||||
// SingleNameBinding[Yield,GeneratorParameter,Await,AsyncParameter] : (Modified) See 13.2.3
|
||||
// [+GeneratorParameter]BindingIdentifier[Yield]Initializer[In]opt
|
||||
// [+AsyncParameter]BindingIdentifier[Await]Initializer[In]opt
|
||||
// [~GeneratorParameter,~AsyncParameter]BindingIdentifier[?Yield,?Await]Initializer[In,?Yield,?Await]opt
|
||||
// SingleNameBinding [Yield,Await]:
|
||||
// BindingIdentifier[?Yield,?Await]Initializer [In, ?Yield,?Await] opt
|
||||
if (parseExpected(SyntaxKind.OpenParenToken)) {
|
||||
let savedYieldContext = inYieldContext();
|
||||
let savedGeneratorParameterContext = inGeneratorParameterContext();
|
||||
let savedAwaitContext = inAwaitContext();
|
||||
let savedAsyncParameterContext = inAsyncParameterContext();
|
||||
|
||||
setYieldContext(yieldAndGeneratorParameterContext);
|
||||
setGeneratorParameterContext(yieldAndGeneratorParameterContext);
|
||||
setAwaitContext(awaitAndAsyncParameterContext);
|
||||
setAsyncParameterContext(awaitAndAsyncParameterContext);
|
||||
setYieldContext(yieldContext);
|
||||
setAwaitContext(awaitContext);
|
||||
|
||||
let result = parseDelimitedList(ParsingContext.Parameters, parseParameter);
|
||||
|
||||
setYieldContext(savedYieldContext);
|
||||
setGeneratorParameterContext(savedGeneratorParameterContext);
|
||||
setAwaitContext(savedAwaitContext);
|
||||
setAsyncParameterContext(savedAsyncParameterContext);
|
||||
|
||||
if (!parseExpected(SyntaxKind.CloseParenToken) && requireCompleteParameterList) {
|
||||
// Caller insisted that we had to end with a ) We didn't. So just return
|
||||
@ -2131,7 +2080,7 @@ namespace ts {
|
||||
if (kind === SyntaxKind.ConstructSignature) {
|
||||
parseExpected(SyntaxKind.NewKeyword);
|
||||
}
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ false, /*requireCompleteParameterList*/ false, node);
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
|
||||
parseTypeMemberSemicolon();
|
||||
return finishNode(node);
|
||||
}
|
||||
@ -2220,8 +2169,8 @@ namespace ts {
|
||||
method.questionToken = questionToken;
|
||||
|
||||
// Method signatues don't exist in expression contexts. So they have neither
|
||||
// [Yield] nor [GeneratorParameter]
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ false, /*requireCompleteParameterList*/ false, method);
|
||||
// [Yield] nor [Await]
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, method);
|
||||
parseTypeMemberSemicolon();
|
||||
return finishNode(method);
|
||||
}
|
||||
@ -2360,7 +2309,7 @@ namespace ts {
|
||||
if (kind === SyntaxKind.ConstructorType) {
|
||||
parseExpected(SyntaxKind.NewKeyword);
|
||||
}
|
||||
fillSignature(SyntaxKind.EqualsGreaterThanToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ false, /*requireCompleteParameterList*/ false, node);
|
||||
fillSignature(SyntaxKind.EqualsGreaterThanToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
@ -2912,7 +2861,7 @@ namespace ts {
|
||||
// a => (b => c)
|
||||
// And think that "(b =>" was actually a parenthesized arrow function with a missing
|
||||
// close paren.
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ isAsync, /*requireCompleteParameterList*/ !allowAmbiguity, node);
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ !allowAmbiguity, node);
|
||||
|
||||
// If we couldn't get parameters, we definitely could not parse out an arrow function.
|
||||
if (!node.parameters) {
|
||||
@ -3566,11 +3515,12 @@ namespace ts {
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
// GeneratorExpression :
|
||||
function parseFunctionExpression(): FunctionExpression {
|
||||
// function * BindingIdentifier[Yield]opt (FormalParameters[Yield, GeneratorParameter]) { GeneratorBody[Yield] }
|
||||
// GeneratorExpression:
|
||||
// function* BindingIdentifier [Yield][opt](FormalParameters[Yield]){ GeneratorBody }
|
||||
//
|
||||
// FunctionExpression:
|
||||
// function BindingIdentifieropt(FormalParameters) { FunctionBody }
|
||||
// function BindingIdentifier[opt](FormalParameters){ FunctionBody }
|
||||
let saveDecoratorContext = inDecoratorContext();
|
||||
if (saveDecoratorContext) {
|
||||
setDecoratorContext(false);
|
||||
@ -3589,7 +3539,7 @@ namespace ts {
|
||||
isAsync ? doInAwaitContext(parseOptionalIdentifier) :
|
||||
parseOptionalIdentifier();
|
||||
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ isGenerator, /*awaitAndAsyncParameterContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
|
||||
node.body = parseFunctionBlock(/*allowYield*/ isGenerator, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false);
|
||||
|
||||
if (saveDecoratorContext) {
|
||||
@ -4303,7 +4253,7 @@ namespace ts {
|
||||
node.name = node.flags & NodeFlags.Default ? parseOptionalIdentifier() : parseIdentifier();
|
||||
let isGenerator = !!node.asteriskToken;
|
||||
let isAsync = isAsyncFunctionLike(node);
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ isGenerator, /*awaitAndAsyncParameterContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
|
||||
node.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, Diagnostics.or_expected);
|
||||
return finishNode(node);
|
||||
}
|
||||
@ -4313,7 +4263,7 @@ namespace ts {
|
||||
node.decorators = decorators;
|
||||
setModifiers(node, modifiers);
|
||||
parseExpected(SyntaxKind.ConstructorKeyword);
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ false, /*requireCompleteParameterList*/ false, node);
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
|
||||
node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false, Diagnostics.or_expected);
|
||||
return finishNode(node);
|
||||
}
|
||||
@ -4327,7 +4277,7 @@ namespace ts {
|
||||
method.questionToken = questionToken;
|
||||
let isGenerator = !!asteriskToken;
|
||||
let isAsync = isAsyncFunctionLike(method);
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ isGenerator, /*awaitAndAsyncParameterContext*/ isAsync, /*requireCompleteParameterList*/ false, method);
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, method);
|
||||
method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage);
|
||||
return finishNode(method);
|
||||
}
|
||||
@ -4381,7 +4331,7 @@ namespace ts {
|
||||
node.decorators = decorators;
|
||||
setModifiers(node, modifiers);
|
||||
node.name = parsePropertyName();
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ false, /*requireCompleteParameterList*/ false, node);
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
|
||||
node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
@ -376,18 +376,12 @@ namespace ts {
|
||||
// If this node was parsed in the 'yield' context created when parsing a generator.
|
||||
Yield = 1 << 2,
|
||||
|
||||
// If this node was parsed in the parameters of a generator.
|
||||
GeneratorParameter = 1 << 3,
|
||||
|
||||
// If this node was parsed as part of a decorator
|
||||
Decorator = 1 << 4,
|
||||
|
||||
// If this node was parsed in the 'await' context created when parsing an async function.
|
||||
Await = 1 << 5,
|
||||
|
||||
// If this node was parsed in the parameters of an async function.
|
||||
AsyncParameter = 1 << 6,
|
||||
|
||||
// If the parser encountered an error when parsing the code that created this node. Note
|
||||
// the parser only sets this directly on the node it creates right after encountering the
|
||||
// error.
|
||||
@ -398,14 +392,10 @@ namespace ts {
|
||||
JavaScriptFile = 1 << 8,
|
||||
|
||||
// Context flags set directly by the parser.
|
||||
ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | Decorator | ThisNodeHasError | Await | AsyncParameter,
|
||||
|
||||
// Context flags passed as part of the modified ES6 grammar.
|
||||
YieldAndGeneratorParameterFlags = Yield | GeneratorParameter,
|
||||
AwaitAndAsyncParameterFlags = Await | AsyncParameter,
|
||||
ParserGeneratedFlags = StrictMode | DisallowIn | Yield | Decorator | ThisNodeHasError | Await,
|
||||
|
||||
// Exclude these flags when parsing a Type
|
||||
TypeExcludesFlags = YieldAndGeneratorParameterFlags | AwaitAndAsyncParameterFlags,
|
||||
TypeExcludesFlags = Yield | Await,
|
||||
|
||||
// Context flags computed by aggregating child flags upwards.
|
||||
|
||||
|
||||
@ -1,8 +1,20 @@
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,10): error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,26): error TS1005: ',' expected.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,29): error TS1138: Parameter declaration expected.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,29): error TS2304: Cannot find name 'yield'.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,34): error TS1005: ';' expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (5 errors) ====
|
||||
function * foo(a = yield => yield) {
|
||||
~
|
||||
!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
|
||||
~~~~~~~~~
|
||||
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
|
||||
~~
|
||||
!!! error TS1005: ',' expected.
|
||||
~~~~~
|
||||
!!! error TS1138: Parameter declaration expected.
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'yield'.
|
||||
~
|
||||
!!! error TS1005: ';' expected.
|
||||
}
|
||||
@ -3,6 +3,6 @@ function * foo(a = yield => yield) {
|
||||
}
|
||||
|
||||
//// [FunctionDeclaration10_es6.js]
|
||||
function foo(a) {
|
||||
if (a === void 0) { a = function (yield) { return yield; }; }
|
||||
yield;
|
||||
{
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,18): error TS2304: Cannot find name 'yield'.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,18): error TS2523: 'yield' expressions cannot be used in a parameter initializer.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts (2 errors) ====
|
||||
@ -7,5 +7,5 @@ tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,1
|
||||
~
|
||||
!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'yield'.
|
||||
!!! error TS2523: 'yield' expressions cannot be used in a parameter initializer.
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,11): error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,20): error TS2304: Cannot find name 'yield'.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,20): error TS2523: 'yield' expressions cannot be used in a parameter initializer.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts (3 errors) ====
|
||||
@ -12,6 +12,6 @@ tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,2
|
||||
~
|
||||
!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'yield'.
|
||||
!!! error TS2523: 'yield' expressions cannot be used in a parameter initializer.
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,12 @@
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction6_es6.ts(2,22): error TS2304: Cannot find name 'await'.
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction6_es6.ts(2,22): error TS2524: 'await' expressions cannot be used in a parameter initializer.
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction6_es6.ts(2,27): error TS1109: Expression expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction6_es6.ts (1 errors) ====
|
||||
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction6_es6.ts (2 errors) ====
|
||||
|
||||
var foo = async (a = await): Promise<void> => {
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'await'.
|
||||
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
|
||||
~
|
||||
!!! error TS1109: Expression expected.
|
||||
}
|
||||
@ -4,6 +4,6 @@ var foo = async (a = await): Promise<void> => {
|
||||
}
|
||||
|
||||
//// [asyncArrowFunction6_es6.js]
|
||||
var foo = (a = await) => __awaiter(function* () {
|
||||
var foo = (a = yield ) => __awaiter(function* () {
|
||||
},
|
||||
this, void 0, Promise);
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction7_es6.ts(4,24): error TS2304: Cannot find name 'await'.
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction7_es6.ts(4,24): error TS2524: 'await' expressions cannot be used in a parameter initializer.
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction7_es6.ts(4,29): error TS1109: Expression expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction7_es6.ts (1 errors) ====
|
||||
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction7_es6.ts (2 errors) ====
|
||||
|
||||
var bar = async (): Promise<void> => {
|
||||
// 'await' here is an identifier, and not an await expression.
|
||||
var foo = async (a = await): Promise<void> => {
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'await'.
|
||||
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
|
||||
~
|
||||
!!! error TS1109: Expression expected.
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,7 @@ var bar = async (): Promise<void> => {
|
||||
//// [asyncArrowFunction7_es6.js]
|
||||
var bar = () => __awaiter(function* () {
|
||||
// 'await' here is an identifier, and not an await expression.
|
||||
var foo = (a = await) => __awaiter(function* () {
|
||||
var foo = (a = yield ) => __awaiter(function* () {
|
||||
},
|
||||
this, void 0, Promise);
|
||||
},
|
||||
|
||||
23
tests/baselines/reference/asyncArrowFunction9_es6.errors.txt
Normal file
23
tests/baselines/reference/asyncArrowFunction9_es6.errors.txt
Normal file
@ -0,0 +1,23 @@
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,11): error TS2304: Cannot find name 'async'.
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,18): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,37): error TS1005: ',' expected.
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,39): error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'.
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,46): error TS1005: '=' expected.
|
||||
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,53): error TS1109: Expression expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts (6 errors) ====
|
||||
var foo = async (a = await => await): Promise<void> => {
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'async'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
~
|
||||
!!! error TS1005: ',' expected.
|
||||
~~~~~~~
|
||||
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'.
|
||||
~
|
||||
!!! error TS1005: '=' expected.
|
||||
~~
|
||||
!!! error TS1109: Expression expected.
|
||||
}
|
||||
@ -3,6 +3,6 @@ var foo = async (a = await => await): Promise<void> => {
|
||||
}
|
||||
|
||||
//// [asyncArrowFunction9_es6.js]
|
||||
var foo = (a = await => await) => __awaiter(function* () {
|
||||
},
|
||||
this, void 0, Promise);
|
||||
var foo = async(a = await => await), Promise = ;
|
||||
{
|
||||
}
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
=== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts ===
|
||||
var foo = async (a = await => await): Promise<void> => {
|
||||
>foo : Symbol(foo, Decl(asyncArrowFunction9_es6.ts, 0, 3))
|
||||
>a : Symbol(a, Decl(asyncArrowFunction9_es6.ts, 0, 17))
|
||||
>await : Symbol(await, Decl(asyncArrowFunction9_es6.ts, 0, 20))
|
||||
>await : Symbol(await, Decl(asyncArrowFunction9_es6.ts, 0, 20))
|
||||
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
=== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts ===
|
||||
var foo = async (a = await => await): Promise<void> => {
|
||||
>foo : (a?: (await: any) => any) => Promise<void>
|
||||
>async (a = await => await): Promise<void> => {} : (a?: (await: any) => any) => Promise<void>
|
||||
>a : (await: any) => any
|
||||
>await => await : (await: any) => any
|
||||
>await : any
|
||||
>await : any
|
||||
>Promise : Promise<T>
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,20): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,30): error TS1109: Expression expected.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,33): error TS1138: Parameter declaration expected.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,33): error TS2304: Cannot find name 'await'.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,38): error TS1005: ';' expected.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,39): error TS1128: Declaration or statement expected.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,53): error TS1109: Expression expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts (7 errors) ====
|
||||
async function foo(a = await => await): Promise<void> {
|
||||
~~~~~~~~~
|
||||
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
|
||||
~~
|
||||
!!! error TS1109: Expression expected.
|
||||
~~~~~
|
||||
!!! error TS1138: Parameter declaration expected.
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'await'.
|
||||
~
|
||||
!!! error TS1005: ';' expected.
|
||||
~
|
||||
!!! error TS1128: Declaration or statement expected.
|
||||
~
|
||||
!!! error TS1109: Expression expected.
|
||||
}
|
||||
@ -3,8 +3,5 @@ async function foo(a = await => await): Promise<void> {
|
||||
}
|
||||
|
||||
//// [asyncFunctionDeclaration10_es6.js]
|
||||
function foo(a = await => await) {
|
||||
return __awaiter(function* () {
|
||||
},
|
||||
this, void 0, Promise);
|
||||
}
|
||||
await;
|
||||
Promise < void > {};
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
=== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts ===
|
||||
async function foo(a = await => await): Promise<void> {
|
||||
>foo : Symbol(foo, Decl(asyncFunctionDeclaration10_es6.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(asyncFunctionDeclaration10_es6.ts, 0, 19))
|
||||
>await : Symbol(await, Decl(asyncFunctionDeclaration10_es6.ts, 0, 22))
|
||||
>await : Symbol(await, Decl(asyncFunctionDeclaration10_es6.ts, 0, 22))
|
||||
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
=== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts ===
|
||||
async function foo(a = await => await): Promise<void> {
|
||||
>foo : (a?: (await: any) => any) => Promise<void>
|
||||
>a : (await: any) => any
|
||||
>await => await : (await: any) => any
|
||||
>await : any
|
||||
>await : any
|
||||
>Promise : Promise<T>
|
||||
}
|
||||
@ -1,8 +1,11 @@
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration6_es6.ts(1,24): error TS2304: Cannot find name 'await'.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration6_es6.ts(1,24): error TS2524: 'await' expressions cannot be used in a parameter initializer.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration6_es6.ts(1,29): error TS1109: Expression expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration6_es6.ts (1 errors) ====
|
||||
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration6_es6.ts (2 errors) ====
|
||||
async function foo(a = await): Promise<void> {
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'await'.
|
||||
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
|
||||
~
|
||||
!!! error TS1109: Expression expected.
|
||||
}
|
||||
@ -3,7 +3,7 @@ async function foo(a = await): Promise<void> {
|
||||
}
|
||||
|
||||
//// [asyncFunctionDeclaration6_es6.js]
|
||||
function foo(a = await) {
|
||||
function foo(a = yield ) {
|
||||
return __awaiter(function* () {
|
||||
},
|
||||
this, void 0, Promise);
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration7_es6.ts(3,26): error TS2304: Cannot find name 'await'.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration7_es6.ts(3,26): error TS2524: 'await' expressions cannot be used in a parameter initializer.
|
||||
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration7_es6.ts(3,31): error TS1109: Expression expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration7_es6.ts (1 errors) ====
|
||||
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration7_es6.ts (2 errors) ====
|
||||
async function bar(): Promise<void> {
|
||||
// 'await' here is an identifier, and not a yield expression.
|
||||
async function foo(a = await): Promise<void> {
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'await'.
|
||||
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
|
||||
~
|
||||
!!! error TS1109: Expression expected.
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,7 @@ async function bar(): Promise<void> {
|
||||
function bar() {
|
||||
return __awaiter(function* () {
|
||||
// 'await' here is an identifier, and not a yield expression.
|
||||
function foo(a = await) {
|
||||
function foo(a = yield ) {
|
||||
return __awaiter(function* () {
|
||||
},
|
||||
this, void 0, Promise);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user