return (path, script, argv) => { const estree2 = aran.weave(Acorn.parse(script), pointcut); return new Worker(URL.createObjectURL(new Blob([ "console.log = function () { \n", " postMessage(Array.from(arguments).map(String).join(' ')+'\\n');\n", "};\n", "var "+aran.namespace+" = "+advice+";\n", "{\n"+Astring.generate(estree1)+"\n}\n", "{\n"+Astring.generate(estree2)+"\n}" ]))); };
const handle = typeNode => { switch (typeNode.type) { case 'Identifier': if (!/@type\s.+/.test(evt.comment)) { evt.comment = setCommentTag(evt.comment, 'type', `{${ctorNameToType(typeNode.name)}}`) } break case 'ArrayExpression': if (!/@type\s.+/.test(evt.comment)) { evt.comment = setCommentTag(evt.comment, 'type', `{${typeNode.elements.map(n => ctorNameToType(n.name)).join('|')}}`) } break case 'ObjectExpression': let typePropNode = typeNode.properties.find(n => n.key.name === 'type') let defaultPropNode = typeNode.properties.find(n => n.key.name === 'default') let requiredPropNode = typeNode.properties.find(n => n.key.name === 'required') if (!typePropNode) return handle(typePropNode.value) if (defaultPropNode && !/^\s*\*\s@default(?:value)?\s.*$/im.test(evt.comment)) { evt.comment = setCommentTag(evt.comment, 'default', generate(defaultPropNode.value)) } if (requiredPropNode) { evt.comment = setCommentTag(evt.comment, 'required') } break } }
function replaceIncludesInAst (ast, replacement = '') { const result = estraverse.replace(ast, { enter: function (node, parent) { if (isInclude(node)) { if (node.arguments && arguments.length > 0) { return {type: 'Literal', value: replacement} } return estraverse.VisitorOption.Skip } } }) return astring.generate(result, {indent: ' ', lineEnd: '\n'}) }
export function generate(ast, options) { return astringGenerate(ast, Object.assign({}, ASTRING_DEFAULTS, options)); }