MCPcopy Create free account
hub / github.com/ampproject/amphtml / processImportMap

Function processImportMap

build-system/eslint-rules/no-duplicate-import.js:26–62  ·  view source on GitHub ↗

* Iterate through imports and report found duplicates. * @param {Map } imports

(imports)

Source from the content-addressed store, hash-verified

24 * @param {Map<string, string>} imports
25 */
26 function processImportMap(imports) {
27 imports.forEach((imports) => {
28 const original = imports[0];
29
30 for (let i = 1; i < imports.length; i++) {
31 const node = imports[i];
32
33 context.report({
34 node,
35 message: `Duplicate import from ${node.source.value}`,
36 fix(fixer) {
37 const originalSpecifiers = original.specifiers;
38 const last = originalSpecifiers[originalSpecifiers.length - 1];
39
40 const {specifiers} = node;
41 let text = '';
42 for (let i = 0; i < specifiers.length; i++) {
43 const {imported, local} = specifiers[i];
44 const {name} = imported;
45
46 if (name === local.name) {
47 text += `, ${name}`;
48 } else {
49 text += `, ${name} as ${local.name}`;
50 }
51 }
52
53 return [
54 fixer.removeRange([node.range[1], node.range[1] + 1]),
55 fixer.remove(node),
56 fixer.insertTextAfter(last, text),
57 ];
58 },
59 });
60 }
61 });
62 }
63
64 return {
65 'Program:exit': function () {

Callers 1

createFunction · 0.85

Calls 2

forEachMethod · 0.45
reportMethod · 0.45

Tested by

no test coverage detected