From 433996ced94d9184b777fb07b178796d0a9bb49c Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Sun, 4 Sep 2022 00:13:02 +0900 Subject: [PATCH] stop to read declare type and support backward compatible --- scripts/globals-extractor.mjs | 24 +++++++++++++++++------- src/compiler/utils/globals.ts | 27 ++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/scripts/globals-extractor.mjs b/scripts/globals-extractor.mjs index 07f3470e77..cabcba3e76 100644 --- a/scripts/globals-extractor.mjs +++ b/scripts/globals-extractor.mjs @@ -9,6 +9,8 @@ see: https://github.com/microsoft/TypeScript/tree/main/lib import http from 'https'; import fs from 'fs'; +const GLOBAL_TS_PATH = './src/compiler/utils/globals.ts'; + // MEMO: add additional objects/functions which existed in `src/compiler/utils/names.ts` // before this script was introduced but could not be retrieved by this process. const SPECIALS = ['global', 'globalThis', 'InternalError', 'process', 'undefined']; @@ -22,10 +24,8 @@ const extract_functions_and_references = (name, data) => { data.split('\n').forEach(line => { const trimmed = line.trim(); const split = trimmed.replace(/[\s+]/, ' ').split(' '); - if (split[0] === 'declare') { - // 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])); + if (split[0] === 'declare' && split[1] !== 'type') { + functions.push(extract_name(split[2])); } else if (trimmed.startsWith('/// `\t'${i}'`).join(',\n')} `.substring(1); }; +const get_exists_globals = () => { + const regexp = /^\s*["'](.+)["'],?\s*$/; + return fs.readFileSync(GLOBAL_TS_PATH, 'utf8') + .split('\n') + .filter(line => line.match(regexp)) + .map(line => line.match(regexp)[1]); +}; + (async () => { - const functions = await get_functions('es2021.full'); - functions.push(...SPECIALS); - fs.writeFileSync('src/compiler/utils/globals.ts', build_output(functions)); + const globals = get_exists_globals(); + const new_globals = await get_functions('es2021.full'); + globals.forEach((g) => new_globals.push(g)); + SPECIALS.forEach((g) => new_globals.push(g)); + fs.writeFileSync(GLOBAL_TS_PATH, build_output(new_globals)); })(); diff --git a/src/compiler/utils/globals.ts b/src/compiler/utils/globals.ts index e95f18db3d..657006d574 100644 --- a/src/compiler/utils/globals.ts +++ b/src/compiler/utils/globals.ts @@ -1,6 +1,6 @@ /** ---------------------------------------------------------------------- This file is automatically generated by `scripts/globals-extractor.mjs`. -Generated At: 2022-08-14T16:40:42.472Z +Generated At: 2022-09-03T15:10:02.144Z ---------------------------------------------------------------------- */ export default new Set([ @@ -69,6 +69,7 @@ export default new Set([ 'CSSTransition', 'Cache', 'CacheStorage', + 'CanvasCaptureMediaStreamTrack', 'CanvasGradient', 'CanvasPattern', 'CanvasRenderingContext2D', @@ -120,11 +121,13 @@ export default new Set([ 'DragEvent', 'DynamicsCompressorNode', 'Element', + 'ElementInternals', 'Enumerator', 'Error', 'ErrorEvent', 'EvalError', 'Event', + 'EventCounts', 'EventSource', 'EventTarget', 'External', @@ -133,9 +136,12 @@ export default new Set([ 'FileReader', 'FileSystem', 'FileSystemDirectoryEntry', + 'FileSystemDirectoryHandle', 'FileSystemDirectoryReader', 'FileSystemEntry', 'FileSystemFileEntry', + 'FileSystemFileHandle', + 'FileSystemHandle', 'FinalizationRegistry', 'Float32Array', 'Float64Array', @@ -169,6 +175,7 @@ export default new Set([ 'HTMLDataElement', 'HTMLDataListElement', 'HTMLDetailsElement', + 'HTMLDialogElement', 'HTMLDirectoryElement', 'HTMLDivElement', 'HTMLDocument', @@ -251,6 +258,7 @@ export default new Set([ 'ImageBitmapRenderingContext', 'ImageData', 'Infinity', + 'InputDeviceInfo', 'InputEvent', 'Int16Array', 'Int32Array', @@ -263,6 +271,8 @@ export default new Set([ 'KeyboardEvent', 'KeyframeEffect', 'Location', + 'Lock', + 'LockManager', 'Map', 'Math', 'MathMLElement', @@ -301,6 +311,7 @@ export default new Set([ 'MutationRecord', 'NaN', 'NamedNodeMap', + 'NavigationPreloadManager', 'Navigator', 'NetworkInformation', 'Node', @@ -359,6 +370,10 @@ export default new Set([ 'RTCDataChannel', 'RTCDataChannelEvent', 'RTCDtlsTransport', + 'RTCEncodedAudioFrame', + 'RTCEncodedVideoFrame', + 'RTCError', + 'RTCErrorEvent', 'RTCIceCandidate', 'RTCIceTransport', 'RTCPeerConnection', @@ -367,13 +382,17 @@ export default new Set([ 'RTCRtpReceiver', 'RTCRtpSender', 'RTCRtpTransceiver', + 'RTCSctpTransport', 'RTCSessionDescription', 'RTCStatsReport', 'RTCTrackEvent', 'RadioNodeList', 'Range', 'RangeError', + 'ReadableByteStreamController', 'ReadableStream', + 'ReadableStreamBYOBReader', + 'ReadableStreamBYOBRequest', 'ReadableStreamDefaultController', 'ReadableStreamDefaultReader', 'ReferenceError', @@ -553,6 +572,7 @@ export default new Set([ 'VTTRegion', 'ValidityState', 'VarDate', + 'VideoColorSpace', 'VideoPlaybackQuality', 'VisualViewport', 'WSH', @@ -608,6 +628,7 @@ export default new Set([ 'captureEvents', 'clearInterval', 'clearTimeout', + 'clientInformation', 'close', 'closed', 'confirm', @@ -733,11 +754,13 @@ export default new Set([ 'onreset', 'onresize', 'onscroll', + 'onsecuritypolicyviolation', 'onseeked', 'onseeking', 'onselect', 'onselectionchange', 'onselectstart', + 'onslotchange', 'onstalled', 'onstorage', 'onsubmit', @@ -781,6 +804,7 @@ export default new Set([ 'queueMicrotask', 'releaseEvents', 'removeEventListener', + 'reportError', 'requestAnimationFrame', 'requestIdleCallback', 'resizeBy', @@ -804,6 +828,7 @@ export default new Set([ 'status', 'statusbar', 'stop', + 'structuredClone', 'toString', 'toolbar', 'top',