Sha256: 9bd8a4e88cf8c454d40901398a8ce618b399a353236fb058ce5a184c2ce85bad

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

exports["default"] = function (_ref) {
  var Plugin = _ref.Plugin;

  var immutabilityVisitor = {
    enter: function enter(node, parent, scope, state) {
      var _this = this;

      var stop = function stop() {
        state.isImmutable = false;
        _this.stop();
      };

      if (this.isJSXClosingElement()) {
        this.skip();
        return;
      }

      if (this.isJSXIdentifier({ name: "ref" }) && this.parentPath.isJSXAttribute({ name: node })) {
        return stop();
      }

      if (this.isJSXIdentifier() || this.isIdentifier() || this.isJSXMemberExpression()) {
        return;
      }

      if (!this.isImmutable()) stop();
    }
  };

  return new Plugin("react-constant-elements", {
    metadata: {
      group: "builtin-basic"
    },

    visitor: {
      JSXElement: function JSXElement(node) {
        if (node._hoisted) return;

        var state = { isImmutable: true };
        this.traverse(immutabilityVisitor, state);

        if (state.isImmutable) {
          this.hoist();
        } else {
          node._hoisted = true;
        }
      }
    }
  });
};

module.exports = exports["default"];

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
ilog-0.4.1 node_modules/babel-plugin-react-constant-elements/lib/index.js
ilog-0.4.0 node_modules/babel-plugin-react-constant-elements/lib/index.js
ilog-0.3.3 node_modules/babel-plugin-react-constant-elements/lib/index.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/babel-plugin-react-constant-elements/lib/index.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/babel-plugin-react-constant-elements/lib/index.js
es6_tilt-0.1.2 test/dummy/app/assets/javascripts/node_modules/babel-plugin-react-constant-elements/lib/index.js
es6_tilt-0.1.1 test/dummy/app/assets/javascripts/node_modules/babel-plugin-react-constant-elements/lib/index.js
es6_tilt-0.1.0 test/dummy/app/assets/javascripts/node_modules/babel-plugin-react-constant-elements/lib/index.js