Repository: Rich-Harris/buble
Pull request #3 (2017-09-23 17:30:53)

Make class accessors (static or not) configurable, like spec.
*moved from https://gitlab.com/Rich-Harris/buble/merge_requests/121*


Patch:
diff --git a/src/program/types/ClassBody.js b/src/program/types/ClassBody.js
index 8df3398..65c00b5 100644
--- a/src/program/types/ClassBody.js
+++ b/src/program/types/ClassBody.js
@@ -156,12 +156,12 @@ export default class ClassBody extends Node {
 				let outro = [];
 
 				if ( prototypeGettersAndSetters.length ) {
-					intro.push( `var ${prototypeAccessors} = { ${prototypeGettersAndSetters.map( name => `${name}: {}` ).join( ',' )} };` );
+					intro.push( `var ${prototypeAccessors} = { ${prototypeGettersAndSetters.map( name => `${name}: { configurable: true }` ).join( ',' )} };` );
 					outro.push( `Object.defineProperties( ${name}.prototype, ${prototypeAccessors} );` );
 				}
 
 				if ( staticGettersAndSetters.length ) {
-					intro.push( `var ${staticAccessors} = { ${staticGettersAndSetters.map( name => `${name}: {}` ).join( ',' )} };` );
+					intro.push( `var ${staticAccessors} = { ${staticGettersAndSetters.map( name => `${name}: { configurable: true }` ).join( ',' )} };` );
 					outro.push( `Object.defineProperties( ${name}, ${staticAccessors} );` );
 				}
 


Test patch:
diff --git a/test/samples/classes-no-named-function-expressions.js b/test/samples/classes-no-named-function-expressions.js
index 8d94e29..20543fb 100644
--- a/test/samples/classes-no-named-function-expressions.js
+++ b/test/samples/classes-no-named-function-expressions.js
@@ -462,8 +462,8 @@ module.exports = [
 				this.radius = radius;
 			};
 
-			var prototypeAccessors = { area: {} };
-			var staticAccessors = { description: {} };
+			var prototypeAccessors = { area: { configurable: true } };
+			var staticAccessors = { description: { configurable: true } };
 
 			prototypeAccessors.area.get = function () {
 				return Math.PI * Math.pow( this.radius, 2 );
@@ -516,8 +516,8 @@ module.exports = [
 				Circle.prototype = Object.create( Shape && Shape.prototype );
 				Circle.prototype.constructor = Circle;
 
-				var prototypeAccessors = { area: {} };
-				var staticAccessors = { description: {} };
+				var prototypeAccessors = { area: { configurable: true } };
+				var staticAccessors = { description: { configurable: true } };
 
 				prototypeAccessors.area.get = function () {
 					return Math.PI * Math.pow( this.radius, 2 );
@@ -828,7 +828,7 @@ module.exports = [
 		output: `
 			var Foo = function () {};
 
-			var staticAccessors = { bar: {} };
+			var staticAccessors = { bar: { configurable: true } };
 
 			staticAccessors.bar.get = function () { return 'baz' };
 
diff --git a/test/samples/classes.js b/test/samples/classes.js
index f33d3dd..4d5ff09 100644
--- a/test/samples/classes.js
+++ b/test/samples/classes.js
@@ -447,8 +447,8 @@ module.exports = [
 				this.radius = radius;
 			};
 
-			var prototypeAccessors = { area: {} };
-			var staticAccessors = { description: {} };
+			var prototypeAccessors = { area: { configurable: true } };
+			var staticAccessors = { description: { configurable: true } };
 
 			prototypeAccessors.area.get = function () {
 				return Math.PI * Math.pow( this.radius, 2 );
@@ -500,8 +500,8 @@ module.exports = [
 				Circle.prototype = Object.create( Shape && Shape.prototype );
 				Circle.prototype.constructor = Circle;
 
-				var prototypeAccessors = { area: {} };
-				var staticAccessors = { description: {} };
+				var prototypeAccessors = { area: { configurable: true } };
+				var staticAccessors = { description: { configurable: true } };
 
 				prototypeAccessors.area.get = function () {
 					return Math.PI * Math.pow( this.radius, 2 );
@@ -803,7 +803,7 @@ module.exports = [
 		output: `
 			var Foo = function Foo () {};
 
-			var staticAccessors = { bar: {} };
+			var staticAccessors = { bar: { configurable: true } };
 
 			staticAccessors.bar.get = function () { return 'baz' };