blob: d8c60992b51f4f194007fd34a675ee10e0563452 [file] [log] [blame]
Victor Porof1a8a30d2022-06-13 13:07:10 +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
5// eslint-disable-next-line rulesdir/es_modules_import
6import idl from '@webref/idl';
7import * as fs from 'fs';
8import * as path from 'path';
9import * as url from 'url';
10
11import {SPECS} from './config.js';
12import {addMetadata, getIDLProps, minimize} from './get-props.js';
13import {getMissingTypes} from './util.js';
14
15if (process.argv.length !== 3) {
16 throw new Error('Please provide the path to devtools-frontend');
17}
18
19const files = await idl.listAll();
20const names = Object.keys(SPECS);
21const specs = await Promise.all(names.map(name => files[name].parse().then(idls => ({name, idls}))));
22
23const output = addMetadata(getIDLProps(specs));
24const missing = getMissingTypes(output);
25
26for (const type of missing) {
27 console.warn('Found missing type:', type);
28}
29
30const frontendPath = path.resolve(process.argv[2]);
31const jsMetadataPath = path.join(frontendPath, 'front_end/models/javascript_metadata/');
32const outPath = path.join(jsMetadataPath, 'DOMPinnedProperties.ts');
33const thisPath = path.relative(frontendPath, url.fileURLToPath(import.meta.url));
34
Victor Porof93f266f2022-06-15 11:59:55 +000035const stringify = object => JSON.stringify(object, null, 2);
36
Victor Porof1a8a30d2022-06-13 13:07:10 +000037fs.writeFileSync(outPath, `
38// Copyright 2022 The Chromium Authors. All rights reserved.
39// Use of this source code is governed by a BSD-style license that can be
40// found in the LICENSE file.
41// Generated from ${thisPath}
42
43/**
44 * All the specs used when generating the DOM pinned properties dataset.
45 */
Victor Porof93f266f2022-06-15 11:59:55 +000046export const SPECS = ${stringify(SPECS)};
Victor Porof1a8a30d2022-06-13 13:07:10 +000047
48export interface DOMPinnedWebIDLProp {
49 // A flag specifying whether it's a "global" attribute.
50 global?: boolean;
51 // A bitfield of the specs in which the property is found.
52 // If missing, it implies the default spec: "html".
53 specs?: number;
54}
55
56export interface DOMPinnedWebIDLType {
57 // An inherited Type.
58 inheritance?: string;
59 // A set of Types to also include properties from.
60 includes?: Array<string>;
61 // The properties defined on this Type.
62 props?: {
63 // A property name such as "checked".
64 [PropName: string]: DOMPinnedWebIDLProp,
65 };
66 // The "states" in which only certain properties are "applicable".
67 states?: {
68 // A CSS selector such as "[type=checkbox]".
69 [State: string]: {
70 [PropName: string]: DOMPinnedWebIDLProp,
71 },
72 };
73}
74
75export interface DOMPinnedPropertiesDataset {
76 [TypeName: string]: DOMPinnedWebIDLType;
77}
78
79/**
80 * The DOM pinned properties dataset. Generated from WebIDL data parsed from
81 * the SPECS above.
82 *
83 * This is an object with WebIDL type names as keys and their WebIDL properties
84 * and inheritance/include chains as values.
85 */
Victor Porof93f266f2022-06-15 11:59:55 +000086export const DOMPinnedProperties: DOMPinnedPropertiesDataset = ${stringify(minimize(output))};
87
Victor Porof1a8a30d2022-06-13 13:07:10 +000088`);