Skip to content

Emit declaration of class extending intersection#15537

Merged
sandersn merged 4 commits into
masterfrom
emit-declaration-of-class-extending-intersection
May 5, 2017
Merged

Emit declaration of class extending intersection#15537
sandersn merged 4 commits into
masterfrom
emit-declaration-of-class-extending-intersection

Conversation

@sandersn
Copy link
Copy Markdown
Member

@sandersn sandersn commented May 2, 2017

Classes that extend expressions will get a synthetic var declaration for
the expression. This is required for classes that extend an expression
that return an intersection type.

Fixes #14075, but not #15066, which is the full mixin scenario. You still can't export a class that inherits from a class expression that was returned from a function. That probably requires more complicated type declarations to be generated.

sandersn added 2 commits May 2, 2017 13:36
Classes that extend expressions will get a synthetic var declaration for
the expression. This is required for classes that extend an expression
that return an intersection type.
Comment thread src/compiler/declarationEmitter.ts Outdated
const baseTypeNode = getClassExtendsHeritageClauseElement(node);
let tempVarName: string;
if (isNonNullExpression(baseTypeNode)) {
tempVarName = emitTempVariableDeclaration(baseTypeNode.expression, `_${node.name.text}_intersection_base`, {
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.

i would remove the _intersection

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.

do not think you need the leading "_" either

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread src/compiler/declarationEmitter.ts Outdated
if (!noDeclare) {
write("declare ");
}
write("var ");
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.

consider making this const

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread src/compiler/checker.ts Outdated
resolveBaseTypesOfClass(classType);
const baseType = classType.resolvedBaseTypes.length ? classType.resolvedBaseTypes[0] : unknownType;
if (!baseType.symbol) {
if (!baseType.symbol && !(baseType.flags & TypeFlags.Intersection)) {
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.

this should not be necessary here, right? we never call this function with an expression..

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right! Removed.

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented May 5, 2017

@sandersn, does this also address #15572?

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented May 5, 2017

Please port the change to release-2.3 as well.

@sandersn sandersn merged commit 4303a29 into master May 5, 2017
@sandersn sandersn deleted the emit-declaration-of-class-extending-intersection branch May 5, 2017 15:33
@sandersn
Copy link
Copy Markdown
Member Author

sandersn commented May 5, 2017

It should fix #15572 since the error arises from incorrect flattening of an expression in extends. I'm testing it right now.

@sandersn
Copy link
Copy Markdown
Member Author

sandersn commented May 5, 2017

Yes, it fixes #15572. I also ported this change to 2.3

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.

3 participants