Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix: check all import styles
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Nov 29, 2021
1 parent 5dfc1bd commit 9021e2d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ethers-solc/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use walkdir::WalkDir;
/// statement with the named groups "path", "id".
pub static RE_SOL_IMPORT: Lazy<Regex> = Lazy::new(|| {
// Adapted from https://github.com/nomiclabs/hardhat/blob/cced766c65b25d3d0beb39ef847246ac9618bdd9/packages/hardhat-core/src/internal/solidity/parse.ts#L100
Regex::new(r#"import\s+(?:(?:"(?P<path>[^;]*)"|'([^;]*)')(?:;|\s+as\s+(?P<id>[^;]*);)|.+from\s+(?:"(.*)"|'(.*)');)"#).unwrap()
Regex::new(r#"import\s+(?:(?:"(?P<p1>[^;]*)"|'([^;]*)')(?:;|\s+as\s+(?P<id>[^;]*);)|.+from\s+(?:"(?P<p2>.*)"|'(?P<p3>.*)');)"#).unwrap()
});

/// A regex that matches the version part of a solidity pragma
Expand All @@ -27,7 +27,7 @@ pub static RE_SOL_PRAGMA_VERSION: Lazy<Regex> =
pub fn find_import_paths(contract: &str) -> Vec<&str> {
RE_SOL_IMPORT
.captures_iter(contract)
.filter_map(|cap| cap.name("path"))
.filter_map(|cap| cap.name("p1").or(cap.name("p2")).or(cap.name("p3")))
.map(|m| m.as_str())
.collect()
}
Expand Down Expand Up @@ -153,8 +153,13 @@ mod tests {
pragma solidity ^0.8.0;
import "hardhat/console.sol";
import "../contract/Contract.sol";
import { T } from "../Test.sol";
import { T } from '../Test2.sol';
"##;
assert_eq!(vec!["hardhat/console.sol", "../contract/Contract.sol"], find_import_paths(s));
assert_eq!(
vec!["hardhat/console.sol", "../contract/Contract.sol", "../Test.sol", "../Test2.sol"],
find_import_paths(s)
);
}
#[test]
fn can_find_version() {
Expand Down

0 comments on commit 9021e2d

Please sign in to comment.