Skip to content

v2.5.0

Compare
Choose a tag to compare
@leafo leafo released this 15 Nov 05:34
· 3 commits to master since this release

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 remove initial_type option
  • Undocumented and unused transformer = true field on the Transform type has been removed
  • Reimplement types.integer using updated types.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 at self.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 final opts argument has been removed from many type node constructors
  • Undocumented featured removed: Previously it was possible to pass in optional = true to an options object to automatically call is_optional on the resulting node. This has been removed
  • Undocumented feature removed: Previously it was possible for override the _describe method by passing in a describe 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 the opts 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, remove opts argument
  • Type: length option now uses coerce_literal to guarantee a valid value is passed for type checking
  • Type: remove self.opts
  • ArrayType: remove self.opts, remove opts argument
  • OneOf: remove self.opts, remove opts argument
  • AllOf: remove self.opts, remove opts argument
  • ArrayOf: length option now uses coerce_literal
  • ArrayOf: remove self.opts, remove opts argument
  • ArrayContains: remove self.opts, remove opts argument
  • MapOf: Expected key and value now use coerce_literal
  • MapOf: remove self.opts, remove opts argument
  • Shape: extra_fields option is now asserted to be a subclass of BaseType
  • Shape: is_open will exclude the extra_fields option when creating the new Shape object
  • Shape: remove self.opts
  • Pattern: remove self.opts,
  • Literal: remove self.opts, remove opts argument
  • Custom: assert that the custom checker is a function type
  • Custom: remove self.opts, remove opts argument
  • Equivalent: remove self.opts, remove opts argument
  • Range: remove self.opts, remove opts argument
  • Proxy: remove self.opts, remove opts argument
  • AssertType: remove self.opts, remove opts argument
  • NotType: remove self.opts, remove opts argument
  • MetatableIsType: remove self.opts

Full Changelog: v2.4.0...v2.5.0