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

Crash when class extends <expression> #679

Closed
aomarks opened this issue Dec 21, 2017 · 1 comment
Closed

Crash when class extends <expression> #679

aomarks opened this issue Dec 21, 2017 · 1 comment

Comments

@aomarks
Copy link
Contributor

aomarks commented Dec 21, 2017

tsickle crashes if the RHS of a class extends is an expression instead of a symbol. This pattern is useful when declaring classes built up using class mixin functions as described here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html

declare function MyMixin<T extends new (...args: any[]) => {}>(base: T):
    T & MixinConstructor;

interface MixinConstructor {
  new(...args: any[]): MyMixin;
}

interface MyMixin {
  mixinProp: string;
}

declare class MyClass extends MyMixin(HTMLElement) {
  classProp: string;
}
$ tsickle --externs=tsickle.js
Warning at mixin.d.ts: unhandled type flags: Intersection
/Users/aomarks/.nvm/versions/node/v9.0.0/lib/node_modules/tsickle/src/tsickle.js:1700
                        finally { if (e_18) throw e_18.error; }
                                            ^

Error: no symbol
    at ExternsWriter.ClosureRewriter.mustGetSymbolAtLocation (/Users/aomarks/.nvm/versions/node/v9.0.0/lib/node_modules/tsickle/src/tsickle.js:202:23)
    at ExternsWriter.ClosureRewriter.maybeAddHeritageClauses (/Users/aomarks/.nvm/versions/node/v9.0.0/lib/node_modules/tsickle/src/tsickle.js:488:44)
    at ExternsWriter.writeExternsType (/Users/aomarks/.nvm/versions/node/v9.0.0/lib/node_modules/tsickle/src/tsickle.js:1861:22)
    at ExternsWriter.visit (/Users/aomarks/.nvm/versions/node/v9.0.0/lib/node_modules/tsickle/src/tsickle.js:1788:26)
    at ExternsWriter.visit (/Users/aomarks/.nvm/versions/node/v9.0.0/lib/node_modules/tsickle/src/tsickle.js:1692:34)
    at /Users/aomarks/.nvm/versions/node/v9.0.0/lib/node_modules/tsickle/src/tsickle.js:1669:75
    at Array.forEach (<anonymous>)
    at ExternsWriter.process (/Users/aomarks/.nvm/versions/node/v9.0.0/lib/node_modules/tsickle/src/tsickle.js:1669:36)
    at writeExterns (/Users/aomarks/.nvm/versions/node/v9.0.0/lib/node_modules/tsickle/src/tsickle.js:2071:59)
    at /Users/aomarks/.nvm/versions/node/v9.0.0/lib/node_modules/tsickle/src/tsickle.js:2184:26```
@evmar
Copy link
Contributor

evmar commented Dec 21, 2017

Do you have any thoughts on what closure JS we should emit in this case?

mprobst pushed a commit that referenced this issue Feb 6, 2018
Fixes #679.

It's possible for a class declaration to extend an expression that does
not have a symbol, for example when a mixin function is used to build a
base class, as in `declare MyClass extends MyMixin(MyBaseClass)`.

Handling this correctly is tricky. Closure throws on this
`extends <expression>` syntax (see
google/closure-compiler#2182). We would
probably need to generate an intermediate class declaration and extend
that. For now, just omit the `extends` annotation.
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

No branches or pull requests

2 participants