@putout/printer
Advanced tools
Comparing version 1.6.2 to 1.6.3
'use strict'; | ||
module.exports.MemberExpression = (path, {traverse, write}) => { | ||
module.exports.MemberExpression = (path, {print}) => { | ||
const {computed} = path.node; | ||
const propertyPath = path.get('property'); | ||
traverse(path.get('object')); | ||
print('__object'); | ||
if (computed) { | ||
write('['); | ||
traverse(propertyPath); | ||
write(']'); | ||
print('['); | ||
print('__property'); | ||
print(']'); | ||
@@ -17,13 +16,11 @@ return; | ||
write('.'); | ||
traverse(propertyPath); | ||
print('.'); | ||
print('__property'); | ||
}; | ||
module.exports.OptionalMemberExpression = (path, {traverse, write}) => { | ||
const propertyPath = path.get('property'); | ||
traverse(path.get('object')); | ||
write('?.'); | ||
traverse(propertyPath); | ||
module.exports.OptionalMemberExpression = (path, {print}) => { | ||
print('__object'); | ||
print('?.'); | ||
print('__property'); | ||
}; | ||
@@ -5,9 +5,9 @@ 'use strict'; | ||
module.exports.NewExpression = (path, {write, maybeWrite, traverse, indent}) => { | ||
module.exports.NewExpression = (path, {indent, print, maybe}) => { | ||
indent(); | ||
write('new '); | ||
traverse(path.get('callee')); | ||
print('new '); | ||
print('__callee'); | ||
const args = path.get('arguments'); | ||
write('('); | ||
print('('); | ||
@@ -17,8 +17,8 @@ const n = args.length - 1; | ||
for (const [i, arg] of entries(args)) { | ||
traverse(arg); | ||
maybeWrite(i < n, ', '); | ||
print(arg); | ||
maybe.print(i < n, ', '); | ||
} | ||
write(')'); | ||
print(')'); | ||
}; | ||
@@ -12,3 +12,3 @@ 'use strict'; | ||
module.exports.ObjectExpression = (path, {traverse, write, maybe, indent}) => { | ||
module.exports.ObjectExpression = (path, {print, maybe, indent}) => { | ||
indent.inc(); | ||
@@ -21,6 +21,6 @@ | ||
maybe.write(parens, '('); | ||
write('{'); | ||
maybe.print(parens, '('); | ||
print('{'); | ||
maybe.write(manyLines, '\n'); | ||
maybe.print(manyLines, '\n'); | ||
@@ -30,7 +30,7 @@ for (const property of properties) { | ||
maybe.indent(length > 1); | ||
traverse(property); | ||
print(property); | ||
if (length > 1) { | ||
write(','); | ||
write.newline(); | ||
print(','); | ||
print.newline(); | ||
} | ||
@@ -46,16 +46,16 @@ | ||
if (property.isObjectMethod()) { | ||
traverse(property); | ||
print(property); | ||
continue; | ||
} | ||
maybe.write(computed, '['); | ||
traverse(property.get('key')); | ||
maybe.write(computed, ']'); | ||
maybe.print(computed, '['); | ||
print(property.get('key')); | ||
maybe.print(computed, ']'); | ||
if (!shorthand) { | ||
write(': '); | ||
traverse(property.get('value')); | ||
print(': '); | ||
print(property.get('value')); | ||
} | ||
maybe.write(manyLines, ',\n'); | ||
maybe.print(manyLines, ',\n'); | ||
} | ||
@@ -66,4 +66,4 @@ | ||
maybe.indent(manyLines); | ||
write('}'); | ||
maybe.write(parens, ')'); | ||
print('}'); | ||
maybe.print(parens, ')'); | ||
}; | ||
@@ -70,0 +70,0 @@ function isOneLine(path) { |
'use strict'; | ||
module.exports.RestElement = (path, {write, traverse}) => { | ||
write('...'); | ||
traverse(path.get('argument')); | ||
module.exports.RestElement = (path, {print}) => { | ||
print('...'); | ||
print('__argument'); | ||
}; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports.SequenceExpression = (path, {maybe, traverse}) => { | ||
module.exports.SequenceExpression = (path, {maybe, print}) => { | ||
const expressions = path.get('expressions'); | ||
@@ -11,7 +11,7 @@ const n = expressions.length - 1; | ||
for (const [index, expression] of entries(expressions)) { | ||
traverse(expression); | ||
maybe.write(index < n, ','); | ||
maybe.write(index < n, ' '); | ||
print(expression); | ||
maybe.print(index < n, ','); | ||
maybe.print(index < n, ' '); | ||
} | ||
}; | ||
'use strict'; | ||
module.exports.SpreadElement = (path, {write, traverse}) => { | ||
write('...'); | ||
traverse(path.get('argument')); | ||
module.exports.SpreadElement = (path, {print}) => { | ||
print('...'); | ||
print('__argument'); | ||
}; | ||
'use strict'; | ||
module.exports.UnaryExpression = unaryExpressions; | ||
module.exports.UpdateExpression = unaryExpressions; | ||
module.exports.AwaitExpression = (path, {write, traverse}) => { | ||
module.exports.UnaryExpression = unaryExpression; | ||
module.exports.UpdateExpression = unaryExpression; | ||
module.exports.AwaitExpression = (path, {print}) => { | ||
printUnary(path, 'await', { | ||
write, | ||
traverse, | ||
print, | ||
}); | ||
}; | ||
module.exports.YieldExpression = (path, {write, traverse}) => { | ||
module.exports.YieldExpression = (path, {print}) => { | ||
printUnary(path, 'yield', { | ||
write, | ||
traverse, | ||
print, | ||
}); | ||
}; | ||
module.exports.ThrowStatement = (path, {write, indent, traverse}) => { | ||
module.exports.ThrowStatement = (path, {print, indent}) => { | ||
indent(); | ||
printUnary(path, 'throw', { | ||
write, | ||
traverse, | ||
print, | ||
}); | ||
write(';'); | ||
write.newline(); | ||
print(';'); | ||
print.newline(); | ||
}; | ||
function printUnary(path, name, {write, traverse}) { | ||
write(`${name} `); | ||
traverse(path.get('argument')); | ||
function printUnary(path, name, {print}) { | ||
print(`${name} `); | ||
print('__argument'); | ||
} | ||
@@ -37,14 +34,14 @@ | ||
function unaryExpressions(path, {traverse, write, maybe}) { | ||
function unaryExpression(path, {print, maybe}) { | ||
const {prefix, operator} = path.node; | ||
if (prefix) | ||
write(operator); | ||
print(operator); | ||
maybe.write(isWord(operator), ' '); | ||
traverse(path.get('argument')); | ||
maybe.print(isWord(operator), ' '); | ||
print('__argument'); | ||
if (!prefix) | ||
write(operator); | ||
print(operator); | ||
} | ||
@@ -7,13 +7,12 @@ 'use strict'; | ||
TemplateLiteral, | ||
NumericLiteral(path, {write}) { | ||
const {raw} = path.node; | ||
write(raw); | ||
//write(raw || extra.raw); | ||
NumericLiteral(path, {print}) { | ||
const {raw, extra} = path.node; | ||
print(raw || extra.raw); | ||
}, | ||
BooleanLiteral(path, {write}) { | ||
write(path.node.value); | ||
BooleanLiteral(path, {print}) { | ||
print(path.node.value); | ||
}, | ||
StringLiteral(path, {write}) { | ||
StringLiteral(path, {print}) { | ||
const {value} = path.node; | ||
write(`'${value}'`); | ||
print(`'${value}'`); | ||
}, | ||
@@ -20,0 +19,0 @@ Identifier(path, {write}) { |
'use strict'; | ||
const isObject = (a) => a && typeof a === 'object'; | ||
const babelTraverse = require('@babel/traverse').default; | ||
@@ -46,3 +48,2 @@ const expressions = require('./expressions'); | ||
const maybeWrite = (a, b) => a && write(b); | ||
const maybeIndent = (a) => a && indent(); | ||
@@ -98,3 +99,2 @@ const maybeIndentInc = (a) => a && indent.inc(); | ||
const maybe = { | ||
write: maybeWrite, | ||
indent: maybeIndent, | ||
@@ -115,3 +115,2 @@ markBefore: maybeMarkBefore, | ||
write, | ||
maybeWrite, | ||
debug, | ||
@@ -184,9 +183,10 @@ maybeIndent, | ||
if (!isString(maybeLine)) | ||
if (isString(maybeLine) && maybeLine.startsWith(GET)) | ||
return traverse(get(path, maybeLine)); | ||
if (isObject(maybeLine)) | ||
return traverse(maybeLine); | ||
if (maybeLine.startsWith(GET)) | ||
return traverse(get(path, maybeLine)); | ||
return write(maybeLine); | ||
}; | ||
{ | ||
"name": "@putout/printer", | ||
"version": "1.6.2", | ||
"version": "1.6.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
37757
1054