Skip to content

Commit

Permalink
feat: remove ability to override parse options
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Feb 1, 2022
1 parent 6950bdc commit 149495c
Show file tree
Hide file tree
Showing 12 changed files with 3 additions and 99 deletions.
21 changes: 3 additions & 18 deletions src/core/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import {
getTagName,
} from "../internal";

export interface ParseOptions {
state: "html" | "cdata" | "parsed-text" | "static-text";
ignoreAttributes: boolean;
}

export interface Part {
pos: number;
endPos: number;
Expand Down Expand Up @@ -54,7 +49,6 @@ export class Parser {
public activePart!: Part; // The current part at the top of the part stack
public forward!: boolean;
public notifiers: ReturnType<typeof createNotifiers>;
public userIsOpenTagOnly?: (tagName: string) => boolean;
public currentOpenTag: STATE.OpenTagPart | undefined; // Used to reference the current open tag that is being parsed
public currentAttribute: STATE.AttrPart | undefined; // Used to reference the current attribute that is being parsed
public withinAttrGroup!: boolean; // Set to true if the parser is within a concise mode attribute group
Expand All @@ -68,7 +62,7 @@ export class Parser {
public endingMixedModeAtEOL?: boolean; // Used as a flag to record that the next EOL to exit HTML mode and go back to concise
public textPos!: number; // Used to buffer text that is found within the body of a tag
public text!: string; // Used to buffer text that is found within the body of a tag
public textParseMode!: ParseOptions["state"];
public textParseMode!: "html" | "cdata" | "parsed-text" | "static-text";
public blockStack!: ((
| STATE.OpenTagPart
| {
Expand All @@ -78,16 +72,9 @@ export class Parser {
}
) & { body?: BODY_MODE; nestedIndent?: string })[]; // Used to keep track of HTML tags and HTML blocks

constructor(
listeners,
options?: {
concise?: boolean;
isOpenTagOnly?: (tagName: string) => boolean;
}
) {
constructor(listeners) {
this.reset();
this.notifiers = createNotifiers(this, listeners);
this.userIsOpenTagOnly = options?.isOpenTagOnly;
}

reset() {
Expand Down Expand Up @@ -242,9 +229,7 @@ export class Parser {
* are immediately closed.
*/
isOpenTagOnly(tagName: string) {
if (!tagName) return false;
tagName = tagName.toLowerCase();
return this.userIsOpenTagOnly?.(tagName) ?? htmlTags.isOpenTagOnly(tagName);
return tagName ? htmlTags.isOpenTagOnly(tagName.toLowerCase()) : false;
}

addText(text: string) {
Expand Down
13 changes: 0 additions & 13 deletions src/states/OPEN_TAG.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { ParseOptions } from "querystring";
import {
CODE,
STATE,
Expand Down Expand Up @@ -30,7 +29,6 @@ export interface OpenTagPart extends Part {
attributes: STATE.AttrPart[];
indent: string;
nestedIndent?: string;
parseOptions?: Partial<ParseOptions> & Record<string, unknown>;
}

export const OPEN_TAG: StateDefinition<OpenTagPart> = {
Expand Down Expand Up @@ -61,19 +59,8 @@ export const OPEN_TAG: StateDefinition<OpenTagPart> = {

exit(tag) {
const tagName = tag.tagName;
const attributes = tag.attributes;
const parseOptions = tag.parseOptions;
const selfClosed = tag.selfClosed;

const ignoreAttributes =
parseOptions && parseOptions.ignoreAttributes === true;

if (ignoreAttributes) {
attributes.length = 0;
}

const openTagOnly = (tag.openTagOnly = this.isOpenTagOnly(tagName.value));

const origState = this.state;
this.notifiers.notifyOpenTag(tag);

Expand Down
21 changes: 0 additions & 21 deletions src/util/notify-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ export function createNotifiers(parser: Parser, listeners) {
concise: tagInfo.concise,
shorthandId: tagInfo.shorthandId,
shorthandClassNames: tagInfo.shorthandClassNames,
setParseOptions(parseOptions) {
if (parseOptions) {
tagInfo.parseOptions = parseOptions;
}
},
};

eventFunc.call(parser, event, parser);
Expand Down Expand Up @@ -136,22 +131,6 @@ export function createNotifiers(parser: Parser, listeners) {
method: attr.method,
bound: attr.bound,
})),
setParseOptions(parseOptions) {
if (!parseOptions) {
return;
}
const newState = parseOptions.state;

if (newState) {
if (newState === "parsed-text") {
parser.enterParsedTextContentState();
} else if (newState === "static-text") {
parser.enterStaticTextContentState();
}
}

tagInfo.parseOptions = parseOptions;
},
};

eventFunc.call(parser, event, parser);
Expand Down
7 changes: 0 additions & 7 deletions test/autotest/commas-relax/test.js

This file was deleted.

2 changes: 0 additions & 2 deletions test/autotest/ignoreAttributes/expected.html

This file was deleted.

1 change: 0 additions & 1 deletion test/autotest/ignoreAttributes/input.htmljs

This file was deleted.

7 changes: 0 additions & 7 deletions test/autotest/ignoreAttributes/test.js

This file was deleted.

5 changes: 0 additions & 5 deletions test/autotest/mixed-open-tag-only/expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@
text:"\n"
<img src=("marko2.png") OPEN_ONLY>
</img>
<foo-img src=("marko3.png") OPEN_ONLY>
</foo-img>
<FOO-IMG src=("marko4.png") OPEN_ONLY>
</FOO-IMG>
text:"\n"
<div class=("foo")>
</div>
2 changes: 0 additions & 2 deletions test/autotest/mixed-open-tag-only/input.htmljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var colors=['red', 'green', 'blue']
<img src="marko.png">
img src="marko2.png"
foo-img src="marko3.png"
<FOO-IMG src="marko4.png">
div class="foo"
10 changes: 0 additions & 10 deletions test/autotest/open-tag-only-custom/expected.html

This file was deleted.

4 changes: 0 additions & 4 deletions test/autotest/open-tag-only-custom/input.htmljs

This file was deleted.

9 changes: 0 additions & 9 deletions test/autotest/open-tag-only-custom/test.js

This file was deleted.

0 comments on commit 149495c

Please sign in to comment.