-
Notifications
You must be signed in to change notification settings - Fork 15
Implement partial transpilation #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
c4ac4cc
Implement partial transpilation
Amxx 06f00f1
missing newlines
Amxx 8064ec1
use getData to mark object that are not transpiled
Amxx 890d8de
remove non-transpiled objects from files that are transpiled
Amxx 48d3f61
fix
Amxx 71e16a9
lint
Amxx f6cd41a
remove unecessary eslint-disable
Amxx 4b19e44
declare TransformData.importPath in the fix-import-directives file
Amxx bfcb1e1
fix bug when a.local === undefined
Amxx 9b831ea
refactor import for Initializable
Amxx 46c62ab
update test cache
Amxx d216e47
change linting of the produced solidity code
Amxx 904500b
Apply suggestions from code review
Amxx d4faaf8
Update src/transformations/rename-identifiers.ts
Amxx 7f53af6
Rename importPath to importFromPeer
Amxx 94c1892
move partial transpilation form class Transform to function transpile
Amxx 8d5a339
add helper function excludeAndImportPathsForPeer
Amxx 1bc7930
Update index.ts
Amxx 2b95625
change exclude return
Amxx b12b69d
renames
frangio 7d7cb3f
use for..of
frangio fd1302d
move variable definition inside
frangio 0a3b6cf
Apply suggestions from code review
Amxx 30ab602
resolve any imported node
Amxx be412df
lint
Amxx b806261
Switch node type
Amxx 13ddd81
peer import constant variable declarations
Amxx e2456ab
Update peer-import.ts
Amxx 3037c78
explicit comparaison against undefined
Amxx eb9a435
minimize change
Amxx d4a70dd
Update src/transformations/peer-import.ts
Amxx 1f7c353
add assertion
frangio ea04008
add struct to test
frangio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.6; | ||
|
|
||
| interface ISomeInterface { | ||
| function someFunction() external returns (bool); | ||
| function someOtherFunction() external returns (bool); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.6; | ||
|
|
||
| import { ISomeInterface } from "./ISomeInterface.sol"; | ||
| import { SomeLibrary } from "./SomeLibrary.sol"; | ||
|
|
||
| interface ISomeContract is ISomeInterface {} | ||
|
|
||
| contract SomeContract is ISomeContract { | ||
| function someFunction() public override returns (bool) { | ||
| return false; | ||
| } | ||
|
|
||
| function someOtherFunction() public override returns (bool) { | ||
| return true; | ||
| } | ||
|
|
||
| function test(ISomeInterface other) public returns (bool) { | ||
| return SomeLibrary.bothFunctions(this) && SomeLibrary.bothFunctions(other); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.6; | ||
|
|
||
| import { ISomeInterface } from "./ISomeInterface.sol"; | ||
|
|
||
| library SomeLibrary { | ||
| function bothFunctions(ISomeInterface instance) internal returns (bool) { | ||
| return instance.someFunction() && instance.someOtherFunction(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.6; | ||
|
|
||
| import { ISomeInterface } from "./ISomeInterface.sol"; | ||
| import { SomeLibrary } from "./SomeLibrary.sol"; | ||
| import { ISomeContract, SomeContract } from "./SomeContract.sol"; | ||
|
|
||
| contract SomeOtherContract is SomeContract { | ||
| function extraFunction() public returns (uint256) { | ||
| return 42; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import _test, { TestFn } from 'ava'; | ||
| import hre from 'hardhat'; | ||
|
|
||
| import { getBuildInfo } from './test-utils/get-build-info'; | ||
| import { OutputFile, transpile } from '.'; | ||
| import { SolcOutput } from './solc/input-output'; | ||
|
|
||
| const test = _test as TestFn<Context>; | ||
|
|
||
| interface Context { | ||
| files: OutputFile[]; | ||
| } | ||
|
|
||
| const projectDir = 'contracts/project'; | ||
| const peerProject = '@openzeppelin/test/..'; | ||
|
|
||
| test.serial.before('compile', async t => { | ||
| const buildInfo = await getBuildInfo('0.6'); | ||
| const solcInput = buildInfo.input; | ||
| const solcOutput = buildInfo.output as SolcOutput; | ||
| const exclude = Object.keys(solcOutput.sources).filter(path => !path.startsWith(projectDir)); | ||
|
|
||
| t.context.files = await transpile(solcInput, solcOutput, hre.config.paths, { | ||
| exclude, | ||
| peerProject, | ||
| }); | ||
| }); | ||
|
|
||
| for (const fileName of ['ISomeInterface.sol', 'SomeLibrary.sol']) { | ||
| test(`do not transpile ${fileName}`, t => { | ||
| const file = t.context.files.find(f => f.fileName === fileName); | ||
| t.is(file, undefined, 'file should not be transpiled'); | ||
| }); | ||
| } | ||
|
|
||
| for (const fileName of ['SomeContract.sol', 'SomeOtherContract.sol']) { | ||
| test(`transpile ${fileName}`, t => { | ||
| const file = t.context.files.find(f => f.fileName === fileName); | ||
| t.not(file, undefined, 'file not found'); | ||
| t.snapshot(file); | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.