Co-Authored-By: Christopher J. Brody <chris@brody.consulting>
Co-Authored-By: Christopher Quadflieg <christopher.quadflieg@adsoul.com>
Co-Authored-By: Georgii Dolzhykov <thorn.mailbox@gmail.com>
The issue here is that the `stripTrailingHardline` does not work for js/ts, I fixed it and then I realized that we always print trailing newline in every language, so there's no need to strip newline for text in script-like tag.
In addition to a tiny performance improvement outlined below,
the CPU profile of traverseDoc is now more readable.
Also anonymous arrow functions changed to named regular functions
so that they are properly displayed in the CPU profile,
and moved to outer scope where there's no closure
so that they aren't re-created (this change's performance is dependent
on JS engine implementation and optimization details).
Before (profile):
```
7129.9 ms 5.43 % 13349.9 ms 10.18 % traverseDocRec
7067.4 ms 5.39 % 11285.5 ms 8.60 % traverseDocRec
31.5 ms 0.02 % 1031.9 ms 0.79 % traverseDoc
23.6 ms 0.02 % 12313.4 ms 9.39 % traverseDoc
2.6 ms 0.00 % 0.3 ms 0.00 % (anonymous)
1.7 ms 0.00 % 1.7 ms 0.00 % call
1.6 ms 0.00 % 1.6 ms 0.00 % call
0.5 ms 0.00 % 0.5 ms 0.00 % conditionalGroup
0.4 ms 0.00 % 0.4 ms 0.00 % printDocToString$1
0.1 ms 0.00 % 0.1 ms 0.00 % printGenerically
0.1 ms 0.00 % 0.1 ms 0.00 % t
0.1 ms 0.00 % 0.1 ms 0.00 % ifBreak
0.1 ms 0.00 % 0.1 ms 0.00 % (anonymous)
0 ms 0 % 0.1 ms 0.00 % forEach
```
After (profile):
```
6937.9 ms 5.37 % 12872.5 ms 9.97 % traverseDoc
5944.0 ms 4.60 % 11047.3 ms 8.55 % propagateBreaks
735.7 ms 0.57 % 1358.3 ms 1.05 % findInDoc
257.9 ms 0.20 % 466.7 ms 0.36 % findInDoc
0.1 ms 0.00 % 0.1 ms 0.00 % has
0.1 ms 0.00 % 0.1 ms 0.00 % printArgumentsList
```
Before (performance):
```
cat ../LspLanguageService.js | NODE_ENV=production node --inspect-brk ./dist/bin-prettier.js --stdin-filepath LspLanguageService.js --loglevel debug --debug-repeat 1000 > /dev/null
Debugger listening on ws://127.0.0.1:9229/4b52c027-ef62-49d6-8770-179e805a0f43
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
[debug] normalized argv: {"color":true,"editorconfig":true,"stdin-filepath":"LspLanguageService.js","loglevel":"debug","debug-repeat":1000,"plugin-search-dir":[],"plugin":[],"ignore-path":".prettierignore","config-precedence":"cli-override","_":[]}
[debug] resolve config from '/Users/ivanbabak/_sompylasar/_github/prettier-2/LspLanguageService.js'
[debug] loaded options `null`
[debug] applied config-precedence (cli-override): {"filepath":"LspLanguageService.js"}
[debug] '--debug-repeat' option found, running formatWithCursor 1000 times.
[debug] '--debug-repeat' measurements for formatWithCursor: {
[debug] "repeat": 1000,
[debug] "hz": 7.774598830700336,
[debug] "ms": 128.624
[debug] }
```
After (performance):
```
cat ../LspLanguageService.js | NODE_ENV=production node --inspect-brk ./dist/bin-prettier.js --stdin-filepath LspLanguageService.js --loglevel debug --debug-repeat 1000 > /dev/null
Debugger listening on ws://127.0.0.1:9229/aa76e134-a68c-44ed-89a8-efb68bc46baa
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
[debug] normalized argv: {"color":true,"editorconfig":true,"stdin-filepath":"LspLanguageService.js","loglevel":"debug","debug-repeat":1000,"plugin-search-dir":[],"plugin":[],"ignore-path":".prettierignore","config-precedence":"cli-override","_":[]}
[debug] resolve config from '/Users/ivanbabak/_sompylasar/_github/prettier/LspLanguageService.js'
[debug] loaded options `null`
[debug] applied config-precedence (cli-override): {"filepath":"LspLanguageService.js"}
[debug] '--debug-repeat' option found, running formatWithCursor 1000 times.
[debug] '--debug-repeat' measurements for formatWithCursor: {
[debug] "repeat": 1000,
[debug] "hz": 7.888114977163907,
[debug] "ms": 126.773
[debug] }
```
- preserve trailing spaces in html, excluding html comment
- `doc-printer` is now unrelated to `options.parser`
- fix some cases that two trailing spaces are mis-considered as `break`
* handle cusor position relative to comments correctly
* use more robust method of cursor offset tracking
* add support for cursorOffset with rangeStart/End
* add tests for cursorOffset
* use old JS syntax for node4
* add another cursor offset test case
* remove trailing whitespace in cursor tests
* fix null findNodeAtOffset handling
* remove dead code
* add more test cases
* use indexOf for node4
* revert comments.js
* add more comment tests
* change tests infra
* Fix AST_COMPARE
* move CURSOR to top level of file
* mutate result
* use es6 property shorthand
* simplify diff offset calculation
* put remaining test cases in individual files
* test: add test cases
* test: add test cases
* fix(javascript): ternary with `--use-tabs`
* chore: add istanbul ignore comment
* fix: remove unnecessary condition
* docs(commands): update `align`
* fix: do not transform the middle part
* refactor: markAsRoot
* fix: print tabs in sub-ternaries
* docs(commands): update
* test: add a cool test case