MCPcopy
hub / github.com/rollup/rollup / addImport

Method addImport

src/Module.ts:1162–1190  ·  view source on GitHub ↗
(node: ImportDeclaration)

Source from the content-addressed store, hash-verified

1160 }
1161
1162 private addImport(node: ImportDeclaration): void {
1163 const source = node.source.value;
1164 this.addSource(source, node);
1165
1166 for (const specifier of node.specifiers) {
1167 const localName = specifier.local.name;
1168 if (this.scope.variables.has(localName) || this.importDescriptions.has(localName)) {
1169 this.error(logRedeclarationError(localName), specifier.local.start);
1170 }
1171
1172 const name =
1173 node.phase === 'source'
1174 ? SOURCE_PHASE_IMPORT
1175 : specifier instanceof ImportDefaultSpecifier
1176 ? 'default'
1177 : specifier instanceof ImportNamespaceSpecifier
1178 ? '*'
1179 : specifier.imported instanceof Identifier
1180 ? specifier.imported.name
1181 : specifier.imported.value;
1182 this.importDescriptions.set(localName, {
1183 module: null as never, // filled in later
1184 name,
1185 phase: node.phase === 'source' ? 'source' : 'instance',
1186 source,
1187 start: specifier.start
1188 });
1189 }
1190 }
1191
1192 private addImportSource(importSource: string): void {
1193 if (importSource && !this.sourcesWithAttributes.has(importSource)) {

Callers 1

initialiseMethod · 0.80

Calls 5

addSourceMethod · 0.95
errorMethod · 0.95
logRedeclarationErrorFunction · 0.90
hasMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected