consider remappings while compilation

pull/5370/head
aniket-engg 1 year ago committed by yann300
parent 39eceae6bf
commit ad24e988bb
  1. 3
      libs/remix-solidity/src/compiler/compiler-input.ts
  2. 11
      libs/remix-solidity/src/compiler/compiler.ts
  3. 4
      libs/remix-solidity/src/compiler/types.ts
  4. 1
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx

@ -17,7 +17,8 @@ export default (sources: Source, opts: CompilerInputOptions): string => {
'': ['ast'], '': ['ast'],
'*': ['abi', 'metadata', 'devdoc', 'userdoc', 'storageLayout', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates', 'evm.assembly'] '*': ['abi', 'metadata', 'devdoc', 'userdoc', 'storageLayout', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates', 'evm.assembly']
} }
} },
remappings: opts.remappings || []
} }
} }
if (opts.evmVersion) { if (opts.evmVersion) {

@ -32,6 +32,7 @@ export class Compiler {
runs: 200, runs: 200,
evmVersion: null, evmVersion: null,
language: 'Solidity', language: 'Solidity',
remappings: [],
compilationStartTime: null, compilationStartTime: null,
target: null, target: null,
useFileConfiguration: false, useFileConfiguration: false,
@ -213,12 +214,12 @@ export class Compiler {
let input = "" let input = ""
try { try {
if (source && source.sources) { if (source && source.sources) {
const { optimize, runs, evmVersion, language, useFileConfiguration, configFileContent } = this.state const { optimize, runs, evmVersion, language, remappings, useFileConfiguration, configFileContent } = this.state
console.log('remappings---->', remappings)
if (useFileConfiguration) { if (useFileConfiguration) {
input = compilerInputForConfigFile(source.sources, JSON.parse(configFileContent)) input = compilerInputForConfigFile(source.sources, JSON.parse(configFileContent))
} else { } else {
input = compilerInput(source.sources, { optimize, runs, evmVersion, language }) input = compilerInput(source.sources, { optimize, runs, evmVersion, language, remappings })
} }
result = JSON.parse(remoteCompiler.compile(input, { import: missingInputsCallback })) result = JSON.parse(remoteCompiler.compile(input, { import: missingInputsCallback }))
@ -331,7 +332,7 @@ export class Compiler {
this.state.compileJSON = (source: SourceWithTarget, timeStamp: number) => { this.state.compileJSON = (source: SourceWithTarget, timeStamp: number) => {
if (source && source.sources) { if (source && source.sources) {
const { optimize, runs, evmVersion, language, useFileConfiguration, configFileContent } = this.state const { optimize, runs, evmVersion, language, remappings, useFileConfiguration, configFileContent } = this.state
jobs.push({ sources: source }) jobs.push({ sources: source })
let input = "" let input = ""
@ -339,7 +340,7 @@ export class Compiler {
if (useFileConfiguration) { if (useFileConfiguration) {
input = compilerInputForConfigFile(source.sources, JSON.parse(configFileContent)) input = compilerInputForConfigFile(source.sources, JSON.parse(configFileContent))
} else { } else {
input = compilerInput(source.sources, { optimize, runs, evmVersion, language }) input = compilerInput(source.sources, { optimize, runs, evmVersion, language, remappings })
} }
} catch (exception) { } catch (exception) {
this.onCompilationFinished({ error: { formattedMessage: exception.message } }, [], source, "", this.state.currentVersion) this.onCompilationFinished({ error: { formattedMessage: exception.message } }, [], source, "", this.state.currentVersion)

@ -147,7 +147,8 @@ export interface CompilerInputOptions {
[fileName: string]: Record<string, string> [fileName: string]: Record<string, string>
}, },
evmVersion?: EVMVersion, evmVersion?: EVMVersion,
language?: Language language?: Language,
remappings?: string[]
} }
export type EVMVersion = 'homestead' | 'tangerineWhistle' | 'spuriousDragon' | 'byzantium' | 'constantinople' | 'petersburg' | 'istanbul' | 'berlin' | 'london' | 'paris' | null export type EVMVersion = 'homestead' | 'tangerineWhistle' | 'spuriousDragon' | 'byzantium' | 'constantinople' | 'petersburg' | 'istanbul' | 'berlin' | 'london' | 'paris' | null
@ -168,6 +169,7 @@ export interface CompilerState {
runs: number runs: number
evmVersion: EVMVersion| null, evmVersion: EVMVersion| null,
language: Language, language: Language,
remappings: string[]
compilationStartTime: number| null, compilationStartTime: number| null,
target: string | null, target: string | null,
useFileConfiguration: boolean, useFileConfiguration: boolean,

@ -59,6 +59,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
compiledFileName: '', compiledFileName: '',
includeNightlies: false, includeNightlies: false,
language: 'Solidity', language: 'Solidity',
remappings: [],
evmVersion: '', evmVersion: '',
createFileOnce: true createFileOnce: true
}) })

Loading…
Cancel
Save