|
|
|
@ -4,6 +4,7 @@ import validate, { Validator } from '../index';
|
|
|
|
|
import { Node } from '../../interfaces';
|
|
|
|
|
import { dimensions } from '../../utils/patterns';
|
|
|
|
|
import isVoidElementName from '../../utils/isVoidElementName';
|
|
|
|
|
import isValidIdentifier from '../../utils/isValidIdentifier';
|
|
|
|
|
|
|
|
|
|
const svg = /^(?:altGlyph|altGlyphDef|altGlyphItem|animate|animateColor|animateMotion|animateTransform|circle|clipPath|color-profile|cursor|defs|desc|discard|ellipse|feBlend|feColorMatrix|feComponentTransfer|feComposite|feConvolveMatrix|feDiffuseLighting|feDisplacementMap|feDistantLight|feDropShadow|feFlood|feFuncA|feFuncB|feFuncG|feFuncR|feGaussianBlur|feImage|feMerge|feMergeNode|feMorphology|feOffset|fePointLight|feSpecularLighting|feSpotLight|feTile|feTurbulence|filter|font|font-face|font-face-format|font-face-name|font-face-src|font-face-uri|foreignObject|g|glyph|glyphRef|hatch|hatchpath|hkern|image|line|linearGradient|marker|mask|mesh|meshgradient|meshpatch|meshrow|metadata|missing-glyph|mpath|path|pattern|polygon|polyline|radialGradient|rect|set|solidcolor|stop|switch|symbol|text|textPath|tref|tspan|unknown|use|view|vkern)$/;
|
|
|
|
|
|
|
|
|
@ -82,9 +83,18 @@ export default function validateElement(
|
|
|
|
|
|
|
|
|
|
node.attributes.forEach((attribute: Node) => {
|
|
|
|
|
if (attribute.type === 'Ref') {
|
|
|
|
|
if (!isValidIdentifier(attribute.name)) {
|
|
|
|
|
const suggestion = attribute.name.replace(/[^_$a-z0-9]/ig, '_').replace(/^\d/, '_$&');
|
|
|
|
|
|
|
|
|
|
validator.error(attribute, {
|
|
|
|
|
code: `invalid-reference-name`,
|
|
|
|
|
message: `Reference name '${attribute.name}' is invalid — must be a valid identifier such as ${suggestion}`
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
if (!refs.has(attribute.name)) refs.set(attribute.name, []);
|
|
|
|
|
refs.get(attribute.name).push(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attribute.type === 'Binding') {
|
|
|
|
|
const { name } = attribute;
|
|
|
|
|