コード例 #1
0
ファイル: spawn-dead.js プロジェクト: lachrist/aran
 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}"
   ])));
 };
コード例 #2
0
ファイル: vue.js プロジェクト: lengyuedaidai/vuelayers
  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
    }
  }
コード例 #3
0
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'})
}
コード例 #4
0
ファイル: ast.js プロジェクト: martypdx/diamond-compiler
export function generate(ast, options) {
    return astringGenerate(ast, Object.assign({}, ASTRING_DEFAULTS, options));
}