Files
node_modules
.bin
@alloc
@jridgewell
@mapbox
@nodelib
@tailwindcss
@types
abbrev
accepts
adm-zip
agent-base
ansi-regex
ansi-styles
any-promise
anymatch
aproba
are-we-there-yet
arg
array-flatten
async
balanced-match
bcrypt
binary-extensions
body-parser
brace-expansion
braces
bson
bytes
call-bind
camelcase-css
cassandra-driver
chalk
chokidar
chownr
color-convert
color-name
color-support
commander
concat-map
console-control-strings
content-disposition
content-type
cookie
cookie-parser
cookie-signature
cssesc
debug
delegates
depd
destroy
detect-libc
didyoumean
dlv
ee-first
ejs
emoji-regex
encodeurl
escape-html
etag
express
express-session
fast-glob
fastq
filelist
fill-range
finalhandler
forwarded
fresh
fs
fs-minipass
fs.realpath
fsevents
function-bind
gauge
get-intrinsic
glob
glob-parent
has
has-flag
has-proto
has-symbols
has-unicode
http-errors
https-proxy-agent
iconv-lite
inflight
inherits
ip
ipaddr.js
is-binary-path
is-core-module
is-extglob
is-fullwidth-code-point
is-glob
is-number
jake
jiti
lilconfig
lines-and-columns
long
lru-cache
make-dir
media-typer
memory-pager
merge-descriptors
merge2
methods
micromatch
mime
mime-db
mime-types
mini-svg-data-uri
minimatch
minipass
minizlib
mkdirp
mongodb
mongodb-connection-string-url
ms
mz
nanoid
negotiator
node-addon-api
node-fetch
nopt
normalize-path
npmlog
object-assign
object-hash
object-inspect
on-finished
on-headers
once
parseurl
path-is-absolute
path-parse
path-to-regexp
picocolors
picomatch
pify
pirates
postcss
postcss-import
postcss-js
postcss-less
postcss-load-config
postcss-nested
postcss-selector-parser
postcss-value-parser
proxy-addr
punycode
qs
queue-microtask
random-bytes
range-parser
raw-body
read-cache
readable-stream
readdirp
resolve
reusify
rimraf
run-parallel
safe-buffer
safer-buffer
saslprep
semver
send
serve-static
set-blocking
setprototypeof
side-channel
signal-exit
smart-buffer
socks
source-map
source-map-js
sparse-bitfield
statuses
string-width
string_decoder
strip-ansi
sucrase
bin
dist
esm
parser
transformers
util
elideImportEquals.js
formatTokens.js
getClassInfo.js
getDeclarationInfo.js
getIdentifierNames.js
getImportExportSpecifierInfo.js
getJSXPragmaInfo.js
getNonTypeIdentifiers.js
getTSImportedNames.js
isAsyncOperation.js
isIdentifier.js
removeMaybeImportAssertion.js
shouldElideDefaultExport.js
CJSImportProcessor.js
HelperManager.js
NameManager.js
Options-gen-types.js
Options.js
TokenProcessor.js
cli.js
computeSourceMap.js
identifyShadowedGlobals.js
index.js
register.js
parser
transformers
types
util
CJSImportProcessor.js
HelperManager.js
NameManager.js
Options-gen-types.js
Options.js
TokenProcessor.js
cli.js
computeSourceMap.js
identifyShadowedGlobals.js
index.js
register.js
register
ts-node-plugin
LICENSE
README.md
package.json
supports-color
supports-preserve-symlinks-flag
tailwindcss
tar
thenify
thenify-all
to-regex-range
toidentifier
tr46
ts-interface-checker
type-is
uid-safe
unpipe
util-deprecate
utils-merge
vary
webidl-conversions
whatwg-url
wide-align
wrappy
yallist
yaml
.package-lock.json
public
views
Title.html
cat.gif
index.css
index.html
package-lock.json
package.json
result.js
tailwind.config.js
glink-website/node_modules/sucrase/dist/esm/util/isIdentifier.js
2023-06-21 15:56:08 -05:00

82 lines
1.8 KiB
JavaScript

import {IS_IDENTIFIER_CHAR, IS_IDENTIFIER_START} from "../parser/util/identifier";
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar
// Hard-code a list of reserved words rather than trying to use keywords or contextual keywords
// from the parser, since currently there are various exceptions, like `package` being reserved
// but unused and various contextual keywords being reserved. Note that we assume that all code
// compiled by Sucrase is in a module, so strict mode words and await are all considered reserved
// here.
const RESERVED_WORDS = new Set([
// Reserved keywords as of ECMAScript 2015
"break",
"case",
"catch",
"class",
"const",
"continue",
"debugger",
"default",
"delete",
"do",
"else",
"export",
"extends",
"finally",
"for",
"function",
"if",
"import",
"in",
"instanceof",
"new",
"return",
"super",
"switch",
"this",
"throw",
"try",
"typeof",
"var",
"void",
"while",
"with",
"yield",
// Future reserved keywords
"enum",
"implements",
"interface",
"let",
"package",
"private",
"protected",
"public",
"static",
"await",
// Literals that cannot be used as identifiers
"false",
"null",
"true",
]);
/**
* Determine if the given name is a legal variable name.
*
* This is needed when transforming TypeScript enums; if an enum key is a valid
* variable name, it might be referenced later in the enum, so we need to
* declare a variable.
*/
export default function isIdentifier(name) {
if (name.length === 0) {
return false;
}
if (!IS_IDENTIFIER_START[name.charCodeAt(0)]) {
return false;
}
for (let i = 1; i < name.length; i++) {
if (!IS_IDENTIFIER_CHAR[name.charCodeAt(i)]) {
return false;
}
}
return !RESERVED_WORDS.has(name);
}