Optional externals in amd use globals instead of an explicit dependency

There isn't any mechanism in the amdjs spec to provide optional
dependancies (although a requirejs loader plugin could do that, it's not
standard). The best approach found was knockout's optional dependancy on
jquery, for which it doesn't use require, it only uses globals.

This solution will need to be improved for use of requirejs/amd in
commonjs environments, and could be improved to allow toggling it with a flag.

Extends the solution for #339
Oops, the test cases are in parsing, not generation. Are the test cases still useful, or should they be removed?