Skip to content

Commit

Permalink
fix flow errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 16, 2021
1 parent 5d34ba0 commit 7c9237d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/babel-parser/src/parser/util.js
@@ -1,6 +1,7 @@
// @flow

import {
isTokenType,
tokenIsKeyword,
tokenLabelName,
tt,
Expand Down Expand Up @@ -173,17 +174,19 @@ export default class UtilParser extends Tokenizer {
template: "Unexpected token",
},
): empty {
if (typeof messageOrType === "number") {
if (isTokenType(messageOrType)) {
messageOrType = {
code: ErrorCodes.SyntaxError,
reasonCode: "UnexpectedToken",
template: `Unexpected token, expected "${tokenLabelName(
// $FlowIgnore: Flow does not support assertion signature and TokenType is opaque
messageOrType,
)}"`,
};
}

/* eslint-disable @babel/development-internal/dry-error-messages */
// $FlowIgnore: Flow does not support assertion signature and TokenType is opaque
throw this.raise(pos != null ? pos : this.state.start, messageOrType);
/* eslint-enable @babel/development-internal/dry-error-messages */
}
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-parser/src/tokenizer/types.js
Expand Up @@ -306,6 +306,10 @@ export function getExportedToken(token: TokenType): ExportedTokenType {
return tokenTypes[token];
}

export function isTokenType(obj: any): boolean {
return typeof obj === "number";
}

if (!process.env.BABEL_8_BREAKING) {
tokenTypes[tt.braceR].updateContext = context => {
context.pop();
Expand Down

0 comments on commit 7c9237d

Please sign in to comment.