From 9a8423da364a3a80dc190a05f79a1edf1a42078d Mon Sep 17 00:00:00 2001 From: Dzmitry Shylovich Date: Fri, 9 Dec 2016 21:45:48 +0300 Subject: [PATCH] fix(selector): SelectorMatcher match elements with :not selector (#12977) --- modules/@angular/compiler/src/selector.ts | 6 +++--- modules/@angular/compiler/test/selector_spec.ts | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/@angular/compiler/src/selector.ts b/modules/@angular/compiler/src/selector.ts index e15bf4a7aa..2934414ac3 100644 --- a/modules/@angular/compiler/src/selector.ts +++ b/modules/@angular/compiler/src/selector.ts @@ -297,12 +297,12 @@ export class SelectorMatcher { return false; } - let selectables = map.get(name); - const starSelectables = map.get('*'); + let selectables: SelectorContext[] = map.get(name) || []; + const starSelectables: SelectorContext[] = map.get('*'); if (starSelectables) { selectables = selectables.concat(starSelectables); } - if (!selectables) { + if (selectables.length === 0) { return false; } let selectable: SelectorContext; diff --git a/modules/@angular/compiler/test/selector_spec.ts b/modules/@angular/compiler/test/selector_spec.ts index c58875df21..5e26f584c5 100644 --- a/modules/@angular/compiler/test/selector_spec.ts +++ b/modules/@angular/compiler/test/selector_spec.ts @@ -223,6 +223,11 @@ export function main() { expect(matched).toEqual([s1[0], 1, s2[0], 2, s3[0], 3, s4[0], 4]); }); + it('should match * with :not selector', () => { + matcher.addSelectables(CssSelector.parse(':not([a])'), 1); + expect(matcher.match(CssSelector.parse('div')[0], () => {})).toEqual(true); + }); + it('should match with multiple :not selectors', () => { matcher.addSelectables(s1 = CssSelector.parse('div:not([a]):not([b])'), 1); expect(matcher.match(CssSelector.parse('div[a]')[0], selectableCollector)).toBe(false);