From b194ebb6770fbd3af57316ea4d2139f57c008bef Mon Sep 17 00:00:00 2001 From: erwin mombay Date: Fri, 26 Feb 2021 09:46:38 -0800 Subject: [PATCH] remove IS_AMP_ALT (#31493) * remove IS_AMP_ALT This flag was only needed for single pass which is abandoned * remove rule from rc file --- .eslintrc.js | 1 - build-system/eslint-rules/no-is-amp-alt.js | 28 ----- build-system/externs/amp.extern.js | 3 - src/amp.js | 139 ++++++++++----------- 4 files changed, 63 insertions(+), 108 deletions(-) delete mode 100644 build-system/eslint-rules/no-is-amp-alt.js diff --git a/.eslintrc.js b/.eslintrc.js index 6293eed7f637..cf2e2181c3a4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -147,7 +147,6 @@ module.exports = { 'local/no-import-meta': 2, 'local/no-import-rename': 2, 'local/no-invalid-this': 2, - 'local/no-is-amp-alt': 2, 'local/no-log-array': 2, 'local/no-mixed-interpolation': 2, 'local/no-mixed-operators': 2, diff --git a/build-system/eslint-rules/no-is-amp-alt.js b/build-system/eslint-rules/no-is-amp-alt.js deleted file mode 100644 index b59d1f944b8b..000000000000 --- a/build-system/eslint-rules/no-is-amp-alt.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright 2018 The AMP HTML Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -'use strict'; - -const selector = 'AssignmentExpression Identifier[name=IS_AMP_ALT]'; -module.exports = function (context) { - return { - [selector]: function (node) { - context.report({ - node, - message: 'No Assignment to IS_AMP_ALT global property allowed', - }); - }, - }; -}; diff --git a/build-system/externs/amp.extern.js b/build-system/externs/amp.extern.js index d8357c4c31ae..b52c57eafbdf 100644 --- a/build-system/externs/amp.extern.js +++ b/build-system/externs/amp.extern.js @@ -154,9 +154,6 @@ var process = {}; process.env; process.env.NODE_ENV; -/** @type {boolean|undefined} */ -window.IS_AMP_ALT; - // Exposed to ads. // Preserve these filedNames so they can be accessed by 3p code. window.context = {}; diff --git a/src/amp.js b/src/amp.js index ced204b4b784..e6f07a059777 100644 --- a/src/amp.js +++ b/src/amp.js @@ -52,15 +52,6 @@ import {preconnectToOrigin} from './preconnect'; import {startupChunk} from './chunk'; import {stubElementsForDoc} from './service/custom-element-registry'; -/** - * self.IS_AMP_ALT (is AMP alternative binary) is undefined by default in the - * main v0.js since it is the "main" js. - * This global boolean is set by alternative binaries like amp-inabox and - * amp-shadow which has their own bootstrapping sequence. - * @type {boolean|undefined} - */ -const shouldMainBootstrapRun = !self.IS_AMP_ALT; - /** * Execute the bootstrap * @param {!./service/ampdoc-impl.AmpDoc} ampdoc @@ -109,77 +100,73 @@ function bootstrap(ampdoc, perf) { }); } -if (shouldMainBootstrapRun) { - // Store the originalHash as early as possible. Trying to debug: - // https://github.com/ampproject/amphtml/issues/6070 - if (self.location) { - self.location.originalHash = self.location.hash; - } +// Store the originalHash as early as possible. Trying to debug: +// https://github.com/ampproject/amphtml/issues/6070 +if (self.location) { + self.location.originalHash = self.location.hash; +} - /** @type {!./service/ampdoc-impl.AmpDocService} */ - let ampdocService; - // We must under all circumstances call makeBodyVisible. - // It is much better to have AMP tags not rendered than having - // a completely blank page. - try { - // Should happen first. - installErrorReporting(self); // Also calls makeBodyVisibleRecovery on errors. +/** @type {!./service/ampdoc-impl.AmpDocService} */ +let ampdocService; +// We must under all circumstances call makeBodyVisible. +// It is much better to have AMP tags not rendered than having +// a completely blank page. +try { + // Should happen first. + installErrorReporting(self); // Also calls makeBodyVisibleRecovery on errors. - // Declare that this runtime will support a single root doc. Should happen - // as early as possible. - installDocService(self, /* isSingleDoc */ true); - ampdocService = Services.ampdocServiceFor(self); - } catch (e) { - // In case of an error call this. - makeBodyVisibleRecovery(self.document); - throw e; + // Declare that this runtime will support a single root doc. Should happen + // as early as possible. + installDocService(self, /* isSingleDoc */ true); + ampdocService = Services.ampdocServiceFor(self); +} catch (e) { + // In case of an error call this. + makeBodyVisibleRecovery(self.document); + throw e; +} +startupChunk(self.document, function initial() { + /** @const {!./service/ampdoc-impl.AmpDoc} */ + const ampdoc = ampdocService.getAmpDoc(self.document); + installPlatformService(self); + installPerformanceService(self); + /** @const {!./service/performance-impl.Performance} */ + const perf = Services.performanceFor(self); + if (self.document.documentElement.hasAttribute('i-amphtml-no-boilerplate')) { + perf.addEnabledExperiment('no-boilerplate'); } - startupChunk(self.document, function initial() { - /** @const {!./service/ampdoc-impl.AmpDoc} */ - const ampdoc = ampdocService.getAmpDoc(self.document); - installPlatformService(self); - installPerformanceService(self); - /** @const {!./service/performance-impl.Performance} */ - const perf = Services.performanceFor(self); - if ( - self.document.documentElement.hasAttribute('i-amphtml-no-boilerplate') - ) { - perf.addEnabledExperiment('no-boilerplate'); - } - if (IS_ESM) { - perf.addEnabledExperiment('esm'); - } - fontStylesheetTimeout(self); - perf.tick(TickLabel.INSTALL_STYLES); - if (IS_ESM) { - bootstrap(ampdoc, perf); - } else { - installStylesForDoc( - ampdoc, - ampDocCss + ampSharedCss, - () => bootstrap(ampdoc, perf), - /* opt_isRuntimeCss */ true, - /* opt_ext */ 'amp-runtime' - ); - } - }); - - // Output a message to the console and add an attribute to the - // tag to give some information that can be used in error reports. - // (At least by sophisticated users). - if (self.console) { - (console.info || console.log).call( - console, - `Powered by AMP ⚡ HTML – Version ${internalRuntimeVersion()}`, - self.location.href - ); + if (IS_ESM) { + perf.addEnabledExperiment('esm'); } - // This code is eleminated in prod build through a babel transformer. - if (getMode().localDev) { - self.document.documentElement.setAttribute('esm', IS_ESM ? 1 : 0); + fontStylesheetTimeout(self); + perf.tick(TickLabel.INSTALL_STYLES); + if (IS_ESM) { + bootstrap(ampdoc, perf); + } else { + installStylesForDoc( + ampdoc, + ampDocCss + ampSharedCss, + () => bootstrap(ampdoc, perf), + /* opt_isRuntimeCss */ true, + /* opt_ext */ 'amp-runtime' + ); } - self.document.documentElement.setAttribute( - 'amp-version', - internalRuntimeVersion() +}); + +// Output a message to the console and add an attribute to the +// tag to give some information that can be used in error reports. +// (At least by sophisticated users). +if (self.console) { + (console.info || console.log).call( + console, + `Powered by AMP ⚡ HTML – Version ${internalRuntimeVersion()}`, + self.location.href ); } +// This code is eleminated in prod build through a babel transformer. +if (getMode().localDev) { + self.document.documentElement.setAttribute('esm', IS_ESM ? 1 : 0); +} +self.document.documentElement.setAttribute( + 'amp-version', + internalRuntimeVersion() +);