Skip to content

Commit 756efd2

Browse files
DanielRosenwasserAndaristsheetalkamatjakebailey
authored
Fixes for release-5.3. (#56424)
Co-authored-by: Mateusz Burzyński <[email protected]> Co-authored-by: Sheetal Nandi <[email protected]> Co-authored-by: Jake Bailey <[email protected]>
1 parent 88f80c7 commit 756efd2

35 files changed

+3337
-37
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "typescript",
33
"author": "Microsoft Corp.",
44
"homepage": "https://www.typescriptlang.org/",
5-
"version": "5.3.1-rc",
5+
"version": "5.3.2",
66
"license": "Apache-2.0",
77
"description": "TypeScript is a language for application scale JavaScript development",
88
"keywords": [

Diff for: src/compiler/checker.ts

+10-13
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
18681868
const nodeLinks = getNodeLinks(node);
18691869
cachedResolvedSignatures.push([nodeLinks, nodeLinks.resolvedSignature] as const);
18701870
nodeLinks.resolvedSignature = undefined;
1871-
if (isFunctionLike(node)) {
1871+
if (isFunctionExpressionOrArrowFunction(node)) {
18721872
const symbolLinks = getSymbolLinks(getSymbolOfDeclaration(node));
18731873
const type = symbolLinks.type;
18741874
cachedTypes.push([symbolLinks, type] as const);
@@ -6949,6 +6949,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
69496949
context.symbolDepth!.set(id, depth + 1);
69506950
}
69516951
context.visitedTypes.add(typeId);
6952+
const prevTrackedSymbols = context.trackedSymbols;
6953+
context.trackedSymbols = undefined;
69526954
const startLength = context.approximateLength;
69536955
const result = transform(type);
69546956
const addedLength = context.approximateLength - startLength;
@@ -6964,6 +6966,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
69646966
if (id) {
69656967
context.symbolDepth!.set(id, depth!);
69666968
}
6969+
context.trackedSymbols = prevTrackedSymbols;
69676970
return result;
69686971

69696972
function deepCloneOrReuseNode<T extends Node>(node: T): T {
@@ -7312,7 +7315,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
73127315

73137316
if (propertySymbol.flags & SymbolFlags.Accessor) {
73147317
const writeType = getWriteTypeOfSymbol(propertySymbol);
7315-
if (propertyType !== writeType) {
7318+
if (propertyType !== writeType && !isErrorType(propertyType) && !isErrorType(writeType)) {
73167319
const getterDeclaration = getDeclarationOfKind<GetAccessorDeclaration>(propertySymbol, SyntaxKind.GetAccessor)!;
73177320
const getterSignature = getSignatureFromDeclaration(getterDeclaration);
73187321
typeElements.push(
@@ -8299,7 +8302,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
82998302
return factory.createStringLiteral(name, !!singleQuote);
83008303
}
83018304
if (isNumericLiteralName(name) && startsWith(name, "-")) {
8302-
return factory.createComputedPropertyName(factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(+name))));
8305+
return factory.createComputedPropertyName(factory.createNumericLiteral(+name));
83038306
}
83048307
return createPropertyNameNodeForIdentifierOrLiteral(name, getEmitScriptTarget(compilerOptions), singleQuote, stringNamed, isMethod);
83058308
}
@@ -38953,14 +38956,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3895338956
return hasSkipDirectInferenceFlag(node) ?
3895438957
blockedStringType :
3895538958
getFreshTypeOfLiteralType(getStringLiteralType((node as StringLiteralLike).text));
38956-
case SyntaxKind.NumericLiteral: {
38959+
case SyntaxKind.NumericLiteral:
3895738960
checkGrammarNumericLiteral(node as NumericLiteral);
38958-
const value = +(node as NumericLiteral).text;
38959-
if (!isFinite(value)) {
38960-
return numberType;
38961-
}
38962-
return getFreshTypeOfLiteralType(getNumberLiteralType(value));
38963-
}
38961+
return getFreshTypeOfLiteralType(getNumberLiteralType(+(node as NumericLiteral).text));
3896438962
case SyntaxKind.BigIntLiteral:
3896538963
checkGrammarBigIntLiteral(node as BigIntLiteral);
3896638964
return getFreshTypeOfLiteralType(getBigIntLiteralType({
@@ -47883,9 +47881,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4788347881
if (enumResult) return enumResult;
4788447882
const literalValue = (type as LiteralType).value;
4788547883
return typeof literalValue === "object" ? factory.createBigIntLiteral(literalValue) :
47886-
typeof literalValue === "string" ? factory.createStringLiteral(literalValue) :
47887-
literalValue < 0 ? factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(literalValue))) :
47888-
factory.createNumericLiteral(literalValue);
47884+
typeof literalValue === "number" ? factory.createNumericLiteral(literalValue) :
47885+
factory.createStringLiteral(literalValue);
4788947886
}
4789047887

4789147888
function createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, tracker: SymbolTracker) {

Diff for: src/compiler/corePublic.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const versionMajorMinor = "5.3";
44
// The following is baselined as a literal template type without intervention
55
/** The version of the TypeScript compiler release */
66
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
7-
export const version = "5.3.1-rc" as string;
7+
export const version = "5.3.2" as string;
88

99
/**
1010
* Type of objects whose values are all of the same type.

Diff for: src/compiler/factory/nodeFactory.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import {
4444
CaseOrDefaultClause,
4545
cast,
4646
CatchClause,
47-
CharacterCodes,
4847
ClassDeclaration,
4948
ClassElement,
5049
ClassExpression,
@@ -1254,10 +1253,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
12541253

12551254
// @api
12561255
function createNumericLiteral(value: string | number, numericLiteralFlags: TokenFlags = TokenFlags.None): NumericLiteral {
1257-
const text = typeof value === "number" ? value + "" : value;
1258-
Debug.assert(text.charCodeAt(0) !== CharacterCodes.minus, "Negative numbers should be created in combination with createPrefixUnaryExpression");
12591256
const node = createBaseDeclaration<NumericLiteral>(SyntaxKind.NumericLiteral);
1260-
node.text = text;
1257+
node.text = typeof value === "number" ? value + "" : value;
12611258
node.numericLiteralFlags = numericLiteralFlags;
12621259
if (numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier) node.transformFlags |= TransformFlags.ContainsES2015;
12631260
return node;

Diff for: src/compiler/transformers/declarations.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -1798,14 +1798,7 @@ export function transformDeclarations(context: TransformationContext) {
17981798
if (shouldStripInternal(m)) return;
17991799
// Rewrite enum values to their constants, if available
18001800
const constValue = resolver.getConstantValue(m);
1801-
const newInitializer = constValue === undefined
1802-
? undefined
1803-
: typeof constValue === "string"
1804-
? factory.createStringLiteral(constValue)
1805-
: constValue < 0
1806-
? factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(constValue)))
1807-
: factory.createNumericLiteral(constValue);
1808-
return preserveJsDoc(factory.updateEnumMember(m, m.name, newInitializer), m);
1801+
return preserveJsDoc(factory.updateEnumMember(m, m.name, constValue !== undefined ? typeof constValue === "string" ? factory.createStringLiteral(constValue) : factory.createNumericLiteral(constValue) : undefined), m);
18091802
})),
18101803
));
18111804
}

Diff for: src/compiler/transformers/generators.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
25242524
labelExpressions = [];
25252525
}
25262526

2527-
const expression = factory.createNumericLiteral(Number.MAX_SAFE_INTEGER);
2527+
const expression = factory.createNumericLiteral(-1);
25282528
if (labelExpressions[label] === undefined) {
25292529
labelExpressions[label] = [expression];
25302530
}

Diff for: src/compiler/transformers/ts.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1901,9 +1901,7 @@ export function transformTypeScript(context: TransformationContext) {
19011901
function transformEnumMemberDeclarationValue(member: EnumMember): Expression {
19021902
const value = resolver.getConstantValue(member);
19031903
if (value !== undefined) {
1904-
return typeof value === "string" ? factory.createStringLiteral(value) :
1905-
value < 0 ? factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value))) :
1906-
factory.createNumericLiteral(value);
1904+
return typeof value === "string" ? factory.createStringLiteral(value) : factory.createNumericLiteral(value);
19071905
}
19081906
else {
19091907
enableSubstitutionForNonQualifiedEnumMembers();

Diff for: src/compiler/utilitiesPublic.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ArrayBindingElement,
66
ArrayBindingOrAssignmentElement,
77
ArrayBindingOrAssignmentPattern,
8+
ArrowFunction,
89
AssertionExpression,
910
AssignmentDeclarationKind,
1011
AssignmentPattern,
@@ -64,6 +65,7 @@ import {
6465
ForInitializer,
6566
ForInOrOfStatement,
6667
FunctionBody,
68+
FunctionExpression,
6769
FunctionLikeDeclaration,
6870
FunctionTypeNode,
6971
GeneratedIdentifier,
@@ -119,6 +121,7 @@ import {
119121
isExportSpecifier,
120122
isFunctionBlock,
121123
isFunctionExpression,
124+
isFunctionExpressionOrArrowFunction,
122125
isFunctionTypeNode,
123126
isIdentifier,
124127
isImportSpecifier,
@@ -1928,8 +1931,8 @@ export function isPropertyAccessOrQualifiedName(node: Node): node is PropertyAcc
19281931
}
19291932

19301933
/** @internal */
1931-
export function isCallLikeOrFunctionLikeExpression(node: Node): node is CallLikeExpression | SignatureDeclaration {
1932-
return isCallLikeExpression(node) || isFunctionLike(node);
1934+
export function isCallLikeOrFunctionLikeExpression(node: Node): node is CallLikeExpression | FunctionExpression | ArrowFunction {
1935+
return isCallLikeExpression(node) || isFunctionExpressionOrArrowFunction(node);
19331936
}
19341937

19351938
export function isCallLikeExpression(node: Node): node is CallLikeExpression {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
accessorInferredReturnTypeErrorInReturnStatement.ts(2,7): error TS7023: 'primaryPath' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
2+
accessorInferredReturnTypeErrorInReturnStatement.ts(4,18): error TS2339: Property 'collection' does not exist on type '{ readonly primaryPath: any; }'.
3+
4+
5+
==== accessorInferredReturnTypeErrorInReturnStatement.ts (2 errors) ====
6+
export var basePrototype = {
7+
get primaryPath() {
8+
~~~~~~~~~~~
9+
!!! error TS7023: 'primaryPath' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
10+
var _this = this;
11+
return _this.collection.schema.primaryPath;
12+
~~~~~~~~~~
13+
!!! error TS2339: Property 'collection' does not exist on type '{ readonly primaryPath: any; }'.
14+
},
15+
};
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/compiler/accessorInferredReturnTypeErrorInReturnStatement.ts] ////
2+
3+
//// [accessorInferredReturnTypeErrorInReturnStatement.ts]
4+
export var basePrototype = {
5+
get primaryPath() {
6+
var _this = this;
7+
return _this.collection.schema.primaryPath;
8+
},
9+
};
10+
11+
12+
//// [accessorInferredReturnTypeErrorInReturnStatement.js]
13+
"use strict";
14+
Object.defineProperty(exports, "__esModule", { value: true });
15+
exports.basePrototype = void 0;
16+
exports.basePrototype = {
17+
get primaryPath() {
18+
var _this = this;
19+
return _this.collection.schema.primaryPath;
20+
},
21+
};
22+
23+
24+
//// [accessorInferredReturnTypeErrorInReturnStatement.d.ts]
25+
export declare var basePrototype: {
26+
readonly primaryPath: any;
27+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [tests/cases/compiler/accessorInferredReturnTypeErrorInReturnStatement.ts] ////
2+
3+
=== accessorInferredReturnTypeErrorInReturnStatement.ts ===
4+
export var basePrototype = {
5+
>basePrototype : Symbol(basePrototype, Decl(accessorInferredReturnTypeErrorInReturnStatement.ts, 0, 10))
6+
7+
get primaryPath() {
8+
>primaryPath : Symbol(primaryPath, Decl(accessorInferredReturnTypeErrorInReturnStatement.ts, 0, 28))
9+
10+
var _this = this;
11+
>_this : Symbol(_this, Decl(accessorInferredReturnTypeErrorInReturnStatement.ts, 2, 7))
12+
>this : Symbol(basePrototype, Decl(accessorInferredReturnTypeErrorInReturnStatement.ts, 0, 26))
13+
14+
return _this.collection.schema.primaryPath;
15+
>_this : Symbol(_this, Decl(accessorInferredReturnTypeErrorInReturnStatement.ts, 2, 7))
16+
17+
},
18+
};
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [tests/cases/compiler/accessorInferredReturnTypeErrorInReturnStatement.ts] ////
2+
3+
=== accessorInferredReturnTypeErrorInReturnStatement.ts ===
4+
export var basePrototype = {
5+
>basePrototype : { readonly primaryPath: any; }
6+
>{ get primaryPath() { var _this = this; return _this.collection.schema.primaryPath; }, } : { readonly primaryPath: any; }
7+
8+
get primaryPath() {
9+
>primaryPath : any
10+
11+
var _this = this;
12+
>_this : { readonly primaryPath: any; }
13+
>this : { readonly primaryPath: any; }
14+
15+
return _this.collection.schema.primaryPath;
16+
>_this.collection.schema.primaryPath : any
17+
>_this.collection.schema : any
18+
>_this.collection : any
19+
>_this : { readonly primaryPath: any; }
20+
>collection : any
21+
>schema : any
22+
>primaryPath : any
23+
24+
},
25+
};
26+

0 commit comments

Comments
 (0)