mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-27 09:52:19 +00:00
Merge branch 'master' into master
This commit is contained in:
26
tests/ts/JavaScriptUnionUnderlyingTypeTest.js
Normal file
26
tests/ts/JavaScriptUnionUnderlyingTypeTest.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import assert from 'assert'
|
||||
import * as flatbuffers from 'flatbuffers'
|
||||
import {UnionUnderlyingType as Test} from './union_underlying_type_test.js'
|
||||
|
||||
function main() {
|
||||
let a = new Test.AT();
|
||||
a.a = 1;
|
||||
let b = new Test.BT();
|
||||
b.b = "foo";
|
||||
let c = new Test.CT();
|
||||
c.c = true;
|
||||
let d = new Test.DT();
|
||||
d.testUnionType = Test.ABC.A;
|
||||
d.testUnion = a;
|
||||
d.testVectorOfUnionType = [Test.ABC.A, Test.ABC.B, Test.ABC.C];
|
||||
d.testVectorOfUnion = [a, b, c];
|
||||
|
||||
let fbb = new flatbuffers.Builder();
|
||||
let offset = d.pack(fbb);
|
||||
fbb.finish(offset);
|
||||
|
||||
let unpacked = Test.D.getRootAsD(fbb.dataBuffer()).unpack();
|
||||
assert.equal(JSON.stringify(unpacked), JSON.stringify(d));
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -117,6 +117,11 @@ flatc(
|
||||
)
|
||||
esbuild("typescript_keywords.ts", "typescript_keywords_generated.cjs")
|
||||
|
||||
flatc(
|
||||
options=["--ts", "--reflect-names", "--gen-name-strings", "--gen-mutable", "--gen-object-api", "--ts-entry-points", "--ts-flat-files"],
|
||||
schema="../union_underlying_type_test.fbs"
|
||||
)
|
||||
|
||||
print("Running TypeScript Compiler...")
|
||||
check_call(["tsc"])
|
||||
print("Running TypeScript Compiler in old node resolution mode for no_import_ext...")
|
||||
@@ -129,6 +134,7 @@ check_call(NODE_CMD + ["JavaScriptTest"])
|
||||
check_call(NODE_CMD + ["JavaScriptUnionVectorTest"])
|
||||
check_call(NODE_CMD + ["JavaScriptFlexBuffersTest"])
|
||||
check_call(NODE_CMD + ["JavaScriptComplexArraysTest"])
|
||||
check_call(NODE_CMD + ["JavaScriptUnionUnderlyingTypeTest"])
|
||||
|
||||
print("Running old v1 TypeScript Tests...")
|
||||
check_call(NODE_CMD + ["JavaScriptTestv1.cjs", "./monster_test_generated.cjs"])
|
||||
|
||||
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
|
||||
@@ -17,7 +17,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
|
||||
BAZEL_BIN="$(rlocation bazel_linux_x86_64/file/bazel)"
|
||||
readonly BAZEL_BIN
|
||||
|
||||
if [[ ! -e "${BAZEL_BIN}" ]]; then
|
||||
if [[ ! -x "${BAZEL_BIN}" ]]; then
|
||||
echo "Failed to find the bazel binary." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
132
tests/ts/foobar/tab.ts
Normal file
132
tests/ts/foobar/tab.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Abc } from '../foobar/abc.js';
|
||||
import { class_ } from '../foobar/class.js';
|
||||
|
||||
|
||||
export class Tab implements flatbuffers.IUnpackableObject<TabT> {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Tab {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsTab(bb:flatbuffers.ByteBuffer, obj?:Tab):Tab {
|
||||
return (obj || new Tab()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsTab(bb:flatbuffers.ByteBuffer, obj?:Tab):Tab {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Tab()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
abc():Abc {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : Abc.a;
|
||||
}
|
||||
|
||||
mutate_abc(value:Abc):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
arg():class_ {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : class_.arguments_;
|
||||
}
|
||||
|
||||
mutate_arg(value:class_):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
name():string|null
|
||||
name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||
name(optionalEncoding?:any):string|Uint8Array|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'foobar.Tab';
|
||||
}
|
||||
|
||||
static startTab(builder:flatbuffers.Builder) {
|
||||
builder.startObject(3);
|
||||
}
|
||||
|
||||
static addAbc(builder:flatbuffers.Builder, abc:Abc) {
|
||||
builder.addFieldInt32(0, abc, Abc.a);
|
||||
}
|
||||
|
||||
static addArg(builder:flatbuffers.Builder, arg:class_) {
|
||||
builder.addFieldInt32(1, arg, class_.arguments_);
|
||||
}
|
||||
|
||||
static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(2, nameOffset, 0);
|
||||
}
|
||||
|
||||
static endTab(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createTab(builder:flatbuffers.Builder, abc:Abc, arg:class_, nameOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||
Tab.startTab(builder);
|
||||
Tab.addAbc(builder, abc);
|
||||
Tab.addArg(builder, arg);
|
||||
Tab.addName(builder, nameOffset);
|
||||
return Tab.endTab(builder);
|
||||
}
|
||||
|
||||
unpack(): TabT {
|
||||
return new TabT(
|
||||
this.abc(),
|
||||
this.arg(),
|
||||
this.name()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: TabT): void {
|
||||
_o.abc = this.abc();
|
||||
_o.arg = this.arg();
|
||||
_o.name = this.name();
|
||||
}
|
||||
}
|
||||
|
||||
export class TabT implements flatbuffers.IGeneratedObject {
|
||||
constructor(
|
||||
public abc: Abc = Abc.a,
|
||||
public arg: class_ = class_.arguments_,
|
||||
public name: string|Uint8Array|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const name = (this.name !== null ? builder.createString(this.name!) : 0);
|
||||
|
||||
return Tab.createTab(builder,
|
||||
this.abc,
|
||||
this.arg,
|
||||
name
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
@@ -928,6 +932,10 @@ var Monster2 = class {
|
||||
const offset = this.bb.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
/**
|
||||
* an example documentation comment: this will end up in the generated code
|
||||
* multiline too
|
||||
*/
|
||||
testarrayoftables(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 26);
|
||||
return offset ? (obj || new Monster2()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"optional_scalars/**/*.ts",
|
||||
"namespace_test/**/*.ts",
|
||||
"union_vector/**/*.ts",
|
||||
"arrays_test_complex/**/*.ts"
|
||||
"arrays_test_complex/**/*.ts",
|
||||
"union_underlying_type_test.ts"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
@@ -246,6 +250,9 @@ var Type = class {
|
||||
this.bb.writeUint16(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* The size (octets) of the `base_type` field.
|
||||
*/
|
||||
baseSize() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.readUint32(this.bb_pos + offset) : 4;
|
||||
@@ -258,6 +265,9 @@ var Type = class {
|
||||
this.bb.writeUint32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* The size (octets) of the `element` field, if present.
|
||||
*/
|
||||
elementSize() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
|
||||
@@ -779,6 +789,9 @@ var Field = class {
|
||||
this.bb.writeInt8(this.bb_pos + offset, +value);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Number of padding octets to always add after this field. Structs only.
|
||||
*/
|
||||
padding() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 28);
|
||||
return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
|
||||
@@ -1551,6 +1564,10 @@ var Schema = class {
|
||||
this.bb.writeUint64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* All the files used in this compilation. Files are relative to where
|
||||
* flatc was invoked.
|
||||
*/
|
||||
fbsFiles(index, obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 18);
|
||||
return offset ? (obj || new SchemaFile()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
|
||||
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user