Finally done :)

canary
WolverinDEV 2018-12-15 13:55:08 +01:00
parent 21e6ce7582
commit 18268ead80
11 changed files with 69 additions and 22 deletions

View File

@ -20,7 +20,7 @@ BASEDIR=$(dirname "$0")
cd "$BASEDIR/../" cd "$BASEDIR/../"
#Building the generator #Building the generator
cd build/dtsgen cd tools/dtsgen
execute_tsc -p tsconfig.json execute_tsc -p tsconfig.json
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to build typescript declaration generator" echo "Failed to build typescript declaration generator"

View File

@ -28,6 +28,4 @@ function execute_npm_command() {
echo "Arguments: ${@:2}" echo "Arguments: ${@:2}"
${!command_variable} ${@:2} ${!command_variable} ${@:2}
} }
execute_npm_command $@

View File

@ -21,30 +21,30 @@ function guid() {
} }
namespace i18n { namespace i18n {
interface TranslationKey { export interface TranslationKey {
message: string; message: string;
line?: number; line?: number;
character?: number; character?: number;
filename?: string; filename?: string;
} }
interface Translation { export interface Translation {
key: TranslationKey; key: TranslationKey;
translated: string; translated: string;
flags?: string[]; flags?: string[];
} }
interface Contributor { export interface Contributor {
name: string; name: string;
email: string; email: string;
} }
interface FileInfo { export interface FileInfo {
name: string; name: string;
contributors: Contributor[]; contributors: Contributor[];
} }
interface TranslationFile { export interface TranslationFile {
url: string; url: string;
info: FileInfo; info: FileInfo;

View File

@ -1,3 +1,4 @@
/// <reference path="../i18n/localize.ts" />
interface JQuery<TElement = HTMLElement> { interface JQuery<TElement = HTMLElement> {
asTabWidget(copy?: boolean) : JQuery<TElement>; asTabWidget(copy?: boolean) : JQuery<TElement>;

View File

@ -6,7 +6,15 @@
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"module": "none", "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": [ "exclude": [
"../js/workers", "../js/workers",

View File

@ -252,7 +252,13 @@ generators[SyntaxKind.Constructor] = (settings, stack, node: ts.ConstructorDecla
generators[SyntaxKind.FunctionDeclaration] = (settings, stack, node: ts.FunctionDeclaration) => { generators[SyntaxKind.FunctionDeclaration] = (settings, stack, node: ts.FunctionDeclaration) => {
if(stack.flag_namespace && !has_modifier(node.modifiers, SyntaxKind.ExportKeyword)) return; 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);
}; };

View File

@ -31,6 +31,10 @@ while(args.length > 0) {
config_file = args[1]; config_file = args[1];
base_path = path.normalize(path.dirname(config_file)); base_path = path.normalize(path.dirname(config_file));
args = args.slice(2); 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 { } else {
console.error("Invalid command line option %s", args[0]); console.error("Invalid command line option %s", args[0]);
process.exit(1); process.exit(1);

View File

@ -31,4 +31,17 @@ namespace T {
export function Y() {} export function Y() {}
} }
}
namespace T {
export async function async_void() {}
export async function async_any() : Promise<any> {
return "" as any;
}
export async function async_number() : Promise<number> {
return 0;
}
export async function async_number_string() : Promise<number | string> {
return 0;
}
} }

View File

@ -209,7 +209,6 @@ export function transform(config: Configuration, context: ts.TransformationConte
//FIXME //FIXME
//if(generated_names.indexOf(name) != -1) //if(generated_names.indexOf(name) != -1)
// return cache.name_generator(config, node, message); // return cache.name_generator(config, node, message);
generated_names.push({name: name, node: node}); generated_names.push({name: name, node: node});
return name; return name;
}; };

View File

@ -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 translations: TranslationEntry[] = [];
const transformer = (context: ts.TransformationContext) => (rootNode: ts.SourceFile) => { const transformer = (context: ts.TransformationContext) =>
console.log("Processing " + rootNode.fileName); (rootNode: ts.Node) => {
const result = ts_generator.transform({ const handler = (rootNode: ts.Node) => {
use_window: false, if(rootNode.kind == ts.SyntaxKind.Bundle) {
replace_cache: true const bundle = rootNode as ts.Bundle;
}, context, rootNode); const result = [];
translations.push(...result.translations); for(const file of bundle.sourceFiles)
return result.node; 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);
}; };

2
vendor/bbcode vendored

@ -1 +1 @@
Subproject commit fafda400bc654848531f8aa163b6cac7cc7abebe Subproject commit 7b931ed61cf265937dc742579f9070e7c4e50775