Skip to content

Commit 2afeb32

Browse files
authored
fix: insert before yield (#4461)
1 parent 0407c91 commit 2afeb32

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/flows/pipes/Table/index.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import View from './view'
2-
import {parse} from '@influxdata/flux-lsp-browser'
2+
import {parse, format_from_js_file} from '@influxdata/flux-lsp-browser'
33
import {parseQuery} from 'src/shared/contexts/query'
44
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
55

@@ -24,14 +24,34 @@ export default register => {
2424
const ast = isFlagEnabled('fastFlows')
2525
? parseQuery(query)
2626
: parse(query)
27-
if (!ast.body.length) {
27+
const expressions = ast.body.filter(
28+
p => p.type === 'ExpressionStatement'
29+
)
30+
31+
if (!expressions.length) {
2832
return ''
2933
}
30-
} catch {
34+
35+
expressions.forEach(e => {
36+
let _ast
37+
if (e.expression?.call?.callee?.name !== 'yield') {
38+
_ast = parse(`${e.location.source} |> limit(n: 100)`)
39+
e.expression = _ast.body[0].expression
40+
e.location = _ast.body[0].location
41+
return
42+
}
43+
44+
_ast = parse(
45+
`${e.expression.argument.location.source} |> limit(n: 100) |> ${e.expression.call.location.source}`
46+
)
47+
e.expression = _ast.body[0].expression
48+
e.location = _ast.body[0].location
49+
})
50+
return format_from_js_file(ast)
51+
} catch (e) {
52+
console.error(e)
3153
return ''
3254
}
33-
34-
return `${query} |> limit(n: 100)`
3555
},
3656
})
3757
}

0 commit comments

Comments
 (0)