v0.2.0
Pre-release-
Fix invalid code generation for big tags in enums and unions
bare-ts applies an optimization when tags can be encoded on 7bits.
The general case was not tested yet.
The addition of tests enabled to catch typo errors.
The generated code imported non-existing readers and writers. -
Fix generator choice
The option
--generator
enables to specify which generator is used to
produce the output.
When the output is written to stdout, the generatorts
is used by
default.
The option--generator
should override this default.Previously the option did not override the default.
-
Fix location report upon compilation errors
Upon errors the compiler reports the error and a file location.
Previously, the reported location was shifted by 1 column and at
the end of a token.
Now, the compiler reports the correct location and at the start of a
token.For instance, if a type alias is in lowercase in a bare schema,
then the parser reported an error at the end of the alias.
The error is now reported at the start of the alias:type lowerCaseAlias u8 ^ error was previously reported here ^ error is now reported here
-
Make @bare-ts/tools library platform-agnostic
Use your favorite ESM-ready CDN and simply import @bare-ts/tools.
This was made possible by removing the dependency over node:assert. -
Add
--use-class
optionThis generates classes instead of interfaces for struct types.
-
Automatically handle simple flat unions
By default bare-ts generates tagged unions.
For instance, the following BARE schema:type Union (A | B)
generates the TypeSCript type:
type Union = | { readonly tag: 0, readonly val: A } | { readonly tag: 1, readonly val: B }
You can force the use of flat unions with the option
--use-flat-union
.
However, you have to provide a function that computes the tag of the object.
This function must be exported from a file namedext.{js,ts}
and placed
in the same directory as the file generated by bare-ts.export function tagUnion(x: A | B): 0 | 1 { // returns 0 if x has type A or 1 if x has type B }
bare-ts is now able to compute the tag of simple flat unions without
your help. A simple union is either:- a union of types that can be discriminated by their typeof value, or
- a union of classes (requires the option
--use-class
).
-
Add @bare-ts/lib as peer dependency
This enables to inform the user of @bare-ts/tools which version of
@bare-ts/lib is expected. -
Forbid bare schema with undefined aliases
-
Forbid bare schema in which length and tags are too large
Length of fixed data and (typed) array must be a u32.
This is a limitation of the ECMAScript standard.Tags of enums and unions must be a safe integers.
In the future, this requirement could be relaxed by switching to
bigint for larger integers. -
Forbid bare schema in which the length of a fixed data is 0
The following schema is now invalid:
type EmptyData data<0>
-
Forbid bare schema in which a type is repeated in an union
The following schema is now invalid:
type X (u8 | u8)
Note that the following schema is still valid:
type Y u8 type X (u8 | Y)
Y
is a user-defined type. -
Forbid bare schema in which an enum have several members with the same name
The following schema is now invalid:
enum Gender { FLUID FEMALE MALE FLUID }
-
Forbid bare schema in which a struct have several fields with the same name
The following schema is now invalid:
struct Person { name: string name: string }
-
Forbid bare schema with circular references
-
Better diagnostics when semicolons are used to separate enum or
struct members -
BREAKING CHANGE: adapt to @bare-ts/[email protected]
@bare-ts/[email protected] introduces several breaking changes.
As a consequence:- all decode/encode are renamed into read/write
- all pack/unpack are renamed into encode/decode
- decoders (previously unpackers) no longer accept
ArrayBuffer
as
type of read buffer