{"name":"ast-parser","version":"0.0.0","description":"","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"","license":"ISC","_id":"ast-parser@0.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.0","_npmUser":{"name":"younkue","email":"daybrush@gmail.com"},"dist":{"integrity":"sha512-kvK7jGHlM5JBgvlSHD7HucJIrTMpsfmViT6RNR+WacrDwCt0ZtL4g4KYumDq4uR13ToSvbNkLTkQ2wZrHJ/mMA==","shasum":"e08f2bcdccebabbd4f6ea6cba6f0f344cd1b5322","tarball":"http://registry-npm.ywwl.com/ast-parser/download/ast-parser-0.0.0.tgz","fileCount":1,"unpackedSize":206,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcUpnKCRA9TVsSAnZWagAAxi4P/08XMPxcZwaRhzoseaGE\nXawFVA27FC6/nFC3Fr8DVIm6xnlG50KlmR1KWhQHAzsOVd+TVmtx4Wrocglu\nmeEgvm5cJRCAtRSpp816N8OhjFuJBVjuukRFG64HGB0ygL+gBVrib2WcN8w6\nXWffPV4Tv33rHtc9SUGYAiDFvUPox1T+pXN5/DbLdJvlM2yO5pt1ppDXAzSm\nSMlvUeFuNyZlY1tmp4xubFlsizqlCNOF0Lg7jdKISn/UlLaMpYIESqTohKf7\nSlQ+6t+9obHGrCb/ej7qJ/rzSYcxY7mAtwJTgwv2BMK90f3xIX1kjlruM11d\nVzaG09IsUhYLnZFJ43guwt+6y3Vi9KuiNrvuXOWy5JndY0/Da3bfXrdf0BH/\n4eGfgAroLQFyVCSCsJ9H9vn3u6EKQ8/JBgVyxQnvgVwRq0aMc0s90VgTKc7l\nP4uUkTeHlB5uhJA6MZ76SXRRNpHwion/cI7KK8Yq1YEgZ1FYclvEaLJG36If\ny9Zm/5ej2zX9SOZMEYjFbg1hj2TMotOejMguID1B6zwlBm5CCo3XxHzqYTWR\n4AFsOGejCBegmpvCTfZ/ENA4pQq+9Oo5PuRWcbVngwkWQ7pV7Dm4ag9PmfME\n2j1tov8V1gAKSrAC8AqIE8umKbupJT3hWChWn4DvKD84NqmCrb2xCk7d1Vlg\nZUkT\r\n=Fv20\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD0E7tIZ/+T3tK0DuRz2PJzDwE3PXh/UTn8AYRxvoH9nAIgKT/Juet5UWAyMMsYPo8RwCnU6srPrqd7wB5cPyhePFU="}],"size":241,"noattachment":false,"key":"/ast-parser/-/ast-parser-0.0.0.tgz"},"maintainers":[{"name":"younkue","email":"daybrush@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ast-parser_0.0.0_1548917193392_0.7311275886658042"},"_hasShrinkwrap":false,"readme":"# ast-parser\n\n```sh\n$ npm i ast-parser -D\n```\n\n```js\nconst {parse: babelParse} = require(\"@babel/parser\");\nconst {parse: astParse, find, findInfo} = require(\"ast-parser\");\n\nfunction getNode(code) {\n  return babelParse(code, {\n    sourceType: \"module\",\n    plugins: [\"classProperties\", \"typescript\"],\n  });\n}\n\nexpect(astParse(getNode(code)).nodeType).toBe(\"File\");\nexpect(astParse(getNode(code).program).nodeType).toBe(\"Program\");\n\nconst info = astParse(getNode(`\n  const a = {a: 1, b: 2};\n`)).program.body[0];\nconst info2 = info.declarations[0];\n\nexpect(info.nodeType).toBe(\"VariableDeclaration\");\nexpect(info.kind).toBe(\"const\");\nexpect(info.declarations.length).toBe(1);\n\nexpect(info2.id.nodeType).toBe(\"Identifier\");\nexpect(info2.id.name).toBe(\"a\");\nexpect(info2.id.string).toBe(\"a\");\nexpect(info2.init.nodeType).toBe(\"ObjectExpression\");\nexpect(info2.init.string).toBe(\"{a: 1, b: 2}\");\nexpect(info.string).toBe(\"const a = {a: 1, b: 2}\");\n\nexpect(\n  astParse(getNode(`\n    const a = {a: 1, b: 2};\n  `)).program.body[0]\n).).toBe(\"VariableDeclaration\");\n```\n\n## find ObjectExpression, ObjectProperty\n```js\nconst info = find(\"ObjectExpression\", getNode(`\n  const a = {a: 1, b: 2};\n`));\nconst info2 = findInfo(\"ObjectProperty\", info);\n\nexpect(info.string).toBe(\"{a: 1, b: 2}\");\nexpect(info2.length).toBe(2);\nexpect(info2[0].string).toBe(\"a: 1\");\nexpect(info2[0].key.string).toBe(\"a\");\nexpect(info2[0].value.string).toBe(\"1\");\nexpect(info2[1].string).toBe(\"b: 2\");\nexpect(info2[1].key.string).toBe(\"b\");\nexpect(info2[1].value.string).toBe(\"2\");\n```\n\n## find ClassProperty\n```js\nconst info = find(\"ClassDeclaration\", `\n  class A extends B implements C {\n    a = \"0\";\n    b: number = \"1\";\n    private c: string = \"2\";\n    public static d: () => void = () => ({});\n    public static abstract e: () => void;\n    constructor(a: string, private b?: number) {\n\n    }\n    public method1(): number {\n\n    }\n  }\n`);\nconst info2 = findInfo(\"ClassProperty\", info);\nconst info3 = findInfo(\"ClassMethod\", info);\n\nexpect(info.string).toBe(\"class A extends B implements C\");\nexpect(info2.length).toBe(5);\nexpect(info3.length).toBe(2);\nexpect(info2[0].string).toBe(\"a\");\nexpect(info2[1].string).toBe(\"b: number\");\nexpect(info2[2].string).toBe(\"private c: string\");\nexpect(info2[3].string).toBe(\"public static d: () => void\");\nexpect(info2[4].string).toBe(\"public static abstract e: () => void\");\nexpect(info3[0].string).toBe(\"constructor(a: string, private b?: number)\");\nexpect(info3[1].string).toBe(\"public method1(): number\");\n```\n\n","publish_time":1548917193459,"_cnpm_publish_time":1548917193459,"dist-tags":{"latest":"0.2.0"}}