JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14920
  • Score
    100M100P100Q134918F
  • License MIT

HTML parser for template literals

Package Exports

  • @html-eslint/template-parser
  • @html-eslint/template-parser/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@html-eslint/template-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@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.