Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

Commit

Permalink
fix: close #22
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Nov 25, 2018
1 parent 9f5b18e commit 08fea44
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/standard/es5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ export const es5: ES5Map = {
for (let i = 0; i < node.params.length; i++) {
const param = node.params[i];
if (isIdentifier(param)) {
funcScope.const(param.name, args[i]);
funcScope.let(param.name, args[i]);
} else if (isAssignmentPattern(param)) {
// @es2015 default parameters
path.evaluate(path.createChild(param, funcScope, { value: args[i] }));
Expand Down
18 changes: 18 additions & 0 deletions test/ecma5/function/FunctionExpression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,21 @@ obj["a"]();
);
}, ErrIsNotFunction("obj.a").message);
});

test("function params should can be overwrite", t => {
const sandbox: any = vm.createContext({});

const test = vm.runInContext(
`
function test (a) {
a = a || 'hello'
return a
}
module.exports = test
`,
sandbox
);

t.deepEqual(test(), "hello");
});

0 comments on commit 08fea44

Please sign in to comment.