moodle/lib/amd/build/str.min.js.map
Andrew Nicols 0a4047ab31 MDL-73915 js: Switch amd minification to terser
Unfortunately the babel minify-mangle plugin seems to be abandoned and
in certain circumstances can be very buggy. The only safe options are to
disable it, or to switch to a different minification library.

Not minifying our javascript is not ideal, so this commit updates the
javascript tasks to use a rollup, combined with babel, and terser.

Babel still converts code from ES/UMD/AMD to AMD modules with the
relevant browser support, whilst terser minifies the code.

The rollup bundler handles tracking and creation of sourcemaps, and
supports better parallelisation of the tasks.

Since the upgrade to Node LTS/Gallium requires an upgrade to @babel/core
and eslint, which change the built files anyway, this seems like the
ideal time to make this change.
2022-02-23 08:55:09 +08:00

1 line
10 KiB
Plaintext

{"version":3,"file":"str.min.js","sources":["../src/str.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Fetch and return language strings.\n *\n * @module core/str\n * @copyright 2015 Damyon Wiese <damyon@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 2.9\n *\n */\nimport $ from 'jquery';\nimport Ajax from 'core/ajax';\nimport LocalStorage from 'core/localstorage';\n\n// Module cache for the promises so that we don't make multiple\n// unnecessary requests.\nlet promiseCache = [];\n\n/* eslint-disable no-restricted-properties */\n\n/**\n * Return a Promise that resolves to a string.\n *\n * If the string has previously been cached, then the Promise will be resolved immediately, otherwise it will be fetched\n * from the server and resolved when available.\n *\n * @method get_string\n * @param {string} key The language string key\n * @param {string} component The language string component\n * @param {string} param The param for variable expansion in the string.\n * @param {string} lang The users language - if not passed it is deduced.\n * @return {Promise}\n *\n * @example <caption>Fetching a string</caption>\n *\n * import {get_string as getString} from 'core/str';\n * get_string('cannotfindteacher', 'error')\n * .then(str => {\n * window.console.log(str); // Cannot find teacher\n * })\n * .catch();\n */\n// eslint-disable-next-line camelcase\nexport const get_string = (key, component, param, lang) => {\n return get_strings([{key, component, param, lang}])\n .then(results => results[0]);\n};\n\n/**\n * Make a batch request to load a set of strings.\n *\n * Any missing string will be fetched from the server.\n * The Promise will only be resolved once all strings are available, or an attempt has been made to fetch them.\n *\n * @method get_strings\n * @param {Object[]} requests List of strings to fetch\n * @param {string} requests.key The string identifer to fetch\n * @param {string} [requests.component='core'] The componet to fetch from\n * @param {string} [requests.lang] The language to fetch a string for. Defaults to current page language.\n * @param {object|string} [requests.param] The param for variable expansion in the string.\n * @return {Promise[]}\n *\n * @example <caption>Fetching a set of strings</caption>\n *\n * import {get_strings as getStrings} from 'core/str';\n * get_strings([\n * {\n * key: 'cannotfindteacher',\n * component: 'error',\n * },\n * {\n * key: 'yes',\n * component: 'core',\n * },\n * {\n * key: 'no',\n * component: 'core',\n * },\n * ])\n * .then((cannotFindTeacher, yes, no) => {\n * window.console.log(cannotFindTeacher); // Cannot find teacher\n * window.console.log(yes); // Yes\n * window.console.log(no); // No\n * })\n * .catch();\n */\n// eslint-disable-next-line camelcase\nexport const get_strings = (requests) => {\n let requestData = [];\n const pageLang = $('html').attr('lang').replace(/-/g, '_');\n // Helper function to construct the cache key.\n const getCacheKey = ({key, component, lang = pageLang}) => {\n if (!component) {\n component = 'core';\n }\n return `core_str/${key}/${component}/${lang}`;\n };\n\n const stringPromises = requests.map((request) => {\n const cacheKey = getCacheKey(request);\n const {component, key, param, lang = pageLang} = request;\n // Helper function to add the promise to cache.\n const buildReturn = (promise) => {\n // Make sure the promise cache contains our promise.\n promiseCache[cacheKey] = promise;\n return promise;\n };\n\n // Check if we can serve the string straight from M.str.\n if (component in M.str && key in M.str[component]) {\n return buildReturn(new Promise((resolve) => {\n resolve(M.util.get_string(key, component, param, lang));\n }));\n }\n\n // Check if the string is in the browser's local storage.\n const cached = LocalStorage.get(cacheKey);\n if (cached) {\n M.str[component] = {...M.str[component], [key]: cached};\n return buildReturn(new Promise((resolve) => {\n resolve(M.util.get_string(key, component, param, lang));\n }));\n }\n\n // Check if we've already loaded this string from the server.\n if (cacheKey in promiseCache) {\n return buildReturn(promiseCache[cacheKey]).then(() => {\n return M.util.get_string(key, component, param, lang);\n });\n } else {\n // We're going to have to ask the server for the string so\n // add this string to the list of requests to be sent.\n return buildReturn(new Promise((resolve, reject) => {\n requestData.push({\n methodname: 'core_get_string',\n args: {\n stringid: key,\n stringparams: [],\n component,\n lang,\n },\n done: (str) => {\n // When we get the response from the server\n // we should update M.str and the browser's\n // local storage before resolving this promise.\n M.str[component] = {...M.str[component], [key]: str};\n LocalStorage.set(cacheKey, str);\n resolve(M.util.get_string(key, component, param, lang));\n },\n fail: reject\n });\n }));\n }\n });\n\n if (requestData.length) {\n // If we need to load any strings from the server then send\n // off the request.\n Ajax.call(requestData, true, false, false, 0, M.cfg.langrev);\n }\n\n // We need to use jQuery here because some calling code uses the\n // .done handler instead of the .then handler.\n return $.when.apply($, stringPromises)\n .then((...strings) => strings);\n};\n\n/**\n * Add a list of strings to the caches.\n *\n * This function should typically only be called from core APIs to pre-cache values.\n *\n * @method cache_strings\n * @protected\n * @param {Object[]} strings List of strings to fetch\n * @param {string} strings.key The string identifer to fetch\n * @param {string} strings.value The string value\n * @param {string} [strings.component='core'] The componet to fetch from\n * @param {string} [strings.lang] The language to fetch a string for. Defaults to current page language.\n */\n// eslint-disable-next-line camelcase\nexport const cache_strings = (strings) => {\n const defaultLang = $('html').attr('lang').replace(/-/g, '_');\n\n strings.forEach(({key, component, value, lang = defaultLang}) => {\n const cacheKey = ['core_str', key, component, lang].join('/');\n\n // Check M.str caching.\n if (!(component in M.str) || !(key in M.str[component])) {\n if (!(component in M.str)) {\n M.str[component] = {};\n }\n\n M.str[component][key] = value;\n }\n\n // Check local storage.\n if (!LocalStorage.get(cacheKey)) {\n LocalStorage.set(cacheKey, value);\n }\n\n // Check the promises cache.\n if (!(cacheKey in promiseCache)) {\n promiseCache[cacheKey] = $.Deferred().resolve(value).promise();\n }\n });\n};\n/* eslint-enable no-restricted-properties */\n"],"names":["promiseCache","key","component","param","lang","get_strings","then","results","requests","requestData","pageLang","attr","replace","stringPromises","map","request","cacheKey","getCacheKey","buildReturn","promise","M","str","Promise","resolve","util","get_string","cached","LocalStorage","get","reject","push","methodname","args","stringid","stringparams","done","set","fail","length","call","cfg","langrev","$","when","apply","strings","defaultLang","forEach","value","join","Deferred"],"mappings":"o3CA8BIA,aAAe,uBA2BO,SAACC,IAAKC,UAAWC,MAAOC,aACvCC,YAAY,CAAC,CAACJ,IAAAA,IAAKC,UAAAA,UAAWC,MAAAA,MAAOC,KAAAA,QACvCE,MAAK,SAAAC,gBAAWA,QAAQ,WA0CpBF,YAAc,SAACG,cACpBC,YAAc,GACZC,UAAW,mBAAE,QAAQC,KAAK,QAAQC,QAAQ,KAAM,KAShDC,eAAiBL,SAASM,KAAI,SAACC,aAC3BC,SARU,mBAAEf,SAAAA,IAAKC,eAAAA,yBAAWE,KAAAA,wBAAOM,0BACpCR,YACDA,UAAY,2BAEGD,gBAAOC,sBAAaE,MAItBa,CAAYF,SACtBb,UAA0Ca,QAA1Cb,UAAWD,IAA+Bc,QAA/Bd,IAAKE,MAA0BY,QAA1BZ,oBAA0BY,QAAnBX,KAAAA,4BAAOM,uBAE/BQ,YAAc,SAACC,gBAEjBnB,aAAagB,UAAYG,QAClBA,YAIPjB,aAAakB,EAAEC,KAAOpB,OAAOmB,EAAEC,IAAInB,kBAC5BgB,YAAY,IAAII,SAAQ,SAACC,SAC5BA,QAAQH,EAAEI,KAAKC,WAAWxB,IAAKC,UAAWC,MAAOC,eAKnDsB,OAASC,sBAAaC,IAAIZ,iBAC5BU,QACAN,EAAEC,IAAInB,0CAAiBkB,EAAEC,IAAInB,kCAAa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