|
|
@ -1,27 +1,28 @@ |
|
|
|
'use strict' |
|
|
|
'use strict' |
|
|
|
|
|
|
|
|
|
|
|
import solc from 'solc/wrapper' |
|
|
|
import * as solc from 'solc/wrapper' |
|
|
|
import { CompilerInput, MessageToWorker } from './types' |
|
|
|
import { CompilerInput, MessageToWorker } from './types' |
|
|
|
var compileJSON: ((input: CompilerInput) => string) | null = (input) => { return '' } |
|
|
|
let compileJSON: ((input: CompilerInput) => string) | null = (input) => { return '' } |
|
|
|
var missingInputs: string[] = [] |
|
|
|
const missingInputs: string[] = [] |
|
|
|
|
|
|
|
|
|
|
|
// 'DedicatedWorkerGlobalScope' object (the Worker global scope) is accessible through the self keyword
|
|
|
|
// '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
|
|
|
|
// '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) => { |
|
|
|
self.addEventListener('message', (e) => { |
|
|
|
const data: MessageToWorker = e.data |
|
|
|
const data: MessageToWorker = e.data |
|
|
|
switch (data.cmd) { |
|
|
|
switch (data.cmd) { |
|
|
|
case 'loadVersion': |
|
|
|
case 'loadVersion': |
|
|
|
|
|
|
|
{ |
|
|
|
delete self.Module |
|
|
|
delete self.Module |
|
|
|
// NOTE: workaround some browsers?
|
|
|
|
// NOTE: workaround some browsers?
|
|
|
|
self.Module = undefined |
|
|
|
self.Module = undefined |
|
|
|
compileJSON = null |
|
|
|
compileJSON = null |
|
|
|
//importScripts() method of synchronously imports one or more scripts into the worker's scope
|
|
|
|
//importScripts() method of synchronously imports one or more scripts into the worker's scope
|
|
|
|
self.importScripts(data.data) |
|
|
|
self.importScripts(data.data) |
|
|
|
let compiler: solc = solc(self.Module) |
|
|
|
const compiler: solc = solc(self.Module) |
|
|
|
compileJSON = (input) => { |
|
|
|
compileJSON = (input) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
let missingInputsCallback = (path) => { |
|
|
|
const missingInputsCallback = (path) => { |
|
|
|
missingInputs.push(path) |
|
|
|
missingInputs.push(path) |
|
|
|
return { 'error': 'Deferred import' } |
|
|
|
return { 'error': 'Deferred import' } |
|
|
|
} |
|
|
|
} |
|
|
@ -35,6 +36,7 @@ export default (self) => { |
|
|
|
data: compiler.version() |
|
|
|
data: compiler.version() |
|
|
|
}) |
|
|
|
}) |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case 'compile': |
|
|
|
case 'compile': |
|
|
|
missingInputs.length = 0 |
|
|
|
missingInputs.length = 0 |
|
|
|