Example #1
0
func url(call *ast.CallExpr, args ...*ast.BasicLit) (*ast.BasicLit, error) {
	val := args[0].Value
	if args[0].Kind == token.QSTRING {
		val = `"` + val + `"`
	}
	val = "url(" + val + ")"
	lit := &ast.BasicLit{
		Kind:     token.STRING,
		Value:    val,
		ValuePos: call.Pos(),
	}
	return lit, nil
}
Example #2
0
func unit(call *ast.CallExpr, args ...*ast.BasicLit) (*ast.BasicLit, error) {
	in := *args[0]
	lit := &ast.BasicLit{
		Kind:     token.QSTRING,
		ValuePos: call.Pos(),
	}
	switch in.Kind {
	case token.UEM:
		lit.Value = "em"
	case token.UPX:
		lit.Value = "px"
	case token.UPCT:
		lit.Value = "%"
	case token.INT, token.FLOAT:
		lit.Value = ""
	case token.STRING, token.QSTRING, token.QSSTRING:
		return nil, fmt.Errorf(`$number: "%s" is not a number for unit`, in.Value)
	default:
		return nil, errors.New("unsupported type for type-of")
	}

	return lit, nil
}