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.9.0 to 23.10.0

lib/supplement.d.ts

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:a,ruleName:i}={}){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",b=`${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:`${b} ${r}`,bareMessage:r,context:b,line:l,sourceName:e.name,level:o,ruleName:i,autofix:a,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 Base{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 i(e,t){const n=e.consume("?");n&&(t.tokens.nullable=n),e.probe("?")&&e.error("Can't nullable more than once")}function c(e,t){let n=function(e,t){const n=e.consume("FrozenArray","Promise","sequence","record");if(!n)return;const r=new type_Type({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=b(e,t)||e.error("Missing Promise subtype");r.subtype.push(n);break}case"sequence":case"FrozenArray":{const s=y(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(...v)||e.error(`Record key must be one of: ${v.join(", ")}`),s=new type_Type({source:e.source,tokens:{base:n}});s.tokens.separator=e.consume(",")||e.error("Missing comma after record key type"),s.type=t;const o=y(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)||m(e);if(!n){const t=e.consume("identifier",...v);if(!t)return;n=new type_Type({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,i(e,n),n.nullable&&"any"===n.idlType&&e.error("Type `any` cannot be made nullable"),n}class type_Type extends Base{static parse(e,t){return c(e,t)||function(e,t){const n={};if(n.open=e.consume("("),!n.open)return;const r=new type_Type({source:e.source,tokens:n});for(r.type=t||null;;){const t=y(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"),i(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 u([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 default_Default extends Base{static parse(e){const t=e.consume("=");if(!t)return null;const n=p(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 default_Default({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 d(this.expression[0]).type}get value(){return d(this.expression[0]).value}get negative(){return d(this.expression[0]).negative}}class ArrayBase extends Array{constructor({source:e,tokens:t}){super(),Object.defineProperties(this,{source:{value:e},tokens:{value:t}})}}class extended_attributes_ExtendedAttributeParameters extends Base{static parse(e){const t={assign:e.consume("=")},n=new extended_attributes_ExtendedAttributeParameters({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=l(e,{parser:token_Token.parser(e,"identifier"),listName:"identifier list"});t.length||e.error("Expected identifiers but none found");return t}(e):f(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 extended_attributes_SimpleExtendedAttribute extends Base{static parse(e){const t=e.consume("identifier");if(t)return new extended_attributes_SimpleExtendedAttribute({source:e.source,tokens:{name:t},params:extended_attributes_ExtendedAttributeParameters.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 extended_attributes_ExtendedAttributes extends ArrayBase{static parse(e){const t={};if(t.open=e.consume("["),!t.open)return new extended_attributes_ExtendedAttributes({});const n=new extended_attributes_ExtendedAttributes({source:e.source,tokens:t});return n.push(...l(e,{parser:extended_attributes_SimpleExtendedAttribute.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 argument_Argument extends Base{static parse(e){const t=e.position,n={},r=new argument_Argument({source:e.source,tokens:n});return r.extAttrs=extended_attributes_ExtendedAttributes.parse(e),n.optional=e.consume("optional"),r.idlType=y(e,"argument-type"),r.idlType?(n.optional||(n.variadic=e.consume("...")),n.name=e.consume("identifier",..._),n.name?(r.default=n.optional?default_Default.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 u(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=default_Default.parse(new tokeniser_Tokeniser(" = {}"))})})}var t}}class token_Token extends Base{static parser(e,t){return()=>{const n=e.consume(t);if(n)return new token_Token({source:e.source,tokens:{value:n}})}}get value(){return this.tokens.value.value}}class operation_Operation extends Base{static parse(e,{special:t,regular:n}={}){const r={special:t},s=new operation_Operation({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=b(e)||e.error("Missing return type"),r.name=e.consume("identifier","includes"),r.open=e.consume("(")||e.error("Invalid operation"),s.arguments=f(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?u(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 attribute_Attribute extends Base{static parse(e,{special:t,noInherit:n=!1,readonly:r=!1}={}){const s=e.position,o={special:t},a=new attribute_Attribute({source:e.source,tokens:o});if(t||n||(o.special=e.consume("inherit")),"inherit"===a.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(a.idlType=y(e,"attribute-type")||e.error("Attribute lacks a type"),a.idlType.generic){case"sequence":case"record":e.error(`Attributes cannot accept ${a.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 `;`"),a}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 u(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}function u(e){return e.startsWith("_")?e.slice(1):e}function l(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 p(e){return e.consume("true","false","Infinity","-Infinity","NaN","decimal","integer")}function d({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 m(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 type_Type({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 type_Type({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 type_Type({source:t,tokens:{base:r}}):void 0}function f(e){return l(e,{parser:argument_Argument.parse,listName:"arguments list"})}function y(e,t){const n=extended_attributes_ExtendedAttributes.parse(e),r=type_Type.parse(e,t);return r&&(r.extAttrs=n),r}function b(e,t){const n=type_Type.parse(e,t||"return-type");if(n)return n;const r=e.consume("void");if(r){const t=new type_Type({source:e.source,tokens:{base:r}});return t.type="return-type",t}}function k(e){const t=e.consume("stringifier");if(t)return attribute_Attribute.parse(e,{special:t})||operation_Operation.parse(e,{special:t})||e.error("Unterminated stringifier")}function h(e){const t=e.split("\n");if(t.length){const e=t[t.length-1].match(/^\s+/);if(e)return e[0]}return""}function g(e){return()=>{if(e.extAttrs.length){const t=new tokeniser_Tokeniser("Exposed=Window,"),n=extended_attributes_SimpleExtendedAttribute.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=extended_attributes_ExtendedAttributes.parse(new tokeniser_Tokeniser("[Exposed=Window]"));const t=e.tokens.base.trivia;e.extAttrs.tokens.open.trivia=t,e.tokens.base.trivia=`\n${h(t)}`}}}const x={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},v=["ByteString","DOMString","USVString"],_=["async","attribute","callback","const","constructor","deleter","dictionary","enum","getter","includes","inherit","interface","iterable","maplike","namespace","partial","required","setlike","setter","static","stringifier","typedef","unrestricted"],w=["-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(_,v),T=["(",")",",","...",":",";","<","=",">","?","[","]","{","}"],A=["_constructor","toString","_toString"];class tokeniser_Tokeniser{constructor(e){this.source=function(e){const t=[];let n=0,r="",o=1,a=0;for(;n<e.length;){const c=e.charAt(n);let l=-1;if(/[\t\n\r ]/.test(c)?l=i("whitespace",{noFlushTrivia:!0}):"/"===c&&(l=i("comment",{noFlushTrivia:!0})),-1!==l){const e=t.pop().value;o+=(e.match(/\n/g)||[]).length,r+=e,a-=1}else if(/[-0-9.A-Z_a-z]/.test(c)){if(-1===(l=i("decimal"))&&(l=i("integer")),-1===l){l=i("identifier");const e=t.length-1,n=t[e];if(-1!==l){if(A.includes(n.value)){const r=`${u(n.value)} is a reserved identifier and must not be used.`;throw new WebIDLParseError(s(t,e,null,r))}w.includes(n.value)&&(n.type=n.value)}}}else'"'===c&&(l=i("string"));for(const s of T)if(e.startsWith(s,n)){t.push({type:s,value:s,trivia:r,line:o,index:a}),r="",l=n+=s.length;break}if(-1===l&&(l=i("other")),-1===l)throw new Error("Token stream not progressing");n=l,a+=1}return t.push({type:"eof",value:"",trivia:r}),t;function i(s,{noFlushTrivia:i}={}){const c=x[s];c.lastIndex=n;const u=c.exec(e);return u?(t.push({type:s,value:u[0],trivia:r,line:o,index:a}),i||(r=""),c.lastIndex):-1}}(e),this.position=0}error(e){throw new WebIDLParseError(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 WebIDLParseError extends Error{constructor({message:e,bareMessage:t,context:n,line:r,sourceName:s,input:o,tokens:a}){super(e),this.name="WebIDLParseError",this.bareMessage=t,this.context=n,this.line=r,this.sourceName=s,this.input=o,this.tokens=a}}class enum_EnumValue extends token_Token{static parse(e){const t=e.consume("string");if(t)return new enum_EnumValue({source:e.source,tokens:{value:t}})}get type(){return"enum-value"}get value(){return super.value.slice(1,-1)}}class enum_Enum extends Base{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 enum_Enum({source:e.source,tokens:t});return t.open=e.consume("{")||e.error("Bodyless enum"),n.values=l(e,{parser:enum_EnumValue.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 u(this.tokens.name.value)}}class includes_Includes extends Base{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 includes_Includes({source:e.source,tokens:n});e.unconsume(t.index)}get type(){return"includes"}get target(){return u(this.tokens.target.value)}get includes(){return u(this.tokens.mixin.value)}}class typedef_Typedef extends Base{static parse(e){const t={},n=new typedef_Typedef({source:e.source,tokens:t});if(t.base=e.consume("typedef"),t.base)return n.idlType=y(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 u(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}class callback_CallbackFunction extends Base{static parse(e,t){const n={base:t},r=new callback_CallbackFunction({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=b(e)||e.error("Callback lacks a return type"),n.open=e.consume("(")||e.error("Callback lacks parentheses for arguments"),r.arguments=f(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 u(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}class container_Container extends Base{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=extended_attributes_ExtendedAttributes.parse(e);let a;for(const[t,...n]of s)if(a=t(e,...n))break;a||e.error("Unknown member"),a.extAttrs=r,t.members.push(a)}}get partial(){return!!this.tokens.partial}get name(){return u(this.tokens.name.value)}get inheritance(){return this.tokens.inheritance?u(this.tokens.inheritance.value):null}*validate(e){for(const t of this.members)t.validate&&(yield*t.validate(e))}}class constant_Constant extends Base{static parse(e){const t={};if(t.base=e.consume("const"),!t.base)return;let n=m(e);if(!n){const t=e.consume("identifier")||e.error("Const lacks a type");n=new type_Type({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=p(e)||e.error("Const lacks a value"),t.termination=e.consume(";")||e.error("Unterminated const, expected `;`");const r=new constant_Constant({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 d(this.tokens.value)}}class iterable_IterableLike extends Base{static parse(e){const t=e.position,n={},r=new iterable_IterableLike({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,a=o||"iterable"===s;n.open=e.consume("<")||e.error(`Missing less-than sign \`<\` in ${s} declaration`);const i=y(e)||e.error(`Missing a type argument in ${s} declaration`);return r.idlType=[i],a&&(i.tokens.separator=e.consume(","),i.tokens.separator?r.idlType.push(y(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 constructor_Constructor extends Base{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=f(e);n.close=e.consume(")")||e.error("Unterminated constructor"),n.termination=e.consume(";")||e.error("No semicolon after constructor");const s=new constructor_Constructor({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 I(e){const t=e.consume("static");if(t)return attribute_Attribute.parse(e,{special:t})||operation_Operation.parse(e,{special:t})||e.error("No body in static member")}class interface_Interface extends container_Container{static parse(e,t,{partial:n=null}={}){const r={partial:n,base:t};return container_Container.parse(e,new interface_Interface({source:e.source,tokens:r}),{type:"interface",inheritable:!n,allowedMembers:[[constant_Constant.parse],[constructor_Constructor.parse],[I],[k],[iterable_IterableLike.parse],[attribute_Attribute.parse],[operation_Operation.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:g(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:E(this,e)})}yield*super.validate(e),this.partial||(yield*function*(e,t){const n=new Set(i(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=i(e);yield*a(r,n,e,t);for(const e of r)n.add(e.name)}function*a(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 i(e){return e.members.filter(({type:e})=>"operation"===e)}}(e,this))}}function E(e,t){return()=>{const n=h(e.extAttrs.tokens.open.trivia),r=e.members.length?h(function e(t){if(t.extAttrs.length)return t.extAttrs.tokens.open;if("operation"===t.type&&!t.special)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=h(e),n=t.includes("\t")?"\t":" ";return t+n}(n),s=constructor_Constructor.parse(new tokeniser_Tokeniser(`\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:a}=e.tokens;a.trivia.includes("\n")||(a.trivia+=`\n${n}`);const{extAttrs:i}=e,c=i.indexOf(t),u=i.splice(c,1);i.length?i.length===c?i[c-1].tokens.separator=void 0:i[c].tokens.name.trivia.trim()||(i[c].tokens.name.trivia=u[0].tokens.name.trivia):i.tokens.open=i.tokens.close=void 0}}class mixin_Mixin extends container_Container{static parse(e,t,{partial:n}={}){const r={partial:n,base:t};if(r.mixin=e.consume("mixin"),r.mixin)return container_Container.parse(e,new mixin_Mixin({source:e.source,tokens:r}),{type:"interface mixin",allowedMembers:[[constant_Constant.parse],[k],[attribute_Attribute.parse,{noInherit:!0}],[operation_Operation.parse,{regular:!0}]]})}get type(){return"interface mixin"}}class field_Field extends Base{static parse(e){const t={},n=new field_Field({source:e.source,tokens:t});return n.extAttrs=extended_attributes_ExtendedAttributes.parse(e),t.required=e.consume("required"),n.idlType=y(e,"dictionary-type")||e.error("Dictionary member lacks a type"),t.name=e.consume("identifier")||e.error("Dictionary member lacks a name"),n.default=default_Default.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 u(this.tokens.name.value)}get required(){return!!this.tokens.required}*validate(e){yield*this.idlType.validate(e)}}class dictionary_Dictionary extends container_Container{static parse(e,{partial:t}={}){const n={partial:t};if(n.base=e.consume("dictionary"),n.base)return container_Container.parse(e,new dictionary_Dictionary({source:e.source,tokens:n}),{type:"dictionary",inheritable:!t,allowedMembers:[[field_Field.parse]]})}get type(){return"dictionary"}}class namespace_Namespace extends container_Container{static parse(e,{partial:t}={}){const n={partial:t};if(n.base=e.consume("namespace"),n.base)return container_Container.parse(e,new namespace_Namespace({source:e.source,tokens:n}),{type:"namespace",allowedMembers:[[attribute_Attribute.parse,{noInherit:!0,readonly:!0}],[operation_Operation.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:g(this)})}yield*super.validate(e)}}class callback_interface_CallbackInterface extends container_Container{static parse(e,t,{partial:n=null}={}){const r={callback:t};if(r.base=e.consume("interface"),r.base)return container_Container.parse(e,new callback_interface_CallbackInterface({source:e.source,tokens:r}),{type:"callback interface",inheritable:!n,allowedMembers:[[constant_Constant.parse],[operation_Operation.parse,{regular:!0}]]})}get type(){return"callback interface"}}function N(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 mixin_Mixin.parse(e,n,t)||interface_Interface.parse(e,n,t)||r("Interface has no proper body")}function a(){return function(){const t=s("callback");if(t)return e.probe("interface")?callback_interface_CallbackInterface.parse(e,t):callback_CallbackFunction.parse(e,t)}()||o()||function(){const t=s("partial");if(t)return dictionary_Dictionary.parse(e,{partial:t})||o({partial:t})||namespace_Namespace.parse(e,{partial:t})||r("Partial doesn't apply to anything")}()||dictionary_Dictionary.parse(e)||enum_Enum.parse(e)||typedef_Typedef.parse(e)||includes_Includes.parse(e)||namespace_Namespace.parse(e)}const i=function(){if(!n.length)return[];const o=[];for(;;){const t=extended_attributes_ExtendedAttributes.parse(e),n=a();if(!n){t.length&&r("Stray extended attributes");break}n.extAttrs=t,o.push(n)}const i=s("eof");return t.concrete&&o.push(i),o}();return e.position<n.length&&r("Unrecognised tokens"),i}function C(e,t={}){const n=new tokeniser_Tokeniser(e);return void 0!==t.sourceName&&(n.source.name=t.sourceName),N(n,t)}function $(e){return e}const M={wrap:e=>e.join(""),trivia:$,name:$,reference:$,type:$,generic:$,nameless:$,inheritance:$,definition:$,extendedAttribute:$,extendedAttributeReference:$};function O(e,{templates:t=M}={}){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=$,...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 a(e){if(e.union||e.generic)return t.wrap([r(e.tokens.base,t.generic),r(e.tokens.open),...e.subtype.map(i),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)]:[],a=n(t.wrap([...o,e.tokens.base.value,r(e.tokens.postfix)]),{unescaped:e.idlType,context:e});return t.wrap([t.trivia(s.trivia),a])}function i(e){return t.wrap([p(e.extAttrs),a(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(i(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(i)),r(e.tokens.close),r(e.tokens.termination)]),{data:e,parent:n})}t=Object.assign({},M,t);const f={interface:d,"interface mixin":d,namespace:d,operation:function(e,n){const s=e.idlType?[t.type(i(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(i(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(i(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(i(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(i(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(i(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 D(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*P(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:D(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 j(e){return[...P((t=e,t.flat?t.flat():[].concat(...t)))];var t}n.d(t,"parse",function(){return C}),n.d(t,"write",function(){return O}),n.d(t,"validate",function(){return j}),n.d(t,"WebIDLParseError",function(){return WebIDLParseError})}])});
!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:i="error",autofix:o,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(""),i=e[t];return"eof"===i.type?s:r?s+i.trivia:s.slice(i.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",b=`${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:`${b} ${r}`,bareMessage:r,context:b,line:l,sourceName:e.name,level:i,ruleName:a,autofix:o,input:m,tokens:d}}function s(e,t,n,s){return r(e,t,n,s,"Syntax")}function i(e,t,n,s,i={}){return i.ruleName=n,r(t.source,e.index,t,s,"Validation",i)}n.r(t);class Base{constructor({source:e,tokens:t}){Object.defineProperties(this,{source:{value:e},tokens:{value:t},parent:{value:null,writable:!0},this:{value:this}})}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 o(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=o(r.idlType,t);if(t.cache.typedefIncludesDictionary.set(r,s),s)return{reference:e,dictionary:s.dictionary}}if("dictionary"===r.type&&(n||!e.nullable))return{reference:e,dictionary:r}}for(const n of e.subtype){const e=o(n,t);if(e)return n.union?e:{reference:n,dictionary:e.dictionary}}}function a(e,t){const n=e.consume("?");n&&(t.tokens.nullable=n),e.probe("?")&&e.error("Can't nullable more than once")}function c(e,t){let n=function(e,t){const n=e.consume("FrozenArray","Promise","sequence","record");if(!n)return;const r=w(new type_Type({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=k(e,t)||e.error("Missing Promise subtype");r.subtype.push(n);break}case"sequence":case"FrozenArray":{const s=h(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(...I)||e.error(`Record key must be one of: ${I.join(", ")}`),s=new type_Type({source:e.source,tokens:{base:n}});s.tokens.separator=e.consume(",")||e.error("Missing comma after record key type"),s.type=t;const i=h(e,t)||e.error("Error parsing generic type record");r.subtype.push(s,i);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.this}(e,t)||y(e);if(!n){const t=e.consume("identifier",...I,...T);if(!t)return;n=new type_Type({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,a(e,n),n.nullable&&"any"===n.idlType&&e.error("Type `any` cannot be made nullable"),n}class type_Type extends Base{static parse(e,t){return c(e,t)||function(e,t){const n={};if(n.open=e.consume("("),!n.open)return;const r=w(new type_Type({source:e.source,tokens:n}));for(r.type=t||null;;){const t=h(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"),"Promise"===t.generic&&e.error("Type `Promise` 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"),a(e,r),r.this}(e,t)}constructor({source:e,tokens:t}){super({source:e,tokens:t}),Object.defineProperty(this,"subtype",{value:[],writable:!0}),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 p([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{reference:t}=o(n,e)||{};if(t){const e=(this.union?t:this).tokens.base,n="Nullable union cannot include a dictionary type";yield i(e,this,"no-nullable-union-dict",n)}}else for(const t of this.subtype)yield*t.validate(e)}}class default_Default extends Base{static parse(e){const t=e.consume("=");if(!t)return null;const n=m(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 default_Default({source:e.source,tokens:{assign:t},expression:r})}constructor({source:e,tokens:t,expression:n}){super({source:e,tokens:t}),n.parent=this,Object.defineProperty(this,"expression",{value:n})}get type(){return f(this.expression[0]).type}get value(){return f(this.expression[0]).value}get negative(){return f(this.expression[0]).negative}}class ArrayBase extends Array{constructor({source:e,tokens:t}){super(),Object.defineProperties(this,{source:{value:e},tokens:{value:t},parent:{value:null,writable:!0}})}}class token_Token extends Base{static parser(e,t){return()=>{const n=e.consume(t);if(n)return new token_Token({source:e.source,tokens:{value:n}})}}get value(){return p(this.tokens.value.value)}}function u(e,t){return d(e,{parser:token_Token.parser(e,t),listName:t+" list"})}class extended_attributes_ExtendedAttributeParameters extends Base{static parse(e){const t={assign:e.consume("=")},n=w(new extended_attributes_ExtendedAttributeParameters({source:e.source,tokens:t}));return t.assign&&(t.secondaryName=e.consume("identifier","decimal","integer","string")),t.open=e.consume("("),t.open?(n.list=n.rhsIsList?function(e){let t=u(e,"identifier");return t.length?t:(t=u(e,"string")).length?t:void e.error("Expected identifiers or strings but none found")}(e):b(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.this}get rhsIsList(){return this.tokens.assign&&!this.tokens.secondaryName}get rhsType(){return this.rhsIsList?this.list[0].tokens.value.type+"-list":this.tokens.secondaryName?this.tokens.secondaryName.type:null}}class extended_attributes_SimpleExtendedAttribute extends Base{static parse(e){const t=e.consume("identifier");if(t)return new extended_attributes_SimpleExtendedAttribute({source:e.source,tokens:{name:t},params:extended_attributes_ExtendedAttributeParameters.parse(e)})}constructor({source:e,tokens:t,params:n}){super({source:e,tokens:t}),n.parent=this,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:this.params.rhsIsList?n:p(t.secondaryName.value)}:null}get arguments(){const{rhsIsList:e,list:t}=this.params;return!t||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 i(this.tokens.name,this,"no-nointerfaceobject",e,{level:"warning"})}for(const t of this.arguments)yield*t.validate(e)}}class extended_attributes_ExtendedAttributes extends ArrayBase{static parse(e){const t={};if(t.open=e.consume("["),!t.open)return new extended_attributes_ExtendedAttributes({});const n=new extended_attributes_ExtendedAttributes({source:e.source,tokens:t});return n.push(...d(e,{parser:extended_attributes_SimpleExtendedAttribute.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 argument_Argument extends Base{static parse(e){const t=e.position,n={},r=w(new argument_Argument({source:e.source,tokens:n}));return r.extAttrs=extended_attributes_ExtendedAttributes.parse(e),n.optional=e.consume("optional"),r.idlType=h(e,"argument-type"),r.idlType?(n.optional||(n.variadic=e.consume("...")),n.name=e.consume("identifier",...E),n.name?(r.default=n.optional?default_Default.parse(e):null,r.this):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 p(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e);const t=o(this.idlType,e,{useNullableInner:!0});if(t)if(this.idlType.nullable){const e="Dictionary arguments cannot be nullable.";yield i(this.tokens.name,this,"no-nullable-dict-arg",e)}else if(this.optional){if(!this.default){const e="Optional dictionary arguments must have a default value of `{}`.";yield i(this.tokens.name,this,"dict-arg-default",e,{autofix:l(this)})}}else if(this.parent&&!function e(t,n){if(n.cache.dictionaryIncludesRequiredField.has(t))return n.cache.dictionaryIncludesRequiredField.get(t);if(n.cache.dictionaryIncludesRequiredField.set(t,void 0),t.inheritance){const r=n.unique.get(t.inheritance);if(!r)return!0;if(e(r,n))return!0}const r=t.members.some(e=>e.required);return n.cache.dictionaryIncludesRequiredField.set(t,r),r}(t.dictionary,e)&&function(e){const t=e.parent.arguments||e.parent.list,n=t.indexOf(e);return!t.slice(n+1).some(e=>!e.optional)}(this)){const e="Dictionary argument must be optional if it has no required fields";yield i(this.tokens.name,this,"dict-arg-optional",e,{autofix:(n=this,()=>{const e=_(n.idlType);n.tokens.optional={type:"optional",value:"optional",trivia:e.trivia},e.trivia=" ",l(n)()})})}var n}}function l(e){return()=>{e.default=default_Default.parse(new tokeniser_Tokeniser(" = {}"))}}class operation_Operation extends Base{static parse(e,{special:t,regular:n}={}){const r={special:t},s=w(new operation_Operation({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=k(e)||e.error("Missing return type"),r.name=e.consume("identifier","includes"),r.open=e.consume("(")||e.error("Invalid operation"),s.arguments=b(e),r.close=e.consume(")")||e.error("Unterminated operation"),r.termination=e.consume(";")||e.error("Unterminated operation, expected `;`"),s.this)}get type(){return"operation"}get name(){const{name:e}=this.tokens;return e?p(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 i(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 attribute_Attribute extends Base{static parse(e,{special:t,noInherit:n=!1,readonly:r=!1}={}){const s=e.position,i={special:t},o=w(new attribute_Attribute({source:e.source,tokens:i}));if(t||n||(i.special=e.consume("inherit")),"inherit"===o.special&&e.probe("readonly")&&e.error("Inherited attributes cannot be read-only"),i.readonly=e.consume("readonly"),r&&!i.readonly&&e.probe("attribute")&&e.error("Attributes must be readonly in this context"),i.base=e.consume("attribute"),i.base){switch(o.idlType=h(e,"attribute-type")||e.error("Attribute lacks a type"),o.idlType.generic){case"sequence":case"record":e.error(`Attributes cannot accept ${o.idlType.generic} types`)}return i.name=e.consume("identifier","async","required")||e.error("Attribute lacks a name"),i.termination=e.consume(";")||e.error("Unterminated attribute, expected `;`"),o.this}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 p(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}function p(e){return e.startsWith("_")?e.slice(1):e}function d(e,{parser:t,allowDangler:n,listName:r="list"}){const s=t(e);if(!s)return[];s.tokens.separator=e.consume(",");const i=[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(","),i.push(s),!s.tokens.separator)break}return i}function m(e){return e.consume("true","false","Infinity","-Infinity","NaN","decimal","integer")}function f({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 y(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 type_Type({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 type_Type({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 type_Type({source:t,tokens:{base:r}}):void 0}function b(e){return d(e,{parser:argument_Argument.parse,listName:"arguments list"})}function h(e,t){const n=extended_attributes_ExtendedAttributes.parse(e),r=type_Type.parse(e,t);return r&&(w(r).extAttrs=n),r}function k(e,t){const n=type_Type.parse(e,t||"return-type");if(n)return n;const r=e.consume("void");if(r){const t=new type_Type({source:e.source,tokens:{base:r}});return t.type="return-type",t}}function g(e){const t=e.consume("stringifier");if(t)return attribute_Attribute.parse(e,{special:t})||operation_Operation.parse(e,{special:t})||e.error("Unterminated stringifier")}function x(e){const t=e.split("\n");if(t.length){const e=t[t.length-1].match(/^\s+/);if(e)return e[0]}return""}function v(e){return()=>{if(e.extAttrs.length){const t=new tokeniser_Tokeniser("Exposed=Window,"),n=extended_attributes_SimpleExtendedAttribute.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{w(e).extAttrs=extended_attributes_ExtendedAttributes.parse(new tokeniser_Tokeniser("[Exposed=Window]"));const t=e.tokens.base.trivia;e.extAttrs.tokens.open.trivia=t,e.tokens.base.trivia=`\n${x(t)}`}}}function _(e){if(e.extAttrs.length)return e.extAttrs.tokens.open;if("operation"===e.type&&!e.special)return _(e.idlType);return Object.values(e.tokens).sort((e,t)=>e.index-t.index)[0]}function w(e,t){return t||(t=e),e?new Proxy(e,{get(e,t){const n=e[t];return Array.isArray(n)?w(n,e):n},set(e,n,r){if(e[n]=r,!r)return!0;if(Array.isArray(r))for(const e of r)void 0!==e.parent&&(e.parent=t);else void 0!==r.parent&&(r.parent=t);return!0}}):e}const A={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},T=["ArrayBuffer","DataView","Int8Array","Int16Array","Int32Array","Uint8Array","Uint16Array","Uint32Array","Uint8ClampedArray","Float32Array","Float64Array","any","object","symbol"],I=["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"],N=["-Infinity","FrozenArray","Infinity","NaN","Promise","boolean","byte","double","false","float","long","mixin","null","octet","optional","or","readonly","record","sequence","short","true","unsigned","void"].concat(E,I,T),C=["(",")",",","...",":",";","<","=",">","?","[","]","{","}"],$=["_constructor","toString","_toString"];class tokeniser_Tokeniser{constructor(e){this.source=function(e){const t=[];let n=0,r="",i=1,o=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;i+=(e.match(/\n/g)||[]).length,r+=e,o-=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($.includes(n.value)){const r=`${p(n.value)} is a reserved identifier and must not be used.`;throw new WebIDLParseError(s(t,e,null,r))}N.includes(n.value)&&(n.type=n.value)}}}else'"'===c&&(u=a("string"));for(const s of C)if(e.startsWith(s,n)){t.push({type:s,value:s,trivia:r,line:i,index:o}),r="",u=n+=s.length;break}if(-1===u&&(u=a("other")),-1===u)throw new Error("Token stream not progressing");n=u,o+=1}return t.push({type:"eof",value:"",trivia:r}),t;function a(s,{noFlushTrivia:a}={}){const c=A[s];c.lastIndex=n;const u=c.exec(e);return u?(t.push({type:s,value:u[0],trivia:r,line:i,index:o}),a||(r=""),c.lastIndex):-1}}(e),this.position=0}error(e){throw new WebIDLParseError(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 WebIDLParseError extends Error{constructor({message:e,bareMessage:t,context:n,line:r,sourceName:s,input:i,tokens:o}){super(e),this.name="WebIDLParseError",this.bareMessage=t,this.context=n,this.line=r,this.sourceName=s,this.input=i,this.tokens=o}}class enum_EnumValue extends token_Token{static parse(e){const t=e.consume("string");if(t)return new enum_EnumValue({source:e.source,tokens:{value:t}})}get type(){return"enum-value"}get value(){return super.value.slice(1,-1)}}class enum_Enum extends Base{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=w(new enum_Enum({source:e.source,tokens:t}));return e.current=n.this,t.open=e.consume("{")||e.error("Bodyless enum"),n.values=d(e,{parser:enum_EnumValue.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.this}get type(){return"enum"}get name(){return p(this.tokens.name.value)}}class includes_Includes extends Base{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 includes_Includes({source:e.source,tokens:n});e.unconsume(t.index)}get type(){return"includes"}get target(){return p(this.tokens.target.value)}get includes(){return p(this.tokens.mixin.value)}}class typedef_Typedef extends Base{static parse(e){const t={},n=w(new typedef_Typedef({source:e.source,tokens:t}));if(t.base=e.consume("typedef"),t.base)return n.idlType=h(e,"typedef-type")||e.error("Typedef lacks a type"),t.name=e.consume("identifier")||e.error("Typedef lacks a name"),e.current=n.this,t.termination=e.consume(";")||e.error("Unterminated typedef, expected `;`"),n.this}get type(){return"typedef"}get name(){return p(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}class callback_CallbackFunction extends Base{static parse(e,t){const n={base:t},r=w(new callback_CallbackFunction({source:e.source,tokens:n}));return n.name=e.consume("identifier")||e.error("Callback lacks a name"),e.current=r.this,n.assign=e.consume("=")||e.error("Callback lacks an assignment"),r.idlType=k(e)||e.error("Callback lacks a return type"),n.open=e.consume("(")||e.error("Callback lacks parentheses for arguments"),r.arguments=b(e),n.close=e.consume(")")||e.error("Unterminated callback"),n.termination=e.consume(";")||e.error("Unterminated callback, expected `;`"),r.this}get type(){return"callback"}get name(){return p(this.tokens.name.value)}*validate(e){yield*this.idlType.validate(e)}}class container_Container extends Base{static parse(e,t,{type:n,inheritable:r,allowedMembers:s}){const{tokens:i}=t;for(i.name=e.consume("identifier")||e.error(`Missing name in ${t.type}`),e.current=t,t=w(t),r&&Object.assign(i,function(e){const t=e.consume(":");return t?{colon:t,inheritance:e.consume("identifier")||e.error("Inheritance lacks a type")}:{}}(e)),i.open=e.consume("{")||e.error(`Bodyless ${n}`),t.members=[];;){if(i.close=e.consume("}"),i.close)return i.termination=e.consume(";")||e.error(`Missing semicolon after ${n}`),t.this;const r=extended_attributes_ExtendedAttributes.parse(e);let o;for(const[t,...n]of s)if(o=w(t(e,...n)))break;o||e.error("Unknown member"),o.extAttrs=r,t.members.push(o.this)}}get partial(){return!!this.tokens.partial}get name(){return p(this.tokens.name.value)}get inheritance(){return this.tokens.inheritance?p(this.tokens.inheritance.value):null}*validate(e){for(const t of this.members)t.validate&&(yield*t.validate(e))}}class constant_Constant extends Base{static parse(e){const t={};if(t.base=e.consume("const"),!t.base)return;let n=y(e);if(!n){const t=e.consume("identifier")||e.error("Const lacks a type");n=new type_Type({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=m(e)||e.error("Const lacks a value"),t.termination=e.consume(";")||e.error("Unterminated const, expected `;`");const r=new constant_Constant({source:e.source,tokens:t});return w(r).idlType=n,r}get type(){return"const"}get name(){return unescape(this.tokens.name.value)}get value(){return f(this.tokens.value)}}class iterable_IterableLike extends Base{static parse(e){const t=e.position,n={},r=w(new iterable_IterableLike({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,i="maplike"===s||r.async,o=i||"iterable"===s;n.open=e.consume("<")||e.error(`Missing less-than sign \`<\` in ${s} declaration`);const a=h(e)||e.error(`Missing a type argument in ${s} declaration`);return r.idlType=[a],o&&(a.tokens.separator=e.consume(","),a.tokens.separator?r.idlType.push(h(e)):i&&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.this}get type(){return this.tokens.base.value}get readonly(){return!!this.tokens.readonly}get async(){return!!this.tokens.async}}class constructor_Constructor extends Base{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=b(e);n.close=e.consume(")")||e.error("Unterminated constructor"),n.termination=e.consume(";")||e.error("No semicolon after constructor");const s=new constructor_Constructor({source:e.source,tokens:n});return w(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 M(e){const t=e.consume("static");if(t)return attribute_Attribute.parse(e,{special:t})||operation_Operation.parse(e,{special:t})||e.error("No body in static member")}class interface_Interface extends container_Container{static parse(e,t,{partial:n=null}={}){const r={partial:n,base:t};return container_Container.parse(e,new interface_Interface({source:e.source,tokens:r}),{type:"interface",inheritable:!n,allowedMembers:[[constant_Constant.parse],[constructor_Constructor.parse],[M],[g],[iterable_IterableLike.parse],[attribute_Attribute.parse],[operation_Operation.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 i(this.tokens.name,this,"require-exposed",e,{autofix:v(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 i(e.tokens.name,this,"constructor-member",t,{autofix:O(this,e)})}if(this.extAttrs.some(e=>"Global"===e.name)){const e=this.extAttrs.filter(e=>"NamedConstructor"===e.name);for(const t of e){const e="Interfaces marked as `[Global]` cannot have named constructors.";yield i(t.tokens.name,this,"no-constructible-global",e)}const t=this.members.filter(e=>"constructor"===e.type);for(const e of t){const t="Interfaces marked as `[Global]` cannot have constructors.";yield i(e.tokens.base,this,"no-constructible-global",t)}}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*o(r,n,e,t);for(const e of r)n.add(e.name)}function*o(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 i(s.tokens.name,n,"no-cross-overload",t)}}}function a(e){return e.members.filter(({type:e})=>"operation"===e)}}(e,this))}}function O(e,t){return e=w(e),()=>{const n=x(e.extAttrs.tokens.open.trivia),r=e.members.length?x(_(e.members[0]).trivia):function(e){const t=x(e),n=t.includes("\t")?"\t":" ";return t+n}(n),s=constructor_Constructor.parse(new tokeniser_Tokeniser(`\n${r}constructor();`));s.extAttrs=[],w(s).arguments=t.arguments;const i=function(e,t){const n=e.slice().reverse().findIndex(t);return-1===n?n:e.length-n-1}(e.members,e=>"constructor"===e.type);e.members.splice(i+1,0,s);const{close:o}=e.tokens;o.trivia.includes("\n")||(o.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 mixin_Mixin extends container_Container{static parse(e,t,{partial:n}={}){const r={partial:n,base:t};if(r.mixin=e.consume("mixin"),r.mixin)return container_Container.parse(e,new mixin_Mixin({source:e.source,tokens:r}),{type:"interface mixin",allowedMembers:[[constant_Constant.parse],[g],[attribute_Attribute.parse,{noInherit:!0}],[operation_Operation.parse,{regular:!0}]]})}get type(){return"interface mixin"}}class field_Field extends Base{static parse(e){const t={},n=w(new field_Field({source:e.source,tokens:t}));return n.extAttrs=extended_attributes_ExtendedAttributes.parse(e),t.required=e.consume("required"),n.idlType=h(e,"dictionary-type")||e.error("Dictionary member lacks a type"),t.name=e.consume("identifier")||e.error("Dictionary member lacks a name"),n.default=default_Default.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.this}get type(){return"field"}get name(){return p(this.tokens.name.value)}get required(){return!!this.tokens.required}*validate(e){yield*this.idlType.validate(e)}}class dictionary_Dictionary extends container_Container{static parse(e,{partial:t}={}){const n={partial:t};if(n.base=e.consume("dictionary"),n.base)return container_Container.parse(e,new dictionary_Dictionary({source:e.source,tokens:n}),{type:"dictionary",inheritable:!t,allowedMembers:[[field_Field.parse]]})}get type(){return"dictionary"}}class namespace_Namespace extends container_Container{static parse(e,{partial:t}={}){const n={partial:t};if(n.base=e.consume("namespace"),n.base)return container_Container.parse(e,new namespace_Namespace({source:e.source,tokens:n}),{type:"namespace",allowedMembers:[[attribute_Attribute.parse,{noInherit:!0,readonly:!0}],[operation_Operation.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 i(this.tokens.name,this,"require-exposed",e,{autofix:v(this)})}yield*super.validate(e)}}class callback_interface_CallbackInterface extends container_Container{static parse(e,t,{partial:n=null}={}){const r={callback:t};if(r.base=e.consume("interface"),r.base)return container_Container.parse(e,new callback_interface_CallbackInterface({source:e.source,tokens:r}),{type:"callback interface",inheritable:!n,allowedMembers:[[constant_Constant.parse],[operation_Operation.parse,{regular:!0}]]})}get type(){return"callback interface"}}function D(e,t){const n=e.source;function r(t){e.error(t)}function s(...t){return e.consume(...t)}function i(t){const n=s("interface");if(n)return mixin_Mixin.parse(e,n,t)||interface_Interface.parse(e,n,t)||r("Interface has no proper body")}function o(){return function(){const t=s("callback");if(t)return e.probe("interface")?callback_interface_CallbackInterface.parse(e,t):callback_CallbackFunction.parse(e,t)}()||i()||function(){const t=s("partial");if(t)return dictionary_Dictionary.parse(e,{partial:t})||i({partial:t})||namespace_Namespace.parse(e,{partial:t})||r("Partial doesn't apply to anything")}()||dictionary_Dictionary.parse(e)||enum_Enum.parse(e)||typedef_Typedef.parse(e)||includes_Includes.parse(e)||namespace_Namespace.parse(e)}const a=function(){if(!n.length)return[];const i=[];for(;;){const t=extended_attributes_ExtendedAttributes.parse(e),n=o();if(!n){t.length&&r("Stray extended attributes");break}w(n).extAttrs=t,i.push(n)}const a=s("eof");return t.concrete&&i.push(a),i}();return e.position<n.length&&r("Unrecognised tokens"),a}function P(e,t={}){const n=new tokeniser_Tokeniser(e);return void 0!==t.sourceName&&(n.source.name=t.sourceName),D(n,t)}function j(e){return e}const q={wrap:e=>e.join(""),trivia:j,name:j,reference:j,type:j,generic:j,nameless:j,inheritance:j,definition:j,extendedAttribute:j,extendedAttributeReference:j};function B(e,{templates:t=q}={}){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=j,...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 i(e,n){return r(e,t.name,n)}function o(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,i=e.tokens.prefix?[e.tokens.prefix.value,t.trivia(e.tokens.base.trivia)]:[],o=n(t.wrap([...i,e.tokens.base.value,r(e.tokens.postfix)]),{unescaped:e.idlType,context:e});return t.wrap([t.trivia(s.trivia),o])}function a(e){return t.wrap([d(e.extAttrs),o(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([d(e.extAttrs),r(e.tokens.optional),t.type(a(e.idlType)),r(e.tokens.variadic),i(e.tokens.name,{data:e}),c(e.default),r(e.tokens.separator)])}function l(e){return t.wrap([r(e.tokens.value),r(e.tokens.separator)])}function p(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):"string-list"===n?l:u):[],r(e.params.tokens.close)])),r(e.tokens.separator)])}function d(e){return e.length?t.wrap([r(e.tokens.open),...e.map(p),r(e.tokens.close)]):""}function m(e){return t.definition(t.wrap([d(e.extAttrs),r(e.tokens.callback),r(e.tokens.partial),r(e.tokens.base),r(e.tokens.mixin),i(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),b(e.members,e),r(e.tokens.close),r(e.tokens.termination)]),{data:e});var s}function f(e,n){return t.definition(t.wrap([d(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({},q,t);const y={interface:m,"interface mixin":m,namespace:m,operation:function(e,n){const s=e.idlType?[t.type(a(e.idlType)),i(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([d(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([d(e.extAttrs),r(e.tokens.special),r(e.tokens.readonly),r(e.tokens.base),t.type(a(e.idlType)),i(e.tokens.name,{data:e,parent:n}),r(e.tokens.termination)]),{data:e,parent:n})},constructor:function(e,n){return t.definition(t.wrap([d(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:m,field:function(e,n){return t.definition(t.wrap([d(e.extAttrs),r(e.tokens.required),t.type(a(e.idlType)),i(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([d(e.extAttrs),r(e.tokens.base),t.type(a(e.idlType)),i(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([d(e.extAttrs),r(e.tokens.base),t.type(a(e.idlType)),i(e.tokens.name,{data:e}),r(e.tokens.termination)]),{data:e})},includes:function(e){return t.definition(t.wrap([d(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([d(e.extAttrs),r(e.tokens.base),i(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([d(e.extAttrs),r(e.tokens.base),i(e.tokens.name,{data:e}),r(e.tokens.open),b(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:f,maplike:f,setlike:f,"callback interface":m,eof:function(e){return t.trivia(e.trivia)}};function b(e,n){if(!e)return;const r=e.map(e=>(function(e,t){if(!y[e.type])throw new Error(`Type "${e.type}" is unsupported`);return y[e.type](e,t)})(e,n));return t.wrap(r)}return b(e)}function W(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*F(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:W(e,t),cache:{typedefIncludesDictionary:new WeakMap,dictionaryIncludesRequiredField: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 i(n.tokens.name,n,"no-duplicate",r)}}(t)}function U(e){return[...F((t=e,t.flat?t.flat():[].concat(...t)))];var t}n.d(t,"parse",(function(){return P})),n.d(t,"write",(function(){return B})),n.d(t,"validate",(function(){return U})),n.d(t,"WebIDLParseError",(function(){return WebIDLParseError}))}])}));
//# sourceMappingURL=webidl2.js.map

@@ -11,4 +11,4 @@ /**

* @typedef {object} WebIDL2ErrorOptions
* @property {"error" | "warning"} level
* @property {Function} autofix
* @property {"error" | "warning"} [level]
* @property {Function} [autofix]
*

@@ -15,0 +15,0 @@ * @param {string} message error message

@@ -0,8 +1,10 @@

// @ts-check
import { Base } from "./base.js";
import { Default } from "./default.js";
import { ExtendedAttributes } from "./extended-attributes.js";
import { unescape, type_with_extended_attributes } from "./helpers.js";
import { unescape, type_with_extended_attributes, autoParenter, getFirstToken } from "./helpers.js";
import { argumentNameKeywords, Tokeniser } from "../tokeniser.js";
import { validationError } from "../error.js";
import { idlTypeIncludesDictionary } from "../validators/helpers.js";
import { idlTypeIncludesDictionary, dictionaryIncludesRequiredField } from "../validators/helpers.js";

@@ -15,4 +17,5 @@ export class Argument extends Base {

const start_position = tokeniser.position;
/** @type {Base["tokens"]} */
const tokens = {};
const ret = new Argument({ source: tokeniser.source, tokens });
const ret = autoParenter(new Argument({ source: tokeniser.source, tokens }));
ret.extAttrs = ExtendedAttributes.parse(tokeniser);

@@ -32,3 +35,3 @@ tokens.optional = tokeniser.consume("optional");

ret.default = tokens.optional ? Default.parse(tokeniser) : null;
return ret;
return ret.this;
}

@@ -49,9 +52,20 @@

/**
* @param {import("../validator.js").Definitions} defs
*/
*validate(defs) {
yield* this.idlType.validate(defs);
if (idlTypeIncludesDictionary(this.idlType, defs, { useNullableInner: true })) {
const result = idlTypeIncludesDictionary(this.idlType, defs, { useNullableInner: true });
if (result) {
if (this.idlType.nullable) {
const message = `Dictionary arguments cannot be nullable.`;
yield validationError(this.tokens.name, this, "no-nullable-dict-arg", message);
} else if (this.optional && !this.default) {
} else if (!this.optional) {
if (this.parent && !dictionaryIncludesRequiredField(result.dictionary, defs) && isLastRequiredArgument(this)) {
const message = `Dictionary argument must be optional if it has no required fields`;
yield validationError(this.tokens.name, this, "dict-arg-optional", message, {
autofix: autofixDictionaryArgumentOptionality(this)
});
}
} else if (!this.default) {
const message = `Optional dictionary arguments must have a default value of \`{}\`.`;

@@ -69,2 +83,24 @@ yield validationError(this.tokens.name, this, "dict-arg-default", message, {

*/
function isLastRequiredArgument(arg) {
const list = arg.parent.arguments || arg.parent.list;
const index = list.indexOf(arg);
const requiredExists = list.slice(index + 1).some(a => !a.optional);
return !requiredExists;
}
/**
* @param {Argument} arg
*/
function autofixDictionaryArgumentOptionality(arg) {
return () => {
const firstToken = getFirstToken(arg.idlType);
arg.tokens.optional = { type: "optional", value: "optional", trivia: firstToken.trivia };
firstToken.trivia = " ";
autofixOptionalDictionaryDefaultValue(arg)();
};
}
/**
* @param {Argument} arg
*/
function autofixOptionalDictionaryDefaultValue(arg) {

@@ -71,0 +107,0 @@ return () => {

@@ -0,1 +1,3 @@

// @ts-check
export class ArrayBase extends Array {

@@ -6,5 +8,6 @@ constructor({ source, tokens }) {

source: { value: source },
tokens: { value: tokens }
tokens: { value: tokens },
parent: { value: null, writable: true }
});
}
}
import { Base } from "./base.js";
import { type_with_extended_attributes, unescape } from "./helpers.js";
import { type_with_extended_attributes, unescape, autoParenter } from "./helpers.js";

@@ -11,3 +11,3 @@ export class Attribute extends Base {

const tokens = { special };
const ret = new Attribute({ source: tokeniser.source, tokens });
const ret = autoParenter(new Attribute({ source: tokeniser.source, tokens }));
if (!special && !noInherit) {

@@ -35,3 +35,3 @@ tokens.special = tokeniser.consume("inherit");

tokens.termination = tokeniser.consume(";") || tokeniser.error("Unterminated attribute, expected `;`");
return ret;
return ret.this;
}

@@ -38,0 +38,0 @@

@@ -0,6 +1,15 @@

// @ts-check
export class Base {
/**
* @param {object} initializer
* @param {Base["source"]} initializer.source
* @param {Base["tokens"]} initializer.tokens
*/
constructor({ source, tokens }) {
Object.defineProperties(this, {
source: { value: source },
tokens: { value: tokens }
tokens: { value: tokens },
parent: { value: null, writable: true },
this: { value: this } // useful when escaping from proxy
});

@@ -16,2 +25,3 @@ }

if (value.enumerable || value.get) {
// @ts-ignore - allow indexing here
json[key] = this[key];

@@ -18,0 +28,0 @@ }

@@ -0,1 +1,3 @@

// @ts-check
import { Container } from "./container.js";

@@ -5,3 +7,2 @@ import { Operation } from "./operation.js";

export class CallbackInterface extends Container {

@@ -8,0 +9,0 @@ /**

import { Base } from "./base.js";
import { return_type, argument_list, unescape } from "./helpers.js";
import { return_type, argument_list, unescape, autoParenter } from "./helpers.js";

@@ -10,5 +10,5 @@ export class CallbackFunction extends Base {

const tokens = { base };
const ret = new CallbackFunction({ source: tokeniser.source, tokens });
const ret = autoParenter(new CallbackFunction({ source: tokeniser.source, tokens }));
tokens.name = tokeniser.consume("identifier") || tokeniser.error("Callback lacks a name");
tokeniser.current = ret;
tokeniser.current = ret.this;
tokens.assign = tokeniser.consume("=") || tokeniser.error("Callback lacks an assignment");

@@ -20,3 +20,3 @@ ret.idlType = return_type(tokeniser) || tokeniser.error("Callback lacks a return type");

tokens.termination = tokeniser.consume(";") || tokeniser.error("Unterminated callback, expected `;`");
return ret;
return ret.this;
}

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

import { Base } from "./base.js";
import { Type } from "./type.js";
import { const_data, const_value, primitive_type } from "./helpers.js";
import { const_data, const_value, primitive_type, autoParenter } from "./helpers.js";

@@ -10,2 +10,3 @@ export class Constant extends Base {

static parse(tokeniser) {
/** @type {Base["tokens"]} */
const tokens = {};

@@ -30,3 +31,3 @@ tokens.base = tokeniser.consume("const");

const ret = new Constant({ source: tokeniser.source, tokens });
ret.idlType = idlType;
autoParenter(ret).idlType = idlType;
return ret;

@@ -33,0 +34,0 @@ }

import { Base } from "./base.js";
import { argument_list } from "./helpers.js";
import { argument_list, autoParenter } from "./helpers.js";

@@ -13,2 +13,3 @@ export class Constructor extends Base {

}
/** @type {Base["tokens"]} */
const tokens = { base };

@@ -19,4 +20,4 @@ tokens.open = tokeniser.consume("(") || tokeniser.error("No argument list in constructor");

tokens.termination = tokeniser.consume(";") || tokeniser.error("No semicolon after constructor");
const ret = new Constructor({ tokens });
ret.arguments = args;
const ret = new Constructor({ source: tokeniser.source, tokens });
autoParenter(ret).arguments = args;
return ret;

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

import { Base } from "./base.js";
import { ExtendedAttributes } from "./extended-attributes.js";
import { unescape } from "./helpers.js";
import { unescape, autoParenter } from "./helpers.js";

@@ -19,4 +19,5 @@ /**

/**
* @template T
* @param {import("../tokeniser.js").Tokeniser} tokeniser
* @param {*} instance
* @param {T} instance
* @param {*} args

@@ -28,2 +29,3 @@ */

tokeniser.current = instance;
instance = autoParenter(instance);
if (inheritable) {

@@ -38,3 +40,3 @@ Object.assign(tokens, inheritance(tokeniser));

tokens.termination = tokeniser.consume(";") || tokeniser.error(`Missing semicolon after ${type}`);
return instance;
return instance.this;
}

@@ -44,3 +46,3 @@ const ea = ExtendedAttributes.parse(tokeniser);

for (const [parser, ...args] of allowedMembers) {
mem = parser(tokeniser, ...args);
mem = autoParenter(parser(tokeniser, ...args));
if (mem) {

@@ -54,3 +56,3 @@ break;

mem.extAttrs = ea;
instance.members.push(mem);
instance.members.push(mem.this);
}

@@ -57,0 +59,0 @@ }

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

super({ source, tokens });
expression.parent = this;
Object.defineProperty(this, "expression", { value: expression });

@@ -29,0 +30,0 @@ }

@@ -0,1 +1,3 @@

// @ts-check
import { Container } from "./container.js";

@@ -7,2 +9,4 @@ import { Field } from "./field.js";

* @param {import("../tokeniser").Tokeniser} tokeniser
* @param {object} [options]
* @param {import("../tokeniser.js").Token} [options.partial]
*/

@@ -9,0 +13,0 @@ static parse(tokeniser, { partial } = {}) {

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

import { list, unescape } from "./helpers.js";
import { list, unescape, autoParenter } from "./helpers.js";
import { Token } from "./token.js";

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

static parse(tokeniser) {
/** @type {Base["tokens"]} */
const tokens = {};

@@ -36,3 +37,4 @@ tokens.base = tokeniser.consume("enum");

tokens.name = tokeniser.consume("identifier") || tokeniser.error("No name for enum");
const ret = tokeniser.current = new Enum({ source: tokeniser.source, tokens });
const ret = autoParenter(new Enum({ source: tokeniser.source, tokens }));
tokeniser.current = ret.this;
tokens.open = tokeniser.consume("{") || tokeniser.error("Bodyless enum");

@@ -52,3 +54,3 @@ ret.values = list(tokeniser, {

tokens.termination = tokeniser.consume(";") || tokeniser.error("No semicolon after enum");
return ret;
return ret.this;
}

@@ -55,0 +57,0 @@

import { Base } from "./base.js";
import { ArrayBase } from "./array-base.js";
import { list, identifiers, argument_list } from "./helpers.js";
import { Token } from "./token.js";
import { list, argument_list, autoParenter, unescape } from "./helpers.js";
import { validationError } from "../error.js";
/**
* @param {import("../tokeniser").Tokeniser} tokeniser
* @param {string} tokenName
*/
function tokens(tokeniser, tokenName) {
const toks = list(tokeniser, {
parser: Token.parser(tokeniser, tokenName),
listName: tokenName + " list"
});
return toks;
}
/**
* This will allow a set of identifiers or strings to be parsed.
* @param {import("../tokeniser").Tokeniser} tokeniser
*/
function identifiersOrStrings(tokeniser) {
let toks = tokens(tokeniser, "identifier");
if (toks.length) {
return toks;
}
toks = tokens(tokeniser, "string");
if (toks.length) {
return toks;
}
tokeniser.error(`Expected identifiers or strings but none found`);
}
class ExtendedAttributeParameters extends Base {

@@ -12,3 +42,3 @@ /**

const tokens = { assign: tokeniser.consume("=") };
const ret = new ExtendedAttributeParameters({ source: tokeniser.source, tokens });
const ret = autoParenter(new ExtendedAttributeParameters({ source: tokeniser.source, tokens }));
if (tokens.assign) {

@@ -19,5 +49,5 @@ tokens.secondaryName = tokeniser.consume("identifier", "decimal", "integer", "string");

if (tokens.open) {
ret.list = ret.rhsType === "identifier-list" ?
ret.list = ret.rhsIsList ?
// [Exposed=(Window,Worker)]
identifiers(tokeniser) :
identifiersOrStrings(tokeniser) :
// [NamedConstructor=Audio(DOMString src)] or [Constructor(DOMString str)]

@@ -29,9 +59,17 @@ argument_list(tokeniser);

}
return ret;
return ret.this;
}
get rhsIsList() {
return this.tokens.assign && !this.tokens.secondaryName;
}
get rhsType() {
return !this.tokens.assign ? null :
!this.tokens.secondaryName ? "identifier-list" :
this.tokens.secondaryName.type;
if (this.rhsIsList) {
return this.list[0].tokens.value.type + "-list";
}
if (this.tokens.secondaryName) {
return this.tokens.secondaryName.type;
}
return null;
}

@@ -57,2 +95,3 @@ }

super({ source, tokens });
params.parent = this;
Object.defineProperty(this, "params", { value: params });

@@ -72,8 +111,8 @@ }

}
const value = type === "identifier-list" ? list : tokens.secondaryName.value;
const value = this.params.rhsIsList ? list : unescape(tokens.secondaryName.value);
return { type, value };
}
get arguments() {
const { rhsType, list } = this.params;
if (!list || rhsType === "identifier-list") {
const { rhsIsList, list } = this.params;
if (!list || rhsIsList) {
return [];

@@ -80,0 +119,0 @@ }

import { Base } from "./base.js";
import { unescape, type_with_extended_attributes } from "./helpers.js";
import { unescape, type_with_extended_attributes, autoParenter } from "./helpers.js";
import { ExtendedAttributes } from "./extended-attributes.js";

@@ -11,4 +11,5 @@ import { Default } from "./default.js";

static parse(tokeniser) {
/** @type {Base["tokens"]} */
const tokens = {};
const ret = new Field({ source: tokeniser.source, tokens });
const ret = autoParenter(new Field({ source: tokeniser.source, tokens }));
ret.extAttrs = ExtendedAttributes.parse(tokeniser);

@@ -21,3 +22,3 @@ tokens.required = tokeniser.consume("required");

tokens.termination = tokeniser.consume(";") || tokeniser.error("Unterminated dictionary member, expected `;`");
return ret;
return ret.this;
}

@@ -24,0 +25,0 @@

import { Type } from "./type.js";
import { Argument } from "./argument.js";
import { Token } from "./token.js";
import { ExtendedAttributes, SimpleExtendedAttribute } from "./extended-attributes.js";

@@ -115,13 +114,2 @@ import { Operation } from "./operation.js";

*/
export function identifiers(tokeniser) {
const ids = list(tokeniser, { parser: Token.parser(tokeniser, "identifier"), listName: "identifier list" });
if (!ids.length) {
tokeniser.error("Expected identifiers but none found");
}
return ids;
}
/**
* @param {import("../tokeniser").Tokeniser} tokeniser
*/
export function argument_list(tokeniser) {

@@ -138,3 +126,3 @@ return list(tokeniser, { parser: Argument.parse, listName: "arguments list" });

const ret = Type.parse(tokeniser, typeName);
if (ret) ret.extAttrs = extAttrs;
if (ret) autoParenter(ret).extAttrs = extAttrs;
return ret;

@@ -212,3 +200,3 @@ }

} else {
def.extAttrs = ExtendedAttributes.parse(new Tokeniser("[Exposed=Window]"));
autoParenter(def).extAttrs = ExtendedAttributes.parse(new Tokeniser("[Exposed=Window]"));
const trivia = def.tokens.base.trivia;

@@ -235,1 +223,61 @@ def.extAttrs.tokens.open.trivia = trivia;

}
/**
* @template T
* @param {T[]} array
* @param {(item: T) => boolean} predicate
*/
export function findLastIndex(array, predicate) {
const index = array.slice().reverse().findIndex(predicate);
if (index === -1) {
return index;
}
return array.length - index - 1;
}
/**
* Returns a proxy that auto-assign `parent` field.
* @template T
* @param {T} data
* @param {*} [parent] The object that will be assigned to `parent`.
* If absent, it will be `data` by default.
* @return {T}
*/
export function autoParenter(data, parent) {
if (!parent) {
// Defaults to `data` unless specified otherwise.
parent = data;
}
if (!data) {
// This allows `autoParenter(undefined)` which again allows
// `autoParenter(parse())` where the function may return nothing.
return data;
}
return new Proxy(data, {
get(target, p) {
const value = target[p];
if (Array.isArray(value)) {
// Wraps the array so that any added items will also automatically
// get their `parent` values.
return autoParenter(value, target);
}
return value;
},
set(target, p, value) {
target[p] = value;
if (!value) {
return true;
} else if (Array.isArray(value)) {
// Assigning an array will add `parent` to its items.
for (const item of value) {
if (typeof item.parent !== "undefined") {
item.parent = parent;
}
}
} else if (typeof value.parent !== "undefined") {
value.parent = parent;
}
return true;
}
});
}

@@ -0,1 +1,3 @@

// @ts-check
import { Base } from "./base.js";

@@ -2,0 +4,0 @@ import { unescape } from "./helpers.js";

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

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

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

}
const constructors = this.extAttrs.filter(extAttr => extAttr.name === "Constructor");
for (const constructor of constructors) {
const oldConstructors = this.extAttrs.filter(extAttr => extAttr.name === "Constructor");
for (const constructor of oldConstructors) {
const message = `Constructors should now be represented as a \`constructor()\` operation on the interface \

@@ -78,2 +78,17 @@ instead of \`[Constructor]\` extended attribute. Refer to the \

const isGlobal = this.extAttrs.some(extAttr => extAttr.name === "Global");
if (isGlobal) {
const namedConstructors = this.extAttrs.filter(extAttr => extAttr.name === "NamedConstructor");
for (const named of namedConstructors) {
const message = `Interfaces marked as \`[Global]\` cannot have named constructors.`;
yield validationError(named.tokens.name, this, "no-constructible-global", message);
}
const constructors = this.members.filter(member => member.type === "constructor");
for (const named of constructors) {
const message = `Interfaces marked as \`[Global]\` cannot have constructors.`;
yield validationError(named.tokens.base, this, "no-constructible-global", message);
}
}
yield* super.validate(defs);

@@ -87,2 +102,3 @@ if (!this.partial) {

function autofixConstructor(interfaceDef, constructorExtAttr) {
interfaceDef = autoParenter(interfaceDef);
return () => {

@@ -95,5 +111,5 @@ const indentation = getLastIndentation(interfaceDef.extAttrs.tokens.open.trivia);

constructorOp.extAttrs = [];
constructorOp.arguments = constructorExtAttr.arguments;
autoParenter(constructorOp).arguments = constructorExtAttr.arguments;
const existingIndex = interfaceDef.members.findIndex(m => m.type === "constructor");
const existingIndex = findLastIndex(interfaceDef.members, m => m.type === "constructor");
interfaceDef.members.splice(existingIndex + 1, 0, constructorOp);

@@ -100,0 +116,0 @@

import { Base } from "./base.js";
import { type_with_extended_attributes } from "./helpers.js";
import { type_with_extended_attributes, autoParenter } from "./helpers.js";

@@ -11,3 +11,3 @@ export class IterableLike extends Base {

const tokens = {};
const ret = new IterableLike({ source: tokeniser.source, tokens });
const ret = autoParenter(new IterableLike({ source: tokeniser.source, tokens }));
tokens.readonly = tokeniser.consume("readonly");

@@ -45,3 +45,3 @@ if (!tokens.readonly) {

return ret;
return ret.this;
}

@@ -48,0 +48,0 @@

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

/**
* @param {import("../tokeniser").Tokeniser} tokeniser
* @typedef {import("../tokeniser.js").Token} Token
*
* @param {import("../tokeniser.js").Tokeniser} tokeniser
* @param {Token} base
* @param {object} [options]
* @param {Token} [options.partial]
*/

@@ -12,0 +17,0 @@ static parse(tokeniser, base, { partial } = {}) {

@@ -10,2 +10,4 @@ import { Container } from "./container.js";

* @param {import("../tokeniser").Tokeniser} tokeniser
* @param {object} [options]
* @param {import("../tokeniser.js").Token} [options.partial]
*/

@@ -12,0 +14,0 @@ static parse(tokeniser, { partial } = {}) {

import { Base } from "./base.js";
import { return_type, argument_list, unescape } from "./helpers.js";
import { return_type, argument_list, unescape, autoParenter } from "./helpers.js";
import { validationError } from "../error.js";

@@ -7,7 +7,12 @@

/**
* @typedef {import("../tokeniser.js").Token} Token
*
* @param {import("../tokeniser.js").Tokeniser} tokeniser
* @param {object} [options]
* @param {Token} [options.special]
* @param {Token} [options.regular]
*/
static parse(tokeniser, { special, regular } = {}) {
const tokens = { special };
const ret = new Operation({ source: tokeniser.source, tokens });
const ret = autoParenter(new Operation({ source: tokeniser.source, tokens }));
if (special && special.value === "stringifier") {

@@ -29,3 +34,3 @@ tokens.termination = tokeniser.consume(";");

tokens.termination = tokeniser.consume(";") || tokeniser.error("Unterminated operation, expected `;`");
return ret;
return ret.this;
}

@@ -32,0 +37,0 @@

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

// @ts-check
import { Base } from "./base.js";
import { unescape } from "./helpers.js";

@@ -18,4 +21,4 @@ export class Token extends Base {

get value() {
return this.tokens.value.value;
return unescape(this.tokens.value.value);
}
}
import { Base } from "./base.js";
import { unescape, type_with_extended_attributes, return_type, primitive_type } from "./helpers.js";
import { stringTypes } from "../tokeniser.js";
import { unescape, type_with_extended_attributes, return_type, primitive_type, autoParenter } from "./helpers.js";
import { stringTypes, typeNameKeywords } from "../tokeniser.js";
import { validationError } from "../error.js";

@@ -16,3 +16,3 @@ import { idlTypeIncludesDictionary } from "../validators/helpers.js";

}
const ret = new Type({ source: tokeniser.source, tokens: { base } });
const ret = autoParenter(new Type({ source: tokeniser.source, tokens: { base } }));
ret.tokens.open = tokeniser.consume("<") || tokeniser.error(`No opening bracket after ${base.type}`);

@@ -45,3 +45,3 @@ switch (base.type) {

ret.tokens.close = tokeniser.consume(">") || tokeniser.error(`Missing closing bracket after ${base.type}`);
return ret;
return ret.this;
}

@@ -67,3 +67,3 @@

if (!ret) {
const base = tokeniser.consume("identifier", ...stringTypes);
const base = tokeniser.consume("identifier", ...stringTypes, ...typeNameKeywords);
if (!base) {

@@ -92,3 +92,3 @@ return;

if (!tokens.open) return;
const ret = new Type({ source: tokeniser.source, tokens });
const ret = autoParenter(new Type({ source: tokeniser.source, tokens }));
ret.type = type || null;

@@ -98,2 +98,3 @@ while (true) {

if (typ.idlType === "any") tokeniser.error("Type `any` cannot be included in a union type");
if (typ.generic === "Promise") tokeniser.error("Type `Promise` cannot be included in a union type");
ret.subtype.push(typ);

@@ -111,3 +112,3 @@ const or = tokeniser.consume("or");

type_suffix(tokeniser, ret);
return ret;
return ret.this;
}

@@ -126,3 +127,3 @@

super({ source, tokens });
Object.defineProperty(this, "subtype", { value: [] });
Object.defineProperty(this, "subtype", { value: [], writable: true });
this.extAttrs = [];

@@ -168,3 +169,3 @@ }

// do not allow any dictionary
const reference = idlTypeIncludesDictionary(target, defs);
const { reference } = idlTypeIncludesDictionary(target, defs) || {};
if (reference) {

@@ -171,0 +172,0 @@ const targetToken = (this.union ? reference : this).tokens.base;

import { Base } from "./base.js";
import { type_with_extended_attributes, unescape } from "./helpers.js";
import { type_with_extended_attributes, unescape, autoParenter } from "./helpers.js";

@@ -9,4 +9,5 @@ export class Typedef extends Base {

static parse(tokeniser) {
/** @type {Base["tokens"]} */
const tokens = {};
const ret = new Typedef({ source: tokeniser.source, tokens });
const ret = autoParenter(new Typedef({ source: tokeniser.source, tokens }));
tokens.base = tokeniser.consume("typedef");

@@ -18,5 +19,5 @@ if (!tokens.base) {

tokens.name = tokeniser.consume("identifier") || tokeniser.error("Typedef lacks a name");
tokeniser.current = ret;
tokeniser.current = ret.this;
tokens.termination = tokeniser.consume(";") || tokeniser.error("Unterminated typedef, expected `;`");
return ret;
return ret.this;
}

@@ -23,0 +24,0 @@

@@ -18,2 +18,19 @@ import { syntaxError } from "./error.js";

export const typeNameKeywords = [
"ArrayBuffer",
"DataView",
"Int8Array",
"Int16Array",
"Int32Array",
"Uint8Array",
"Uint16Array",
"Uint32Array",
"Uint8ClampedArray",
"Float32Array",
"Float64Array",
"any",
"object",
"symbol"
];
export const stringTypes = [

@@ -57,6 +74,4 @@ "ByteString",

"Promise",
"async",
"boolean",
"byte",
"constructor",
"double",

@@ -78,3 +93,3 @@ "false",

"void"
].concat(argumentNameKeywords, stringTypes);
].concat(argumentNameKeywords, stringTypes, typeNameKeywords);

@@ -106,2 +121,3 @@ const punctuations = [

/**
* @typedef {ArrayItemType<ReturnType<typeof tokenise>>} Token
* @param {string} str

@@ -183,4 +199,4 @@ */

/**
* @param {keyof tokenRe} type
* @param {object} [options]
* @param {keyof typeof tokenRe} type
* @param {object} options
* @param {boolean} [options.noFlushTrivia]

@@ -214,2 +230,3 @@ */

* @param {string} message
* @return {never}
*/

@@ -248,2 +265,12 @@ error(message) {

export class WebIDLParseError extends Error {
/**
* @param {object} options
* @param {string} options.message
* @param {string} options.bareMessage
* @param {string} options.context
* @param {number} options.line
* @param {*} options.sourceName
* @param {string} options.input
* @param {*[]} options.tokens
*/
constructor({ message, bareMessage, context, line, sourceName, input, tokens }) {

@@ -250,0 +277,0 @@ super(message);

@@ -23,2 +23,5 @@ "use strict";

/**
* @typedef {ReturnType<typeof groupDefinitions>} Definitions
*/
function groupDefinitions(all) {

@@ -54,3 +57,4 @@ const unique = new Map();

cache: {
typedefIncludesDictionary: new WeakMap()
typedefIncludesDictionary: new WeakMap(),
dictionaryIncludesRequiredField: new WeakMap()
},

@@ -57,0 +61,0 @@ };

@@ -0,7 +1,11 @@

// @ts-check
/**
* @typedef {import("../productions/dictionary.js").Dictionary} Dictionary
*
* @param {*} idlType
* @param {*[]} defs
* @param {import("../validator.js").Definitions} defs
* @param {object} [options]
* @param {boolean} [options.useNullableInner] use when the input idlType is nullable and you want to use its inner type
* @return the type reference that ultimately includes dictionary.
* @return {{ reference: *, dictionary: Dictionary }} the type reference that ultimately includes dictionary.
*/

@@ -15,3 +19,3 @@ export function idlTypeIncludesDictionary(idlType, defs, { useNullableInner } = {}) {

if (def.type === "typedef") {
const { typedefIncludesDictionary} = defs.cache;
const { typedefIncludesDictionary } = defs.cache;
if (typedefIncludesDictionary.has(def)) {

@@ -26,7 +30,13 @@ // Note that this also halts when it met indeterminate state

if (result) {
return idlType;
return {
reference: idlType,
dictionary: result.dictionary
};
}
}
if (def.type === "dictionary" && (useNullableInner || !idlType.nullable)) {
return idlType;
return {
reference: idlType,
dictionary: def
};
}

@@ -40,5 +50,32 @@ }

}
return subtype;
return {
reference: subtype,
dictionary: result.dictionary
};
}
}
}
/**
* @param {*} dict dictionary type
* @param {import("../validator.js").Definitions} defs
* @return {boolean}
*/
export function dictionaryIncludesRequiredField(dict, defs) {
if (defs.cache.dictionaryIncludesRequiredField.has(dict)) {
return defs.cache.dictionaryIncludesRequiredField.get(dict);
}
defs.cache.dictionaryIncludesRequiredField.set(dict, undefined); // indeterminate
if (dict.inheritance) {
const superdict = defs.unique.get(dict.inheritance);
if (!superdict) {
return true;
}
if (dictionaryIncludesRequiredField(superdict, defs)) {
return true;
}
}
const result = dict.members.some(field => field.required);
defs.cache.dictionaryIncludesRequiredField.set(dict, result);
return result;
}

@@ -0,1 +1,3 @@

// @ts-check
import { validationError } from "../error.js";

@@ -2,0 +4,0 @@

@@ -14,2 +14,3 @@ "use strict";

import { CallbackInterface } from "./productions/callback-interface.js";
import { autoParenter } from "./productions/helpers.js";

@@ -80,3 +81,3 @@ /**

}
def.extAttrs = ea;
autoParenter(def).extAttrs = ea;
defs.push(def);

@@ -95,2 +96,8 @@ }

/**
* @param {string} str
* @param {object} [options]
* @param {*} [options.sourceName]
* @param {boolean} [options.concrete]
*/
export function parse(str, options = {}) {

@@ -97,0 +104,0 @@ const tokeniser = new Tokeniser(str);

@@ -96,2 +96,8 @@ "use strict";

}
function string(str) {
return ts.wrap([
token(str.tokens.value),
token(str.tokens.separator)
]);
}
function identifier(id, context) {

@@ -114,3 +120,5 @@ return ts.wrap([

it.params.list.map(
rhsType === "identifier-list" ? id => identifier(id, it) : argument
rhsType === "identifier-list" ? id => identifier(id, it) :
rhsType === "string-list" ? string :
argument
),

@@ -117,0 +125,0 @@ token(it.params.tokens.close)

{
"name": "webidl2",
"description": "A WebIDL Parser",
"version": "23.9.0",
"version": "23.10.0",
"contributors": [

@@ -14,13 +14,16 @@ "Robin Berjon <robin@berjon.com> (https://berjon.com)",

"devDependencies": {
"eslint": "^6.2.2",
"eslint": "^6.5.1",
"eslint-plugin-import": "^2.18.2",
"expect": "^24.9.0",
"jsondiffpatch": "0.3.11",
"mocha": "6.1.4",
"terser-webpack-plugin": "1.1.0",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.7"
"mocha": "^6.2.1",
"terser-webpack-plugin": "^2.1.2",
"typescript": "^3.6.3",
"webpack": "^4.41.0",
"webpack-cli": "^3.3.9"
},
"scripts": {
"lint": "eslint lib/**/*.js test/*.js test/util/*.js",
"eslint": "eslint lib test",
"typecheck": "tsc -p jsconfig.json",
"lint": "npm run eslint && npm run typecheck",
"test": "npm run lint && webpack && mocha",

@@ -27,0 +30,0 @@ "acquire": "node test/util/acquire.js",

# webidl2.js
[![NPM version](https://badge.fury.io/js/webidl2.svg)](http://badge.fury.io/js/webidl2)
[![NPM version](https://badge.fury.io/js/webidl2.svg)](http://badge.fury.io/js/webidl2) [![Greenkeeper badge](https://badges.greenkeeper.io/w3c/webidl2.js.svg)](https://greenkeeper.io/)

@@ -188,2 +188,3 @@ ## Purpose

* `dict-arg-default`: Optional dictionary type arguments must have a default value of `{}`.
* `dict-arg-optional`: Dictionary type arguments must be optional if the type does not include a required field.
* `no-nullable-dict-arg`: Dictionary arguments cannot be nullable.

@@ -196,2 +197,3 @@ * `no-nullable-union-dict`: Nullable unions cannot include a dictionary type.

* `no-cross-overload`: Overloading must be done within a single interface or namespace.
* `no-constructible-global`: Interfaces with `[Global]` cannot have constructors.
* `input`: a short peek at the text at the point where the error happened

@@ -240,18 +242,2 @@ * `tokens`: the five tokens at the point of error, as understood by the tokeniser

### Trivia
Structures often have `trivia` field that represents whitespaces and comments before tokens. It gives a string if the syntatic component is made of a single token or an object with multiple string type fields.
A trivia object looks like the following example:
```JS
{
"base": "\n",
"name": " ",
"...": "..."
}
```
Frequently, `base` is for type keywords, `name` is for identifiers, `open`/`close` are for brackets, and `termination` for semicolons.
### Interface

@@ -544,3 +530,4 @@

}],
"extAttrs": []
"extAttrs": [],
"parent": { ... }
}

@@ -557,2 +544,3 @@ ```

* `extAttrs`: An array of [extended attributes](#extended-attributes).
* `parent`: The container of this type as an Object.

@@ -580,3 +568,4 @@ ### Constructor Operation Member

}],
"extAttrs": []
"extAttrs": [],
"parent": { ... }
}

@@ -590,2 +579,3 @@ ```

* `extAttrs`: An array of [extended attributes](#extended-attributes).
* `parent`: The container of this type as an Object.

@@ -612,3 +602,4 @@ ### Attribute Member

"name": "regexp",
"extAttrs": []
"extAttrs": [],
"parent": { ... }
}

@@ -625,2 +616,3 @@ ```

* `extAttrs`: An array of [extended attributes](#extended-attributes).
* `parent`: The container of this type as an Object.

@@ -647,3 +639,4 @@ ### Constant Member

},
"extAttrs": []
"extAttrs": [],
"parent": { ... }
}

@@ -659,2 +652,3 @@ ```

* `extAttrs`: An array of [extended attributes](#extended-attributes).
* `parent`: The container of this type as an Object.

@@ -681,2 +675,3 @@ ### Arguments

"name": "ints",
"parent": { ... }
}]

@@ -693,2 +688,3 @@ }

* `extAttrs`: An array of [extended attributes](#extended-attributes).
* `parent`: The container of this type as an Object.

@@ -708,3 +704,4 @@ ### Extended Attributes

"value": "EmptyString"
}
},
"parent": { ... }
}]

@@ -725,4 +722,9 @@ }

* `type`: Always `"extended-attribute"`.
* `rhs`: If there is a right-hand side, this will capture its `type` (which can be
"identifier" or "identifier-list"), its `value`, and its preceding trivia.
* `rhs`: If there is a right-hand side, this will capture its `type` and `value`. The
type can be one of the following:
* `"identifier"`
* `"identifier-list"`
* `"string"`
* `"string-list"`
* `parent`: The container of this type as an Object.

@@ -753,3 +755,4 @@ ### Default and Const Values

"readonly": false, // only for maplike and setlike
"extAttrs": []
"extAttrs": [],
"parent": { ... }
}

@@ -764,2 +767,3 @@ ```

* `extAttrs`: An array of [extended attributes](#extended-attributes).
* `parent`: The container of this type as an Object.

@@ -766,0 +770,0 @@ ### End of file

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