get-switch-case-head-location.js 718 B

123456789101112131415161718192021
  1. 'use strict';
  2. const {isColonToken} = require('@eslint-community/eslint-utils');
  3. /**
  4. @typedef {line: number, column: number} Position
  5. Get the location of the given `SwitchCase` node for reporting.
  6. @param {Node} node - The `SwitchCase` node to get.
  7. @param {SourceCode} sourceCode - The source code object to get tokens from.
  8. @returns {{start: Position, end: Position}} The location of the class node for reporting.
  9. */
  10. function getSwitchCaseHeadLocation(node, sourceCode) {
  11. const startToken = node.test || sourceCode.getFirstToken(node);
  12. const colonToken = sourceCode.getTokenAfter(startToken, isColonToken);
  13. return {start: node.loc.start, end: colonToken.loc.end};
  14. }
  15. module.exports = getSwitchCaseHeadLocation;