Skip to content

Commit 3147244

Browse files
committed
chore: rest ts
1 parent 5ff95c6 commit 3147244

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/jest/demoPreprocessor.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,34 @@ function createDemo({ types: t }: { types: typeof babel.types }): babel.PluginOb
5353
},
5454

5555
CallExpression(path) {
56+
const callee = path.node.callee as Extract<
57+
babel.types.Expression,
58+
{
59+
type: 'MemberExpression';
60+
}
61+
>;
62+
63+
type Identifier = Extract<
64+
typeof callee.object,
65+
{
66+
type: 'Identifier';
67+
}
68+
>;
69+
5670
if (
57-
path.node.callee.object &&
58-
(path.node.callee.object as { name: string }).name === 'ReactDOM' &&
59-
path.node.callee.property.name === 'render'
71+
callee.object &&
72+
(callee.object as Identifier).name === 'ReactDOM' &&
73+
(callee.property as Identifier).name === 'render'
6074
) {
6175
const app = t.variableDeclaration('const', [
62-
t.variableDeclarator(t.identifier('__Demo'), path.node.arguments[0]),
76+
t.variableDeclarator(
77+
t.identifier('__Demo'),
78+
(
79+
path.node as {
80+
arguments: babel.types.Expression[];
81+
}
82+
).arguments[0]
83+
),
6384
]);
6485
path.scope.registerDeclaration(path.replaceWith(app)[0]);
6586
const exportDefault = t.exportDefaultDeclaration(t.identifier('__Demo'));
@@ -93,7 +114,7 @@ interface GetCacheKeyOptions {
93114
configString: string;
94115
}
95116

96-
function process(src: string, pathFilename: string): ProcessResult {
117+
function transform(src: string, pathFilename: string): ProcessResult {
97118
const markdown = markTwain(src);
98119
src = getCode(markdown.content);
99120

@@ -151,6 +172,6 @@ function getCacheKey(fileData: string, filename: string, options: GetCacheKeyOpt
151172
}
152173

153174
export default {
154-
process,
175+
process: transform,
155176
getCacheKey,
156177
};

0 commit comments

Comments
 (0)