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

♻️ Extract type assertions out of log to multiple pure function calls #34088

Merged
merged 15 commits into from
May 4, 2021
12 changes: 12 additions & 0 deletions build-system/test-configs/dep-check-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,18 @@ exports.rules = [
allowlist: ['src/amp.js->src/polyfills/index.js'],
},

// Base assertions should never be used explicitly; only the user/dev wrappers
// or the Log class should have access to the base implementations.
{
filesMatching: '**/*.js',
mustNotDependOn: 'src/core/assert/base.js',
allowlist: [
'src/core/assert/dev.js->src/core/assert/base.js',
'src/core/assert/user.js->src/core/assert/base.js',
'src/log.js->src/core/assert/base.js',
],
},

// Rules for main src.
{
filesMatching: 'src/**/*.js',
Expand Down
3 changes: 2 additions & 1 deletion build-system/test-configs/forbidden-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,8 @@ const forbiddenTermsGlobal = {
'/\\*\\* @type \\{\\!Element\\} \\*/': {
message: 'Use assertElement instead of casting to !Element.',
allowlist: [
'src/log.js', // Has actual implementation of assertElement.
'src/core/assert/base.js', // Has actual implementation of assertElement.
'src/core/assert/dev.js', // Has actual implementation of assertElement.
'src/polyfills/custom-elements.js',
'ads/google/imaVideo.js', // Required until #22277 is fixed.
'3p/twitter.js', // Runs in a 3p window context, so cannot import log.js.
Expand Down
193 changes: 0 additions & 193 deletions src/core/assert.js

This file was deleted.

25 changes: 25 additions & 0 deletions src/core/assert/assert.extern.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright 2021 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.
*/

/**
* @fileoverview Type externs for assertions.
* @externs
*/

/**
* @typedef {function(?, string=, ...*):?|function(?, !Array<*>)}
*/
let AssertionFunction;
Loading