MCPcopy Create free account
hub / github.com/RubyLouvre/anu / loadScripts

Function loadScripts

test/babel.js:60856–60910  ·  view source on GitHub ↗

* Loop over provided script tags and get the content, via innerHTML if an * inline script, or by using XHR. Transforms are applied if needed. The scripts * are executed in the order they are found on the page.

(transformFn, scripts)

Source from the content-addressed store, hash-verified

60854 * are executed in the order they are found on the page.
60855 */
60856 function loadScripts(transformFn, scripts) {
60857 var result = [];
60858 var count = scripts.length;
60859
60860 function check() {
60861 var script, i;
60862
60863 for (i = 0; i < count; i++) {
60864 script = result[i];
60865
60866 if (script.loaded && !script.executed) {
60867 script.executed = true;
60868 run(transformFn, script);
60869 } else if (!script.loaded && !script.error && !script.async) {
60870 break;
60871 }
60872 }
60873 }
60874
60875 scripts.forEach(function (script, i) {
60876 var scriptData = {
60877 // script.async is always true for non-JavaScript script tags
60878 async: script.hasAttribute('async'),
60879 error: false,
60880 executed: false,
60881 plugins: getPluginsOrPresetsFromScript(script, 'data-plugins'),
60882 presets: getPluginsOrPresetsFromScript(script, 'data-presets')
60883 };
60884
60885 if (script.src) {
60886 result[i] = _extends({}, scriptData, {
60887 content: null,
60888 loaded: false,
60889 url: script.src
60890 });
60891
60892 load(script.src, function (content) {
60893 result[i].loaded = true;
60894 result[i].content = content;
60895 check();
60896 }, function () {
60897 result[i].error = true;
60898 check();
60899 });
60900 } else {
60901 result[i] = _extends({}, scriptData, {
60902 content: script.innerHTML,
60903 loaded: true,
60904 url: null
60905 });
60906 }
60907 });
60908
60909 check();
60910 }
60911
60912 /**
60913 * Find and run all script tags with type="text/jsx".

Callers 1

runScriptsFunction · 0.85

Calls 3

loadFunction · 0.85
checkFunction · 0.85

Tested by

no test coverage detected