-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support flow, apply to react native modules by default
- Loading branch information
Showing
12 changed files
with
374 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {transform} from 'sucrase' | ||
|
||
/** | ||
* Strip flow types from the given source code. | ||
* | ||
* Why sucrase is used instead of babel, bundle size of this package: | ||
* - `sucrase`: 848kb -> 1.1mb | ||
* - `@babel/core` (with `@babel/plugin-transform-flow-strip-types`): 848kb -> 5.7mb | ||
*/ | ||
export function stripFlowTypes(source: string, filename?: string) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call | ||
const result = transform(source, { | ||
transforms: ['flow', 'jsx', 'imports'], | ||
jsxRuntime: 'automatic', | ||
production: true, | ||
filePath: filename, | ||
}) | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access | ||
return result.code | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
measure-bundle-size/test/__snapshots__/stripFlowTypes.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`stripFlowTypes 1`] = ` | ||
"\\"use strict\\";var _jsxruntime = require(\\"react/jsx-runtime\\");Object.defineProperty(exports, \\"__esModule\\", {value: true}); | ||
const countries = { | ||
US: \\"United States\\", | ||
IT: \\"Italy\\", | ||
FR: \\"France\\" | ||
}; | ||
const italy = 'IT'; exports.italy = italy; | ||
const foo = _jsxruntime.jsx.call(void 0, 'div', {} ); exports.foo = foo | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {stripFlowTypes} from '../src/stripFlowTypes'; | ||
|
||
test('stripFlowTypes', () => { | ||
const code = ` | ||
const countries = { | ||
US: "United States", | ||
IT: "Italy", | ||
FR: "France" | ||
}; | ||
type Country = $Keys<typeof countries>; | ||
export const italy: Country = 'IT'; | ||
export const foo = <div /> | ||
` | ||
expect(stripFlowTypes(code)).toMatchSnapshot() | ||
}) |
Oops, something went wrong.