v2.5.0
Install
luarocks install tableshape
opm get leafo/tableshape
What's new?
- add
subclass_of
MoonScript type checker
What's changed?
- add strict type coersion/assertion for types that can take values instead of type literals. Specific changes listed below
- add strict type coersion/assertion to
*
and+
operators: you must pass a valid type or something that can unambiguously be converted into a type literal +
operator can simplify node tree if combining with another add node on both left and right hand side- Undocumented:
types.pattern
coerce option has been reimplemented, supports using a type transformer - Undocumented:
types.pattern
removeinitial_type
option - Undocumented and unused
transformer = true
field on the Transform type has been removed - Reimplement
types.integer
using updatedtypes.pattern
Removal of internal self.opts
field on nodes
These changes should not affect you unless you were using undocumented functionality. The overall goals of these changes are to standardize how type nodes are configured, simplify arguments for type node constructors, and remove multiple ways to accomplish the same thing
- There was an undocumented field on some tableshape types called
opts
that could be used to control some aspects of the type- The default constructor of
BaseType
would look atself.opts
, if it existed, to alter its behavior - This
self.opts
field has been removed from all nodes - Instead of having general purpose
opts
field, each node now must implement their own constructor to handle arguments as they see fit. No documented argument signatures have been changed, but a undocumented finalopts
argument has been removed from many type node constructors
- The default constructor of
- Undocumented featured removed: Previously it was possible to pass in
optional = true
to an options object to automatically callis_optional
on the resulting node. This has been removed - Undocumented feature removed: Previously it was possible for override the
_describe
method by passing in adescribe
field to the options of some nodes. This has been removed. Use the:describe
method to return a new node with that description. - The undocumented
clone_opts
method is now disabled and will throw an error. It previously would clone theopts
field - The default constructor is now an empty function. It is not necessary to call super when inheriting from BaseType when creating your own type class
Stricter validation on options parsing for various types, clean up of arguments
For nodes where the opts argument has been removed: Many nodes supported a last argument of an options table that would be assigned to self.opts
. This was inconsistently implemented, but has been universally removed in this update. See the list below to see what nodes are affected.
- AnnotateNode:
format_error
option must always be a function if provided - AnnotateNode: remove
self.opts
- OptionalType: remove
self.opts
, removeopts
argument - Type:
length
option now usescoerce_literal
to guarantee a valid value is passed for type checking - Type: remove
self.opts
- ArrayType: remove
self.opts
, removeopts
argument - OneOf: remove
self.opts
, removeopts
argument - AllOf: remove
self.opts
, removeopts
argument - ArrayOf:
length
option now usescoerce_literal
- ArrayOf: remove
self.opts
, removeopts
argument - ArrayContains: remove
self.opts
, removeopts
argument - MapOf: Expected key and value now use
coerce_literal
- MapOf: remove
self.opts
, removeopts
argument - Shape:
extra_fields
option is now asserted to be a subclass ofBaseType
- Shape:
is_open
will exclude theextra_fields
option when creating the newShape
object - Shape: remove
self.opts
- Pattern: remove
self.opts
, - Literal: remove
self.opts
, removeopts
argument - Custom: assert that the custom checker is a function type
- Custom: remove
self.opts
, removeopts
argument - Equivalent: remove
self.opts
, removeopts
argument - Range: remove
self.opts
, removeopts
argument - Proxy: remove
self.opts
, removeopts
argument - AssertType: remove
self.opts
, removeopts
argument - NotType: remove
self.opts
, removeopts
argument - MetatableIsType: remove
self.opts
Full Changelog: v2.4.0...v2.5.0