@html-eslint/template-parser
TypeScript icon, indicating that this package has built-in type declarations

0.40.0 • Public • Published

@html-eslint/template-parser

A parser that parses the html written inside a template literal.

Usage

const { parse } = require("@html-eslint/template-parser");
const espree = require("espree");
const { SourceCode } = require("eslint");

const code = `html\`<div
  id="\${ id }">
    \${text}
  </div>\`;`;

const ast = espree.parse(code, {
  range: true,
  loc: true,
  ecmaVersion: "latest",
});
const sourceCode = new SourceCode({
  text: code,
  ast: {
    ...ast,
    tokens: [],
    comments: ast.comments ?? [],
    loc: ast.loc,
    range: ast.range,
  },
});

const exp = ast.body[0].expression.quasi;
parse(exp, sourcecode, {
  Tag(node) {
    // ...
  },
  AttributeValue(node) {
    // ...
  },
});

License

Distributed under the MIT License.

/@html-eslint/template-parser/

    Package Sidebar

    Install

    npm i @html-eslint/template-parser

    Weekly Downloads

    15,033

    Version

    0.40.0

    License

    MIT

    Unpacked Size

    19.2 kB

    Total Files

    18

    Last publish

    Collaborators

    • yeonjuan-joah