MCPcopy
hub / github.com/ampproject/amphtml / ImportDeclaration

Function ImportDeclaration

build-system/eslint-rules/no-import-rename.js:114–149  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

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};

Callers

nothing calls this directly

Calls 6

resolveMethod · 0.80
ImportSpecifierFunction · 0.70
ImportNamespaceSpecifierFunction · 0.70
testMethod · 0.45
replaceMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected