Skip to content

Commit

Permalink
feat(jsii): Erase un-exported base interfaces instead of prohibiting …
Browse files Browse the repository at this point in the history
…those (#426)

The previous version of interface erasure simply replaced un-exported
interfaces with whatever their exported bases were (if any), but did not
merge declarations of un-exported types into the exported ones.

This merges declarations from the erased interfaces into the exported
interface, and ignores any re-declaration that is hidden by an existing
declaration in the exported type, or another erased interface.

Fixes #417
  • Loading branch information
RomainMuller committed Apr 4, 2019
1 parent d006f5c commit afbabff
Show file tree
Hide file tree
Showing 34 changed files with 888 additions and 216 deletions.
10 changes: 5 additions & 5 deletions packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1464,8 +1464,8 @@ export class InternalClass {
/**
* @internal
*/
export interface IInternalInterface {
prop: string;
export interface InternalInterface {
readonly prop: string;
}

/**
Expand Down Expand Up @@ -1516,19 +1516,19 @@ interface IPrivateInterface {
private: string;
}

export interface ExtendsInternalInterface extends IInternalInterface {
export interface ExtendsInternalInterface extends InternalInterface {
readonly boom: boolean
}

export class ImplementInternalInterface implements IInternalInterface {
export class ImplementInternalInterface implements InternalInterface {
prop = 'implement me'
}

export class ImplementsPrivateInterface implements IPrivateInterface {
public private = 'i came from private into the light'
}

export interface ExtendsPrivateInterface extends IPrivateInterface {
export interface IExtendsPrivateInterface extends IPrivateInterface {
readonly moreThings: string[];
}

Expand Down
14 changes: 14 additions & 0 deletions packages/jsii-calc/lib/erasures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@ export class JSII417Derived extends JSII417PrivateBase {
}
public baz() { return; }
}
// Same thing with interfaces
interface IJSII417PrivateRoot {
readonly hasRoot: boolean;
}
export interface IJSII417PublicBaseOfBase extends IJSII417PrivateRoot {
foo(): void;
}
interface IJSII417PrivateBase extends IJSII417PublicBaseOfBase {
readonly property: string;
bar(): void;
}
export interface IJSII417Derived extends IJSII417PrivateBase {
baz(): void;
}
3 changes: 2 additions & 1 deletion packages/jsii-calc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"scripts": {
"build": "jsii",
"watch": "jsii -w",
"test": "node test/test.calc.js && diff-test test/assembly.jsii .jsii"
"test": "node test/test.calc.js && diff-test test/assembly.jsii .jsii",
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
},
"bundledDependencies": [
"jsii-calc-bundled"
Expand Down
116 changes: 98 additions & 18 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,9 @@
},
{
"name": "b",
"overrides": {
"fqn": "jsii-calc.INonInternalInterface"
},
"type": {
"primitive": "string"
}
Expand Down Expand Up @@ -1181,6 +1184,9 @@
},
{
"name": "b",
"overrides": {
"fqn": "jsii-calc.INonInternalInterface"
},
"type": {
"primitive": "string"
}
Expand Down Expand Up @@ -1895,27 +1901,13 @@
"type": {
"primitive": "boolean"
}
}
]
},
"jsii-calc.ExtendsPrivateInterface": {
"assembly": "jsii-calc",
"datatype": true,
"fqn": "jsii-calc.ExtendsPrivateInterface",
"kind": "interface",
"name": "ExtendsPrivateInterface",
"properties": [
},
{
"abstract": true,
"immutable": true,
"name": "moreThings",
"name": "prop",
"type": {
"collection": {
"elementtype": {
"primitive": "string"
},
"kind": "array"
}
"primitive": "string"
}
}
]
Expand Down Expand Up @@ -2056,6 +2048,34 @@
}
]
},
"jsii-calc.IExtendsPrivateInterface": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IExtendsPrivateInterface",
"kind": "interface",
"name": "IExtendsPrivateInterface",
"properties": [
{
"abstract": true,
"immutable": true,
"name": "moreThings",
"type": {
"collection": {
"elementtype": {
"primitive": "string"
},
"kind": "array"
}
}
},
{
"abstract": true,
"name": "private",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IFriendlier": {
"assembly": "jsii-calc",
"docs": {
Expand Down Expand Up @@ -2257,6 +2277,59 @@
}
]
},
"jsii-calc.IJSII417Derived": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IJSII417Derived",
"interfaces": [
{
"fqn": "jsii-calc.IJSII417PublicBaseOfBase"
}
],
"kind": "interface",
"methods": [
{
"abstract": true,
"name": "bar"
},
{
"abstract": true,
"name": "baz"
}
],
"name": "IJSII417Derived",
"properties": [
{
"abstract": true,
"immutable": true,
"name": "property",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IJSII417PublicBaseOfBase": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IJSII417PublicBaseOfBase",
"kind": "interface",
"methods": [
{
"abstract": true,
"name": "foo"
}
],
"name": "IJSII417PublicBaseOfBase",
"properties": [
{
"abstract": true,
"immutable": true,
"name": "hasRoot",
"type": {
"primitive": "boolean"
}
}
]
},
"jsii-calc.IMutableObjectLiteral": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IMutableObjectLiteral",
Expand All @@ -2283,6 +2356,13 @@
"kind": "interface",
"name": "INonInternalInterface",
"properties": [
{
"abstract": true,
"name": "b",
"type": {
"primitive": "string"
}
},
{
"abstract": true,
"name": "c",
Expand Down Expand Up @@ -4800,5 +4880,5 @@
}
},
"version": "0.8.2",
"fingerprint": "5kMI3UzT9N2sovIndhAmSefEqtrUStnpb0hmWwfLjOs="
"fingerprint": "WJgwH2kAeJLVBMQx/Ek9JLty5tmfiy5sHAz0T8eMX7o="
}
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,9 @@
},
{
"name": "b",
"overrides": {
"fqn": "jsii-calc.INonInternalInterface"
},
"type": {
"primitive": "string"
}
Expand Down Expand Up @@ -1181,6 +1184,9 @@
},
{
"name": "b",
"overrides": {
"fqn": "jsii-calc.INonInternalInterface"
},
"type": {
"primitive": "string"
}
Expand Down Expand Up @@ -1895,27 +1901,13 @@
"type": {
"primitive": "boolean"
}
}
]
},
"jsii-calc.ExtendsPrivateInterface": {
"assembly": "jsii-calc",
"datatype": true,
"fqn": "jsii-calc.ExtendsPrivateInterface",
"kind": "interface",
"name": "ExtendsPrivateInterface",
"properties": [
},
{
"abstract": true,
"immutable": true,
"name": "moreThings",
"name": "prop",
"type": {
"collection": {
"elementtype": {
"primitive": "string"
},
"kind": "array"
}
"primitive": "string"
}
}
]
Expand Down Expand Up @@ -2056,6 +2048,34 @@
}
]
},
"jsii-calc.IExtendsPrivateInterface": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IExtendsPrivateInterface",
"kind": "interface",
"name": "IExtendsPrivateInterface",
"properties": [
{
"abstract": true,
"immutable": true,
"name": "moreThings",
"type": {
"collection": {
"elementtype": {
"primitive": "string"
},
"kind": "array"
}
}
},
{
"abstract": true,
"name": "private",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IFriendlier": {
"assembly": "jsii-calc",
"docs": {
Expand Down Expand Up @@ -2257,6 +2277,59 @@
}
]
},
"jsii-calc.IJSII417Derived": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IJSII417Derived",
"interfaces": [
{
"fqn": "jsii-calc.IJSII417PublicBaseOfBase"
}
],
"kind": "interface",
"methods": [
{
"abstract": true,
"name": "bar"
},
{
"abstract": true,
"name": "baz"
}
],
"name": "IJSII417Derived",
"properties": [
{
"abstract": true,
"immutable": true,
"name": "property",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IJSII417PublicBaseOfBase": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IJSII417PublicBaseOfBase",
"kind": "interface",
"methods": [
{
"abstract": true,
"name": "foo"
}
],
"name": "IJSII417PublicBaseOfBase",
"properties": [
{
"abstract": true,
"immutable": true,
"name": "hasRoot",
"type": {
"primitive": "boolean"
}
}
]
},
"jsii-calc.IMutableObjectLiteral": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IMutableObjectLiteral",
Expand All @@ -2283,6 +2356,13 @@
"kind": "interface",
"name": "INonInternalInterface",
"properties": [
{
"abstract": true,
"name": "b",
"type": {
"primitive": "string"
}
},
{
"abstract": true,
"name": "c",
Expand Down Expand Up @@ -4800,5 +4880,5 @@
}
},
"version": "0.8.2",
"fingerprint": "5kMI3UzT9N2sovIndhAmSefEqtrUStnpb0hmWwfLjOs="
"fingerprint": "WJgwH2kAeJLVBMQx/Ek9JLty5tmfiy5sHAz0T8eMX7o="
}
Loading

0 comments on commit afbabff

Please sign in to comment.