@@ -149,6 +149,7 @@ namespace ts {
149
149
let getGlobalESSymbolConstructorSymbol: () => Symbol;
150
150
151
151
let getGlobalPromiseConstructorSymbol: () => Symbol;
152
+ let tryGetGlobalPromiseConstructorSymbol: () => Symbol;
152
153
153
154
let globalObjectType: ObjectType;
154
155
let globalFunctionType: ObjectType;
@@ -8337,10 +8338,13 @@ namespace ts {
8337
8338
// can explicitly bound arguments objects
8338
8339
if (symbol === argumentsSymbol) {
8339
8340
const container = getContainingFunction(node);
8340
- if (container.kind === SyntaxKind.ArrowFunction ) {
8341
- if (languageVersion < ScriptTarget.ES6 ) {
8341
+ if (languageVersion < ScriptTarget.ES6 ) {
8342
+ if (container.kind === SyntaxKind.ArrowFunction ) {
8342
8343
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
8343
8344
}
8345
+ else if (hasModifier(container, ModifierFlags.Async)) {
8346
+ error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_async_function_or_method_in_ES3_and_ES5_Consider_using_a_standard_function_or_method);
8347
+ }
8344
8348
}
8345
8349
8346
8350
if (node.flags & NodeFlags.AwaitContext) {
@@ -12991,7 +12995,7 @@ namespace ts {
12991
12995
return type;
12992
12996
}
12993
12997
12994
- function checkNumericLiteral(node: LiteralExpression ): Type {
12998
+ function checkNumericLiteral(node: NumericLiteral ): Type {
12995
12999
// Grammar checking
12996
13000
checkGrammarNumericLiteral(node);
12997
13001
return numberType;
@@ -13011,7 +13015,7 @@ namespace ts {
13011
13015
case SyntaxKind.FalseKeyword:
13012
13016
return booleanType;
13013
13017
case SyntaxKind.NumericLiteral:
13014
- return checkNumericLiteral(<LiteralExpression >node);
13018
+ return checkNumericLiteral(<NumericLiteral >node);
13015
13019
case SyntaxKind.TemplateExpression:
13016
13020
return checkTemplateExpression(<TemplateExpression>node);
13017
13021
case SyntaxKind.StringLiteral:
@@ -14194,7 +14198,7 @@ namespace ts {
14194
14198
* @param returnType The return type of a FunctionLikeDeclaration
14195
14199
* @param location The node on which to report the error.
14196
14200
*/
14197
- function checkCorrectPromiseType(returnType: Type, location: Node) {
14201
+ function checkCorrectPromiseType(returnType: Type, location: Node, diagnostic: DiagnosticMessage, typeName?: string ) {
14198
14202
if (returnType === unknownType) {
14199
14203
// The return type already had some other error, so we ignore and return
14200
14204
// the unknown type.
@@ -14213,7 +14217,7 @@ namespace ts {
14213
14217
14214
14218
// The promise type was not a valid type reference to the global promise type, so we
14215
14219
// report an error and return the unknown type.
14216
- error(location, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type );
14220
+ error(location, diagnostic, typeName );
14217
14221
return unknownType;
14218
14222
}
14219
14223
@@ -14233,7 +14237,7 @@ namespace ts {
14233
14237
function checkAsyncFunctionReturnType(node: FunctionLikeDeclaration): Type {
14234
14238
if (languageVersion >= ScriptTarget.ES6) {
14235
14239
const returnType = getTypeFromTypeNode(node.type);
14236
- return checkCorrectPromiseType(returnType, node.type);
14240
+ return checkCorrectPromiseType(returnType, node.type, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type );
14237
14241
}
14238
14242
14239
14243
const globalPromiseConstructorLikeType = getGlobalPromiseConstructorLikeType();
@@ -14279,19 +14283,19 @@ namespace ts {
14279
14283
14280
14284
const promiseConstructor = getNodeLinks(node.type).resolvedSymbol;
14281
14285
if (!promiseConstructor || !symbolIsValue(promiseConstructor)) {
14286
+ // try to fall back to global promise type.
14282
14287
const typeName = promiseConstructor
14283
14288
? symbolToString(promiseConstructor)
14284
14289
: typeToString(promiseType);
14285
- error(node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeName);
14286
- return unknownType;
14290
+ return checkCorrectPromiseType(promiseType, node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeName);
14287
14291
}
14288
14292
14289
14293
// If the Promise constructor, resolved locally, is an alias symbol we should mark it as referenced.
14290
14294
checkReturnTypeAnnotationAsExpression(node);
14291
14295
14292
14296
// Validate the promise constructor type.
14293
14297
const promiseConstructorType = getTypeOfSymbol(promiseConstructor);
14294
- if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) {
14298
+ if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node.type , Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) {
14295
14299
return unknownType;
14296
14300
}
14297
14301
@@ -16272,7 +16276,7 @@ namespace ts {
16272
16276
}
16273
16277
return undefined;
16274
16278
case SyntaxKind.NumericLiteral:
16275
- return +(<LiteralExpression >e).text;
16279
+ return +(<NumericLiteral >e).text;
16276
16280
case SyntaxKind.ParenthesizedExpression:
16277
16281
return evalConstant((<ParenthesizedExpression>e).expression);
16278
16282
case SyntaxKind.Identifier:
@@ -17491,7 +17495,7 @@ namespace ts {
17491
17495
if (objectType === unknownType) return undefined;
17492
17496
const apparentType = getApparentType(objectType);
17493
17497
if (apparentType === unknownType) return undefined;
17494
- return getPropertyOfType(apparentType, (<LiteralExpression >node).text);
17498
+ return getPropertyOfType(apparentType, (<NumericLiteral >node).text);
17495
17499
}
17496
17500
break;
17497
17501
}
@@ -17976,6 +17980,11 @@ namespace ts {
17976
17980
function getTypeReferenceSerializationKind(typeName: EntityName, location?: Node): TypeReferenceSerializationKind {
17977
17981
// Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
17978
17982
const valueSymbol = resolveEntityName(typeName, SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
17983
+ const globalPromiseSymbol = tryGetGlobalPromiseConstructorSymbol();
17984
+ if (globalPromiseSymbol && valueSymbol === globalPromiseSymbol) {
17985
+ return TypeReferenceSerializationKind.Promise;
17986
+ }
17987
+
17979
17988
const constructorType = valueSymbol ? getTypeOfSymbol(valueSymbol) : undefined;
17980
17989
if (constructorType && isConstructorType(constructorType)) {
17981
17990
return TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
@@ -17994,8 +18003,8 @@ namespace ts {
17994
18003
else if (type.flags & TypeFlags.Any) {
17995
18004
return TypeReferenceSerializationKind.ObjectType;
17996
18005
}
17997
- else if (isTypeOfKind(type, TypeFlags.Void)) {
17998
- return TypeReferenceSerializationKind.VoidType ;
18006
+ else if (isTypeOfKind(type, TypeFlags.Void | TypeFlags.Nullable | TypeFlags.Never )) {
18007
+ return TypeReferenceSerializationKind.VoidNullableOrNeverType ;
17999
18008
}
18000
18009
else if (isTypeOfKind(type, TypeFlags.Boolean)) {
18001
18010
return TypeReferenceSerializationKind.BooleanType;
@@ -18293,6 +18302,7 @@ namespace ts {
18293
18302
getGlobalPromiseLikeType = memoize(() => getGlobalType("PromiseLike", /*arity*/ 1));
18294
18303
getInstantiatedGlobalPromiseLikeType = memoize(createInstantiatedPromiseLikeType);
18295
18304
getGlobalPromiseConstructorSymbol = memoize(() => getGlobalValueSymbol("Promise"));
18305
+ tryGetGlobalPromiseConstructorSymbol = memoize(() => getGlobalSymbol("Promise", SymbolFlags.Value, /*diagnostic*/ undefined) && getGlobalPromiseConstructorSymbol());
18296
18306
getGlobalPromiseConstructorLikeType = memoize(() => getGlobalType("PromiseConstructorLike"));
18297
18307
getGlobalThenableType = memoize(createThenableType);
18298
18308
@@ -18348,6 +18358,9 @@ namespace ts {
18348
18358
}
18349
18359
if (requestedExternalEmitHelpers & NodeFlags.HasAsyncFunctions) {
18350
18360
verifyHelperSymbol(exports, "__awaiter", SymbolFlags.Value);
18361
+ if (languageVersion < ScriptTarget.ES6) {
18362
+ verifyHelperSymbol(exports, "__generator", SymbolFlags.Value);
18363
+ }
18351
18364
}
18352
18365
}
18353
18366
}
@@ -18654,10 +18667,6 @@ namespace ts {
18654
18667
}
18655
18668
18656
18669
function checkGrammarAsyncModifier(node: Node, asyncModifier: Node): boolean {
18657
- if (languageVersion < ScriptTarget.ES6) {
18658
- return grammarErrorOnNode(asyncModifier, Diagnostics.Async_functions_are_only_available_when_targeting_ECMAScript_2015_or_higher);
18659
- }
18660
-
18661
18670
switch (node.kind) {
18662
18671
case SyntaxKind.MethodDeclaration:
18663
18672
case SyntaxKind.FunctionDeclaration:
@@ -18967,7 +18976,7 @@ namespace ts {
18967
18976
// Grammar checking for computedPropertyName and shorthandPropertyAssignment
18968
18977
checkGrammarForInvalidQuestionMark(prop, (<PropertyAssignment>prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
18969
18978
if (name.kind === SyntaxKind.NumericLiteral) {
18970
- checkGrammarNumericLiteral(<LiteralExpression >name);
18979
+ checkGrammarNumericLiteral(<NumericLiteral >name);
18971
18980
}
18972
18981
currentKind = Property;
18973
18982
}
@@ -19489,7 +19498,7 @@ namespace ts {
19489
19498
}
19490
19499
}
19491
19500
19492
- function checkGrammarNumericLiteral(node: LiteralExpression ): boolean {
19501
+ function checkGrammarNumericLiteral(node: NumericLiteral ): boolean {
19493
19502
// Grammar checking
19494
19503
if (node.isOctalLiteral && languageVersion >= ScriptTarget.ES5) {
19495
19504
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
0 commit comments