htmljs-parser 3.2.1 → 3.2.2
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/README.md +343 -537
- package/dist/core/Parser.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +80 -49
- package/dist/index.mjs +79 -49
- package/dist/util/constants.d.ts +30 -2
- package/dist/util/util.d.ts +1 -1
- package/package.json +1 -1
package/dist/core/Parser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { STATE, Range, ParserOptions as Options } from "../internal";
|
|
1
|
+
import { STATE, Range, ParserOptions as Options, ErrorCode } from "../internal";
|
|
2
2
|
export interface Meta extends Range {
|
|
3
3
|
parent: Meta;
|
|
4
4
|
state: StateDefinition;
|
|
@@ -56,7 +56,7 @@ export declare class Parser {
|
|
|
56
56
|
* tags within a block are properly closed.
|
|
57
57
|
*/
|
|
58
58
|
beginHtmlBlock(delimiter: string | undefined, singleLine: boolean): void;
|
|
59
|
-
emitError(range: number | Range, code:
|
|
59
|
+
emitError(range: number | Range, code: ErrorCode, message: string): void;
|
|
60
60
|
closeTag(start: number, end: number, value: Range | undefined): void;
|
|
61
61
|
consumeWhitespaceIfBefore(str: string, start?: number): boolean;
|
|
62
62
|
getPreviousNonWhitespaceCharCode(start?: number): number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ParserOptions, type Range } from "./internal";
|
|
2
|
-
export { TagType, type ParserOptions as Handlers, type Position, type Location, type Ranges, type Range, } from "./internal";
|
|
2
|
+
export { TagType, ErrorCode, type ParserOptions as Handlers, type Position, type Location, type Ranges, type Range, } from "./internal";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new Marko parser.
|
|
5
5
|
*/
|
|
@@ -15,7 +15,7 @@ export declare function createParser(handlers: ParserOptions): {
|
|
|
15
15
|
/**
|
|
16
16
|
* Given a offset in the current source code, returns a Position object with line & character information.
|
|
17
17
|
*/
|
|
18
|
-
positionAt(
|
|
18
|
+
positionAt(offset: number): import("./internal").Position;
|
|
19
19
|
/**
|
|
20
20
|
* Given a offset range in the current source code, returns a Location object with a start & end position information.
|
|
21
21
|
*/
|
package/dist/index.js
CHANGED
|
@@ -19,12 +19,42 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/index.ts
|
|
20
20
|
var src_exports = {};
|
|
21
21
|
__export(src_exports, {
|
|
22
|
+
ErrorCode: () => ErrorCode,
|
|
22
23
|
TagType: () => TagType,
|
|
23
24
|
createParser: () => createParser
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(src_exports);
|
|
26
27
|
|
|
27
28
|
// src/util/constants.ts
|
|
29
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode3) => {
|
|
30
|
+
ErrorCode3[ErrorCode3["EXTRA_CLOSING_TAG"] = 0] = "EXTRA_CLOSING_TAG";
|
|
31
|
+
ErrorCode3[ErrorCode3["INVALID_ATTRIBUTE_ARGUMENT"] = 1] = "INVALID_ATTRIBUTE_ARGUMENT";
|
|
32
|
+
ErrorCode3[ErrorCode3["INVALID_ATTRIBUTE_NAME"] = 2] = "INVALID_ATTRIBUTE_NAME";
|
|
33
|
+
ErrorCode3[ErrorCode3["INVALID_ATTRIBUTE_VALUE"] = 3] = "INVALID_ATTRIBUTE_VALUE";
|
|
34
|
+
ErrorCode3[ErrorCode3["INVALID_CHARACTER"] = 4] = "INVALID_CHARACTER";
|
|
35
|
+
ErrorCode3[ErrorCode3["INVALID_CODE_AFTER_SEMICOLON"] = 5] = "INVALID_CODE_AFTER_SEMICOLON";
|
|
36
|
+
ErrorCode3[ErrorCode3["INVALID_EXPRESSION"] = 6] = "INVALID_EXPRESSION";
|
|
37
|
+
ErrorCode3[ErrorCode3["INVALID_INDENTATION"] = 7] = "INVALID_INDENTATION";
|
|
38
|
+
ErrorCode3[ErrorCode3["INVALID_LINE_START"] = 8] = "INVALID_LINE_START";
|
|
39
|
+
ErrorCode3[ErrorCode3["INVALID_REGULAR_EXPRESSION"] = 9] = "INVALID_REGULAR_EXPRESSION";
|
|
40
|
+
ErrorCode3[ErrorCode3["INVALID_STRING"] = 10] = "INVALID_STRING";
|
|
41
|
+
ErrorCode3[ErrorCode3["INVALID_TAG_ARGUMENT"] = 11] = "INVALID_TAG_ARGUMENT";
|
|
42
|
+
ErrorCode3[ErrorCode3["INVALID_TAG_SHORTHAND"] = 12] = "INVALID_TAG_SHORTHAND";
|
|
43
|
+
ErrorCode3[ErrorCode3["INVALID_TEMPLATE_STRING"] = 13] = "INVALID_TEMPLATE_STRING";
|
|
44
|
+
ErrorCode3[ErrorCode3["MALFORMED_CDATA"] = 14] = "MALFORMED_CDATA";
|
|
45
|
+
ErrorCode3[ErrorCode3["MALFORMED_CLOSE_TAG"] = 15] = "MALFORMED_CLOSE_TAG";
|
|
46
|
+
ErrorCode3[ErrorCode3["MALFORMED_COMMENT"] = 16] = "MALFORMED_COMMENT";
|
|
47
|
+
ErrorCode3[ErrorCode3["MALFORMED_DECLARATION"] = 17] = "MALFORMED_DECLARATION";
|
|
48
|
+
ErrorCode3[ErrorCode3["MALFORMED_DOCUMENT_TYPE"] = 18] = "MALFORMED_DOCUMENT_TYPE";
|
|
49
|
+
ErrorCode3[ErrorCode3["MALFORMED_OPEN_TAG"] = 19] = "MALFORMED_OPEN_TAG";
|
|
50
|
+
ErrorCode3[ErrorCode3["MALFORMED_PLACEHOLDER"] = 20] = "MALFORMED_PLACEHOLDER";
|
|
51
|
+
ErrorCode3[ErrorCode3["MISMATCHED_CLOSING_TAG"] = 21] = "MISMATCHED_CLOSING_TAG";
|
|
52
|
+
ErrorCode3[ErrorCode3["MISSING_END_TAG"] = 22] = "MISSING_END_TAG";
|
|
53
|
+
ErrorCode3[ErrorCode3["MISSING_TAG_VARIABLE"] = 23] = "MISSING_TAG_VARIABLE";
|
|
54
|
+
ErrorCode3[ErrorCode3["RESERVED_TAG_NAME"] = 24] = "RESERVED_TAG_NAME";
|
|
55
|
+
ErrorCode3[ErrorCode3["ROOT_TAG_ONLY"] = 25] = "ROOT_TAG_ONLY";
|
|
56
|
+
return ErrorCode3;
|
|
57
|
+
})(ErrorCode || {});
|
|
28
58
|
var TagType = /* @__PURE__ */ ((TagType2) => {
|
|
29
59
|
TagType2[TagType2["html"] = 0] = "html";
|
|
30
60
|
TagType2[TagType2["text"] = 1] = "text";
|
|
@@ -73,7 +103,7 @@ function htmlEOF() {
|
|
|
73
103
|
if (this.activeTag.concise) {
|
|
74
104
|
this.closeTag(this.pos, this.pos, void 0);
|
|
75
105
|
} else {
|
|
76
|
-
return this.emitError(this.activeTag,
|
|
106
|
+
return this.emitError(this.activeTag, 22 /* MISSING_END_TAG */, 'Missing ending "' + this.read(this.activeTag.tagName) + '" tag');
|
|
77
107
|
}
|
|
78
108
|
}
|
|
79
109
|
}
|
|
@@ -443,7 +473,7 @@ var ATTRIBUTE = {
|
|
|
443
473
|
if (this.isConcise) {
|
|
444
474
|
this.exitState();
|
|
445
475
|
} else {
|
|
446
|
-
this.emitError(attr,
|
|
476
|
+
this.emitError(attr, 19 /* MALFORMED_OPEN_TAG */, 'EOF reached while parsing attribute "' + (attr.name ? this.read(attr.name) : "default") + '" for the "' + this.read(this.activeTag.tagName) + '" tag');
|
|
447
477
|
}
|
|
448
478
|
},
|
|
449
479
|
return(child, attr) {
|
|
@@ -459,7 +489,7 @@ var ATTRIBUTE = {
|
|
|
459
489
|
}
|
|
460
490
|
case 3 /* ARGUMENT */: {
|
|
461
491
|
if (attr.args) {
|
|
462
|
-
this.emitError(child,
|
|
492
|
+
this.emitError(child, 1 /* INVALID_ATTRIBUTE_ARGUMENT */, "An attribute can only have one set of arguments");
|
|
463
493
|
return;
|
|
464
494
|
}
|
|
465
495
|
const start = child.start - 1;
|
|
@@ -506,7 +536,7 @@ var ATTRIBUTE = {
|
|
|
506
536
|
}
|
|
507
537
|
case 2 /* VALUE */: {
|
|
508
538
|
if (child.start === child.end) {
|
|
509
|
-
return this.emitError(child,
|
|
539
|
+
return this.emitError(child, 3 /* INVALID_ATTRIBUTE_VALUE */, "Missing value for attribute");
|
|
510
540
|
}
|
|
511
541
|
if (attr.spread) {
|
|
512
542
|
(_h = (_g = this.options).onAttrSpread) == null ? void 0 : _h.call(_g, {
|
|
@@ -607,7 +637,7 @@ function handleDelimitedBlockEOL(parser, newLineLength, {
|
|
|
607
637
|
parser.exitState();
|
|
608
638
|
parser.exitState();
|
|
609
639
|
} else {
|
|
610
|
-
parser.emitError(parser.pos,
|
|
640
|
+
parser.emitError(parser.pos, 4 /* INVALID_CHARACTER */, "A concise mode closing block delimiter can only be followed by whitespace.");
|
|
611
641
|
}
|
|
612
642
|
} else if (parser.lookAheadFor(indent, parser.pos + newLineLength)) {
|
|
613
643
|
parser.startText();
|
|
@@ -653,7 +683,7 @@ var CDATA = {
|
|
|
653
683
|
eol() {
|
|
654
684
|
},
|
|
655
685
|
eof(cdata) {
|
|
656
|
-
this.emitError(cdata,
|
|
686
|
+
this.emitError(cdata, 14 /* MALFORMED_CDATA */, "EOF reached while parsing CDATA");
|
|
657
687
|
},
|
|
658
688
|
return() {
|
|
659
689
|
}
|
|
@@ -692,7 +722,7 @@ var CLOSE_TAG = {
|
|
|
692
722
|
eol() {
|
|
693
723
|
},
|
|
694
724
|
eof(closeTag) {
|
|
695
|
-
this.emitError(closeTag,
|
|
725
|
+
this.emitError(closeTag, 15 /* MALFORMED_CLOSE_TAG */, "EOF reached while parsing closing tag");
|
|
696
726
|
},
|
|
697
727
|
return() {
|
|
698
728
|
}
|
|
@@ -729,7 +759,7 @@ function ensureExpectedCloseTag(parser, closeTag) {
|
|
|
729
759
|
const closeTagNameStart = closeTag.start + 2;
|
|
730
760
|
const closeTagNameEnd = closeTag.end - 1;
|
|
731
761
|
if (!activeTag) {
|
|
732
|
-
parser.emitError(closeTag,
|
|
762
|
+
parser.emitError(closeTag, 0 /* EXTRA_CLOSING_TAG */, 'The closing "' + parser.read({ start: closeTagNameStart, end: closeTagNameEnd }) + '" tag was not expected');
|
|
733
763
|
return false;
|
|
734
764
|
}
|
|
735
765
|
const closeTagNamePos = {
|
|
@@ -742,7 +772,7 @@ function ensureExpectedCloseTag(parser, closeTag) {
|
|
|
742
772
|
start: activeTag.tagName.start,
|
|
743
773
|
end: activeTag.shorthandEnd
|
|
744
774
|
})) {
|
|
745
|
-
parser.emitError(closeTag,
|
|
775
|
+
parser.emitError(closeTag, 21 /* MISMATCHED_CLOSING_TAG */, 'The closing "' + parser.read(closeTagNamePos) + '" tag does not match the corresponding opening "' + (parser.read(activeTag.tagName) || "div") + '" tag');
|
|
746
776
|
return false;
|
|
747
777
|
}
|
|
748
778
|
}
|
|
@@ -778,18 +808,18 @@ var CONCISE_HTML_CONTENT = {
|
|
|
778
808
|
parentTag = this.activeTag;
|
|
779
809
|
}
|
|
780
810
|
if (!parentTag && curIndent) {
|
|
781
|
-
this.emitError(this.pos,
|
|
811
|
+
this.emitError(this.pos, 7 /* INVALID_INDENTATION */, "Line has extra indentation at the beginning");
|
|
782
812
|
return;
|
|
783
813
|
}
|
|
784
814
|
if (parentTag) {
|
|
785
815
|
if (parentTag.type === 1 /* text */ && code !== 45 /* HTML_BLOCK_DELIMITER */) {
|
|
786
|
-
this.emitError(this.pos,
|
|
816
|
+
this.emitError(this.pos, 8 /* INVALID_LINE_START */, 'A line within a tag that only allows text content must begin with a "-" character');
|
|
787
817
|
return;
|
|
788
818
|
}
|
|
789
819
|
if (parentTag.nestedIndent === void 0) {
|
|
790
820
|
parentTag.nestedIndent = this.indent;
|
|
791
821
|
} else if (parentTag.nestedIndent !== this.indent) {
|
|
792
|
-
this.emitError(this.pos,
|
|
822
|
+
this.emitError(this.pos, 7 /* INVALID_INDENTATION */, "Line indentation does match indentation of previous line");
|
|
793
823
|
return;
|
|
794
824
|
}
|
|
795
825
|
}
|
|
@@ -811,7 +841,7 @@ var CONCISE_HTML_CONTENT = {
|
|
|
811
841
|
this.enterState(states_exports.BEGIN_DELIMITED_HTML_BLOCK);
|
|
812
842
|
this.pos--;
|
|
813
843
|
} else {
|
|
814
|
-
this.emitError(this.pos,
|
|
844
|
+
this.emitError(this.pos, 8 /* INVALID_LINE_START */, 'A line in concise mode cannot start with a single hyphen. Use "--" instead. See: https://github.com/marko-js/htmljs-parser/issues/43');
|
|
815
845
|
}
|
|
816
846
|
return;
|
|
817
847
|
case 47 /* FORWARD_SLASH */:
|
|
@@ -825,7 +855,7 @@ var CONCISE_HTML_CONTENT = {
|
|
|
825
855
|
this.pos++;
|
|
826
856
|
return;
|
|
827
857
|
default:
|
|
828
|
-
this.emitError(this.pos,
|
|
858
|
+
this.emitError(this.pos, 8 /* INVALID_LINE_START */, 'A line in concise mode cannot start with "/" unless it starts a "//" or "/*" comment');
|
|
829
859
|
return;
|
|
830
860
|
}
|
|
831
861
|
}
|
|
@@ -862,7 +892,7 @@ var CONCISE_HTML_CONTENT = {
|
|
|
862
892
|
}
|
|
863
893
|
});
|
|
864
894
|
if (!this.consumeWhitespaceOnLine(0)) {
|
|
865
|
-
this.emitError(this.pos,
|
|
895
|
+
this.emitError(this.pos, 4 /* INVALID_CHARACTER */, "In concise mode a javascript comment block can only be followed by whitespace characters and a newline.");
|
|
866
896
|
}
|
|
867
897
|
break;
|
|
868
898
|
}
|
|
@@ -896,7 +926,7 @@ var DECLARATION = {
|
|
|
896
926
|
eol() {
|
|
897
927
|
},
|
|
898
928
|
eof(declaration) {
|
|
899
|
-
this.emitError(declaration,
|
|
929
|
+
this.emitError(declaration, 17 /* MALFORMED_DECLARATION */, "EOF reached while parsing declaration");
|
|
900
930
|
},
|
|
901
931
|
return() {
|
|
902
932
|
}
|
|
@@ -947,7 +977,7 @@ var DTD = {
|
|
|
947
977
|
eol() {
|
|
948
978
|
},
|
|
949
979
|
eof(documentType) {
|
|
950
|
-
this.emitError(documentType,
|
|
980
|
+
this.emitError(documentType, 18 /* MALFORMED_DOCUMENT_TYPE */, "EOF reached while parsing document type");
|
|
951
981
|
},
|
|
952
982
|
return() {
|
|
953
983
|
}
|
|
@@ -1027,11 +1057,11 @@ var EXPRESSION = {
|
|
|
1027
1057
|
case 93 /* CLOSE_SQUARE_BRACKET */:
|
|
1028
1058
|
case 125 /* CLOSE_CURLY_BRACE */: {
|
|
1029
1059
|
if (!expression.groupStack.length) {
|
|
1030
|
-
return this.emitError(expression,
|
|
1060
|
+
return this.emitError(expression, 6 /* INVALID_EXPRESSION */, 'Mismatched group. A closing "' + String.fromCharCode(code) + '" character was found but it is not matched with a corresponding opening character.');
|
|
1031
1061
|
}
|
|
1032
1062
|
const expectedCode = expression.groupStack.pop();
|
|
1033
1063
|
if (expectedCode !== code) {
|
|
1034
|
-
return this.emitError(expression,
|
|
1064
|
+
return this.emitError(expression, 6 /* INVALID_EXPRESSION */, 'Mismatched group. A "' + String.fromCharCode(code) + '" character was found when "' + String.fromCharCode(expectedCode) + '" was expected.');
|
|
1035
1065
|
}
|
|
1036
1066
|
break;
|
|
1037
1067
|
}
|
|
@@ -1051,16 +1081,16 @@ var EXPRESSION = {
|
|
|
1051
1081
|
case states_exports.ATTRIBUTE: {
|
|
1052
1082
|
const attr = parent;
|
|
1053
1083
|
if (!attr.spread && !attr.name) {
|
|
1054
|
-
return this.emitError(expression,
|
|
1084
|
+
return this.emitError(expression, 19 /* MALFORMED_OPEN_TAG */, 'EOF reached while parsing attribute name for the "' + this.read(this.activeTag.tagName) + '" tag');
|
|
1055
1085
|
}
|
|
1056
|
-
return this.emitError(expression,
|
|
1086
|
+
return this.emitError(expression, 19 /* MALFORMED_OPEN_TAG */, `EOF reached while parsing attribute value for the ${attr.spread ? "..." : attr.name ? `"${this.read(attr.name)}"` : `"default"`} attribute`);
|
|
1057
1087
|
}
|
|
1058
1088
|
case states_exports.TAG_NAME:
|
|
1059
|
-
return this.emitError(expression,
|
|
1089
|
+
return this.emitError(expression, 19 /* MALFORMED_OPEN_TAG */, "EOF reached while parsing tag name");
|
|
1060
1090
|
case states_exports.PLACEHOLDER:
|
|
1061
|
-
return this.emitError(expression,
|
|
1091
|
+
return this.emitError(expression, 20 /* MALFORMED_PLACEHOLDER */, "EOF reached while parsing placeholder");
|
|
1062
1092
|
}
|
|
1063
|
-
return this.emitError(expression,
|
|
1093
|
+
return this.emitError(expression, 6 /* INVALID_EXPRESSION */, "EOF reached while parsing expression");
|
|
1064
1094
|
}
|
|
1065
1095
|
},
|
|
1066
1096
|
return() {
|
|
@@ -1152,7 +1182,7 @@ var HTML_COMMENT = {
|
|
|
1152
1182
|
eol() {
|
|
1153
1183
|
},
|
|
1154
1184
|
eof(comment) {
|
|
1155
|
-
this.emitError(comment,
|
|
1185
|
+
this.emitError(comment, 16 /* MALFORMED_COMMENT */, "EOF reached while parsing comment");
|
|
1156
1186
|
},
|
|
1157
1187
|
return() {
|
|
1158
1188
|
}
|
|
@@ -1317,7 +1347,7 @@ var JS_COMMENT_BLOCK = {
|
|
|
1317
1347
|
eol() {
|
|
1318
1348
|
},
|
|
1319
1349
|
eof(comment) {
|
|
1320
|
-
this.emitError(comment,
|
|
1350
|
+
this.emitError(comment, 16 /* MALFORMED_COMMENT */, "EOF reached while parsing multi-line JavaScript comment");
|
|
1321
1351
|
},
|
|
1322
1352
|
return() {
|
|
1323
1353
|
}
|
|
@@ -1440,7 +1470,7 @@ var PLACEHOLDER = {
|
|
|
1440
1470
|
},
|
|
1441
1471
|
return(child) {
|
|
1442
1472
|
if (child.start === child.end) {
|
|
1443
|
-
this.emitError(child,
|
|
1473
|
+
this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
|
|
1444
1474
|
}
|
|
1445
1475
|
this.pos++;
|
|
1446
1476
|
this.exitState();
|
|
@@ -1514,10 +1544,10 @@ var REGULAR_EXPRESSION = {
|
|
|
1514
1544
|
}
|
|
1515
1545
|
},
|
|
1516
1546
|
eol(_, regExp) {
|
|
1517
|
-
this.emitError(regExp,
|
|
1547
|
+
this.emitError(regExp, 9 /* INVALID_REGULAR_EXPRESSION */, "EOL reached while parsing regular expression");
|
|
1518
1548
|
},
|
|
1519
1549
|
eof(regExp) {
|
|
1520
|
-
this.emitError(regExp,
|
|
1550
|
+
this.emitError(regExp, 9 /* INVALID_REGULAR_EXPRESSION */, "EOF reached while parsing regular expression");
|
|
1521
1551
|
},
|
|
1522
1552
|
return() {
|
|
1523
1553
|
}
|
|
@@ -1551,7 +1581,7 @@ var STRING = {
|
|
|
1551
1581
|
eol() {
|
|
1552
1582
|
},
|
|
1553
1583
|
eof(string) {
|
|
1554
|
-
this.emitError(string,
|
|
1584
|
+
this.emitError(string, 10 /* INVALID_STRING */, "EOF reached while parsing string expression");
|
|
1555
1585
|
},
|
|
1556
1586
|
return() {
|
|
1557
1587
|
}
|
|
@@ -1579,7 +1609,7 @@ var TAG_NAME = {
|
|
|
1579
1609
|
switch (tagName.shorthandCode) {
|
|
1580
1610
|
case 35 /* NUMBER_SIGN */:
|
|
1581
1611
|
if (this.activeTag.hasShorthandId) {
|
|
1582
|
-
return this.emitError(tagName,
|
|
1612
|
+
return this.emitError(tagName, 12 /* INVALID_TAG_SHORTHAND */, "Multiple shorthand ID parts are not allowed on the same tag");
|
|
1583
1613
|
}
|
|
1584
1614
|
this.activeTag.hasShorthandId = true;
|
|
1585
1615
|
(_b = (_a = this.options).onTagShorthandId) == null ? void 0 : _b.call(_a, {
|
|
@@ -1611,10 +1641,10 @@ var TAG_NAME = {
|
|
|
1611
1641
|
tag.type = tagType;
|
|
1612
1642
|
if (tagType === 3 /* statement */) {
|
|
1613
1643
|
if (!tag.concise) {
|
|
1614
|
-
return this.emitError(tagName,
|
|
1644
|
+
return this.emitError(tagName, 24 /* RESERVED_TAG_NAME */, `The "${this.read(tagName)}" tag is reserved and cannot be used as an HTML tag.`);
|
|
1615
1645
|
}
|
|
1616
1646
|
if (tag.parentTag) {
|
|
1617
|
-
return this.emitError(tagName,
|
|
1647
|
+
return this.emitError(tagName, 25 /* ROOT_TAG_ONLY */, `"${this.read(tagName)}" can only be used at the root of the template.`);
|
|
1618
1648
|
}
|
|
1619
1649
|
this.enterState(states_exports.EXPRESSION).terminatedByEOL = true;
|
|
1620
1650
|
}
|
|
@@ -1649,12 +1679,12 @@ var TAG_NAME = {
|
|
|
1649
1679
|
if (child.terminatedByEOL)
|
|
1650
1680
|
return;
|
|
1651
1681
|
if (child.start === child.end) {
|
|
1652
|
-
this.emitError(child,
|
|
1682
|
+
this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
|
|
1653
1683
|
}
|
|
1654
1684
|
const { quasis, expressions } = tagName;
|
|
1655
1685
|
const start = child.start - 2;
|
|
1656
1686
|
const end = ++this.pos;
|
|
1657
|
-
const nextStart = end
|
|
1687
|
+
const nextStart = end;
|
|
1658
1688
|
expressions.push({
|
|
1659
1689
|
start,
|
|
1660
1690
|
end,
|
|
@@ -1697,13 +1727,13 @@ var TEMPLATE_STRING = {
|
|
|
1697
1727
|
}
|
|
1698
1728
|
},
|
|
1699
1729
|
eof(templateString) {
|
|
1700
|
-
this.emitError(templateString,
|
|
1730
|
+
this.emitError(templateString, 13 /* INVALID_TEMPLATE_STRING */, "EOF reached while parsing template string expression");
|
|
1701
1731
|
},
|
|
1702
1732
|
eol() {
|
|
1703
1733
|
},
|
|
1704
1734
|
return(child) {
|
|
1705
1735
|
if (child.start === child.end) {
|
|
1706
|
-
this.emitError(child,
|
|
1736
|
+
this.emitError(child, 20 /* MALFORMED_PLACEHOLDER */, "Invalid placeholder, the expression cannot be missing");
|
|
1707
1737
|
}
|
|
1708
1738
|
this.pos++;
|
|
1709
1739
|
}
|
|
@@ -1785,12 +1815,12 @@ var OPEN_TAG = {
|
|
|
1785
1815
|
eof(tag) {
|
|
1786
1816
|
if (this.isConcise) {
|
|
1787
1817
|
if (tag.stage === 4 /* ATTR_GROUP */) {
|
|
1788
|
-
this.emitError(tag,
|
|
1818
|
+
this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, 'EOF reached while within an attribute group (e.g. "[ ... ]").');
|
|
1789
1819
|
return;
|
|
1790
1820
|
}
|
|
1791
1821
|
this.exitState();
|
|
1792
1822
|
} else {
|
|
1793
|
-
this.emitError(tag,
|
|
1823
|
+
this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, "EOF reached while parsing open tag");
|
|
1794
1824
|
}
|
|
1795
1825
|
},
|
|
1796
1826
|
char(code, tag) {
|
|
@@ -1820,17 +1850,17 @@ var OPEN_TAG = {
|
|
|
1820
1850
|
}
|
|
1821
1851
|
break;
|
|
1822
1852
|
}
|
|
1823
|
-
this.emitError(this.pos,
|
|
1853
|
+
this.emitError(this.pos, 5 /* INVALID_CODE_AFTER_SEMICOLON */, "A semicolon indicates the end of a line. Only comments may follow it.");
|
|
1824
1854
|
}
|
|
1825
1855
|
return;
|
|
1826
1856
|
}
|
|
1827
1857
|
if (code === 45 /* HTML_BLOCK_DELIMITER */) {
|
|
1828
1858
|
if (this.lookAtCharCodeAhead(1) !== 45 /* HTML_BLOCK_DELIMITER */) {
|
|
1829
|
-
this.emitError(tag,
|
|
1859
|
+
this.emitError(tag, 19 /* MALFORMED_OPEN_TAG */, '"-" not allowed as first character of attribute name');
|
|
1830
1860
|
return;
|
|
1831
1861
|
}
|
|
1832
1862
|
if (tag.stage === 4 /* ATTR_GROUP */) {
|
|
1833
|
-
this.emitError(this.pos,
|
|
1863
|
+
this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, "Attribute group was not properly ended");
|
|
1834
1864
|
return;
|
|
1835
1865
|
}
|
|
1836
1866
|
this.exitState();
|
|
@@ -1855,14 +1885,14 @@ var OPEN_TAG = {
|
|
|
1855
1885
|
return;
|
|
1856
1886
|
} else if (code === 91 /* OPEN_SQUARE_BRACKET */) {
|
|
1857
1887
|
if (tag.stage === 4 /* ATTR_GROUP */) {
|
|
1858
|
-
this.emitError(this.pos,
|
|
1888
|
+
this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, 'Unexpected "[" character within open tag.');
|
|
1859
1889
|
return;
|
|
1860
1890
|
}
|
|
1861
1891
|
tag.stage = 4 /* ATTR_GROUP */;
|
|
1862
1892
|
return;
|
|
1863
1893
|
} else if (code === 93 /* CLOSE_SQUARE_BRACKET */) {
|
|
1864
1894
|
if (tag.stage !== 4 /* ATTR_GROUP */) {
|
|
1865
|
-
this.emitError(this.pos,
|
|
1895
|
+
this.emitError(this.pos, 19 /* MALFORMED_OPEN_TAG */, 'Unexpected "]" character within open tag.');
|
|
1866
1896
|
return;
|
|
1867
1897
|
}
|
|
1868
1898
|
tag.stage = 0 /* UNKNOWN */;
|
|
@@ -1879,7 +1909,7 @@ var OPEN_TAG = {
|
|
|
1879
1909
|
return;
|
|
1880
1910
|
}
|
|
1881
1911
|
if (code === 60 /* OPEN_ANGLE_BRACKET */) {
|
|
1882
|
-
return this.emitError(this.pos,
|
|
1912
|
+
return this.emitError(this.pos, 2 /* INVALID_ATTRIBUTE_NAME */, 'Invalid attribute name. Attribute name cannot begin with the "<" character.');
|
|
1883
1913
|
}
|
|
1884
1914
|
if (code === 47 /* FORWARD_SLASH */ && this.lookAtCharCodeAhead(1) === 42 /* ASTERISK */) {
|
|
1885
1915
|
this.enterState(states_exports.JS_COMMENT_BLOCK);
|
|
@@ -1901,7 +1931,7 @@ var OPEN_TAG = {
|
|
|
1901
1931
|
this.pos--;
|
|
1902
1932
|
} else if (code === 40 /* OPEN_PAREN */ && !tag.hasAttrs) {
|
|
1903
1933
|
if (tag.hasArgs) {
|
|
1904
|
-
this.emitError(this.pos,
|
|
1934
|
+
this.emitError(this.pos, 11 /* INVALID_TAG_ARGUMENT */, "A tag can only have one argument");
|
|
1905
1935
|
return;
|
|
1906
1936
|
}
|
|
1907
1937
|
tag.stage = 2 /* ARGUMENT */;
|
|
@@ -1937,7 +1967,7 @@ var OPEN_TAG = {
|
|
|
1937
1967
|
switch (tag.stage) {
|
|
1938
1968
|
case 1 /* VAR */: {
|
|
1939
1969
|
if (child.start === child.end) {
|
|
1940
|
-
return this.emitError(child,
|
|
1970
|
+
return this.emitError(child, 23 /* MISSING_TAG_VARIABLE */, "A slash was found that was not followed by a variable name or lhs expression");
|
|
1941
1971
|
}
|
|
1942
1972
|
(_b = (_a = this.options).onTagVar) == null ? void 0 : _b.call(_a, {
|
|
1943
1973
|
start: child.start - 1,
|
|
@@ -2001,8 +2031,8 @@ function createParser(handlers) {
|
|
|
2001
2031
|
read(range) {
|
|
2002
2032
|
return parser.read(range);
|
|
2003
2033
|
},
|
|
2004
|
-
positionAt(
|
|
2005
|
-
return parser.positionAt(
|
|
2034
|
+
positionAt(offset) {
|
|
2035
|
+
return parser.positionAt(offset);
|
|
2006
2036
|
},
|
|
2007
2037
|
locationAt(range) {
|
|
2008
2038
|
return parser.locationAt(range);
|
|
@@ -2011,6 +2041,7 @@ function createParser(handlers) {
|
|
|
2011
2041
|
}
|
|
2012
2042
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2013
2043
|
0 && (module.exports = {
|
|
2044
|
+
ErrorCode,
|
|
2014
2045
|
TagType,
|
|
2015
2046
|
createParser
|
|
2016
2047
|
});
|