admin管理员组

文章数量:1394163

I am getting syntax error while pressing js file using a mand line tool yuipressor jar.

[ERROR] 1796:28:invalid property id

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

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

Why is it telling invalid property id?

I am using yuipressor-2.4.7.jar

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

Output

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

I think YUI pressor does not understand {[mentGroup]: 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 mentGroup = 'owner';
var aObject= {};
aObject[mentGroup]= 1;  
var groupIndex= [];
groupIndex.push(aObject);

I am getting syntax error while pressing js file using a mand line tool yuipressor jar.

[ERROR] 1796:28:invalid property id

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

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

Why is it telling invalid property id?

I am using yuipressor-2.4.7.jar

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

Output

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

I think YUI pressor does not understand {[mentGroup]: 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 mentGroup = 'owner';
var aObject= {};
aObject[mentGroup]= 1;  
var groupIndex= [];
groupIndex.push(aObject);
Share Improve this question asked Nov 9, 2017 at 6:29 Kaustubh KhareKaustubh Khare 3,5103 gold badges38 silver badges50 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

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

本文标签: yui compressor giving syntax error for valid javascript syntaxStack Overflow