A TemplateLiteral consists of alternating TemplateElement and
non-TemplateElement nodes, with tokens in between:
<TemplateLiteral>
<tokens> -- formatted in #beforeVisit for TemplateElement
<TemplateElement> -- formatted in #afterVisit for TemplateElement
<tokens>
<TemplateElement>
<tokens> -- formatted in #beforeVisit for Expression
<Expression> -- formatted in #afterVisit for Expression
...
</Expression>
</TemplateLiteral>
We must not insert spaces while formatting within a TemplateLiteral
with the exception of the Expression. This happens within
the #afterVisit call to non-TemplateElement.
Fixed: 386857215
Change-Id: I0269747e825f64ecccb32c52f5a372b3d915e4ed
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6168856
Auto-Submit: Yang Guo <yangguo@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
1. In DevTools, go to Sources > Snippets > Create a snippet with the following code
const double = x => x * 2;
2. Click on {} to format code
Nothing should change during formatting as the code is currently the same as what’s expected
post formatting. In the example below, blank spaces surrounding an arrow function token ‘=>’
are removed.
Expected: const double = x => x * 2;
Result: const double = x=>x * 2;
Problem:
javascriptFormatter does not have a set spacing for arrow functions, In turn the formatter
defaults to no spaces / removes any current spacing surrounding arrow functions.
Fix:
Created a unique arrowIdentifier in our AcornTokenizer.js which identifies an arrow function
token. If True, it returns its proper spacing to our javascriptFormatter.
R=szuend@chromium.org
Fixed: 339172103
Change-Id: Ia3f5c08312344b84bf3d760b62fdd78e55e802aa
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5631360
Reviewed-by: Simon Zünd <szuend@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
The parser already produces a token stream, we don't need to tokenize
a second time (it also uses different options for some reason).
This greatly simplifies the logic in the AcornTokenzier, as we don't
need to sync a comment stream with a token stream. We can just dump
everything into a single array and iterate that.
The performance gains are negligable, but the code becomes much
simpler.
Drive-by: Remove tokenColumnStart as well, it was unused.
R=bmeurer@chromium.org
Bug: 333945853
Change-Id: Iea283c012765842c37e824740dd52ddab380bfed
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5465768
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Accessing 'type' of ESTree AST nodes is megamorphic. Doing this
repeatedly in an if-cascade in a hot loop is very costly.
This CL reduces the time it takes to parse and format two large
bundles (3.8MB and 11MB) from:
```
Formatting ./blitz.7dbe22a9.js (median): 1510.70 ms
Formatting ./workbench.web.main.js (median): 5784.81 ms
```
to
```
Formatting ./blitz.7dbe22a9.js (median): 1365.15 ms
Formatting ./workbench.web.main.js (median): 5023.51 ms
```
R=bmeurer@chromium.org
Bug: 333945853
Change-Id: If6b0ff55bc0f5ea2f1f1b7b1fc4523fbcd835952
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5463982
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Not every single ts_library invocation has (and should have) access
to the ESTree types. Therefore, re-export these types via Acorn,
which is the only user of these types.
This also improves the build performance, as we are no longer
rebuilding all of DevTools when these types change.
DISABLE_THIRD_PARTY_CHECK=Tsc cleanup
R=szuend@chromium.org
Bug: 1209844
Change-Id: Ib182ba4f7877d26eea844ac75180542ce2bac44a
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2900444
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>