From 65097b3cfc845adbc13ea9d1abf84233b90fa0fe Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Thu, 24 Apr 2014 16:21:48 -0700 Subject: [PATCH] Fixed "unclosed string" bugs for first line strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is particularly useful for people who start their code with “use strict”; This should resolve #29. --- src/JShrink/Minifier.php | 7 ++++++- tests/Resources/jshrink/input/strictmode.js | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/Resources/jshrink/input/strictmode.js diff --git a/src/JShrink/Minifier.php b/src/JShrink/Minifier.php index b64469e..1e65a04 100644 --- a/src/JShrink/Minifier.php +++ b/src/JShrink/Minifier.php @@ -162,7 +162,9 @@ protected function initialize($js, $options) // comment error that can otherwise occur. $this->input .= PHP_EOL; - $this->a = $this->getReal(); + // Populate "a" with a new line, "b" with the first character, before + // entering the loop + $this->a = "\n"; $this->b = $this->getReal(); } @@ -430,6 +432,7 @@ protected function getNext($string) * When a javascript string is detected this function crawls for the end of * it and saves the whole string. * + * @throws \RuntimeException Unclosed strings will throw an error */ protected function saveString() { @@ -504,6 +507,8 @@ protected function saveString() /** * When a regular expression is detected this function crawls for the end of * it and saves the whole regex. + * + * @throws \RuntimeException Unclosed regex will throw an error */ protected function saveRegex() { diff --git a/tests/Resources/jshrink/input/strictmode.js b/tests/Resources/jshrink/input/strictmode.js new file mode 100644 index 0000000..bc0bbbc --- /dev/null +++ b/tests/Resources/jshrink/input/strictmode.js @@ -0,0 +1,2 @@ +"use strict"; +var foo=22; \ No newline at end of file