jrburke/backbone — comment on commit 57c2029117649452c6cf4d3337e03f5d52bb8331
File: backbone.js line 27
By jrburke:

require() calls with variable names or concatentated names are explicitly avoided in matching because those dependencies will not be found in a build either. Those indicate a dynamic require situation and should be using the callback-form of require(), not the declarative require('') form. An AMD optimizer will only process declarative, string literal require calls anyway, and at least the requirejs optimizer uses an AST to find them.

arguments.length will not be used in AMD factory functions that use this approach, since these would be declarative require calls. I can see arguments.length being used for dynamic, callback-style require calls, but those explicitly need the dependency array.

As for concerns around minification, the expectation is that an AMD optimizer is being used for building/minfication because it also needs to name any anonymous define calls, and those build tools use (or should use) an AST to find the dependencies.

A similar approach has been in use for Dojo xdomain builds for quite a while, but even using the regexp in the build step. There is rarely a problem, and the ones that have cropped up were because the build tool used a regexp not an AST (fwiw, I believe this has changed with the latest release).

So, we have some data that declarative require() use is fairly safe in practice. People normally put all module dependencies at the top of a file anyway, before other regexps/string stuff. Yes, there is a possibility of failure, but it in practice it is so rare that better developer ergonomics win out.