Comparing version 1.0.0 to 1.0.1
@@ -61,2 +61,11 @@ const vm = require("vm"); | ||
const code = prepareCodeForParsing(snippet, flags); | ||
if (code) { | ||
return rewriteSource(code); | ||
} else { | ||
return ""; | ||
} | ||
} | ||
function prepareCodeForParsing(snippet, flags) { | ||
const { code } = snippet; | ||
@@ -66,5 +75,5 @@ if (!code) { | ||
} else if (flags.async) { | ||
return rewriteSource(`(async function () {${code}})();`); | ||
return `(async function () {\n${code}\n})();`; | ||
} else { | ||
return rewriteSource(`(function () {${code}})();`); | ||
return `(function () {\n${code}\n})();`; | ||
} | ||
@@ -139,6 +148,2 @@ } | ||
removeExtraneousGlobals(global, globalsToReplace); | ||
for (const key of Object.keys(globalsToReplace)) { | ||
global[key] = globalsToReplace[key]; | ||
} | ||
} else if (flags.persist) { | ||
@@ -152,2 +157,6 @@ const persistGlobals = recordExtraneousGlobals( | ||
} | ||
for (const key of Object.keys(globalsToReplace)) { | ||
global[key] = globalsToReplace[key]; | ||
} | ||
}; | ||
@@ -295,4 +304,7 @@ } | ||
module.exports.evaluateSnippet = evaluateSnippet; | ||
module.exports.prepareCode = function prepareCode(snippet, flags) { | ||
return prepareCodeForParsing(snippet, flags); | ||
}; | ||
module.exports.prepareFlags = function prepareFlags(snippet, options) { | ||
return prepareFlagsForExecution(options.capture, snippet); | ||
}; |
@@ -5,3 +5,3 @@ const findUp = require("find-up"); | ||
const canEvaluate = require("./canEvaluate"); | ||
const { prepareFlags } = require("./evaluateSnippets"); | ||
const { prepareCode, prepareFlags } = require("./evaluateSnippets"); | ||
const resolve = require("../resolve"); | ||
@@ -50,9 +50,3 @@ | ||
const flags = prepareFlags(snippet, options); | ||
if (flags.async) { | ||
return `(async function () {${snippet.code}})();`; | ||
} else if (flags.return) { | ||
return `(function () {${snippet.code}})();`; | ||
} else { | ||
return snippet.code; | ||
} | ||
return prepareCode(snippet, flags); | ||
}); | ||
@@ -59,0 +53,0 @@ |
{ | ||
"name": "evaldown", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Evalute JavaScript snippets in markdown files and output static pages.", | ||
@@ -5,0 +5,0 @@ "main": "lib/Evaldown.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59356
1498