From c7093cb3e4a02dd3e8510eb3a4d9911737134b2c Mon Sep 17 00:00:00 2001 From: Lucas Duailibe Date: Sat, 13 Oct 2018 20:03:51 -0300 Subject: [PATCH] Add ASI protection for TSNonNullExpression (#5262) --- src/language-js/printer-estree.js | 3 ++- .../__snapshots__/jsfmt.spec.js.snap | 22 +++++++++++++++++++ tests/no-semi-typescript/non-null.ts | 3 +++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/no-semi-typescript/non-null.ts diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 5d56bda8..068df10e 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -5461,7 +5461,8 @@ function hasNakedLeftSide(node) { node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "BindExpression" || - (node.type === "UpdateExpression" && !node.prefix) + (node.type === "UpdateExpression" && !node.prefix) || + node.type === "TSNonNullExpression" ); } diff --git a/tests/no-semi-typescript/__snapshots__/jsfmt.spec.js.snap b/tests/no-semi-typescript/__snapshots__/jsfmt.spec.js.snap index b75f2ba1..73324dfb 100644 --- a/tests/no-semi-typescript/__snapshots__/jsfmt.spec.js.snap +++ b/tests/no-semi-typescript/__snapshots__/jsfmt.spec.js.snap @@ -49,3 +49,25 @@ class A { } `; + +exports[`non-null.ts - typescript-verify 1`] = ` +// the 2nd line needs ASI protection +const el = ReactDOM.findDOMNode(ref) +;(el as HTMLElement)!.style.cursor = 'pointer' +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// the 2nd line needs ASI protection +const el = ReactDOM.findDOMNode(ref); +(el as HTMLElement)!.style.cursor = "pointer"; + +`; + +exports[`non-null.ts - typescript-verify 2`] = ` +// the 2nd line needs ASI protection +const el = ReactDOM.findDOMNode(ref) +;(el as HTMLElement)!.style.cursor = 'pointer' +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// the 2nd line needs ASI protection +const el = ReactDOM.findDOMNode(ref) +;(el as HTMLElement)!.style.cursor = "pointer" + +`; diff --git a/tests/no-semi-typescript/non-null.ts b/tests/no-semi-typescript/non-null.ts new file mode 100644 index 00000000..df503c0d --- /dev/null +++ b/tests/no-semi-typescript/non-null.ts @@ -0,0 +1,3 @@ +// the 2nd line needs ASI protection +const el = ReactDOM.findDOMNode(ref) +;(el as HTMLElement)!.style.cursor = 'pointer'