blob: 6911d97ea3a3f0054db8c89a0c2e326898e7b303 [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));
Victor Porof1a8a30d2022-06-13 13:07:10 +000024
Victor Porof7e0446e2022-06-15 12:03:33 +000025const missing = getMissingTypes(output);
Victor Porof1a8a30d2022-06-13 13:07:10 +000026for (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;
Victor Porof7e0446e2022-06-15 12:03:33 +000054 // The "states" in which this property is "applicable".
55 rules?: Array<DOMPinnedWebIDLRule>;
Victor Porof1a8a30d2022-06-13 13:07:10 +000056}
57
58export interface DOMPinnedWebIDLType {
59 // An inherited Type.
60 inheritance?: string;
61 // A set of Types to also include properties from.
62 includes?: Array<string>;
63 // The properties defined on this Type.
64 props?: {
65 // A property name such as "checked".
66 [PropName: string]: DOMPinnedWebIDLProp,
67 };
68 // The "states" in which only certain properties are "applicable".
Victor Porof7e0446e2022-06-15 12:03:33 +000069 rules?: Array<DOMPinnedWebIDLRule>;
70}
71
72export interface DOMPinnedWebIDLRule {
73 when: string;
74 is: string;
Victor Porof1a8a30d2022-06-13 13:07:10 +000075}
76
77export interface DOMPinnedPropertiesDataset {
78 [TypeName: string]: DOMPinnedWebIDLType;
79}
80
81/**
82 * The DOM pinned properties dataset. Generated from WebIDL data parsed from
83 * the SPECS above.
84 *
85 * This is an object with WebIDL type names as keys and their WebIDL properties
86 * and inheritance/include chains as values.
87 */
Victor Porof93f266f2022-06-15 11:59:55 +000088export const DOMPinnedProperties: DOMPinnedPropertiesDataset = ${stringify(minimize(output))};
89
Victor Porof1a8a30d2022-06-13 13:07:10 +000090`);