5

I am getting syntax error while compressing js file using a command line tool yuicompressor jar.

[ERROR] 1796:28:invalid property id

I have a variable commentGroup. I want to push it as JSON object with the value of commentGroup as key. To achieve this I referred this answer.

var commentGroup = 'owner';
var groupIndex= [];
groupIndex.push({[commentGroup]: 1}); // Error line 1796

Why is it telling invalid property id?

I am using yuicompressor-2.4.7.jar

I have tried above code on JavaScript/CSS/HTML Compressor

Output

{
  "message": "Unexpected token: name (commentGroup)",
  "filename": 0,
  "line": 3,
  "col": 18,
  "pos": 66
}

I think YUI compressor does not understand {[commentGroup]: 1}

I got the solution for above problem, I need to declare temporary variable, then I put my object as a key into that variable and then pushed into the array.

var commentGroup = 'owner';
var aObject= {};
aObject[commentGroup]= 1;  
var groupIndex= [];
groupIndex.push(aObject);

1 Answer 1

4

That's because what you have used is ES6 syntax. And YUI Compressor is not supporting ES6 yet.There's open ticket here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.