{"name":"ast-parser","version":"0.0.1","description":"```sh $ npm i ast-parser -D ```","main":"parser.js","types":"parser.d.ts","scripts":{"test":"jest --watchAll","coverage":"jest --coverage && print-coveralls --sort=desc","coveralls":"cat ./coverage/lcov.info | coveralls"},"keywords":["ast","babel","tsdoc","jsdoc","typescript"],"bugs":{"url":"https://github.com/daybrush/ast-parser/issues"},"homepage":"https://github.com/daybrush/ast-parser","author":{"name":"Daybrush"},"license":"MIT","dependencies":{"@babel/traverse":"^7.2.3","@babel/types":"^7.3.0","@daybrush/utils":"^0.6.0"},"devDependencies":{"@babel/parser":"^7.3.1","eslint":"^5.12.1","jest":"^24.0.0"},"gitHead":"5570f309d8e16f93c03160cf4596164a6a82ae2a","_id":"ast-parser@0.0.1","_npmVersion":"6.4.1","_nodeVersion":"10.15.0","_npmUser":{"name":"younkue","email":"daybrush@gmail.com"},"dist":{"integrity":"sha512-0hDFt4wGmDjMSCkyOsg7tbe9iVBGBRr/yEOrfB4NIqBuNjZpQS0996nueeEJZjCKYC2StDxZsrtfwfgDy22t+Q==","shasum":"db942761855fc163789d0be7686b137b3c876130","tarball":"http://registry-npm.ywwl.com/ast-parser/download/ast-parser-0.0.1.tgz","fileCount":16,"unpackedSize":314112,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcY40vCRA9TVsSAnZWagAAUYwP+wevQtIbVb659NJutrR6\n3/9jlliS9HIhzqh/kKrRiF4oDOHUsGK34srqJGJcOwY81LTOw4jHtYaecWbF\nBtOgaqT/CZfQCRvyy66S0IViu7KbwsHwub8QkGyqZw5R7H5/Oxa3/+5lkiiE\nHfBgwk4ErkXB5jTZhV2mjUBjgzYamX/2BZPehBSVlQHRJT8lpS0E7e6FQ8tX\nzRuG4SqwqBAwE8SHlZTMVKoziwI0yYtgm+Lu1D3uFsM3CavgV++IBR/yTWDb\nqu56H4320RUOyS/sGABcpLtduCibg3xT/gYqnXmsDAvpFwCr1TeL7YR76GwO\nr4wRDYfifPqBoJM4/FkaJY6FSL53eEeLQQy3nKilc1dn3ER19qUvUtFZYM8r\nfFSWxRZeQp7jAkkm1Zh67d/9O/2WDm0BLyQTpz59tBQDr30DaIySi4k5a6+L\neczUZIxbkH1sfcBQQgJVMT9B4hQJFWn0BjTf3RY8ImackNInCi/myBsFMSPO\nKtYp7na3PnU9iHO0wtfWeYyXfHa80BXfS+RZiJbnECZB9vfNsRVxi+FWBiPw\nduOmNx8sqNk79qmJAmivhTZsvSL+l4vjEVIjZfEphlV6T+nD85z3zvgf8qlC\n3AnHoS2TZ7pNf3znwWeOMwzuimDca9A3a8HT1SQ8b6ZnB7XahN+i0MqBxdjI\n3onN\r\n=oKqL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB619BsD4R/qPPmo3TRVF53dyy7akF5aAczHDa8d27ZzAiEAzClTT8bMGD2/1ySgCVpLfkTKJNS6QCKdmKIe5DTbrsg="}],"size":51911,"noattachment":false,"key":"/ast-parser/-/ast-parser-0.0.1.tgz"},"maintainers":[{"name":"younkue","email":"daybrush@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ast-parser_0.0.1_1550028078738_0.10602911159818773"},"_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":1550028078897,"_cnpm_publish_time":1550028078897,"dist-tags":{"latest":"0.2.0"}}