aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-compiler
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-10-03 08:29:47 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-10-03 08:29:47 +0800
commit37c55302e74d6a6706a390fe03432c0d3f119510 (patch)
tree20c71254977d9368fc27123f906986397b7858a4 /packages/sol-compiler
parent98c1952956d87adf5e73a42a1b78b8bf8b4119d2 (diff)
downloaddexon-sol-tools-37c55302e74d6a6706a390fe03432c0d3f119510.tar
dexon-sol-tools-37c55302e74d6a6706a390fe03432c0d3f119510.tar.gz
dexon-sol-tools-37c55302e74d6a6706a390fe03432c0d3f119510.tar.bz2
dexon-sol-tools-37c55302e74d6a6706a390fe03432c0d3f119510.tar.lz
dexon-sol-tools-37c55302e74d6a6706a390fe03432c0d3f119510.tar.xz
dexon-sol-tools-37c55302e74d6a6706a390fe03432c0d3f119510.tar.zst
dexon-sol-tools-37c55302e74d6a6706a390fe03432c0d3f119510.zip
Fix some small bugs in compiler.ts
Diffstat (limited to 'packages/sol-compiler')
-rw-r--r--packages/sol-compiler/src/compiler.ts21
1 files changed, 18 insertions, 3 deletions
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts
index 350a5a125..ea080c312 100644
--- a/packages/sol-compiler/src/compiler.ts
+++ b/packages/sol-compiler/src/compiler.ts
@@ -349,7 +349,7 @@ export class Compiler {
): number {
let nextId_ = nextId;
- const importStatementMatches = contractSource.match(/import[^;]*;/g);
+ const importStatementMatches = contractSource.match(/\nimport[^;]*;/g);
if (importStatementMatches === null) {
return nextId_;
}
@@ -360,9 +360,24 @@ export class Compiler {
}
let importPath = importPathMatches[1];
+ // HACK(ablrow): We have, e.g.:
+ //
+ // importPath = "../../utils/LibBytes/LibBytes.sol"
+ // contractPath = "2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol"
+ //
+ // Resolver doesn't understand "../" so we want to pass
+ // "2.0.0/utils/LibBytes/LibBytes.sol" to resolver.
+ //
+ // This hack involves using path.resolve. But path.resolve returns
+ // absolute directories by default. We trick it into thinking that
+ // contractPath is a root directory by prepending a '/' and then
+ // removing the '/' the end.
+ //
+ // path.resolve("/a/b/c", ""../../d/e") === "/a/d/e"
+ //
const lastPathSeparatorPos = contractPath.lastIndexOf('/');
- const importFolder = lastPathSeparatorPos === -1 ? '' : contractPath.slice(0, lastPathSeparatorPos + 1);
- importPath = importPath.slice(0, 2) === './' ? importPath.replace(/^.\//, importFolder) : importPath;
+ const contractFolder = lastPathSeparatorPos === -1 ? '' : contractPath.slice(0, lastPathSeparatorPos + 1);
+ importPath = path.resolve('/' + contractFolder, importPath).replace('/', '');
if (_.isUndefined(sourcesToAppendTo[importPath])) {
sourcesToAppendTo[importPath] = { id: nextId_ };