Skip to content

Instantly share code, notes, and snippets.

@orenelbaum
Created December 8, 2022 07:24
Show Gist options
  • Save orenelbaum/c039b1aa9f19fa0eae7c0d3808fc8ee1 to your computer and use it in GitHub Desktop.
Save orenelbaum/c039b1aa9f19fa0eae7c0d3808fc8ee1 to your computer and use it in GitHub Desktop.
Civet / TS comparison
{ babel } from '@rollup/plugin-babel'
{ Plugin } from 'rollup'
{ handleRemainingPluginImports } from './handle-remaining-plugin-imports'
{ funcVisitor } from './func-visitor'
// This is the entry point for babel.
export babelPluginUndestructure :=->
visitor :=
FunctionDeclaration: funcVisitor
FunctionExpression: funcVisitor
ArrowFunctionExpression: funcVisitor
Program: { exit: handleRemainingPluginImports }
{ name: 'babel-plugin-solid-undestructure', visitor }
// This export is used for configuration.
export undestructurePlugin := (mode?: 'ts' | 'vanilla-js') ->
if !mode || mode === 'ts' return [
{
...babel(
plugins: [
['@babel/plugin-syntax-typescript', { isTSX: true }]
'babel-plugin-solid-undestructure'
]
extensions: ['.tsx']
)
enforce: 'pre'
} as Plugin
{
...babel({
plugins: [
'@babel/plugin-syntax-typescript'
'babel-plugin-solid-undestructure'
]
extensions: ['.ts']
babelHelpers: 'bundled'
})
enforce: 'pre'
} as Plugin
]
else if mode === 'vanilla-js'
return ['babel-plugin-solid-undestructure', { mode: 'vanilla-js' }]
else throw new Error(
`babel-plugin-solid-undestructure error: Invalid mode.
Mode must be either 'ts' or 'vanilla-js'
`
)
import { babel } from '@rollup/plugin-babel'
import { Plugin } from 'rollup'
import { handleRemainingPluginImports } from './handle-remaining-plugin-imports'
import { funcVisitor } from './func-visitor'
// This is the entry point for babel.
export const babelPluginUndestructure = () => {
const visitor = {
FunctionDeclaration: funcVisitor,
FunctionExpression: funcVisitor,
ArrowFunctionExpression: funcVisitor,
Program: { exit: handleRemainingPluginImports }
}
return { name: 'babel-plugin-solid-undestructure', visitor }
}
// This export is used for configuration.
export const undestructurePlugin = (mode: 'ts') => {
if (!mode || mode === 'ts') return [
{
...babel({
plugins: [
['@babel/plugin-syntax-typescript', { isTSX: true }],
'babel-plugin-solid-undestructure'
],
extensions: ['.tsx']
}),
enforce: 'pre'
} as Plugin,
{
...babel({
plugins: [
'@babel/plugin-syntax-typescript',
'babel-plugin-solid-undestructure'
],
extensions: ['.ts'],
babelHelpers: 'bundled'
}),
enforce: 'pre'
} as Plugin
]
else if (mode === 'vanilla-js')
return ['babel-plugin-solid-undestructure', { mode: 'vanilla-js' }]
else throw new Error(
`babel-plugin-solid-undestructure error: Invalid mode.
Mode must be either 'ts' or 'vanilla-js'
`
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment