Comparing version 2.0.1 to 2.1.0
@@ -121,2 +121,6 @@ export interface DeclarationBase { | ||
} | ||
export interface ExportDefaultDeclaration extends DeclarationBase { | ||
kind: "exportDefault"; | ||
name: string; | ||
} | ||
export interface ExportNameDeclaration extends DeclarationBase { | ||
@@ -201,4 +205,4 @@ kind: "exportName"; | ||
export declare type NamespaceMember = InterfaceDeclaration | TypeAliasDeclaration | ClassDeclaration | NamespaceDeclaration | ConstDeclaration | VariableDeclaration | FunctionDeclaration; | ||
export declare type ModuleMember = InterfaceDeclaration | TypeAliasDeclaration | ClassDeclaration | NamespaceDeclaration | ConstDeclaration | VariableDeclaration | FunctionDeclaration | Import; | ||
export declare type TopLevelDeclaration = NamespaceMember | ExportEqualsDeclaration | ExportNameDeclaration | ModuleDeclaration | EnumDeclaration | Import; | ||
export declare type ModuleMember = InterfaceDeclaration | TypeAliasDeclaration | ClassDeclaration | NamespaceDeclaration | ConstDeclaration | VariableDeclaration | FunctionDeclaration | Import | ExportEqualsDeclaration | ExportDefaultDeclaration; | ||
export declare type TopLevelDeclaration = NamespaceMember | ExportEqualsDeclaration | ExportDefaultDeclaration | ExportNameDeclaration | ModuleDeclaration | EnumDeclaration | Import; | ||
export declare enum DeclarationFlags { | ||
@@ -246,2 +250,3 @@ None = 0, | ||
exportEquals(target: string): ExportEqualsDeclaration; | ||
exportDefault(name: string): ExportDefaultDeclaration; | ||
exportName(name: string, as?: string | undefined): ExportNameDeclaration; | ||
@@ -248,0 +253,0 @@ module(name: string): ModuleDeclaration; |
@@ -175,2 +175,8 @@ "use strict"; | ||
}, | ||
exportDefault: function (name) { | ||
return { | ||
kind: 'exportDefault', | ||
name: name | ||
}; | ||
}, | ||
exportName: function (name, as) { | ||
@@ -335,3 +341,5 @@ return { | ||
var indentLevel = 0; | ||
var contextStack = [rootFlags]; | ||
var isModuleWithModuleFlag = rootDecl.kind === 'module' && rootFlags === ContextFlags.Module; | ||
// For a module root declaration we must omit the module flag. | ||
var contextStack = isModuleWithModuleFlag ? [] : [rootFlags]; | ||
tripleSlashDirectives.forEach(writeTripleSlashDirective); | ||
@@ -396,2 +404,5 @@ writeDeclaration(rootDecl); | ||
} | ||
else if (getContextFlags() & ContextFlags.Module) { | ||
start(s); | ||
} | ||
else { | ||
@@ -778,2 +789,6 @@ start("declare " + s); | ||
} | ||
function writeExportDefault(e) { | ||
start("export default " + e.name + ";"); | ||
newline(); | ||
} | ||
function writeExportName(e) { | ||
@@ -784,3 +799,3 @@ start("export { " + e.name); | ||
} | ||
print(" };"); | ||
print(' };'); | ||
newline(); | ||
@@ -901,2 +916,4 @@ } | ||
return writeExportEquals(d); | ||
case "exportDefault": | ||
return writeExportDefault(d); | ||
case "exportName": | ||
@@ -903,0 +920,0 @@ return writeExportName(d); |
@@ -14,3 +14,3 @@ import {ContextFlags, TripleSlashDirective, create, emit} from "../index" | ||
const module = create.module("test"); | ||
const emitOptions = {rootFlags: ContextFlags.Module, tripleSlashDirectives}; | ||
const emitOptions = {tripleSlashDirectives}; | ||
@@ -25,4 +25,4 @@ expect(emit(module, emitOptions)).toMatchSnapshot(); | ||
expect(emit(module, {rootFlags: ContextFlags.Module})).toMatchSnapshot(); | ||
expect(emit(module)).toMatchSnapshot(); | ||
}); | ||
}); |
@@ -143,2 +143,7 @@ export interface DeclarationBase { | ||
export interface ExportDefaultDeclaration extends DeclarationBase { | ||
kind: "exportDefault"; | ||
name: string; | ||
} | ||
export interface ExportNameDeclaration extends DeclarationBase { | ||
@@ -246,4 +251,4 @@ kind: "exportName"; | ||
export type NamespaceMember = InterfaceDeclaration | TypeAliasDeclaration | ClassDeclaration | NamespaceDeclaration | ConstDeclaration | VariableDeclaration | FunctionDeclaration; | ||
export type ModuleMember = InterfaceDeclaration | TypeAliasDeclaration | ClassDeclaration | NamespaceDeclaration | ConstDeclaration | VariableDeclaration | FunctionDeclaration | Import; | ||
export type TopLevelDeclaration = NamespaceMember | ExportEqualsDeclaration | ExportNameDeclaration | ModuleDeclaration | EnumDeclaration | Import; | ||
export type ModuleMember = InterfaceDeclaration | TypeAliasDeclaration | ClassDeclaration | NamespaceDeclaration | ConstDeclaration | VariableDeclaration | FunctionDeclaration | Import | ExportEqualsDeclaration | ExportDefaultDeclaration; | ||
export type TopLevelDeclaration = NamespaceMember | ExportEqualsDeclaration | ExportDefaultDeclaration | ExportNameDeclaration | ModuleDeclaration | EnumDeclaration | Import; | ||
@@ -433,2 +438,9 @@ export enum DeclarationFlags { | ||
exportDefault(name: string): ExportDefaultDeclaration { | ||
return { | ||
kind: 'exportDefault', | ||
name | ||
}; | ||
}, | ||
exportName(name: string, as?: string): ExportNameDeclaration { | ||
@@ -611,4 +623,7 @@ return { | ||
let indentLevel = 0; | ||
let contextStack: ContextFlags[] = [rootFlags]; | ||
const isModuleWithModuleFlag = rootDecl.kind === 'module' && rootFlags === ContextFlags.Module; | ||
// For a module root declaration we must omit the module flag. | ||
const contextStack: ContextFlags[] = isModuleWithModuleFlag ? [] : [rootFlags]; | ||
tripleSlashDirectives.forEach(writeTripleSlashDirective); | ||
@@ -682,2 +697,4 @@ | ||
start(`export default ${s}`); | ||
} else if (getContextFlags() & ContextFlags.Module) { | ||
start(s); | ||
} else { | ||
@@ -1084,2 +1101,7 @@ start(`declare ${s}`); | ||
function writeExportDefault(e: ExportDefaultDeclaration) { | ||
start(`export default ${e.name};`); | ||
newline(); | ||
} | ||
function writeExportName(e: ExportNameDeclaration) { | ||
@@ -1090,3 +1112,3 @@ start(`export { ${e.name}`); | ||
} | ||
print(` };`); | ||
print(' };'); | ||
newline(); | ||
@@ -1217,2 +1239,4 @@ } | ||
return writeExportEquals(d); | ||
case "exportDefault": | ||
return writeExportDefault(d); | ||
case "exportName": | ||
@@ -1219,0 +1243,0 @@ return writeExportName(d); |
{ | ||
"name": "dts-dom", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"homepage": "https://github.com/RyanCavanaugh/dts-dom", | ||
@@ -5,0 +5,0 @@ "description": "DOM for TypeScript Declaration Files", |
@@ -46,2 +46,21 @@ [![npm version](https://badge.fury.io/js/dts-dom.svg)](https://badge.fury.io/js/dts-dom) | ||
## 2.1 | ||
* **New Functionality**: Added the ability to emit `export default` assignments | ||
```ts | ||
const module = create.module('my-module'); | ||
const constDeclaration = create.const('test', 'string'); | ||
const exportDefault = create.exportDefault('test'); | ||
module.members.push(constDeclaration, exportDefault); | ||
const s = emit(module); | ||
``` | ||
Produces: | ||
```ts | ||
declare module 'my-module' { | ||
const test: string; | ||
export default test; | ||
} | ||
``` | ||
* **Non-breaking Change**: Superfluous `declare` keywords are no longer emitted inside `module` declarations | ||
## 2.0 | ||
@@ -97,2 +116,2 @@ * **New Functionality**: Added the ability to emit [triple-slash directives](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) #39 | ||
* [Hendrik Liebau](https://github.com/KingHenne) | ||
* [Timur Amirov](https://github.com/DeTeam) | ||
* [Timur Amirov](https://github.com/DeTeam) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
127827
28
2515
116