Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Split the text node content arround expression and create node for each
const tokenizedContent = rawText.split(EXPRESSION_RE);
for (const token of tokenizedContent) {
// Don't create nodes for emtpy strings
if (!token.length) {
continue;
}
let value;
if (isExpression(token)) {
try {
value = parseTemplateExpression(parent, token);
} catch (error) {
addDiagnostic(
normalizeToDiagnostic(
ParserDiagnostics.TEMPLATE_EXPRESSION_PARSING_ERROR,
error,
{
location: normalizeLocation(location),
}
)
);
return;
}
} else {
value = decodeTextContent(token);
}
const textNode = createText(node, value);
textNode.parent = parent;
let index: TemplateIdentifier | undefined;
if (forIndex) {
removeAttribute(element, forIndex.name);
if (forIndex.type !== IRAttributeType.String) {
return warnAt(
ParserDiagnostics.FOR_INDEX_DIRECTIVE_SHOULD_BE_STRING,
[],
forIndex.location
);
}
try {
index = parseIdentifier(forIndex.value);
} catch (error) {
return addDiagnostic(
normalizeToDiagnostic(ParserDiagnostics.IDENTIFIER_PARSING_ERROR, error, {
location: normalizeLocation(forIndex.location),
})
);
}
}
element.forEach = {
expression: forEachAttribute.value,
item,
index,
};
} else if (forEachAttribute || forItemAttribute) {
// If only one directive is defined
return warnOnElement(
ParserDiagnostics.FOR_EACH_AND_FOR_ITEM_DIRECTIVES_SHOULD_BE_TOGETHER,
element.__original
const [, iteratorName] = iteratorAttributeName.split(':');
if (iteratorExpression.type !== IRAttributeType.Expression) {
return warnAt(
ParserDiagnostics.DIRECTIVE_SHOULD_BE_EXPRESSION,
[iteratorExpression.name],
iteratorExpression.location
);
}
let iterator: TemplateIdentifier;
try {
iterator = parseIdentifier(iteratorName);
} catch (error) {
return addDiagnostic(
normalizeToDiagnostic(ParserDiagnostics.IDENTIFIER_PARSING_ERROR, error, {
location: normalizeLocation(iteratorExpression.location),
})
);
}
element.forOf = {
expression: iteratorExpression.value,
iterator,
};
}