Socket
Socket
Sign inDemoInstall

webidl2

Package Overview
Dependencies
Maintainers
4
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webidl2 - npm Package Compare versions

Comparing version 23.8.2 to 23.8.3

2

dist/webidl2.js

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.WebIDL2=t():e.WebIDL2=t()}(this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var s=t[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(r,s,function(t){return e[t]}.bind(null,s));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e,t,n,r,s,{level:o="error",autofix:i}={}){function a(n){return n>0?e.slice(t,t+n):e.slice(Math.max(t+n,0),t)}function c(n,{precedes:r}={}){const s=n.map(e=>e.trivia+e.value).join(""),o=e[t];return"eof"===o.type?s:r?s+o.trivia:s.slice(o.trivia.length)}const u="eof"!==e[t].type?e[t].line:e.length>1?e[t-1].line:1,l=function(e){const t=e.split("\n");return t[t.length-1]}(c(a(-5),{precedes:!0})),p=a(5),d=c(p),m=l+d.split("\n")[0]+"\n"+(" ".repeat(l.length)+"^"),f="Syntax"===s?"since":"inside",y=`${s} error at line ${u}${e.name?` in ${e.name}`:""}${n&&n.name?`, ${f} \`${n.partial?"partial ":""}${n.type} ${n.name}\``:""}:\n${m}`;return{message:`${y} ${r}`,bareMessage:r,context:y,line:u,sourceName:e.name,level:o,autofix:i,input:d,tokens:p}}function s(e,t,n,s){return r(e,t,n,s,"Syntax")}function o(e,t,n,s){return r(t.source,e.index,t,n,"Validation",s)}n.r(t);class i{constructor({source:e,tokens:t}){Object.defineProperties(this,{source:{value:e},tokens:{value:t}})}toJSON(){const e={type:void 0,name:void 0,inheritance:void 0};let t=this;for(;t!==Object.prototype;){const n=Object.getOwnPropertyDescriptors(t);for(const[t,r]of Object.entries(n))(r.enumerable||r.get)&&(e[t]=this[t]);t=Object.getPrototypeOf(t)}return e}}function a(e,t,{useNullableInner:n}={}){if(!e.union){const r=t.unique.get(e.idlType);if(!r)return;if("typedef"===r.type){const{typedefIncludesDictionary:n}=t.cache;if(n.has(r))return n.get(r);t.cache.typedefIncludesDictionary.set(r,void 0);const s=a(r.idlType,t);if(t.cache.typedefIncludesDictionary.set(r,s),s)return e}if("dictionary"===r.type&&(n||!e.nullable))return e}for(const n of e.subtype){const e=a(n,t);if(e)return n.union?e:n}}function c(e,t){const n=e.consume("?");n&&(t.tokens.nullable=n),e.probe("?")&&e.error("Can't nullable more than once")}function u(e,t){let n=function(e,t){const n=e.consume("FrozenArray","Promise","sequence","record");if(!n)return;const r=new l({source:e.source,tokens:{base:n}});switch(r.tokens.open=e.consume("<")||e.error(`No opening bracket after ${n.type}`),n.type){case"Promise":{e.probe("[")&&e.error("Promise type cannot have extended attribute");const n=I(e,t)||e.error("Missing Promise subtype");r.subtype.push(n);break}case"sequence":case"FrozenArray":{const s=$(e,t)||e.error(`Missing ${n.type} subtype`);r.subtype.push(s);break}case"record":{e.probe("[")&&e.error("Record key cannot have extended attribute");const n=e.consume(...P)||e.error(`Record key must be one of: ${P.join(", ")}`),s=new l({source:e.source,tokens:{base:n}});s.tokens.separator=e.consume(",")||e.error("Missing comma after record key type"),s.type=t;const o=$(e,t)||e.error("Error parsing generic type record");r.subtype.push(s,o);break}}return r.idlType||e.error(`Error parsing generic type ${n.type}`),r.tokens.close=e.consume(">")||e.error(`Missing closing bracket after ${n.type}`),r}(e,t)||A(e);if(!n){const t=e.consume("identifier",...P);if(!t)return;n=new l({source:e.source,tokens:{base:t}}),e.probe("<")&&e.error(`Unsupported generic type ${t.value}`)}return"Promise"===n.generic&&e.probe("?")&&e.error("Promise type cannot be nullable"),n.type=t||null,c(e,n),n.nullable&&"any"===n.idlType&&e.error("Type `any` cannot be made nullable"),n}class l extends i{static parse(e,t){return u(e,t)||function(e,t){const n={};if(n.open=e.consume("("),!n.open)return;const r=new l({source:e.source,tokens:n});for(r.type=t||null;;){const t=$(e)||e.error("No type after open parenthesis or 'or' in union type");"any"===t.idlType&&e.error("Type `any` cannot be included in a union type"),r.subtype.push(t);const n=e.consume("or");if(!n)break;t.tokens.separator=n}return r.idlType.length<2&&e.error("At least two types are expected in a union type but found less"),n.close=e.consume(")")||e.error("Unterminated union type"),c(e,r),r}(e,t)}constructor({source:e,tokens:t}){super({source:e,tokens:t}),Object.defineProperty(this,"subtype",{value:[]}),this.extAttrs=[]}get generic(){return this.subtype.length&&this.tokens.base?this.tokens.base.value:""}get nullable(){return Boolean(this.tokens.nullable)}get union(){return Boolean(this.subtype.length)&&!this.tokens.base}get idlType(){if(this.subtype.length)return this.subtype;return v([this.tokens.prefix,this.tokens.base,this.tokens.postfix].filter(e=>e).map(e=>e.value).join(" "))}*validate(e){const t=!this.union&&e.unique.get(this.idlType),n=this.union?this:t&&"typedef"===t.type?t.idlType:void 0;if(n&&this.nullable){const t=a(n,e);if(t){const e=(this.union?t:this).tokens.base,n="Nullable union cannot include a dictionary type";yield o(e,this,n)}}else for(const t of this.subtype)yield*t.validate(e)}}class p extends i{static parse(e){const t=e.consume("=");if(!t)return null;const n=w(e)||e.consume("string","null","[","{")||e.error("No value for default"),r=[n];if("["===n.type){const t=e.consume("]")||e.error("Default sequence value must be empty");r.push(t)}else if("{"===n.type){const t=e.consume("}")||e.error("Default dictionary value must be empty");r.push(t)}return new p({source:e.source,tokens:{assign:t},expression:r})}constructor({source:e,tokens:t,expression:n}){super({source:e,tokens:t}),Object.defineProperty(this,"expression",{value:n})}get type(){return T(this.expression[0]).type}get value(){return T(this.expression[0]).value}get negative(){return T(this.expression[0]).negative}}class d extends Array{constructor({source:e,tokens:t}){super(),Object.defineProperties(this,{source:{value:e},tokens:{value:t}})}}class m extends i{static parse(e){const t={assign:e.consume("=")},n=new m({source:e.source,tokens:t});return t.assign&&(t.secondaryName=e.consume("identifier","decimal","integer","string")),t.open=e.consume("("),t.open?(n.list="identifier-list"===n.rhsType?function(e){const t=x(e,{parser:k.parser(e,"identifier"),listName:"identifier list"});t.length||e.error("Expected identifiers but none found");return t}(e):N(e),t.close=e.consume(")")||e.error("Unexpected token in extended attribute argument list")):n.hasRhs&&!t.secondaryName&&e.error("No right hand side to extended attribute assignment"),n}get rhsType(){return this.tokens.assign?this.tokens.secondaryName?this.tokens.secondaryName.type:"identifier-list":null}}class f extends i{static parse(e){const t=e.consume("identifier");if(t)return new f({source:e.source,tokens:{name:t},params:m.parse(e)})}constructor({source:e,tokens:t,params:n}){super({source:e,tokens:t}),Object.defineProperty(this,"params",{value:n})}get type(){return"extended-attribute"}get name(){return this.tokens.name.value}get rhs(){const{rhsType:e,tokens:t,list:n}=this.params;return e?{type:e,value:"identifier-list"===e?n:t.secondaryName.value}:null}get arguments(){const{rhsType:e,list:t}=this.params;return t&&"identifier-list"!==e?t:[]}*validate(e){if("NoInterfaceObject"===this.name){const e="`[NoInterfaceObject]` extended attribute is an undesirable feature that may be removed from Web IDL in the future. Refer to the [relevant upstream PR](https://github.com/heycam/webidl/pull/609) for more information.";yield o(this.tokens.name,this,e,{level:"warning"})}for(const t of this.arguments)yield*t.validate(e)}}class y extends d{static parse(e){const t={};if(t.open=e.consume("["),!t.open)return new y({});const n=new y({source:e.source,tokens:t});return n.push(...x(e,{parser:f.parse,listName:"extended attribute"})),t.close=e.consume("]")||e.error("Unexpected closing token of extended attribute"),n.length||e.error("Found an empty extended attribute"),e.probe("[")&&e.error("Illegal double extended attribute lists, consider merging them"),n}*validate(e){for(const t of this)yield*t.validate(e)}}class h extends i{static parse(e){const t=e.position,n={},r=new h({source:e.source,tokens:n});return r.extAttrs=y.parse(e),n.optional=e.consume("optional"),r.idlType=$(e,"argument-type"),r.idlType?(n.optional||(n.variadic=e.consume("...")),n.name=e.consume("identifier",...E),n.name?(r.default=n.optional?p.parse(e):null,r):e.unconsume(t)):e.unconsume(t)}get type(){return"argument"}get optional(){return!!this.tokens.optional}get variadic(){return!!this.tokens.variadic}get name(){return v(this.tokens.name.value)}*validate(e){if(yield*this.idlType.validate(e),a(this.idlType,e,{useNullableInner:!0}))if(this.idlType.nullable){const e="Dictionary arguments cannot be nullable.";yield o(this.tokens.name,this,e)}else if(this.optional&&!this.default){const e="Optional dictionary arguments must have a default value of `{}`.";yield o(this.tokens.name,this,e,{autofix:(t=this,()=>{t.default=p.parse(new W(" = {}"))})})}var t}}class k extends i{static parser(e,t){return()=>{const n=e.consume(t);if(n)return new k({source:e.source,tokens:{value:n}})}}get value(){return this.tokens.value.value}}class b extends i{static parse(e,{special:t,regular:n}={}){const r={special:t},s=new b({source:e.source,tokens:r});return t&&"stringifier"===t.value&&(r.termination=e.consume(";"),r.termination)?(s.arguments=[],s):(t||n||(r.special=e.consume("getter","setter","deleter")),s.idlType=I(e)||e.error("Missing return type"),r.name=e.consume("identifier","includes"),r.open=e.consume("(")||e.error("Invalid operation"),s.arguments=N(e),r.close=e.consume(")")||e.error("Unterminated operation"),r.termination=e.consume(";")||e.error("Unterminated operation, expected `;`"),s)}get type(){return"operation"}get name(){const{name:e}=this.tokens;return e?v(e.value):""}get special(){return this.tokens.special?this.tokens.special.value:""}*validate(e){if(!this.name&&["","static"].includes(this.special)){const e="Regular or static operations must have both a return type and an identifier.";yield o(this.tokens.open,this,e)}this.idlType&&(yield*this.idlType.validate(e));for(const t of this.arguments)yield*t.validate(e)}}class g extends i{static parse(e,{special:t,noInherit:n=!1,readonly:r=!1}={}){const s=e.position,o={special:t},i=new g({source:e.source,tokens:o});if(t||n||(o.special=e.consume("inherit")),"inherit"===i.special&&e.probe("readonly")&&e.error("Inherited attributes cannot be read-only"),o.readonly=e.consume("readonly"),r&&!o.readonly&&e.probe("attribute")&&e.error("Attributes must be readonly in this context"),o.base=e.consume("attribute"),o.base){switch(i.idlType=$(e,"attribute-type")||e.error("Attribute lacks a type"),i.idlType.generic){case"sequence":case"record":e.error(`Attributes cannot accept ${i.idlType.generic} types`)}return o.name=e.consume("identifier","async","required")||e.error("Attribute lacks a name"),o.termination=e.consume(";")||e.error("Unterminated attribute, expected `;`"),i}e.unconsume(s)}get type(){return"attribute"}get special(){return this.tokens.special?this.tokens.special.value:""}get readonly(){return!!this.tokens.readonly}get name(){return v(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}function v(e){return e.startsWith("_")?e.slice(1):e}function x(e,{parser:t,allowDangler:n,listName:r="list"}){const s=t(e);if(!s)return[];s.tokens.separator=e.consume(",");const o=[s];for(;s.tokens.separator;){const s=t(e);if(!s){n||e.error(`Trailing comma in ${r}`);break}if(s.tokens.separator=e.consume(","),o.push(s),!s.tokens.separator)break}return o}function w(e){return e.consume("true","false","Infinity","-Infinity","NaN","decimal","integer")}function T({type:e,value:t}){switch(e){case"true":case"false":return{type:"boolean",value:"true"===e};case"Infinity":case"-Infinity":return{type:"Infinity",negative:e.startsWith("-")};case"[":return{type:"sequence",value:[]};case"{":return{type:"dictionary"};case"decimal":case"integer":return{type:"number",value:t};case"string":return{type:"string",value:t.slice(1,-1)};default:return{type:e}}}function A(e){const{source:t}=e,n=function(){const n=e.consume("unsigned"),r=e.consume("short","long");if(r){const s=e.consume("long");return new l({source:t,tokens:{prefix:n,base:r,postfix:s}})}n&&e.error("Failed to parse integer type")}()||function(){const n=e.consume("unrestricted"),r=e.consume("float","double");if(r)return new l({source:t,tokens:{prefix:n,base:r}});n&&e.error("Failed to parse float type")}();if(n)return n;const r=e.consume("boolean","byte","octet");return r?new l({source:t,tokens:{base:r}}):void 0}function N(e){return x(e,{parser:h.parse,listName:"arguments list"})}function $(e,t){const n=y.parse(e),r=l.parse(e,t);return r&&(r.extAttrs=n),r}function I(e,t){const n=l.parse(e,t||"return-type");if(n)return n;const r=e.consume("void");if(r){const t=new l({source:e.source,tokens:{base:r}});return t.type="return-type",t}}function M(e){const t=e.consume("stringifier");if(t)return g.parse(e,{special:t})||b.parse(e,{special:t})||e.error("Unterminated stringifier")}function j(e){return()=>{if(e.extAttrs.length){const t=new W("Exposed=Window,"),n=f.parse(t);n.tokens.separator=t.consume(",");const r=e.extAttrs[0];/^\s/.test(r.tokens.name.trivia)||(r.tokens.name.trivia=` ${r.tokens.name.trivia}`),e.extAttrs.unshift(n)}else e.extAttrs=y.parse(new W("[Exposed=Window]")),e.extAttrs.tokens.open.trivia=e.tokens.base.trivia,e.tokens.base.trivia=" "}}const O={decimal:/-?(?=[0-9]*\.|[0-9]+[eE])(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0-9]+)?|[0-9]+[Ee][-+]?[0-9]+)/y,integer:/-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/y,identifier:/[_-]?[A-Za-z][0-9A-Z_a-z-]*/y,string:/"[^"]*"/y,whitespace:/[\t\n\r ]+/y,comment:/((\/(\/.*|\*([^*]|\*[^\/])*\*\/)[\t\n\r ]*)+)/y,other:/[^\t\n\r 0-9A-Za-z]/y},P=["ByteString","DOMString","USVString"],E=["async","attribute","callback","const","constructor","deleter","dictionary","enum","getter","includes","inherit","interface","iterable","maplike","namespace","partial","required","setlike","setter","static","stringifier","typedef","unrestricted"],D=["-Infinity","FrozenArray","Infinity","NaN","Promise","async","boolean","byte","constructor","double","false","float","long","mixin","null","octet","optional","or","readonly","record","sequence","short","true","unsigned","void"].concat(E,P),q=["(",")",",","...",":",";","<","=",">","?","[","]","{","}"],U=["_constructor","toString","_toString"];class W{constructor(e){this.source=function(e){const t=[];let n=0,r="",o=1,i=0;for(;n<e.length;){const c=e.charAt(n);let u=-1;if(/[\t\n\r ]/.test(c)?u=a("whitespace",{noFlushTrivia:!0}):"/"===c&&(u=a("comment",{noFlushTrivia:!0})),-1!==u){const e=t.pop().value;o+=(e.match(/\n/g)||[]).length,r+=e,i-=1}else if(/[-0-9.A-Z_a-z]/.test(c)){if(-1===(u=a("decimal"))&&(u=a("integer")),-1===u){u=a("identifier");const e=t.length-1,n=t[e];if(-1!==u){if(U.includes(n.value)){const r=`${v(n.value)} is a reserved identifier and must not be used.`;throw new S(s(t,e,null,r))}D.includes(n.value)&&(n.type=n.value)}}}else'"'===c&&(u=a("string"));for(const s of q)if(e.startsWith(s,n)){t.push({type:s,value:s,trivia:r,line:o,index:i}),r="",u=n+=s.length;break}if(-1===u&&(u=a("other")),-1===u)throw new Error("Token stream not progressing");n=u,i+=1}return t.push({type:"eof",value:"",trivia:r}),t;function a(s,{noFlushTrivia:a}={}){const c=O[s];c.lastIndex=n;const u=c.exec(e);return u?(t.push({type:s,value:u[0],trivia:r,line:o,index:i}),a||(r=""),c.lastIndex):-1}}(e),this.position=0}error(e){throw new S(s(this.source,this.position,this.current,e))}probe(e){return this.source.length>this.position&&this.source[this.position].type===e}consume(...e){for(const t of e){if(!this.probe(t))continue;const e=this.source[this.position];return this.position++,e}}unconsume(e){this.position=e}}class S extends Error{constructor({message:e,bareMessage:t,context:n,line:r,sourceName:s,input:o,tokens:i}){super(e),this.name="WebIDLParseError",this.bareMessage=t,this.context=n,this.line=r,this.sourceName=s,this.input=o,this.tokens=i}}class _ extends k{static parse(e){const t=e.consume("string");if(t)return new _({source:e.source,tokens:{value:t}})}get type(){return"enum-value"}get value(){return super.value.slice(1,-1)}}class C extends i{static parse(e){const t={};if(t.base=e.consume("enum"),!t.base)return;t.name=e.consume("identifier")||e.error("No name for enum");const n=e.current=new C({source:e.source,tokens:t});return t.open=e.consume("{")||e.error("Bodyless enum"),n.values=x(e,{parser:_.parse,allowDangler:!0,listName:"enumeration"}),e.probe("string")&&e.error("No comma between enum values"),t.close=e.consume("}")||e.error("Unexpected value in enum"),n.values.length||e.error("No value in enum"),t.termination=e.consume(";")||e.error("No semicolon after enum"),n}get type(){return"enum"}get name(){return v(this.tokens.name.value)}}class R extends i{static parse(e){const t=e.consume("identifier");if(!t)return;const n={target:t};if(n.includes=e.consume("includes"),n.includes)return n.mixin=e.consume("identifier")||e.error("Incomplete includes statement"),n.termination=e.consume(";")||e.error("No terminating ; for includes statement"),new R({source:e.source,tokens:n});e.unconsume(t.index)}get type(){return"includes"}get target(){return v(this.tokens.target.value)}get includes(){return v(this.tokens.mixin.value)}}class F extends i{static parse(e){const t={},n=new F({source:e.source,tokens:t});if(t.base=e.consume("typedef"),t.base)return n.idlType=$(e,"typedef-type")||e.error("Typedef lacks a type"),t.name=e.consume("identifier")||e.error("Typedef lacks a name"),e.current=n,t.termination=e.consume(";")||e.error("Unterminated typedef, expected `;`"),n}get type(){return"typedef"}get name(){return v(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}class z extends i{static parse(e,t){const n={base:t},r=new z({source:e.source,tokens:n});return n.name=e.consume("identifier")||e.error("Callback lacks a name"),e.current=r,n.assign=e.consume("=")||e.error("Callback lacks an assignment"),r.idlType=I(e)||e.error("Callback lacks a return type"),n.open=e.consume("(")||e.error("Callback lacks parentheses for arguments"),r.arguments=N(e),n.close=e.consume(")")||e.error("Unterminated callback"),n.termination=e.consume(";")||e.error("Unterminated callback, expected `;`"),r}get type(){return"callback"}get name(){return v(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}class L extends i{static parse(e,t,{type:n,inheritable:r,allowedMembers:s}){const{tokens:o}=t;for(o.name=e.consume("identifier")||e.error(`Missing name in ${t.type}`),e.current=t,r&&Object.assign(o,function(e){const t=e.consume(":");return t?{colon:t,inheritance:e.consume("identifier")||e.error("Inheritance lacks a type")}:{}}(e)),o.open=e.consume("{")||e.error(`Bodyless ${n}`),t.members=[];;){if(o.close=e.consume("}"),o.close)return o.termination=e.consume(";")||e.error(`Missing semicolon after ${n}`),t;const r=y.parse(e);let i;for(const[t,...n]of s)if(i=t(e,...n))break;i||e.error("Unknown member"),i.extAttrs=r,t.members.push(i)}}get partial(){return!!this.tokens.partial}get name(){return v(this.tokens.name.value)}get inheritance(){return this.tokens.inheritance?v(this.tokens.inheritance.value):null}*validate(e){for(const t of this.members)t.validate&&(yield*t.validate(e))}}class B extends i{static parse(e){const t={};if(t.base=e.consume("const"),!t.base)return;let n=A(e);if(!n){const t=e.consume("identifier")||e.error("Const lacks a type");n=new l({source:e.source,tokens:{base:t}})}e.probe("?")&&e.error("Unexpected nullable constant type"),n.type="const-type",t.name=e.consume("identifier")||e.error("Const lacks a name"),t.assign=e.consume("=")||e.error("Const lacks value assignment"),t.value=w(e)||e.error("Const lacks a value"),t.termination=e.consume(";")||e.error("Unterminated const, expected `;`");const r=new B({source:e.source,tokens:t});return r.idlType=n,r}get type(){return"const"}get name(){return unescape(this.tokens.name.value)}get value(){return T(this.tokens.value)}}class Z extends i{static parse(e){const t=e.position,n={},r=new Z({source:e.source,tokens:n});if(n.readonly=e.consume("readonly"),n.readonly||(n.async=e.consume("async")),n.base=n.readonly?e.consume("maplike","setlike"):n.async?e.consume("iterable"):e.consume("iterable","maplike","setlike"),!n.base)return void e.unconsume(t);const{type:s}=r,o="maplike"===s||r.async,i=o||"iterable"===s;n.open=e.consume("<")||e.error(`Missing less-than sign \`<\` in ${s} declaration`);const a=$(e)||e.error(`Missing a type argument in ${s} declaration`);return r.idlType=[a],i&&(a.tokens.separator=e.consume(","),a.tokens.separator?r.idlType.push($(e)):o&&e.error(`Missing second type argument in ${s} declaration`)),n.close=e.consume(">")||e.error(`Missing greater-than sign \`>\` in ${s} declaration`),n.termination=e.consume(";")||e.error(`Missing semicolon after ${s} declaration`),r}get type(){return this.tokens.base.value}get readonly(){return!!this.tokens.readonly}get async(){return!!this.tokens.async}}class V extends i{static parse(e){const t=e.consume("constructor");if(!t)return;const n={base:t};n.open=e.consume("(")||e.error("No argument list in constructor");const r=N(e);n.close=e.consume(")")||e.error("Unterminated constructor"),n.termination=e.consume(";")||e.error("No semicolon after constructor");const s=new V({tokens:n});return s.arguments=r,s}get type(){return"constructor"}*validate(e){this.idlType&&(yield*this.idlType.validate(e));for(const t of this.arguments)yield*t.validate(e)}}function J(e){const t=e.consume("static");if(t)return g.parse(e,{special:t})||b.parse(e,{special:t})||e.error("No body in static member")}class X extends L{static parse(e,t,{partial:n=null}={}){const r={partial:n,base:t};return L.parse(e,new X({source:e.source,tokens:r}),{type:"interface",inheritable:!n,allowedMembers:[[B.parse],[V.parse],[J],[M],[Z.parse],[g.parse],[b.parse]]})}get type(){return"interface"}*validate(e){if(yield*this.extAttrs.validate(e),!this.partial&&this.extAttrs.every(e=>"Exposed"!==e.name)&&this.extAttrs.every(e=>"NoInterfaceObject"!==e.name)){const e="Interfaces must have `[Exposed]` extended attribute. To fix, add, for example, `[Exposed=Window]`. Please also consider carefully if your interface should also be exposed in a Worker scope. Refer to the [WebIDL spec section on Exposed](https://heycam.github.io/webidl/#Exposed) for more information.";yield o(this.tokens.name,this,e,{autofix:j(this)})}const t=this.extAttrs.filter(e=>"Constructor"===e.name);for(const e of t){const t="Constructors should now be represented as a `constructor()` operation on the interface instead of `[Constructor]` extended attribute. Refer to the [WebIDL spec section on constructor operations](https://heycam.github.io/webidl/#idl-constructors) for more information.";yield o(e.tokens.name,this,t,{autofix:G(this,e)})}yield*super.validate(e),this.partial||(yield*function*(e,t){const n=new Set(a(t).map(e=>e.name)),r=e.partials.get(t.name)||[],s=e.mixinMap.get(t.name)||[];for(const e of[...r,...s]){const r=a(e);yield*i(r,n,e,t);for(const e of r)n.add(e.name)}function*i(e,t,n,r){for(const s of e){const{name:e}=s;if(e&&t.has(e)){const t=`The operation "${e}" has already been defined for the base interface "${r.name}" either in itself or in a mixin`;yield o(s.tokens.name,n,t)}}}function a(e){return e.members.filter(({type:e})=>"operation"===e)}}(e,this))}}function G(e,t){return()=>{const n=function(e){const t=function(e){const t=e.split("\n");for(const e of t){const t=e.match(/^\s+/);if(t)return t[0]}return""}(e),n=t.includes("\t")?"\t":" ";return t+n}(e.tokens.close.trivia),r=V.parse(new W(`\n${n}constructor();`));r.extAttrs=[],r.arguments=t.arguments,e.members.unshift(r);const{extAttrs:s}=e,o=s.indexOf(t),i=s.splice(o,1);s.length?s.length===o?s[o-1].tokens.separator=void 0:s[o].tokens.name.trivia.trim()||(s[o].tokens.name.trivia=i[0].tokens.name.trivia):s.tokens.open=s.tokens.close=void 0}}class H extends L{static parse(e,t,{partial:n}={}){const r={partial:n,base:t};if(r.mixin=e.consume("mixin"),r.mixin)return L.parse(e,new H({source:e.source,tokens:r}),{type:"interface mixin",allowedMembers:[[B.parse],[M],[g.parse,{noInherit:!0}],[b.parse,{regular:!0}]]})}get type(){return"interface mixin"}}class K extends i{static parse(e){const t={},n=new K({source:e.source,tokens:t});return n.extAttrs=y.parse(e),t.required=e.consume("required"),n.idlType=$(e,"dictionary-type")||e.error("Dictionary member lacks a type"),t.name=e.consume("identifier")||e.error("Dictionary member lacks a name"),n.default=p.parse(e),t.required&&n.default&&e.error("Required member must not have a default"),t.termination=e.consume(";")||e.error("Unterminated dictionary member, expected `;`"),n}get type(){return"field"}get name(){return v(this.tokens.name.value)}get required(){return!!this.tokens.required}*validate(e){yield*this.idlType.validate(e)}}class Q extends L{static parse(e,{partial:t}={}){const n={partial:t};if(n.base=e.consume("dictionary"),n.base)return L.parse(e,new Q({source:e.source,tokens:n}),{type:"dictionary",inheritable:!t,allowedMembers:[[K.parse]]})}get type(){return"dictionary"}}class Y extends L{static parse(e,{partial:t}={}){const n={partial:t};if(n.base=e.consume("namespace"),n.base)return L.parse(e,new Y({source:e.source,tokens:n}),{type:"namespace",allowedMembers:[[g.parse,{noInherit:!0,readonly:!0}],[b.parse,{regular:!0}]]})}get type(){return"namespace"}*validate(e){if(!this.partial&&this.extAttrs.every(e=>"Exposed"!==e.name)){const e="Namespaces must have [Exposed] extended attribute. To fix, add, for example, [Exposed=Window]. Please also consider carefully if your namespace should also be exposed in a Worker scope. Refer to the [WebIDL spec section on Exposed](https://heycam.github.io/webidl/#Exposed) for more information.";yield o(this.tokens.name,this,e,{autofix:j(this)})}yield*super.validate(e)}}class ee extends L{static parse(e,t,{partial:n=null}={}){const r={callback:t};if(r.base=e.consume("interface"),r.base)return L.parse(e,new ee({source:e.source,tokens:r}),{type:"callback interface",inheritable:!n,allowedMembers:[[B.parse],[b.parse,{regular:!0}]]})}get type(){return"callback interface"}}function te(e,t){const n=e.source;function r(t){e.error(t)}function s(...t){return e.consume(...t)}function o(t){const n=s("interface");if(n)return H.parse(e,n,t)||X.parse(e,n,t)||r("Interface has no proper body")}function i(){return function(){const t=s("callback");if(t)return e.probe("interface")?ee.parse(e,t):z.parse(e,t)}()||o()||function(){const t=s("partial");if(t)return Q.parse(e,{partial:t})||o({partial:t})||Y.parse(e,{partial:t})||r("Partial doesn't apply to anything")}()||Q.parse(e)||C.parse(e)||F.parse(e)||R.parse(e)||Y.parse(e)}const a=function(){if(!n.length)return[];const o=[];for(;;){const t=y.parse(e),n=i();if(!n){t.length&&r("Stray extended attributes");break}n.extAttrs=t,o.push(n)}const a=s("eof");return t.concrete&&o.push(a),o}();return e.position<n.length&&r("Unrecognised tokens"),a}function ne(e,t={}){const n=new W(e);return void 0!==t.sourceName&&(n.source.name=t.sourceName),te(n,t)}function re(e){return e}const se={wrap:e=>e.join(""),trivia:re,name:re,reference:re,type:re,generic:re,nameless:re,inheritance:re,definition:re,extendedAttribute:re,extendedAttributeReference:re};function oe(e,{templates:t=se}={}){function n(e,{unescaped:n,context:r}){return n||(n=e.startsWith("_")?e.slice(1):e),t.reference(e,n,r)}function r(e,n=re,...r){if(!e)return"";const s=n(e.value,...r);return t.wrap([t.trivia(e.trivia),s])}function s(e,t){return r(e,n,{context:t})}function o(e,n){return r(e,t.name,n)}function i(e){if(e.union||e.generic)return t.wrap([r(e.tokens.base,t.generic),r(e.tokens.open),...e.subtype.map(a),r(e.tokens.close)]);const s=e.tokens.prefix||e.tokens.base,o=e.tokens.prefix?[e.tokens.prefix.value,t.trivia(e.tokens.base.trivia)]:[],i=n(t.wrap([...o,e.tokens.base.value,r(e.tokens.postfix)]),{unescaped:e.idlType,context:e});return t.wrap([t.trivia(s.trivia),i])}function a(e){return t.wrap([p(e.extAttrs),i(e),r(e.tokens.nullable),r(e.tokens.separator)])}function c(e){return e?t.wrap([r(e.tokens.assign),...e.expression.map(e=>r(e))]):""}function u(e){return t.wrap([p(e.extAttrs),r(e.tokens.optional),t.type(a(e.idlType)),r(e.tokens.variadic),o(e.tokens.name,{data:e}),c(e.default),r(e.tokens.separator)])}function l(e){const{rhsType:n}=e.params;return t.wrap([t.trivia(e.tokens.name.trivia),t.extendedAttribute(t.wrap([t.extendedAttributeReference(e.name),r(e.params.tokens.assign),s(e.params.tokens.secondaryName,e),r(e.params.tokens.open),...e.params.list?e.params.list.map("identifier-list"===n?n=>(function(e,n){return t.wrap([s(e.tokens.value,n),r(e.tokens.separator)])})(n,e):u):[],r(e.params.tokens.close)])),r(e.tokens.separator)])}function p(e){return e.length?t.wrap([r(e.tokens.open),...e.map(l),r(e.tokens.close)]):""}function d(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.callback),r(e.tokens.partial),r(e.tokens.base),r(e.tokens.mixin),o(e.tokens.name,{data:e}),(s=e,s.tokens.inheritance?t.wrap([r(s.tokens.colon),t.trivia(s.tokens.inheritance.trivia),t.inheritance(n(s.tokens.inheritance.value,{context:s}))]):""),r(e.tokens.open),y(e.members,e),r(e.tokens.close),r(e.tokens.termination)]),{data:e});var s}function m(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.readonly),r(e.tokens.async),r(e.tokens.base,t.generic),r(e.tokens.open),t.wrap(e.idlType.map(a)),r(e.tokens.close),r(e.tokens.termination)]),{data:e,parent:n})}t=Object.assign({},se,t);const f={interface:d,"interface mixin":d,namespace:d,operation:function(e,n){const s=e.idlType?[t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.open),t.wrap(e.arguments.map(u)),r(e.tokens.close)]:[];return t.definition(t.wrap([p(e.extAttrs),e.tokens.name?r(e.tokens.special):r(e.tokens.special,t.nameless,{data:e,parent:n}),...s,r(e.tokens.termination)]),{data:e,parent:n})},attribute:function(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.special),r(e.tokens.readonly),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.termination)]),{data:e,parent:n})},constructor:function(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base,t.nameless,{data:e,parent:n}),r(e.tokens.open),t.wrap(e.arguments.map(u)),r(e.tokens.close),r(e.tokens.termination)]),{data:e,parent:n})},dictionary:d,field:function(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.required),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),c(e.default),r(e.tokens.termination)]),{data:e,parent:n})},const:function(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.assign),r(e.tokens.value),r(e.tokens.termination)]),{data:e,parent:n})},typedef:function(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e}),r(e.tokens.termination)]),{data:e})},includes:function(e){return t.definition(t.wrap([p(e.extAttrs),s(e.tokens.target,e),r(e.tokens.includes),s(e.tokens.mixin,e),r(e.tokens.termination)]),{data:e})},callback:function(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),o(e.tokens.name,{data:e}),r(e.tokens.assign),t.type(a(e.idlType)),r(e.tokens.open),...e.arguments.map(u),r(e.tokens.close),r(e.tokens.termination)]),{data:e})},enum:function(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),o(e.tokens.name,{data:e}),r(e.tokens.open),y(e.values,e),r(e.tokens.close),r(e.tokens.termination)]),{data:e})},"enum-value":function(e,n){return t.wrap([t.trivia(e.tokens.value.trivia),t.definition(t.wrap(['"',t.name(e.value,{data:e,parent:n}),'"']),{data:e,parent:n}),r(e.tokens.separator)])},iterable:m,maplike:m,setlike:m,"callback interface":d,eof:function(e){return t.trivia(e.trivia)}};function y(e,n){if(!e)return;const r=e.map(e=>(function(e,t){if(!f[e.type])throw new Error(`Type "${e.type}" is unsupported`);return f[e.type](e,t)})(e,n));return t.wrap(r)}return y(e)}function ie(e,t){const n=new Map,r=e.filter(e=>"includes"===e.type);for(const e of r){const r=t.get(e.includes);if(!r)continue;const s=n.get(e.target);s?s.push(r):n.set(e.target,[r])}return n}function*ae(e){const t=function(e){const t=new Map,n=new Set,r=new Map;for(const s of e)if(s.partial){const e=r.get(s.name);e?e.push(s):r.set(s.name,[s])}else s.name&&(t.has(s.name)?n.add(s):t.set(s.name,s));return{all:e,unique:t,partials:r,duplicates:n,mixinMap:ie(e,t),cache:{typedefIncludesDictionary:new WeakMap}}}(e);for(const e of t.all)e.validate&&(yield*e.validate(t));yield*function*({unique:e,duplicates:t}){for(const n of t){const{name:t}=n,r=`The name "${t}" of type "${e.get(t).type}" was already seen`;yield o(n.tokens.name,n,r)}}(t)}function ce(e){return[...ae((t=e,t.flat?t.flat():[].concat(...t)))];var t}n.d(t,"parse",function(){return ne}),n.d(t,"write",function(){return oe}),n.d(t,"validate",function(){return ce})}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.WebIDL2=t():e.WebIDL2=t()}(this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var s=t[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(r,s,function(t){return e[t]}.bind(null,s));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e,t,n,r,s,{level:o="error",autofix:i,ruleName:a}={}){function c(n){return n>0?e.slice(t,t+n):e.slice(Math.max(t+n,0),t)}function u(n,{precedes:r}={}){const s=n.map(e=>e.trivia+e.value).join(""),o=e[t];return"eof"===o.type?s:r?s+o.trivia:s.slice(o.trivia.length)}const l="eof"!==e[t].type?e[t].line:e.length>1?e[t-1].line:1,p=function(e){const t=e.split("\n");return t[t.length-1]}(u(c(-5),{precedes:!0})),d=c(5),m=u(d),f=p+m.split("\n")[0]+"\n"+(" ".repeat(p.length)+"^"),y="Syntax"===s?"since":"inside",h=`${s} error at line ${l}${e.name?` in ${e.name}`:""}${n&&n.name?`, ${y} \`${n.partial?"partial ":""}${n.type} ${n.name}\``:""}:\n${f}`;return{message:`${h} ${r}`,bareMessage:r,context:h,line:l,sourceName:e.name,level:o,ruleName:a,autofix:i,input:m,tokens:d}}function s(e,t,n,s){return r(e,t,n,s,"Syntax")}function o(e,t,n,s,o={}){return o.ruleName=n,r(t.source,e.index,t,s,"Validation",o)}n.r(t);class i{constructor({source:e,tokens:t}){Object.defineProperties(this,{source:{value:e},tokens:{value:t}})}toJSON(){const e={type:void 0,name:void 0,inheritance:void 0};let t=this;for(;t!==Object.prototype;){const n=Object.getOwnPropertyDescriptors(t);for(const[t,r]of Object.entries(n))(r.enumerable||r.get)&&(e[t]=this[t]);t=Object.getPrototypeOf(t)}return e}}function a(e,t,{useNullableInner:n}={}){if(!e.union){const r=t.unique.get(e.idlType);if(!r)return;if("typedef"===r.type){const{typedefIncludesDictionary:n}=t.cache;if(n.has(r))return n.get(r);t.cache.typedefIncludesDictionary.set(r,void 0);const s=a(r.idlType,t);if(t.cache.typedefIncludesDictionary.set(r,s),s)return e}if("dictionary"===r.type&&(n||!e.nullable))return e}for(const n of e.subtype){const e=a(n,t);if(e)return n.union?e:n}}function c(e,t){const n=e.consume("?");n&&(t.tokens.nullable=n),e.probe("?")&&e.error("Can't nullable more than once")}function u(e,t){let n=function(e,t){const n=e.consume("FrozenArray","Promise","sequence","record");if(!n)return;const r=new l({source:e.source,tokens:{base:n}});switch(r.tokens.open=e.consume("<")||e.error(`No opening bracket after ${n.type}`),n.type){case"Promise":{e.probe("[")&&e.error("Promise type cannot have extended attribute");const n=I(e,t)||e.error("Missing Promise subtype");r.subtype.push(n);break}case"sequence":case"FrozenArray":{const s=$(e,t)||e.error(`Missing ${n.type} subtype`);r.subtype.push(s);break}case"record":{e.probe("[")&&e.error("Record key cannot have extended attribute");const n=e.consume(...E)||e.error(`Record key must be one of: ${E.join(", ")}`),s=new l({source:e.source,tokens:{base:n}});s.tokens.separator=e.consume(",")||e.error("Missing comma after record key type"),s.type=t;const o=$(e,t)||e.error("Error parsing generic type record");r.subtype.push(s,o);break}}return r.idlType||e.error(`Error parsing generic type ${n.type}`),r.tokens.close=e.consume(">")||e.error(`Missing closing bracket after ${n.type}`),r}(e,t)||A(e);if(!n){const t=e.consume("identifier",...E);if(!t)return;n=new l({source:e.source,tokens:{base:t}}),e.probe("<")&&e.error(`Unsupported generic type ${t.value}`)}return"Promise"===n.generic&&e.probe("?")&&e.error("Promise type cannot be nullable"),n.type=t||null,c(e,n),n.nullable&&"any"===n.idlType&&e.error("Type `any` cannot be made nullable"),n}class l extends i{static parse(e,t){return u(e,t)||function(e,t){const n={};if(n.open=e.consume("("),!n.open)return;const r=new l({source:e.source,tokens:n});for(r.type=t||null;;){const t=$(e)||e.error("No type after open parenthesis or 'or' in union type");"any"===t.idlType&&e.error("Type `any` cannot be included in a union type"),r.subtype.push(t);const n=e.consume("or");if(!n)break;t.tokens.separator=n}return r.idlType.length<2&&e.error("At least two types are expected in a union type but found less"),n.close=e.consume(")")||e.error("Unterminated union type"),c(e,r),r}(e,t)}constructor({source:e,tokens:t}){super({source:e,tokens:t}),Object.defineProperty(this,"subtype",{value:[]}),this.extAttrs=[]}get generic(){return this.subtype.length&&this.tokens.base?this.tokens.base.value:""}get nullable(){return Boolean(this.tokens.nullable)}get union(){return Boolean(this.subtype.length)&&!this.tokens.base}get idlType(){if(this.subtype.length)return this.subtype;return v([this.tokens.prefix,this.tokens.base,this.tokens.postfix].filter(e=>e).map(e=>e.value).join(" "))}*validate(e){const t=!this.union&&e.unique.get(this.idlType),n=this.union?this:t&&"typedef"===t.type?t.idlType:void 0;if(n&&this.nullable){const t=a(n,e);if(t){const e=(this.union?t:this).tokens.base,n="Nullable union cannot include a dictionary type";yield o(e,this,"no-nullable-union-dict",n)}}else for(const t of this.subtype)yield*t.validate(e)}}class p extends i{static parse(e){const t=e.consume("=");if(!t)return null;const n=w(e)||e.consume("string","null","[","{")||e.error("No value for default"),r=[n];if("["===n.type){const t=e.consume("]")||e.error("Default sequence value must be empty");r.push(t)}else if("{"===n.type){const t=e.consume("}")||e.error("Default dictionary value must be empty");r.push(t)}return new p({source:e.source,tokens:{assign:t},expression:r})}constructor({source:e,tokens:t,expression:n}){super({source:e,tokens:t}),Object.defineProperty(this,"expression",{value:n})}get type(){return T(this.expression[0]).type}get value(){return T(this.expression[0]).value}get negative(){return T(this.expression[0]).negative}}class d extends Array{constructor({source:e,tokens:t}){super(),Object.defineProperties(this,{source:{value:e},tokens:{value:t}})}}class m extends i{static parse(e){const t={assign:e.consume("=")},n=new m({source:e.source,tokens:t});return t.assign&&(t.secondaryName=e.consume("identifier","decimal","integer","string")),t.open=e.consume("("),t.open?(n.list="identifier-list"===n.rhsType?function(e){const t=x(e,{parser:k.parser(e,"identifier"),listName:"identifier list"});t.length||e.error("Expected identifiers but none found");return t}(e):N(e),t.close=e.consume(")")||e.error("Unexpected token in extended attribute argument list")):n.hasRhs&&!t.secondaryName&&e.error("No right hand side to extended attribute assignment"),n}get rhsType(){return this.tokens.assign?this.tokens.secondaryName?this.tokens.secondaryName.type:"identifier-list":null}}class f extends i{static parse(e){const t=e.consume("identifier");if(t)return new f({source:e.source,tokens:{name:t},params:m.parse(e)})}constructor({source:e,tokens:t,params:n}){super({source:e,tokens:t}),Object.defineProperty(this,"params",{value:n})}get type(){return"extended-attribute"}get name(){return this.tokens.name.value}get rhs(){const{rhsType:e,tokens:t,list:n}=this.params;return e?{type:e,value:"identifier-list"===e?n:t.secondaryName.value}:null}get arguments(){const{rhsType:e,list:t}=this.params;return t&&"identifier-list"!==e?t:[]}*validate(e){if("NoInterfaceObject"===this.name){const e="`[NoInterfaceObject]` extended attribute is an undesirable feature that may be removed from Web IDL in the future. Refer to the [relevant upstream PR](https://github.com/heycam/webidl/pull/609) for more information.";yield o(this.tokens.name,this,"no-nointerfaceobject",e,{level:"warning"})}for(const t of this.arguments)yield*t.validate(e)}}class y extends d{static parse(e){const t={};if(t.open=e.consume("["),!t.open)return new y({});const n=new y({source:e.source,tokens:t});return n.push(...x(e,{parser:f.parse,listName:"extended attribute"})),t.close=e.consume("]")||e.error("Unexpected closing token of extended attribute"),n.length||e.error("Found an empty extended attribute"),e.probe("[")&&e.error("Illegal double extended attribute lists, consider merging them"),n}*validate(e){for(const t of this)yield*t.validate(e)}}class h extends i{static parse(e){const t=e.position,n={},r=new h({source:e.source,tokens:n});return r.extAttrs=y.parse(e),n.optional=e.consume("optional"),r.idlType=$(e,"argument-type"),r.idlType?(n.optional||(n.variadic=e.consume("...")),n.name=e.consume("identifier",...q),n.name?(r.default=n.optional?p.parse(e):null,r):e.unconsume(t)):e.unconsume(t)}get type(){return"argument"}get optional(){return!!this.tokens.optional}get variadic(){return!!this.tokens.variadic}get name(){return v(this.tokens.name.value)}*validate(e){if(yield*this.idlType.validate(e),a(this.idlType,e,{useNullableInner:!0}))if(this.idlType.nullable){const e="Dictionary arguments cannot be nullable.";yield o(this.tokens.name,this,"no-nullable-dict-arg",e)}else if(this.optional&&!this.default){const e="Optional dictionary arguments must have a default value of `{}`.";yield o(this.tokens.name,this,"dict-arg-default",e,{autofix:(t=this,()=>{t.default=p.parse(new S(" = {}"))})})}var t}}class k extends i{static parser(e,t){return()=>{const n=e.consume(t);if(n)return new k({source:e.source,tokens:{value:n}})}}get value(){return this.tokens.value.value}}class b extends i{static parse(e,{special:t,regular:n}={}){const r={special:t},s=new b({source:e.source,tokens:r});return t&&"stringifier"===t.value&&(r.termination=e.consume(";"),r.termination)?(s.arguments=[],s):(t||n||(r.special=e.consume("getter","setter","deleter")),s.idlType=I(e)||e.error("Missing return type"),r.name=e.consume("identifier","includes"),r.open=e.consume("(")||e.error("Invalid operation"),s.arguments=N(e),r.close=e.consume(")")||e.error("Unterminated operation"),r.termination=e.consume(";")||e.error("Unterminated operation, expected `;`"),s)}get type(){return"operation"}get name(){const{name:e}=this.tokens;return e?v(e.value):""}get special(){return this.tokens.special?this.tokens.special.value:""}*validate(e){if(!this.name&&["","static"].includes(this.special)){const e="Regular or static operations must have both a return type and an identifier.";yield o(this.tokens.open,this,"incomplete-op",e)}this.idlType&&(yield*this.idlType.validate(e));for(const t of this.arguments)yield*t.validate(e)}}class g extends i{static parse(e,{special:t,noInherit:n=!1,readonly:r=!1}={}){const s=e.position,o={special:t},i=new g({source:e.source,tokens:o});if(t||n||(o.special=e.consume("inherit")),"inherit"===i.special&&e.probe("readonly")&&e.error("Inherited attributes cannot be read-only"),o.readonly=e.consume("readonly"),r&&!o.readonly&&e.probe("attribute")&&e.error("Attributes must be readonly in this context"),o.base=e.consume("attribute"),o.base){switch(i.idlType=$(e,"attribute-type")||e.error("Attribute lacks a type"),i.idlType.generic){case"sequence":case"record":e.error(`Attributes cannot accept ${i.idlType.generic} types`)}return o.name=e.consume("identifier","async","required")||e.error("Attribute lacks a name"),o.termination=e.consume(";")||e.error("Unterminated attribute, expected `;`"),i}e.unconsume(s)}get type(){return"attribute"}get special(){return this.tokens.special?this.tokens.special.value:""}get readonly(){return!!this.tokens.readonly}get name(){return v(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}function v(e){return e.startsWith("_")?e.slice(1):e}function x(e,{parser:t,allowDangler:n,listName:r="list"}){const s=t(e);if(!s)return[];s.tokens.separator=e.consume(",");const o=[s];for(;s.tokens.separator;){const s=t(e);if(!s){n||e.error(`Trailing comma in ${r}`);break}if(s.tokens.separator=e.consume(","),o.push(s),!s.tokens.separator)break}return o}function w(e){return e.consume("true","false","Infinity","-Infinity","NaN","decimal","integer")}function T({type:e,value:t}){switch(e){case"true":case"false":return{type:"boolean",value:"true"===e};case"Infinity":case"-Infinity":return{type:"Infinity",negative:e.startsWith("-")};case"[":return{type:"sequence",value:[]};case"{":return{type:"dictionary"};case"decimal":case"integer":return{type:"number",value:t};case"string":return{type:"string",value:t.slice(1,-1)};default:return{type:e}}}function A(e){const{source:t}=e,n=function(){const n=e.consume("unsigned"),r=e.consume("short","long");if(r){const s=e.consume("long");return new l({source:t,tokens:{prefix:n,base:r,postfix:s}})}n&&e.error("Failed to parse integer type")}()||function(){const n=e.consume("unrestricted"),r=e.consume("float","double");if(r)return new l({source:t,tokens:{prefix:n,base:r}});n&&e.error("Failed to parse float type")}();if(n)return n;const r=e.consume("boolean","byte","octet");return r?new l({source:t,tokens:{base:r}}):void 0}function N(e){return x(e,{parser:h.parse,listName:"arguments list"})}function $(e,t){const n=y.parse(e),r=l.parse(e,t);return r&&(r.extAttrs=n),r}function I(e,t){const n=l.parse(e,t||"return-type");if(n)return n;const r=e.consume("void");if(r){const t=new l({source:e.source,tokens:{base:r}});return t.type="return-type",t}}function M(e){const t=e.consume("stringifier");if(t)return g.parse(e,{special:t})||b.parse(e,{special:t})||e.error("Unterminated stringifier")}function j(e){const t=e.split("\n");if(t.length){const e=t[t.length-1].match(/^\s+/);if(e)return e[0]}return""}function O(e){return()=>{if(e.extAttrs.length){const t=new S("Exposed=Window,"),n=f.parse(t);n.tokens.separator=t.consume(",");const r=e.extAttrs[0];/^\s/.test(r.tokens.name.trivia)||(r.tokens.name.trivia=` ${r.tokens.name.trivia}`),e.extAttrs.unshift(n)}else{e.extAttrs=y.parse(new S("[Exposed=Window]"));const t=e.tokens.base.trivia;e.extAttrs.tokens.open.trivia=t,e.tokens.base.trivia=`\n${j(t)}`}}}const P={decimal:/-?(?=[0-9]*\.|[0-9]+[eE])(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0-9]+)?|[0-9]+[Ee][-+]?[0-9]+)/y,integer:/-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/y,identifier:/[_-]?[A-Za-z][0-9A-Z_a-z-]*/y,string:/"[^"]*"/y,whitespace:/[\t\n\r ]+/y,comment:/((\/(\/.*|\*([^*]|\*[^\/])*\*\/)[\t\n\r ]*)+)/y,other:/[^\t\n\r 0-9A-Za-z]/y},E=["ByteString","DOMString","USVString"],q=["async","attribute","callback","const","constructor","deleter","dictionary","enum","getter","includes","inherit","interface","iterable","maplike","namespace","partial","required","setlike","setter","static","stringifier","typedef","unrestricted"],D=["-Infinity","FrozenArray","Infinity","NaN","Promise","async","boolean","byte","constructor","double","false","float","long","mixin","null","octet","optional","or","readonly","record","sequence","short","true","unsigned","void"].concat(q,E),U=["(",")",",","...",":",";","<","=",">","?","[","]","{","}"],W=["_constructor","toString","_toString"];class S{constructor(e){this.source=function(e){const t=[];let n=0,r="",o=1,i=0;for(;n<e.length;){const c=e.charAt(n);let u=-1;if(/[\t\n\r ]/.test(c)?u=a("whitespace",{noFlushTrivia:!0}):"/"===c&&(u=a("comment",{noFlushTrivia:!0})),-1!==u){const e=t.pop().value;o+=(e.match(/\n/g)||[]).length,r+=e,i-=1}else if(/[-0-9.A-Z_a-z]/.test(c)){if(-1===(u=a("decimal"))&&(u=a("integer")),-1===u){u=a("identifier");const e=t.length-1,n=t[e];if(-1!==u){if(W.includes(n.value)){const r=`${v(n.value)} is a reserved identifier and must not be used.`;throw new _(s(t,e,null,r))}D.includes(n.value)&&(n.type=n.value)}}}else'"'===c&&(u=a("string"));for(const s of U)if(e.startsWith(s,n)){t.push({type:s,value:s,trivia:r,line:o,index:i}),r="",u=n+=s.length;break}if(-1===u&&(u=a("other")),-1===u)throw new Error("Token stream not progressing");n=u,i+=1}return t.push({type:"eof",value:"",trivia:r}),t;function a(s,{noFlushTrivia:a}={}){const c=P[s];c.lastIndex=n;const u=c.exec(e);return u?(t.push({type:s,value:u[0],trivia:r,line:o,index:i}),a||(r=""),c.lastIndex):-1}}(e),this.position=0}error(e){throw new _(s(this.source,this.position,this.current,e))}probe(e){return this.source.length>this.position&&this.source[this.position].type===e}consume(...e){for(const t of e){if(!this.probe(t))continue;const e=this.source[this.position];return this.position++,e}}unconsume(e){this.position=e}}class _ extends Error{constructor({message:e,bareMessage:t,context:n,line:r,sourceName:s,input:o,tokens:i}){super(e),this.name="WebIDLParseError",this.bareMessage=t,this.context=n,this.line=r,this.sourceName=s,this.input=o,this.tokens=i}}class C extends k{static parse(e){const t=e.consume("string");if(t)return new C({source:e.source,tokens:{value:t}})}get type(){return"enum-value"}get value(){return super.value.slice(1,-1)}}class R extends i{static parse(e){const t={};if(t.base=e.consume("enum"),!t.base)return;t.name=e.consume("identifier")||e.error("No name for enum");const n=e.current=new R({source:e.source,tokens:t});return t.open=e.consume("{")||e.error("Bodyless enum"),n.values=x(e,{parser:C.parse,allowDangler:!0,listName:"enumeration"}),e.probe("string")&&e.error("No comma between enum values"),t.close=e.consume("}")||e.error("Unexpected value in enum"),n.values.length||e.error("No value in enum"),t.termination=e.consume(";")||e.error("No semicolon after enum"),n}get type(){return"enum"}get name(){return v(this.tokens.name.value)}}class F extends i{static parse(e){const t=e.consume("identifier");if(!t)return;const n={target:t};if(n.includes=e.consume("includes"),n.includes)return n.mixin=e.consume("identifier")||e.error("Incomplete includes statement"),n.termination=e.consume(";")||e.error("No terminating ; for includes statement"),new F({source:e.source,tokens:n});e.unconsume(t.index)}get type(){return"includes"}get target(){return v(this.tokens.target.value)}get includes(){return v(this.tokens.mixin.value)}}class z extends i{static parse(e){const t={},n=new z({source:e.source,tokens:t});if(t.base=e.consume("typedef"),t.base)return n.idlType=$(e,"typedef-type")||e.error("Typedef lacks a type"),t.name=e.consume("identifier")||e.error("Typedef lacks a name"),e.current=n,t.termination=e.consume(";")||e.error("Unterminated typedef, expected `;`"),n}get type(){return"typedef"}get name(){return v(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}class L extends i{static parse(e,t){const n={base:t},r=new L({source:e.source,tokens:n});return n.name=e.consume("identifier")||e.error("Callback lacks a name"),e.current=r,n.assign=e.consume("=")||e.error("Callback lacks an assignment"),r.idlType=I(e)||e.error("Callback lacks a return type"),n.open=e.consume("(")||e.error("Callback lacks parentheses for arguments"),r.arguments=N(e),n.close=e.consume(")")||e.error("Unterminated callback"),n.termination=e.consume(";")||e.error("Unterminated callback, expected `;`"),r}get type(){return"callback"}get name(){return v(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}class B extends i{static parse(e,t,{type:n,inheritable:r,allowedMembers:s}){const{tokens:o}=t;for(o.name=e.consume("identifier")||e.error(`Missing name in ${t.type}`),e.current=t,r&&Object.assign(o,function(e){const t=e.consume(":");return t?{colon:t,inheritance:e.consume("identifier")||e.error("Inheritance lacks a type")}:{}}(e)),o.open=e.consume("{")||e.error(`Bodyless ${n}`),t.members=[];;){if(o.close=e.consume("}"),o.close)return o.termination=e.consume(";")||e.error(`Missing semicolon after ${n}`),t;const r=y.parse(e);let i;for(const[t,...n]of s)if(i=t(e,...n))break;i||e.error("Unknown member"),i.extAttrs=r,t.members.push(i)}}get partial(){return!!this.tokens.partial}get name(){return v(this.tokens.name.value)}get inheritance(){return this.tokens.inheritance?v(this.tokens.inheritance.value):null}*validate(e){for(const t of this.members)t.validate&&(yield*t.validate(e))}}class Z extends i{static parse(e){const t={};if(t.base=e.consume("const"),!t.base)return;let n=A(e);if(!n){const t=e.consume("identifier")||e.error("Const lacks a type");n=new l({source:e.source,tokens:{base:t}})}e.probe("?")&&e.error("Unexpected nullable constant type"),n.type="const-type",t.name=e.consume("identifier")||e.error("Const lacks a name"),t.assign=e.consume("=")||e.error("Const lacks value assignment"),t.value=w(e)||e.error("Const lacks a value"),t.termination=e.consume(";")||e.error("Unterminated const, expected `;`");const r=new Z({source:e.source,tokens:t});return r.idlType=n,r}get type(){return"const"}get name(){return unescape(this.tokens.name.value)}get value(){return T(this.tokens.value)}}class V extends i{static parse(e){const t=e.position,n={},r=new V({source:e.source,tokens:n});if(n.readonly=e.consume("readonly"),n.readonly||(n.async=e.consume("async")),n.base=n.readonly?e.consume("maplike","setlike"):n.async?e.consume("iterable"):e.consume("iterable","maplike","setlike"),!n.base)return void e.unconsume(t);const{type:s}=r,o="maplike"===s||r.async,i=o||"iterable"===s;n.open=e.consume("<")||e.error(`Missing less-than sign \`<\` in ${s} declaration`);const a=$(e)||e.error(`Missing a type argument in ${s} declaration`);return r.idlType=[a],i&&(a.tokens.separator=e.consume(","),a.tokens.separator?r.idlType.push($(e)):o&&e.error(`Missing second type argument in ${s} declaration`)),n.close=e.consume(">")||e.error(`Missing greater-than sign \`>\` in ${s} declaration`),n.termination=e.consume(";")||e.error(`Missing semicolon after ${s} declaration`),r}get type(){return this.tokens.base.value}get readonly(){return!!this.tokens.readonly}get async(){return!!this.tokens.async}}class J extends i{static parse(e){const t=e.consume("constructor");if(!t)return;const n={base:t};n.open=e.consume("(")||e.error("No argument list in constructor");const r=N(e);n.close=e.consume(")")||e.error("Unterminated constructor"),n.termination=e.consume(";")||e.error("No semicolon after constructor");const s=new J({tokens:n});return s.arguments=r,s}get type(){return"constructor"}*validate(e){this.idlType&&(yield*this.idlType.validate(e));for(const t of this.arguments)yield*t.validate(e)}}function X(e){const t=e.consume("static");if(t)return g.parse(e,{special:t})||b.parse(e,{special:t})||e.error("No body in static member")}class G extends B{static parse(e,t,{partial:n=null}={}){const r={partial:n,base:t};return B.parse(e,new G({source:e.source,tokens:r}),{type:"interface",inheritable:!n,allowedMembers:[[Z.parse],[J.parse],[X],[M],[V.parse],[g.parse],[b.parse]]})}get type(){return"interface"}*validate(e){if(yield*this.extAttrs.validate(e),!this.partial&&this.extAttrs.every(e=>"Exposed"!==e.name)&&this.extAttrs.every(e=>"NoInterfaceObject"!==e.name)){const e="Interfaces must have `[Exposed]` extended attribute. To fix, add, for example, `[Exposed=Window]`. Please also consider carefully if your interface should also be exposed in a Worker scope. Refer to the [WebIDL spec section on Exposed](https://heycam.github.io/webidl/#Exposed) for more information.";yield o(this.tokens.name,this,"require-exposed",e,{autofix:O(this)})}const t=this.extAttrs.filter(e=>"Constructor"===e.name);for(const e of t){const t="Constructors should now be represented as a `constructor()` operation on the interface instead of `[Constructor]` extended attribute. Refer to the [WebIDL spec section on constructor operations](https://heycam.github.io/webidl/#idl-constructors) for more information.";yield o(e.tokens.name,this,"constructor-member",t,{autofix:H(this,e)})}yield*super.validate(e),this.partial||(yield*function*(e,t){const n=new Set(a(t).map(e=>e.name)),r=e.partials.get(t.name)||[],s=e.mixinMap.get(t.name)||[];for(const e of[...r,...s]){const r=a(e);yield*i(r,n,e,t);for(const e of r)n.add(e.name)}function*i(e,t,n,r){for(const s of e){const{name:e}=s;if(e&&t.has(e)){const t=`The operation "${e}" has already been defined for the base interface "${r.name}" either in itself or in a mixin`;yield o(s.tokens.name,n,"no-cross-overload",t)}}}function a(e){return e.members.filter(({type:e})=>"operation"===e)}}(e,this))}}function H(e,t){return()=>{const n=j(e.extAttrs.tokens.open.trivia),r=e.members.length?j(function e(t){if(t.extAttrs.length)return t.extAttrs.tokens.open;if("operation"===t.type)return e(t.idlType);return Object.values(t.tokens).sort((e,t)=>e.index-t.index)[0]}(e.members[0]).trivia):function(e){const t=j(e),n=t.includes("\t")?"\t":" ";return t+n}(n),s=J.parse(new S(`\n${r}constructor();`));s.extAttrs=[],s.arguments=t.arguments;const o=e.members.findIndex(e=>"constructor"===e.type);e.members.splice(o+1,0,s);const{close:i}=e.tokens;i.trivia.includes("\n")||(i.trivia+=`\n${n}`);const{extAttrs:a}=e,c=a.indexOf(t),u=a.splice(c,1);a.length?a.length===c?a[c-1].tokens.separator=void 0:a[c].tokens.name.trivia.trim()||(a[c].tokens.name.trivia=u[0].tokens.name.trivia):a.tokens.open=a.tokens.close=void 0}}class K extends B{static parse(e,t,{partial:n}={}){const r={partial:n,base:t};if(r.mixin=e.consume("mixin"),r.mixin)return B.parse(e,new K({source:e.source,tokens:r}),{type:"interface mixin",allowedMembers:[[Z.parse],[M],[g.parse,{noInherit:!0}],[b.parse,{regular:!0}]]})}get type(){return"interface mixin"}}class Q extends i{static parse(e){const t={},n=new Q({source:e.source,tokens:t});return n.extAttrs=y.parse(e),t.required=e.consume("required"),n.idlType=$(e,"dictionary-type")||e.error("Dictionary member lacks a type"),t.name=e.consume("identifier")||e.error("Dictionary member lacks a name"),n.default=p.parse(e),t.required&&n.default&&e.error("Required member must not have a default"),t.termination=e.consume(";")||e.error("Unterminated dictionary member, expected `;`"),n}get type(){return"field"}get name(){return v(this.tokens.name.value)}get required(){return!!this.tokens.required}*validate(e){yield*this.idlType.validate(e)}}class Y extends B{static parse(e,{partial:t}={}){const n={partial:t};if(n.base=e.consume("dictionary"),n.base)return B.parse(e,new Y({source:e.source,tokens:n}),{type:"dictionary",inheritable:!t,allowedMembers:[[Q.parse]]})}get type(){return"dictionary"}}class ee extends B{static parse(e,{partial:t}={}){const n={partial:t};if(n.base=e.consume("namespace"),n.base)return B.parse(e,new ee({source:e.source,tokens:n}),{type:"namespace",allowedMembers:[[g.parse,{noInherit:!0,readonly:!0}],[b.parse,{regular:!0}]]})}get type(){return"namespace"}*validate(e){if(!this.partial&&this.extAttrs.every(e=>"Exposed"!==e.name)){const e="Namespaces must have [Exposed] extended attribute. To fix, add, for example, [Exposed=Window]. Please also consider carefully if your namespace should also be exposed in a Worker scope. Refer to the [WebIDL spec section on Exposed](https://heycam.github.io/webidl/#Exposed) for more information.";yield o(this.tokens.name,this,"require-exposed",e,{autofix:O(this)})}yield*super.validate(e)}}class te extends B{static parse(e,t,{partial:n=null}={}){const r={callback:t};if(r.base=e.consume("interface"),r.base)return B.parse(e,new te({source:e.source,tokens:r}),{type:"callback interface",inheritable:!n,allowedMembers:[[Z.parse],[b.parse,{regular:!0}]]})}get type(){return"callback interface"}}function ne(e,t){const n=e.source;function r(t){e.error(t)}function s(...t){return e.consume(...t)}function o(t){const n=s("interface");if(n)return K.parse(e,n,t)||G.parse(e,n,t)||r("Interface has no proper body")}function i(){return function(){const t=s("callback");if(t)return e.probe("interface")?te.parse(e,t):L.parse(e,t)}()||o()||function(){const t=s("partial");if(t)return Y.parse(e,{partial:t})||o({partial:t})||ee.parse(e,{partial:t})||r("Partial doesn't apply to anything")}()||Y.parse(e)||R.parse(e)||z.parse(e)||F.parse(e)||ee.parse(e)}const a=function(){if(!n.length)return[];const o=[];for(;;){const t=y.parse(e),n=i();if(!n){t.length&&r("Stray extended attributes");break}n.extAttrs=t,o.push(n)}const a=s("eof");return t.concrete&&o.push(a),o}();return e.position<n.length&&r("Unrecognised tokens"),a}function re(e,t={}){const n=new S(e);return void 0!==t.sourceName&&(n.source.name=t.sourceName),ne(n,t)}function se(e){return e}const oe={wrap:e=>e.join(""),trivia:se,name:se,reference:se,type:se,generic:se,nameless:se,inheritance:se,definition:se,extendedAttribute:se,extendedAttributeReference:se};function ie(e,{templates:t=oe}={}){function n(e,{unescaped:n,context:r}){return n||(n=e.startsWith("_")?e.slice(1):e),t.reference(e,n,r)}function r(e,n=se,...r){if(!e)return"";const s=n(e.value,...r);return t.wrap([t.trivia(e.trivia),s])}function s(e,t){return r(e,n,{context:t})}function o(e,n){return r(e,t.name,n)}function i(e){if(e.union||e.generic)return t.wrap([r(e.tokens.base,t.generic),r(e.tokens.open),...e.subtype.map(a),r(e.tokens.close)]);const s=e.tokens.prefix||e.tokens.base,o=e.tokens.prefix?[e.tokens.prefix.value,t.trivia(e.tokens.base.trivia)]:[],i=n(t.wrap([...o,e.tokens.base.value,r(e.tokens.postfix)]),{unescaped:e.idlType,context:e});return t.wrap([t.trivia(s.trivia),i])}function a(e){return t.wrap([p(e.extAttrs),i(e),r(e.tokens.nullable),r(e.tokens.separator)])}function c(e){return e?t.wrap([r(e.tokens.assign),...e.expression.map(e=>r(e))]):""}function u(e){return t.wrap([p(e.extAttrs),r(e.tokens.optional),t.type(a(e.idlType)),r(e.tokens.variadic),o(e.tokens.name,{data:e}),c(e.default),r(e.tokens.separator)])}function l(e){const{rhsType:n}=e.params;return t.wrap([t.trivia(e.tokens.name.trivia),t.extendedAttribute(t.wrap([t.extendedAttributeReference(e.name),r(e.params.tokens.assign),s(e.params.tokens.secondaryName,e),r(e.params.tokens.open),...e.params.list?e.params.list.map("identifier-list"===n?n=>(function(e,n){return t.wrap([s(e.tokens.value,n),r(e.tokens.separator)])})(n,e):u):[],r(e.params.tokens.close)])),r(e.tokens.separator)])}function p(e){return e.length?t.wrap([r(e.tokens.open),...e.map(l),r(e.tokens.close)]):""}function d(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.callback),r(e.tokens.partial),r(e.tokens.base),r(e.tokens.mixin),o(e.tokens.name,{data:e}),(s=e,s.tokens.inheritance?t.wrap([r(s.tokens.colon),t.trivia(s.tokens.inheritance.trivia),t.inheritance(n(s.tokens.inheritance.value,{context:s}))]):""),r(e.tokens.open),y(e.members,e),r(e.tokens.close),r(e.tokens.termination)]),{data:e});var s}function m(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.readonly),r(e.tokens.async),r(e.tokens.base,t.generic),r(e.tokens.open),t.wrap(e.idlType.map(a)),r(e.tokens.close),r(e.tokens.termination)]),{data:e,parent:n})}t=Object.assign({},oe,t);const f={interface:d,"interface mixin":d,namespace:d,operation:function(e,n){const s=e.idlType?[t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.open),t.wrap(e.arguments.map(u)),r(e.tokens.close)]:[];return t.definition(t.wrap([p(e.extAttrs),e.tokens.name?r(e.tokens.special):r(e.tokens.special,t.nameless,{data:e,parent:n}),...s,r(e.tokens.termination)]),{data:e,parent:n})},attribute:function(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.special),r(e.tokens.readonly),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.termination)]),{data:e,parent:n})},constructor:function(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base,t.nameless,{data:e,parent:n}),r(e.tokens.open),t.wrap(e.arguments.map(u)),r(e.tokens.close),r(e.tokens.termination)]),{data:e,parent:n})},dictionary:d,field:function(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.required),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),c(e.default),r(e.tokens.termination)]),{data:e,parent:n})},const:function(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.assign),r(e.tokens.value),r(e.tokens.termination)]),{data:e,parent:n})},typedef:function(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e}),r(e.tokens.termination)]),{data:e})},includes:function(e){return t.definition(t.wrap([p(e.extAttrs),s(e.tokens.target,e),r(e.tokens.includes),s(e.tokens.mixin,e),r(e.tokens.termination)]),{data:e})},callback:function(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),o(e.tokens.name,{data:e}),r(e.tokens.assign),t.type(a(e.idlType)),r(e.tokens.open),...e.arguments.map(u),r(e.tokens.close),r(e.tokens.termination)]),{data:e})},enum:function(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),o(e.tokens.name,{data:e}),r(e.tokens.open),y(e.values,e),r(e.tokens.close),r(e.tokens.termination)]),{data:e})},"enum-value":function(e,n){return t.wrap([t.trivia(e.tokens.value.trivia),t.definition(t.wrap(['"',t.name(e.value,{data:e,parent:n}),'"']),{data:e,parent:n}),r(e.tokens.separator)])},iterable:m,maplike:m,setlike:m,"callback interface":d,eof:function(e){return t.trivia(e.trivia)}};function y(e,n){if(!e)return;const r=e.map(e=>(function(e,t){if(!f[e.type])throw new Error(`Type "${e.type}" is unsupported`);return f[e.type](e,t)})(e,n));return t.wrap(r)}return y(e)}function ae(e,t){const n=new Map,r=e.filter(e=>"includes"===e.type);for(const e of r){const r=t.get(e.includes);if(!r)continue;const s=n.get(e.target);s?s.push(r):n.set(e.target,[r])}return n}function*ce(e){const t=function(e){const t=new Map,n=new Set,r=new Map;for(const s of e)if(s.partial){const e=r.get(s.name);e?e.push(s):r.set(s.name,[s])}else s.name&&(t.has(s.name)?n.add(s):t.set(s.name,s));return{all:e,unique:t,partials:r,duplicates:n,mixinMap:ae(e,t),cache:{typedefIncludesDictionary:new WeakMap}}}(e);for(const e of t.all)e.validate&&(yield*e.validate(t));yield*function*({unique:e,duplicates:t}){for(const n of t){const{name:t}=n,r=`The name "${t}" of type "${e.get(t).type}" was already seen`;yield o(n.tokens.name,n,"no-duplicate",r)}}(t)}function ue(e){return[...ce((t=e,t.flat?t.flat():[].concat(...t)))];var t}n.d(t,"parse",function(){return re}),n.d(t,"write",function(){return ie}),n.d(t,"validate",function(){return ue})}])});
//# sourceMappingURL=webidl2.js.map
export { parse } from "./lib/webidl2.js";
export { write } from "./lib/writer.js";
export { validate } from "./lib/validator.js";

@@ -18,3 +18,3 @@ /**

*/
function error(source, position, current, message, kind, { level = "error", autofix } = {}) {
function error(source, position, current, message, kind, { level = "error", autofix, ruleName } = {}) {
/**

@@ -69,2 +69,3 @@ * @param {number} count

level,
ruleName,
autofix,

@@ -87,4 +88,5 @@ input: subsequentText,

*/
export function validationError(token, current, message, options) {
export function validationError(token, current, ruleName, message, options = {}) {
options.ruleName = ruleName;
return error(current.source, token.index, current, message, "Validation", options);
}

@@ -52,6 +52,6 @@ import { Base } from "./base.js";

const message = `Dictionary arguments cannot be nullable.`;
yield validationError(this.tokens.name, this, message);
yield validationError(this.tokens.name, this, "no-nullable-dict-arg", message);
} else if (this.optional && !this.default) {
const message = `Optional dictionary arguments must have a default value of \`{}\`.`;
yield validationError(this.tokens.name, this, message, {
yield validationError(this.tokens.name, this, "dict-arg-default", message, {
autofix: autofixOptionalDictionaryDefaultValue(this)

@@ -58,0 +58,0 @@ });

@@ -85,3 +85,3 @@ import { Base } from "./base.js";

information.`;
yield validationError(this.tokens.name, this, message, { level: "warning" });
yield validationError(this.tokens.name, this, "no-nointerfaceobject", message, { level: "warning" });
}

@@ -88,0 +88,0 @@ for (const arg of this.arguments) {

@@ -173,6 +173,7 @@ import { Type } from "./type.js";

*/
function getFirstIndentation(str) {
export function getLastIndentation(str) {
const lines = str.split("\n");
for (const line of lines) {
const match = line.match(/^\s+/);
// the first line visually binds to the preceding token
if (lines.length) {
const match = lines[lines.length - 1].match(/^\s+/);
if (match) {

@@ -189,3 +190,3 @@ return match[0];

export function getMemberIndentation(parentTrivia) {
const indentation = getFirstIndentation(parentTrivia);
const indentation = getLastIndentation(parentTrivia);
const indentCh = indentation.includes("\t") ? "\t" : " ";

@@ -212,6 +213,22 @@ return indentation + indentCh;

def.extAttrs = ExtendedAttributes.parse(new Tokeniser("[Exposed=Window]"));
def.extAttrs.tokens.open.trivia = def.tokens.base.trivia;
def.tokens.base.trivia = " ";
const trivia = def.tokens.base.trivia;
def.extAttrs.tokens.open.trivia = trivia;
def.tokens.base.trivia = `\n${getLastIndentation(trivia)}`;
}
};
}
/**
* Get the first syntax token for the given IDL object.
* @param {*} data
*/
export function getFirstToken(data) {
if (data.extAttrs.length) {
return data.extAttrs.tokens.open;
}
if (data.type === "operation") {
return getFirstToken(data.idlType);
}
const tokens = Object.values(data.tokens).sort((x, y) => x.index - y.index);
return tokens[0];
}

@@ -6,3 +6,3 @@ import { Container } from "./container.js";

import { IterableLike } from "./iterable.js";
import { stringifier, autofixAddExposedWindow, getMemberIndentation } from "./helpers.js";
import { stringifier, autofixAddExposedWindow, getMemberIndentation, getLastIndentation, getFirstToken } from "./helpers.js";
import { validationError } from "../error.js";

@@ -62,3 +62,3 @@ import { checkInterfaceMemberDuplication } from "../validators/interface.js";

for more information.`;
yield validationError(this.tokens.name, this, message, {
yield validationError(this.tokens.name, this, "require-exposed", message, {
autofix: autofixAddExposedWindow(this)

@@ -73,3 +73,3 @@ });

for more information.`;
yield validationError(constructor.tokens.name, this, message, {
yield validationError(constructor.tokens.name, this, "constructor-member", message, {
autofix: autofixConstructor(this, constructor)

@@ -88,7 +88,18 @@ });

return () => {
const indentation = getMemberIndentation(interfaceDef.tokens.close.trivia);
const constructorOp = Constructor.parse(new Tokeniser(`\n${indentation}constructor();`));
const indentation = getLastIndentation(interfaceDef.extAttrs.tokens.open.trivia);
const memberIndent = interfaceDef.members.length ?
getLastIndentation(getFirstToken(interfaceDef.members[0]).trivia) :
getMemberIndentation(indentation);
const constructorOp = Constructor.parse(new Tokeniser(`\n${memberIndent}constructor();`));
constructorOp.extAttrs = [];
constructorOp.arguments = constructorExtAttr.arguments;
interfaceDef.members.unshift(constructorOp);
const existingIndex = interfaceDef.members.findIndex(m => m.type === "constructor");
interfaceDef.members.splice(existingIndex + 1, 0, constructorOp);
const { close } = interfaceDef.tokens;
if (!close.trivia.includes("\n")) {
close.trivia += `\n${indentation}`;
}
const { extAttrs } = interfaceDef;

@@ -95,0 +106,0 @@ const index = extAttrs.indexOf(constructorExtAttr);

@@ -37,3 +37,3 @@ import { Container } from "./container.js";

for more information.`;
yield validationError(this.tokens.name, this, message, {
yield validationError(this.tokens.name, this, "require-exposed", message, {
autofix: autofixAddExposedWindow(this)

@@ -40,0 +40,0 @@ });

@@ -51,3 +51,3 @@ import { Base } from "./base.js";

const message = `Regular or static operations must have both a return type and an identifier.`;
yield validationError(this.tokens.open, this, message);
yield validationError(this.tokens.open, this, "incomplete-op", message);
}

@@ -54,0 +54,0 @@ if (this.idlType) {

@@ -165,3 +165,3 @@ import { Base } from "./base.js";

const message = `Nullable union cannot include a dictionary type`;
yield validationError(targetToken, this, message);
yield validationError(targetToken, this, "no-nullable-union-dict", message);
}

@@ -168,0 +168,0 @@ } else {

@@ -62,3 +62,3 @@ "use strict";

const message = `The name "${name}" of type "${unique.get(name).type}" was already seen`;
yield error(dup.tokens.name, dup, message);
yield error(dup.tokens.name, dup, "no-duplicate", message);
}

@@ -65,0 +65,0 @@ }

@@ -20,3 +20,3 @@ import { validationError } from "../error.js";

const message = `The operation "${name}" has already been defined for the base interface "${base.name}" either in itself or in a mixin`;
yield validationError(addition.tokens.name, ext, message);
yield validationError(addition.tokens.name, ext, "no-cross-overload", message);
}

@@ -23,0 +23,0 @@ }

@@ -0,0 +0,0 @@ "use strict";

{
"name": "webidl2",
"description": "A WebIDL Parser",
"version": "23.8.2",
"version": "23.8.3",
"contributors": [

@@ -6,0 +6,0 @@ "Robin Berjon <robin@berjon.com> (https://berjon.com)",

# WebIDL 2
# webidl2.js

@@ -185,2 +185,12 @@ [![NPM version](https://badge.fury.io/js/webidl2.svg)](http://badge.fury.io/js/webidl2)

* `sourceName`: the source name you passed to `parse()`.
* `level`: `"error"` by default, can be `"warning"` for some validations for e.g. potential future deprecations.
* `ruleName`: Only for validations. Currently the followings are supported:
* `dict-arg-default`: Optional dictionary type arguments must have a default value of `{}`.
* `no-nullable-dict-arg`: Dictionary arguments cannot be nullable.
* `no-nullable-union-dict`: Nullable unions cannot include a dictionary type.
* `constructor-member`: Constructors must use newer `constructor()` syntax.
* `no-duplicate`: Types cannot have identical names.
* `require-exposed`: Interfaces must explicitly expose themselves to specific contexts by `[Exposed]`.
* `incomplete-op`: Regular or static operations must have both a return type and an identifier.
* `no-cross-overload`: Overloading must be done within a single interface or namespace.
* `input`: a short peek at the text at the point where the error happened

@@ -187,0 +197,0 @@ * `tokens`: the five tokens at the point of error, as understood by the tokeniser

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc