From 0e054397e22dd1cb274c99adb315a68863c243f5 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Wed, 21 Aug 2019 13:34:03 +0200 Subject: [PATCH] Improved command handling --- tools/dtsgen/declarator.ts | 23 +++++++++++++++++++---- tools/dtsgen/out.d.ts | 9 +++++---- tools/dtsgen/test/test_06.ts | 6 ++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 tools/dtsgen/test/test_06.ts diff --git a/tools/dtsgen/declarator.ts b/tools/dtsgen/declarator.ts index 5449ebef..13fe17be 100644 --- a/tools/dtsgen/declarator.ts +++ b/tools/dtsgen/declarator.ts @@ -24,9 +24,25 @@ function has_modifier(modifiers: ts.ModifiersArra function append_modifier(modifiers: ts.ModifiersArray | undefined, target: T) : ts.ModifiersArray { if(has_modifier(modifiers, target)) return modifiers; - return ts.createNodeArray([ts.createModifier(target as number), ...(modifiers || [])], (modifiers || {hasTrailingComma: false}).hasTrailingComma); + return ts.createNodeArray( + [ts.createModifier(target as number), ...(modifiers || [])].map((e, index, array) => { + const range = ts.getCommentRange(e); + if(range.end === -1 && range.pos === -1) + return e; + ts.setCommentRange(e, {pos: -1, end: -1}); + + const first_range = ts.getCommentRange(array[0]); + if(first_range.end === -1 && first_range.pos === -1) + ts.setCommentRange(array[0], range); + else + console.warn("Dropping comment on node because first node already has a comment"); + return e; + }), + (modifiers || {hasTrailingComma: false}).hasTrailingComma + ); } +//TODO: Transfer comments? function remove_modifier(modifiers: ts.ModifiersArray | undefined, target: T) : ts.ModifiersArray { if(!has_modifier(modifiers, target)) return modifiers; @@ -103,7 +119,7 @@ class StackParameters implements StackParameter { const generators: {[key: number]:((settings: _Settings, stack: StackParameters, node: ts.Node) => ts.Node | undefined) | undefined} = {}; function _generate(settings: _Settings, stack: StackParameters, layer: ts.Node[], node: ts.Node) { - //console.log(SyntaxKind[node.kind]); + console.log(SyntaxKind[node.kind]); if(generators[node.kind]) { const result = generators[node.kind](settings, stack, node); if(result) @@ -185,8 +201,7 @@ export function generate(file: ts.SourceFile, settings?: Settings) : ts.Node[]{ export function print(source: ts.SourceFile, nodes: ts.Node[]) : string { const printer = ts.createPrinter({ - newLine: ts.NewLineKind.LineFeed, - removeComments: true /* quick fix for comments mess up our target file. May consider to copy comments? (For example a method doc) */ + newLine: ts.NewLineKind.LineFeed }); return printer.printList( diff --git a/tools/dtsgen/out.d.ts b/tools/dtsgen/out.d.ts index a83ad91e..c07e01ce 100644 --- a/tools/dtsgen/out.d.ts +++ b/tools/dtsgen/out.d.ts @@ -1,5 +1,6 @@ -/* File: /home/wolverindev/TeaSpeak/TeaSpeak/Web-Client/tools/dtsgen/test/test_04.ts */ -type T = "a" | "b" | "c"; -declare function _t(parm: T); -declare function __t(); +/* File: C:\Users\WolverinDEV\TeaSpeak\TeaWeb\tools\dtsgen\test\test_05.ts */ +/// +/// +declare abstract class InfoManagerBase { +} diff --git a/tools/dtsgen/test/test_06.ts b/tools/dtsgen/test/test_06.ts new file mode 100644 index 00000000..08f30c6f --- /dev/null +++ b/tools/dtsgen/test/test_06.ts @@ -0,0 +1,6 @@ +/* get () is not allowed within decl files. So declare the variable instead */ + +class A { + get x() { return "X"; } + set x(value: string) {} +} \ No newline at end of file