Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

htmljs-parser

Package Overview
Dependencies
Maintainers
5
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmljs-parser - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

6

dist/core/Parser.d.ts

@@ -1,2 +0,2 @@

import { STATE, Range, Handlers } from "../internal";
import { STATE, Range, ParserOptions as Options } from "../internal";
export interface Meta extends Range {

@@ -18,3 +18,3 @@ parent: Meta;

export declare class Parser {
handlers: Handlers;
options: Options;
pos: number;

@@ -34,3 +34,3 @@ maxPos: number;

lines: undefined | number[];
constructor(handlers: Handlers);
constructor(options: Options);
read(range: Range): string;

@@ -37,0 +37,0 @@ positionAt(index: number): import("../internal").Position;

@@ -1,7 +0,7 @@

import { type Handlers, type Range } from "./internal";
export { OpenTagEnding, type Handlers, type Position, type Location, type Ranges, type Range, } from "./internal";
import { type ParserOptions, type Range } from "./internal";
export { TagType, type ParserOptions as Handlers, type Position, type Location, type Ranges, type Range, } from "./internal";
/**
* Creates a new Marko parser.
*/
export declare function createParser(handlers: Handlers): {
export declare function createParser(handlers: ParserOptions): {
/**

@@ -8,0 +8,0 @@ * Parses code and calls the provided handlers.

@@ -22,3 +22,3 @@ var __defProp = Object.defineProperty;

__export(src_exports, {
OpenTagEnding: () => OpenTagEnding,
TagType: () => TagType,
createParser: () => createParser

@@ -29,9 +29,9 @@ });

// src/util/constants.ts
var OpenTagEnding = /* @__PURE__ */ ((OpenTagEnding2) => {
OpenTagEnding2[OpenTagEnding2["tag"] = 0] = "tag";
OpenTagEnding2[OpenTagEnding2["self"] = 1] = "self";
OpenTagEnding2[OpenTagEnding2["void"] = 2] = "void";
OpenTagEnding2[OpenTagEnding2["code"] = 4] = "code";
return OpenTagEnding2;
})(OpenTagEnding || {});
var TagType = /* @__PURE__ */ ((TagType2) => {
TagType2[TagType2["html"] = 0] = "html";
TagType2[TagType2["text"] = 1] = "text";
TagType2[TagType2["void"] = 2] = "void";
TagType2[TagType2["statement"] = 3] = "statement";
return TagType2;
})(TagType || {});

@@ -85,5 +85,5 @@ // src/util/util.ts

var Parser = class {
constructor(handlers) {
this.handlers = handlers;
this.handlers = handlers;
constructor(options) {
this.options = options;
this.options = options;
}

@@ -179,3 +179,3 @@ pos;

if (start !== -1) {
(_b = (_a = this.handlers).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
(_b = (_a = this.options).onText) == null ? void 0 : _b.call(_a, { start, end: this.pos });
this.textPos = -1;

@@ -186,3 +186,3 @@ }

var _a;
const content = this.enterState(((_a = this.activeTag) == null ? void 0 : _a.bodyMode) === 1 /* PARSED_TEXT */ ? states_exports.PARSED_TEXT_CONTENT : states_exports.HTML_CONTENT);
const content = this.enterState(((_a = this.activeTag) == null ? void 0 : _a.type) === 1 /* text */ ? states_exports.PARSED_TEXT_CONTENT : states_exports.HTML_CONTENT);
content.singleLine = singleLine;

@@ -201,3 +201,3 @@ content.delimiter = delimiter;

}
(_b = (_a = this.handlers).onError) == null ? void 0 : _b.call(_a, {
(_b = (_a = this.options).onError) == null ? void 0 : _b.call(_a, {
start,

@@ -216,3 +216,3 @@ end,

this.activeTag = parentTag;
(_b = (_a = this.handlers).onCloseTag) == null ? void 0 : _b.call(_a, {
(_b = (_a = this.options).onCloseTag) == null ? void 0 : _b.call(_a, {
start,

@@ -464,3 +464,3 @@ end,

};
(_b = (_a = this.handlers).onAttrName) == null ? void 0 : _b.call(_a, attr.name);
(_b = (_a = this.options).onAttrName) == null ? void 0 : _b.call(_a, attr.name);
break;

@@ -487,3 +487,3 @@ }

attr.args = true;
(_d = (_c = this.handlers).onAttrArgs) == null ? void 0 : _d.call(_c, {
(_d = (_c = this.options).onAttrArgs) == null ? void 0 : _d.call(_c, {
start,

@@ -500,3 +500,3 @@ end,

const end = ++this.pos;
(_f = (_e = this.handlers).onAttrMethod) == null ? void 0 : _f.call(_e, {
(_f = (_e = this.options).onAttrMethod) == null ? void 0 : _f.call(_e, {
start,

@@ -522,3 +522,3 @@ end,

if (attr.spread) {
(_h = (_g = this.handlers).onAttrSpread) == null ? void 0 : _h.call(_g, {
(_h = (_g = this.options).onAttrSpread) == null ? void 0 : _h.call(_g, {
start: attr.valueStart,

@@ -532,3 +532,3 @@ end: child.end,

} else {
(_j = (_i = this.handlers).onAttrValue) == null ? void 0 : _j.call(_i, {
(_j = (_i = this.options).onAttrValue) == null ? void 0 : _j.call(_i, {
start: attr.valueStart,

@@ -552,3 +552,3 @@ end: child.end,

if (!attr.name) {
(_b = (_a = parser.handlers).onAttrName) == null ? void 0 : _b.call(_a, {
(_b = (_a = parser.options).onAttrName) == null ? void 0 : _b.call(_a, {
start: attr.start,

@@ -650,3 +650,3 @@ end: attr.start

var _a, _b;
(_b = (_a = this.handlers).onCDATA) == null ? void 0 : _b.call(_a, {
(_b = (_a = this.options).onCDATA) == null ? void 0 : _b.call(_a, {
start: cdata.start,

@@ -799,7 +799,3 @@ end: cdata.end,

if (parentTag) {
if (parentTag.ending !== 0 /* tag */) {
this.emitError(this.pos, "INVALID_BODY", `The "${this.read(parentTag.tagName)}" tag does not allow nested body content`);
return;
}
if (parentTag.bodyMode === 1 /* PARSED_TEXT */ && code !== 45 /* HTML_BLOCK_DELIMITER */) {
if (parentTag.type === 1 /* text */ && code !== 45 /* HTML_BLOCK_DELIMITER */) {
this.emitError(this.pos, "ILLEGAL_LINE_START", 'A line within a tag that only allows text content must begin with a "-" character');

@@ -865,3 +861,3 @@ return;

case states_exports.JS_COMMENT_LINE:
(_b = (_a = this.handlers).onComment) == null ? void 0 : _b.call(_a, {
(_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
start: child.start,

@@ -876,3 +872,3 @@ end: child.end,

case states_exports.JS_COMMENT_BLOCK: {
(_d = (_c = this.handlers).onComment) == null ? void 0 : _d.call(_c, {
(_d = (_c = this.options).onComment) == null ? void 0 : _d.call(_c, {
start: child.start,

@@ -929,3 +925,3 @@ end: child.end,

parser.exitState();
(_b = (_a = parser.handlers).onDeclaration) == null ? void 0 : _b.call(_a, {
(_b = (_a = parser.options).onDeclaration) == null ? void 0 : _b.call(_a, {
start: declaration.start,

@@ -954,3 +950,3 @@ end: declaration.end,

var _a, _b;
(_b = (_a = this.handlers).onDoctype) == null ? void 0 : _b.call(_a, {
(_b = (_a = this.options).onDoctype) == null ? void 0 : _b.call(_a, {
start: documentType.start,

@@ -1158,3 +1154,3 @@ end: documentType.end,

var _a, _b;
(_b = (_a = this.handlers).onComment) == null ? void 0 : _b.call(_a, {
(_b = (_a = this.options).onComment) == null ? void 0 : _b.call(_a, {
start: comment.start,

@@ -1289,3 +1285,3 @@ end: comment.end,

var _a, _b;
(_b = (_a = this.handlers).onScriptlet) == null ? void 0 : _b.call(_a, {
(_b = (_a = this.options).onScriptlet) == null ? void 0 : _b.call(_a, {
start: inlineScript.start,

@@ -1370,3 +1366,3 @@ end: inlineScript.end,

var _a;
if (!this.isConcise && code === 60 /* OPEN_ANGLE_BRACKET */ && ((_a = this.activeTag) == null ? void 0 : _a.bodyMode) === 1 /* PARSED_TEXT */) {
if (!this.isConcise && code === 60 /* OPEN_ANGLE_BRACKET */ && ((_a = this.activeTag) == null ? void 0 : _a.type) === 1 /* text */) {
states_exports.checkForClosingTag(this);

@@ -1455,3 +1451,3 @@ }

var _a, _b;
(_b = (_a = this.handlers).onPlaceholder) == null ? void 0 : _b.call(_a, {
(_b = (_a = this.options).onPlaceholder) == null ? void 0 : _b.call(_a, {
start: placeholder.start,

@@ -1592,19 +1588,2 @@ end: placeholder.end,

// src/states/TAG_NAME.ts
var VOID_TAGS = [
"area",
"base",
"br",
"col",
"hr",
"embed",
"img",
"input",
"link",
"meta",
"param",
"source",
"track",
"wbr"
];
var CODE_TAGS = ["import", "export", "static", "class"];
var TAG_NAME = {

@@ -1634,3 +1613,3 @@ name: "TAG_NAME",

this.activeTag.hasShorthandId = true;
(_b = (_a = this.handlers).onTagShorthandId) == null ? void 0 : _b.call(_a, {
(_b = (_a = this.options).onTagShorthandId) == null ? void 0 : _b.call(_a, {
start,

@@ -1643,3 +1622,3 @@ end,

case 46 /* PERIOD */:
(_d = (_c = this.handlers).onTagShorthandClass) == null ? void 0 : _d.call(_c, {
(_d = (_c = this.options).onTagShorthandClass) == null ? void 0 : _d.call(_c, {
start,

@@ -1653,7 +1632,13 @@ end,

const tag = this.activeTag;
const tagType = (_f = (_e = this.options).onTagName) == null ? void 0 : _f.call(_e, {
start,
end,
quasis,
expressions,
concise: this.isConcise
});
tag.tagName = tagName;
if (tagName.expressions.length === 0) {
if (this.matchAnyAtPos(tagName, VOID_TAGS)) {
tag.ending |= 2 /* void */;
} else if (this.matchAnyAtPos(tagName, CODE_TAGS)) {
if (tagType) {
tag.type = tagType;
if (tagType === 3 /* statement */) {
if (!tag.concise) {

@@ -1665,13 +1650,5 @@ return this.emitError(tagName, "RESERVED_TAG_NAME", `The "${this.read(tagName)}" tag is reserved and cannot be used as an HTML tag.`);

}
tag.ending |= 4 /* code */;
this.enterState(states_exports.EXPRESSION).terminatedByEOL = true;
}
}
(_f = (_e = this.handlers).onTagName) == null ? void 0 : _f.call(_e, {
start,
end,
quasis,
expressions,
concise: this.isConcise
});
break;

@@ -1768,3 +1745,2 @@ }

// src/states/OPEN_TAG.ts
var PARSED_TEXT_TAGS = ["script", "style", "textarea", "html-comment"];
var CONCISE_TAG_VAR_TERMINATORS = [

@@ -1790,2 +1766,3 @@ 59 /* SEMICOLON */,

state: OPEN_TAG,
type: 0 /* html */,
parent,

@@ -1801,7 +1778,6 @@ start,

hasAttrs: false,
selfClosed: false,
shorthandEnd: -1,
tagName: void 0,
ending: 0 /* tag */,
concise: this.isConcise,
bodyMode: 0 /* HTML */,
beginMixedMode: this.beginMixedMode || this.endingMixedModeAtEOL

@@ -1816,17 +1792,23 @@ };

var _a, _b;
const { tagName, ending } = tag;
(_b = (_a = this.handlers).onOpenTagEnd) == null ? void 0 : _b.call(_a, {
start: this.pos - (this.isConcise ? 0 : ending & 1 /* self */ ? 2 : 1),
const { selfClosed } = tag;
(_b = (_a = this.options).onOpenTagEnd) == null ? void 0 : _b.call(_a, {
start: this.pos - (this.isConcise ? 0 : selfClosed ? 2 : 1),
end: this.pos,
ending
selfClosed
});
if (!this.isConcise && ending !== 0 /* tag */) {
this.closeTag(this.pos, this.pos, void 0);
} else if (tagName.expressions.length === 0 && this.matchAnyAtPos(tagName, PARSED_TEXT_TAGS)) {
tag.bodyMode = 1 /* PARSED_TEXT */;
if (this.isConcise) {
this.enterState(states_exports.CONCISE_HTML_CONTENT);
} else {
this.enterState(states_exports.PARSED_TEXT_CONTENT);
switch (selfClosed ? 2 /* void */ : tag.type) {
case 2 /* void */:
case 3 /* statement */: {
if (tag.beginMixedMode)
this.endingMixedModeAtEOL = true;
this.activeTag = tag.parentTag;
break;
}
case 1 /* text */:
if (this.isConcise) {
this.enterState(states_exports.CONCISE_HTML_CONTENT);
} else {
this.enterState(states_exports.PARSED_TEXT_CONTENT);
}
break;
}

@@ -1930,3 +1912,3 @@ },

} else if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 62 /* CLOSE_ANGLE_BRACKET */) {
tag.ending |= 1 /* self */;
tag.selfClosed = true;
this.pos += 2;

@@ -1997,3 +1979,3 @@ this.exitState();

}
(_b = (_a = this.handlers).onTagVar) == null ? void 0 : _b.call(_a, {
(_b = (_a = this.options).onTagVar) == null ? void 0 : _b.call(_a, {
start: child.start - 1,

@@ -2023,3 +2005,3 @@ end: child.end,

tag.hasArgs = true;
(_d = (_c = this.handlers).onTagArgs) == null ? void 0 : _d.call(_c, {
(_d = (_c = this.options).onTagArgs) == null ? void 0 : _d.call(_c, {
start,

@@ -2034,3 +2016,3 @@ end,

const end = ++this.pos;
(_f = (_e = this.handlers).onTagParams) == null ? void 0 : _f.call(_e, {
(_f = (_e = this.options).onTagParams) == null ? void 0 : _f.call(_e, {
start: child.start - 1,

@@ -2072,4 +2054,4 @@ end,

0 && (module.exports = {
OpenTagEnding,
TagType,
createParser
});

@@ -1,2 +0,2 @@

import { StateDefinition, BODY_MODE, OpenTagEnding, Ranges, Meta } from "../internal";
import { StateDefinition, Ranges, Meta, TagType } from "../internal";
declare const enum TAG_STAGE {

@@ -10,3 +10,3 @@ UNKNOWN = 0,

export interface OpenTagMeta extends Meta {
bodyMode: BODY_MODE;
type: TagType;
stage: TAG_STAGE;

@@ -20,3 +20,3 @@ concise: boolean;

hasShorthandId: boolean;
ending: OpenTagEnding;
selfClosed: boolean;
indent: string;

@@ -23,0 +23,0 @@ nestedIndent: string | undefined;

@@ -40,6 +40,2 @@ export declare const enum CODE {

}
export declare const enum BODY_MODE {
HTML = 0,
PARSED_TEXT = 1
}
export interface Position {

@@ -98,3 +94,3 @@ /**

interface OpenTagEnd extends Range {
ending: OpenTagEnding;
selfClosed: boolean;
}

@@ -105,9 +101,9 @@ interface CloseTag extends Range {

}
export declare const enum OpenTagEnding {
tag = 0,
self = 1,
export declare const enum TagType {
html = 0,
text = 1,
void = 2,
code = 4
statement = 3
}
export interface Handlers {
export interface ParserOptions {
onError?(data: Ranges.Error): void;

@@ -121,3 +117,3 @@ onText?(data: Range): void;

onPlaceholder?(data: Ranges.Placeholder): void;
onTagName?(data: Ranges.TagName): void;
onTagName?(data: Ranges.TagName): TagType | void;
onTagShorthandId?(data: Ranges.Template): void;

@@ -124,0 +120,0 @@ onTagShorthandClass?(data: Ranges.Template): void;

{
"name": "htmljs-parser",
"description": "An HTML parser recognizes content and string placeholders and allows JavaScript expressions as attribute values",
"version": "3.1.0",
"version": "3.2.0",
"author": "Phillip Gates-Idem <phillip.idem@gmail.com>",

@@ -6,0 +6,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

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