Home / Function/ findMatchingImport() — astro Function Reference

findMatchingImport() — astro Function Reference

Architecture documentation for the findMatchingImport() function in rehype.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  a078dbe3_ce8d_013a_b061_8bceac48c778["findMatchingImport()"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8["rehype.ts"]
  a078dbe3_ce8d_013a_b061_8bceac48c778 -->|defined in| 89da4403_ab4a_62fa_64f0_d53bd0b3aee8
  d17ed63a_5ec6_bc29_96d7_b3145cec7d5d["rehypeAnalyzeAstroMetadata()"]
  d17ed63a_5ec6_bc29_96d7_b3145cec7d5d -->|calls| a078dbe3_ce8d_013a_b061_8bceac48c778
  style a078dbe3_ce8d_013a_b061_8bceac48c778 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/jsx/rehype.ts lines 227–261

function findMatchingImport(
	tagName: string,
	imports: Map<string, Set<ImportSpecifier>>,
): MatchedImport | undefined {
	const tagSpecifier = tagName.split('.')[0];
	for (const [source, specs] of imports) {
		for (const { imported, local } of specs) {
			if (local === tagSpecifier) {
				// If tagName access properties, we need to make sure the returned `name`
				// properly access the properties from `path`
				if (tagSpecifier !== tagName) {
					switch (imported) {
						// Namespace import: "<buttons.Foo.Bar />" => name: "Foo.Bar"
						case '*': {
							const accessPath = tagName.slice(tagSpecifier.length + 1);
							return { name: accessPath, path: source };
						}
						// Default import: "<buttons.Foo.Bar />" => name: "default.Foo.Bar"
						case 'default': {
							// "buttons.Foo.Bar" => "Foo.Bar"
							const accessPath = tagName.slice(tagSpecifier.length + 1);
							return { name: `default.${accessPath}`, path: source };
						}
						// Named import: "<buttons.Foo.Bar />" => name: "buttons.Foo.Bar"
						default: {
							return { name: tagName, path: source };
						}
					}
				}

				return { name: imported, path: source };
			}
		}
	}
}

Domain

Subdomains

Frequently Asked Questions

What does findMatchingImport() do?
findMatchingImport() is a function in the astro codebase, defined in packages/astro/src/jsx/rehype.ts.
Where is findMatchingImport() defined?
findMatchingImport() is defined in packages/astro/src/jsx/rehype.ts at line 227.
What calls findMatchingImport()?
findMatchingImport() is called by 1 function(s): rehypeAnalyzeAstroMetadata.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free