// <script type="module"> support
var anonSources = {};
if (typeof document != 'undefined' && document.getElementsByTagName) {
- function handleError(err) {
+ var handleError = function(err) {
// dispatch an error event so that we can display in errors in browsers
// that don't yet support unhandledrejection
if (window.onunhandledrejection === undefined) {
throw err;
}
- function ready() {
+ var ready = function() {
document.removeEventListener('DOMContentLoaded', ready, false );
var anonCnt = 0;
function xhrFetch(url, resolve, reject) {
var xhr = new XMLHttpRequest();
- function load(source) {
+ var load = function(source) {
resolve(xhr.responseText);
}
- function error() {
+ var error = function() {
reject(new Error('XHR error' + (xhr.status ? ' (' + xhr.status + (xhr.statusText ? ' ' + xhr.statusText : '') + ')' : '') + ' loading ' + url));
}
})
.then(function(source) {
// check our cache first
- const cacheEntryTrans = localStorage.getItem(key+'!transpiled');
- if (cacheEntryTrans) {
- const cacheEntryRaw = localStorage.getItem(key+'!raw');
+ var cacheEntry = localStorage.getItem(key);
+ if (cacheEntry) {
+ cacheEntry = JSON.parse(cacheEntry);
// TODO: store a hash instead
- if (cacheEntryRaw === source) {
- return Promise.resolve({key: key, code: cacheEntryTrans, source: source});
+ if (cacheEntry.source === source) {
+ return Promise.resolve({key: key, code: cacheEntry.code, source: cacheEntry.source});
}
}
return new Promise(function (resolve, reject) {
// evaluate without require, exports and module variables
// we leave module in for now to allow module.require access
try {
- localStorage.setItem(key+'!raw', data.source);
- localStorage.setItem(data.key+'!transpiled', data.code);
+ var cacheEntry = JSON.stringify({source: data.source, code: data.code});
+ localStorage.setItem(key, cacheEntry);
} catch (e) {
if (window.console) {
window.console.warn('Unable to cache transpiled version of ' + key + ': ' + e);