aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-compiler
diff options
context:
space:
mode:
authorF. Eugene Aumson <gene@aumson.org>2018-08-14 13:48:14 +0800
committerF. Eugene Aumson <gene@aumson.org>2018-08-15 02:42:06 +0800
commit478bf14289d1555753353b837e4efc63b2c776fe (patch)
tree20166650db19c5bbbda348caeeef57d09124f417 /packages/sol-compiler
parentd89934954d22e5175a7d97f407e2cd43a04d0b57 (diff)
downloaddexon-sol-tools-478bf14289d1555753353b837e4efc63b2c776fe.tar
dexon-sol-tools-478bf14289d1555753353b837e4efc63b2c776fe.tar.gz
dexon-sol-tools-478bf14289d1555753353b837e4efc63b2c776fe.tar.bz2
dexon-sol-tools-478bf14289d1555753353b837e4efc63b2c776fe.tar.lz
dexon-sol-tools-478bf14289d1555753353b837e4efc63b2c776fe.tar.xz
dexon-sol-tools-478bf14289d1555753353b837e4efc63b2c776fe.tar.zst
dexon-sol-tools-478bf14289d1555753353b837e4efc63b2c776fe.zip
extract method _compile()
Diffstat (limited to 'packages/sol-compiler')
-rw-r--r--packages/sol-compiler/src/compiler.ts51
1 files changed, 27 insertions, 24 deletions
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts
index 5c99e3dae..83caa2a19 100644
--- a/packages/sol-compiler/src/compiler.ts
+++ b/packages/sol-compiler/src/compiler.ts
@@ -175,30 +175,7 @@ export class Compiler {
},
settings: this._compilerSettings,
};
- const compiled: solc.StandardOutput = JSON.parse(
- solcInstance.compileStandardWrapper(JSON.stringify(standardInput), importPath => {
- const sourceCodeIfExists = this._resolver.resolve(importPath);
- return { contents: sourceCodeIfExists.source };
- }),
- );
-
- if (!_.isUndefined(compiled.errors)) {
- const SOLIDITY_WARNING = 'warning';
- const errors = _.filter(compiled.errors, entry => entry.severity !== SOLIDITY_WARNING);
- const warnings = _.filter(compiled.errors, entry => entry.severity === SOLIDITY_WARNING);
- if (!_.isEmpty(errors)) {
- errors.forEach(error => {
- const normalizedErrMsg = getNormalizedErrMsg(error.formattedMessage || error.message);
- logUtils.log(chalk.red(normalizedErrMsg));
- });
- process.exit(1);
- } else {
- warnings.forEach(warning => {
- const normalizedWarningMsg = getNormalizedErrMsg(warning.formattedMessage || warning.message);
- logUtils.log(chalk.yellow(normalizedWarningMsg));
- });
- }
- }
+ const compiled: solc.StandardOutput = this._compile(solcInstance, standardInput);
const compiledData = compiled.contracts[contractSource.path][contractName];
if (_.isUndefined(compiledData)) {
throw new Error(
@@ -258,6 +235,32 @@ export class Compiler {
await fsWrapper.writeFileAsync(currentArtifactPath, artifactString);
logUtils.log(`${contractName} artifact saved!`);
}
+ private _compile(solcInstance: solc.SolcInstance, standardInput: solc.StandardInput): solc.StandardOutput {
+ const compiled: solc.StandardOutput = JSON.parse(
+ solcInstance.compileStandardWrapper(JSON.stringify(standardInput), importPath => {
+ const sourceCodeIfExists = this._resolver.resolve(importPath);
+ return { contents: sourceCodeIfExists.source };
+ }),
+ );
+ if (!_.isUndefined(compiled.errors)) {
+ const SOLIDITY_WARNING = 'warning';
+ const errors = _.filter(compiled.errors, entry => entry.severity !== SOLIDITY_WARNING);
+ const warnings = _.filter(compiled.errors, entry => entry.severity === SOLIDITY_WARNING);
+ if (!_.isEmpty(errors)) {
+ errors.forEach(error => {
+ const normalizedErrMsg = getNormalizedErrMsg(error.formattedMessage || error.message);
+ logUtils.log(chalk.red(normalizedErrMsg));
+ });
+ throw new Error("Compilation errors encountered");
+ } else {
+ warnings.forEach(warning => {
+ const normalizedWarningMsg = getNormalizedErrMsg(warning.formattedMessage || warning.message);
+ logUtils.log(chalk.yellow(normalizedWarningMsg));
+ });
+ }
+ }
+ return compiled;
+ }
/**
* Gets the source tree hash for a file and its dependencies.
* @param fileName Name of contract file.