From 553e9bb1ac528dd8d44bfd8c621d2002382f9d61 Mon Sep 17 00:00:00 2001 From: Ika Date: Mon, 21 May 2018 18:57:30 +0800 Subject: [PATCH] fix(typescript): preserve quoted class property (#4517) --- src/language-js/printer-estree.js | 3 ++- .../typescript_class/__snapshots__/jsfmt.spec.js.snap | 11 +++++++++++ tests/typescript_class/quoted-property.ts | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/typescript_class/quoted-property.ts diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 19ff14d1..09a78b2f 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -3247,7 +3247,8 @@ function printPropertyKey(path, options, print) { isStringLiteral(key) && isIdentifierName(key.value) && !node.computed && - options.parser !== "json" + options.parser !== "json" && + !(options.parser === "typescript" && node.type === "ClassProperty") ) { // 'a' -> a return path.call( diff --git a/tests/typescript_class/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_class/__snapshots__/jsfmt.spec.js.snap index 861224dd..2648f4c5 100644 --- a/tests/typescript_class/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_class/__snapshots__/jsfmt.spec.js.snap @@ -171,3 +171,14 @@ class X { } `; + +exports[`quoted-property.ts 1`] = ` +class User { + "username": string; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +class User { + "username": string; +} + +`; diff --git a/tests/typescript_class/quoted-property.ts b/tests/typescript_class/quoted-property.ts new file mode 100644 index 00000000..d9755ac8 --- /dev/null +++ b/tests/typescript_class/quoted-property.ts @@ -0,0 +1,3 @@ +class User { + "username": string; +}