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