Skip to content

Commit 575339c

Browse files
committed
Merge branch 'master' into testChanges
2 parents 4530d3e + 4055689 commit 575339c

File tree

46 files changed

+10675
-10237
lines changed

Some content is hidden

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

46 files changed

+10675
-10237
lines changed

.github/ISSUE_TEMPLATE/Bug_report.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ Please help us by doing the following steps before logging an issue:
1515
Please fill in the *entire* template below.
1616
-->
1717

18-
<!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->
18+
<!--
19+
Please try to reproduce the issue with the latest published version. It may have already been fixed.
20+
For npm: `typescript@next`
21+
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly
22+
-->
1923
**TypeScript Version:** 3.7.x-dev.201xxxxx
2024

2125
<!-- Search terms you tried before logging this (so others can find this issue more easily) -->

src/compiler/builder.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ namespace ts {
251251
state.seenAffectedFiles = createMap<true>();
252252
}
253253

254-
state.emittedBuildInfo = !state.changedFilesSet.size &&
255-
!state.affectedFilesPendingEmit;
256-
254+
state.emittedBuildInfo = !state.changedFilesSet.size && !state.affectedFilesPendingEmit;
257255
return state;
258256
}
259257

src/compiler/checker.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,6 @@ namespace ts {
174174
IsForSignatureHelp = 1 << 4, // Call resolution for purposes of signature help
175175
}
176176

177-
const enum ContextFlags {
178-
None = 0,
179-
Signature = 1 << 0, // Obtaining contextual signature
180-
NoConstraints = 1 << 1, // Don't obtain type variable constraints
181-
}
182-
183177
const enum AccessFlags {
184178
None = 0,
185179
NoIndexSignatures = 1 << 0,
@@ -454,9 +448,9 @@ namespace ts {
454448
},
455449
getAugmentedPropertiesOfType,
456450
getRootSymbols,
457-
getContextualType: nodeIn => {
451+
getContextualType: (nodeIn: Expression, contextFlags?: ContextFlags) => {
458452
const node = getParseTreeNode(nodeIn, isExpression);
459-
return node ? getContextualType(node) : undefined;
453+
return node ? getContextualType(node, contextFlags) : undefined;
460454
},
461455
getContextualTypeForObjectLiteralElement: nodeIn => {
462456
const node = getParseTreeNode(nodeIn, isObjectLiteralElementLike);
@@ -10746,7 +10740,7 @@ namespace ts {
1074610740
errorType;
1074710741
}
1074810742
if (symbol.flags & SymbolFlags.Value && isJSDocTypeReference(node)) {
10749-
const jsdocType = getTypeFromJSAlias(node, symbol);
10743+
const jsdocType = getTypeFromJSDocValueReference(node, symbol);
1075010744
if (jsdocType) {
1075110745
return jsdocType;
1075210746
}
@@ -10760,19 +10754,25 @@ namespace ts {
1076010754
}
1076110755

1076210756
/**
10763-
* A JSdoc TypeReference may be to a value imported from commonjs.
10764-
* These should really be aliases, but this special-case code fakes alias resolution
10765-
* by producing a type from a value.
10757+
* A JSdoc TypeReference may be to a value, but resolve it as a type anyway.
10758+
* Note: If the value is imported from commonjs, it should really be an alias,
10759+
* but this function fakes special-case code fakes alias resolution as well.
1076610760
*/
10767-
function getTypeFromJSAlias(node: NodeWithTypeArguments, symbol: Symbol): Type | undefined {
10761+
function getTypeFromJSDocValueReference(node: NodeWithTypeArguments, symbol: Symbol): Type | undefined {
1076810762
const valueType = getTypeOfSymbol(symbol);
10769-
const typeType =
10770-
valueType.symbol &&
10771-
valueType.symbol !== symbol && // Make sure this is a commonjs export by checking that symbol -> type -> symbol doesn't roundtrip.
10772-
getTypeReferenceType(node, valueType.symbol);
10773-
if (typeType) {
10774-
return getSymbolLinks(symbol).resolvedJSDocType = typeType;
10763+
let typeType = valueType;
10764+
if (symbol.valueDeclaration) {
10765+
const decl = getRootDeclaration(symbol.valueDeclaration);
10766+
const isRequireAlias = isVariableDeclaration(decl)
10767+
&& decl.initializer
10768+
&& isCallExpression(decl.initializer)
10769+
&& isRequireCall(decl.initializer, /*requireStringLiteralLikeArgument*/ true)
10770+
&& valueType.symbol;
10771+
if (isRequireAlias) {
10772+
typeType = getTypeReferenceType(node, valueType.symbol);
10773+
}
1077510774
}
10775+
return getSymbolLinks(symbol).resolvedJSDocType = typeType;
1077610776
}
1077710777

1077810778
function getSubstitutionType(typeVariable: TypeVariable, substitute: Type) {
@@ -20948,19 +20948,23 @@ namespace ts {
2094820948
}
2094920949

2095020950
// In a typed function call, an argument or substitution expression is contextually typed by the type of the corresponding parameter.
20951-
function getContextualTypeForArgument(callTarget: CallLikeExpression, arg: Expression): Type | undefined {
20951+
function getContextualTypeForArgument(callTarget: CallLikeExpression, arg: Expression, contextFlags?: ContextFlags): Type | undefined {
2095220952
const args = getEffectiveCallArguments(callTarget);
2095320953
const argIndex = args.indexOf(arg); // -1 for e.g. the expression of a CallExpression, or the tag of a TaggedTemplateExpression
20954-
return argIndex === -1 ? undefined : getContextualTypeForArgumentAtIndex(callTarget, argIndex);
20954+
return argIndex === -1 ? undefined : getContextualTypeForArgumentAtIndex(callTarget, argIndex, contextFlags);
2095520955
}
2095620956

20957-
function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number): Type {
20957+
function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number, contextFlags?: ContextFlags): Type {
2095820958
// If we're already in the process of resolving the given signature, don't resolve again as
2095920959
// that could cause infinite recursion. Instead, return anySignature.
2096020960
const signature = getNodeLinks(callTarget).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(callTarget);
2096120961
if (isJsxOpeningLikeElement(callTarget) && argIndex === 0) {
2096220962
return getEffectiveFirstArgumentForJsxSignature(signature, callTarget);
2096320963
}
20964+
if (contextFlags && contextFlags & ContextFlags.Completion && signature.target) {
20965+
const baseSignature = getBaseSignature(signature.target);
20966+
return intersectTypes(getTypeAtPosition(signature, argIndex), getTypeAtPosition(baseSignature, argIndex));
20967+
}
2096420968
return getTypeAtPosition(signature, argIndex);
2096520969
}
2096620970

@@ -21352,7 +21356,7 @@ namespace ts {
2135221356
}
2135321357
/* falls through */
2135421358
case SyntaxKind.NewExpression:
21355-
return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node);
21359+
return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node, contextFlags);
2135621360
case SyntaxKind.TypeAssertionExpression:
2135721361
case SyntaxKind.AsExpression:
2135821362
return isConstTypeReference((<AssertionExpression>parent).type) ? undefined : getTypeFromTypeNode((<AssertionExpression>parent).type);

src/compiler/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ namespace ts {
18111811
const node = <ForOfStatement>createSynthesizedNode(SyntaxKind.ForOfStatement);
18121812
node.awaitModifier = awaitModifier;
18131813
node.initializer = initializer;
1814-
node.expression = expression;
1814+
node.expression = isCommaSequence(expression) ? createParen(expression) : expression;
18151815
node.statement = asEmbeddedStatement(statement);
18161816
return node;
18171817
}
@@ -4739,7 +4739,7 @@ namespace ts {
47394739
const conditionalPrecedence = getOperatorPrecedence(SyntaxKind.ConditionalExpression, SyntaxKind.QuestionToken);
47404740
const emittedCondition = skipPartiallyEmittedExpressions(condition);
47414741
const conditionPrecedence = getExpressionPrecedence(emittedCondition);
4742-
if (compareValues(conditionPrecedence, conditionalPrecedence) === Comparison.LessThan) {
4742+
if (compareValues(conditionPrecedence, conditionalPrecedence) !== Comparison.GreaterThan) {
47434743
return createParen(condition);
47444744
}
47454745
return condition;

src/compiler/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3371,8 +3371,10 @@ namespace ts {
33713371

33723372
getFullyQualifiedName(symbol: Symbol): string;
33733373
getAugmentedPropertiesOfType(type: Type): Symbol[];
3374+
33743375
getRootSymbols(symbol: Symbol): readonly Symbol[];
33753376
getContextualType(node: Expression): Type | undefined;
3377+
/* @internal */ getContextualType(node: Expression, contextFlags?: ContextFlags): Type | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
33763378
/* @internal */ getContextualTypeForObjectLiteralElement(element: ObjectLiteralElementLike): Type | undefined;
33773379
/* @internal */ getContextualTypeForArgumentAtIndex(call: CallLikeExpression, argIndex: number): Type | undefined;
33783380
/* @internal */ getContextualTypeForJsxAttribute(attribute: JsxAttribute | JsxSpreadAttribute): Type | undefined;
@@ -3532,6 +3534,14 @@ namespace ts {
35323534
Subtype
35333535
}
35343536

3537+
/* @internal */
3538+
export const enum ContextFlags {
3539+
None = 0,
3540+
Signature = 1 << 0, // Obtaining contextual signature
3541+
NoConstraints = 1 << 1, // Don't obtain type variable constraints
3542+
Completion = 1 << 2, // Obtaining constraint type for completion
3543+
}
3544+
35353545
// NOTE: If modifying this enum, must modify `TypeFormatFlags` too!
35363546
export const enum NodeBuilderFlags {
35373547
None = 0,

src/compiler/utilities.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,9 +1819,9 @@ namespace ts {
18191819
* exactly one argument (of the form 'require("name")').
18201820
* This function does not test if the node is in a JavaScript file or not.
18211821
*/
1822-
export function isRequireCall(callExpression: Node, checkArgumentIsStringLiteralLike: true): callExpression is RequireOrImportCall & { expression: Identifier, arguments: [StringLiteralLike] };
1823-
export function isRequireCall(callExpression: Node, checkArgumentIsStringLiteralLike: boolean): callExpression is CallExpression;
1824-
export function isRequireCall(callExpression: Node, checkArgumentIsStringLiteralLike: boolean): callExpression is CallExpression {
1822+
export function isRequireCall(callExpression: Node, requireStringLiteralLikeArgument: true): callExpression is RequireOrImportCall & { expression: Identifier, arguments: [StringLiteralLike] };
1823+
export function isRequireCall(callExpression: Node, requireStringLiteralLikeArgument: boolean): callExpression is CallExpression;
1824+
export function isRequireCall(callExpression: Node, requireStringLiteralLikeArgument: boolean): callExpression is CallExpression {
18251825
if (callExpression.kind !== SyntaxKind.CallExpression) {
18261826
return false;
18271827
}
@@ -1835,7 +1835,7 @@ namespace ts {
18351835
return false;
18361836
}
18371837
const arg = args[0];
1838-
return !checkArgumentIsStringLiteralLike || isStringLiteralLike(arg);
1838+
return !requireStringLiteralLikeArgument || isStringLiteralLike(arg);
18391839
}
18401840

18411841
export function isSingleOrDoubleQuote(charCode: number) {

src/harness/fourslash.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,9 @@ namespace FourSlash {
775775
private verifyCompletionsWorker(options: FourSlashInterface.VerifyCompletionsOptions): void {
776776
const actualCompletions = this.getCompletionListAtCaret({ ...options.preferences, triggerCharacter: options.triggerCharacter })!;
777777
if (!actualCompletions) {
778-
if (ts.hasProperty(options, "exact") && options.exact === undefined) return;
778+
if (ts.hasProperty(options, "exact") && (options.exact === undefined || ts.isArray(options.exact) && !options.exact.length)) {
779+
return;
780+
}
779781
this.raiseError(`No completions at position '${this.currentCaretPosition}'.`);
780782
}
781783

src/lib/dom.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9762,7 +9762,7 @@ interface ImageData {
97629762
declare var ImageData: {
97639763
prototype: ImageData;
97649764
new(width: number, height: number): ImageData;
9765-
new(array: Uint8ClampedArray, width: number, height: number): ImageData;
9765+
new(array: Uint8ClampedArray, width: number, height?: number): ImageData;
97669766
};
97679767

97689768
interface InnerHTML {

src/lib/es5.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -873,12 +873,12 @@ interface DateConstructor {
873873
/**
874874
* Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date.
875875
* @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year.
876-
* @param month The month as an number between 0 and 11 (January to December).
877-
* @param date The date as an number between 1 and 31.
878-
* @param hours Must be supplied if minutes is supplied. An number from 0 to 23 (midnight to 11pm) that specifies the hour.
879-
* @param minutes Must be supplied if seconds is supplied. An number from 0 to 59 that specifies the minutes.
880-
* @param seconds Must be supplied if milliseconds is supplied. An number from 0 to 59 that specifies the seconds.
881-
* @param ms An number from 0 to 999 that specifies the milliseconds.
876+
* @param month The month as a number between 0 and 11 (January to December).
877+
* @param date The date as a number between 1 and 31.
878+
* @param hours Must be supplied if minutes is supplied. A number from 0 to 23 (midnight to 11pm) that specifies the hour.
879+
* @param minutes Must be supplied if seconds is supplied. A number from 0 to 59 that specifies the minutes.
880+
* @param seconds Must be supplied if milliseconds is supplied. A number from 0 to 59 that specifies the seconds.
881+
* @param ms A number from 0 to 999 that specifies the milliseconds.
882882
*/
883883
UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number;
884884
now(): number;

src/lib/webworker.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,7 @@ interface ImageData {
22022202
declare var ImageData: {
22032203
prototype: ImageData;
22042204
new(width: number, height: number): ImageData;
2205-
new(array: Uint8ClampedArray, width: number, height: number): ImageData;
2205+
new(array: Uint8ClampedArray, width: number, height?: number): ImageData;
22062206
};
22072207

22082208
/** This Channel Messaging API interface allows us to create a new message channel and send data through it via its two MessagePort properties. */

0 commit comments

Comments
 (0)