{"name":"ast-parser","version":"0.1.0","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.11.0"},"devDependencies":{"@babel/parser":"^7.3.1","eslint":"^5.12.1","jest":"^24.0.0"},"gitHead":"7435b240cedaf78339af6a7e883ae5fe670c1ff4","_id":"ast-parser@0.1.0","_nodeVersion":"14.15.4","_npmVersion":"6.14.10","dist":{"integrity":"sha512-UWTgi8Gex8PFzOigwBULbeCZb16d9MJ65KjiiwqdXVf7x1KTbA47jj2DonipDxb5UtfTFCE2NoCSP+eh2GkaWg==","shasum":"15a6abb97b0bbcc7fec34a47ae8cb3f94e382c23","tarball":"http://registry-npm.ywwl.com/ast-parser/download/ast-parser-0.1.0.tgz","fileCount":5,"unpackedSize":33293,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhNvC6CRA9TVsSAnZWagAA5QAQAJioRts8D9VgrbgtJlLa\n77YLmgMO9MclLrVnl07cWTm3QIGq4H9zj2/x6MiEc2w/8H68fISxjCQSEF+S\nswSakyOSlC85Jy78j0yYmCAP+hP5OM6ZL3ee+K2/6dCwtLQJVm9FmFASTFAD\nfiW6ffS69KyEl/rl01DQ7MeTYuCutRgVSDRAAGn1TUDcpwymgYAGt+H6Rqhk\nxafCMF1dAnO4Gm6amwGxP3HGuEcTbNSGdQcFyR50G+VcGYkh2xpW2t8r4OHb\nyd5cyWMqOFZN0w7y58OEEfNCdlhq3QidqOtkzoI1fKhHZs1ccTrCLCLdCGCG\nIg4fE0ekItHTCWv+23zagGcYifY5dQ5xgtuG+bJyMDNMm4ym3Q2dRQjjfcwM\n0RbbhG95S0I7ZKzM/UehTHZSc4HjssYHMDrkEbaGtno07nWvlhxhJC6bKNhz\nIpItnWt4WnGKxNZtxp5Z751RZC8mjzAOgtupXJ4fWOhs+Yg2pQjtl20p834X\n68w5Gji7AlrhTMEXTUUqbju91oXseb0IWDR3VPZ02YCBwI/7Lk8ttFmvMGis\nUSZpkATqs5kCjL9PUV2fajvakJzjndepE4uFkIPUznYmlI6gOy8dkMjM5Dag\noAiIIO2gSmSzoeWkOvceJFtUek1A61rclDq3xoLaFgHoEaOfhumFHztoZV9K\nXDBm\r\n=XXdS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDZyAIrV3rGQ49cZfZgNFht38wKG+E2VAFbECZvY7xNQwIhAPeCXcnc+rFvq9vrfm3Lf4gJzsYdvdsRtOINctvjatWf"}],"size":7115,"noattachment":false,"key":"/ast-parser/-/ast-parser-0.1.0.tgz"},"_npmUser":{"name":"younkue","email":"daybrush@gmail.com"},"directories":{},"maintainers":[{"name":"younkue","email":"daybrush@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ast-parser_0.1.0_1630990522784_0.39954324876791647"},"_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":1630990522904,"_cnpm_publish_time":1630990522904,"dist-tags":{"latest":"0.2.0"}}