Fix turning division operator into line comment in compact mode (#7131)

This commit is contained in:
Fabian Streitel 2017-12-29 15:11:35 +01:00 committed by Brian Ng
parent 2297e2d764
commit 3956b3ee0e
5 changed files with 10 additions and 1 deletions

View File

@ -116,7 +116,10 @@ export default class Printer {
*/
word(str: string): void {
if (this._endsWithWord) this._space();
// prevent concatenating words and creating // comment out of division and regex
if (this._endsWithWord || (this.endsWith("/") && str.indexOf("/") === 0)) {
this._space();
}
this._maybeAddAuxComment();
this._append(str);

View File

@ -0,0 +1,2 @@
var a = 1 / /*c*/ v / //c2
v;

View File

@ -0,0 +1,2 @@
var a=1/ /*c*/v/ //c2
v;

View File

@ -0,0 +1 @@
var a = 4 / /2/.source;

View File

@ -0,0 +1 @@
var a=4/ /2/.source;