0

I'm working on a legacy project with grunt. I believe from the package.json that the version is 0.4.5 but I don't do too much front end work so may have made a mistake there.

Essentially I'm trying to build a JSON object from JavaScript that has some dynamic key value pairs.

I'm doing this

var params = {
    [localObject.propertyValue]: localObject.otherPropertyValue,
    "dateRange": {
        "start": localObject.startPropertyValue,
        "end": localObject.endPropertyValue
    }
}

This works perfectly. I post it off to the end point and get the result I want and I've been playing with it all afternoon using

grunt --profile=devServer

However when I do a grunt build I get a failure. It is around the computed property name - [localObject.propertyValue]. If I leave this out it builds without a problem.

This is the error. I'm struggling to think if a different way to dynamically add the key and I know no one will want me to update grunt. I just wondered if anyone could help ?

JS_Parse_Error {   message: 'Unexpected token: name
(scheduleSearchController)',   filename:
'../../.tmp/concat/js/app.js',   line: 34463,   col: 6,   pos:
1254651,   stack:    'Error\n    at new JS_Parse_Error
(/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:196:18)\n  
at js_error
(/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:204:11)\n
at croak
(/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:674:9)\n
at token_error
(/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:682:9)\n
at unexpected
(/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:688:9)\n
at as_property_name
(/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:1276:13)\n
at
/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:1230:24\n
at
/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:721:24\n
at expr_atom
(/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:1181:35)\n
at maybe_unary
(/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:1357:19)'
}
>> Uglifying source .tmp/concat/js/app.js failed. Warning: Uglification failed.
RobC
  • 22,977
  • 20
  • 73
  • 80
gringogordo
  • 1,990
  • 6
  • 24
  • 60
  • What version of `grunt-contrib-uglify` are you using? – Felix Kling Oct 20 '21 at 18:20
  • *"I'm struggling to think if a different way to dynamically add the key"* `params[localObject.propertyValue] = localObject.otherPropertyValue`, see https://stackoverflow.com/q/695050/218196 – Felix Kling Oct 20 '21 at 18:22

0 Answers0