-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add DevMode helper and keep devmode nodes during optimization #4371
Add DevMode helper and keep devmode nodes during optimization #4371
Conversation
while ($headNode) { | ||
$nextSibling = $headNode->nextSibling; | ||
if ($headNode instanceof DOMElement) { | ||
if ($headNode instanceof DOMElement && (! $devMode || ! DevMode::hasExemptionForNode($headNode))) { |
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.
Why not use isExemptFromValidation
?
if ($headNode instanceof DOMElement && (! $devMode || ! DevMode::hasExemptionForNode($headNode))) { | |
if ($headNode instanceof DOMElement && ! DevMode::isExemptFromValidation($headNode)) { |
Then $devMode
variable could be removed.
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.
Because it's a loop, and that would do the check against the document multiple times although it's only needed once.
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.
OK. But that's almost always true for other instances of where isExemptFromValidation
is used currently.
I don't feel strongly about this.
@@ -74,9 +75,10 @@ public function transform(Document $document, ErrorCollection $errors) | |||
private function removeStyleAndNoscriptTags(Document $document) | |||
{ | |||
$headNode = $document->head->firstChild; | |||
$devMode = DevMode::isActiveForDocument($document); |
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.
$devMode = DevMode::isActiveForDocument($document); |
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.
Agreed with @westonruter's comments, otherwise looks good!
Summary
This PR makes the following changes:
AmpProject\DevMode
helper class (with tests);AMP_Base_Sanitizer
;AMP_Base_Sanitizer
methods over to the newAmpProject\DevMode
helper class;AmpBoilerplate
transformer does not remove nodes that are marked as being in devmode.The
AmpProject\DevMode
helper class was introduced (and theAMP_BaseSanitizer
code deprecated) because theampproject/optimizer
cannot have a dependency pointing to the plugin package. Dependencies can only ever be allowed the other way around.Fixes #4369
Checklist