Skip to content

Commit

Permalink
add flow type annotation to production-parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jan 3, 2020
1 parent 03a763d commit 98ac14f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/babel-parser/src/util/production-parameter.js
@@ -1,3 +1,4 @@
// @flow
export const PARAM_ = 0b000, // Initial Parameter flags
PARAM_YIELD = 0b001, // track [Await] production parameter
PARAM_AWAIT = 0b010; // track [Yield] production parameter
Expand All @@ -24,29 +25,34 @@ export const PARAM_ = 0b000, // Initial Parameter flags
// 6. parse function body
// 7. exit current stack

export type ParamKind = typeof PARAM_ | typeof PARAM_AWAIT | typeof PARAM_YIELD;

export default class ProductionParameterHandler {
stacks: Array = [];
enter(flags) {
stacks: Array<ParamKind> = [];
enter(flags: ParamKind) {
this.stacks.push(flags);
}

exit() {
this.stacks.pop();
}

currentFlags() {
currentFlags(): ParamKind {
return this.stacks[this.stacks.length - 1];
}

get hasAwait() {
get hasAwait(): boolean {
return (this.currentFlags() & PARAM_AWAIT) > 0;
}

get hasYield() {
get hasYield(): boolean {
return (this.currentFlags() & PARAM_YIELD) > 0;
}
}

export function functionFlags(isAsync: boolean, isGenerator: boolean) {
export function functionFlags(
isAsync: boolean,
isGenerator: boolean,
): ParamKind {
return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0);
}

0 comments on commit 98ac14f

Please sign in to comment.