Add source string to func node object
parent
5078ee2167
commit
2c4ccdbaa2
|
@ -36,24 +36,26 @@ export default class Walker {
|
|||
return []
|
||||
}
|
||||
|
||||
const source = currentNode.location.source
|
||||
let name
|
||||
let args
|
||||
if (currentNode.call) {
|
||||
name = currentNode.call.callee.name
|
||||
args = currentNode.call.arguments
|
||||
return [...this.walk(currentNode.argument), {name, args}]
|
||||
return [...this.walk(currentNode.argument), {name, args, source}]
|
||||
}
|
||||
|
||||
name = currentNode.callee.name
|
||||
args = currentNode.arguments
|
||||
return [{name, args}]
|
||||
return [{name, args, source}]
|
||||
}
|
||||
|
||||
private buildFuncNodes = nodes => {
|
||||
return nodes.map(node => {
|
||||
return nodes.map(({name, args, source}) => {
|
||||
return {
|
||||
name: node.name,
|
||||
arguments: this.reduceArgs(node.args),
|
||||
name,
|
||||
arguments: this.reduceArgs(args),
|
||||
source,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ describe('IFQL.AST.Walker', () => {
|
|||
expect(walker.functions).toEqual([
|
||||
{
|
||||
name: 'from',
|
||||
source: 'from(db: "telegraf")',
|
||||
arguments: [
|
||||
{
|
||||
key: 'db',
|
||||
|
@ -27,10 +28,12 @@ describe('IFQL.AST.Walker', () => {
|
|||
expect(walker.functions).toEqual([
|
||||
{
|
||||
name: 'from',
|
||||
source: 'from(db: "telegraf")',
|
||||
arguments: [{key: 'db', value: 'telegraf'}],
|
||||
},
|
||||
{
|
||||
name: 'filter',
|
||||
source: '|> filter(fn: (r) => r["_measurement"] == "cpu")',
|
||||
arguments: [
|
||||
{
|
||||
key: 'fn',
|
||||
|
@ -40,6 +43,7 @@ describe('IFQL.AST.Walker', () => {
|
|||
},
|
||||
{
|
||||
name: 'range',
|
||||
source: '|> range(start: -1m)',
|
||||
arguments: [{key: 'start', value: '-1m'}],
|
||||
},
|
||||
])
|
||||
|
|
Loading…
Reference in New Issue