Skip to content

Commit c48a231

Browse files
authored
fix: event declaration additional tags (#253)
* fix: event declaration additional tags. * add a test for create a tag-only comment.
1 parent 2e8d5f7 commit c48a231

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/module-declaration.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ export const generateModuleDeclaration = (
180180
listener = `(${args.join(`,\n${indent}`)}) => void`;
181181
}
182182

183-
for (let method of ['on', 'off', 'once', 'addListener', 'removeListener']) {
183+
const methods = ['on', 'off', 'once', 'addListener', 'removeListener'];
184+
for (const method of methods) {
185+
if (methods.indexOf(method) > 0) {
186+
utils.extendArray(moduleAPI, utils.wrapComment('', moduleEvent.additionalTags));
187+
}
184188
moduleAPI.push(`${method}(event: '${moduleEvent.name}', listener: ${listener}): this;`);
185189
}
186190
});
@@ -220,7 +224,11 @@ export const generateModuleDeclaration = (
220224
);
221225
}
222226

223-
for (let method of ['addEventListener', 'removeEventListener']) {
227+
const methods = ['addEventListener', 'removeEventListener'];
228+
for (const method of methods) {
229+
if (methods.indexOf(method) > 0) {
230+
utils.extendArray(moduleAPI, utils.wrapComment('', domEvent.additionalTags));
231+
}
224232
moduleAPI.push(
225233
`${method}(event: '${domEvent.name}', listener: (event: ${eventType}) => void${
226234
method === 'addEventListener' ? ', useCapture?: boolean' : ''

test/utils_spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const expect = require('chai').expect;
22
const utils = require('../dist/utils');
3+
const { DocumentationTag } = require('@electron/docs-parser');
34

45
describe('utils', () => {
56
describe('extendArray', () => {
@@ -56,6 +57,14 @@ describe('utils', () => {
5657
);
5758
expect(wrapped.length).equal(4);
5859
});
60+
61+
it('should create a tag-only comment', () => {
62+
const wrapped = utils.wrapComment('', [DocumentationTag.STABILITY_DEPRECATED]);
63+
expect(wrapped.length).equal(3);
64+
expect(wrapped[0]).to.be.equal('/**');
65+
expect(wrapped[1].endsWith('@deprecated')).to.eq(true);
66+
expect(wrapped[wrapped.length - 1]).to.be.equal(' */');
67+
});
5968
});
6069

6170
describe('typify', () => {

0 commit comments

Comments
 (0)