diff --git a/app/common/command/build/Dist.php b/app/common/command/build/Dist.php index 1149529..f216552 100644 --- a/app/common/command/build/Dist.php +++ b/app/common/command/build/Dist.php @@ -6,6 +6,7 @@ namespace app\common\command\build; use app\common\tools\PathTools; use app\common\tools\phpparser\MinifyPrinterTools; +use app\common\tools\phpparser\NodeFakeVarVisitorTools; use app\common\tools\phpparser\NodeVisitorTools; use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; @@ -313,6 +314,11 @@ class Dist extends Command } } + $traverser = new NodeTraverser(); + + $traverser->addVisitor(new NodeFakeVarVisitorTools); + + $stmts = $traverser->traverse($stmts); $newCode = $prettyPrinter->prettyPrintFile($stmts); @@ -410,6 +416,12 @@ class Dist extends Command } + $traverser = new NodeTraverser(); + + $traverser->addVisitor(new NodeFakeVarVisitorTools); + + $function_stmts = $traverser->traverse($function_stmts); + $prettyPrinter = new MinifyPrinterTools(); $function_code = $prettyPrinter->prettyPrintFile($function_stmts); diff --git a/app/common/tools/phpparser/NodeFakeVarVisitorTools.php b/app/common/tools/phpparser/NodeFakeVarVisitorTools.php new file mode 100644 index 0000000..68bfa7d --- /dev/null +++ b/app/common/tools/phpparser/NodeFakeVarVisitorTools.php @@ -0,0 +1,50 @@ +name)) { + + if (in_array($node->name, $this->skipVariableName)) { + return; + } + + if (!isset($this::$varNameMap[$node->name])) { + $var_name = 'ul' . uniqid(); + $this::$varNameMap[$node->name] = $var_name; + } + + $node->name = $this::$varNameMap[$node->name]; + return $node; + } + } + } +} diff --git a/app/common/tools/phpparser/NodeVisitorTools.php b/app/common/tools/phpparser/NodeVisitorTools.php index 3960184..7535b79 100644 --- a/app/common/tools/phpparser/NodeVisitorTools.php +++ b/app/common/tools/phpparser/NodeVisitorTools.php @@ -53,7 +53,7 @@ class NodeVisitorTools extends NodeVisitorAbstract public function leaveNode(Node $node) { - if ($node instanceof Stmt) { + if ($node instanceof Node) { if (isset($node->attributes['comments'])) { $comments = $node->attributes['comments'];