Files
NapCatQQ/.pnpm-store/v3/files/5e/be24a09dfb046fe15d35416a15245642a0e85da9e866b54568fb15e8485325b7f94b54abc41a91a02fd67c3b96ef7d77973d45bf7481a57aa1a26dc3fd4cc3
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

38 lines
1.4 KiB
Plaintext

import {eatTypeToken, lookaheadType, match} from "../tokenizer/index";
import {TokenType as tt} from "../tokenizer/types";
import {isFlowEnabled, isTypeScriptEnabled} from "../traverser/base";
import {baseParseConditional} from "../traverser/expression";
import {flowParseTypeAnnotation} from "./flow";
import {tsParseTypeAnnotation} from "./typescript";
/**
* Common parser code for TypeScript and Flow.
*/
// An apparent conditional expression could actually be an optional parameter in an arrow function.
export function typedParseConditional(noIn) {
// If we see ?:, this can't possibly be a valid conditional. typedParseParenItem will be called
// later to finish off the arrow parameter. We also need to handle bare ? tokens for optional
// parameters without type annotations, i.e. ?, and ?) .
if (match(tt.question)) {
const nextType = lookaheadType();
if (nextType === tt.colon || nextType === tt.comma || nextType === tt.parenR) {
return;
}
}
baseParseConditional(noIn);
}
// Note: These "type casts" are *not* valid TS expressions.
// But we parse them here and change them when completing the arrow function.
export function typedParseParenItem() {
eatTypeToken(tt.question);
if (match(tt.colon)) {
if (isTypeScriptEnabled) {
tsParseTypeAnnotation();
} else if (isFlowEnabled) {
flowParseTypeAnnotation();
}
}
}