Skip to content

Commit 78f75b1

Browse files
update
Co-Authored-By: Claudio Wunder <[email protected]>
1 parent 70bd8ad commit 78f75b1

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/generators/jsx-ast/constants.mjs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ import { JSX_IMPORTS } from '../web/constants.mjs';
55
*
66
* @see https://nodejs.org/api/documentation.html#stability-index
77
*/
8+
9+
// Alert level constants — prefer importing from UI library if available
10+
// but not available for now
11+
export const ALERT_LEVELS = {
12+
DANGER: 'danger',
13+
WARNING: 'warning',
14+
INFO: 'info',
15+
SUCCESS: 'success',
16+
};
17+
818
export const STABILITY_LEVELS = [
9-
'danger', // (0) Deprecated
10-
'warning', // (1) Experimental
11-
'success', // (2) Stable
12-
'info', // (3) Legacy
19+
ALERT_LEVELS.DANGER, // (0) Deprecated
20+
ALERT_LEVELS.WARNING, // (1) Experimental
21+
ALERT_LEVELS.SUCCESS, // (2) Stable
22+
ALERT_LEVELS.INFO, // (3) Legacy
1323
];
1424

1525
// How deep should the Table of Contents go?
@@ -154,6 +164,6 @@ export const TYPES_WITH_METHOD_SIGNATURES = [
154164
// Patterns to map deprecation "Type" text to AlertBox levels.
155165
// Order matters: first match wins.
156166
export const DEPRECATION_TYPE_PATTERNS = [
157-
{ pattern: /^(Documentation|Compilation)/i, level: 'info' },
158-
{ pattern: /^(Runtime|Application)/i, level: 'warning' },
167+
{ pattern: /^(Documentation|Compilation)/i, level: ALERT_LEVELS.INFO },
168+
{ pattern: /^(Runtime|Application)/i, level: ALERT_LEVELS.WARNING },
159169
];

src/generators/jsx-ast/utils/buildContent.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
INTERNATIONALIZABLE,
1818
STABILITY_PREFIX_LENGTH,
1919
DEPRECATION_TYPE_PATTERNS,
20+
ALERT_LEVELS,
2021
TYPES_WITH_METHOD_SIGNATURES,
2122
TYPE_PREFIX_LENGTH,
2223
} from '../constants.mjs';
@@ -173,7 +174,7 @@ export const transformStabilityNode = (node, index, parent) => {
173174
const getLevelFromDeprecationType = typeText => {
174175
const match = DEPRECATION_TYPE_PATTERNS.find(p => p.pattern.test(typeText));
175176

176-
return match ? match.level : 'danger';
177+
return match ? match.level : ALERT_LEVELS.DANGER;
177178
};
178179

179180
/**
@@ -194,12 +195,11 @@ export const transformHeadingNode = (entry, remark, node, index, parent) => {
194195
if (entry.api === 'deprecations' && node.depth === 3) {
195196
// On the 'deprecations.md' page, "Type: <XYZ>" turns into an AlertBox
196197
// Extract the nodes representing the type text
197-
const sliced = slice(
198-
parent.children[index + 1],
199-
TYPE_PREFIX_LENGTH,
200-
undefined,
201-
{ textHandling: { boundaries: 'preserve' } }
202-
).node.children;
198+
const {
199+
node: { children: sliced },
200+
} = slice(parent.children[index + 1], TYPE_PREFIX_LENGTH, undefined, {
201+
textHandling: { boundaries: 'preserve' },
202+
});
203203

204204
parent.children[index + 1] = createJSXElement(JSX_IMPORTS.AlertBox.name, {
205205
children: sliced,

0 commit comments

Comments
 (0)