-
Notifications
You must be signed in to change notification settings - Fork 26.5k
refactor(ivy): make styling instructions use the new styling algorithm #30742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
edccdbf
to
e5b9bca
Compare
6d3f4b2
to
c102bd8
Compare
c102bd8
to
1c4b94a
Compare
92813f8
to
91bdf16
Compare
@@ -1172,7 +1158,7 @@ describe('compiler compliance: styling', () => { | |||
expectEmit(result.source, template, 'Incorrect template'); | |||
}); | |||
|
|||
it('should generate override instructions for only single-level styling bindings when !important is present', | |||
it('should generate overridVjwjwe instructions for only single-level styling bindings when !important is present', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops
} | ||
if (rf & 2) { | ||
$r3$.ɵɵproperty("id", ctx.id, null, true); | ||
$r3$.ɵɵproperty("title", ctx.title, null, true); | ||
$r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a sanitizer is not given explicitly, shouldn't it just use the default one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds reasonable to me, @matsko WDYT?
@@ -586,12 +586,7 @@ function createHostBindingsFunction( | |||
name?: string): o.Expression|null { | |||
// Initialize hostVarsCount to number of bound host properties (interpolations illegal), | |||
// except 'style' and 'class' properties, since they should *not* allocate host var slots |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this comment is outdated now
@@ -324,62 +327,41 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme | |||
} | |||
|
|||
get classes(): {[key: string]: boolean;} { | |||
const classes: {[key: string]: boolean;} = {}; | |||
let classes !: {[key: string]: boolean}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type should be: let classes: {[key: string]: boolean} | undefined;
But why not just return where it's set and avoid branching?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for this is because the if statement below assigns a new map and if it overwrites the value then you end up having an empty map be used for no reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean this:
get classes(): {[key: string]: boolean} {
const element = this.nativeElement;
if (element) {
const context = loadLContextFromNode(element);
const lView = context.lView;
const tData = lView[TVIEW].data;
const tNode = tData[context.nodeIndex] as TNode;
if (tNode.classes) {
if (isStylingContext(tNode.classes)) {
return new NodeStylingDebug(tNode.classes as TStylingContext, lView, true).values;
} else {
return stylingMapToStringMap(tNode.classes);
}
}
}
return {};
}
(removes 1 branch from the function)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. Yes. Excellent contribution.
} | ||
|
||
get styles(): {[key: string]: string | null;} { | ||
const styles: {[key: string]: string | null;} = {}; | ||
let styles !: {[key: string]: string | null}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type should be: let styles: {[key: string]: string | null} | undefined;
But why not just return where it's set and avoid branching?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing here
73bef1b
to
70eaea1
Compare
// it's a container element or it's apart of a test | ||
// environment that doesn't have styling. In either | ||
// case it's safe not to apply styling to the element. | ||
const nativeStyle = native.style; | ||
if (value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matsko it looks like we may need to adjust this check to take into account cases like the one described in #31345, where the value here would be 0
(with the type of number
). My guess is that we may also have empty strings here, so may be we should check for null
here, like:
if (value !== null) {
It's not directly related to this PR, we can do it in a separate one once this PR lands.
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find. I will fix. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!=
needs to be used in the event that the value is undefined
.
eceecbe
to
675a2aa
Compare
eaa6092
to
db9fd9b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@matsko Seeing a cyclic dependency issue in G3
Update: this failure is from master, not this PR. Seems like we'll need to get that patched/fixed before we can run a useful presubmit. |
This commit is the final patch of the ivy styling algorithm refactor. This patch swaps functionality from the old styling mechanism to the new refactored code by changing the instruction code the compiler generates and by pointing the runtime instruction code to the new styling algorithm.
76810b0
to
05a41b3
Compare
angular#30742) This commit is the final patch of the ivy styling algorithm refactor. This patch swaps functionality from the old styling mechanism to the new refactored code by changing the instruction code the compiler generates and by pointing the runtime instruction code to the new styling algorithm. PR Close angular#30742
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This commit is the final patch of the ivy styling algorithm refactor.
This patch swaps functionality from the old styling mechanism to the
new refactored code by changing the instruction code the compiler
generates and by pointing the runtime instruction code to the new
styling algorithm.