diff --git a/src/JShrink/Minifier.php b/src/JShrink/Minifier.php index 85e8de9..fc3fee7 100644 --- a/src/JShrink/Minifier.php +++ b/src/JShrink/Minifier.php @@ -74,6 +74,11 @@ class Minifier */ protected $options; + /** + * These characters are used to define strings. + */ + protected $stringDelimiters = ['\'', '"', '`']; + /** * Contains the default options for minification. This array is merged with * the one passed in by the user to create the request specific set of @@ -442,7 +447,7 @@ protected function saveString() $this->a = $this->b; // If this isn't a string we don't need to do anything. - if ($this->a !== "'" && $this->a !== '"') { + if (!in_array($this->a, $this->stringDelimiters)) { return; } @@ -471,7 +476,11 @@ protected function saveString() // character, so those will be treated just fine using the switch // block below. case "\n": - throw new \RuntimeException('Unclosed string at position: ' . $startpos ); + if ($stringType === '`') { + echo $this->a; + } else { + throw new \RuntimeException('Unclosed string at position: ' . $startpos ); + } break; // Escaped characters get picked up here. If it's an escaped new line it's not really needed diff --git a/tests/Resources/jshrink/input/template_literal.js b/tests/Resources/jshrink/input/template_literal.js new file mode 100644 index 0000000..1c284b7 --- /dev/null +++ b/tests/Resources/jshrink/input/template_literal.js @@ -0,0 +1,2 @@ +var test = `apple +sauce`; diff --git a/tests/Resources/jshrink/output/template_literal.js b/tests/Resources/jshrink/output/template_literal.js new file mode 100644 index 0000000..79174ac --- /dev/null +++ b/tests/Resources/jshrink/output/template_literal.js @@ -0,0 +1,2 @@ +var test=`apple +sauce`; \ No newline at end of file