compiler/astutil
import "github.com/gopherjs/gopherjs/compiler/astutil"
Functions
func DirectiveNew(d ast.Node) bool
Source: compiler/astutil/astutil.go:154
DirectiveNew returns true if gopherjs:new directive is present on a struct, interface, type, variable, constant, or function.
//gopherjs:new is a GopherJS-specific directive, which can be
applied in native overlays and will instruct the augmentation logic to
ensure that the original code is not present so that this code does not
override any original code, otherwise an error will be raised.
func DirectiveReplace(d ast.Node) bool
Source: compiler/astutil/astutil.go:143
DirectiveReplace returns true if gopherjs:replace directive is present on a struct, interface, type, variable, constant, or function.
//gopherjs:replace is a GopherJS-specific directive, which can be
applied in native overlays and will instruct the augmentation logic to
ensure that the original code is present and has not been removed nor renamed,
otherwise an error will be raised.
func EndsWithReturn(stmts []ast.Stmt) bool
Source: compiler/astutil/astutil.go:295
EndsWithReturn returns true if the last effective statement is a "return".
func FindLoopStmt(stack []ast.Node, branch *ast.BranchStmt, typeInfo *types.Info) ast.Stmt
Source: compiler/astutil/astutil.go:263
FindLoopStmt tries to find the loop statement among the AST nodes in the |stack| that corresponds to the break/continue statement represented by branch.
This function is label-aware and assumes the code was successfully type-checked.
func FuncKey(d *ast.FuncDecl) string
Source: compiler/astutil/astutil.go:102
FuncKey returns a string, which uniquely identifies a top-level function or method in a package.
func FuncReceiverKey(d *ast.FuncDecl) string
Source: compiler/astutil/astutil.go:112
FuncReceiverKey returns a string that uniquely identifies the receiver struct of the function or an empty string if there is no receiver. This name will match the name of the struct in the struct's type spec.
func HasDirectivePrefix(file *ast.File, prefix string) bool
Source: compiler/astutil/astutil.go:246
HasDirectivePrefix determines if any line in the given file has the given directive prefix in it.
func ImportName(spec *ast.ImportSpec) string
Source: compiler/astutil/astutil.go:83
ImportName tries to determine the package name for an import.
If the package name isn't specified then this will make a best
make a best guess using the import path.
If the import name is dot (.), blank (_), or there
was an issue determining the package name then empty is returned.
func ImportsUnsafe(file *ast.File) bool
func IsTypeExpr(expr ast.Expr, info *types.Info) bool
Source: compiler/astutil/astutil.go:40
IsTypeExpr returns true if expr denotes a type. This can be used to distinguish between calls and type conversions.
func KeepOriginal(d *ast.FuncDecl) bool
Source: compiler/astutil/astutil.go:169
KeepOriginal returns true if gopherjs:keep-original directive is present before a function decl.
//gopherjs:keep-original is a GopherJS-specific directive, which can be
applied to functions in native overlays and will instruct the augmentation
logic to expose the original function such that it can be called. For a
function in the original called foo, it will be accessible by the name
_gopherjs_original_foo.
This will also ensure that the original function exists and hasn't been removed or renamed, otherwise an error will be raised.
func NewIdent(name string, t types.Type, info *types.Info, pkg *types.Package) *ast.Ident
func OverrideSignature(d *ast.FuncDecl) bool
Source: compiler/astutil/astutil.go:209
OverrideSignature returns true if gopherjs:override-signature directive is present on a function.
//gopherjs:override-signature is a GopherJS-specific directive, which can
be applied in native overlays and will instruct the augmentation logic to
replace the original function signature which has the same FuncKey with the
signature defined in the native overlays.
This directive can be used to remove generics from a function signature or to replace a receiver of a function with another one. The given native overlay function will be removed, so no method body is needed in the overlay.
The new signature may not contain types which require a new import since the imports will not be automatically added when needed, only removed. Use a type alias in the overlay to deal manage imports.
This will also ensure that the original code exists and hasn't been removed or renamed, otherwise an error will be raised.
func Purge(d ast.Node) bool
Source: compiler/astutil/astutil.go:187
Purge returns true if gopherjs:purge directive is present on a struct, interface, type, variable, constant, or function.
//gopherjs:purge is a GopherJS-specific directive, which can be
applied in native overlays and will instruct the augmentation logic to
delete part of the standard library without a replacement. This directive
can be used to remove code that would be invalid in GopherJS, such as code
using unsupported features (e.g. generic interfaces before generics were
fully supported). It should be used with caution since it may remove needed
dependencies. If a type is purged, all methods using that type as
a receiver will also be purged.
This will also ensure that the original code exists and hasn't been removed or renamed, otherwise an error will be raised.
func RemoveParens(e ast.Expr) ast.Expr
func SetType(info *types.Info, t types.Type, e ast.Expr) ast.Expr
func Squeeze[E ast.Node, S ~[]E](s S) S
Source: compiler/astutil/astutil.go:316
Squeeze removes all nil nodes from the slice.
The given slice will be modified. This is designed for squeezing declaration, specification, imports, and identifier lists.
