Skip to content

Commit

Permalink
Merge pull request #70 from tedious/template_literals
Browse files Browse the repository at this point in the history
Template literals
  • Loading branch information
tedivm authored Dec 8, 2017
2 parents 667e997 + 558e533 commit 917ef60
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/JShrink/Minifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/Resources/jshrink/input/template_literal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var test = `apple
sauce`;
2 changes: 2 additions & 0 deletions tests/Resources/jshrink/output/template_literal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var test=`apple
sauce`;

0 comments on commit 917ef60

Please sign in to comment.