Error when trying to uglify object with key defined via square brackets
hdodov opened this issue · 2 comments
hdodov commented
If I try to uglify this:
var foo = {bar: "key"};
var obj = {
[foo.bar]: 3
};
I get the following error:
{ SyntaxError: Unexpected token: punc ([)
at JS_Parse_Error.get (eval at <anonymous> (C:\Users\USER\Desktop\conveuro\node_modules\uglify-js\tools\node.js:20:1), <anonymous>:71:23)
at formatError (util.js:610:16)
at formatValue (util.js:514:18)
at formatProperty (util.js:801:11)
at formatObject (util.js:617:17)
at formatValue (util.js:579:18)
at formatProperty (util.js:801:11)
at formatObject (util.js:617:17)
at formatValue (util.js:579:18)
at inspect (util.js:294:10)
message: 'Unexpected token: punc ([)',
filename: 'foo.js',
line: 3,
col: 4,
pos: 42 },
plugin: 'gulp-uglify',
fileName: 'C:\\Users\\USER\\Desktop\\conveuro\\extension\\content-script\\_src\\js\\foo.js',
showStack: false }
And this is perfectly valid JavaScript. If I execute it in the console, the value of obj
would be {key: 3}
.
I use version 3.0.1 of the plugin, which is the latest.
terinjokes commented
This requires you to use a version of UglifyJS that supports ES Harmony features. Check out the README for more details.
erperejildo commented
Hi @terinjokes. I had a look to the README but I still don't know how to fix this issue. I tried installing this but didn't work:
"uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony"
Do we also need to modify the uglify task or just installing the new version should work automatically?