Merge branch 'master' into rootDir

This commit is contained in:
Sheetal Nandi committed 2019-10-17 12:54:26 -07:00
commit fde10a2494
53 files changed
+10730 -10292

No files matched your search

+1 -3
View File
@@ -251,9 +251,7 @@ namespace ts {
state.seenAffectedFiles = createMap<true>();
}
state.emittedBuildInfo = !state.changedFilesSet.size &&
!state.affectedFilesPendingEmit;
state.emittedBuildInfo = !state.changedFilesSet.size && !state.affectedFilesPendingEmit;
return state;
}
+27 -23
View File
@@ -174,12 +174,6 @@ namespace ts {
IsForSignatureHelp = 1 << 4, // Call resolution for purposes of signature help
}
const enum ContextFlags {
None = 0,
Signature = 1 << 0, // Obtaining contextual signature
NoConstraints = 1 << 1, // Don't obtain type variable constraints
}
const enum AccessFlags {
None = 0,
NoIndexSignatures = 1 << 0,
@@ -454,9 +448,9 @@ namespace ts {
},
getAugmentedPropertiesOfType,
getRootSymbols,
getContextualType: nodeIn => {
getContextualType: (nodeIn: Expression, contextFlags?: ContextFlags) => {
const node = getParseTreeNode(nodeIn, isExpression);
return node ? getContextualType(node) : undefined;
return node ? getContextualType(node, contextFlags) : undefined;
},
getContextualTypeForObjectLiteralElement: nodeIn => {
const node = getParseTreeNode(nodeIn, isObjectLiteralElementLike);
@@ -10746,7 +10740,7 @@ namespace ts {
errorType;
}
if (symbol.flags & SymbolFlags.Value && isJSDocTypeReference(node)) {
const jsdocType = getTypeFromJSAlias(node, symbol);
const jsdocType = getTypeFromJSDocValueReference(node, symbol);
if (jsdocType) {
return jsdocType;
}
@@ -10760,19 +10754,25 @@ namespace ts {
}
/**
* A JSdoc TypeReference may be to a value imported from commonjs.
* These should really be aliases, but this special-case code fakes alias resolution
* by producing a type from a value.
* A JSdoc TypeReference may be to a value, but resolve it as a type anyway.
* Note: If the value is imported from commonjs, it should really be an alias,
* but this function fakes special-case code fakes alias resolution as well.
*/
function getTypeFromJSAlias(node: NodeWithTypeArguments, symbol: Symbol): Type | undefined {
function getTypeFromJSDocValueReference(node: NodeWithTypeArguments, symbol: Symbol): Type | undefined {
const valueType = getTypeOfSymbol(symbol);
const typeType =
valueType.symbol &&
valueType.symbol !== symbol && // Make sure this is a commonjs export by checking that symbol -> type -> symbol doesn't roundtrip.
getTypeReferenceType(node, valueType.symbol);
if (typeType) {
return getSymbolLinks(symbol).resolvedJSDocType = typeType;
let typeType = valueType;
if (symbol.valueDeclaration) {
const decl = getRootDeclaration(symbol.valueDeclaration);
const isRequireAlias = isVariableDeclaration(decl)
&& decl.initializer
&& isCallExpression(decl.initializer)
&& isRequireCall(decl.initializer, /*requireStringLiteralLikeArgument*/ true)
&& valueType.symbol;
if (isRequireAlias) {
typeType = getTypeReferenceType(node, valueType.symbol);
}
}
return getSymbolLinks(symbol).resolvedJSDocType = typeType;
}
function getSubstitutionType(typeVariable: TypeVariable, substitute: Type) {
@@ -20948,19 +20948,23 @@ namespace ts {
}
// In a typed function call, an argument or substitution expression is contextually typed by the type of the corresponding parameter.
function getContextualTypeForArgument(callTarget: CallLikeExpression, arg: Expression): Type | undefined {
function getContextualTypeForArgument(callTarget: CallLikeExpression, arg: Expression, contextFlags?: ContextFlags): Type | undefined {
const args = getEffectiveCallArguments(callTarget);
const argIndex = args.indexOf(arg); // -1 for e.g. the expression of a CallExpression, or the tag of a TaggedTemplateExpression
return argIndex === -1 ? undefined : getContextualTypeForArgumentAtIndex(callTarget, argIndex);
return argIndex === -1 ? undefined : getContextualTypeForArgumentAtIndex(callTarget, argIndex, contextFlags);
}
function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number): Type {
function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number, contextFlags?: ContextFlags): Type {
// If we're already in the process of resolving the given signature, don't resolve again as
// that could cause infinite recursion. Instead, return anySignature.
const signature = getNodeLinks(callTarget).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(callTarget);
if (isJsxOpeningLikeElement(callTarget) && argIndex === 0) {
return getEffectiveFirstArgumentForJsxSignature(signature, callTarget);
}
if (contextFlags && contextFlags & ContextFlags.Completion && signature.target) {
const baseSignature = getBaseSignature(signature.target);
return intersectTypes(getTypeAtPosition(signature, argIndex), getTypeAtPosition(baseSignature, argIndex));
}
return getTypeAtPosition(signature, argIndex);
}
@@ -21352,7 +21356,7 @@ namespace ts {
}
/* falls through */
case SyntaxKind.NewExpression:
return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node);
return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node, contextFlags);
case SyntaxKind.TypeAssertionExpression:
case SyntaxKind.AsExpression:
return isConstTypeReference((<AssertionExpression>parent).type) ? undefined : getTypeFromTypeNode((<AssertionExpression>parent).type);
+2 -2
View File
@@ -1811,7 +1811,7 @@ namespace ts {
const node = <ForOfStatement>createSynthesizedNode(SyntaxKind.ForOfStatement);
node.awaitModifier = awaitModifier;
node.initializer = initializer;
node.expression = expression;
node.expression = isCommaSequence(expression) ? createParen(expression) : expression;
node.statement = asEmbeddedStatement(statement);
return node;
}
@@ -4739,7 +4739,7 @@ namespace ts {
const conditionalPrecedence = getOperatorPrecedence(SyntaxKind.ConditionalExpression, SyntaxKind.QuestionToken);
const emittedCondition = skipPartiallyEmittedExpressions(condition);
const conditionPrecedence = getExpressionPrecedence(emittedCondition);
if (compareValues(conditionPrecedence, conditionalPrecedence) === Comparison.LessThan) {
if (compareValues(conditionPrecedence, conditionalPrecedence) !== Comparison.GreaterThan) {
return createParen(condition);
}
return condition;
+10
View File
@@ -3371,8 +3371,10 @@ namespace ts {
getFullyQualifiedName(symbol: Symbol): string;
getAugmentedPropertiesOfType(type: Type): Symbol[];
getRootSymbols(symbol: Symbol): readonly Symbol[];
getContextualType(node: Expression): Type | undefined;
/* @internal */ getContextualType(node: Expression, contextFlags?: ContextFlags): Type | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
/* @internal */ getContextualTypeForObjectLiteralElement(element: ObjectLiteralElementLike): Type | undefined;
/* @internal */ getContextualTypeForArgumentAtIndex(call: CallLikeExpression, argIndex: number): Type | undefined;
/* @internal */ getContextualTypeForJsxAttribute(attribute: JsxAttribute | JsxSpreadAttribute): Type | undefined;
@@ -3532,6 +3534,14 @@ namespace ts {
Subtype
}
/* @internal */
export const enum ContextFlags {
None = 0,
Signature = 1 << 0, // Obtaining contextual signature
NoConstraints = 1 << 1, // Don't obtain type variable constraints
Completion = 1 << 2, // Obtaining constraint type for completion
}
// NOTE: If modifying this enum, must modify `TypeFormatFlags` too!
export const enum NodeBuilderFlags {
None = 0,
+4 -4
View File
@@ -1819,9 +1819,9 @@ namespace ts {
* exactly one argument (of the form 'require("name")').
* This function does not test if the node is in a JavaScript file or not.
*/
export function isRequireCall(callExpression: Node, checkArgumentIsStringLiteralLike: true): callExpression is RequireOrImportCall & { expression: Identifier, arguments: [StringLiteralLike] };
export function isRequireCall(callExpression: Node, checkArgumentIsStringLiteralLike: boolean): callExpression is CallExpression;
export function isRequireCall(callExpression: Node, checkArgumentIsStringLiteralLike: boolean): callExpression is CallExpression {
export function isRequireCall(callExpression: Node, requireStringLiteralLikeArgument: true): callExpression is RequireOrImportCall & { expression: Identifier, arguments: [StringLiteralLike] };
export function isRequireCall(callExpression: Node, requireStringLiteralLikeArgument: boolean): callExpression is CallExpression;
export function isRequireCall(callExpression: Node, requireStringLiteralLikeArgument: boolean): callExpression is CallExpression {
if (callExpression.kind !== SyntaxKind.CallExpression) {
return false;
}
@@ -1835,7 +1835,7 @@ namespace ts {
return false;
}
const arg = args[0];
return !checkArgumentIsStringLiteralLike || isStringLiteralLike(arg);
return !requireStringLiteralLikeArgument || isStringLiteralLike(arg);
}
export function isSingleOrDoubleQuote(charCode: number) {