Skip to content
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

[WIP] Support the standard JSON via compile() too #122

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ There is also a direct method, `compileStandard`, which is only present on recen

Starting from version 0.4.20 a Semver compatible version number can be retrieved on every compiler release, including old ones, using the `semver()` method.

#### From version 0.4.21
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man, only if we'd have merged this at 0.4.21, it wouldn't be too big a breaking change anymore :)


Starting from version 0.4.21 a *standard JSON input and output* is also accepted by `compile()`:

```javascript
function findImports(path) {
/* Implement support for loading external files here */
return { error: 'File not found' }
}
var output = solc.compile({ /* standard JSON input */ }, findImports)
/* output contains standard JSON output */
```

### Using with Electron

**Note:**
Expand Down
22 changes: 22 additions & 0 deletions wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ function setupMethods (soljson) {
}

var compile = function (input, optimise, readCallback) {
// NOTE: horribly inefficient
if (typeof input === 'string') {
var isStandardJSON = false;
try {
input = JSON.parse(input);
if (typeof input['language'] === 'string') {
isStandardJSON = true;
}
} catch (e) {
}

if (isStandardJSON) {
// NOTE: takes second argument as "readCallback"
return JSON.parse(compileStandardWrapper(input, optimise));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compileStandardWrapper is only assigned in line 83 / 105

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javascript scoping... 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's a callback!

}
}

if (typeof input !== 'string' && typeof input['language'] === 'string') {
// NOTE: takes second argument as "readCallback"
return JSON.parse(compileStandardWrapper(JSON.stringify(input), optimise));
}

var result = '';
if (readCallback !== undefined && compileJSONCallback !== null) {
result = compileJSONCallback(JSON.stringify(input), optimise, readCallback);
Expand Down