Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jsii): Defaulted parameters were not rendered as optional #234

Merged
merged 2 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,22 @@ export class RuntimeTypeChecking {
public methodWithOptionalArguments(arg1: number, arg2: string, arg3?: Date) {
arg1; arg2; arg3;
}

public methodWithDefaultedArguments(arg1: number = 2, arg2: string, arg3: Date = new Date()) {
RomainMuller marked this conversation as resolved.
Show resolved Hide resolved
arg1; arg2; arg3;
}
}

export class OptionalConstructorArgument {
public constructor(public readonly arg1: number,
public readonly arg2: string,
public readonly arg3?: Date) {}
}

export class DefaultedConstructorArgument {
public constructor(public readonly arg1: number = 2,
public readonly arg2: string,
public readonly arg3: Date = new Date()) {}
}

export namespace DerivedClassHasNoProperties {
Expand Down Expand Up @@ -865,4 +881,4 @@ export class AbstractClassReturner {
abstractProperty: 'hello-abstract-property'
}
}
}
}
135 changes: 134 additions & 1 deletion packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,60 @@
}
]
},
"jsii-calc.DefaultedConstructorArgument": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.DefaultedConstructorArgument",
"initializer": {
"initializer": true,
"parameters": [
{
"name": "arg1",
"type": {
"optional": true,
"primitive": "number"
}
},
{
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"name": "arg3",
"type": {
"optional": true,
"primitive": "date"
}
}
]
},
"kind": "class",
"name": "DefaultedConstructorArgument",
"properties": [
{
"immutable": true,
"name": "arg1",
"type": {
"primitive": "number"
}
},
{
"immutable": true,
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"immutable": true,
"name": "arg3",
"type": {
"primitive": "date"
}
}
]
},
"jsii-calc.DerivedClassHasNoProperties.Base": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.DerivedClassHasNoProperties.Base",
Expand Down Expand Up @@ -2073,6 +2127,60 @@
],
"name": "ObjectRefsInCollections"
},
"jsii-calc.OptionalConstructorArgument": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.OptionalConstructorArgument",
"initializer": {
"initializer": true,
"parameters": [
{
"name": "arg1",
"type": {
"primitive": "number"
}
},
{
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"name": "arg3",
"type": {
"optional": true,
"primitive": "date"
}
}
]
},
"kind": "class",
"name": "OptionalConstructorArgument",
"properties": [
{
"immutable": true,
"name": "arg1",
"type": {
"primitive": "number"
}
},
{
"immutable": true,
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"immutable": true,
"name": "arg3",
"type": {
"optional": true,
"primitive": "date"
}
}
]
},
"jsii-calc.OverrideReturnsObject": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.OverrideReturnsObject",
Expand Down Expand Up @@ -2270,6 +2378,31 @@
},
"kind": "class",
"methods": [
{
"name": "methodWithDefaultedArguments",
"parameters": [
{
"name": "arg1",
"type": {
"optional": true,
"primitive": "number"
}
},
{
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"name": "arg3",
"type": {
"optional": true,
"primitive": "date"
}
}
]
},
{
"docs": {
"comment": "Used to verify verification of number of method arguments."
Expand Down Expand Up @@ -3070,5 +3203,5 @@
}
},
"version": "0.7.5",
"fingerprint": "XrmsNUcNdYiHEC6BRVT5XoeVmYQZzjYgiu6MyibgOwk="
"fingerprint": "PrLv57d+5ukv/bps1DvjB9DpM5DS6TpCEld13gQUTe8="
}
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,60 @@
}
]
},
"jsii-calc.DefaultedConstructorArgument": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.DefaultedConstructorArgument",
"initializer": {
"initializer": true,
"parameters": [
{
"name": "arg1",
"type": {
"optional": true,
"primitive": "number"
}
},
{
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"name": "arg3",
"type": {
"optional": true,
"primitive": "date"
}
}
]
},
"kind": "class",
"name": "DefaultedConstructorArgument",
"properties": [
{
"immutable": true,
"name": "arg1",
"type": {
"primitive": "number"
}
},
{
"immutable": true,
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"immutable": true,
"name": "arg3",
"type": {
"primitive": "date"
}
}
]
},
"jsii-calc.DerivedClassHasNoProperties.Base": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.DerivedClassHasNoProperties.Base",
Expand Down Expand Up @@ -2073,6 +2127,60 @@
],
"name": "ObjectRefsInCollections"
},
"jsii-calc.OptionalConstructorArgument": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.OptionalConstructorArgument",
"initializer": {
"initializer": true,
"parameters": [
{
"name": "arg1",
"type": {
"primitive": "number"
}
},
{
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"name": "arg3",
"type": {
"optional": true,
"primitive": "date"
}
}
]
},
"kind": "class",
"name": "OptionalConstructorArgument",
"properties": [
{
"immutable": true,
"name": "arg1",
"type": {
"primitive": "number"
}
},
{
"immutable": true,
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"immutable": true,
"name": "arg3",
"type": {
"optional": true,
"primitive": "date"
}
}
]
},
"jsii-calc.OverrideReturnsObject": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.OverrideReturnsObject",
Expand Down Expand Up @@ -2270,6 +2378,31 @@
},
"kind": "class",
"methods": [
{
"name": "methodWithDefaultedArguments",
"parameters": [
{
"name": "arg1",
"type": {
"optional": true,
"primitive": "number"
}
},
{
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"name": "arg3",
"type": {
"optional": true,
"primitive": "date"
}
}
]
},
{
"docs": {
"comment": "Used to verify verification of number of method arguments."
Expand Down Expand Up @@ -3070,5 +3203,5 @@
}
},
"version": "0.7.5",
"fingerprint": "XrmsNUcNdYiHEC6BRVT5XoeVmYQZzjYgiu6MyibgOwk="
"fingerprint": "PrLv57d+5ukv/bps1DvjB9DpM5DS6TpCEld13gQUTe8="
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Amazon.JSII.Runtime.Deputy;
using System;

namespace Amazon.JSII.Tests.CalculatorNamespace
{
[JsiiClass(typeof(DefaultedConstructorArgument), "jsii-calc.DefaultedConstructorArgument", "[{\"name\":\"arg1\",\"type\":{\"primitive\":\"number\",\"optional\":true}},{\"name\":\"arg2\",\"type\":{\"primitive\":\"string\"}},{\"name\":\"arg3\",\"type\":{\"primitive\":\"date\",\"optional\":true}}]")]
public class DefaultedConstructorArgument : DeputyBase
{
public DefaultedConstructorArgument(double? arg1, string arg2, DateTime? arg3): base(new DeputyProps(new object[]{arg1, arg2, arg3}))
{
}

protected DefaultedConstructorArgument(ByRefValue reference): base(reference)
{
}

protected DefaultedConstructorArgument(DeputyProps props): base(props)
{
}

[JsiiProperty("arg1", "{\"primitive\":\"number\"}")]
public virtual double Arg1
{
get => GetInstanceProperty<double>();
}

[JsiiProperty("arg2", "{\"primitive\":\"string\"}")]
public virtual string Arg2
{
get => GetInstanceProperty<string>();
}

[JsiiProperty("arg3", "{\"primitive\":\"date\"}")]
public virtual DateTime Arg3
{
get => GetInstanceProperty<DateTime>();
}
}
}
Loading