feat(rome_js_formatter): jestEach template literals #3308
Summary
Close https://github.com/rome/tools/issues/3308
Test Plan
cargo test -p rome_js_formatter
Deploy Preview for docs-rometools canceled.
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | 30cb7b9302a252836a57977279f6956cb61e96db |
| Latest deploy log | https://app.netlify.com/sites/docs-rometools/deploys/6371f1f6b3a56c0008050e3b |
Awesome work. I have some small nit comments.
One thing we need to look into is guarding against skipped token trivia on elements that you remove. Because that would result in the skipped token trivia being emitted before the template.
I recommend testing for skipped token trivia in the
is_test_each_patternand bail out if it has any.The alternative is to use the
FormatError::PoorLayoutand catch the template formatting error to fall back to the default formatting. I think explicitly testing is nicer and the overhead should be reasonable (considering the complexity of doing the formatting).
Thank you for your review!
I added is_test_each_pattern_elements function, where we test that each node we remove does not contain any trivia.
!bench_formatter
Formatter Benchmark Results
group main pr
----- ---- --
formatter/checker.ts 1.02 415.6±3.01ms 6.3 MB/sec 1.00 406.9±2.49ms 6.4 MB/sec
formatter/compiler.js 1.01 219.5±1.62ms 4.8 MB/sec 1.00 218.1±1.14ms 4.8 MB/sec
formatter/d3.min.js 1.01 172.6±2.05ms 1554.8 KB/sec 1.00 170.8±1.69ms 1571.3 KB/sec
formatter/dojo.js 1.00 11.3±0.06ms 6.1 MB/sec 1.00 11.3±0.05ms 6.1 MB/sec
formatter/ios.d.ts 1.02 244.7±3.31ms 7.6 MB/sec 1.00 240.3±2.73ms 7.8 MB/sec
formatter/jquery.min.js 1.01 46.1±0.51ms 1834.8 KB/sec 1.00 45.8±0.24ms 1848.3 KB/sec
formatter/math.js 1.01 339.5±1.93ms 1953.0 KB/sec 1.00 336.0±2.08ms 1973.7 KB/sec
formatter/parser.ts 1.01 7.7±0.09ms 6.3 MB/sec 1.00 7.6±0.04ms 6.4 MB/sec
formatter/pixi.min.js 1.00 184.4±1.10ms 2.4 MB/sec 1.00 184.0±1.74ms 2.4 MB/sec
formatter/react-dom.production.min.js 1.01 54.8±0.97ms 2.1 MB/sec 1.00 54.2±0.58ms 2.1 MB/sec
formatter/react.production.min.js 1.00 2.7±0.01ms 2.3 MB/sec 1.00 2.6±0.01ms 2.3 MB/sec
formatter/router.ts 1.00 6.3±0.03ms 9.6 MB/sec 1.00 6.3±0.04ms 9.6 MB/sec
formatter/tex-chtml-full.js 1.01 435.8±2.63ms 2.1 MB/sec 1.00 430.3±1.65ms 2.1 MB/sec
formatter/three.min.js 1.01 219.0±1.27ms 2.7 MB/sec 1.00 217.8±1.26ms 2.7 MB/sec
formatter/typescript.js 1.02 1501.2±6.17ms 6.3 MB/sec 1.00 1469.3±4.27ms 6.5 MB/sec
formatter/vue.global.prod.js 1.00 71.4±0.76ms 1728.1 KB/sec 1.00 71.1±0.74ms 1735.7 KB/sec