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

Conversation

rcebulko
Copy link
Contributor

Moves the logic into src/core/assert. src/log calls the base implementations, which wrap the message extraction logic (which can't yet migrate into core)

@rcebulko rcebulko marked this pull request as ready for review April 29, 2021 17:49
@rcebulko rcebulko requested a review from jridgewell April 29, 2021 17:49
@amp-owners-bot
Copy link

Hey @jridgewell! These files were changed:

src/core/assert.js
src/core/assert/assert.extern.js
src/core/assert/base.js
src/core/assert/dev.js
src/core/assert/index.js
src/core/assert/user.js
src/core/types/string.js

@lgtm-com
Copy link

lgtm-com bot commented Apr 29, 2021

This pull request introduces 1 alert and fixes 1 when merging eaaa9e7 into e7e5b4e - view on LGTM.com

new alerts:

  • 1 for Useless conditional

fixed alerts:

  • 1 for Useless conditional

@rcebulko
Copy link
Contributor Author

rcebulko commented May 3, 2021

@jridgewell bump

@lgtm-com
Copy link

lgtm-com bot commented May 3, 2021

This pull request introduces 1 alert and fixes 1 when merging f2b454d into 6a9ada0 - view on LGTM.com

new alerts:

  • 1 for Useless conditional

fixed alerts:

  • 1 for Useless conditional

*/
export function assertElement(sentinel, shouldBeElement, opt_message) {
return assertions.assertElement(
/** @type {!AssertionFunction} */ (assert),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that none of these are going to be properly DCE'd. The indirection here requires Closure to understand that assert is empty, so assertElement's call to assert is empty, so assertElement is empty, which is difficult (and likely impossible to do if we switch to Terser).

Instead, if the intention is for dev.* to never throw, explicitly check for isMinifiedMode is each.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked at dist output and you were right. Dropped the ifMinifiedMode bailout into all the dev helpers; looks like they're DCEing correctly based on some manual tests (they aren't used anywhere yet so they won't show up in bundle-size bot or v0.js output)

@rcebulko rcebulko requested a review from jridgewell May 4, 2021 18:00
@lgtm-com
Copy link

lgtm-com bot commented May 4, 2021

This pull request introduces 7 alerts and fixes 1 when merging 74ade7c into 1f4187e - view on LGTM.com

new alerts:

  • 7 for Useless conditional

fixed alerts:

  • 1 for Useless conditional

@rcebulko rcebulko merged commit f2a49b8 into ampproject:main May 4, 2021
@rcebulko rcebulko deleted the assert-types branch May 4, 2021 20:27
@rcebulko rcebulko linked an issue May 12, 2021 that may be closed by this pull request
5 tasks
rochapablo pushed a commit to rochapablo/amphtml that referenced this pull request Aug 30, 2021
…ampproject#34088)

* Make assert its own directory

* Fix type annotation on isString

* Update log

* Move type assertion logic out of log

* Provide user/dev assertion modules

* Take assertFn as parameter

* Add comments

* Support Array args to assertion functions

* Missing things

* Remove commented-out import

* Remove outdated comment

* Remove sentinel param from dev/user assert files

* DCE escape hatch on dev assert helpers

* Add typecasts for DCE bail-outs

* Update forbidden terms allowlist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I2I: src/core directory with no runtime dependencies
3 participants