(url: string, scriptType?: string)
| 12 | } |
| 13 | |
| 14 | export function load(url: string, scriptType?: string) { |
| 15 | const node = document.createElement('script'); |
| 16 | |
| 17 | // node.setAttribute('crossorigin', 'anonymous'); |
| 18 | |
| 19 | node.onload = onload; |
| 20 | node.onerror = onload; |
| 21 | |
| 22 | const i = createDefer(); |
| 23 | |
| 24 | function onload(e: any) { |
| 25 | node.onload = null; |
| 26 | node.onerror = null; |
| 27 | if (e.type === 'load') { |
| 28 | i.resolve(); |
| 29 | } else { |
| 30 | i.reject(); |
| 31 | } |
| 32 | // document.head.removeChild(node); |
| 33 | // node = null; |
| 34 | } |
| 35 | |
| 36 | node.src = url; |
| 37 | |
| 38 | // `async=false` is required to make sure all js resources execute sequentially. |
| 39 | node.async = false; |
| 40 | |
| 41 | scriptType && (node.type = scriptType); |
| 42 | |
| 43 | document.head.appendChild(node); |
| 44 | |
| 45 | return i.promise(); |
| 46 | } |
| 47 | |
| 48 | export function evaluateExpression(expr: string) { |
| 49 | // eslint-disable-next-line no-new-func |
no test coverage detected
searching dependent graphs…