* Returns start and end of the node. If the start is preceded with white-space-only before a line break, * the start will be the start of the line. * @param {string} source * @param {LabeledStatement} node
(source, node)
| 1820 | * @param {LabeledStatement} node |
| 1821 | */ |
| 1822 | function get_node_range(source, node) { |
| 1823 | const first_leading_comment = node.leadingComments?.[0]; |
| 1824 | const last_trailing_comment = node.trailingComments?.[node.trailingComments.length - 1]; |
| 1825 | |
| 1826 | // @ts-expect-error the type of `Comment` seems to be wrong...the node actually contains |
| 1827 | // start and end but the type seems to only contain a `range` (which doesn't actually exists) |
| 1828 | let start = /** @type {number} */ (first_leading_comment?.start ?? node.start); |
| 1829 | // @ts-expect-error the type of `Comment` seems to be wrong...the node actually contains |
| 1830 | // start and end but the type seems to only contain a `range` (which doesn't actually exists) |
| 1831 | let end = /** @type {number} */ (last_trailing_comment?.end ?? node.end); |
| 1832 | |
| 1833 | let idx = start; |
| 1834 | while (source[idx - 1] !== '\n' && source[idx - 1] !== '\r') { |
| 1835 | idx--; |
| 1836 | if (source[idx] !== ' ' && source[idx] !== '\t') { |
| 1837 | idx = start; |
| 1838 | break; |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | start = idx; |
| 1843 | |
| 1844 | return { start, end }; |
| 1845 | } |
| 1846 | |
| 1847 | /** |
| 1848 | * @param {Identifier} node |