From 6746b1905e1669a68738563ab23ade1c6a3b25be Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 11 Nov 2020 17:54:26 +0100 Subject: [PATCH] Use Object.create where appropriate This breaks support on ancient Node and IE versions, but at this point that's okay (IE11 has Object.create). Closes #992 --- acorn-walk/src/index.js | 9 +-------- acorn/src/expression.js | 2 +- acorn/src/state.js | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/acorn-walk/src/index.js b/acorn-walk/src/index.js index 2a044b7df..38e6159b3 100644 --- a/acorn-walk/src/index.js +++ b/acorn-walk/src/index.js @@ -164,17 +164,10 @@ export function findNodeBefore(node, pos, test, baseVisitor, state) { return max } -// Fallback to an Object.create polyfill for older environments. -const create = Object.create || function(proto) { - function Ctor() {} - Ctor.prototype = proto - return new Ctor -} - // Used to create a custom walker. Will fill in all missing node // type properties with the defaults. export function make(funcs, baseVisitor) { - let visitor = create(baseVisitor || base) + let visitor = Object.create(baseVisitor || base) for (let type in funcs) visitor[type] = funcs[type] return visitor } diff --git a/acorn/src/expression.js b/acorn/src/expression.js index f1e4f5811..819083a65 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -924,7 +924,7 @@ pp.isSimpleParamList = function(params) { // or "arguments" and duplicate parameters. pp.checkParams = function(node, allowDuplicates) { - let nameHash = {} + let nameHash = Object.create(null) for (let param of node.params) this.checkLValInnerPattern(param, BIND_VAR, allowDuplicates ? null : nameHash) } diff --git a/acorn/src/state.js b/acorn/src/state.js index f7e4700e2..1495ea17d 100644 --- a/acorn/src/state.js +++ b/acorn/src/state.js @@ -71,7 +71,7 @@ export class Parser { // Labels in scope. this.labels = [] // Thus-far undefined exports. - this.undefinedExports = {} + this.undefinedExports = Object.create(null) // If enabled, skip leading hashbang line. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")