Repository navigation
Build/Test Tools: Add TypeScript checking for zxcvbn-async.js - #16302
shail-mehta wants to merge 2 commits into
Conversation
Guard missing settings and a null script parent so the loader can be type-checked under the existing strict tsconfig.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the changes adding TypeScript coverage and defensive guards to the asynchronous zxcvbn loader.
No open issues 🎉
What changed in this PR
Adds TypeScript checking for the asynchronous zxcvbn loader, continuing the file-by-file coverage effort for #66751 while preserving normal password-strength library loading.
Changes:
- Adds the loader to TypeScript checking and declares its optional localized settings global.
- Guards against missing settings, an empty source URL, and an unavailable script insertion point.
- Removes legacy IE event handling and modernizes JavaScript syntax and formatting.
| File | Description |
|---|---|
typings/browser-globals/index.d.ts |
Declares optional _zxcvbnSettings and its source URL. |
tsconfig.json |
Includes zxcvbn-async.js in TypeScript checking. |
src/js/_enqueues/lib/zxcvbn-async.js |
Adds defensive guards and modernizes the load handler. |
Review effort: Balanced
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
lancewillett
left a comment
There was a problem hiding this comment.
TypeScript passes, and I checked the password-strength meter in Chromium on the password reset and Add New User screens. One change before landing: please drop the hard-coded '1.0' from the zxcvbn-async registration so the loader uses the Core version, like password-strength-meter just below it.
Both trunk and this patch serve the changed loader at zxcvbn-async.min.js?ver=1.0. A browser with a fresh cached copy can keep running the old code after an upgrade. Only the loader needs a new cache key.
AI review · gpt-6.2-astra
lancewillett
left a comment
There was a problem hiding this comment.
The cache-key fix works. I checked the registered minified loader URL on both commits. It changed from ?ver=1.0 to the checkout’s Core version. The JavaScript is identical to the version I tested on the password screens, and the TypeScript build passes on 4a433d4. Approved.
AI review · gpt-6.2-astra
Guard against missing loader settings or an unavailable insertion point. Use the Core version for the `zxcvbn-async` script URL. Developed in: #16302 Props shailu25. See #66751. git-svn-id: https://develop.svn.wordpress.org/trunk@65822 602fd350-edb4-49c9-b593-d223f7449a82
|
PR #16302 landed in https://core.trac.wordpress.org/changeset/65822 |
Guard against missing loader settings or an unavailable insertion point. Use the Core version for the `zxcvbn-async` script URL. Developed in: WordPress/wordpress-develop#16302 Props shailu25. See #66751. Built from https://develop.svn.wordpress.org/trunk@65822 git-svn-id: http://core.svn.wordpress.org/trunk@64851 1a063a9b-81f0-0310-95a4-ce76da25c4cd
What
Trac ticket: #66751
Adds
src/js/_enqueues/lib/zxcvbn-async.jsto TypeScript checking and fixes the defects it found.Why
_zxcvbnSettingswas an undeclared globalfirst.parentNodecan benull, which would throw when inserting the scriptwindow.attachEventis not on theWindowtype (IE 8 leftover)How
_zxcvbnSettingsis missing or has nosrc, and when there is no first<script>with a parent node.addEventListener( 'load', ... )only. DropattachEvent(), which was only needed for IE 8 and below.varwithconst, use arrow functions, and reformat to the JavaScript coding standards._zxcvbnSettingsintypings/browser-globals.tsconfig.json, keeping the list sorted.Testing Instructions
npm run typecheck:jsand confirm there are no errors.npx wp-scripts lint-js src/js/_enqueues/lib/zxcvbn-async.jsandnpx prettier --check src/js/_enqueues/lib/zxcvbn-async.jsand confirm there are no errors.zxcvbn.min.jsscript is added after page load.Use of AI Tools