Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement .d.ts generation from jsdoc comments #662

Merged
merged 19 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5411469
add barebones typescript config
jannikac Apr 12, 2024
e39ce1d
updated component to work correctly with generated d.ts
jannikac Apr 12, 2024
8b44b4c
replace typescript with @rollup/plugin-typescript, integrate into bui…
jannikac Apr 12, 2024
e314785
Augment generated jsdoc to make modules more explicit
kewisch May 21, 2024
3059d26
JSDoc improvements for typescript
kewisch May 21, 2024
314f4cf
Use long name in jsdoc links
kewisch May 21, 2024
0c9ab59
move tsconfig to rollup typescript plugin config
jannikac May 23, 2024
dc14837
fix incorrect parameter name
jannikac May 23, 2024
1278610
improve jsdoc types to allow for generation of .d.ts files
jannikac May 23, 2024
0943854
improve ts generation for everything that uses @types and complex @pa…
jannikac May 23, 2024
917ba5e
move `@typedefs` to types.d.js to allow for importing and resolving v…
jannikac May 28, 2024
ce1d2d7
drop prefix for typdef'd types and hack plugin to allow links to work
jannikac May 28, 2024
fa3074b
changed bare import to import type syntax and added plugin to fix jsd…
jannikac May 29, 2024
2cb2c59
added `@ignore` to imports so they are not documented in the generate…
jannikac May 29, 2024
5a19e4c
removed last `ICAL.` reference for consistency
jannikac May 29, 2024
a184851
added `jsdoc-collect-types.cjs` plugin to collect classnames and type…
jannikac May 29, 2024
83ba72c
update plugin to handle `@properties` and move `parserState` typedef …
jannikac May 29, 2024
e94faad
added MPL headers, comments and newlines
jannikac Jun 7, 2024
bacc31f
updated plugins to work correctly by calling jsdoc twice, once to col…
jannikac Jun 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ docs/recur-tester.html
tools/vzic/
tools/tzdb/
tools/libical/
tools/jsdoc-symbols-temp.json
coverage/
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default [
"!test/**/*.{js,cjs}",
"!tools/scriptutils.js",
"!tools/ICALTester/**/*.js",
"!tools/jsdoc-ical.cjs",
"!eslint.config.js",
"!rollup.config.js",
"!karma.conf.cjs"
Expand Down
10 changes: 10 additions & 0 deletions jsdoc-prepare.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"source": {
"include": "lib/ical",
"includePattern": ".js$"
},
"plugins": ["tools/jsdoc-collect-types.cjs", "node_modules/jsdoc-tsimport-plugin/index.js"],
"opts": {
"destination": "docs/api/"
}
}
2 changes: 1 addition & 1 deletion jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"include": "lib/ical",
"includePattern": ".js$"
},
"plugins": ["plugins/markdown"],
"plugins": ["plugins/markdown", "tools/jsdoc-ical.cjs", "node_modules/jsdoc-tsimport-plugin/index.js"],
"opts": {
"encoding": "utf8",
"readme": "README.md",
Expand Down
5 changes: 2 additions & 3 deletions lib/ical/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
/**
* Represents the BINARY value type, which contains extra methods for encoding and decoding.
*
* @class
* @alias ICAL.Binary
* @memberof ICAL
*/
class Binary {
/**
* Creates a binary value from the given string.
*
* @param {String} aString The binary value string
* @return {ICAL.Binary} The binary value instance
* @return {Binary} The binary value instance
*/
static fromString(aString) {
return new Binary(aString);
Expand Down
60 changes: 43 additions & 17 deletions lib/ical/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const COMPONENT_INDEX = 2;
* Wraps a jCal component, adding convenience methods to add, remove and update subcomponents and
* properties.
*
* @class
* @alias ICAL.Component
* @memberof ICAL
*/
class Component {
/**
Expand All @@ -31,11 +30,11 @@ class Component {
}

/**
* Creates a new ICAL.Component instance.
* Creates a new Component instance.
*
* @param {Array|String} jCal Raw jCal component data OR name of new
* component
* @param {ICAL.Component} parent Parent component to associate
* @param {Component=} parent Parent component to associate
*/
constructor(jCal, parent) {
if (typeof(jCal) === 'string') {
Expand Down Expand Up @@ -82,8 +81,20 @@ class Component {
*/
_timezoneCache = null;

/**
* @private
*/
_components = null;

/**
* @private
*/
_properties = null;

/**
* The name of this component
*
* @type {String}
* @readonly
*/
get name() {
Expand All @@ -101,6 +112,9 @@ class Component {
return parentDesign || design.getDesignSet(this.name);
}

/**
* @private
*/
_hydrateComponent(index) {
if (!this._components) {
this._components = [];
Expand All @@ -120,6 +134,9 @@ class Component {
return (this._components[index] = comp);
}

/**
* @private
*/
_hydrateProperty(index) {
if (!this._properties) {
this._properties = [];
Expand All @@ -143,7 +160,7 @@ class Component {
* Finds first sub component, optionally filtered by name.
*
* @param {String=} name Optional name to filter by
* @return {?ICAL.Component} The found subcomponent
* @return {?Component} The found subcomponent
*/
getFirstSubcomponent(name) {
if (name) {
Expand Down Expand Up @@ -171,7 +188,7 @@ class Component {
* Finds all sub components, optionally filtering by name.
*
* @param {String=} name Optional name to filter by
* @return {ICAL.Component[]} The found sub components
* @return {Component[]} The found sub components
*/
getAllSubcomponents(name) {
let jCalLen = this.jCal[COMPONENT_INDEX].length;
Expand Down Expand Up @@ -226,7 +243,7 @@ class Component {
* Finds the first property, optionally with the given name.
*
* @param {String=} name Lowercase property name
* @return {?ICAL.Property} The found property
* @return {?Property} The found property
*/
getFirstProperty(name) {
if (name) {
Expand Down Expand Up @@ -268,7 +285,7 @@ class Component {
* Get all properties in the component, optionally filtered by name.
*
* @param {String=} name Lowercase property name
* @return {ICAL.Property[]} List of properties
* @return {Property[]} List of properties
*/
getAllProperties(name) {
let jCalLen = this.jCal[PROPERTY_INDEX].length;
Expand Down Expand Up @@ -298,6 +315,9 @@ class Component {
}
}

/**
* @private
*/
_removeObjectByIndex(jCalIndex, cache, index) {
cache = cache || [];
// remove cached version
Expand All @@ -314,6 +334,9 @@ class Component {
this.jCal[jCalIndex].splice(index, 1);
}

/**
* @private
*/
_removeObject(jCalIndex, cache, nameOrObject) {
let i = 0;
let objects = this.jCal[jCalIndex];
Expand All @@ -339,6 +362,9 @@ class Component {
return false;
}

/**
* @private
*/
_removeAllObjects(jCalIndex, cache, name) {
let cached = this[cache];

Expand All @@ -359,8 +385,8 @@ class Component {
/**
* Adds a single sub component.
*
* @param {ICAL.Component} component The component to add
* @return {ICAL.Component} The passed in component
* @param {Component} component The component to add
* @return {Component} The passed in component
*/
addSubcomponent(component) {
if (!this._components) {
Expand All @@ -383,7 +409,7 @@ class Component {
* Removes a single component by name or the instance of a specific
* component.
*
* @param {ICAL.Component|String} nameOrComp Name of component, or component
* @param {Component|String} nameOrComp Name of component, or component
* @return {Boolean} True when comp is removed
*/
removeSubcomponent(nameOrComp) {
Expand All @@ -409,8 +435,8 @@ class Component {
/**
* Adds an {@link ICAL.Property} to the component.
*
* @param {ICAL.Property} property The property to add
* @return {ICAL.Property} The passed in property
* @param {Property} property The property to add
* @return {Property} The passed in property
*/
addProperty(property) {
if (!(property instanceof Property)) {
Expand Down Expand Up @@ -438,7 +464,7 @@ class Component {
*
* @param {String} name Property name to add
* @param {String|Number|Object} value Property value
* @return {ICAL.Property} The created property
* @return {Property} The created property
*/
addPropertyWithValue(name, value) {
let prop = new Property(name);
Expand All @@ -456,7 +482,7 @@ class Component {
*
* @param {String} name Property name to update
* @param {String|Number|Object} value Property value
* @return {ICAL.Property} The created property
* @return {Property} The created property
*/
updatePropertyWithValue(name, value) {
let prop = this.getFirstProperty(name);
Expand All @@ -474,7 +500,7 @@ class Component {
* Removes a single property by name or the instance of the specific
* property.
*
* @param {String|ICAL.Property} nameOrProp Property name or instance to remove
* @param {String|Property} nameOrProp Property name or instance to remove
* @return {Boolean} True, when deleted
*/
removeProperty(nameOrProp) {
Expand Down Expand Up @@ -523,7 +549,7 @@ class Component {
* matched, returns null.
*
* @param {String} tzid The ID of the time zone to retrieve
* @return {ICAL.Timezone} The time zone corresponding to the ID, or null
* @return {Timezone} The time zone corresponding to the ID, or null
*/
getTimeZoneByID(tzid) {
// VTIMEZONE components can only appear as a child of the VCALENDAR
Expand Down
9 changes: 4 additions & 5 deletions lib/ical/component_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import Timezone from "./timezone.js";
*
* parser.process(stringOrComponent);
*
* @class
* @alias ICAL.ComponentParser
* @memberof ICAL
*/
class ComponentParser {
/**
Expand Down Expand Up @@ -89,15 +88,15 @@ class ComponentParser {
* Fired when a top level component (VTIMEZONE) is found
*
* @callback
* @param {ICAL.Timezone} component Timezone object
* @param {Timezone} component Timezone object
*/
ontimezone = /* c8 ignore next */ function(component) {};

/**
* Fired when a top level component (VEVENT) is found.
*
* @callback
* @param {ICAL.Event} component Top level component
* @param {Event} component Top level component
*/
onevent = /* c8 ignore next */ function(component) {};

Expand All @@ -107,7 +106,7 @@ class ComponentParser {
*
* Events must be registered prior to calling this method.
*
* @param {ICAL.Component|String|Object} ical The component to process,
* @param {Component|String|Object} ical The component to process,
* either in its final form, as a jCal Object, or string representation
*/
process(ical) {
Expand Down
15 changes: 7 additions & 8 deletions lib/ical/duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ const DATA_PROPS_TO_COPY = ["weeks", "days", "hours", "minutes", "seconds", "isN
* This class represents the "duration" value type, with various calculation
* and manipulation methods.
*
* @class
* @alias ICAL.Duration
* @memberof ICAL
*/
class Duration {
/**
* Returns a new ICAL.Duration instance from the passed seconds value.
*
* @param {Number} aSeconds The seconds to create the instance from
* @return {ICAL.Duration} The newly created duration instance
* @return {Duration} The newly created duration instance
*/
static fromSeconds(aSeconds) {
return (new Duration()).fromSeconds(aSeconds);
Expand All @@ -41,7 +40,7 @@ class Duration {
* Creates a new {@link ICAL.Duration} instance from the passed string.
*
* @param {String} aStr The string to parse
* @return {ICAL.Duration} The created duration instance
* @return {Duration} The created duration instance
*/
static fromString(aStr) {
let pos = 0;
Expand Down Expand Up @@ -76,7 +75,7 @@ class Duration {
* @param {Number} aData.minutes Duration in minutes
* @param {Number} aData.seconds Duration in seconds
* @param {Boolean} aData.isNegative If true, the duration is negative
* @return {ICAL.Duration} The createad duration instance
* @return {Duration} The createad duration instance
*/
static fromData(aData) {
return new Duration(aData);
Expand Down Expand Up @@ -159,7 +158,7 @@ class Duration {
/**
* Returns a clone of the duration object.
*
* @return {ICAL.Duration} The cloned object
* @return {Duration} The cloned object
*/
clone() {
return Duration.fromData(this);
Expand All @@ -182,7 +181,7 @@ class Duration {
* accordingly.
*
* @param {Number} aSeconds The duration value in seconds
* @return {ICAL.Duration} Returns this instance
* @return {Duration} Returns this instance
*/
fromSeconds(aSeconds) {
let secs = Math.abs(aSeconds);
Expand Down Expand Up @@ -246,7 +245,7 @@ class Duration {
/**
* Compares the duration instance with another one.
*
* @param {ICAL.Duration} aOther The instance to compare with
* @param {Duration} aOther The instance to compare with
* @return {Number} -1, 0 or 1 for less/equal/greater
*/
compare(aOther) {
Expand Down
Loading