Skip to content

Followup issue for extending built-ins #7078

Open

Description

@hzoo

Ref #7020

Just making a new issue to track possible changes in another PR

Activity

  1. nicolo-ribaudo commented on Dec 20, 2017

    @nicolo-ribaudo
    Member

    I have already a branch which implements @Kovensky commit, I didn't niclude it in #7020 to avoid introducing too many changes in one pr. nicolo-ribaudo@cbb31c3

    @justinfagnani had a comment: #7020 (comment)

    I can think of two possible implementations:

    • Since Babel now supports JavaScript configuration files, the plugin could accept a function which tells which part of the extend clause needs to be wrapped.
      e.g.

      module.exports = {
        plugins: [
          ["@babel/transform-classes", {
            wrapBuiltin(node) {
              if (node === somethingThatNeedsToBeWrapped) return true;
      
              // class extends mixin(HTMLElement)
              if (
                t.isCallExpression(node) &&
                t.isIdentifier(node.callee, { name: "mixin" }) &&
                t.isIdentifier(node.arguments[0], { name: "HTMLElement" }
              ) {
                return "arguments.0";
              }
            }
          }]
        ]
      };
    • Use a special comment:

      class A extends mixin(/*@babel wrapNative */ HTMLElement) {}
  2. justinfagnani commented on Feb 5, 2018

    @justinfagnani
    Contributor

    I think a simpler solution is to just allow a list of constructors that need to be wrapped in the configuration:

    module.exports = {
      plugins: [
        ["@babel/transform-classes", {
          alwaysWrap: ['HTMLElement']
        }]
      ]
    };

    All extendable built-ins are globals, so this should work fine.

    cc @treshugart who ran into this issue with SkateJS. Since mixins are popular in the web components world, where we also need to extend native classes, it'd be really nice to have this fixed soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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