Page MenuHomePhabricator

ES7 class properties minification bug
Closed, DuplicatePublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • Try to minify this. Run it in your console too to verify input and output.
				class Robot {
					/** @type {String} */
					type = "Astromech Droid";
					constructor() {
						this.id = 1;
					}
					name = "R2D2"
					properties = {}
				}

				var robot = new Robot()
				console.log( robot.type )
				console.log( robot.id )
				console.log( robot.name )
				console.log( robot.properties )

What happens?:

  • Minifies to
class Robot{type="Astromech Droid";constructor(){this.id=1;}name="R2D2"properties={}}var robot=new Robot()
console.log(robot.type)
console.log(robot.id)
console.log(robot.name)
console.log(robot.properties)
  • Console output is: "Uncaught SyntaxError: Unexpected identifier 'properties'"

What should have happened instead?:

  • should have included a semicolon between name="R2D2"properties={}

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Unit test I started writing that ended up catching this. A slimmed down version can be included in the patch if it's helpful.

JavaScriptMinifierTest.php, line 297

			'ES7 class properties' => [
				<<<JAVASCRIPT
				class Robot {
					/** @type {String} */
					type = "Astromech Droid";
					constructor() {
						this.id = 1;
					}
					name = "R2D2"
					properties = {}
				}

				var robot = new Robot()
				console.log( robot.type )
				console.log( robot.id )
				console.log( robot.name )
				console.log( robot.properties )
JAVASCRIPT
				,
				"class Robot{type=\"Astromech Droid\";constructor(){this.id=1;}name=\"R2D2\";properties={}}var robot=new Robot()\nconsole.log(robot.type)\nconsole.log(robot.id)\nconsole.log(robot.name)\nconsole.log(robot.properties)"
			],

Hmm. The list of features by JS version I was consulting had class properties as part of ES7. I guess it was inaccurate though. I'll try switching to this reference. Thanks for catching.