Skip to main content

latest

Parser for Neos Fusion Files

This package works with Node.jsIt is unknown whether this package works with Bun, Cloudflare Workers, Deno, Browsers
JSR Score
64%
Published
3 weeks ago (0.1.46)

Neos Fusion Parser

Based on the official Neos.Fusion parser

AFX & EEL Parsers are new.

Disclaimer

This is currently under active development primarily for the Neos Fusion VSCode Extension.

Example

import { FusionParserOptions, ObjectTreeParser } from 'ts-fusion-parser'
import { TagNode } from 'ts-fusion-parser/out/dsl/afx/nodes/TagNode'
import { AfxParserOptions } from 'ts-fusion-parser/out/dsl/afx/parser'
import { EelParserOptions } from 'ts-fusion-parser/out/dsl/eel/parser'
import { StringValue } from 'ts-fusion-parser/out/fusion/nodes/StringValue'

const eelParserOptions: EelParserOptions = {
    // this allows for `<div>{props.}</div>` to be parsed as `<div>{props}</div>`
    allowIncompleteObjectPaths: true
}

const afxParserOptions: AfxParserOptions = {
    eelParserOptions,
    // this auto-closes left open tags in the end
    allowUnclosedTags: true
}

const fusionParserOptions: FusionParserOptions = {
    eelParserOptions,
    afxParserOptions,
    // save Errors in the `FusionFile.errors` array instead of throwing
    ignoreErrors: true
}

const fusion = `
prototype(Vendor.Website:Component) < prototype(Neos.Fusion:Component) {
    text = "bla"

    renderer = afx\`
 		<div>{props.text}</div>
    \`
}
`

// not really used currently
const contextPathAndFileName = undefined
const fusionFile = ObjectTreeParser.parse(fusion, contextPathAndFileName, fusionParserOptions)

const stringValues = fusionFile.getNodesByType(StringValue)
console.log("text: ", stringValues?.[0].value, stringValues?.[0].value === "bla")

const tagNodes = fusionFile.getNodesByType(TagNode)
// as this is currently WIP there is no real public API specified so a lot of properties are still `protected`
console.log("tag node: ", tagNodes?.[0]["name"], tagNodes?.[0]["name"] === "true")

Add Package

deno add @sjs/ts-fusion-parser

Import symbol

import * as mod from "@sjs/ts-fusion-parser";

Add Package

npx jsr add @sjs/ts-fusion-parser

Import symbol

import * as mod from "@sjs/ts-fusion-parser";

Add Package

yarn dlx jsr add @sjs/ts-fusion-parser

Import symbol

import * as mod from "@sjs/ts-fusion-parser";

Add Package

pnpm dlx jsr add @sjs/ts-fusion-parser

Import symbol

import * as mod from "@sjs/ts-fusion-parser";

Add Package

bunx jsr add @sjs/ts-fusion-parser

Import symbol

import * as mod from "@sjs/ts-fusion-parser";