Skip to content

Commit bb05feb

Browse files
authored
Merge pull request #7 from mrclay/es6_lit
Preserve ES6 template literals
2 parents 95df8a5 + 84e3cff commit bb05feb

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/JSMin/JSMin.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ protected function action($command)
196196
// fallthrough intentional
197197
case self::ACTION_DELETE_A: // 2
198198
$this->a = $this->b;
199-
if ($this->a === "'" || $this->a === '"') { // string literal
199+
if ($this->a === "'" || $this->a === '"' || $this->a === '`') { // string/template literal
200+
$delimiter = $this->a;
200201
$str = $this->a; // in case needed for exception
201202
for(;;) {
202203
$this->output .= $this->a;
@@ -206,7 +207,9 @@ protected function action($command)
206207
if ($this->a === $this->b) { // end quote
207208
break;
208209
}
209-
if ($this->isEOF($this->a)) {
210+
if ($delimiter === '`' && $this->a === "\n") {
211+
// leave the newline
212+
} elseif ($this->isEOF($this->a)) {
210213
$byte = $this->inputIndex - 1;
211214
throw new UnterminatedStringException(
212215
"JSMin: Unterminated String at byte {$byte}: {$str}");
@@ -216,7 +219,7 @@ protected function action($command)
216219
$this->output .= $this->a;
217220
$this->lastByteOut = $this->a;
218221

219-
$this->a = $this->get();
222+
$this->a = $this->get();
220223
$str .= $this->a;
221224
}
222225
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`line
2+
break`+`he llo`;foo`hel( '');lo`;`he\nl\`lo`;(`he${one + two}`)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`line
2+
break` + `he llo`; foo`hel( '');lo`; `he\nl\`lo`; (`he${one + two}`)

0 commit comments

Comments
 (0)