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

Commit

Permalink
feat: support new.target in class
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Mar 29, 2018
1 parent 731ddcd commit dc76edb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,10 @@ const visitors: EvaluateMap = {
classScope.const("this", this);
}

classScope.const("new", {
target: ClassConstructor
});

for (const n of constructor.body.body) {
evaluate(
path.createChild(n, classScope, {
Expand Down
26 changes: 26 additions & 0 deletions test/es2015/class/new.target.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import test from "ava";
import vm from "../../../src/vm";

test("new target with new", t => {
const sandbox: any = vm.createContext({});

const { Person, target } = vm.runInContext(
`
var target;
class Person{
constructor(){
target = new.target;
}
}
new Person();
module.exports = {target: target, Person: Person};
`,
sandbox
);

t.true(target === Person);
t.deepEqual(target.name, "Person");
});

0 comments on commit dc76edb

Please sign in to comment.