@yuyi919/ts-transformer-awesome
What is CustomTransformer ?
interface CustomTransformers {
/** Custom transformers to evaluate before built-in .js transformations. */
before?: (TransformerFactory<SourceFile> | CustomTransformerFactory)[];
/** Custom transformers to evaluate after built-in .js transformations. */
after?: (TransformerFactory<SourceFile> | CustomTransformerFactory)[];
/** Custom transformers to evaluate after built-in .d.ts transformations. */
afterDeclarations?: (TransformerFactory<Bundle | SourceFile> | CustomTransformerFactory)[];
}
Api
const { getCustomTransformers } = require('@yuyi919/ts-transformer-awesome')
// ts.createProgram(...)
getCustomTransformers({
program, // ts.Program
importLibs: [
'lodash',
['@material-ui/core', {
libraryDirectory: '',
camel2DashComponentName: false
}]
] // use ts-import-plugin
// ...
}) // { before: [...], after: [...] }
global env
import '@yuyi919/ts-transformer-awesome/env'
Basic
ts-nameof
点击此处查看更多
ts-transformer-keys
就像使用ts-transformer-keys
一样
interface A {
a: number;
b: number;
}
tsKeys<A>() // => ["a", "b"]
点击此处查看更多
tsx-control-statements
就像使用tsx-control-statements
一样
// 转换前
const TsxControlStatments = () => {
return (
<For of={[1, 2, 3]} each="item" index="itemIndex">
<a style={{ background: 'red' }}>{itemIndex}{item}</a>
</For>
);
}
// 转换后
var TsxControlStatments = () => {
return Array.from([1, 2, 3], function (item, itemIndex) {
return React.createElement("a", {
style: __$hoisted_o0
/**
* 此处是`@avensia-oss/ts-transform-hoist-objects-in-props`在发挥作用
*/
}, itemIndex);
});
}
// 自动静态化转译
var __$hoisted_o0 = {
background: 'red'
};
点击此处查看更多