Skip to content

Commit 0ecb11e

Browse files
authored
fix(globals): use globals for globals (#397)
1 parent dc92c22 commit 0ecb11e

File tree

5 files changed

+24
-54
lines changed

5 files changed

+24
-54
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ updates:
3838
- 'eslint'
3939
- 'eslint-*'
4040
- 'lint-staged'
41-
- 'globals'
4241
- '@eslint/*'
4342
unist:
4443
patterns:

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"estree-util-visit": "^2.0.0",
5656
"github-slugger": "^2.0.0",
5757
"glob": "^11.0.3",
58+
"globals": "^16.3.0",
5859
"hast-util-to-string": "^3.0.1",
5960
"hastscript": "^9.0.1",
6061
"lightningcss": "^1.30.1",

src/utils/parser/__tests__/index.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('transformTypeToReferenceLink', () => {
1212
it('should transform a JavaScript primitive type into a Markdown link', () => {
1313
strictEqual(
1414
transformTypeToReferenceLink('string'),
15-
'[`<string>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)'
15+
'[`<string>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type)'
1616
);
1717
});
1818

src/utils/parser/constants.mjs

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
import globals from 'globals';
22

33
// These are string replacements specific to Node.js API docs for anchor IDs
44
export const DOC_API_SLUGS_REPLACEMENTS = [
@@ -71,15 +71,20 @@ export const DOC_API_HEADING_TYPES = [
7171

7272
// This is a mapping for types within the Markdown content and their respective
7373
// JavaScript primitive types within the MDN JavaScript docs
74-
// @see DOC_MDN_BASE_URL_JS_PRIMITIVES
74+
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Data_structures#primitive_values
7575
export const DOC_TYPES_MAPPING_PRIMITIVES = {
76-
boolean: 'Boolean',
77-
integer: 'Number', // Not a primitive, used for clarification.
78-
null: 'Null',
79-
number: 'Number',
80-
string: 'String',
81-
symbol: 'Symbol',
82-
undefined: 'Undefined',
76+
...Object.fromEntries(
77+
[
78+
'null',
79+
'undefined',
80+
'boolean',
81+
'number',
82+
'bigint',
83+
'string',
84+
'symbol',
85+
].map(e => [e, e])
86+
),
87+
integer: 'number',
8388
};
8489

8590
// This is a mapping for types within the Markdown content and their respective
@@ -88,45 +93,15 @@ export const DOC_TYPES_MAPPING_PRIMITIVES = {
8893
export const DOC_TYPES_MAPPING_GLOBALS = {
8994
...Object.fromEntries(
9095
[
91-
'AggregateError',
92-
'Array',
93-
'ArrayBuffer',
94-
'DataView',
95-
'Date',
96-
'Error',
97-
'EvalError',
98-
'Function',
99-
'Map',
100-
'NaN',
101-
'Object',
102-
'Promise',
103-
'Proxy',
104-
'RangeError',
105-
'ReferenceError',
106-
'RegExp',
107-
'Set',
108-
'SharedArrayBuffer',
109-
'SyntaxError',
110-
'Symbol',
111-
'TypeError',
112-
'URIError',
113-
'WeakMap',
114-
'WeakSet',
115-
116-
'TypedArray',
117-
'Float16Array',
118-
'Float32Array',
119-
'Float64Array',
120-
'Int8Array',
121-
'Int16Array',
122-
'Int32Array',
123-
'Uint8Array',
124-
'Uint8ClampedArray',
125-
'Uint16Array',
126-
'Uint32Array',
96+
// This is updated with every ES-spec, so, as long as the
97+
// `globals` package is up-to-date, so will our globals
98+
// list.
99+
...Object.keys(globals.builtin),
100+
'AsyncGeneratorFunction',
101+
'AsyncIterator',
102+
'AsyncFunction',
127103
].map(e => [e, e])
128104
),
129-
bigint: 'BigInt',
130105
'WebAssembly.Instance': 'WebAssembly/Instance',
131106
};
132107

@@ -331,18 +306,12 @@ export const DOC_TYPES_MAPPING_OTHER = {
331306

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

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

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

341-
AsyncGeneratorFunction:
342-
'https://tc39.es/proposal-async-iteration/#sec-asyncgeneratorfunction-constructor',
343-
344314
Iterable: `${DOC_MDN_BASE_URL_JS}Reference/Iteration_protocols#The_iterable_protocol`,
345-
Iterator: `${DOC_MDN_BASE_URL_JS}Reference/Iteration_protocols#The_iterator_protocol`,
346315

347316
CloseEvent: `${DOC_MDN_BASE_URL}/API/CloseEvent`,
348317
EventSource: `${DOC_MDN_BASE_URL}/API/EventSource`,

0 commit comments

Comments
 (0)