jsparse

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFunctionExport = errors.New("function export cannot be the name of the default export")
View Source
var ErrInvalidName = errors.New("variable name is invalid")

Functions

This section is empty.

Types

type DefaultJSDocument

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

DefaultJSDocument is a struct that implements the JSDocument interface this struct can be used as an output for JSDocument parsing.

func NewDocument

func NewDocument(webDir string, pageDir string) *DefaultJSDocument

NewDocument creates a new JS document

func NewEmptyDocument

func NewEmptyDocument() *DefaultJSDocument

NewEmptyDocument creates a new empty JSDocument

func NewImportDocument added in v0.7.0

func NewImportDocument(imports ...*ImportDependency) *DefaultJSDocument

func (*DefaultJSDocument) AddImport

func (p *DefaultJSDocument) AddImport(dependency *ImportDependency) []*ImportDependency

func (*DefaultJSDocument) AddOther

func (p *DefaultJSDocument) AddOther(new ...string)

func (*DefaultJSDocument) AddSerializable added in v0.7.0

func (p *DefaultJSDocument) AddSerializable(s JSSerialize)

func (*DefaultJSDocument) Clone added in v0.21.0

func (p *DefaultJSDocument) Clone() JSDocument

func (*DefaultJSDocument) DefaultExport added in v0.7.0

func (p *DefaultJSDocument) DefaultExport() *JsDocumentScope

func (*DefaultJSDocument) Extension

func (p *DefaultJSDocument) Extension() string

func (*DefaultJSDocument) Imports

func (p *DefaultJSDocument) Imports() []*ImportDependency

func (*DefaultJSDocument) Key

func (p *DefaultJSDocument) Key() string

func (*DefaultJSDocument) Name

func (p *DefaultJSDocument) Name() string

func (*DefaultJSDocument) Other

func (p *DefaultJSDocument) Other() []string

func (*DefaultJSDocument) WriteFile

func (p *DefaultJSDocument) WriteFile(dir string) error

type FunctionDefinition

type FunctionDefinition struct {
	Content    string
	Name       string
	IsExported bool
}

FunctionDefinition is a light-weight struct to define JS function definition

type ImportDependency

type ImportDependency struct {
	FinalStatement string
	InitialPath    string
	Type           ImportType
}

ImportDependency represents an entire import path within a javascript file.

type ImportType

type ImportType int32

ImportType represents a javascript import type

const (
	// LocalImportType represents an import that appears to be a local module
	// e.g import Thing from '../stuff/help.js'
	LocalImportType ImportType = 0

	// ModuleImportType represents an import that appears to be located in
	// as a node module. e.g import Thing from '@someorg/help.js'
	ModuleImportType ImportType = 1
)

type JSDocArgList added in v0.7.0

type JSDocArgList []string

func (JSDocArgList) ToString added in v0.7.0

func (s JSDocArgList) ToString() string

type JSDocument

type JSDocument interface {
	WriteFile(string) error
	Key() string
	Imports() []*ImportDependency
	AddImport(*ImportDependency) []*ImportDependency
	Other() []string
	// AddOther(string) []string
	AddOther(...string)
	Extension() string
	AddSerializable(s JSSerialize)
	Name() string
	DefaultExport() *JsDocumentScope
	Clone() JSDocument
}

JSDocument is an interface that describes the behavior of a JSDocument

type JSExport added in v0.7.0

type JSExport int
const (
	ExportNone    JSExport = 0
	ExportDefault JSExport = 1
	ExportConst   JSExport = 2
)

type JSFileParser

type JSFileParser struct{}

func (*JSFileParser) CanParse added in v0.16.0

func (p *JSFileParser) CanParse(path string) bool

func (*JSFileParser) Parse

func (p *JSFileParser) Parse(pageDir string, webDir string) (JSDocument, error)

type JSParser

type JSParser interface {
	Parse(string, string) (JSDocument, error)
	CanParse(path string) bool
}

type JSSerialize added in v0.7.0

type JSSerialize interface {
	Serialize() string
}

type JSToken

type JSToken string

JSToken is some tokens found in javascript used to tokenize js statements.

const (
	ImportToken        JSToken = "import"
	ExportDefaultToken JSToken = "export default"
	ExportConstToken   JSToken = "export const"
	ConstToken         JSToken = "const"
	FuncToken          JSToken = "function"
	VarToken           JSToken = "var"
	LetToken           JSToken = "let"
	CommentToken       JSToken = "//"
	DoubleQuoteToken   JSToken = `"`
	SingleQuoteToken   JSToken = "'"
	MultiStringToken   JSToken = "`"
)

type JSType added in v0.7.0

type JSType string
const (
	JSString JSType = "string"
	JSNumber JSType = "number"
)

type JsDocFunc added in v0.7.0

type JsDocFunc struct {
	Declaration string
	// contains filtered or unexported fields
}

func NewFunc added in v0.7.0

func NewFunc(declaration string, body JSSerialize) *JsDocFunc

func (*JsDocFunc) Serialize added in v0.7.0

func (s *JsDocFunc) Serialize() string

type JsDocSwitch added in v0.7.0

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

func NewSwitch added in v0.7.0

func NewSwitch(varname string) *JsDocSwitch

func (*JsDocSwitch) Add added in v0.7.0

func (s *JsDocSwitch) Add(t JSType, value string, body string)

func (*JsDocSwitch) Serialize added in v0.7.0

func (s *JsDocSwitch) Serialize() string

type JsDocumentScope added in v0.7.0

type JsDocumentScope struct {
	TokenType JSToken
	Name      string
	Export    JSExport
	Args      JSDocArgList
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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