Skip to content

@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

Ensure

Methods

componentLiteral()

static componentLiteral(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()

static componentTagDeclaration(path, tagName, variableName, createDeclaration): Identifier

Defined in: compiler/compiler-utils.ts:330

Parameters
path

NodePath

tagName

string

variableName

string

createDeclaration

() => VariableDeclarator

Returns

Identifier

findProgramPathFromNodePath()

static findProgramPathFromNodePath(path): NodePath<Program>

Defined in: compiler/compiler-utils.ts:53

Parameters
path

NodePath

Returns

NodePath<Program>

getArrowExpressionPath()

static getArrowExpressionPath(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()

static getClosestBinding(path, name): Binding | undefined

Defined in: compiler/compiler-utils.ts:186

Parameters
path

NodePath

name

string

Returns

Binding | undefined

getClosestStatementPath()

static getClosestStatementPath(path): NodePath<Statement>

Defined in: compiler/compiler-utils.ts:174

Parameters
path

NodePath

Returns

NodePath<Statement>

getNodePath()

static getNodePath<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()

static getProgramPathFromFile(filePath): NodePath<Program> | undefined

Defined in: compiler/compiler-utils.ts:61

Parameters
filePath

string

Returns

NodePath<Program> | undefined

hoistAsTopLevelVariable()

static hoistAsTopLevelVariable(path, variableName, expression): Identifier

Defined in: compiler/compiler-utils.ts:282

Parameters
path

NodePath

variableName

string

expression

Expression

Returns

Identifier

import()

static import(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()

static replaceAndHoistAsVariable(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

EnsureImport

Methods

attributePart()

static attributePart(program, path): void

Defined in: compiler/compiler-utils.ts:548

Parameters
program

Program

path

NodePath

Returns

void

booleanPart()

static booleanPart(program, path): void

Defined in: compiler/compiler-utils.ts:544

Parameters
program

Program

path

NodePath

Returns

void

childPart()

static childPart(program, path): void

Defined in: compiler/compiler-utils.ts:564

Parameters
program

Program

path

NodePath

Returns

void

classMap()

static classMap(program, path): void

Defined in: compiler/compiler-utils.ts:528

Parameters
program

Program

path

NodePath

Returns

void

createRef()

static createRef(program, path): void

Defined in: compiler/compiler-utils.ts:520

Parameters
program

Program

path

NodePath

Returns

void

elementPart()

static elementPart(program, path): void

Defined in: compiler/compiler-utils.ts:556

Parameters
program

Program

path

NodePath

Returns

void

ensureImport()

protected static ensureImport(config, program, path): void

Defined in: compiler/compiler-utils.ts:470

Parameters
config

ImportConfig

program

Program

path

NodePath

Returns

void

eventPart()

static eventPart(program, path): void

Defined in: compiler/compiler-utils.ts:560

Parameters
program

Program

path

NodePath

Returns

void

html()

static html(program, path): void

Defined in: compiler/compiler-utils.ts:492

Parameters
program

Program

path

NodePath

Returns

void

htmlStatic()

static htmlStatic(program, path): void

Defined in: compiler/compiler-utils.ts:496

Parameters
program

Program

path

NodePath

Returns

void

literalMap()

static literalMap(program, path): void

Defined in: compiler/compiler-utils.ts:536

Parameters
program

Program

path

NodePath

Returns

void

mathml()

static mathml(program, path): void

Defined in: compiler/compiler-utils.ts:508

Parameters
program

Program

path

NodePath

Returns

void

mathmlStatic()

static mathmlStatic(program, path): void

Defined in: compiler/compiler-utils.ts:512

Parameters
program

Program

path

NodePath

Returns

void

propertyPart()

static propertyPart(program, path): void

Defined in: compiler/compiler-utils.ts:552

Parameters
program

Program

path

NodePath

Returns

void

rest()

static rest(program, path): void

Defined in: compiler/compiler-utils.ts:532

Parameters
program

Program

path

NodePath

Returns

void

styleMap()

static styleMap(program, path): void

Defined in: compiler/compiler-utils.ts:524

Parameters
program

Program

path

NodePath

Returns

void

svg()

static svg(program, path): void

Defined in: compiler/compiler-utils.ts:500

Parameters
program

Program

path

NodePath

Returns

void

svgStatic()

static svgStatic(program, path): void

Defined in: compiler/compiler-utils.ts:504

Parameters
program

Program

path

NodePath

Returns

void

taggedTemplateUtil()

static taggedTemplateUtil(program, path): void

Defined in: compiler/compiler-utils.ts:540

Parameters
program

Program

path

NodePath

Returns

void

unsafeStatic()

static unsafeStatic(program, path): void

Defined in: compiler/compiler-utils.ts:516

Parameters
program

Program

path

NodePath

Returns

void

Type Aliases

TemplateType

TemplateType = Values<Pick<typeof VARIABLES, "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[keyof T]

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

ProcessorContext

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

TemplateType


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

Released under the Apache-2.0 License.