Skip to content

Commit 2edd1ad

Browse files
committed
support exporting classes
fixed webpack#2523
1 parent 08c0851 commit 2edd1ad

5 files changed

Lines changed: 23 additions & 2 deletions

File tree

lib/Parser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ Parser.prototype.walkVariableDeclaration = function walkVariableDeclaration(stat
579579
};
580580

581581
Parser.prototype.walkClassDeclaration = function walkClassDeclaration(statement) {
582+
this.scope.renames["$" + statement.id.name] = undefined;
583+
this.scope.definitions.push(statement.id.name);
582584
this.walkClass(statement);
583585
};
584586

lib/dependencies/HarmonyExportDependencyParserPlugin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = AbstractPlugin.create({
3535
this.state.module.strict = true;
3636
return true;
3737
},
38-
"export declaration": function() {},
38+
"export declaration": function(statement) {},
3939
"export specifier": function(statement, id, name) {
4040
var rename = this.scope.renames["$" + id];
4141
var dep;
@@ -62,11 +62,12 @@ module.exports = AbstractPlugin.create({
6262
function isImmutableStatement(statement) {
6363
if(statement.type === "FunctionDeclaration") return true;
6464
if(statement.type === "ClassDeclaration") return true;
65+
if(statement.type === "VariableDeclaration" && statement.kind === "const") return true;
6566
return false;
6667
}
6768

6869
function isHoistedStatement(statement) {
6970
if(statement.type === "FunctionDeclaration") return true;
70-
if(statement.type === "VariableDeclarators" && statement.kind === "var") return true;
71+
if(statement.type === "VariableDeclaration" && statement.kind === "var") return true;
7172
return false;
7273
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import A from "./module";
2+
import { B } from "./module";
3+
import { c } from "./module";
4+
5+
it("should allow to export a class", function() {
6+
(typeof A).should.be.eql("function");
7+
(typeof B).should.be.eql("function");
8+
c.should.be.eql("c");
9+
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default class A {}
2+
export class B {}
3+
4+
export const c = 'c';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var supportsES6 = require("../../../helpers/supportsES6");
2+
3+
module.exports = function(config) {
4+
return !config.minimize && supportsES6();
5+
};

0 commit comments

Comments
 (0)