0xProject / 0x-monorepo

0x protocol monorepo - includes our smart contracts and many developer tools
Other
1.41k stars 464 forks source link

[sol-compiler] AST is not present in the output when requested #2746

Closed LogvinovLeon closed 3 years ago

LogvinovLeon commented 3 years ago

Expected Behavior

AST should be present in the artifacts when requested

Current Behavior

It's not there even though Solidity returns it. It does not make it's way to the artifacts file

Possible Solution

In the https://github.com/0xProject/0x-monorepo/blob/development/packages/sol-compiler/src/compiler.ts#L396 Change from:

            const { id } = compilerOutput.sources[sourceContractPath];
            allSources[sourceContractPath] = { id, content };
        }
        const usedSources = getSourcesWithDependencies(contractPath, allSources, importRemappings);

        const contractVersion: ContractVersionData = {
            compilerOutput: compiledContract,
            sourceTreeHashHex,
            sources: _.mapValues(usedSources, ({ id }) => ({ id })),

to

            const { id, ast } = compilerOutput.sources[sourceContractPath];
            allSources[sourceContractPath] = { id, ast, content };
        }
        const usedSources = getSourcesWithDependencies(contractPath, allSources, importRemappings);

        const contractVersion: ContractVersionData = {
            compilerOutput: compiledContract,
            sourceTreeHashHex,
            sources: usedSources,

Steps to Reproduce (for bugs)

Compile any contract and request AST in the output.

Context

Trying to get an AST of the contract using sol-compiler

Your Environment

Package Version

└─ @0x/sol-compiler@4.4.3

LogvinovLeon commented 3 years ago

@merklejerk Could you please take a look when you have a moment? Should be a quick fix

dorothy-zbornak commented 3 years ago

Good to see you're still around, Leo. This should be fixed in sol-compiler@4.5.0, which I just published.