diff options
Diffstat (limited to 'packages/astro-parser/src/utils/names.ts')
-rw-r--r-- | packages/astro-parser/src/utils/names.ts | 234 |
1 files changed, 117 insertions, 117 deletions
diff --git a/packages/astro-parser/src/utils/names.ts b/packages/astro-parser/src/utils/names.ts index f041d20ce..38e1ec2e8 100644 --- a/packages/astro-parser/src/utils/names.ts +++ b/packages/astro-parser/src/utils/names.ts @@ -2,141 +2,141 @@ 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', + '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', + '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'; + 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; + let i = 0; - while (i < str.length) { - const code = full_char_code_at(str, i); - if (!(i === 0 ? isIdentifierStart : isIdentifierChar)(code, true)) return false; + 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; - } + i += code <= 0xffff ? 1 : 2; + } - return true; + return true; } /** Utility to normalize HTML */ export function sanitize(name: string) { - return name - .replace(/[^a-zA-Z0-9_]+/g, '_') - .replace(/^_/, '') - .replace(/_$/, '') - .replace(/^[0-9]/, '_$&'); + return name + .replace(/[^a-zA-Z0-9_]+/g, '_') + .replace(/^_/, '') + .replace(/_$/, '') + .replace(/^[0-9]/, '_$&'); } |