New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

htmlx-parser-svast

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmlx-parser-svast

Htmlx parser which generates unist/svast AST

  • 0.1.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

htmlx-parser-svast

A parser for HTMLx that produces a Svast AST which implements the Unist.

Unlike its older handcrafted sibling svelte-parse, this library is not focused on speed. It is built with Chevrotain so that it may inherit the excellent error recovery properties of that parser generator.

It was developed to help with processing Svelte files during development, where the files may contain errors, or expressions and scripts written in languages that svelte's own parser can't handle (eg Typescript).

Usage

Import and invoke the parser by calling parse.

import { parse } from 'htmlx-parser-svast'

const input = '<h1 title={someExpression}>Heading</h1>';
const result = parse(input);

The result returned is as much of the AST as could be generated along with any errors encountered

declare type ParseResult = {
    ast: Root; //Root is a Svast AST node
    errors: ParseError[]
};

With errors having the type

 type ParseError = {
    source: "Lexer" | "Parser"
    name: string
    message: string    
    position: {
        start: Point,
        end: Point
    }
}

Limitations

  • It doesn't implement svast's each block.
  • It is slower and larger than svelte-parse.
  • HTMLx expressions are parsed by looking for the nearest, unbalanced }.
  • The AST builder currently doesn't take full advantage of the error recovery features of chevrotain.
  • Writing more tests is a work in progress.

Keywords

FAQs

Package last updated on 16 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc