fonts
node_modules
.bin
@alloc
@jridgewell
@nodelib
any-promise
anymatch
arg
balanced-match
binary-extensions
brace-expansion
braces
camelcase-css
chokidar
colord
commander
concat-map
css-selector-tokenizer
cssesc
daisyui
didyoumean
dlv
fast-glob
fastparse
fastq
fill-range
fs.realpath
function-bind
glob
glob-parent
has
inflight
inherits
is-binary-path
is-core-module
is-extglob
is-glob
is-number
jiti
lilconfig
lines-and-columns
merge2
micromatch
minimatch
mz
nanoid
normalize-path
object-assign
object-hash
once
path-is-absolute
path-parse
picocolors
picomatch
pify
pirates
postcss
postcss-import
postcss-js
postcss-load-config
postcss-nested
postcss-selector-parser
postcss-value-parser
queue-microtask
read-cache
readdirp
resolve
reusify
run-parallel
source-map-js
sucrase
bin
dist
esm
parser
plugins
tokenizer
index.js
keywords.js
readWord.js
readWordTree.js
state.js
types.js
traverser
util
index.js
transformers
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
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-preserve-symlinks-flag
tailwindcss
thenify
thenify-all
to-regex-range
ts-interface-checker
util-deprecate
wrappy
yaml
.package-lock.json
GLink-Logo-alt.svg
cat.gif
checkloc.php
dashboard.html
db.inc.php
deletelink.php
form.html
header.php
home2.html
homepagevideo.mp4
howItWorks.txt
htmx.min.js
index.css
index.html
index.js
input.css
login.html
login.js
login.php
logout.php
output.css
package-lock.json
package.json
redirect.php
reqloc.html
result.php
signup.html
signup.php
step1.png
step2.png
step3.png
tailwind.config.js
undodeletelink.php
updatelink.php
65 lines
1.9 KiB
JavaScript
65 lines
1.9 KiB
JavaScript
import {input, state} from "../traverser/base";
|
|
import {charCodes} from "../util/charcodes";
|
|
import {IS_IDENTIFIER_CHAR} from "../util/identifier";
|
|
import {finishToken} from "./index";
|
|
import {READ_WORD_TREE} from "./readWordTree";
|
|
import {TokenType as tt} from "./types";
|
|
|
|
/**
|
|
* Read an identifier, producing either a name token or matching on one of the existing keywords.
|
|
* For performance, we pre-generate big decision tree that we traverse. Each node represents a
|
|
* prefix and has 27 values, where the first value is the token or contextual token, if any (-1 if
|
|
* not), and the other 26 values are the transitions to other nodes, or -1 to stop.
|
|
*/
|
|
export default function readWord() {
|
|
let treePos = 0;
|
|
let code = 0;
|
|
let pos = state.pos;
|
|
while (pos < input.length) {
|
|
code = input.charCodeAt(pos);
|
|
if (code < charCodes.lowercaseA || code > charCodes.lowercaseZ) {
|
|
break;
|
|
}
|
|
const next = READ_WORD_TREE[treePos + (code - charCodes.lowercaseA) + 1];
|
|
if (next === -1) {
|
|
break;
|
|
} else {
|
|
treePos = next;
|
|
pos++;
|
|
}
|
|
}
|
|
|
|
const keywordValue = READ_WORD_TREE[treePos];
|
|
if (keywordValue > -1 && !IS_IDENTIFIER_CHAR[code]) {
|
|
state.pos = pos;
|
|
if (keywordValue & 1) {
|
|
finishToken(keywordValue >>> 1);
|
|
} else {
|
|
finishToken(tt.name, keywordValue >>> 1);
|
|
}
|
|
return;
|
|
}
|
|
|
|
while (pos < input.length) {
|
|
const ch = input.charCodeAt(pos);
|
|
if (IS_IDENTIFIER_CHAR[ch]) {
|
|
pos++;
|
|
} else if (ch === charCodes.backslash) {
|
|
// \u
|
|
pos += 2;
|
|
if (input.charCodeAt(pos) === charCodes.leftCurlyBrace) {
|
|
while (pos < input.length && input.charCodeAt(pos) !== charCodes.rightCurlyBrace) {
|
|
pos++;
|
|
}
|
|
pos++;
|
|
}
|
|
} else if (ch === charCodes.atSign && input.charCodeAt(pos + 1) === charCodes.atSign) {
|
|
pos += 2;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
state.pos = pos;
|
|
finishToken(tt.name);
|
|
}
|