|
|
|
@ -3,7 +3,7 @@ |
|
|
|
|
import { update } from 'solc/abi' |
|
|
|
|
import webworkify from 'webworkify' |
|
|
|
|
import compilerInput from './compiler-input' |
|
|
|
|
import { EventManager } from 'remix-lib' |
|
|
|
|
import { EventManager } from '@remix-project/remix-lib' |
|
|
|
|
import { default as txHelper } from './txHelper'; |
|
|
|
|
import { Source, SourceWithTarget, MessageFromWorker, CompilerState, CompilationResult,
|
|
|
|
|
visitContractsCallbackParam, visitContractsCallbackInterface, CompilationError,
|
|
|
|
@ -13,10 +13,10 @@ import { Source, SourceWithTarget, MessageFromWorker, CompilerState, Compilation |
|
|
|
|
trigger compilationFinished, compilerLoaded, compilationStarted, compilationDuration |
|
|
|
|
*/ |
|
|
|
|
export class Compiler { |
|
|
|
|
event: EventManager |
|
|
|
|
event |
|
|
|
|
state: CompilerState |
|
|
|
|
|
|
|
|
|
constructor (public handleImportCall: (fileurl: string, cb: Function) => void) { |
|
|
|
|
constructor (public handleImportCall: (fileurl: string, cb) => void) { |
|
|
|
|
this.event = new EventManager() |
|
|
|
|
this.state = { |
|
|
|
|
compileJSON: null, |
|
|
|
@ -51,7 +51,7 @@ export class Compiler { |
|
|
|
|
* @param value value of key in CompilerState |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
set <K extends keyof CompilerState>(key: K, value: CompilerState[K]) { |
|
|
|
|
set <K extends keyof CompilerState>(key: K, value: CompilerState[K]): void { |
|
|
|
|
this.state[key] = value |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -101,7 +101,7 @@ export class Compiler { |
|
|
|
|
if (this.state.worker === null) { |
|
|
|
|
const compiler: any = typeof (window) === 'undefined' ? require('solc') : require('solc/wrapper')(window['Module']) |
|
|
|
|
this.state.compileJSON = (source: SourceWithTarget) => { |
|
|
|
|
let missingInputs: string[] = [] |
|
|
|
|
const missingInputs: string[] = [] |
|
|
|
|
const missingInputsCallback = (path: string) => { |
|
|
|
|
missingInputs.push(path) |
|
|
|
|
return { error: 'Deferred import' } |
|
|
|
@ -129,7 +129,7 @@ export class Compiler { |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
onCompilationFinished (data: CompilationResult, missingInputs?: string[], source?: SourceWithTarget): void { |
|
|
|
|
let noFatalErrors: boolean = true // ie warnings are ok
|
|
|
|
|
let noFatalErrors = true // ie warnings are ok
|
|
|
|
|
|
|
|
|
|
const checkIfFatalError = (error: CompilationError) => { |
|
|
|
|
// Ignore warnings and the 'Deferred import' error as those are generated by us as a workaround
|
|
|
|
@ -192,7 +192,7 @@ export class Compiler { |
|
|
|
|
this.state.compileJSON = (source: SourceWithTarget) => { |
|
|
|
|
this.onCompilationFinished({ error: { formattedMessage: 'Compiler not yet loaded.' } }) |
|
|
|
|
} |
|
|
|
|
let newScript: HTMLScriptElement = document.createElement('script') |
|
|
|
|
const newScript: HTMLScriptElement = document.createElement('script') |
|
|
|
|
newScript.type = 'text/javascript' |
|
|
|
|
newScript.src = url |
|
|
|
|
document.getElementsByTagName('head')[0].appendChild(newScript) |
|
|
|
@ -212,7 +212,7 @@ export class Compiler { |
|
|
|
|
|
|
|
|
|
loadWorker (url: string): void { |
|
|
|
|
this.state.worker = webworkify(require('./compiler-worker.js').default) |
|
|
|
|
let jobs: Record<'sources', SourceWithTarget> [] = [] |
|
|
|
|
const jobs: Record<'sources', SourceWithTarget> [] = [] |
|
|
|
|
|
|
|
|
|
this.state.worker.addEventListener('message', (msg: Record <'data', MessageFromWorker>) => { |
|
|
|
|
const data: MessageFromWorker = msg.data |
|
|
|
@ -220,7 +220,8 @@ export class Compiler { |
|
|
|
|
case 'versionLoaded': |
|
|
|
|
if(data.data) this.onCompilerLoaded(data.data) |
|
|
|
|
break |
|
|
|
|
case 'compiled': |
|
|
|
|
case 'compiled':
|
|
|
|
|
{ |
|
|
|
|
let result: CompilationResult |
|
|
|
|
if(data.data && data.job !== undefined && data.job >= 0) { |
|
|
|
|
try { |
|
|
|
@ -236,6 +237,7 @@ export class Compiler { |
|
|
|
|
this.onCompilationFinished(result, data.missingInputs, sources) |
|
|
|
|
} |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -275,7 +277,7 @@ export class Compiler { |
|
|
|
|
importHints = importHints || [] |
|
|
|
|
// FIXME: This will only match imports if the file begins with one '.'
|
|
|
|
|
// It should tokenize by lines and check each.
|
|
|
|
|
const importRegex: RegExp = /^\s*import\s*[\'\"]([^\'\"]+)[\'\"];/g |
|
|
|
|
const importRegex = /^\s*import\s*['"]([^'"]+)['"];/g |
|
|
|
|
for (const fileName in files) { |
|
|
|
|
let match: RegExpExecArray | null |
|
|
|
|
while ((match = importRegex.exec(files[fileName].content))) { |
|
|
|
|