From 9af485a584e47fd503ed5c62b9f6482574715f1e Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 10 Oct 2016 03:50:11 +0200 Subject: Squashed 'thirdparty/systemjs/' content from commit 5ed69b6 git-subtree-dir: thirdparty/systemjs git-subtree-split: 5ed69b6344e8fc1cd43bf758350b2236f57e1499 --- lib/amd.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/amd.js (limited to 'lib/amd.js') 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); + }; + }); + +})(); -- cgit v1.2.3