Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/JS.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ protected function extractRegex()
);
$delimiters = array_fill(0, count($propertiesAndMethods), '/');
$propertiesAndMethods = array_map('preg_quote', $propertiesAndMethods, $delimiters);
$after = '(?=\s*([\.,;:\)\}&\|+]|\/\/|$|\.(' . implode('|', $propertiesAndMethods) . ')))';
$implodePropertiesAndMethod = implode('|', $propertiesAndMethods);
$after = '(?=\s*([\.,;:\)\}&\|+]|\/\/|$|\.(' . $implodePropertiesAndMethod . ')))';
$this->registerPattern('/' . $before . '\K' . $pattern . $after . '/', $callback);

// regular expressions following a `)` are rather annoying to detect...
Expand All @@ -278,7 +279,7 @@ protected function extractRegex()
// if a regex following `)` is not followed by `.<property or method>`,
// it's quite likely not a regex
$before = '\)\s*';
$after = '(?=\s*\.(' . implode('|', $propertiesAndMethods) . '))';
$after = '(?=\s*\.(' . $implodePropertiesAndMethod . '))';
$this->registerPattern('/' . $before . '\K' . $pattern . $after . '/', $callback);

// 1 more edge case: a regex can be followed by a lot more operators or
Expand Down Expand Up @@ -607,7 +608,8 @@ protected function shortenBools($content)
if ($open === $close) {
// only restore `while` if amount of `{` and `}` are the same;
// otherwise, that `for` isn't associated with this `do`
$content = substr_replace($content, 'while(!0)', $offsetWhile, strlen('for(;;)'));
// A length of 7 is assigned to the for(;;) loop.
$content = substr_replace($content, 'while(!0)', $offsetWhile, 7);
break;
}
}
Expand Down