Skip to content

Commit

Permalink
Fixes for release-5.3. (#56424)
Browse files Browse the repository at this point in the history
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
  • Loading branch information
4 people committed Nov 16, 2023
1 parent 88f80c7 commit 756efd2
Show file tree
Hide file tree
Showing 35 changed files with 3,337 additions and 37 deletions.
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": "5.3.1-rc",
"version": "5.3.2",
"license": "Apache-2.0",
"description": "TypeScript is a language for application scale JavaScript development",
"keywords": [
Expand Down
23 changes: 10 additions & 13 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const nodeLinks = getNodeLinks(node);
cachedResolvedSignatures.push([nodeLinks, nodeLinks.resolvedSignature] as const);
nodeLinks.resolvedSignature = undefined;
if (isFunctionLike(node)) {
if (isFunctionExpressionOrArrowFunction(node)) {
const symbolLinks = getSymbolLinks(getSymbolOfDeclaration(node));
const type = symbolLinks.type;
cachedTypes.push([symbolLinks, type] as const);
Expand Down Expand Up @@ -6949,6 +6949,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
context.symbolDepth!.set(id, depth + 1);
}
context.visitedTypes.add(typeId);
const prevTrackedSymbols = context.trackedSymbols;
context.trackedSymbols = undefined;
const startLength = context.approximateLength;
const result = transform(type);
const addedLength = context.approximateLength - startLength;
Expand All @@ -6964,6 +6966,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (id) {
context.symbolDepth!.set(id, depth!);
}
context.trackedSymbols = prevTrackedSymbols;
return result;

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

if (propertySymbol.flags & SymbolFlags.Accessor) {
const writeType = getWriteTypeOfSymbol(propertySymbol);
if (propertyType !== writeType) {
if (propertyType !== writeType && !isErrorType(propertyType) && !isErrorType(writeType)) {
const getterDeclaration = getDeclarationOfKind<GetAccessorDeclaration>(propertySymbol, SyntaxKind.GetAccessor)!;
const getterSignature = getSignatureFromDeclaration(getterDeclaration);
typeElements.push(
Expand Down Expand Up @@ -8299,7 +8302,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return factory.createStringLiteral(name, !!singleQuote);
}
if (isNumericLiteralName(name) && startsWith(name, "-")) {
return factory.createComputedPropertyName(factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(+name))));
return factory.createComputedPropertyName(factory.createNumericLiteral(+name));
}
return createPropertyNameNodeForIdentifierOrLiteral(name, getEmitScriptTarget(compilerOptions), singleQuote, stringNamed, isMethod);
}
Expand Down Expand Up @@ -38953,14 +38956,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return hasSkipDirectInferenceFlag(node) ?
blockedStringType :
getFreshTypeOfLiteralType(getStringLiteralType((node as StringLiteralLike).text));
case SyntaxKind.NumericLiteral: {
case SyntaxKind.NumericLiteral:
checkGrammarNumericLiteral(node as NumericLiteral);
const value = +(node as NumericLiteral).text;
if (!isFinite(value)) {
return numberType;
}
return getFreshTypeOfLiteralType(getNumberLiteralType(value));
}
return getFreshTypeOfLiteralType(getNumberLiteralType(+(node as NumericLiteral).text));
case SyntaxKind.BigIntLiteral:
checkGrammarBigIntLiteral(node as BigIntLiteral);
return getFreshTypeOfLiteralType(getBigIntLiteralType({
Expand Down Expand Up @@ -47883,9 +47881,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (enumResult) return enumResult;
const literalValue = (type as LiteralType).value;
return typeof literalValue === "object" ? factory.createBigIntLiteral(literalValue) :
typeof literalValue === "string" ? factory.createStringLiteral(literalValue) :
literalValue < 0 ? factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(literalValue))) :
factory.createNumericLiteral(literalValue);
typeof literalValue === "number" ? factory.createNumericLiteral(literalValue) :
factory.createStringLiteral(literalValue);
}

function createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, tracker: SymbolTracker) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/corePublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const versionMajorMinor = "5.3";
// 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
export const version = "5.3.1-rc" as string;
export const version = "5.3.2" as string;

/**
* Type of objects whose values are all of the same type.
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
CaseOrDefaultClause,
cast,
CatchClause,
CharacterCodes,
ClassDeclaration,
ClassElement,
ClassExpression,
Expand Down Expand Up @@ -1254,10 +1253,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode

// @api
function createNumericLiteral(value: string | number, numericLiteralFlags: TokenFlags = TokenFlags.None): NumericLiteral {
const text = typeof value === "number" ? value + "" : value;
Debug.assert(text.charCodeAt(0) !== CharacterCodes.minus, "Negative numbers should be created in combination with createPrefixUnaryExpression");
const node = createBaseDeclaration<NumericLiteral>(SyntaxKind.NumericLiteral);
node.text = text;
node.text = typeof value === "number" ? value + "" : value;
node.numericLiteralFlags = numericLiteralFlags;
if (numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier) node.transformFlags |= TransformFlags.ContainsES2015;
return node;
Expand Down
9 changes: 1 addition & 8 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1798,14 +1798,7 @@ export function transformDeclarations(context: TransformationContext) {
if (shouldStripInternal(m)) return;
// Rewrite enum values to their constants, if available
const constValue = resolver.getConstantValue(m);
const newInitializer = constValue === undefined
? undefined
: typeof constValue === "string"
? factory.createStringLiteral(constValue)
: constValue < 0
? factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(constValue)))
: factory.createNumericLiteral(constValue);
return preserveJsDoc(factory.updateEnumMember(m, m.name, newInitializer), m);
return preserveJsDoc(factory.updateEnumMember(m, m.name, constValue !== undefined ? typeof constValue === "string" ? factory.createStringLiteral(constValue) : factory.createNumericLiteral(constValue) : undefined), m);
})),
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2524,7 +2524,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
labelExpressions = [];
}

const expression = factory.createNumericLiteral(Number.MAX_SAFE_INTEGER);
const expression = factory.createNumericLiteral(-1);
if (labelExpressions[label] === undefined) {
labelExpressions[label] = [expression];
}
Expand Down
4 changes: 1 addition & 3 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1901,9 +1901,7 @@ export function transformTypeScript(context: TransformationContext) {
function transformEnumMemberDeclarationValue(member: EnumMember): Expression {
const value = resolver.getConstantValue(member);
if (value !== undefined) {
return typeof value === "string" ? factory.createStringLiteral(value) :
value < 0 ? factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value))) :
factory.createNumericLiteral(value);
return typeof value === "string" ? factory.createStringLiteral(value) : factory.createNumericLiteral(value);
}
else {
enableSubstitutionForNonQualifiedEnumMembers();
Expand Down
7 changes: 5 additions & 2 deletions src/compiler/utilitiesPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ArrayBindingElement,
ArrayBindingOrAssignmentElement,
ArrayBindingOrAssignmentPattern,
ArrowFunction,
AssertionExpression,
AssignmentDeclarationKind,
AssignmentPattern,
Expand Down Expand Up @@ -64,6 +65,7 @@ import {
ForInitializer,
ForInOrOfStatement,
FunctionBody,
FunctionExpression,
FunctionLikeDeclaration,
FunctionTypeNode,
GeneratedIdentifier,
Expand Down Expand Up @@ -119,6 +121,7 @@ import {
isExportSpecifier,
isFunctionBlock,
isFunctionExpression,
isFunctionExpressionOrArrowFunction,
isFunctionTypeNode,
isIdentifier,
isImportSpecifier,
Expand Down Expand Up @@ -1928,8 +1931,8 @@ export function isPropertyAccessOrQualifiedName(node: Node): node is PropertyAcc
}

/** @internal */
export function isCallLikeOrFunctionLikeExpression(node: Node): node is CallLikeExpression | SignatureDeclaration {
return isCallLikeExpression(node) || isFunctionLike(node);
export function isCallLikeOrFunctionLikeExpression(node: Node): node is CallLikeExpression | FunctionExpression | ArrowFunction {
return isCallLikeExpression(node) || isFunctionExpressionOrArrowFunction(node);
}

export function isCallLikeExpression(node: Node): node is CallLikeExpression {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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.
accessorInferredReturnTypeErrorInReturnStatement.ts(4,18): error TS2339: Property 'collection' does not exist on type '{ readonly primaryPath: any; }'.


==== accessorInferredReturnTypeErrorInReturnStatement.ts (2 errors) ====
export var basePrototype = {
get primaryPath() {
~~~~~~~~~~~
!!! 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.
var _this = this;
return _this.collection.schema.primaryPath;
~~~~~~~~~~
!!! error TS2339: Property 'collection' does not exist on type '{ readonly primaryPath: any; }'.
},
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//// [tests/cases/compiler/accessorInferredReturnTypeErrorInReturnStatement.ts] ////

//// [accessorInferredReturnTypeErrorInReturnStatement.ts]
export var basePrototype = {
get primaryPath() {
var _this = this;
return _this.collection.schema.primaryPath;
},
};


//// [accessorInferredReturnTypeErrorInReturnStatement.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.basePrototype = void 0;
exports.basePrototype = {
get primaryPath() {
var _this = this;
return _this.collection.schema.primaryPath;
},
};


//// [accessorInferredReturnTypeErrorInReturnStatement.d.ts]
export declare var basePrototype: {
readonly primaryPath: any;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/accessorInferredReturnTypeErrorInReturnStatement.ts] ////

=== accessorInferredReturnTypeErrorInReturnStatement.ts ===
export var basePrototype = {
>basePrototype : Symbol(basePrototype, Decl(accessorInferredReturnTypeErrorInReturnStatement.ts, 0, 10))

get primaryPath() {
>primaryPath : Symbol(primaryPath, Decl(accessorInferredReturnTypeErrorInReturnStatement.ts, 0, 28))

var _this = this;
>_this : Symbol(_this, Decl(accessorInferredReturnTypeErrorInReturnStatement.ts, 2, 7))
>this : Symbol(basePrototype, Decl(accessorInferredReturnTypeErrorInReturnStatement.ts, 0, 26))

return _this.collection.schema.primaryPath;
>_this : Symbol(_this, Decl(accessorInferredReturnTypeErrorInReturnStatement.ts, 2, 7))

},
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//// [tests/cases/compiler/accessorInferredReturnTypeErrorInReturnStatement.ts] ////

=== accessorInferredReturnTypeErrorInReturnStatement.ts ===
export var basePrototype = {
>basePrototype : { readonly primaryPath: any; }
>{ get primaryPath() { var _this = this; return _this.collection.schema.primaryPath; }, } : { readonly primaryPath: any; }

get primaryPath() {
>primaryPath : any

var _this = this;
>_this : { readonly primaryPath: any; }
>this : { readonly primaryPath: any; }

return _this.collection.schema.primaryPath;
>_this.collection.schema.primaryPath : any
>_this.collection.schema : any
>_this.collection : any
>_this : { readonly primaryPath: any; }
>collection : any
>schema : any
>primaryPath : any

},
};

0 comments on commit 756efd2

Please sign in to comment.