Skip to content

Commit

Permalink
fix(ShadowCss): support quoted attribute values
Browse files Browse the repository at this point in the history
fixes #6085
  • Loading branch information
vicb authored and chuckjaz committed Oct 5, 2016
1 parent d985cc0 commit 7395400
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 6 additions & 6 deletions modules/@angular/compiler/src/shadow_css.ts
Expand Up @@ -174,7 +174,7 @@ export class ShadowCss {
private _insertPolyfillDirectivesInCssText(cssText: string): string {
// Difference with webcomponents.js: does not handle comments
return cssText.replace(
_cssContentNextSelectorRe, function(...m: string[]) { return m[1] + '{'; });
_cssContentNextSelectorRe, function(...m: string[]) { return m[2] + '{'; });
}

/*
Expand All @@ -196,7 +196,7 @@ export class ShadowCss {
// Difference with webcomponents.js: does not handle comments
return cssText.replace(_cssContentRuleRe, (...m: string[]) => {
const rule = m[0].replace(m[1], '').replace(m[2], '');
return m[3] + rule;
return m[4] + rule;
});
}

Expand Down Expand Up @@ -242,7 +242,7 @@ export class ShadowCss {
let m: RegExpExecArray;
_cssContentUnscopedRuleRe.lastIndex = 0;
while ((m = _cssContentUnscopedRuleRe.exec(cssText)) !== null) {
const rule = m[0].replace(m[2], '').replace(m[1], m[3]);
const rule = m[0].replace(m[2], '').replace(m[1], m[4]);
r += rule + '\n\n';
}
return r;
Expand Down Expand Up @@ -458,10 +458,10 @@ export class ShadowCss {
}
}
const _cssContentNextSelectorRe =
/polyfill-next-selector[^}]*content:[\s]*?['"](.*?)['"][;\s]*}([^{]*?){/gim;
const _cssContentRuleRe = /(polyfill-rule)[^}]*(content:[\s]*['"](.*?)['"])[;\s]*[^}]*}/gim;
/polyfill-next-selector[^}]*content:[\s]*?(['"])(.*?)\1[;\s]*}([^{]*?){/gim;
const _cssContentRuleRe = /(polyfill-rule)[^}]*(content:[\s]*(['"])(.*?)\3)[;\s]*[^}]*}/gim;
const _cssContentUnscopedRuleRe =
/(polyfill-unscoped-rule)[^}]*(content:[\s]*['"](.*?)['"])[;\s]*[^}]*}/gim;
/(polyfill-unscoped-rule)[^}]*(content:[\s]*(['"])(.*?)\3)[;\s]*[^}]*}/gim;
const _polyfillHost = '-shadowcsshost';
// note: :host-context pre-processed to -shadowcsshostcontext.
const _polyfillHostContext = '-shadowcsscontext';
Expand Down
9 changes: 9 additions & 0 deletions modules/@angular/compiler/test/shadow_css_spec.ts
Expand Up @@ -128,6 +128,9 @@ export function main() {

css = s('polyfill-next-selector {content: "x > y"} z {}', 'a');
expect(css).toEqual('x[a] > y[a]{}');

css = s(`polyfill-next-selector {content: 'button[priority="1"]'} z {}`, 'a');
expect(css).toEqual('button[priority="1"][a] {}');
});

it('should support polyfill-unscoped-rule', () => {
Expand All @@ -136,6 +139,9 @@ export function main() {

css = s('polyfill-unscoped-rule {content: "#menu > .bar";color: blue;}', 'a');
expect(css).toContain('#menu > .bar {;color:blue;}');

css = s(`polyfill-unscoped-rule {content: 'button[priority="1"]'}`, 'a');
expect(css).toContain('button[priority="1"] {}');
});

it('should support multiple instances polyfill-unscoped-rule', () => {
Expand All @@ -153,6 +159,9 @@ export function main() {

css = s('polyfill-rule {content: ":host.foo .bar";color:blue;}', 'a', 'a-host');
expect(css).toEqual('.foo[a-host] .bar[a] {;color:blue;}');

css = s(`polyfill-rule {content: 'button[priority="1"]'}`, 'a', 'a-host');
expect(css).toEqual('button[priority="1"][a] {}');
});

it('should handle ::shadow', () => {
Expand Down

0 comments on commit 7395400

Please sign in to comment.