Skip to content

Commit

Permalink
fix: anitomy npe
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed May 9, 2023
1 parent 5bf99f8 commit 17b213c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/anitomy/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function checkTokenFlags(token: Token, flags: TokenFlag[]) {

export function findNextToken(tokens: Token[], position: number, ...flags: TokenFlag[]) {
for (let i = position + 1; i < tokens.length; i++) {
if (checkTokenFlags(tokens[i], flags)) {
if (tokens[i] && checkTokenFlags(tokens[i], flags)) {
return i;
}
}
Expand All @@ -94,7 +94,7 @@ export function findNextToken(tokens: Token[], position: number, ...flags: Token

export function findPrevToken(tokens: Token[], position: number, ...flags: TokenFlag[]) {
for (let i = position - 1; i >= 0; i--) {
if (checkTokenFlags(tokens[i], flags)) {
if (tokens[i] && checkTokenFlags(tokens[i], flags)) {
return i;
}
}
Expand All @@ -103,7 +103,7 @@ export function findPrevToken(tokens: Token[], position: number, ...flags: Token

export function findToken(tokens: Token[], start: number, end: number, ...flags: TokenFlag[]) {
for (let i = start; i < end; i++) {
if (checkTokenFlags(tokens[i], flags)) {
if (tokens[i] && checkTokenFlags(tokens[i], flags)) {
return i;
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/anitomy/src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export function tokenize(filename: string, options: AnitomyOptions) {
}

function isSingleCharacterToken(idx: number) {
if (!inRange(tokens, idx)) return false;
const content = tokens[idx].content;
return isUnknownToken(idx) && content.length === 1 && content !== '-';
}
Expand Down

0 comments on commit 17b213c

Please sign in to comment.