-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jsii): Correctly handle singleton enums (#535)
When an enum has only one option, TypeScript handles it in a special way and tries very hard to hide the enum declaration in favor of the sole member. This caused incorrect type names and kinds to be emitted in the JSII assembly, resulting in incorrect behavior. This uses a non-public part of the TSC API (possibly an omission from the hand-written type model), so it includes an additional guard check to fail explicitly in case the API's behavior happens to change in a breaking way. Fixes #231
- Loading branch information
1 parent
e804cab
commit 01aed03
Showing
20 changed files
with
748 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...azon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonInt.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
/// <summary>Verifies that singleton enums are handled correctly.</summary> | ||
/// <remarks> | ||
/// https://github.com/awslabs/jsii/issues/231 | ||
/// stability: Experimental | ||
/// </remarks> | ||
[JsiiClass(nativeType: typeof(SingletonInt), fullyQualifiedName: "jsii-calc.SingletonInt")] | ||
public class SingletonInt : DeputyBase | ||
{ | ||
protected SingletonInt(ByRefValue reference): base(reference) | ||
{ | ||
} | ||
|
||
protected SingletonInt(DeputyProps props): base(props) | ||
{ | ||
} | ||
|
||
/// <remarks>stability: Experimental</remarks> | ||
[JsiiMethod(name: "isSingletonInt", returnsJson: "{\"type\":{\"primitive\":\"boolean\"}}", parametersJson: "[{\"name\":\"value\",\"type\":{\"primitive\":\"number\"}}]")] | ||
public virtual bool IsSingletonInt(double value) | ||
{ | ||
return InvokeInstanceMethod<bool>(new object[]{value}); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
....JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonIntEnum.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
/// <summary>A singleton integer.</summary> | ||
/// <remarks>stability: Experimental</remarks> | ||
[JsiiEnum(nativeType: typeof(SingletonIntEnum), fullyQualifiedName: "jsii-calc.SingletonIntEnum")] | ||
public enum SingletonIntEnum | ||
{ | ||
/// <summary>Elite!</summary> | ||
/// <remarks>stability: Experimental</remarks> | ||
[JsiiEnumMember(name: "SingletonInt")] | ||
SingletonInt | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...n.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/SingletonString.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Amazon.JSII.Runtime.Deputy; | ||
|
||
namespace Amazon.JSII.Tests.CalculatorNamespace | ||
{ | ||
/// <summary>Verifies that singleton enums are handled correctly.</summary> | ||
/// <remarks> | ||
/// https://github.com/awslabs/jsii/issues/231 | ||
/// stability: Experimental | ||
/// </remarks> | ||
[JsiiClass(nativeType: typeof(SingletonString), fullyQualifiedName: "jsii-calc.SingletonString")] | ||
public class SingletonString : DeputyBase | ||
{ | ||
protected SingletonString(ByRefValue reference): base(reference) | ||
{ | ||
} | ||
|
||
protected SingletonString(DeputyProps props): base(props) | ||
{ | ||
} | ||
|
||
/// <remarks>stability: Experimental</remarks> | ||
[JsiiMethod(name: "isSingletonString", returnsJson: "{\"type\":{\"primitive\":\"boolean\"}}", parametersJson: "[{\"name\":\"value\",\"type\":{\"primitive\":\"string\"}}]")] | ||
public virtual bool IsSingletonString(string value) | ||
{ | ||
return InvokeInstanceMethod<bool>(new object[]{value}); | ||
} | ||
} | ||
} |
Oops, something went wrong.