systemjs/dist/extras/transform.js
Guy Bedford 2839f30af8 6.1.3
2019-10-06 12:59:23 -04:00

33 lines
1000 B
JavaScript

/*
* Support for a "transform" loader interface
*/
(function (global) {
const systemJSPrototype = global.System.constructor.prototype;
const instantiate = systemJSPrototype.instantiate;
systemJSPrototype.instantiate = function (url, parent) {
if (url.slice(-5) === '.wasm')
return instantiate.call(this, url, parent);
const loader = this;
return fetch(url, { credentials: 'same-origin' })
.then(function (res) {
if (!res.ok)
throw Error('Fetch error: ' + res.status + ' ' + res.statusText + (parent ? ' loading from ' + parent : ''));
return res.text();
})
.then(function (source) {
return loader.transform.call(this, url, source);
})
.then(function (source) {
(0, eval)(source + '\n//# sourceURL=' + url);
return loader.getRegister();
});
};
// Hookable transform function!
systemJSPrototype.transform = function (_id, source) {
return source;
};
})(typeof self !== 'undefined' ? self : global);