edit

package
v0.163.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2022 License: MIT Imports: 4 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OptionNotFoundError = &flux.Error{Code: codes.Invalid, Msg: "option not found"}

OptionNotFoundError variable is to handle the error gracefully in the client code

Functions

func DeleteOption added in v0.75.0

func DeleteOption(file *ast.File, name string)

DeleteOption removes an option if it exists. The file AST is mutated in place.

func DeleteProperty added in v0.75.0

func DeleteProperty(obj *ast.ObjectExpression, key string)

DeleteProperty removes a property from the object expression if it exists. The object expression AST is mutated in place.

func GetOption added in v0.75.0

func GetOption(file *ast.File, name string) (ast.Expression, error)

GetOption finds and returns the init for the option's variable assignment

func GetProperty added in v0.75.0

func GetProperty(obj *ast.ObjectExpression, key string) (ast.Expression, error)

GetProperty finds and returns the AST node for the property value.

func HasDuplicateOptions added in v0.81.0

func HasDuplicateOptions(file *ast.File, name string) bool

HasDuplicateOptions determines whether or not there are multiple assignments to the same option variable.

func Match added in v0.20.0

func Match(node ast.Node, pattern ast.Node, matchSlicesFuzzy bool) []ast.Node

Match takes an AST and a pattern and returns the nodes of the AST that match the given pattern. The pattern is an AST in turn, but it is partially specified, i.e. nil nodes are ignored while matching. In the case of slices (e.g. ast.File.Body, ast.CallExpression.Arguments) the matching mode can be "exact" or "fuzzy". Let ps be a slice of nodes in the pattern and ns in node. In "exact" mode, slices match iff len(ps) == len(ns) and every non-nil node ps[i] matches ns[i]. In "fuzzy" mode, slices match iff ns is a superset of ps; e.g. if ps is empty, it matches every slice.

func Option

func Option(node ast.Node, optionIdentifier string, fn OptionFn) (bool, error)

`Option` passes the `OptionStatement` in the AST rooted at `node` that has the specified identifier to `fn`. The function can have side effects on the option statement and/or return a non-nil `Expression` that is set as value for the option. If the value returned by the edit function is `nil` (or an error is returned) no new value is set for the option statement (but any, maybe partial, side effect is applied). `Option` returns whether it could find and edit the option (possibly with errors) or not.

func SetOption added in v0.75.0

func SetOption(file *ast.File, name string, expr ast.Expression)

SetOption replaces an existing option's init with the provided init or adds the option if it doesn't exist. The file AST is mutated in place.

func SetProperty added in v0.75.0

func SetProperty(obj *ast.ObjectExpression, key string, value ast.Expression)

SetProperty replaces an existing property definition with the provided object expression or adds the property if it doesn't exist. The object expression AST is mutated in place.

Types

type OptionFn

type OptionFn func(opt *ast.OptionStatement) (ast.Expression, error)

`OptionFn` is a function that, provided with an `OptionStatement`, returns an `Expression` or an error. It is used by `Option` functions to edit AST's options statements.

func OptionObjectFn

func OptionObjectFn(keyMap map[string]ast.Expression) OptionFn

Creates an `OptionFn` for updating the values of an `OptionStatement` that has an `ObjectExpression` as value. Returns error if the child of the option statement is not an object expression. If some key is not a property of the object it is added.

func OptionValueFn

func OptionValueFn(expr ast.Expression) OptionFn

Creates an `OptionFn` for setting the value of an `OptionStatement`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL