mirror of
https://github.com/beautifier/js-beautify.git
synced 2025-02-24 07:11:17 +00:00
Add more navgation to token
This commit is contained in:
parent
859c2f410d
commit
89e91a8242
@ -41,8 +41,10 @@ function Token(type, text, newlines, whitespace_before) {
|
||||
this.newlines = newlines || 0;
|
||||
this.whitespace_before = whitespace_before || '';
|
||||
this.parent = null;
|
||||
this.next = null;
|
||||
this.previous = null;
|
||||
this.opened = null;
|
||||
this.closed = null;
|
||||
this.directives = null;
|
||||
}
|
||||
|
||||
|
@ -73,16 +73,17 @@ Tokenizer.prototype.tokenize = function() {
|
||||
current.parent = open_token;
|
||||
|
||||
if (this.is_opening(current)) {
|
||||
current.opened = open_token;
|
||||
open_stack.push(open_token);
|
||||
open_token = current;
|
||||
} else if (open_token && this.is_closing(current, open_token)) {
|
||||
current.opened = open_token;
|
||||
open_token.closed = current;
|
||||
open_token = open_stack.pop();
|
||||
current.parent = open_token;
|
||||
}
|
||||
|
||||
current.previous = previous;
|
||||
previous.next = current;
|
||||
|
||||
this._tokens.add(current);
|
||||
previous = current;
|
||||
|
@ -36,6 +36,8 @@ class Token:
|
||||
self.newlines = newlines
|
||||
self.whitespace_before = whitespace_before
|
||||
self.parent = None
|
||||
self.next = None
|
||||
self.previous = None
|
||||
self.opened = None
|
||||
self.closed = None
|
||||
self.directives = None
|
||||
|
@ -77,16 +77,19 @@ class Tokenizer:
|
||||
current.comments_before = comments
|
||||
comments = TokenStream()
|
||||
|
||||
current.parent = open_token
|
||||
|
||||
if self.is_opening(current):
|
||||
current.parent = open_token
|
||||
open_stack.append(open_token)
|
||||
open_token = current
|
||||
elif open_token is not None and self.is_closing(current, open_token):
|
||||
current.opened = open_token
|
||||
open_token.closed = current
|
||||
open_token = open_stack.pop()
|
||||
current.parent = open_token
|
||||
|
||||
current.previous = previous
|
||||
previous.next = current
|
||||
|
||||
self._tokens.add(current)
|
||||
previous = current
|
||||
|
Loading…
x
Reference in New Issue
Block a user