Skip to content

Fix redundant export {} in declaration file #58912

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

Closed
wants to merge 3 commits into from
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export function transformDeclarations(context: TransformationContext) {
else {
const statements = visitNodes(node.statements, visitDeclarationStatements, isStatement);
combinedStatements = setTextRange(factory.createNodeArray(transformAndReplaceLatePaintedStatements(statements)), node.statements);
if (isExternalModule(node) && (!resultHasExternalModuleIndicator || (needsScopeFixMarker && !resultHasScopeMarker))) {
if (isExternalModule(node) && !resultHasExternalModuleIndicator) {
combinedStatements = setTextRange(factory.createNodeArray([...combinedStatements, createEmptyExports(factory)]), combinedStatements);
}
}
Expand Down Expand Up @@ -1529,8 +1529,6 @@ export function transformDeclarations(context: TransformationContext) {
needsDeclare = false;
const inner = input.body;
if (inner && inner.kind === SyntaxKind.ModuleBlock) {
const oldNeedsScopeFix = needsScopeFixMarker;
const oldHasScopeFix = resultHasScopeMarker;
resultHasScopeMarker = false;
needsScopeFixMarker = false;
const statements = visitNodes(inner.statements, visitDeclarationStatements, isStatement);
Expand All @@ -1552,8 +1550,6 @@ export function transformDeclarations(context: TransformationContext) {
}
const body = factory.updateModuleBlock(inner, lateStatements);
needsDeclare = previousNeedsDeclare;
needsScopeFixMarker = oldNeedsScopeFix;
resultHasScopeMarker = oldHasScopeFix;
const mods = ensureModifiers(input);

return cleanup(updateModuleDeclarationAndKeyword(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ type T = {
export interface I {
f: T;
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,3 @@ declare const A_base: Class<OutputFrom<{
}>>;
export declare class A extends A_base {
}
export {};
1 change: 0 additions & 1 deletion tests/baselines/reference/declarationEmitAliasInlineing.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ type I = {
prop: string;
};
export declare const fn: (v: O["prop"], p: Omit<O, "prop">, key: keyof O, p2: Omit<O, keyof I>) => void;
export {};
//// [aExp.d.ts]
export type O = {
prop: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ export interface GetLocalesOptions<T extends LocaleData> {
name?: string;
}
export declare const getLocales: <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ export declare class C {
reuseType8?: `${string}-ok` | `${string}-ok`;
reuseType9?: this | this;
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ export declare class C {
reuseType8?: `${string}-ok` | `${string}-ok`;
reuseType9?: this | this;
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,3 @@ export declare const t9: number;
export declare const t10: number;
export declare const t11: number;
export declare const t12: number;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,3 @@ declare const XmlElement2_base: {
};
export declare class XmlElement2 extends XmlElement2_base {
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ export declare class ExportedClass1 {
export declare class ExportedClass2 {
protected constructor(data: PrivateInterface);
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ export type Type = {
[Foo.sym]: 0;
};
};
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ q.val = (0, a_1.f)();
interface I {
}
export declare function f(): I;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,3 @@ export declare class MyClass3 extends MyClass3_base<LocalInterface> {
declare const MyClass4_base: typeof ExportedClass;
export declare class MyClass4 extends MyClass4_base<ExportedInterface> {
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ import * as A from "./a";
declare const Foo: typeof A.Foo;
export default class extends Foo {
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ type AX = {
readonly A: unique symbol;
};
export declare const A: AX;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,3 @@ interface GreeterConstructor {
declare const default_base: GreeterConstructor;
export default class extends default_base {
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ interface I {
a: number;
}
export declare function f(x: any): x is I;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ type Foo<T> = T | {
x: Foo<T>;
};
export declare function returnSomeGlobalValue(): Foo<number[]>;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export declare function excludePrivateKeys2<Obj>(obj: Obj): {
};
export type PublicKeys1<T> = T extends `_${string}` ? never : T;
type PublicKeys2<T> = T extends `_${string}` ? never : T;
export {};
//// [api.d.ts]
export declare const dropPrivateProps1: <Obj>(obj: Obj) => { [K in import("./internal").PublicKeys1<keyof Obj>]: Obj[K]; };
export declare const dropPrivateProps2: <Obj>(obj: Obj) => { [K in keyof Obj extends infer T ? T extends keyof Obj ? T extends `_${string}` ? never : T : never : never]: Obj[K]; };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,3 @@ declare const FilteredThing_base: (abstract new (...args: any[]) => {
export declare class FilteredThing extends FilteredThing_base {
match(path: string): boolean;
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,3 @@ export declare namespace Y {
}
export declare class Y {
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ interface Bar {
declare namespace Bar {
function biz(): number;
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ declare const renamed: {
export type AliasType2 = typeof renamed;
declare const c: string;
export type AliasType3 = typeof c;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export declare const o: (p1: typeof nImported, p2: typeof nNotImported, p3: type
bar: typeof nPrivate;
baz: typeof nNotImported;
};
export {};
//// [b.d.ts]
import { nImported } from "./a";
export declare const g: (p1: typeof nImported, p2: typeof import("./a").nNotImported, p3: "private") => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export declare const o: (p1: SpecialString, p2: PrivateSpecialString, p3: N.Spec
bar: PrivateSpecialString;
baz: N.SpecialString;
};
export {};
//// [b.d.ts]
import * as a from "./a";
export declare const g: (p1: a.SpecialString, p2: string, p3: a.N.SpecialString) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ export declare function ignoreExtraVariables<CtorT extends {
[IGNORE_EXTRA_VARIABLES]: boolean;
};
} & CtorT;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,3 @@ export interface HttpResponse<D extends unknown, E extends unknown = unknown> ex
export declare class HttpClient<SecurityDataType = unknown> {
request: <T = any, E = any>() => TPromise<HttpResponse<T, E>>;
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ declare const _data: unique symbol;
export declare class User {
private [_data];
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export declare const o1: (o: A["a"]["b"]) => void;
export declare const o2: (o: (typeof a)["a"]) => void;
export declare const o3: (o: (typeof a)["a"]) => void;
export declare const o4: (o: keyof A["a"]) => void;
export {};
//// [main.d.ts]
export declare const f: {
o1: (o: "value of b") => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ type UpdatedClient<C> = C & {
foo: number;
};
export declare const createClient: <D extends (new (...args: any[]) => Client) | Record<string, new (...args: any[]) => Client>>(clientDef: D) => D extends new (...args: any[]) => infer C ? UpdatedClient<C> : { [K in keyof D]: D[K] extends new (...args: any[]) => infer C ? UpdatedClient<C> : never; };
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@ export declare const SpotifyAgeGroupEnum: {
"45-59": (typeof AgeGroups)["45-59"];
"60-150": (typeof AgeGroups)["60-150"];
};
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ export declare class C {
}
declare class D extends C {
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ interface Foo {
export declare const obj: {
m(): this is Foo;
};
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ type Foo<T, Y> = {
foo<U, J>(): Foo<U, J>;
};
export type SubFoo<R> = Foo<string, R>;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,3 @@ interface IEntry {
Category: string;
}
export declare const useEntries: () => import("@tanstack/vue-query").UseQueryReturnType<IEntry[], Error>;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,3 @@ interface IEntry {
Category: string;
}
export declare const useEntries: () => import("@tanstack/vue-query").UseQueryReturnType<IEntry[], Error>;
export {};
1 change: 0 additions & 1 deletion tests/baselines/reference/declarationNoDanglingGenerics.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,3 @@ declare const CKind_base: {
};
export declare class CKind extends CKind_base {
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ export declare const mixin: (Base: Constructor) => {
get(domNode: DOMNode): void;
};
};
export {};
1 change: 0 additions & 1 deletion tests/baselines/reference/dynamicNamesErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,3 @@ export declare const ObjectLiteralVisibility: {
readonly [z]: number;
[w]: number;
};
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,3 @@ declare const Test_base: {
} & typeof FooItem;
export declare class Test extends Test_base {
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,3 @@ interface TestUndefined {
readonly prop: undefined;
}
export declare function testUndefined(): TestUndefined;
export {};
1 change: 0 additions & 1 deletion tests/baselines/reference/expandoFunctionSymbolProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ interface TestSymb {
readonly [symb]: boolean;
}
export declare function test(): TestSymb;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,5 @@ declare const MyExtendedClass_base: typeof MyBaseClass & import("./BaseClass").C
export declare class MyExtendedClass extends MyExtendedClass_base<string> {
extendedClassProperty: number;
}
export {};
//// [Main.d.ts]
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ declare class C {
export declare namespace M {
var foo: C;
}
export {};

1 change: 0 additions & 1 deletion tests/baselines/reference/giant.js
Original file line number Diff line number Diff line change
Expand Up @@ -1413,4 +1413,3 @@ export declare namespace eaM {
namespace eM { }
}
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ export declare const fail2: import("module").Modifier<(<T>(x: T) => T)>;
export declare const works1: import("module").Modifier<(x: number) => number>;
type MakeItWork = <T>(x: T) => T;
export declare const works2: import("module").Modifier<MakeItWork>;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,3 @@ interface OK<T> {
value: T;
}
export declare function ok<T>(value: T): OK<T>;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ type OmitUnveiled<T, K extends string | number | symbol> = {
};
export declare function test1<T, K extends string>(obj: T, k: K): OmitReal<T, K>;
export declare function test2<T, K extends string>(obj: T, k: K): OmitUnveiled<T, K>;
export {};
//// [index.d.ts]
export declare function wrappedTest1<T, K extends string>(obj: T, k: K): Exclude<keyof T, K> extends infer T_1 extends keyof T ? { [P in T_1]: T[P]; } : never;
export declare function wrappedTest2<T, K extends string>(obj: T, k: K): { [P in Exclude<keyof T, K>]: T[P]; };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ export declare class Bar {
readonly r = 1;
f: number;
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ declare global {
//// [c.d.ts]
type Foo = teams.calling.Foo;
export declare const bar: (p?: Foo) => void;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ export declare function usePrivateType<T extends unknown[]>(...args: T): Private
type PrivateMapped<Obj> = {
[K in keyof Obj]: Obj[K];
};
export {};
//// [api.d.ts]
export declare const mappedUnionWithPrivateType: <T extends unknown[]>(...args: T) => T[any] extends infer T_1 ? { [K in keyof T_1]: T[any][K]; } : never;
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,5 @@ declare module "./f1" {
baz(): C;
}
}
export {};
//// [f4.d.ts]
import "./f3";
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,5 @@ declare module "./f1" {
baz(): C;
}
}
export {};
//// [f4.d.ts]
import "./f3";
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,5 @@ declare module "./f1" {
baz(): C;
}
}
export {};
//// [f4.d.ts]
import "./f3";
1 change: 0 additions & 1 deletion tests/baselines/reference/omitTypeTestErrors01.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ export type Bar = Omit<Foo, "c">;
export type Baz = Omit<Foo, "b" | "c">;
export declare function getBarC(bar: Bar): any;
export declare function getBazB(baz: Baz): any;
export {};
1 change: 0 additions & 1 deletion tests/baselines/reference/omitTypeTests01.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ export type Bar = Omit<Foo, "c">;
export type Baz = Omit<Foo, "b" | "c">;
export declare function getBarA(bar: Bar): string;
export declare function getBazA(baz: Baz): string;
export {};
1 change: 0 additions & 1 deletion tests/baselines/reference/privacyAccessorDeclFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3702,7 +3702,6 @@ declare namespace privateModule {
}
export {};
}
export {};
//// [privacyAccessorDeclFile_GlobalFile.d.ts]
declare class publicClassInGlobal {
}
Expand Down
1 change: 0 additions & 1 deletion tests/baselines/reference/privacyCheckTypeOfFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ exports.b = foo;
declare function foo(): void;
export declare var x: typeof foo;
export declare var b: typeof foo;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ export declare class publicClassExtendingPrivateClass extends privateClass {
}
export declare class publicClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule {
}
export {};
//// [privacyClassExtendsClauseDeclFile_GlobalFile.d.ts]
declare namespace publicModuleInGlobal {
export class publicClassInPublicModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ export declare class publicClassImplementingPrivateInterface implements privateI
}
export declare class publicClassImplementingFromPrivateModuleInterface implements privateModule.publicInterfaceInPrivateModule {
}
export {};
//// [privacyClassImplementsClauseDeclFile_GlobalFile.d.ts]
declare namespace publicModuleInGlobal {
export interface publicInterfaceInPublicModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,6 @@ declare namespace privateModule {
export function publicAmbientFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void;
export {};
}
export {};
//// [privacyFunctionParameterDeclFile_GlobalFile.d.ts]
declare class publicClassInGlobal {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2459,7 +2459,6 @@ declare namespace privateModule {
export function publicAmbientFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass;
export {};
}
export {};
//// [privacyFunctionReturnTypeDeclFile_GlobalFile.d.ts]
declare class publicClassInGlobal {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export interface publicInterfaceImplementingPrivateInterface extends privateInte
}
export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule {
}
export {};
//// [privacyInterfaceExtendsClauseDeclFile_GlobalFile.d.ts]
declare namespace publicModuleInGlobal {
export interface publicInterfaceInPublicModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,3 @@ export declare namespace import_public {
var publicUse_im_public_mi_public: im_public_mi_public.c;
var publicUse_im_public_mu_public: im_public_mu_public.i;
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,3 @@ export declare namespace import_public {
var publicUse_im_private_mi_public: im_private_mi_public.c;
var publicUse_im_private_mu_public: im_private_mu_public.i;
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,3 @@ export declare var publicUse_im_public_v_public: number;
export declare var publicUse_im_public_i_public: im_public_i_public;
export declare var publicUse_im_public_mi_public: im_public_mi_public.c;
export declare var publicUse_im_public_mu_public: im_public_mu_public.i;
export {};
Loading