blob: f3798e683ed7b76dd828e9e5031e972be410a839 [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
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 }
Simon Zünd41c62602022-04-26 10:15:38 +020048 const data = fs.readFileSync(file, 'utf8');
Johan Bay49f681a2022-01-27 09:25:13 +000049 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();