All files index.js

100% Statements 14/14
87.5% Branches 7/8
100% Functions 3/3
100% Lines 13/13

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  10x 10x 4x       1x 3x   3x 2x   1x   3x       10x 10x 10x 6x            
function hasPrefetchComment(node) {
  const { leadingComments } = node
  return (leadingComments || []).some(comment =>
    comment.value.includes('webpackPrefetch'),
  )
}
 
module.exports = ({ version }) => {
  const babelVersion = Number(version.split('.')[0])
  let dynamicImportPlugin
  if (babelVersion >= 7) {
    dynamicImportPlugin = require('@babel/plugin-syntax-dynamic-import').default
  } else {
    dynamicImportPlugin = require('babel-plugin-syntax-dynamic-import')
  }
  return {
    inherits: dynamicImportPlugin,
    visitor: {
      CallExpression(path) {
        Eif (path.node.callee.type === 'Import') {
          const args = path.get('arguments')
          if (hasPrefetchComment(args[0].node)) return
          args[0].addComment('leading', ' webpackPrefetch: true ')
        }
      },
    },
  }
}