Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const resolve = (child: AbbreviationNode): Abbreviation | null => {
const snippet = child.name && config.snippets[child.name];
// A snippet in stack means circular reference.
// It can be either a user error or a perfectly valid snippet like
// "img": "img[src alt]/", e.g. an element with predefined shape.
// In any case, simply stop parsing and keep element as is
if (!snippet || stack.includes(snippet)) {
return null;
}
const snippetAbbr = parse(snippet, config);
stack.push(snippet);
walkResolve(snippetAbbr, resolve);
stack.pop();
// Add attributes from current node into every top-level node of parsed abbreviation
for (const topNode of snippetAbbr.children) {
const from: AbbreviationAttribute[] = topNode.attributes || [];
const to: AbbreviationAttribute[] = child.attributes || [];
topNode.attributes = reversed ? to.concat(from) : from.concat(to);
mergeNodes(child, topNode);
}
return snippetAbbr;
};
export default function parse(abbr: string | Abbreviation, config: Config): Abbreviation {
if (typeof abbr === 'string') {
let parseOpt: ParserOptions = config;
if (config.options['jsx.enabled']) {
parseOpt = {
...parseOpt,
jsx: true
};
}
abbr = abbreviation(abbr, parseOpt);
}
// Run abbreviation resolve in two passes:
// 1. Map each node to snippets, which are abbreviations as well. A single snippet
// may produce multiple nodes
// 2. Transform every resolved node
abbr = snippets(abbr, config);
walk(abbr, transform, config);
return abbr;
}
Object.keys(xsl).forEach(k => ok(markup(xsl[k]), k));
});