From 48f7598e57e05ab9d4397cb11a4137df40a2605e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 15 Jan 2026 01:44:39 +0800 Subject: [PATCH] Update flow-parser (#18598) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: fisker --- package.json | 4 +- src/language-js/comments/handle-comments.js | 3 +- .../__snapshots__/format.test.js.snap | 21 ++++++--- .../flow/component/declare-component.js | 12 +++-- .../__snapshots__/format.test.js.snap | 21 +++++++++ .../expression.js | 4 ++ .../format.test.js | 1 + .../__snapshots__/format.test.js.snap | 44 +++++++++---------- .../record/__snapshots__/format.test.js.snap | 16 +++++++ .../misc/errors/flow/record/format.test.js | 7 +++ .../__snapshots__/format.test.js.snap | 4 +- yarn.lock | 30 ++++++------- 12 files changed, 115 insertions(+), 52 deletions(-) create mode 100644 tests/format/flow/records/no-line-break-before-expression/__snapshots__/format.test.js.snap create mode 100644 tests/format/flow/records/no-line-break-before-expression/expression.js create mode 100644 tests/format/flow/records/no-line-break-before-expression/format.test.js create mode 100644 tests/format/misc/errors/flow/record/__snapshots__/format.test.js.snap create mode 100644 tests/format/misc/errors/flow/record/format.test.js diff --git a/package.json b/package.json index 0c22cd165..2e891951a 100644 --- a/package.json +++ b/package.json @@ -73,11 +73,11 @@ "fast-json-stable-stringify": "2.1.0", "file-entry-cache": "11.1.1", "find-cache-directory": "6.0.0", - "flow-parser": "0.295.0", + "flow-parser": "0.296.0", "get-east-asian-width": "1.4.0", "get-stdin": "9.0.0", "graphql": "16.12.0", - "hermes-parser": "0.33.1", + "hermes-parser": "0.33.3", "html-element-attributes": "3.5.0", "html-ua-styles": "0.3.1", "ignore": "7.0.5", diff --git a/src/language-js/comments/handle-comments.js b/src/language-js/comments/handle-comments.js index 4e29d723f..a9cc371ec 100644 --- a/src/language-js/comments/handle-comments.js +++ b/src/language-js/comments/handle-comments.js @@ -704,7 +704,8 @@ function handleLastComponentArgComments({ if ( (precedingNode?.type === "ComponentParameter" || precedingNode?.type === "RestElement") && - enclosingNode?.type === "ComponentDeclaration" && + (enclosingNode?.type === "ComponentDeclaration" || + enclosingNode?.type === "DeclareComponent") && getNextNonSpaceNonCommentCharacter(text, locEnd(comment)) === ")" ) { addTrailingComment(precedingNode, comment); diff --git a/tests/format/flow/component/__snapshots__/format.test.js.snap b/tests/format/flow/component/__snapshots__/format.test.js.snap index 0c364134b..72c6abecb 100644 --- a/tests/format/flow/component/__snapshots__/format.test.js.snap +++ b/tests/format/flow/component/__snapshots__/format.test.js.snap @@ -337,11 +337,11 @@ declare component MyComponent(bar: string); declare component MyComponent(bar?: string); -declare component MyComponent('data-bar': string); +// declare component MyComponent('data-bar': string); declare component MyComponent(...restProps: $ReadOnly<{k: string}>); -declare component MyComponent(...$ReadOnly<{k: string}>); +// declare component MyComponent(...$ReadOnly<{k: string}>); declare component MyComponent(bar: string, baz: $ReadOnly<{k: string}>); @@ -355,7 +355,11 @@ declare component MyComponent( bar: string, // Trailing comment // preceding comment - 'data-baz': $ReadOnly<{k: string, reallllllllllllllllllllllllllllllllllllllyLong: string}> + dataBaz: $ReadOnly<{k: string, reallllllllllllllllllllllllllllllllllllllyLong: string}> + // Trailing comment + + // preceding comment + // 'data-baz': $ReadOnly<{k: string, reallllllllllllllllllllllllllllllllllllllyLong: string}> // Trailing comment ); @@ -368,6 +372,7 @@ declare component MyComponent( ...props: $ReadOnly<{k: string, reallllllllllllllllllllllllllllllllllllllyLong: string}> // Trailing comment ) renders SomeComponent; + =====================================output===================================== declare component MyComponent(); @@ -387,11 +392,11 @@ declare component MyComponent(bar: string); declare component MyComponent(bar?: string); -declare component MyComponent("data-bar": string); +// declare component MyComponent('data-bar': string); declare component MyComponent(...restProps: $ReadOnly<{ k: string }>); -declare component MyComponent(...$ReadOnly<{ k: string }>); +// declare component MyComponent(...$ReadOnly<{k: string}>); declare component MyComponent(bar: string, baz: $ReadOnly<{ k: string }>); @@ -409,11 +414,15 @@ declare component MyComponent( bar: string, // Trailing comment // preceding comment - "data-baz": $ReadOnly<{ + dataBaz: $ReadOnly<{ k: string, reallllllllllllllllllllllllllllllllllllllyLong: string, }>, // Trailing comment + + // preceding comment + // 'data-baz': $ReadOnly<{k: string, reallllllllllllllllllllllllllllllllllllllyLong: string}> + // Trailing comment ); declare component MyComponent( diff --git a/tests/format/flow/component/declare-component.js b/tests/format/flow/component/declare-component.js index 49d2bb3bb..1ace55408 100644 --- a/tests/format/flow/component/declare-component.js +++ b/tests/format/flow/component/declare-component.js @@ -12,11 +12,11 @@ declare component MyComponent(bar: string); declare component MyComponent(bar?: string); -declare component MyComponent('data-bar': string); +// declare component MyComponent('data-bar': string); declare component MyComponent(...restProps: $ReadOnly<{k: string}>); -declare component MyComponent(...$ReadOnly<{k: string}>); +// declare component MyComponent(...$ReadOnly<{k: string}>); declare component MyComponent(bar: string, baz: $ReadOnly<{k: string}>); @@ -30,7 +30,11 @@ declare component MyComponent( bar: string, // Trailing comment // preceding comment - 'data-baz': $ReadOnly<{k: string, reallllllllllllllllllllllllllllllllllllllyLong: string}> + dataBaz: $ReadOnly<{k: string, reallllllllllllllllllllllllllllllllllllllyLong: string}> + // Trailing comment + + // preceding comment + // 'data-baz': $ReadOnly<{k: string, reallllllllllllllllllllllllllllllllllllllyLong: string}> // Trailing comment ); @@ -42,4 +46,4 @@ declare component MyComponent( declare component MyComponent( ...props: $ReadOnly<{k: string, reallllllllllllllllllllllllllllllllllllllyLong: string}> // Trailing comment -) renders SomeComponent; \ No newline at end of file +) renders SomeComponent; diff --git a/tests/format/flow/records/no-line-break-before-expression/__snapshots__/format.test.js.snap b/tests/format/flow/records/no-line-break-before-expression/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..27d7f677c --- /dev/null +++ b/tests/format/flow/records/no-line-break-before-expression/__snapshots__/format.test.js.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`expression.js format 1`] = ` +====================================options===================================== +parsers: ["flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// Not a \`RecordExpression\` +const x = Foo +{ +}; + +=====================================output===================================== +// Not a \`RecordExpression\` +const x = Foo; +{ +} + +================================================================================ +`; diff --git a/tests/format/flow/records/no-line-break-before-expression/expression.js b/tests/format/flow/records/no-line-break-before-expression/expression.js new file mode 100644 index 000000000..2d50ebab6 --- /dev/null +++ b/tests/format/flow/records/no-line-break-before-expression/expression.js @@ -0,0 +1,4 @@ +// Not a `RecordExpression` +const x = Foo +{ +}; diff --git a/tests/format/flow/records/no-line-break-before-expression/format.test.js b/tests/format/flow/records/no-line-break-before-expression/format.test.js new file mode 100644 index 000000000..fa7a31c03 --- /dev/null +++ b/tests/format/flow/records/no-line-break-before-expression/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ["flow", "typescript"]); diff --git a/tests/format/js/explicit-resource-management/__snapshots__/format.test.js.snap b/tests/format/js/explicit-resource-management/__snapshots__/format.test.js.snap index b7ca39be3..717dde628 100644 --- a/tests/format/js/explicit-resource-management/__snapshots__/format.test.js.snap +++ b/tests/format/js/explicit-resource-management/__snapshots__/format.test.js.snap @@ -796,24 +796,24 @@ Cause: Unexpected token {" `; exports[`valid-module-block-top-level-await-using-binding.js [flow] format 1`] = ` -"Unexpected identifier, expected the token \`,\` (2:9) - 1 | const m = module { -> 2 | await using foo = bar(); - | ^^^^^ +"Unexpected token \`{\`, expected the token \`;\` (1:18) +> 1 | const m = module { + | ^ + 2 | await using foo = bar(); 3 | } 4 |" `; exports[`valid-module-block-top-level-await-using-binding.js [hermes] format 1`] = ` -"':' expected in property initialization (2:8) - 1 | const m = module { -> 2 | await using foo = bar(); - | ^ +"';' expected (1:17) +> 1 | const m = module { + | ^ + 2 | await using foo = bar(); 3 | } 4 | -Cause: ':' expected in property initialization (2:8) - await using foo = bar(); - ~~~~~~^" +Cause: ';' expected (1:17) +const m = module { + ^" `; exports[`valid-module-block-top-level-await-using-binding.js [meriyah] format 1`] = ` @@ -893,24 +893,24 @@ Cause: Unexpected token {" `; exports[`valid-module-block-top-level-using-binding.js [flow] format 1`] = ` -"Unexpected identifier, expected the token \`,\` (2:9) - 1 | module { -> 2 | using foo = bar(); - | ^^^ +"Unexpected token \`{\`, expected the end of an expression statement (\`;\`) (1:8) +> 1 | module { + | ^ + 2 | using foo = bar(); 3 | } 4 |" `; exports[`valid-module-block-top-level-using-binding.js [hermes] format 1`] = ` -"':' expected in property initialization (2:8) - 1 | module { -> 2 | using foo = bar(); - | ^ +"';' expected (1:7) +> 1 | module { + | ^ + 2 | using foo = bar(); 3 | } 4 | -Cause: ':' expected in property initialization (2:8) - using foo = bar(); - ~~~~~~^" +Cause: ';' expected (1:7) +module { + ^" `; exports[`valid-module-block-top-level-using-binding.js [meriyah] format 1`] = ` diff --git a/tests/format/misc/errors/flow/record/__snapshots__/format.test.js.snap b/tests/format/misc/errors/flow/record/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..d6bd49412 --- /dev/null +++ b/tests/format/misc/errors/flow/record/__snapshots__/format.test.js.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`snippet: #0 [flow] format 1`] = ` +"Unexpected token \`{\`, expected the token \`;\` (1:24) +> 1 | const a = not_a_record {} + | ^" +`; + +exports[`snippet: #0 [hermes] format 1`] = ` +"';' expected (1:23) +> 1 | const a = not_a_record {} + | ^ +Cause: ';' expected (1:23) +const a = not_a_record {} + ^" +`; diff --git a/tests/format/misc/errors/flow/record/format.test.js b/tests/format/misc/errors/flow/record/format.test.js new file mode 100644 index 000000000..39b093366 --- /dev/null +++ b/tests/format/misc/errors/flow/record/format.test.js @@ -0,0 +1,7 @@ +runFormatTest( + { + importMeta: import.meta, + snippets: ["const a = not_a_record {}"], + }, + ["flow", "hermes"], +); diff --git a/tests/format/misc/errors/js/explicit-resource-management/__snapshots__/format.test.js.snap b/tests/format/misc/errors/js/explicit-resource-management/__snapshots__/format.test.js.snap index 3681aca7f..e8bbd0df1 100644 --- a/tests/format/misc/errors/js/explicit-resource-management/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/js/explicit-resource-management/__snapshots__/format.test.js.snap @@ -92,10 +92,10 @@ Cause: Unexpected token, expected ")" (4:24)" `; exports[`invalid-using-binding-pattern.js [flow] format 1`] = ` -"Invalid left-hand side in assignment (2:3) +"Unexpected token \`{\`, expected the end of an expression statement (\`;\`) (2:9) 1 | { > 2 | using { foo } = f(); - | ^^^^^^^^^^^^^ + | ^ 3 | using [ bar ] = g(); 4 | for (using { qux } of h()); 5 | for (using [ quux ] of i());" diff --git a/yarn.lock b/yarn.lock index d311f66f6..c4438029b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5080,10 +5080,10 @@ __metadata: languageName: node linkType: hard -"flow-parser@npm:0.295.0": - version: 0.295.0 - resolution: "flow-parser@npm:0.295.0" - checksum: 10/a70b90d6a9e754199749eef58f69f203a807c857318baac144746f336c5f5266e4de5457c2976f2aee0a593736c9ac7c2501673e627f451acccf1f6305730120 +"flow-parser@npm:0.296.0": + version: 0.296.0 + resolution: "flow-parser@npm:0.296.0" + checksum: 10/bc7a799dc90ce8c1011356df99405cb88154182988448483e2b23b166e5fedecbe56a089dd6895a21bd2c7974ec158f21f2390db9532a74e4620bc3cfafd1ebd languageName: node linkType: hard @@ -5429,19 +5429,19 @@ __metadata: languageName: node linkType: hard -"hermes-estree@npm:0.33.1": - version: 0.33.1 - resolution: "hermes-estree@npm:0.33.1" - checksum: 10/8da08418f10c70bd943db3acfd6be3bca28de6974ab85034f087513d771546b7410246c8c03d7781ce3b613d2f03769058caa7f82e21028df7545284ba485caa +"hermes-estree@npm:0.33.3": + version: 0.33.3 + resolution: "hermes-estree@npm:0.33.3" + checksum: 10/dfaac7eb91e282cf04f26c8f557fcadbfb78f630062c7abc1e75b9765918103ebee1359dffbe6c5e42a52c7cee0b14420affda984d534f76ba3d7e8d9ba98215 languageName: node linkType: hard -"hermes-parser@npm:0.33.1": - version: 0.33.1 - resolution: "hermes-parser@npm:0.33.1" +"hermes-parser@npm:0.33.3": + version: 0.33.3 + resolution: "hermes-parser@npm:0.33.3" dependencies: - hermes-estree: "npm:0.33.1" - checksum: 10/f7caeb5609b47b44fcc3fc0be5d171ec1c5747db854e43eded16c1ff4de1bda4c6e00c115361e3bd62cbaca4518683f8e2bcab94034d6d762a1c3b4ab0af2bd8 + hermes-estree: "npm:0.33.3" + checksum: 10/709dac7283a9eab706f3fff5c6f09deee5197a1a38751da66fdf499a307120ba3ef14ce734715430a838145531973a8c0b69874bf5bc615cca10059ee87f5ff3 languageName: node linkType: hard @@ -8417,14 +8417,14 @@ __metadata: fast-json-stable-stringify: "npm:2.1.0" file-entry-cache: "npm:11.1.1" find-cache-directory: "npm:6.0.0" - flow-parser: "npm:0.295.0" + flow-parser: "npm:0.296.0" get-east-asian-width: "npm:1.4.0" get-port: "npm:7.1.0" get-stdin: "npm:9.0.0" gfm-test-suite: "npm:0.0.2" globals: "npm:17.0.0" graphql: "npm:16.12.0" - hermes-parser: "npm:0.33.1" + hermes-parser: "npm:0.33.3" html-element-attributes: "npm:3.5.0" html-ua-styles: "npm:0.3.1" ignore: "npm:7.0.5"