| 1 | export function wrapCode(magicString, uses, moduleName, exportsName, indentExclusionRanges) { |
| 2 | const args = []; |
| 3 | const passedArgs = []; |
| 4 | if (uses.module) { |
| 5 | args.push('module'); |
| 6 | passedArgs.push(moduleName); |
| 7 | } |
| 8 | if (uses.exports) { |
| 9 | args.push('exports'); |
| 10 | passedArgs.push(uses.module ? `${moduleName}.exports` : exportsName); |
| 11 | } |
| 12 | magicString |
| 13 | .trim() |
| 14 | .indent('\t', { exclude: indentExclusionRanges }) |
| 15 | .prepend(`(function (${args.join(', ')}) {\n`) |
| 16 | // For some reason, this line is only indented correctly when using a |
| 17 | // require-wrapper if we have this leading space |
| 18 | .append(` \n} (${passedArgs.join(', ')}));`); |
| 19 | } |
| 20 | |
| 21 | export function rewriteExportsAndGetExportsBlock( |
| 22 | magicString, |