htmljs-parser 5.0.2 → 5.1.0
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/core/Parser.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +40 -26
- package/dist/index.mjs +36 -25
- package/dist/util/util.d.ts +13 -3
- package/package.json +1 -1
package/dist/core/Parser.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class Parser {
|
|
|
32
32
|
lines: undefined | number[];
|
|
33
33
|
constructor(options: Options);
|
|
34
34
|
read(range: Range): string;
|
|
35
|
-
positionAt(
|
|
35
|
+
positionAt(offset: number): import("../internal").Position;
|
|
36
36
|
locationAt(range: Range): import("../internal").Location;
|
|
37
37
|
enterState<P extends Meta>(state: StateDefinition<P>): P;
|
|
38
38
|
exitState(): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ParserOptions, type Range } from "./internal";
|
|
2
|
-
export { TagType, ErrorCode, type ParserOptions as Handlers, type Position, type Location, type Ranges, type Range, } from "./internal";
|
|
2
|
+
export { TagType, ErrorCode, getLines, getLocation, getPosition, 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
|
*/
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,10 @@ var src_exports = {};
|
|
|
21
21
|
__export(src_exports, {
|
|
22
22
|
ErrorCode: () => ErrorCode,
|
|
23
23
|
TagType: () => TagType,
|
|
24
|
-
createParser: () => createParser
|
|
24
|
+
createParser: () => createParser,
|
|
25
|
+
getLines: () => getLines,
|
|
26
|
+
getLocation: () => getLocation,
|
|
27
|
+
getPosition: () => getPosition
|
|
25
28
|
});
|
|
26
29
|
module.exports = __toCommonJS(src_exports);
|
|
27
30
|
|
|
@@ -67,26 +70,13 @@ var TagType = /* @__PURE__ */ ((TagType2) => {
|
|
|
67
70
|
function isWhitespaceCode(code) {
|
|
68
71
|
return code <= 32 /* SPACE */;
|
|
69
72
|
}
|
|
70
|
-
function
|
|
71
|
-
const start =
|
|
72
|
-
const end =
|
|
73
|
+
function getLocation(lines, startOffset, endOffset) {
|
|
74
|
+
const start = getPosition(lines, startOffset);
|
|
75
|
+
const end = startOffset === endOffset ? start : getPosAfterLine(lines, start.line, endOffset);
|
|
73
76
|
return { start, end };
|
|
74
77
|
}
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
let line = startLine;
|
|
78
|
-
while (line < max) {
|
|
79
|
-
const mid = 1 + line + max >>> 1;
|
|
80
|
-
if (lines[mid] <= index) {
|
|
81
|
-
line = mid;
|
|
82
|
-
} else {
|
|
83
|
-
max = mid - 1;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
line,
|
|
88
|
-
character: index - lines[line]
|
|
89
|
-
};
|
|
78
|
+
function getPosition(lines, offset) {
|
|
79
|
+
return getPosAfterLine(lines, 0, offset);
|
|
90
80
|
}
|
|
91
81
|
function getLines(src) {
|
|
92
82
|
const lines = [0];
|
|
@@ -107,6 +97,22 @@ function htmlEOF() {
|
|
|
107
97
|
}
|
|
108
98
|
}
|
|
109
99
|
}
|
|
100
|
+
function getPosAfterLine(lines, startLine, index) {
|
|
101
|
+
let max = lines.length - 1;
|
|
102
|
+
let line = startLine;
|
|
103
|
+
while (line < max) {
|
|
104
|
+
const mid = 1 + line + max >>> 1;
|
|
105
|
+
if (lines[mid] <= index) {
|
|
106
|
+
line = mid;
|
|
107
|
+
} else {
|
|
108
|
+
max = mid - 1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
line,
|
|
113
|
+
character: index - lines[line]
|
|
114
|
+
};
|
|
115
|
+
}
|
|
110
116
|
|
|
111
117
|
// src/core/Parser.ts
|
|
112
118
|
var Parser = class {
|
|
@@ -131,11 +137,11 @@ var Parser = class {
|
|
|
131
137
|
read(range) {
|
|
132
138
|
return this.data.slice(range.start, range.end);
|
|
133
139
|
}
|
|
134
|
-
positionAt(
|
|
135
|
-
return
|
|
140
|
+
positionAt(offset) {
|
|
141
|
+
return getPosition(this.lines || (this.lines = getLines(this.data)), offset);
|
|
136
142
|
}
|
|
137
143
|
locationAt(range) {
|
|
138
|
-
return
|
|
144
|
+
return getLocation(this.lines || (this.lines = getLines(this.data)), range.start, range.end);
|
|
139
145
|
}
|
|
140
146
|
enterState(state) {
|
|
141
147
|
this.activeState = state;
|
|
@@ -1042,7 +1048,10 @@ var EXPRESSION = {
|
|
|
1042
1048
|
this.pos++;
|
|
1043
1049
|
break;
|
|
1044
1050
|
default: {
|
|
1045
|
-
if (
|
|
1051
|
+
if (canCharCodeBeFollowedByDivision(this.getPreviousNonWhitespaceCharCode())) {
|
|
1052
|
+
this.pos++;
|
|
1053
|
+
this.consumeWhitespace();
|
|
1054
|
+
} else {
|
|
1046
1055
|
this.enterState(states_exports.REGULAR_EXPRESSION);
|
|
1047
1056
|
}
|
|
1048
1057
|
break;
|
|
@@ -1103,9 +1112,9 @@ var EXPRESSION = {
|
|
|
1103
1112
|
};
|
|
1104
1113
|
function buildPattern(type) {
|
|
1105
1114
|
const space = type === 1 /* CONCISE_ATTRS */ ? "[ \\t]" : "\\s";
|
|
1106
|
-
const binary = `(?:[!~*%&^|?<]+=*)+|:+(?!=)|[>/+=-]+=|=>|(?<!\\+)[ \\t]*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)-${type === 1 /* CONCISE_ATTRS */ ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(
|
|
1115
|
+
const binary = `(?:[!~*%&^|?<]+=*)+|:+(?!=)|[>/+=-]+=|=>|(?<!\\+)[ \\t]*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)-${type === 1 /* CONCISE_ATTRS */ ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<!\\.)\\.(?!\\.)|>${type === 0 /* HTML_ATTRS */ ? "{2,}" : "+"}|[ \\t]+(?:in(?:stanceof)?|as|extends)(?=[ \\t]+[^=/,;:>])`;
|
|
1107
1116
|
const unary = "\\b(?<![.]\\s*)(?:a(?:sync|wait)|keyof|class|function|new|typeof|void)\\b";
|
|
1108
|
-
const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(])`;
|
|
1117
|
+
const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(]|/[^>])`;
|
|
1109
1118
|
const lookBehindPattern = `(?<=${unary}|${binary})`;
|
|
1110
1119
|
return new RegExp(`${lookAheadPattern}|${lookBehindPattern}`, "ym");
|
|
1111
1120
|
}
|
|
@@ -1807,6 +1816,7 @@ var CONCISE_TAG_VAR_TERMINATORS = [
|
|
|
1807
1816
|
40 /* OPEN_PAREN */,
|
|
1808
1817
|
124 /* PIPE */,
|
|
1809
1818
|
61 /* EQUAL */,
|
|
1819
|
+
44 /* COMMA */,
|
|
1810
1820
|
[58 /* COLON */, 61 /* EQUAL */]
|
|
1811
1821
|
];
|
|
1812
1822
|
var HTML_TAG_VAR_TERMINATORS = [
|
|
@@ -1814,6 +1824,7 @@ var HTML_TAG_VAR_TERMINATORS = [
|
|
|
1814
1824
|
40 /* OPEN_PAREN */,
|
|
1815
1825
|
124 /* PIPE */,
|
|
1816
1826
|
61 /* EQUAL */,
|
|
1827
|
+
44 /* COMMA */,
|
|
1817
1828
|
[58 /* COLON */, 61 /* EQUAL */],
|
|
1818
1829
|
[47 /* FORWARD_SLASH */, 62 /* CLOSE_ANGLE_BRACKET */]
|
|
1819
1830
|
];
|
|
@@ -2114,5 +2125,8 @@ function createParser(handlers) {
|
|
|
2114
2125
|
0 && (module.exports = {
|
|
2115
2126
|
ErrorCode,
|
|
2116
2127
|
TagType,
|
|
2117
|
-
createParser
|
|
2128
|
+
createParser,
|
|
2129
|
+
getLines,
|
|
2130
|
+
getLocation,
|
|
2131
|
+
getPosition
|
|
2118
2132
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -46,26 +46,13 @@ var TagType = /* @__PURE__ */ ((TagType2) => {
|
|
|
46
46
|
function isWhitespaceCode(code) {
|
|
47
47
|
return code <= 32 /* SPACE */;
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
const start =
|
|
51
|
-
const end =
|
|
49
|
+
function getLocation(lines, startOffset, endOffset) {
|
|
50
|
+
const start = getPosition(lines, startOffset);
|
|
51
|
+
const end = startOffset === endOffset ? start : getPosAfterLine(lines, start.line, endOffset);
|
|
52
52
|
return { start, end };
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
let line = startLine;
|
|
57
|
-
while (line < max) {
|
|
58
|
-
const mid = 1 + line + max >>> 1;
|
|
59
|
-
if (lines[mid] <= index) {
|
|
60
|
-
line = mid;
|
|
61
|
-
} else {
|
|
62
|
-
max = mid - 1;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
line,
|
|
67
|
-
character: index - lines[line]
|
|
68
|
-
};
|
|
54
|
+
function getPosition(lines, offset) {
|
|
55
|
+
return getPosAfterLine(lines, 0, offset);
|
|
69
56
|
}
|
|
70
57
|
function getLines(src) {
|
|
71
58
|
const lines = [0];
|
|
@@ -86,6 +73,22 @@ function htmlEOF() {
|
|
|
86
73
|
}
|
|
87
74
|
}
|
|
88
75
|
}
|
|
76
|
+
function getPosAfterLine(lines, startLine, index) {
|
|
77
|
+
let max = lines.length - 1;
|
|
78
|
+
let line = startLine;
|
|
79
|
+
while (line < max) {
|
|
80
|
+
const mid = 1 + line + max >>> 1;
|
|
81
|
+
if (lines[mid] <= index) {
|
|
82
|
+
line = mid;
|
|
83
|
+
} else {
|
|
84
|
+
max = mid - 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
line,
|
|
89
|
+
character: index - lines[line]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
89
92
|
|
|
90
93
|
// src/core/Parser.ts
|
|
91
94
|
var Parser = class {
|
|
@@ -110,11 +113,11 @@ var Parser = class {
|
|
|
110
113
|
read(range) {
|
|
111
114
|
return this.data.slice(range.start, range.end);
|
|
112
115
|
}
|
|
113
|
-
positionAt(
|
|
114
|
-
return
|
|
116
|
+
positionAt(offset) {
|
|
117
|
+
return getPosition(this.lines || (this.lines = getLines(this.data)), offset);
|
|
115
118
|
}
|
|
116
119
|
locationAt(range) {
|
|
117
|
-
return
|
|
120
|
+
return getLocation(this.lines || (this.lines = getLines(this.data)), range.start, range.end);
|
|
118
121
|
}
|
|
119
122
|
enterState(state) {
|
|
120
123
|
this.activeState = state;
|
|
@@ -1021,7 +1024,10 @@ var EXPRESSION = {
|
|
|
1021
1024
|
this.pos++;
|
|
1022
1025
|
break;
|
|
1023
1026
|
default: {
|
|
1024
|
-
if (
|
|
1027
|
+
if (canCharCodeBeFollowedByDivision(this.getPreviousNonWhitespaceCharCode())) {
|
|
1028
|
+
this.pos++;
|
|
1029
|
+
this.consumeWhitespace();
|
|
1030
|
+
} else {
|
|
1025
1031
|
this.enterState(states_exports.REGULAR_EXPRESSION);
|
|
1026
1032
|
}
|
|
1027
1033
|
break;
|
|
@@ -1082,9 +1088,9 @@ var EXPRESSION = {
|
|
|
1082
1088
|
};
|
|
1083
1089
|
function buildPattern(type) {
|
|
1084
1090
|
const space = type === 1 /* CONCISE_ATTRS */ ? "[ \\t]" : "\\s";
|
|
1085
|
-
const binary = `(?:[!~*%&^|?<]+=*)+|:+(?!=)|[>/+=-]+=|=>|(?<!\\+)[ \\t]*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)-${type === 1 /* CONCISE_ATTRS */ ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(
|
|
1091
|
+
const binary = `(?:[!~*%&^|?<]+=*)+|:+(?!=)|[>/+=-]+=|=>|(?<!\\+)[ \\t]*\\+(?:\\s*\\+\\s*\\+)*\\s*(?!\\+)|(?<!-)-${type === 1 /* CONCISE_ATTRS */ ? "" : "(?:\\s*-\\s*-)*\\s*"}(?!-)|(?<!\\.)\\.(?!\\.)|>${type === 0 /* HTML_ATTRS */ ? "{2,}" : "+"}|[ \\t]+(?:in(?:stanceof)?|as|extends)(?=[ \\t]+[^=/,;:>])`;
|
|
1086
1092
|
const unary = "\\b(?<![.]\\s*)(?:a(?:sync|wait)|keyof|class|function|new|typeof|void)\\b";
|
|
1087
|
-
const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(])`;
|
|
1093
|
+
const lookAheadPattern = `${space}*(?:${binary})\\s*|${space}+(?=[{(]|/[^>])`;
|
|
1088
1094
|
const lookBehindPattern = `(?<=${unary}|${binary})`;
|
|
1089
1095
|
return new RegExp(`${lookAheadPattern}|${lookBehindPattern}`, "ym");
|
|
1090
1096
|
}
|
|
@@ -1786,6 +1792,7 @@ var CONCISE_TAG_VAR_TERMINATORS = [
|
|
|
1786
1792
|
40 /* OPEN_PAREN */,
|
|
1787
1793
|
124 /* PIPE */,
|
|
1788
1794
|
61 /* EQUAL */,
|
|
1795
|
+
44 /* COMMA */,
|
|
1789
1796
|
[58 /* COLON */, 61 /* EQUAL */]
|
|
1790
1797
|
];
|
|
1791
1798
|
var HTML_TAG_VAR_TERMINATORS = [
|
|
@@ -1793,6 +1800,7 @@ var HTML_TAG_VAR_TERMINATORS = [
|
|
|
1793
1800
|
40 /* OPEN_PAREN */,
|
|
1794
1801
|
124 /* PIPE */,
|
|
1795
1802
|
61 /* EQUAL */,
|
|
1803
|
+
44 /* COMMA */,
|
|
1796
1804
|
[58 /* COLON */, 61 /* EQUAL */],
|
|
1797
1805
|
[47 /* FORWARD_SLASH */, 62 /* CLOSE_ANGLE_BRACKET */]
|
|
1798
1806
|
];
|
|
@@ -2092,5 +2100,8 @@ function createParser(handlers) {
|
|
|
2092
2100
|
export {
|
|
2093
2101
|
ErrorCode,
|
|
2094
2102
|
TagType,
|
|
2095
|
-
createParser
|
|
2103
|
+
createParser,
|
|
2104
|
+
getLines,
|
|
2105
|
+
getLocation,
|
|
2106
|
+
getPosition
|
|
2096
2107
|
};
|
package/dist/util/util.d.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { type Parser } from "../internal";
|
|
2
|
-
import { Location, Position
|
|
2
|
+
import { Location, Position } from "./constants";
|
|
3
3
|
export declare function isWhitespaceCode(code: number): boolean;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Given a source code line offsets, a start offset and an end offset, returns a Location object with line & character information for the start and end offsets.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getLocation(lines: number[], startOffset: number, endOffset: number): Location;
|
|
8
|
+
/**
|
|
9
|
+
* Given a source code line offsets and an offset, returns a Position object with line & character information.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getPosition(lines: number[], offset: number): Position;
|
|
12
|
+
/**
|
|
13
|
+
* Scan through some source code and generate an array of offsets for each newline.
|
|
14
|
+
* Useful for generating line/column information for source code.
|
|
15
|
+
*/
|
|
6
16
|
export declare function getLines(src: string): number[];
|
|
7
17
|
export declare function htmlEOF(this: Parser): void;
|
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": "5.0
|
|
4
|
+
"version": "5.1.0",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@changesets/changelog-github": "^0.4.4",
|
|
7
7
|
"@changesets/cli": "^2.22.0",
|