tonic + npm: babylon

const babylon = require("babylon") function doSomething(a, b, c) { // get the values of passed argumenst const argValues = arguments // get the names of the arguments by parsing the function const ast = babylon.parse(doSomething.toString()) const argNames = ast.program.body[0].params.map(node => node.name) // join the 2 arrays, by looping over the longest of 2 arrays const maxLen = Math.max(argNames.length, argValues.length) const args = [] for (i = 0; i < maxLen; i++) { args.push({name: argNames[i], value: argValues[i]}) } console.log(JSON.stringify(args)) // implement the actual function here } doSomething(1, 2, 3, 4)
Created from: https://tonicdev.com/npm/babylon
Loading…

no comments

    sign in to comment