Skip to content

Commit 2d9af0b

Browse files
committed
Merge branch 'master' into requireJson
2 parents 2071466 + be1c115 commit 2d9af0b

113 files changed

Lines changed: 8824 additions & 254 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
1+
defaultFilters: &defaultFilters
2+
filters:
3+
branches:
4+
only:
5+
- master
6+
- release-2.5
7+
- release-2.6
8+
- release-2.7
19
workflows:
210
version: 2
311
main:
412
jobs:
513
- node9:
6-
filters:
7-
branches:
8-
only:
9-
- master
10-
- release-2.5
11-
- release-2.6
12-
- release-2.7
14+
<<: *defaultFilters
1315
- node8:
14-
filters:
15-
branches:
16-
only:
17-
- master
18-
- release-2.5
19-
- release-2.6
20-
- release-2.7
16+
<<: *defaultFilters
2117
- node6:
22-
filters:
23-
branches:
24-
only:
25-
- master
26-
- release-2.5
27-
- release-2.6
28-
- release-2.7
18+
<<: *defaultFilters
2919
nightly:
3020
triggers:
3121
- schedule:
@@ -35,39 +25,23 @@ workflows:
3525
only: master
3626
jobs:
3727
- node9:
38-
filters:
39-
branches:
40-
only:
41-
- master
42-
- release-2.5
43-
- release-2.6
44-
- release-2.7
28+
<<: *defaultFilters
4529
context: nightlies
4630
- node8:
47-
filters:
48-
branches:
49-
only:
50-
- master
51-
- release-2.5
52-
- release-2.6
53-
- release-2.7
31+
<<: *defaultFilters
5432
context: nightlies
5533
- node6:
56-
filters:
57-
branches:
58-
only:
59-
- master
60-
- release-2.5
61-
- release-2.6
62-
- release-2.7
34+
<<: *defaultFilters
6335
context: nightlies
6436

6537
base: &base
6638
environment:
6739
- workerCount: 4
6840
- timeout: 400000
6941
steps:
70-
- checkout
42+
- checkout:
43+
post:
44+
- git submodule update --init --recursive
7145
- run: |
7246
npm uninstall typescript --no-save
7347
npm uninstall tslint --no-save

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ matrix:
1616
branches:
1717
only:
1818
- master
19-
- release-2.5
20-
- release-2.6
2119
- release-2.7
20+
- release-2.8
2221

2322
install:
2423
- npm uninstall typescript --no-save

src/compiler/checker.ts

Lines changed: 53 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -8031,7 +8031,7 @@ namespace ts {
80318031
function getLiteralTypeFromPropertyName(prop: Symbol) {
80328032
const links = getSymbolLinks(getLateBoundSymbol(prop));
80338033
if (!links.nameType) {
8034-
if (links.target) {
8034+
if (links.target && links.target !== unknownSymbol && links.target !== resolvingSymbol) {
80358035
Debug.assert(links.target.escapedName === prop.escapedName || links.target.escapedName === InternalSymbolName.Computed, "Target symbol and symbol do not have the same name");
80368036
links.nameType = getLiteralTypeFromPropertyName(links.target);
80378037
}
@@ -14115,7 +14115,7 @@ namespace ts {
1411514115
}
1411614116
}
1411714117

14118-
function getContainingObjectLiteral(func: FunctionLike): ObjectLiteralExpression | undefined {
14118+
function getContainingObjectLiteral(func: SignatureDeclaration): ObjectLiteralExpression | undefined {
1411914119
return (func.kind === SyntaxKind.MethodDeclaration ||
1412014120
func.kind === SyntaxKind.GetAccessor ||
1412114121
func.kind === SyntaxKind.SetAccessor) && func.parent.kind === SyntaxKind.ObjectLiteralExpression ? func.parent :
@@ -14133,7 +14133,7 @@ namespace ts {
1413314133
});
1413414134
}
1413514135

14136-
function getContextualThisParameterType(func: FunctionLike): Type {
14136+
function getContextualThisParameterType(func: SignatureDeclaration): Type {
1413714137
if (func.kind === SyntaxKind.ArrowFunction) {
1413814138
return undefined;
1413914139
}
@@ -14330,7 +14330,7 @@ namespace ts {
1433014330
return false;
1433114331
}
1433214332

14333-
function getContextualReturnType(functionDecl: FunctionLike): Type {
14333+
function getContextualReturnType(functionDecl: SignatureDeclaration): Type {
1433414334
// If the containing function has a return type annotation, is a constructor, or is a get accessor whose
1433514335
// corresponding set accessor has a type annotation, return statements in the function are contextually typed
1433614336
if (functionDecl.kind === SyntaxKind.Constructor ||
@@ -18528,27 +18528,23 @@ namespace ts {
1852818528

1852918529
function checkAndAggregateYieldOperandTypes(func: FunctionLikeDeclaration, checkMode: CheckMode): Type[] {
1853018530
const aggregatedTypes: Type[] = [];
18531-
const functionFlags = getFunctionFlags(func);
18531+
const isAsync = (getFunctionFlags(func) & FunctionFlags.Async) !== 0;
1853218532
forEachYieldExpression(<Block>func.body, yieldExpression => {
18533-
const expr = yieldExpression.expression;
18534-
if (expr) {
18535-
let type = checkExpressionCached(expr, checkMode);
18536-
if (yieldExpression.asteriskToken) {
18537-
// A yield* expression effectively yields everything that its operand yields
18538-
type = checkIteratedTypeOrElementType(type, yieldExpression.expression, /*allowStringInput*/ false, (functionFlags & FunctionFlags.Async) !== 0);
18539-
}
18540-
if (functionFlags & FunctionFlags.Async) {
18541-
type = checkAwaitedType(type, expr, yieldExpression.asteriskToken
18542-
? Diagnostics.Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
18543-
: Diagnostics.Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member);
18544-
}
18545-
pushIfUnique(aggregatedTypes, type);
18546-
}
18533+
pushIfUnique(aggregatedTypes, getYieldedTypeOfYieldExpression(yieldExpression, isAsync, checkMode));
1854718534
});
18548-
1854918535
return aggregatedTypes;
1855018536
}
1855118537

18538+
function getYieldedTypeOfYieldExpression(node: YieldExpression, isAsync: boolean, checkMode?: CheckMode): Type {
18539+
const errorNode = node.expression || node;
18540+
const expressionType = node.expression ? checkExpressionCached(node.expression, checkMode) : undefinedWideningType;
18541+
// A `yield*` expression effectively yields everything that its operand yields
18542+
const yieldedType = node.asteriskToken ? checkIteratedTypeOrElementType(expressionType, errorNode, /*allowStringInput*/ false, isAsync) : expressionType;
18543+
return !isAsync ? yieldedType : getAwaitedType(yieldedType, errorNode, node.asteriskToken
18544+
? Diagnostics.Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
18545+
: Diagnostics.Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member);
18546+
}
18547+
1855218548
function isExhaustiveSwitchStatement(node: SwitchStatement): boolean {
1855318549
if (!node.possiblyExhaustive) {
1855418550
return false;
@@ -19504,62 +19500,40 @@ namespace ts {
1950419500
}
1950519501
}
1950619502

19507-
if (node.expression) {
19508-
const func = getContainingFunction(node);
19509-
// If the user's code is syntactically correct, the func should always have a star. After all,
19510-
// we are in a yield context.
19511-
const functionFlags = func && getFunctionFlags(func);
19512-
if (node.asteriskToken) {
19513-
// Async generator functions prior to ESNext require the __await, __asyncDelegator,
19514-
// and __asyncValues helpers
19515-
if ((functionFlags & FunctionFlags.AsyncGenerator) === FunctionFlags.AsyncGenerator &&
19516-
languageVersion < ScriptTarget.ESNext) {
19517-
checkExternalEmitHelpers(node, ExternalEmitHelpers.AsyncDelegatorIncludes);
19518-
}
19519-
19520-
// Generator functions prior to ES2015 require the __values helper
19521-
if ((functionFlags & FunctionFlags.AsyncGenerator) === FunctionFlags.Generator &&
19522-
languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
19523-
checkExternalEmitHelpers(node, ExternalEmitHelpers.Values);
19524-
}
19525-
}
19526-
19527-
if (functionFlags & FunctionFlags.Generator) {
19528-
const expressionType = checkExpressionCached(node.expression);
19529-
let expressionElementType: Type;
19530-
const nodeIsYieldStar = !!node.asteriskToken;
19531-
if (nodeIsYieldStar) {
19532-
expressionElementType = checkIteratedTypeOrElementType(expressionType, node.expression, /*allowStringInput*/ false, (functionFlags & FunctionFlags.Async) !== 0);
19533-
}
19534-
19535-
// There is no point in doing an assignability check if the function
19536-
// has no explicit return type because the return type is directly computed
19537-
// from the yield expressions.
19538-
const returnType = getEffectiveReturnTypeNode(func);
19539-
if (returnType) {
19540-
const signatureElementType = getIteratedTypeOfGenerator(getTypeFromTypeNode(returnType), (functionFlags & FunctionFlags.Async) !== 0) || anyType;
19541-
if (nodeIsYieldStar) {
19542-
checkTypeAssignableTo(
19543-
functionFlags & FunctionFlags.Async
19544-
? getAwaitedType(expressionElementType, node.expression, Diagnostics.Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member)
19545-
: expressionElementType,
19546-
signatureElementType,
19547-
node.expression,
19548-
/*headMessage*/ undefined);
19549-
}
19550-
else {
19551-
checkTypeAssignableTo(
19552-
functionFlags & FunctionFlags.Async
19553-
? getAwaitedType(expressionType, node.expression, Diagnostics.Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member)
19554-
: expressionType,
19555-
signatureElementType,
19556-
node.expression,
19557-
/*headMessage*/ undefined);
19558-
}
19559-
}
19503+
const func = getContainingFunction(node);
19504+
const functionFlags = func ? getFunctionFlags(func) : FunctionFlags.Normal;
19505+
19506+
if (!(functionFlags & FunctionFlags.Generator)) {
19507+
// If the user's code is syntactically correct, the func should always have a star. After all, we are in a yield context.
19508+
return anyType;
19509+
}
19510+
19511+
if (node.asteriskToken) {
19512+
// Async generator functions prior to ESNext require the __await, __asyncDelegator,
19513+
// and __asyncValues helpers
19514+
if ((functionFlags & FunctionFlags.AsyncGenerator) === FunctionFlags.AsyncGenerator &&
19515+
languageVersion < ScriptTarget.ESNext) {
19516+
checkExternalEmitHelpers(node, ExternalEmitHelpers.AsyncDelegatorIncludes);
19517+
}
19518+
19519+
// Generator functions prior to ES2015 require the __values helper
19520+
if ((functionFlags & FunctionFlags.AsyncGenerator) === FunctionFlags.Generator &&
19521+
languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
19522+
checkExternalEmitHelpers(node, ExternalEmitHelpers.Values);
1956019523
}
1956119524
}
1956219525

19526+
const isAsync = (functionFlags & FunctionFlags.Async) !== 0;
19527+
const yieldedType = getYieldedTypeOfYieldExpression(node, isAsync);
19528+
// There is no point in doing an assignability check if the function
19529+
// has no explicit return type because the return type is directly computed
19530+
// from the yield expressions.
19531+
const returnType = getEffectiveReturnTypeNode(func);
19532+
if (returnType) {
19533+
const signatureElementType = getIteratedTypeOfGenerator(getTypeFromTypeNode(returnType), isAsync) || anyType;
19534+
checkTypeAssignableTo(yieldedType, signatureElementType, node.expression || node, /*headMessage*/ undefined);
19535+
}
19536+
1956319537
// Both yield and yield* expressions have type 'any'
1956419538
return anyType;
1956519539
}
@@ -20711,12 +20685,12 @@ namespace ts {
2071120685
let hasOverloads = false;
2071220686
let bodyDeclaration: FunctionLikeDeclaration;
2071320687
let lastSeenNonAmbientDeclaration: FunctionLikeDeclaration;
20714-
let previousDeclaration: FunctionLike;
20688+
let previousDeclaration: SignatureDeclaration;
2071520689

2071620690
const declarations = symbol.declarations;
2071720691
const isConstructor = (symbol.flags & SymbolFlags.Constructor) !== 0;
2071820692

20719-
function reportImplementationExpectedError(node: FunctionLike): void {
20693+
function reportImplementationExpectedError(node: SignatureDeclaration): void {
2072020694
if (node.name && nodeIsMissing(node.name)) {
2072120695
return;
2072220696
}
@@ -20778,7 +20752,7 @@ namespace ts {
2077820752
let duplicateFunctionDeclaration = false;
2077920753
let multipleConstructorImplementation = false;
2078020754
for (const current of declarations) {
20781-
const node = <FunctionLike>current;
20755+
const node = <SignatureDeclaration>current;
2078220756
const inAmbientContext = node.flags & NodeFlags.Ambient;
2078320757
const inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext;
2078420758
if (inAmbientContextOrInterface) {
@@ -22786,12 +22760,12 @@ namespace ts {
2278622760
// TODO: Check that target label is valid
2278722761
}
2278822762

22789-
function isGetAccessorWithAnnotatedSetAccessor(node: FunctionLike) {
22763+
function isGetAccessorWithAnnotatedSetAccessor(node: SignatureDeclaration) {
2279022764
return node.kind === SyntaxKind.GetAccessor
2279122765
&& getEffectiveSetAccessorTypeAnnotationNode(getDeclarationOfKind<SetAccessorDeclaration>(node.symbol, SyntaxKind.SetAccessor)) !== undefined;
2279222766
}
2279322767

22794-
function isUnwrappedReturnTypeVoidOrAny(func: FunctionLike, returnType: Type): boolean {
22768+
function isUnwrappedReturnTypeVoidOrAny(func: SignatureDeclaration, returnType: Type): boolean {
2279522769
const unwrappedReturnType = (getFunctionFlags(func) & FunctionFlags.AsyncGenerator) === FunctionFlags.Async
2279622770
? getPromisedTypeOfPromise(returnType) // Async function
2279722771
: returnType; // AsyncGenerator function, Generator function, or normal function
@@ -25512,7 +25486,7 @@ namespace ts {
2551225486
return false;
2551325487
}
2551425488

25515-
function isImplementationOfOverload(node: FunctionLike) {
25489+
function isImplementationOfOverload(node: SignatureDeclaration) {
2551625490
if (nodeIsPresent((node as FunctionLikeDeclaration).body)) {
2551725491
const symbol = getSymbolOfNode(node);
2551825492
const signaturesOfSymbol = getSignaturesOfSymbol(symbol);

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2201,7 +2201,7 @@ namespace ts {
22012201

22022202
if (options.emitDeclarationOnly) {
22032203
if (!options.declaration) {
2204-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declarations");
2204+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declaration");
22052205
}
22062206

22072207
if (options.noEmit) {

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ namespace ts {
17801780
return createArrayLiteral(expressions);
17811781
}
17821782

1783-
function getParametersOfDecoratedDeclaration(node: FunctionLike, container: ClassLikeDeclaration) {
1783+
function getParametersOfDecoratedDeclaration(node: SignatureDeclaration, container: ClassLikeDeclaration) {
17841784
if (container && node.kind === SyntaxKind.GetAccessor) {
17851785
const { setAccessor } = getAllAccessorDeclarations(container.members, <AccessorDeclaration>node);
17861786
if (setAccessor) {

src/compiler/types.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -968,15 +968,8 @@ namespace ts {
968968
| SetAccessorDeclaration
969969
| FunctionExpression
970970
| ArrowFunction;
971-
export type FunctionLike =
972-
| FunctionLikeDeclaration
973-
| FunctionTypeNode
974-
| ConstructorTypeNode
975-
| IndexSignatureDeclaration
976-
| MethodSignature
977-
| ConstructSignatureDeclaration
978-
| CallSignatureDeclaration
979-
| JSDocFunctionType;
971+
/** @deprecated Use SignatureDeclaration */
972+
export type FunctionLike = SignatureDeclaration;
980973

981974
export interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement {
982975
kind: SyntaxKind.FunctionDeclaration;
@@ -2870,7 +2863,7 @@ namespace ts {
28702863
*/
28712864
getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature;
28722865
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature | undefined;
2873-
isImplementationOfOverload(node: FunctionLike): boolean | undefined;
2866+
isImplementationOfOverload(node: SignatureDeclaration): boolean | undefined;
28742867
isUndefinedSymbol(symbol: Symbol): boolean;
28752868
isArgumentsSymbol(symbol: Symbol): boolean;
28762869
isUnknownSymbol(symbol: Symbol): boolean;

src/compiler/utilities.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ namespace ts {
10471047
}
10481048
}
10491049

1050-
export function getContainingFunction(node: Node): FunctionLike {
1050+
export function getContainingFunction(node: Node): SignatureDeclaration {
10511051
return findAncestor(node.parent, isFunctionLike);
10521052
}
10531053

@@ -1825,7 +1825,7 @@ namespace ts {
18251825
return parameter && parameter.symbol;
18261826
}
18271827

1828-
export function getHostSignatureFromJSDoc(node: JSDocParameterTag): FunctionLike | undefined {
1828+
export function getHostSignatureFromJSDoc(node: JSDocParameterTag): SignatureDeclaration | undefined {
18291829
const host = getJSDocHost(node);
18301830
const decl = getSourceOfDefaultedAssignment(host) ||
18311831
getSourceOfAssignment(host) ||
@@ -2160,7 +2160,7 @@ namespace ts {
21602160
AsyncGenerator = Async | Generator, // Function is an async generator function
21612161
}
21622162

2163-
export function getFunctionFlags(node: FunctionLike | undefined) {
2163+
export function getFunctionFlags(node: SignatureDeclaration | undefined) {
21642164
if (!node) {
21652165
return FunctionFlags.Invalid;
21662166
}
@@ -5325,7 +5325,7 @@ namespace ts {
53255325

53265326
// Functions
53275327

5328-
export function isFunctionLike(node: Node): node is FunctionLike {
5328+
export function isFunctionLike(node: Node): node is SignatureDeclaration {
53295329
return node && isFunctionLikeKind(node.kind);
53305330
}
53315331

0 commit comments

Comments
 (0)