diff options
author | 2021-03-19 17:07:45 -0400 | |
---|---|---|
committer | 2021-03-19 17:07:45 -0400 | |
commit | 17c3c98f07628b43b941b84831e8e1f9bcd7ca46 (patch) | |
tree | 2e2b3c7d6bd67ebaabe6636ae6867ad368ac6c3a /src/compiler/utils/names.ts | |
parent | 8ebc077cb0d9f50aae22d2651bd5ef13fe4641d3 (diff) | |
download | astro-17c3c98f07628b43b941b84831e8e1f9bcd7ca46.tar.gz astro-17c3c98f07628b43b941b84831e8e1f9bcd7ca46.tar.zst astro-17c3c98f07628b43b941b84831e8e1f9bcd7ca46.zip |
Initial tests set up (#10)
* Begin debugging
* Initial tests set up
This adds tests using uvu (we can switch if people want) and restructures things a bit so that it's easier to test.
Like in snowpack you set up a little project. In our tests you can say:
```js
const result = await runtime.load('/blog/hello-world')
```
And analyze the result. I included a `test-helpers.js` which has a function that will turn HTML into a cheerio instance, for inspecting the result HTML.
* Add CI
* Remove extra console logs
* Formatting
Diffstat (limited to 'src/compiler/utils/names.ts')
-rw-r--r-- | src/compiler/utils/names.ts | 234 |
1 files changed, 117 insertions, 117 deletions
diff --git a/src/compiler/utils/names.ts b/src/compiler/utils/names.ts index c386541a2..f2e1dfc8e 100644 --- a/src/compiler/utils/names.ts +++ b/src/compiler/utils/names.ts @@ -2,138 +2,138 @@ 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)$/; export function is_void(name: string) { - return void_element_names.test(name) || name.toLowerCase() === '!doctype'; + return void_element_names.test(name) || name.toLowerCase() === '!doctype'; } 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; } 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]/, '_$&'); } |