UNPKG

910 BJavaScriptView Raw
1/**
2 * @fileoverview Common utils for AST.
3 *
4 * This file contains only shared items for core and rules.
5 * If you make a utility for rules, please see `../rules/utils/ast-utils.js`.
6 *
7 * @author Toru Nagashima <https://github.com/mysticatea>
8 */
9"use strict";
10
11const breakableTypePattern = /^(?:(?:Do)?While|For(?:In|Of)?|Switch)Statement$/u;
12const lineBreakPattern = /\r\n|[\r\n\u2028\u2029]/u;
13const shebangPattern = /^#!([^\r\n]+)/u;
14
15/**
16 * Creates a version of the `lineBreakPattern` regex with the global flag.
17 * Global regexes are mutable, so this needs to be a function instead of a constant.
18 * @returns {RegExp} A global regular expression that matches line terminators
19 */
20function createGlobalLinebreakMatcher() {
21 return new RegExp(lineBreakPattern.source, "gu");
22}
23
24module.exports = {
25 breakableTypePattern,
26 lineBreakPattern,
27 createGlobalLinebreakMatcher,
28 shebangPattern
29};