Finally done :)
parent
21e6ce7582
commit
18268ead80
|
@ -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"
|
||||
|
|
|
@ -29,5 +29,3 @@ function execute_npm_command() {
|
|||
echo "Arguments: ${@:2}"
|
||||
${!command_variable} ${@:2}
|
||||
}
|
||||
|
||||
execute_npm_command $@
|
|
@ -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;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/// <reference path="../i18n/localize.ts" />
|
||||
|
||||
interface JQuery<TElement = HTMLElement> {
|
||||
asTabWidget(copy?: boolean) : JQuery<TElement>;
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -32,3 +32,16 @@ namespace T {
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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 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, rootNode);
|
||||
}, context, file);
|
||||
translations.push(...result.translations);
|
||||
return result.node;
|
||||
} else {
|
||||
console.warn("Invalid transform input: %s", ts.SyntaxKind[rootNode.kind]);
|
||||
}
|
||||
};
|
||||
|
||||
return handler(rootNode);
|
||||
};
|
|
@ -1 +1 @@
|
|||
Subproject commit fafda400bc654848531f8aa163b6cac7cc7abebe
|
||||
Subproject commit 7b931ed61cf265937dc742579f9070e7c4e50775
|
Loading…
Reference in New Issue