Skip to content

Commit

Permalink
refactor: simplify isMaybeDefaultImport
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 17, 2021
1 parent a4f5205 commit 1ccd28b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/babel-parser/src/plugins/flow/index.js
Expand Up @@ -163,8 +163,8 @@ function hasTypeImportKind(node: N.Node): boolean {
return node.importKind === "type" || node.importKind === "typeof";
}

function isMaybeDefaultImport(state: { type: TokenType, value: any }): boolean {
return tokenIsKeywordOrIdentifier(state.type) && state.value !== "from";
function isMaybeDefaultImport(type: TokenType): boolean {
return tokenIsKeywordOrIdentifier(type) && type !== tt._from;
}

const exportSuggestions = {
Expand Down Expand Up @@ -2576,7 +2576,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return super.shouldParseDefaultImport(node);
}

return isMaybeDefaultImport(this.state);
return isMaybeDefaultImport(this.state.type);
}

parseImportSpecifierLocal(
Expand Down Expand Up @@ -2608,16 +2608,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
if (kind) {
const lh = this.lookahead();
const { type } = lh;

// import type * is not allowed
if (kind === "type" && lh.type === tt.star) {
if (kind === "type" && type === tt.star) {
this.unexpected(lh.start);
}

if (
isMaybeDefaultImport(lh) ||
lh.type === tt.braceL ||
lh.type === tt.star
isMaybeDefaultImport(type) ||
type === tt.braceL ||
type === tt.star
) {
this.next();
node.importKind = kind;
Expand Down
1 change: 1 addition & 0 deletions packages/babel-parser/src/tokenizer/types.js
Expand Up @@ -78,6 +78,7 @@ export class ExportedTokenType {
}
}

// A map from keyword/keyword-like string value to the token type
export const keywords = new Map<string, TokenType>();

function createKeyword(name: string, options: TokenOptions = {}): TokenType {
Expand Down

0 comments on commit 1ccd28b

Please sign in to comment.