Commit Graph
5 Commits
Author SHA1 Message Date
Simon Zünd f69667700c Emit real TypeScript enums for inline declared protocol enum types
Commands, Events and Object types can declare "inline enums" to
restrict the possible values of a 'string' field.

Example field:

  referrerPolicy: ('unsafe-url'|'...'|'...')

To enable type-checking with TypeScript and stay compatible with
existing code, we now generate explicit enums. The naming scheme
for the enum names is adapted from code_generator_frontend.py
and needs to always match.

Example generated enum for the above code:

  export enum RequestReferrerPolicy {
    UnsafeUrl = 'unsafe-url',
    NoReferrerWhenDowngrade = 'no-referrer-when-downgrade',
    NoReferrer = 'no-referrer',
    Origin = 'origin',
    OriginWhenCrossOrigin = 'origin-when-cross-origin',
    SameOrigin = 'same-origin',
    StrictOrigin = 'strict-origin',
    StrictOriginWhenCrossOrigin = 'strict-origin-when-cross-origin',
  }

This is necessary as we didn't had any type for this enum before
but existing code was using

  Protocol.Network.RequestReferrerPolicy

as a type in JSDoc.

R=tvanderlippe@chromium.org

Bug: chromium:1011811
Change-Id: I4b4aa04b69fa4d7bf3b79ad97d61d4e3bfb7e228
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2113374
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
2020-03-23 15:47:21 +00:00
Simon Zünd c385b48e5d Emit TypeScript enums in protocol.d.ts for Protocol enums
Instead of

    export type MixedContentType = ('blockable'|'...'|'none');

we know emit

    export enum MixedContentType {
      Blockable = 'blockable',
      OptionallyBlockable = 'optionally-blockable',
      None = 'none',
    }

This is necessary as existing JavaScript code accesses these
enums using

   Protocol.Security.MixedContentType.None

R=tvanderlippe@chromium.org

Bug: chromium:1011811
Change-Id: Id4bf2c1333affcdc4df37a43bf95379700e3e9d0
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2113373
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
2020-03-23 15:17:31 +00:00
Tim van der Lippe c19ea32ca5 Fix protocol generator formats
- The protocol files were generated without license headers
- There were whitespace issues in the .d.ts files

Change-Id: I19572989360a4a537fdfe829f212587ae70e180f
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2107217
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Philip Pfaffe <pfaffe@chromium.org>
2020-03-17 12:34:08 +00:00
Tim van der Lippe 4a8441c385 Port license header check to ESLint
This improves the PRESUBMIT performance as we can rely on the AST
parsing of ESLint, meaning we don't have to parse AST twice.

It also allows us to use the nice `--fix` solution to insert the proper
license header in the files.

This shaves an expected 5 seconds of the presubmit time
(non-scientifically computed based on 2 uploads).

Change-Id: I5c53e9b232585f9ec46f86b36557c50bf80f7add
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2097992
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
2020-03-12 16:08:22 +00:00
Jack Franklin 8297869795 Generate protocol.d.ts files in devtools-frontend
We need this to be able to migrate parts of the frontend over to
TypeScript that use the Protocol.

We can generate this automatically via a script [1] from the
devtools-protocol repository on GitHub that we've pulled into our repo
and tweaked slightly.

The files are commited and can be easily re-generated should the PDL
files be updated.

DISABLE_THIRD_PARTY_CHECK=expected ts_library changes

[1]: https://github.com/ChromeDevTools/devtools-protocol/tree/master/scripts

Change-Id: I7115fdf109487a82edcaaf7f9984e8ec587d8b04
Bug: 1011811
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2096703
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
2020-03-12 15:18:42 +00:00