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

Parse and ignore private members #49

Merged
merged 1 commit into from
Oct 19, 2017
Merged

Conversation

sbrunk
Copy link
Contributor

@sbrunk sbrunk commented Oct 19, 2017

Compiler generated .d.ts files contain private methods/fields in order to avoid name collisions when subclassing in TypeScript microsoft/TypeScript#1867. The type of private fields is not included.

The approach in this PR is to just ignore them.

modifiers ~ propertyName ~ optionalMarker >> {
case mods ~ name ~ optional => (
functionSignature ^^ (FunctionMember(name, optional, _, mods))
| typeAnnotation ^^ (PropertyMember(name, optional, _, mods))
)
}
} | "private" ~> propertyName ~ (functionSignature | ";") ^^^ PrivateMember
Copy link
Owner

Choose a reason for hiding this comment

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

The semi-colon must not be there. It is already present in the definition of memberBlock.

I suggest extracting this case in a separate lazy val privateMember, and add privateMember as an alternative to typeMember rather than to namedMember.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -262,7 +262,7 @@ class TSDefParser extends StdTokenParsers with ImplicitConversions {
memberBlock ^^ ObjectType

lazy val memberBlock: Parser[List[MemberTree]] =
"{" ~> rep(typeMember <~ opt(";" | ",")) <~ "}"
"{" ~> rep((typeMember | privateMember) <~ opt(";" | ",")) <~ "}"
Copy link
Owner

Choose a reason for hiding this comment

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

Er, sorry, I meant as an alternative in the definition of lazy val typeMember. So a typeMember can be a callMember, etc., or a privateMember. typeMember is any kind of member than kind appear in a memberBlock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sure, totally makes sense looking more closely. So next try :)

@sbrunk
Copy link
Contributor Author

sbrunk commented Oct 19, 2017

private static members can occur as well so I just added support for that

Copy link
Owner

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Thanks

@sjrd sjrd merged commit f55b14f into sjrd:master Oct 19, 2017
@sbrunk sbrunk deleted the private-members branch October 25, 2017 06:15
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.

2 participants