Fix turning division operator into line comment in compact mode (#7131)
This commit is contained in:
parent
2297e2d764
commit
3956b3ee0e
@ -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);
|
||||
|
||||
2
packages/babel-generator/test/fixtures/compact/comment-after-division/actual.js
vendored
Normal file
2
packages/babel-generator/test/fixtures/compact/comment-after-division/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
var a = 1 / /*c*/ v / //c2
|
||||
v;
|
||||
2
packages/babel-generator/test/fixtures/compact/comment-after-division/expected.js
vendored
Normal file
2
packages/babel-generator/test/fixtures/compact/comment-after-division/expected.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
var a=1/ /*c*/v/ //c2
|
||||
v;
|
||||
1
packages/babel-generator/test/fixtures/compact/regex-after-division/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/compact/regex-after-division/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var a = 4 / /2/.source;
|
||||
1
packages/babel-generator/test/fixtures/compact/regex-after-division/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/compact/regex-after-division/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var a=4/ /2/.source;
|
||||
Loading…
x
Reference in New Issue
Block a user