Skip to content

Improvements to generateTypes #28458

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

Merged
2 commits merged into from
Nov 12, 2018
Merged

Improvements to generateTypes #28458

2 commits merged into from
Nov 12, 2018

Conversation

ghost
Copy link

@ghost ghost commented Nov 10, 2018

  • When an object doesn't have the prototype Object.prototype, don't treat it as a namespace but as a const. (Note we can still have a class merged with a namespace even though the class won't have Object.prototype.)
  • Deduplicate instance members detected from parsing the constructor.

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

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

Seems sensible to me but someone who understands prototypes should probably take a look.

forEachOwnNodeOfFunction(fnAst, node => {
if (isAssignmentExpression(node, /*excludeCompoundAssignment*/ true) &&
isPropertyAccessExpression(node.left) && node.left.expression.kind === SyntaxKind.ThisKeyword) {
const name = node.left.name.text;
if (!isJsPrivate(name)) members.push(createProperty(/*decorators*/ undefined, /*modifiers*/ undefined, name, /*questionOrExclamationToken*/ undefined, anyType(), /*initializer*/ undefined));
if (!isJsPrivate(name)) {
members.set(name, createProperty(/*decorators*/ undefined, /*modifiers*/ undefined, name, /*questionOrExclamationToken*/ undefined, anyType(), /*initializer*/ undefined));
Copy link
Member

Choose a reason for hiding this comment

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

Maybe skip the work if name is already present in members?

@ghost ghost merged commit fe1ba9b into master Nov 12, 2018
@ghost ghost deleted the generateTypesImprovements branch November 12, 2018 19:50
This pull request was closed.
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