Skip to content

Should Jessie allow new.target? #128

@gibson042

Description

@gibson042

Without it, I think proper subclass emulation is impossible:

const Ctor = function (...args) {
  // @jessie.js/eslint-plugin disallows all meta-properties, including `new.target`.
  // eslint-disable-next-line no-restricted-syntax
  return Reflect.construct(parent, args, new.target ?? Ctor);
};
Object.defineProperty(Ctor, 'name', { value: name });
Object.setPrototypeOf(Ctor, parent);
Object.setPrototypeOf(Ctor.prototype, parent.prototype);

However, since Subsetting EcmaScript documents exclusion of Reflect as well, I think that's intentional... such an endowment is of course possible, and such an environment has already accepted the complexity of ECMAScript classes, but it would still be a parsing imposition on all Jessie implementations to allow new at the start of a MemberExpression iff followed by symbols . and target.

And finally, note that even if new.target remains disallowed, the current "'import.meta' is not allowed in Jessie" error message is incorrect so use-jessie-rules.js should be updated regardless, e.g.:

     {
       selector: `MetaProperty`,
-      message: `'import.meta' is ${nono}`,
+      message: `meta-properties like 'import.meta' and 'new.target' are ${nono}`,
     },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions