From f16f82f208a57f71ebe5ba61bcc685fbed628069 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Wed, 21 Aug 2019 12:51:52 +0200 Subject: [PATCH] Fixed strings in declarations --- tools/dtsgen/declarator.ts | 21 ++++----------------- tools/dtsgen/index.ts | 2 +- tools/dtsgen/test/test_04.ts | 5 ++++- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/tools/dtsgen/declarator.ts b/tools/dtsgen/declarator.ts index c14d4e88..d2ae2067 100644 --- a/tools/dtsgen/declarator.ts +++ b/tools/dtsgen/declarator.ts @@ -183,15 +183,7 @@ export function generate(file: ts.SourceFile, settings?: Settings) : ts.Node[]{ return layer; } -export function print(nodes: ts.Node[]) : string { - const dummy_file = ts.createSourceFile( - "dummy_file", - "", - ts.ScriptTarget.ES2016, - false, - ts.ScriptKind.TS - ); - +export function print(source: ts.SourceFile, nodes: ts.Node[]) : string { const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); @@ -199,7 +191,7 @@ export function print(nodes: ts.Node[]) : string { return printer.printList( ts.ListFormat.SpaceBetweenBraces | ts.ListFormat.MultiLine | ts.ListFormat.PreferNewLine, nodes as any, - dummy_file + source ); } @@ -379,18 +371,13 @@ generators[SyntaxKind.TypeAliasDeclaration] = (settings, stack, node: ts.TypeAli const union = node.type; for(const element of union.types as any as any[]) { - if(element.kind === SyntaxKind.LiteralType && element.literal && element.literal.text) { - union_members.push(ts.createStringLiteral(element.literal.text)); - } - else - union_members.push(element); - console.log(SyntaxKind[element.kind]); + union_members.push(element); } type = ts.createUnionTypeNode(union_members); } - return ts.createTypeAliasDeclaration(node.decorators, node.modifiers, node.name, node.typeParameters, type); + return ts.createTypeAliasDeclaration(node.decorators, append_declare(node.modifiers, !stack.flag_declare), node.name, node.typeParameters, type); }; generators[SyntaxKind.EnumMember] = (settings, stack, node: ts.EnumMember) => { diff --git a/tools/dtsgen/index.ts b/tools/dtsgen/index.ts index 325c38dd..8b9742ff 100644 --- a/tools/dtsgen/index.ts +++ b/tools/dtsgen/index.ts @@ -86,7 +86,7 @@ source_files.forEach(file => { ); console.log("Compile " + _file); - result += "\n/* File: " + _file + " */\n" + decl.print(decl.generate(source, { + result += "\n/* File: " + _file + " */\n" + decl.print(source, decl.generate(source, { remove_private: false })); }); diff --git a/tools/dtsgen/test/test_04.ts b/tools/dtsgen/test/test_04.ts index bad78697..ea16fd7c 100644 --- a/tools/dtsgen/test/test_04.ts +++ b/tools/dtsgen/test/test_04.ts @@ -1,5 +1,8 @@ type T = "a" | "b" | "c"; function _t(parm: T) {} +function __t() {} -function __t() {} \ No newline at end of file +function __0(a: "a" | "b") { + +} \ No newline at end of file