-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplaceFileName.ts
More file actions
42 lines (35 loc) · 934 Bytes
/
Copy pathreplaceFileName.ts
File metadata and controls
42 lines (35 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as ts from "typescript"
const transformer: ts.TransformerFactory<ts.SourceFile> = (
context,
) => {
return (sourceFile) => {
console.log("its me")
const visitor = (
node: ts.Node,
): ts.Node | undefined => {
if (ts.isImportDeclaration(node)) {
return undefined
}
if (ts.isIdentifier(node)) {
switch (node.escapedText) {
case "babel":
return ts.factory.createIdentifier("a")
case "plugins":
return ts.factory.createIdentifier("b")
}
}
return ts.visitEachChild(node, visitor, context)
}
const sourceFileVisitor = (
sourceFile: ts.SourceFile,
): ts.SourceFile => {
return ts.visitEachChild(sourceFile, visitor, context)
}
return ts.visitNode(
sourceFile,
sourceFileVisitor,
ts.isSourceFile,
)
}
}
export default TransformStreamDefaultController