From 89d7233543240857943b90aef0aeea8e4f60537b Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 22 Feb 2021 10:05:45 +0000 Subject: [PATCH] Add extension scripts in logical order (#1143) * Adapt referenceNode after adding an extension * Update snapshots --- .../lib/transformers/AutoExtensionImporter.js | 3 ++- .../amp-access-laterpay/expected_output.html | 4 ++-- .../amp-subscriptions/expected_output.html | 6 +++--- .../expected_output.html | 20 +++++++++---------- .../expected_output.html | 2 +- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/optimizer/lib/transformers/AutoExtensionImporter.js b/packages/optimizer/lib/transformers/AutoExtensionImporter.js index 55524314c..02bad8b13 100644 --- a/packages/optimizer/lib/transformers/AutoExtensionImporter.js +++ b/packages/optimizer/lib/transformers/AutoExtensionImporter.js @@ -176,7 +176,7 @@ class AutoExtensionImporter { } // We use this for adding new import elements to the header - const referenceNode = findMetaViewport(head); + let referenceNode = findMetaViewport(head); // Use cdn.ampproject.org as default, RewriteUrlTransformer will change this in case of self-hosting const host = AMP_CACHE_HOST; @@ -201,6 +201,7 @@ class AutoExtensionImporter { extensionImportAttribs[extension.type] = extensionName; const extensionImport = createElement('script', extensionImportAttribs); insertAfter(head, extensionImport, referenceNode); + referenceNode = extensionImport; } } diff --git a/packages/optimizer/spec/transformers/valid/AutoExtensionImporter/amp-access-laterpay/expected_output.html b/packages/optimizer/spec/transformers/valid/AutoExtensionImporter/amp-access-laterpay/expected_output.html index 99045ab49..d0ec2cb2a 100644 --- a/packages/optimizer/spec/transformers/valid/AutoExtensionImporter/amp-access-laterpay/expected_output.html +++ b/packages/optimizer/spec/transformers/valid/AutoExtensionImporter/amp-access-laterpay/expected_output.html @@ -5,9 +5,9 @@ amp-access-laterpay - - + + - - + + + - - - - - - - - - + + + + + + + + + + diff --git a/packages/optimizer/spec/transformers/valid/AutoExtensionImporter/ignores-existing-extensions/expected_output.html b/packages/optimizer/spec/transformers/valid/AutoExtensionImporter/ignores-existing-extensions/expected_output.html index fdbd86ca3..2bb01c5a7 100644 --- a/packages/optimizer/spec/transformers/valid/AutoExtensionImporter/ignores-existing-extensions/expected_output.html +++ b/packages/optimizer/spec/transformers/valid/AutoExtensionImporter/ignores-existing-extensions/expected_output.html @@ -5,8 +5,8 @@ My AMP Page - +