(node)
| 112 | |
| 113 | return { |
| 114 | ImportDeclaration(node) { |
| 115 | const fileName = context.getFilename(); |
| 116 | if (/test-/.test(context.getFilename())) { |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | const {source, specifiers} = node; |
| 121 | const sourceValue = source.value; |
| 122 | const absolutePath = path |
| 123 | .resolve(path.dirname(fileName), sourceValue) |
| 124 | .replace(/\.js$/, ''); |
| 125 | |
| 126 | // Find out if the import matches one of the modules. |
| 127 | // But we don't know the repo's root directory, so do some work. |
| 128 | const parts = absolutePath.split('/'); |
| 129 | let modulePath = parts.pop(); |
| 130 | let mods; |
| 131 | while (parts.length && !mods) { |
| 132 | modulePath = `${parts.pop()}/${modulePath}`; |
| 133 | mods = imports[modulePath]; |
| 134 | } |
| 135 | |
| 136 | if (!mods) { |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | for (let i = 0; i < specifiers.length; i++) { |
| 141 | const spec = specifiers[i]; |
| 142 | |
| 143 | if (spec.type === 'ImportSpecifier') { |
| 144 | ImportSpecifier(spec, modulePath, mods); |
| 145 | } else if (spec.type === 'ImportNamespaceSpecifier') { |
| 146 | ImportNamespaceSpecifier(spec, sourceValue, mods); |
| 147 | } |
| 148 | } |
| 149 | }, |
| 150 | }; |
| 151 | }; |
nothing calls this directly
no test coverage detected