8000 enforce Error type and add test · github/include-fragment-element@ad2af2d · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ad2af2d

Browse files
committed
enforce Error type and add test
1 parent 6ffb1f9 commit ad2af2d

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

custom-elements.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
{
1010
"kind": "variable",
1111
"name": "IncludeFragmentElement",
12-
"default": "class extends HTMLElement {\n constructor() {\n super(...arguments);\n _IncludeFragmentElement_instances.add(this);\n _IncludeFragmentElement_busy.set(this, false);\n _IncludeFragmentElement_observer.set(this, new IntersectionObserver((entries) => {\n for (const entry of entries) {\n if (entry.isIntersecting) {\n const { target } = entry;\n __classPrivateFieldGet(this, _IncludeFragmentElement_observer, \"f\").unobserve(target);\n if (!(target instanceof IncludeFragmentElement))\n return;\n if (target.loading === \"lazy\") {\n __classPrivateFieldGet(this, _IncludeFragmentElement_instances, \"m\", _IncludeFragmentElement_handleData).call(this);\n }\n }\n }\n }, {\n rootMargin: \"0px 0px 256px 0px\",\n threshold: 0.01\n }));\n }\n static define(tag = \"include-fragment\", registry = customElements) {\n registry.define(tag, this);\n return this;\n }\n static setCSPTrustedTypesPolicy(policy) {\n cspTrustedTypesPolicyPromise = policy === null ? policy : Promise.resolve(policy);\n }\n static get observedAttributes() {\n return [\"src\", \"loading\"];\n }\n get src() {\n const src = this.getAttribute(\"src\");\n if (src) {\n const link = this.ownerDocument.createElement(\"a\");\n link.href = src;\n return link.href;\n } else {\n return \"\";\n }\n }\n set src(val) {\n this.setAttribute(\"src\", val);\n }\n get loading() {\n if (this.getAttribute(\"loading\") === \"lazy\")\n return \"lazy\";\n return \"eager\";\n }\n set loading(value) {\n this.setAttribute(\"loading\", value);\n }\n get accept() {\n return this.getAttribute(\"accept\") || \"\";\n }\n set accept(val) {\n this.setAttribute(\"accept\", val);\n }\n get data() {\n return __classPrivateFieldGet(this, _IncludeFragmentElement_instances, \"m\", _IncludeFragmentElement_getStringOrErrorData).call(this);\n }\n attributeChangedCallback(attribute, oldVal) {\n if (attribute === \"src\") {\n if (this.isConnected && this.loading === \"eager\") {\n __classPrivateFieldGet(this, _IncludeFragmentElement_instances, \"m\", _IncludeFragmentElement_handleData).call(this);\n }\n } else if (attribute === \"loading\") {\n if (this.isConnected && oldVal !== \"eager\" && this.loading === \"eager\") {\n __classPrivateFieldGet(this, _IncludeFragmentElement_instances, \"m\", _IncludeFragmentElement_handleData).call(this);\n }\n }\n }\n connectedCallback() {\n if (!this.shadowRoot) {\n this.attachShadow({ mode: \"open\" });\n const style = document.createElement(\"style\");\n style.textContent = `:host {display: block;}`;\n this.shadowRoot.append(style, document.createElement(\"slot\"));\n }\n if (this.src && this.loading === \"eager\") {\n __classPrivateFieldGet(this, _IncludeFragmentElement_instances, \"m\", _IncludeFragmentElement_handleData).call(this);\n }\n if (this.loading === \"lazy\") {\n __classPrivateFieldGet(this, _IncludeFragmentElement_observer, \"f\").observe(this);\n }\n }\n request() {\n const src = this.src;\n if (!src) {\n throw new Error(\"missing src\");\n }\n return new Request(src, {\n method: \"GET\",\n credentials: \"same-origin\",\n headers: {\n Accept: this.accept || \"text/html\"\n }\n });\n }\n load() {\n return __classPrivateFieldGet(this, _IncludeFragmentElement_instances, \"m\", _IncludeFragmentElement_getStringOrErrorData).call(this);\n }\n fetch(request) {\n return fetch(request);\n }\n refetch() {\n privateData.delete(this);\n __classPrivateFieldGet(this, _IncludeFragmentElement_instances, \"m\", _IncludeFragmentElement_handleData).call(this);\n }\n}"
12+
"default": "class _IncludeFragmentElement extends HTMLElement {\n static"
1313
},
1414
{
1515
"kind": "variable",
16-
"name": "dist_default",
16+
"name": "index_default",
1717
"default": "IncludeFragmentElement"
1818
}
1919
],
@@ -30,7 +30,7 @@
3030
"kind": "js",
3131
"name": "default",
3232
"declaration": {
33-
"name": "dist_default",
33+
"name": "index_default",
3434
"module": "dist/bundle.js"
3535
}
3636
}
@@ -188,12 +188,6 @@
188188
}
189189
]
190190
},
191-
{
192-
"kind": "javascript-module",
193-
"path": "test/test.js",
194-
"declarations": [],
195-
"exports": []
196-
},
197191
{
198192
"kind": "javascript-module",
199193
"path": "src/include-fragment-element-define.ts",
@@ -383,6 +377,13 @@
383377
"type": {
384378
"text": "string[]"
385379
}
380+
},
381+
{
382+
"name": "error",
383+
"optional": true,
384+
"type": {
385+
"text": "Error"
386+
}
386387
}
387388
]
388389
},
@@ -408,12 +409,6 @@
408409
"type": {
409410
"text": "CustomEvent"
410411
}
411-
},
412-
{
413-
"name": "eventType",
414-
"type": {
415-
"text": "Event"
416-
}
417412
}
418413
],
419414
"attributes": [
@@ -471,6 +466,12 @@
471466
}
472467
}
473468
]
469+
},
470+
{
471+
"kind": "javascript-module",
472+
"path": "test/test.js",
473+
"declarations": [],
474+
"exports": []
474475
}
475476
]
476477
}

src/include-fragment-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export class IncludeFragmentElement extends HTMLElement {
258258
// Dispatch `error` and `loadend` async to allow
259259
// the `load()` promise to resolve _before_ these
260260
// events are fired.
261-
this.#task(['error', 'loadend'], error)
261+
this.#task(['error', 'loadend'], error as Error)
262262
throw error
263263
}
264264
}

test/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ suite('include-fragment-element', function () {
342342
const event = await when(div.firstChild, 'error')
343343
assert.equal(event.bubbles, false)
344344
assert.equal(event.cancelable, false)
345+
assert.equal(event.detail.error, 'Failed to load resource: the server responded with a status of 500')
345346
})
346347

347348
test('adds is-error class on 500 status', async function () {

0 commit comments

Comments
 (0)
0