From bdf09b2077828aa8c7b38ad419e9282fe5c8bf78 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 3 May 2020 23:32:04 +0200 Subject: [PATCH] Updated the declaration builder --- ChangeLog.md | 2 ++ shared/js/events.ts | 2 +- shared/js/file/Icons.tsx | 2 +- shared/js/ui/frames/MenuBar.ts | 2 +- shared/js/ui/frames/control-bar/dropdown.tsx | 2 +- shared/js/ui/frames/control-bar/index.tsx | 2 +- shared/js/ui/react-elements/Icon.tsx | 2 +- shared/js/ui/tree/Channel.tsx | 2 +- tools/dtsgen/declarator.ts | 24 +++++++++++++++++--- tools/dtsgen/import_organizer.ts | 5 ++++ tools/dtsgen/index.ts | 2 +- tools/dtsgen/test_modular/test_05.ts | 11 +++++++++ 12 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 tools/dtsgen/test_modular/test_05.ts diff --git a/ChangeLog.md b/ChangeLog.md index d11a428f..31ac01da 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,8 @@ - Splitup the file transfer & management part - Added the ability to register a custom file transfer provider (required for the native client) - Added DockerHub image deploy automatisation + - Fixed enum member declaration for the dts generator + - Hiding non exported classes from `.d.ts` files * **25.04.20** - Fixed missing channel tree update on talk power change diff --git a/shared/js/events.ts b/shared/js/events.ts index 8efb7c89..050ffad0 100644 --- a/shared/js/events.ts +++ b/shared/js/events.ts @@ -7,7 +7,7 @@ export interface Event { as() : Events[T]; } -interface SingletonEvents { +export interface SingletonEvents { "singletone-instance": never; } diff --git a/shared/js/file/Icons.tsx b/shared/js/file/Icons.tsx index e9bd6df6..a818b50d 100644 --- a/shared/js/file/Icons.tsx +++ b/shared/js/file/Icons.tsx @@ -21,7 +21,7 @@ export interface IconManagerEvents { } //TODO: Invalidate icon after certain time if loading has failed and try to redownload (only if an icon loader has been set!) -type IconLoader = (icon?: LocalIcon) => Promise; +export type IconLoader = (icon?: LocalIcon) => Promise; export class LocalIcon { readonly icon_id: number; readonly server_unique_id: string; diff --git a/shared/js/ui/frames/MenuBar.ts b/shared/js/ui/frames/MenuBar.ts index fe432670..bc08f128 100644 --- a/shared/js/ui/frames/MenuBar.ts +++ b/shared/js/ui/frames/MenuBar.ts @@ -1,4 +1,3 @@ -import {icon_cache_loader, IconManager, LocalIcon} from "tc-shared/file/FileManager"; import {spawnBookmarkModal} from "tc-shared/ui/modal/ModalBookmarks"; import { add_server_to_bookmarks, @@ -24,6 +23,7 @@ import {server_connections} from "tc-shared/ui/frames/connection_handlers"; import * as loader from "tc-loader"; import {formatMessage} from "tc-shared/ui/frames/chat"; import {control_bar_instance} from "tc-shared/ui/frames/control-bar"; +import {icon_cache_loader, IconManager, LocalIcon} from "tc-shared/file/Icons"; export interface HRItem { } diff --git a/shared/js/ui/frames/control-bar/dropdown.tsx b/shared/js/ui/frames/control-bar/dropdown.tsx index 2481f39c..88bd44d4 100644 --- a/shared/js/ui/frames/control-bar/dropdown.tsx +++ b/shared/js/ui/frames/control-bar/dropdown.tsx @@ -1,7 +1,7 @@ import * as React from "react"; import {ReactComponentBase} from "tc-shared/ui/react-elements/ReactComponentBase"; import {IconRenderer} from "tc-shared/ui/react-elements/Icon"; -import {LocalIcon} from "tc-shared/file/FileManager"; +import {LocalIcon} from "tc-shared/file/Icons"; const cssStyle = require("./button.scss"); export interface DropdownEntryProperties { diff --git a/shared/js/ui/frames/control-bar/index.tsx b/shared/js/ui/frames/control-bar/index.tsx index 26b89f04..7ed45e19 100644 --- a/shared/js/ui/frames/control-bar/index.tsx +++ b/shared/js/ui/frames/control-bar/index.tsx @@ -16,11 +16,11 @@ import { DirectoryBookmark, find_bookmark } from "tc-shared/bookmarks"; -import {icon_cache_loader, IconManager} from "tc-shared/file/FileManager"; import * as contextmenu from "tc-shared/ui/elements/ContextMenu"; import {createInputModal} from "tc-shared/ui/elements/Modal"; import {default_recorder} from "tc-shared/voice/RecorderProfile"; import {global_client_actions} from "tc-shared/events/GlobalEvents"; +import {icon_cache_loader} from "tc-shared/file/Icons"; const cssStyle = require("./index.scss"); const cssButtonStyle = require("./button.scss"); diff --git a/shared/js/ui/react-elements/Icon.tsx b/shared/js/ui/react-elements/Icon.tsx index 7ea50ee1..e12b38ee 100644 --- a/shared/js/ui/react-elements/Icon.tsx +++ b/shared/js/ui/react-elements/Icon.tsx @@ -1,5 +1,5 @@ import * as React from "react"; -import {LocalIcon} from "tc-shared/file/FileManager"; +import {LocalIcon} from "tc-shared/file/Icons"; export interface IconProperties { icon: string | LocalIcon; diff --git a/shared/js/ui/tree/Channel.tsx b/shared/js/ui/tree/Channel.tsx index daa7fa61..0aad1152 100644 --- a/shared/js/ui/tree/Channel.tsx +++ b/shared/js/ui/tree/Channel.tsx @@ -214,7 +214,7 @@ class ChannelEntryName extends ReactComponentBase { last?(): T; @@ -321,6 +322,9 @@ generators[SyntaxKind.PropertyDeclaration] = (settings, stack, node: ts.Property /* class types */ generators[SyntaxKind.ClassDeclaration] = (settings, stack, node: ts.ClassDeclaration) => { + if((stack.flag_namespace || settings.module_mode) && !has_modifier(node.modifiers, SyntaxKind.ExportKeyword)) + return; + const members = [] as ts.Node[]; { stack.push({ @@ -350,7 +354,15 @@ generators[SyntaxKind.ClassDeclaration] = (settings, stack, node: ts.ClassDeclar }); */ - return ts.createClassDeclaration(node.decorators, append_export(append_declare(node.modifiers, !stack.flag_declare), stack.flag_namespace), node.name, node.typeParameters, node.heritageClauses, members as any); + const decorators = node.decorators?.map(e => { + let text: string; + if(e.getSourceFile()) + text = e.getText(); + else + text = "*synthetic added annotation*"; + return ts.createIdentifier("/* " + text.replace("*/", "* /") + " */"); + }); + return ts.createClassDeclaration(decorators as any, append_export(append_declare(node.modifiers, !stack.flag_declare), stack.flag_namespace), node.name, node.typeParameters, node.heritageClauses, members as any); }; generators[SyntaxKind.PropertySignature] = (settings, stack, node: ts.PropertySignature) => { @@ -428,8 +440,14 @@ generators[SyntaxKind.EnumMember] = (settings, stack, node: ts.EnumMember) => { generators[SyntaxKind.EnumDeclaration] = (settings, stack, node: ts.EnumDeclaration) => { const members: any[] = []; - for(const member of node.members) - members.push(generators[SyntaxKind.EnumMember](settings, stack, member)); + + let uninitialized_index = 0; + for(const member of node.members) { + let initializer = member.initializer; + if(!initializer) + initializer = ts.createIdentifier((uninitialized_index++).toString()); + members.push(ts.createEnumMember(member.name, initializer)); + } return ts.createEnumDeclaration(undefined, append_export(append_declare(node.modifiers, !stack.flag_declare), stack.flag_namespace), node.name, members); }; diff --git a/tools/dtsgen/import_organizer.ts b/tools/dtsgen/import_organizer.ts index 998720eb..e791195d 100644 --- a/tools/dtsgen/import_organizer.ts +++ b/tools/dtsgen/import_organizer.ts @@ -248,6 +248,11 @@ function analyze_type_node(node: ts.TypeNode | ts.LeftHandSideExpression, data: break; case SyntaxKind.PropertyAccessExpression: + let pae = node as ts.PropertyAccessExpression; + while(pae.expression.kind == SyntaxKind.PropertyAccessExpression) + pae = pae.expression as ts.PropertyAccessExpression; + + analyze_type_node(pae.expression, data); break; default: diff --git a/tools/dtsgen/index.ts b/tools/dtsgen/index.ts index 1489c6c8..daa8fdad 100644 --- a/tools/dtsgen/index.ts +++ b/tools/dtsgen/index.ts @@ -113,7 +113,7 @@ source_files.forEach(file => { console.log("Compile %s (%s)", _file, relpath); const decl_nodes = decl.generate(source, { - remove_private: false, + remove_private: true, module_mode: module_mode }); diff --git a/tools/dtsgen/test_modular/test_05.ts b/tools/dtsgen/test_modular/test_05.ts new file mode 100644 index 00000000..62a781dd --- /dev/null +++ b/tools/dtsgen/test_modular/test_05.ts @@ -0,0 +1,11 @@ +enum A { + A = "_a", + B = 2, + C, + D = 3, + E +} + +export type B = { + a: A.B +} \ No newline at end of file