Bug 293557
| Summary: | Web Inspector: "Pretty print" removes required space in 1 .toString, producing invalid syntax | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Andrei Iugai <andrew.yugay> |
| Component: | Web Inspector | Assignee: | Nobody <webkit-unassigned> |
| Status: | NEW | ||
| Severity: | Normal | CC: | inspector-bugzilla-changes, rcaliman, webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Safari 18 | ||
| Hardware: | All | ||
| OS: | All | ||
Andrei Iugai
Steps to Reproduce
---
1. In a JavaScript file, add the following line:
// 1.js
var numberToString = uncurryThis(1 .toString);
* Notice the space between "1" and ".toString", which is valid JavaScript syntax.
2. Load this code in Safari, open Web Inspector, and use the { } ("Pretty print") button.
Actual Result
---
Web Inspector reformats the code, removing the space and producing:
// 1.js (formatted)
var numberToString = uncurryThis(1.toString);
This is invalid JavaScript syntax and causes a parsing error:
> SyntaxError: No identifiers allowed directly after numeric literal.
As a result, the code can no longer be executed.
Expected Result
---
Web Inspector should preserve the space, or rewrite the expression as "(1).toString", which is both valid and reliable JavaScript syntax.
Other code formatters (such as Prettier and Biome) and Firefox DevTools' pretty-printer handle this case correctly.
Impact
---
- This bug breaks code for users of libraries such as "core-js", who use Local override and format button (see web.url.constructor.js: https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url.constructor.js#L38). Many JavaScript projects use build tools like "esbuild" or "bun" that generate code with "1 .toString" (with a space). If a developer formats such code in Web Inspector, valid code may silently become invalid.
- The issue is well known (core-js PR: https://github.com/zloirock/core-js/pull/1368) among JS toolchain maintainers.
- Similar problems are present in Chromium DevTools; see Chromium bug #342488683: https://issues.chromium.org/issues/342488683.
References
---
* core-js: web.url.constructor.js, 1.0.toString usage: https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url.constructor.js#L38
* core-js PR #1072: https://github.com/zloirock/core-js/pull/1072
* core-js PR #1368: https://github.com/zloirock/core-js/pull/1368
* esbuild issue #3975: https://github.com/evanw/esbuild/issues/3975
* Chromium bug #342488683: https://issues.chromium.org/issues/342488683
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/152044607>