src/nodes/arrays.js in prettier-0.22.0 vs src/nodes/arrays.js in prettier-1.0.0.pre.rc1

- old
+ new

@@ -7,10 +7,12 @@ join, line, softline } = require("../prettier"); +const { getTrailingComma } = require("../utils"); + // Checks that every argument within this args node is a string_literal node // that has no spaces or interpolations. This means we're dealing with an array // that looks something like: // // ['a', 'b', 'c'] @@ -35,13 +37,14 @@ // interpolated, so again we can return false. if (part.type !== "@tstring_content") { return false; } - // Finally, verify that the string doesn't contain a space or an escape - // character so that we know it can be put into a string literal array. - return !part.body.includes(" ") && !part.body.includes("\\"); + // Finally, verify that the string doesn't contain a space, an escape + // character, or brackets so that we know it can be put into a string + // literal array. + return !/[\s\\[\]]/.test(part.body); }); } // Checks that every argument within this args node is a symbol_literal node (as // opposed to a dyna_symbol) so it has no interpolation. This means we're @@ -151,10 +154,10 @@ "[", indent( concat([ softline, join(concat([",", line]), path.call(print, "body", 0)), - opts.addTrailingCommas ? ifBreak(",", "") : "" + getTrailingComma(opts) ? ifBreak(",", "") : "" ]) ), softline, "]" ])