From 55aec4805cec15f83dd33c326b6c91ed14b0c389 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Mon, 27 Jan 2020 18:26:47 +0530 Subject: [PATCH] example - App - show swap expression transform by default --- example/src/App.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/example/src/App.js b/example/src/App.js index 7c00cb1..4888270 100644 --- a/example/src/App.js +++ b/example/src/App.js @@ -7,7 +7,7 @@ import { } from "ts-transformer-visualizer"; import * as ts from "typescript"; -const source = "x = 1;"; +const source = "x = y;\nx=1;\nx=y=z;"; const mainFile = ts.createSourceFile("/test", source, ts.ScriptTarget.ES2015); @@ -19,11 +19,13 @@ const transformer = context => { * @returns {ts.VisitResult} */ const visitor = node => { - // If it is a expression statement, - if (ts.isExpressionStatement(node)) { - // Return it twice. - // Effectively duplicating the statement - return [node, ts.getMutableClone(node)]; + if ( + ts.isBinaryExpression(node) && + node.operatorToken.kind === ts.SyntaxKind.EqualsToken && + ts.isIdentifier(node.left) && + ts.isIdentifier(node.right) + ) { + return ts.updateBinary(node, node.right, node.left); } return ts.visitEachChild(node, visitor, context);