function postprocessToken(token) { if (_tk.isComment(token)) { processComment(token); } else if (_shouldRemoveTrailingWs && _tk.isWs(token)) { removeTrailingWs(token); } }
node.declarations.forEach(function(declarator, i) { var idStartToken = declarator.id.startToken; // need to swap comma-first line break var prevNonEmpty = _tk.findPrevNonEmpty(idStartToken); if (i && prevNonEmpty.value === ',') { if (_tk.isBr(prevNonEmpty.prev) || _tk.isBr(prevNonEmpty.prev.prev)) { var beforeComma = _tk.findPrev(prevNonEmpty, function(t) { return !_tk.isEmpty(t) && !_tk.isComment(t); }); _ws.limit(prevNonEmpty, 0); _tk.remove(prevNonEmpty); _tk.after(beforeComma, prevNonEmpty); } } if (!i && !_tk.isComment(_tk.findPrevNonEmpty(idStartToken))) { // XXX: we don't allow line breaks or multiple spaces after "var" // keyword for now (might change in the future) _tk.removeEmptyAdjacentBefore(idStartToken); } else if (!insideFor && declarator.init) { _br.limit(idStartToken, 'VariableName'); } _ws.limitBefore(idStartToken, 'VariableName'); if (declarator.init) { _ws.limitAfter(declarator.id.endToken, 'VariableName'); var equalSign = _tk.findNext(declarator.id.endToken, '='); var valueStart = _tk.findNextNonEmpty(equalSign); _br.limitBefore(valueStart, 'VariableValue'); _ws.limitBefore(valueStart, 'VariableValue'); _br.limitAfter(declarator.endToken, 'VariableValue'); _ws.limitAfter(declarator.endToken, 'VariableValue'); } });
function nextInLineNotComment(token) { token = token.next; while (token) { if (tk.isBr(token)) { return true; } if (!tk.isEmpty(token)) { return !tk.isComment(token); } token = token.next; } return true; }
exports.getIndentEdges = function(node, opts) { var edges = []; var test = node.test; var consequent = node.consequent; var alt = node.alternate; // test (IfStatementConditional) edges.push({ level: opts.IfStatementConditional, startToken: _tk.findNext(node.startToken, '('), endToken: _tk.findPrev(consequent.startToken, ')'), }); function isExecutable(token) { return _tk.isNotEmpty(token) && !_tk.isComment(token); } // consequent (body) edges.push({ startToken: ( consequent.type === 'BlockStatement' ? consequent.startToken : test.endToken.next ), // we have some special rules for comments just before the `else` statement // because of jQuery style guide. maybe in the future we will add // a setting to toggle this behavior (if someone asks for it) endToken: ( alt && _tk.isComment(_tk.findPrevNonEmpty(consequent.endToken)) ? _tk.findPrev(consequent.endToken, isExecutable).next : consequent.endToken ) }); // alt (else) if (alt && alt.type !== 'IfStatement') { // it the alternate is IfStatement it will already take care of indentation edges.push({ startToken: ( alt.type === 'BlockStatement' ? alt.startToken : _tk.findPrevNonEmpty(alt.startToken).next ), endToken: alt.endToken }); } return edges; };
function alignComments(nodeOrAst) { var first = nodeOrAst.startToken && nodeOrAst.startToken.prev; var token = nodeOrAst.endToken; while (token && token !== first) { if (tk.isComment(token) && isFirstNonEmptyTokenOfLine(token)) { var base = findReferenceIndent(token); matchBaseIndent(token, base); // if inside an empty block we add indent otherwise it looks weird var change = _opts.CommentInsideEmptyBlock != null ? _opts.CommentInsideEmptyBlock : 1; if (change && isInsideEmptyBlock(token)) { addLevel(token, change); } if (token.type === 'BlockComment') { updateBlockComment(token); } } token = token.prev; } }
function isExecutable(token) { return _tk.isNotEmpty(token) && !_tk.isComment(token); }
var beforeComma = _tk.findPrev(prevNonEmpty, function(t) { return !_tk.isEmpty(t) && !_tk.isComment(t); });
function shouldSkipToken(token) { // if comment is at same line we skip it unless it has a specific rule that // would add line breaks var result = _tk.isComment(token) && !isOnSeparateLine(token); return result && getExpect('before', token.type) <= 0; }
function siblingIsComment(token) { return _tk.isComment(_tk.findPrev(token, _tk.isNotEmpty)) || _tk.isComment(_tk.findNext(token, _tk.isNotEmpty)); }
function preprocessToken(token) { if (_tk.isComment(token)) { _br.limit(token, token.type); } }
var valueEnd = _tk.findPrev(eol, function(token) { return !_tk.isEmpty(token) && !_tk.isComment(token); });
function preprocessToken(token) { if (_tk.isComment(token)) { _br.limit(token, token.type); } plugins.tokenBefore(token); }