Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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]);
if (Array.isArray(section[property])) {
let toPush = section[property];

if (section.source) {
toPush = toPush.map(item => ({ ...item, source: section.source }));
}

generatedValue[property].push(...toPush);
Comment thread
ovflowd marked this conversation as resolved.
Outdated
}
});
});
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
69 changes: 53 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,72 @@ 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,
Comment thread
avivkeller marked this conversation as resolved.
}) => ({
changes,
added: enforceArray(added_in),
napiVersion: enforceArray(n_api_version),
deprecated: enforceArray(deprecated_in),
removed: enforceArray(removed_in),
});
}) => {
const meta = { changes };
Comment thread
avivkeller marked this conversation as resolved.

const aded_in_array = enforceArray(added_in);

if (aded_in_array.length) {
meta.added = aded_in_array;
}

const n_api_version_array = enforceArray(n_api_version);
Comment thread
ovflowd marked this conversation as resolved.
Outdated

if (n_api_version_array.length) {
meta.napiVersion = n_api_version_array;
}

const deprecated_in_array = enforceArray(deprecated_in);

if (deprecated_in_array.length) {
meta.deprecated = deprecated_in_array;
}

const removed_in_array = enforceArray(removed_in);

if (removed_in_array.length) {
meta.removed = removed_in_array;
}

// Check if there are any non-empty fields in the meta object
const atLeastOneNonEmptyField = Object.values(meta).some(
value => value.length > 0
);
Comment thread
ovflowd marked this conversation as resolved.
Outdated

// Return undefined if the meta object is completely empty
return atLeastOneNonEmptyField ? meta : undefined;
Comment thread
ovflowd marked this conversation as resolved.
};

/**
* 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;
};
Comment thread
ovflowd marked this conversation as resolved.

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

if (stabilityInfo) {
section.stability = stabilityInfo.index;
section.stability = Number(stabilityInfo.index);
Comment thread
ovflowd marked this conversation as resolved.
Comment thread
avivkeller marked this conversation as resolved.
section.stabilityText = stabilityInfo.description;
nodes.shift(); // Remove stability node from processing
}
Expand Down
Loading