@putout/printer
Advanced tools
Comparing version 1.71.2 to 1.72.0
'use strict'; | ||
const {isNext} = require('./is'); | ||
const { | ||
@@ -5,0 +6,0 @@ markBefore, |
'use strict'; | ||
module.exports.ObjectMethod = (path, {print}) => { | ||
const {kind} = path.node; | ||
if (kind !== 'method') | ||
print(`${kind} `); | ||
print('__key'); | ||
print('('); | ||
const params = path.get('params'); | ||
const n = params.length - 1; | ||
for (let i = 0; i <= n; i++) { | ||
print(params[i]); | ||
const {isNewlineBetweenSiblings} = require('../../is'); | ||
module.exports.ObjectMethod = { | ||
print(path, {print}) { | ||
const {kind} = path.node; | ||
if (i < n) | ||
print(', '); | ||
} | ||
print(') '); | ||
print('__body'); | ||
if (kind !== 'method') | ||
print(`${kind} `); | ||
print('__key'); | ||
print('('); | ||
const params = path.get('params'); | ||
const n = params.length - 1; | ||
for (let i = 0; i <= n; i++) { | ||
print(params[i]); | ||
if (i < n) | ||
print(', '); | ||
} | ||
print(') '); | ||
print('__body'); | ||
}, | ||
afterIf(path) { | ||
return isNewlineBetweenSiblings(path); | ||
}, | ||
after(path, {print}) { | ||
print.linebreak(); | ||
}, | ||
}; | ||
@@ -8,2 +8,4 @@ 'use strict'; | ||
const insideCase = (path) => path.parentPath.isSwitchCase(); | ||
module.exports.BreakStatement = { | ||
@@ -24,4 +26,7 @@ split(path, {print}) { | ||
if (insideCase(path)) | ||
return true; | ||
return false; | ||
}, | ||
}; |
@@ -45,2 +45,1 @@ 'use strict'; | ||
}; | ||
@@ -17,4 +17,5 @@ 'use strict'; | ||
const alternate = path.get('alternate'); | ||
const isConsequentBlock = consequent.isBlockStatement(); | ||
if (consequent.isBlockStatement()) { | ||
if (isConsequentBlock) { | ||
print(' '); | ||
@@ -39,2 +40,3 @@ print(consequent); | ||
} else if (exists(alternate)) { | ||
maybe.indent(!isConsequentBlock); | ||
write('else'); | ||
@@ -41,0 +43,0 @@ print.newline(); |
'use strict'; | ||
module.exports.SwitchStatement = (path, {print, maybe}) => { | ||
print('switch'); | ||
print.space(); | ||
print('('); | ||
print('__discriminant'); | ||
print(') {'); | ||
print.newline(); | ||
const cases = path.get('cases'); | ||
const n = cases.length - 1; | ||
for (const [index, switchCase] of cases.entries()) { | ||
print('case'); | ||
const {isNext} = require('../is'); | ||
module.exports.SwitchStatement = { | ||
print(path, {print, maybe}) { | ||
print('switch'); | ||
print.space(); | ||
print(switchCase.get('test')); | ||
print(':'); | ||
print('('); | ||
print('__discriminant'); | ||
print(') {'); | ||
print.newline(); | ||
const isBlock = switchCase.get('consequent.0').isBlockStatement(); | ||
maybe.indent.inc(!isBlock); | ||
maybe.print.newline(!isBlock); | ||
const cases = path.get('cases'); | ||
const n = cases.length - 1; | ||
for (const consequent of switchCase.get('consequent')) { | ||
if (!consequent.isBlockStatement()) { | ||
for (const [index, switchCase] of cases.entries()) { | ||
print('case'); | ||
print.space(); | ||
print(switchCase.get('test')); | ||
print(':'); | ||
const isBlock = switchCase.get('consequent.0').isBlockStatement(); | ||
maybe.indent.inc(!isBlock); | ||
maybe.print.newline(!isBlock); | ||
for (const consequent of switchCase.get('consequent')) { | ||
if (!consequent.isBlockStatement()) { | ||
print(consequent); | ||
continue; | ||
} | ||
print.space(); | ||
print(consequent); | ||
continue; | ||
} | ||
print.space(); | ||
print(consequent); | ||
if (index < n) { | ||
print.linebreak(); | ||
} | ||
maybe.indent.dec(!isBlock); | ||
} | ||
if (index < n) { | ||
print.indent(); | ||
maybe.indent.dec(!isBlock); | ||
print.newline(); | ||
} | ||
} | ||
print('}'); | ||
print('}'); | ||
}, | ||
afterSatisfy: () => [ | ||
isNext, | ||
], | ||
after(path, {print}) { | ||
print.breakline(); | ||
print.breakline(); | ||
}, | ||
}; |
{ | ||
"name": "@putout/printer", | ||
"version": "1.71.2", | ||
"version": "1.72.0", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", |
Sorry, the diff of this file is not supported yet
103340
2709