How to use the rocambole-token.findNext function in rocambole-token

To help you get started, we’ve selected a few rocambole-token examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ionutvmi / sublime-jsfmt / node_modules / jsfmt / node_modules / esformatter / lib / hooks / AssignmentExpression.js View on Github external
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');
};
github millermedeiros / esformatter / lib / hooks / AssignmentExpression.js View on Github external
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');
};
github ionutvmi / sublime-jsfmt / node_modules / jsfmt / node_modules / esformatter / lib / hooks / CallExpression.js View on Github external
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);
  }
github millermedeiros / esformatter / lib / hooks / CallExpression.js View on Github external
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);
  }
github millermedeiros / esformatter / lib / hooks / UnaryExpression.js View on Github external
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');
    }
  }
};
github millermedeiros / esformatter / lib / hooks / SwitchStatement.js View on Github external
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!

};
github millermedeiros / esformatter / lib / hooks / ConditionalExpression.js View on Github external
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'));
};
github millermedeiros / esformatter / lib / hooks / DoWhileStatement.js View on Github external
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;
};
github ionutvmi / sublime-jsfmt / node_modules / jsfmt / node_modules / esformatter / lib / hooks / AssignmentExpression.js View on Github external
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
    };
  }
};
github millermedeiros / esformatter / lib / hooks / AssignmentExpression.js View on Github external
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
    };
  }
};

rocambole-token

Helpers for rocambole AST token manipulation

MIT
Latest version published 10 years ago

Package Health Score

47 / 100
Full package analysis

Popular rocambole-token functions