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