htmljs-parser 3.3.3 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +22 -10
- package/dist/index.mjs +22 -10
- package/dist/states/OPEN_TAG.d.ts +1 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -363,6 +363,7 @@ __export(states_exports, {
|
|
|
363
363
|
REGULAR_EXPRESSION: () => REGULAR_EXPRESSION,
|
|
364
364
|
STRING: () => STRING,
|
|
365
365
|
TAG_NAME: () => TAG_NAME,
|
|
366
|
+
TAG_STAGE: () => TAG_STAGE,
|
|
366
367
|
TEMPLATE_STRING: () => TEMPLATE_STRING,
|
|
367
368
|
checkForCDATA: () => checkForCDATA,
|
|
368
369
|
checkForClosingTag: () => checkForClosingTag,
|
|
@@ -984,8 +985,9 @@ var DTD = {
|
|
|
984
985
|
};
|
|
985
986
|
|
|
986
987
|
// src/states/EXPRESSION.ts
|
|
987
|
-
var
|
|
988
|
-
var
|
|
988
|
+
var htmlAttrsPattern = buildPattern(0 /* HTML_ATTRS */);
|
|
989
|
+
var conciseAttrsPattern = buildPattern(1 /* CONCISE_ATTRS */);
|
|
990
|
+
var conciseAttrsGroupPattern = buildPattern(2 /* CONCISE_ATTRS_GROUP */);
|
|
989
991
|
var EXPRESSION = {
|
|
990
992
|
name: "EXPRESSION",
|
|
991
993
|
enter(parent, start) {
|
|
@@ -1068,7 +1070,7 @@ var EXPRESSION = {
|
|
|
1068
1070
|
}
|
|
1069
1071
|
},
|
|
1070
1072
|
eol(_, expression) {
|
|
1071
|
-
if (!expression.groupStack.length && (expression.
|
|
1073
|
+
if (!expression.groupStack.length && (expression.terminatedByEOL || expression.terminatedByWhitespace) && !checkForOperators(this, expression)) {
|
|
1072
1074
|
this.exitState();
|
|
1073
1075
|
}
|
|
1074
1076
|
},
|
|
@@ -1096,28 +1098,30 @@ var EXPRESSION = {
|
|
|
1096
1098
|
return() {
|
|
1097
1099
|
}
|
|
1098
1100
|
};
|
|
1099
|
-
function
|
|
1100
|
-
const
|
|
1101
|
-
const
|
|
1102
|
-
const
|
|
1101
|
+
function buildPattern(type) {
|
|
1102
|
+
const space = type === 1 /* CONCISE_ATTRS */ ? "[ \\t]" : "\\s";
|
|
1103
|
+
const binary = `(?:[!~*%&^|?<]+=*)+|:+(?!=)|[>/+=-]+=|=>|(?<!\\+)[ \\t]*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)-${type === 1 /* CONCISE_ATTRS */ ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<![/*])/(?![/*${type === 0 /* HTML_ATTRS */ ? ">" : ""}])|(?<!\\.)\\.(?!\\.)|>${type === 0 /* HTML_ATTRS */ ? "{2,}" : "+"}|[ \\t]+(?:in(?:stanceof)?|as|extends)(?=[ \\t]+[^=/,;:>])`;
|
|
1104
|
+
const unary = "\\b(?<![.]\\s*)(?:a(?:sync|wait)|keyof|class|function|new|typeof|void)\\b";
|
|
1105
|
+
const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(])`;
|
|
1103
1106
|
const lookBehindPattern = `(?<=${unary}|${binary})`;
|
|
1104
1107
|
return new RegExp(`${lookAheadPattern}|${lookBehindPattern}`, "ym");
|
|
1105
1108
|
}
|
|
1106
1109
|
function checkForOperators(parser, expression) {
|
|
1110
|
+
var _a;
|
|
1107
1111
|
if (expression.skipOperators) {
|
|
1108
1112
|
return false;
|
|
1109
1113
|
}
|
|
1110
|
-
const pattern = parser.isConcise
|
|
1114
|
+
const pattern = parser.isConcise ? ((_a = parser.activeTag) == null ? void 0 : _a.stage) === states_exports.TAG_STAGE.ATTR_GROUP ? conciseAttrsGroupPattern : conciseAttrsPattern : expression.terminatedByEOL ? conciseAttrsPattern : htmlAttrsPattern;
|
|
1111
1115
|
pattern.lastIndex = parser.pos;
|
|
1112
1116
|
const matches = pattern.exec(parser.data);
|
|
1113
1117
|
if (matches) {
|
|
1114
1118
|
const [match] = matches;
|
|
1115
1119
|
if (match.length === 0) {
|
|
1116
1120
|
parser.consumeWhitespace();
|
|
1117
|
-
parser.pos--;
|
|
1118
1121
|
} else {
|
|
1119
|
-
parser.pos += match.length
|
|
1122
|
+
parser.pos += match.length;
|
|
1120
1123
|
}
|
|
1124
|
+
parser.forward = 0;
|
|
1121
1125
|
} else {
|
|
1122
1126
|
return false;
|
|
1123
1127
|
}
|
|
@@ -1740,6 +1744,14 @@ var TEMPLATE_STRING = {
|
|
|
1740
1744
|
};
|
|
1741
1745
|
|
|
1742
1746
|
// src/states/OPEN_TAG.ts
|
|
1747
|
+
var TAG_STAGE = /* @__PURE__ */ ((TAG_STAGE2) => {
|
|
1748
|
+
TAG_STAGE2[TAG_STAGE2["UNKNOWN"] = 0] = "UNKNOWN";
|
|
1749
|
+
TAG_STAGE2[TAG_STAGE2["VAR"] = 1] = "VAR";
|
|
1750
|
+
TAG_STAGE2[TAG_STAGE2["ARGUMENT"] = 2] = "ARGUMENT";
|
|
1751
|
+
TAG_STAGE2[TAG_STAGE2["PARAMS"] = 3] = "PARAMS";
|
|
1752
|
+
TAG_STAGE2[TAG_STAGE2["ATTR_GROUP"] = 4] = "ATTR_GROUP";
|
|
1753
|
+
return TAG_STAGE2;
|
|
1754
|
+
})(TAG_STAGE || {});
|
|
1743
1755
|
var CONCISE_TAG_VAR_TERMINATORS = [
|
|
1744
1756
|
59 /* SEMICOLON */,
|
|
1745
1757
|
40 /* OPEN_PAREN */,
|
package/dist/index.mjs
CHANGED
|
@@ -342,6 +342,7 @@ __export(states_exports, {
|
|
|
342
342
|
REGULAR_EXPRESSION: () => REGULAR_EXPRESSION,
|
|
343
343
|
STRING: () => STRING,
|
|
344
344
|
TAG_NAME: () => TAG_NAME,
|
|
345
|
+
TAG_STAGE: () => TAG_STAGE,
|
|
345
346
|
TEMPLATE_STRING: () => TEMPLATE_STRING,
|
|
346
347
|
checkForCDATA: () => checkForCDATA,
|
|
347
348
|
checkForClosingTag: () => checkForClosingTag,
|
|
@@ -963,8 +964,9 @@ var DTD = {
|
|
|
963
964
|
};
|
|
964
965
|
|
|
965
966
|
// src/states/EXPRESSION.ts
|
|
966
|
-
var
|
|
967
|
-
var
|
|
967
|
+
var htmlAttrsPattern = buildPattern(0 /* HTML_ATTRS */);
|
|
968
|
+
var conciseAttrsPattern = buildPattern(1 /* CONCISE_ATTRS */);
|
|
969
|
+
var conciseAttrsGroupPattern = buildPattern(2 /* CONCISE_ATTRS_GROUP */);
|
|
968
970
|
var EXPRESSION = {
|
|
969
971
|
name: "EXPRESSION",
|
|
970
972
|
enter(parent, start) {
|
|
@@ -1047,7 +1049,7 @@ var EXPRESSION = {
|
|
|
1047
1049
|
}
|
|
1048
1050
|
},
|
|
1049
1051
|
eol(_, expression) {
|
|
1050
|
-
if (!expression.groupStack.length && (expression.
|
|
1052
|
+
if (!expression.groupStack.length && (expression.terminatedByEOL || expression.terminatedByWhitespace) && !checkForOperators(this, expression)) {
|
|
1051
1053
|
this.exitState();
|
|
1052
1054
|
}
|
|
1053
1055
|
},
|
|
@@ -1075,28 +1077,30 @@ var EXPRESSION = {
|
|
|
1075
1077
|
return() {
|
|
1076
1078
|
}
|
|
1077
1079
|
};
|
|
1078
|
-
function
|
|
1079
|
-
const
|
|
1080
|
-
const
|
|
1081
|
-
const
|
|
1080
|
+
function buildPattern(type) {
|
|
1081
|
+
const space = type === 1 /* CONCISE_ATTRS */ ? "[ \\t]" : "\\s";
|
|
1082
|
+
const binary = `(?:[!~*%&^|?<]+=*)+|:+(?!=)|[>/+=-]+=|=>|(?<!\\+)[ \\t]*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)-${type === 1 /* CONCISE_ATTRS */ ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<![/*])/(?![/*${type === 0 /* HTML_ATTRS */ ? ">" : ""}])|(?<!\\.)\\.(?!\\.)|>${type === 0 /* HTML_ATTRS */ ? "{2,}" : "+"}|[ \\t]+(?:in(?:stanceof)?|as|extends)(?=[ \\t]+[^=/,;:>])`;
|
|
1083
|
+
const unary = "\\b(?<![.]\\s*)(?:a(?:sync|wait)|keyof|class|function|new|typeof|void)\\b";
|
|
1084
|
+
const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(])`;
|
|
1082
1085
|
const lookBehindPattern = `(?<=${unary}|${binary})`;
|
|
1083
1086
|
return new RegExp(`${lookAheadPattern}|${lookBehindPattern}`, "ym");
|
|
1084
1087
|
}
|
|
1085
1088
|
function checkForOperators(parser, expression) {
|
|
1089
|
+
var _a;
|
|
1086
1090
|
if (expression.skipOperators) {
|
|
1087
1091
|
return false;
|
|
1088
1092
|
}
|
|
1089
|
-
const pattern = parser.isConcise
|
|
1093
|
+
const pattern = parser.isConcise ? ((_a = parser.activeTag) == null ? void 0 : _a.stage) === states_exports.TAG_STAGE.ATTR_GROUP ? conciseAttrsGroupPattern : conciseAttrsPattern : expression.terminatedByEOL ? conciseAttrsPattern : htmlAttrsPattern;
|
|
1090
1094
|
pattern.lastIndex = parser.pos;
|
|
1091
1095
|
const matches = pattern.exec(parser.data);
|
|
1092
1096
|
if (matches) {
|
|
1093
1097
|
const [match] = matches;
|
|
1094
1098
|
if (match.length === 0) {
|
|
1095
1099
|
parser.consumeWhitespace();
|
|
1096
|
-
parser.pos--;
|
|
1097
1100
|
} else {
|
|
1098
|
-
parser.pos += match.length
|
|
1101
|
+
parser.pos += match.length;
|
|
1099
1102
|
}
|
|
1103
|
+
parser.forward = 0;
|
|
1100
1104
|
} else {
|
|
1101
1105
|
return false;
|
|
1102
1106
|
}
|
|
@@ -1719,6 +1723,14 @@ var TEMPLATE_STRING = {
|
|
|
1719
1723
|
};
|
|
1720
1724
|
|
|
1721
1725
|
// src/states/OPEN_TAG.ts
|
|
1726
|
+
var TAG_STAGE = /* @__PURE__ */ ((TAG_STAGE2) => {
|
|
1727
|
+
TAG_STAGE2[TAG_STAGE2["UNKNOWN"] = 0] = "UNKNOWN";
|
|
1728
|
+
TAG_STAGE2[TAG_STAGE2["VAR"] = 1] = "VAR";
|
|
1729
|
+
TAG_STAGE2[TAG_STAGE2["ARGUMENT"] = 2] = "ARGUMENT";
|
|
1730
|
+
TAG_STAGE2[TAG_STAGE2["PARAMS"] = 3] = "PARAMS";
|
|
1731
|
+
TAG_STAGE2[TAG_STAGE2["ATTR_GROUP"] = 4] = "ATTR_GROUP";
|
|
1732
|
+
return TAG_STAGE2;
|
|
1733
|
+
})(TAG_STAGE || {});
|
|
1722
1734
|
var CONCISE_TAG_VAR_TERMINATORS = [
|
|
1723
1735
|
59 /* SEMICOLON */,
|
|
1724
1736
|
40 /* OPEN_PAREN */,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StateDefinition, Ranges, Meta, TagType } from "../internal";
|
|
2
|
-
declare const enum TAG_STAGE {
|
|
2
|
+
export declare const enum TAG_STAGE {
|
|
3
3
|
UNKNOWN = 0,
|
|
4
4
|
VAR = 1,
|
|
5
5
|
ARGUMENT = 2,
|
|
@@ -22,4 +22,3 @@ export interface OpenTagMeta extends Meta {
|
|
|
22
22
|
parentTag: OpenTagMeta | undefined;
|
|
23
23
|
}
|
|
24
24
|
export declare const OPEN_TAG: StateDefinition<OpenTagMeta>;
|
|
25
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "htmljs-parser",
|
|
3
3
|
"description": "An HTML parser recognizes content and string placeholders and allows JavaScript expressions as attribute values",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.4",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@changesets/changelog-github": "^0.4.4",
|
|
7
7
|
"@changesets/cli": "^2.22.0",
|