Skip to content

Commit

Permalink
feat(compiler): support directive selectors with attributes containin…
Browse files Browse the repository at this point in the history
…g `$`

This commit adds support for `$` in when selecting attributes.

Resolves angular#41244.

test(language-service): Add test to expose bug caused by source file change (angular#41500)

This commit adds a test to expose the bug caused by source file change in
between typecheck programs.

PR Close angular#41500
  • Loading branch information
kyliau authored and iRealNirmal committed Apr 12, 2021
1 parent 61bfa3d commit 9d4aae9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/compiler/src/selector.ts
Expand Up @@ -13,11 +13,11 @@ const _SELECTOR_REGEXP = new RegExp(
'(([\\.\\#]?)[-\\w]+)|' + // 2: "tag"; 3: "."/"#";
// "-" should appear first in the regexp below as FF31 parses "[.-\w]" as a range
// 4: attribute; 5: attribute_string; 6: attribute_value
'(?:\\[([-.\\w*]+)(?:=([\"\']?)([^\\]\"\']*)\\5)?\\])|' + // "[name]", "[name=value]",
// "[name="value"]",
// "[name='value']"
'(\\))|' + // 7: ")"
'(\\s*,\\s*)', // 8: ","
'(?:\\[([-.\\w$*]+)(?:=([\"\']?)([^\\]\"\']*)\\5)?\\])|' + // "[name]", "[name=value]",
// "[name="value"]",
// "[name='value']"
'(\\))|' + // 7: ")"
'(\\s*,\\s*)', // 8: ","
'g');

/**
Expand Down
13 changes: 13 additions & 0 deletions packages/compiler/test/selector/selector_spec.ts
Expand Up @@ -126,6 +126,19 @@ import {el} from '@angular/platform-browser/testing/src/browser_util';
expect(matched).toEqual([s1[0], 1]);
});

it('should support "$" in attribute names', () => {
matcher.addSelectables(s1 = CssSelector.parse('[someAttr$]'), 1);

expect(matcher.match(getSelectorFor({attrs: [['someAttr', '']]}), selectableCollector))
.toEqual(false);
expect(matched).toEqual([]);

reset();
expect(matcher.match(getSelectorFor({attrs: [['someAttr$', '']]}), selectableCollector))
.toEqual(true);
expect(matched).toEqual([s1[0], 1]);
});

it('should select by attr name only once if the value is from the DOM', () => {
matcher.addSelectables(s1 = CssSelector.parse('[some-decor]'), 1);

Expand Down

0 comments on commit 9d4aae9

Please sign in to comment.