totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

`MERGE()` String value compression #705

Closed luasenvy closed 5 years ago

luasenvy commented 5 years ago

hi, i use totaljs with vue and vue i18n.

i service with next codes via MERGE() function. but i found little logical error. Perhaps this seems to be a problem with the es version coming up.

next code is perfectly compressed and work fine:

let translated = "hello totaljs, " + vm.$t('hello - world');

// after merged: let translated=vm.$t('hello - world');

but, next code compress with removing the necessary space. and cannot found language.:

let translated = `hello totaljs, ${vm.$t(`hello - world`)}`;

// after merged: let translated=`hello totaljs, ${vm.$t('hello-world')}`;

I think hello - world seems to be recognized as a formula. :)

petersirka commented 5 years ago

Hi, I htink that your code is typed wrong because you use twice operator:

`

BAD:
let translated = `hello totaljs, ${vm.$t(`hello - world`)}`;

GOOD:
let translated = `hello totaljs, ${vm.$t(\`hello - world\`)}`;

TEST:

require('total.js');

console.log(U.minifyScript('let translated = `${vm.$t(\\`hello - world\\`)}`;'));
// correct output: let translated=`${vm.$t(\`hello - world\`)}`;

For understading:

var translated = 'BAD 'STRING'';   // WRONG
var translated = 'BAD \'STRING\''; // GOOD

// or:
var translated = "BAD "STRING"";   // WRONG
var translated = "BAD \"STRING\""; // GOOD

// or:
var translated = `BAD `STRING``;   // WRONG
var translated = `BAD \`STRING\``; // GOOD

Thank you!

luasenvy commented 5 years ago

i'll use your guide. thanks for reply :D