mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-12 16:00:59 +00:00
Add --ts-undefined-for-optionals command line option (#8861)
* Add --ts-undefined-for-optionals command line option # Details - Fixes #7656 - Added a new `--ts-undefined-for-optionals` command line option for `flatc`. - If enabled, generated TypeScript code uses `undefined` for optional fields rather than `null`. * Also add TS generated test files * Run `sh scripts/clang-format-git.sh` * also add tests/ts/lalala-options.ts to the repo * move new tests to tests/ts/optional_values dir * add tests/ts/optional_values/optional_values_generated.cjs to the repo * reuse existing optional_scalars.fbs and add new test * add comma * sh scripts/clang-format-git.sh * remove comma * sh scripts/clang-format-git.sh * trying things * sh scripts/clang-format-git.sh * done * address feedback * sh scripts/clang-format-git.sh * run `sh scripts/clang-format-git.sh` * remove uneeded `eslint-disable @typescript-eslint/no-namespace` line --------- Co-authored-by: José Luis Millán <jmillan@aliax.net>
This commit is contained in:
committed by
GitHub
parent
95ff1f1d80
commit
3211f857d1
@@ -212,7 +212,7 @@ export class Builder {
|
||||
addFieldInt8(
|
||||
voffset: number,
|
||||
value: number,
|
||||
defaultValue: number | null,
|
||||
defaultValue: number | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value != defaultValue) {
|
||||
this.addInt8(value);
|
||||
@@ -223,7 +223,7 @@ export class Builder {
|
||||
addFieldInt16(
|
||||
voffset: number,
|
||||
value: number,
|
||||
defaultValue: number | null,
|
||||
defaultValue: number | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value != defaultValue) {
|
||||
this.addInt16(value);
|
||||
@@ -234,7 +234,7 @@ export class Builder {
|
||||
addFieldInt32(
|
||||
voffset: number,
|
||||
value: number,
|
||||
defaultValue: number | null,
|
||||
defaultValue: number | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value != defaultValue) {
|
||||
this.addInt32(value);
|
||||
@@ -245,7 +245,7 @@ export class Builder {
|
||||
addFieldInt64(
|
||||
voffset: number,
|
||||
value: bigint,
|
||||
defaultValue: bigint | null,
|
||||
defaultValue: bigint | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value !== defaultValue) {
|
||||
this.addInt64(value);
|
||||
@@ -256,7 +256,7 @@ export class Builder {
|
||||
addFieldFloat32(
|
||||
voffset: number,
|
||||
value: number,
|
||||
defaultValue: number | null,
|
||||
defaultValue: number | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value != defaultValue) {
|
||||
this.addFloat32(value);
|
||||
@@ -267,7 +267,7 @@ export class Builder {
|
||||
addFieldFloat64(
|
||||
voffset: number,
|
||||
value: number,
|
||||
defaultValue: number | null,
|
||||
defaultValue: number | null | undefined,
|
||||
): void {
|
||||
if (this.force_defaults || value != defaultValue) {
|
||||
this.addFloat64(value);
|
||||
@@ -614,8 +614,8 @@ export class Builder {
|
||||
*
|
||||
* @returns offset of obj
|
||||
*/
|
||||
createObjectOffset(obj: string | IGeneratedObject | null): Offset {
|
||||
if (obj === null) {
|
||||
createObjectOffset(obj: string | IGeneratedObject | null | undefined): Offset {
|
||||
if (obj === null || obj === undefined) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -629,7 +629,7 @@ export class Builder {
|
||||
/**
|
||||
* A helper function to pack a list of object
|
||||
*
|
||||
* @returns list of offsets of each non null object
|
||||
* @returns list of offsets of each non null/undefined object
|
||||
*/
|
||||
createObjectOffsetList(list: (string | IGeneratedObject)[]): Offset[] {
|
||||
const ret: number[] = [];
|
||||
@@ -637,11 +637,11 @@ export class Builder {
|
||||
for (let i = 0; i < list.length; ++i) {
|
||||
const val = list[i];
|
||||
|
||||
if (val !== null) {
|
||||
if (val !== null && val !== undefined) {
|
||||
ret.push(this.createObjectOffset(val));
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'FlatBuffers: Argument for createObjectOffsetList cannot contain null.',
|
||||
'FlatBuffers: Argument for createObjectOffsetList cannot contain null or undefined.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
import {Builder} from './flexbuffers/builder.js';
|
||||
import {toReference} from './flexbuffers/reference.js';
|
||||
export {toReference} from './flexbuffers/reference.js';
|
||||
|
||||
Reference in New Issue
Block a user