parse5-element.js 1.6 KB

12345678910111213141516171819202122232425262728293031
  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.io/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. const schematics_1 = require("@angular-devkit/schematics");
  11. /** Determines the indentation of child elements for the given Parse5 element. */
  12. function getChildElementIndentation(element) {
  13. const childElement = element.childNodes
  14. .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. exports.getChildElementIndentation = getChildElementIndentation;
  31. //# sourceMappingURL=parse5-element.js.map