Skip to content

Commit

Permalink
Merge branch 'main' into cacheModuleResolution
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Aug 10, 2022
2 parents e06b492 + 3c3909b commit 7612a5e
Show file tree
Hide file tree
Showing 290 changed files with 5,288 additions and 2,156 deletions.
220 changes: 110 additions & 110 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "typescript",
"author": "Microsoft Corp.",
"homepage": "https://www.typescriptlang.org/",
"version": "4.8.0",
"version": "4.9.0",
"license": "Apache-2.0",
"description": "TypeScript is a language for application scale JavaScript development",
"keywords": [
Expand Down
47 changes: 35 additions & 12 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,9 @@ namespace ts {
case SyntaxKind.BindingElement:
bindBindingElementFlow(node as BindingElement);
break;
case SyntaxKind.Parameter:
bindParameterFlow(node as ParameterDeclaration);
break;
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.ArrayLiteralExpression:
case SyntaxKind.PropertyAssignment:
Expand Down Expand Up @@ -1655,20 +1658,40 @@ namespace ts {
}

function bindBindingElementFlow(node: BindingElement) {
if (isBindingPattern(node.name)) {
// When evaluating a binding pattern, the initializer is evaluated before the binding pattern, per:
// - https://tc39.es/ecma262/#sec-destructuring-binding-patterns-runtime-semantics-iteratorbindinginitialization
// - `BindingElement: BindingPattern Initializer?`
// - https://tc39.es/ecma262/#sec-runtime-semantics-keyedbindinginitialization
// - `BindingElement: BindingPattern Initializer?`
bind(node.dotDotDotToken);
bind(node.propertyName);
bind(node.initializer);
bind(node.name);
// When evaluating a binding pattern, the initializer is evaluated before the binding pattern, per:
// - https://tc39.es/ecma262/#sec-destructuring-binding-patterns-runtime-semantics-iteratorbindinginitialization
// - `BindingElement: BindingPattern Initializer?`
// - https://tc39.es/ecma262/#sec-runtime-semantics-keyedbindinginitialization
// - `BindingElement: BindingPattern Initializer?`
bind(node.dotDotDotToken);
bind(node.propertyName);
bindInitializer(node.initializer);
bind(node.name);
}

function bindParameterFlow(node: ParameterDeclaration) {
bindEach(node.modifiers);
bind(node.dotDotDotToken);
bind(node.questionToken);
bind(node.type);
bindInitializer(node.initializer);
bind(node.name);
}

// a BindingElement/Parameter does not have side effects if initializers are not evaluated and used. (see GH#49759)
function bindInitializer(node: Expression | undefined) {
if (!node) {
return;
}
else {
bindEachChild(node);
const entryFlow = currentFlow;
bind(node);
if (entryFlow === unreachableFlow || entryFlow === currentFlow) {
return;
}
const exitFlow = createBranchLabel();
addAntecedent(exitFlow, entryFlow);
addAntecedent(exitFlow, currentFlow);
currentFlow = finishFlowLabel(exitFlow);
}

function bindJSDocTypeAlias(node: JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag) {
Expand Down
63 changes: 44 additions & 19 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ namespace ts {
function mergeSymbolTable(target: SymbolTable, source: SymbolTable, unidirectional = false) {
source.forEach((sourceSymbol, id) => {
const targetSymbol = target.get(id);
target.set(id, targetSymbol ? mergeSymbol(targetSymbol, sourceSymbol, unidirectional) : sourceSymbol);
target.set(id, targetSymbol ? mergeSymbol(targetSymbol, sourceSymbol, unidirectional) : getMergedSymbol(sourceSymbol));
});
}

Expand Down Expand Up @@ -9065,10 +9065,8 @@ namespace ts {
return getReturnTypeOfSignature(getterSignature);
}
}
if (isInJSFile(declaration)) {
const type = getParameterTypeOfTypeTag(func, declaration);
if (type) return type;
}
const parameterTypeOfTypeTag = getParameterTypeOfTypeTag(func, declaration);
if (parameterTypeOfTypeTag) return parameterTypeOfTypeTag;
// Use contextual parameter type if one is available
const type = declaration.symbol.escapedName === InternalSymbolName.This ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration);
if (type) {
Expand Down Expand Up @@ -13117,7 +13115,14 @@ namespace ts {
continue;
}
}
result.push(getSignatureFromDeclaration(decl));
// If this is a function or method declaration, get the signature from the @type tag for the sake of optional parameters.
// Exclude contextually-typed kinds because we already apply the @type tag to the context, plus applying it here to the initializer would supress checks that the two are compatible.
result.push(
(!isFunctionExpressionOrArrowFunction(decl) &&
!isObjectLiteralMethod(decl) &&
getSignatureOfTypeTag(decl)) ||
getSignatureFromDeclaration(decl)
);
}
return result;
}
Expand Down Expand Up @@ -13152,7 +13157,7 @@ namespace ts {
else {
const type = signature.declaration && getEffectiveReturnTypeNode(signature.declaration);
let jsdocPredicate: TypePredicate | undefined;
if (!type && isInJSFile(signature.declaration)) {
if (!type) {
const jsdocSignature = getSignatureOfTypeTag(signature.declaration!);
if (jsdocSignature && signature !== jsdocSignature) {
jsdocPredicate = getTypePredicateOfSignature(jsdocSignature);
Expand Down Expand Up @@ -17470,8 +17475,7 @@ namespace ts {
}

function isContextSensitiveFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean {
return (!isFunctionDeclaration(node) || isInJSFile(node) && !!getTypeForDeclarationFromJSDocComment(node)) &&
(hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node));
return hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node);
}

function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) {
Expand All @@ -17480,7 +17484,7 @@ namespace ts {
}

function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration {
return (isInJSFile(func) && isFunctionDeclaration(func) || isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) &&
return (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) &&
isContextSensitiveFunctionLikeDeclaration(func);
}

Expand Down Expand Up @@ -28163,16 +28167,31 @@ namespace ts {
// If object literal is contextually typed by the implied type of a binding pattern, augment the result
// type with those properties for which the binding pattern specifies a default value.
// If the object literal is spread into another object literal, skip this step and let the top-level object
// literal handle it instead.
if (contextualTypeHasPattern && node.parent.kind !== SyntaxKind.SpreadAssignment) {
for (const prop of getPropertiesOfType(contextualType)) {
if (!propertiesTable.get(prop.escapedName) && !getPropertyOfType(spread, prop.escapedName)) {
if (!(prop.flags & SymbolFlags.Optional)) {
error(prop.valueDeclaration || (prop as TransientSymbol).bindingElement,
Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value);
// literal handle it instead. Note that this might require full traversal to the root pattern's parent
// as it's the guaranteed to be the common ancestor of the pattern node and the current object node.
// It's not possible to check if the immediate parent node is a spread assignment
// since the type flows in non-obvious ways through conditional expressions, IIFEs and more.
if (contextualTypeHasPattern) {
const rootPatternParent = findAncestor(contextualType.pattern!.parent, n =>
n.kind === SyntaxKind.VariableDeclaration ||
n.kind === SyntaxKind.BinaryExpression ||
n.kind === SyntaxKind.Parameter
);
const spreadOrOutsideRootObject = findAncestor(node, n =>
n === rootPatternParent ||
n.kind === SyntaxKind.SpreadAssignment
)!;

if (spreadOrOutsideRootObject.kind !== SyntaxKind.SpreadAssignment) {
for (const prop of getPropertiesOfType(contextualType)) {
if (!propertiesTable.get(prop.escapedName) && !getPropertyOfType(spread, prop.escapedName)) {
if (!(prop.flags & SymbolFlags.Optional)) {
error(prop.valueDeclaration || (prop as TransientSymbol).bindingElement,
Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value);
}
propertiesTable.set(prop.escapedName, prop);
propertiesArray.push(prop);
}
propertiesTable.set(prop.escapedName, prop);
propertiesArray.push(prop);
}
}
}
Expand Down Expand Up @@ -42533,6 +42552,12 @@ namespace ts {
return resolveJSDocMemberName(name, /*ignoreErrors*/ false, getSymbolOfNode(container));
}
}
if (result && isJSDoc) {
const container = getJSDocHost(name);
if (container && isEnumMember(container) && container === result.valueDeclaration) {
return resolveEntityName(name, meaning, /*ignoreErrors*/ true, /* dontResolveAlias */ true, getSourceFileOfNode(container)) || result;
}
}
return result;
}
else if (isPrivateIdentifier(name)) {
Expand Down
11 changes: 8 additions & 3 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,19 +778,24 @@ namespace ts {
return [] as any as SortedArray<T>; // TODO: GH#19873
}

export function insertSorted<T>(array: SortedArray<T>, insert: T, compare: Comparer<T>, allowDuplicates?: boolean): void {
export function insertSorted<T>(array: SortedArray<T>, insert: T, compare: Comparer<T>, allowDuplicates?: boolean): boolean {
if (array.length === 0) {
array.push(insert);
return;
return true;
}

const insertIndex = binarySearch(array, insert, identity, compare);
if (insertIndex < 0) {
array.splice(~insertIndex, 0, insert);
return true;
}
else if (allowDuplicates) {

if (allowDuplicates) {
array.splice(insertIndex, 0, insert);
return true;
}

return false;
}

export function sortAndDeduplicate<T>(array: readonly string[]): SortedReadonlyArray<string>;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/corePublic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ts {
// WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
// If changing the text in this section, be sure to test `configurePrerelease` too.
export const versionMajorMinor = "4.8";
export const versionMajorMinor = "4.9";
// The following is baselined as a literal template type without intervention
/** The version of the TypeScript compiler release */
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
Expand Down
8 changes: 6 additions & 2 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1217,14 +1217,18 @@ namespace ts {

const previousNeedsDeclare = needsDeclare;
switch (input.kind) {
case SyntaxKind.TypeAliasDeclaration: // Type aliases get `declare`d if need be (for legacy support), but that's all
return cleanup(factory.updateTypeAliasDeclaration(
case SyntaxKind.TypeAliasDeclaration: {
needsDeclare = false;
const clean = cleanup(factory.updateTypeAliasDeclaration(
input,
ensureModifiers(input),
input.name,
visitNodes(input.typeParameters, visitDeclarationSubtree, isTypeParameterDeclaration),
visitNode(input.type, visitDeclarationSubtree, isTypeNode)
));
needsDeclare = previousNeedsDeclare;
return clean;
}
case SyntaxKind.InterfaceDeclaration: {
return cleanup(factory.updateInterfaceDeclaration(
input,
Expand Down
14 changes: 14 additions & 0 deletions src/compiler/transformers/module/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,20 @@ namespace ts {
factory.createAssignment(importVariableName, parameterName)
)
);
if (hasSyntacticModifier(entry, ModifierFlags.Export)) {
statements.push(
factory.createExpressionStatement(
factory.createCallExpression(
exportFunction,
/*typeArguments*/ undefined,
[
factory.createStringLiteral(idText(importVariableName)),
parameterName,
]
)
)
);
}
break;

case SyntaxKind.ExportDeclaration:
Expand Down
Loading

0 comments on commit 7612a5e

Please sign in to comment.