I'm currently trying to optimize the current jQuery (development version 1.8.1) using r.js. This happens when compiling assets in a rails project using gem requirejs-rails.
I think I encountered an error in the optimizer. Around line 999 in the jquery source you will find the following code:
(function add(args) { jQuery.each(args, function (_, arg) { var type = jQuery.type(arg); if (type === "function" && (!options.unique || !self.has(arg))) { list.push(arg); } else if (arg && arg.length && type !== "string") {
When optimized jquery gets into a string containing add(arg); , an error will be thrown that add not detected. This is because the optimizer renamed the add function to e , and the function call remained add(...) as follows:
(function e(args) { jQuery.each(args, function (_, arg) { var type = jQuery.type(arg); if (type === "function" && (!options.unique || !self.has(arg))) { list.push(arg); } else if (arg && arg.length && type !== "string") {
I managed to fix the code by rewriting it:
var fnAdd = function (args) { jQuery.each(args, function (_, arg) { var type = jQuery.type(arg); if (type === "function" && (!options.unique || !self.has(arg))) { list.push(arg); } else if (arg && arg.length && type !== "string") {
Can this be considered a mistake in r.js? Or is javascript not allowed? I wonder why I'm the first to have a problem (at least Google didn't have any solutions).
source share