Sha256: 5caae8f66d93ab197bde383ebdb77f0ba3d8e11171b315c7723dbd501b14939f

Contents?: true

Size: 1.91 KB

Versions: 28

Compression:

Stored size: 1.91 KB

Contents

"use strict";

exports.__esModule = true;
exports.isReactComponent = undefined;
exports.isCompatTag = isCompatTag;
exports.buildChildren = buildChildren;

var _index = require("./index");

var t = _interopRequireWildcard(_index);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

var isReactComponent = exports.isReactComponent = t.buildMatchMemberExpression("React.Component");

function isCompatTag(tagName) {
  return !!tagName && /^[a-z]|\-/.test(tagName);
}

function cleanJSXElementLiteralChild(child, args) {
  var lines = child.value.split(/\r\n|\n|\r/);

  var lastNonEmptyLine = 0;

  for (var i = 0; i < lines.length; i++) {
    if (lines[i].match(/[^ \t]/)) {
      lastNonEmptyLine = i;
    }
  }

  var str = "";

  for (var _i = 0; _i < lines.length; _i++) {
    var line = lines[_i];

    var isFirstLine = _i === 0;
    var isLastLine = _i === lines.length - 1;
    var isLastNonEmptyLine = _i === lastNonEmptyLine;

    var trimmedLine = line.replace(/\t/g, " ");

    if (!isFirstLine) {
      trimmedLine = trimmedLine.replace(/^[ ]+/, "");
    }

    if (!isLastLine) {
      trimmedLine = trimmedLine.replace(/[ ]+$/, "");
    }

    if (trimmedLine) {
      if (!isLastNonEmptyLine) {
        trimmedLine += " ";
      }

      str += trimmedLine;
    }
  }

  if (str) args.push(t.stringLiteral(str));
}

function buildChildren(node) {
  var elems = [];

  for (var i = 0; i < node.children.length; i++) {
    var child = node.children[i];

    if (t.isJSXText(child)) {
      cleanJSXElementLiteralChild(child, elems);
      continue;
    }

    if (t.isJSXExpressionContainer(child)) child = child.expression;
    if (t.isJSXEmptyExpression(child)) continue;

    elems.push(child);
  }

  return elems;
}

Version data entries

28 entries across 28 versions & 9 rubygems

Version Path
immosquare-cleaner-0.1.51 node_modules/babel-types/lib/react.js
immosquare-cleaner-0.1.50 node_modules/babel-types/lib/react.js
immosquare-cleaner-0.1.49 node_modules/babel-types/lib/react.js
immosquare-cleaner-0.1.48 node_modules/babel-types/lib/react.js
immosquare-cleaner-0.1.47 node_modules/babel-types/lib/react.js
immosquare-cleaner-0.1.46 node_modules/babel-types/lib/react.js
immosquare-cleaner-0.1.45 node_modules/babel-types/lib/react.js
immosquare-cleaner-0.1.44 node_modules/babel-types/lib/react.js
immosquare-cleaner-0.1.43 node_modules/babel-types/lib/react.js
immosquare-cleaner-0.1.42 node_modules/babel-types/lib/react.js
immosquare-cleaner-0.1.41 node_modules/babel-types/lib/react.js
immosquare-cleaner-0.1.40 node_modules/babel-types/lib/react.js
ilog-0.4.1 node_modules/babel-types/lib/react.js
ilog-0.4.0 node_modules/babel-types/lib/react.js
ilog-0.3.3 node_modules/babel-types/lib/react.js
optimacms-0.4.3 spec/dummy/node_modules/babel-types/lib/react.js
optimacms-0.4.2 spec/dummy/node_modules/babel-types/lib/react.js
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/babel-types/lib/react.js
lux_assets-0.2.11 ./node_modules/babel-types/lib/react.js
lux_assets-0.2.9 ./node_modules/babel-types/lib/react.js