Skip to content
This repository was archived by the owner on Feb 20, 2020. It is now read-only.

v2.0.0 #2

Merged
merged 103 commits into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
4938808
Remove all to prepare v2
ikatyang May 17, 2017
f1d9477
Add GenericType, GenericDeclaration, NativeType
ikatyang May 17, 2017
c63828e
Update .travis.yml
ikatyang May 17, 2017
eb7b0bd
Add ArrayType
ikatyang May 17, 2017
f65e5c2
Add comments
ikatyang May 17, 2017
8cfc731
Add Parameter
ikatyang May 17, 2017
07864dd
Add FunctionType
ikatyang May 17, 2017
2788dde
Rename Parameter with ParameterDeclaration
ikatyang May 17, 2017
3333a7f
Add FunctionType
ikatyang May 17, 2017
d62bdf3
Update tests
ikatyang May 17, 2017
5d43041
Rename print with emit
ikatyang May 17, 2017
9ab7d0f
Add IntersectionType
ikatyang May 17, 2017
64e2f9b
Add UnionType
ikatyang May 17, 2017
dfd2105
Add LiteralType
ikatyang May 17, 2017
8b4998c
Add KeyofType
ikatyang May 17, 2017
9291936
Add TypeofType
ikatyang May 17, 2017
d5b06dd
Add TupleType
ikatyang May 17, 2017
22ead47
Add VariableDeclaration
ikatyang May 17, 2017
6b5c4ff
Add ObjectMember
ikatyang May 17, 2017
ea77de8
Add ConstructorType
ikatyang May 17, 2017
df26f1b
Update ObjectMember
ikatyang May 17, 2017
bf727bc
Add IndexSignature
ikatyang May 17, 2017
f743781
Add ObjectType
ikatyang May 17, 2017
06d1065
Add BasicType
ikatyang May 17, 2017
527d82d
Tidy code
ikatyang May 17, 2017
93b2c11
Add TypeDeclaration
ikatyang May 17, 2017
4dbb44e
Add TypedType
ikatyang May 17, 2017
88ea997
Add InterfaceDeclaration
ikatyang May 17, 2017
62733fe
Add InterfaceType
ikatyang May 17, 2017
e9fafe5
Update InterfaceDeclaration
ikatyang May 17, 2017
0f53ee3
Add ClassMember
ikatyang May 18, 2017
af30b12
Add ClassDeclaration
ikatyang May 18, 2017
7e26a52
Add ClassType
ikatyang May 18, 2017
92cebce
Update tsc config
ikatyang May 18, 2017
37f8d0e
Update ClassDeclaration
ikatyang May 18, 2017
5e4618e
Add NamespaceDeclaration
ikatyang May 18, 2017
4a3bd87
Fix linting
ikatyang May 18, 2017
7ecb73c
Add ModuleDeclaration
ikatyang May 18, 2017
4c0210d
Add EnumDeclaration
ikatyang May 18, 2017
856bc3e
Add EnumType
ikatyang May 18, 2017
f91dc71
Rename symbols
ikatyang May 18, 2017
fdaf057
Add TypePredicate
ikatyang May 18, 2017
0c10a93
Update FunctionType
ikatyang May 18, 2017
5edc483
Add TripleSlashReference
ikatyang May 18, 2017
2faa57b
Update TripleSlashReference
ikatyang May 18, 2017
320a29b
Add TopLevelElement
ikatyang May 18, 2017
19da597
Add SingleLineComment
ikatyang May 18, 2017
717ff51
Update SingleLineComment
ikatyang May 18, 2017
07289b7
Add MultiLineComment
ikatyang May 18, 2017
44b80f3
Update Single/MultiLineComment
ikatyang May 18, 2017
3929c0f
Update collections
ikatyang May 18, 2017
5a7220e
Rename BasicType with GeneralType
ikatyang May 18, 2017
30d4f0f
Update types
ikatyang May 18, 2017
29e97e0
Fix linting
ikatyang May 18, 2017
0d7b31f
Add SubType
ikatyang May 18, 2017
6a210b7
Add tests
ikatyang May 19, 2017
b32bce3
Fix typo
ikatyang May 19, 2017
ace5063
Add JSDocComment
ikatyang May 19, 2017
046cc87
Update JSDocComment
ikatyang May 19, 2017
ee0859a
Refactor transform
ikatyang May 19, 2017
c600d9a
Update transform
ikatyang May 19, 2017
ed35206
Update index
ikatyang May 19, 2017
abb4bf4
Move tests to __tests__
ikatyang May 19, 2017
abcb538
Support JSDoc for every element
ikatyang May 19, 2017
495d0b3
Update GeneralType
ikatyang May 19, 2017
4ec4398
Add tests
ikatyang May 19, 2017
55ff247
Add MappedType
ikatyang May 19, 2017
50c534e
Add declare keyword automatically
ikatyang May 19, 2017
9d76b9c
Add GlobalDeclaration
ikatyang May 20, 2017
993bae0
Fix typo
ikatyang May 20, 2017
9708ea1
Normalize name
ikatyang May 20, 2017
cb684e4
Normalize GeneralType
ikatyang May 20, 2017
3af1bf1
Add utils for qualifiedName
ikatyang May 20, 2017
dbe2705
Add utils for typeParameters
ikatyang May 20, 2017
574c0c5
Add utils for typeArguments
ikatyang May 20, 2017
41878ff
Rename type_arguments with type_nodes
ikatyang May 20, 2017
fc8690b
Update GeneralType
ikatyang May 20, 2017
4d93b17
Add ImportNamed, ImportMember
ikatyang May 20, 2017
ced8c35
Add ImportNamespace
ikatyang May 20, 2017
1120e23
Add ExportMember
ikatyang May 20, 2017
789ed68
Add ExportNamed
ikatyang May 20, 2017
4eb0afc
Add ExportEqual
ikatyang May 20, 2017
333e135
Add ExportNamespace
ikatyang May 20, 2017
3d332ce
Add ExportDefault
ikatyang May 21, 2017
158f5a8
Update ExportNamed
ikatyang May 21, 2017
421c804
Update element
ikatyang May 21, 2017
a3603fd
Add tests
ikatyang May 21, 2017
d2efa0b
Fix wrong detection for detection
ikatyang May 21, 2017
b5afb6e
Add tests
ikatyang May 21, 2017
bd181d9
Add parse/SourceFile
ikatyang May 21, 2017
9345c1e
Add parsers/variable-statement
ikatyang May 21, 2017
6862f07
Add parse/keyword-types
ikatyang May 21, 2017
a7122fd
Add parsers/types
ikatyang May 21, 2017
e3eeb63
Add parsers/others
ikatyang May 21, 2017
df8e43b
Add parsers/imports
ikatyang May 21, 2017
71ae9e2
Add parsers/exports
ikatyang May 22, 2017
150c23e
Add parsers/class-declaration
ikatyang May 22, 2017
27b21c6
Update parsers
ikatyang May 22, 2017
dec81c7
Add parsers
ikatyang May 22, 2017
a0a974b
Tidy code
ikatyang May 22, 2017
040a6c3
Update informations
ikatyang May 23, 2017
17ad5ac
Upgrade [email protected]
ikatyang May 24, 2017
6050ab1
Prepare for v2
ikatyang May 24, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text eof=lf
*.png binary
15 changes: 0 additions & 15 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,15 +0,0 @@
.vscode/
coverage/
docs/
node_modules/
src/
tests/
.editorconfig
.gitattributes
.gitignore
.travis.yml
jest.json
tsconfig.build.json
tsconfig.json
tslint.json
yarn.lock
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ env:
script:
- if [ "$JOB" = "lint" ]; then yarn run lint; fi
- if [ "$JOB" = "test" ]; then yarn run test-ci; fi
- if [ "$JOB" = "build" ]; then yarn run build; fi
- if [ "$JOB" = "test-coverage" ]; then yarn run test-coverage-ci && yarn run coverage-ci; fi

cache:
Expand All @@ -22,8 +21,6 @@ matrix:
include:
- node_js: "stable"
env: JOB=lint
- node_js: "stable"
env: JOB=build
- node_js: "stable"
env: JOB=test-coverage

Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ All changes to this project will be documented in this file.
> - 🏠 [Internal]
> - 💅 [Polish]

## Unreleased

#### 💥 Breaking Change
- package
- all elements are pure object now
- use `dts.emit(dts_element)` instead of `dts_element.emit()`
- use `dts.create_element(options)` instead of `new dts.Element(options)`
- advanced
- remove curry-relative functions since it should not be a part of DOM library

#### 🚀 New Feature
- comments
- support `single-line-comment` and `multi-line-comment` element, or using `comments` field in every element
- parsers
- support parsing TypeScript syntax into `dts-element` ( `dts.parse()` ), useful for restructuring types

#### 🏠 Internal
- package
- rewrite using TypeScript Printer API

## v1.3.0 (2017-05-10)

#### 🚀 New Feature
Expand Down
153 changes: 36 additions & 117 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ A DOM library for generation TypeScript declaration (.d.ts) files
[Changelog](https://github.com/ikatyang/dts-element/blob/master/CHANGELOG.md) - [Examples](https://github.com/ikatyang/dts-element/tree/master/tests/) - [Documentation](https://ikatyang.github.io/dts-element/)

## Features

- reusable
- `FunctionDeclaration`: it can be method or function based on where it is.
- `VariableDeclaration`: it can be property or variable based on where it is.
- clonable
- `element.clone(is_deep_clone: boolean = false)`
- `element.copy(element: Element, is_deep_copy: boolean = false)`
- advanced
- `create_curried_function_interfaces()`
- `create_curried_function_types()` [[example](#curried-function-types)]
- parsable
- parsing TypeScript syntax into `dts-element` using `dts.parse()`, useful for restructuring types

## Installation

Expand All @@ -36,138 +31,62 @@ yarn add dts-element

## Usage

#### normal

Sample
Code

```ts
import * as dts from 'dts-element';

const interface_MyInterface = new dts.InterfaceDeclaration({
const getThing = dts.create_function_declaration({
name: 'getThing',
type: dts.create_function_type({
parameters: [
dts.create_parameter_declaration({
name: 'x',
type: dts.number_type,
}),
],
return: dts.void_type,
}),
});

const MyInterface = dts.create_interface_declaration({
name: 'MyInterface',
jsdoc: 'This is my nice interface',
members: [
new dts.ObjectMember({
owned: new dts.FunctionDeclaration({
name: 'getThing',
type: dts.create_object_type({
members: [
dts.create_object_member({
optional: true,
type: new dts.FunctionType({
parameters: [
new dts.Parameter({
name: 'x',
type: dts.number_type,
}),
],
return: dts.void_type,
}),
owned: getThing,
}),
}),
],
],
}),
});

const namespace_SomeNamespace = new dts.NamespaceDeclaration({
const SomeNamespace = dts.create_namespace_declaration({
name: 'SomeNamespace',
children: [interface_MyInterface],
});

const doucment = new dts.Document({
children: [namespace_SomeNamespace],
members: [MyInterface],
});

console.log(doucment.emit());
console.log(dts.emit(
dts.create_top_level_element({
members: [SomeNamespace],
}),
));
```

Output

```ts
declare namespace SomeNamespace {
/**
* This is my nice interface
*/
interface MyInterface {
getThing?(x: number): void;
}
/**
* This is my nice interface
*/
interface MyInterface {
getThing?(x: number): void;
}
}
```

#### curried-function-types

Sample

```ts
import * as dts from 'dts-element';

const name = 'adjust';
const placeholder = new dts.BasicType({name: 'PH'});

const generic_T = new dts.GenericType({name: 'T'});
const generic_U = new dts.GenericType({name: 'U'});

// <T, U>(fn: (v: T) => U, index: number, array: T[]) => (T | U)[]
const function_type = new dts.FunctionType({
generics: [generic_T, generic_U],
parameters: [
new dts.Parameter({
name: 'fn',
type: new dts.FunctionType({
parameters: [
new dts.Parameter({name: 'v', type: generic_T}),
],
return: generic_U,
}),
}),
new dts.Parameter({name: 'index', type: dts.number_type}),
new dts.Parameter({name: 'array', type: new dts.ArrayType({owned: generic_T})}),
],
return: new dts.ArrayType({owned: new dts.UnionType({types: [generic_T, generic_U]})}),
});

const types = dts.create_curried_function_types({name, type: function_type, placeholder});
const document = new dts.Document({children: types});

console.log(document.emit());
```

Output

```ts
type adjust = adjust_000;
type adjust_000 = {
<T, U>(fn: (v: T) => U, index: number, array: T[]): adjust_111<T, U>;
<T, U>(fn: (v: T) => U, _index: PH, array: T[]): adjust_101<T, U>;
<T>(_fn: PH, index: number, array: T[]): adjust_011<T>;
<T>(_fn: PH, _index: PH, array: T[]): adjust_001<T>;
<T, U>(fn: (v: T) => U, index: number): adjust_110<T, U>;
(_fn: PH, index: number): adjust_010;
<T, U>(fn: (v: T) => U): adjust_100<T, U>;
};
type adjust_001<T> = {
<U>(fn: (v: T) => U, index: number): adjust_111<T, U>;
(_fn: PH, index: number): adjust_011<T>;
<U>(fn: (v: T) => U): adjust_101<T, U>;
};
type adjust_010 = {
<T, U>(fn: (v: T) => U, array: T[]): adjust_111<T, U>;
<T>(_fn: PH, array: T[]): adjust_011<T>;
<T, U>(fn: (v: T) => U): adjust_110<T, U>;
};
type adjust_011<T> = {
<U>(fn: (v: T) => U): adjust_111<T, U>;
};
type adjust_100<T, U> = {
(index: number, array: T[]): adjust_111<T, U>;
(_index: PH, array: T[]): adjust_101<T, U>;
(index: number): adjust_110<T, U>;
};
type adjust_101<T, U> = {
(index: number): adjust_111<T, U>;
};
type adjust_110<T, U> = {
(array: T[]): adjust_111<T, U>;
};
type adjust_111<T, U> = (T | U)[];
```

## Development

```sh
Expand Down
Loading