diff options
Diffstat (limited to 'tools/eslint/lib/token-store/skip-cursor.js')
-rw-r--r-- | tools/eslint/lib/token-store/skip-cursor.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/eslint/lib/token-store/skip-cursor.js b/tools/eslint/lib/token-store/skip-cursor.js new file mode 100644 index 0000000000..ab34dfab0d --- /dev/null +++ b/tools/eslint/lib/token-store/skip-cursor.js @@ -0,0 +1,42 @@ +/** + * @fileoverview Define the cursor which ignores the first few tokens. + * @author Toru Nagashima + */ +"use strict"; + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const DecorativeCursor = require("./decorative-cursor"); + +//------------------------------------------------------------------------------ +// Exports +//------------------------------------------------------------------------------ + +/** + * The decorative cursor which ignores the first few tokens. + */ +module.exports = class SkipCursor extends DecorativeCursor { + + /** + * Initializes this cursor. + * @param {Cursor} cursor - The cursor to be decorated. + * @param {number} count - The count of tokens this cursor skips. + */ + constructor(cursor, count) { + super(cursor); + this.count = count; + } + + /** @inheritdoc */ + moveNext() { + while (this.count > 0) { + this.count -= 1; + if (!super.moveNext()) { + return false; + } + } + return super.moveNext(); + } +}; |