Skip to content

Commit

Permalink
feat!: fix #277, for that change estarget to es6
Browse files Browse the repository at this point in the history
  • Loading branch information
taoqf committed Dec 26, 2024
1 parent a8acb96 commit 432a3e7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/nodes/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,9 @@ export default class HTMLElement extends Node {
this.childNodes.length = o;

// remove whitespace between attributes
const attrs = Object.keys( this.rawAttributes).map((key) => {
const attrs = Object.keys(this.rawAttributes).map((key) => {
const val = this.rawAttributes[key];
return `${key}=${ JSON.stringify(val)}`;
return `${key}=${JSON.stringify(val)}`;
}).join(' ');
this.rawAttrs = attrs;
delete this._rawAttrs;
Expand Down Expand Up @@ -959,8 +959,10 @@ export default class HTMLElement extends Node {
}
}

// #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]
// https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
const kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g;
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;
// const kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g;
const kAttributePattern = /(?:^|\s)(id|class)\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+)/gi;
const kElementsClosedByOpening = {
li: { li: true, LI: true },
Expand Down
2 changes: 1 addition & 1 deletion test/tests/issues/268.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe.skip('issue 268', function () {
const html = `<a href="#" 2'>x</a><a href="#" 2'>x</a>`;
const root = parse(html);
const a = root.querySelector("a");
console.error('sss',a.attributes);
console.error('sss', a.attributes);
a.toString().should.eql('<a href="#" 2">x</a>');
// for (let tr of root.querySelectorAll("#mytable tr.myrow")) {
// console.log('xxx',tr.querySelectorAll(":scope > td").map(e => e.innerText));
Expand Down
38 changes: 38 additions & 0 deletions test/tests/issues/277.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { parse } = require('@test/test-target');

describe('issue 277', function () {
it('custom tag name', function () {
const html = `<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
</head>
<body>
<template>
<h@1>Smile!</h@1>
</template>
</body>
</html>`;
const root = parse(html);
const t = root.querySelector('template');
const el = t.childNodes[1];
el.toString().should.eql('<h@1>Smile!</h@1>');
});
it('unicode tag name', function () {
const html = `<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
</head>
<body>
<template>
<h测试اختبار>Smile!</h测试اختبار>
</template>
</body>
</html>`;
const root = parse(html);
const t = root.querySelector('template');
const el = t.childNodes[1];
el.toString().should.eql('<h测试اختبار>Smile!</h测试اختبار>');
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"target": "es6",
"noImplicitAny": true,
"sourceMap": false,
"emitDecoratorMetadata": true,
Expand Down

0 comments on commit 432a3e7

Please sign in to comment.