blob: bc75452692d0d28bc712eb49c4e2a9d89d932f81 [file] [log] [blame]
Tim van der Lippec2cb4302020-03-11 17:22:14 +00001// 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 Bay49f681a2022-01-27 09:25:13 +00005import * as fs from 'fs';
6import glob from 'glob';
Johan Bay49f681a2022-01-27 09:25:13 +00007import ts from 'typescript';
8import * as WebIDL2 from 'webidl2';
9
10import {parseTSFunction, postProcess, walkRoot} from './helpers.js';
11
Johan Bay8d8c6842022-02-02 17:44:23 +000012if (process.argv.length !== 4) {
13 throw new Error('Please provide path to chromium/src and devtools-frontend');
14}
15
16const chromiumSource = process.argv[2];
17const typescriptSource = process.argv[3] + 'node_modules/typescript/lib/lib.esnext.d.ts';
18
19const program = ts.createProgram([typescriptSource], {noLib: false, types: []});
Johan Bay49f681a2022-01-27 09:25:13 +000020
Joel Einbinder3f23eb22018-05-14 23:27:51 +000021for (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 Lippeba26b2b2020-03-11 14:40:00 +000025 if (member.kind === ts.SyntaxKind.MethodSignature) {
Joel Einbinder3f23eb22018-05-14 23:27:51 +000026 parseTSFunction(member, node);
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000027 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000028 }
29 }
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000030 if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
Joel Einbinder3f23eb22018-05-14 23:27:51 +000031 parseTSFunction(node, {name: {text: 'Window'}});
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000032 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000033
34 });
35}
36
Mathias Bynensb1b64fc2021-10-08 14:10:49 +020037// 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 Bay49f681a2022-01-27 09:25:13 +000040const files =
Johan Bay8d8c6842022-02-02 17:44:23 +000041 glob.sync(`${chromiumSource}/third_party/blink/renderer/+(core|modules)/**/*.idl`, {cwd: process.env.PWD});
Joel Einbinder3f23eb22018-05-14 23:27:51 +000042
Johan Bay49f681a2022-01-27 09:25:13 +000043for (const file of files) {
44 if (file.includes('testing')) {
45 continue;
46 }
Simon Zünd41c62602022-04-26 10:15:38 +020047 const data = fs.readFileSync(file, 'utf8');
Johan Bay49f681a2022-01-27 09:25:13 +000048 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 Lippeba26b2b2020-03-11 14:40:00 +000053 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000054 }
Johan Bay49f681a2022-01-27 09:25:13 +000055
56 try {
57 WebIDL2.parse(newLines.join('\n')).forEach(walkRoot);
58 } catch (e) {
59 // console.error(file);
Joel Einbinder3f23eb22018-05-14 23:27:51 +000060 }
Johan Bay49f681a2022-01-27 09:25:13 +000061
62 // Source for Console spec: https://console.spec.whatwg.org/#idl-index
63 WebIDL2
64 .parse(`
65[Exposed=(Window,Worker,Worklet)]
66namespace 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 Einbinder3f23eb22018-05-14 23:27:51 +000095}
Johan Bay49f681a2022-01-27 09:25:13 +000096postProcess();