Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
visitAttr(ast) {
const element = path.head;
if (!element || !(element instanceof ElementAst)) return;
// Create a mapping of all directives applied to the element from their selectors.
const matcher = new SelectorMatcher();
for (const dir of element.directives) {
if (!dir.directive.selector) continue;
matcher.addSelectables(CssSelector.parse(dir.directive.selector), dir);
}
// See if this attribute matches the selector of any directive on the element.
// TODO(ayazhafiz): Consider caching selector matches (at the expense of potentially
// very high memory usage).
const attributeSelector = `[${ast.name}=${ast.value}]`;
const parsedAttribute = CssSelector.parse(attributeSelector);
if (!parsedAttribute.length) return;
matcher.match(parsedAttribute[0], (_, directive) => {
symbol = info.template.query.getTypeSymbol(directive.directive.type.reference);
symbol = symbol && new OverrideKindSymbol(symbol, DirectiveKind.DIRECTIVE);
span = spanOf(ast);
});
return result;
}));
// Add template attribute if a directive contains a template reference
selectorAndAttributeNames.forEach(function (selectorAndAttr) {
var selector = selectorAndAttr.selector;
var directive = selectorMap.get(selector);
if (directive && utils_1.hasTemplateReference(directive.type) && selector.attrs.length &&
selector.attrs[0]) {
attrs_1.push({ name: selector.attrs[0], template: true });
}
});
// All input and output properties of the matching directives should be added.
var elementSelector = element ?
createElementCssSelector(element) :
createElementCssSelector(new compiler_1.Element(elementName, [], [], null, null, null));
var matcher = new compiler_1.SelectorMatcher();
matcher.addSelectables(selectors);
matcher.match(elementSelector, function (selector) {
var directive = selectorMap.get(selector);
if (directive) {
attrs_1.push.apply(attrs_1, tslib_1.__spread(Object.keys(directive.inputs).map(function (name) { return ({ name: name, input: true }); })));
attrs_1.push.apply(attrs_1, tslib_1.__spread(Object.keys(directive.outputs).map(function (name) { return ({ name: name, output: true }); })));
}
});
// If a name shows up twice, fold it into a single value.
attrs_1 = foldAttrs(attrs_1);
// Now expand them back out to ensure that input/output shows up as well as input and
// output.
attributes.push.apply(attributes, tslib_1.__spread(utils_1.flatten(attrs_1.map(expandedAttr))));
}
return attributes;
}
Parse5DomAdapter.prototype.elementMatches = function (node, selector, matcher) {
if (matcher === void 0) { matcher = null; }
if (this.isElementNode(node) && selector === '*') {
return true;
}
var /** @type {?} */ result = false;
if (selector && selector.charAt(0) == '#') {
result = this.getAttribute(node, 'id') == selector.substring(1);
}
else if (selector) {
if (!matcher) {
matcher = new SelectorMatcher();
matcher.addSelectables(CssSelector.parse(selector));
}
var /** @type {?} */ cssSelector = new CssSelector();
cssSelector.setElement(this.tagName(node));
if (node.attribs) {
for (var attrName in node.attribs) {
cssSelector.addAttribute(attrName, node.attribs[attrName]);
}
}
var /** @type {?} */ classList = this.classList(node);
for (var /** @type {?} */ i = 0; i < classList.length; i++) {
cssSelector.addClassName(classList[i]);
}
matcher.match(cssSelector, function (selector, cb) { result = true; });
}
return result;
querySelectorAll(el, selector) {
const /** @type {?} */ res = [];
const /** @type {?} */ _recursive = (result, node, selector, matcher) => {
const /** @type {?} */ cNodes = node.childNodes;
if (cNodes && cNodes.length > 0) {
for (let /** @type {?} */ i = 0; i < cNodes.length; i++) {
const /** @type {?} */ childNode = cNodes[i];
if (this.elementMatches(childNode, selector, matcher)) {
result.push(childNode);
}
_recursive(result, childNode, selector, matcher);
}
}
};
const /** @type {?} */ matcher = new SelectorMatcher();
matcher.addSelectables(CssSelector.parse(selector));
_recursive(res, el, selector, matcher);
return res;
}
/**
elementMatches(node, selector, matcher = null) {
if (this.isElementNode(node) && selector === '*') {
return true;
}
let /** @type {?} */ result = false;
if (selector && selector.charAt(0) == '#') {
result = this.getAttribute(node, 'id') == selector.substring(1);
}
else if (selector) {
if (!matcher) {
matcher = new SelectorMatcher();
matcher.addSelectables(CssSelector.parse(selector));
}
const /** @type {?} */ cssSelector = new CssSelector();
cssSelector.setElement(this.tagName(node));
if (node.attribs) {
for (const /** @type {?} */ attrName in node.attribs) {
cssSelector.addAttribute(attrName, node.attribs[attrName]);
}
}
const /** @type {?} */ classList = this.classList(node);
for (let /** @type {?} */ i = 0; i < classList.length; i++) {
cssSelector.addClassName(classList[i]);
}
matcher.match(cssSelector, function (selector, cb) { result = true; });
}
return result;
querySelectorAll(el, selector) {
const /** @type {?} */ res = [];
const /** @type {?} */ _recursive = (result, node, selector, matcher) => {
const /** @type {?} */ cNodes = node.childNodes;
if (cNodes && cNodes.length > 0) {
for (let /** @type {?} */ i = 0; i < cNodes.length; i++) {
const /** @type {?} */ childNode = cNodes[i];
if (this.elementMatches(childNode, selector, matcher)) {
result.push(childNode);
}
_recursive(result, childNode, selector, matcher);
}
}
};
const /** @type {?} */ matcher = new SelectorMatcher();
matcher.addSelectables(CssSelector.parse(selector));
_recursive(res, el, selector, matcher);
return res;
}
/**
Parse5DomAdapter.prototype.querySelectorAll = function (el, selector) {
var _this = this;
var res = [];
var _recursive = function (result, node, selector, matcher) {
var cNodes = node.childNodes;
if (cNodes && cNodes.length > 0) {
for (var i = 0; i < cNodes.length; i++) {
var childNode = cNodes[i];
if (_this.elementMatches(childNode, selector, matcher)) {
result.push(childNode);
}
_recursive(result, childNode, selector, matcher);
}
}
};
var matcher = new SelectorMatcher();
matcher.addSelectables(CssSelector.parse(selector));
_recursive(res, el, selector, matcher);
return res;
};
Parse5DomAdapter.prototype.elementMatches = function (node, selector, matcher) {
querySelectorAll(el, selector) {
const /** @type {?} */ res = [];
const /** @type {?} */ _recursive = (result, node, selector, matcher) => {
const /** @type {?} */ cNodes = node.childNodes;
if (cNodes && cNodes.length > 0) {
for (let /** @type {?} */ i = 0; i < cNodes.length; i++) {
const /** @type {?} */ childNode = cNodes[i];
if (this.elementMatches(childNode, selector, matcher)) {
result.push(childNode);
}
_recursive(result, childNode, selector, matcher);
}
}
};
const /** @type {?} */ matcher = new SelectorMatcher();
matcher.addSelectables(CssSelector.parse(selector));
_recursive(res, el, selector, matcher);
return res;
}
/**
Parse5DomAdapter.prototype.querySelectorAll = function (el, selector) {
var _this = this;
var /** @type {?} */ res = [];
var /** @type {?} */ _recursive = function (result, node, selector, matcher) {
var /** @type {?} */ cNodes = node.childNodes;
if (cNodes && cNodes.length > 0) {
for (var /** @type {?} */ i = 0; i < cNodes.length; i++) {
var /** @type {?} */ childNode = cNodes[i];
if (_this.elementMatches(childNode, selector, matcher)) {
result.push(childNode);
}
_recursive(result, childNode, selector, matcher);
}
}
};
var /** @type {?} */ matcher = new SelectorMatcher();
matcher.addSelectables(CssSelector.parse(selector));
_recursive(res, el, selector, matcher);
return res;
};
/**