tedious / JShrink

Javascript Minifier built in PHP
http://www.tedivm.com
BSD 3-Clause "New" or "Revised" License
751 stars 152 forks source link

Template literals with multiline quotes doesn't work #66

Closed Igloczek closed 6 years ago

Igloczek commented 7 years ago

Minifier can't handle a new line after quote and double-quote. It wasn't a case with ES5, b/c it will generate not valid code, but with template literals, we can do this i.e. writing HTML code.

Simple example:

var test =`"
test
"`;

Real-life example:

return template(`
  <div class="
         ${classNames.item}
         ${classNames.itemChoice}
         ${data.disabled ? classNames.itemDisabled : classNames.itemSelectable}
       "
       data-select-text="${this.config.itemSelectText}"
       data-id="${data.id}"
       data-value="${data.value}"
       data-sku="${data.sku}"
       data-choice
       ${data.groupId > 0 ? 'role="treeitem"' : 'role="option"'}
       ${data.disabled ? 'data-choice-disabled aria-disabled="true"' : 'data-choice-selectable'}
  >
    ${data.label}
  </div>
`);
dugwood commented 7 years ago

Note that's a backtick ` and not a single quote '. At first I thought you were mistaken, but just found out about backticks in Javascript :-)

tedivm commented 6 years ago

Works now.