Don't confuse keywords with keys-of-object

Unless they're preceded/followed by whitespace (which is
already stripped around most operators) or ; or {}, a
keyword is likely not a keyword, but a key of an object.

Fixes issue #33
This commit is contained in:
Matthias Mullie 2015-02-02 15:59:05 -08:00
parent b0cd6f5e0a
commit 3e997eb9b3

View File

@ -245,12 +245,6 @@ class JS extends Minify
$content = preg_replace('/(?<![\+\-])\s*([\+\-])/', '\\1', $content);
$content = preg_replace('/([\+\-])\s*(?!\\1)/', '\\1', $content);
// collapse whitespace around reserved words into single space
$before = $this->getKeywordsForRegex($this->keywordsBefore, '/');
$after = $this->getKeywordsForRegex($this->keywordsAfter, '/');
$content = preg_replace('/(' . implode('|', $before) . ')\s+/', '\\1 ', $content);
$content = preg_replace('/\s+(' . implode('|', $after) . ')/', ' \\1', $content);
/*
* We didn't strip whitespace after a couple of operators because they
* could be used in different contexts and we can't be sure it's ok to
@ -260,6 +254,12 @@ class JS extends Minify
$operators = $this->getOperatorsForRegex($this->operatorsBefore + $this->operatorsAfter, '/');
$content = preg_replace('/([\}\)\]])[^\S\n]+(?!' . implode('|', $operators) . ')/', '\\1', $content);
// collapse whitespace around reserved words into single space
$before = $this->getKeywordsForRegex($this->keywordsBefore, '/');
$after = $this->getKeywordsForRegex($this->keywordsAfter, '/');
$content = preg_replace('/(^|[;\}\s])\K(' . implode('|', $before) . ')\s+/', '\\2 ', $content);
$content = preg_replace('/\s+(' . implode('|', $after) . ')(?=([;\{\s]|$))/', ' \\1', $content);
/*
* We also don't really want to terminate statements followed by closing
* curly braces (which we've ignored completely up until now): ASI will