Skip to content

Commit f9999e9

Browse files
committed
PR Feedback
1 parent 35ef1f7 commit f9999e9

File tree

8 files changed

+53
-68
lines changed

8 files changed

+53
-68
lines changed

src/compiler/binder.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,7 +2794,6 @@ namespace ts {
27942794
transformFlags |= node.asteriskToken ? TransformFlags.AssertESNext : TransformFlags.AssertES2017;
27952795
}
27962796

2797-
// Currently, we only support generators that were originally async function bodies.
27982797
if (node.asteriskToken) {
27992798
transformFlags |= TransformFlags.AssertGenerator;
28002799
}
@@ -2922,8 +2921,6 @@ namespace ts {
29222921
// If a FunctionExpression is generator function and is the body of a
29232922
// transformed async function, then this node can be transformed to a
29242923
// down-level generator.
2925-
// Currently we do not support transforming any other generator fucntions
2926-
// down level.
29272924
if (node.asteriskToken) {
29282925
transformFlags |= TransformFlags.AssertGenerator;
29292926
}

src/compiler/checker.ts

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ namespace ts {
210210
let deferredGlobalAsyncIterableType: GenericType;
211211
let deferredGlobalAsyncIteratorType: GenericType;
212212
let deferredGlobalAsyncIterableIteratorType: GenericType;
213-
let defferedGlobalTemplateStringsArrayType: ObjectType;
213+
let deferredGlobalTemplateStringsArrayType: ObjectType;
214214
let deferredJsxElementClassType: Type;
215215

216216
let deferredNodes: Node[];
@@ -5647,75 +5647,75 @@ namespace ts {
56475647
return <ObjectType>type;
56485648
}
56495649

5650-
function getGlobalValueSymbol(name: string, unchecked?: boolean): Symbol {
5651-
return getGlobalSymbol(name, SymbolFlags.Value, unchecked ? undefined : Diagnostics.Cannot_find_global_value_0);
5650+
function getGlobalValueSymbol(name: string, reportErrors: boolean): Symbol {
5651+
return getGlobalSymbol(name, SymbolFlags.Value, reportErrors ? Diagnostics.Cannot_find_global_value_0 : undefined);
56525652
}
56535653

5654-
function getGlobalTypeSymbol(name: string, unchecked?: boolean): Symbol {
5655-
return getGlobalSymbol(name, SymbolFlags.Type, unchecked ? undefined : Diagnostics.Cannot_find_global_type_0);
5654+
function getGlobalTypeSymbol(name: string, reportErrors: boolean): Symbol {
5655+
return getGlobalSymbol(name, SymbolFlags.Type, reportErrors ? Diagnostics.Cannot_find_global_type_0 : undefined);
56565656
}
56575657

56585658
function getGlobalSymbol(name: string, meaning: SymbolFlags, diagnostic: DiagnosticMessage): Symbol {
56595659
return resolveName(undefined, name, meaning, diagnostic, name);
56605660
}
56615661

5662-
function getGlobalType(name: string, arity?: 0, unchecked?: boolean): ObjectType;
5663-
function getGlobalType(name: string, arity: number, unchecked?: boolean): GenericType;
5664-
function getGlobalType(name: string, arity = 0, unchecked?: boolean): ObjectType {
5665-
const symbol = getGlobalTypeSymbol(name, unchecked);
5666-
return symbol || !unchecked ? getTypeOfGlobalSymbol(symbol, arity) : undefined;
5662+
function getGlobalType(name: string, arity: 0, reportErrors: boolean): ObjectType;
5663+
function getGlobalType(name: string, arity: number, reportErrors: boolean): GenericType;
5664+
function getGlobalType(name: string, arity: number, reportErrors: boolean): ObjectType {
5665+
const symbol = getGlobalTypeSymbol(name, reportErrors);
5666+
return symbol || reportErrors ? getTypeOfGlobalSymbol(symbol, arity) : undefined;
56675667
}
56685668

56695669
function getGlobalTypedPropertyDescriptorType() {
5670-
return deferredGlobalTypedPropertyDescriptorType || (deferredGlobalTypedPropertyDescriptorType = getGlobalType("TypedPropertyDescriptor", 1)) || emptyGenericType;
5670+
return deferredGlobalTypedPropertyDescriptorType || (deferredGlobalTypedPropertyDescriptorType = getGlobalType("TypedPropertyDescriptor", /*arity*/ 1, /*reportErrors*/ true)) || emptyGenericType;
56715671
}
56725672

56735673
function getGlobalTemplateStringsArrayType() {
5674-
return defferedGlobalTemplateStringsArrayType || (defferedGlobalTemplateStringsArrayType = getGlobalType("TemplateStringsArray")) || emptyObjectType;
5674+
return deferredGlobalTemplateStringsArrayType || (deferredGlobalTemplateStringsArrayType = getGlobalType("TemplateStringsArray", /*arity*/ 0, /*reportErrors*/ true)) || emptyObjectType;
56755675
}
56765676

5677-
function getGlobalESSymbolConstructorSymbol(checked: boolean) {
5678-
return deferredGlobalESSymbolConstructorSymbol || (deferredGlobalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol", !checked));
5677+
function getGlobalESSymbolConstructorSymbol(reportErrors: boolean) {
5678+
return deferredGlobalESSymbolConstructorSymbol || (deferredGlobalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol", reportErrors));
56795679
}
56805680

5681-
function getGlobalESSymbolType(checked: boolean) {
5682-
return deferredGlobalESSymbolType || (deferredGlobalESSymbolType = getGlobalType("Symbol", 0, !checked)) || emptyObjectType;
5681+
function getGlobalESSymbolType(reportErrors: boolean) {
5682+
return deferredGlobalESSymbolType || (deferredGlobalESSymbolType = getGlobalType("Symbol", /*arity*/ 0, reportErrors)) || emptyObjectType;
56835683
}
56845684

5685-
function getGlobalPromiseType(checked: boolean) {
5686-
return deferredGlobalPromiseType || (deferredGlobalPromiseType = getGlobalType("Promise", 1, !checked)) || emptyGenericType;
5685+
function getGlobalPromiseType(reportErrors: boolean) {
5686+
return deferredGlobalPromiseType || (deferredGlobalPromiseType = getGlobalType("Promise", /*arity*/ 1, reportErrors)) || emptyGenericType;
56875687
}
56885688

5689-
function getGlobalPromiseConstructorSymbol(checked: boolean): Symbol | undefined {
5690-
return deferredGlobalPromiseConstructorSymbol || (deferredGlobalPromiseConstructorSymbol = getGlobalValueSymbol("Promise", !checked));
5689+
function getGlobalPromiseConstructorSymbol(reportErrors: boolean): Symbol | undefined {
5690+
return deferredGlobalPromiseConstructorSymbol || (deferredGlobalPromiseConstructorSymbol = getGlobalValueSymbol("Promise", reportErrors));
56915691
}
56925692

5693-
function getGlobalPromiseConstructorLikeType(checked: boolean) {
5694-
return deferredGlobalPromiseConstructorLikeType || (deferredGlobalPromiseConstructorLikeType = getGlobalType("PromiseConstructorLike", 0, !checked)) || emptyObjectType;
5693+
function getGlobalPromiseConstructorLikeType(reportErrors: boolean) {
5694+
return deferredGlobalPromiseConstructorLikeType || (deferredGlobalPromiseConstructorLikeType = getGlobalType("PromiseConstructorLike", /*arity*/ 0, reportErrors)) || emptyObjectType;
56955695
}
56965696

5697-
function getGlobalAsyncIterableType(checked: boolean) {
5698-
return deferredGlobalAsyncIterableType || (deferredGlobalAsyncIterableType = getGlobalType("AsyncIterable", 1, !checked)) || emptyGenericType;
5697+
function getGlobalAsyncIterableType(reportErrors: boolean) {
5698+
return deferredGlobalAsyncIterableType || (deferredGlobalAsyncIterableType = getGlobalType("AsyncIterable", /*arity*/ 1, reportErrors)) || emptyGenericType;
56995699
}
57005700

5701-
function getGlobalAsyncIteratorType(checked: boolean) {
5702-
return deferredGlobalAsyncIteratorType || (deferredGlobalAsyncIteratorType = getGlobalType("AsyncIterator", 1, !checked)) || emptyGenericType;
5701+
function getGlobalAsyncIteratorType(reportErrors: boolean) {
5702+
return deferredGlobalAsyncIteratorType || (deferredGlobalAsyncIteratorType = getGlobalType("AsyncIterator", /*arity*/ 1, reportErrors)) || emptyGenericType;
57035703
}
57045704

5705-
function getGlobalAsyncIterableIteratorType(checked: boolean) {
5706-
return deferredGlobalAsyncIterableIteratorType || (deferredGlobalAsyncIterableIteratorType = getGlobalType("AsyncIterableIterator", 1, !checked)) || emptyGenericType;
5705+
function getGlobalAsyncIterableIteratorType(reportErrors: boolean) {
5706+
return deferredGlobalAsyncIterableIteratorType || (deferredGlobalAsyncIterableIteratorType = getGlobalType("AsyncIterableIterator", /*arity*/ 1, reportErrors)) || emptyGenericType;
57075707
}
57085708

5709-
function getGlobalIterableType(checked: boolean) {
5710-
return deferredGlobalIterableType || (deferredGlobalIterableType = getGlobalType("Iterable", 1, !checked)) || emptyGenericType;
5709+
function getGlobalIterableType(reportErrors: boolean) {
5710+
return deferredGlobalIterableType || (deferredGlobalIterableType = getGlobalType("Iterable", /*arity*/ 1, reportErrors)) || emptyGenericType;
57115711
}
57125712

5713-
function getGlobalIteratorType(checked: boolean) {
5714-
return deferredGlobalIteratorType || (deferredGlobalIteratorType = getGlobalType("Iterator", 1, !checked)) || emptyGenericType;
5713+
function getGlobalIteratorType(reportErrors: boolean) {
5714+
return deferredGlobalIteratorType || (deferredGlobalIteratorType = getGlobalType("Iterator", /*arity*/ 1, reportErrors)) || emptyGenericType;
57155715
}
57165716

5717-
function getGlobalIterableIteratorType(checked: boolean) {
5718-
return deferredGlobalIterableIteratorType || (deferredGlobalIterableIteratorType = getGlobalType("IterableIterator", 1, !checked)) || emptyGenericType;
5717+
function getGlobalIterableIteratorType(reportErrors: boolean) {
5718+
return deferredGlobalIterableIteratorType || (deferredGlobalIterableIteratorType = getGlobalType("IterableIterator", /*arity*/ 1, reportErrors)) || emptyGenericType;
57195719
}
57205720

57215721
/**
@@ -16667,7 +16667,7 @@ namespace ts {
1666716667
const widenedType = getWidenedType(type);
1666816668
if (isThenableType(widenedType)) {
1666916669
if (errorNode) {
16670-
error(errorNode, Diagnostics.Type_used_as_operand_to_await_or_the_return_type_of_an_async_function_must_not_contain_a_callable_then_member_if_it_is_not_a_promise);
16670+
error(errorNode, Diagnostics.Type_used_as_operand_to_await_or_the_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member);
1667116671
}
1667216672
return undefined;
1667316673
}
@@ -21093,17 +21093,17 @@ namespace ts {
2109321093
addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0);
2109421094

2109521095
getSymbolLinks(undefinedSymbol).type = undefinedWideningType;
21096-
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
21096+
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments", /*arity*/ 0, /*reportErrors*/ true);
2109721097
getSymbolLinks(unknownSymbol).type = unknownType;
2109821098

2109921099
// Initialize special types
21100-
globalArrayType = <GenericType>getGlobalType("Array", /*arity*/ 1);
21101-
globalObjectType = getGlobalType("Object");
21102-
globalFunctionType = getGlobalType("Function");
21103-
globalStringType = getGlobalType("String");
21104-
globalNumberType = getGlobalType("Number");
21105-
globalBooleanType = getGlobalType("Boolean");
21106-
globalRegExpType = getGlobalType("RegExp");
21100+
globalArrayType = getGlobalType("Array", /*arity*/ 1, /*reportErrors*/ true);
21101+
globalObjectType = getGlobalType("Object", /*arity*/ 0, /*reportErrors*/ true);
21102+
globalFunctionType = getGlobalType("Function", /*arity*/ 0, /*reportErrors*/ true);
21103+
globalStringType = getGlobalType("String", /*arity*/ 0, /*reportErrors*/ true);
21104+
globalNumberType = getGlobalType("Number", /*arity*/ 0, /*reportErrors*/ true);
21105+
globalBooleanType = getGlobalType("Boolean", /*arity*/ 0, /*reportErrors*/ true);
21106+
globalRegExpType = getGlobalType("RegExp", /*arity*/ 0, /*reportErrors*/ true);
2110721107
jsxElementType = getExportedTypeFromNamespace("JSX", JsxNames.Element);
2110821108
anyArrayType = createArrayType(anyType);
2110921109
autoArrayType = createArrayType(autoType);

src/compiler/comments.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ namespace ts {
2525
let detachedCommentsInfo: { nodePos: number, detachedCommentEndPos: number}[];
2626
let hasWrittenComment = false;
2727
let disabled: boolean = compilerOptions.removeComments;
28-
// let leadingCommentPositions: Map<boolean>;
29-
// let trailingCommentPositions: Map<boolean>;
3028

3129
return {
3230
reset,
@@ -288,17 +286,13 @@ namespace ts {
288286
currentText = undefined;
289287
currentLineMap = undefined;
290288
detachedCommentsInfo = undefined;
291-
// leadingCommentPositions = undefined;
292-
// trailingCommentPositions = undefined;
293289
}
294290

295291
function setSourceFile(sourceFile: SourceFile) {
296292
currentSourceFile = sourceFile;
297293
currentText = currentSourceFile.text;
298294
currentLineMap = getLineStarts(currentSourceFile);
299295
detachedCommentsInfo = undefined;
300-
// leadingCommentPositions = createMap<boolean>();
301-
// trailingCommentPositions = createMap<boolean>();
302296
}
303297

304298
function hasDetachedComments(pos: number) {

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
"category": "Error",
176176
"code": 1057
177177
},
178-
"Type used as operand to 'await' or the return type of an async function must not contain a callable 'then' member if it is not a promise.": {
178+
"Type used as operand to 'await' or the return type of an async function must either be a valid promise or must not contain a callable 'then' member.": {
179179
"category": "Error",
180180
"code": 1058
181181
},

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3776,7 +3776,7 @@ namespace ts {
37763776
SpreadIncludes = Read | Spread,
37773777

37783778
FirstEmitHelper = Extends,
3779-
LastEmitHelper = Spread
3779+
LastEmitHelper = AsyncValues
37803780
}
37813781

37823782
/* @internal */

src/compiler/visitor.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,17 +1217,11 @@ namespace ts {
12171217

12181218
/**
12191219
* Merges generated lexical declarations into a statement list, creating a new statement list.
1220-
*
1221-
* @param statements The statements.
1222-
* @param declarations The lexical declarations to merge.
12231220
*/
12241221
export function mergeLexicalEnvironment(statements: NodeArray<Statement>, declarations: Statement[]): NodeArray<Statement>;
12251222

12261223
/**
12271224
* Appends generated lexical declarations to an array of statements.
1228-
*
1229-
* @param statements The statements.
1230-
* @param declarations The lexical declarations to merge.
12311225
*/
12321226
export function mergeLexicalEnvironment(statements: Statement[], declarations: Statement[]): Statement[];
12331227
export function mergeLexicalEnvironment(statements: Statement[], declarations: Statement[]) {

tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
88
Types of property 'then' are incompatible.
99
Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => any, onrejected?: (reason: any) => any): PromiseLike<any>; <TResult>(onfulfilled: (value: any) => any, onrejected: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<any>; <TResult>(onfulfilled: (value: any) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>; <TResult1, TResult2>(onfulfilled: (value: any) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): PromiseLike<TResult1 | TResult2>; }'.
1010
Type 'void' is not assignable to type 'PromiseLike<any>'.
11-
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(17,16): error TS1058: Type used as operand to 'await' or the return type of an async function must not contain a callable 'then' member if it is not a promise.
12-
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(23,25): error TS1058: Type used as operand to 'await' or the return type of an async function must not contain a callable 'then' member if it is not a promise.
11+
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(17,16): error TS1058: Type used as operand to 'await' or the return type of an async function must either be a valid promise or must not contain a callable 'then' member.
12+
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(23,25): error TS1058: Type used as operand to 'await' or the return type of an async function must either be a valid promise or must not contain a callable 'then' member.
1313

1414

1515
==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts (8 errors) ====
@@ -47,13 +47,13 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
4747
async function fn12() { return obj; } // valid: Promise<{ then: string; }>
4848
async function fn13() { return thenable; } // error
4949
~~~~
50-
!!! error TS1058: Type used as operand to 'await' or the return type of an async function must not contain a callable 'then' member if it is not a promise.
50+
!!! error TS1058: Type used as operand to 'await' or the return type of an async function must either be a valid promise or must not contain a callable 'then' member.
5151
async function fn14() { await 1; } // valid: Promise<void>
5252
async function fn15() { await null; } // valid: Promise<void>
5353
async function fn16() { await undefined; } // valid: Promise<void>
5454
async function fn17() { await a; } // valid: Promise<void>
5555
async function fn18() { await obj; } // valid: Promise<void>
5656
async function fn19() { await thenable; } // error
5757
~~~~~~~~~~~~~~
58-
!!! error TS1058: Type used as operand to 'await' or the return type of an async function must not contain a callable 'then' member if it is not a promise.
58+
!!! error TS1058: Type used as operand to 'await' or the return type of an async function must either be a valid promise or must not contain a callable 'then' member.
5959

0 commit comments

Comments
 (0)