本文整理汇总了Golang中github.com/ditashi/jsbeautifier-go/tokenizer.Token.Type方法的典型用法代码示例。如果您正苦于以下问题:Golang Token.Type方法的具体用法?Golang Token.Type怎么用?Golang Token.Type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ditashi/jsbeautifier-go/tokenizer.Token
的用法示例。
在下文中一共展示了Token.Type方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handle_token
func (self *jsbeautifier) handle_token(t *tokenizer.Token) {
newlines := t.NewLines()
keep_whitespace := self.options["keep_array_indentation"].(bool) && self.is_array(self.flags.mode)
if keep_whitespace {
for i := 0; i < newlines; i++ {
self.print_newline(i > 0, false)
}
} else {
if self.options["max_preserve_newlines"].(int) != 0 && newlines > self.options["max_preserve_newlines"].(int) {
newlines = self.options["max_preserve_newlines"].(int)
}
if self.options["preserve_newlines"].(bool) && newlines > 1 {
self.print_newline(false, false)
for i := 1; i < newlines; i++ {
self.print_newline(true, false)
}
}
}
handlers[t.Type()](self, t)
}
示例2: parse_token
func (self *jsbeautifier) parse_token(t tokenizer.Token) {
for _, comment_token := range t.CommentsBefore() {
self.handle_token(&comment_token)
}
self.handle_token(&t)
self.last_last_text = self.flags.last_text
self.last_type = t.Type()
self.flags.last_text = t.Text()
self.token_pos++
}
示例3: start_of_statement
func (self *jsbeautifier) start_of_statement(current_token tokenizer.Token) bool {
if (self.last_type == "TK_RESERVED" && utils.InStrArray(self.flags.last_text, []string{"var", "let", "const"}) && current_token.Type() == "TK_WORD") || (self.last_type == "TK_RESERVED" && self.flags.last_text == "do") || (self.last_type == "TK_RESERVED" && self.flags.last_text == "return" && !current_token.WantedNewLine()) || (self.last_type == "TK_RESERVED" && self.flags.last_text == "else" && !(current_token.Type() == "TK_RESERVED" && current_token.Text() == "if")) || (self.last_type == "TK_END_EXPR" && (self.previous_flags.mode == ForInitializer || self.previous_flags.mode == Conditional)) || (self.last_type == "TK_WORD" && self.flags.mode == BlockStatement && !self.flags.in_case && !(current_token.Text() == "--" || current_token.Text() == "++") && current_token.Type() != "TK_WORD" && current_token.Type() != "TK_RESERVED") || (self.flags.mode == ObjectLiteral && ((self.flags.last_text == ":" && self.flags.ternary_depth == 0) || (self.last_type == "TK_RESERVED" && utils.InStrArray(self.flags.last_text, []string{"get", "set"})))) {
self.set_mode(Statement)
self.indent()
if self.last_type == "TK_RESERVED" && utils.InStrArray(self.flags.last_text, []string{"var", "let", "const"}) && current_token.Type() == "TK_WORD" {
self.flags.declaration_statement = true
}
if !self.start_of_object_property() {
self.allow_wrap_or_preserved_newline(current_token, (current_token.Type() == "TK_RESERVED" && utils.InStrArray(current_token.Text(), []string{"do", "for", "if", "while"})))
}
return true
} else {
return false
}
}
示例4: handle_word
func (self *jsbeautifier) handle_word(current_token *tokenizer.Token) {
if current_token.Type() == "TK_RESERVED" && self.flags.mode != ObjectLiteral && (current_token.Text() == "set" || current_token.Text() == "get") {
current_token.SetType("TK_WORD")
}
if current_token.Type() == "TK_RESERVED" && self.flags.mode == ObjectLiteral {
next_token, _ := self.get_token()
if next_token.Text() == ":" {
current_token.SetType("TK_WORD")
}
}
if self.start_of_statement(*current_token) {
} else if current_token.WantedNewLine() && !self.is_expression(self.flags.mode) && (self.last_type != "TK_OPERATOR" || (self.flags.last_text == "--" || self.flags.last_text == "++")) && self.last_type != "TK_EQUALS" && (self.options["preserve_newlines"].(bool) || !(self.last_type == "TK_RESERVED" && utils.InStrArray(self.flags.last_text, []string{"var", "let", "const", "set", "get"}))) {
self.print_newline(false, false)
}
if self.flags.do_block && !self.flags.do_while {
if current_token.Type() == "TK_RESERVED" && current_token.Text() == "while" {
self.output.space_before_token = true
self.print_token(*current_token, "")
self.output.space_before_token = true
self.flags.do_while = true
return
} else {
self.print_newline(false, false)
self.flags.do_block = false
}
}
if self.flags.if_block {
if (!self.flags.else_block) && (current_token.Type() == "TK_RESERVED" && current_token.Text() == "else") {
self.flags.else_block = true
} else {
for self.flags.mode == Statement {
self.restore_mode()
}
self.flags.if_block = false
}
}
if current_token.Type() == "TK_RESERVED" && (current_token.Text() == "case" || (current_token.Text() == "default" && self.flags.in_case_statement)) {
self.print_newline(false, false)
if self.flags.case_body || self.options["jslint_happy"].(bool) {
self.flags.case_body = false
self.deindent()
}
self.print_token(*current_token, "")
self.flags.in_case = true
self.flags.in_case_statement = true
return
}
if current_token.Type() == "TK_RESERVED" && current_token.Text() == "function" {
if (self.flags.last_text == "}" || self.flags.last_text == ";") || (self.output.just_added_newline() && !utils.InStrArray(self.flags.last_text, []string{"[", "{", ":", "=", ","})) {
if !self.output.just_added_blankline() && len(current_token.CommentsBefore()) == 0 {
self.print_newline(false, false)
self.print_newline(true, false)
}
}
if self.last_type == "TK_RESERVED" || self.last_type == "TK_WORD" {
if self.last_type == "TK_RESERVED" && utils.InStrArray(self.flags.last_text, []string{"get", "set", "new", "return", "export"}) {
self.output.space_before_token = true
} else if self.last_type == "TK_RESERVED" && self.flags.last_text == "default" && self.last_last_text == "export" {
self.output.space_before_token = true
} else {
self.print_newline(false, false)
}
} else if self.last_type == "TK_OPERATOR" || self.flags.last_text == "=" {
self.output.space_before_token = true
} else if !self.flags.multiline_frame && (self.is_expression(self.flags.mode) || self.is_array(self.flags.mode)) {
} else {
self.print_newline(false, false)
}
}
if utils.InStrArray(self.last_type, []string{"TK_COMMA", "TK_START_EXPR", "TK_EQUALS", "TK_OPERATOR"}) {
if !self.start_of_object_property() {
self.allow_wrap_or_preserved_newline(*current_token, false)
}
}
if current_token.Type() == "TK_RESERVED" && utils.InStrArray(current_token.Text(), []string{"function", "get", "set"}) {
self.print_token(*current_token, "")
self.flags.last_word = current_token.Text()
return
}
prefix := "NONE"
if self.last_type == "TK_END_BLOCK" {
if !(current_token.Type() == "TK_RESERVED" && utils.InStrArray(current_token.Text(), []string{"else", "catch", "finally"})) {
prefix = "NEWLINE"
} else {
//.........这里部分代码省略.........