Skip to content

Commit

Permalink
parser plugin-utils: Remove Object.entries call for Node聽6
Browse files Browse the repository at this point in the history
  • Loading branch information
js-choi committed Nov 22, 2021
1 parent e7c71dc commit f387fa7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/babel-parser/src/parser/base.js
Expand Up @@ -44,8 +44,8 @@ export default class BaseParser {
return false;
}
const actualOptions = this.plugins.get(pluginName);
for (const [key, value] of Object.entries(pluginOptions)) {
if (value !== actualOptions?.[key]) {
for (const key of Object.keys(pluginOptions)) {
if (actualOptions?.[key] !== pluginOptions[key]) {
return false;
}
}
Expand All @@ -55,7 +55,7 @@ export default class BaseParser {

getPluginOption(plugin: string, name: string) {
// $FlowIssue
if (this.hasPlugin(plugin)) return this.plugins.get(plugin)[name];
return this.plugins.get(plugin)?.[name];
}
}

Expand Down
9 changes: 5 additions & 4 deletions packages/babel-parser/src/plugin-utils.js
Expand Up @@ -24,8 +24,9 @@ export function hasPlugin(
const [expectedName, expectedOptions] =
typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;

const expectedOptionsIsEmpty =
[...Object.entries(expectedOptions)].length === 0;
const expectedKeys = Object.keys(expectedOptions);

const expectedOptionsIsEmpty = expectedKeys.length === 0;

return plugins.some(p => {
if (typeof p === "string") {
Expand All @@ -35,8 +36,8 @@ export function hasPlugin(
if (pluginName !== expectedName) {
return false;
}
for (const [key, expectedValue] of Object.entries(expectedOptions)) {
if (expectedValue !== pluginOptions[key]) {
for (const key of expectedKeys) {
if (pluginOptions[key] !== expectedOptions[key]) {
return false;
}
}
Expand Down

0 comments on commit f387fa7

Please sign in to comment.