From 9aa1e78caa1c9397982f59a081f1e9bdd21b10c8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2020 06:58:46 +0000 Subject: [PATCH 01/14] Build(deps): Bump @babel/parser from 7.12.3 to 7.12.5 Bumps [@babel/parser](https://github.com/babel/babel/tree/HEAD/packages/babel-parser) from 7.12.3 to 7.12.5. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.12.5/packages/babel-parser) Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 94875c42634b..9ccaf159e70e 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "dependencies": { "@angular/compiler": "10.2.2", "@babel/code-frame": "7.10.4", - "@babel/parser": "7.12.3", + "@babel/parser": "7.12.5", "@glimmer/syntax": "0.62.4", "@iarna/toml": "2.2.5", "@typescript-eslint/typescript-estree": "3.10.1", diff --git a/yarn.lock b/yarn.lock index d348230b2a82..10fef9ae286c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -277,10 +277,10 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/parser@7.12.3", "@babel/parser@^7.1.0", "@babel/parser@^7.10.4", "@babel/parser@^7.12.1", "@babel/parser@^7.12.3", "@babel/parser@^7.7.0": - version "7.12.3" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.3.tgz#a305415ebe7a6c7023b40b5122a0662d928334cd" - integrity sha512-kFsOS0IbsuhO5ojF8Hc8z/8vEIOkylVBrjiZUbLTE3XFe0Qi+uu6HjzQixkFaqr0ZPAMZcBVxEwmsnsLPZ2Xsw== +"@babel/parser@7.12.5", "@babel/parser@^7.1.0", "@babel/parser@^7.10.4", "@babel/parser@^7.12.1", "@babel/parser@^7.12.3", "@babel/parser@^7.7.0": + version "7.12.5" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.5.tgz#b4af32ddd473c0bfa643bd7ff0728b8e71b81ea0" + integrity sha512-FVM6RZQ0mn2KCf1VUED7KepYeUWoVShczewOCfm3nzoBybaih51h+sYVVGthW9M6lPByEPTQf+xm27PBdlpwmQ== "@babel/plugin-proposal-async-generator-functions@^7.12.1": version "7.12.1" From 292c53c98940f771501c5b1e99fe114afb197e68 Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Fri, 6 Nov 2020 10:55:02 +0900 Subject: [PATCH 02/14] Add tests for babel/babel#12224 --- .../__snapshots__/jsfmt.spec.js.snap | 2 ++ tests/js/babel-plugins/module-string-names.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 20 ++++++++++++++++++- ...names.js => module-string-names-export.js} | 0 .../module-string-names-import.js | 3 +++ .../js/__snapshots__/jsfmt.spec.js.snap | 8 -------- .../errors/js/module-string-name-import.js | 2 -- 7 files changed, 25 insertions(+), 11 deletions(-) rename tests/js/module-string-names/{module-string-names.js => module-string-names-export.js} (100%) create mode 100644 tests/js/module-string-names/module-string-names-import.js delete mode 100644 tests/misc/errors/js/module-string-name-import.js diff --git a/tests/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap b/tests/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap index 26bfa6f5f464..41582d2342a6 100644 --- a/tests/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap @@ -851,9 +851,11 @@ parsers: ["babel", "babel-ts", "babel-flow"] printWidth: 80 | printWidth =====================================input====================================== +import { "😄" as smile } from "./emojis.js"; export { smile as "😄" } from "./emojis.js"; =====================================output===================================== +import { "😄" as smile } from "./emojis.js"; export { smile as "😄" } from "./emojis.js"; ================================================================================ diff --git a/tests/js/babel-plugins/module-string-names.js b/tests/js/babel-plugins/module-string-names.js index 631c04f79793..2bdb75fb7037 100644 --- a/tests/js/babel-plugins/module-string-names.js +++ b/tests/js/babel-plugins/module-string-names.js @@ -1 +1,2 @@ +import { "😄" as smile } from "./emojis.js"; export { smile as "😄" } from "./emojis.js"; diff --git a/tests/js/module-string-names/__snapshots__/jsfmt.spec.js.snap b/tests/js/module-string-names/__snapshots__/jsfmt.spec.js.snap index b2f9e1c02d49..d94cc0445628 100644 --- a/tests/js/module-string-names/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/module-string-names/__snapshots__/jsfmt.spec.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`module-string-names.js format 1`] = ` +exports[`module-string-names-export.js format 1`] = ` ====================================options===================================== parsers: ["babel"] printWidth: 80 @@ -30,3 +30,21 @@ export { "smile" } from "./emojis.js"; ================================================================================ `; + +exports[`module-string-names-import.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +import { "default" as quotation } from "Confucius"; +import { "foo" as bar, "default" as qux } from "module-a"; +import { "學而時習之,不亦說乎?" as quotation } from "Confucius"; + +=====================================output===================================== +import { "default" as quotation } from "Confucius"; +import { "foo" as bar, "default" as qux } from "module-a"; +import { "學而時習之,不亦說乎?" as quotation } from "Confucius"; + +================================================================================ +`; diff --git a/tests/js/module-string-names/module-string-names.js b/tests/js/module-string-names/module-string-names-export.js similarity index 100% rename from tests/js/module-string-names/module-string-names.js rename to tests/js/module-string-names/module-string-names-export.js diff --git a/tests/js/module-string-names/module-string-names-import.js b/tests/js/module-string-names/module-string-names-import.js new file mode 100644 index 000000000000..84ca0d81bcec --- /dev/null +++ b/tests/js/module-string-names/module-string-names-import.js @@ -0,0 +1,3 @@ +import { "default" as quotation } from "Confucius"; +import { "foo" as bar, "default" as qux } from "module-a"; +import { "學而時習之,不亦說乎?" as quotation } from "Confucius"; diff --git a/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap b/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap index 5354a8b1c146..d6f2725153ea 100644 --- a/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap @@ -25,14 +25,6 @@ exports[`module-attributes.js error test 1`] = ` 2 | " `; -exports[`module-string-name-import.js error test 1`] = ` -"Unexpected token (2:10) - 1 | // https://github.com/babel/babel/issues/12209 -> 2 | import { \\"foo\\" as foo } from \\"module-a\\"; - | ^ - 3 | " -`; - exports[`no-for-in-init-concise-binary-in.js error test 1`] = ` "Unexpected token, expected \\")\\" (3:18) 1 | // https://github.com/babel/babel/pull/11931 diff --git a/tests/misc/errors/js/module-string-name-import.js b/tests/misc/errors/js/module-string-name-import.js deleted file mode 100644 index 53167a0d5443..000000000000 --- a/tests/misc/errors/js/module-string-name-import.js +++ /dev/null @@ -1,2 +0,0 @@ -// https://github.com/babel/babel/issues/12209 -import { "foo" as foo } from "module-a"; From 1a2216dcabbf58e055aaeac82ffe6f01e705034f Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Fri, 6 Nov 2020 11:02:39 +0900 Subject: [PATCH 03/14] Add tests for babel/babel#12281 --- .../__snapshots__/jsfmt.spec.js.snap | 14 ++++++++++++++ .../import-assertions-without-from.js | 1 + tests/js/import-assertions/jsfmt.spec.js | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 tests/js/import-assertions/import-assertions-without-from.js diff --git a/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap b/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap index df01ffc7403d..4ea0898ac071 100644 --- a/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap @@ -42,6 +42,20 @@ import json from "./foo.json" assert { type: "json" }; ================================================================================ `; +exports[`import-assertions-without-from.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +import "foo" assert { type: "json" } + +=====================================output===================================== +import "foo" assert { type: "json" }; + +================================================================================ +`; + exports[`not-import-assertions.js format 1`] = ` ====================================options===================================== parsers: ["babel"] diff --git a/tests/js/import-assertions/import-assertions-without-from.js b/tests/js/import-assertions/import-assertions-without-from.js new file mode 100644 index 000000000000..daf38156ebb5 --- /dev/null +++ b/tests/js/import-assertions/import-assertions-without-from.js @@ -0,0 +1 @@ +import "foo" assert { type: "json" } diff --git a/tests/js/import-assertions/jsfmt.spec.js b/tests/js/import-assertions/jsfmt.spec.js index 7599ddea9386..9430e1f1a4d7 100644 --- a/tests/js/import-assertions/jsfmt.spec.js +++ b/tests/js/import-assertions/jsfmt.spec.js @@ -4,11 +4,13 @@ run_spec(__dirname, ["babel"], { "import-assertions-dynamic.js", "import-assertions-multi-types.js", "import-assertions-static.js", + "import-assertions-without-from.js", ], meriyah: [ "import-assertions-dynamic.js", "import-assertions-multi-types.js", "import-assertions-static.js", + "import-assertions-without-from.js", ], }, }); From 08193c5104ebf72c8fe2fb3257ae7ce0af5bf232 Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Fri, 6 Nov 2020 11:04:43 +0900 Subject: [PATCH 04/14] Add test for babel/babel#12249 --- .../__snapshots__/jsfmt.spec.js.snap | 18 ++++++++++++++++++ .../import-assertions-for-export.js | 3 +++ tests/js/import-assertions/jsfmt.spec.js | 2 ++ 3 files changed, 23 insertions(+) create mode 100644 tests/js/import-assertions/import-assertions-for-export.js diff --git a/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap b/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap index 4ea0898ac071..04928d341594 100644 --- a/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap @@ -14,6 +14,24 @@ import("./foo.json", { assert: { type: "json" } }); ================================================================================ `; +exports[`import-assertions-for-export.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +export { foo2 } from "foo.json" assert { type: "json" }; +export * from "foo.json" assert { type: "json" }; +export * as foo3 from "foo.json" assert { type: "json" }; + +=====================================output===================================== +export { foo2 } from "foo.json"; +export * from "foo.json"; +export * as foo3 from "foo.json"; + +================================================================================ +`; + exports[`import-assertions-multi-types.js format 1`] = ` ====================================options===================================== parsers: ["babel"] diff --git a/tests/js/import-assertions/import-assertions-for-export.js b/tests/js/import-assertions/import-assertions-for-export.js new file mode 100644 index 000000000000..dd9640ec20ad --- /dev/null +++ b/tests/js/import-assertions/import-assertions-for-export.js @@ -0,0 +1,3 @@ +export { foo2 } from "foo.json" assert { type: "json" }; +export * from "foo.json" assert { type: "json" }; +export * as foo3 from "foo.json" assert { type: "json" }; diff --git a/tests/js/import-assertions/jsfmt.spec.js b/tests/js/import-assertions/jsfmt.spec.js index 9430e1f1a4d7..ccbf94dcb8b6 100644 --- a/tests/js/import-assertions/jsfmt.spec.js +++ b/tests/js/import-assertions/jsfmt.spec.js @@ -5,12 +5,14 @@ run_spec(__dirname, ["babel"], { "import-assertions-multi-types.js", "import-assertions-static.js", "import-assertions-without-from.js", + "import-assertions-for-export.js", ], meriyah: [ "import-assertions-dynamic.js", "import-assertions-multi-types.js", "import-assertions-static.js", "import-assertions-without-from.js", + "import-assertions-for-export.js", ], }, }); From d7e3214f47dc6a91396c12f5cf2da559e8e90984 Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Fri, 6 Nov 2020 11:06:16 +0900 Subject: [PATCH 05/14] Add test for babel/babel#12264 --- tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap | 7 +++++++ .../errors/js/import-assertions-for-export-without-from.js | 1 + 2 files changed, 8 insertions(+) create mode 100644 tests/misc/errors/js/import-assertions-for-export-without-from.js diff --git a/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap b/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap index d6f2725153ea..8c01590d2d70 100644 --- a/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,13 @@ exports[`html-like-comments.js error test 1`] = ` 6 | " `; +exports[`import-assertions-for-export-without-from.js error test 1`] = ` +"Unexpected token, expected \\";\\" (1:16) +> 1 | export { foo } assert { type: \\"json\\" }; + | ^ + 2 | " +`; + exports[`import-assertions-with-parens.js error test 1`] = ` "Unexpected token (1:19) > 1 | import \\"x\\" assert ({type: 'json'}); diff --git a/tests/misc/errors/js/import-assertions-for-export-without-from.js b/tests/misc/errors/js/import-assertions-for-export-without-from.js new file mode 100644 index 000000000000..bf54727d56a0 --- /dev/null +++ b/tests/misc/errors/js/import-assertions-for-export-without-from.js @@ -0,0 +1 @@ +export { foo } assert { type: "json" }; From 30099fa981d78e63b32a96565e73a33152eeffa0 Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Fri, 6 Nov 2020 11:29:23 +0900 Subject: [PATCH 06/14] Add tests for babel/babel#12254 --- .../__snapshots__/jsfmt.spec.js.snap | 41 +++++++++++++++++++ tests/js/reserved-word/interfaces.js | 14 +++++++ tests/js/reserved-word/jsfmt.spec.js | 1 + 3 files changed, 56 insertions(+) create mode 100644 tests/js/reserved-word/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/js/reserved-word/interfaces.js create mode 100644 tests/js/reserved-word/jsfmt.spec.js diff --git a/tests/js/reserved-word/__snapshots__/jsfmt.spec.js.snap b/tests/js/reserved-word/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..f0f1cb3543b7 --- /dev/null +++ b/tests/js/reserved-word/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,41 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`interfaces.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +interface = "foo"; +interface + 3; +interface(); +class interface {} +interface ? true : false; +function interface() {} +import interface from "foo"; +foo.interface; +interface.foo; +new interface(); +({ interface: "foo" }); +(interface, "foo"); +void interface; +const interface = "foo"; + +=====================================output===================================== +interface = "foo"; +interface + 3; +interface(); +class interface {} +interface ? true : false; +function interface() {} +import interface from "foo"; +foo.interface; +interface.foo; +new interface(); +({ interface: "foo" }); +interface, "foo"; +void interface; +const interface = "foo"; + +================================================================================ +`; diff --git a/tests/js/reserved-word/interfaces.js b/tests/js/reserved-word/interfaces.js new file mode 100644 index 000000000000..2ce057e27fd8 --- /dev/null +++ b/tests/js/reserved-word/interfaces.js @@ -0,0 +1,14 @@ +interface = "foo"; +interface + 3; +interface(); +class interface {} +interface ? true : false; +function interface() {} +import interface from "foo"; +foo.interface; +interface.foo; +new interface(); +({ interface: "foo" }); +(interface, "foo"); +void interface; +const interface = "foo"; diff --git a/tests/js/reserved-word/jsfmt.spec.js b/tests/js/reserved-word/jsfmt.spec.js new file mode 100644 index 000000000000..0fab4456dc8e --- /dev/null +++ b/tests/js/reserved-word/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["babel"], { errors: { espree: true, meriyah: true } }); From f934269eaf18d51804813d8d6043036e79c21798 Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Fri, 6 Nov 2020 11:33:45 +0900 Subject: [PATCH 07/14] Add tests for babel/babel#12221 --- .../errors/babel-ts/__snapshots__/jsfmt.spec.js.snap | 11 +++++++++++ tests/misc/errors/babel-ts/type-annotation-in-jsx.tsx | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 tests/misc/errors/babel-ts/type-annotation-in-jsx.tsx diff --git a/tests/misc/errors/babel-ts/__snapshots__/jsfmt.spec.js.snap b/tests/misc/errors/babel-ts/__snapshots__/jsfmt.spec.js.snap index 63d4dde0ac58..e5c3104547cb 100644 --- a/tests/misc/errors/babel-ts/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/errors/babel-ts/__snapshots__/jsfmt.spec.js.snap @@ -13,3 +13,14 @@ exports[`type-annotation-func.ts error test 1`] = ` | ^ 2 | " `; + +exports[`type-annotation-in-jsx.tsx error test 1`] = ` +"Did not expect a type annotation here. (3:22) + 1 | function Foo() { + 2 | return ( +> 3 |
+ | ^ + 4 | ); + 5 | } + 6 | " +`; diff --git a/tests/misc/errors/babel-ts/type-annotation-in-jsx.tsx b/tests/misc/errors/babel-ts/type-annotation-in-jsx.tsx new file mode 100644 index 000000000000..ae4343ec3e21 --- /dev/null +++ b/tests/misc/errors/babel-ts/type-annotation-in-jsx.tsx @@ -0,0 +1,5 @@ +function Foo() { + return ( +
+ ); +} From c4d10b5a7da533ee98fc2d2a0f167eaf345cd299 Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Fri, 6 Nov 2020 12:32:34 +0900 Subject: [PATCH 08/14] Add tests for babel/babel#12267 --- .../__snapshots__/jsfmt.spec.js.snap | 14 ++++++++++++++ tests/js/binary-expressions/jsfmt.spec.js | 4 +++- tests/js/binary-expressions/like-regexp.js | 1 + tests/js/label/__snapshots__/jsfmt.spec.js.snap | 17 +++++++++++++++++ tests/js/label/block-statement-and-regexp.js | 1 + 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/js/binary-expressions/like-regexp.js create mode 100644 tests/js/label/block-statement-and-regexp.js diff --git a/tests/js/binary-expressions/__snapshots__/jsfmt.spec.js.snap b/tests/js/binary-expressions/__snapshots__/jsfmt.spec.js.snap index 7599f115f1e4..f13fc2fbd244 100644 --- a/tests/js/binary-expressions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/binary-expressions/__snapshots__/jsfmt.spec.js.snap @@ -740,6 +740,20 @@ printWidth: 80 ================================================================================ `; +exports[`like-regexp.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +0 ? a : { b : 1 }/2; + +=====================================output===================================== +0 ? a : { b: 1 } / 2; + +================================================================================ +`; + exports[`math.js format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] diff --git a/tests/js/binary-expressions/jsfmt.spec.js b/tests/js/binary-expressions/jsfmt.spec.js index eb85eda6bd02..7872139988cb 100644 --- a/tests/js/binary-expressions/jsfmt.spec.js +++ b/tests/js/binary-expressions/jsfmt.spec.js @@ -1 +1,3 @@ -run_spec(__dirname, ["babel", "flow", "typescript"]); +run_spec(__dirname, ["babel", "flow", "typescript"], { + errors: { espree: ["like-regexp.js"] }, +}); diff --git a/tests/js/binary-expressions/like-regexp.js b/tests/js/binary-expressions/like-regexp.js new file mode 100644 index 000000000000..b424d657d3b4 --- /dev/null +++ b/tests/js/binary-expressions/like-regexp.js @@ -0,0 +1 @@ +0 ? a : { b : 1 }/2; diff --git a/tests/js/label/__snapshots__/jsfmt.spec.js.snap b/tests/js/label/__snapshots__/jsfmt.spec.js.snap index 0eb99749d530..d012d92b6198 100644 --- a/tests/js/label/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/label/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,22 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`block-statement-and-regexp.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +a : { b : 1 }/2/; + +=====================================output===================================== +a: { + b: 1; +} +/2/; + +================================================================================ +`; + exports[`comment.js format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] diff --git a/tests/js/label/block-statement-and-regexp.js b/tests/js/label/block-statement-and-regexp.js new file mode 100644 index 000000000000..b69bf681e7d9 --- /dev/null +++ b/tests/js/label/block-statement-and-regexp.js @@ -0,0 +1 @@ +a : { b : 1 }/2/; From b6a58654ffccf54a81707aaccc9299eeea451a21 Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Fri, 6 Nov 2020 12:56:09 +0900 Subject: [PATCH 09/14] Add tests for babel/babel#12227 --- .../declare/__snapshots__/jsfmt.spec.js.snap | 12 +++++ tests/typescript/declare/declare_interface.ts | 6 +++ .../__snapshots__/jsfmt.spec.js.snap | 45 +++++++++++++++++++ .../interface/pattern-parameters.ts | 5 +++ .../__snapshots__/jsfmt.spec.js.snap | 23 ++++++++++ tests/typescript/type-alias/jsfmt.spec.js | 1 + .../type-alias/pattern-parameter.ts | 5 +++ 7 files changed, 97 insertions(+) create mode 100644 tests/typescript/interface/pattern-parameters.ts create mode 100644 tests/typescript/type-alias/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/typescript/type-alias/jsfmt.spec.js create mode 100644 tests/typescript/type-alias/pattern-parameter.ts diff --git a/tests/typescript/declare/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/declare/__snapshots__/jsfmt.spec.js.snap index 9f673f0da2f3..fe39e136e522 100644 --- a/tests/typescript/declare/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/declare/__snapshots__/jsfmt.spec.js.snap @@ -110,11 +110,23 @@ declare interface Dictionary { [index: string]: T } +declare interface B { + foo([]?): void; + bar({}, []?): any; + baz(a: string, b: number, []?): void; +} + =====================================output===================================== declare interface Dictionary { [index: string]: T; } +declare interface B { + foo([]?): void; + bar({}, []?): any; + baz(a: string, b: number, []?): void; +} + ================================================================================ `; diff --git a/tests/typescript/declare/declare_interface.ts b/tests/typescript/declare/declare_interface.ts index 77a9962cd03a..14e4bfe6177d 100644 --- a/tests/typescript/declare/declare_interface.ts +++ b/tests/typescript/declare/declare_interface.ts @@ -1,3 +1,9 @@ declare interface Dictionary { [index: string]: T } + +declare interface B { + foo([]?): void; + bar({}, []?): any; + baz(a: string, b: number, []?): void; +} diff --git a/tests/typescript/interface/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/interface/__snapshots__/jsfmt.spec.js.snap index 393512f5267e..6c3b914cd00c 100644 --- a/tests/typescript/interface/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/interface/__snapshots__/jsfmt.spec.js.snap @@ -844,6 +844,51 @@ export interface ThirdVeryLongAndBoringInterfaceName ================================================================================ `; +exports[`pattern-parameters.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +interface B { + foo([]?): void; + bar({}, []?): any; + baz(a: string, b: number, []?): void; +} + +=====================================output===================================== +interface B { + foo([]?): void + bar({}, []?): any + baz(a: string, b: number, []?): void +} + +================================================================================ +`; + +exports[`pattern-parameters.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +interface B { + foo([]?): void; + bar({}, []?): any; + baz(a: string, b: number, []?): void; +} + +=====================================output===================================== +interface B { + foo([]?): void; + bar({}, []?): any; + baz(a: string, b: number, []?): void; +} + +================================================================================ +`; + exports[`separator.ts - {"semi":false} format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/typescript/interface/pattern-parameters.ts b/tests/typescript/interface/pattern-parameters.ts new file mode 100644 index 000000000000..f1cf8d0d3d73 --- /dev/null +++ b/tests/typescript/interface/pattern-parameters.ts @@ -0,0 +1,5 @@ +interface B { + foo([]?): void; + bar({}, []?): any; + baz(a: string, b: number, []?): void; +} diff --git a/tests/typescript/type-alias/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/type-alias/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..7f2c78b4eb82 --- /dev/null +++ b/tests/typescript/type-alias/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,23 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`pattern-parameter.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type C = { + foo([]?): void; + bar({}, []?): any; + baz(a: string, b: number, []?): void; +}; + +=====================================output===================================== +type C = { + foo([]?): void; + bar({}, []?): any; + baz(a: string, b: number, []?): void; +}; + +================================================================================ +`; diff --git a/tests/typescript/type-alias/jsfmt.spec.js b/tests/typescript/type-alias/jsfmt.spec.js new file mode 100644 index 000000000000..2ea3bb6eb2e4 --- /dev/null +++ b/tests/typescript/type-alias/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["typescript"]); diff --git a/tests/typescript/type-alias/pattern-parameter.ts b/tests/typescript/type-alias/pattern-parameter.ts new file mode 100644 index 000000000000..6880a5bff23a --- /dev/null +++ b/tests/typescript/type-alias/pattern-parameter.ts @@ -0,0 +1,5 @@ +type C = { + foo([]?): void; + bar({}, []?): any; + baz(a: string, b: number, []?): void; +}; From d70376e4cc26ab917108b3961c0584ef58962dce Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Fri, 6 Nov 2020 13:34:42 +0900 Subject: [PATCH 10/14] Support Import Assertions for re-export statement --- src/language-js/print/module.js | 13 ++++++++++++ src/language-js/printer-estree.js | 21 +++++++++++-------- .../__snapshots__/jsfmt.spec.js.snap | 6 +++--- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/language-js/print/module.js b/src/language-js/print/module.js index dc0f8ccf506d..7d264301427a 100644 --- a/src/language-js/print/module.js +++ b/src/language-js/print/module.js @@ -94,7 +94,20 @@ function printModuleSpecifiers(path, options, print) { return concat(parts); } +function printImportAssertions(path, options, print) { + const node = path.getNode(); + if (Array.isArray(node.assertions) && node.assertions.length !== 0) { + return concat([ + " assert { ", + join(", ", path.map(print, "assertions")), + " }", + ]); + } + return ""; +} + module.exports = { printModuleSource, printModuleSpecifiers, + printImportAssertions, }; diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 3f0fd94412ff..164c446cdee0 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -124,7 +124,11 @@ const { printMemberLookup, printBindExpressionCallee, } = require("./print/misc"); -const { printModuleSource, printModuleSpecifiers } = require("./print/module"); +const { + printModuleSource, + printModuleSpecifiers, + printImportAssertions, +} = require("./print/module"); const printTernaryOperator = require("./print/ternary"); const needsQuoteProps = new WeakMap(); @@ -847,7 +851,11 @@ function printPathNoParens(path, options, print, args) { parts.push(" as ", path.call(print, "exported")); } - parts.push(printModuleSource(path, options, print), semi); + parts.push( + printModuleSource(path, options, print), + printImportAssertions(path, options, print), + semi + ); return concat(parts); @@ -877,13 +885,7 @@ function printPathNoParens(path, options, print, args) { parts.push(" ", path.call(print, "source")); } - if (Array.isArray(n.assertions) && n.assertions.length !== 0) { - parts.push( - " assert { ", - join(", ", path.map(print, "assertions")), - " }" - ); - } + parts.push(printImportAssertions(path, options, print)); parts.push(semi); @@ -4146,6 +4148,7 @@ function printExportDeclaration(path, options, print) { parts.push(decl.exportKind === "type" ? "type " : ""); parts.push(printModuleSpecifiers(path, options, print)); parts.push(printModuleSource(path, options, print)); + parts.push(printImportAssertions(path, options, print)); parts.push(semi); } diff --git a/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap b/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap index 04928d341594..ae7cf028047e 100644 --- a/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap @@ -25,9 +25,9 @@ export * from "foo.json" assert { type: "json" }; export * as foo3 from "foo.json" assert { type: "json" }; =====================================output===================================== -export { foo2 } from "foo.json"; -export * from "foo.json"; -export * as foo3 from "foo.json"; +export { foo2 } from "foo.json" assert { type: "json" }; +export * from "foo.json" assert { type: "json" }; +export * as foo3 from "foo.json" assert { type: "json" }; ================================================================================ `; From 95b1f34852895c997a71ca86909c58c61456863b Mon Sep 17 00:00:00 2001 From: fisker Date: Fri, 6 Nov 2020 16:02:30 +0800 Subject: [PATCH 11/14] Apply `--no-bracket-spacing` --- src/language-js/print/module.js | 6 +- .../__snapshots__/jsfmt.spec.js.snap | 88 +++++++++++++++++++ .../import-assertions-dynamic.js | 1 + .../import-assertions-for-export.js | 1 + .../import-assertions-static.js | 1 + .../bracket-spacing/jsfmt.spec.js | 15 ++++ 6 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 tests/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/js/import-assertions/bracket-spacing/import-assertions-dynamic.js create mode 100644 tests/js/import-assertions/bracket-spacing/import-assertions-for-export.js create mode 100644 tests/js/import-assertions/bracket-spacing/import-assertions-static.js create mode 100644 tests/js/import-assertions/bracket-spacing/jsfmt.spec.js diff --git a/src/language-js/print/module.js b/src/language-js/print/module.js index 7d264301427a..1076773416dd 100644 --- a/src/language-js/print/module.js +++ b/src/language-js/print/module.js @@ -98,9 +98,11 @@ function printImportAssertions(path, options, print) { const node = path.getNode(); if (Array.isArray(node.assertions) && node.assertions.length !== 0) { return concat([ - " assert { ", + " assert {", + options.bracketSpacing ? " " : "", join(", ", path.map(print, "assertions")), - " }", + options.bracketSpacing ? " " : "", + "}", ]); } return ""; diff --git a/tests/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap b/tests/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..3f81979492e3 --- /dev/null +++ b/tests/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,88 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`import-assertions-dynamic.js - {"bracketSpacing":false} [espree] format 1`] = ` +"Unexpected token , (1:20) +> 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } }); + | ^ + 2 | " +`; + +exports[`import-assertions-dynamic.js - {"bracketSpacing":false} [meriyah] format 1`] = ` +"[1:20]: Expected ')' (1:20) +> 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } }); + | ^ + 2 | " +`; + +exports[`import-assertions-dynamic.js - {"bracketSpacing":false} format 1`] = ` +====================================options===================================== +bracketSpacing: false +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +import("./foo.json", { assert: { type: "json" } }); + +=====================================output===================================== +import("./foo.json", {assert: {type: "json"}}); + +================================================================================ +`; + +exports[`import-assertions-for-export.js - {"bracketSpacing":false} [espree] format 1`] = ` +"Unexpected token assert (1:33) +> 1 | export { foo2 } from \\"foo.json\\" assert { type: \\"json\\" }; + | ^ + 2 | " +`; + +exports[`import-assertions-for-export.js - {"bracketSpacing":false} [meriyah] format 1`] = ` +"[1:38]: Unexpected token: 'identifier' (1:38) +> 1 | export { foo2 } from \\"foo.json\\" assert { type: \\"json\\" }; + | ^ + 2 | " +`; + +exports[`import-assertions-for-export.js - {"bracketSpacing":false} format 1`] = ` +====================================options===================================== +bracketSpacing: false +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +export { foo2 } from "foo.json" assert { type: "json" }; + +=====================================output===================================== +export {foo2} from "foo.json" assert {type: "json"}; + +================================================================================ +`; + +exports[`import-assertions-static.js - {"bracketSpacing":false} [espree] format 1`] = ` +"Unexpected token assert (1:31) +> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" }; + | ^ + 2 | " +`; + +exports[`import-assertions-static.js - {"bracketSpacing":false} [meriyah] format 1`] = ` +"[1:36]: Unexpected token: 'identifier' (1:36) +> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" }; + | ^ + 2 | " +`; + +exports[`import-assertions-static.js - {"bracketSpacing":false} format 1`] = ` +====================================options===================================== +bracketSpacing: false +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +import json from "./foo.json" assert { type: "json" }; + +=====================================output===================================== +import json from "./foo.json" assert {type: "json"}; + +================================================================================ +`; diff --git a/tests/js/import-assertions/bracket-spacing/import-assertions-dynamic.js b/tests/js/import-assertions/bracket-spacing/import-assertions-dynamic.js new file mode 100644 index 000000000000..2411a524bf12 --- /dev/null +++ b/tests/js/import-assertions/bracket-spacing/import-assertions-dynamic.js @@ -0,0 +1 @@ +import("./foo.json", { assert: { type: "json" } }); diff --git a/tests/js/import-assertions/bracket-spacing/import-assertions-for-export.js b/tests/js/import-assertions/bracket-spacing/import-assertions-for-export.js new file mode 100644 index 000000000000..d3a40791589d --- /dev/null +++ b/tests/js/import-assertions/bracket-spacing/import-assertions-for-export.js @@ -0,0 +1 @@ +export { foo2 } from "foo.json" assert { type: "json" }; diff --git a/tests/js/import-assertions/bracket-spacing/import-assertions-static.js b/tests/js/import-assertions/bracket-spacing/import-assertions-static.js new file mode 100644 index 000000000000..890e4290079e --- /dev/null +++ b/tests/js/import-assertions/bracket-spacing/import-assertions-static.js @@ -0,0 +1 @@ +import json from "./foo.json" assert { type: "json" }; diff --git a/tests/js/import-assertions/bracket-spacing/jsfmt.spec.js b/tests/js/import-assertions/bracket-spacing/jsfmt.spec.js new file mode 100644 index 000000000000..1a2eabfad660 --- /dev/null +++ b/tests/js/import-assertions/bracket-spacing/jsfmt.spec.js @@ -0,0 +1,15 @@ +run_spec(__dirname, ["babel"], { + bracketSpacing: false, + errors: { + espree: [ + "import-assertions-dynamic.js", + "import-assertions-static.js", + "import-assertions-for-export.js", + ], + meriyah: [ + "import-assertions-dynamic.js", + "import-assertions-static.js", + "import-assertions-for-export.js", + ], + }, +}); From 66709f5024299d4df4f34f44234946271d1ff1f0 Mon Sep 17 00:00:00 2001 From: fisker Date: Fri, 6 Nov 2020 16:08:34 +0800 Subject: [PATCH 12/14] Add empty tests --- .../__snapshots__/jsfmt.spec.js.snap | 45 +++++++++++++++++++ .../js/import-assertions/empty-assertions.js | 7 +++ tests/js/import-assertions/jsfmt.spec.js | 2 + 3 files changed, 54 insertions(+) create mode 100644 tests/js/import-assertions/empty-assertions.js diff --git a/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap b/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap index 5798d5c0c6ae..e7017254fff0 100644 --- a/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,50 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`empty-assertions.js [espree] format 1`] = ` +"Unexpected token assert (2:33) + 1 | export * as foo from \\"foo.json\\" +> 2 | export * as bar from \\"bar.json\\" assert { } + | ^ + 3 | export * as baz from \\"baz.json\\" assert { /* comment */ } + 4 | + 5 | import * as foo from \\"foo.json\\"" +`; + +exports[`empty-assertions.js [meriyah] format 1`] = ` +"[2:38]: Unexpected token: 'identifier' (2:38) + 1 | export * as foo from \\"foo.json\\" +> 2 | export * as bar from \\"bar.json\\" assert { } + | ^ + 3 | export * as baz from \\"baz.json\\" assert { /* comment */ } + 4 | + 5 | import * as foo from \\"foo.json\\"" +`; + +exports[`empty-assertions.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +export * as foo from "foo.json" +export * as bar from "bar.json" assert { } +export * as baz from "baz.json" assert { /* comment */ } + +import * as foo from "foo.json" +import * as bar from "bar.json" assert { } +import * as baz from "baz.json" assert { /* comment */ } +=====================================output===================================== +export * as foo from "foo.json"; +export * as bar from "bar.json"; +export * as baz from "baz.json" /* comment */; + +import * as foo from "foo.json"; +import * as bar from "bar.json"; +import * as baz from "baz.json" /* comment */; + +================================================================================ +`; + exports[`import-assertions-dynamic.js [espree] format 1`] = ` "Unexpected token , (1:20) > 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } }); diff --git a/tests/js/import-assertions/empty-assertions.js b/tests/js/import-assertions/empty-assertions.js new file mode 100644 index 000000000000..25de961c2745 --- /dev/null +++ b/tests/js/import-assertions/empty-assertions.js @@ -0,0 +1,7 @@ +export * as foo from "foo.json" +export * as bar from "bar.json" assert { } +export * as baz from "baz.json" assert { /* comment */ } + +import * as foo from "foo.json" +import * as bar from "bar.json" assert { } +import * as baz from "baz.json" assert { /* comment */ } \ No newline at end of file diff --git a/tests/js/import-assertions/jsfmt.spec.js b/tests/js/import-assertions/jsfmt.spec.js index ccbf94dcb8b6..28f2dc9fcc1d 100644 --- a/tests/js/import-assertions/jsfmt.spec.js +++ b/tests/js/import-assertions/jsfmt.spec.js @@ -6,6 +6,7 @@ run_spec(__dirname, ["babel"], { "import-assertions-static.js", "import-assertions-without-from.js", "import-assertions-for-export.js", + "empty-assertions.js", ], meriyah: [ "import-assertions-dynamic.js", @@ -13,6 +14,7 @@ run_spec(__dirname, ["babel"], { "import-assertions-static.js", "import-assertions-without-from.js", "import-assertions-for-export.js", + "empty-assertions.js", ], }, }); From c0c9652dd87d6f5a4199b4277e5380b5c2c61891 Mon Sep 17 00:00:00 2001 From: fisker Date: Fri, 6 Nov 2020 16:19:10 +0800 Subject: [PATCH 13/14] Rename tests --- .../__snapshots__/jsfmt.spec.js.snap | 134 +++++++++--------- .../__snapshots__/jsfmt.spec.js.snap | 44 ++++-- ...ssertions-dynamic.js => dynamic-import.js} | 0 .../bracket-spacing/empty.js | 1 + .../bracket-spacing/jsfmt.spec.js | 14 +- ...-assertions-for-export.js => re-export.js} | 0 ...-assertions-static.js => static-import.js} | 0 ...ssertions-dynamic.js => dynamic-import.js} | 0 .../{empty-assertions.js => empty.js} | 0 tests/js/import-assertions/jsfmt.spec.js | 24 ++-- ...sertions-multi-types.js => multi-types.js} | 0 ...-assertions-for-export.js => re-export.js} | 0 ...-assertions-static.js => static-import.js} | 0 ...rtions-without-from.js => without-from.js} | 0 14 files changed, 123 insertions(+), 94 deletions(-) rename tests/js/import-assertions/bracket-spacing/{import-assertions-dynamic.js => dynamic-import.js} (100%) create mode 100644 tests/js/import-assertions/bracket-spacing/empty.js rename tests/js/import-assertions/bracket-spacing/{import-assertions-for-export.js => re-export.js} (100%) rename tests/js/import-assertions/bracket-spacing/{import-assertions-static.js => static-import.js} (100%) rename tests/js/import-assertions/{import-assertions-dynamic.js => dynamic-import.js} (100%) rename tests/js/import-assertions/{empty-assertions.js => empty.js} (100%) rename tests/js/import-assertions/{import-assertions-multi-types.js => multi-types.js} (100%) rename tests/js/import-assertions/{import-assertions-for-export.js => re-export.js} (100%) rename tests/js/import-assertions/{import-assertions-static.js => static-import.js} (100%) rename tests/js/import-assertions/{import-assertions-without-from.js => without-from.js} (100%) diff --git a/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap b/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap index e7017254fff0..1dfb06751cb3 100644 --- a/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap @@ -1,6 +1,34 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`empty-assertions.js [espree] format 1`] = ` +exports[`dynamic-import.js [espree] format 1`] = ` +"Unexpected token , (1:20) +> 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } }); + | ^ + 2 | " +`; + +exports[`dynamic-import.js [meriyah] format 1`] = ` +"[1:20]: Expected ')' (1:20) +> 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } }); + | ^ + 2 | " +`; + +exports[`dynamic-import.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +import("./foo.json", { assert: { type: "json" } }); + +=====================================output===================================== +import("./foo.json", { assert: { type: "json" } }); + +================================================================================ +`; + +exports[`empty.js [espree] format 1`] = ` "Unexpected token assert (2:33) 1 | export * as foo from \\"foo.json\\" > 2 | export * as bar from \\"bar.json\\" assert { } @@ -10,7 +38,7 @@ exports[`empty-assertions.js [espree] format 1`] = ` 5 | import * as foo from \\"foo.json\\"" `; -exports[`empty-assertions.js [meriyah] format 1`] = ` +exports[`empty.js [meriyah] format 1`] = ` "[2:38]: Unexpected token: 'identifier' (2:38) 1 | export * as foo from \\"foo.json\\" > 2 | export * as bar from \\"bar.json\\" assert { } @@ -20,7 +48,7 @@ exports[`empty-assertions.js [meriyah] format 1`] = ` 5 | import * as foo from \\"foo.json\\"" `; -exports[`empty-assertions.js format 1`] = ` +exports[`empty.js format 1`] = ` ====================================options===================================== parsers: ["babel"] printWidth: 80 @@ -45,35 +73,51 @@ import * as baz from "baz.json" /* comment */; ================================================================================ `; -exports[`import-assertions-dynamic.js [espree] format 1`] = ` -"Unexpected token , (1:20) -> 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } }); - | ^ +exports[`multi-types.js [espree] format 1`] = ` +"Unexpected token assert (1:31) +> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\", type: \\"bar\\" }; + | ^ 2 | " `; -exports[`import-assertions-dynamic.js [meriyah] format 1`] = ` -"[1:20]: Expected ')' (1:20) -> 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } }); - | ^ +exports[`multi-types.js [meriyah] format 1`] = ` +"[1:36]: Unexpected token: 'identifier' (1:36) +> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\", type: \\"bar\\" }; + | ^ 2 | " `; -exports[`import-assertions-dynamic.js format 1`] = ` +exports[`multi-types.js format 1`] = ` ====================================options===================================== parsers: ["babel"] printWidth: 80 | printWidth =====================================input====================================== -import("./foo.json", { assert: { type: "json" } }); +import json from "./foo.json" assert { type: "json", type: "bar" }; =====================================output===================================== -import("./foo.json", { assert: { type: "json" } }); +import json from "./foo.json" assert { type: "json", type: "bar" }; + +================================================================================ +`; + +exports[`not-import-assertions.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +import "x" +assert ({type: 'json'}); + +=====================================output===================================== +import "x"; +assert({ type: "json" }); ================================================================================ `; -exports[`import-assertions-for-export.js [espree] format 1`] = ` +exports[`re-export.js [espree] format 1`] = ` "Unexpected token assert (1:33) > 1 | export { foo2 } from \\"foo.json\\" assert { type: \\"json\\" }; | ^ @@ -82,7 +126,7 @@ exports[`import-assertions-for-export.js [espree] format 1`] = ` 4 | " `; -exports[`import-assertions-for-export.js [meriyah] format 1`] = ` +exports[`re-export.js [meriyah] format 1`] = ` "[1:38]: Unexpected token: 'identifier' (1:38) > 1 | export { foo2 } from \\"foo.json\\" assert { type: \\"json\\" }; | ^ @@ -91,7 +135,7 @@ exports[`import-assertions-for-export.js [meriyah] format 1`] = ` 4 | " `; -exports[`import-assertions-for-export.js format 1`] = ` +exports[`re-export.js format 1`] = ` ====================================options===================================== parsers: ["babel"] printWidth: 80 @@ -109,49 +153,21 @@ export * as foo3 from "foo.json" assert { type: "json" }; ================================================================================ `; -exports[`import-assertions-multi-types.js [espree] format 1`] = ` -"Unexpected token assert (1:31) -> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\", type: \\"bar\\" }; - | ^ - 2 | " -`; - -exports[`import-assertions-multi-types.js [meriyah] format 1`] = ` -"[1:36]: Unexpected token: 'identifier' (1:36) -> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\", type: \\"bar\\" }; - | ^ - 2 | " -`; - -exports[`import-assertions-multi-types.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -import json from "./foo.json" assert { type: "json", type: "bar" }; - -=====================================output===================================== -import json from "./foo.json" assert { type: "json", type: "bar" }; - -================================================================================ -`; - -exports[`import-assertions-static.js [espree] format 1`] = ` +exports[`static-import.js [espree] format 1`] = ` "Unexpected token assert (1:31) > 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" }; | ^ 2 | " `; -exports[`import-assertions-static.js [meriyah] format 1`] = ` +exports[`static-import.js [meriyah] format 1`] = ` "[1:36]: Unexpected token: 'identifier' (1:36) > 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" }; | ^ 2 | " `; -exports[`import-assertions-static.js format 1`] = ` +exports[`static-import.js format 1`] = ` ====================================options===================================== parsers: ["babel"] printWidth: 80 @@ -165,21 +181,21 @@ import json from "./foo.json" assert { type: "json" }; ================================================================================ `; -exports[`import-assertions-without-from.js [espree] format 1`] = ` +exports[`without-from.js [espree] format 1`] = ` "Unexpected token assert (1:14) > 1 | import \\"foo\\" assert { type: \\"json\\" } | ^ 2 | " `; -exports[`import-assertions-without-from.js [meriyah] format 1`] = ` +exports[`without-from.js [meriyah] format 1`] = ` "[1:19]: Unexpected token: 'identifier' (1:19) > 1 | import \\"foo\\" assert { type: \\"json\\" } | ^ 2 | " `; -exports[`import-assertions-without-from.js format 1`] = ` +exports[`without-from.js format 1`] = ` ====================================options===================================== parsers: ["babel"] printWidth: 80 @@ -192,19 +208,3 @@ import "foo" assert { type: "json" }; ================================================================================ `; - -exports[`not-import-assertions.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -import "x" -assert ({type: 'json'}); - -=====================================output===================================== -import "x"; -assert({ type: "json" }); - -================================================================================ -`; diff --git a/tests/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap b/tests/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap index 3f81979492e3..3e06a9d9effe 100644 --- a/tests/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/import-assertions/bracket-spacing/__snapshots__/jsfmt.spec.js.snap @@ -1,20 +1,20 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`import-assertions-dynamic.js - {"bracketSpacing":false} [espree] format 1`] = ` +exports[`dynamic-import.js - {"bracketSpacing":false} [espree] format 1`] = ` "Unexpected token , (1:20) > 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } }); | ^ 2 | " `; -exports[`import-assertions-dynamic.js - {"bracketSpacing":false} [meriyah] format 1`] = ` +exports[`dynamic-import.js - {"bracketSpacing":false} [meriyah] format 1`] = ` "[1:20]: Expected ')' (1:20) > 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } }); | ^ 2 | " `; -exports[`import-assertions-dynamic.js - {"bracketSpacing":false} format 1`] = ` +exports[`dynamic-import.js - {"bracketSpacing":false} format 1`] = ` ====================================options===================================== bracketSpacing: false parsers: ["babel"] @@ -29,21 +29,47 @@ import("./foo.json", {assert: {type: "json"}}); ================================================================================ `; -exports[`import-assertions-for-export.js - {"bracketSpacing":false} [espree] format 1`] = ` +exports[`empty.js - {"bracketSpacing":false} [espree] format 1`] = ` +"Unexpected token assert (1:33) +> 1 | export * as bar from \\"bar.json\\" assert { } + | ^" +`; + +exports[`empty.js - {"bracketSpacing":false} [meriyah] format 1`] = ` +"[1:38]: Unexpected token: 'identifier' (1:38) +> 1 | export * as bar from \\"bar.json\\" assert { } + | ^" +`; + +exports[`empty.js - {"bracketSpacing":false} format 1`] = ` +====================================options===================================== +bracketSpacing: false +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +export * as bar from "bar.json" assert { } +=====================================output===================================== +export * as bar from "bar.json"; + +================================================================================ +`; + +exports[`re-export.js - {"bracketSpacing":false} [espree] format 1`] = ` "Unexpected token assert (1:33) > 1 | export { foo2 } from \\"foo.json\\" assert { type: \\"json\\" }; | ^ 2 | " `; -exports[`import-assertions-for-export.js - {"bracketSpacing":false} [meriyah] format 1`] = ` +exports[`re-export.js - {"bracketSpacing":false} [meriyah] format 1`] = ` "[1:38]: Unexpected token: 'identifier' (1:38) > 1 | export { foo2 } from \\"foo.json\\" assert { type: \\"json\\" }; | ^ 2 | " `; -exports[`import-assertions-for-export.js - {"bracketSpacing":false} format 1`] = ` +exports[`re-export.js - {"bracketSpacing":false} format 1`] = ` ====================================options===================================== bracketSpacing: false parsers: ["babel"] @@ -58,21 +84,21 @@ export {foo2} from "foo.json" assert {type: "json"}; ================================================================================ `; -exports[`import-assertions-static.js - {"bracketSpacing":false} [espree] format 1`] = ` +exports[`static-import.js - {"bracketSpacing":false} [espree] format 1`] = ` "Unexpected token assert (1:31) > 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" }; | ^ 2 | " `; -exports[`import-assertions-static.js - {"bracketSpacing":false} [meriyah] format 1`] = ` +exports[`static-import.js - {"bracketSpacing":false} [meriyah] format 1`] = ` "[1:36]: Unexpected token: 'identifier' (1:36) > 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" }; | ^ 2 | " `; -exports[`import-assertions-static.js - {"bracketSpacing":false} format 1`] = ` +exports[`static-import.js - {"bracketSpacing":false} format 1`] = ` ====================================options===================================== bracketSpacing: false parsers: ["babel"] diff --git a/tests/js/import-assertions/bracket-spacing/import-assertions-dynamic.js b/tests/js/import-assertions/bracket-spacing/dynamic-import.js similarity index 100% rename from tests/js/import-assertions/bracket-spacing/import-assertions-dynamic.js rename to tests/js/import-assertions/bracket-spacing/dynamic-import.js diff --git a/tests/js/import-assertions/bracket-spacing/empty.js b/tests/js/import-assertions/bracket-spacing/empty.js new file mode 100644 index 000000000000..f6b005613c7d --- /dev/null +++ b/tests/js/import-assertions/bracket-spacing/empty.js @@ -0,0 +1 @@ +export * as bar from "bar.json" assert { } \ No newline at end of file diff --git a/tests/js/import-assertions/bracket-spacing/jsfmt.spec.js b/tests/js/import-assertions/bracket-spacing/jsfmt.spec.js index 1a2eabfad660..141e96b4f27f 100644 --- a/tests/js/import-assertions/bracket-spacing/jsfmt.spec.js +++ b/tests/js/import-assertions/bracket-spacing/jsfmt.spec.js @@ -2,14 +2,16 @@ run_spec(__dirname, ["babel"], { bracketSpacing: false, errors: { espree: [ - "import-assertions-dynamic.js", - "import-assertions-static.js", - "import-assertions-for-export.js", + "dynamic-import.js", + "static-import.js", + "re-export.js", + "empty.js", ], meriyah: [ - "import-assertions-dynamic.js", - "import-assertions-static.js", - "import-assertions-for-export.js", + "dynamic-import.js", + "static-import.js", + "re-export.js", + "empty.js", ], }, }); diff --git a/tests/js/import-assertions/bracket-spacing/import-assertions-for-export.js b/tests/js/import-assertions/bracket-spacing/re-export.js similarity index 100% rename from tests/js/import-assertions/bracket-spacing/import-assertions-for-export.js rename to tests/js/import-assertions/bracket-spacing/re-export.js diff --git a/tests/js/import-assertions/bracket-spacing/import-assertions-static.js b/tests/js/import-assertions/bracket-spacing/static-import.js similarity index 100% rename from tests/js/import-assertions/bracket-spacing/import-assertions-static.js rename to tests/js/import-assertions/bracket-spacing/static-import.js diff --git a/tests/js/import-assertions/import-assertions-dynamic.js b/tests/js/import-assertions/dynamic-import.js similarity index 100% rename from tests/js/import-assertions/import-assertions-dynamic.js rename to tests/js/import-assertions/dynamic-import.js diff --git a/tests/js/import-assertions/empty-assertions.js b/tests/js/import-assertions/empty.js similarity index 100% rename from tests/js/import-assertions/empty-assertions.js rename to tests/js/import-assertions/empty.js diff --git a/tests/js/import-assertions/jsfmt.spec.js b/tests/js/import-assertions/jsfmt.spec.js index 28f2dc9fcc1d..69aab7bca670 100644 --- a/tests/js/import-assertions/jsfmt.spec.js +++ b/tests/js/import-assertions/jsfmt.spec.js @@ -1,20 +1,20 @@ run_spec(__dirname, ["babel"], { errors: { espree: [ - "import-assertions-dynamic.js", - "import-assertions-multi-types.js", - "import-assertions-static.js", - "import-assertions-without-from.js", - "import-assertions-for-export.js", - "empty-assertions.js", + "dynamic-import.js", + "empty.js", + "multi-types.js", + "static-import.js", + "re-export.js", + "without-from.js", ], meriyah: [ - "import-assertions-dynamic.js", - "import-assertions-multi-types.js", - "import-assertions-static.js", - "import-assertions-without-from.js", - "import-assertions-for-export.js", - "empty-assertions.js", + "dynamic-import.js", + "empty.js", + "multi-types.js", + "static-import.js", + "re-export.js", + "without-from.js", ], }, }); diff --git a/tests/js/import-assertions/import-assertions-multi-types.js b/tests/js/import-assertions/multi-types.js similarity index 100% rename from tests/js/import-assertions/import-assertions-multi-types.js rename to tests/js/import-assertions/multi-types.js diff --git a/tests/js/import-assertions/import-assertions-for-export.js b/tests/js/import-assertions/re-export.js similarity index 100% rename from tests/js/import-assertions/import-assertions-for-export.js rename to tests/js/import-assertions/re-export.js diff --git a/tests/js/import-assertions/import-assertions-static.js b/tests/js/import-assertions/static-import.js similarity index 100% rename from tests/js/import-assertions/import-assertions-static.js rename to tests/js/import-assertions/static-import.js diff --git a/tests/js/import-assertions/import-assertions-without-from.js b/tests/js/import-assertions/without-from.js similarity index 100% rename from tests/js/import-assertions/import-assertions-without-from.js rename to tests/js/import-assertions/without-from.js From 5ed6df0371e228ff5a14852e75bcfe67f77c885d Mon Sep 17 00:00:00 2001 From: fisker Date: Fri, 6 Nov 2020 16:29:27 +0800 Subject: [PATCH 14/14] Update changelog --- changelog_unreleased/javascript/pr-9408.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/changelog_unreleased/javascript/pr-9408.md b/changelog_unreleased/javascript/pr-9408.md index b496ce45f6a5..0444bb337109 100644 --- a/changelog_unreleased/javascript/pr-9408.md +++ b/changelog_unreleased/javascript/pr-9408.md @@ -1,4 +1,4 @@ -#### Update to `@babel/parser` 7.12 (#9408, #9476 by @sosukesuzuki) +#### Update to `@babel/parser` 7.12 (#9408, #9476, #9597 by @sosukesuzuki) Updated the JavaScript parser to [`@babel/parser` 7.12](https://babeljs.io/blog/2020/10/15/7.12.0). This fixes several bugs and supports some new syntax. @@ -7,15 +7,11 @@ Updated the JavaScript parser to [`@babel/parser` 7.12](https://babeljs.io/blog/ [The "module attributes" proposal supported on 2.1](https://prettier.io/blog/2020/08/24/2.1.0.html#support-es-module-attributes-and-json-modules-8436httpsgithubcomprettierprettierpull8436-by-fiskerhttpsgithubcomfisker) has been significantly changed and also renamed to "import assertions". ```js -import json from "./foo.json" assert { type: "json" }; +import foo from "./foo.json" assert { type: "json" }; ``` ##### Support imports and exports with string names - - -Due to a [bug in `@babel/parser`](https://github.com/babel/babel/issues/12209), Prettier can only use exports, but that will be fixed. - ```js let happy = "happy"; export { happy as "😃" };