MCPcopy Create free account
hub / github.com/angular/components / getChildElementIndentation

Function getChildElementIndentation

src/cdk/schematics/utils/parse5-element.ts:18–39  ·  view source on GitHub ↗
(element: Element)

Source from the content-addressed store, hash-verified

16
17/** Determines the indentation of child elements for the given Parse5 element. */
18export function getChildElementIndentation(element: Element) {
19 const childElement = element.childNodes.find(node => (node as Element).tagName) as Element | null;
20
21 if ((childElement && !childElement.sourceCodeLocation) || !element.sourceCodeLocation) {
22 throw new SchematicsException(
23 'Cannot determine child element indentation because the ' +
24 'specified Parse5 element does not have any source code location metadata.',
25 );
26 }
27
28 const startColumns = childElement
29 ? // In case there are child elements inside of the element, we assume that their
30 // indentation is also applicable for other child elements.
31 childElement.sourceCodeLocation!.startCol
32 : // In case there is no child element, we just assume that child elements should be indented
33 // by two spaces.
34 element.sourceCodeLocation!.startCol + 2;
35
36 // Since Parse5 does not set the `startCol` properties as zero-based, we need to subtract
37 // one column in order to have a proper zero-based offset for the indentation.
38 return startColumns - 1;
39}

Callers 1

appendHtmlElementToHeadFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected