Skip to content

Commit b89fbcb

Browse files
authored
feat: bigIntLiteral option for using BigInt literals (#1063)
Fixes #928. Since I finally got around to contributing, I figured I'd try this old issue out too, and it was surprisingly simple. Entirely up to you whether to trash it or not - it's not a very consequential option and the size optimization should probably be handled by terser/terser#1535 anyway, and it could cause some breakage for users. Supercedes #932.
1 parent db1b1a2 commit b89fbcb

File tree

22 files changed

+1710
-63
lines changed

22 files changed

+1710
-63
lines changed

README.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ Generated code will be placed in the Gradle build directory.
551551

552552
- With `--ts_proto_opt=comments=false`, comments won't be copied from the proto files to the generated code.
553553

554+
- With `--ts_proto_opt=bigIntLiteral=false`, the generated code will use `BigInt("0")` instead of `0n` for BigInt literals. BigInt literals aren't supported by TypeScript when the "target" compiler option set to something older than "ES2020".
555+
554556
- With `--ts_proto_opt=useNullAsOptional=true`, `undefined` values will be converted to `null`, and if you use `optional` label in your `.proto` file, the field will have `undefined` type as well. for example:
555557

556558
```protobuf
@@ -603,7 +605,7 @@ export interface User {
603605
}
604606
```
605607

606-
- With `--ts_proto_opt=noDefaultsForOptionals=true`, `undefined` primitive values will not be defaulted as per the protobuf spec. Additionally unlike the standard behavior, when a field is set to it's standard default value, it *will* be encoded allowing it to be sent over the wire and distinguished from undefined values. For example if a message does not set a boolean value, ordinarily this would be defaulted to `false` which is different to it being undefined.
608+
- With `--ts_proto_opt=noDefaultsForOptionals=true`, `undefined` primitive values will not be defaulted as per the protobuf spec. Additionally unlike the standard behavior, when a field is set to it's standard default value, it *will* be encoded allowing it to be sent over the wire and distinguished from undefined values. For example if a message does not set a boolean value, ordinarily this would be defaulted to `false` which is different to it being undefined.
607609

608610
This option allows the library to act in a compatible way with the [Wire implementation](https://square.github.io/wire/) maintained and used by Square/Block. Note: this option should only be used in combination with other client/server code generated using Wire or ts-proto with this option enabled.
609611

integration/extension-import/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es2018",
3+
"target": "es2020",
44
"lib": ["es2018"],
55
"module": "commonjs",
66
"strict": true,

integration/fieldoption-jstype-with-forcelong-bigint/fieldoption-jstype-with-forcelong-bigint.ts

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/map-bigint-optional/test.ts

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/pbjs.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ if match "simple-long-bigint"; then
5050
yarn run pbts --no-comments -o integration/simple-long-bigint/pbjs.d.ts integration/simple-long-bigint/pbjs.js
5151
fi
5252

53+
if match "simple-long-bigint-noliteral"; then
54+
yarn run pbjs --force-message --force-long -t static-module -o integration/simple-long-bigint-noliteral/pbjs.js integration/simple-long-bigint-noliteral/simple.proto
55+
yarn run pbts --no-comments -o integration/simple-long-bigint-noliteral/pbjs.d.ts integration/simple-long-bigint-noliteral/pbjs.js
56+
fi
57+
5358
if match "vector-tile"; then
5459
yarn run pbjs --force-message --force-number -t static-module -o integration/vector-tile/pbjs.js integration/vector-tile/vector_tile.proto
5560
yarn run pbts --no-comments -o integration/vector-tile/pbjs.d.ts integration/vector-tile/pbjs.js

integration/simple-esmodule-interop/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es2018",
3+
"target": "es2020",
44
"lib": ["es2018"],
55
"module": "commonjs",
66
"strict": true,

integration/simple-long-bigint-noliteral/google/protobuf/timestamp.ts

Lines changed: 217 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)