Skip to content

Commit b8815a9

Browse files
committed
Leave top level scope when traversing Class nodes
1 parent ae0dc62 commit b8815a9

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

lib/Parser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,13 @@ class Parser extends Tapable {
609609
if(classy.superClass)
610610
this.walkExpression(classy.superClass);
611611
if(classy.body && classy.body.type === "ClassBody") {
612-
for(const methodDefinition of classy.body.body)
612+
const wasTopLevel = this.scope.topLevelScope;
613+
this.scope.topLevelScope = false;
614+
for(const methodDefinition of classy.body.body) {
613615
if(methodDefinition.type === "MethodDefinition")
614616
this.walkMethodDefinition(methodDefinition);
617+
}
618+
this.scope.topLevelScope = wasTopLevel;
615619
}
616620
}
617621

test/configCases/parsing/harmony-this/abc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ export class C {
2222
foo() {
2323
return this.x;
2424
}
25+
bar(x = this.x) {
26+
return x;
27+
}
28+
}
29+
30+
export const extendThisClass = () => {
31+
return class extends this.Buffer {};
2532
}
2633

2734
export function D() {

test/configCases/parsing/harmony-this/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
import d, {a, b as B, C as _C, D as _D, returnThisArrow, returnThisMember, that} from "./abc";
3+
import d, {a, b as B, C as _C, D as _D, extendThisClass, returnThisArrow, returnThisMember, that} from "./abc";
44

55
import * as abc from "./abc";
66

@@ -15,10 +15,14 @@ it("should have this = undefined on harmony modules", function() {
1515
(function() {
1616
abc.returnThisMember();
1717
}).should.throw();
18+
(function() {
19+
extendThisClass();
20+
}).should.throw();
1821
});
1922

2023
it("should not break classes and functions", function() {
2124
(new _C).foo().should.be.eql("bar");
25+
(new _C).bar().should.be.eql("bar");
2226
(new _D).prop().should.be.eql("ok");
2327
});
2428

0 commit comments

Comments
 (0)