Skip to content

Commit 8a72c27

Browse files
committed
feature: @putout/printer: ArrayExpression: call: newline
1 parent d692805 commit 8a72c27

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

lib/tokenize/expressions/array-expression/array-expression.spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ test('printer: tokenizer: array-expression: strings: inside call', (t) => {
355355

356356
test('printer: tokenizer: statement: ArrayExpression: one element', (t) => {
357357
const ast = parse(fixture.arrayOneString);
358-
359358
const result = print(ast);
360359

361360
t.equal(result, fixture.arrayOneStringFix);
@@ -376,3 +375,11 @@ test('printer: tokenizer: array-expression: tuple strings last object', (t) => {
376375
t.print(fixture.arrayTupleStringsLastObject);
377376
t.end();
378377
});
378+
379+
test('printer: tokenizer: statement: ArrayExpression: call', (t) => {
380+
const ast = parse(fixture.arrayCall);
381+
const result = print(ast);
382+
383+
t.equal(result, fixture.arrayCallFix);
384+
t.end();
385+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
h1('Hello ', linkRef(imgRef('License', 'NPMURL'), 'NPMIMGURL')),
3+
def('NPMURL', 'https://npmjs.org/package/hello', 'npm'),
4+
def('NPMIMGURL', 'https://img.shields.io/npm/v/hello.svg?style=flat'),
5+
];

lib/tokenize/expressions/array-expression/fixture/array-call.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tokenize/expressions/array-expression/newline.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,16 @@ const isMixedTuples = (path, {maxElementLengthInOneLine}) => {
254254
return false;
255255
};
256256

257+
function hasCall(path) {
258+
const [first] = path.node.elements;
259+
return isCallExpression(first);
260+
}
261+
257262
export const isMultiLine = createTypeChecker([
258263
['-: node.elements.length -> -'],
259264
['-', isStringsAndObject],
260265
['-', isTupleInsideArray],
266+
['+', hasCall],
261267
['+', isMixedTuples],
262268
['+', isBodyWithOneElement],
263269
['+', isMoreThenMaxElementLengthInOneLine],
@@ -301,9 +307,6 @@ function isOneSimple(path) {
301307
if (!first.isIdentifier() && isSimple(first))
302308
return true;
303309

304-
if (first.isCallExpression())
305-
return false;
306-
307310
return first.isMemberExpression();
308311
}
309312

0 commit comments

Comments
 (0)