Skip to content

Commit

Permalink
split out testcase-sources and operate on .d.ts input files
Browse files Browse the repository at this point in the history
also closes #26 and ensures correct output filenames
  • Loading branch information
Swatinem committed Jun 3, 2019
1 parent 59b89f2 commit 672f8be
Show file tree
Hide file tree
Showing 176 changed files with 560 additions and 76 deletions.
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,27 @@ const plugin: PluginImpl<Options> = (options = {}) => {

banner: mode === CompileMode.Types && options.banner !== false ? BANNER : undefined,

options(options) {
if (mode === CompileMode.Js) {
return options;
}
return {
...options,
treeshake: {
moduleSideEffects: "no-external",
propertyReadSideEffects: true,
},
};
},

outputOptions(options) {
if (mode === CompileMode.Js) {
return options;
}
return {
...options,
chunkFileNames: options.chunkFileNames || "[name]-[hash].d.ts",
entryFileNames: options.entryFileNames || "[name].d.ts",
format: "es",
exports: "named",
compact: false,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions tests/testcase-sources/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"lib": ["es2018", "esnext", "dom"],
"skipDefaultLibCheck": true,

"strict": true,

"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"module": "esnext",
"stripInternal": true,

"declaration": true,
"emitDeclarationOnly": true,
"outDir": "../testcases"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions tests/testcases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ async function assertTestcase(dir: string, meta: Meta) {
pluginOptions.tsconfig = path.join(dir, pluginOptions.tsconfig);
}

// TODO(swatinem): also test the js bundling code :-)
const creator = createBundle({ ...rollupOptions, input: withInput(dir, rollupOptions) }, pluginOptions);
if (expectedError) {
await expect(creator).rejects.toThrow(expectedError);
Expand Down Expand Up @@ -101,7 +100,7 @@ describe("rollup-plugin-dts", () => {
tsconfig: path.join(TESTCASES, "tsconfig.json"),
};
const rollupOptions: InputOptions = {
input: "index.ts",
input: "index.d.ts",
};
const meta: Meta = {
skip: false,
Expand Down
8 changes: 8 additions & 0 deletions tests/testcases/call-signature/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface I {
(arg: string): string;
staticProp: string;
}
export declare const fn: {
(arg: string): string;
staticProp: string;
};
3 changes: 3 additions & 0 deletions tests/testcases/circular-dependency-star/a.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./b";
export declare class A {
}
3 changes: 3 additions & 0 deletions tests/testcases/circular-dependency-star/b.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./a";
export declare class B {
}
1 change: 1 addition & 0 deletions tests/testcases/circular-dependency-star/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { B } from "./a";
3 changes: 3 additions & 0 deletions tests/testcases/circular-dependency/a.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { B } from "./b";
export declare class A {
}
3 changes: 3 additions & 0 deletions tests/testcases/circular-dependency/b.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { A } from "./a";
export declare class B {
}
1 change: 1 addition & 0 deletions tests/testcases/circular-dependency/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { A } from "./a";
3 changes: 3 additions & 0 deletions tests/testcases/construct-signature/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Foo {
new (): any;
}
10 changes: 10 additions & 0 deletions tests/testcases/constructor-shorthands/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface A {
}
declare class B {
}
export declare class Foo {
private a;
protected b: B;
constructor(a: A, b: B);
}
export {};
12 changes: 12 additions & 0 deletions tests/testcases/enum/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export declare enum A {
A = 0
}
export declare enum B {
B = "B"
}
export declare const enum C {
C = 0
}
export declare const enum D {
D = "D"
}
10 changes: 10 additions & 0 deletions tests/testcases/export-const/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export declare const sLit = "";
export declare const nLit = 0;
export declare const aLit: never[];
export declare const sLitDef: "";
export declare const nLitDef: 0;
export declare const sDef: string;
export declare const nDef: number;
export declare const aDef: Array<number>;
export declare const tuple: [number, string];
export declare const unique: unique symbol;
2 changes: 2 additions & 0 deletions tests/testcases/export-default-class/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default class Foo {
}
1 change: 1 addition & 0 deletions tests/testcases/export-default-function/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function foo(): void;
2 changes: 2 additions & 0 deletions tests/testcases/export-default-interface/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default interface Foo {
}
4 changes: 4 additions & 0 deletions tests/testcases/export-simple-alias/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface Foo {
}
export declare type Bar = Foo;
export {};
2 changes: 2 additions & 0 deletions tests/testcases/export-simple-class/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare class Foo {
}
1 change: 1 addition & 0 deletions tests/testcases/export-simple-function/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function foo(): void;
2 changes: 2 additions & 0 deletions tests/testcases/export-simple-interface/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export interface Foo {
}
1 change: 1 addition & 0 deletions tests/testcases/export-star/a.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function A(): void;
2 changes: 2 additions & 0 deletions tests/testcases/export-star/b.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export interface B {
}
2 changes: 2 additions & 0 deletions tests/testcases/export-star/exports.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./a";
export * from "./b";
3 changes: 3 additions & 0 deletions tests/testcases/export-star/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class A {
}
export { B } from "./exports";
49 changes: 49 additions & 0 deletions tests/testcases/generics/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
interface A {
}
interface B {
}
interface C {
}
interface D {
}
interface E {
}
interface F {
}
interface G {
}
interface H {
}
interface J {
}
interface K {
}
interface L {
}
interface M {
}
interface N {
}
interface O {
}
interface P {
}
declare type Gen<T> = T;
export interface I1<T = A> {
a: T;
b: Gen<B>;
}
export declare type Ty<T = C> = {
c: T;
d: Gen<D>;
};
export declare class Cl<T = E> {
e: T;
f: Gen<F>;
}
export declare function fn<T = G>(g: T, h: Gen<H>): void;
export declare type TyFn = <T = J>(j: T, k: Gen<K>) => L;
export declare type TyCtor = new <T = M>(m: T, n: Gen<N>) => O;
export interface I2 extends Gen<P> {
}
export {};
10 changes: 10 additions & 0 deletions tests/testcases/has-class/foo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export declare abstract class A {
}
export interface B {
}
export interface C {
}
export interface D {
}
export interface E {
}
6 changes: 6 additions & 0 deletions tests/testcases/has-class/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { A, B, C, D, E } from "./foo";
export default class Foo extends A {
b: B;
constructor(c: C);
method(d: D): E;
}
9 changes: 9 additions & 0 deletions tests/testcases/implements-expression/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ns from "./ns";
interface G {
}
export interface MyComponentProps extends ns.Props<G> {
bar: string;
}
export declare class MyComponent extends ns.Component<MyComponentProps> {
}
export {};
9 changes: 9 additions & 0 deletions tests/testcases/implements-expression/ns.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare namespace ns {
interface Props<T> {
foo: T;
}
class Component<P> {
props: P;
}
}
export default ns;
2 changes: 2 additions & 0 deletions tests/testcases/import-default-interface/bar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default interface Bar {
}
3 changes: 3 additions & 0 deletions tests/testcases/import-default-interface/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Bar from "./bar";
export interface Foo extends Bar {
}
2 changes: 2 additions & 0 deletions tests/testcases/import-no-import-clause/bar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export interface Bar {
}
3 changes: 3 additions & 0 deletions tests/testcases/import-no-import-clause/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "./bar";
export interface Foo {
}
2 changes: 2 additions & 0 deletions tests/testcases/import-referenced-interface/bar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export interface Bar {
}
4 changes: 4 additions & 0 deletions tests/testcases/import-referenced-interface/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Bar } from "./bar";
export interface Foo {
bar: Bar;
}
2 changes: 2 additions & 0 deletions tests/testcases/import-renamed/bar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export interface Bar {
}
4 changes: 4 additions & 0 deletions tests/testcases/import-renamed/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Bar as Baz } from "./bar";
export interface Foo {
bar: Baz;
}
2 changes: 2 additions & 0 deletions tests/testcases/import-unused-interface/bar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export interface Bar {
}
2 changes: 2 additions & 0 deletions tests/testcases/import-unused-interface/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export interface Foo {
}
4 changes: 4 additions & 0 deletions tests/testcases/inline-import-external-namespace/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Foo {
ns1: import("foo");
ns2: typeof import("foo");
}
2 changes: 2 additions & 0 deletions tests/testcases/inline-import-namespace/bar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export interface Bar {
}
3 changes: 3 additions & 0 deletions tests/testcases/inline-import-namespace/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Foo {
ns: typeof import("./bar");
}
3 changes: 3 additions & 0 deletions tests/testcases/inline-import/bar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Bar {
}
export declare const Baz = 123;
4 changes: 4 additions & 0 deletions tests/testcases/inline-import/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Foo {
bar: import("./bar").Bar;
baz: typeof import("./bar").Baz;
}
24 changes: 0 additions & 24 deletions tests/testcases/intl-codegen/expected.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions tests/testcases/intl-codegen/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion tests/testcases/intl-codegen/intl-codegen
Submodule intl-codegen deleted from b88879
8 changes: 0 additions & 8 deletions tests/testcases/intl-codegen/meta.json

This file was deleted.

4 changes: 0 additions & 4 deletions tests/testcases/intl-codegen/tsconfig.json

This file was deleted.

5 changes: 5 additions & 0 deletions tests/testcases/keep-extended-interface/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Bar {
}
export interface Foo extends Bar {
}
export {};
4 changes: 4 additions & 0 deletions tests/testcases/keep-interface-definition/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Foo {
a: string;
b: Array<number>;
}
6 changes: 6 additions & 0 deletions tests/testcases/keep-referenced-interface/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface Bar {
}
export interface Foo {
bar: Bar;
}
export {};
6 changes: 6 additions & 0 deletions tests/testcases/multiple-entries/common.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface A {
}
export interface B {
}
export interface unused {
}
10 changes: 5 additions & 5 deletions tests/testcases/multiple-entries/expected.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// a.js
export { A } from './chunk-ecf69fe7.js';
// b.js
export { B } from './chunk-ecf69fe7.js';
// chunk-ecf69fe7.js
// a.d.ts
export { A } from './chunk-b49336de.d.ts';
// b.d.ts
export { B } from './chunk-b49336de.d.ts';
// chunk-b49336de.d.ts
interface A {
}
interface B {
Expand Down
1 change: 1 addition & 0 deletions tests/testcases/multiple-entries/main-a.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { A } from "./common";
1 change: 1 addition & 0 deletions tests/testcases/multiple-entries/main-b.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { B } from "./common";

0 comments on commit 672f8be

Please sign in to comment.