From 18268ead8099d85104872803da5b44e7c6d6f048 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 15 Dec 2018 13:55:08 +0100 Subject: [PATCH] Finally done :) --- scripts/build_declarations.sh | 2 +- scripts/resolve_commands.sh | 4 +--- shared/js/i18n/localize.ts | 10 ++++---- shared/js/utils/tab.ts | 1 + shared/tsconfig/tsconfig_packed.json | 10 +++++++- tools/dtsgen/declarator.ts | 8 ++++++- tools/dtsgen/index.ts | 4 ++++ tools/dtsgen/test/test_01.ts | 13 ++++++++++ tools/trgen/ts_generator.ts | 1 - tools/trgen/ttsc_transformer.ts | 36 +++++++++++++++++++++------- vendor/bbcode | 2 +- 11 files changed, 69 insertions(+), 22 deletions(-) diff --git a/scripts/build_declarations.sh b/scripts/build_declarations.sh index 1276f138..05d75c1c 100755 --- a/scripts/build_declarations.sh +++ b/scripts/build_declarations.sh @@ -20,7 +20,7 @@ BASEDIR=$(dirname "$0") cd "$BASEDIR/../" #Building the generator -cd build/dtsgen +cd tools/dtsgen execute_tsc -p tsconfig.json if [ $? -ne 0 ]; then echo "Failed to build typescript declaration generator" diff --git a/scripts/resolve_commands.sh b/scripts/resolve_commands.sh index 6a3b36b5..9e69e802 100755 --- a/scripts/resolve_commands.sh +++ b/scripts/resolve_commands.sh @@ -28,6 +28,4 @@ function execute_npm_command() { echo "Arguments: ${@:2}" ${!command_variable} ${@:2} -} - -execute_npm_command $@ \ No newline at end of file +} \ No newline at end of file diff --git a/shared/js/i18n/localize.ts b/shared/js/i18n/localize.ts index fd01ff77..5787d3ce 100644 --- a/shared/js/i18n/localize.ts +++ b/shared/js/i18n/localize.ts @@ -21,30 +21,30 @@ function guid() { } namespace i18n { - interface TranslationKey { + export interface TranslationKey { message: string; line?: number; character?: number; filename?: string; } - interface Translation { + export interface Translation { key: TranslationKey; translated: string; flags?: string[]; } - interface Contributor { + export interface Contributor { name: string; email: string; } - interface FileInfo { + export interface FileInfo { name: string; contributors: Contributor[]; } - interface TranslationFile { + export interface TranslationFile { url: string; info: FileInfo; diff --git a/shared/js/utils/tab.ts b/shared/js/utils/tab.ts index 4851248b..92307a0c 100644 --- a/shared/js/utils/tab.ts +++ b/shared/js/utils/tab.ts @@ -1,3 +1,4 @@ +/// interface JQuery { asTabWidget(copy?: boolean) : JQuery; diff --git a/shared/tsconfig/tsconfig_packed.json b/shared/tsconfig/tsconfig_packed.json index 91abde47..75d915dd 100644 --- a/shared/tsconfig/tsconfig_packed.json +++ b/shared/tsconfig/tsconfig_packed.json @@ -6,7 +6,15 @@ "extends": "./tsconfig.json", "compilerOptions": { "module": "none", - "outFile": "../generated/shared.js" + "outFile": "../generated/shared.js", + "plugins": [ /* ttypescript */ + { + "transform": "../../tools/trgen/ttsc_transformer.js", + "type": "program", + "target_file": "../generated/messages_script.json", + "verbose": true + } + ] }, "exclude": [ "../js/workers", diff --git a/tools/dtsgen/declarator.ts b/tools/dtsgen/declarator.ts index c44b2ff9..9f381814 100644 --- a/tools/dtsgen/declarator.ts +++ b/tools/dtsgen/declarator.ts @@ -252,7 +252,13 @@ generators[SyntaxKind.Constructor] = (settings, stack, node: ts.ConstructorDecla generators[SyntaxKind.FunctionDeclaration] = (settings, stack, node: ts.FunctionDeclaration) => { if(stack.flag_namespace && !has_modifier(node.modifiers, SyntaxKind.ExportKeyword)) return; - return ts.createFunctionDeclaration(node.decorators, append_declare(node.modifiers, !stack.flag_declare), node.asteriskToken, node.name, node.typeParameters, _generate_param_declare(settings, stack, node.parameters), node.type, undefined); + let return_type = node.type; + if(has_modifier(node.modifiers, SyntaxKind.AsyncKeyword)) { + if(!return_type) + return_type = ts.createTypeReferenceNode("Promise", [ts.createIdentifier("any") as any]); + } + + return ts.createFunctionDeclaration(node.decorators, remove_modifier(append_declare(node.modifiers, !stack.flag_declare), SyntaxKind.AsyncKeyword), node.asteriskToken, node.name, node.typeParameters, _generate_param_declare(settings, stack, node.parameters), return_type, undefined); }; diff --git a/tools/dtsgen/index.ts b/tools/dtsgen/index.ts index 8147d1a7..325c38dd 100644 --- a/tools/dtsgen/index.ts +++ b/tools/dtsgen/index.ts @@ -31,6 +31,10 @@ while(args.length > 0) { config_file = args[1]; base_path = path.normalize(path.dirname(config_file)); args = args.slice(2); + } else if(args[0] == "-b" || args[0] == "--base") { + base_path = args[1]; + base_path = path.normalize(base_path); + args = args.slice(2); } else { console.error("Invalid command line option %s", args[0]); process.exit(1); diff --git a/tools/dtsgen/test/test_01.ts b/tools/dtsgen/test/test_01.ts index 3c073af4..2caafd2f 100644 --- a/tools/dtsgen/test/test_01.ts +++ b/tools/dtsgen/test/test_01.ts @@ -31,4 +31,17 @@ namespace T { export function Y() {} } +} + +namespace T { + export async function async_void() {} + export async function async_any() : Promise { + return "" as any; + } + export async function async_number() : Promise { + return 0; + } + export async function async_number_string() : Promise { + return 0; + } } \ No newline at end of file diff --git a/tools/trgen/ts_generator.ts b/tools/trgen/ts_generator.ts index b2d19c88..02097924 100644 --- a/tools/trgen/ts_generator.ts +++ b/tools/trgen/ts_generator.ts @@ -209,7 +209,6 @@ export function transform(config: Configuration, context: ts.TransformationConte //FIXME //if(generated_names.indexOf(name) != -1) // return cache.name_generator(config, node, message); - generated_names.push({name: name, node: node}); return name; }; diff --git a/tools/trgen/ttsc_transformer.ts b/tools/trgen/ttsc_transformer.ts index 9bb1eae2..7bc58503 100644 --- a/tools/trgen/ttsc_transformer.ts +++ b/tools/trgen/ttsc_transformer.ts @@ -34,16 +34,34 @@ export default function(program: ts.Program, config?: PluginConfig) : (context: } }); - return ctx => transformer(ctx); + return ctx => transformer(ctx) as any; } const translations: TranslationEntry[] = []; -const transformer = (context: ts.TransformationContext) => (rootNode: ts.SourceFile) => { - console.log("Processing " + rootNode.fileName); - const result = ts_generator.transform({ - use_window: false, - replace_cache: true - }, context, rootNode); - translations.push(...result.translations); - return result.node; +const transformer = (context: ts.TransformationContext) => +(rootNode: ts.Node) => { + const handler = (rootNode: ts.Node) => { + if(rootNode.kind == ts.SyntaxKind.Bundle) { + const bundle = rootNode as ts.Bundle; + const result = []; + for(const file of bundle.sourceFiles) + result.push(handler(file)); + return ts.updateBundle(bundle, result as any, bundle.prepends as any); + + } else if(rootNode.kind == ts.SyntaxKind.SourceFile) { + const file = rootNode as ts.SourceFile; + + console.log("Processing " + file.fileName); + const result = ts_generator.transform({ + use_window: false, + replace_cache: true + }, context, file); + translations.push(...result.translations); + return result.node; + } else { + console.warn("Invalid transform input: %s", ts.SyntaxKind[rootNode.kind]); + } + }; + + return handler(rootNode); }; \ No newline at end of file diff --git a/vendor/bbcode b/vendor/bbcode index fafda400..7b931ed6 160000 --- a/vendor/bbcode +++ b/vendor/bbcode @@ -1 +1 @@ -Subproject commit fafda400bc654848531f8aa163b6cac7cc7abebe +Subproject commit 7b931ed61cf265937dc742579f9070e7c4e50775