Documentation ¶
Index ¶
- Constants
- Variables
- func QuoteTemplate(t string, templateType TemplateType) string
- func SetTokeniser(t *parser.Tokeniser) *parser.Tokeniser
- func Unquote(str string) (string, error)
- func UnquoteTemplate(t string) (string, error)
- type AdditiveExpression
- type AdditiveOperator
- type Argument
- type Arguments
- type ArrayAssignmentPattern
- type ArrayBindingPattern
- type ArrayElement
- type ArrayLiteral
- type ArrowFunction
- type AssignmentElement
- type AssignmentExpression
- type AssignmentOperator
- type AssignmentPattern
- type AssignmentProperty
- type BindingElement
- type BindingProperty
- type BitwiseANDExpression
- type BitwiseORExpression
- type BitwiseXORExpression
- type Block
- type CallExpression
- type CaseClause
- type ClassDeclaration
- type ClassElement
- type ClassElementName
- type CoalesceExpression
- type ConditionalExpression
- type ConditionalWrappable
- type Declaration
- type DestructuringAssignmentTarget
- type EqualityExpression
- type EqualityOperator
- type Error
- type ExponentiationExpression
- type ExportClause
- type ExportDeclaration
- type ExportSpecifier
- type Expression
- type FieldDefinition
- type ForType
- type FormalParameters
- type FromClause
- type FunctionDeclaration
- type FunctionType
- type IfStatement
- type ImportClause
- type ImportDeclaration
- type ImportSpecifier
- type IterationStatementDo
- type IterationStatementFor
- type IterationStatementWhile
- type LeftHandSideExpression
- type LetOrConst
- type LexicalBinding
- type LexicalDeclaration
- type LogicalANDExpression
- type LogicalORExpression
- type MemberExpression
- type MethodDefinition
- type MethodType
- type Module
- type ModuleItem
- type MultiplicativeExpression
- type MultiplicativeOperator
- type NamedImports
- type NewExpression
- type ObjectAssignmentPattern
- type ObjectBindingPattern
- type ObjectLiteral
- type OptionalChain
- type OptionalExpression
- type ParenthesizedExpression
- type PrimaryExpression
- type PropertyDefinition
- type PropertyName
- type RelationalExpression
- type RelationshipOperator
- type Script
- type ShiftExpression
- type ShiftOperator
- type Statement
- type StatementListItem
- type StatementType
- type SwitchStatement
- type TemplateLiteral
- type TemplateType
- type Token
- type Tokeniser
- type Tokens
- type TryStatement
- type Type
- type UnaryExpression
- type UnaryOperator
- type UpdateExpression
- type UpdateOperator
- type VariableDeclaration
- type VariableStatement
- type WithStatement
Constants ¶
const ( TokenWhitespace parser.TokenType = iota TokenLineTerminator TokenSingleLineComment TokenMultiLineComment TokenIdentifier TokenPrivateIdentifier TokenBooleanLiteral TokenKeyword TokenPunctuator TokenNumericLiteral TokenStringLiteral TokenNoSubstitutionTemplate TokenTemplateHead TokenTemplateMiddle TokenTemplateTail TokenDivPunctuator TokenRightBracePunctuator TokenRegularExpressionLiteral TokenNullLiteral TokenFutureReservedWord )
Javascript Token values
Variables ¶
var ( ErrInvalidQuoted = errors.New("invalid quoted string") ErrInvalidMethodName = errors.New("invalid method name") ErrInvalidPropertyName = errors.New("invalid property name") ErrInvalidClassDeclaration = errors.New("invalid class declaration") ErrInvalidCallExpression = errors.New("invalid CallExpression") ErrMissingOptional = errors.New("missing optional chain punctuator") ErrInvalidOptionalChain = errors.New("invalid OptionalChain") ErrInvalidFunction = errors.New("invalid function") ErrReservedIdentifier = errors.New("reserved identifier") ErrNoIdentifier = errors.New("missing identifier") ErrMissingFunction = errors.New("missing function") ErrMissingOpeningParenthesis = errors.New("missing opening parenthesis") ErrMissingClosingParenthesis = errors.New("missing closing parenthesis") ErrMissingOpeningBrace = errors.New("missing opening brace") ErrMissingClosingBrace = errors.New("missing closing brace") ErrMissingOpeningBracket = errors.New("missing opening bracket") ErrMissingClosingBracket = errors.New("missing closing bracket") ErrMissingComma = errors.New("missing comma") ErrMissingArrow = errors.New("missing arrow") ErrMissingCaseClause = errors.New("missing case clause") ErrMissingExpression = errors.New("missing expression") ErrMissingCatchFinally = errors.New("missing catch/finally block") ErrMissingSemiColon = errors.New("missing semi-colon") ErrMissingColon = errors.New("missing colon") ErrMissingInitializer = errors.New("missing initializer") ErrInvalidStatementList = errors.New("invalid statement list") ErrInvalidStatement = errors.New("invalid statement") ErrInvalidDeclaration = errors.New("invalid declaration") ErrInvalidLexicalDeclaration = errors.New("invalid lexical declaration") ErrInvalidAssignment = errors.New("invalid assignment operator") ErrInvalidSuperProperty = errors.New("invalid super property") ErrInvalidMetaProperty = errors.New("invalid meta property") ErrInvalidTemplate = errors.New("invalid template") ErrInvalidAsyncArrowFunction = errors.New("invalid async arrow function") ErrInvalidImport = errors.New("invalid import statement") ErrInvalidExportDeclaration = errors.New("invalid export declaration") ErrInvalidNameSpaceImport = errors.New("invalid namespace import") ErrMissingFrom = errors.New("missing from") ErrMissingModuleSpecifier = errors.New("missing module specifier") ErrInvalidNamedImport = errors.New("invalid named import list") ErrInvalidImportSpecifier = errors.New("invalid import specifier") ErrInvalidExportClause = errors.New("invalid export clause") ErrDuplicateDefaultClause = errors.New("duplicate default clause") ErrInvalidIterationStatementDo = errors.New("invalid do iteration statement") ErrInvalidIterationStatementWhile = errors.New("invalid while iteration statement") ErrInvalidIterationStatementFor = errors.New("invalid for iteration statement") ErrInvalidForLoop = errors.New("invalid for loop") ErrInvalidForAwaitLoop = errors.New("invalid for await loop") ErrInvalidIfStatement = errors.New("invalid if statement") ErrInvalidSwitchStatement = errors.New("invalid switch statement") ErrInvalidWithStatement = errors.New("invalid with statement") ErrInvalidTryStatement = errors.New("invalid try statement") ErrInvalidVariableStatement = errors.New("invalid variable statement") ErrLabelledFunction = errors.New("LabelledItemFunction not allowed here") ErrInvalidCharacter = errors.New("invalid character") ErrInvalidSequence = errors.New("invalid character sequence") ErrInvalidRegexpCharacter = errors.New("invalid regexp character") ErrInvalidRegexpSequence = errors.New("invalid regexp sequence") ErrInvalidNumber = errors.New("invalid number") ErrUnexpectedBackslash = errors.New("unexpected backslash") ErrInvalidUnicode = errors.New("invalid unicode escape sequence") ErrInvalidEscapeSequence = errors.New("invalid escape sequence") ErrUnexpectedLineTerminator = errors.New("line terminator in string") ErrBadRestElement = errors.New("bad rest element") ErrInvalidAssignmentProperty = errors.New("invalid assignment property") ErrInvalidDestructuringAssignmentTarget = errors.New("invalid DestructuringAssignmentTarget") ErrNotSimple = errors.New("not a simple expression") )
Errors
Functions ¶
func QuoteTemplate ¶ added in v1.4.1
func QuoteTemplate(t string, templateType TemplateType) string
QuoteTemplate creates a minimally quoted template string.
templateType determines the prefix and suffix.
| Template Type | Prefix | Suffix | |------------------------|----------|----------| | TemplateNoSubstitution | "`" | "`" | | TemplateHead | "`" | "${" | | TemplateMiddle | "}" | "}" | | TemplateTail | "}" | "`" |
func SetTokeniser ¶
SetTokeniser provides javascript parsing functions to a Tokeniser
func UnquoteTemplate ¶ added in v1.4.1
UnquoteTemplate parses a javascript template (either NoSubstitution Template, or any template part), and produces the unquoted version.
Types ¶
type AdditiveExpression ¶
type AdditiveExpression struct { AdditiveExpression *AdditiveExpression AdditiveOperator AdditiveOperator MultiplicativeExpression MultiplicativeExpression Tokens Tokens }
AdditiveExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-AdditiveExpression
If AdditiveOperator is not AdditiveNone then AdditiveExpression must be non-nil, and vice-versa.
type AdditiveOperator ¶
type AdditiveOperator int
AdditiveOperator determines the additive type for AdditiveExpression
const ( AdditiveNone AdditiveOperator = iota AdditiveAdd AdditiveMinus )
Valid AdditiveOperator's
func (AdditiveOperator) String ¶
func (a AdditiveOperator) String() string
String implements the fmt.Stringer interface
type Argument ¶ added in v0.2.9
type Argument struct { Spread bool AssignmentExpression AssignmentExpression Tokens Tokens }
Argument is an item in an ArgumentList and contains the spread information and the AssignementExpression
type Arguments ¶
Arguments as defined in TC39 https://tc39.es/ecma262/#prod-Arguments
type ArrayAssignmentPattern ¶ added in v0.0.10
type ArrayAssignmentPattern struct { AssignmentElements []AssignmentElement AssignmentRestElement *LeftHandSideExpression Tokens Tokens }
ArrayAssignmentPattern as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ArrayAssignmentPattern
type ArrayBindingPattern ¶
type ArrayBindingPattern struct { BindingElementList []BindingElement BindingRestElement *BindingElement Tokens Tokens }
ArrayBindingPattern as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ArrayBindingPattern
type ArrayElement ¶ added in v0.2.5
type ArrayElement struct { Spread bool AssignmentExpression Tokens Tokens }
ArrayElement is an element of ElementList in ECMA-262 https://262.ecma-international.org/11.0/#prod-ElementList
type ArrayLiteral ¶
type ArrayLiteral struct { ElementList []ArrayElement Tokens Tokens }
ArrayLiteral as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ArrayLiteral
type ArrowFunction ¶
type ArrowFunction struct { Async bool BindingIdentifier *Token FormalParameters *FormalParameters AssignmentExpression *AssignmentExpression FunctionBody *Block Tokens Tokens }
ArrowFunction as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ArrowFunction
Also includes AsyncArrowFunction.
Only one of BindingIdentifier or FormalParameters must be non-nil.
Only one of AssignmentExpression or FunctionBody must be non-nil.
type AssignmentElement ¶ added in v0.0.10
type AssignmentElement struct { DestructuringAssignmentTarget DestructuringAssignmentTarget Initializer *AssignmentExpression Tokens Tokens }
AssignmentElement as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-AssignmentElement
type AssignmentExpression ¶
type AssignmentExpression struct { ConditionalExpression *ConditionalExpression ArrowFunction *ArrowFunction LeftHandSideExpression *LeftHandSideExpression AssignmentPattern *AssignmentPattern Yield bool Delegate bool AssignmentOperator AssignmentOperator AssignmentExpression *AssignmentExpression Tokens Tokens }
AssignmentExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-AssignmentExpression
It is only valid for one of ConditionalExpression, ArrowFunction, LeftHandSideExpression, and AssignmentPattern to be non-nil.
If LeftHandSideExpression, or AssignmentPattern are non-nil, then AssignmentOperator must not be AssignmentNone and AssignmentExpression must be non-nil.
If LeftHandSideArray, or LeftHandSideObject are non-nil, AssignmentOperator must be AssignmentAssign.
If Yield is true, AssignmentExpression must be non-nil.
It is only valid for Delagate to be true if Yield is also true.
If AssignmentOperator is AssignmentNone LeftHandSideExpression must be nil.
If LeftHandSideExpression, and AssignmentPattern are nil and Yield is false, AssignmentExpression must be nil.
type AssignmentOperator ¶
type AssignmentOperator uint8
AssignmentOperator specifies the type of assignment in AssignmentExpression
const ( AssignmentNone AssignmentOperator = iota AssignmentAssign AssignmentMultiply AssignmentDivide AssignmentRemainder AssignmentAdd AssignmentSubtract AssignmentLeftShift AssignmentSignPropagatingRightShift AssignmentZeroFillRightShift AssignmentBitwiseAND AssignmentBitwiseXOR AssignmentBitwiseOR AssignmentExponentiation AssignmentLogicalAnd AssignmentLogicalOr AssignmentNullish )
Valid AssignmentOperator's
func (AssignmentOperator) String ¶
func (a AssignmentOperator) String() string
String implements the fmt.Stringer interface
type AssignmentPattern ¶ added in v0.0.10
type AssignmentPattern struct { ObjectAssignmentPattern *ObjectAssignmentPattern ArrayAssignmentPattern *ArrayAssignmentPattern Tokens Tokens }
AssignmentPattern as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-AssignmentPattern
Only one of ObjectAssignmentPattern or ArrayAssignmentPattern must be non-nil
type AssignmentProperty ¶ added in v0.0.10
type AssignmentProperty struct { PropertyName PropertyName DestructuringAssignmentTarget *DestructuringAssignmentTarget Initializer *AssignmentExpression Tokens Tokens }
AssignmentProperty as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-AssignmentProperty
type BindingElement ¶
type BindingElement struct { SingleNameBinding *Token ArrayBindingPattern *ArrayBindingPattern ObjectBindingPattern *ObjectBindingPattern Initializer *AssignmentExpression Tokens Tokens }
BindingElement as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-BindingElement
Only one of SingleNameBinding, ArrayBindingPattern, or ObjectBindingPattern must be non-nil.
The Initializer is optional.
type BindingProperty ¶
type BindingProperty struct { PropertyName PropertyName BindingElement BindingElement Tokens Tokens }
BindingProperty as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-BindingProperty
A SingleNameBinding, with or without an initializer, is cloned into the Property Name and Binding Element. This allows the Binding Element Identifier to be modified while keeping the correct Property Name
type BitwiseANDExpression ¶
type BitwiseANDExpression struct { BitwiseANDExpression *BitwiseANDExpression EqualityExpression EqualityExpression Tokens Tokens }
BitwiseANDExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-BitwiseANDExpression
type BitwiseORExpression ¶
type BitwiseORExpression struct { BitwiseORExpression *BitwiseORExpression BitwiseXORExpression BitwiseXORExpression Tokens Tokens }
BitwiseORExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-BitwiseORExpression
type BitwiseXORExpression ¶
type BitwiseXORExpression struct { BitwiseXORExpression *BitwiseXORExpression BitwiseANDExpression BitwiseANDExpression Tokens Tokens }
BitwiseXORExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-BitwiseXORExpression
type Block ¶
type Block struct { StatementList []StatementListItem Tokens Tokens }
Block as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-Block
type CallExpression ¶
type CallExpression struct { MemberExpression *MemberExpression SuperCall bool ImportCall *AssignmentExpression CallExpression *CallExpression Arguments *Arguments Expression *Expression IdentifierName *Token TemplateLiteral *TemplateLiteral PrivateIdentifier *Token Tokens Tokens }
CallExpression as defined in ECMA-262 https://tc39.es/ecma262/#prod-CallExpression
It is only valid for one of MemberExpression, ImportCall, or CallExpression to be non-nil or SuperCall to be true.
If MemberExpression is non-nil, or SuperCall is true, Arguments must be non-nil.
If CallExpression is non-nil, only one of Arguments, Expression, IdentifierName, TemplateLiteral, or PrivateIdentifier must be non-nil.
func (CallExpression) Format ¶
func (f CallExpression) Format(s fmt.State, v rune)
Format implements the fmt.Formatter interface
func (*CallExpression) IsSimple ¶ added in v0.1.0
func (ce *CallExpression) IsSimple() bool
IsSimple returns whether or not the CallExpression is classed as 'simple'
type CaseClause ¶
type CaseClause struct { Expression Expression StatementList []StatementListItem Tokens Tokens }
CaseClause as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-CaseClauses
type ClassDeclaration ¶
type ClassDeclaration struct { BindingIdentifier *Token ClassHeritage *LeftHandSideExpression ClassBody []ClassElement Tokens Tokens }
ClassDeclaration as defined in ECMA-262 https://tc39.es/ecma262/#prod-ClassDeclaration
Also covers ClassExpression when BindingIdentifier is nil.
type ClassElement ¶ added in v0.2.0
type ClassElement struct { Static bool MethodDefinition *MethodDefinition FieldDefinition *FieldDefinition ClassStaticBlock *Block Tokens Tokens }
ClassElement as defined in ECMA-262 https://tc39.es/ecma262/#prod-ClassElement
Only one of MethodDefinition, FieldDefinition, or ClassStaticBlock must be non-nil.
If ClassStaticBlock is non-nil, Static should be true
type ClassElementName ¶ added in v0.2.0
type ClassElementName struct { PropertyName *PropertyName PrivateIdentifier *Token Tokens Tokens }
ClassElementName as defined in ECMA-262 https://tc39.es/ecma262/#prod-ClassElementName
Only one of PropertyName or PrivateIdentifier must be non-nil
type CoalesceExpression ¶
type CoalesceExpression struct { CoalesceExpressionHead *CoalesceExpression BitwiseORExpression BitwiseORExpression Tokens Tokens }
CoalesceExpression as defined in TC39 https://tc39.es/ecma262/#prod-CoalesceExpression
type ConditionalExpression ¶
type ConditionalExpression struct { LogicalORExpression *LogicalORExpression CoalesceExpression *CoalesceExpression True *AssignmentExpression False *AssignmentExpression Tokens Tokens }
ConditionalExpression as defined in TC39 https://tc39.es/ecma262/#prod-ConditionalExpression
One, and only one, of LogicalORExpression or CoalesceExpression must be non-nil ¶
If True is non-nil, False must be non-nil also.
func WrapConditional ¶
func WrapConditional(p ConditionalWrappable) *ConditionalExpression
WrapConditional takes one of many types and wraps it in a *ConditionalExpression.
The accepted types/pointers are as follows:
ConditionalExpression LogicalORExpression LogicalANDExpression BitwiseORExpression BitwiseXORExpression BitwiseANDExpression EqualityExpression RelationalExpression ShiftExpression AdditiveExpression MultiplicativeExpression ExponentiationExpression UnaryExpression UpdateExpression LeftHandSideExpression CallExpression OptionalExpression NewExpression MemberExpression PrimaryExpression ArrayLiteral ObjectLiteral FunctionDeclaration (FunctionExpression) ClassDeclaration (ClassExpression) TemplateLiteral ParenthesizedExpression
type ConditionalWrappable ¶ added in v0.0.2
type ConditionalWrappable interface { Type // contains filtered or unexported methods }
ConditionalWrappable is an interface that is implemented by all types that are accepted by the WrapConditional function, and is the returned type of the UnwrapConditional function
func UnwrapConditional ¶
func UnwrapConditional(c *ConditionalExpression) ConditionalWrappable
UnwrapConditional returns the first value up the ConditionalExpression chain that contains all of the information required to rebuild the lower chain.
Possible returns types are as follows:
*ConditionalExpression *LogicalORExpression *LogicalANDExpression *BitwiseORExpression *BitwiseXORExpression *BitwiseANDExpression *EqualityExpression *RelationalExpression *ShiftExpression *AdditiveExpression *MultiplicativeExpression *ExponentiationExpression *UnaryExpression *UpdateExpression *CallExpression *OptionalExpression *NewExpression *MemberExpression *PrimaryExpression *ArrayLiteral *ObjectLiteral *FunctionDeclaration (FunctionExpression) *ClassDeclaration (ClassExpression) *TemplateLiteral *ParenthesizedExpression
type Declaration ¶
type Declaration struct { ClassDeclaration *ClassDeclaration FunctionDeclaration *FunctionDeclaration LexicalDeclaration *LexicalDeclaration Tokens Tokens }
Declaration as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-Declaration
Only one of ClassDeclaration, FunctionDeclaration or LexicalDeclaration must be non-nil
type DestructuringAssignmentTarget ¶ added in v0.0.10
type DestructuringAssignmentTarget struct { LeftHandSideExpression *LeftHandSideExpression AssignmentPattern *AssignmentPattern Tokens Tokens }
DestructuringAssignmentTarget as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-DestructuringAssignmentTarget
Only one of LeftHandSideExpression or AssignmentPattern must be non-nil
type EqualityExpression ¶
type EqualityExpression struct { EqualityExpression *EqualityExpression EqualityOperator EqualityOperator RelationalExpression RelationalExpression Tokens Tokens }
EqualityExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-EqualityExpression
If EqualityOperator is not EqualityNone, then EqualityExpression must be non-nil, and vice-versa.
type EqualityOperator ¶
type EqualityOperator int
EqualityOperator determines the type of EqualityExpression
const ( EqualityNone EqualityOperator = iota EqualityEqual EqualityNotEqual EqualityStrictEqual EqualityStrictNotEqual )
Valid EqualityOperator's
func (EqualityOperator) String ¶
func (e EqualityOperator) String() string
String implements the fmt.Stringer interface
type ExponentiationExpression ¶
type ExponentiationExpression struct { ExponentiationExpression *ExponentiationExpression UnaryExpression UnaryExpression Tokens Tokens }
ExponentiationExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ExponentiationExpression
type ExportClause ¶
type ExportClause struct { ExportList []ExportSpecifier Tokens Tokens }
ExportClause as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ExportClause
type ExportDeclaration ¶
type ExportDeclaration struct { ExportClause *ExportClause ExportFromClause *Token FromClause *FromClause VariableStatement *VariableStatement Declaration *Declaration DefaultFunction *FunctionDeclaration DefaultClass *ClassDeclaration DefaultAssignmentExpression *AssignmentExpression Tokens Tokens }
ExportDeclaration as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ExportDeclaration
It is only valid for one of ExportClause, ExportFromClause, VariableStatement, Declaration, DefaultFunction, DefaultClass, or DefaultAssignmentExpression to be non-nil.
FromClause can be non-nil exclusively or paired with ExportClause.
type ExportSpecifier ¶
ExportSpecifier as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ExportSpecifier
IdentifierName must be non-nil, EIdentifierName should be non-nil.
type Expression ¶
type Expression struct { Expressions []AssignmentExpression Tokens Tokens }
Expression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-Expression
Expressions must have a length of at least one to be valid.
type FieldDefinition ¶ added in v0.2.0
type FieldDefinition struct { ClassElementName ClassElementName Initializer *AssignmentExpression Tokens Tokens }
FieldDefinition as defined in ECMA-262 https://tc39.es/ecma262/#prod-FieldDefinition
type ForType ¶
type ForType uint8
ForType determines which kind of for-loop is described by IterationStatementFor
type FormalParameters ¶
type FormalParameters struct { FormalParameterList []BindingElement BindingIdentifier *Token ArrayBindingPattern *ArrayBindingPattern ObjectBindingPattern *ObjectBindingPattern Tokens Tokens }
FormalParameters as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-FormalParameters
Only one of BindingIdentifier, ArrayBindingPattern, or ObjectBindingPattern can be non-nil.
type FromClause ¶
FromClause as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-FromClause
ModuleSpecifier must be non-nil.
type FunctionDeclaration ¶
type FunctionDeclaration struct { Type FunctionType BindingIdentifier *Token FormalParameters FormalParameters FunctionBody Block Tokens Tokens }
FunctionDeclaration as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-FunctionDeclaration
Also parses FunctionExpression, for when BindingIdentifier is nil.
Include TC39 proposal for async generator functions https://github.com/tc39/proposal-async-iteration#async-generator-functions
type FunctionType ¶
type FunctionType uint8
FunctionType determines which type of function is specified by FunctionDeclaration
const ( FunctionNormal FunctionType = iota FunctionGenerator FunctionAsync FunctionAsyncGenerator )
Valid FunctionType's
func (FunctionType) String ¶
func (ft FunctionType) String() string
String implements the fmt.Stringer interface
type IfStatement ¶
type IfStatement struct { Expression Expression Statement Statement ElseStatement *Statement Tokens Tokens }
IfStatement as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-IfStatement
type ImportClause ¶
type ImportClause struct { ImportedDefaultBinding *Token NameSpaceImport *Token NamedImports *NamedImports Tokens Tokens }
ImportClause as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ImportClause
At least one of ImportedDefaultBinding, NameSpaceImport, and NamedImports must be non-nil.
Both NameSpaceImport and NamedImports can not be non-nil.
type ImportDeclaration ¶
type ImportDeclaration struct { *ImportClause FromClause Tokens Tokens }
ImportDeclaration as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ImportDeclaration
type ImportSpecifier ¶
ImportSpecifier as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ImportSpecifier
ImportedBinding must be non-nil, and IdentifierName should be non-nil.
type IterationStatementDo ¶
type IterationStatementDo struct { Statement Statement Expression Expression Tokens Tokens }
IterationStatementDo is the do-while part of IterationStatement as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-IterationStatement
type IterationStatementFor ¶
type IterationStatementFor struct { Type ForType InitExpression *Expression InitVar []VariableDeclaration InitLexical *LexicalDeclaration Conditional *Expression Afterthought *Expression LeftHandSideExpression *LeftHandSideExpression ForBindingIdentifier *Token ForBindingPatternObject *ObjectBindingPattern ForBindingPatternArray *ArrayBindingPattern In *Expression Of *AssignmentExpression Statement Statement Tokens Tokens }
IterationStatementFor is the for part of IterationStatement as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-IterationStatement
Includes TC39 proposal for for-await-of https://github.com/tc39/proposal-async-iteration#the-async-iteration-statement-for-await-of
The Type determines which fields must be non-nil:
ForInLeftHandSide: LeftHandSideExpression and In ForInVar, ForInLet, ForInConst: ForBindingIdentifier, ForBindingPatternObject, or ForBindingPatternArray and In ForOfLeftHandSide, ForAwaitOfLeftHandSide: LeftHandSideExpression and Of ForOfVar, ForAwaitOfVar, ForOfLet, ForAwaitOfLet, ForOfConst, ForAwaitOfConst: ForBindingIdentifier, ForBindingPatternObject, or ForBindingPatternArray and Of
type IterationStatementWhile ¶
type IterationStatementWhile struct { Expression Expression Statement Statement Tokens Tokens }
IterationStatementWhile is the while part of IterationStatement as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-IterationStatement
type LeftHandSideExpression ¶
type LeftHandSideExpression struct { NewExpression *NewExpression CallExpression *CallExpression OptionalExpression *OptionalExpression Tokens Tokens }
LeftHandSideExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-LeftHandSideExpression
It is only valid for one of NewExpression, CallExpression or OptionalExpression to be non-nil.
Includes OptionalExpression as per TC39 (2020-03)
func (LeftHandSideExpression) Format ¶
func (f LeftHandSideExpression) Format(s fmt.State, v rune)
Format implements the fmt.Formatter interface
func (*LeftHandSideExpression) IsSimple ¶ added in v0.1.0
func (lhs *LeftHandSideExpression) IsSimple() bool
IsSimple returns whether or not the LeftHandSideExpression is classed as 'simple'
type LetOrConst ¶
type LetOrConst bool
LetOrConst specifies whether a LexicalDeclaration is a let or const declaration
const ( Let LetOrConst = false Const LetOrConst = true )
Valid LetOrConst values
func (LetOrConst) String ¶
func (l LetOrConst) String() string
String implements the fmt.Stringer interface
type LexicalBinding ¶
type LexicalBinding struct { BindingIdentifier *Token ArrayBindingPattern *ArrayBindingPattern ObjectBindingPattern *ObjectBindingPattern Initializer *AssignmentExpression Tokens Tokens }
LexicalBinding as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-LexicalBinding
Only one of BindingIdentifier, ArrayBindingPattern or ObjectBindingPattern must be non-nil. The Initializer is optional only for a BindingIdentifier.
type LexicalDeclaration ¶
type LexicalDeclaration struct { LetOrConst BindingList []LexicalBinding Tokens Tokens }
LexicalDeclaration as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-LexicalDeclaration
type LogicalANDExpression ¶
type LogicalANDExpression struct { LogicalANDExpression *LogicalANDExpression BitwiseORExpression BitwiseORExpression Tokens Tokens }
LogicalANDExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-LogicalANDExpression
type LogicalORExpression ¶
type LogicalORExpression struct { LogicalORExpression *LogicalORExpression LogicalANDExpression LogicalANDExpression Tokens Tokens }
LogicalORExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-LogicalORExpression
type MemberExpression ¶
type MemberExpression struct { MemberExpression *MemberExpression PrimaryExpression *PrimaryExpression Expression *Expression IdentifierName *Token TemplateLiteral *TemplateLiteral SuperProperty bool NewTarget bool ImportMeta bool Arguments *Arguments PrivateIdentifier *Token Tokens Tokens }
MemberExpression as defined in ECMA-262 https://tc39.es/ecma262/#prod-MemberExpression
If PrimaryExpression is nil, SuperProperty is true, NewTarget is true, or ImportMeta is true, Expression, IdentifierName, TemplateLiteral, Arguments and PrivateIdentifier must be nil.
If Expression, IdentifierName, TemplateLiteral, Arguments, or PrivateIdentifier is non-nil, then MemberExpression must be non-nil.
It is only valid if one of Expression, IdentifierName, TemplateLiteral, Arguments, and PrivateIdentifier is non-nil.
func (MemberExpression) Format ¶
func (f MemberExpression) Format(s fmt.State, v rune)
Format implements the fmt.Formatter interface
func (*MemberExpression) IsSimple ¶ added in v0.1.0
func (me *MemberExpression) IsSimple() bool
IsSimple returns whether or not the MemberExpression is classed as 'simple'
type MethodDefinition ¶
type MethodDefinition struct { Type MethodType ClassElementName ClassElementName Params FormalParameters FunctionBody Block Tokens Tokens }
MethodDefinition as specified in ECMA-262 https://tc39.es/ecma262/#prod-MethodDefinition
type MethodType ¶
type MethodType uint8
MethodType determines the prefixes for MethodDefinition
const ( MethodNormal MethodType = iota MethodGenerator MethodAsync MethodAsyncGenerator MethodGetter MethodSetter )
Valid MethodType's
func (MethodType) String ¶
func (mt MethodType) String() string
String implements the fmt.Stringer interface
type Module ¶
type Module struct { ModuleListItems []ModuleItem Tokens Tokens }
Module represents the top-level of a parsed javascript module
func ParseModule ¶
ParseModule parses a javascript module
func ScriptToModule ¶ added in v1.4.1
ScriptToModule converts a Script type to a Module type
type ModuleItem ¶
type ModuleItem struct { ImportDeclaration *ImportDeclaration StatementListItem *StatementListItem ExportDeclaration *ExportDeclaration Tokens Tokens }
ModuleItem as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ModuleItem
Only one of ImportDeclaration, StatementListItem, or ExportDeclaration must be non-nil.
type MultiplicativeExpression ¶
type MultiplicativeExpression struct { MultiplicativeExpression *MultiplicativeExpression MultiplicativeOperator MultiplicativeOperator ExponentiationExpression ExponentiationExpression Tokens Tokens }
MultiplicativeExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-MultiplicativeExpression
If MultiplicativeOperator is not MultiplicativeNone then MultiplicativeExpression must be non-nil, and vice-versa.
type MultiplicativeOperator ¶
type MultiplicativeOperator int
MultiplicativeOperator determines the multiplication type for MultiplicativeExpression
const ( MultiplicativeNone MultiplicativeOperator = iota MultiplicativeMultiply MultiplicativeDivide MultiplicativeRemainder )
Valid MultiplicativeOperator's
func (MultiplicativeOperator) String ¶
func (m MultiplicativeOperator) String() string
String implements the fmt.Stringer interface
type NamedImports ¶
type NamedImports struct { ImportList []ImportSpecifier Tokens Tokens }
NamedImports as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-NamedImports
type NewExpression ¶
type NewExpression struct { News uint MemberExpression MemberExpression Tokens Tokens }
NewExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-NewExpression
The News field is a count of the number of 'new' keywords that proceed the MemberExpression
type ObjectAssignmentPattern ¶ added in v0.0.10
type ObjectAssignmentPattern struct { AssignmentPropertyList []AssignmentProperty AssignmentRestElement *LeftHandSideExpression Tokens Tokens }
ObjectAssignmentPattern as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ObjectAssignmentPattern
type ObjectBindingPattern ¶
type ObjectBindingPattern struct { BindingPropertyList []BindingProperty BindingRestProperty *Token Tokens Tokens }
ObjectBindingPattern as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ObjectBindingPattern
type ObjectLiteral ¶
type ObjectLiteral struct { PropertyDefinitionList []PropertyDefinition Tokens Tokens }
ObjectLiteral as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ObjectLiteral
type OptionalChain ¶
type OptionalChain struct { OptionalChain *OptionalChain Arguments *Arguments Expression *Expression IdentifierName *Token TemplateLiteral *TemplateLiteral PrivateIdentifier *Token Tokens Tokens }
OptionalChain as defined in TC39 https://tc39.es/ecma262/#prod-OptionalExpression
It is only valid for one of Arguments, Expression, IdentifierName, TemplateLiteral, or PrivateIdentifier to be non-nil.
type OptionalExpression ¶
type OptionalExpression struct { MemberExpression *MemberExpression CallExpression *CallExpression OptionalExpression *OptionalExpression OptionalChain OptionalChain Tokens Tokens }
OptionalExpression as defined in TC39 https://tc39.es/ecma262/#prod-OptionalExpression
It is only valid for one of NewExpression, CallExpression or OptionalExpression to be non-nil.
type ParenthesizedExpression ¶ added in v0.1.1
type ParenthesizedExpression struct { Expressions []AssignmentExpression Tokens Tokens // contains filtered or unexported fields }
ParenthesizedExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ParenthesizedExpression
It is valid for only one of BindingIdentifier, ArrayBindingPattern, and ObjectBindingPattern to be non-nil
type PrimaryExpression ¶
type PrimaryExpression struct { This *Token IdentifierReference *Token Literal *Token ArrayLiteral *ArrayLiteral ObjectLiteral *ObjectLiteral FunctionExpression *FunctionDeclaration ClassExpression *ClassDeclaration TemplateLiteral *TemplateLiteral ParenthesizedExpression *ParenthesizedExpression Tokens Tokens }
PrimaryExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-PrimaryExpression
It is only valid is one IdentifierReference, Literal, ArrayLiteral, ObjectLiteral, FunctionExpression, ClassExpression, TemplateLiteral, or ParenthesizedExpression is non-nil or This is true.
func (PrimaryExpression) Format ¶
func (f PrimaryExpression) Format(s fmt.State, v rune)
Format implements the fmt.Formatter interface
func (*PrimaryExpression) IsSimple ¶ added in v0.1.0
func (pe *PrimaryExpression) IsSimple() bool
IsSimple returns whether or not the PrimaryExpression is classed as 'simple'
type PropertyDefinition ¶
type PropertyDefinition struct { IsCoverInitializedName bool PropertyName *PropertyName AssignmentExpression *AssignmentExpression MethodDefinition *MethodDefinition Tokens Tokens }
PropertyDefinition as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-PropertyDefinition
One, and only one, of AssignmentExpression or MethodDefinition must be non-nil.
It is only valid for PropertyName to be non-nil when AssignmentExpression is also non-nil.
The IdentifierReference is stored within PropertyName.
type PropertyName ¶
type PropertyName struct { LiteralPropertyName *Token ComputedPropertyName *AssignmentExpression Tokens Tokens }
PropertyName as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-PropertyName
Only one of LiteralPropertyName or ComputedPropertyName must be non-nil.
type RelationalExpression ¶
type RelationalExpression struct { PrivateIdentifier *Token RelationalExpression *RelationalExpression RelationshipOperator RelationshipOperator ShiftExpression ShiftExpression Tokens Tokens }
RelationalExpression as defined in ECMA-262 https://tc39.es/ecma262/#prod-RelationalExpression
If PrivateIdentifier is non-nil, then RelationshipOperator should be RelationshipIn.
If PrivateIdentifier is nil and RelationshipOperator does not equal RelationshipNone, then RelationalExpression should be non-nil
type RelationshipOperator ¶
type RelationshipOperator int
RelationshipOperator determines the relationship type for RelationalExpression
const ( RelationshipNone RelationshipOperator = iota RelationshipLessThan RelationshipGreaterThan RelationshipLessThanEqual RelationshipGreaterThanEqual RelationshipInstanceOf RelationshipIn )
Valid RelationshipOperator's
func (RelationshipOperator) String ¶
func (r RelationshipOperator) String() string
String implements the fmt.Stringer interface
type Script ¶
type Script struct { StatementList []StatementListItem Tokens Tokens }
Script represents the top-level of a parsed javascript text
func ParseScript ¶
ParseScript parses a javascript input into an AST.
It is recommended to use ParseModule instead of this function.
type ShiftExpression ¶
type ShiftExpression struct { ShiftExpression *ShiftExpression ShiftOperator ShiftOperator AdditiveExpression AdditiveExpression Tokens Tokens }
ShiftExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-ShiftExpression
If ShiftOperator is not ShiftNone then ShiftExpression must be non-nil, and vice-versa.
type ShiftOperator ¶
type ShiftOperator int
ShiftOperator determines the shift tyoe for ShiftExpression
const ( ShiftNone ShiftOperator = iota ShiftLeft ShiftRight ShiftUnsignedRight )
Valid ShiftOperator's
func (ShiftOperator) String ¶
func (s ShiftOperator) String() string
String implements the fmt.Stringer interface
type Statement ¶
type Statement struct { Type StatementType BlockStatement *Block VariableStatement *VariableStatement ExpressionStatement *Expression IfStatement *IfStatement IterationStatementDo *IterationStatementDo IterationStatementWhile *IterationStatementWhile IterationStatementFor *IterationStatementFor SwitchStatement *SwitchStatement WithStatement *WithStatement LabelIdentifier *Token LabelledItemFunction *FunctionDeclaration LabelledItemStatement *Statement TryStatement *TryStatement Tokens Tokens }
Statement as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-Statement
It is only valid for one of the pointer type to be non-nil.
If LabelIdentifier is non-nil, either one of LabelledItemFunction, or LabelledItemStatement must be non-nil, or Type must be StatementContinue or StatementBreak.
If Type is StatementThrow, ExpressionStatement must be non-nil.
type StatementListItem ¶
type StatementListItem struct { Statement *Statement Declaration *Declaration Tokens Tokens }
StatementListItem as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-StatementListItem Only one of Statement, or Declaration must be non-nil.
type StatementType ¶
type StatementType uint8
StatementType determines the type of a Statement type
const ( StatementNormal StatementType = iota StatementContinue StatementBreak StatementReturn StatementThrow StatementDebugger )
Valid StatementType's
func (StatementType) String ¶
func (st StatementType) String() string
String implements the fmt.Stringer interface
type SwitchStatement ¶
type SwitchStatement struct { Expression Expression CaseClauses []CaseClause DefaultClause []StatementListItem PostDefaultCaseClauses []CaseClause Tokens Tokens }
SwitchStatement as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-SwitchStatement
type TemplateLiteral ¶
type TemplateLiteral struct { NoSubstitutionTemplate *Token TemplateHead *Token Expressions []Expression TemplateMiddleList []*Token TemplateTail *Token Tokens Tokens }
TemplateLiteral as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-TemplateLiteral
If NoSubstitutionTemplate is non-nil it is only valid for TemplateHead, Expressions, TemplateMiddleList, and TemplateTail to be nil.
If NoSubstitutionTemplate is nil, the TemplateHead, Expressions, and TemplateTail must be non-nil. TemplateMiddleList must have a length of one less than the length of Expressions.
type TemplateType ¶ added in v1.4.1
type TemplateType byte
TemplateType determines the type of Template used in QuoteTemplate.
const ( TemplateNoSubstitution TemplateType = iota TemplateHead TemplateMiddle TemplateTail )
func TokenTypeToTemplateType ¶ added in v1.4.1
func TokenTypeToTemplateType(tokenType parser.TokenType) TemplateType
TokenTypeToTemplateType converts from a parser.TokenType to the appropriate TemplateType.
Invalid TokenTypes return 255.
type Tokeniser ¶ added in v1.3.0
type Tokeniser interface { GetToken() (parser.Token, error) GetError() error TokeniserState(parser.TokenFunc) }
Tokeniser is an interface representing a tokeniser
func AsTypescript ¶ added in v1.4.0
AsTypescript converts the tokeniser to one that reads Typescript.
When used with ParseScript or ParseModule, will produce Javascript AST from most valid Typescript files, though it may also parse invalid Typescript.
Currently does not support any Typescript feature that requires codegen or lookahead/lookback, such as the Typescript 'private' modifier, or the 'enum' and 'namespace' declarations.
type TryStatement ¶
type TryStatement struct { TryBlock Block CatchParameterBindingIdentifier *Token CatchParameterObjectBindingPattern *ObjectBindingPattern CatchParameterArrayBindingPattern *ArrayBindingPattern CatchBlock *Block FinallyBlock *Block Tokens Tokens }
TryStatement as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-TryStatement
Only one of CatchParameterBindingIdentifier, CatchParameterObjectBindingPattern, and CatchParameterArrayBindingPattern can be non-nil, and must be so if CatchBlock is non-nil.
If one of CatchParameterBindingIdentifier, CatchParameterObjectBindingPattern, CatchParameterArrayBindingPattern is non-nil, then CatchBlock must be non-nil.
type UnaryExpression ¶
type UnaryExpression struct { UnaryOperators []UnaryOperator UpdateExpression UpdateExpression Tokens Tokens }
UnaryExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-UnaryExpression
type UnaryOperator ¶
type UnaryOperator byte
UnaryOperator determines a unary operator within UnaryExpression
const ( UnaryNone UnaryOperator = iota UnaryDelete UnaryVoid UnaryTypeOf UnaryAdd UnaryMinus UnaryBitwiseNot UnaryLogicalNot UnaryAwait )
Valid UnaryOperator's
func (UnaryOperator) String ¶
func (u UnaryOperator) String() string
String implements the fmt.Stringer interface
type UpdateExpression ¶
type UpdateExpression struct { LeftHandSideExpression *LeftHandSideExpression UpdateOperator UpdateOperator UnaryExpression *UnaryExpression Tokens Tokens }
UpdateExpression as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-UpdateExpression
If UpdateOperator is UpdatePreIncrement or UpdatePreDecrement UnaryExpression must be non-nil, and vice-versa. In all other cases, LeftHandSideExpression must be non-nil.
type UpdateOperator ¶
type UpdateOperator int
UpdateOperator determines the type of update operation for UpdateExpression
const ( UpdateNone UpdateOperator = iota UpdatePostIncrement UpdatePostDecrement UpdatePreIncrement UpdatePreDecrement )
Valid UpdateOperator's
func (UpdateOperator) String ¶
func (u UpdateOperator) String() string
String implements the fmt.Stringer interface
type VariableDeclaration ¶
type VariableDeclaration = LexicalBinding
VariableDeclaration as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-VariableDeclaration
type VariableStatement ¶
type VariableStatement struct { VariableDeclarationList []VariableDeclaration Tokens Tokens }
VariableStatement as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-VariableStatement
VariableDeclarationList must have a length or at least one.
type WithStatement ¶
type WithStatement struct { Expression Expression Statement Statement Tokens Tokens }
WithStatement as defined in ECMA-262 https://262.ecma-international.org/11.0/#prod-WithStatement