sweet-js/sweet-core

Cannot create syntax literal for class whose superclass is a member expression

suchipi opened this issue · 3 comments

If you attempt to create a class declaration (or expression) inside a syntax template literal that extends a superclass which is accessed via a member expression, an error is thrown:

syntax cannot_use_member_expression_as_superclass = function(ctx) {
  return #`class Foo extends Bar.Baz {}`;
};
cannot_use_member_expression_as_superclass;
// Error: [assertion error]: Not a primary expression
//   at assert (node_modules/sweet.js/dist/errors.js:26:11)
//   at Enforester.enforestPrimaryExpression (node_modules/sweet.js/dist/enforester.js:1259:24)
//   at Enforester.enforestLeftHandSideExpression (node_modules/sweet.js/dist/enforester.js:1298:26)
//   at Enforester.enforestAssignmentExpression (node_modules/sweet.js/dist/enforester.js:1171:19)
//   at Enforester.enforestExpressionLoop (node_modules/sweet.js/dist/enforester.js:1072:23)
//   at Enforester.enforestClass (node_modules/sweet.js/dist/enforester.js:768:19)
//   at Enforester.enforestStatement (node_modules/sweet.js/dist/enforester.js:405:19)
//   at Enforester.enforestModuleItem (node_modules/sweet.js/dist/enforester.js:142:17)
//   at Enforester.enforestBody (node_modules/sweet.js/dist/enforester.js:129:17)
//   at Enforester.enforestModule (node_modules/sweet.js/dist/enforester.js:125:17)

Sweet.js version: 3.0.0

Not related to syntax literal, just a plain extends member expression is sufficient to exercise the bug:

class Foo extends Bar.Baz {} // throws error

I think enforestLeftHandSideExpression can just be called directly. That method didn't exist when the enforestClass was written.

I was wrong. It shouldn't be called directly.

Works great now, thanks!