Skip to content

Commit

Permalink
fix(transformer): strip typeof import statements using regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
leegeunhyeok committed Sep 14, 2024
1 parent 443e727 commit 52f7c80
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/transformer/lib/pipelines/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
import { babelPresets } from '../transformer';
import type { TransformPipeline } from './pipeline';

const FLOW_SYMBOL = ['@flow', '@noflow'] as const;
const FLOW_SYMBOL = ['@flow', '@noflow', 'import typeof'] as const;

export abstract class TransformPipelineBuilder<
Step extends TransformStep<unknown>,
Expand Down
7 changes: 3 additions & 4 deletions packages/transformer/lib/transformer/sucrase/sucrase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { transform, type Transform } from 'sucrase';
import type { SyncTransformer } from '../../types';

const TRANSFORM_FOR_STRIP_FLOW: Transform[] = ['flow', 'jsx'];
const typeofImportRegExp =
/import\s+typeof\s+[^;]+\s+from\s+['"][^'"]+['"];\s*/g;

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

export const stripFlowWithSucrase: SyncTransformer<void> = (code, context) => {
Expand Down

1 comment on commit 52f7c80

@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.12% 328/2035
🔴 Branches 16.24% 82/505
🔴 Functions 10.8% 65/602
🔴 Lines 15.41% 298/1934

Test suite run success

83 tests passing in 10 suites.

Report generated by 🧪jest coverage report action from 52f7c80

Please sign in to comment.