Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 User test baselines have changed for mappedTypeMemberResolution #36755

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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": "3.8.0",
"version": "3.9.0",
"license": "Apache-2.0",
"description": "TypeScript is a language for application scale JavaScript development",
"keywords": [
Expand Down
41 changes: 27 additions & 14 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ namespace ts {
},
getSymbolAtLocation: node => {
node = getParseTreeNode(node);
return node ? getSymbolAtLocation(node) : undefined;
// set ignoreErrors: true because any lookups invoked by the API shouldn't cause any new errors
return node ? getSymbolAtLocation(node, /*ignoreErrors*/ true) : undefined;
},
getShorthandAssignmentValueSymbol: node => {
node = getParseTreeNode(node);
Expand Down Expand Up @@ -13032,7 +13033,7 @@ namespace ts {
* this function should be called in a left folding style, with left = previous result of getSpreadType
* and right = the new element to be spread.
*/
function getSpreadType(left: Type, right: Type, symbol: Symbol | undefined, objectFlags: ObjectFlags, readonly: boolean): Type {
function getSpreadType(left: Type, right: Type, symbol: Symbol | undefined, objectFlags: ObjectFlags, readonly: boolean, isParentTypeNullable?: boolean): Type {
if (left.flags & TypeFlags.Any || right.flags & TypeFlags.Any) {
return anyType;
}
Expand All @@ -13048,16 +13049,16 @@ namespace ts {
if (left.flags & TypeFlags.Union) {
const merged = tryMergeUnionOfObjectTypeAndEmptyObject(left as UnionType, readonly);
if (merged) {
return getSpreadType(merged, right, symbol, objectFlags, readonly);
return getSpreadType(merged, right, symbol, objectFlags, readonly, isParentTypeNullable);
}
return mapType(left, t => getSpreadType(t, right, symbol, objectFlags, readonly));
return mapType(left, t => getSpreadType(t, right, symbol, objectFlags, readonly, isParentTypeNullable));
}
if (right.flags & TypeFlags.Union) {
const merged = tryMergeUnionOfObjectTypeAndEmptyObject(right as UnionType, readonly);
if (merged) {
return getSpreadType(left, merged, symbol, objectFlags, readonly);
return getSpreadType(left, merged, symbol, objectFlags, readonly, maybeTypeOfKind(right, TypeFlags.Nullable));
}
return mapType(right, t => getSpreadType(left, t, symbol, objectFlags, readonly));
return mapType(right, t => getSpreadType(left, t, symbol, objectFlags, readonly, maybeTypeOfKind(right, TypeFlags.Nullable)));
}
if (right.flags & (TypeFlags.BooleanLike | TypeFlags.NumberLike | TypeFlags.BigIntLike | TypeFlags.StringLike | TypeFlags.EnumLike | TypeFlags.NonPrimitive | TypeFlags.Index)) {
return left;
Expand Down Expand Up @@ -13121,6 +13122,14 @@ namespace ts {
result.nameType = getSymbolLinks(leftProp).nameType;
members.set(leftProp.escapedName, result);
}
else if (strictNullChecks &&
!isParentTypeNullable &&
symbol &&
!isFromSpreadAssignment(leftProp, symbol) &&
isFromSpreadAssignment(rightProp, symbol) &&
!maybeTypeOfKind(rightType, TypeFlags.Nullable)) {
error(leftProp.valueDeclaration, Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, unescapeLeadingUnderscores(leftProp.escapedName));
}
}
else {
members.set(leftProp.escapedName, getSpreadSymbol(leftProp, readonly));
Expand Down Expand Up @@ -15901,7 +15910,7 @@ namespace ts {
// with respect to T. We do not report errors here, as we will use the existing
// error result from checking each constituent of the union.
if (source.flags & (TypeFlags.Object | TypeFlags.Intersection) && target.flags & TypeFlags.Union) {
const objectOnlyTarget = extractTypesOfKind(target, TypeFlags.Object);
const objectOnlyTarget = extractTypesOfKind(target, TypeFlags.Object | TypeFlags.Intersection | TypeFlags.Substitution);
if (objectOnlyTarget.flags & TypeFlags.Union) {
const result = typeRelatedToDiscriminatedType(source, objectOnlyTarget as UnionType);
if (result) {
Expand Down Expand Up @@ -15998,7 +16007,7 @@ namespace ts {
// NOTE: See ~/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithDiscriminatedUnion.ts
// for examples.

const sourceProperties = getPropertiesOfObjectType(source);
const sourceProperties = getPropertiesOfType(source);
const sourcePropertiesFiltered = findDiscriminantProperties(sourceProperties, target);
if (!sourcePropertiesFiltered) return Ternary.False;

Expand Down Expand Up @@ -16037,7 +16046,7 @@ namespace ts {
outer: for (const type of target.types) {
for (let i = 0; i < sourcePropertiesFiltered.length; i++) {
const sourceProperty = sourcePropertiesFiltered[i];
const targetProperty = getPropertyOfObjectType(type, sourceProperty.escapedName);
const targetProperty = getPropertyOfType(type, sourceProperty.escapedName);
if (!targetProperty) continue outer;
if (sourceProperty === targetProperty) continue;
// We compare the source property to the target in the context of a single discriminant type.
Expand Down Expand Up @@ -16620,6 +16629,10 @@ namespace ts {
return match === -1 || discriminable.indexOf(/*searchElement*/ true, match + 1) !== -1 ? defaultValue : target.types[match];
}

function isFromSpreadAssignment(prop: Symbol, container: Symbol) {
return prop.valueDeclaration?.parent !== container.valueDeclaration;
}

/**
* A type is 'weak' if it is an object type with at least one optional property
* and no required properties, call/construct signatures or index signatures
Expand Down Expand Up @@ -24886,7 +24899,7 @@ namespace ts {
}
}

return produceDiagnostics || !args ? resolveErrorCall(node) : getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray);
return getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray);

function chooseOverload(candidates: Signature[], relation: Map<RelationComparisonResult>, signatureHelpTrailingComma = false) {
candidatesForArgumentError = undefined;
Expand Down Expand Up @@ -25178,7 +25191,7 @@ namespace ts {
if (node.arguments.length === 1) {
const text = getSourceFileOfNode(node).text;
if (isLineBreak(text.charCodeAt(skipTrivia(text, node.expression.end, /* stopAfterLineBreak */ true) - 1))) {
relatedInformation = createDiagnosticForNode(node.expression, Diagnostics.It_is_highly_likely_that_you_are_missing_a_semicolon);
relatedInformation = createDiagnosticForNode(node.expression, Diagnostics.Are_you_missing_a_semicolon);
}
}
invocationError(node.expression, apparentType, SignatureKind.Call, relatedInformation);
Expand Down Expand Up @@ -34400,7 +34413,7 @@ namespace ts {
return undefined;
}

function getSymbolAtLocation(node: Node): Symbol | undefined {
function getSymbolAtLocation(node: Node, ignoreErrors?: boolean): Symbol | undefined {
if (node.kind === SyntaxKind.SourceFile) {
return isExternalModule(<SourceFile>node) ? getMergedSymbol(node.symbol) : undefined;
}
Expand Down Expand Up @@ -34484,7 +34497,7 @@ namespace ts {
((isInJSFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteralLike*/ false)) || isImportCall(node.parent)) ||
(isLiteralTypeNode(node.parent) && isLiteralImportTypeNode(node.parent.parent) && node.parent.parent.argument === node.parent)
) {
return resolveExternalModuleName(node, <LiteralExpression>node);
return resolveExternalModuleName(node, <LiteralExpression>node, ignoreErrors);
}
if (isCallExpression(parent) && isBindableObjectDefinePropertyCall(parent) && parent.arguments[1] === node) {
return getSymbolOfNode(parent);
Expand All @@ -34506,7 +34519,7 @@ namespace ts {
case SyntaxKind.ClassKeyword:
return getSymbolOfNode(node.parent);
case SyntaxKind.ImportType:
return isLiteralImportTypeNode(node) ? getSymbolAtLocation(node.argument.literal) : undefined;
return isLiteralImportTypeNode(node) ? getSymbolAtLocation(node.argument.literal, ignoreErrors) : undefined;

case SyntaxKind.ExportKeyword:
return isExportAssignment(node.parent) ? Debug.assertDefined(node.parent.symbol) : undefined;
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 = "3.8";
export const versionMajorMinor = "3.9";
/** The version of the TypeScript compiler release */
export const version = `${versionMajorMinor}.0-dev`;

Expand Down
22 changes: 21 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,14 @@
"category": "Error",
"code": 1380
},
"Unexpected token. Did you mean `{'}'}` or `&rbrace;`?": {
"category": "Error",
"code": 1381
},
"Unexpected token. Did you mean `{'>'}` or `&gt;`?": {
"category": "Error",
"code": 1382
},

"The types of '{0}' are incompatible between these types.": {
"category": "Error",
Expand Down Expand Up @@ -2683,7 +2691,7 @@
"category": "Error",
"code": 2733
},
"It is highly likely that you are missing a semicolon.": {
"Are you missing a semicolon?": {
"category": "Error",
"code": 2734
},
Expand Down Expand Up @@ -2879,6 +2887,10 @@
"category": "Message",
"code": 2782
},
"'{0}' is specified more than once, so this usage will be overwritten.": {
"category": "Error",
"code": 2783
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
Expand Down Expand Up @@ -5457,6 +5469,14 @@
"category": "Message",
"code": 95099
},
"Convert invalid character to its html entity code": {
"category": "Message",
"code": 95100
},
"Wrap invalid character in an expression container": {
"category": "Message",
"code": 95101
},

"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
"category": "Error",
Expand Down
10 changes: 6 additions & 4 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7017,10 +7017,12 @@ namespace ts {
comments.push(text);
indent += text.length;
}
if (initialMargin) {
if (initialMargin !== undefined) {
// jump straight to saving comments if there is some initial indentation
pushComment(initialMargin);
state = JSDocState.SavingComments;
if (initialMargin !== "") {
pushComment(initialMargin);
}
state = JSDocState.SawAsterisk;
}
let tok = token() as JSDocSyntaxKind;
loop: while (true) {
Expand Down Expand Up @@ -7558,7 +7560,7 @@ namespace ts {
const typeParameter = <TypeParameterDeclaration>createNode(SyntaxKind.TypeParameter);
typeParameter.name = parseJSDocIdentifierName(Diagnostics.Unexpected_token_A_type_parameter_name_was_expected_without_curly_braces);
finishNode(typeParameter);
skipWhitespace();
skipWhitespaceOrAsterisk();
typeParameters.push(typeParameter);
} while (parseOptionalJsdoc(SyntaxKind.CommaToken));

Expand Down
6 changes: 6 additions & 0 deletions src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,12 @@ namespace ts {
}
break;
}
if (char === CharacterCodes.greaterThan) {
error(Diagnostics.Unexpected_token_Did_you_mean_or_gt, pos, 1);
}
if (char === CharacterCodes.closeBrace) {
error(Diagnostics.Unexpected_token_Did_you_mean_or_rbrace, pos, 1);
}

if (lastNonWhitespace > 0) lastNonWhitespace++;

Expand Down
2 changes: 2 additions & 0 deletions src/server/scriptInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ namespace ts.server {
/*@internal*/
export function isDynamicFileName(fileName: NormalizedPath) {
return fileName[0] === "^" ||
((stringContains(fileName, "walkThroughSnippet:/") || stringContains(fileName, "untitled:/")) &&
getBaseFileName(fileName)[0] === "^") ||
(stringContains(fileName, ":^") && !stringContains(fileName, directorySeparator));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ namespace ts.codefix {
// so duplicates cannot occur.
const abstractAndNonPrivateExtendsSymbols = checker.getPropertiesOfType(instantiatedExtendsType).filter(symbolPointsToNonPrivateAndAbstractMember);

createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, context, preferences, member => changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, member));
const importAdder = createImportAdder(sourceFile, context.program, preferences, context.host);
createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, context, preferences, importAdder, member => changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, member));
importAdder.writeFixes(changeTracker);
}

function symbolPointsToNonPrivateAndAbstractMember(symbol: Symbol): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ namespace ts.codefix {
createMissingIndexSignatureDeclaration(implementedType, IndexKind.String);
}

createMissingMemberNodes(classDeclaration, nonPrivateAndNotExistedInHeritageClauseMembers, context, preferences, member => insertInterfaceMemberNode(sourceFile, classDeclaration, member));
const importAdder = createImportAdder(sourceFile, context.program, preferences, context.host);
createMissingMemberNodes(classDeclaration, nonPrivateAndNotExistedInHeritageClauseMembers, context, preferences, importAdder, member => insertInterfaceMemberNode(sourceFile, classDeclaration, member));
importAdder.writeFixes(changeTracker);

function createMissingIndexSignatureDeclaration(type: InterfaceType, kind: IndexKind): void {
const indexInfoOfKind = checker.getIndexInfoOfType(type, kind);
Expand Down
42 changes: 42 additions & 0 deletions src/services/codefixes/fixInvalidJsxCharacters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* @internal */
namespace ts.codefix {
const fixIdHtmlEntity = "invalidJsxCharactersConvertToHtmlEntity";
const fixIdExpression = "invalidJsxCharactersConvertToExpression";

const errorCodes = [Diagnostics.Unexpected_token_Did_you_mean_or_gt.code, Diagnostics.Unexpected_token_Did_you_mean_or_rbrace.code];

registerCodeFix({
errorCodes,
getCodeActions: context => {
const { sourceFile, span } = context;
const changeToExpression = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, span.start, /* useHtmlEntity */ false));
const changeToHtmlEntity = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, span.start, /* useHtmlEntity */ true));
return [
createCodeFixActionWithoutFixAll(fixIdExpression, changeToExpression, Diagnostics.Wrap_invalid_character_in_an_expression_container),
createCodeFixAction(fixIdHtmlEntity, changeToHtmlEntity, Diagnostics.Convert_invalid_character_to_its_html_entity_code, fixIdHtmlEntity, Diagnostics.Convert_invalid_character_to_its_html_entity_code),
];
},
fixIds: [fixIdExpression, fixIdHtmlEntity],
});

const htmlEntity = {
">": "&gt;",
"}": "&rbrace;",
};
function isValidCharacter(character: string): character is keyof typeof htmlEntity {
return hasProperty(htmlEntity, character);
}

function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, start: number, useHtmlEntity: boolean) {
const character = sourceFile.getText()[start];
// sanity check
if (!isValidCharacter(character)) {
return;
}

const replacement = useHtmlEntity
? htmlEntity[character]
: `{'${character}'}`;
changes.replaceRangeWithText(sourceFile, { pos: start, end: start + 1 }, replacement);
}
}
Loading