Tim van der Lippe | c2cb430 | 2020-03-11 17:22:14 +0000 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Johan Bay | 49f681a | 2022-01-27 09:25:13 +0000 | [diff] [blame] | 5 | import * as fs from 'fs'; |
| 6 | import glob from 'glob'; |
Johan Bay | 49f681a | 2022-01-27 09:25:13 +0000 | [diff] [blame] | 7 | import ts from 'typescript'; |
| 8 | import * as WebIDL2 from 'webidl2'; |
| 9 | |
| 10 | import {parseTSFunction, postProcess, walkRoot} from './helpers.js'; |
| 11 | |
Johan Bay | 8d8c684 | 2022-02-02 17:44:23 +0000 | [diff] [blame] | 12 | if (process.argv.length !== 4) { |
| 13 | throw new Error('Please provide path to chromium/src and devtools-frontend'); |
| 14 | } |
| 15 | |
| 16 | const chromiumSource = process.argv[2]; |
| 17 | const typescriptSource = process.argv[3] + 'node_modules/typescript/lib/lib.esnext.d.ts'; |
| 18 | |
| 19 | const program = ts.createProgram([typescriptSource], {noLib: false, types: []}); |
Johan Bay | 49f681a | 2022-01-27 09:25:13 +0000 | [diff] [blame] | 20 | |
Joel Einbinder | 3f23eb2 | 2018-05-14 23:27:51 +0000 | [diff] [blame] | 21 | for (const file of program.getSourceFiles()) { |
| 22 | ts.forEachChild(file, node => { |
| 23 | if (node.kind === ts.SyntaxKind.InterfaceDeclaration) { |
| 24 | for (const member of node.members) { |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 25 | if (member.kind === ts.SyntaxKind.MethodSignature) { |
Joel Einbinder | 3f23eb2 | 2018-05-14 23:27:51 +0000 | [diff] [blame] | 26 | parseTSFunction(member, node); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 27 | } |
Joel Einbinder | 3f23eb2 | 2018-05-14 23:27:51 +0000 | [diff] [blame] | 28 | } |
| 29 | } |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 30 | if (node.kind === ts.SyntaxKind.FunctionDeclaration) { |
Joel Einbinder | 3f23eb2 | 2018-05-14 23:27:51 +0000 | [diff] [blame] | 31 | parseTSFunction(node, {name: {text: 'Window'}}); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 32 | } |
Joel Einbinder | 3f23eb2 | 2018-05-14 23:27:51 +0000 | [diff] [blame] | 33 | |
| 34 | }); |
| 35 | } |
| 36 | |
Mathias Bynens | b1b64fc | 2021-10-08 14:10:49 +0200 | [diff] [blame] | 37 | // Assume the DevTools front-end repository is at |
| 38 | // `devtools/devtools-frontend`, where `devtools` is on the same level |
| 39 | // as `chromium`. This matches `scripts/npm_test.js`. |
Johan Bay | 49f681a | 2022-01-27 09:25:13 +0000 | [diff] [blame] | 40 | const files = |
Johan Bay | 8d8c684 | 2022-02-02 17:44:23 +0000 | [diff] [blame] | 41 | glob.sync(`${chromiumSource}/third_party/blink/renderer/+(core|modules)/**/*.idl`, {cwd: process.env.PWD}); |
Joel Einbinder | 3f23eb2 | 2018-05-14 23:27:51 +0000 | [diff] [blame] | 42 | |
Johan Bay | 49f681a | 2022-01-27 09:25:13 +0000 | [diff] [blame] | 43 | for (const file of files) { |
| 44 | if (file.includes('testing')) { |
| 45 | continue; |
| 46 | } |
Simon Zünd | 41c6260 | 2022-04-26 10:15:38 +0200 | [diff] [blame] | 47 | const data = fs.readFileSync(file, 'utf8'); |
Johan Bay | 49f681a | 2022-01-27 09:25:13 +0000 | [diff] [blame] | 48 | const lines = data.split('\n'); |
| 49 | const newLines = []; |
| 50 | for (const line of lines) { |
| 51 | if (!line.includes(' attribute ')) { |
| 52 | newLines.push(line); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 53 | } |
Joel Einbinder | 3f23eb2 | 2018-05-14 23:27:51 +0000 | [diff] [blame] | 54 | } |
Johan Bay | 49f681a | 2022-01-27 09:25:13 +0000 | [diff] [blame] | 55 | |
| 56 | try { |
| 57 | WebIDL2.parse(newLines.join('\n')).forEach(walkRoot); |
| 58 | } catch (e) { |
| 59 | // console.error(file); |
Joel Einbinder | 3f23eb2 | 2018-05-14 23:27:51 +0000 | [diff] [blame] | 60 | } |
Johan Bay | 49f681a | 2022-01-27 09:25:13 +0000 | [diff] [blame] | 61 | |
| 62 | // Source for Console spec: https://console.spec.whatwg.org/#idl-index |
| 63 | WebIDL2 |
| 64 | .parse(` |
| 65 | [Exposed=(Window,Worker,Worklet)] |
| 66 | namespace console { // but see namespace object requirements below |
| 67 | // Logging |
| 68 | undefined assert(optional boolean condition = false, any... data); |
| 69 | undefined clear(); |
| 70 | undefined debug(any... data); |
| 71 | undefined error(any... data); |
| 72 | undefined info(any... data); |
| 73 | undefined log(any... data); |
| 74 | undefined table(optional any tabularData, optional sequence<DOMString> properties); |
| 75 | undefined trace(any... data); |
| 76 | undefined warn(any... data); |
| 77 | undefined dir(optional any item, optional object? options); |
| 78 | undefined dirxml(any... data); |
| 79 | |
| 80 | // Counting |
| 81 | undefined count(optional DOMString label = "default"); |
| 82 | undefined countReset(optional DOMString label = "default"); |
| 83 | |
| 84 | // Grouping |
| 85 | undefined group(any... data); |
| 86 | undefined groupCollapsed(any... data); |
| 87 | undefined groupEnd(); |
| 88 | |
| 89 | // Timing |
| 90 | undefined time(optional DOMString label = "default"); |
| 91 | undefined timeLog(optional DOMString label = "default", any... data); |
| 92 | undefined timeEnd(optional DOMString label = "default"); |
| 93 | }; |
| 94 | `).forEach(walkRoot); |
Joel Einbinder | 3f23eb2 | 2018-05-14 23:27:51 +0000 | [diff] [blame] | 95 | } |
Johan Bay | 49f681a | 2022-01-27 09:25:13 +0000 | [diff] [blame] | 96 | postProcess(); |