From 6dd7b196c34902037564fd229c074e7590be3b2b Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 1 Dec 2022 10:29:26 +0800 Subject: [PATCH 1/9] Add tests for keyword class property --- src/language-js/print/statement.js | 2 - .../__snapshots__/jsfmt.spec.js.snap | 187 ++++++++++++++++++ .../js/classes/keyword-property/async.js | 4 + .../format/js/classes/keyword-property/get.js | 4 + .../js/classes/keyword-property/jsfmt.spec.js | 7 + .../format/js/classes/keyword-property/set.js | 4 + .../js/classes/keyword-property/static.js | 4 + 7 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/js/classes/keyword-property/async.js create mode 100644 tests/format/js/classes/keyword-property/get.js create mode 100644 tests/format/js/classes/keyword-property/jsfmt.spec.js create mode 100644 tests/format/js/classes/keyword-property/set.js create mode 100644 tests/format/js/classes/keyword-property/static.js diff --git a/src/language-js/print/statement.js b/src/language-js/print/statement.js index da2ff299e387..69675d3c219e 100644 --- a/src/language-js/print/statement.js +++ b/src/language-js/print/statement.js @@ -174,8 +174,6 @@ const isClassProperty = ({ type }) => */ function shouldPrintSemicolonAfterClassProperty(node, nextNode) { const name = node.key && node.key.name; - // this isn't actually possible yet with most parsers available today - // so isn't properly tested yet. if ( (name === "static" || name === "get" || name === "set") && !node.value && diff --git a/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..d3bc6bf1a64a --- /dev/null +++ b/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,187 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`async.js - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +class A { + async; + foo() {}; +} + +=====================================output===================================== +class A { + async + foo() {} +} + +================================================================================ +`; + +exports[`async.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class A { + async; + foo() {}; +} + +=====================================output===================================== +class A { + async; + foo() {} +} + +================================================================================ +`; + +exports[`get.js - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +class A { + get; + foo; +} +=====================================output===================================== +class A { + get; + foo +} + +================================================================================ +`; + +exports[`get.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class A { + get; + foo; +} +=====================================output===================================== +class A { + get; + foo; +} + +================================================================================ +`; + +exports[`set.js - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +class A { + set; + foo; +} + +=====================================output===================================== +class A { + set; + foo +} + +================================================================================ +`; + +exports[`set.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class A { + set; + foo; +} + +=====================================output===================================== +class A { + set; + foo; +} + +================================================================================ +`; + +exports[`static.js [flow] format 1`] = ` +"Unexpected token \`;\`, expected an identifier (2:9) + 1 | class A { +> 2 | static; + | ^ + 3 | foo() {}; + 4 | } + 5 |" +`; + +exports[`static.js [meriyah] format 1`] = `"Cannot read properties of null (reading 'type')"`; + +exports[`static.js - {"semi":false} [flow] format 1`] = ` +"Unexpected token \`;\`, expected an identifier (2:9) + 1 | class A { +> 2 | static; + | ^ + 3 | foo() {}; + 4 | } + 5 |" +`; + +exports[`static.js - {"semi":false} [meriyah] format 1`] = `"Cannot read properties of null (reading 'type')"`; + +exports[`static.js - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +class A { + static; + foo() {}; +} + +=====================================output===================================== +class A { + static; + foo() {} +} + +================================================================================ +`; + +exports[`static.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class A { + static; + foo() {}; +} + +=====================================output===================================== +class A { + static; + foo() {} +} + +================================================================================ +`; diff --git a/tests/format/js/classes/keyword-property/async.js b/tests/format/js/classes/keyword-property/async.js new file mode 100644 index 000000000000..faf597cf005f --- /dev/null +++ b/tests/format/js/classes/keyword-property/async.js @@ -0,0 +1,4 @@ +class A { + async; + foo() {}; +} diff --git a/tests/format/js/classes/keyword-property/get.js b/tests/format/js/classes/keyword-property/get.js new file mode 100644 index 000000000000..ed2df3d3e040 --- /dev/null +++ b/tests/format/js/classes/keyword-property/get.js @@ -0,0 +1,4 @@ +class A { + get; + foo; +} \ No newline at end of file diff --git a/tests/format/js/classes/keyword-property/jsfmt.spec.js b/tests/format/js/classes/keyword-property/jsfmt.spec.js new file mode 100644 index 000000000000..4d19a6936719 --- /dev/null +++ b/tests/format/js/classes/keyword-property/jsfmt.spec.js @@ -0,0 +1,7 @@ +const errors = { + flow: ["static.js"], + meriyah: ["static.js"], +}; + +run_spec(__dirname, ["babel", "flow", "typescript"], { errors }); +run_spec(__dirname, ["babel", "flow", "typescript"], { errors, semi: false }); diff --git a/tests/format/js/classes/keyword-property/set.js b/tests/format/js/classes/keyword-property/set.js new file mode 100644 index 000000000000..03f5c7ea0fdf --- /dev/null +++ b/tests/format/js/classes/keyword-property/set.js @@ -0,0 +1,4 @@ +class A { + set; + foo; +} diff --git a/tests/format/js/classes/keyword-property/static.js b/tests/format/js/classes/keyword-property/static.js new file mode 100644 index 000000000000..f959f0cb1086 --- /dev/null +++ b/tests/format/js/classes/keyword-property/static.js @@ -0,0 +1,4 @@ +class A { + static; + foo() {}; +} From 859d3a317e53477b107f0673f6bee2c79e4bb458 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 1 Dec 2022 10:31:20 +0800 Subject: [PATCH 2/9] Add TODO --- tests/format/js/classes/keyword-property/jsfmt.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/format/js/classes/keyword-property/jsfmt.spec.js b/tests/format/js/classes/keyword-property/jsfmt.spec.js index 4d19a6936719..f65c15c9c6ca 100644 --- a/tests/format/js/classes/keyword-property/jsfmt.spec.js +++ b/tests/format/js/classes/keyword-property/jsfmt.spec.js @@ -1,5 +1,6 @@ const errors = { flow: ["static.js"], + // TODO: Remove this when fixing https://github.com/prettier/prettier/pull/13927 meriyah: ["static.js"], }; From 15086187feeaf2f0bc769358625f7460198d64d6 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 1 Dec 2022 10:33:26 +0800 Subject: [PATCH 3/9] Update test to be more reasonable --- .../__snapshots__/jsfmt.spec.js.snap | 18 ++++++++++-------- .../format/js/classes/keyword-property/get.js | 4 ++-- .../format/js/classes/keyword-property/set.js | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap index d3bc6bf1a64a..8d32d381600d 100644 --- a/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap @@ -50,12 +50,13 @@ semi: false =====================================input====================================== class A { get; - foo; + foo() {} } + =====================================output===================================== class A { get; - foo + foo() {} } ================================================================================ @@ -69,12 +70,13 @@ printWidth: 80 =====================================input====================================== class A { get; - foo; + foo() {} } + =====================================output===================================== class A { get; - foo; + foo() {} } ================================================================================ @@ -89,13 +91,13 @@ semi: false =====================================input====================================== class A { set; - foo; + foo() {} } =====================================output===================================== class A { set; - foo + foo() {} } ================================================================================ @@ -109,13 +111,13 @@ printWidth: 80 =====================================input====================================== class A { set; - foo; + foo() {} } =====================================output===================================== class A { set; - foo; + foo() {} } ================================================================================ diff --git a/tests/format/js/classes/keyword-property/get.js b/tests/format/js/classes/keyword-property/get.js index ed2df3d3e040..80f9195819f1 100644 --- a/tests/format/js/classes/keyword-property/get.js +++ b/tests/format/js/classes/keyword-property/get.js @@ -1,4 +1,4 @@ class A { get; - foo; -} \ No newline at end of file + foo() {} +} diff --git a/tests/format/js/classes/keyword-property/set.js b/tests/format/js/classes/keyword-property/set.js index 03f5c7ea0fdf..639c326d3655 100644 --- a/tests/format/js/classes/keyword-property/set.js +++ b/tests/format/js/classes/keyword-property/set.js @@ -1,4 +1,4 @@ class A { set; - foo; + foo() {} } From 1619007a54671993b1306ae0228dbda123b67587 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 1 Dec 2022 10:36:06 +0800 Subject: [PATCH 4/9] Add test for static properties --- .../__snapshots__/jsfmt.spec.js.snap | 65 +++++++++++++++++-- .../format/js/classes/keyword-property/set.js | 2 +- .../keyword-property/static-properties.js | 8 +++ 3 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 tests/format/js/classes/keyword-property/static-properties.js diff --git a/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap index 8d32d381600d..c1a2a82aa70e 100644 --- a/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap @@ -91,13 +91,13 @@ semi: false =====================================input====================================== class A { set; - foo() {} + foo(v) {} } =====================================output===================================== class A { set; - foo() {} + foo(v) {} } ================================================================================ @@ -111,13 +111,13 @@ printWidth: 80 =====================================input====================================== class A { set; - foo() {} + foo(v) {} } =====================================output===================================== class A { set; - foo() {} + foo(v) {} } ================================================================================ @@ -187,3 +187,60 @@ class A { ================================================================================ `; + +exports[`static-properties.js - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +class A { + static async; + a() {} + static get; + b() {} + static set; + c(v) {} +} + +=====================================output===================================== +class A { + static async + a() {} + static get; + b() {} + static set; + c(v) {} +} + +================================================================================ +`; + +exports[`static-properties.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class A { + static async; + a() {} + static get; + b() {} + static set; + c(v) {} +} + +=====================================output===================================== +class A { + static async; + a() {} + static get; + b() {} + static set; + c(v) {} +} + +================================================================================ +`; diff --git a/tests/format/js/classes/keyword-property/set.js b/tests/format/js/classes/keyword-property/set.js index 639c326d3655..679a13f195e7 100644 --- a/tests/format/js/classes/keyword-property/set.js +++ b/tests/format/js/classes/keyword-property/set.js @@ -1,4 +1,4 @@ class A { set; - foo() {} + foo(v) {} } diff --git a/tests/format/js/classes/keyword-property/static-properties.js b/tests/format/js/classes/keyword-property/static-properties.js new file mode 100644 index 000000000000..a5aca4c9677c --- /dev/null +++ b/tests/format/js/classes/keyword-property/static-properties.js @@ -0,0 +1,8 @@ +class A { + static async; + a() {} + static get; + b() {} + static set; + c(v) {} +} From b51d04bfebcc74f83470b63c8be1212be3a5c89a Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 1 Dec 2022 11:24:39 +0800 Subject: [PATCH 5/9] Workaround for meriyah --- src/language-js/parse/postprocess/index.js | 20 ++ src/language-js/print/class.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 309 ++++++++++++++++-- .../js/classes/keyword-property/async.js | 5 + .../format/js/classes/keyword-property/get.js | 5 + .../js/classes/keyword-property/jsfmt.spec.js | 2 - .../format/js/classes/keyword-property/set.js | 5 + .../classes/keyword-property/static-async.js | 9 + .../js/classes/keyword-property/static-get.js | 9 + .../keyword-property/static-properties.js | 8 - .../js/classes/keyword-property/static-set.js | 9 + .../classes/keyword-property/static-static.js | 9 + .../js/classes/keyword-property/static.js | 5 + 13 files changed, 362 insertions(+), 34 deletions(-) create mode 100644 tests/format/js/classes/keyword-property/static-async.js create mode 100644 tests/format/js/classes/keyword-property/static-get.js delete mode 100644 tests/format/js/classes/keyword-property/static-properties.js create mode 100644 tests/format/js/classes/keyword-property/static-set.js create mode 100644 tests/format/js/classes/keyword-property/static-static.js diff --git a/src/language-js/parse/postprocess/index.js b/src/language-js/parse/postprocess/index.js index 62959af5b16e..e384759dcef6 100644 --- a/src/language-js/parse/postprocess/index.js +++ b/src/language-js/parse/postprocess/index.js @@ -153,6 +153,26 @@ function postprocess(ast, options) { } break; } + // TODO: Remove this when https://github.com/meriyah/meriyah/issues/231 get fixed + case "PropertyDefinition": + if ( + options.parser === "meriyah" && + node.static && + !node.computed && + node.key === null + ) { + const name = "static"; + const start = locStart(node); + Object.assign(node, { + static: true, + key: { + type: "Identifier", + name, + range: [start, start + name.length], + }, + }); + } + break; } }); diff --git a/src/language-js/print/class.js b/src/language-js/print/class.js index d8675c7d9b5d..50065a255367 100644 --- a/src/language-js/print/class.js +++ b/src/language-js/print/class.js @@ -224,6 +224,7 @@ function printClassProperty(path, options, print) { if (node.type === "ClassAccessorProperty") { parts.push("accessor "); } + parts.push( printPropertyKey(path, options, print), printOptionalToken(path), diff --git a/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap index c1a2a82aa70e..0cf3a8be92af 100644 --- a/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap @@ -12,12 +12,22 @@ class A { foo() {}; } +class B { + async = 1; + foo() {} +} + =====================================output===================================== class A { async foo() {} } +class B { + async = 1 + foo() {} +} + ================================================================================ `; @@ -32,12 +42,22 @@ class A { foo() {}; } +class B { + async = 1; + foo() {} +} + =====================================output===================================== class A { async; foo() {} } +class B { + async = 1; + foo() {} +} + ================================================================================ `; @@ -53,12 +73,22 @@ class A { foo() {} } +class B { + get = 1; + foo() {} +} + =====================================output===================================== class A { get; foo() {} } +class B { + get = 1 + foo() {} +} + ================================================================================ `; @@ -73,12 +103,22 @@ class A { foo() {} } +class B { + get = 1; + foo() {} +} + =====================================output===================================== class A { get; foo() {} } +class B { + get = 1; + foo() {} +} + ================================================================================ `; @@ -94,12 +134,22 @@ class A { foo(v) {} } +class B { + set = 1; + foo(v) {} +} + =====================================output===================================== class A { set; foo(v) {} } +class B { + set = 1 + foo(v) {} +} + ================================================================================ `; @@ -114,12 +164,22 @@ class A { foo(v) {} } +class B { + set = 1; + foo(v) {} +} + =====================================output===================================== class A { set; foo(v) {} } +class B { + set = 1; + foo(v) {} +} + ================================================================================ `; @@ -133,8 +193,6 @@ exports[`static.js [flow] format 1`] = ` 5 |" `; -exports[`static.js [meriyah] format 1`] = `"Cannot read properties of null (reading 'type')"`; - exports[`static.js - {"semi":false} [flow] format 1`] = ` "Unexpected token \`;\`, expected an identifier (2:9) 1 | class A { @@ -145,8 +203,6 @@ exports[`static.js - {"semi":false} [flow] format 1`] = ` 5 |" `; -exports[`static.js - {"semi":false} [meriyah] format 1`] = `"Cannot read properties of null (reading 'type')"`; - exports[`static.js - {"semi":false} format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] @@ -159,12 +215,21 @@ class A { foo() {}; } +class B { + static = 1; + foo() {}; +} =====================================output===================================== class A { static; foo() {} } +class B { + static = 1 + foo() {} +} + ================================================================================ `; @@ -179,16 +244,25 @@ class A { foo() {}; } +class B { + static = 1; + foo() {}; +} =====================================output===================================== class A { static; foo() {} } +class B { + static = 1; + foo() {} +} + ================================================================================ `; -exports[`static-properties.js - {"semi":false} format 1`] = ` +exports[`static-async.js - {"semi":false} format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] printWidth: 80 @@ -197,27 +271,29 @@ semi: false =====================================input====================================== class A { static async; - a() {} - static get; - b() {} - static set; - c(v) {} + foo() {} +} + +class B { + static async = 1; + foo() {} } =====================================output===================================== class A { static async - a() {} - static get; - b() {} - static set; - c(v) {} + foo() {} +} + +class B { + static async = 1 + foo() {} } ================================================================================ `; -exports[`static-properties.js format 1`] = ` +exports[`static-async.js format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] printWidth: 80 @@ -225,21 +301,206 @@ printWidth: 80 =====================================input====================================== class A { static async; - a() {} - static get; - b() {} - static set; - c(v) {} + foo() {} +} + +class B { + static async = 1; + foo() {} } =====================================output===================================== class A { static async; - a() {} + foo() {} +} + +class B { + static async = 1; + foo() {} +} + +================================================================================ +`; + +exports[`static-get.js - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +class A { static get; - b() {} + foo() {} +} + +class B { + static get = 1; + foo() {} +} + +=====================================output===================================== +class A { + static get; + foo() {} +} + +class B { + static get = 1 + foo() {} +} + +================================================================================ +`; + +exports[`static-get.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class A { + static get; + foo() {} +} + +class B { + static get = 1; + foo() {} +} + +=====================================output===================================== +class A { + static get; + foo() {} +} + +class B { + static get = 1; + foo() {} +} + +================================================================================ +`; + +exports[`static-set.js - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +class A { + static set; + foo(v) {} +} + +class B { + static set = 1; + foo(v) {} +} + +=====================================output===================================== +class A { + static set; + foo(v) {} +} + +class B { + static set = 1 + foo(v) {} +} + +================================================================================ +`; + +exports[`static-set.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class A { + static set; + foo(v) {} +} + +class B { + static set = 1; + foo(v) {} +} + +=====================================output===================================== +class A { static set; - c(v) {} + foo(v) {} +} + +class B { + static set = 1; + foo(v) {} +} + +================================================================================ +`; + +exports[`static-static.js - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +class A { + static static; + foo() {} +} + +class B { + static static = 1; + foo() {} +} + +=====================================output===================================== +class A { + static static; + foo() {} +} + +class B { + static static = 1 + foo() {} +} + +================================================================================ +`; + +exports[`static-static.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class A { + static static; + foo() {} +} + +class B { + static static = 1; + foo() {} +} + +=====================================output===================================== +class A { + static static; + foo() {} +} + +class B { + static static = 1; + foo() {} } ================================================================================ diff --git a/tests/format/js/classes/keyword-property/async.js b/tests/format/js/classes/keyword-property/async.js index faf597cf005f..db7dbccccbc0 100644 --- a/tests/format/js/classes/keyword-property/async.js +++ b/tests/format/js/classes/keyword-property/async.js @@ -2,3 +2,8 @@ class A { async; foo() {}; } + +class B { + async = 1; + foo() {} +} diff --git a/tests/format/js/classes/keyword-property/get.js b/tests/format/js/classes/keyword-property/get.js index 80f9195819f1..63bf058f9b83 100644 --- a/tests/format/js/classes/keyword-property/get.js +++ b/tests/format/js/classes/keyword-property/get.js @@ -2,3 +2,8 @@ class A { get; foo() {} } + +class B { + get = 1; + foo() {} +} diff --git a/tests/format/js/classes/keyword-property/jsfmt.spec.js b/tests/format/js/classes/keyword-property/jsfmt.spec.js index f65c15c9c6ca..a0d2e24cda04 100644 --- a/tests/format/js/classes/keyword-property/jsfmt.spec.js +++ b/tests/format/js/classes/keyword-property/jsfmt.spec.js @@ -1,7 +1,5 @@ const errors = { flow: ["static.js"], - // TODO: Remove this when fixing https://github.com/prettier/prettier/pull/13927 - meriyah: ["static.js"], }; run_spec(__dirname, ["babel", "flow", "typescript"], { errors }); diff --git a/tests/format/js/classes/keyword-property/set.js b/tests/format/js/classes/keyword-property/set.js index 679a13f195e7..45d6dbd75c84 100644 --- a/tests/format/js/classes/keyword-property/set.js +++ b/tests/format/js/classes/keyword-property/set.js @@ -2,3 +2,8 @@ class A { set; foo(v) {} } + +class B { + set = 1; + foo(v) {} +} diff --git a/tests/format/js/classes/keyword-property/static-async.js b/tests/format/js/classes/keyword-property/static-async.js new file mode 100644 index 000000000000..ea3a7c2d88bb --- /dev/null +++ b/tests/format/js/classes/keyword-property/static-async.js @@ -0,0 +1,9 @@ +class A { + static async; + foo() {} +} + +class B { + static async = 1; + foo() {} +} diff --git a/tests/format/js/classes/keyword-property/static-get.js b/tests/format/js/classes/keyword-property/static-get.js new file mode 100644 index 000000000000..910e47daf610 --- /dev/null +++ b/tests/format/js/classes/keyword-property/static-get.js @@ -0,0 +1,9 @@ +class A { + static get; + foo() {} +} + +class B { + static get = 1; + foo() {} +} diff --git a/tests/format/js/classes/keyword-property/static-properties.js b/tests/format/js/classes/keyword-property/static-properties.js deleted file mode 100644 index a5aca4c9677c..000000000000 --- a/tests/format/js/classes/keyword-property/static-properties.js +++ /dev/null @@ -1,8 +0,0 @@ -class A { - static async; - a() {} - static get; - b() {} - static set; - c(v) {} -} diff --git a/tests/format/js/classes/keyword-property/static-set.js b/tests/format/js/classes/keyword-property/static-set.js new file mode 100644 index 000000000000..3300eae1a2d5 --- /dev/null +++ b/tests/format/js/classes/keyword-property/static-set.js @@ -0,0 +1,9 @@ +class A { + static set; + foo(v) {} +} + +class B { + static set = 1; + foo(v) {} +} diff --git a/tests/format/js/classes/keyword-property/static-static.js b/tests/format/js/classes/keyword-property/static-static.js new file mode 100644 index 000000000000..406943ae7230 --- /dev/null +++ b/tests/format/js/classes/keyword-property/static-static.js @@ -0,0 +1,9 @@ +class A { + static static; + foo() {} +} + +class B { + static static = 1; + foo() {} +} diff --git a/tests/format/js/classes/keyword-property/static.js b/tests/format/js/classes/keyword-property/static.js index f959f0cb1086..9416ec4317d1 100644 --- a/tests/format/js/classes/keyword-property/static.js +++ b/tests/format/js/classes/keyword-property/static.js @@ -2,3 +2,8 @@ class A { static; foo() {}; } + +class B { + static = 1; + foo() {}; +} \ No newline at end of file From 75affa6604af150e12d5fa0519a9ca47faa8edfd Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 1 Dec 2022 11:30:43 +0800 Subject: [PATCH 6/9] Blank lines --- src/language-js/print/class.js | 1 - .../classes/keyword-property/__snapshots__/jsfmt.spec.js.snap | 2 ++ tests/format/js/classes/keyword-property/static.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/language-js/print/class.js b/src/language-js/print/class.js index 50065a255367..d8675c7d9b5d 100644 --- a/src/language-js/print/class.js +++ b/src/language-js/print/class.js @@ -224,7 +224,6 @@ function printClassProperty(path, options, print) { if (node.type === "ClassAccessorProperty") { parts.push("accessor "); } - parts.push( printPropertyKey(path, options, print), printOptionalToken(path), diff --git a/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap index 0cf3a8be92af..0c96b7a25cec 100644 --- a/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/classes/keyword-property/__snapshots__/jsfmt.spec.js.snap @@ -219,6 +219,7 @@ class B { static = 1; foo() {}; } + =====================================output===================================== class A { static; @@ -248,6 +249,7 @@ class B { static = 1; foo() {}; } + =====================================output===================================== class A { static; diff --git a/tests/format/js/classes/keyword-property/static.js b/tests/format/js/classes/keyword-property/static.js index 9416ec4317d1..e2aca638eaab 100644 --- a/tests/format/js/classes/keyword-property/static.js +++ b/tests/format/js/classes/keyword-property/static.js @@ -6,4 +6,4 @@ class A { class B { static = 1; foo() {}; -} \ No newline at end of file +} From 16cf125f7d0b6fdf7c4d7c2d0278a63dcbc34a17 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 1 Dec 2022 12:09:25 +0800 Subject: [PATCH 7/9] Disable `meriyah` --- tests/config/format-test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/config/format-test.js b/tests/config/format-test.js index 3574fddf1e40..ae1e85c4ebb3 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -79,6 +79,14 @@ const meriyahDisabledTests = new Set([ __dirname, "../format/js/babel-plugins/decorator-auto-accessors.js" ), + path.join( + __dirname, + "../format/js/classes/keyword-property/static-static.js" + ), + path.join( + __dirname, + "../format/js/classes/keyword-property/static.js" + ), ]); const isUnstable = (filename, options) => { From bade33197e032881b29a23a287dc965dd24f2743 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 1 Dec 2022 12:12:01 +0800 Subject: [PATCH 8/9] Format --- tests/config/format-test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/config/format-test.js b/tests/config/format-test.js index ae1e85c4ebb3..b8c018c6633f 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -83,10 +83,7 @@ const meriyahDisabledTests = new Set([ __dirname, "../format/js/classes/keyword-property/static-static.js" ), - path.join( - __dirname, - "../format/js/classes/keyword-property/static.js" - ), + path.join(__dirname, "../format/js/classes/keyword-property/static.js"), ]); const isUnstable = (filename, options) => { From 6c9658f9486acd2a14d904eb99fb3bc6dd70def0 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 1 Dec 2022 13:49:22 +0800 Subject: [PATCH 9/9] Fix meriyah --- src/language-js/parse/postprocess/index.js | 4 ++-- tests/config/format-test.js | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/language-js/parse/postprocess/index.js b/src/language-js/parse/postprocess/index.js index e384759dcef6..d2005c4f1f34 100644 --- a/src/language-js/parse/postprocess/index.js +++ b/src/language-js/parse/postprocess/index.js @@ -159,12 +159,12 @@ function postprocess(ast, options) { options.parser === "meriyah" && node.static && !node.computed && - node.key === null + !node.key ) { const name = "static"; const start = locStart(node); Object.assign(node, { - static: true, + static: false, key: { type: "Identifier", name, diff --git a/tests/config/format-test.js b/tests/config/format-test.js index b8c018c6633f..3574fddf1e40 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -79,11 +79,6 @@ const meriyahDisabledTests = new Set([ __dirname, "../format/js/babel-plugins/decorator-auto-accessors.js" ), - path.join( - __dirname, - "../format/js/classes/keyword-property/static-static.js" - ), - path.join(__dirname, "../format/js/classes/keyword-property/static.js"), ]); const isUnstable = (filename, options) => {