Skip to content

Commit

Permalink
Support Standard JSON string as an input to compile()
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Feb 22, 2018
1 parent 7954d96 commit 38db1f7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ 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));
}
}

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

0 comments on commit 38db1f7

Please sign in to comment.