Skip to content

Commit

Permalink
🤖 Pick PR #58810 (Fixed declaration emit issue relate...) into releas…
Browse files Browse the repository at this point in the history
…e-5.5 (#58842)

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
TypeScript Bot and Andarist authored Jun 15, 2024
1 parent 552b07e commit 17933ee
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8684,7 +8684,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
if (isJSDocTypeLiteral(node)) {
return factory.createTypeLiteralNode(map(node.jsDocPropertyTags, t => {
const name = isIdentifier(t.name) ? t.name : t.name.right;
const name = visitNode(isIdentifier(t.name) ? t.name : t.name.right, visitExistingNodeTreeSymbols, isIdentifier)!;
const typeViaParent = getTypeOfPropertyOfType(getTypeFromTypeNode(context, node), name.escapedText);
const overrideTypeNode = typeViaParent && t.typeExpression && getTypeFromTypeNode(context, t.typeExpression.type) !== typeViaParent ? typeToTypeNodeHelper(typeViaParent, context) : undefined;

Expand Down Expand Up @@ -8723,7 +8723,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
/*modifiers*/ undefined,
getEffectiveDotDotDotForParameter(p),
setTextRange(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p),
p.questionToken,
factory.cloneNode(p.questionToken),
visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode),
/*initializer*/ undefined,
)),
Expand All @@ -8738,7 +8738,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
/*modifiers*/ undefined,
getEffectiveDotDotDotForParameter(p),
setTextRange(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p),
p.questionToken,
factory.cloneNode(p.questionToken),
visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode),
/*initializer*/ undefined,
)),
Expand All @@ -8756,7 +8756,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (isTypeParameterDeclaration(node)) {
return factory.updateTypeParameterDeclaration(
node,
node.modifiers,
visitNodes(node.modifiers, visitExistingNodeTreeSymbols, isModifier),
setTextRange(context, typeParameterToName(getDeclaredTypeOfSymbol(getSymbolOfDeclaration(node)), context), node),
visitNode(node.constraint, visitExistingNodeTreeSymbols, isTypeNode),
visitNode(node.default, visitExistingNodeTreeSymbols, isTypeNode),
Expand Down Expand Up @@ -8797,8 +8797,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return factory.updateImportTypeNode(
node,
factory.updateLiteralTypeNode(node.argument, rewriteModuleSpecifier(node, node.argument.literal)),
node.attributes,
node.qualifier,
visitNode(node.attributes, visitExistingNodeTreeSymbols, isImportAttributes),
visitNode(node.qualifier, visitExistingNodeTreeSymbols, isEntityName),
visitNodes(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode),
node.isTypeOf,
);
Expand Down Expand Up @@ -8877,9 +8877,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
parameterName = result;
}
else {
parameterName = node.parameterName;
parameterName = factory.cloneNode(node.parameterName);
}
return factory.updateTypePredicateNode(node, node.assertsModifier, parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode));
return factory.updateTypePredicateNode(node, factory.cloneNode(node.assertsModifier), parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode));
}

if (isTupleTypeNode(node) || isTypeLiteralNode(node) || isMappedTypeNode(node)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//// [tests/cases/compiler/declarationEmitTopLevelNodeFromCrossFile2.ts] ////

//// [a.ts]
import { boxedBox } from "./boxedBox";

export const _ = boxedBox;

// At index 83
/**
* wat
*/

//// [boxedBox.d.ts]
export declare const boxedBox: import("./box").Box<{
boxed: import("./box").Box<number>;
}>; // ^This is index 83 in this file

//// [box.d.ts]
export declare class Box<T> {
value: T;
constructor(value: T);
}
export declare function box<T>(value: T): Box<T>;

//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
var boxedBox_1 = require("./boxedBox");
exports._ = boxedBox_1.boxedBox;
// At index 83
/**
* wat
*/


//// [a.d.ts]
export declare const _: import("./box").Box<{
boxed: import("./box").Box<number>;
}>;
/**
* wat
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//// [tests/cases/compiler/declarationEmitTopLevelNodeFromCrossFile2.ts] ////

=== a.ts ===
import { boxedBox } from "./boxedBox";
>boxedBox : Symbol(boxedBox, Decl(a.ts, 0, 8))

export const _ = boxedBox;
>_ : Symbol(_, Decl(a.ts, 2, 12))
>boxedBox : Symbol(boxedBox, Decl(a.ts, 0, 8))

// At index 83
/**
* wat
*/

=== boxedBox.d.ts ===
export declare const boxedBox: import("./box").Box<{
>boxedBox : Symbol(boxedBox, Decl(boxedBox.d.ts, 0, 20))
>Box : Symbol(Box, Decl(box.d.ts, 0, 0))

boxed: import("./box").Box<number>;
>boxed : Symbol(boxed, Decl(boxedBox.d.ts, 0, 52))
>Box : Symbol(Box, Decl(box.d.ts, 0, 0))

}>; // ^This is index 83 in this file

=== box.d.ts ===
export declare class Box<T> {
>Box : Symbol(Box, Decl(box.d.ts, 0, 0))
>T : Symbol(T, Decl(box.d.ts, 0, 25))

value: T;
>value : Symbol(Box.value, Decl(box.d.ts, 0, 29))
>T : Symbol(T, Decl(box.d.ts, 0, 25))

constructor(value: T);
>value : Symbol(value, Decl(box.d.ts, 2, 16))
>T : Symbol(T, Decl(box.d.ts, 0, 25))
}
export declare function box<T>(value: T): Box<T>;
>box : Symbol(box, Decl(box.d.ts, 3, 1))
>T : Symbol(T, Decl(box.d.ts, 4, 28))
>value : Symbol(value, Decl(box.d.ts, 4, 31))
>T : Symbol(T, Decl(box.d.ts, 4, 28))
>Box : Symbol(Box, Decl(box.d.ts, 0, 0))
>T : Symbol(T, Decl(box.d.ts, 4, 28))

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

=== a.ts ===
import { boxedBox } from "./boxedBox";
>boxedBox : import("box").Box<{ boxed: import("box").Box<number>; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^

export const _ = boxedBox;
>_ : import("box").Box<{ boxed: import("box").Box<number>; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^
>boxedBox : import("box").Box<{ boxed: import("box").Box<number>; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^

// At index 83
/**
* wat
*/

=== boxedBox.d.ts ===
export declare const boxedBox: import("./box").Box<{
>boxedBox : import("box").Box<{ boxed: import("./box").Box<number>; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^

boxed: import("./box").Box<number>;
>boxed : import("box").Box<number>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

}>; // ^This is index 83 in this file

=== box.d.ts ===
export declare class Box<T> {
>Box : Box<T>
> : ^^^^^^

value: T;
>value : T
> : ^

constructor(value: T);
>value : T
> : ^
}
export declare function box<T>(value: T): Box<T>;
>box : <T>(value: T) => Box<T>
> : ^ ^^ ^^ ^^^^^
>value : T
> : ^

24 changes: 24 additions & 0 deletions tests/cases/compiler/declarationEmitTopLevelNodeFromCrossFile2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @strict: true
// @declaration: true

// @filename: a.ts
import { boxedBox } from "./boxedBox";

export const _ = boxedBox;

// At index 83
/**
* wat
*/

// @filename: boxedBox.d.ts
export declare const boxedBox: import("./box").Box<{
boxed: import("./box").Box<number>;
}>; // ^This is index 83 in this file

// @filename: box.d.ts
export declare class Box<T> {
value: T;
constructor(value: T);
}
export declare function box<T>(value: T): Box<T>;

0 comments on commit 17933ee

Please sign in to comment.