diff options
Diffstat (limited to 'src/parser/utils/names.ts')
-rw-r--r-- | src/parser/utils/names.ts | 142 |
1 files changed, 0 insertions, 142 deletions
diff --git a/src/parser/utils/names.ts b/src/parser/utils/names.ts deleted file mode 100644 index f041d20ce..000000000 --- a/src/parser/utils/names.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { isIdentifierStart, isIdentifierChar } from 'acorn'; -import full_char_code_at from './full_char_code_at.js'; - -export const globals = new Set([ - 'alert', - 'Array', - 'Boolean', - 'clearInterval', - 'clearTimeout', - 'confirm', - 'console', - 'Date', - 'decodeURI', - 'decodeURIComponent', - 'document', - 'Element', - 'encodeURI', - 'encodeURIComponent', - 'Error', - 'EvalError', - 'Event', - 'EventSource', - 'fetch', - 'global', - 'globalThis', - 'history', - 'Infinity', - 'InternalError', - 'Intl', - 'isFinite', - 'isNaN', - 'JSON', - 'localStorage', - 'location', - 'Map', - 'Math', - 'NaN', - 'navigator', - 'Number', - 'Node', - 'Object', - 'parseFloat', - 'parseInt', - 'process', - 'Promise', - 'prompt', - 'RangeError', - 'ReferenceError', - 'RegExp', - 'sessionStorage', - 'Set', - 'setInterval', - 'setTimeout', - 'String', - 'SyntaxError', - 'TypeError', - 'undefined', - 'URIError', - 'URL', - 'window', -]); - -export const reserved = new Set([ - 'arguments', - 'await', - 'break', - 'case', - 'catch', - 'class', - 'const', - 'continue', - 'debugger', - 'default', - 'delete', - 'do', - 'else', - 'enum', - 'eval', - 'export', - 'extends', - 'false', - 'finally', - 'for', - 'function', - 'if', - 'implements', - 'import', - 'in', - 'instanceof', - 'interface', - 'let', - 'new', - 'null', - 'package', - 'private', - 'protected', - 'public', - 'return', - 'static', - 'super', - 'switch', - 'this', - 'throw', - 'true', - 'try', - 'typeof', - 'var', - 'void', - 'while', - 'with', - 'yield', -]); - -const void_element_names = /^(?:area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/; - -/** Is this a void HTML element? */ -export function is_void(name: string) { - return void_element_names.test(name) || name.toLowerCase() === '!doctype'; -} - -/** Is this a valid HTML element? */ -export function is_valid(str: string): boolean { - let i = 0; - - while (i < str.length) { - const code = full_char_code_at(str, i); - if (!(i === 0 ? isIdentifierStart : isIdentifierChar)(code, true)) return false; - - i += code <= 0xffff ? 1 : 2; - } - - return true; -} - -/** Utility to normalize HTML */ -export function sanitize(name: string) { - return name - .replace(/[^a-zA-Z0-9_]+/g, '_') - .replace(/^_/, '') - .replace(/_$/, '') - .replace(/^[0-9]/, '_$&'); -} |