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 22.1.0 to 22.2.0

lib/productions/attribute.js

18

CHANGELOG.md
# Change Log
## [v22.0.0](https://github.com/w3c/webidl2.js/tree/v22.0.0) (2019-06-04)
## [v22.1.0](https://github.com/w3c/webidl2.js/tree/v22.1.0) (2019-07-02)
[Full Changelog](https://github.com/w3c/webidl2.js/compare/v22.0.0...v22.1.0)
**Closed issues:**
- Hard to upgrade to the latest version [\#328](https://github.com/w3c/webidl2.js/issues/328)
**Merged pull requests:**
- refactor\(lib/webidl2\): modularize types+extattrs [\#339](https://github.com/w3c/webidl2.js/pull/339) ([saschanaz](https://github.com/saschanaz))
- feat\(productions/default\): support {} as a default value [\#338](https://github.com/w3c/webidl2.js/pull/338) ([saschanaz](https://github.com/saschanaz))
- refactor\(lib/webidl2\): modularize Type [\#335](https://github.com/w3c/webidl2.js/pull/335) ([saschanaz](https://github.com/saschanaz))
- chore\(package\): update dependencies [\#334](https://github.com/w3c/webidl2.js/pull/334) ([saschanaz](https://github.com/saschanaz))
## [v22.0.0](https://github.com/w3c/webidl2.js/tree/v22.0.0) (2019-06-03)
[Full Changelog](https://github.com/w3c/webidl2.js/compare/v21.1.1...v22.0.0)

@@ -733,2 +747,2 @@

\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*

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";n.r(t);class r{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 s(e,t,n,r,s){function o(n){return n>0?e.slice(t,t+n):e.slice(Math.max(t+n,0),t)}function i(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 a="eof"!==e[t].type?e[t].line:e.length>1?e[t-1].line:1,u=function(e){const t=e.split("\n");return t[t.length-1]}(i(o(-5),{precedes:!0})),c=o(5),p=i(c),l=u+p.split("\n")[0]+"\n"+(" ".repeat(u.length)+"^ "+r);return{message:`${s} error at line ${a}${n?`, ${"Syntax"===s?"since":"inside"} \`${n.partial?"partial ":""}${n.type} ${n.name}\``:""}:\n${l}`,line:a,input:p,tokens:c}}function o(e,t,n,r){return s(e,t.index,n,r,"Validation").message}const i={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},a=["ByteString","DOMString","USVString"],u=["attribute","callback","const","deleter","dictionary","enum","getter","includes","inherit","interface","iterable","maplike","namespace","partial","required","setlike","setter","static","stringifier","typedef","unrestricted"],c=["-Infinity","FrozenArray","Infinity","NaN","Promise","boolean","byte","double","false","float","implements","legacyiterable","long","mixin","null","octet","optional","or","readonly","record","sequence","short","true","unsigned","void"].concat(u,a),p=["(",")",",","...",":",";","<","=",">","?","[","]","{","}"];class l{constructor(e){this.source=function(e){const t=[];let n=0,r="",s=1,o=0;for(;n<e.length;){const i=e.charAt(n);let u=-1;if(/[\t\n\r ]/.test(i)?u=a("whitespace",{noFlushTrivia:!0}):"/"===i&&(u=a("comment",{noFlushTrivia:!0})),-1!==u){const e=t.pop().value;s+=(e.match(/\n/g)||[]).length,r+=e,o-=1}else if(/[-0-9.A-Z_a-z]/.test(i)){if(-1===(u=a("decimal"))&&(u=a("integer")),-1===u){u=a("identifier");const e=t[t.length-1];-1!==u&&c.includes(e.value)&&(e.type=e.value)}}else'"'===i&&(u=a("string"));for(const i of p)if(e.startsWith(i,n)){t.push({type:i,value:i,trivia:r,line:s,index:o}),r="",u=n+=i.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(a,{noFlushTrivia:u}={}){const c=i[a];c.lastIndex=n;const p=c.exec(e);return p?(t.push({type:a,value:p[0],trivia:r,line:s,index:o}),u||(r=""),c.lastIndex):-1}}(e),this.position=0}error(e){throw new d(function(e,t,n,r){return s(e,t,n,r,"Syntax")}(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 d extends Error{constructor({message:e,line:t,input:n,tokens:r}){super(e),this.name="WebIDLParseError",this.line=t,this.input=n,this.tokens=r}}function f(e,t){const n=e.consume("?");n&&(t.tokens.nullable=n),e.probe("?")&&e.error("Can't nullable more than once")}function m(e,t){let n=function(e,t){const n=e.consume("FrozenArray","Promise","sequence","record");if(!n)return;const r=new y({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=P(e,t)||e.error("Missing Promise subtype");r.subtype.push(n);break}case"sequence":case"FrozenArray":{const s=O(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(...a)||e.error(`Record key must be one of: ${a.join(", ")}`),s=new y({source:e.source,tokens:{base:n}});s.tokens.separator=e.consume(",")||e.error("Missing comma after record key type"),s.type=t;const o=O(e,t)||e.error("Error parsing generic type record");r.subtype.push(s,o);break}}return r.idlType||e.error(`Error parsing generic type ${n.type}`),r.tokens.close=e.consume(">")||e.error(`Missing closing bracket after ${n.type}`),r}(e,t)||j(e);if(!n){const t=e.consume("identifier",...a);if(!t)return;n=new y({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,f(e,n),n.nullable&&"any"===n.idlType&&e.error("Type `any` cannot be made nullable"),n}class y extends r{static parse(e,t){return m(e,t)||function(e,t){const n={};if(n.open=e.consume("("),!n.open)return;const r=new y({source:e.source,tokens:n});for(r.type=t||null;;){const t=O(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"),f(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 T([this.tokens.prefix,this.tokens.base,this.tokens.postfix].filter(e=>e).map(e=>e.value).join(" "))}}class k extends r{static parse(e){const t=e.consume("=");if(!t)return null;const n=A(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 k({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 $(this.expression[0]).type}get value(){return $(this.expression[0]).value}get negative(){return $(this.expression[0]).negative}}class b extends Array{constructor({source:e,tokens:t}){super(),Object.defineProperties(this,{source:{value:e},tokens:{value:t}})}}class g extends r{static parse(e){const t={assign:e.consume("=")},n=new g({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=N(e,{parser:w.parser(e,"identifier"),listName:"identifier list"});t.length||e.error("Expected identifiers but none found");return t}(e):M(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 h extends r{static parse(e){const t=e.consume("identifier");if(t)return new h({tokens:{name:t},params:g.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:[]}}class v extends b{static parse(e){const t={};if(t.open=e.consume("["),!t.open)return[];const n=new v({source:e.source,tokens:t});return n.push(...N(e,{parser:h.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}}class x extends r{static parse(e){const t=e.position,n={},r=new x({source:e.source,tokens:n});return r.extAttrs=v.parse(e),n.optional=e.consume("optional"),r.idlType=O(e,"argument-type"),r.idlType?(n.optional||(n.variadic=e.consume("...")),n.name=e.consume("identifier",...u),n.name?(r.default=n.optional?k.parse(e):null,r):e.unconsume(t)):e.unconsume(t)}get optional(){return!!this.tokens.optional}get variadic(){return!!this.tokens.variadic}get name(){return T(this.tokens.name.value)}}class w extends r{static parser(e,t){return()=>{const n=e.consume(t);if(n)return new w({source:e.source,tokens:{value:n}})}}get value(){return this.tokens.value.value}}function T(e){return e.startsWith("_")?e.slice(1):e}function N(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 A(e){return e.consume("true","false","Infinity","-Infinity","NaN","decimal","integer")}function $({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 j(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 y({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 y({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 y({source:t,tokens:{base:r}}):void 0}function M(e){return N(e,{parser:x.parse,listName:"arguments list"})}function O(e,t){const n=v.parse(e),r=y.parse(e,t);return r&&(r.extAttrs=n),r}function P(e,t){const n=y.parse(e,t||"return-type");if(n)return n;const r=e.consume("void");if(r){const t=new y({source:e.source,tokens:{base:r}});return t.type="return-type",t}}class I extends w{static parse(e){const t=e.consume("string");if(t)return new I({source:e.source,tokens:{value:t}})}get type(){return"enum-value"}get value(){return super.value.slice(1,-1)}}class q extends r{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 q({source:e.source,tokens:t});return t.open=e.consume("{")||e.error("Bodyless enum"),n.values=N(e,{parser:I.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 T(this.tokens.name.value)}}class U extends r{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 U({source:e.source,tokens:n});e.unconsume(t.index)}get type(){return"includes"}get target(){return T(this.tokens.target.value)}get includes(){return T(this.tokens.mixin.value)}}function S(e,t){const n=e.source,s="identifier";function o(t){e.error(t)}function i(t){return e.probe(t)}function a(...t){return e.consume(...t)}function u(t){return e.unconsume(t)}class c extends r{static parse(){const t={};if(t.base=a("const"),!t.base)return;let r=j(e);if(!r){const e=a(s)||o("No type for const");r=new y({source:n,tokens:{base:e}})}i("?")&&o("Unexpected nullable constant type"),r.type="const-type",t.name=a(s)||o("No name for const"),t.assign=a("=")||o("No value assignment for const"),t.value=A(e)||o("No value for const"),t.termination=a(";")||o("Unterminated const");const u=new c({source:n,tokens:t});return u.idlType=r,u}get type(){return"const"}get name(){return T(this.tokens.name.value)}get value(){return $(this.tokens.value)}}class p extends r{static parse(t){const r={base:t},i=new p({source:n,tokens:r});return r.name=a(s)||o("No name for callback"),e.current=i,r.assign=a("=")||o("No assignment in callback"),i.idlType=P(e)||o("Missing return type"),r.open=a("(")||o("No arguments in callback"),i.arguments=M(e),r.close=a(")")||o("Unterminated callback"),r.termination=a(";")||o("Unterminated callback"),i}get type(){return"callback"}get name(){return T(this.tokens.name.value)}}class l extends r{static parse({special:t,noInherit:r=!1,readonly:c=!1}={}){const p=e.position,d={special:t},f=new l({source:n,tokens:d});if(t||r||(d.special=a("inherit")),"inherit"===f.special&&i("readonly")&&o("Inherited attributes cannot be read-only"),d.readonly=a("readonly"),c&&!d.readonly&&i("attribute")&&o("Attributes must be readonly in this context"),d.base=a("attribute"),d.base){switch(f.idlType=O(e,"attribute-type")||o("No type in attribute"),f.idlType.generic){case"sequence":case"record":o(`Attributes cannot accept ${f.idlType.generic} types`)}return d.name=a(s,"required")||o("No name in attribute"),d.termination=a(";")||o("Unterminated attribute"),f}u(p)}get type(){return"attribute"}get special(){return this.tokens.special?this.tokens.special.value:""}get readonly(){return!!this.tokens.readonly}get name(){return T(this.tokens.name.value)}}class d extends r{static parse({special:t,regular:r}={}){const i={special:t},u=new d({source:n,tokens:i});return t&&"stringifier"===t.value&&(i.termination=a(";"),i.termination)?(u.arguments=[],u):(t||r||(i.special=a("getter","setter","deleter")),u.idlType=P(e)||o("Missing return type"),i.name=a(s),i.open=a("(")||o("Invalid operation"),u.arguments=M(e),i.close=a(")")||o("Unterminated operation"),i.termination=a(";")||o("Unterminated attribute"),u)}get type(){return"operation"}get name(){const{name:e}=this.tokens;return e?T(e.value):""}get special(){return this.tokens.special?this.tokens.special.value:""}}function f(){const e=a("static");if(e)return l.parse({special:e})||d.parse({special:e})||o("No body in static member")}function m(){const e=a("stringifier");if(e)return l.parse({special:e})||d.parse({special:e})||o("Unterminated stringifier")}class b extends r{static parse(){const t=e.position,r={},s=new b({source:n,tokens:r});if(r.readonly=a("readonly"),r.base=r.readonly?a("maplike","setlike"):a("iterable","maplike","setlike"),!r.base)return void u(t);const{type:i}=s,c="maplike"===i,p=c||"iterable"===i;r.open=a("<")||o(`Error parsing ${i} declaration`);const l=O(e)||o(`Error parsing ${i} declaration`);return s.idlType=[l],p&&(l.tokens.separator=a(","),l.tokens.separator?s.idlType.push(O(e)):c&&o(`Missing second type argument in ${i} declaration`)),r.close=a(">")||o(`Unterminated ${i} declaration`),r.termination=a(";")||o(`Missing semicolon after ${i} declaration`),s}get type(){return this.tokens.base.value}get readonly(){return!!this.tokens.readonly}}class g extends r{static parse(t,{type:n,inheritable:r,allowedMembers:i}){const{tokens:u}=t;for(u.name=a(s)||o("No name for interface"),e.current=t,r&&Object.assign(u,function(){const e=a(":");return e?{colon:e,inheritance:a(s)||o("No type in inheritance")}:{}}()),u.open=a("{")||o(`Bodyless ${n}`),t.members=[];;){if(u.close=a("}"),u.close)return u.termination=a(";")||o(`Missing semicolon after ${n}`),t;const r=v.parse(e);let s;for(const[e,...t]of i)if(s=e(...t))break;s||o("Unknown member"),s.extAttrs=r,t.members.push(s)}}get partial(){return!!this.tokens.partial}get name(){return T(this.tokens.name.value)}get inheritance(){return this.tokens.inheritance?T(this.tokens.inheritance.value):null}}class h extends g{static parse(e,{callback:t=null,partial:r=null}={}){const s={callback:t,partial:r,base:e};return g.parse(new h({source:n,tokens:s}),{type:"interface",inheritable:!r,allowedMembers:[[c.parse],[f],[m],[b.parse],[l.parse],[d.parse]]})}get type(){return this.tokens.callback?"callback interface":"interface"}}class x extends g{static parse(e,{partial:t}={}){const r={partial:t,base:e};if(r.mixin=a("mixin"),r.mixin)return g.parse(new x({source:n,tokens:r}),{type:"interface mixin",allowedMembers:[[c.parse],[m],[l.parse,{noInherit:!0}],[d.parse,{regular:!0}]]})}get type(){return"interface mixin"}}function w(e){const t=a("interface");if(t)return x.parse(t,e)||h.parse(t,e)||o("Interface has no proper body")}class N extends g{static parse({partial:e}={}){const t={partial:e};if(t.base=a("namespace"),t.base)return g.parse(new N({source:n,tokens:t}),{type:"namespace",allowedMembers:[[l.parse,{noInherit:!0,readonly:!0}],[d.parse,{regular:!0}]]})}get type(){return"namespace"}}class I extends g{static parse({partial:e}={}){const t={partial:e};if(t.base=a("dictionary"),t.base)return g.parse(new I({source:n,tokens:t}),{type:"dictionary",inheritable:!e,allowedMembers:[[S.parse]]})}get type(){return"dictionary"}}class S extends r{static parse(){const t={},r=new S({source:n,tokens:t});return r.extAttrs=v.parse(e),t.required=a("required"),r.idlType=O(e,"dictionary-type")||o("No type for dictionary member"),t.name=a(s)||o("No name for dictionary member"),r.default=k.parse(e),t.required&&r.default&&o("Required member must not have a default"),t.termination=a(";")||o("Unterminated dictionary member"),r}get type(){return"field"}get name(){return T(this.tokens.name.value)}get required(){return!!this.tokens.required}}class E extends r{static parse(){const t={},r=new E({source:n,tokens:t});if(t.base=a("typedef"),t.base)return r.idlType=O(e,"typedef-type")||o("No type in typedef"),t.name=a(s)||o("No name in typedef"),e.current=r,t.termination=a(";")||o("Unterminated typedef"),r}get type(){return"typedef"}get name(){return T(this.tokens.name.value)}}function _(){return function(){const e=a("callback");if(!e)return;const t=a("interface");return t?h.parse(t,{callback:e}):p.parse(e)}()||w()||function(){const e=a("partial");if(e)return I.parse({partial:e})||w({partial:e})||N.parse({partial:e})||o("Partial doesn't apply to anything")}()||I.parse()||q.parse(e)||E.parse()||U.parse(e)||N.parse()}const F=function(){if(!n.length)return[];const r=[];for(;;){const t=v.parse(e),n=_();if(!n){t.length&&o("Stray extended attributes");break}n.extAttrs=t,r.push(n)}const s=a("eof");return t.concrete&&r.push(s),r}();return e.position<n.length&&o("Unrecognised tokens"),F}function E(e,t={}){return S(new l(e),t)}function _(e){return e}const F={wrap:e=>e.join(""),trivia:_,name:_,reference:_,type:_,generic:_,inheritance:_,definition:_,extendedAttribute:_,extendedAttributeReference:_};function D(e,{templates:t=F}={}){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 i(e){if(e.union||e.generic)return t.wrap([r(e.tokens.base,t.generic),r(e.tokens.open),...e.subtype.map(a),r(e.tokens.close)]);const s=e.tokens.prefix||e.tokens.base,o=e.tokens.prefix?[e.tokens.prefix.value,t.trivia(e.tokens.base.trivia)]:[],i=n(t.wrap([...o,e.tokens.base.value,r(e.tokens.postfix)]),{unescaped:e.idlType,context:e});return t.wrap([t.trivia(s.trivia),i])}function a(e){return t.wrap([l(e.extAttrs),i(e),r(e.tokens.nullable),r(e.tokens.separator)])}function u(e){return e?t.wrap([r(e.tokens.assign),...e.expression.map(e=>r(e))]):""}function c(e){return t.wrap([l(e.extAttrs),r(e.tokens.optional),t.type(a(e.idlType)),r(e.tokens.variadic),o(e.tokens.name,{data:e}),u(e.default),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):c):[],r(e.params.tokens.close)])),r(e.tokens.separator)])}function l(e){return e.length?t.wrap([r(e.tokens.open),...e.map(p),r(e.tokens.close)]):""}function d(e){return t.definition(t.wrap([l(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 f(e,n){return t.definition(t.wrap([l(e.extAttrs),r(e.tokens.readonly),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({},F,t);const m={interface:d,"interface mixin":d,namespace:d,operation:function(e,n){const s=e.idlType?[t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.open),t.wrap(e.arguments.map(c)),r(e.tokens.close)]:[];return t.definition(t.wrap([l(e.extAttrs),r(e.tokens.special),...s,r(e.tokens.termination)]),{data:e,parent:n})},attribute:function(e,n){return t.definition(t.wrap([l(e.extAttrs),r(e.tokens.special),r(e.tokens.readonly),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.termination)]),{data:e,parent:n})},dictionary:d,field:function(e,n){return t.definition(t.wrap([l(e.extAttrs),r(e.tokens.required),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),u(e.default),r(e.tokens.termination)]),{data:e,parent:n})},const:function(e,n){return t.definition(t.wrap([l(e.extAttrs),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.assign),r(e.tokens.value),r(e.tokens.termination)]),{data:e,parent:n})},typedef:function(e){return t.definition(t.wrap([l(e.extAttrs),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e}),r(e.tokens.termination)]),{data:e})},includes:function(e){return t.definition(t.wrap([l(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([l(e.extAttrs),r(e.tokens.base),o(e.tokens.name,{data:e}),r(e.tokens.assign),t.type(a(e.idlType)),r(e.tokens.open),...e.arguments.map(c),r(e.tokens.close),r(e.tokens.termination)]),{data:e})},enum:function(e){return t.definition(t.wrap([l(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:f,legacyiterable:f,maplike:f,setlike:f,"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(!m[e.type])throw new Error(`Type "${e.type}" is unsupported`);return m[e.type](e,t)})(e,n));return t.wrap(r)}return y(e)}function*z({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.source,n.tokens.name,n,r)}}function*W(e){const t=[...e.unique.values()].filter(e=>"interface"===e.type),n=function(){const t=new Map,n=e.all.filter(e=>"includes"===e.type);for(const r of n){const n=t.get(r.target),s=e.unique.get(r.includes);s&&(n?n.push(s):t.set(r.target,[s]))}return t}();for(const e of t)yield*r(e);function*r(t){const r=new Set(i(t).map(e=>e.name)),o=e.partials.get(t.name)||[],a=n.get(t.name)||[];for(const e of[...o,...a]){const n=i(e);yield*s(n,r,e,t);for(const e of n)r.add(e.name)}}function*s(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(n.source,s.tokens.name,n,t)}}}function i(e){return e.members.filter(({type:e})=>"operation"===e)}}function R(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}}(e);return[...z(t),...W(t)]}n.d(t,"parse",function(){return E}),n.d(t,"write",function(){return D}),n.d(t,"validate",function(){return R})}])});
!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){function o(n){return n>0?e.slice(t,t+n):e.slice(Math.max(t+n,0),t)}function i(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 a="eof"!==e[t].type?e[t].line:e.length>1?e[t-1].line:1,c=function(e){const t=e.split("\n");return t[t.length-1]}(i(o(-5),{precedes:!0})),u=o(5),l=i(u),p=c+l.split("\n")[0]+"\n"+(" ".repeat(c.length)+"^ "+r);return{message:`${s} error at line ${a}${n?`, ${"Syntax"===s?"since":"inside"} \`${n.partial?"partial ":""}${n.type} ${n.name}\``:""}:\n${p}`,line:a,input:l,tokens:u}}function s(e,t,n,s){return r(e,t.index,n,s,"Validation").message}n.r(t);const o={decimal:/-?(?=[0-9]*\.|[0-9]+[eE])(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0-9]+)?|[0-9]+[Ee][-+]?[0-9]+)/y,integer:/-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/y,identifier:/[_-]?[A-Za-z][0-9A-Z_a-z-]*/y,string:/"[^"]*"/y,whitespace:/[\t\n\r ]+/y,comment:/((\/(\/.*|\*([^*]|\*[^\/])*\*\/)[\t\n\r ]*)+)/y,other:/[^\t\n\r 0-9A-Za-z]/y},i=["ByteString","DOMString","USVString"],a=["attribute","callback","const","deleter","dictionary","enum","getter","includes","inherit","interface","iterable","maplike","namespace","partial","required","setlike","setter","static","stringifier","typedef","unrestricted"],c=["-Infinity","FrozenArray","Infinity","NaN","Promise","boolean","byte","double","false","float","implements","legacyiterable","long","mixin","null","octet","optional","or","readonly","record","sequence","short","true","unsigned","void"].concat(a,i),u=["(",")",",","...",":",";","<","=",">","?","[","]","{","}"];class l{constructor(e){this.source=function(e){const t=[];let n=0,r="",s=1,i=0;for(;n<e.length;){const o=e.charAt(n);let l=-1;if(/[\t\n\r ]/.test(o)?l=a("whitespace",{noFlushTrivia:!0}):"/"===o&&(l=a("comment",{noFlushTrivia:!0})),-1!==l){const e=t.pop().value;s+=(e.match(/\n/g)||[]).length,r+=e,i-=1}else if(/[-0-9.A-Z_a-z]/.test(o)){if(-1===(l=a("decimal"))&&(l=a("integer")),-1===l){l=a("identifier");const e=t[t.length-1];-1!==l&&c.includes(e.value)&&(e.type=e.value)}}else'"'===o&&(l=a("string"));for(const o of u)if(e.startsWith(o,n)){t.push({type:o,value:o,trivia:r,line:s,index:i}),r="",l=n+=o.length;break}if(-1===l&&(l=a("other")),-1===l)throw new Error("Token stream not progressing");n=l,i+=1}return t.push({type:"eof",value:"",trivia:r}),t;function a(a,{noFlushTrivia:c}={}){const u=o[a];u.lastIndex=n;const l=u.exec(e);return l?(t.push({type:a,value:l[0],trivia:r,line:s,index:i}),c||(r=""),u.lastIndex):-1}}(e),this.position=0}error(e){throw new p(function(e,t,n,s){return r(e,t,n,s,"Syntax")}(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 p extends Error{constructor({message:e,line:t,input:n,tokens:r}){super(e),this.name="WebIDLParseError",this.line=t,this.input=n,this.tokens=r}}class d{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 m(e,t){const n=e.consume("?");n&&(t.tokens.nullable=n),e.probe("?")&&e.error("Can't nullable more than once")}function f(e,t){let n=function(e,t){const n=e.consume("FrozenArray","Promise","sequence","record");if(!n)return;const r=new y({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=q(e,t)||e.error("Missing Promise subtype");r.subtype.push(n);break}case"sequence":case"FrozenArray":{const s=E(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 y({source:e.source,tokens:{base:n}});s.tokens.separator=e.consume(",")||e.error("Missing comma after record key type"),s.type=t;const o=E(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)||O(e);if(!n){const t=e.consume("identifier",...i);if(!t)return;n=new y({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,m(e,n),n.nullable&&"any"===n.idlType&&e.error("Type `any` cannot be made nullable"),n}class y extends d{static parse(e,t){return f(e,t)||function(e,t){const n={};if(n.open=e.consume("("),!n.open)return;const r=new y({source:e.source,tokens:n});for(r.type=t||null;;){const t=E(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"),m(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 $([this.tokens.prefix,this.tokens.base,this.tokens.postfix].filter(e=>e).map(e=>e.value).join(" "))}}class k extends d{static parse(e){const t=e.consume("=");if(!t)return null;const n=j(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 k({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 I(this.expression[0]).type}get value(){return I(this.expression[0]).value}get negative(){return I(this.expression[0]).negative}}class b extends Array{constructor({source:e,tokens:t}){super(),Object.defineProperties(this,{source:{value:e},tokens:{value:t}})}}class h extends d{static parse(e){const t={assign:e.consume("=")},n=new h({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=N(e,{parser:w.parser(e,"identifier"),listName:"identifier list"});t.length||e.error("Expected identifiers but none found");return t}(e):P(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 g extends d{static parse(e){const t=e.consume("identifier");if(t)return new g({tokens:{name:t},params:h.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:[]}}class x extends b{static parse(e){const t={};if(t.open=e.consume("["),!t.open)return[];const n=new x({source:e.source,tokens:t});return n.push(...N(e,{parser:g.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}}class v extends d{static parse(e){const t=e.position,n={},r=new v({source:e.source,tokens:n});return r.extAttrs=x.parse(e),n.optional=e.consume("optional"),r.idlType=E(e,"argument-type"),r.idlType?(n.optional||(n.variadic=e.consume("...")),n.name=e.consume("identifier",...a),n.name?(r.default=n.optional?k.parse(e):null,r):e.unconsume(t)):e.unconsume(t)}get optional(){return!!this.tokens.optional}get variadic(){return!!this.tokens.variadic}get name(){return $(this.tokens.name.value)}}class w extends d{static parser(e,t){return()=>{const n=e.consume(t);if(n)return new w({source:e.source,tokens:{value:n}})}}get value(){return this.tokens.value.value}}function T(e,t){if(!e.union){const n=t.unique.get(e.idlType);return!!n&&("typedef"===n.type?T(n.idlType,t):"dictionary"===n.type)}for(const n of e.subtype)if(T(n,t))return!0;return!1}class A extends d{static parse(e,{special:t,regular:n}={}){const r={special:t},s=new A({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=q(e)||e.error("Missing return type"),r.name=e.consume("identifier"),r.open=e.consume("(")||e.error("Invalid operation"),s.arguments=P(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?$(e.value):""}get special(){return this.tokens.special?this.tokens.special.value:""}*validate(e){for(const t of this.arguments)if(T(t.idlType,e)&&!t.default){const e="Optional dictionary arguments must have a default value of `{}`.";yield s(this.source,t.tokens.name,this,e)}}}class M extends d{static parse(e,{special:t,noInherit:n=!1,readonly:r=!1}={}){const s=e.position,o={special:t},i=new M({source:e.source,tokens:o});if(t||n||(o.special=e.consume("inherit")),"inherit"===i.special&&e.probe("readonly")&&e.error("Inherited attributes cannot be read-only"),o.readonly=e.consume("readonly"),r&&!o.readonly&&e.probe("attribute")&&e.error("Attributes must be readonly in this context"),o.base=e.consume("attribute"),o.base){switch(i.idlType=E(e,"attribute-type")||e.error("Attribute lacks a type"),i.idlType.generic){case"sequence":case"record":e.error(`Attributes cannot accept ${i.idlType.generic} types`)}return o.name=e.consume("identifier","required")||e.error("Attribute lacks a name"),o.termination=e.consume(";")||e.error("Unterminated attribute, expected `;`"),i}e.unconsume(s)}get type(){return"attribute"}get special(){return this.tokens.special?this.tokens.special.value:""}get readonly(){return!!this.tokens.readonly}get name(){return $(this.tokens.name.value)}}function $(e){return e.startsWith("_")?e.slice(1):e}function N(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 j(e){return e.consume("true","false","Infinity","-Infinity","NaN","decimal","integer")}function I({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 O(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 y({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 y({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 y({source:t,tokens:{base:r}}):void 0}function P(e){return N(e,{parser:v.parse,listName:"arguments list"})}function E(e,t){const n=x.parse(e),r=y.parse(e,t);return r&&(r.extAttrs=n),r}function q(e,t){const n=y.parse(e,t||"return-type");if(n)return n;const r=e.consume("void");if(r){const t=new y({source:e.source,tokens:{base:r}});return t.type="return-type",t}}function U(e){const t=e.consume("stringifier");if(t)return M.parse(e,{special:t})||A.parse(e,{special:t})||e.error("Unterminated stringifier")}class S extends w{static parse(e){const t=e.consume("string");if(t)return new S({source:e.source,tokens:{value:t}})}get type(){return"enum-value"}get value(){return super.value.slice(1,-1)}}class D extends d{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 D({source:e.source,tokens:t});return t.open=e.consume("{")||e.error("Bodyless enum"),n.values=N(e,{parser:S.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 $(this.tokens.name.value)}}class W extends d{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 W({source:e.source,tokens:n});e.unconsume(t.index)}get type(){return"includes"}get target(){return $(this.tokens.target.value)}get includes(){return $(this.tokens.mixin.value)}}class _ extends d{static parse(e){const t={},n=new _({source:e.source,tokens:t});if(t.base=e.consume("typedef"),t.base)return n.idlType=E(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 $(this.tokens.name.value)}}class F extends d{static parse(e,t){const n={base:t},r=new F({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=q(e)||e.error("Callback lacks a return type"),n.open=e.consume("(")||e.error("Callback lacks parentheses for arguments"),r.arguments=P(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 $(this.tokens.name.value)}}class C extends d{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=x.parse(e);let i;for(const[t,...n]of s)if(i=t(e,...n))break;i||e.error("Unknown member"),i.extAttrs=r,t.members.push(i)}}get partial(){return!!this.tokens.partial}get name(){return $(this.tokens.name.value)}get inheritance(){return this.tokens.inheritance?$(this.tokens.inheritance.value):null}*validate(e){for(const t of this.members)t.validate&&(yield*t.validate(e))}}class R extends d{static parse(e){const t={};if(t.base=e.consume("const"),!t.base)return;let n=O(e);if(!n){const t=e.consume("identifier")||e.error("Const lacks a type");n=new y({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=j(e)||e.error("Const lacks a value"),t.termination=e.consume(";")||e.error("Unterminated const, expected `;`");const r=new R({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 I(this.tokens.value)}}class z extends d{static parse(e){const t=e.position,n={},r=new z({source:e.source,tokens:n});if(n.readonly=e.consume("readonly"),n.base=n.readonly?e.consume("maplike","setlike"):e.consume("iterable","maplike","setlike"),!n.base)return void e.unconsume(t);const{type:s}=r,o="maplike"===s,i=o||"iterable"===s;n.open=e.consume("<")||e.error(`Missing less-than sign \`<\` in ${s} declaration`);const a=E(e)||e.error(`Missing a type argument in ${s} declaration`);return r.idlType=[a],i&&(a.tokens.separator=e.consume(","),a.tokens.separator?r.idlType.push(E(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}}function B(e){const t=e.consume("static");if(t)return M.parse(e,{special:t})||A.parse(e,{special:t})||e.error("No body in static member")}class L extends C{static parse(e,t,{partial:n=null}={}){const r={partial:n,base:t};return C.parse(e,new L({source:e.source,tokens:r}),{type:"interface",inheritable:!n,allowedMembers:[[R.parse],[B],[U],[z.parse],[M.parse],[A.parse]]})}get type(){return"interface"}*validate(e){if(!this.partial&&this.extAttrs.every(e=>"Exposed"!==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 s(this.source,this.tokens.name,this,e)}yield*super.validate(e),this.partial||(yield*function*(e,t){const n=new Set(a(t).map(e=>e.name)),r=e.partials.get(t.name)||[],o=e.mixinMap.get(t.name)||[];for(const e of[...r,...o]){const r=a(e);yield*i(r,n,e,t);for(const e of r)n.add(e.name)}function*i(e,t,n,r){for(const o of e){const{name:e}=o;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 s(n.source,o.tokens.name,n,t)}}}function a(e){return e.members.filter(({type:e})=>"operation"===e)}}(e,this))}}class Z extends C{static parse(e,t,{partial:n}={}){const r={partial:n,base:t};if(r.mixin=e.consume("mixin"),r.mixin)return C.parse(e,new Z({source:e.source,tokens:r}),{type:"interface mixin",allowedMembers:[[R.parse],[U],[M.parse,{noInherit:!0}],[A.parse,{regular:!0}]]})}get type(){return"interface mixin"}}class V extends d{static parse(e){const t={},n=new V({source:e.source,tokens:t});return n.extAttrs=x.parse(e),t.required=e.consume("required"),n.idlType=E(e,"dictionary-type")||e.error("Dictionary member lacks a type"),t.name=e.consume("identifier")||e.error("Dictionary member lacks a name"),n.default=k.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 $(this.tokens.name.value)}get required(){return!!this.tokens.required}}class J extends C{static parse(e,{partial:t}={}){const n={partial:t};if(n.base=e.consume("dictionary"),n.base)return C.parse(e,new J({source:e.source,tokens:n}),{type:"dictionary",inheritable:!t,allowedMembers:[[V.parse]]})}get type(){return"dictionary"}}class X extends C{static parse(e,{partial:t}={}){const n={partial:t};if(n.base=e.consume("namespace"),n.base)return C.parse(e,new X({source:e.source,tokens:n}),{type:"namespace",allowedMembers:[[M.parse,{noInherit:!0,readonly:!0}],[A.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 s(this.source,this.tokens.name,this,e)}yield*super.validate(e)}}class G extends C{static parse(e,t,{partial:n=null}={}){const r={callback:t};if(r.base=e.consume("interface"),r.base)return C.parse(e,new G({source:e.source,tokens:r}),{type:"callback interface",inheritable:!n,allowedMembers:[[R.parse],[A.parse,{regular:!0}]]})}get type(){return"callback interface"}}function H(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 Z.parse(e,n,t)||L.parse(e,n,t)||r("Interface has no proper body")}function i(){return function(){const t=s("callback");if(t)return e.probe("interface")?G.parse(e,t):F.parse(e,t)}()||o()||function(){const t=s("partial");if(t)return J.parse(e,{partial:t})||o({partial:t})||X.parse(e,{partial:t})||r("Partial doesn't apply to anything")}()||J.parse(e)||D.parse(e)||_.parse(e)||W.parse(e)||X.parse(e)}const a=function(){if(!n.length)return[];const o=[];for(;;){const t=x.parse(e),n=i();if(!n){t.length&&r("Stray extended attributes");break}n.extAttrs=t,o.push(n)}const a=s("eof");return t.concrete&&o.push(a),o}();return e.position<n.length&&r("Unrecognised tokens"),a}function K(e,t={}){return H(new l(e),t)}function Q(e){return e}const Y={wrap:e=>e.join(""),trivia:Q,name:Q,reference:Q,type:Q,generic:Q,inheritance:Q,definition:Q,extendedAttribute:Q,extendedAttributeReference:Q};function ee(e,{templates:t=Y}={}){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=Q,...r){if(!e)return"";const s=n(e.value,...r);return t.wrap([t.trivia(e.trivia),s])}function s(e,t){return r(e,n,{context:t})}function o(e,n){return r(e,t.name,n)}function i(e){if(e.union||e.generic)return t.wrap([r(e.tokens.base,t.generic),r(e.tokens.open),...e.subtype.map(a),r(e.tokens.close)]);const s=e.tokens.prefix||e.tokens.base,o=e.tokens.prefix?[e.tokens.prefix.value,t.trivia(e.tokens.base.trivia)]:[],i=n(t.wrap([...o,e.tokens.base.value,r(e.tokens.postfix)]),{unescaped:e.idlType,context:e});return t.wrap([t.trivia(s.trivia),i])}function a(e){return t.wrap([p(e.extAttrs),i(e),r(e.tokens.nullable),r(e.tokens.separator)])}function c(e){return e?t.wrap([r(e.tokens.assign),...e.expression.map(e=>r(e))]):""}function u(e){return t.wrap([p(e.extAttrs),r(e.tokens.optional),t.type(a(e.idlType)),r(e.tokens.variadic),o(e.tokens.name,{data:e}),c(e.default),r(e.tokens.separator)])}function l(e){const{rhsType:n}=e.params;return t.wrap([t.trivia(e.tokens.name.trivia),t.extendedAttribute(t.wrap([t.extendedAttributeReference(e.name),r(e.params.tokens.assign),s(e.params.tokens.secondaryName,e),r(e.params.tokens.open),...e.params.list?e.params.list.map("identifier-list"===n?n=>(function(e,n){return t.wrap([s(e.tokens.value,n),r(e.tokens.separator)])})(n,e):u):[],r(e.params.tokens.close)])),r(e.tokens.separator)])}function p(e){return e.length?t.wrap([r(e.tokens.open),...e.map(l),r(e.tokens.close)]):""}function d(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.callback),r(e.tokens.partial),r(e.tokens.base),r(e.tokens.mixin),o(e.tokens.name,{data:e}),(s=e,s.tokens.inheritance?t.wrap([r(s.tokens.colon),t.trivia(s.tokens.inheritance.trivia),t.inheritance(n(s.tokens.inheritance.value,{context:s}))]):""),r(e.tokens.open),y(e.members,e),r(e.tokens.close),r(e.tokens.termination)]),{data:e});var s}function m(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.readonly),r(e.tokens.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({},Y,t);const f={interface:d,"interface mixin":d,namespace:d,operation:function(e,n){const s=e.idlType?[t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.open),t.wrap(e.arguments.map(u)),r(e.tokens.close)]:[];return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.special),...s,r(e.tokens.termination)]),{data:e,parent:n})},attribute:function(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.special),r(e.tokens.readonly),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.termination)]),{data:e,parent:n})},dictionary:d,field:function(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.required),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),c(e.default),r(e.tokens.termination)]),{data:e,parent:n})},const:function(e,n){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e,parent:n}),r(e.tokens.assign),r(e.tokens.value),r(e.tokens.termination)]),{data:e,parent:n})},typedef:function(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),t.type(a(e.idlType)),o(e.tokens.name,{data:e}),r(e.tokens.termination)]),{data:e})},includes:function(e){return t.definition(t.wrap([p(e.extAttrs),s(e.tokens.target,e),r(e.tokens.includes),s(e.tokens.mixin,e),r(e.tokens.termination)]),{data:e})},callback:function(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),o(e.tokens.name,{data:e}),r(e.tokens.assign),t.type(a(e.idlType)),r(e.tokens.open),...e.arguments.map(u),r(e.tokens.close),r(e.tokens.termination)]),{data:e})},enum:function(e){return t.definition(t.wrap([p(e.extAttrs),r(e.tokens.base),o(e.tokens.name,{data:e}),r(e.tokens.open),y(e.values,e),r(e.tokens.close),r(e.tokens.termination)]),{data:e})},"enum-value":function(e,n){return t.wrap([t.trivia(e.tokens.value.trivia),t.definition(t.wrap(['"',t.name(e.value,{data:e,parent:n}),'"']),{data:e,parent:n}),r(e.tokens.separator)])},iterable:m,legacyiterable: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 te(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*ne(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:te(e,t)}}(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 s(n.source,n.tokens.name,n,r)}}(t)}function re(e){return[...ne((t=e,t.flat?t.flat():[].concat(...t)))];var t}n.d(t,"parse",function(){return K}),n.d(t,"write",function(){return ee}),n.d(t,"validate",function(){return re})}])});
//# sourceMappingURL=webidl2.js.map

@@ -0,0 +0,0 @@ /**

@@ -5,2 +5,4 @@ import { Type } from "./type.js";

import { ExtendedAttributes } from "./extended-attributes.js";
import { Operation } from "./operation.js";
import { Attribute } from "./attribute.js";

@@ -155,1 +157,13 @@ /**

}
/**
* @param {import("../tokeniser").Tokeniser} tokeniser
*/
export function stringifier(tokeniser) {
const special = tokeniser.consume("stringifier");
if (!special) return;
const member = Attribute.parse(tokeniser, { special }) ||
Operation.parse(tokeniser, { special }) ||
tokeniser.error("Unterminated stringifier");
return member;
}

@@ -0,0 +0,0 @@ import { syntaxError } from "./error.js";

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

function getMixinMap(all, unique) {
const map = new Map();
const includes = all.filter(def => def.type === "includes");
for (const include of includes) {
const mixin = unique.get(include.includes);
if (!mixin) {
continue;
}
const array = map.get(include.target);
if (array) {
array.push(mixin);
} else {
map.set(include.target, [mixin]);
}
}
return map;
}
function groupDefinitions(all) {

@@ -29,3 +47,9 @@ const unique = new Map();

}
return { all, unique, partials, duplicates };
return {
all,
unique,
partials,
duplicates,
mixinMap: getMixinMap(all, unique)
};
}

@@ -41,63 +65,25 @@

function* checkInterfaceMemberDuplication(defs) {
const interfaces = [...defs.unique.values()].filter(def => def.type === "interface");
const includesMap = getIncludesMap();
for (const i of interfaces) {
yield* forEachInterface(i);
}
function* forEachInterface(i) {
const opNames = new Set(getOperations(i).map(op => op.name));
const partials = defs.partials.get(i.name) || [];
const mixins = includesMap.get(i.name) || [];
for (const ext of [...partials, ...mixins]) {
const additions = getOperations(ext);
yield* forEachExtension(additions, opNames, ext, i);
for (const addition of additions) {
opNames.add(addition.name);
}
function* validateIterable(ast) {
const defs = groupDefinitions(ast);
for (const def of defs.all) {
if (def.validate) {
yield* def.validate(defs);
}
}
yield* checkDuplicatedNames(defs);
}
function* forEachExtension(additions, existings, ext, base) {
for (const addition of additions) {
const { name } = addition;
if (name && existings.has(name)) {
const message = `The operation "${name}" has already been defined for the base interface "${base.name}" either in itself or in a mixin`;
yield error(ext.source, addition.tokens.name, ext, message);
}
}
// Remove this once all of our support targets expose `.flat()` by default
function flatten(array) {
if (array.flat) {
return array.flat();
}
function getOperations(i) {
return i.members
.filter(({type}) => type === "operation");
}
function getIncludesMap() {
const map = new Map();
const includes = defs.all.filter(def => def.type === "includes");
for (const include of includes) {
const array = map.get(include.target);
const mixin = defs.unique.get(include.includes);
if (!mixin) {
continue;
}
if (array) {
array.push(mixin);
} else {
map.set(include.target, [mixin]);
}
}
return map;
}
return [].concat(...array);
}
/**
* @param {*} ast AST or array of ASTs
*/
export function validate(ast) {
const defs = groupDefinitions(ast);
return [
...checkDuplicatedNames(defs),
...checkInterfaceMemberDuplication(defs)
];
return [...validateIterable(flatten(ast))];
}
"use strict";
import { const_data, const_value, unescape, primitive_type, argument_list, type_with_extended_attributes, return_type } from "./productions/helpers.js";
import { Tokeniser } from "./tokeniser.js";
import { Base } from "./productions/base.js";
import { Default } from "./productions/default.js";
import { Enum } from "./productions/enum.js";
import { Includes } from "./productions/includes.js";
import { Type } from "./productions/type.js";
import { ExtendedAttributes } from "./productions/extended-attributes.js";
import { Typedef } from "./productions/typedef.js";
import { CallbackFunction } from "./productions/callback.js";
import { Interface } from "./productions/interface.js";
import { Mixin } from "./productions/mixin.js";
import { Dictionary } from "./productions/dictionary.js";
import { Namespace } from "./productions/namespace.js";
import { CallbackInterface } from "./productions/callback-interface.js";

@@ -20,4 +23,2 @@ /**

const ID = "identifier";
function error(str) {

@@ -27,6 +28,2 @@ tokeniser.error(str);

function probe(type) {
return tokeniser.probe(type);
}
function consume(...candidates) {

@@ -36,332 +33,16 @@ return tokeniser.consume(...candidates);

function unconsume(position) {
return tokeniser.unconsume(position);
}
class Constant extends Base {
static parse() {
const tokens = {};
tokens.base = consume("const");
if (!tokens.base) {
return;
}
let idlType = primitive_type(tokeniser);
if (!idlType) {
const base = consume(ID) || error("No type for const");
idlType = new Type({ source, tokens: { base } });
}
if (probe("?")) {
error("Unexpected nullable constant type");
}
idlType.type = "const-type";
tokens.name = consume(ID) || error("No name for const");
tokens.assign = consume("=") || error("No value assignment for const");
tokens.value = const_value(tokeniser) || error("No value for const");
tokens.termination = consume(";") || error("Unterminated const");
const ret = new Constant({ source, tokens });
ret.idlType = idlType;
return ret;
}
get type() {
return "const";
}
get name() {
return unescape(this.tokens.name.value);
}
get value() {
return const_data(this.tokens.value);
}
}
class CallbackFunction extends Base {
static parse(base) {
const tokens = { base };
const ret = new CallbackFunction({ source, tokens });
tokens.name = consume(ID) || error("No name for callback");
tokeniser.current = ret;
tokens.assign = consume("=") || error("No assignment in callback");
ret.idlType = return_type(tokeniser) || error("Missing return type");
tokens.open = consume("(") || error("No arguments in callback");
ret.arguments = argument_list(tokeniser);
tokens.close = consume(")") || error("Unterminated callback");
tokens.termination = consume(";") || error("Unterminated callback");
return ret;
}
get type() {
return "callback";
}
get name() {
return unescape(this.tokens.name.value);
}
}
function callback() {
const callback = consume("callback");
if (!callback) return;
const tok = consume("interface");
if (tok) {
return Interface.parse(tok, { callback });
if (tokeniser.probe("interface")) {
return CallbackInterface.parse(tokeniser, callback);
}
return CallbackFunction.parse(callback);
return CallbackFunction.parse(tokeniser, callback);
}
class Attribute extends Base {
static parse({ special, noInherit = false, readonly = false } = {}) {
const start_position = tokeniser.position;
const tokens = { special };
const ret = new Attribute({ source, tokens });
if (!special && !noInherit) {
tokens.special = consume("inherit");
}
if (ret.special === "inherit" && probe("readonly")) {
error("Inherited attributes cannot be read-only");
}
tokens.readonly = consume("readonly");
if (readonly && !tokens.readonly && probe("attribute")) {
error("Attributes must be readonly in this context");
}
tokens.base = consume("attribute");
if (!tokens.base) {
unconsume(start_position);
return;
}
ret.idlType = type_with_extended_attributes(tokeniser, "attribute-type") || error("No type in attribute");
switch (ret.idlType.generic) {
case "sequence":
case "record": error(`Attributes cannot accept ${ret.idlType.generic} types`);
}
tokens.name = consume(ID, "required") || error("No name in attribute");
tokens.termination = consume(";") || error("Unterminated attribute");
return ret;
}
get type() {
return "attribute";
}
get special() {
if (!this.tokens.special) {
return "";
}
return this.tokens.special.value;
}
get readonly() {
return !!this.tokens.readonly;
}
get name() {
return unescape(this.tokens.name.value);
}
}
class Operation extends Base {
static parse({ special, regular } = {}) {
const tokens = { special };
const ret = new Operation({ source, tokens });
if (special && special.value === "stringifier") {
tokens.termination = consume(";");
if (tokens.termination) {
ret.arguments = [];
return ret;
}
}
if (!special && !regular) {
tokens.special = consume("getter", "setter", "deleter");
}
ret.idlType = return_type(tokeniser) || error("Missing return type");
tokens.name = consume(ID);
tokens.open = consume("(") || error("Invalid operation");
ret.arguments = argument_list(tokeniser);
tokens.close = consume(")") || error("Unterminated operation");
tokens.termination = consume(";") || error("Unterminated attribute");
return ret;
}
get type() {
return "operation";
}
get name() {
const { name } = this.tokens;
if (!name) {
return "";
}
return unescape(name.value);
}
get special() {
if (!this.tokens.special) {
return "";
}
return this.tokens.special.value;
}
}
function static_member() {
const special = consume("static");
if (!special) return;
const member = Attribute.parse({ special }) ||
Operation.parse({ special }) ||
error("No body in static member");
return member;
}
function stringifier() {
const special = consume("stringifier");
if (!special) return;
const member = Attribute.parse({ special }) ||
Operation.parse({ special }) ||
error("Unterminated stringifier");
return member;
}
class IterableLike extends Base {
static parse() {
const start_position = tokeniser.position;
const tokens = {};
const ret = new IterableLike({ source, tokens });
tokens.readonly = consume("readonly");
tokens.base = tokens.readonly ?
consume("maplike", "setlike") :
consume("iterable", "maplike", "setlike");
if (!tokens.base) {
unconsume(start_position);
return;
}
const { type } = ret;
const secondTypeRequired = type === "maplike";
const secondTypeAllowed = secondTypeRequired || type === "iterable";
tokens.open = consume("<") || error(`Error parsing ${type} declaration`);
const first = type_with_extended_attributes(tokeniser) || error(`Error parsing ${type} declaration`);
ret.idlType = [first];
if (secondTypeAllowed) {
first.tokens.separator = consume(",");
if (first.tokens.separator) {
ret.idlType.push(type_with_extended_attributes(tokeniser));
}
else if (secondTypeRequired)
error(`Missing second type argument in ${type} declaration`);
}
tokens.close = consume(">") || error(`Unterminated ${type} declaration`);
tokens.termination = consume(";") || error(`Missing semicolon after ${type} declaration`);
return ret;
}
get type() {
return this.tokens.base.value;
}
get readonly() {
return !!this.tokens.readonly;
}
}
function inheritance() {
const colon = consume(":");
if (!colon) {
return {};
}
const inheritance = consume(ID) || error("No type in inheritance");
return { colon, inheritance };
}
class Container extends Base {
static parse(instance, { type, inheritable, allowedMembers }) {
const { tokens } = instance;
tokens.name = consume(ID) || error("No name for interface");
tokeniser.current = instance;
if (inheritable) {
Object.assign(tokens, inheritance());
}
tokens.open = consume("{") || error(`Bodyless ${type}`);
instance.members = [];
while (true) {
tokens.close = consume("}");
if (tokens.close) {
tokens.termination = consume(";") || error(`Missing semicolon after ${type}`);
return instance;
}
const ea = ExtendedAttributes.parse(tokeniser);
let mem;
for (const [parser, ...args] of allowedMembers) {
mem = parser(...args);
if (mem) {
break;
}
}
if (!mem) {
error("Unknown member");
}
mem.extAttrs = ea;
instance.members.push(mem);
}
}
get partial() {
return !!this.tokens.partial;
}
get name() {
return unescape(this.tokens.name.value);
}
get inheritance() {
if (!this.tokens.inheritance) {
return null;
}
return unescape(this.tokens.inheritance.value);
}
}
class Interface extends Container {
static parse(base, { callback = null, partial = null } = {}) {
const tokens = { callback, partial, base };
return Container.parse(new Interface({ source, tokens }), {
type: "interface",
inheritable: !partial,
allowedMembers: [
[Constant.parse],
[static_member],
[stringifier],
[IterableLike.parse],
[Attribute.parse],
[Operation.parse]
]
});
}
get type() {
if (this.tokens.callback) {
return "callback interface";
}
return "interface";
}
}
class Mixin extends Container {
static parse(base, { partial } = {}) {
const tokens = { partial, base };
tokens.mixin = consume("mixin");
if (!tokens.mixin) {
return;
}
return Container.parse(new Mixin({ source, tokens }), {
type: "interface mixin",
allowedMembers: [
[Constant.parse],
[stringifier],
[Attribute.parse, { noInherit: true }],
[Operation.parse, { regular: true }]
]
});
}
get type() {
return "interface mixin";
}
}
function interface_(opts) {
const base = consume("interface");
if (!base) return;
const ret = Mixin.parse(base, opts) ||
Interface.parse(base, opts) ||
const ret = Mixin.parse(tokeniser, base, opts) ||
Interface.parse(tokeniser, base, opts) ||
error("Interface has no proper body");

@@ -371,101 +52,11 @@ return ret;

class Namespace extends Container {
static parse({ partial } = {}) {
const tokens = { partial };
tokens.base = consume("namespace");
if (!tokens.base) {
return;
}
return Container.parse(new Namespace({ source, tokens }), {
type: "namespace",
allowedMembers: [
[Attribute.parse, { noInherit: true, readonly: true }],
[Operation.parse, { regular: true }]
]
});
}
get type() {
return "namespace";
}
}
function partial() {
const partial = consume("partial");
if (!partial) return;
return Dictionary.parse({ partial }) ||
return Dictionary.parse(tokeniser, { partial }) ||
interface_({ partial }) ||
Namespace.parse({ partial }) ||
Namespace.parse(tokeniser, { partial }) ||
error("Partial doesn't apply to anything");
}
class Dictionary extends Container {
static parse({ partial } = {}) {
const tokens = { partial };
tokens.base = consume("dictionary");
if (!tokens.base) {
return;
}
return Container.parse(new Dictionary({ source, tokens }), {
type: "dictionary",
inheritable: !partial,
allowedMembers: [
[Field.parse],
]
});
}
get type() {
return "dictionary";
}
}
class Field extends Base {
static parse() {
const tokens = {};
const ret = new Field({ source, tokens });
ret.extAttrs = ExtendedAttributes.parse(tokeniser);
tokens.required = consume("required");
ret.idlType = type_with_extended_attributes(tokeniser, "dictionary-type") || error("No type for dictionary member");
tokens.name = consume(ID) || error("No name for dictionary member");
ret.default = Default.parse(tokeniser);
if (tokens.required && ret.default) error("Required member must not have a default");
tokens.termination = consume(";") || error("Unterminated dictionary member");
return ret;
}
get type() {
return "field";
}
get name() {
return unescape(this.tokens.name.value);
}
get required() {
return !!this.tokens.required;
}
}
class Typedef extends Base {
static parse() {
const tokens = {};
const ret = new Typedef({ source, tokens });
tokens.base = consume("typedef");
if (!tokens.base) {
return;
}
ret.idlType = type_with_extended_attributes(tokeniser, "typedef-type") || error("No type in typedef");
tokens.name = consume(ID) || error("No name in typedef");
tokeniser.current = ret;
tokens.termination = consume(";") || error("Unterminated typedef");
return ret;
}
get type() {
return "typedef";
}
get name() {
return unescape(this.tokens.name.value);
}
}
function definition() {

@@ -475,7 +66,7 @@ return callback() ||

partial() ||
Dictionary.parse() ||
Dictionary.parse(tokeniser) ||
Enum.parse(tokeniser) ||
Typedef.parse() ||
Typedef.parse(tokeniser) ||
Includes.parse(tokeniser) ||
Namespace.parse();
Namespace.parse(tokeniser);
}

@@ -482,0 +73,0 @@

{
"name": "webidl2",
"description": "A WebIDL Parser",
"version": "22.1.0",
"version": "22.2.0",
"contributors": [

@@ -24,3 +24,5 @@ "Robin Berjon <robin@berjon.com> (https://berjon.com)",

"test": "npm run lint && webpack && mocha",
"acquire": "node test/util/acquire.js"
"acquire": "node test/util/acquire.js",
"build": "npx webpack",
"build-debug": "npx webpack --mode none"
},

@@ -27,0 +29,0 @@ "repository": "git://github.com/w3c/webidl2.js",

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