-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow TypeScript in worklet classes (#6667)
Turns out `@babel/preset-typescript` always has to be included when calling `transformSync` from `babel` (it cannot be included in a later call). Due to that I made all `transformSync` calls into a wrapper call that uses a required set of plugins and presets. Fixes - #6642 - [x] Plugin unit tests pass - [x] Runtime tests pass
- Loading branch information
Showing
9 changed files
with
115 additions
and
43 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,28 @@ | ||
import { transformSync } from '@babel/core'; | ||
import type { PluginItem, TransformOptions } from '@babel/core'; | ||
|
||
export function workletTransformSync( | ||
code: string, | ||
opts: WorkletTransformOptions | ||
) { | ||
const { extraPlugins = [], extraPresets = [], ...rest } = opts; | ||
|
||
return transformSync(code, { | ||
...rest, | ||
plugins: [...defaultPlugins, ...extraPlugins], | ||
presets: [...defaultPresets, ...extraPresets], | ||
}); | ||
} | ||
|
||
const defaultPresets: PluginItem[] = [ | ||
require.resolve('@babel/preset-typescript'), | ||
]; | ||
|
||
const defaultPlugins: PluginItem[] = []; | ||
|
||
interface WorkletTransformOptions | ||
extends Omit<TransformOptions, 'plugins' | 'presets'> { | ||
extraPlugins?: PluginItem[]; | ||
extraPresets?: PluginItem[]; | ||
filename: TransformOptions['filename']; | ||
} |
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