allow array as callexpression argument
This commit is contained in:
@ -181,6 +181,23 @@ function makeArguments(
|
|||||||
const isIdentifierOrLiteral =
|
const isIdentifierOrLiteral =
|
||||||
nextBraceOrCommaToken.token.type === 'comma' ||
|
nextBraceOrCommaToken.token.type === 'comma' ||
|
||||||
nextBraceOrCommaToken.token.type === 'brace'
|
nextBraceOrCommaToken.token.type === 'brace'
|
||||||
|
if (
|
||||||
|
argumentToken.token.type === 'brace' &&
|
||||||
|
argumentToken.token.value === '['
|
||||||
|
) {
|
||||||
|
const { expression, lastIndex } = makeArrayExpression(
|
||||||
|
tokens,
|
||||||
|
argumentToken.index
|
||||||
|
)
|
||||||
|
const nextCommarOrBraceTokenIndex = nextMeaningfulToken(
|
||||||
|
tokens,
|
||||||
|
lastIndex
|
||||||
|
).index
|
||||||
|
return makeArguments(tokens, nextCommarOrBraceTokenIndex, [
|
||||||
|
...previousArgs,
|
||||||
|
expression,
|
||||||
|
])
|
||||||
|
}
|
||||||
if (!isIdentifierOrLiteral) {
|
if (!isIdentifierOrLiteral) {
|
||||||
const { expression, lastIndex } = makeBinaryExpression(tokens, index)
|
const { expression, lastIndex } = makeBinaryExpression(tokens, index)
|
||||||
return makeArguments(tokens, lastIndex, [...previousArgs, expression])
|
return makeArguments(tokens, lastIndex, [...previousArgs, expression])
|
||||||
|
@ -286,6 +286,17 @@ function executePipeBody(
|
|||||||
return programMemory.root[arg.name]
|
return programMemory.root[arg.name]
|
||||||
} else if (arg.type === 'PipeSubstitution') {
|
} else if (arg.type === 'PipeSubstitution') {
|
||||||
return previousResults[expressionIndex - 1]
|
return previousResults[expressionIndex - 1]
|
||||||
|
} else if (arg.type === 'ArrayExpression') {
|
||||||
|
return arg.elements.map((el) => {
|
||||||
|
if (el.type === 'Literal') {
|
||||||
|
return el.value
|
||||||
|
} else if (el.type === 'Identifier') {
|
||||||
|
return programMemory.root[el.name]
|
||||||
|
} else if (el.type === 'BinaryExpression') {
|
||||||
|
return getBinaryExpressionResult(el, programMemory)
|
||||||
|
}
|
||||||
|
throw new Error('Invalid argument type')
|
||||||
|
})
|
||||||
}
|
}
|
||||||
throw new Error('Invalid argument type')
|
throw new Error('Invalid argument type')
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user