mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-19 19:45:43 +00:00
[TS/JS] Move TS tests to dedicated folder and deps upgrade (#7508)
* Move TS tests to dedicated folder and deps upgrade * Attempt to fix generate_code * Fix dir on CI * Add js extension * Fix missing extension * Harmonize with test gen * Unexplained code gen change * Restore yarn.lock * Naive attempt to fix bazel stuff * Pin @bazel/typescript to 5.2.0 * Attempt to fix bazel * More tweak * Upgrade deps * Tweak? * Fix path * Fix test package Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
6
tests/ts/typescript/class.js
Normal file
6
tests/ts/typescript/class.js
Normal file
@@ -0,0 +1,6 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
export var class_;
|
||||
(function (class_) {
|
||||
class_[class_["new_"] = 0] = "new_";
|
||||
class_[class_["instanceof_"] = 1] = "instanceof_";
|
||||
})(class_ || (class_ = {}));
|
||||
6
tests/ts/typescript/class.ts
Normal file
6
tests/ts/typescript/class.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export enum class_ {
|
||||
new_ = 0,
|
||||
instanceof_ = 1
|
||||
}
|
||||
166
tests/ts/typescript/object.js
Normal file
166
tests/ts/typescript/object.js
Normal file
@@ -0,0 +1,166 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
import { Abc } from '../foobar/abc.js';
|
||||
import { class_ as foobar_class_ } from '../foobar/class.js';
|
||||
import { Schema } from '../reflection/schema.js';
|
||||
import { class_ } from '../typescript/class.js';
|
||||
export class Object_ {
|
||||
constructor() {
|
||||
this.bb = null;
|
||||
this.bb_pos = 0;
|
||||
}
|
||||
__init(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
static getRootAsObject(bb, obj) {
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
static getSizePrefixedRootAsObject(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
return_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_return(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 4);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
if_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_if(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 6);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
switch_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
mutate_switch(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 8);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
enum_() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : class_.new_;
|
||||
}
|
||||
mutate_enum(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 10);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
enum2() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : foobar_class_.arguments_;
|
||||
}
|
||||
mutate_enum2(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
enum3() {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.readInt32(this.bb_pos + offset) : Abc.a;
|
||||
}
|
||||
mutate_enum3(value) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
reflect(obj) {
|
||||
const offset = this.bb.__offset(this.bb_pos, 16);
|
||||
return offset ? (obj || new Schema()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
|
||||
}
|
||||
static getFullyQualifiedName() {
|
||||
return 'typescript_Object';
|
||||
}
|
||||
static startObject(builder) {
|
||||
builder.startObject(7);
|
||||
}
|
||||
static addReturn(builder, return_) {
|
||||
builder.addFieldInt32(0, return_, 0);
|
||||
}
|
||||
static addIf(builder, if_) {
|
||||
builder.addFieldInt32(1, if_, 0);
|
||||
}
|
||||
static addSwitch(builder, switch_) {
|
||||
builder.addFieldInt32(2, switch_, 0);
|
||||
}
|
||||
static addEnum(builder, enum_) {
|
||||
builder.addFieldInt32(3, enum_, class_.new_);
|
||||
}
|
||||
static addEnum2(builder, enum2) {
|
||||
builder.addFieldInt32(4, enum2, foobar_class_.arguments_);
|
||||
}
|
||||
static addEnum3(builder, enum3) {
|
||||
builder.addFieldInt32(5, enum3, Abc.a);
|
||||
}
|
||||
static addReflect(builder, reflectOffset) {
|
||||
builder.addFieldOffset(6, reflectOffset, 0);
|
||||
}
|
||||
static endObject(builder) {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
unpack() {
|
||||
return new Object_T(this.return_(), this.if_(), this.switch_(), this.enum_(), this.enum2(), this.enum3(), (this.reflect() !== null ? this.reflect().unpack() : null));
|
||||
}
|
||||
unpackTo(_o) {
|
||||
_o.return_ = this.return_();
|
||||
_o.if_ = this.if_();
|
||||
_o.switch_ = this.switch_();
|
||||
_o.enum_ = this.enum_();
|
||||
_o.enum2 = this.enum2();
|
||||
_o.enum3 = this.enum3();
|
||||
_o.reflect = (this.reflect() !== null ? this.reflect().unpack() : null);
|
||||
}
|
||||
}
|
||||
export class Object_T {
|
||||
constructor(return_ = 0, if_ = 0, switch_ = 0, enum_ = class_.new_, enum2 = foobar_class_.arguments_, enum3 = Abc.a, reflect = null) {
|
||||
this.return_ = return_;
|
||||
this.if_ = if_;
|
||||
this.switch_ = switch_;
|
||||
this.enum_ = enum_;
|
||||
this.enum2 = enum2;
|
||||
this.enum3 = enum3;
|
||||
this.reflect = reflect;
|
||||
}
|
||||
pack(builder) {
|
||||
const reflect = (this.reflect !== null ? this.reflect.pack(builder) : 0);
|
||||
Object_.startObject(builder);
|
||||
Object_.addReturn(builder, this.return_);
|
||||
Object_.addIf(builder, this.if_);
|
||||
Object_.addSwitch(builder, this.switch_);
|
||||
Object_.addEnum(builder, this.enum_);
|
||||
Object_.addEnum2(builder, this.enum2);
|
||||
Object_.addEnum3(builder, this.enum3);
|
||||
Object_.addReflect(builder, reflect);
|
||||
return Object_.endObject(builder);
|
||||
}
|
||||
}
|
||||
222
tests/ts/typescript/object.ts
Normal file
222
tests/ts/typescript/object.ts
Normal file
@@ -0,0 +1,222 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Abc } from '../foobar/abc.js';
|
||||
import { class_ as foobar_class_ } from '../foobar/class.js';
|
||||
import { Schema, SchemaT } from '../reflection/schema.js';
|
||||
import { class_ } from '../typescript/class.js';
|
||||
|
||||
|
||||
export class Object_ {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Object_ {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ {
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
return_():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_return(value:number):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;
|
||||
}
|
||||
|
||||
if_():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_if(value:number):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;
|
||||
}
|
||||
|
||||
switch_():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_switch(value:number):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum_():class_ {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : class_.new_;
|
||||
}
|
||||
|
||||
mutate_enum(value:class_):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum2():foobar_class_ {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : foobar_class_.arguments_;
|
||||
}
|
||||
|
||||
mutate_enum2(value:foobar_class_):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum3():Abc {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : Abc.a;
|
||||
}
|
||||
|
||||
mutate_enum3(value:Abc):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 14);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
reflect(obj?:Schema):Schema|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 16);
|
||||
return offset ? (obj || new Schema()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'typescript_Object';
|
||||
}
|
||||
|
||||
static startObject(builder:flatbuffers.Builder) {
|
||||
builder.startObject(7);
|
||||
}
|
||||
|
||||
static addReturn(builder:flatbuffers.Builder, return_:number) {
|
||||
builder.addFieldInt32(0, return_, 0);
|
||||
}
|
||||
|
||||
static addIf(builder:flatbuffers.Builder, if_:number) {
|
||||
builder.addFieldInt32(1, if_, 0);
|
||||
}
|
||||
|
||||
static addSwitch(builder:flatbuffers.Builder, switch_:number) {
|
||||
builder.addFieldInt32(2, switch_, 0);
|
||||
}
|
||||
|
||||
static addEnum(builder:flatbuffers.Builder, enum_:class_) {
|
||||
builder.addFieldInt32(3, enum_, class_.new_);
|
||||
}
|
||||
|
||||
static addEnum2(builder:flatbuffers.Builder, enum2:foobar_class_) {
|
||||
builder.addFieldInt32(4, enum2, foobar_class_.arguments_);
|
||||
}
|
||||
|
||||
static addEnum3(builder:flatbuffers.Builder, enum3:Abc) {
|
||||
builder.addFieldInt32(5, enum3, Abc.a);
|
||||
}
|
||||
|
||||
static addReflect(builder:flatbuffers.Builder, reflectOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(6, reflectOffset, 0);
|
||||
}
|
||||
|
||||
static endObject(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
unpack(): Object_T {
|
||||
return new Object_T(
|
||||
this.return_(),
|
||||
this.if_(),
|
||||
this.switch_(),
|
||||
this.enum_(),
|
||||
this.enum2(),
|
||||
this.enum3(),
|
||||
(this.reflect() !== null ? this.reflect()!.unpack() : null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: Object_T): void {
|
||||
_o.return_ = this.return_();
|
||||
_o.if_ = this.if_();
|
||||
_o.switch_ = this.switch_();
|
||||
_o.enum_ = this.enum_();
|
||||
_o.enum2 = this.enum2();
|
||||
_o.enum3 = this.enum3();
|
||||
_o.reflect = (this.reflect() !== null ? this.reflect()!.unpack() : null);
|
||||
}
|
||||
}
|
||||
|
||||
export class Object_T {
|
||||
constructor(
|
||||
public return_: number = 0,
|
||||
public if_: number = 0,
|
||||
public switch_: number = 0,
|
||||
public enum_: class_ = class_.new_,
|
||||
public enum2: foobar_class_ = foobar_class_.arguments_,
|
||||
public enum3: Abc = Abc.a,
|
||||
public reflect: SchemaT|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const reflect = (this.reflect !== null ? this.reflect!.pack(builder) : 0);
|
||||
|
||||
Object_.startObject(builder);
|
||||
Object_.addReturn(builder, this.return_);
|
||||
Object_.addIf(builder, this.if_);
|
||||
Object_.addSwitch(builder, this.switch_);
|
||||
Object_.addEnum(builder, this.enum_);
|
||||
Object_.addEnum2(builder, this.enum2);
|
||||
Object_.addEnum3(builder, this.enum3);
|
||||
Object_.addReflect(builder, reflect);
|
||||
|
||||
return Object_.endObject(builder);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user