Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { EdgeBuffer, expressions, Parser } from 'edge-parser'
import { TagContract } from '../Contracts'
import { StringifiedObject } from '../StringifiedObject'
import { expressionsToStringifyObject, isBlockToken, allowExpressions } from '../utils'
/**
* A list of allowed expressions for the component name
*/
const componentNameAllowedExpressions: (keyof typeof expressions)[] = [
expressions.Identifier,
expressions.Literal,
expressions.LogicalExpression,
expressions.MemberExpression,
expressions.ConditionalExpression,
expressions.CallExpression,
expressions.TemplateLiteral,
]
/**
* Returns the component name and props by parsing the component jsArg expression
*/
function getComponentNameAndProps (expression: any, parser: Parser): [string, string] {
let name
/**
* Use the first expression inside the sequence expression as the name
* of the component
*/
if (expression.type === expressions.SequenceExpression) {
name = expression.expressions.shift()
} else {
compile (parser, buffer, token) {
const parsed = parser.generateEdgeExpression(token.properties.jsArg, token.loc)
allowExpressions(
parsed,
[
expressions.Identifier,
expressions.Literal,
expressions.LogicalExpression,
expressions.MemberExpression,
expressions.ConditionalExpression,
expressions.CallExpression,
expressions.TemplateLiteral,
],
parser.options.filename,
`{${token.properties.jsArg}} is not a valid argument type for the @include tag`,
)
/**
* Include template. Since the partials can be a runtime value, we cannot inline
* the content right now and have to defer to runtime to get the value of
* the partial and then process it
*/
buffer.writeLine(`template.renderInline(${parser.stringifyExpression(parsed)})(template, ctx)`)
},
}