mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 07:58:05 +00:00
TS/JS: Use minvalue from enum if not found (#7888)
Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
@@ -474,14 +474,13 @@ class TsGenerator : public BaseGenerator {
|
|||||||
return "BigInt('" + value.constant + "')";
|
return "BigInt('" + value.constant + "')";
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
if (auto val = value.type.enum_def->FindByValue(value.constant)) {
|
EnumVal *val = value.type.enum_def->FindByValue(value.constant);
|
||||||
return AddImport(imports, *value.type.enum_def,
|
if (val == nullptr)
|
||||||
*value.type.enum_def)
|
val = const_cast<EnumVal *>(value.type.enum_def->MinValue());
|
||||||
.name +
|
return AddImport(imports, *value.type.enum_def,
|
||||||
"." + namer_.Variant(*val);
|
*value.type.enum_def)
|
||||||
} else {
|
.name +
|
||||||
return value.constant;
|
"." + namer_.Variant(*val);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|||||||
return to;
|
return to;
|
||||||
};
|
};
|
||||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
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,
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||||
mod
|
mod
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -18,10 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|||||||
return to;
|
return to;
|
||||||
};
|
};
|
||||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
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,
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||||
mod
|
mod
|
||||||
));
|
));
|
||||||
@@ -818,7 +814,7 @@ var Vec3 = class {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var Vec3T = class {
|
var Vec3T = class {
|
||||||
constructor(x = 0, y = 0, z = 0, test1 = 0, test2 = 0, test3 = null) {
|
constructor(x = 0, y = 0, z = 0, test1 = 0, test2 = Color.Red, test3 = null) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
@@ -932,10 +928,6 @@ var Monster2 = class {
|
|||||||
const offset = this.bb.__offset(this.bb_pos, 24);
|
const offset = this.bb.__offset(this.bb_pos, 24);
|
||||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
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) {
|
testarrayoftables(index, obj) {
|
||||||
const offset = this.bb.__offset(this.bb_pos, 26);
|
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;
|
return offset ? (obj || new Monster2()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
import { Color } from '../../my-game/example/color.js';
|
||||||
import { Test } from '../../my-game/example/test.js';
|
import { Test } from '../../my-game/example/test.js';
|
||||||
export class Vec3 {
|
export class Vec3 {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -83,7 +84,7 @@ export class Vec3 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class Vec3T {
|
export class Vec3T {
|
||||||
constructor(x = 0.0, y = 0.0, z = 0.0, test1 = 0.0, test2 = 0, test3 = null) {
|
constructor(x = 0.0, y = 0.0, z = 0.0, test1 = 0.0, test2 = Color.Red, test3 = null) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ constructor(
|
|||||||
public y: number = 0.0,
|
public y: number = 0.0,
|
||||||
public z: number = 0.0,
|
public z: number = 0.0,
|
||||||
public test1: number = 0.0,
|
public test1: number = 0.0,
|
||||||
public test2: Color = 0,
|
public test2: Color = Color.Red,
|
||||||
public test3: TestT|null = null
|
public test3: TestT|null = null
|
||||||
){}
|
){}
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|||||||
return to;
|
return to;
|
||||||
};
|
};
|
||||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
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,
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||||
mod
|
mod
|
||||||
));
|
));
|
||||||
@@ -250,9 +246,6 @@ var Type = class {
|
|||||||
this.bb.writeUint16(this.bb_pos + offset, value);
|
this.bb.writeUint16(this.bb_pos + offset, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* The size (octets) of the `base_type` field.
|
|
||||||
*/
|
|
||||||
baseSize() {
|
baseSize() {
|
||||||
const offset = this.bb.__offset(this.bb_pos, 12);
|
const offset = this.bb.__offset(this.bb_pos, 12);
|
||||||
return offset ? this.bb.readUint32(this.bb_pos + offset) : 4;
|
return offset ? this.bb.readUint32(this.bb_pos + offset) : 4;
|
||||||
@@ -265,9 +258,6 @@ var Type = class {
|
|||||||
this.bb.writeUint32(this.bb_pos + offset, value);
|
this.bb.writeUint32(this.bb_pos + offset, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* The size (octets) of the `element` field, if present.
|
|
||||||
*/
|
|
||||||
elementSize() {
|
elementSize() {
|
||||||
const offset = this.bb.__offset(this.bb_pos, 14);
|
const offset = this.bb.__offset(this.bb_pos, 14);
|
||||||
return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
|
return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
|
||||||
@@ -789,9 +779,6 @@ var Field = class {
|
|||||||
this.bb.writeInt8(this.bb_pos + offset, +value);
|
this.bb.writeInt8(this.bb_pos + offset, +value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Number of padding octets to always add after this field. Structs only.
|
|
||||||
*/
|
|
||||||
padding() {
|
padding() {
|
||||||
const offset = this.bb.__offset(this.bb_pos, 28);
|
const offset = this.bb.__offset(this.bb_pos, 28);
|
||||||
return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
|
return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
|
||||||
@@ -1564,10 +1551,6 @@ var Schema = class {
|
|||||||
this.bb.writeUint64(this.bb_pos + offset, value);
|
this.bb.writeUint64(this.bb_pos + offset, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* All the files used in this compilation. Files are relative to where
|
|
||||||
* flatc was invoked.
|
|
||||||
*/
|
|
||||||
fbsFiles(index, obj) {
|
fbsFiles(index, obj) {
|
||||||
const offset = this.bb.__offset(this.bb_pos, 18);
|
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;
|
return offset ? (obj || new SchemaFile()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||||
|
|||||||
@@ -18,10 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|||||||
return to;
|
return to;
|
||||||
};
|
};
|
||||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
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,
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||||
mod
|
mod
|
||||||
));
|
));
|
||||||
|
|||||||
Reference in New Issue
Block a user