Skip to content

Commit

Permalink
Use Object.create where appropriate
Browse files Browse the repository at this point in the history
This breaks support on ancient Node and IE versions, but at this point
that's okay (IE11 has Object.create).

Closes #992
  • Loading branch information
marijnh committed Nov 11, 2020
1 parent 7f8799a commit 6746b19
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
9 changes: 1 addition & 8 deletions acorn-walk/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion acorn/src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion acorn/src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) === "#!")
Expand Down

0 comments on commit 6746b19

Please sign in to comment.