Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
56 changes: 28 additions & 28 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/generators/legacy-json-all/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ export default {
input.forEach(section => {
// Copy the relevant properties from each section into our output
propertiesToCopy.forEach(property => {
if (section[property]) {
generatedValue[property].push(...section[property]);
const items = section[property];

if (Array.isArray(items)) {
const enrichedItems = section.source
? items.map(item => ({ ...item, source: section.source }))
: items;

generatedValue[property].push(...enrichedItems);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/generators/legacy-json/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface SectionBase {
/**
* Stability index of the section.
*/
stability?: string;
stability?: number;

/**
* Descriptive text related to the stability of the section (E.G. "Experimental").
Expand Down
60 changes: 44 additions & 16 deletions src/generators/legacy-json/utils/buildSection.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,63 @@ export const createSectionBuilder = () => {
/**
* Creates metadata from a hierarchized entry.
* @param {import('../types.d.ts').HierarchizedEntry} entry - The entry to create metadata from.
* @returns {import('../types.d.ts').Meta} The created metadata.
* @returns {import('../types.d.ts').Meta | undefined} The created metadata, or undefined if all fields are empty.
*/
const createMeta = ({
added_in = [],
n_api_version = [],
deprecated_in = [],
removed_in = [],
changes,
}) => ({
changes,
added: enforceArray(added_in),
napiVersion: enforceArray(n_api_version),
deprecated: enforceArray(deprecated_in),
removed: enforceArray(removed_in),
});
}) => {
const meta = { changes };

if (added_in?.length) {
meta.added = enforceArray(added_in);
}

if (n_api_version?.length) {
meta.napiVersion = enforceArray(n_api_version);
}

if (deprecated_in?.length) {
meta.deprecated = enforceArray(deprecated_in);
}

if (removed_in?.length) {
meta.removed = enforceArray(removed_in);
}

// Check if there are any non-empty fields in the meta object
const atLeastOneNonEmptyField =
changes?.length || Object.keys(meta).length > 1;

// Return undefined if the meta object is completely empty
return atLeastOneNonEmptyField ? meta : undefined;
};

/**
* Creates a section from an entry and its heading.
* @param {import('../types.d.ts').HierarchizedEntry} entry - The AST entry.
* @param {HeadingMetadataParent} head - The head node of the entry.
* @returns {import('../types.d.ts').Section} The created section.
*/
const createSection = (entry, head) => ({
textRaw: transformNodesToString(head.children),
name: head.data.name,
type: head.data.type,
meta: createMeta(entry),
introduced_in: entry.introduced_in,
});
const createSection = (entry, head) => {
const section = {
textRaw: transformNodesToString(head.children),
name: head.data.name,
type: head.data.type,
introduced_in: entry.introduced_in,
};

const meta = createMeta(entry);

if (meta !== undefined) {
section.meta = meta;
}

return section;
};

/**
* Parses stability metadata and adds it to the section.
Expand All @@ -76,7 +104,7 @@ export const createSectionBuilder = () => {
const stabilityInfo = stability.children.map(node => node.data)?.[0];

if (stabilityInfo) {
section.stability = stabilityInfo.index;
section.stability = Number(stabilityInfo.index);
section.stabilityText = stabilityInfo.description;
nodes.shift(); // Remove stability node from processing
}
Expand Down
Loading