blob: 26dc00e1dadd3abd2cdaede6a036aa9b1e505f4a [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
Tim van der Lippee6a98682020-01-15 14:23:08 +000013const program = ts.createProgram(
14 [
Johan Bay49f681a2022-01-27 09:25:13 +000015 new URL('node_modules/typescript/lib/lib.esnext.d.ts', import.meta.url).pathname,
Tim van der Lippee6a98682020-01-15 14:23:08 +000016 ],
Johan Bay49f681a2022-01-27 09:25:13 +000017 {noLib: false, types: []});
18
Joel Einbinder3f23eb22018-05-14 23:27:51 +000019for (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 Lippeba26b2b2020-03-11 14:40:00 +000023 if (member.kind === ts.SyntaxKind.MethodSignature) {
Joel Einbinder3f23eb22018-05-14 23:27:51 +000024 parseTSFunction(member, node);
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000025 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000026 }
27 }
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000028 if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
Joel Einbinder3f23eb22018-05-14 23:27:51 +000029 parseTSFunction(node, {name: {text: 'Window'}});
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000030 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000031
32 });
33}
34
Mathias Bynensb1b64fc2021-10-08 14:10:49 +020035// 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 Bay49f681a2022-01-27 09:25:13 +000038const files =
39 glob.sync('../../../../chromium/src/third_party/blink/renderer/+(core|modules)/**/*.idl', {cwd: process.env.PWD});
Joel Einbinder3f23eb22018-05-14 23:27:51 +000040
Johan Bay49f681a2022-01-27 09:25:13 +000041for (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 Lippeba26b2b2020-03-11 14:40:00 +000051 }
Joel Einbinder3f23eb22018-05-14 23:27:51 +000052 }
Johan Bay49f681a2022-01-27 09:25:13 +000053
54 try {
55 WebIDL2.parse(newLines.join('\n')).forEach(walkRoot);
56 } catch (e) {
57 // console.error(file);
Joel Einbinder3f23eb22018-05-14 23:27:51 +000058 }
Johan Bay49f681a2022-01-27 09:25:13 +000059
60 // Source for Console spec: https://console.spec.whatwg.org/#idl-index
61 WebIDL2
62 .parse(`
63[Exposed=(Window,Worker,Worklet)]
64namespace 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 Einbinder3f23eb22018-05-14 23:27:51 +000093}
Johan Bay49f681a2022-01-27 09:25:13 +000094postProcess();