/
githubmirror
/
babel
Обзор
Документация
Войти
/
githubmirror
/
babel
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/babel-parser/src/util/production-parameter.ts
84 строки
2 KB
Huáng Jùnliàng
Improve F# pipeline direct body check (#17806)
27 фев 2026, 19:46
Не верифицирован
27 фев 2026, 19:46
9f94c18
Код
Авторство
О чём код?
// ProductionParameterHandler is a stack fashioned production parameter tracker // https://tc39.es/ecma262/#sec-grammar-notation // The tracked parameters are defined above. // // Whenever [+Await]/[+Yield] appears in the right-hand sides of a production, // we must enter a new tracking stack. For example when parsing // // AsyncFunctionDeclaration [Yield, Await]: // async [no LineTerminator here] function BindingIdentifier[?Yield, ?Await] // ( FormalParameters[~Yield, +Await] ) { AsyncFunctionBody } // // we must follow such process: // // 1. parse async keyword // 2. parse function keyword // 3. parse bindingIdentifier <= inherit current parameters: [?Await] // 4. enter new stack with (PARAM_AWAIT) // 5. parse formal parameters <= must have [Await] parameter [+Await] // 6. parse function body // 7. exit current stack export const enum ParamKind { // Initial Parameter flags PARAM = 0b0000, // track [Yield] production parameter PARAM_YIELD = 0b0001, // track [Await] production parameter PARAM_AWAIT = 0b0010, // track [Return] production parameter PARAM_RETURN = 0b0100, // track [In] production parameter PARAM_IN = 0b1000, // Mark most productions as not being directly in F# pipeline body PARAM_NOT_FSHARP_PIPELINE_DIRECT_BODY = 0b10000, } export default class ProductionParameterHandler { stacks: ParamKind[] = []; enter(flags: ParamKind) { this.stacks.push(flags); } exit() { this.stacks.pop(); } currentFlags(): ParamKind { return this.stacks[this.stacks.length - 1]; } get hasAwait(): boolean { return (this.currentFlags() & ParamKind.PARAM_AWAIT) > 0; } get hasYield(): boolean { return (this.currentFlags() & ParamKind.PARAM_YIELD) > 0; } get hasReturn(): boolean { return (this.currentFlags() & ParamKind.PARAM_RETURN) > 0; } get hasIn(): boolean { return (this.currentFlags() & ParamKind.PARAM_IN) > 0; } get inFSharpPipelineDirectBody(): boolean { return ( (this.currentFlags() & ParamKind.PARAM_NOT_FSHARP_PIPELINE_DIRECT_BODY) === 0 ); } } export function functionFlags( isAsync: boolean, isGenerator: boolean, ): ParamKind { return ( (isAsync ? ParamKind.PARAM_AWAIT : 0) | (isGenerator ? ParamKind.PARAM_YIELD : 0) ); }