Skip to content

Commit

Permalink
feat: strip flow syntax with keep esm statements
Browse files Browse the repository at this point in the history
- remove "imports" from sucrase transforms
- strip typeof import statements manually
  • Loading branch information
leegeunhyeok committed Nov 16, 2023
1 parent 4646fc3 commit bec3b70
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/transformer/lib/transformer/sucrase/sucrase.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { transform, type Transform } from 'sucrase';
import type { SyncTransformer } from '../../types';

const TRANSFORM_FOR_STRIP_FLOW: Transform[] = ['flow', 'imports', 'jsx'];
const TRANSFORM_FOR_STRIP_FLOW: Transform[] = ['flow', 'jsx'];

const stripFlowTypeofImportStatements = (code: string): string => {
return code
.split('\n')
.filter((line) => !line.startsWith('import typeof '))
.join('\n');
};

export const stripFlowWithSucrase: SyncTransformer<void> = (code, context) => {
return transform(code, {
transforms: TRANSFORM_FOR_STRIP_FLOW,
filePath: context.path,
}).code;
return stripFlowTypeofImportStatements(
transform(code, {
transforms: TRANSFORM_FOR_STRIP_FLOW,
filePath: context.path,
}).code,
);
};

2 comments on commit bec3b70

@vercel
Copy link

@vercel vercel bot commented on bec3b70 Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🔴 Statements 16.22% 328/2022
🔴 Branches 16.3% 82/503
🔴 Functions 10.8% 65/602
🔴 Lines 15.51% 298/1921

Test suite run success

83 tests passing in 10 suites.

Report generated by 🧪jest coverage report action from bec3b70

Please sign in to comment.