1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Update mod.js

This commit is contained in:
Bagel03 2022-02-06 13:03:45 -05:00 committed by GitHub
parent c5d81ce8b5
commit 9d8b755901
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,39 @@
module.exports = function (source, map) {
return source + `\nexport const __$S__=(n,v)=>eval("(function(v){" + n + "=v})")(v)`;
const oneExport = exp => {
return `${exp}=v`; // No checks needed
};
const twoExports = (exp1, exp2) => {
return `n=="${exp1}"?${exp1}=v:${exp2}=v`;
};
const multiExports = exps => {
exps = exps.map(exp => `case "${exp}":${exp}=v;break;`);
return `switch(n){${exps.toString().replaceAll(";,", ";")} }`;
};
const defineFnBody = source => {
const regex = /export (?:let|class) (?<name>\w+)/g;
let names = [...source.matchAll(regex)].map(n => n.groups.name);
switch (names.length) {
case 0:
return false;
case 1:
return oneExport(names[0]);
case 2:
return twoExports(names[0], names[1]);
default:
return multiExports(names);
}
};
/**
*
* @param {string} source
* @param {*} map
* @returns
*/
module.exports = function (source, map) {
const body = defineFnBody(source);
if (!body) return source;
return source + `\nexport const __$S__=(n,v)=>{${body}}`;
};