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

Merged
merged 4 commits into from
Aug 15, 2025
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
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
1 change: 1 addition & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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
73 changes: 21 additions & 52 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,15 +71,20 @@ 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
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Data_structures#primitive_values
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',
...Object.fromEntries(
[
'null',
'undefined',
'boolean',
'number',
'bigint',
'string',
'symbol',
].map(e => [e, e])
),
integer: 'number',
};

// This is a mapping for types within the Markdown content and their respective
Expand All @@ -88,45 +93,15 @@ export const DOC_TYPES_MAPPING_PRIMITIVES = {
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 +306,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
Loading