Skip to content

Commit

Permalink
Whitespace fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclay committed Mar 30, 2015
1 parent 47cace7 commit 932c963
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/JSMin/JSMin.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ protected function isRegexpLiteral()
return true;
}

// check if first non-ws token is "/" (see starts-regex.js)
$length = strlen($this->output);
// check if first non-ws token is "/" (see starts-regex.js)
$length = strlen($this->output);
if ($this->a === ' ' || $this->a === "\n") {
if ($length < 2) { // weird edge case
return true;
Expand All @@ -292,25 +292,25 @@ protected function isRegexpLiteral()

// if the "/" follows a keyword, it must be a regexp, otherwise it's best to assume division

$subject = $this->output . trim($this->a);
if (!preg_match('/(?:case|else|in|return|typeof)$/', $subject, $m)) {
// not a keyword
return false;
}

// can't be sure it's a keyword yet (see not-regexp.js)
$charBeforeKeyword = substr($subject, 0 - strlen($m[0]) - 1, 1);
if ($this->isAlphaNum($charBeforeKeyword)) {
// this is really an identifier ending in a keyword, e.g. "xreturn"
return false;
}

// it's a regexp. Remove unneeded whitespace after keyword
if ($this->a === ' ' || $this->a === "\n") {
$this->a = '';
}

return true;
$subject = $this->output . trim($this->a);
if (!preg_match('/(?:case|else|in|return|typeof)$/', $subject, $m)) {
// not a keyword
return false;
}

// can't be sure it's a keyword yet (see not-regexp.js)
$charBeforeKeyword = substr($subject, 0 - strlen($m[0]) - 1, 1);
if ($this->isAlphaNum($charBeforeKeyword)) {
// this is really an identifier ending in a keyword, e.g. "xreturn"
return false;
}

// it's a regexp. Remove unneeded whitespace after keyword
if ($this->a === ' ' || $this->a === "\n") {
$this->a = '';
}

return true;
}

/**
Expand Down

0 comments on commit 932c963

Please sign in to comment.