@arcmantle/lit-jsx / compiler/compiler-utils
compiler/compiler-utils
Classes
Ensure
Defined in: compiler/compiler-utils.ts:51
Contains utility methods for retrieving and manipulating node paths in Babel ASTs.
Constructors
Constructor
new Ensure():
Ensure
Returns
Methods
componentLiteral()
staticcomponentLiteral(tagName,variableName,path,program,isClass):Identifier
Defined in: compiler/compiler-utils.ts:402
Parameters
tagName
string
variableName
string
path
NodePath
program
Program
isClass
boolean = false
Returns
Identifier
componentTagDeclaration()
staticcomponentTagDeclaration(path,tagName,variableName,createDeclaration):Identifier
Defined in: compiler/compiler-utils.ts:330
Parameters
path
NodePath
tagName
string
variableName
string
createDeclaration
() => VariableDeclarator
Returns
Identifier
findProgramPathFromNodePath()
staticfindProgramPathFromNodePath(path):NodePath<Program>
Defined in: compiler/compiler-utils.ts:53
Parameters
path
NodePath
Returns
NodePath<Program>
getArrowExpressionPath()
staticgetArrowExpressionPath(path):NodePath<ArrowFunctionExpression> |undefined
Defined in: compiler/compiler-utils.ts:202
Finds the closest arrow function expression with an expression body starting from the given path. Returns the NodePath of the arrow function expression if found, otherwise undefined.
Parameters
path
NodePath
Returns
NodePath<ArrowFunctionExpression> | undefined
getClosestBinding()
staticgetClosestBinding(path,name):Binding|undefined
Defined in: compiler/compiler-utils.ts:186
Parameters
path
NodePath
name
string
Returns
Binding | undefined
getClosestStatementPath()
staticgetClosestStatementPath(path):NodePath<Statement>
Defined in: compiler/compiler-utils.ts:174
Parameters
path
NodePath
Returns
NodePath<Statement>
getNodePath()
staticgetNodePath<T>(node,path):NodePath<T> |undefined
Defined in: compiler/compiler-utils.ts:150
Type Parameters
T
T extends Node
Parameters
node
T
path
NodePath
Returns
NodePath<T> | undefined
getProgramPathFromFile()
staticgetProgramPathFromFile(filePath):NodePath<Program> |undefined
Defined in: compiler/compiler-utils.ts:61
Parameters
filePath
string
Returns
NodePath<Program> | undefined
hoistAsTopLevelVariable()
statichoistAsTopLevelVariable(path,variableName,expression):Identifier
Defined in: compiler/compiler-utils.ts:282
Parameters
path
NodePath
variableName
string
expression
Expression
Returns
Identifier
import()
staticimport(importSource,importName,createImport,program,path):void
Defined in: compiler/compiler-utils.ts:93
Parameters
importSource
(value) => boolean
importName
(value) => boolean
createImport
() => ImportDeclaration
program
Program
path
NodePath
Returns
void
replaceAndHoistAsVariable()
staticreplaceAndHoistAsVariable(path,variableName,expression,expandArrow):Identifier
Defined in: compiler/compiler-utils.ts:231
Hoists the expression to a variable declaration in the closest scope.
If the path is inside an arrow function with an expression body, it converts the arrow function body to a block statement and inserts the variable declaration before the return statement.
If the path is not inside such an arrow function, it inserts the variable declaration before the closest statement and replaces the target node with the new variable identifier.
Parameters
path
NodePath
variableName
string
expression
Expression
expandArrow
boolean = true
Returns
Identifier
EnsureImport
Defined in: compiler/compiler-utils.ts:468
Constructors
Constructor
new EnsureImport():
EnsureImport
Returns
Methods
attributePart()
staticattributePart(program,path):void
Defined in: compiler/compiler-utils.ts:548
Parameters
program
Program
path
NodePath
Returns
void
booleanPart()
staticbooleanPart(program,path):void
Defined in: compiler/compiler-utils.ts:544
Parameters
program
Program
path
NodePath
Returns
void
childPart()
staticchildPart(program,path):void
Defined in: compiler/compiler-utils.ts:564
Parameters
program
Program
path
NodePath
Returns
void
classMap()
staticclassMap(program,path):void
Defined in: compiler/compiler-utils.ts:528
Parameters
program
Program
path
NodePath
Returns
void
createRef()
staticcreateRef(program,path):void
Defined in: compiler/compiler-utils.ts:520
Parameters
program
Program
path
NodePath
Returns
void
elementPart()
staticelementPart(program,path):void
Defined in: compiler/compiler-utils.ts:556
Parameters
program
Program
path
NodePath
Returns
void
ensureImport()
protectedstaticensureImport(config,program,path):void
Defined in: compiler/compiler-utils.ts:470
Parameters
config
ImportConfig
program
Program
path
NodePath
Returns
void
eventPart()
staticeventPart(program,path):void
Defined in: compiler/compiler-utils.ts:560
Parameters
program
Program
path
NodePath
Returns
void
html()
statichtml(program,path):void
Defined in: compiler/compiler-utils.ts:492
Parameters
program
Program
path
NodePath
Returns
void
htmlStatic()
statichtmlStatic(program,path):void
Defined in: compiler/compiler-utils.ts:496
Parameters
program
Program
path
NodePath
Returns
void
literalMap()
staticliteralMap(program,path):void
Defined in: compiler/compiler-utils.ts:536
Parameters
program
Program
path
NodePath
Returns
void
mathml()
staticmathml(program,path):void
Defined in: compiler/compiler-utils.ts:508
Parameters
program
Program
path
NodePath
Returns
void
mathmlStatic()
staticmathmlStatic(program,path):void
Defined in: compiler/compiler-utils.ts:512
Parameters
program
Program
path
NodePath
Returns
void
propertyPart()
staticpropertyPart(program,path):void
Defined in: compiler/compiler-utils.ts:552
Parameters
program
Program
path
NodePath
Returns
void
rest()
staticrest(program,path):void
Defined in: compiler/compiler-utils.ts:532
Parameters
program
Program
path
NodePath
Returns
void
styleMap()
staticstyleMap(program,path):void
Defined in: compiler/compiler-utils.ts:524
Parameters
program
Program
path
NodePath
Returns
void
svg()
staticsvg(program,path):void
Defined in: compiler/compiler-utils.ts:500
Parameters
program
Program
path
NodePath
Returns
void
svgStatic()
staticsvgStatic(program,path):void
Defined in: compiler/compiler-utils.ts:504
Parameters
program
Program
path
NodePath
Returns
void
taggedTemplateUtil()
statictaggedTemplateUtil(program,path):void
Defined in: compiler/compiler-utils.ts:540
Parameters
program
Program
path
NodePath
Returns
void
unsafeStatic()
staticunsafeStatic(program,path):void
Defined in: compiler/compiler-utils.ts:516
Parameters
program
Program
path
NodePath
Returns
void
Type Aliases
TemplateType
TemplateType =
Values<Pick<typeofVARIABLES,"HTML"|"SVG"|"MATHML">>
Defined in: compiler/compiler-utils.ts:725
ValidJSXElement
ValidJSXElement =
t.JSXElement&object
Defined in: compiler/compiler-utils.ts:571
Type Declaration
openingElement
openingElement:
t.JSXOpeningElement&object
Type Declaration
name
name:
t.JSXIdentifier|t.JSXMemberExpression
Values
Values<
T> =T[keyofT]
Defined in: compiler/compiler-utils.ts:16
Type Parameters
T
T
Functions
ensureImports()
ensureImports(
context):void
Defined in: compiler/compiler-utils.ts:713
Parameters
context
Returns
void
getJSXElementName()
getJSXElementName(
node):string
Defined in: compiler/compiler-utils.ts:592
Parameters
node
JSXElement
Returns
string
getPathFilename()
getPathFilename(
path):string
Defined in: compiler/compiler-utils.ts:34
Parameters
path
NodePath
Returns
string
getPathSourceCode()
getPathSourceCode(
path):string
Defined in: compiler/compiler-utils.ts:41
Parameters
path
NodePath
Returns
string
getProgramFromPath()
getProgramFromPath(
path):Program
Defined in: compiler/compiler-utils.ts:25
Parameters
path
NodePath
Returns
Program
getTemplateTag()
getTemplateTag(
tagName):Values<Pick<{ATTRIBUTE_PART:"AttributePart";BOOLEAN_PART:"BooleanPart";CHILD_PART:"ChildPart";CLASS_MAP:"classMap";CLASS_MAP_LOCAL:"__$classMap";ELEMENT_PART:"ElementPart";EVENT_PART:"EventPart";HTML:"html";HTML_LOCAL:"__$html";HTML_STATIC:"htmlStatic";HTML_STATIC_LOCAL:"__$htmlStatic";LITERAL_MAP:"__$literalMap";MATHML:"mathml";MATHML_LOCAL:"__$mathml";MATHML_STATIC:"mathmlStatic";MATHML_STATIC_LOCAL:"__$mathmlStatic";PROPERTY_PART:"PropertyPart";REF:"ref";REF_LOCAL:"__$ref";REST:"__$rest";STYLE_MAP:"styleMap";STYLE_MAP_LOCAL:"__$styleMap";SVG:"svg";SVG_LOCAL:"__$svg";SVG_STATIC:"svgStatic";SVG_STATIC_LOCAL:"__$svgStatic";T_TEMPLATE_UTIL:"__$t";UNSAFE_STATIC:"unsafeStatic";UNSAFE_STATIC_LOCAL:"__$unsafeStatic"; },"HTML"|"SVG"|"MATHML">>
Defined in: compiler/compiler-utils.ts:744
Parameters
tagName
string
Returns
Values<Pick<{ ATTRIBUTE_PART: "AttributePart"; BOOLEAN_PART: "BooleanPart"; CHILD_PART: "ChildPart"; CLASS_MAP: "classMap"; CLASS_MAP_LOCAL: "__$classMap"; ELEMENT_PART: "ElementPart"; EVENT_PART: "EventPart"; HTML: "html"; HTML_LOCAL: "__$html"; HTML_STATIC: "htmlStatic"; HTML_STATIC_LOCAL: "__$htmlStatic"; LITERAL_MAP: "__$literalMap"; MATHML: "mathml"; MATHML_LOCAL: "__$mathml"; MATHML_STATIC: "mathmlStatic"; MATHML_STATIC_LOCAL: "__$mathmlStatic"; PROPERTY_PART: "PropertyPart"; REF: "ref"; REF_LOCAL: "__$ref"; REST: "__$rest"; STYLE_MAP: "styleMap"; STYLE_MAP_LOCAL: "__$styleMap"; SVG: "svg"; SVG_LOCAL: "__$svg"; SVG_STATIC: "svgStatic"; SVG_STATIC_LOCAL: "__$svgStatic"; T_TEMPLATE_UTIL: "__$t"; UNSAFE_STATIC: "unsafeStatic"; UNSAFE_STATIC_LOCAL: "__$unsafeStatic"; }, "HTML" | "SVG" | "MATHML">>
getTemplateType()
getTemplateType(
path):TemplateType
Defined in: compiler/compiler-utils.ts:726
Parameters
path
NodePath<JSXElement | JSXFragment>
Returns
isComponent()
isComponent(
tagName):boolean
Defined in: compiler/compiler-utils.ts:19
Parameters
tagName
string
Returns
boolean
isJSXCustomElementComponent()
isJSXCustomElementComponent(
path):boolean
Defined in: compiler/compiler-utils.ts:607
Parameters
path
NodePath<JSXElement | JSXFragment>
Returns
boolean
isJSXElementPath()
isJSXElementPath(
path):path is NodePath<JSXElement>
Defined in: compiler/compiler-utils.ts:675
Parameters
path
NodePath
Returns
path is NodePath<JSXElement>
isJSXElementStatic()
isJSXElementStatic(
path):boolean
Defined in: compiler/compiler-utils.ts:687
Determines if a JSX element will result in a static template. This function traverses the JSX tree to check if any custom element components are present, which would make the template static.
Parameters
path
NodePath<JSXElement | JSXFragment>
The NodePath of the JSX element to analyze
Returns
boolean
true if the template will be static, false otherwise
isJSXFragmentPath()
isJSXFragmentPath(
path):path is NodePath<JSXFragment>
Defined in: compiler/compiler-utils.ts:676
Parameters
path
NodePath
Returns
path is NodePath<JSXFragment>
isJSXFunctionElementComponent()
isJSXFunctionElementComponent(
path):boolean
Defined in: compiler/compiler-utils.ts:641
Parameters
path
NodePath<JSXElement | JSXFragment>
Returns
boolean
isValidJSXElement()
isValidJSXElement(
path):path is NodePath<ValidJSXElement>
Defined in: compiler/compiler-utils.ts:577
Parameters
path
NodePath
Returns
path is NodePath<ValidJSXElement>
isValidOpeningElement()
isValidOpeningElement(
path): path is NodePath<JSXElement | JSXFragment>
Defined in: compiler/compiler-utils.ts:587
Parameters
path
NodePath
Returns
path is NodePath<JSXElement | JSXFragment>
normalizeText()
normalizeText(
text):string
Defined in: compiler/compiler-utils.ts:757
Parameters
text
string
Returns
string