Skip to content

Commit

Permalink
skip u flag before parse
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 30, 2019
1 parent 2f57da8 commit 633bcab
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rules/regex-shorthand.js
Expand Up @@ -9,12 +9,18 @@ const message = 'Use regex shorthands to improve readability.';
const create = context => {
return {
'Literal[regex]': node => {
const {type, value} = context.getSourceCode().getFirstToken(node);
const {type, value, regex} = context.getSourceCode().getFirstToken(node);

if (type !== 'RegularExpression') {
return;
}

// regex with `u` flag is not well handled by `regexp-tree`
// https://github.com/DmitrySoshnikov/regexp-tree/issues/162
if (regex.flags.includes('u')) {
return;
}

let parsedSource;
try {
parsedSource = parse(value);
Expand All @@ -31,12 +37,6 @@ const create = context => {
return;
}

// `u` flag regex is not well handled by `regexp-tree`
// https://github.com/DmitrySoshnikov/regexp-tree/issues/162
if (parsedSource.flags.includes('u')) {
return;
}

const originalRegex = generate(parsedSource).toString();
const optimizedRegex = optimize(value).toString();

Expand Down

0 comments on commit 633bcab

Please sign in to comment.