diff options
Diffstat (limited to 'lib/amd.js')
-rw-r--r-- | lib/amd.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/amd.js b/lib/amd.js new file mode 100644 index 000000000..2e2d37948 --- /dev/null +++ b/lib/amd.js @@ -0,0 +1,42 @@ +/* + SystemJS AMD Format +*/ +(function() { + // AMD Module Format Detection RegEx + // define([.., .., ..], ...) + // define(varName); || define(function(require, exports) {}); || define({}) + var amdRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])define\s*\(\s*("[^"]+"\s*,\s*|'[^']+'\s*,\s*)?\s*(\[(\s*(("[^"]+"|'[^']+')\s*,|\/\/.*\r?\n|\/\*(.|\s)*?\*\/))*(\s*("[^"]+"|'[^']+')\s*,?)?(\s*(\/\/.*\r?\n|\/\*(.|\s)*?\*\/))*\s*\]|function\s*|{|[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*\))/; + + hook('instantiate', function(instantiate) { + return function(load) { + var loader = this; + + if (load.metadata.format == 'amd' || !load.metadata.format && load.source.match(amdRegEx)) { + load.metadata.format = 'amd'; + + if (!loader.builder && loader.execute !== false) { + var curDefine = __global.define; + __global.define = this.amdDefine; + + try { + __exec.call(loader, load); + } + finally { + __global.define = curDefine; + } + + if (!load.metadata.entry && !load.metadata.bundle) + throw new TypeError('AMD module ' + load.name + ' did not define'); + } + else { + load.metadata.execute = function() { + return load.metadata.builderExecute.apply(this, arguments); + }; + } + } + + return instantiate.call(loader, load); + }; + }); + +})(); |