Skip to content

Commit d11038c

Browse files
committed
my first transformer
1 parent 02ffaed commit d11038c

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"ts-node": "^9.1.1"
1111
},
1212
"scripts": {
13-
"start": "ts-node --compiler ttypescript source.ts"
13+
"start": "ts-node --compiler ttypescript source.ts",
14+
"build": "ttsc"
1415
},
1516
"repository": {
1617
"type": "git",

Diff for: source.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var hello = "world";
2+
console.log(hello);

Diff for: source.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
console.log("hello")
1+
const hello = "test"
2+
console.log(hello)

Diff for: transform.ts

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import * as ts from 'typescript';
22

33
const transformer = (program: ts.Program): ts.TransformerFactory<ts.SourceFile> => context => sourceFile => {
44
const visitor = (node: ts.Node): ts.Node => {
5+
if (ts.isVariableDeclaration(node)) {
6+
return ts.updateVariableDeclaration(node, node.name, node.type, ts.createStringLiteral('world'));
7+
}
8+
59
console.log(node.kind, `\t# ts.SyntaxKind.${ts.SyntaxKind[node.kind]}`);
610
return ts.visitEachChild(node, visitor, context);
711
};

0 commit comments

Comments
 (0)