當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Token.SetType方法代碼示例

本文整理匯總了Golang中github.com/ditashi/jsbeautifier-go/tokenizer.Token.SetType方法的典型用法代碼示例。如果您正苦於以下問題:Golang Token.SetType方法的具體用法?Golang Token.SetType怎麽用?Golang Token.SetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/ditashi/jsbeautifier-go/tokenizer.Token的用法示例。


在下文中一共展示了Token.SetType方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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 {
//.........這裏部分代碼省略.........
開發者ID:luiseduardohdbackup,項目名稱:jsbeautifier-go,代碼行數:101,代碼來源:jsbeautifier.go


注:本文中的github.com/ditashi/jsbeautifier-go/tokenizer.Token.SetType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。