Skip to content

Commit 04436cf

Browse files
dylhunnalxhub
authored andcommitted
refactor(compiler): Drop !important when parsing host style/class bindings (angular#51950)
For components, the parser already extracts the `important` property (and it is later disregarded). However, because host bindings use a totally separate parsing code path, this was never happing for host bindings. Here, we add some code to the host style parsing phase to drop the `!important` suffix. We could solve this category of problems for good by parsing host bindings with the same code as template bindings. PR Close angular#51950
1 parent aa6bb8e commit 04436cf

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/host_bindings/TEST_CASES.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"inputFiles": [
3535
"important.ts"
3636
],
37-
"skipForTemplatePipeline": true,
3837
"expectations": [
3938
{
4039
"failureMessage": "Incorrect template",

packages/compiler/src/template/pipeline/ir/src/ops/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export interface BindingOp extends Op<UpdateOp> {
114114
securityContext: SecurityContext;
115115

116116
/**
117-
* Whether the binding is a TextAttribute (e.g. `some-attr="some-value"`). This needs ot be
117+
* Whether the binding is a TextAttribute (e.g. `some-attr="some-value"`). This needs to be
118118
* tracked for compatiblity with `TemplateDefinitionBuilder` which treats `style` and `class`
119119
* TextAttributes differently from `[attr.style]` and `[attr.class]`.
120120
*/

packages/compiler/src/template/pipeline/src/phases/host_style_property_parsing.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ const CLASS_DOT = 'class.';
1616

1717
const STYLE_BANG = 'style!';
1818
const CLASS_BANG = 'class!';
19+
const BANG_IMPORTANT = '!important';
1920

2021
export function phaseHostStylePropertyParsing(job: CompilationJob): void {
2122
for (const op of job.root.update) {
2223
if (op.kind !== ir.OpKind.Binding) {
2324
continue;
2425
}
2526

27+
if (op.name.endsWith(BANG_IMPORTANT)) {
28+
// Delete any `!important` suffixes from the binding name.
29+
op.name = op.name.substring(0, op.name.length - BANG_IMPORTANT.length);
30+
}
31+
2632
if (op.name.startsWith(STYLE_DOT)) {
2733
op.bindingKind = ir.BindingKind.StyleProperty;
2834
op.name = op.name.substring(STYLE_DOT.length);

0 commit comments

Comments
 (0)