Skip to content

Commit

Permalink
Merge pull request #7 from mrclay/es6_lit
Browse files Browse the repository at this point in the history
Preserve ES6 template literals
  • Loading branch information
mrclay authored Dec 6, 2018
2 parents 95df8a5 + 84e3cff commit bb05feb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/JSMin/JSMin.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ protected function action($command)
// fallthrough intentional
case self::ACTION_DELETE_A: // 2
$this->a = $this->b;
if ($this->a === "'" || $this->a === '"') { // string literal
if ($this->a === "'" || $this->a === '"' || $this->a === '`') { // string/template literal
$delimiter = $this->a;
$str = $this->a; // in case needed for exception
for(;;) {
$this->output .= $this->a;
Expand All @@ -206,7 +207,9 @@ protected function action($command)
if ($this->a === $this->b) { // end quote
break;
}
if ($this->isEOF($this->a)) {
if ($delimiter === '`' && $this->a === "\n") {
// leave the newline
} elseif ($this->isEOF($this->a)) {
$byte = $this->inputIndex - 1;
throw new UnterminatedStringException(
"JSMin: Unterminated String at byte {$byte}: {$str}");
Expand All @@ -216,7 +219,7 @@ protected function action($command)
$this->output .= $this->a;
$this->lastByteOut = $this->a;

$this->a = $this->get();
$this->a = $this->get();
$str .= $this->a;
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Resources/minify/expected/es6-literal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`line
break`+`he llo`;foo`hel( '');lo`;`he\nl\`lo`;(`he${one + two}`)
2 changes: 2 additions & 0 deletions tests/Resources/minify/input/es6-literal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`line
break` + `he llo`; foo`hel( '');lo`; `he\nl\`lo`; (`he${one + two}`)

0 comments on commit bb05feb

Please sign in to comment.