parse5-element.js 1.6 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google LLC All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.dev/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. exports.getChildElementIndentation = getChildElementIndentation;
  11. const schematics_1 = require("@angular-devkit/schematics");
  12. /** Determines the indentation of child elements for the given Parse5 element. */
  13. function getChildElementIndentation(element) {
  14. const childElement = element.childNodes.find(node => node.tagName);
  15. if ((childElement && !childElement.sourceCodeLocation) || !element.sourceCodeLocation) {
  16. throw new schematics_1.SchematicsException('Cannot determine child element indentation because the ' +
  17. 'specified Parse5 element does not have any source code location metadata.');
  18. }
  19. const startColumns = childElement
  20. ? // In case there are child elements inside of the element, we assume that their
  21. // indentation is also applicable for other child elements.
  22. childElement.sourceCodeLocation.startCol
  23. : // In case there is no child element, we just assume that child elements should be indented
  24. // by two spaces.
  25. element.sourceCodeLocation.startCol + 2;
  26. // Since Parse5 does not set the `startCol` properties as zero-based, we need to subtract
  27. // one column in order to have a proper zero-based offset for the indentation.
  28. return startColumns - 1;
  29. }
  30. //# sourceMappingURL=parse5-element.js.map