Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pass data types (structs) by-value instead of by-ref (#376)
Data types ("structs") are defined through a TypeScript interface that only contains properties and doesn't begin with an `I`. This change also adds a requirement that all properties (shallow) are marked `readonly`. This allows passing around structs by-value safely because any consuming code would not expect to be able to write to the object. Python already passes structs by value, especially in the context of when a struct is used as keyword arguments. This use case will also exist in Ruby. This is also the general perception around data that's passed around in most programming languages. To enforce this, the jsii compiler will now fail if a struct includes properties that are not marked `readonly`. Both the Java and .NET generators have been modified to generate builders which allow users to construct structs by serializing them as JSON hashes instead of passed down by reference. Existing compliance tests in all languages have been fixed. This change fixes aws/aws-cdk#965 and fixes #375 by erasing any `null`s or `undefined` values from passed in objects, so they do not appear to have been defined at all. Added a compliance test called **erase-unset-data-values** to verify. BREAKING CHANGE: all properties in interfaces which represent data types must be marked as `readonly`. Otherwise, jsii compilation will fail.
- Loading branch information