3

When using closure compiler with ADVANCED_OPTIMIZATIONS, jQuery.ajax.data object is changed:

$.ajax({
  type: "POST",
  url: "ajax.php",
  data: {
     act : "some"
  },
  success : function(data){}
});

jQuery.ajax.data object is converted to {L : "some"}

I can use quotes, like 'act' : "some", but I want this to work without quotes. In my externs file there is:

/** @type {Object.<string,*>} */ jQuery.ajax.data; But this doesn't work. Closure compiler version 1043

Hitman_99
  • 2,252
  • 2
  • 19
  • 21
  • You need the quotes to tell Closure not to mangle the property name. This is a requirement. You cannot get it to work without quotes. – Stephen Chung Jun 15 '11 at 08:50
  • Your extern file is also not correct. `jQuery.ajax.data` means the `data` property under `jQuery.ajax`. There is no `data` property under `jQuery.ajax` (which is a function). `data` is a property of an object passed to `jQuery.ajax` as an argument. You are "externing" the wrong thing. – Stephen Chung Jun 23 '11 at 06:05
  • However, if you do: `var foo = {}; foo.act = null;` in your extern file, Closure will no longer rename any property called "act" (or any variable called "foo", which you don't care) on **ALL** objects, *including* in your object hash passed to the "data" property. However, beware that ALL properties called "act" will not be renamed, even when you want them to! – Stephen Chung Jun 23 '11 at 06:07
  • Same question, same answer http://stackoverflow.com/questions/7823811/prevent-google-closure-compiler-from-renaming-settings-objects/7825886#7825886 – Chris Moschini Oct 19 '11 at 19:44

1 Answers1

0

Try the externs with something like :

var jQuery = {};
jQuery.ajax = {
    data: '' 
}

This will not rename 'jQuery.ajax' and 'jQuery.ajax.data'

sbr
  • 4,735
  • 5
  • 43
  • 49