* Gets global object. * @param {string | undefined} definition global object definition * @returns {string | undefined} save to use global object
(definition)
| 78 | * @returns {string | undefined} save to use global object |
| 79 | */ |
| 80 | function getGlobalObject(definition) { |
| 81 | if (!definition) return definition; |
| 82 | const trimmed = definition.trim(); |
| 83 | |
| 84 | if ( |
| 85 | // identifier, we do not need real identifier regarding ECMAScript/Unicode |
| 86 | /^[_\p{L}][_0-9\p{L}]*$/iu.test(trimmed) || |
| 87 | // iife |
| 88 | // call expression |
| 89 | // expression in parentheses |
| 90 | /^(?:[_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed) |
| 91 | ) { |
| 92 | return trimmed; |
| 93 | } |
| 94 | |
| 95 | return `Object(${trimmed})`; |
| 96 | } |
| 97 | |
| 98 | class RuntimeTemplate { |
| 99 | /** |