allow array as callexpression argument

This commit is contained in:
Kurt Hutten IrevDev
2023-01-01 13:44:48 +11:00
parent d80d487d08
commit 84d76b5763
2 changed files with 28 additions and 0 deletions

View File

@ -181,6 +181,23 @@ function makeArguments(
const isIdentifierOrLiteral =
nextBraceOrCommaToken.token.type === 'comma' ||
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) {
const { expression, lastIndex } = makeBinaryExpression(tokens, index)
return makeArguments(tokens, lastIndex, [...previousArgs, expression])

View File

@ -286,6 +286,17 @@ function executePipeBody(
return programMemory.root[arg.name]
} else if (arg.type === 'PipeSubstitution') {
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')
})