From 3e05f210bb4a1cf1175fb8a4cedade94b76429b7 Mon Sep 17 00:00:00 2001 From: Toru Kobayashi Date: Sat, 29 Sep 2018 01:51:34 +0900 Subject: [PATCH] fix(js): quote property name as es5 compatible (#5157) --- src/language-js/printer-estree.js | 2 +- tests/quotes/__snapshots__/jsfmt.spec.js.snap | 30 +++++++++++++++++++ tests/quotes/objects.js | 5 ++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/quotes/objects.js diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 04136c590..e1a46343f 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -28,7 +28,7 @@ const { isNextLineEmptyAfterIndex, getNextNonSpaceNonCommentCharacterIndex } = require("../common/util-shared"); -const isIdentifierName = require("esutils").keyword.isIdentifierNameES6; +const isIdentifierName = require("esutils").keyword.isIdentifierNameES5; const embed = require("./embed"); const clean = require("./clean"); const insertPragma = require("./pragma").insertPragma; diff --git a/tests/quotes/__snapshots__/jsfmt.spec.js.snap b/tests/quotes/__snapshots__/jsfmt.spec.js.snap index 03942bc34..6c1a1817f 100644 --- a/tests/quotes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/quotes/__snapshots__/jsfmt.spec.js.snap @@ -30,6 +30,36 @@ function b(object, key) { `; +exports[`objects.js - flow-verify 1`] = ` +const obj = { + 'a': true, + b: true, + "𐊧": true, +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const obj = { + a: true, + b: true, + "𐊧": true +}; + +`; + +exports[`objects.js - flow-verify 2`] = ` +const obj = { + 'a': true, + b: true, + "𐊧": true, +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const obj = { + a: true, + b: true, + '𐊧': true +}; + +`; + exports[`strings.js - flow-verify 1`] = ` // Prevent strings from being parsed as directives // See https://github.com/prettier/prettier/pull/1560#issue-227225960 diff --git a/tests/quotes/objects.js b/tests/quotes/objects.js new file mode 100644 index 000000000..53a8fe998 --- /dev/null +++ b/tests/quotes/objects.js @@ -0,0 +1,5 @@ +const obj = { + 'a': true, + b: true, + "𐊧": true, +}