|
|
|
@ -1,40 +1,42 @@ |
|
|
|
|
'use strict' |
|
|
|
|
|
|
|
|
|
import solc from 'solc/wrapper' |
|
|
|
|
import * as solc from 'solc/wrapper' |
|
|
|
|
import { CompilerInput, MessageToWorker } from './types' |
|
|
|
|
var compileJSON: ((input: CompilerInput) => string) | null = (input) => { return '' } |
|
|
|
|
var missingInputs: string[] = [] |
|
|
|
|
let compileJSON: ((input: CompilerInput) => string) | null = (input) => { return '' } |
|
|
|
|
const missingInputs: string[] = [] |
|
|
|
|
|
|
|
|
|
// 'DedicatedWorkerGlobalScope' object (the Worker global scope) is accessible through the self keyword
|
|
|
|
|
// 'dom' and 'webworker' library files can't be included together https://github.com/microsoft/TypeScript/issues/20595
|
|
|
|
|
export default (self) => { |
|
|
|
|
export default function (self) { // eslint-disable-line @typescript-eslint/explicit-module-boundary-types
|
|
|
|
|
self.addEventListener('message', (e) => { |
|
|
|
|
const data: MessageToWorker = e.data |
|
|
|
|
switch (data.cmd) { |
|
|
|
|
case 'loadVersion': |
|
|
|
|
delete self.Module |
|
|
|
|
// NOTE: workaround some browsers?
|
|
|
|
|
self.Module = undefined |
|
|
|
|
compileJSON = null |
|
|
|
|
//importScripts() method of synchronously imports one or more scripts into the worker's scope
|
|
|
|
|
self.importScripts(data.data) |
|
|
|
|
let compiler: solc = solc(self.Module) |
|
|
|
|
compileJSON = (input) => { |
|
|
|
|
try { |
|
|
|
|
let missingInputsCallback = (path) => { |
|
|
|
|
missingInputs.push(path) |
|
|
|
|
return { 'error': 'Deferred import' } |
|
|
|
|
{ |
|
|
|
|
delete self.Module |
|
|
|
|
// NOTE: workaround some browsers?
|
|
|
|
|
self.Module = undefined |
|
|
|
|
compileJSON = null |
|
|
|
|
//importScripts() method of synchronously imports one or more scripts into the worker's scope
|
|
|
|
|
self.importScripts(data.data) |
|
|
|
|
const compiler: solc = solc(self.Module) |
|
|
|
|
compileJSON = (input) => { |
|
|
|
|
try { |
|
|
|
|
const missingInputsCallback = (path) => { |
|
|
|
|
missingInputs.push(path) |
|
|
|
|
return { 'error': 'Deferred import' } |
|
|
|
|
} |
|
|
|
|
return compiler.compile(input, { import: missingInputsCallback }) |
|
|
|
|
} catch (exception) { |
|
|
|
|
return JSON.stringify({ error: 'Uncaught JavaScript exception:\n' + exception }) |
|
|
|
|
} |
|
|
|
|
return compiler.compile(input, { import: missingInputsCallback }) |
|
|
|
|
} catch (exception) { |
|
|
|
|
return JSON.stringify({ error: 'Uncaught JavaScript exception:\n' + exception }) |
|
|
|
|
} |
|
|
|
|
self.postMessage({ |
|
|
|
|
cmd: 'versionLoaded', |
|
|
|
|
data: compiler.version() |
|
|
|
|
}) |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
self.postMessage({ |
|
|
|
|
cmd: 'versionLoaded', |
|
|
|
|
data: compiler.version() |
|
|
|
|
}) |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
case 'compile': |
|
|
|
|
missingInputs.length = 0 |
|
|
|
|