Skip to content

Commit 73821d8

Browse files
fix(CustomStateSet): added to window and will throw illegal constructor by default
1 parent c59e4f6 commit 73821d8

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"types": "dist/index.d.ts",
1111
"scripts": {
1212
"pretest": "npm run build",
13-
"test": "web-test-runner test/*.test.js --node-resolve --playwright --browsers chromium firefox webkit",
13+
"test": "web-test-runner test/*.test.* --node-resolve --playwright --browsers chromium firefox webkit",
1414
"test:watch": "npm run test -- --watch",
1515
"test:coverage": "npm run test -- --coverage",
1616
"start": "rollup -c --watch --environment BUILD:dev",

Diff for: src/CustomStateSet.ts

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const customStateMap = new WeakMap<CustomStateSet, ICustomElement>();
66
export class CustomStateSet extends Set<string> {
77
constructor(ref: ICustomElement) {
88
super();
9+
if (!ref || !ref.tagName || ref.tagName.indexOf('-') === -1) {
10+
throw new TypeError('Illegal constructor');
11+
}
912

1013
customStateMap.set(this, ref);
1114
}

Diff for: src/element-internals.ts

+4
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ declare global {
248248
}
249249
}
250250

251+
if (!window.CustomStateSet) {
252+
window.CustomStateSet = CustomStateSet;
253+
}
254+
251255
if (!window.ElementInternals) {
252256
window.ElementInternals = ElementInternals;
253257

Diff for: src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { ElementInternals } from './element-internals';
22
import './element-internals';
3+
import { CustomStateSet } from './CustomStateSet';
34
export * from './types';
45

56
declare global {
67
interface Window {
8+
CustomStateSet: typeof CustomStateSet;
79
ElementInternals: typeof ElementInternals;
810
}
911
interface Element {

0 commit comments

Comments
 (0)