Commit Graph
18 Commits
Author SHA1 Message Date
Yang Guo 5e45944cc3 Fix pretty print for expressions within template literals
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>
2025-01-14 01:58:38 -08:00
Danil Somsikov 6806877859 Use type-only import where possible.
Not only this is shorter, it also allows having a side-effect import in addition to the type-only
import and is properly understood by lit-analyzer.

No-Presubmit: true
Bug: 370734442
Change-Id: I32f0a6198e8de8175201d8ce576a63a9ce25806f
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5921081
Commit-Queue: Danil Somsikov <dsv@chromium.org>
Reviewed-by: Paul Irish <paulirish@chromium.org>
Commit-Queue: Paul Irish <paulirish@chromium.org>
Auto-Submit: Danil Somsikov <dsv@chromium.org>
2024-10-11 20:29:33 +00:00
Will Hernandez a3575e7c5e Formatting code should not unnecessarily remove spacing
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>
2024-06-20 04:53:42 +00:00
Simon Zünd 2a9dd748cf [formatter] Simplify AcornTokenzier for JavaScript formatting
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>
2024-04-18 12:55:07 +00:00
Simon Zünd 10fa3cbf07 [formatter] Extract node.type into it's own variable in a hot function
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>
2024-04-18 10:41:51 +00:00
Benedikt Meurer 4164e91fa6 [pretty-print] Don't insert additional spaces within template literals.
Fixed: chromium:1477210
Change-Id: I085c7a742a69ad8623af02e6cf1554e722c739c2
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4987626
Commit-Queue: Simon Zünd <szuend@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
2023-10-30 09:53:58 +00:00
Benedikt Meurer b1e60b7241 Correctly pretty-print top-level await.
Fixed: chromium:1381031
Also-By: alexrudenko@chromium.org
Change-Id: I758ce3c13b80299fc5cdeffba0a6f25dd2633238
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3998781
Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
2022-11-03 09:16:30 +00:00
Jack Franklin 3a80260722 Inline type imports in front_end
This CL enables the `inline_type_imports` rule for devtools-frontend,
and is the result of running the auto-fixer to update all imports
accordingly.

Bug: 1319340
Change-Id: I303256476fd4e94f4505bbf4355c0070ac101aa9
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3752799
Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
2022-07-13 09:26:00 +00:00
Tim van der Lippe 12bcadba35 Migrate to private class members in entrypoints/
This also enables the ESLint rule for this folder

R=jacktfranklin@chromium.org

Bug: 1222126
Change-Id: I872ac654d4a37946aba75def17cc1f1aa8ad893c
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3341610
Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Auto-Submit: Tim Van der Lippe <tvanderlippe@chromium.org>
2021-12-16 10:31:28 +00:00
Tim van der Lippe e343bdfafb Migrate to private class fields in entrypoints/
R=szuend@chromium.org

Bug: 1222126
Change-Id: I6863d8180c6a44a0e607e860bbce89bf9d3642ca
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3338351
Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org>
Auto-Submit: Tim Van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
2021-12-15 11:49:27 +00:00
Jan Scheffler d5bf879558 [Underscore Migration] Migrate entrypoints
This patch is part of the underscore migration that adds the private
keyword to all properties that start with an underscore and removes the
underscore.

Bug:chromium:1207342
Change-Id: Iec114859ae3f46457bafa2d823e11add202c6eb2
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3077887
Commit-Queue: Jan Scheffler <janscheffler@chromium.org>
Auto-Submit: Jan Scheffler <janscheffler@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
2021-08-07 15:52:16 +00:00
Tim van der Lippe c2cbf32af8 Remove no-unused-vars suppressions
We don't use this rule any longer. Therefore, any supression of
the rule is considered a no-op. (We use the typescript-eslint
version instead).

R=jacktfranklin@chromium.org

Bug: none
Change-Id: I13595fffc980db423ee8ad5d133fd187d0dbdbbb
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3053746
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Paul Lewis <aerotwist@chromium.org>
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
2021-07-27 09:48:39 +00:00
Tim van der Lippe 877f04aa0e Remove eslint-disable statements from type imports
We no longer use the no-unused-vars and instead use the version
of typescript-eslint. The latter can properly detect unused
type-import usages. Therefore, we can remove the eslint-disable
statements, which are essentially noops.

This CL is the result of replacing

```
import type (.*) // eslint-disable-line no-unused-vars
```

with

```
import type $1
```

R=jacktfranklin@chromium.org

Bug: none
Change-Id: I141edcb7125e414c405760af1e4058bfdc6e30f3
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3048473
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
2021-07-26 12:53:27 +00:00
Tim van der Lippe 4965ccdd03 Update types packages
This includes the fixes for istanbul-reports and ESTree.
Some functional changes were required to make the type checker
happy again.

DISABLE_THIRD_PARTY_CHECK=Functional changes for types
R=jacktfranklin@chromium.org

Bug: none
Change-Id: I57964301d51b5e94cd6ca8a5453bdc51ca6d9758
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2933803
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
2021-06-02 16:36:54 +00:00
Tim van der Lippe 665f504502 Fix formatting for class definitions
The version of TypeScript we use now properly emits class field
definitions. Since this is an ES2022 feature, we need to bump
the version of Acorn to support parsing class field definitions.
Additionally, we need to update the formatter to handle the
spacing around the tokens in a class field definition.

We can revert the local patch to Acorn once
https://github.com/acornjs/acorn/pull/1041 is merged. I will
also work on updating the ESTree type definitions.

R=bmeurer@chromium.org

Bug: none
Change-Id: Id2232e6ce2d8a0a35002e87f181259bb60d26feb
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2930379
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
2021-06-02 12:11:54 +00:00
Tim van der Lippe c78a7193d7 Move ESTree types to acorn
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>
2021-05-18 05:24:23 +00:00
Jack Franklin a75ae7cbb3 Enforce import type when importing TS types.
Bug: none
Change-Id: I02ef1182143b7fe091ce92d59f04ac2188903e0d
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2886925
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Mathias Bynens <mathias@chromium.org>
2021-05-11 14:00:22 +00:00
Tim van der Lippe 7256e5e754 Move formatter_worker to entrypoints/formatter_worker
R=aerotwist@chromium.org

Bug: 1187573
Change-Id: I12afe682c2781651ff7cdc1650843010e2c8cbfd
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2826294
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
2021-04-15 10:30:32 +00:00