jsc

package
v0.0.0-...-277be3d Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClientInvalidParamsAndRefs = sht.CreateBoolMap([]string{
	"STX", "$", "push", "watch", "tick",

	"OnMount", "BeforeUpdate", "AfterUpdate", "BeforeRender", "AfterRender", "OnDestroy", "OnConnect", "OnDisconnect",
	"OnError", "OnEvent",
})

ClientInvalidParamsAndRefs reserved variable names, cannot be used in parameters or references. The prefix "_$" is also not allowed.

View Source
var ClientLifeCycleMap = map[string]string{
	"OnMount":      "a",
	"BeforeUpdate": "b",
	"AfterUpdate":  "c",
	"BeforeRender": "d",
	"AfterRender":  "e",
	"OnDestroy":    "f",
	"OnConnect":    "g",
	"OnDisconnect": "h",
	"OnEvent":      "i",
	"OnError":      "j",
}

ClientLifeCycleMap The methods and attributes that are part of the structure of a JS component

View Source
var HtmlEventsPush = sht.CreateBoolMap([]string{

	"onblur", "onchange", "oncontextmenu", "onfocus", "oninput", "oninvalid", "onreset", "onsearch", "onselect", "onsubmit",

	"onclick", "ondblclick", "onmousedown", "onmousemove", "onmouseout", "onmouseover", "onmouseup", "onwheel",
})

HtmlEventsPush list of events that are enabled by default to push to server

Functions

func AddDispatcers

func AddDispatcers(ast js.INode, globalScope *js.Scope, contextVariables *cmn.IndexedSet, stack *WalkScopeStack)

func CallExpr

func CallExpr(name string, args ...js.IExpr) *js.CallExpr

func GetContextFunctionBodyExpr

func GetContextFunctionBodyExpr(contextAst *js.AST, funcRef *js.Var) *js.BlockStmt

func GroupCommaExpr

func GroupCommaExpr(list ...js.IExpr) js.GroupExpr

func HasSideEffect

func HasSideEffect(ast js.INode, contextAst *js.AST) (bool, string)

HasSideEffect checks if the Expression has a side effect. Returns on first side effect Expression found.

func IntegerExpr

func IntegerExpr(value int) js.LiteralExpr

func Interpolate

func Interpolate(text string, sequence *sht.Sequence) (string, map[string]*Interpolation, error)

Interpolate processa as interpolações javascript em um texto

JAVASCRIPT INTERPOLATION ( ${value} or #{value} )

<element attribute="${return value}"> <element attribute="xpto ${escape safe}"> <element attribute="xpto #{escape unsafe}"> <element attribute="#{escape unsafe}"> <element>${escape safe}</element> <element>#{escape unsafe}</element> #{serverExpressionUnescaped}

@TODO: Filters/Pipe. Ex. ${ myValue | upperCase}

newText, watches, err = Interpolate('Hello ${name}!'); newText == "Hello _j$_i15151ffacb" interpolations == {"_j$_i15151ffacb": {Expression: "name", isScape: true}} exp.Exec({name:'Syntax'}).String() == "Hello Syntax!"

func IsBinaryAssignmentOperator

func IsBinaryAssignmentOperator(tokenType js.TokenType) bool

IsBinaryAssignmentOperator check if is a JavaScript Assignment Operators

func IsContextLetOrVarDecl

func IsContextLetOrVarDecl(variable *js.Var, contextAst *js.AST) (bool, *js.BindingElement)

IsContextLetOrVarDecl checks if the variable is a "var" or "let" declaration in the global context

func IsContextSingleLetOrVarReference

func IsContextSingleLetOrVarReference(ast *js.AST, contextAst *js.AST) (bool, *js.Var)

IsContextSingleLetOrVarReference checks if the given expression refers to a single variable defined in the global scope

func IsDeclaredOnScope

func IsDeclaredOnScope(expr *js.Var, scope *js.Scope) (bool, *js.Var)

IsDeclaredOnScope check if this Expression is declared on specified scope

func StringExpr

func StringExpr(value string) js.LiteralExpr

func WalkScoped

func WalkScoped(v IVisitorScoped, n js.INode, stack *WalkScopeStack)

WalkScoped traverses an AST in depth-first order

Types

type ExpressionsParser

type ExpressionsParser struct {
	Node               *sht.Node
	Sequence           *sht.Sequence
	ContextAst         *js.AST
	ContextAstScope    *js.Scope
	ContextVariables   *cmn.IndexedSet
	Elements           *cmn.IndexedSet
	AttributeNames     *cmn.IndexedSet
	Expressions        *cmn.IndexedSet
	EventNames         *cmn.IndexedSet
	Events             *cmn.IndexedSet
	Writers            *cmn.IndexedSet
	Watchers           *cmn.IndexedSet
	NodeIdentifierFunc func(node *sht.Node) string
}

func (*ExpressionsParser) Parse

func (p *ExpressionsParser) Parse() error

Parse Faz o processamento e validação de todas as expressões existente no código HTML do template

Check for expressions (${value} or #{value})

Text escaping <element>${escape safe}</element> <element>#{escape unsafe}</element>

Attributes escaping <element attr="text ${escape safe}"> <element attr="text #{escape unsafe}"> <element attr="${return value}"> <element attr="#{escape unsafe}">

Bindings <input value="${value}"></input>

type IVisitorScoped

type IVisitorScoped interface {
	Enter(n js.INode, scope *WalkScopeStack) IVisitorScoped
	Exit(n js.INode)
}

IVisitorScoped represents the AST Visitor Each INode encountered by `Walk` is passed to `Enter`, children nodes will be ignored if the returned IVisitor is nil `Exit` is called upon the exit of a node

type IVisitorScopedFunc

type IVisitorScopedFunc func(node js.INode, scope *WalkScopeStack) (visitChildren bool)

IVisitorScopedFunc use function as AST Visitor

func (IVisitorScopedFunc) Enter

func (IVisitorScopedFunc) Exit

func (f IVisitorScopedFunc) Exit(node js.INode)

type Interpolation

type Interpolation struct {
	Expression    string
	IsSafeSignal  bool
	IsFullContent bool
}

func (*Interpolation) Debug

func (i *Interpolation) Debug() string

type Javascript

type Javascript struct {
	Content         string
	ComponentParams []cmn.ComponentParam
}

Javascript Represents a resource needed by a component

func Compile

func Compile(nodeParent *sht.Node, nodeScript *sht.Node, sequenceGlobal *sht.Sequence) (asset *Javascript, err error)

Compile does all the necessary handling to link the template with javascript

type JsNodeReference

type JsNodeReference struct {
	VarName string
	Node    *sht.Node
	Attr    *sht.Attribute
}

func ParseReferences

func ParseReferences(node *sht.Node) ([]*JsNodeReference, error)

ParseReferences handles references made available to JS (<element ref="myJsVariable">)

type NodeComponentParams

type NodeComponentParams struct {
	ServerParams       []cmn.ComponentParam // server params
	ClientParams       []cmn.ComponentParam // javascript params
	AttrsToRemove      []*sht.Attribute
	ServerParamsByName map[string]*cmn.ComponentParam
	ClientParamsByName map[string]*cmn.ComponentParam
}

func ParseComponentParams

func ParseComponentParams(node *sht.Node) (*NodeComponentParams, error)

ParseComponentParams Processes the parameters of a component

Qualquer componente

type VisitorEnterFunc

type VisitorEnterFunc func(node js.INode) (visitChildren bool)

VisitorEnterFunc use function as AST Visitor

Each INode encountered by `walk` is passed to func, children nodes will be ignored if return false

func (VisitorEnterFunc) Enter

func (f VisitorEnterFunc) Enter(node js.INode) js.IVisitor

func (VisitorEnterFunc) Exit

func (f VisitorEnterFunc) Exit(node js.INode)

type WalkScope

type WalkScope struct {
	// contains filtered or unexported fields
}

type WalkScopeStack

type WalkScopeStack struct {
	// contains filtered or unexported fields
}

func (*WalkScopeStack) Pop

func (r *WalkScopeStack) Pop()

func (*WalkScopeStack) Push

func (r *WalkScopeStack) Push(scope *WalkScope)

func (*WalkScopeStack) Replace

func (r *WalkScopeStack) Replace(node js.INode, by js.INode) bool

Jump to

Keyboard shortcuts

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