Skip to content

Commit

Permalink
Release 3.1.1; Fix accessor comment (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrinktofit committed Apr 15, 2021
1 parent 16d2615 commit 27504ca
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tfig",
"version": "3.1.0",
"version": "3.1.1",
"description": "Yet another tool to generate .d.ts bundle.",
"main": "build/gift.js",
"types": "build/gift.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions source/recast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,23 +544,23 @@ export function recastTopLevelModule({
classElements.push(nodeFactor.createSemicolonClassElement());
} else if (ts.isGetAccessor(element)) {
// Since TS 3.7
classElements.push(nodeFactor.createGetAccessorDeclaration(
classElements.push(copyComments(element, nodeFactor.createGetAccessorDeclaration(
undefined, // decorators
recastModifiers(element.modifiers), // modifiers
recastPropertyName(element.name), // name
recastParameterArray(element.parameters), // parameters
recastTypeNode(element.type), // type
undefined, // body
));
)));
} else if (ts.isSetAccessor(element)) {
// Since TS 3.7
classElements.push(nodeFactor.createSetAccessorDeclaration(
classElements.push(copyComments(element, nodeFactor.createSetAccessorDeclaration(
undefined, // decorators
recastModifiers(element.modifiers), // modifiers
recastPropertyName(element.name), // name
recastParameterArray(element.parameters), // parameters
undefined, // body
));
)));
} else {
console.warn(`Don't know how to handle element ${element.name?.getText()} of class ${newName}`);
}
Expand Down
24 changes: 24 additions & 0 deletions test/comments/comments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

import ps from 'path';
import fs from 'fs-extra';
import { bundle } from '../../source/gift';

test('Type alias', async () => {
const inputPath = ps.join(__dirname, 'input.d.ts');
const outputPath = ps.join(__dirname, 'output.d.ts');
const { groups } = bundle({
input: inputPath,
rootModule: 'foo',
name: 'out/index',
output: outputPath,
});
expect(groups.length).toBe(1);
const group0 = groups[0];

if (!await fs.pathExists(outputPath)) {
await fs.outputFile(outputPath, group0.code, { encoding: 'utf8' });
} else {
const expected = await fs.readFile(outputPath, 'utf8');
expect(group0.code).toBe(expected);
}
});
52 changes: 52 additions & 0 deletions test/comments/input.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@


declare module "foo" {
/**
* Variable.
*/
export const v: number;

/**
* Function.
*/
export function f(p1: number, p2: string): void;

/**
* Class.
*/
export class C {
/**
* Constructor.
*/
constructor();

/**
* Property
*/
p: number;

/**
* Get accessor.
*/
get a(): number;

/**
* Set accessor.
*/
set a(value: number);

/**
* Method.
*/
m(p1: number, p2: number): void;
}

/**
* Namespace.
*/
export * as bar from 'bar';
}

declare module "bar" {
export class Bar {}
}
40 changes: 40 additions & 0 deletions test/comments/output.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
declare module "out/index" {
/**
* Function.
*/
export function f(p1: number, p2: string): void;
/**
* Variable.
*/
export const v: number;
/**
* Class.
*/
export class C {
/**
* Constructor.
*/
constructor();
/**
* Property
*/
p: number;
/**
* Get accessor.
*/
get a(): number;
/**
* Set accessor.
*/
set a(value: number);
/**
* Method.
*/
m(p1: number, p2: number): void;
}
export namespace bar {
export class Bar {
}
}
export {};
}

0 comments on commit 27504ca

Please sign in to comment.