Skip to content

Commit 432a3e7

Browse files
committedDec 26, 2024·
feat!: fix #277, for that change estarget to es6
1 parent a8acb96 commit 432a3e7

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed
 

‎src/nodes/html.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ export default class HTMLElement extends Node {
456456
this.childNodes.length = o;
457457

458458
// remove whitespace between attributes
459-
const attrs = Object.keys( this.rawAttributes).map((key) => {
459+
const attrs = Object.keys(this.rawAttributes).map((key) => {
460460
const val = this.rawAttributes[key];
461-
return `${key}=${ JSON.stringify(val)}`;
461+
return `${key}=${JSON.stringify(val)}`;
462462
}).join(' ');
463463
this.rawAttrs = attrs;
464464
delete this._rawAttrs;
@@ -959,8 +959,10 @@ export default class HTMLElement extends Node {
959959
}
960960
}
961961

962+
// #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
962963
// https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
963-
const kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g;
964+
const kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z@\xB7\xC0-\xD6\xD8-\xF6\u00F8-\u03A1\u03A3-\u03D9\u03DB-\u03EF\u03F7-\u03FF\u0400-\u04FF\u0500-\u052F\u1D00-\u1D2B\u1D6B-\u1D77\u1D79-\u1D9A\u1E00-\u1E9B\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2126\u212A-\u212B\u2132\u214E\u2160-\u2188\u2C60-\u2C7F\uA722-\uA787\uA78B-\uA78E\uA790-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA7FF\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64-\uAB65\uFB00-\uFB06\uFB13-\uFB17\uFF21-\uFF3A\uFF41-\uFF5A\x37F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/gu;
965+
// const kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g;
964966
const kAttributePattern = /(?:^|\s)(id|class)\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+)/gi;
965967
const kElementsClosedByOpening = {
966968
li: { li: true, LI: true },

‎test/tests/issues/268.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe.skip('issue 268', function () {
2525
const html = `<a href="#" 2'>x</a><a href="#" 2'>x</a>`;
2626
const root = parse(html);
2727
const a = root.querySelector("a");
28-
console.error('sss',a.attributes);
28+
console.error('sss', a.attributes);
2929
a.toString().should.eql('<a href="#" 2">x</a>');
3030
// for (let tr of root.querySelectorAll("#mytable tr.myrow")) {
3131
// console.log('xxx',tr.querySelectorAll(":scope > td").map(e => e.innerText));

‎test/tests/issues/277.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const { parse } = require('@test/test-target');
2+
3+
describe('issue 277', function () {
4+
it('custom tag name', function () {
5+
const html = `<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<title>test</title>
9+
</head>
10+
<body>
11+
<template>
12+
<h@1>Smile!</h@1>
13+
</template>
14+
</body>
15+
</html>`;
16+
const root = parse(html);
17+
const t = root.querySelector('template');
18+
const el = t.childNodes[1];
19+
el.toString().should.eql('<h@1>Smile!</h@1>');
20+
});
21+
it('unicode tag name', function () {
22+
const html = `<!DOCTYPE html>
23+
<html lang="en">
24+
<head>
25+
<title>test</title>
26+
</head>
27+
<body>
28+
<template>
29+
<h测试اختبار>Smile!</h测试اختبار>
30+
</template>
31+
</body>
32+
</html>`;
33+
const root = parse(html);
34+
const t = root.querySelector('template');
35+
const el = t.childNodes[1];
36+
el.toString().should.eql('<h测试اختبار>Smile!</h测试اختبار>');
37+
});
38+
});

‎tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
],
55
"compilerOptions": {
66
"module": "commonjs",
7-
"target": "es5",
7+
"target": "es6",
88
"noImplicitAny": true,
99
"sourceMap": false,
1010
"emitDecoratorMetadata": true,

0 commit comments

Comments
 (0)
Please sign in to comment.