本文整理汇总了Golang中github.com/gopherjs/gopherjs/compiler/typesutil.IsJsPackage函数的典型用法代码示例。如果您正苦于以下问题:Golang IsJsPackage函数的具体用法?Golang IsJsPackage怎么用?Golang IsJsPackage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsJsPackage函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: translateStmt
//.........这里部分代码省略.........
c.PrintCond(false, "goto "+s.Label.Name, fmt.Sprintf("$s = %d; continue;", c.labelCase(c.p.Uses[s.Label].(*types.Label))))
case token.FALLTHROUGH:
// handled in CaseClause
default:
panic("Unhandled branch statment: " + s.Tok.String())
}
case *ast.ReturnStmt:
results := s.Results
if c.resultNames != nil {
if len(s.Results) != 0 {
c.translateStmt(&ast.AssignStmt{
Lhs: c.resultNames,
Tok: token.ASSIGN,
Rhs: s.Results,
}, nil)
}
results = c.resultNames
}
c.Printf("return%s;", c.translateResults(results))
case *ast.DeferStmt:
isBuiltin := false
isJs := false
switch fun := s.Call.Fun.(type) {
case *ast.Ident:
var builtin *types.Builtin
builtin, isBuiltin = c.p.Uses[fun].(*types.Builtin)
if isBuiltin && builtin.Name() == "recover" {
c.Printf("$deferred.push([$recover, []]);")
return
}
case *ast.SelectorExpr:
isJs = typesutil.IsJsPackage(c.p.Uses[fun.Sel].Pkg())
}
sig := c.p.Types[s.Call.Fun].Type.Underlying().(*types.Signature)
args := c.translateArgs(sig, s.Call.Args, s.Call.Ellipsis.IsValid(), true)
if isBuiltin || isJs {
vars := make([]string, len(s.Call.Args))
callArgs := make([]ast.Expr, len(s.Call.Args))
for i, arg := range s.Call.Args {
v := c.newVariable("_arg")
vars[i] = v
callArgs[i] = c.newIdent(v, c.p.Types[arg].Type)
}
call := c.translateExpr(&ast.CallExpr{
Fun: s.Call.Fun,
Args: callArgs,
Ellipsis: s.Call.Ellipsis,
})
c.Printf("$deferred.push([function(%s) { %s; }, [%s]]);", strings.Join(vars, ", "), call, strings.Join(args, ", "))
return
}
c.Printf("$deferred.push([%s, [%s]]);", c.translateExpr(s.Call.Fun), strings.Join(args, ", "))
case *ast.AssignStmt:
if s.Tok != token.ASSIGN && s.Tok != token.DEFINE {
panic(s.Tok)
}
if s.Tok == token.DEFINE {
for _, lhs := range s.Lhs {
if !isBlank(lhs) {
obj := c.p.Defs[lhs.(*ast.Ident)]
if obj == nil {
obj = c.p.Uses[lhs.(*ast.Ident)]
开发者ID:wmydz1,项目名称:gopherjs,代码行数:67,代码来源:statements.go
示例2: translateExpr
func (c *funcContext) translateExpr(expr ast.Expr) *expression {
exprType := c.p.TypeOf(expr)
if value := c.p.Types[expr].Value; value != nil {
basic := exprType.Underlying().(*types.Basic)
switch {
case isBoolean(basic):
return c.formatExpr("%s", strconv.FormatBool(exact.BoolVal(value)))
case isInteger(basic):
if is64Bit(basic) {
if basic.Kind() == types.Int64 {
d, ok := exact.Int64Val(value)
if !ok {
panic("could not get exact uint")
}
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatInt(d>>32, 10), strconv.FormatUint(uint64(d)&(1<<32-1), 10))
}
d, ok := exact.Uint64Val(value)
if !ok {
panic("could not get exact uint")
}
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatUint(d>>32, 10), strconv.FormatUint(d&(1<<32-1), 10))
}
d, ok := exact.Int64Val(value)
if !ok {
panic("could not get exact int")
}
return c.formatExpr("%s", strconv.FormatInt(d, 10))
case isFloat(basic):
f, _ := exact.Float64Val(value)
return c.formatExpr("%s", strconv.FormatFloat(f, 'g', -1, 64))
case isComplex(basic):
r, _ := exact.Float64Val(exact.Real(value))
i, _ := exact.Float64Val(exact.Imag(value))
if basic.Kind() == types.UntypedComplex {
exprType = types.Typ[types.Complex128]
}
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatFloat(r, 'g', -1, 64), strconv.FormatFloat(i, 'g', -1, 64))
case isString(basic):
return c.formatExpr("%s", encodeString(exact.StringVal(value)))
default:
panic("Unhandled constant type: " + basic.String())
}
}
var obj types.Object
switch e := expr.(type) {
case *ast.SelectorExpr:
obj = c.p.Uses[e.Sel]
case *ast.Ident:
obj = c.p.Defs[e]
if obj == nil {
obj = c.p.Uses[e]
}
}
if obj != nil && typesutil.IsJsPackage(obj.Pkg()) {
switch obj.Name() {
case "Global":
return c.formatExpr("$global")
case "Module":
return c.formatExpr("$module")
case "Undefined":
return c.formatExpr("undefined")
}
}
switch e := expr.(type) {
case *ast.CompositeLit:
if ptrType, isPointer := exprType.(*types.Pointer); isPointer {
exprType = ptrType.Elem()
}
collectIndexedElements := func(elementType types.Type) []string {
var elements []string
i := 0
zero := c.translateExpr(c.zeroValue(elementType)).String()
for _, element := range e.Elts {
if kve, isKve := element.(*ast.KeyValueExpr); isKve {
key, ok := exact.Int64Val(c.p.Types[kve.Key].Value)
if !ok {
panic("could not get exact int")
}
i = int(key)
element = kve.Value
}
for len(elements) <= i {
elements = append(elements, zero)
}
elements[i] = c.translateImplicitConversionWithCloning(element, elementType).String()
i++
}
return elements
}
switch t := exprType.Underlying().(type) {
case *types.Array:
elements := collectIndexedElements(t.Elem())
if len(elements) == 0 {
return c.formatExpr("%s.zero()", c.typeName(t))
}
//.........这里部分代码省略.........
开发者ID:drawapp8,项目名称:gopherjs,代码行数:101,代码来源:expressions.go
注:本文中的github.com/gopherjs/gopherjs/compiler/typesutil.IsJsPackage函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论