@markuplint/astro-parser 3.3.1 → 3.5.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/lib/astro-parser.d.ts +2 -2
- package/lib/attr-tokenizer.js +12 -10
- package/lib/index.d.ts +1 -1
- package/lib/parse.js +29 -8
- package/package.json +5 -5
package/lib/astro-parser.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type ASTNode = TemplateNode;
|
|
|
5
5
|
export type ASTStyleNode = Style;
|
|
6
6
|
export type ASTAttribute = Attribute;
|
|
7
7
|
export type AstroAST = {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
html?: ASTNode;
|
|
9
|
+
style?: ASTStyleNode[];
|
|
10
10
|
};
|
|
11
11
|
export declare function astroParse(code: string): AstroAST | AstroCompileError;
|
package/lib/attr-tokenizer.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.attrTokenizer = void 0;
|
|
4
4
|
const parser_utils_1 = require("@markuplint/parser-utils");
|
|
5
|
-
function attrTokenizer(
|
|
6
|
-
|
|
5
|
+
function attrTokenizer(
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
7
|
+
attr, rawHtml, codeOffset) {
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
7
9
|
const { raw, startOffset } = (0, parser_utils_1.sliceFragment)(rawHtml, attr.start + codeOffset, attr.end + codeOffset);
|
|
8
10
|
const isDynamicValue = ((_b = (_a = attr.value) === null || _a === void 0 ? void 0 : _a.some) === null || _b === void 0 ? void 0 : _b.call(_a, v => {
|
|
9
11
|
// @ts-ignore
|
|
@@ -28,21 +30,21 @@ function attrTokenizer(attr, rawHtml, codeOffset) {
|
|
|
28
30
|
rawValueStart = name.endOffset;
|
|
29
31
|
}
|
|
30
32
|
else if (isDynamicValue) {
|
|
31
|
-
rawValue = attr.value[0].expression.codeChunks.join('');
|
|
32
|
-
rawValueStart = attr.value[0].expression.start;
|
|
33
|
+
rawValue = (_d = (_c = attr.value[0]) === null || _c === void 0 ? void 0 : _c.expression.codeChunks.join('')) !== null && _d !== void 0 ? _d : '';
|
|
34
|
+
rawValueStart = (_f = (_e = attr.value[0]) === null || _e === void 0 ? void 0 : _e.expression.start) !== null && _f !== void 0 ? _f : name.endOffset;
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
35
|
-
rawValue = attr.value[0].raw;
|
|
36
|
-
rawValueStart = attr.value[0].start;
|
|
37
|
+
rawValue = (_h = (_g = attr.value[0]) === null || _g === void 0 ? void 0 : _g.raw) !== null && _h !== void 0 ? _h : '';
|
|
38
|
+
rawValueStart = (_k = (_j = attr.value[0]) === null || _j === void 0 ? void 0 : _j.start) !== null && _k !== void 0 ? _k : name.endOffset;
|
|
37
39
|
}
|
|
38
40
|
const value = (0, parser_utils_1.createTokenFromRawCode)(rawValue, rawValueStart + codeOffset, rawHtml);
|
|
39
41
|
const eq = (0, parser_utils_1.sliceFragment)(rawHtml, name.endOffset, value.startOffset);
|
|
40
42
|
const eqRegexp = /^(?<bs>\s*)(?<eq>=)(?<as>\s*)(?<squot>"|'|{)?$/g;
|
|
41
43
|
const exp = eqRegexp.exec(eq.raw);
|
|
42
|
-
const bsChar = ((
|
|
43
|
-
const eqChar = ((
|
|
44
|
-
const asChar = ((
|
|
45
|
-
const squotChar = ((
|
|
44
|
+
const bsChar = ((_l = exp === null || exp === void 0 ? void 0 : exp.groups) === null || _l === void 0 ? void 0 : _l.bs) || '';
|
|
45
|
+
const eqChar = ((_m = exp === null || exp === void 0 ? void 0 : exp.groups) === null || _m === void 0 ? void 0 : _m.eq) || '';
|
|
46
|
+
const asChar = ((_o = exp === null || exp === void 0 ? void 0 : exp.groups) === null || _o === void 0 ? void 0 : _o.as) || '';
|
|
47
|
+
const squotChar = ((_p = exp === null || exp === void 0 ? void 0 : exp.groups) === null || _p === void 0 ? void 0 : _p.squot) || '';
|
|
46
48
|
const spacesBeforeEqual = (0, parser_utils_1.createTokenFromRawCode)(bsChar, name.endOffset, rawHtml);
|
|
47
49
|
const equal = (0, parser_utils_1.createTokenFromRawCode)(eqChar, spacesBeforeEqual.endOffset, rawHtml);
|
|
48
50
|
const spacesAfterEqual = (0, parser_utils_1.createTokenFromRawCode)(asChar, equal.endOffset, rawHtml);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { parse } from './parse';
|
|
2
|
-
export declare const endTag =
|
|
2
|
+
export declare const endTag = "xml";
|
package/lib/parse.js
CHANGED
|
@@ -25,13 +25,13 @@ const parse = (rawCode, options) => {
|
|
|
25
25
|
const styleNodes = parseStyle(ast.style, 'http://www.w3.org/1999/xhtml', rawCode, 0, options);
|
|
26
26
|
htmlRawNodeList.push(...styleNodes);
|
|
27
27
|
}
|
|
28
|
-
const nodeList = (0,
|
|
28
|
+
const nodeList = (0, parser_utils_1.flattenNodes)(htmlRawNodeList, rawCode);
|
|
29
29
|
// Remove `</template>`
|
|
30
30
|
const templateEndTagIndex = nodeList.findIndex(node => /\s*<\/\s*template\s*>\s*/i.test(node.raw));
|
|
31
31
|
if (templateEndTagIndex !== -1) {
|
|
32
32
|
const templateEndTag = nodeList[templateEndTagIndex];
|
|
33
33
|
for (const node of nodeList) {
|
|
34
|
-
if (node.nextNode && node.nextNode.uuid === templateEndTag.uuid) {
|
|
34
|
+
if (node.nextNode && node.nextNode.uuid === (templateEndTag === null || templateEndTag === void 0 ? void 0 : templateEndTag.uuid)) {
|
|
35
35
|
node.nextNode = null;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -43,7 +43,9 @@ const parse = (rawCode, options) => {
|
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
exports.parse = parse;
|
|
46
|
-
function traverse(
|
|
46
|
+
function traverse(
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
48
|
+
rootNode, parentNode = null, scopeNS, rawHtml, offset, options) {
|
|
47
49
|
const nodeList = [];
|
|
48
50
|
if (!rootNode.children) {
|
|
49
51
|
return nodeList;
|
|
@@ -68,7 +70,13 @@ function traverse(rootNode, parentNode = null, scopeNS, rawHtml, offset, options
|
|
|
68
70
|
}
|
|
69
71
|
return nodeList;
|
|
70
72
|
}
|
|
71
|
-
function nodeize(
|
|
73
|
+
function nodeize(
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
75
|
+
originNode,
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
77
|
+
prevNode,
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
79
|
+
parentNode, scopeNS, rawHtml, offset = 0, options) {
|
|
72
80
|
var _a, _b;
|
|
73
81
|
const nextNode = null;
|
|
74
82
|
const startOffset = originNode.start + offset;
|
|
@@ -222,13 +230,22 @@ function nodeize(originNode, prevNode, parentNode, scopeNS, rawHtml, offset = 0,
|
|
|
222
230
|
}
|
|
223
231
|
}
|
|
224
232
|
}
|
|
225
|
-
function parseElement(nodeName,
|
|
233
|
+
function parseElement(nodeName,
|
|
234
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
235
|
+
originNode, scopeNS, rawHtml, startLine, startCol, startOffset,
|
|
236
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
237
|
+
parentNode,
|
|
238
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
239
|
+
prevNode,
|
|
240
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
241
|
+
nextNode, offset, options) {
|
|
242
|
+
var _a, _b;
|
|
226
243
|
const { raw } = (0, parser_utils_1.sliceFragment)(rawHtml, originNode.start + offset, originNode.end + offset);
|
|
227
244
|
let childrenStart;
|
|
228
245
|
let childrenEnd;
|
|
229
246
|
if (originNode.children && originNode.children[0]) {
|
|
230
247
|
childrenStart = originNode.children[0].start + offset;
|
|
231
|
-
childrenEnd = originNode.children[originNode.children.length - 1].end + offset;
|
|
248
|
+
childrenEnd = ((_b = (_a = originNode.children[originNode.children.length - 1]) === null || _a === void 0 ? void 0 : _a.end) !== null && _b !== void 0 ? _b : 0) + offset;
|
|
232
249
|
}
|
|
233
250
|
else if (originNode.content) {
|
|
234
251
|
childrenStart = originNode.content.start + offset;
|
|
@@ -290,7 +307,9 @@ function parseElement(nodeName, originNode, scopeNS, rawHtml, startLine, startCo
|
|
|
290
307
|
type: 'starttag',
|
|
291
308
|
namespace: scopeNS,
|
|
292
309
|
elementType: (0, parser_utils_1.detectElementType)(tagName, options === null || options === void 0 ? void 0 : options.authoredElementName, /^[A-Z]|\./),
|
|
293
|
-
attributes: originNode.attributes.map((
|
|
310
|
+
attributes: originNode.attributes.map((
|
|
311
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
312
|
+
attr) => (0, attr_tokenizer_1.attrTokenizer)(attr, rawHtml, offset)),
|
|
294
313
|
hasSpreadAttr: false,
|
|
295
314
|
parentNode,
|
|
296
315
|
prevNode,
|
|
@@ -309,7 +328,9 @@ function parseElement(nodeName, originNode, scopeNS, rawHtml, startLine, startCo
|
|
|
309
328
|
startTag.childNodes = traverse(originNode, startTag, scopeNS, rawHtml, offset);
|
|
310
329
|
return startTag;
|
|
311
330
|
}
|
|
312
|
-
function parseStyle(
|
|
331
|
+
function parseStyle(
|
|
332
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
333
|
+
nodes, scopeNS, rawHtml, offset, options) {
|
|
313
334
|
const result = [];
|
|
314
335
|
for (const node of nodes) {
|
|
315
336
|
const { startLine, startCol, startOffset } = (0, parser_utils_1.sliceFragment)(rawHtml, node.start, node.end);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/astro-parser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "astro parser for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@astrojs/parser": "0.20",
|
|
20
|
-
"@markuplint/html-parser": "3.
|
|
21
|
-
"@markuplint/ml-ast": "3.
|
|
22
|
-
"@markuplint/parser-utils": "3.
|
|
20
|
+
"@markuplint/html-parser": "3.5.0",
|
|
21
|
+
"@markuplint/ml-ast": "3.1.0",
|
|
22
|
+
"@markuplint/parser-utils": "3.5.0",
|
|
23
23
|
"tslib": "^2.4.1"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "0c47b2c2722f6823a17f36edbab98486275f8ab4"
|
|
26
26
|
}
|