@putout/printer
Advanced tools
Comparing version 1.14.2 to 1.14.3
@@ -6,3 +6,3 @@ 'use strict'; | ||
module.exports.ForStatement = { | ||
print(path, {print, maybe, indent}) { | ||
print(path, {print, maybe}) { | ||
const { | ||
@@ -28,6 +28,8 @@ test, | ||
} else { | ||
print.newline(); | ||
indent.inc(); | ||
const is = !path.get('body').isEmptyStatement(); | ||
maybe.print.newline(is); | ||
maybe.indent.inc(is); | ||
print('__body'); | ||
indent.dec(); | ||
maybe.indent.dec(is); | ||
} | ||
@@ -34,0 +36,0 @@ }, |
@@ -6,45 +6,55 @@ 'use strict'; | ||
module.exports.IfStatement = (path, {indent, print}) => { | ||
if (shouldAddNewlineBefore(path)) { | ||
const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement(); | ||
module.exports.IfStatement = { | ||
before: (path, {print}) => { | ||
print.linebreak(); | ||
} | ||
indent(); | ||
print('if ('); | ||
print('__test'); | ||
print(')'); | ||
const consequent = path.get('consequent'); | ||
const alternate = path.get('alternate'); | ||
if (consequent.isBlockStatement()) { | ||
print(' '); | ||
print(consequent); | ||
} else { | ||
}, | ||
beforeIf: shouldAddNewlineBefore, | ||
print: (path, {indent, print, maybe}) => { | ||
indent(); | ||
print('if ('); | ||
print('__test'); | ||
print(')'); | ||
const consequent = path.get('consequent'); | ||
const alternate = path.get('alternate'); | ||
if (consequent.isBlockStatement()) { | ||
print(' '); | ||
print(consequent); | ||
} else { | ||
const is = !isEmptyConsequent(path); | ||
maybe.print.newline(is); | ||
maybe.indent.inc(is); | ||
print(consequent); | ||
maybe.indent.dec(is); | ||
} | ||
if (alternate.isBlockStatement()) { | ||
print(' else '); | ||
print(alternate); | ||
} else if (alternate.node) { | ||
print.breakline(); | ||
print('else'); | ||
print.newline(); | ||
indent.inc(); | ||
print(alternate); | ||
indent.dec(); | ||
} | ||
}, | ||
afterIf: (path) => { | ||
const next = path.getNextSibling(); | ||
if (!next.node || next.isExpressionStatement() || next.isReturnStatement()) | ||
return false; | ||
return true; | ||
}, | ||
after: (path, {print}) => { | ||
print.indent(); | ||
print.newline(); | ||
indent.inc(); | ||
print(consequent); | ||
indent.dec(); | ||
} | ||
if (alternate.isBlockStatement()) { | ||
print(' else '); | ||
print(alternate); | ||
} else if (alternate.node) { | ||
print.breakline(); | ||
print('else'); | ||
print.newline(); | ||
indent.inc(); | ||
print(alternate); | ||
indent.dec(); | ||
} | ||
const next = path.getNextSibling(); | ||
if (!next.node || next.isExpressionStatement() || next.isReturnStatement()) | ||
return; | ||
print.indent(); | ||
print.newline(); | ||
markAfter(path); | ||
markAfter(path); | ||
}, | ||
}; | ||
@@ -51,0 +61,0 @@ |
@@ -38,3 +38,5 @@ 'use strict'; | ||
}, | ||
EmptyStatement({}) {}, | ||
EmptyStatement(path, {write}) { | ||
write(';'); | ||
}, | ||
InterpreterDirective(path, {print}) { | ||
@@ -41,0 +43,0 @@ print(`#!${path.node.value}`); |
{ | ||
"name": "@putout/printer", | ||
"version": "1.14.2", | ||
"version": "1.14.3", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57855
1658