Skip to content

feat: internal accessibility#390

Merged
eladb merged 4 commits intomasterfrom
benisrae/strip-internal
Mar 19, 2019
Merged

feat: internal accessibility#390
eladb merged 4 commits intomasterfrom
benisrae/strip-internal

Conversation

@eladb
Copy link
Copy Markdown
Contributor

@eladb eladb commented Mar 18, 2019

Respect the @internal jsdoc tag on types and members. Any type of member marked internal will not be exposed in the API of the module and in .d.ts. files (through --strip-internal).

Members (properties/methods) that are marked as @internal must also have an underscore prefix (i.e. _myMethod) and vice versa in order to ensure that implementers or subclasses won't modify accessibility.

If a class implements (or an interface extends) an internal or private interface, that interface is erased from the implementer's API. So it is possible to use internal interfaces as bases, while still maintaining API integrity (related to #287).

Fixes #388

BREAKING CHANGE: member names that begin with underscore now must be marked as "@internal" in their jsdocs, which will cause them to disappear from type declaration files and jsii APIs.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

strips classes, interfaces, enums or members that have an "@internal"
jsdoc tag both from the jsii assembly manifest and .d.ts

fixes #388
@eladb eladb requested a review from a team as a code owner March 18, 2019 22:58
Comment thread packages/jsii-calc/lib/compliance.ts
Comment thread packages/jsii-calc/lib/compliance.ts Outdated
@RomainMuller
Copy link
Copy Markdown
Contributor

Other question that occurred to me now... is @internal on a method inherited by overrides or not? If not, the case for making a single method on an interface internal is really awkward, since that'd have to be repeated for every single implementation of it...

@eladb
Copy link
Copy Markdown
Contributor Author

eladb commented Mar 19, 2019

Other question that occurred to me now... is @internal on a method inherited by overrides or not? If not, the case for making a single method on an interface internal is really awkward, since that'd have to be repeated for every single implementation of it...

That's a good question. Let me check

@eladb
Copy link
Copy Markdown
Contributor Author

eladb commented Mar 19, 2019

So the answer is that you have to explicitly define @internal on all inherited members, or otherwise the typescript compiler will make the method visible. Does it make sense to enforce this with jsii? I guess it does, no?

@eladb eladb changed the title feat: strip @internal feat: internal Mar 19, 2019
Comment thread packages/jsii/test/negatives/neg.internal-underscore.3.ts Outdated
@eladb eladb changed the title feat: internal feat: internal accessibility Mar 19, 2019
@eladb eladb merged commit e232cb5 into master Mar 19, 2019
@eladb eladb deleted the benisrae/strip-internal branch March 19, 2019 13:03

/**
* Members with names starting with ``_`` and members that are private are hidden.
* Members with names starting with `_` (and marked as @internal) and members
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc does no longer reflect what the implementation does.

Comment thread packages/jsii/lib/assembler.ts
Comment thread packages/jsii/lib/assembler.ts
Comment thread packages/jsii/lib/assembler.ts
Comment thread packages/jsii/lib/assembler.ts
Comment thread packages/jsii/lib/assembler.ts
Comment thread packages/jsii/lib/assembler.ts
eladb pushed a commit that referenced this pull request Mar 19, 2019
When a type inherits (extends/implements) from a hidden (private/internal)
interface, and that interface extends a non-hidden interface, we need to 
copy the non-hidden interface to the consuming type so that it can be polymorphically
used.

Follow up on #390

Co-authored-by: RomainMuller <rmuller@amazon.com>
eladb pushed a commit that referenced this pull request Mar 19, 2019
When a type inherits (extends/implements) from a hidden (private/internal)
interface, and that interface extends a non-hidden interface, we need to 
copy the non-hidden interface to the consuming type so that it can be polymorphically
used.

Follow up on #390

Co-authored-by: RomainMuller <rmuller@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

strip elements marked with @internal jsdoc tag

4 participants