File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -944,6 +944,12 @@ module.exports = function (code) {
944944 // IllegalReturn
945945 const deleteIllegalReturn = require ( '../visitor/delete-illegal-return' )
946946 traverse ( ast , deleteIllegalReturn )
947+ // Lint before split statements
948+ const lintIfStatement = require ( '../visitor/lint-if-statement' )
949+ traverse ( ast , lintIfStatement )
950+ // Split declarations to avoid bugs
951+ const splitVarDeclaration = require ( '../visitor/split-variable-declaration' )
952+ traverse ( ast , splitVarDeclaration )
947953 // 清理二进制显示内容
948954 traverse ( ast , {
949955 StringLiteral : ( { node } ) => {
Original file line number Diff line number Diff line change 1+ const t = require ( '@babel/types' )
2+
3+ function LintIfStatement ( path ) {
4+ let { test, consequent, alternate } = path . node
5+ let changed = false
6+ if ( ! t . isBlockStatement ( consequent ) ) {
7+ consequent = t . blockStatement ( [ consequent ] )
8+ changed = true
9+ }
10+ if ( alternate && ! t . isBlockStatement ( alternate ) ) {
11+ alternate = t . blockStatement ( [ alternate ] )
12+ changed = true
13+ }
14+ if ( ! changed ) {
15+ return
16+ }
17+ path . replaceWith ( t . ifStatement ( test , consequent , alternate ) )
18+ }
19+
20+ module . exports = {
21+ IfStatement : { exit : LintIfStatement } ,
22+ }
You can’t perform that action at this time.
0 commit comments