Commit Graph
21 Commits
Author SHA1 Message Date
Tim van der Lippe d7cfd14814 Fix no-implicit-coercion errors in front_end/
R=jacktfranklin@chromium.org

No-Presubmit: True
Bug: 1082789
Change-Id: Ic77884bf7e9b5dc74053915b3b10699368841b66
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2595268
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
2021-01-07 12:40:16 +00:00
Tim van der Lippe 9e8b150f70 Improve formatting of do-while loop
This makes sure we add a new line after the semi-colon of do-while
loops.

R=yangguo@chromium.org

Fixed: 983851
Change-Id: Ie5f6f2e3e3d780a0ba2bad493d505168c0814cb1
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2571461
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
2020-12-04 16:27:09 +00:00
Tim van der Lippe f2c5e8313e Add support for hashbang comments when formatting JavaScript
Acorn has a separate option to turn on compatibility for hashbang
comments. We need to turn on this flag for both our parser and
tokenizer.

Sadly, this wasn't enough to make the formatting work. What we discovered
is that comments can arrive out-of-order. In the case of hashbang
comments, we first receive the comment and then the token. However,
for all other comments, we first receive the token and then the comment.

To combat this reordering problem, we have to update our constructor
to only perform initializations when we don't have any comments at the start
(which is the situation for regular comments). Then when we do have
a hashbang comments, we bail out of shifting the comment away (and thus
would lose track of it) and let both `peekToken` and `nextToken` process
the comment.

R=bmeurer@chromium.org

Also-By: jacktfranklin@chromium.org
Fixed: 942422
Change-Id: Ic1971072b9c2d1e3ffeda7c3f9eede3b10f669fe
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2571126
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
2020-12-03 15:25:05 +00:00
Tim van der Lippe 2e38eeaf9f Remove all comments with only the unrestricted annotation
The unrestricted annotation is Closure-specific and can be removed.
This patch removes all comments with only the unrestricted annotation
in them.

R=szuend@chromium.org

No-Presubmit: True
Bug: 1011811
Change-Id: Iba0723644f53f5307c3077d341271af86becc32a
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2569758
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
2020-12-02 15:25:32 +00:00
Tim van der Lippe 769a734c24 Move acorn entrypoint to front_end/third_party/acorn
Instead of including the acorn entrypoint in `formatter_worker`,
we move it to the same directory as `acorn` lives in.

Note that we still bundle all extensions of acorn in the Acorn
bundle itself, as such we have to explicitly include only
`third_party/acorn/acorn.js` from the imports in Rollup.

R=aerotwist@chromium.org,bmeurer@chromium.org

Change-Id: Ic7b855fba38e05edd19b7c0fc352d81c00a32497
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2302600
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
2020-07-17 12:29:44 +00:00
Tim van der Lippe ec199476f4 Typecheck formatter_worker/JavascriptFormatter.js with TypeScript
R=bmeurer@chromium.org,jacktfranklin@chromium.org

Bug: 1011811, 1098730
Change-Id: Ia064fb231622e5aa567265d7a4900652968a46da
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2264127
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
2020-06-25 11:52:32 +00:00
Ng Zhi An 8d54f1a43a Use acorn-logical-assignment
Bug: chromium:1080569
Change-Id: Id65b11e9df68f1e04ec2b84b18b8684db3452f37
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2235965
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
2020-06-22 16:38:03 +00:00
Ng Zhi An 7c842d0b8b Add Acorn wrapper file and consolidate calls to Acorn
This will allow us to extend Acorn in one place and have all callers use
the extended parser/tokenizer.

Bug: chromium:1080569
Change-Id: Idf39bdd7160d1d05d94fd3e4324867239b228277
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2248868
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
2020-06-17 16:27:38 +00:00
Tim van der Lippe 25b938b8a3 Typecheck formatter_worker/AcornTokenizer.js with TypeScript
The `.mjs.d.ts` file has been upstreamed in
https://github.com/acornjs/acorn/pull/954 as per the instructions in
https://github.com/microsoft/TypeScript/issues/27957#issuecomment-623631119

R=jacktfranklin@chromium.org,bmeurer@chromium.org

Bug: 1011811
Change-Id: Ia2e0c3145318ac93b5e49d2b40780ffe7c469bab
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2218015
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
2020-05-29 15:40:23 +00:00
Tim van der Lippe 800891e5ad Use ESM build for acorn
This uses the `acorn.mjs` ESM build, rather than side-effect importing
it in `formatter_worker.js`. To make sure that Closure still understands
what is going on, we add `_types.mjs` files that describe the structure
for Closure.

To make sure that the unittests still work, Karma can now serve the `*.mjs`
files. The unittests have been updated to also no longer side-effect
importing acorn.

This CL requires https://chromium-review.googlesource.com/c/chromium/src/+/2212124
to land in Chromium first.

Bug: 1011811

Change-Id: I33c93b9cfb0c57b1970a98ecaa323481a4e0d1b1
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2212165
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
2020-05-27 16:07:17 +00:00
Benedikt Meurer 37c97e9aca [formatter_worker] Fix pretty printing of nullish coalescing.
This adds an `ECMA_VERSION` constant (and bumps it to 11), which is used
by both the parser and the tokenizer now.

Also use this constant consistently everywhere and not only for the
`JavaScriptFormatter`.

Fixed: chromium:1083797
Also-By: tvanderlippe@chromium.org
Change-Id: I6c7a4433322bfebd2f3d91915eb72bd2d7f2f1b9
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2208138
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
2020-05-20 15:30:33 +00:00
Tim van der Lippe ee97fa3e34 Add ts_library definitions and ts-nocheck for Karma tests
In https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2102717
we are updating the Karma configuration to use the Ninja output for
all unittests. This CL includes all existing unittests in relevant
ts_library definitions and adds the corresponding (previously missed)
dependencies as ts_library as well.

Since most of these dependencies are actually not compiling with
the TypeScript compiler (the original intent of the CL linked above),
we are adding the @ts-nocheck annotation for now. Of course, we should
remove these annotations as soon as possible, but that is a bit more
work, as the tests involved are primarily UI driven.

R=jacktfranklin@chromium.org

# Windows presubmit breaks with large CLs
No-Presubmit: true
Bug: 1061125
Change-Id: Ic67dbbc805642eaa618340a67ea0975eaacffc24
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2162850
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>
2020-04-23 16:33:00 +00:00
Simon Zünd d7f02588fc [formatter] Improve formatting for code containing await expressions
This CL adds basic formatting support for 'await' expressions. While
the result is not perfect, we no longer print the argument to the
AwaitExpression on a single line.

R=yangguo@chromium.org

Bug: chromium:1062617
Change-Id: Ic0e93b3ec6daec8fde53c8395c43ebc42bb19843
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2127006
Reviewed-by: Mathias Bynens <mathias@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
2020-03-31 07:43:14 +00:00
Mathias Bynens f06e8c0758 Enable no-else-return lint rule with autofix
This rule matches the Chromium-wide coding style.

Bug: chromium:1057042

Change-Id: I21ad946227ca7344146abace1d2f6146b3a6c207
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2078924
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
2020-02-28 14:17:07 +00:00
Tim van der Lippe d3c3b72021 Migrate formatter_worker/ to ESM internally
Bug: 1006759
Change-Id: I895bd53ff3f5381cc7e159f0813b426f34e8fef7
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1991638
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
2020-01-10 13:59:37 +00:00
Tim van der Lippe fd90361fad Rollup workers and migrate dependent modules
Since workers do not support modules [1], it is not possible to
currently import any ESM DevTools module. To be able to migrate
text_utils/ to ESM, we would need to duplicate a large portion of
text_utils/, which would be unmaintainable.

We already had the same situation when we migrated platform/ to ESM and
decided to copy the relevant functions, but this time around that is no
longer an option.

Thus, the 2 workers (heap_snapshot_worker and formatter_worker) are now
being bundled on build time. This means that in a release build, the
respective entrypoints are bundled and inserted in the output.

To bundle, we use `rollup`, which is a bundler only concerned with
rolling up ES modules. All other functionality of rollup (such as
tree-shaking) is unused. We can revisit later if we need a bundler for
the rest of devtools, but since we are in active migration to ESM that
is infeasible at this point in time.

As part of this CL, the following folders are migrated to ESM:
- cm_headless/
- formatter_worker/
- heap_snapshot_model/
- heap_snapshot_worker/
- text_utils/

Since text_utils is also an autostart module for the shell, this is the
only module that is imported from root.js.

Some of these modules also include files that are annotated with
skip_compilation and thus run with dummy files during Closure
compilation.

Note that, because of the usages of import-statements in the workers
and the blocking bug [1], the workers are generated even when Chromium
is built with `debug_devtools=true`.

Since heap_snapshot_model/ also used in the profiler, we have to eagerly
load this module in root.js. Once all other dependencies of the profiler
have been migrated to ESM, we can remove this import-statement.

[1]: crbug.com/680046

Bug:1013129,1006759
Change-Id: I4c03c7b8a1f351ae9693cbcd922412083dd34bba
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1883707
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
2019-11-07 11:55:25 +00:00
Sigurd Schneider ab8035da9c [devtools] Support import/export in JavaScript formatter
Our configuration did not allow import/export to appear in JavaScript
files. This CL changes that to always accept import/export, and adds
pretty printing support. This includes dynamic imports.

Bug: chromium:1021971
Change-Id: I447646224445190e6d5d6d1e96f161acc8dbacc6
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1901388
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Mathias Bynens <mathias@chromium.org>
2019-11-06 17:15:25 +00:00
Benedikt Meurer ddc863ad1a [devtools] Roll acorn and acorn-loose 7.1.0.
Remove the `ACORN_ECMA_VERSION` constant, and instead rely on the
official `ecmaVersion` default in acorn, which is now 10 (corresponding
to ES2019).

Bug: chromium:995036, chromium:1009927
Change-Id: Ie6b4c5e2839012f498c2c561c33d811b37749eee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1829713
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#701461}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: aab2a58e5ee211ce020df3a8b426b898a8df2d5c
2019-10-01 07:19:09 +00:00
Tim van der Lippe 1d6e57a0e3 Always add braces to single-line if-statements
The Chromium/Google style guides does not enforce curly braces for
single-line if-statements, but does strongly recommend doing so. Adding
braces will improve code readability, by visually separating code
blocks. This will also prevent issues where accidental additions are
pushed to the "else"-clause instead of in the if-block.

This CL also updates the presubmit `eslint` to run the fix with the
correct configuration. It will now fix all issues it can fix.

Change-Id: I4b616f21a99393f168dec743c0bcbdc7f5db04a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1821526
Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Jeff Fisher <jeffish@microsoft.com>
Cr-Original-Commit-Position: refs/heads/master@{#701070}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 7e0bdbe2d7f9fc2386bfaefda3cc29c66ccc18f9
2019-09-30 11:55:34 +00:00
Tim van der Lippe b0e9644ffa Update Acorn ecmaVersion to 2018 to support Object spread
Also define a constant and use the constant everywhere we interact with
Acorn, as we were using 3 different ecmaVersions.

Bug: 999794
Change-Id: I56043ebccdb7767180af2f4a6c337f1f58ff187b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1778617
Commit-Queue: Tim van der Lippe <tvanderlippe@google.com>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Erik Luo <luoe@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#693082}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: bfc38380057ba567763525d844d37f17539b903e
2019-09-04 09:46:32 +00:00
Blink Reformat 4c46d0969f The Great Blink mv for source files, part 2.
Move and rename files.

NOAUTOREVERT=true
NOPRESUBMIT=true
NOTREECHECKS=true
Bug: 768828
TBR=darin@chromium.org
NOTRY=true

Change-Id: I66d3b155808bc5bdbf237b80208e1e552bcf7f28
Reviewed-on: https://chromium-review.googlesource.com/1001153
Reviewed-by: Blink Reformat <blink-reformat@chromium.org>
Commit-Queue: Blink Reformat <blink-reformat@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#549061}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0aee4434a4dba42a42abaea9bfbc0cd196a63bc1
2018-04-07 15:32:37 +00:00