From 6df7b216ec92b61d95d227c39c193dc161db9a65 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Fri, 30 Aug 2019 19:16:47 +0200 Subject: [PATCH] fixed type leaks in namespaces --- tools/dtsgen/declarator.ts | 13 ++++++++++++- tools/dtsgen/test/test_07.ts | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tools/dtsgen/test/test_07.ts diff --git a/tools/dtsgen/declarator.ts b/tools/dtsgen/declarator.ts index 99b210b9..f74572e4 100644 --- a/tools/dtsgen/declarator.ts +++ b/tools/dtsgen/declarator.ts @@ -119,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) @@ -381,6 +381,8 @@ generators[SyntaxKind.VariableStatement] = (settings, stack, node: ts.VariableSt }; generators[SyntaxKind.TypeAliasDeclaration] = (settings, stack, node: ts.TypeAliasDeclaration) => { + if(stack.flag_namespace && !has_modifier(node.modifiers, SyntaxKind.ExportKeyword)) return; + let type = node.type; if(type.kind == SyntaxKind.UnionType) { const union_members = []; @@ -405,4 +407,13 @@ generators[SyntaxKind.EnumDeclaration] = (settings, stack, node: ts.EnumDeclarat for(const member of node.members) members.push(generators[SyntaxKind.EnumMember](settings, stack, member)); return ts.createEnumDeclaration(undefined, append_export(append_declare(node.modifiers, !stack.flag_declare), stack.flag_namespace), node.name, members); +}; + +/* every variable in a block has no global scope! */ +generators[SyntaxKind.Block] = (settings, stack, node: ts.EnumMember) => { + return undefined; +}; + +generators[SyntaxKind.IfStatement] = (settings, stack, node: ts.EnumMember) => { + return undefined; }; \ No newline at end of file diff --git a/tools/dtsgen/test/test_07.ts b/tools/dtsgen/test/test_07.ts new file mode 100644 index 00000000..3585856f --- /dev/null +++ b/tools/dtsgen/test/test_07.ts @@ -0,0 +1,7 @@ +namespace C { + type B = string; +} +namespace C { + type B = string; + export function test(arg: string) {} +} \ No newline at end of file