From f9999e9738bc038e75c5cfb5e6955f05025a0ad0 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 18 Jan 2017 12:42:51 -0800 Subject: [PATCH] PR Feedback --- src/compiler/binder.ts | 3 - src/compiler/checker.ts | 86 +++++++++---------- src/compiler/comments.ts | 6 -- src/compiler/diagnosticMessages.json | 2 +- src/compiler/types.ts | 2 +- src/compiler/visitor.ts | 6 -- .../asyncFunctionDeclaration15_es5.errors.txt | 8 +- .../asyncFunctionDeclaration15_es6.errors.txt | 8 +- 8 files changed, 53 insertions(+), 68 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 554e43604aa..8a9b1a507c5 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2794,7 +2794,6 @@ namespace ts { transformFlags |= node.asteriskToken ? TransformFlags.AssertESNext : TransformFlags.AssertES2017; } - // Currently, we only support generators that were originally async function bodies. if (node.asteriskToken) { transformFlags |= TransformFlags.AssertGenerator; } @@ -2922,8 +2921,6 @@ namespace ts { // If a FunctionExpression is generator function and is the body of a // transformed async function, then this node can be transformed to a // down-level generator. - // Currently we do not support transforming any other generator fucntions - // down level. if (node.asteriskToken) { transformFlags |= TransformFlags.AssertGenerator; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c420835c1bb..5afdef09e45 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -210,7 +210,7 @@ namespace ts { let deferredGlobalAsyncIterableType: GenericType; let deferredGlobalAsyncIteratorType: GenericType; let deferredGlobalAsyncIterableIteratorType: GenericType; - let defferedGlobalTemplateStringsArrayType: ObjectType; + let deferredGlobalTemplateStringsArrayType: ObjectType; let deferredJsxElementClassType: Type; let deferredNodes: Node[]; @@ -5647,75 +5647,75 @@ namespace ts { return type; } - function getGlobalValueSymbol(name: string, unchecked?: boolean): Symbol { - return getGlobalSymbol(name, SymbolFlags.Value, unchecked ? undefined : Diagnostics.Cannot_find_global_value_0); + function getGlobalValueSymbol(name: string, reportErrors: boolean): Symbol { + return getGlobalSymbol(name, SymbolFlags.Value, reportErrors ? Diagnostics.Cannot_find_global_value_0 : undefined); } - function getGlobalTypeSymbol(name: string, unchecked?: boolean): Symbol { - return getGlobalSymbol(name, SymbolFlags.Type, unchecked ? undefined : Diagnostics.Cannot_find_global_type_0); + function getGlobalTypeSymbol(name: string, reportErrors: boolean): Symbol { + return getGlobalSymbol(name, SymbolFlags.Type, reportErrors ? Diagnostics.Cannot_find_global_type_0 : undefined); } function getGlobalSymbol(name: string, meaning: SymbolFlags, diagnostic: DiagnosticMessage): Symbol { return resolveName(undefined, name, meaning, diagnostic, name); } - function getGlobalType(name: string, arity?: 0, unchecked?: boolean): ObjectType; - function getGlobalType(name: string, arity: number, unchecked?: boolean): GenericType; - function getGlobalType(name: string, arity = 0, unchecked?: boolean): ObjectType { - const symbol = getGlobalTypeSymbol(name, unchecked); - return symbol || !unchecked ? getTypeOfGlobalSymbol(symbol, arity) : undefined; + function getGlobalType(name: string, arity: 0, reportErrors: boolean): ObjectType; + function getGlobalType(name: string, arity: number, reportErrors: boolean): GenericType; + function getGlobalType(name: string, arity: number, reportErrors: boolean): ObjectType { + const symbol = getGlobalTypeSymbol(name, reportErrors); + return symbol || reportErrors ? getTypeOfGlobalSymbol(symbol, arity) : undefined; } function getGlobalTypedPropertyDescriptorType() { - return deferredGlobalTypedPropertyDescriptorType || (deferredGlobalTypedPropertyDescriptorType = getGlobalType("TypedPropertyDescriptor", 1)) || emptyGenericType; + return deferredGlobalTypedPropertyDescriptorType || (deferredGlobalTypedPropertyDescriptorType = getGlobalType("TypedPropertyDescriptor", /*arity*/ 1, /*reportErrors*/ true)) || emptyGenericType; } function getGlobalTemplateStringsArrayType() { - return defferedGlobalTemplateStringsArrayType || (defferedGlobalTemplateStringsArrayType = getGlobalType("TemplateStringsArray")) || emptyObjectType; + return deferredGlobalTemplateStringsArrayType || (deferredGlobalTemplateStringsArrayType = getGlobalType("TemplateStringsArray", /*arity*/ 0, /*reportErrors*/ true)) || emptyObjectType; } - function getGlobalESSymbolConstructorSymbol(checked: boolean) { - return deferredGlobalESSymbolConstructorSymbol || (deferredGlobalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol", !checked)); + function getGlobalESSymbolConstructorSymbol(reportErrors: boolean) { + return deferredGlobalESSymbolConstructorSymbol || (deferredGlobalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol", reportErrors)); } - function getGlobalESSymbolType(checked: boolean) { - return deferredGlobalESSymbolType || (deferredGlobalESSymbolType = getGlobalType("Symbol", 0, !checked)) || emptyObjectType; + function getGlobalESSymbolType(reportErrors: boolean) { + return deferredGlobalESSymbolType || (deferredGlobalESSymbolType = getGlobalType("Symbol", /*arity*/ 0, reportErrors)) || emptyObjectType; } - function getGlobalPromiseType(checked: boolean) { - return deferredGlobalPromiseType || (deferredGlobalPromiseType = getGlobalType("Promise", 1, !checked)) || emptyGenericType; + function getGlobalPromiseType(reportErrors: boolean) { + return deferredGlobalPromiseType || (deferredGlobalPromiseType = getGlobalType("Promise", /*arity*/ 1, reportErrors)) || emptyGenericType; } - function getGlobalPromiseConstructorSymbol(checked: boolean): Symbol | undefined { - return deferredGlobalPromiseConstructorSymbol || (deferredGlobalPromiseConstructorSymbol = getGlobalValueSymbol("Promise", !checked)); + function getGlobalPromiseConstructorSymbol(reportErrors: boolean): Symbol | undefined { + return deferredGlobalPromiseConstructorSymbol || (deferredGlobalPromiseConstructorSymbol = getGlobalValueSymbol("Promise", reportErrors)); } - function getGlobalPromiseConstructorLikeType(checked: boolean) { - return deferredGlobalPromiseConstructorLikeType || (deferredGlobalPromiseConstructorLikeType = getGlobalType("PromiseConstructorLike", 0, !checked)) || emptyObjectType; + function getGlobalPromiseConstructorLikeType(reportErrors: boolean) { + return deferredGlobalPromiseConstructorLikeType || (deferredGlobalPromiseConstructorLikeType = getGlobalType("PromiseConstructorLike", /*arity*/ 0, reportErrors)) || emptyObjectType; } - function getGlobalAsyncIterableType(checked: boolean) { - return deferredGlobalAsyncIterableType || (deferredGlobalAsyncIterableType = getGlobalType("AsyncIterable", 1, !checked)) || emptyGenericType; + function getGlobalAsyncIterableType(reportErrors: boolean) { + return deferredGlobalAsyncIterableType || (deferredGlobalAsyncIterableType = getGlobalType("AsyncIterable", /*arity*/ 1, reportErrors)) || emptyGenericType; } - function getGlobalAsyncIteratorType(checked: boolean) { - return deferredGlobalAsyncIteratorType || (deferredGlobalAsyncIteratorType = getGlobalType("AsyncIterator", 1, !checked)) || emptyGenericType; + function getGlobalAsyncIteratorType(reportErrors: boolean) { + return deferredGlobalAsyncIteratorType || (deferredGlobalAsyncIteratorType = getGlobalType("AsyncIterator", /*arity*/ 1, reportErrors)) || emptyGenericType; } - function getGlobalAsyncIterableIteratorType(checked: boolean) { - return deferredGlobalAsyncIterableIteratorType || (deferredGlobalAsyncIterableIteratorType = getGlobalType("AsyncIterableIterator", 1, !checked)) || emptyGenericType; + function getGlobalAsyncIterableIteratorType(reportErrors: boolean) { + return deferredGlobalAsyncIterableIteratorType || (deferredGlobalAsyncIterableIteratorType = getGlobalType("AsyncIterableIterator", /*arity*/ 1, reportErrors)) || emptyGenericType; } - function getGlobalIterableType(checked: boolean) { - return deferredGlobalIterableType || (deferredGlobalIterableType = getGlobalType("Iterable", 1, !checked)) || emptyGenericType; + function getGlobalIterableType(reportErrors: boolean) { + return deferredGlobalIterableType || (deferredGlobalIterableType = getGlobalType("Iterable", /*arity*/ 1, reportErrors)) || emptyGenericType; } - function getGlobalIteratorType(checked: boolean) { - return deferredGlobalIteratorType || (deferredGlobalIteratorType = getGlobalType("Iterator", 1, !checked)) || emptyGenericType; + function getGlobalIteratorType(reportErrors: boolean) { + return deferredGlobalIteratorType || (deferredGlobalIteratorType = getGlobalType("Iterator", /*arity*/ 1, reportErrors)) || emptyGenericType; } - function getGlobalIterableIteratorType(checked: boolean) { - return deferredGlobalIterableIteratorType || (deferredGlobalIterableIteratorType = getGlobalType("IterableIterator", 1, !checked)) || emptyGenericType; + function getGlobalIterableIteratorType(reportErrors: boolean) { + return deferredGlobalIterableIteratorType || (deferredGlobalIterableIteratorType = getGlobalType("IterableIterator", /*arity*/ 1, reportErrors)) || emptyGenericType; } /** @@ -16667,7 +16667,7 @@ namespace ts { const widenedType = getWidenedType(type); if (isThenableType(widenedType)) { if (errorNode) { - 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); + 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); } return undefined; } @@ -21093,17 +21093,17 @@ namespace ts { addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0); getSymbolLinks(undefinedSymbol).type = undefinedWideningType; - getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments"); + getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments", /*arity*/ 0, /*reportErrors*/ true); getSymbolLinks(unknownSymbol).type = unknownType; // Initialize special types - globalArrayType = getGlobalType("Array", /*arity*/ 1); - globalObjectType = getGlobalType("Object"); - globalFunctionType = getGlobalType("Function"); - globalStringType = getGlobalType("String"); - globalNumberType = getGlobalType("Number"); - globalBooleanType = getGlobalType("Boolean"); - globalRegExpType = getGlobalType("RegExp"); + globalArrayType = getGlobalType("Array", /*arity*/ 1, /*reportErrors*/ true); + globalObjectType = getGlobalType("Object", /*arity*/ 0, /*reportErrors*/ true); + globalFunctionType = getGlobalType("Function", /*arity*/ 0, /*reportErrors*/ true); + globalStringType = getGlobalType("String", /*arity*/ 0, /*reportErrors*/ true); + globalNumberType = getGlobalType("Number", /*arity*/ 0, /*reportErrors*/ true); + globalBooleanType = getGlobalType("Boolean", /*arity*/ 0, /*reportErrors*/ true); + globalRegExpType = getGlobalType("RegExp", /*arity*/ 0, /*reportErrors*/ true); jsxElementType = getExportedTypeFromNamespace("JSX", JsxNames.Element); anyArrayType = createArrayType(anyType); autoArrayType = createArrayType(autoType); diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index a7a4c2ed7d0..5d300f44934 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -25,8 +25,6 @@ namespace ts { let detachedCommentsInfo: { nodePos: number, detachedCommentEndPos: number}[]; let hasWrittenComment = false; let disabled: boolean = compilerOptions.removeComments; - // let leadingCommentPositions: Map; - // let trailingCommentPositions: Map; return { reset, @@ -288,8 +286,6 @@ namespace ts { currentText = undefined; currentLineMap = undefined; detachedCommentsInfo = undefined; - // leadingCommentPositions = undefined; - // trailingCommentPositions = undefined; } function setSourceFile(sourceFile: SourceFile) { @@ -297,8 +293,6 @@ namespace ts { currentText = currentSourceFile.text; currentLineMap = getLineStarts(currentSourceFile); detachedCommentsInfo = undefined; - // leadingCommentPositions = createMap(); - // trailingCommentPositions = createMap(); } function hasDetachedComments(pos: number) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index df17871979c..9a67f34cb9a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -175,7 +175,7 @@ "category": "Error", "code": 1057 }, - "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.": { + "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.": { "category": "Error", "code": 1058 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3b01af08b19..3ec39ed7fca 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3776,7 +3776,7 @@ namespace ts { SpreadIncludes = Read | Spread, FirstEmitHelper = Extends, - LastEmitHelper = Spread + LastEmitHelper = AsyncValues } /* @internal */ diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index cf40fdda755..6432670cea1 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -1217,17 +1217,11 @@ namespace ts { /** * Merges generated lexical declarations into a statement list, creating a new statement list. - * - * @param statements The statements. - * @param declarations The lexical declarations to merge. */ export function mergeLexicalEnvironment(statements: NodeArray, declarations: Statement[]): NodeArray; /** * Appends generated lexical declarations to an array of statements. - * - * @param statements The statements. - * @param declarations The lexical declarations to merge. */ export function mergeLexicalEnvironment(statements: Statement[], declarations: Statement[]): Statement[]; export function mergeLexicalEnvironment(statements: Statement[], declarations: Statement[]) { diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt index 2056ab3f2dc..090718f6fdf 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt @@ -8,8 +8,8 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1 Types of property 'then' are incompatible. Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => any, onrejected?: (reason: any) => any): PromiseLike; (onfulfilled: (value: any) => any, onrejected: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled: (value: any) => TResult1 | PromiseLike, onrejected: (reason: any) => TResult2 | PromiseLike): PromiseLike; }'. Type 'void' is not assignable to type 'PromiseLike'. -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. -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. +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. +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. ==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts (8 errors) ==== @@ -47,7 +47,7 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1 async function fn12() { return obj; } // valid: Promise<{ then: string; }> async function fn13() { return thenable; } // error ~~~~ -!!! 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. +!!! 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. async function fn14() { await 1; } // valid: Promise async function fn15() { await null; } // valid: Promise async function fn16() { await undefined; } // valid: Promise @@ -55,5 +55,5 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1 async function fn18() { await obj; } // valid: Promise async function fn19() { await thenable; } // error ~~~~~~~~~~~~~~ -!!! 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. +!!! 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. \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt index 224bc6133d8..60f57f3dfbf 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt @@ -3,8 +3,8 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1 tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,23): error TS1064: The return type of an async function or method must be the global Promise type. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,23): error TS1064: The return type of an async function or method must be the global Promise type. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,23): error TS1064: The return type of an async function or method must be the global Promise type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.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. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.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. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.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. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.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. ==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts (7 errors) ==== @@ -36,7 +36,7 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1 async function fn12() { return obj; } // valid: Promise<{ then: string; }> async function fn13() { return thenable; } // error ~~~~ -!!! 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. +!!! 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. async function fn14() { await 1; } // valid: Promise async function fn15() { await null; } // valid: Promise async function fn16() { await undefined; } // valid: Promise @@ -44,5 +44,5 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1 async function fn18() { await obj; } // valid: Promise async function fn19() { await thenable; } // error ~~~~~~~~~~~~~~ -!!! 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. +!!! 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. \ No newline at end of file