closure-compiler: Extending computed class name identifiers throws:

Input:

var a = {
  foo: class {}
}

class bar extends a['foo']{
  
}

CC throws:

JSC_DYNAMIC_EXTENDS_TYPE: The class in an extends clause must be a qualified name. at line 6 character 18
class bar extends a['foo']{
                  ^

Is this by design? The JS code is valid.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 20 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I ran into this issue and decided to take a stab at fixing it (despite never having touched the Closure Compiler codebase before…). As far as I can tell, the most elegant solution is to allow CC to consider terms like a.b['c'] as a qualified name, similar (but not equivalent!) to a.b.c.

I don’t want to submit a PR for this as my fix isn’t perfect – it fails some tests – but perhaps somebody more familiar with the codebase can build upon it and complete it: https://github.com/Treeki/closure-compiler/tree/allow-constant-getelem-in-qualified-names

You should be able to do that with type:

type CustomErrorTemp = CustomError<API>;

class APIClientError extends CustomErrorTemp {
// ...
}