Skip to content

fix(globals): use globals for globals #397

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ updates:
- 'eslint'
- 'eslint-*'
- 'lint-staged'
- 'globals'
- '@eslint/*'
unist:
patterns:
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"eslint": "^9.31.0",
"eslint-plugin-import-x": "^4.16.1",
"eslint-plugin-jsdoc": "^51.4.1",
"globals": "^16.3.0",
"husky": "^9.1.7",
"lint-staged": "^16.1.2",
"prettier": "3.6.2"
Expand All @@ -55,6 +54,7 @@
"estree-util-visit": "^2.0.0",
"github-slugger": "^2.0.0",
"glob": "^11.0.3",
"globals": "^16.3.0",
"hast-util-to-string": "^3.0.1",
"hastscript": "^9.0.1",
"lightningcss": "^1.30.1",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/parser/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('transformTypeToReferenceLink', () => {
it('should transform a JavaScript primitive type into a Markdown link', () => {
strictEqual(
transformTypeToReferenceLink('string'),
'[`<string>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)'
'[`<string>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type)'
);
});

Expand Down
72 changes: 18 additions & 54 deletions src/utils/parser/constants.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
import globals from 'globals';

// These are string replacements specific to Node.js API docs for anchor IDs
export const DOC_API_SLUGS_REPLACEMENTS = [
Expand Down Expand Up @@ -71,62 +71,32 @@ export const DOC_API_HEADING_TYPES = [

// This is a mapping for types within the Markdown content and their respective
// JavaScript primitive types within the MDN JavaScript docs
// @see DOC_MDN_BASE_URL_JS_PRIMITIVES
export const DOC_TYPES_MAPPING_PRIMITIVES = {
boolean: 'Boolean',
integer: 'Number', // Not a primitive, used for clarification.
null: 'Null',
number: 'Number',
string: 'String',
symbol: 'Symbol',
undefined: 'Undefined',
};
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Data_structures#primitive_values
export const DOC_TYPES_MAPPING_PRIMITIVES = [
'null',
'undefined',
'boolean',
'number',
'bigint',
'string',
'symbol',
];

// This is a mapping for types within the Markdown content and their respective
// JavaScript globals types within the MDN JavaScript docs
// @see DOC_MDN_BASE_URL_JS_GLOBALS
export const DOC_TYPES_MAPPING_GLOBALS = {
...Object.fromEntries(
[
'AggregateError',
'Array',
'ArrayBuffer',
'DataView',
'Date',
'Error',
'EvalError',
'Function',
'Map',
'NaN',
'Object',
'Promise',
'Proxy',
'RangeError',
'ReferenceError',
'RegExp',
'Set',
'SharedArrayBuffer',
'SyntaxError',
'Symbol',
'TypeError',
'URIError',
'WeakMap',
'WeakSet',

'TypedArray',
'Float16Array',
'Float32Array',
'Float64Array',
'Int8Array',
'Int16Array',
'Int32Array',
'Uint8Array',
'Uint8ClampedArray',
'Uint16Array',
'Uint32Array',
// This is updated with every ES-spec, so, as long as the
// `globals` package is up-to-date, so will our globals
// list.
...Object.keys(globals.builtin),
'AsyncGeneratorFunction',
'AsyncIterator',
'AsyncFunction',
].map(e => [e, e])
),
bigint: 'BigInt',
'WebAssembly.Instance': 'WebAssembly/Instance',
};

Expand Down Expand Up @@ -331,18 +301,12 @@ export const DOC_TYPES_MAPPING_OTHER = {

ArrayBufferView: `${DOC_MDN_BASE_URL}/API/ArrayBufferView`,

AsyncIterator: 'https://tc39.github.io/ecma262/#sec-asynciterator-interface',
AsyncIterable: 'https://tc39.github.io/ecma262/#sec-asynciterable-interface',
AsyncFunction: 'https://tc39.es/ecma262/#sec-async-function-constructor',

'Module Namespace Object':
'https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects',

AsyncGeneratorFunction:
'https://tc39.es/proposal-async-iteration/#sec-asyncgeneratorfunction-constructor',

Iterable: `${DOC_MDN_BASE_URL_JS}Reference/Iteration_protocols#The_iterable_protocol`,
Iterator: `${DOC_MDN_BASE_URL_JS}Reference/Iteration_protocols#The_iterator_protocol`,

CloseEvent: `${DOC_MDN_BASE_URL}/API/CloseEvent`,
EventSource: `${DOC_MDN_BASE_URL}/API/EventSource`,
Expand Down
6 changes: 2 additions & 4 deletions src/utils/parser/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ export const transformTypeToReferenceLink = type => {
*/
const transformType = lookupPiece => {
// Transform JS primitive type references into Markdown links (MDN)
if (lookupPiece.toLowerCase() in DOC_TYPES_MAPPING_PRIMITIVES) {
const typeValue = DOC_TYPES_MAPPING_PRIMITIVES[lookupPiece.toLowerCase()];

return `${DOC_MDN_BASE_URL_JS_PRIMITIVES}#${typeValue}_type`;
if (DOC_TYPES_MAPPING_PRIMITIVES.includes(lookupPiece.toLowerCase())) {
return `${DOC_MDN_BASE_URL_JS_PRIMITIVES}#${lookupPiece.toLowerCase()}_type`;
Copy link
Preview

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes the mapping logic that was previously handled by DOC_TYPES_MAPPING_PRIMITIVES. For example, 'integer' was mapped to 'Number', but now 'integer' will be used directly, potentially creating invalid MDN URLs.

Suggested change
return `${DOC_MDN_BASE_URL_JS_PRIMITIVES}#${lookupPiece.toLowerCase()}_type`;
const canonical = DOC_TYPES_MAPPING_PRIMITIVES[lookupPiece.toLowerCase()];
return `${DOC_MDN_BASE_URL_JS_PRIMITIVES}#${canonical.toLowerCase()}_type`;

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was updated to match the list at mdn (which was needed, since, bigint is a primitive, which was previously defined as a global.

See nodejs/node#59421

}

// Transforms JS Global type references into Markdown links (MDN)
Expand Down
Loading