Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.format = function AssignmentExpression(node) {
// can't use node.right.startToken since it might be surrounded by
// a parenthesis (see #5)
var operator = _tk.findNext(node.left.endToken, node.operator);
_br.limit(operator, 'AssignmentOperator');
_ws.limit(operator, 'AssignmentOperator');
};
exports.format = function AssignmentExpression(node) {
// can't use node.right.startToken since it might be surrounded by
// a parenthesis (see #5)
var operator = _tk.findNext(node.left.endToken, node.operator);
_br.limit(operator, 'AssignmentOperator');
_ws.limit(operator, 'AssignmentOperator');
};
exports.getIndentEdges = function(node, opts) {
var openingParentheses = _tk.findNext(node.callee.endToken, _tk.isCode);
if (openingParentheses.value !== '(') return;
if (!node.arguments.length) {
// it might contain comments inside even tho there are no args
return {
startToken: openingParentheses,
endToken: _tk.findNext(openingParentheses, ')')
};
}
var start;
function hasBr(start, end) {
return _tk.findInBetween(start, end, _tk.isBr);
}
exports.getIndentEdges = function(node, opts) {
var openingParentheses = _tk.findNext(node.callee.endToken, _tk.isCode);
if (openingParentheses.value !== '(') return;
if (!node.arguments.length) {
// it might contain comments inside even tho there are no args
return {
startToken: openingParentheses,
endToken: _tk.findNext(openingParentheses, ')')
};
}
var start;
function hasBr(start, end) {
return _tk.findInBetween(start, end, _tk.isBr);
}
endToken = endToken.next;
}
_br.limitAfter(endToken, 'DeleteOperator');
} else if (node.operator === 'typeof' || node.operator === 'void') {
_ws.limitAfter(node.startToken, 1);
} else {
// multiple consecutive operators like `!!foo` should not have spaces in
// between then (we consider whole block as a single operator)
var operator = node.startToken;
var prev = _tk.findPrev(operator, _tk.isNotEmpty);
if (prev && prev.value === operator.value) {
_ws.limitBefore(operator, 0);
} else {
_ws.limitBefore(operator, 'UnaryExpressionOperator');
}
var next = _tk.findNext(operator, _tk.isNotEmpty);
if (next && next.value === operator.value) {
_ws.limitAfter(operator, 0);
} else {
_ws.limitAfter(operator, 'UnaryExpressionOperator');
}
}
};
exports.format = function SwitchStatement(node) {
var opening = _tk.findPrev(node.discriminant.startToken, '(');
var closing = _tk.findNext(node.discriminant.endToken, ')');
var openingBrace = _tk.findNext(closing, '{');
var closingBrace = node.endToken;
_limit.around(openingBrace, 'SwitchOpeningBrace');
_limit.around(closingBrace, 'SwitchClosingBrace');
_limit.around(opening, 'SwitchDiscriminantOpening');
_limit.around(closing, 'SwitchDiscriminantClosing');
// cases are handled by SwitchCase hook!
};
exports.format = function ConditionalExpression(node) {
// we need to grab the actual punctuators since parenthesis aren't counted
// as part of test/consequent/alternate
var questionMark = _tk.findNext(node.test.endToken, '?');
var colon = _tk.findNext(node.consequent.endToken, ':');
_ws.limitBefore(questionMark, _ws.expectedAfter('ConditionalExpressionTest'));
_ws.limitAfter(questionMark, _ws.expectedBefore('ConditionalExpressionConsequent'));
_ws.limitBefore(colon, _ws.expectedAfter('ConditionalExpressionConsequent'));
_ws.limitAfter(colon, _ws.expectedBefore('ConditionalExpressionAlternate'));
};
exports.getIndentEdges = function(node) {
var edges = [
{ // do
startToken: node.startToken.next,
endToken: node.body.endToken
},
{ // while
startToken: _tk.findNext(node.body.endToken, '('),
endToken: node.endToken.value === ')' ? node.endToken : _tk.findPrev(node.endToken, ')')
}
];
return edges;
};
exports.getIndentEdges = function(node, opts) {
var operator = _tk.findNext(node.left.endToken, node.operator);
if (_tk.findInBetween(operator, node.right.startToken, _tk.isBr) ||
(opts['AssignmentExpression.' + node.right.type] &&
_tk.findInBetween(operator, node.right.endToken, _tk.isBr))) {
// we only indent if assignment is on next line
return {
startToken: operator,
endToken: node.endToken.type !== 'Punctuator' ?
node.endToken.next : node.endToken
};
}
};
exports.getIndentEdges = function(node, opts) {
var operator = _tk.findNext(node.left.endToken, node.operator);
if (_tk.findInBetween(operator, node.right.startToken, _tk.isBr) ||
(helpers.shouldIndentChild(node, node.right, opts) &&
_tk.findInBetween(operator, node.right.endToken, _tk.isBr))) {
// we only indent if assignment is on next line
return {
level: opts['AssignmentExpression.' + node.right.type],
startToken: operator,
endToken: node.endToken.type !== 'Punctuator' ?
node.endToken.next : node.endToken
};
}
};