Check for yields before filter and range funcs in expression

Co-authored-by: Iris Scholten <ischolten.is@gmail.com>
pull/10616/head
Delmer Reed 2018-06-18 15:22:55 -04:00 committed by Iris Scholten
parent 5c01e91c2f
commit f31c207f42
1 changed files with 36 additions and 4 deletions

View File

@ -18,10 +18,12 @@ interface Props {
onDeleteBody: (bodyID: string) => void onDeleteBody: (bodyID: string) => void
} }
interface State { interface YieldToggles {
nonYieldableIndexesToggled: {
[x: number]: boolean [x: number]: boolean
} }
interface State {
nonYieldableIndexesToggled: YieldToggles
isImplicitYieldToggled: boolean isImplicitYieldToggled: boolean
} }
@ -31,7 +33,7 @@ class ExpressionNode extends PureComponent<Props, State> {
super(props) super(props)
this.state = { this.state = {
nonYieldableIndexesToggled: {}, nonYieldableIndexesToggled: this.nonYieldableNodesFromScript,
isImplicitYieldToggled: this.isImplicitYieldToggled, isImplicitYieldToggled: this.isImplicitYieldToggled,
} }
} }
@ -210,6 +212,36 @@ class ExpressionNode extends PureComponent<Props, State> {
return false return false
} }
private get nonYieldableNodesFromScript(): YieldToggles {
const {funcs} = this.props
let isBeforeFilter = true
let isBeforeRange = true
return _.reduce(
funcs,
(acc: YieldToggles, f, index) => {
if (f.name === 'range') {
isBeforeRange = false
}
if (f.name === 'filter') {
isBeforeFilter = false
}
if (isBeforeFilter || isBeforeRange) {
const nextNode = _.get(funcs, `${index + 1}`, null)
if (nextNode && nextNode.name === 'yield') {
return {...acc, [index]: true}
}
}
return acc
},
{}
)
}
private get isImplicitYieldToggled(): boolean { private get isImplicitYieldToggled(): boolean {
const {isLastBody} = this.props const {isLastBody} = this.props