Skip to content
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

♻️ Organize polyfills in prep for type-checking and core extraction #34020

Merged
merged 3 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions build-system/test-configs/dep-check-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,32 +428,32 @@ exports.rules = [
mustNotDependOn: 'src/base-element.js',
},
{
filesMatching: 'src/polyfills/**/*.js',
filesMatching: 'src/polyfills/*.js',
mustNotDependOn: '**/*.js',
allowlist: [
'src/polyfills/fetch.js->src/log.js',
'src/polyfills/fetch.js->src/json.js',
'src/polyfills/fetch.js->src/core/types/index.js',
'src/polyfills/fetch.js->src/core/types/object.js',
'src/polyfills/fetch.js->src/utils/bytes.js',
'src/polyfills/intersection-observer.js->src/polyfillstub/intersection-observer-stub.js',
'src/polyfills/resize-observer.js->src/polyfillstub/resize-observer-stub.js',
'src/polyfills/intersection-observer.js->src/polyfills/stubs/intersection-observer-stub.js',
'src/polyfills/resize-observer.js->src/polyfills/stubs/resize-observer-stub.js',
'src/polyfills/custom-elements.js->src/resolved-promise.js',
],
},
{
filesMatching: 'src/polyfillstub/**/*.js',
filesMatching: 'src/polyfills/stubs/**/*.js',
mustNotDependOn: '**/*.js',
allowlist: [
'src/polyfillstub/intersection-observer-stub.js->src/services.js',
'src/polyfillstub/intersection-observer-stub.js->src/resolved-promise.js',
'src/polyfillstub/resize-observer-stub.js->src/services.js',
'src/polyfillstub/resize-observer-stub.js->src/resolved-promise.js',
'src/polyfills/stubs/intersection-observer-stub.js->src/services.js',
'src/polyfills/stubs/intersection-observer-stub.js->src/resolved-promise.js',
'src/polyfills/stubs/resize-observer-stub.js->src/services.js',
'src/polyfills/stubs/resize-observer-stub.js->src/resolved-promise.js',
],
},
{
filesMatching: '**/*.js',
mustNotDependOn: 'src/polyfills/**/*.js',
mustNotDependOn: 'src/polyfills/*.js',
allowlist: [
// DO NOT add extensions/ files
'3p/polyfills.js->src/polyfills/math-sign.js',
Expand Down
8 changes: 2 additions & 6 deletions build-system/test-configs/forbidden-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,6 @@ const forbiddenTermsGlobal = {
'test/unit/test-mustache.js',
'test/unit/test-pass.js',
'test/unit/test-platform.js',
'test/unit/test-polyfill-document-contains.js',
'test/unit/test-polyfill-math-sign.js',
'test/unit/test-polyfill-object-assign.js',
'test/unit/test-polyfill-object-values.js',
'test/unit/test-pull-to-refresh.js',
'test/unit/test-purifier.js',
'test/unit/test-render-delaying-services.js',
Expand Down Expand Up @@ -955,8 +951,8 @@ const forbiddenTermsSrcInclusive = {
message: bannedTermsHelpString,
allowlist: [
'src/friendly-iframe-embed.js',
'src/polyfillstub/intersection-observer-stub.js',
'src/polyfillstub/resize-observer-stub.js',
'src/polyfills/stubs/intersection-observer-stub.js',
'src/polyfills/stubs/resize-observer-stub.js',
'src/service/extensions-impl.js',
'src/service/crypto-impl.js',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {installIntersectionObserver} from 'intersection-observer/intersection-observer.install';
import {maybeSetupCrossOriginObserver} from './cross-origin-observer';
import {registerServiceBuilder} from '../../../src/service';
import {upgradePolyfill} from '../../../src/polyfillstub/intersection-observer-stub';
import {upgradePolyfill} from '../../../src/polyfills/stubs/intersection-observer-stub';

const TAG = 'amp-intersection-observer-polyfill';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {installResizeObserver} from '../../../third_party/resize-observer-polyfill/ResizeObserver.install';
import {registerServiceBuilder} from '../../../src/service';
import {upgradePolyfill} from '../../../src/polyfillstub/resize-observer-stub';
import {upgradePolyfill} from '../../../src/polyfills/stubs/resize-observer-stub';

const TAG = 'amp-resize-observer-polyfill';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {
ResizeObserverStub,
installStub,
} from '../../../../src/polyfillstub/resize-observer-stub';
} from '../../../../src/polyfills/stubs/resize-observer-stub';
import {upgradeResizeObserverPolyfill} from '../amp-resize-observer-polyfill';

describes.realWin('amp-resize-observer-polyfill', {amp: false}, (env) => {
Expand Down
2 changes: 1 addition & 1 deletion src/polyfills/intersection-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import {
installStub,
shouldLoadPolyfill,
} from '../polyfillstub/intersection-observer-stub';
} from '../polyfills/stubs/intersection-observer-stub';

/**
* Installs the IntersectionObserver polyfill. There are a few different modes of operation.
Expand Down
2 changes: 1 addition & 1 deletion src/polyfills/resize-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import {
installStub,
shouldLoadPolyfill,
} from '../polyfillstub/resize-observer-stub';
} from '../polyfills/stubs/resize-observer-stub';

/**
* Installs the ResizeObserver polyfill. There are a few different modes of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* amp-intersection-observer-polyfill extension.
*/

import {Services} from '../services';
import {Services} from '../../services';

const UPGRADERS = '_upgraders';
const NATIVE = '_native';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* amp-resize-observer-polyfill extension.
*/

import {Services} from '../services';
import {Services} from '../../services';

const UPGRADERS = '_upgraders';
const STUB = '_stub';
Expand Down
4 changes: 2 additions & 2 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import {
import {internalRuntimeVersion} from './internal-version';
import {isExperimentOn, toggleExperiment} from './experiments';
import {reportErrorForWin} from './error-reporting';
import {scheduleUpgradeIfNeeded as scheduleInObUpgradeIfNeeded} from './polyfillstub/intersection-observer-stub';
import {scheduleUpgradeIfNeeded as scheduleResObUpgradeIfNeeded} from './polyfillstub/resize-observer-stub';
import {scheduleUpgradeIfNeeded as scheduleInObUpgradeIfNeeded} from './polyfills/stubs/intersection-observer-stub';
import {scheduleUpgradeIfNeeded as scheduleResObUpgradeIfNeeded} from './polyfills/stubs/resize-observer-stub';
import {setStyle} from './style';
import {startupChunk} from './chunk';
import {stubElementsForDoc} from './service/custom-element-registry';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {install} from '../../src/polyfills/array-includes';
import {install} from '../src/polyfills/array-includes';

describes.fakeWin('Array.includes', {}, (env) => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {copyProperties, install} from '../../src/polyfills/custom-elements';
import {copyProperties, install} from '../src/polyfills/custom-elements';

describes.realWin(
'install patches',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import {install} from '../../src/polyfills/document-contains';
import {install} from '../src/polyfills/document-contains';

describe('HTMLDocument.contains', () => {
describes.sandboxed('HTMLDocument.contains', {}, () => {
let fakeWinWithContains;
let fakeWinWithoutContains;
let nativeContains;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import {install} from '../../src/polyfills/domtokenlist';
import {toArray} from '../../src/core/types/array';
import {install} from '../src/polyfills/domtokenlist';
import {toArray} from '../src/core/types/array';

describes.fakeWin(
'DOMTokenList.toggle/add on non-IE',
Expand Down
2 changes: 1 addition & 1 deletion test/unit/polyfills/test-intersection-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
resetStubsForTesting,
shouldLoadPolyfill,
upgradePolyfill,
} from '../../../src/polyfillstub/intersection-observer-stub';
} from '../../../src/polyfills/stubs/intersection-observer-stub';
import {Services} from '../../../src/services';
import {
install,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import {sign} from '../../src/polyfills/math-sign';
import {sign} from '../src/polyfills/math-sign';

describe('Math.sign', () => {
describes.sandboxed('Math.sign', {}, () => {
it('returns 1 for positive x', () => {
expect(sign(1)).to.equal(1);
expect(sign(10)).to.equal(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import {assign} from '../../src/polyfills/object-assign';
import {assign} from '../src/polyfills/object-assign';

describe('Object.assign', () => {
describes.sandboxed('Object.assign', {}, () => {
it('should throw an error if target is null or undefined', () => {
expect(() => assign(null, {a: 1})).to.throw(
/Cannot convert undefined or null to object/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import {values} from '../../src/polyfills/object-values';
import {values} from '../src/polyfills/object-values';

describe('Object.values', () => {
describes.sandboxed('Object.values', {}, () => {
it('should disallow null and undefined', () => {
expect(() => values(null)).to.throw();
expect(() => values(undefined)).to.throw();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/polyfills/test-resize-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
resetStubsForTesting,
shouldLoadPolyfill,
upgradePolyfill,
} from '../../../src/polyfillstub/resize-observer-stub';
} from '../../../src/polyfills/stubs/resize-observer-stub';
import {
install,
installForChildWin,
Expand Down