Skip to content

Commit

Permalink
refactor: extract builtins, make readonly set
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Dec 16, 2021
1 parent b43ab5b commit 23dff43
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
63 changes: 63 additions & 0 deletions src/utils/BUILTINS.ts
@@ -0,0 +1,63 @@
const BUILTINS: ReadonlySet<string> = new Set([
'Infinity',
'NaN',
'undefined',
'null',
'true',
'false',
'eval',
'uneval',
'isFinite',
'isNaN',
'parseFloat',
'parseInt',
'decodeURI',
'decodeURIComponent',
'encodeURI',
'encodeURIComponent',
'escape',
'unescape',
'Object',
'Function',
'Boolean',
'Symbol',
'Error',
'EvalError',
'InternalError',
'RangeError',
'ReferenceError',
'SyntaxError',
'TypeError',
'URIError',
'Number',
'Math',
'Date',
'String',
'RegExp',
'Array',
'Int8Array',
'Uint8Array',
'Uint8ClampedArray',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array',
'Map',
'Set',
'WeakMap',
'WeakSet',
'SIMD',
'ArrayBuffer',
'DataView',
'JSON',
'Promise',
'Generator',
'GeneratorFunction',
'Reflect',
'Proxy',
'Intl'
]);

export default BUILTINS;
8 changes: 2 additions & 6 deletions src/utils/identifierHelpers.ts
@@ -1,11 +1,7 @@
import BUILTINS from './BUILTINS';
import RESERVED_WORDS from './RESERVED_WORDS';

const builtins =
'Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split(
' '
);

const blacklisted = new Set([...RESERVED_WORDS, ...builtins]);
const blacklisted = new Set([...RESERVED_WORDS, ...BUILTINS]);

const illegalCharacters = /[^$_a-zA-Z0-9]/g;

Expand Down

0 comments on commit 23dff43

Please sign in to comment.