# All files / src/webpack/plugins react-loadable-routes.js

85.71% Statements 18/21
66.67% Branches 4/6
100% Functions 2/2
88.89% Lines 16/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    452x

    4x

    76x
    76x
    76x

    68x

    68x

    68x

    68x
    68x

    68x
    340x
    340x

    68x

    68x

    68x

     const syntax =  require("babel-plugin-syntax-dynamic-import");

    module.exports = ({types: t}) => ({
      inherits: syntax,

      visitor: {
        Import(path) {

          const parent = path.parentPath.parent;
          Iif (parent.type !== "ObjectProperty") return;
          if (parent.key.name !== "component") return;

          const source = path.parentPath.node.arguments[0].value;

          try {

            const obj = path.parentPath.parentPath;

            let propertiesMap = {};
            let newContainer = [];

            obj.container.forEach(property => {
              propertiesMap[property.key.name] = property.value.value;
              newContainer.push(property);
            });

            Iif (propertiesMap.modules) {
              return;
            }

            const moduleObj = t.objectProperty(
              t.identifier("modules"),
              t.arrayExpression([
                t.StringLiteral(source)
              ])
            );

            obj.parentPath.pushContainer("properties", moduleObj);
          } catch(ex) {
            // eslint-disable-next-line
            console.log(ex);
          }
        },
      },
    });