Comparing version 21.1.1 to 22.0.0
# Change Log | ||
## [21.1.1](https://github.com/w3c/webidl2.js/tree/21.1.1) (2019-06-02) | ||
[Full Changelog](https://github.com/w3c/webidl2.js/compare/v21.1.0...21.1.1) | ||
## [v22.0.0](https://github.com/w3c/webidl2.js/tree/v22.0.0) (2019-06-04) | ||
[Full Changelog](https://github.com/w3c/webidl2.js/compare/v21.1.1...v22.0.0) | ||
**Closed issues:** | ||
- eof nodes [\#327](https://github.com/w3c/webidl2.js/issues/327) | ||
**Merged pull requests:** | ||
- BREAKING CHANGE: emit eof only if options.concrete=true [\#333](https://github.com/w3c/webidl2.js/pull/333) ([saschanaz](https://github.com/saschanaz)) | ||
## [v21.1.1](https://github.com/w3c/webidl2.js/tree/v21.1.1) (2019-06-02) | ||
[Full Changelog](https://github.com/w3c/webidl2.js/compare/v21.1.0...v21.1.1) | ||
**Merged pull requests:** | ||
- fix\(lib/webidl2\): inherited attributes cannot be readonly [\#332](https://github.com/w3c/webidl2.js/pull/332) ([saschanaz](https://github.com/saschanaz)) | ||
@@ -9,0 +20,0 @@ |
@@ -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){return e.startsWith("_")?e.slice(1):e}function s(e,{parser:t,allowDangler:n,listName:r="list"}){const s=t(e);if(!s)return[];s.tokens.separator=e.consume(",");const a=[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(","),a.push(s),!s.tokens.separator)break}return a}function a(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"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,t,n,r,s){function a(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(""),a=e[t];return"eof"===a.type?s:r?s+a.trivia:s.slice(a.trivia.length)}const o="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(a(-5),{precedes:!0})),c=a(5),l=i(c),p=u+l.split("\n")[0]+"\n"+(" ".repeat(u.length)+"^ "+r);return{message:`${s} error at line ${o}${n?`, ${"Syntax"===s?"since":"inside"} \`${n.partial?"partial ":""}${n.type} ${n.name}\``:""}:\n${p}`,line:o,input:l,tokens:c}}function u(e,t,n,r){return o(e,t.index,n,r,"Validation").message}n.r(t);const c={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},l=["ByteString","DOMString","USVString"],p=["attribute","callback","const","deleter","dictionary","enum","getter","includes","inherit","interface","iterable","maplike","namespace","partial","required","setlike","setter","static","stringifier","typedef","unrestricted"],d=["-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(p,l),f=["(",")",",","...",":",";","<","=",">","?","[","]","{","}"];class m{constructor(e){this.source=function(e){const t=[];let n=0,r="",s=1,a=0;for(;n<e.length;){const o=e.charAt(n);let u=-1;if(/[\t\n\r ]/.test(o)?u=i("whitespace",{noFlushTrivia:!0}):"/"===o&&(u=i("comment",{noFlushTrivia:!0})),-1!==u){const e=t.pop().value;s+=(e.match(/\n/g)||[]).length,r+=e,a-=1}else if(/[-0-9.A-Z_a-z]/.test(o)){if(-1===(u=i("decimal"))&&(u=i("integer")),-1===u){u=i("identifier");const e=t[t.length-1];-1!==u&&d.includes(e.value)&&(e.type=e.value)}}else'"'===o&&(u=i("string"));for(const i of f)if(e.startsWith(i,n)){t.push({type:i,value:i,trivia:r,line:s,index:a}),r="",u=n+=i.length;break}if(-1===u&&(u=i("other")),-1===u)throw new Error("Token stream not progressing");n=u,a+=1}return t.push({type:"eof",value:"",trivia:r}),t;function i(i,{noFlushTrivia:o}={}){const u=c[i];u.lastIndex=n;const l=u.exec(e);return l?(t.push({type:i,value:l[0],trivia:r,line:s,index:a}),o||(r=""),u.lastIndex):-1}}(e),this.position=0}error(e){throw new y(function(e,t,n,r){return o(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 y 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 k extends Array{constructor({source:e,tokens:t}){super(),Object.defineProperties(this,{source:{value:e},tokens:{value:t}})}}class g{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}}class b extends g{static parser(e,t){return()=>{const n=e.consume(t);if(n)return new b({source:e.source,tokens:{value:n}})}}get value(){return this.tokens.value.value}}class h extends g{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)}return new h({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 v extends b{static parse(e){const t=e.consume("string");if(t)return new v({source:e.source,tokens:{value:t}})}get type(){return"enum-value"}get value(){return super.value.slice(1,-1)}}class x extends g{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 x({source:e.source,tokens:t});return t.open=e.consume("{")||e.error("Bodyless enum"),n.values=s(e,{parser:v.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 r(this.tokens.name.value)}}class w extends g{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 r(this.tokens.target.value)}get includes(){return r(this.tokens.mixin.value)}}function T(e){const t=e.source,n="decimal",o="integer",u="identifier",c="string";function d(t){e.error(t)}function f(t){return e.probe(t)}function m(...t){return e.consume(...t)}function y(t){return e.unconsume(t)}function v(){const e=function(){const e=m("unsigned"),n=m("short","long");if(n){const r=m("long");return new N({source:t,tokens:{prefix:e,base:n,postfix:r}})}e&&d("Failed to parse integer type")}()||function(){const e=m("unrestricted"),n=m("float","double");if(n)return new N({source:t,tokens:{prefix:e,base:n}});e&&d("Failed to parse float type")}();if(e)return e;const n=m("boolean","byte","octet");return n?new N({source:t,tokens:{base:n}}):void 0}function T(e){const t=m("?");t&&(e.tokens.nullable=t),f("?")&&d("Can't nullable more than once")}class N extends g{constructor({source:e,tokens:t}){super({source:e,tokens:t}),Object.defineProperty(this,"subtype",{value:[]}),this.extAttrs=[]}get generic(){return""}get nullable(){return!!this.tokens.nullable}get union(){return!1}get idlType(){if(this.subtype.length)return this.subtype;return r([this.tokens.prefix,this.tokens.base,this.tokens.postfix].filter(e=>e).map(e=>e.value).join(" "))}}class A extends N{static parse(e){const n=m("FrozenArray","Promise","sequence","record");if(!n)return;const r=new A({source:t,tokens:{base:n}});switch(r.tokens.open=m("<")||d(`No opening bracket after ${n.type}`),n.type){case"Promise":{f("[")&&d("Promise type cannot have extended attribute");const t=F(e)||d("Missing Promise subtype");r.subtype.push(t);break}case"sequence":case"FrozenArray":{const t=M(e)||d(`Missing ${n.type} subtype`);r.subtype.push(t);break}case"record":{f("[")&&d("Record key cannot have extended attribute");const n=m(...l)||d(`Record key must be one of: ${l.join(", ")}`),s=new N({source:t,tokens:{base:n}});s.tokens.separator=m(",")||d("Missing comma after record key type"),s.type=e;const a=M(e)||d("Error parsing generic type record");r.subtype.push(s,a);break}}return r.idlType||d(`Error parsing generic type ${n.type}`),r.tokens.close=m(">")||d(`Missing closing bracket after ${n.type}`),r}get generic(){return this.tokens.base.value}}class $ extends N{static parse(e){const n={};if(n.open=m("("),!n.open)return;const r=new $({source:t,tokens:n});for(r.type=e||null;;){const e=M()||d("No type after open parenthesis or 'or' in union type");"any"===e.idlType&&d("Type `any` cannot be included in a union type"),r.subtype.push(e);const t=m("or");if(!t)break;e.tokens.separator=t}return r.idlType.length<2&&d("At least two types are expected in a union type but found less"),n.close=m(")")||d("Unterminated union type"),T(r),r}get union(){return!0}}function j(e){return function(e){let n=A.parse(e)||v();if(!n){const e=m(u,...l);if(!e)return;n=new N({source:t,tokens:{base:e}}),f("<")&&d(`Unsupported generic type ${e.value}`)}return"Promise"===n.generic&&f("?")&&d("Promise type cannot be nullable"),n.type=e||null,T(n),n.nullable&&"any"===n.idlType&&d("Type `any` cannot be made nullable"),n}(e)||$.parse(e)}function M(e){const t=U.parse(),n=j(e);return n&&(n.extAttrs=t),n}class O extends g{static parse(){const n=e.position,r={},s=new O({source:t,tokens:r});return s.extAttrs=U.parse(),r.optional=m("optional"),s.idlType=M("argument-type"),s.idlType?(r.optional||(r.variadic=m("...")),r.name=m(u,...p),r.name?(s.default=r.optional?h.parse(e):null,s):y(n)):y(n)}get optional(){return!!this.tokens.optional}get variadic(){return!!this.tokens.variadic}get name(){return r(this.tokens.name.value)}}function P(){return s(e,{parser:O.parse,listName:"arguments list"})}class I extends g{static parse(){const r={assign:m("=")},a=new I({source:t,tokens:r});return r.assign&&(r.secondaryName=m(u,n,o,c)),r.open=m("("),r.open?(a.list="identifier-list"===a.rhsType?function(){const t=s(e,{parser:b.parser(e,u),listName:"identifier list"});return t.length||d("Expected identifiers but none found"),t}():P(),r.close=m(")")||d("Unexpected token in extended attribute argument list")):a.hasRhs&&!r.secondaryName&&d("No right hand side to extended attribute assignment"),a}get rhsType(){return this.tokens.assign?this.tokens.secondaryName?this.tokens.secondaryName.type:"identifier-list":null}}class q extends g{static parse(){const e=m(u);if(e)return new q({tokens:{name:e},params:I.parse()})}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 U extends k{static parse(){const n={};if(n.open=m("["),!n.open)return[];const r=new U({source:t,tokens:n});return r.push(...s(e,{parser:q.parse,listName:"extended attribute"})),n.close=m("]")||d("Unexpected form of extended attribute"),r.length||d("Found an empty extended attribute"),f("[")&&d("Illegal double extended attribute lists, consider merging them"),r}}class S extends g{static parse(){const n={};if(n.base=m("const"),!n.base)return;let r=v();if(!r){const e=m(u)||d("No type for const");r=new N({source:t,tokens:{base:e}})}f("?")&&d("Unexpected nullable constant type"),r.type="const-type",n.name=m(u)||d("No name for const"),n.assign=m("=")||d("No value assignment for const"),n.value=a(e)||d("No value for const"),n.termination=m(";")||d("Unterminated const");const s=new S({source:t,tokens:n});return s.idlType=r,s}get type(){return"const"}get name(){return r(this.tokens.name.value)}get value(){return i(this.tokens.value)}}class E extends g{static parse(n){const r={base:n},s=new E({source:t,tokens:r});return r.name=m(u)||d("No name for callback"),e.current=s,r.assign=m("=")||d("No assignment in callback"),s.idlType=F()||d("Missing return type"),r.open=m("(")||d("No arguments in callback"),s.arguments=P(),r.close=m(")")||d("Unterminated callback"),r.termination=m(";")||d("Unterminated callback"),s}get type(){return"callback"}get name(){return r(this.tokens.name.value)}}class _ extends g{static parse({special:n,noInherit:r=!1,readonly:s=!1}={}){const a=e.position,i={special:n},o=new _({source:t,tokens:i});if(n||r||(i.special=m("inherit")),"inherit"===o.special&&f("readonly")&&d("Inherited attributes cannot be read-only"),i.readonly=m("readonly"),s&&!i.readonly&&f("attribute")&&d("Attributes must be readonly in this context"),i.base=m("attribute"),i.base){switch(o.idlType=M("attribute-type")||d("No type in attribute"),o.idlType.generic){case"sequence":case"record":d(`Attributes cannot accept ${o.idlType.generic} types`)}return i.name=m(u,"required")||d("No name in attribute"),i.termination=m(";")||d("Unterminated attribute"),o}y(a)}get type(){return"attribute"}get special(){return this.tokens.special?this.tokens.special.value:""}get readonly(){return!!this.tokens.readonly}get name(){return r(this.tokens.name.value)}}function F(e){const n=j(e||"return-type");if(n)return n;const r=m("void");if(r){const e=new N({source:t,tokens:{base:r}});return e.type="return-type",e}}class D extends g{static parse({special:e,regular:n}={}){const r={special:e},s=new D({source:t,tokens:r});return e&&"stringifier"===e.value&&(r.termination=m(";"),r.termination)?(s.arguments=[],s):(e||n||(r.special=m("getter","setter","deleter")),s.idlType=F()||d("Missing return type"),r.name=m(u),r.open=m("(")||d("Invalid operation"),s.arguments=P(),r.close=m(")")||d("Unterminated operation"),r.termination=m(";")||d("Unterminated attribute"),s)}get type(){return"operation"}get name(){const{name:e}=this.tokens;return e?r(e.value):""}get special(){return this.tokens.special?this.tokens.special.value:""}}function z(){const e=m("static");if(e)return _.parse({special:e})||D.parse({special:e})||d("No body in static member")}function W(){const e=m("stringifier");if(e)return _.parse({special:e})||D.parse({special:e})||d("Unterminated stringifier")}class R extends g{static parse(){const n=e.position,r={},s=new R({source:t,tokens:r});if(r.readonly=m("readonly"),r.base=r.readonly?m("maplike","setlike"):m("iterable","maplike","setlike"),!r.base)return void y(n);const{type:a}=s,i="maplike"===a,o=i||"iterable"===a;r.open=m("<")||d(`Error parsing ${a} declaration`);const u=M()||d(`Error parsing ${a} declaration`);return s.idlType=[u],o&&(u.tokens.separator=m(","),u.tokens.separator?s.idlType.push(M()):i&&d(`Missing second type argument in ${a} declaration`)),r.close=m(">")||d(`Unterminated ${a} declaration`),r.termination=m(";")||d(`Missing semicolon after ${a} declaration`),s}get type(){return this.tokens.base.value}get readonly(){return!!this.tokens.readonly}}class Z extends g{static parse(t,{type:n,inheritable:r,allowedMembers:s}){const{tokens:a}=t;for(a.name=m(u)||d("No name for interface"),e.current=t,r&&Object.assign(a,function(){const e=m(":");return e?{colon:e,inheritance:m(u)||d("No type in inheritance")}:{}}()),a.open=m("{")||d(`Bodyless ${n}`),t.members=[];;){if(a.close=m("}"),a.close)return a.termination=m(";")||d(`Missing semicolon after ${n}`),t;const e=U.parse();let r;for(const[e,...t]of s)if(r=e(...t))break;r||d("Unknown member"),r.extAttrs=e,t.members.push(r)}}get partial(){return!!this.tokens.partial}get name(){return r(this.tokens.name.value)}get inheritance(){return this.tokens.inheritance?r(this.tokens.inheritance.value):null}}class B extends Z{static parse(e,{callback:n=null,partial:r=null}={}){const s={callback:n,partial:r,base:e};return Z.parse(new B({source:t,tokens:s}),{type:"interface",inheritable:!r,allowedMembers:[[S.parse],[z],[W],[R.parse],[_.parse],[D.parse]]})}get type(){return this.tokens.callback?"callback interface":"interface"}}class L extends Z{static parse(e,{partial:n}={}){const r={partial:n,base:e};if(r.mixin=m("mixin"),r.mixin)return Z.parse(new L({source:t,tokens:r}),{type:"interface mixin",allowedMembers:[[S.parse],[W],[_.parse,{noInherit:!0}],[D.parse,{regular:!0}]]})}get type(){return"interface mixin"}}function V(e){const t=m("interface");if(t)return L.parse(t,e)||B.parse(t,e)||d("Interface has no proper body")}class C extends Z{static parse({partial:e}={}){const n={partial:e};if(n.base=m("namespace"),n.base)return Z.parse(new C({source:t,tokens:n}),{type:"namespace",allowedMembers:[[_.parse,{noInherit:!0,readonly:!0}],[D.parse,{regular:!0}]]})}get type(){return"namespace"}}class J extends Z{static parse({partial:e}={}){const n={partial:e};if(n.base=m("dictionary"),n.base)return Z.parse(new J({source:t,tokens:n}),{type:"dictionary",inheritable:!e,allowedMembers:[[X.parse]]})}get type(){return"dictionary"}}class X extends g{static parse(){const n={},r=new X({source:t,tokens:n});return r.extAttrs=U.parse(),n.required=m("required"),r.idlType=M("dictionary-type")||d("No type for dictionary member"),n.name=m(u)||d("No name for dictionary member"),r.default=h.parse(e),n.required&&r.default&&d("Required member must not have a default"),n.termination=m(";")||d("Unterminated dictionary member"),r}get type(){return"field"}get name(){return r(this.tokens.name.value)}get required(){return!!this.tokens.required}}class G extends g{static parse(){const n={},r=new G({source:t,tokens:n});if(n.base=m("typedef"),n.base)return r.idlType=M("typedef-type")||d("No type in typedef"),n.name=m(u)||d("No name in typedef"),e.current=r,n.termination=m(";")||d("Unterminated typedef"),r}get type(){return"typedef"}get name(){return r(this.tokens.name.value)}}function H(){return function(){const e=m("callback");if(!e)return;const t=m("interface");return t?B.parse(t,{callback:e}):E.parse(e)}()||V()||function(){const e=m("partial");if(e)return J.parse({partial:e})||V({partial:e})||C.parse({partial:e})||d("Partial doesn't apply to anything")}()||J.parse()||x.parse(e)||G.parse()||w.parse(e)||C.parse()}const K=function(){if(!t.length)return[];const e=[];for(;;){const t=U.parse(),n=H();if(!n){t.length&&d("Stray extended attributes");break}n.extAttrs=t,e.push(n)}return e.push(m("eof")),e}();return e.position<t.length&&d("Unrecognised tokens"),K}function N(e){return T(new m(e))}function A(e){return e}const $={wrap:e=>e.join(""),trivia:A,name:A,reference:A,type:A,generic:A,inheritance:A,definition:A,extendedAttribute:A,extendedAttributeReference:A};function j(e,{templates:t=$}={}){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=A,...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 a(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(o),r(e.tokens.close)]);const s=e.tokens.prefix||e.tokens.base,a=e.tokens.prefix?[e.tokens.prefix.value,t.trivia(e.tokens.base.trivia)]:[],i=n(t.wrap([...a,e.tokens.base.value,r(e.tokens.postfix)]),{unescaped:e.idlType,context:e});return t.wrap([t.trivia(s.trivia),i])}function o(e){return t.wrap([p(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([p(e.extAttrs),r(e.tokens.optional),t.type(o(e.idlType)),r(e.tokens.variadic),a(e.tokens.name,{data:e}),u(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):c):[],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),a(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([p(e.extAttrs),r(e.tokens.readonly),r(e.tokens.base,t.generic),r(e.tokens.open),t.wrap(e.idlType.map(o)),r(e.tokens.close),r(e.tokens.termination)]),{data:e,parent:n})}t=Object.assign({},$,t);const m={interface:d,"interface mixin":d,namespace:d,operation:function(e,n){const s=e.idlType?[t.type(o(e.idlType)),a(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([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(o(e.idlType)),a(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(o(e.idlType)),a(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([p(e.extAttrs),r(e.tokens.base),t.type(o(e.idlType)),a(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(o(e.idlType)),a(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),a(e.tokens.name,{data:e}),r(e.tokens.assign),t.type(o(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([p(e.extAttrs),r(e.tokens.base),a(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*M({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 u(n.source,n.tokens.name,n,r)}}function*O(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(a(t).map(e=>e.name)),i=e.partials.get(t.name)||[],o=n.get(t.name)||[];for(const e of[...i,...o]){const n=a(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 u(n.source,s.tokens.name,n,t)}}}function a(e){return e.members.filter(({type:e})=>"operation"===e)}}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}}(e);return[...M(t),...O(t)]}n.d(t,"parse",function(){return N}),n.d(t,"write",function(){return j}),n.d(t,"validate",function(){return P})}])}); | ||
!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){return e.startsWith("_")?e.slice(1):e}function s(e,{parser:t,allowDangler:n,listName:r="list"}){const s=t(e);if(!s)return[];s.tokens.separator=e.consume(",");const a=[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(","),a.push(s),!s.tokens.separator)break}return a}function a(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"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,t,n,r,s){function a(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(""),a=e[t];return"eof"===a.type?s:r?s+a.trivia:s.slice(a.trivia.length)}const o="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(a(-5),{precedes:!0})),c=a(5),l=i(c),p=u+l.split("\n")[0]+"\n"+(" ".repeat(u.length)+"^ "+r);return{message:`${s} error at line ${o}${n?`, ${"Syntax"===s?"since":"inside"} \`${n.partial?"partial ":""}${n.type} ${n.name}\``:""}:\n${p}`,line:o,input:l,tokens:c}}function u(e,t,n,r){return o(e,t.index,n,r,"Validation").message}n.r(t);const c={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},l=["ByteString","DOMString","USVString"],p=["attribute","callback","const","deleter","dictionary","enum","getter","includes","inherit","interface","iterable","maplike","namespace","partial","required","setlike","setter","static","stringifier","typedef","unrestricted"],d=["-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(p,l),f=["(",")",",","...",":",";","<","=",">","?","[","]","{","}"];class m{constructor(e){this.source=function(e){const t=[];let n=0,r="",s=1,a=0;for(;n<e.length;){const o=e.charAt(n);let u=-1;if(/[\t\n\r ]/.test(o)?u=i("whitespace",{noFlushTrivia:!0}):"/"===o&&(u=i("comment",{noFlushTrivia:!0})),-1!==u){const e=t.pop().value;s+=(e.match(/\n/g)||[]).length,r+=e,a-=1}else if(/[-0-9.A-Z_a-z]/.test(o)){if(-1===(u=i("decimal"))&&(u=i("integer")),-1===u){u=i("identifier");const e=t[t.length-1];-1!==u&&d.includes(e.value)&&(e.type=e.value)}}else'"'===o&&(u=i("string"));for(const i of f)if(e.startsWith(i,n)){t.push({type:i,value:i,trivia:r,line:s,index:a}),r="",u=n+=i.length;break}if(-1===u&&(u=i("other")),-1===u)throw new Error("Token stream not progressing");n=u,a+=1}return t.push({type:"eof",value:"",trivia:r}),t;function i(i,{noFlushTrivia:o}={}){const u=c[i];u.lastIndex=n;const l=u.exec(e);return l?(t.push({type:i,value:l[0],trivia:r,line:s,index:a}),o||(r=""),u.lastIndex):-1}}(e),this.position=0}error(e){throw new y(function(e,t,n,r){return o(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 y 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 k extends Array{constructor({source:e,tokens:t}){super(),Object.defineProperties(this,{source:{value:e},tokens:{value:t}})}}class g{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}}class b extends g{static parser(e,t){return()=>{const n=e.consume(t);if(n)return new b({source:e.source,tokens:{value:n}})}}get value(){return this.tokens.value.value}}class h extends g{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)}return new h({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 v extends b{static parse(e){const t=e.consume("string");if(t)return new v({source:e.source,tokens:{value:t}})}get type(){return"enum-value"}get value(){return super.value.slice(1,-1)}}class x extends g{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 x({source:e.source,tokens:t});return t.open=e.consume("{")||e.error("Bodyless enum"),n.values=s(e,{parser:v.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 r(this.tokens.name.value)}}class w extends g{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 r(this.tokens.target.value)}get includes(){return r(this.tokens.mixin.value)}}function T(e,t){const n=e.source,o="decimal",u="integer",c="identifier",d="string";function f(t){e.error(t)}function m(t){return e.probe(t)}function y(...t){return e.consume(...t)}function v(t){return e.unconsume(t)}function T(){const e=function(){const e=y("unsigned"),t=y("short","long");if(t){const r=y("long");return new A({source:n,tokens:{prefix:e,base:t,postfix:r}})}e&&f("Failed to parse integer type")}()||function(){const e=y("unrestricted"),t=y("float","double");if(t)return new A({source:n,tokens:{prefix:e,base:t}});e&&f("Failed to parse float type")}();if(e)return e;const t=y("boolean","byte","octet");return t?new A({source:n,tokens:{base:t}}):void 0}function N(e){const t=y("?");t&&(e.tokens.nullable=t),m("?")&&f("Can't nullable more than once")}class A extends g{constructor({source:e,tokens:t}){super({source:e,tokens:t}),Object.defineProperty(this,"subtype",{value:[]}),this.extAttrs=[]}get generic(){return""}get nullable(){return!!this.tokens.nullable}get union(){return!1}get idlType(){if(this.subtype.length)return this.subtype;return r([this.tokens.prefix,this.tokens.base,this.tokens.postfix].filter(e=>e).map(e=>e.value).join(" "))}}class $ extends A{static parse(e){const t=y("FrozenArray","Promise","sequence","record");if(!t)return;const r=new $({source:n,tokens:{base:t}});switch(r.tokens.open=y("<")||f(`No opening bracket after ${t.type}`),t.type){case"Promise":{m("[")&&f("Promise type cannot have extended attribute");const t=D(e)||f("Missing Promise subtype");r.subtype.push(t);break}case"sequence":case"FrozenArray":{const n=O(e)||f(`Missing ${t.type} subtype`);r.subtype.push(n);break}case"record":{m("[")&&f("Record key cannot have extended attribute");const t=y(...l)||f(`Record key must be one of: ${l.join(", ")}`),s=new A({source:n,tokens:{base:t}});s.tokens.separator=y(",")||f("Missing comma after record key type"),s.type=e;const a=O(e)||f("Error parsing generic type record");r.subtype.push(s,a);break}}return r.idlType||f(`Error parsing generic type ${t.type}`),r.tokens.close=y(">")||f(`Missing closing bracket after ${t.type}`),r}get generic(){return this.tokens.base.value}}class j extends A{static parse(e){const t={};if(t.open=y("("),!t.open)return;const r=new j({source:n,tokens:t});for(r.type=e||null;;){const e=O()||f("No type after open parenthesis or 'or' in union type");"any"===e.idlType&&f("Type `any` cannot be included in a union type"),r.subtype.push(e);const t=y("or");if(!t)break;e.tokens.separator=t}return r.idlType.length<2&&f("At least two types are expected in a union type but found less"),t.close=y(")")||f("Unterminated union type"),N(r),r}get union(){return!0}}function M(e){return function(e){let t=$.parse(e)||T();if(!t){const e=y(c,...l);if(!e)return;t=new A({source:n,tokens:{base:e}}),m("<")&&f(`Unsupported generic type ${e.value}`)}return"Promise"===t.generic&&m("?")&&f("Promise type cannot be nullable"),t.type=e||null,N(t),t.nullable&&"any"===t.idlType&&f("Type `any` cannot be made nullable"),t}(e)||j.parse(e)}function O(e){const t=S.parse(),n=M(e);return n&&(n.extAttrs=t),n}class P extends g{static parse(){const t=e.position,r={},s=new P({source:n,tokens:r});return s.extAttrs=S.parse(),r.optional=y("optional"),s.idlType=O("argument-type"),s.idlType?(r.optional||(r.variadic=y("...")),r.name=y(c,...p),r.name?(s.default=r.optional?h.parse(e):null,s):v(t)):v(t)}get optional(){return!!this.tokens.optional}get variadic(){return!!this.tokens.variadic}get name(){return r(this.tokens.name.value)}}function I(){return s(e,{parser:P.parse,listName:"arguments list"})}class q extends g{static parse(){const t={assign:y("=")},r=new q({source:n,tokens:t});return t.assign&&(t.secondaryName=y(c,o,u,d)),t.open=y("("),t.open?(r.list="identifier-list"===r.rhsType?function(){const t=s(e,{parser:b.parser(e,c),listName:"identifier list"});return t.length||f("Expected identifiers but none found"),t}():I(),t.close=y(")")||f("Unexpected token in extended attribute argument list")):r.hasRhs&&!t.secondaryName&&f("No right hand side to extended attribute assignment"),r}get rhsType(){return this.tokens.assign?this.tokens.secondaryName?this.tokens.secondaryName.type:"identifier-list":null}}class U extends g{static parse(){const e=y(c);if(e)return new U({tokens:{name:e},params:q.parse()})}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 S extends k{static parse(){const t={};if(t.open=y("["),!t.open)return[];const r=new S({source:n,tokens:t});return r.push(...s(e,{parser:U.parse,listName:"extended attribute"})),t.close=y("]")||f("Unexpected form of extended attribute"),r.length||f("Found an empty extended attribute"),m("[")&&f("Illegal double extended attribute lists, consider merging them"),r}}class E extends g{static parse(){const t={};if(t.base=y("const"),!t.base)return;let r=T();if(!r){const e=y(c)||f("No type for const");r=new A({source:n,tokens:{base:e}})}m("?")&&f("Unexpected nullable constant type"),r.type="const-type",t.name=y(c)||f("No name for const"),t.assign=y("=")||f("No value assignment for const"),t.value=a(e)||f("No value for const"),t.termination=y(";")||f("Unterminated const");const s=new E({source:n,tokens:t});return s.idlType=r,s}get type(){return"const"}get name(){return r(this.tokens.name.value)}get value(){return i(this.tokens.value)}}class _ extends g{static parse(t){const r={base:t},s=new _({source:n,tokens:r});return r.name=y(c)||f("No name for callback"),e.current=s,r.assign=y("=")||f("No assignment in callback"),s.idlType=D()||f("Missing return type"),r.open=y("(")||f("No arguments in callback"),s.arguments=I(),r.close=y(")")||f("Unterminated callback"),r.termination=y(";")||f("Unterminated callback"),s}get type(){return"callback"}get name(){return r(this.tokens.name.value)}}class F extends g{static parse({special:t,noInherit:r=!1,readonly:s=!1}={}){const a=e.position,i={special:t},o=new F({source:n,tokens:i});if(t||r||(i.special=y("inherit")),"inherit"===o.special&&m("readonly")&&f("Inherited attributes cannot be read-only"),i.readonly=y("readonly"),s&&!i.readonly&&m("attribute")&&f("Attributes must be readonly in this context"),i.base=y("attribute"),i.base){switch(o.idlType=O("attribute-type")||f("No type in attribute"),o.idlType.generic){case"sequence":case"record":f(`Attributes cannot accept ${o.idlType.generic} types`)}return i.name=y(c,"required")||f("No name in attribute"),i.termination=y(";")||f("Unterminated attribute"),o}v(a)}get type(){return"attribute"}get special(){return this.tokens.special?this.tokens.special.value:""}get readonly(){return!!this.tokens.readonly}get name(){return r(this.tokens.name.value)}}function D(e){const t=M(e||"return-type");if(t)return t;const r=y("void");if(r){const e=new A({source:n,tokens:{base:r}});return e.type="return-type",e}}class z extends g{static parse({special:e,regular:t}={}){const r={special:e},s=new z({source:n,tokens:r});return e&&"stringifier"===e.value&&(r.termination=y(";"),r.termination)?(s.arguments=[],s):(e||t||(r.special=y("getter","setter","deleter")),s.idlType=D()||f("Missing return type"),r.name=y(c),r.open=y("(")||f("Invalid operation"),s.arguments=I(),r.close=y(")")||f("Unterminated operation"),r.termination=y(";")||f("Unterminated attribute"),s)}get type(){return"operation"}get name(){const{name:e}=this.tokens;return e?r(e.value):""}get special(){return this.tokens.special?this.tokens.special.value:""}}function W(){const e=y("static");if(e)return F.parse({special:e})||z.parse({special:e})||f("No body in static member")}function R(){const e=y("stringifier");if(e)return F.parse({special:e})||z.parse({special:e})||f("Unterminated stringifier")}class Z extends g{static parse(){const t=e.position,r={},s=new Z({source:n,tokens:r});if(r.readonly=y("readonly"),r.base=r.readonly?y("maplike","setlike"):y("iterable","maplike","setlike"),!r.base)return void v(t);const{type:a}=s,i="maplike"===a,o=i||"iterable"===a;r.open=y("<")||f(`Error parsing ${a} declaration`);const u=O()||f(`Error parsing ${a} declaration`);return s.idlType=[u],o&&(u.tokens.separator=y(","),u.tokens.separator?s.idlType.push(O()):i&&f(`Missing second type argument in ${a} declaration`)),r.close=y(">")||f(`Unterminated ${a} declaration`),r.termination=y(";")||f(`Missing semicolon after ${a} declaration`),s}get type(){return this.tokens.base.value}get readonly(){return!!this.tokens.readonly}}class B extends g{static parse(t,{type:n,inheritable:r,allowedMembers:s}){const{tokens:a}=t;for(a.name=y(c)||f("No name for interface"),e.current=t,r&&Object.assign(a,function(){const e=y(":");return e?{colon:e,inheritance:y(c)||f("No type in inheritance")}:{}}()),a.open=y("{")||f(`Bodyless ${n}`),t.members=[];;){if(a.close=y("}"),a.close)return a.termination=y(";")||f(`Missing semicolon after ${n}`),t;const e=S.parse();let r;for(const[e,...t]of s)if(r=e(...t))break;r||f("Unknown member"),r.extAttrs=e,t.members.push(r)}}get partial(){return!!this.tokens.partial}get name(){return r(this.tokens.name.value)}get inheritance(){return this.tokens.inheritance?r(this.tokens.inheritance.value):null}}class L extends B{static parse(e,{callback:t=null,partial:r=null}={}){const s={callback:t,partial:r,base:e};return B.parse(new L({source:n,tokens:s}),{type:"interface",inheritable:!r,allowedMembers:[[E.parse],[W],[R],[Z.parse],[F.parse],[z.parse]]})}get type(){return this.tokens.callback?"callback interface":"interface"}}class V extends B{static parse(e,{partial:t}={}){const r={partial:t,base:e};if(r.mixin=y("mixin"),r.mixin)return B.parse(new V({source:n,tokens:r}),{type:"interface mixin",allowedMembers:[[E.parse],[R],[F.parse,{noInherit:!0}],[z.parse,{regular:!0}]]})}get type(){return"interface mixin"}}function C(e){const t=y("interface");if(t)return V.parse(t,e)||L.parse(t,e)||f("Interface has no proper body")}class J extends B{static parse({partial:e}={}){const t={partial:e};if(t.base=y("namespace"),t.base)return B.parse(new J({source:n,tokens:t}),{type:"namespace",allowedMembers:[[F.parse,{noInherit:!0,readonly:!0}],[z.parse,{regular:!0}]]})}get type(){return"namespace"}}class X extends B{static parse({partial:e}={}){const t={partial:e};if(t.base=y("dictionary"),t.base)return B.parse(new X({source:n,tokens:t}),{type:"dictionary",inheritable:!e,allowedMembers:[[G.parse]]})}get type(){return"dictionary"}}class G extends g{static parse(){const t={},r=new G({source:n,tokens:t});return r.extAttrs=S.parse(),t.required=y("required"),r.idlType=O("dictionary-type")||f("No type for dictionary member"),t.name=y(c)||f("No name for dictionary member"),r.default=h.parse(e),t.required&&r.default&&f("Required member must not have a default"),t.termination=y(";")||f("Unterminated dictionary member"),r}get type(){return"field"}get name(){return r(this.tokens.name.value)}get required(){return!!this.tokens.required}}class H extends g{static parse(){const t={},r=new H({source:n,tokens:t});if(t.base=y("typedef"),t.base)return r.idlType=O("typedef-type")||f("No type in typedef"),t.name=y(c)||f("No name in typedef"),e.current=r,t.termination=y(";")||f("Unterminated typedef"),r}get type(){return"typedef"}get name(){return r(this.tokens.name.value)}}function K(){return function(){const e=y("callback");if(!e)return;const t=y("interface");return t?L.parse(t,{callback:e}):_.parse(e)}()||C()||function(){const e=y("partial");if(e)return X.parse({partial:e})||C({partial:e})||J.parse({partial:e})||f("Partial doesn't apply to anything")}()||X.parse()||x.parse(e)||H.parse()||w.parse(e)||J.parse()}const Q=function(){if(!n.length)return[];const e=[];for(;;){const t=S.parse(),n=K();if(!n){t.length&&f("Stray extended attributes");break}n.extAttrs=t,e.push(n)}const r=y("eof");return t.concrete&&e.push(r),e}();return e.position<n.length&&f("Unrecognised tokens"),Q}function N(e,t={}){return T(new m(e),t)}function A(e){return e}const $={wrap:e=>e.join(""),trivia:A,name:A,reference:A,type:A,generic:A,inheritance:A,definition:A,extendedAttribute:A,extendedAttributeReference:A};function j(e,{templates:t=$}={}){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=A,...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 a(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(o),r(e.tokens.close)]);const s=e.tokens.prefix||e.tokens.base,a=e.tokens.prefix?[e.tokens.prefix.value,t.trivia(e.tokens.base.trivia)]:[],i=n(t.wrap([...a,e.tokens.base.value,r(e.tokens.postfix)]),{unescaped:e.idlType,context:e});return t.wrap([t.trivia(s.trivia),i])}function o(e){return t.wrap([p(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([p(e.extAttrs),r(e.tokens.optional),t.type(o(e.idlType)),r(e.tokens.variadic),a(e.tokens.name,{data:e}),u(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):c):[],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),a(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([p(e.extAttrs),r(e.tokens.readonly),r(e.tokens.base,t.generic),r(e.tokens.open),t.wrap(e.idlType.map(o)),r(e.tokens.close),r(e.tokens.termination)]),{data:e,parent:n})}t=Object.assign({},$,t);const m={interface:d,"interface mixin":d,namespace:d,operation:function(e,n){const s=e.idlType?[t.type(o(e.idlType)),a(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([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(o(e.idlType)),a(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(o(e.idlType)),a(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([p(e.extAttrs),r(e.tokens.base),t.type(o(e.idlType)),a(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(o(e.idlType)),a(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),a(e.tokens.name,{data:e}),r(e.tokens.assign),t.type(o(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([p(e.extAttrs),r(e.tokens.base),a(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*M({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 u(n.source,n.tokens.name,n,r)}}function*O(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(a(t).map(e=>e.name)),i=e.partials.get(t.name)||[],o=n.get(t.name)||[];for(const e of[...i,...o]){const n=a(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 u(n.source,s.tokens.name,n,t)}}}function a(e){return e.members.filter(({type:e})=>"operation"===e)}}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}}(e);return[...M(t),...O(t)]}n.d(t,"parse",function(){return N}),n.d(t,"write",function(){return j}),n.d(t,"validate",function(){return P})}])}); | ||
//# sourceMappingURL=webidl2.js.map |
@@ -14,4 +14,6 @@ "use strict"; | ||
* @param {Tokeniser} tokeniser | ||
* @param {object} options | ||
* @param {boolean} [options.concrete] | ||
*/ | ||
function parseByTokens(tokeniser) { | ||
function parseByTokens(tokeniser, options) { | ||
const source = tokeniser.source; | ||
@@ -809,3 +811,6 @@ | ||
} | ||
defs.push(consume("eof")); | ||
const eof = consume("eof"); | ||
if (options.concrete) { | ||
defs.push(eof); | ||
} | ||
return defs; | ||
@@ -818,5 +823,5 @@ } | ||
export function parse(str) { | ||
export function parse(str, options = {}) { | ||
const tokeniser = new Tokeniser(str); | ||
return parseByTokens(tokeniser); | ||
return parseByTokens(tokeniser, options); | ||
} |
{ | ||
"name": "webidl2", | ||
"description": "A WebIDL Parser", | ||
"version": "21.1.1", | ||
"version": "22.0.0", | ||
"contributors": [ | ||
@@ -6,0 +6,0 @@ "Robin Berjon <robin@berjon.com> (https://berjon.com)", |
@@ -61,2 +61,4 @@ | ||
`parse()` optionally takes an option bag with a boolean field `concrete`. Currently all it does is emitting [EOF](#end-of-file) node. | ||
`write()` optionally takes a "templates" object, whose properties are functions that process input in different ways (depending on what is needed for output). Every property is optional. Each property is documented below: | ||
@@ -679,2 +681,5 @@ | ||
This type only appears as the last item of parser results, only if options.concrete is `true`. | ||
This is needed for the writer to keep any comments or whitespaces at the end of file. | ||
The fields are as follows: | ||
@@ -681,0 +686,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
237304
1747
702