From 2e4b8520cc422dcb1a93d4b3b6712e4ec96b07c2 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 23 Feb 2022 14:56:56 +0530 Subject: [PATCH] emit version and input too --- apps/solidity-compiler/src/app/compiler-api.ts | 4 ++-- .../src/compiler/compiler-worker.ts | 1 + libs/remix-solidity/src/compiler/compiler.ts | 16 +++++++++------- libs/remix-solidity/src/compiler/types.ts | 1 + 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index abfe0b377b..174d40f910 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -261,11 +261,11 @@ export const CompilerApiMixin = (Base) => class extends Base { this.on('fileManager', 'fileClosed', this.data.eventHandlers.onFileClosed) - this.data.eventHandlers.onCompilationFinished = (success, data, source) => { + this.data.eventHandlers.onCompilationFinished = (success, data, source, input, version) => { this.compileErrors = data if (success) { // forwarding the event to the appManager infra - this.emit('compilationFinished', source.target, source, 'soljson', data) + this.emit('compilationFinished', source.target, source, 'soljson', data, input, version) if (data.errors && data.errors.length > 0) { this.statusChanged({ key: data.errors.length, diff --git a/libs/remix-solidity/src/compiler/compiler-worker.ts b/libs/remix-solidity/src/compiler/compiler-worker.ts index 7685a766f3..662a03ec06 100644 --- a/libs/remix-solidity/src/compiler/compiler-worker.ts +++ b/libs/remix-solidity/src/compiler/compiler-worker.ts @@ -45,6 +45,7 @@ export default function (self) { // eslint-disable-line @typescript-eslint/expli cmd: 'compiled', job: data.job, data: compileJSON(data.input), + input: data.input, missingInputs: missingInputs }) } diff --git a/libs/remix-solidity/src/compiler/compiler.ts b/libs/remix-solidity/src/compiler/compiler.ts index 4a7903f5f5..ab2510b950 100644 --- a/libs/remix-solidity/src/compiler/compiler.ts +++ b/libs/remix-solidity/src/compiler/compiler.ts @@ -111,16 +111,17 @@ export class Compiler { return { error: 'Deferred import' } } let result: CompilationResult = {} + let input try { if (source && source.sources) { const { optimize, runs, evmVersion, language } = this.state - const input = compilerInput(source.sources, { optimize, runs, evmVersion, language }) + input = compilerInput(source.sources, { optimize, runs, evmVersion, language }) result = JSON.parse(compiler.compile(input, { import: missingInputsCallback })) } } catch (exception) { result = { error: { formattedMessage: 'Uncaught JavaScript exception:\n' + exception, severity: 'error', mode: 'panic' } } } - this.onCompilationFinished(result, missingInputs, source) + this.onCompilationFinished(result, missingInputs, source, input, this.state.currentVersion) } this.onCompilerLoaded(compiler.version()) } @@ -133,7 +134,7 @@ export class Compiler { * @param source Source */ - onCompilationFinished (data: CompilationResult, missingInputs?: string[], source?: SourceWithTarget): void { + onCompilationFinished (data: CompilationResult, missingInputs?: string[], source?: SourceWithTarget, input?, version?): void { let noFatalErrors = true // ie warnings are ok const checkIfFatalError = (error: CompilationError) => { @@ -159,7 +160,7 @@ export class Compiler { source: source } } - this.event.trigger('compilationFinished', [true, data, source]) + this.event.trigger('compilationFinished', [true, data, source, input, version]) } } @@ -182,16 +183,17 @@ export class Compiler { return { error: 'Deferred import' } } let result: CompilationResult = {} + let input try { if (source && source.sources) { const { optimize, runs, evmVersion, language } = this.state - const input = compilerInput(source.sources, { optimize, runs, evmVersion, language }) + input = compilerInput(source.sources, { optimize, runs, evmVersion, language }) result = JSON.parse(remoteCompiler.compile(input, { import: missingInputsCallback })) } } catch (exception) { result = { error: { formattedMessage: 'Uncaught JavaScript exception:\n' + exception, severity: 'error', mode: 'panic' } } } - this.onCompilationFinished(result, missingInputs, source) + this.onCompilationFinished(result, missingInputs, source, input, version) } this.onCompilerLoaded(version) } @@ -273,7 +275,7 @@ export class Compiler { sources = jobs[data.job].sources delete jobs[data.job] } - this.onCompilationFinished(result, data.missingInputs, sources) + this.onCompilationFinished(result, data.missingInputs, sources, data.input, this.state.currentVersion) } break } diff --git a/libs/remix-solidity/src/compiler/types.ts b/libs/remix-solidity/src/compiler/types.ts index 14751cfabc..709c0c97df 100644 --- a/libs/remix-solidity/src/compiler/types.ts +++ b/libs/remix-solidity/src/compiler/types.ts @@ -186,6 +186,7 @@ export interface MessageFromWorker { cmd: string, job?: number, missingInputs?: string[], + input?: any, data?: string }