blob: 58221a663e1990a5f04f82010d9cecf2b8dd74b2 [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';
7import * as path from 'path';
8import ts from 'typescript';
9import * as WebIDL2 from 'webidl2';
10
11import {parseTSFunction, postProcess, walkRoot} from './helpers.js';
12
Johan Bay8d8c6842022-02-02 17:44:23 +000013if (process.argv.length !== 4) {
14 throw new Error('Please provide path to chromium/src and devtools-frontend');
15}
16
17const chromiumSource = process.argv[2];
18const typescriptSource = process.argv[3] + 'node_modules/typescript/lib/lib.esnext.d.ts';
19
20const program = ts.createProgram([typescriptSource], {noLib: false, types: []});
Johan Bay49f681a2022-01-27 09:25:13 +000021
Joel Einbinder3f23eb22018-05-14 23:27:51 +000022for (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 Lippeba26b2b2020-03-11 14:40:00 +000026 if (member.kind === ts.SyntaxKind.MethodSignature) {
Joel Einbinder3f23eb22018-05-14 23:27:51 +000027 parseTSFunction(member, node);
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000028 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000029 }
30 }
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000031 if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
Joel Einbinder3f23eb22018-05-14 23:27:51 +000032 parseTSFunction(node, {name: {text: 'Window'}});
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000033 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000034
35 });
36}
37
Mathias Bynensb1b64fc2021-10-08 14:10:49 +020038// 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 Bay49f681a2022-01-27 09:25:13 +000041const files =
Johan Bay8d8c6842022-02-02 17:44:23 +000042 glob.sync(`${chromiumSource}/third_party/blink/renderer/+(core|modules)/**/*.idl`, {cwd: process.env.PWD});
Joel Einbinder3f23eb22018-05-14 23:27:51 +000043
Johan Bay49f681a2022-01-27 09:25:13 +000044for (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 Lippeba26b2b2020-03-11 14:40:00 +000054 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000055 }
Johan Bay49f681a2022-01-27 09:25:13 +000056
57 try {
58 WebIDL2.parse(newLines.join('\n')).forEach(walkRoot);
59 } catch (e) {
60 // console.error(file);
Joel Einbinder3f23eb22018-05-14 23:27:51 +000061 }
Johan Bay49f681a2022-01-27 09:25:13 +000062
63 // Source for Console spec: https://console.spec.whatwg.org/#idl-index
64 WebIDL2
65 .parse(`
66[Exposed=(Window,Worker,Worklet)]
67namespace 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 Einbinder3f23eb22018-05-14 23:27:51 +000096}
Johan Bay49f681a2022-01-27 09:25:13 +000097postProcess();