@@ -102,7 +102,7 @@ module ts {
102
102
let globalArraySymbol: Symbol;
103
103
let globalESSymbolConstructorSymbol: Symbol;
104
104
105
- let getGlobalPromiseSymbol : () => Symbol;
105
+ let getGlobalPromiseConstructorSymbol : () => Symbol;
106
106
107
107
let globalObjectType: ObjectType;
108
108
let globalFunctionType: ObjectType;
@@ -139,7 +139,6 @@ module ts {
139
139
let symbolLinks: SymbolLinks[] = [];
140
140
let nodeLinks: NodeLinks[] = [];
141
141
let potentialThisCollisions: Node[] = [];
142
- var potentialArgumentsCollisions: Node[] = [];
143
142
144
143
let diagnostics = createDiagnosticCollection();
145
144
@@ -5420,11 +5419,13 @@ module ts {
5420
5419
// can explicitly bound arguments objects
5421
5420
let container = getContainingFunction(node);
5422
5421
if (symbol === argumentsSymbol) {
5423
- if (container.kind === SyntaxKind.ArrowFunction && languageVersion < ScriptTarget.ES6) {
5424
- error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
5425
- }
5426
- else if (node.parserContextFlags & ParserContextFlags.Await) {
5427
- captureLexicalArguments(node, container);
5422
+ if (container.kind === SyntaxKind.ArrowFunction) {
5423
+ if (languageVersion < ScriptTarget.ES6) {
5424
+ error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
5425
+ }
5426
+ else if (node.parserContextFlags & ParserContextFlags.Await) {
5427
+ error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression);
5428
+ }
5428
5429
}
5429
5430
}
5430
5431
@@ -5434,7 +5435,6 @@ module ts {
5434
5435
5435
5436
checkCollisionWithCapturedSuperVariable(node, node);
5436
5437
checkCollisionWithCapturedThisVariable(node, node);
5437
- checkCollisionWithCapturedArgumentsVariable(node, node);
5438
5438
checkBlockScopedBindingCapturedInLoop(node, symbol);
5439
5439
5440
5440
return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node);
@@ -5516,10 +5516,9 @@ module ts {
5516
5516
// When targeting es6, arrow function lexically bind "this" so we do not need to do the work of binding "this" in emitted code
5517
5517
needToCaptureLexicalThis = (languageVersion < ScriptTarget.ES6);
5518
5518
}
5519
-
5520
- if (node.parserContextFlags & ParserContextFlags.Await) {
5519
+ else if (node.parserContextFlags & ParserContextFlags.Await) {
5521
5520
// if 'this' is part of an async function, we will need to capture 'this'
5522
- needToCaptureLexicalThis = true ;
5521
+ needToCaptureLexicalThis = (languageVersion < ScriptTarget.ES6) ;
5523
5522
}
5524
5523
5525
5524
switch (container.kind) {
@@ -5561,14 +5560,6 @@ module ts {
5561
5560
return anyType;
5562
5561
}
5563
5562
5564
- function captureLexicalArguments(node: Node, container: Node): void {
5565
- if (node.parent.kind !== SyntaxKind.Parameter) {
5566
- getNodeLinks(node).flags |= NodeCheckFlags.LexicalArguments;
5567
- }
5568
-
5569
- getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments;
5570
- }
5571
-
5572
5563
function isInConstructorArgumentInitializer(node: Node, constructorDecl: Node): boolean {
5573
5564
for (let n = node; n && n !== constructorDecl; n = n.parent) {
5574
5565
if (n.kind === SyntaxKind.Parameter) {
@@ -7303,7 +7294,7 @@ module ts {
7303
7294
let widenedType = getWidenedType(type);
7304
7295
return isAsync
7305
7296
? createPromiseType(widenedType, func)
7306
- : type ;
7297
+ : widenedType ;
7307
7298
}
7308
7299
7309
7300
/// Returns a set of types relating to every return expression relating to a function block.
@@ -7421,7 +7412,6 @@ module ts {
7421
7412
if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) {
7422
7413
checkCollisionWithCapturedSuperVariable(node, (<FunctionExpression>node).name);
7423
7414
checkCollisionWithCapturedThisVariable(node, (<FunctionExpression>node).name);
7424
- checkCollisionWithCapturedArgumentsVariable(node, (<FunctionExpression>node).name);
7425
7415
}
7426
7416
7427
7417
return type;
@@ -7574,13 +7564,7 @@ module ts {
7574
7564
function checkAwaitExpression(node: AwaitExpression): Type {
7575
7565
// Grammar checking
7576
7566
if (!(node.parserContextFlags & ParserContextFlags.Await)) {
7577
- var parameter = getContainingParameter(node);
7578
- if (parameter && parameter.parserContextFlags & ParserContextFlags.Await) {
7579
- grammarErrorAfterFirstToken(node, Diagnostics._0_expression_is_not_allowed_in_an_initializer, "await");
7580
- }
7581
- else {
7582
- grammarErrorOnFirstToken(node, Diagnostics.await_expression_must_be_contained_within_an_async_function);
7583
- }
7567
+ grammarErrorOnFirstToken(node, Diagnostics.await_expression_must_be_contained_within_an_async_function);
7584
7568
}
7585
7569
7586
7570
var operandType = checkExpression(node.expression);
@@ -7994,13 +7978,7 @@ module ts {
7994
7978
function checkYieldExpression(node: YieldExpression): void {
7995
7979
// Grammar checking
7996
7980
if (!(node.parserContextFlags & ParserContextFlags.Yield)) {
7997
- let parameter = getContainingParameter(node);
7998
- if (parameter && (parameter.parserContextFlags & ParserContextFlags.GeneratorParameter)) {
7999
- grammarErrorAfterFirstToken(node, Diagnostics._0_expression_is_not_allowed_in_an_initializer, "yield");
8000
- }
8001
- else {
8002
- grammarErrorOnFirstToken(node, Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration);
8003
- }
7981
+ grammarErrorOnFirstToken(node, Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration);
8004
7982
}
8005
7983
else {
8006
7984
grammarErrorOnFirstToken(node, Diagnostics.yield_expressions_are_not_currently_supported);
@@ -8907,23 +8885,25 @@ module ts {
8907
8885
// the "promised type" of a type is the type of the "value" argument of the "onfulfilled" callback.
8908
8886
let globalPromiseLikeType = getInstantiatedGlobalPromiseLikeType();
8909
8887
if (globalPromiseLikeType !== emptyObjectType && isTypeAssignableTo(type, globalPromiseLikeType)) {
8910
- let awaitedTypes: Type[] = [];
8911
8888
let thenProp = getPropertyOfType(type, "then");
8912
- let thenType = getTypeOfSymbol(thenProp);
8913
- let thenSignatures = getSignaturesOfType(thenType, SignatureKind.Call);
8914
- for (let thenSignature of thenSignatures) {
8915
- thenSignature = getErasedSignature(thenSignature);
8916
- let onfulfilledParameterType = getTypeAtPosition(thenSignature, 0);
8917
- let onfulfilledParameterSignatures = getSignaturesOfType(onfulfilledParameterType, SignatureKind.Call);
8918
- for (let onfulfilledParameterSignature of onfulfilledParameterSignatures) {
8919
- let valueParameterType = getTypeAtPosition(onfulfilledParameterSignature, 0);
8920
- if (valueParameterType !== type) {
8921
- awaitedTypes.push(valueParameterType);
8889
+ if (thenProp) {
8890
+ let awaitedTypes: Type[] = [];
8891
+ let thenType = getTypeOfSymbol(thenProp);
8892
+ let thenSignatures = getSignaturesOfType(thenType, SignatureKind.Call);
8893
+ for (let thenSignature of thenSignatures) {
8894
+ thenSignature = getErasedSignature(thenSignature);
8895
+ let onfulfilledParameterType = getTypeAtPosition(thenSignature, 0);
8896
+ let onfulfilledParameterSignatures = getSignaturesOfType(onfulfilledParameterType, SignatureKind.Call);
8897
+ for (let onfulfilledParameterSignature of onfulfilledParameterSignatures) {
8898
+ let valueParameterType = getTypeAtPosition(onfulfilledParameterSignature, 0);
8899
+ if (valueParameterType !== type) {
8900
+ awaitedTypes.push(valueParameterType);
8901
+ }
8922
8902
}
8923
8903
}
8924
- }
8925
-
8926
- return getUnionType(awaitedTypes);
8904
+
8905
+ return getUnionType(awaitedTypes);
8906
+ }
8927
8907
}
8928
8908
8929
8909
return emptyObjectType;
@@ -9142,7 +9122,6 @@ module ts {
9142
9122
9143
9123
checkCollisionWithCapturedSuperVariable(node, node.name);
9144
9124
checkCollisionWithCapturedThisVariable(node, node.name);
9145
- checkCollisionWithCapturedArgumentsVariable(node, node.name);
9146
9125
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
9147
9126
}
9148
9127
}
@@ -9262,12 +9241,6 @@ module ts {
9262
9241
}
9263
9242
}
9264
9243
9265
- function checkCollisionWithCapturedArgumentsVariable(node: Node, name: Identifier): void {
9266
- if (needCollisionCheckForIdentifier(node, name, "_arguments")) {
9267
- potentialArgumentsCollisions.push(node);
9268
- }
9269
- }
9270
-
9271
9244
// this function will run after checking the source file so 'CaptureThis' is correct for all nodes
9272
9245
function checkIfThisIsCapturedInEnclosingScope(node: Node): void {
9273
9246
let current = node;
@@ -9286,25 +9259,6 @@ module ts {
9286
9259
}
9287
9260
}
9288
9261
9289
- function checkIfArgumentsIsCapturedInEnclosingScope(node: Node): void {
9290
- let current = node;
9291
- while (current) {
9292
- if (getNodeCheckFlags(current) & NodeCheckFlags.CaptureArguments) {
9293
- let isDeclaration = node.kind !== SyntaxKind.Identifier;
9294
- if (isDeclaration) {
9295
- error((<Declaration>node).name, Diagnostics.Duplicate_identifier_arguments_Compiler_uses_variable_declaration_arguments_to_capture_arguments_reference);
9296
- }
9297
- else {
9298
- error(node, Diagnostics.Expression_resolves_to_variable_declaration_arguments_that_compiler_uses_to_capture_arguments_reference);
9299
- }
9300
-
9301
- return;
9302
- }
9303
-
9304
- current = current.parent;
9305
- }
9306
- }
9307
-
9308
9262
function checkCollisionWithCapturedSuperVariable(node: Node, name: Identifier) {
9309
9263
if (!needCollisionCheckForIdentifier(node, name, "_super")) {
9310
9264
return;
@@ -9421,15 +9375,17 @@ module ts {
9421
9375
}
9422
9376
9423
9377
function getPromiseConstructor(node: SignatureDeclaration): EntityName {
9424
- if (node.type && node.type.kind === SyntaxKind.TypeReference) {
9425
- return (<TypeReferenceNode>node.type).typeName;
9426
- }
9427
-
9428
- let globalPromiseSymbol = getGlobalPromiseSymbol();
9429
- if (globalPromiseSymbol && globalPromiseSymbol === resolveName(node, "Promise", SymbolFlags.Value, undefined, undefined)) {
9430
- return <Identifier>globalPromiseSymbol.valueDeclaration.name;
9378
+ if (isAsyncFunctionLike(node)) {
9379
+ let links = getNodeLinks(node);
9380
+ if (!links.promiseConstructor) {
9381
+ if (node.type && node.type.kind === SyntaxKind.TypeReference) {
9382
+ links.promiseConstructor = (<TypeReferenceNode>node.type).typeName;
9383
+ }
9384
+ }
9385
+
9386
+ return links.promiseConstructor;
9431
9387
}
9432
-
9388
+
9433
9389
return undefined;
9434
9390
}
9435
9391
@@ -9550,14 +9506,8 @@ module ts {
9550
9506
}
9551
9507
checkCollisionWithCapturedSuperVariable(node, <Identifier>node.name);
9552
9508
checkCollisionWithCapturedThisVariable(node, <Identifier>node.name);
9553
- checkCollisionWithCapturedArgumentsVariable(node, <Identifier>node.name);
9554
9509
checkCollisionWithRequireExportsInGeneratedCode(node, <Identifier>node.name);
9555
9510
}
9556
-
9557
- if (symbol === argumentsSymbol && (node.parserContextFlags & ParserContextFlags.Await)) {
9558
- let container = getContainingFunction(node);
9559
- captureLexicalArguments(node.name, container);
9560
- }
9561
9511
}
9562
9512
9563
9513
function checkVariableDeclaration(node: VariableDeclaration) {
@@ -11258,7 +11208,6 @@ module ts {
11258
11208
emitDecorate = false;
11259
11209
emitParam = false;
11260
11210
potentialThisCollisions.length = 0;
11261
- potentialArgumentsCollisions.length = 0;
11262
11211
11263
11212
forEach(node.statements, checkSourceElement);
11264
11213
checkFunctionExpressionBodies(node);
@@ -11272,11 +11221,6 @@ module ts {
11272
11221
potentialThisCollisions.length = 0;
11273
11222
}
11274
11223
11275
- if (potentialArgumentsCollisions.length) {
11276
- forEach(potentialArgumentsCollisions, checkIfArgumentsIsCapturedInEnclosingScope);
11277
- potentialArgumentsCollisions.length = 0;
11278
- }
11279
-
11280
11224
if (emitExtends) {
11281
11225
links.flags |= NodeCheckFlags.EmitExtends;
11282
11226
}
@@ -12279,6 +12223,7 @@ module ts {
12279
12223
serializeTypeOfNode,
12280
12224
serializeParameterTypesOfNode,
12281
12225
serializeReturnTypeOfNode,
12226
+ getPromiseConstructor,
12282
12227
};
12283
12228
}
12284
12229
@@ -12313,10 +12258,10 @@ module ts {
12313
12258
getGlobalPropertyDecoratorType = memoize(() => getGlobalType("PropertyDecorator"));
12314
12259
getGlobalMethodDecoratorType = memoize(() => getGlobalType("MethodDecorator"));
12315
12260
getGlobalParameterDecoratorType = memoize(() => getGlobalType("ParameterDecorator"));
12316
- getGlobalPromiseSymbol = memoize(() => getGlobalTypeSymbol("Promise"));
12317
- getGlobalPromiseType = memoize(() => getTypeOfGlobalSymbol(getGlobalPromiseSymbol(), /*arity*/ 1));
12261
+ getGlobalPromiseType = memoize(() => getGlobalType("Promise", /*arity*/ 1));
12318
12262
getGlobalPromiseLikeType = memoize(() => getGlobalType("PromiseLike", /*arity*/ 1));
12319
12263
getInstantiatedGlobalPromiseLikeType = memoize(createInstantiatedPromiseLikeType);
12264
+ getGlobalPromiseConstructorSymbol = memoize(() => getGlobalValueSymbol("Promise"));
12320
12265
getGlobalPromiseConstructorLikeType = memoize(() => getGlobalType("PromiseConstructorLike"));
12321
12266
getGlobalThenableType = memoize(createThenableType);
12322
12267
0 commit comments