get-class-head-location.js 593 B

12345678910111213141516171819202122
  1. 'use strict';
  2. /**
  3. @typedef {line: number, column: number} Position
  4. Get the location of the given class node for reporting.
  5. @param {Node} node - The class node to get.
  6. @param {SourceCode} sourceCode - The source code object to get tokens.
  7. @returns {{start: Position, end: Position}} The location of the class node for reporting.
  8. */
  9. function getClassHeadLocation(node, sourceCode) {
  10. const {loc, body} = node;
  11. const tokenBeforeBody = sourceCode.getTokenBefore(body);
  12. const {start} = loc;
  13. const {end} = tokenBeforeBody.loc;
  14. return {start, end};
  15. }
  16. module.exports = getClassHeadLocation;