Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
"eslint-plugin-lint": "^1.0.0",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-relay": "^1.8.3",
"flow-api-translator": "0.336.0",
"flow-api-translator": "0.340.0",
"flow-bin": "^0.340.0",
"flow-eslint": "0.336.0",
"flow-estree": "0.336.0",
"flow-parser": "0.336.0",
"flow-eslint": "0.340.0",
"flow-estree": "0.340.0",
"flow-parser": "0.340.0",
"invariant": "^2.2.4",
"istanbul-lib-coverage": "3.0.0",
"istanbul-lib-report": "3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/metro-babel-register/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@babel/preset-typescript": "^7.24.7",
"@babel/register": "^7.24.6",
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
"flow-parser": "0.336.0",
"flow-parser": "0.340.0",
"babel-plugin-transform-flow-enums": "^0.0.2",
"escape-string-regexp": "^1.0.5",
"flow-enums-runtime": "^0.0.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/metro-babel-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@babel/core": "^7.25.2",
"flow-enums-runtime": "^0.0.6",
"flow-parser": "0.336.0",
"flow-parser": "0.340.0",
"metro-cache-key": "0.88.0",
"nullthrows": "^1.1.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/metro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"debug": "^4.4.0",
"error-stack-parser": "^2.0.6",
"flow-enums-runtime": "^0.0.6",
"flow-parser": "0.336.0",
"flow-parser": "0.340.0",
"invariant": "^2.2.4",
"jest-worker": "^29.7.0",
"jsc-safe-url": "^0.2.2",
Expand Down
45 changes: 45 additions & 0 deletions scripts/__tests__/declaration-input-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/

import {expandFlowCommentTypes} from '../generateTypeScriptDefinitions';
import {translateFlowToFlowDef} from 'flow-api-translator';

test('declaration input removes an executable hashbang without moving lines', () => {
const source =
'#!/usr/bin/env node\r\n/** @flow */\r\nexport const value: string = "ok";';
expect(expandFlowCommentTypes(source)).toBe(
'\r\n/** @flow */\r\nexport const value: string = "ok";',
);
});

test('preserves hashbang text in ordinary strings', () => {
const source = 'export const value: string = "#!/usr/bin/env node";';
expect(expandFlowCommentTypes(source)).toBe(source);
});

test('expands comment types after removing a hashbang', () => {
const source = '#!/usr/bin/env node\nconst value /*: string */ = "ok";';
expect(expandFlowCommentTypes(source)).toBe(
'\nconst value : string = "ok";',
);
});

test('translates a typed CLI into declarations with the published parser', async () => {
const source =
'#!/usr/bin/env node\n/** @flow */\nexport const value: string = "ok";';
const result = await translateFlowToFlowDef(
expandFlowCommentTypes(source),
{},
{},
);
expect(result).not.toContain('#!');
expect(result).toContain('value: string');
});
7 changes: 4 additions & 3 deletions scripts/generateTypeScriptDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ export async function generateTsDefsForJsGlobs(
// https://flow.org/en/docs/types/comments/:
// `/*: T */` -> `: T`
// `/*:: code */` and `/*flow-include code */` -> `code`
function expandFlowCommentTypes(source: string): string {
export function expandFlowCommentTypes(source: string): string {
const declarationSource = source.replace(/^#![^\r\n]*/, '');
// Splice from the end so earlier comment ranges stay valid.
return parse(source, {flow: 'all'}).comments.reduceRight(
return parse(declarationSource, {flow: 'all'}).comments.reduceRight(
(code, {type, value, range: [start, end]}) => {
const marker =
type === 'Block' ? /^(::|flow-include|:)/.exec(value)?.[1] : null;
Expand All @@ -331,7 +332,7 @@ function expandFlowCommentTypes(source: string): string {
code.slice(end)
);
},
source,
declarationSource,
);
}

Expand Down
60 changes: 30 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3379,19 +3379,19 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787"
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==

flow-api-translator@0.336.0:
version "0.336.0"
resolved "https://registry.yarnpkg.com/flow-api-translator/-/flow-api-translator-0.336.0.tgz#588c4672c6a32f7fcb00064314b7ad1551e728a5"
integrity sha512-0odorqlErVwnXLuFpQdpRwlUNaqklR2H2tN8uRmlV/Usb82k0S++ReH3afKL7BhUevi4xMsBa02vd38Lf8RznQ==
flow-api-translator@0.340.0:
version "0.340.0"
resolved "https://registry.yarnpkg.com/flow-api-translator/-/flow-api-translator-0.340.0.tgz#c064bd1b86d0f68432d3aff620a3e4fc1e8543b5"
integrity sha512-scSfD46icbYxjzN4a0zER1Jc++po4TXeIKwCKQlKGjE7QfYNKpdf3KoN8hjnAH1HsVjM14gDYglYKqQepZ+AiQ==
dependencies:
"@babel/code-frame" "^7.16.0"
"@typescript-eslint/parser" "8.38.0"
"@typescript-eslint/visitor-keys" "8.38.0"
flow-enums-runtime "^0.0.6"
flow-eslint "0.336.0"
flow-estree "0.336.0"
flow-parser "0.336.0"
flow-transform "0.336.0"
flow-eslint "0.340.0"
flow-estree "0.340.0"
flow-parser "0.340.0"
flow-transform "0.340.0"
typescript "5.3.2"

flow-bin@^0.340.0:
Expand All @@ -3404,38 +3404,38 @@ flow-enums-runtime@^0.0.6:
resolved "https://registry.yarnpkg.com/flow-enums-runtime/-/flow-enums-runtime-0.0.6.tgz#5bb0cd1b0a3e471330f4d109039b7eba5cb3e787"
integrity sha512-3PYnM29RFXwvAN6Pc/scUfkI7RwhQ/xqyLUyPNlXUp9S40zI8nup9tUSrTLSVnWGBN38FNiGWbwZOB6uR4OGdw==

flow-eslint@0.336.0:
version "0.336.0"
resolved "https://registry.yarnpkg.com/flow-eslint/-/flow-eslint-0.336.0.tgz#2a9e807c85f41f8ba2329e787fd84bc67c411f6d"
integrity sha512-HWsiMD2mC3HbVwPKX74BxyX+ZjgiJi3BYDOG/FofbpLce/Eg1wftSuGEyvWprYpgKOnTEe/7o32IdLdTv25LaQ==
flow-eslint@0.340.0:
version "0.340.0"
resolved "https://registry.yarnpkg.com/flow-eslint/-/flow-eslint-0.340.0.tgz#dbca65729dd9d671ae06ff935b6a0897f22f8d9f"
integrity sha512-Ms9ViJJtdv5dMH3M4i6jD3j+YTg0DyNN8rzLQrBKHLcsxH0zFbv4uajpJK9SgLmw2RKaBuuwRXKdDgfsfanWKQ==
dependencies:
esrecurse "^4.3.0"
flow-estree "0.336.0"
flow-parser "0.336.0"
flow-estree "0.340.0"
flow-parser "0.340.0"

flow-estree@0.336.0:
version "0.336.0"
resolved "https://registry.yarnpkg.com/flow-estree/-/flow-estree-0.336.0.tgz#e9e90c68ac69b078b2d167588e47a11e5d240d86"
integrity sha512-0VaGWHJourzh88otU5bVJ4Z/oIsD+R6yaeR0Q8t8dezsKQI/RLi5m3fNzkiLYLhJ+YwM3JRSKlOqGplOI5Yo3w==
flow-estree@0.340.0:
version "0.340.0"
resolved "https://registry.yarnpkg.com/flow-estree/-/flow-estree-0.340.0.tgz#e86e368f5f33f4f5cc8871a18d3f79122569ebc2"
integrity sha512-LpYdzPWHsfDAc5nNmVrUPLo8UedFkJqogIxNyVO19tG7qBhvNwjs+Oo4TfWB+2Qa4arFevu3vdbxR5tfWps53g==

flow-parser@0.*, flow-parser@0.336.0:
version "0.336.0"
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.336.0.tgz#5c34f8a97edfa241d3e71c7a1dcd99a56b1cc2bc"
integrity sha512-O8QvQf/B3rBF+eagcc9/WMAjfJoaKckdgSd8PT/qvMIIe4ZjVKrSqV5SDnRFAKY0VrE8r5C4ADYgvYhmwkWADA==
flow-parser@0.*, flow-parser@0.340.0:
version "0.340.0"
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.340.0.tgz#7e1790634772a462612cc3d3347e2979ca4261af"
integrity sha512-zB1DgZcBVes/hHj/upWKLhukHAIkj+6g2o0yVnxCxS1Wyi/YLX513w8XpFLJ7/LUrbSE7CIHJAEZ94smHujt9Q==
dependencies:
flow-estree "0.336.0"
flow-estree "0.340.0"

flow-transform@0.336.0:
version "0.336.0"
resolved "https://registry.yarnpkg.com/flow-transform/-/flow-transform-0.336.0.tgz#61fd6c761b63c412b67c707dcd81333d24e5fa8d"
integrity sha512-KQEt9y581jhxaUOM80sPbssa/t6bEnwGz0x/xfwmxXv8a69bs6wW83/1Roq1h9qoJfwvSTncWk3IlrpdBVBXXQ==
flow-transform@0.340.0:
version "0.340.0"
resolved "https://registry.yarnpkg.com/flow-transform/-/flow-transform-0.340.0.tgz#ae9fa16ba916378d25806606fa7073c921652e29"
integrity sha512-JC7YcbERLI0XV0D3BkAXCFkZktq0EILxXRvJsWoHjdAZAZe2hIS1DGOmhbRyFti6crskGD/ui8w8nLvM/SoPxg==
dependencies:
"@babel/code-frame" "^7.16.0"
esquery "^1.4.0"
flow-enums-runtime "^0.0.6"
flow-eslint "0.336.0"
flow-estree "0.336.0"
flow-parser "0.336.0"
flow-eslint "0.340.0"
flow-estree "0.340.0"
flow-parser "0.340.0"
string-width "4.2.3"

for-each@^0.3.3, for-each@^0.3.5:
Expand Down
Loading