remove useless globals

pull/7786/head
Yuichiro Yamashita 4 years ago
parent 3878915d1d
commit 29080a0704

@ -16,14 +16,17 @@ const SPECIALS = ['global', 'globalThis', 'InternalError', 'process', 'undefined
const get_url = (name) => `https://raw.githubusercontent.com/microsoft/TypeScript/main/lib/lib.${name}.d.ts`; const get_url = (name) => `https://raw.githubusercontent.com/microsoft/TypeScript/main/lib/lib.${name}.d.ts`;
const extract_name = (split) => split.match(/^[a-zA-Z0-9_$]+/)[0]; const extract_name = (split) => split.match(/^[a-zA-Z0-9_$]+/)[0];
const extract_functions_and_references = (data) => { const extract_functions_and_references = (name, data) => {
const functions = []; const functions = [];
const references = []; const references = [];
data.split('\n').forEach(line => { data.split('\n').forEach(line => {
const trimmed = line.trim(); const trimmed = line.trim();
const split = trimmed.replace(/[\s+]/, ' ').split(' '); const split = trimmed.replace(/[\s+]/, ' ').split(' ');
if (split[0] === 'declare') functions.push(extract_name(split[2])); if (split[0] === 'declare') {
else if (trimmed.startsWith('/// <reference')) { // MEMO: ignore `declare type xxx` statement in lib.es5.d.ts.
// Because all of these are TypeScript types. (not exists in runtime.)
if (name !== 'es5' || split[1] !== 'type') functions.push(extract_name(split[2]));
} else if (trimmed.startsWith('/// <reference')) {
const matched = trimmed.match(/ lib="(.+)"/); const matched = trimmed.match(/ lib="(.+)"/);
const reference = matched && matched[1]; const reference = matched && matched[1];
if (reference) references.push(reference); if (reference) references.push(reference);
@ -50,7 +53,7 @@ const get_functions = async (name) => {
if (fetched_names.has(name)) return res; if (fetched_names.has(name)) return res;
fetched_names.add(name); fetched_names.add(name);
const body = await do_get(get_url(name)); const body = await do_get(get_url(name));
const { functions, references } = extract_functions_and_references(body); const { functions, references } = extract_functions_and_references(name, body);
res.push(...functions); res.push(...functions);
const chile_functions = await Promise.all(references.map(get_functions)); const chile_functions = await Promise.all(references.map(get_functions));
chile_functions.forEach(i => res.push(...i)); chile_functions.forEach(i => res.push(...i));

@ -1,6 +1,6 @@
/** ---------------------------------------------------------------------- /** ----------------------------------------------------------------------
This file is automatically generated by `scripts/globals-extractor.mjs`. This file is automatically generated by `scripts/globals-extractor.mjs`.
Generated At: 2022-08-14T15:28:31.556Z Generated At: 2022-08-14T16:40:42.472Z
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
export default new Set([ export default new Set([
@ -75,7 +75,6 @@ export default new Set([
'ChannelMergerNode', 'ChannelMergerNode',
'ChannelSplitterNode', 'ChannelSplitterNode',
'CharacterData', 'CharacterData',
'ClassDecorator',
'ClientRect', 'ClientRect',
'Clipboard', 'Clipboard',
'ClipboardEvent', 'ClipboardEvent',
@ -294,7 +293,6 @@ export default new Set([
'MessageChannel', 'MessageChannel',
'MessageEvent', 'MessageEvent',
'MessagePort', 'MessagePort',
'MethodDecorator',
'MimeType', 'MimeType',
'MimeTypeArray', 'MimeTypeArray',
'MouseEvent', 'MouseEvent',
@ -319,7 +317,6 @@ export default new Set([
'OverconstrainedError', 'OverconstrainedError',
'PageTransitionEvent', 'PageTransitionEvent',
'PannerNode', 'PannerNode',
'ParameterDecorator',
'Path2D', 'Path2D',
'PaymentAddress', 'PaymentAddress',
'PaymentMethodChangeEvent', 'PaymentMethodChangeEvent',
@ -350,10 +347,7 @@ export default new Set([
'ProcessingInstruction', 'ProcessingInstruction',
'ProgressEvent', 'ProgressEvent',
'Promise', 'Promise',
'PromiseConstructorLike',
'PromiseRejectionEvent', 'PromiseRejectionEvent',
'PropertyDecorator',
'PropertyKey',
'Proxy', 'Proxy',
'PublicKeyCredential', 'PublicKeyCredential',
'PushManager', 'PushManager',

Loading…
Cancel
Save