mirror of
https://github.com/google/flatbuffers.git
synced 2025-04-08 09:12:14 +08:00
* TS/ES6 modules spike iteration 1 * Initial modularized dasherized output * Remove obsoleted parts and namespace wrapping * Use _flatbuffers_ prefix * First part of imports logic * Second part of imports logic * Fix TS/JS code removal mixup * Alias imported symbols if same name from different namespaces and some fixes * Use star import for bare imports * Fix messed up string concat * var to const and remove not needed semi * Remove some cases of ns prefixing * Add missing space * Cleanups * Completed initial import tracking logic * Compilable output * Adjust TypeScriptTest and dependents to work * Use local flatbuffers package for tests * Refactor away use of any * Remove obsolete imported_fileset and reexport_map * Still need any and fix JavaScriptTest.sh * Fix test runs out of the box * Temp add generated files * TypeScriptTest replaces JavaScriptTest and cleanups * Also remove reference to JavaScriptTest in TestAll.sh * Remove old generated ts/js files * Remove use of --js in generate_code scripts * idl_gen_js_ts to idl_gen_ts and removal of js gen * Remove obsoleted options * Fix obsolete ts test detection * Tweak ts compilation be as strict as possible * Remove jsdoc type annotation generation * Generated test ts files * Fix search and replace messup * Regenerated ts test output * Use CharToLower * Use normal for loop * Rework namespacedir * Revert "Rework namespacedir" This reverts commit 6f4eb0104ceeb86011bb076ebca901138c48e068. * Revert "Use normal for loop" This reverts commit 676b2135bfaa1853dfbb06c92b5c16a0d81bb13a. * Revert "Use CharToLower" This reverts commit 2d08648d0d72d0af201fad80d54cdc76412b35e9. * Again do rework but correct * Avoid runtime cast * Fix test runs * Also add npm install to get tsc * Bump node test versions * for range to std for loop * Clang format * Missed one clang format * Move accessor to later * Attempt to make windows version of TypeScriptTest * Want to see the output * Try to get newer node at appveyor * Style changes
42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
// automatically generated by the FlatBuffers compiler, do not modify
|
|
|
|
import { Monster as MyGameExample2Monster, MonsterT as MyGameExample2MonsterT } from '../../my-game/example2/monster';
|
|
import { Monster, MonsterT } from '../../my-game/example/monster';
|
|
import { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from '../../my-game/example/test-simple-table-with-enum';
|
|
|
|
|
|
export enum Any{
|
|
NONE = 0,
|
|
Monster = 1,
|
|
TestSimpleTableWithEnum = 2,
|
|
MyGame_Example2_Monster = 3
|
|
}
|
|
|
|
export function unionToAny(
|
|
type: Any,
|
|
accessor: (obj:Monster|MyGameExample2Monster|TestSimpleTableWithEnum) => Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null
|
|
): Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null {
|
|
switch(Any[type]) {
|
|
case 'NONE': return null;
|
|
case 'Monster': return accessor(new Monster())! as Monster;
|
|
case 'TestSimpleTableWithEnum': return accessor(new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum;
|
|
case 'MyGame_Example2_Monster': return accessor(new MyGameExample2Monster())! as MyGameExample2Monster;
|
|
default: return null;
|
|
}
|
|
}
|
|
|
|
export function unionListToAny(
|
|
type: Any,
|
|
accessor: (index: number, obj:Monster|MyGameExample2Monster|TestSimpleTableWithEnum) => Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null,
|
|
index: number
|
|
): Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null {
|
|
switch(Any[type]) {
|
|
case 'NONE': return null;
|
|
case 'Monster': return accessor(index, new Monster())! as Monster;
|
|
case 'TestSimpleTableWithEnum': return accessor(index, new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum;
|
|
case 'MyGame_Example2_Monster': return accessor(index, new MyGameExample2Monster())! as MyGameExample2Monster;
|
|
default: return null;
|
|
}
|
|
}
|
|
|