Skip to content

Commit

Permalink
Revert "Fix exports (#82)"
Browse files Browse the repository at this point in the history
This reverts commit b9435de.
  • Loading branch information
dummdidumm committed Jul 2, 2024
1 parent 079b5d1 commit 7bf2dcd
Show file tree
Hide file tree
Showing 54 changed files with 104 additions and 155 deletions.
23 changes: 16 additions & 7 deletions src/create-module-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ export function create_module_declaration(id, entry, created, resolve) {
declaration.alias = get_name(globals.has(name) ? declaration.name : name);
mark(declaration);

export_specifiers.push(
declaration.alias === name ? name : `${declaration.alias} as ${name}`
);
if (declaration.alias !== name) {
export_specifiers.push(`${declaration.alias} as ${name}`);
} else {
declaration.exported = true;
}
} else {
throw new Error('Something strange happened');
}
Expand Down Expand Up @@ -323,10 +325,15 @@ export function create_module_declaration(id, entry, created, resolve) {
}
}

let b = export_modifier.end;
const a = b - 6;
while (/\s/.test(module.dts[b])) b += 1;
result.remove(a, b);
if (!exports.has(declaration.alias)) {
// remove all export keywords in the initial pass; reinstate as necessary later
let b = export_modifier.end;
const a = b - 6;
while (/\s/.test(module.dts[b])) b += 1;
result.remove(a, b);
}
} else if (declaration.exported) {
export_specifiers.push(declaration.alias);
}
}

Expand Down Expand Up @@ -500,6 +507,7 @@ export function create_module_declaration(id, entry, created, resolve) {
module: '<builtin>',
external: false,
included: true,
exported: false,
name,
alias: name,
dependencies: [],
Expand Down Expand Up @@ -527,6 +535,7 @@ function create_external_declaration(binding, alias) {
module: binding.id,
name: binding.name,
alias: '',
exported: false,
external: true,
included: false,
dependencies: [],
Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Declaration {
module: string;
name: string;
alias: string;
exported: boolean;
external: boolean;
included: boolean;
dependencies: Reference[];
Expand Down
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ export function get_dts(file, created, resolve) {
module: file,
name,
alias: '',
exported: false,
included: false,
external: false,
dependencies: [],
Expand Down
4 changes: 1 addition & 3 deletions test/samples/ambient-imports/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/// <reference types="some-ambient-import" />

declare module 'ambient-imports' {
interface Foo {}

export { Foo };
export interface Foo {}
}

//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion test/samples/ambient-imports/output/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"sourcesContent": [
null
],
"mappings": ";;;WAEiBA,GAAGA"
"mappings": ";;;kBAEiBA,GAAGA"
}
12 changes: 4 additions & 8 deletions test/samples/basic/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'basic' {
/** A vector with two components */
interface Vector2 {
export interface Vector2 {
/** The x component */
x: number;
/** The y component */
Expand All @@ -11,18 +11,14 @@ declare module 'basic' {
* @param a the first vector
* @param b the second vector
* */
function add(a: Vector2, b: Vector2): Vector2;

export { Vector2, add };
export function add(a: Vector2, b: Vector2): Vector2;
}

declare module 'basic/subpackage' {
/**
* Multiply two vectors
* */
function multiply(a: import('basic').Vector2, b: import('basic').Vector2): import('basic').Vector2;

export { multiply };
export function multiply(a: import('basic').Vector2, b: import('basic').Vector2): import('basic').Vector2;
}

//# sourceMappingURL=index.d.ts.map
//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion test/samples/basic/output/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
null,
null
],
"mappings": ";;WACiBA,OAAOA;;;;;;;;;;;UCKRC,GAAGA;;;;;;;;;UCAHC,QAAQA"
"mappings": ";;kBACiBA,OAAOA;;;;;;;;;;;iBCKRC,GAAGA;;;;;;;iBCAHC,QAAQA"
}
4 changes: 1 addition & 3 deletions test/samples/const-namespace/output 5.0/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
declare module 'const-namespace' {
namespace a {
export namespace a {
const x: number;
}

export { a };
}

//# sourceMappingURL=index.d.ts.map
6 changes: 2 additions & 4 deletions test/samples/const-namespace/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
declare module 'const-namespace' {
namespace a {
export namespace a {
let x: number;
}

export { a };
}

//# sourceMappingURL=index.d.ts.map
//# sourceMappingURL=index.d.ts.map
4 changes: 1 addition & 3 deletions test/samples/declare-module/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
declare module 'declare-module' {
interface Foo {}

export { Foo };
export interface Foo {}
}

//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion test/samples/declare-module/output/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"sourcesContent": [
null
],
"mappings": ";WAOiBA,GAAGA"
"mappings": ";kBAOiBA,GAAGA"
}
4 changes: 1 addition & 3 deletions test/samples/deconflict-priority/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
declare module 'deconflict-priority' {
function x(foo: Foo, bar: Bar): void;
export function x(foo: Foo, bar: Bar): void;
interface Foo {}
interface Bar {}

export { x };
}

//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion test/samples/deconflict-priority/output/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
null,
null
],
"mappings": ";UAIgBA,CAACA;WCJAC,GAAGA;WCCHC,GAAGA"
"mappings": ";iBAIgBA,CAACA;WCJAC,GAAGA;WCCHC,GAAGA"
}
6 changes: 2 additions & 4 deletions test/samples/enum/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
declare module 'enum' {
enum categories {
export enum categories {
ANIMAL = 0,
VEGETABLE = 1,
MINERAL = 2
}

export { categories };
}

//# sourceMappingURL=index.d.ts.map
//# sourceMappingURL=index.d.ts.map
4 changes: 2 additions & 2 deletions test/samples/enum/output/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"sourcesContent": [
null
],
"mappings": ";MAAYA,UAAUA"
}
"mappings": ";aAAYA,UAAUA"
}
4 changes: 1 addition & 3 deletions test/samples/export-default-as/output/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ declare module 'export-default-as' {
/**
* Add two numbers
* */
function add(a: number, b: number): number;

export { add };
export function add(a: number, b: number): number;
}

//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion test/samples/export-default-as/output/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"sourcesContent": [
null
],
"mappings": ";;;;UAMwBA,GAAGA"
"mappings": ";;;;iBAMwBA,GAAGA"
}
2 changes: 0 additions & 2 deletions test/samples/export-default-function/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
declare module 'export-default-function' {
export default function foo(): void;

export { default };
}

//# sourceMappingURL=index.d.ts.map
2 changes: 0 additions & 2 deletions test/samples/export-default-value/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
declare module 'export-default-value' {
const _default: 42;
export default _default;

export { default };
}

//# sourceMappingURL=index.d.ts.map
4 changes: 1 addition & 3 deletions test/samples/export-from/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
declare module 'export-from' {
const foo: "hello";

export { foo };
export const foo: "hello";
}

//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion test/samples/export-from/output/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"sourcesContent": [
null
],
"mappings": ";OAAaA,GAAGA"
"mappings": ";cAAaA,GAAGA"
}
4 changes: 1 addition & 3 deletions test/samples/export-named-as/output/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ declare module 'export-named-as' {
/**
* Add two numbers
* */
function plus(a: number, b: number): number;

export { plus };
export function plus(a: number, b: number): number;
}

//# sourceMappingURL=index.d.ts.map
8 changes: 3 additions & 5 deletions test/samples/export-type/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
declare module 'export-type' {
type D = {};
class B<D> {}

export { B, D };
export type D = {};
export class B<D> {}
}

//# sourceMappingURL=index.d.ts.map
//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion test/samples/export-type/output/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"sources": [],
"sourcesContent": [],
"mappings": ""
}
}
4 changes: 1 addition & 3 deletions test/samples/generics/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
declare module 'generics' {
interface Foo<T> {
export interface Foo<T> {
bar: T;
}

export { Foo };
}

//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion test/samples/generics/output/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"sourcesContent": [
null
],
"mappings": ";WAAiBA,GAAGA"
"mappings": ";kBAAiBA,GAAGA"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
declare module 'ignores-missing-sourcemap-segments' {
function hello(): void;
namespace object {
export function hello(): void;
export namespace object {
const answer: number;
}

export { hello, object };
}

//# sourceMappingURL=index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
null,
null
],
"mappings": ";UAIgBA,KAAKA;WCHJC,MAAMA"
}
"mappings": ";iBAIgBA,KAAKA;kBCHJC,MAAMA"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
declare module 'ignores-missing-sourcemap-segments' {
function hello(): void;
namespace object {
export function hello(): void;
export namespace object {
let answer: number;
}

export { hello, object };
}

//# sourceMappingURL=index.d.ts.map
//# sourceMappingURL=index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
null,
null
],
"mappings": ";UAIgBA,KAAKA;WCHJC,MAAMA"
"mappings": ";iBAIgBA,KAAKA;kBCHJC,MAAMA"
}
6 changes: 2 additions & 4 deletions test/samples/import-external-default/output/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
declare module 'import-external-default' {
import type { default as x } from 'external';
function foo(input: x): x;

export { foo };
export function foo(input: x): x;
}

//# sourceMappingURL=index.d.ts.map
//# sourceMappingURL=index.d.ts.map
4 changes: 2 additions & 2 deletions test/samples/import-external-default/output/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"sourcesContent": [
null
],
"mappings": ";;UAEgBA,GAAGA"
}
"mappings": ";;iBAEgBA,GAAGA"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
declare module 'import-external-named-as-conflict' {
import type { foo as f } from 'external';
function foo(): void;

export { foo, f };
export function foo(): void;
export { f };
}

//# sourceMappingURL=index.d.ts.map
//# sourceMappingURL=index.d.ts.map
Loading

0 comments on commit 7bf2dcd

Please sign in to comment.