Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 1 | // 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 |
| 6 | import idl from '@webref/idl'; |
| 7 | import * as fs from 'fs'; |
| 8 | import * as path from 'path'; |
| 9 | import * as url from 'url'; |
| 10 | |
| 11 | import {SPECS} from './config.js'; |
| 12 | import {addMetadata, getIDLProps, minimize} from './get-props.js'; |
| 13 | import {getMissingTypes} from './util.js'; |
| 14 | |
| 15 | if (process.argv.length !== 3) { |
| 16 | throw new Error('Please provide the path to devtools-frontend'); |
| 17 | } |
| 18 | |
| 19 | const files = await idl.listAll(); |
| 20 | const names = Object.keys(SPECS); |
| 21 | const specs = await Promise.all(names.map(name => files[name].parse().then(idls => ({name, idls})))); |
| 22 | |
| 23 | const output = addMetadata(getIDLProps(specs)); |
| 24 | const missing = getMissingTypes(output); |
| 25 | |
| 26 | for (const type of missing) { |
| 27 | console.warn('Found missing type:', type); |
| 28 | } |
| 29 | |
| 30 | const frontendPath = path.resolve(process.argv[2]); |
| 31 | const jsMetadataPath = path.join(frontendPath, 'front_end/models/javascript_metadata/'); |
| 32 | const outPath = path.join(jsMetadataPath, 'DOMPinnedProperties.ts'); |
| 33 | const thisPath = path.relative(frontendPath, url.fileURLToPath(import.meta.url)); |
| 34 | |
Victor Porof | 93f266f | 2022-06-15 11:59:55 +0000 | [diff] [blame^] | 35 | const stringify = object => JSON.stringify(object, null, 2); |
| 36 | |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 37 | fs.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 Porof | 93f266f | 2022-06-15 11:59:55 +0000 | [diff] [blame^] | 46 | export const SPECS = ${stringify(SPECS)}; |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 47 | |
| 48 | export 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 | |
| 56 | export 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 | |
| 75 | export 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 Porof | 93f266f | 2022-06-15 11:59:55 +0000 | [diff] [blame^] | 86 | export const DOMPinnedProperties: DOMPinnedPropertiesDataset = ${stringify(minimize(output))}; |
| 87 | |
Victor Porof | 1a8a30d | 2022-06-13 13:07:10 +0000 | [diff] [blame] | 88 | `); |