diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a58e4343..df3532e6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -38,7 +38,6 @@ updates: - 'eslint' - 'eslint-*' - 'lint-staged' - - 'globals' - '@eslint/*' unist: patterns: diff --git a/package-lock.json b/package-lock.json index cde2fa1c..e2784e9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,6 +23,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", diff --git a/package.json b/package.json index 7a06f4d1..033ebfe2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/utils/parser/__tests__/index.test.mjs b/src/utils/parser/__tests__/index.test.mjs index 944d3de6..e51c0309 100644 --- a/src/utils/parser/__tests__/index.test.mjs +++ b/src/utils/parser/__tests__/index.test.mjs @@ -12,7 +12,7 @@ describe('transformTypeToReferenceLink', () => { it('should transform a JavaScript primitive type into a Markdown link', () => { strictEqual( transformTypeToReferenceLink('string'), - '[``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)' + '[``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type)' ); }); diff --git a/src/utils/parser/constants.mjs b/src/utils/parser/constants.mjs index 46ad3628..9b3c9021 100644 --- a/src/utils/parser/constants.mjs +++ b/src/utils/parser/constants.mjs @@ -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 = [ @@ -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 @@ -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', }; @@ -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`,