Skip to content

Commit 2613556

Browse files
committed
Make Element.attributes an IterableIterator
1 parent 11dfe9e commit 2613556

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ wasm-pack build --target nodejs
1616

1717
echo "---> Patching JavaScript glue code..."
1818
# Wraps write/end with asyncify magic and adds this returns for chaining
19+
# diff -uN pkg/html_rewriter.js pkg2/html_rewriter.js > html_rewriter.js.patch
1920
patch -uN pkg/html_rewriter.js < html_rewriter.js.patch
2021

2122
echo "---> Copying required files to dist..."

html_rewriter.js.patch

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- pkg/html_rewriter.js 2021-07-21 19:45:46.000000000 +0100
2-
+++ pkg2/html_rewriter.js 2021-07-21 19:44:41.000000000 +0100
1+
--- pkg/html_rewriter.js 2021-07-22 16:09:24.000000000 +0100
2+
+++ pkg2/html_rewriter.js 2021-07-22 16:10:13.000000000 +0100
33
@@ -1,7 +1,7 @@
44
let imports = {};
55
imports['__wbindgen_placeholder__'] = module.exports;
@@ -77,6 +77,15 @@
7777
}
7878
/**
7979
* @returns {boolean}
80+
@@ -463,7 +472,7 @@
81+
*/
82+
get attributes() {
83+
var ret = wasm.element_attributes(this.ptr);
84+
- return takeObject(ret);
85+
+ return takeObject(ret)[Symbol.iterator]();
86+
}
87+
/**
88+
* @param {string} name
8089
@@ -495,6 +504,7 @@
8190
var ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
8291
var len1 = WASM_VECTOR_LEN;

src/html_rewriter.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Element {
1515
append(content: string, options?: ContentTypeOptions): this;
1616
setInnerContent(content: string, options?: ContentTypeOptions): this;
1717
removeAndKeepContent(): this;
18-
readonly attributes: [string, string][];
18+
readonly attributes: IterableIterator<[string, string]>;
1919
readonly namespaceURI: string;
2020
readonly removed: boolean;
2121
tagName: string;
@@ -47,7 +47,7 @@ export class Doctype {
4747
}
4848

4949
export class DocumentEnd {
50-
append(content: string, options?: ContentTypeOptions): DocumentEnd;
50+
append(content: string, options?: ContentTypeOptions): this;
5151
}
5252

5353
export interface ElementHandlers {

test/element.spec.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ const elementMutationsExpected = {
1919
};
2020

2121
test("handles element properties", async (t) => {
22-
t.plan(5);
22+
t.plan(6);
2323
const res = await new HTMLRewriter()
2424
.on("p", {
2525
element(element) {
2626
t.is(element.tagName, "p");
2727
element.tagName = "h1";
28-
t.deepEqual([...element.attributes], [["class", "red"]]);
2928
t.false(element.removed);
3029
t.is(element.namespaceURI, "http://www.w3.org/1999/xhtml");
30+
31+
// Check element.attributes is an IterableIterator
32+
t.deepEqual(element.attributes.next(), {
33+
value: ["class", "red"],
34+
done: false,
35+
});
36+
t.deepEqual([...element.attributes], [["class", "red"]]);
3137
},
3238
})
3339
.transform('<p class="red">test</p>');

0 commit comments

Comments
 (0)