Skip to content

Commit

Permalink
♻️ Consolidating more core type helpers (ampproject#34253)
Browse files Browse the repository at this point in the history
* Move time.js types into src/core/types/date

* Move finite-state-machine to core/data-structures

* Make core/types/string a submodule

* Move base64 and bytes tests with core

* Move curve.js to core/data-structures

* Make src/core/function a submodule

* Update dep-check and conformance configs for string.js

* Fix legacy tests

* Move tests for exponential backoff

* Standardize data structures tests

* Update test file structure

* Make curve map side-effect-free

* Use map and isString helpers

* Tweak test names

* Fix import

* Fix types

* Update imports of finite-state-machine

* Update imports of bytes and base64

* Update imports of curve

* Update imports of exponential-backoff

* make lerp static

* make getPointX/Y static

* make solvePositionFromXValue static

* make Bezier fully static

* Use Bezier not static this

* Fix typo

* Use static solver in Curves map

* Fix type decls

* tweak comments

* Remove unused import

* Fix imports from merge

* Move normtimedef to curve
  • Loading branch information
rcebulko authored and rochapablo committed Aug 30, 2021
1 parent 5af55dc commit 0fe7b35
Show file tree
Hide file tree
Showing 77 changed files with 551 additions and 574 deletions.
2 changes: 1 addition & 1 deletion 3p/frame-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {dev} from '../src/log';
import {dict} from '../src/core/types/object';
import {getMode} from '../src/mode';
import {once} from '../src/core/types/function.js';
import {once} from '../src/core/types/function';
import {parseJson} from '../src/json';
import {parseUrlDeprecated} from '../src/url';

Expand Down
4 changes: 2 additions & 2 deletions build-system/test-configs/conformance-config.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ requirement: {
error_message: 'string.prototype.trimStart is not allowed'
value: 'string.prototype.trimStart'
value: 'string.prototype.trimLeft'
allowlist: 'src/core/types/string.js'
allowlist: 'src/core/types/string/index.js'
}

requirement: {
type: BANNED_PROPERTY_CALL
error_message: 'string.prototype.trimEnd is not allowed'
value: 'string.prototype.trimEnd'
value: 'string.prototype.trimRight'
allowlist: 'src/core/types/string.js'
allowlist: 'src/core/types/string/index.js'
}

requirement: {
Expand Down
8 changes: 4 additions & 4 deletions build-system/test-configs/dep-check-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ exports.rules = [
'3p/**->src/core/data-structures/observable.js',
'3p/**->src/core/data-structures/promise.js',
'3p/**->src/core/error.js',
'3p/**->src/core/types/function.js',
'3p/**->src/core/types/function/index.js',
'3p/**->src/core/types/index.js',
'3p/**->src/core/types/object.js',
'3p/**->src/core/types/string.js',
'3p/**->src/core/types/string/index.js',
'3p/**->src/log.js',
'3p/**->src/style.js',
'3p/**->src/url.js',
Expand Down Expand Up @@ -121,10 +121,10 @@ exports.rules = [
allowlist: [
'ads/**->src/utils/dom-fingerprint.js',
'ads/**->src/core/error.js',
'ads/**->src/core/types/function.js',
'ads/**->src/core/types/function/index.js',
'ads/**->src/core/types/index.js',
'ads/**->src/core/types/object.js',
'ads/**->src/core/types/string.js',
'ads/**->src/core/types/string/index.js',
'ads/**->src/log.js',
'ads/**->src/mode.js',
'ads/**->src/url.js',
Expand Down
9 changes: 5 additions & 4 deletions build-system/test-configs/forbidden-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ const forbiddenTermsSrcInclusive = {
'validator/js/webui/webui.js',
'src/url.js',
'src/url-try-decode-uri-component.js',
'src/utils/bytes.js',
'src/core/types/string/bytes.js',
],
},
'Text(Encoder|Decoder)\\(': {
Expand All @@ -817,7 +817,7 @@ const forbiddenTermsSrcInclusive = {
allowlist: [
'ads/google/a4a/line-delimited-response-handler.js',
'examples/pwa/pwa.js',
'src/utils/bytes.js',
'src/core/types/string/bytes.js',
'src/utils/stream-response.js',
],
},
Expand Down Expand Up @@ -942,10 +942,11 @@ const forbiddenTermsSrcInclusive = {
message: 'Unresolved merge conflict.',
},
'\\.indexOf\\([\'"][^)]+\\)\\s*===?\\s*0\\b': {
message: 'use startsWith helper in src/string.js',
message: 'use startsWith helper in src/core/types/string',
allowlist: ['build-system/server/app.js'],
},
'\\.indexOf\\(.*===?.*\\.length': 'use endsWith helper in src/string.js',
'\\.indexOf\\(.*===?.*\\.length':
'use endsWith helper in src/core/types/string',
'/url-parse-query-string': {
message: 'Import parseQueryString from `src/url.js`',
allowlist: [
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-a4a/0.1/amp-a4a.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import {setStyle} from '../../../src/style';
import {signingServerURLs} from '../../../ads/_a4a-config';
import {streamResponseToWriter} from '../../../src/utils/stream-response';
import {triggerAnalyticsEvent} from '../../../src/analytics';
import {utf8Decode} from '../../../src/utils/bytes';
import {utf8Decode} from '../../../src/core/types/string/bytes';
import {whenWithinViewport} from './within-viewport';

/** @type {Array<string>} */
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-a4a/0.1/cryptographic-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {SignatureVerifier, VerificationStatus} from './signature-verifier';
import {getAmpAdMetadata} from './amp-ad-utils';
import {signingServerURLs} from '../../../ads/_a4a-config';
import {user} from '../../../src/log';
import {utf8Decode} from '../../../src/utils/bytes';
import {utf8Decode} from '../../../src/core/types/string/bytes';

export const SIGNATURE_VERIFIER_PROPERTY_NAME =
'AMP_FAST_FETCH_SIGNATURE_VERIFIER_';
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-a4a/0.1/name-frame-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
intersectionEntryToJson,
measureIntersection,
} from '../../../src/utils/intersection';
import {utf8Decode} from '../../../src/utils/bytes';
import {utf8Decode} from '../../../src/core/types/string/bytes';

/**
* Render a non-AMP creative into a NameFrame.
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-a4a/0.1/signature-verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {Services} from '../../../src/services';
import {base64DecodeToBytes} from '../../../src/utils/base64';
import {base64DecodeToBytes} from '../../../src/core/types/string/base64';
import {dev, devAssert, user} from '../../../src/log';
import {isArray} from '../../../src/core/types';

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-a4a/0.1/template-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {getAmpAdTemplateHelper} from './amp-ad-template-helper';
import {preloadFriendlyIframeEmbedExtensions} from '../../../src/friendly-iframe-embed';
import {tryParseJson} from '../../../src/json';
import {urls} from '../../../src/config';
import {utf8Decode} from '../../../src/utils/bytes';
import {utf8Decode} from '../../../src/core/types/string/bytes';

/** @const {string} */
export const AMP_TEMPLATED_CREATIVE_HEADER_NAME = 'AMP-Ad-Template-Extension';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import {VerificationStatus} from '../signature-verifier';
import {data} from './testdata/valid_css_at_rules_amp.reserialized';
import {user} from '../../../../src/log';
import {utf8Encode} from '../../../../src/utils/bytes';
import {utf8Encode} from '../../../../src/core/types/string/bytes';

const realWinConfig = {
amp: {},
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-a4a/0.1/test/test-name-frame-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {NameFrameRenderer} from '../name-frame-renderer';
import {parseJson} from '../../../../src/json';
import {utf8Encode} from '../../../../src/utils/bytes';
import {utf8Encode} from '../../../../src/core/types/string/bytes';

const realWinConfig = {
amp: {},
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-a4a/0.1/test/test-signature-verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
// TODO(@jridgewell, #11081): fix linter to allow fixing weird indentation

import {SignatureVerifier, VerificationStatus} from '../signature-verifier';
import {base64EncodeFromBytes} from '../../../../src/utils/base64';
import {base64EncodeFromBytes} from '../../../../src/core/types/string/base64';
import {dev, user} from '../../../../src/log';
import {utf8Encode} from '../../../../src/utils/bytes';
import {utf8Encode} from '../../../../src/core/types/string/bytes';

const networkFailure = {throws: new TypeError('Failed to fetch')};

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-a4a/0.1/test/test-template-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {TemplateRenderer} from '../template-renderer';
import {ValidatorResult} from '../amp-ad-type-defs';
import {data} from './testdata/valid_css_at_rules_amp.reserialized';
import {getAmpAdTemplateHelper} from '../amp-ad-template-helper';
import {utf8Encode} from '../../../../src/utils/bytes';
import {utf8Encode} from '../../../../src/core/types/string/bytes';

const realWinConfig = {
amp: {},
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-a4a/0.1/test/test-template-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import {AdResponseType, ValidatorResult} from '../amp-ad-type-defs';
import {data} from './testdata/valid_css_at_rules_amp.reserialized';
import {getAmpAdTemplateHelper} from '../amp-ad-template-helper';
import {utf8Encode} from '../../../../src/utils/bytes';
import {utf8Encode} from '../../../../src/core/types/string/bytes';

const realWinConfig = {
amp: {},
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-access/0.1/jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import {
base64DecodeToBytes,
base64UrlDecodeToBytes,
} from '../../../src/utils/base64';
import {stringToBytes, utf8Decode} from '../../../src/utils/bytes';
} from '../../../src/core/types/string/base64';
import {stringToBytes, utf8Decode} from '../../../src/core/types/string/bytes';
import {tryParseJson} from '../../../src/json';

/**
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-accordion/0.1/amp-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {CSS} from '../../../build/amp-accordion-0.1.css';
import {Keys} from '../../../src/core/constants/key-codes';
import {Layout} from '../../../src/layout';
import {Services} from '../../../src/services';
import {bezierCurve} from '../../../src/curve';
import {bezierCurve} from '../../../src/core/data-structures/curve';
import {clamp} from '../../../src/utils/math';
import {closest, dispatchCustomEvent, tryFocus} from '../../../src/dom';
import {createCustomEvent} from '../../../src/event-helper';
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-ad-custom/0.1/test/test-amp-ad-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {AmpAdTemplate} from '../amp-ad-custom';
import {data} from '../../../amp-a4a/0.1/test/testdata/valid_css_at_rules_amp.reserialized';
import {getAmpAdTemplateHelper} from '../../../amp-a4a/0.1/amp-ad-template-helper';
import {tryParseJson} from '../../../../src/json';
import {utf8Encode} from '../../../../src/utils/bytes';
import {utf8Encode} from '../../../../src/core/types/string/bytes';

const realWinConfig = {
amp: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import {getMode} from '../../../src/mode';
import {insertAnalyticsElement} from '../../../src/extension-analytics';
import {removeElement} from '../../../src/dom';
import {stringHash32} from '../../../src/core/types/string';
import {utf8Decode} from '../../../src/utils/bytes';
import {utf8Decode} from '../../../src/core/types/string/bytes';

/** @const {string} */
const ADSENSE_BASE_URL = 'https://googleads.g.doubleclick.net/pagead/ads';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
toggleExperiment,
} from '../../../../src/experiments';
import {toWin} from '../../../../src/types';
import {utf8Decode, utf8Encode} from '../../../../src/utils/bytes';
import {utf8Decode, utf8Encode} from '../../../../src/core/types/string/bytes';

function createAdsenseImplElement(attributes, doc, opt_tag) {
const tag = opt_tag || 'amp-ad';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {getMode} from '../../../src/mode';
import {mergeExtensionsMetadata} from '../../amp-a4a/0.1/amp-ad-utils';
import {tryParseJson} from '../../../src/json';
import {tryResolve} from '../../../src/core/data-structures/promise';
import {utf8Decode, utf8Encode} from '../../../src/utils/bytes';
import {utf8Decode, utf8Encode} from '../../../src/core/types/string/bytes';

/** @type {string} */
const TAG = 'amp-ad-network-adzerk-impl';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from '../amp-ad-network-adzerk-impl';
import {Xhr} from '../../../../src/service/xhr-impl';
import {createElementWithAttributes} from '../../../../src/dom';
import {utf8Decode, utf8Encode} from '../../../../src/utils/bytes';
import {utf8Decode, utf8Encode} from '../../../../src/core/types/string/bytes';

describes.fakeWin('amp-ad-network-adzerk-impl', {amp: true}, (env) => {
let win, doc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ import {
is3pThrottled,
waitFor3pThrottle,
} from '../../amp-ad/0.1/concurrent-load';
import {getCryptoRandomBytesArray, utf8Decode} from '../../../src/utils/bytes';
import {
getCryptoRandomBytesArray,
utf8Decode,
} from '../../../src/core/types/string/bytes';
import {
getExperimentBranch,
isExperimentOn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {getPageLayoutBoxBlocking} from '../../../src/utils/page-layout-box';
import {isInManualExperiment} from '../../../ads/google/a4a/traffic-experiments';
import {isObject} from '../../../src/core/types';
import {tryResolve} from '../../../src/core/data-structures/promise';
import {utf8Encode} from '../../../src/utils/bytes';
import {utf8Encode} from '../../../src/core/types/string/bytes';

/** @type {string} */
const TAG = 'amp-ad-network-doubleclick-impl';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// always available for them. However, when we test an impl in isolation,
// AmpAd is not loaded already, so we need to load it separately.
import '../../../amp-ad/0.1/amp-ad';
import * as bytesUtils from '../../../../src/utils/bytes';
import * as bytesUtils from '../../../../src/core/types/string/bytes';
import {
AMP_EXPERIMENT_ATTRIBUTE,
QQID_HEADER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import '../../../amp-ad/0.1/amp-ad';
import {AmpAdNetworkDoubleclickImpl} from '../amp-ad-network-doubleclick-impl';
import {SafeframeHostApi, removeSafeframeListener} from '../safeframe-host';
import {createElementWithAttributes} from '../../../../src/dom';
import {utf8Encode} from '../../../../src/utils/bytes';
import {utf8Encode} from '../../../../src/core/types/string/bytes';

/**
* We're allowing external resources because otherwise using realWin causes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {Xhr} from '../../../../src/service/xhr-impl';
import {createElementWithAttributes} from '../../../../src/dom';
import {devAssert} from '../../../../src/log';
import {layoutRectLtwh} from '../../../../src/layout-rect';
import {utf8Decode, utf8Encode} from '../../../../src/utils/bytes';
import {utf8Decode, utf8Encode} from '../../../../src/core/types/string/bytes';

const config = {amp: true, allowExternalResources: true};

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/crc32.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {utf8Encode} from '../../../src/utils/bytes';
import {utf8Encode} from '../../../src/core/types/string/bytes';

/**
* Standard key for CRC32
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {WindowInterface} from '../../../src/window-interface';
import {
base64UrlDecodeFromString,
base64UrlEncodeFromString,
} from '../../../src/utils/base64';
} from '../../../src/core/types/string/base64';
import {crc32} from './crc32';
import {user} from '../../../src/log';

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {Services} from '../../../src/services';
import {TickLabel} from '../../../src/core/constants/enums';
import {asyncStringReplace} from '../../../src/core/types/string';
import {base64UrlEncodeFromString} from '../../../src/utils/base64';
import {base64UrlEncodeFromString} from '../../../src/core/types/string/base64';
import {cookieReader} from './cookie-reader';
import {dev, devAssert, user, userAssert} from '../../../src/log';
import {dict} from '../../../src/core/types/object';
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-carousel/0.1/slidescroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {Animation} from '../../../src/animation';
import {BaseSlides} from './base-slides';
import {Keys} from '../../../src/core/constants/key-codes';
import {Services} from '../../../src/services';
import {bezierCurve} from '../../../src/curve';
import {bezierCurve} from '../../../src/core/data-structures/curve';
import {
closestAncestorElementBySelector,
dispatchCustomEvent,
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-consent/0.1/crc32.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {utf8Encode} from '../../../src/utils/bytes';
import {utf8Encode} from '../../../src/core/types/string/bytes';

/**
* Standard key for CRC32
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-consent/0.1/linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {WindowInterface} from '../../../src/window-interface';
import {
base64UrlDecodeFromString,
base64UrlEncodeFromString,
} from '../../../src/utils/base64';
} from '../../../src/core/types/string/base64';
import {crc32} from './crc32';
import {user} from '../../../src/log';

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-date-picker/0.1/amp-date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {CSS} from '../../../build/amp-date-picker-0.1.css';
import {DEFAULT_FORMAT, DEFAULT_LOCALE, FORMAT_STRINGS} from './constants';
import {DatesList} from './dates-list';
import {Deferred} from '../../../src/core/data-structures/promise';
import {FiniteStateMachine} from '../../../src/finite-state-machine';
import {FiniteStateMachine} from '../../../src/core/data-structures/finite-state-machine';
import {Keys} from '../../../src/core/constants/key-codes';
import {Layout, isLayoutSizeDefined} from '../../../src/layout';
import {Services} from '../../../src/services';
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-iframe/0.1/amp-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {LayoutPriority, isLayoutSizeDefined} from '../../../src/layout';
import {MessageType} from '../../../src/3p-frame-messaging';
import {PauseHelper} from '../../../src/utils/pause-helper';
import {Services} from '../../../src/services';
import {base64EncodeFromBytes} from '../../../src/utils/base64.js';
import {base64EncodeFromBytes} from '../../../src/core/types/string/base64.js';
import {createCustomEvent, getData, listen} from '../../../src/event-helper';
import {devAssert, user, userAssert} from '../../../src/log';
import {dict} from '../../../src/core/types/object';
Expand All @@ -40,7 +40,7 @@ import {removeElement} from '../../../src/dom';
import {removeFragment} from '../../../src/url';
import {setStyle} from '../../../src/style';
import {urls} from '../../../src/config';
import {utf8Encode} from '../../../src/utils/bytes.js';
import {utf8Encode} from '../../../src/core/types/string/bytes.js';

/** @const {string} */
const TAG_ = 'amp-iframe';
Expand Down
8 changes: 4 additions & 4 deletions extensions/amp-image-lightbox/0.1/amp-image-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {Gestures} from '../../../src/gesture';
import {Keys} from '../../../src/core/constants/key-codes';
import {Services} from '../../../src/services';
import {WindowInterface} from '../../../src/window-interface';
import {bezierCurve} from '../../../src/curve';
import {bezierCurve} from '../../../src/core/data-structures/curve';
import {boundValue, clamp, distance, magnitude} from '../../../src/utils/math';
import {continueMotion} from '../../../src/motion';
import {dev, userAssert} from '../../../src/log';
Expand All @@ -53,13 +53,13 @@ const SUPPORTED_ELEMENTS_ = {
/** @private @const */
const ARIA_ATTRIBUTES = ['aria-label', 'aria-describedby', 'aria-labelledby'];

/** @private @const {!../../../src/curve.CurveDef} */
/** @private @const {!../../../src/core/data-structures/curve.CurveDef} */
const ENTER_CURVE_ = bezierCurve(0.4, 0, 0.2, 1);

/** @private @const {!../../../src/curve.CurveDef} */
/** @private @const {!../../../src/core/data-structures/curve.CurveDef} */
const EXIT_CURVE_ = bezierCurve(0.4, 0, 0.2, 1);

/** @private @const {!../../../src/curve.CurveDef} */
/** @private @const {!../../../src/core/data-structures/curve.CurveDef} */
const PAN_ZOOM_CURVE_ = bezierCurve(0.4, 0, 0.2, 1.4);

/** @private @const {number} */
Expand Down
Loading

0 comments on commit 0fe7b35

Please sign in to comment.