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

Don't emit __extends if one is already in scope #1356

Closed
wants to merge 1 commit into from

Conversation

RyanCavanaugh
Copy link
Member

Addresses #1350 and probably some other suggestions as well.

This changes the "do we need to emit __extends" logic to see if a symbol named __extends is already in visible scope at the site of the class declaration.

@@ -7886,7 +7886,7 @@ module ts {
var staticType = <ObjectType>getTypeOfSymbol(symbol);
var baseTypeNode = getClassBaseTypeNode(node);
if (baseTypeNode) {
emitExtends = emitExtends || !isInAmbientContext(node);
emitExtends = emitExtends || !(isInAmbientContext(node) || resolveName(node.parent, escapeIdentifier('__extends'), SymbolFlags.Value, undefined, undefined));
Copy link
Contributor

Choose a reason for hiding this comment

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

would this work:

module M {
  export var __extends = () =>{};

  class A { }
  class B extends A { }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Should we have the emitter handle this, or just say that only a global __extends is valid?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can go either ways. limiting it to global __extends seems simple to implement and handles common scenarios.

Copy link
Contributor

Choose a reason for hiding this comment

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

please break this into multiple lines. Or provide a helper function for it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants