Skip to content

Commit

Permalink
0.0.128
Browse files Browse the repository at this point in the history
  • Loading branch information
bahrus committed Sep 1, 2024
1 parent 98a5ca9 commit 9d8a3e8
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions doInline.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,35 @@
*
* @param {string} key
* @param {string} innerText
* @param {string} splitTerm
* @param {string} keyword
*/
function getModifiedText(key, innerText, splitTerm){
function getModifiedText(key, innerText, keyword){
const splitTerm = `export ${keyword}`;
const splitText = innerText.split(splitTerm);
const winKey = `window['${key}']`;
for (let i = 1, ii = splitText.length; i < ii; i++) {
const token = splitText[i];
const iPosOfEq = token.indexOf('=');
const lhs = token.substr(0, iPosOfEq).trim();
splitText[i] = `const ${lhs} = ${winKey}.beEnhanced.beExportable.exports.${lhs} = ${token.substr(iPosOfEq + 1)};`;
switch(keyword){
case 'const': {
const iPosOfEq = token.indexOf('=');
const lhs = token.substr(0, iPosOfEq).trim();
splitText[i] = `${keyword} ${lhs} = ${winKey}.beEnhanced.beExportable.exports.${lhs} = ${token.substr(iPosOfEq + 1)};`;
break;
}

case 'class': {
debugger;
const iPosOfOpenBrace = token.indexOf('{');
const lhs = token.substr(0, iPosOfOpenBrace).trim();
splitText[i] = `${winKey}.beEnhanced.beExportable.exports.${lhs} = ${keyword} ${lhs} {
${token.substr(iPosOfOpenBrace + 1)
}`;
break;
}


}

}
return splitText.join('');
}
Expand All @@ -22,8 +41,8 @@ export async function doInline(target) {
window[key] = target;
let innerText = target.innerText;
innerText = innerText.replaceAll('selfish', `window['${key}']`);
let modifiedText = getModifiedText(key, innerText, 'export const');
modifiedText = getModifiedText(key, modifiedText, 'export class ');
let modifiedText = getModifiedText(key, innerText, 'const');
modifiedText = getModifiedText(key, modifiedText, 'class');
modifiedText = /* js */ `
${modifiedText}
window['${key}'].dispatchEvent(new Event('load'));
Expand Down

0 comments on commit 9d8a3e8

Please sign in to comment.