Skip to content

Commit 29c1b7e

Browse files
committed
fix(globals): use \globals\ for globals
1 parent dc92c22 commit 29c1b7e

File tree

5 files changed

+21
-58
lines changed

5 files changed

+21
-58
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/constants.mjs

Lines changed: 18 additions & 54 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,62 +71,32 @@ 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
75-
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',
83-
};
74+
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Data_structures#primitive_values
75+
export const DOC_TYPES_MAPPING_PRIMITIVES = [
76+
'null',
77+
'undefined',
78+
'boolean',
79+
'number',
80+
'bigint',
81+
'string',
82+
'symbol',
83+
];
8484

8585
// This is a mapping for types within the Markdown content and their respective
8686
// JavaScript globals types within the MDN JavaScript docs
8787
// @see DOC_MDN_BASE_URL_JS_GLOBALS
8888
export const DOC_TYPES_MAPPING_GLOBALS = {
8989
...Object.fromEntries(
9090
[
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',
91+
// This is updated with every ES-spec, so, as long as the
92+
// `globals` package is up-to-date, so will our globals
93+
// list.
94+
...Object.keys(globals.builtin),
95+
'AsyncGeneratorFunction',
96+
'AsyncIterator',
97+
'AsyncFunction',
12798
].map(e => [e, e])
12899
),
129-
bigint: 'BigInt',
130100
'WebAssembly.Instance': 'WebAssembly/Instance',
131101
};
132102

@@ -331,18 +301,12 @@ export const DOC_TYPES_MAPPING_OTHER = {
331301

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

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

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

341-
AsyncGeneratorFunction:
342-
'https://tc39.es/proposal-async-iteration/#sec-asyncgeneratorfunction-constructor',
343-
344309
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`,
346310

347311
CloseEvent: `${DOC_MDN_BASE_URL}/API/CloseEvent`,
348312
EventSource: `${DOC_MDN_BASE_URL}/API/EventSource`,

src/utils/parser/index.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ export const transformTypeToReferenceLink = type => {
8282
const transformType = lookupPiece => {
8383
// Transform JS primitive type references into Markdown links (MDN)
8484
if (lookupPiece.toLowerCase() in DOC_TYPES_MAPPING_PRIMITIVES) {
85-
const typeValue = DOC_TYPES_MAPPING_PRIMITIVES[lookupPiece.toLowerCase()];
86-
87-
return `${DOC_MDN_BASE_URL_JS_PRIMITIVES}#${typeValue}_type`;
85+
return `${DOC_MDN_BASE_URL_JS_PRIMITIVES}#${lookupPiece.toLowerCase()}_type`;
8886
}
8987

9088
// Transforms JS Global type references into Markdown links (MDN)

0 commit comments

Comments
 (0)