@babel/plugin-transform-object-super

Examples

In

  1. let obj = {
  2. say () {
  3. return "Hello"
  4. }
  5. }
  6. let obj2 = {
  7. say () {
  8. return super.say() + "World!"
  9. }
  10. }

Out

  1. var _obj;
  2. var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
  3. var obj = {
  4. say: function say() {
  5. return "Hello";
  6. }
  7. };
  8. var obj2 = _obj = {
  9. say: function say() {
  10. return _get(_obj.__proto__ || Object.getPrototypeOf(_obj), "say", this).call(this) + "World!";
  11. }
  12. };

Installation

  1. npm install --save-dev @babel/plugin-transform-object-super

Usage

  1. {
  2. "plugins": ["@babel/plugin-transform-object-super"]
  3. }

Via CLI

  1. babel --plugins @babel/plugin-transform-object-super script.js

Via Node API

  1. require("@babel/core").transform("code", {
  2. plugins: ["@babel/plugin-transform-object-super"]
  3. });