From 18afadec61917abf87648ac833e5c884603b6f32 Mon Sep 17 00:00:00 2001 From: Lucas Duailibe Date: Thu, 7 Dec 2017 10:24:59 -0200 Subject: [PATCH] Only prevent lone `get` and `set` if property has no value --- src/printer.js | 1 + .../no-semi/__snapshots__/jsfmt.spec.js.snap | 150 ++++++++++++------ tests/no-semi/no-semi.js | 25 ++- 3 files changed, 120 insertions(+), 56 deletions(-) diff --git a/src/printer.js b/src/printer.js index e17697614a62..74541bdfdc3a 100644 --- a/src/printer.js +++ b/src/printer.js @@ -4812,6 +4812,7 @@ function classPropMayCauseASIProblems(path) { // so isn't properly tested yet. if ( (name === "static" || name === "get" || name === "set") && + !node.value && !node.typeAnnotation ) { return true; diff --git a/tests/no-semi/__snapshots__/jsfmt.spec.js.snap b/tests/no-semi/__snapshots__/jsfmt.spec.js.snap index b9754ea02f0f..b22f823bf7ce 100644 --- a/tests/no-semi/__snapshots__/jsfmt.spec.js.snap +++ b/tests/no-semi/__snapshots__/jsfmt.spec.js.snap @@ -409,14 +409,23 @@ class X {} [1, 2, 3].forEach(fn) // static; // The semicolon *is* necessary // x(){} // } -// class C { -// get; // The semicolon *is* necessary -// x(){} -// } -// class C { -// set; // The semicolon *is* necessary -// x(){} -// } + +class C { + get; // The semicolon *is* necessary + x(){} +} +class C { + get = () => {}; // The semicolon is *not* necessary + x(){} +} +class C { + set; // The semicolon *is* necessary + x(){} +} +class C { + set = () => {}; // The semicolon is *not* necessary + x(){} +} // don't semicolon if it doesn't start statement @@ -577,14 +586,23 @@ class X {} // static; // The semicolon *is* necessary // x(){} // } -// class C { -// get; // The semicolon *is* necessary -// x(){} -// } -// class C { -// set; // The semicolon *is* necessary -// x(){} -// } + +class C { + get; // The semicolon *is* necessary + x() {} +} +class C { + get = () => {}; // The semicolon is *not* necessary + x() {} +} +class C { + set; // The semicolon *is* necessary + x() {} +} +class C { + set = () => {}; // The semicolon is *not* necessary + x() {} +} // don't semicolon if it doesn't start statement @@ -734,14 +752,23 @@ class X {} [1, 2, 3].forEach(fn) // static; // The semicolon *is* necessary // x(){} // } -// class C { -// get; // The semicolon *is* necessary -// x(){} -// } -// class C { -// set; // The semicolon *is* necessary -// x(){} -// } + +class C { + get; // The semicolon *is* necessary + x(){} +} +class C { + get = () => {}; // The semicolon is *not* necessary + x(){} +} +class C { + set; // The semicolon *is* necessary + x(){} +} +class C { + set = () => {}; // The semicolon is *not* necessary + x(){} +} // don't semicolon if it doesn't start statement @@ -902,14 +929,23 @@ class X {} // static; // The semicolon *is* necessary // x(){} // } -// class C { -// get; // The semicolon *is* necessary -// x(){} -// } -// class C { -// set; // The semicolon *is* necessary -// x(){} -// } + +class C { + get; // The semicolon *is* necessary + x() {} +} +class C { + get = () => {} // The semicolon is *not* necessary + x() {} +} +class C { + set; // The semicolon *is* necessary + x() {} +} +class C { + set = () => {} // The semicolon is *not* necessary + x() {} +} // don't semicolon if it doesn't start statement @@ -1059,14 +1095,23 @@ class X {} [1, 2, 3].forEach(fn) // static; // The semicolon *is* necessary // x(){} // } -// class C { -// get; // The semicolon *is* necessary -// x(){} -// } -// class C { -// set; // The semicolon *is* necessary -// x(){} -// } + +class C { + get; // The semicolon *is* necessary + x(){} +} +class C { + get = () => {}; // The semicolon is *not* necessary + x(){} +} +class C { + set; // The semicolon *is* necessary + x(){} +} +class C { + set = () => {}; // The semicolon is *not* necessary + x(){} +} // don't semicolon if it doesn't start statement @@ -1227,14 +1272,23 @@ class X {} // static; // The semicolon *is* necessary // x(){} // } -// class C { -// get; // The semicolon *is* necessary -// x(){} -// } -// class C { -// set; // The semicolon *is* necessary -// x(){} -// } + +class C { + get; // The semicolon *is* necessary + x() {} +} +class C { + get = () => {} // The semicolon is *not* necessary + x() {} +} +class C { + set; // The semicolon *is* necessary + x() {} +} +class C { + set = () => {} // The semicolon is *not* necessary + x() {} +} // don't semicolon if it doesn't start statement diff --git a/tests/no-semi/no-semi.js b/tests/no-semi/no-semi.js index 526025e02664..91b370a4eb9f 100644 --- a/tests/no-semi/no-semi.js +++ b/tests/no-semi/no-semi.js @@ -28,14 +28,23 @@ class X {} [1, 2, 3].forEach(fn) // static; // The semicolon *is* necessary // x(){} // } -// class C { -// get; // The semicolon *is* necessary -// x(){} -// } -// class C { -// set; // The semicolon *is* necessary -// x(){} -// } + +class C { + get; // The semicolon *is* necessary + x(){} +} +class C { + get = () => {}; // The semicolon is *not* necessary + x(){} +} +class C { + set; // The semicolon *is* necessary + x(){} +} +class C { + set = () => {}; // The semicolon is *not* necessary + x(){} +} // don't semicolon if it doesn't start statement