blob: f1f4895d792b71ad8da828c2c0da3ce9aac6cc5d [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];
Johan Bayebb70e32022-05-23 17:46:37 +020017const REL_TS_LIB_PATH = '/node_modules/typescript/lib/';
18const typescriptSources =
19 fs.readdirSync(process.argv[3] + REL_TS_LIB_PATH).map(name => process.argv[3] + REL_TS_LIB_PATH + name);
Johan Bay8d8c6842022-02-02 17:44:23 +000020
Johan Bayebb70e32022-05-23 17:46:37 +020021const program = ts.createProgram({rootNames: typescriptSources, options: {noResolve: true, types: []}});
Johan Bay49f681a2022-01-27 09:25:13 +000022
Joel Einbinder3f23eb22018-05-14 23:27:51 +000023for (const file of program.getSourceFiles()) {
24 ts.forEachChild(file, node => {
25 if (node.kind === ts.SyntaxKind.InterfaceDeclaration) {
26 for (const member of node.members) {
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000027 if (member.kind === ts.SyntaxKind.MethodSignature) {
Joel Einbinder3f23eb22018-05-14 23:27:51 +000028 parseTSFunction(member, node);
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000029 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000030 }
31 }
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000032 if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
Joel Einbinder3f23eb22018-05-14 23:27:51 +000033 parseTSFunction(node, {name: {text: 'Window'}});
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000034 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000035
36 });
37}
38
Mathias Bynensb1b64fc2021-10-08 14:10:49 +020039// Assume the DevTools front-end repository is at
40// `devtools/devtools-frontend`, where `devtools` is on the same level
41// as `chromium`. This matches `scripts/npm_test.js`.
Johan Bay49f681a2022-01-27 09:25:13 +000042const files =
Johan Bay8d8c6842022-02-02 17:44:23 +000043 glob.sync(`${chromiumSource}/third_party/blink/renderer/+(core|modules)/**/*.idl`, {cwd: process.env.PWD});
Joel Einbinder3f23eb22018-05-14 23:27:51 +000044
Johan Bay49f681a2022-01-27 09:25:13 +000045for (const file of files) {
46 if (file.includes('testing')) {
47 continue;
48 }
Simon Zünd41c62602022-04-26 10:15:38 +020049 const data = fs.readFileSync(file, 'utf8');
Johan Bay49f681a2022-01-27 09:25:13 +000050 const lines = data.split('\n');
51 const newLines = [];
52 for (const line of lines) {
53 if (!line.includes(' attribute ')) {
54 newLines.push(line);
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000055 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000056 }
Johan Bay49f681a2022-01-27 09:25:13 +000057
58 try {
59 WebIDL2.parse(newLines.join('\n')).forEach(walkRoot);
60 } catch (e) {
61 // console.error(file);
Joel Einbinder3f23eb22018-05-14 23:27:51 +000062 }
Johan Bay49f681a2022-01-27 09:25:13 +000063
64 // Source for Console spec: https://console.spec.whatwg.org/#idl-index
65 WebIDL2
66 .parse(`
67[Exposed=(Window,Worker,Worklet)]
68namespace console { // but see namespace object requirements below
69 // Logging
70 undefined assert(optional boolean condition = false, any... data);
71 undefined clear();
72 undefined debug(any... data);
73 undefined error(any... data);
74 undefined info(any... data);
75 undefined log(any... data);
76 undefined table(optional any tabularData, optional sequence<DOMString> properties);
77 undefined trace(any... data);
78 undefined warn(any... data);
79 undefined dir(optional any item, optional object? options);
80 undefined dirxml(any... data);
81
82 // Counting
83 undefined count(optional DOMString label = "default");
84 undefined countReset(optional DOMString label = "default");
85
86 // Grouping
87 undefined group(any... data);
88 undefined groupCollapsed(any... data);
89 undefined groupEnd();
90
91 // Timing
92 undefined time(optional DOMString label = "default");
93 undefined timeLog(optional DOMString label = "default", any... data);
94 undefined timeEnd(optional DOMString label = "default");
95};
96`).forEach(walkRoot);
Joel Einbinder3f23eb22018-05-14 23:27:51 +000097}
Johan Bay49f681a2022-01-27 09:25:13 +000098postProcess();