forked from googlemaps/extended-component-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-elements-manifest.config.js
34 lines (32 loc) · 1.05 KB
/
custom-elements-manifest.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* CEM plugin that adds React prop names to custom event declarations.
* @type {import('@custom-elements-manifest/analyzer').Plugin}
*/
const REACT_EVENT_NAMES_PLUGIN = {
name: 'cem-plugin-react-event-names',
moduleLinkPhase({moduleDoc}) {
// Match React prop name at the end of a custom event description.
const reactPropPattern = /\s\(React: ([a-zA-Z]+)\)$/;
moduleDoc?.declarations?.forEach((declaration) => {
declaration.events?.forEach((event) => {
const matches = event.description.match(reactPropPattern);
if (!matches?.[1]) {
console.error(
`Custom event '${event.name}' has no corresponding React prop. ` +
`Add one to the JSDoc of '${declaration.name}'.`);
process.exit(1);
}
event.description = event.description.replace(reactPropPattern, '');
event.reactName = matches[1];
});
});
}
};
export default {
plugins: [REACT_EVENT_NAMES_PLUGIN],
};