@idlizer/core 2.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/build/lib/src/IndentedPrinter.d.ts +28 -0
  2. package/build/lib/src/IndentedPrinter.js +81 -0
  3. package/build/lib/src/Language.d.ts +15 -0
  4. package/build/lib/src/Language.js +42 -0
  5. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +318 -0
  6. package/build/lib/src/LanguageWriters/ArgConvertors.js +1015 -0
  7. package/build/lib/src/LanguageWriters/InteropConvertor.d.ts +36 -0
  8. package/build/lib/src/LanguageWriters/InteropConvertor.js +174 -0
  9. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +386 -0
  10. package/build/lib/src/LanguageWriters/LanguageWriter.js +746 -0
  11. package/build/lib/src/LanguageWriters/common.d.ts +17 -0
  12. package/build/lib/src/LanguageWriters/common.js +33 -0
  13. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +8 -0
  14. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +35 -0
  15. package/build/lib/src/LanguageWriters/index.d.ts +3 -0
  16. package/build/lib/src/LanguageWriters/index.js +3 -0
  17. package/build/lib/src/LanguageWriters/nameConvertor.d.ts +28 -0
  18. package/build/lib/src/LanguageWriters/nameConvertor.js +61 -0
  19. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +147 -0
  20. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +578 -0
  21. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +46 -0
  22. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +121 -0
  23. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +116 -0
  24. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +472 -0
  25. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +72 -0
  26. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +329 -0
  27. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +83 -0
  28. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +275 -0
  29. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +93 -0
  30. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +390 -0
  31. package/build/lib/src/LibraryInterface.d.ts +21 -0
  32. package/build/lib/src/LibraryInterface.js +2 -0
  33. package/build/lib/src/config.d.ts +8 -0
  34. package/build/lib/src/config.js +20 -0
  35. package/build/lib/src/from-idl/DtsPrinter.d.ts +35 -0
  36. package/build/lib/src/from-idl/DtsPrinter.js +375 -0
  37. package/build/lib/src/from-idl/common.d.ts +5 -0
  38. package/build/lib/src/from-idl/common.js +83 -0
  39. package/build/lib/src/from-idl/deserialize.d.ts +9 -0
  40. package/build/lib/src/from-idl/deserialize.js +384 -0
  41. package/build/lib/src/from-idl/toString.d.ts +2 -0
  42. package/build/lib/src/from-idl/toString.js +18 -0
  43. package/build/lib/src/from-idl/webidl2-utils.d.ts +20 -0
  44. package/build/lib/src/from-idl/webidl2-utils.js +84 -0
  45. package/build/lib/src/idl.d.ts +404 -0
  46. package/build/lib/src/idl.js +1015 -0
  47. package/build/lib/src/idlize.d.ts +4 -0
  48. package/build/lib/src/idlize.js +52 -0
  49. package/build/lib/src/index.d.ts +34 -0
  50. package/build/lib/src/index.js +48 -0
  51. package/build/lib/src/inheritance.d.ts +16 -0
  52. package/build/lib/src/inheritance.js +76 -0
  53. package/build/lib/src/languageSpecificKeywords.d.ts +5 -0
  54. package/build/lib/src/languageSpecificKeywords.js +51 -0
  55. package/build/lib/src/library.d.ts +67 -0
  56. package/build/lib/src/library.js +190 -0
  57. package/build/lib/src/options.d.ts +11 -0
  58. package/build/lib/src/options.js +16 -0
  59. package/build/lib/src/peer-generation/PrimitiveType.d.ts +24 -0
  60. package/build/lib/src/peer-generation/PrimitiveType.js +52 -0
  61. package/build/lib/src/peer-generation/ReferenceResolver.d.ts +9 -0
  62. package/build/lib/src/peer-generation/ReferenceResolver.js +37 -0
  63. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +28 -0
  64. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +82 -0
  65. package/build/lib/src/peer-generation/idl/common.d.ts +9 -0
  66. package/build/lib/src/peer-generation/idl/common.js +70 -0
  67. package/build/lib/src/peer-generation/unions.d.ts +29 -0
  68. package/build/lib/src/peer-generation/unions.js +111 -0
  69. package/build/lib/src/rand_utils.d.ts +6 -0
  70. package/build/lib/src/rand_utils.js +100 -0
  71. package/build/lib/src/util.d.ts +75 -0
  72. package/build/lib/src/util.js +622 -0
  73. package/package.json +49 -0
  74. package/webidl2.js/LICENSE +21 -0
  75. package/webidl2.js/README.md +827 -0
  76. package/webidl2.js/dist/package.json +3 -0
  77. package/webidl2.js/dist/webidl2.js +4547 -0
  78. package/webidl2.js/package.json +55 -0
@@ -0,0 +1,4547 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["WebIDL2"] = factory();
8
+ else
9
+ root["WebIDL2"] = factory();
10
+ })(globalThis, () => {
11
+ return /******/ (() => { // webpackBootstrap
12
+ /******/ "use strict";
13
+ /******/ var __webpack_modules__ = ({
14
+
15
+ /***/ "./lib/error.js":
16
+ /*!**********************!*\
17
+ !*** ./lib/error.js ***!
18
+ \**********************/
19
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
20
+
21
+ __webpack_require__.r(__webpack_exports__);
22
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
23
+ /* harmony export */ syntaxError: () => (/* binding */ syntaxError),
24
+ /* harmony export */ validationError: () => (/* binding */ validationError)
25
+ /* harmony export */ });
26
+ /**
27
+ * @param {string} text
28
+ */
29
+ function lastLine(text) {
30
+ const splitted = text.split("\n");
31
+ return splitted[splitted.length - 1];
32
+ }
33
+
34
+ function appendIfExist(base, target) {
35
+ let result = base;
36
+ if (target) {
37
+ result += ` ${target}`;
38
+ }
39
+ return result;
40
+ }
41
+
42
+ function contextAsText(node) {
43
+ const hierarchy = [node];
44
+ while (node && node.parent) {
45
+ const { parent } = node;
46
+ hierarchy.unshift(parent);
47
+ node = parent;
48
+ }
49
+ return hierarchy.map((n) => appendIfExist(n.type, n.name)).join(" -> ");
50
+ }
51
+
52
+ /**
53
+ * @typedef {object} WebIDL2ErrorOptions
54
+ * @property {"error" | "warning"} [level]
55
+ * @property {Function} [autofix]
56
+ * @property {string} [ruleName]
57
+ *
58
+ * @typedef {ReturnType<typeof error>} WebIDLErrorData
59
+ *
60
+ * @param {string} message error message
61
+ * @param {*} position
62
+ * @param {*} current
63
+ * @param {*} message
64
+ * @param {"Syntax" | "Validation"} kind error type
65
+ * @param {WebIDL2ErrorOptions=} options
66
+ */
67
+ function error(
68
+ source,
69
+ position,
70
+ current,
71
+ message,
72
+ kind,
73
+ { level = "error", autofix, ruleName } = {},
74
+ ) {
75
+ /**
76
+ * @param {number} count
77
+ */
78
+ function sliceTokens(count) {
79
+ return count > 0
80
+ ? source.slice(position, position + count)
81
+ : source.slice(Math.max(position + count, 0), position);
82
+ }
83
+
84
+ /**
85
+ * @param {import("./tokeniser.js").Token[]} inputs
86
+ * @param {object} [options]
87
+ * @param {boolean} [options.precedes]
88
+ * @returns
89
+ */
90
+ function tokensToText(inputs, { precedes } = {}) {
91
+ const text = inputs.map((t) => t.trivia + t.value).join("");
92
+ const nextToken = source[position];
93
+ if (nextToken.type === "eof") {
94
+ return text;
95
+ }
96
+ if (precedes) {
97
+ return text + nextToken.trivia;
98
+ }
99
+ return text.slice(nextToken.trivia.length);
100
+ }
101
+
102
+ const maxTokens = 5; // arbitrary but works well enough
103
+ const line =
104
+ source[position].type !== "eof"
105
+ ? source[position].line
106
+ : source.length > 1
107
+ ? source[position - 1].line
108
+ : 1;
109
+
110
+ const precedingLastLine = lastLine(
111
+ tokensToText(sliceTokens(-maxTokens), { precedes: true }),
112
+ );
113
+
114
+ const subsequentTokens = sliceTokens(maxTokens);
115
+ const subsequentText = tokensToText(subsequentTokens);
116
+ const subsequentFirstLine = subsequentText.split("\n")[0];
117
+
118
+ const spaced = " ".repeat(precedingLastLine.length) + "^";
119
+ const sourceContext = precedingLastLine + subsequentFirstLine + "\n" + spaced;
120
+
121
+ const contextType = kind === "Syntax" ? "since" : "inside";
122
+ const inSourceName = source.name ? ` in ${source.name}` : "";
123
+ const grammaticalContext =
124
+ current && current.name
125
+ ? `, ${contextType} \`${current.partial ? "partial " : ""}${contextAsText(
126
+ current,
127
+ )}\``
128
+ : "";
129
+ const context = `${kind} error at line ${line}${inSourceName}${grammaticalContext}:\n${sourceContext}`;
130
+ return {
131
+ message: `${context} ${message}`,
132
+ bareMessage: message,
133
+ context,
134
+ line,
135
+ sourceName: source.name,
136
+ level,
137
+ ruleName,
138
+ autofix,
139
+ input: subsequentText,
140
+ tokens: subsequentTokens,
141
+ };
142
+ }
143
+
144
+ /**
145
+ * @param {string} message error message
146
+ */
147
+ function syntaxError(source, position, current, message) {
148
+ return error(source, position, current, message, "Syntax");
149
+ }
150
+
151
+ /**
152
+ * @param {string} message error message
153
+ * @param {WebIDL2ErrorOptions} [options]
154
+ */
155
+ function validationError(
156
+ token,
157
+ current,
158
+ ruleName,
159
+ message,
160
+ options = {},
161
+ ) {
162
+ options.ruleName = ruleName;
163
+ return error(
164
+ current.source,
165
+ token.index,
166
+ current,
167
+ message,
168
+ "Validation",
169
+ options,
170
+ );
171
+ }
172
+
173
+
174
+ /***/ }),
175
+
176
+ /***/ "./lib/productions/argument.js":
177
+ /*!*************************************!*\
178
+ !*** ./lib/productions/argument.js ***!
179
+ \*************************************/
180
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
181
+
182
+ __webpack_require__.r(__webpack_exports__);
183
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
184
+ /* harmony export */ Argument: () => (/* binding */ Argument)
185
+ /* harmony export */ });
186
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
187
+ /* harmony import */ var _default_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./default.js */ "./lib/productions/default.js");
188
+ /* harmony import */ var _extended_attributes_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./extended-attributes.js */ "./lib/productions/extended-attributes.js");
189
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
190
+ /* harmony import */ var _tokeniser_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../tokeniser.js */ "./lib/tokeniser.js");
191
+ /* harmony import */ var _error_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../error.js */ "./lib/error.js");
192
+ /* harmony import */ var _validators_helpers_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../validators/helpers.js */ "./lib/validators/helpers.js");
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+ class Argument extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
202
+ /**
203
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
204
+ */
205
+ static parse(tokeniser) {
206
+ const start_position = tokeniser.position;
207
+ /** @type {Base["tokens"]} */
208
+ const tokens = {};
209
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.autoParenter)(
210
+ new Argument({ source: tokeniser.source, tokens }),
211
+ );
212
+ ret.extAttrs = _extended_attributes_js__WEBPACK_IMPORTED_MODULE_2__.ExtendedAttributes.parse(tokeniser);
213
+ tokens.optional = tokeniser.consume("optional");
214
+ ret.idlType = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.type_with_extended_attributes)(tokeniser, "argument-type");
215
+ if (!ret.idlType) {
216
+ return tokeniser.unconsume(start_position);
217
+ }
218
+ if (!tokens.optional) {
219
+ tokens.variadic = tokeniser.consume("...");
220
+ }
221
+ tokens.name =
222
+ tokeniser.consumeKind("identifier") ||
223
+ tokeniser.consume(..._tokeniser_js__WEBPACK_IMPORTED_MODULE_4__.argumentNameKeywords);
224
+ if (!tokens.name) {
225
+ return tokeniser.unconsume(start_position);
226
+ }
227
+ ret.default = tokens.optional ? _default_js__WEBPACK_IMPORTED_MODULE_1__.Default.parse(tokeniser) : null;
228
+ return ret.this;
229
+ }
230
+
231
+ get type() {
232
+ return "argument";
233
+ }
234
+ get optional() {
235
+ return !!this.tokens.optional;
236
+ }
237
+ get variadic() {
238
+ return !!this.tokens.variadic;
239
+ }
240
+ get name() {
241
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.unescape)(this.tokens.name.value);
242
+ }
243
+
244
+ /**
245
+ * @param {import("../validator.js").Definitions} defs
246
+ */
247
+ *validate(defs) {
248
+ yield* this.extAttrs.validate(defs);
249
+ yield* this.idlType.validate(defs);
250
+ const result = (0,_validators_helpers_js__WEBPACK_IMPORTED_MODULE_6__.idlTypeIncludesDictionary)(this.idlType, defs, {
251
+ useNullableInner: true,
252
+ });
253
+ if (result) {
254
+ if (this.idlType.nullable) {
255
+ const message = `Dictionary arguments cannot be nullable.`;
256
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_5__.validationError)(
257
+ this.tokens.name,
258
+ this,
259
+ "no-nullable-dict-arg",
260
+ message,
261
+ );
262
+ } else if (!this.optional) {
263
+ if (
264
+ this.parent &&
265
+ !(0,_validators_helpers_js__WEBPACK_IMPORTED_MODULE_6__.dictionaryIncludesRequiredField)(result.dictionary, defs) &&
266
+ isLastRequiredArgument(this)
267
+ ) {
268
+ const message = `Dictionary argument must be optional if it has no required fields`;
269
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_5__.validationError)(
270
+ this.tokens.name,
271
+ this,
272
+ "dict-arg-optional",
273
+ message,
274
+ {
275
+ autofix: autofixDictionaryArgumentOptionality(this),
276
+ },
277
+ );
278
+ }
279
+ } else if (!this.default) {
280
+ const message = `Optional dictionary arguments must have a default value of \`{}\`.`;
281
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_5__.validationError)(
282
+ this.tokens.name,
283
+ this,
284
+ "dict-arg-default",
285
+ message,
286
+ {
287
+ autofix: autofixOptionalDictionaryDefaultValue(this),
288
+ },
289
+ );
290
+ }
291
+ }
292
+ }
293
+
294
+ /** @param {import("../writer.js").Writer} w */
295
+ write(w) {
296
+ return w.ts.wrap([
297
+ this.extAttrs.write(w),
298
+ w.token(this.tokens.optional),
299
+ w.ts.type(this.idlType.write(w)),
300
+ w.token(this.tokens.variadic),
301
+ w.name_token(this.tokens.name, { data: this }),
302
+ this.default ? this.default.write(w) : "",
303
+ w.token(this.tokens.separator),
304
+ ]);
305
+ }
306
+ }
307
+
308
+ /**
309
+ * @param {Argument} arg
310
+ */
311
+ function isLastRequiredArgument(arg) {
312
+ const list = arg.parent.arguments || arg.parent.list;
313
+ const index = list.indexOf(arg);
314
+ const requiredExists = list.slice(index + 1).some((a) => !a.optional);
315
+ return !requiredExists;
316
+ }
317
+
318
+ /**
319
+ * @param {Argument} arg
320
+ */
321
+ function autofixDictionaryArgumentOptionality(arg) {
322
+ return () => {
323
+ const firstToken = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.getFirstToken)(arg.idlType);
324
+ arg.tokens.optional = {
325
+ ...firstToken,
326
+ type: "optional",
327
+ value: "optional",
328
+ };
329
+ firstToken.trivia = " ";
330
+ autofixOptionalDictionaryDefaultValue(arg)();
331
+ };
332
+ }
333
+
334
+ /**
335
+ * @param {Argument} arg
336
+ */
337
+ function autofixOptionalDictionaryDefaultValue(arg) {
338
+ return () => {
339
+ arg.default = _default_js__WEBPACK_IMPORTED_MODULE_1__.Default.parse(new _tokeniser_js__WEBPACK_IMPORTED_MODULE_4__.Tokeniser(" = {}"));
340
+ };
341
+ }
342
+
343
+
344
+ /***/ }),
345
+
346
+ /***/ "./lib/productions/array-base.js":
347
+ /*!***************************************!*\
348
+ !*** ./lib/productions/array-base.js ***!
349
+ \***************************************/
350
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
351
+
352
+ __webpack_require__.r(__webpack_exports__);
353
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
354
+ /* harmony export */ ArrayBase: () => (/* binding */ ArrayBase)
355
+ /* harmony export */ });
356
+ class ArrayBase extends Array {
357
+ constructor({ source, tokens }) {
358
+ super();
359
+ Object.defineProperties(this, {
360
+ source: { value: source },
361
+ tokens: { value: tokens },
362
+ parent: { value: null, writable: true },
363
+ });
364
+ }
365
+ }
366
+
367
+
368
+ /***/ }),
369
+
370
+ /***/ "./lib/productions/attribute.js":
371
+ /*!**************************************!*\
372
+ !*** ./lib/productions/attribute.js ***!
373
+ \**************************************/
374
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
375
+
376
+ __webpack_require__.r(__webpack_exports__);
377
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
378
+ /* harmony export */ Attribute: () => (/* binding */ Attribute)
379
+ /* harmony export */ });
380
+ /* harmony import */ var _error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../error.js */ "./lib/error.js");
381
+ /* harmony import */ var _validators_helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../validators/helpers.js */ "./lib/validators/helpers.js");
382
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
383
+ /* harmony import */ var _tokeniser_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../tokeniser.js */ "./lib/tokeniser.js");
384
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
385
+
386
+
387
+
388
+
389
+
390
+
391
+ class Attribute extends _base_js__WEBPACK_IMPORTED_MODULE_2__.Base {
392
+ /**
393
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
394
+ * @param {object} [options]
395
+ * @param {import("../tokeniser.js").Token} [options.special]
396
+ * @param {boolean} [options.noInherit]
397
+ * @param {boolean} [options.readonly]
398
+ */
399
+ static parse(
400
+ tokeniser,
401
+ { special, noInherit = false, readonly = false } = {},
402
+ ) {
403
+ const start_position = tokeniser.position;
404
+ const tokens = { special };
405
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_4__.autoParenter)(
406
+ new Attribute({ source: tokeniser.source, tokens }),
407
+ );
408
+ if (!special && !noInherit) {
409
+ tokens.special = tokeniser.consume("inherit");
410
+ }
411
+ if (ret.special === "inherit" && tokeniser.probe("readonly")) {
412
+ tokeniser.error("Inherited attributes cannot be read-only");
413
+ }
414
+ tokens.readonly = tokeniser.consume("readonly");
415
+ if (readonly && !tokens.readonly && tokeniser.probe("attribute")) {
416
+ tokeniser.error("Attributes must be readonly in this context");
417
+ }
418
+ tokens.base = tokeniser.consume("attribute");
419
+ if (!tokens.base) {
420
+ tokeniser.unconsume(start_position);
421
+ return;
422
+ }
423
+ ret.idlType =
424
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_4__.type_with_extended_attributes)(tokeniser, "attribute-type") ||
425
+ tokeniser.error("Attribute lacks a type");
426
+ tokens.name =
427
+ tokeniser.consumeKind("identifier") ||
428
+ tokeniser.consume(..._tokeniser_js__WEBPACK_IMPORTED_MODULE_3__.argumentNameKeywords) ||
429
+ tokeniser.error("Attribute lacks a name");
430
+ tokens.termination =
431
+ tokeniser.consume(";") ||
432
+ tokeniser.error("Unterminated attribute, expected `;`");
433
+ return ret.this;
434
+ }
435
+
436
+ get type() {
437
+ return "attribute";
438
+ }
439
+ get special() {
440
+ if (!this.tokens.special) {
441
+ return "";
442
+ }
443
+ return this.tokens.special.value;
444
+ }
445
+ get readonly() {
446
+ return !!this.tokens.readonly;
447
+ }
448
+ get name() {
449
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_4__.unescape)(this.tokens.name.value);
450
+ }
451
+
452
+ *validate(defs) {
453
+ yield* this.extAttrs.validate(defs);
454
+ yield* this.idlType.validate(defs);
455
+
456
+ if (["sequence", "record"].includes(this.idlType.generic)) {
457
+ const message = `Attributes cannot accept ${this.idlType.generic} types.`;
458
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_0__.validationError)(
459
+ this.tokens.name,
460
+ this,
461
+ "attr-invalid-type",
462
+ message,
463
+ );
464
+ }
465
+
466
+ {
467
+ const { reference } = (0,_validators_helpers_js__WEBPACK_IMPORTED_MODULE_1__.idlTypeIncludesDictionary)(this.idlType, defs) || {};
468
+ if (reference) {
469
+ const targetToken = (this.idlType.union ? reference : this.idlType)
470
+ .tokens.base;
471
+ const message = "Attributes cannot accept dictionary types.";
472
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_0__.validationError)(targetToken, this, "attr-invalid-type", message);
473
+ }
474
+ }
475
+
476
+ if (this.readonly) {
477
+ if ((0,_validators_helpers_js__WEBPACK_IMPORTED_MODULE_1__.idlTypeIncludesEnforceRange)(this.idlType, defs)) {
478
+ const targetToken = this.idlType.tokens.base;
479
+ const message =
480
+ "Readonly attributes cannot accept [EnforceRange] extended attribute.";
481
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_0__.validationError)(targetToken, this, "attr-invalid-type", message);
482
+ }
483
+ }
484
+ }
485
+
486
+ /** @param {import("../writer.js").Writer} w */
487
+ write(w) {
488
+ const { parent } = this;
489
+ return w.ts.definition(
490
+ w.ts.wrap([
491
+ this.extAttrs.write(w),
492
+ w.token(this.tokens.special),
493
+ w.token(this.tokens.readonly),
494
+ w.token(this.tokens.base),
495
+ w.ts.type(this.idlType.write(w)),
496
+ w.name_token(this.tokens.name, { data: this, parent }),
497
+ w.token(this.tokens.termination),
498
+ ]),
499
+ { data: this, parent },
500
+ );
501
+ }
502
+ }
503
+
504
+
505
+ /***/ }),
506
+
507
+ /***/ "./lib/productions/base.js":
508
+ /*!*********************************!*\
509
+ !*** ./lib/productions/base.js ***!
510
+ \*********************************/
511
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
512
+
513
+ __webpack_require__.r(__webpack_exports__);
514
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
515
+ /* harmony export */ Base: () => (/* binding */ Base)
516
+ /* harmony export */ });
517
+ class Base {
518
+ /**
519
+ * @param {object} initializer
520
+ * @param {Base["source"]} initializer.source
521
+ * @param {Base["tokens"]} initializer.tokens
522
+ */
523
+ constructor({ source, tokens }) {
524
+ Object.defineProperties(this, {
525
+ source: { value: source },
526
+ tokens: { value: tokens, writable: true },
527
+ parent: { value: null, writable: true },
528
+ this: { value: this }, // useful when escaping from proxy
529
+ });
530
+ }
531
+
532
+ toJSON() {
533
+ const json = { type: undefined, name: undefined, inheritance: undefined };
534
+ let proto = this;
535
+ while (proto !== Object.prototype) {
536
+ const descMap = Object.getOwnPropertyDescriptors(proto);
537
+ for (const [key, value] of Object.entries(descMap)) {
538
+ if (value.enumerable || value.get) {
539
+ // @ts-ignore - allow indexing here
540
+ json[key] = this[key];
541
+ }
542
+ }
543
+ proto = Object.getPrototypeOf(proto);
544
+ }
545
+ return json;
546
+ }
547
+ }
548
+
549
+
550
+ /***/ }),
551
+
552
+ /***/ "./lib/productions/callback-interface.js":
553
+ /*!***********************************************!*\
554
+ !*** ./lib/productions/callback-interface.js ***!
555
+ \***********************************************/
556
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
557
+
558
+ __webpack_require__.r(__webpack_exports__);
559
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
560
+ /* harmony export */ CallbackInterface: () => (/* binding */ CallbackInterface)
561
+ /* harmony export */ });
562
+ /* harmony import */ var _container_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./container.js */ "./lib/productions/container.js");
563
+ /* harmony import */ var _operation_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./operation.js */ "./lib/productions/operation.js");
564
+ /* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./constant.js */ "./lib/productions/constant.js");
565
+
566
+
567
+
568
+
569
+ class CallbackInterface extends _container_js__WEBPACK_IMPORTED_MODULE_0__.Container {
570
+ /**
571
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
572
+ * @param {*} callback
573
+ * @param {object} [options]
574
+ * @param {import("./container.js").AllowedMember[]} [options.extMembers]
575
+ */
576
+ static parse(tokeniser, callback, { extMembers = [] } = {}) {
577
+ const tokens = { callback };
578
+ tokens.base = tokeniser.consume("interface");
579
+ if (!tokens.base) {
580
+ return;
581
+ }
582
+ return _container_js__WEBPACK_IMPORTED_MODULE_0__.Container.parse(
583
+ tokeniser,
584
+ new CallbackInterface({ source: tokeniser.source, tokens }),
585
+ {
586
+ allowedMembers: [
587
+ ...extMembers,
588
+ [_constant_js__WEBPACK_IMPORTED_MODULE_2__.Constant.parse],
589
+ [_operation_js__WEBPACK_IMPORTED_MODULE_1__.Operation.parse, { regular: true }],
590
+ ],
591
+ },
592
+ );
593
+ }
594
+
595
+ get type() {
596
+ return "callback interface";
597
+ }
598
+ }
599
+
600
+
601
+ /***/ }),
602
+
603
+ /***/ "./lib/productions/callback.js":
604
+ /*!*************************************!*\
605
+ !*** ./lib/productions/callback.js ***!
606
+ \*************************************/
607
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
608
+
609
+ __webpack_require__.r(__webpack_exports__);
610
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
611
+ /* harmony export */ CallbackFunction: () => (/* binding */ CallbackFunction)
612
+ /* harmony export */ });
613
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
614
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
615
+
616
+
617
+
618
+ class CallbackFunction extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
619
+ /**
620
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
621
+ */
622
+ static parse(tokeniser, base) {
623
+ const tokens = { base };
624
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.autoParenter)(
625
+ new CallbackFunction({ source: tokeniser.source, tokens }),
626
+ );
627
+ tokens.name =
628
+ tokeniser.consumeKind("identifier") ||
629
+ tokeniser.error("Callback lacks a name");
630
+ tokeniser.current = ret.this;
631
+ tokens.assign =
632
+ tokeniser.consume("=") || tokeniser.error("Callback lacks an assignment");
633
+ ret.idlType =
634
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.return_type)(tokeniser) || tokeniser.error("Callback lacks a return type");
635
+ tokens.open =
636
+ tokeniser.consume("(") ||
637
+ tokeniser.error("Callback lacks parentheses for arguments");
638
+ ret.arguments = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.argument_list)(tokeniser);
639
+ tokens.close =
640
+ tokeniser.consume(")") || tokeniser.error("Unterminated callback");
641
+ tokens.termination =
642
+ tokeniser.consume(";") ||
643
+ tokeniser.error("Unterminated callback, expected `;`");
644
+ return ret.this;
645
+ }
646
+
647
+ get type() {
648
+ return "callback";
649
+ }
650
+ get name() {
651
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(this.tokens.name.value);
652
+ }
653
+
654
+ *validate(defs) {
655
+ yield* this.extAttrs.validate(defs);
656
+ yield* this.idlType.validate(defs);
657
+ }
658
+
659
+ /** @param {import("../writer.js").Writer} w */
660
+ write(w) {
661
+ return w.ts.definition(
662
+ w.ts.wrap([
663
+ this.extAttrs.write(w),
664
+ w.token(this.tokens.base),
665
+ w.name_token(this.tokens.name, { data: this }),
666
+ w.token(this.tokens.assign),
667
+ w.ts.type(this.idlType.write(w)),
668
+ w.token(this.tokens.open),
669
+ ...this.arguments.map((arg) => arg.write(w)),
670
+ w.token(this.tokens.close),
671
+ w.token(this.tokens.termination),
672
+ ]),
673
+ { data: this },
674
+ );
675
+ }
676
+ }
677
+
678
+
679
+ /***/ }),
680
+
681
+ /***/ "./lib/productions/constant.js":
682
+ /*!*************************************!*\
683
+ !*** ./lib/productions/constant.js ***!
684
+ \*************************************/
685
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
686
+
687
+ __webpack_require__.r(__webpack_exports__);
688
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
689
+ /* harmony export */ Constant: () => (/* binding */ Constant)
690
+ /* harmony export */ });
691
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
692
+ /* harmony import */ var _type_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./type.js */ "./lib/productions/type.js");
693
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
694
+
695
+
696
+
697
+
698
+ class Constant extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
699
+ /**
700
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
701
+ */
702
+ static parse(tokeniser) {
703
+ /** @type {Base["tokens"]} */
704
+ const tokens = {};
705
+ tokens.base = tokeniser.consume("const");
706
+ if (!tokens.base) {
707
+ return;
708
+ }
709
+ let idlType = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.primitive_type)(tokeniser);
710
+ if (!idlType) {
711
+ const base =
712
+ tokeniser.consumeKind("identifier") ||
713
+ tokeniser.error("Const lacks a type");
714
+ idlType = new _type_js__WEBPACK_IMPORTED_MODULE_1__.Type({ source: tokeniser.source, tokens: { base } });
715
+ }
716
+ if (tokeniser.probe("?")) {
717
+ tokeniser.error("Unexpected nullable constant type");
718
+ }
719
+ idlType.type = "const-type";
720
+ tokens.name =
721
+ tokeniser.consumeKind("identifier") ||
722
+ tokeniser.error("Const lacks a name");
723
+ tokens.assign =
724
+ tokeniser.consume("=") || tokeniser.error("Const lacks value assignment");
725
+ tokens.value =
726
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.const_value)(tokeniser) || tokeniser.error("Const lacks a value");
727
+ tokens.termination =
728
+ tokeniser.consume(";") ||
729
+ tokeniser.error("Unterminated const, expected `;`");
730
+ const ret = new Constant({ source: tokeniser.source, tokens });
731
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.autoParenter)(ret).idlType = idlType;
732
+ return ret;
733
+ }
734
+
735
+ get type() {
736
+ return "const";
737
+ }
738
+ get name() {
739
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.unescape)(this.tokens.name.value);
740
+ }
741
+ get value() {
742
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.const_data)(this.tokens.value);
743
+ }
744
+
745
+ /** @param {import("../writer.js").Writer} w */
746
+ write(w) {
747
+ const { parent } = this;
748
+ return w.ts.definition(
749
+ w.ts.wrap([
750
+ this.extAttrs.write(w),
751
+ w.token(this.tokens.base),
752
+ w.ts.type(this.idlType.write(w)),
753
+ w.name_token(this.tokens.name, { data: this, parent }),
754
+ w.token(this.tokens.assign),
755
+ w.token(this.tokens.value),
756
+ w.token(this.tokens.termination),
757
+ ]),
758
+ { data: this, parent },
759
+ );
760
+ }
761
+ }
762
+
763
+
764
+ /***/ }),
765
+
766
+ /***/ "./lib/productions/constructor.js":
767
+ /*!****************************************!*\
768
+ !*** ./lib/productions/constructor.js ***!
769
+ \****************************************/
770
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
771
+
772
+ __webpack_require__.r(__webpack_exports__);
773
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
774
+ /* harmony export */ Constructor: () => (/* binding */ Constructor)
775
+ /* harmony export */ });
776
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
777
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
778
+
779
+
780
+
781
+ class Constructor extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
782
+ /**
783
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
784
+ */
785
+ static parse(tokeniser) {
786
+ const base = tokeniser.consume("constructor");
787
+ if (!base) {
788
+ return;
789
+ }
790
+ /** @type {Base["tokens"]} */
791
+ const tokens = { base };
792
+ tokens.open =
793
+ tokeniser.consume("(") ||
794
+ tokeniser.error("No argument list in constructor");
795
+ const args = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.argument_list)(tokeniser);
796
+ tokens.close =
797
+ tokeniser.consume(")") || tokeniser.error("Unterminated constructor");
798
+ tokens.termination =
799
+ tokeniser.consume(";") ||
800
+ tokeniser.error("No semicolon after constructor");
801
+ const ret = new Constructor({ source: tokeniser.source, tokens });
802
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.autoParenter)(ret).arguments = args;
803
+ return ret;
804
+ }
805
+
806
+ get type() {
807
+ return "constructor";
808
+ }
809
+
810
+ *validate(defs) {
811
+ for (const argument of this.arguments) {
812
+ yield* argument.validate(defs);
813
+ }
814
+ }
815
+
816
+ /** @param {import("../writer.js").Writer} w */
817
+ write(w) {
818
+ const { parent } = this;
819
+ return w.ts.definition(
820
+ w.ts.wrap([
821
+ this.extAttrs.write(w),
822
+ w.token(this.tokens.base, w.ts.nameless, { data: this, parent }),
823
+ w.token(this.tokens.open),
824
+ w.ts.wrap(this.arguments.map((arg) => arg.write(w))),
825
+ w.token(this.tokens.close),
826
+ w.token(this.tokens.termination),
827
+ ]),
828
+ { data: this, parent },
829
+ );
830
+ }
831
+ }
832
+
833
+
834
+ /***/ }),
835
+
836
+ /***/ "./lib/productions/container.js":
837
+ /*!**************************************!*\
838
+ !*** ./lib/productions/container.js ***!
839
+ \**************************************/
840
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
841
+
842
+ __webpack_require__.r(__webpack_exports__);
843
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
844
+ /* harmony export */ Container: () => (/* binding */ Container)
845
+ /* harmony export */ });
846
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
847
+ /* harmony import */ var _parser_state_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./parser-state.js */ "./lib/productions/parser-state.js");
848
+ /* harmony import */ var _extended_attributes_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./extended-attributes.js */ "./lib/productions/extended-attributes.js");
849
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
850
+
851
+
852
+
853
+
854
+
855
+ /**
856
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
857
+ */
858
+ function inheritance(tokeniser) {
859
+ const colon = tokeniser.consume(":");
860
+ if (!colon) {
861
+ return {};
862
+ }
863
+ const extAttrs = _extended_attributes_js__WEBPACK_IMPORTED_MODULE_2__.ExtendedAttributes.parse(tokeniser);
864
+ const inheritance =
865
+ tokeniser.consumeKind("identifier") ||
866
+ tokeniser.error("Inheritance lacks a type");
867
+ return {
868
+ colon,
869
+ extAttrs: extAttrs && extAttrs.length ? extAttrs : undefined,
870
+ inheritance,
871
+ };
872
+ }
873
+
874
+ /**
875
+ * Parser callback.
876
+ * @callback ParserCallback
877
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
878
+ * @param {...*} args
879
+ */
880
+
881
+ /**
882
+ * A parser callback and optional option object.
883
+ * @typedef AllowedMember
884
+ * @type {[ParserCallback, object?]}
885
+ */
886
+
887
+ class Container extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
888
+ /**
889
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
890
+ * @param {*} instance TODO: This should be {T extends Container}, but see https://github.com/microsoft/TypeScript/issues/4628
891
+ * @param {*} args
892
+ */
893
+ static parse(tokeniser, instance, { inheritable, allowedMembers }) {
894
+ const { tokens, type } = instance;
895
+ tokens.name =
896
+ tokeniser.consumeKind("identifier") ||
897
+ tokeniser.error(`Missing name in ${type}`);
898
+ tokeniser.current = instance;
899
+ instance = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.autoParenter)(instance);
900
+ if (inheritable) {
901
+ const inheritanceParsed = inheritance(tokeniser);
902
+ tokens.colon = inheritanceParsed.colon;
903
+ tokens.inheritance = inheritanceParsed.inheritance;
904
+ instance.inheritanceExtAttrs = inheritanceParsed.extAttrs;
905
+ }
906
+ tokens.open = tokeniser.consume("{") || tokeniser.error(`Bodyless ${type}`);
907
+ instance.members = [];
908
+ while (true) {
909
+ tokens.close = tokeniser.consume("}");
910
+ if (tokens.close) {
911
+ tokens.termination =
912
+ tokeniser.consume(";") ||
913
+ tokeniser.error(`Missing semicolon after ${type}`);
914
+ return instance.this;
915
+ }
916
+ const psu1 = _parser_state_js__WEBPACK_IMPORTED_MODULE_1__.ParserState.update(tokeniser);
917
+ if (psu1) {
918
+ instance.members.push(psu1);
919
+ continue;
920
+ }
921
+ const ea = _extended_attributes_js__WEBPACK_IMPORTED_MODULE_2__.ExtendedAttributes.parse(tokeniser);
922
+ let mem;
923
+ for (const [parser, ...args] of allowedMembers) {
924
+ mem = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.autoParenter)(parser(tokeniser, ...args));
925
+ if (mem) {
926
+ break;
927
+ }
928
+ }
929
+ if (!mem) {
930
+ tokeniser.error("Unknown member");
931
+ }
932
+ mem.extAttrs = ea;
933
+ instance.members.push(mem.this);
934
+ }
935
+ }
936
+
937
+ get partial() {
938
+ return !!this.tokens.partial;
939
+ }
940
+ get name() {
941
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.unescape)(this.tokens.name.value);
942
+ }
943
+ get inheritance() {
944
+ if (!this.tokens.inheritance) {
945
+ return null;
946
+ }
947
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.unescape)(this.tokens.inheritance.value);
948
+ }
949
+
950
+ *validate(defs) {
951
+ for (const member of this.members) {
952
+ if (member.validate) {
953
+ yield* member.validate(defs);
954
+ }
955
+ }
956
+ }
957
+
958
+ /** @param {import("../writer.js").Writer} w */
959
+ write(w) {
960
+ const inheritance = () => {
961
+ if (!this.tokens.inheritance) {
962
+ return "";
963
+ }
964
+ return w.ts.wrap([
965
+ w.token(this.tokens.colon),
966
+ this.inheritanceExtAttrs?.write(w),
967
+ w.ts.trivia(this.tokens.inheritance.trivia),
968
+ w.ts.inheritance(
969
+ w.reference(this.tokens.inheritance.value, { context: this }),
970
+ ),
971
+ ]);
972
+ };
973
+
974
+ return w.ts.definition(
975
+ w.ts.wrap([
976
+ this.extAttrs.write(w),
977
+ w.token(this.tokens.callback),
978
+ w.token(this.tokens.partial),
979
+ w.token(this.tokens.base),
980
+ w.token(this.tokens.mixin),
981
+ w.name_token(this.tokens.name, { data: this }),
982
+ inheritance(),
983
+ w.token(this.tokens.open),
984
+ w.ts.wrap(this.members.map((m) => m.write(w))),
985
+ w.token(this.tokens.close),
986
+ w.token(this.tokens.termination),
987
+ ]),
988
+ { data: this },
989
+ );
990
+ }
991
+ }
992
+
993
+
994
+ /***/ }),
995
+
996
+ /***/ "./lib/productions/default.js":
997
+ /*!************************************!*\
998
+ !*** ./lib/productions/default.js ***!
999
+ \************************************/
1000
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
1001
+
1002
+ __webpack_require__.r(__webpack_exports__);
1003
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1004
+ /* harmony export */ Default: () => (/* binding */ Default)
1005
+ /* harmony export */ });
1006
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
1007
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
1008
+
1009
+
1010
+
1011
+ class Default extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
1012
+ /**
1013
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1014
+ */
1015
+ static parse(tokeniser) {
1016
+ const assign = tokeniser.consume("=");
1017
+ if (!assign) {
1018
+ return null;
1019
+ }
1020
+ const def =
1021
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.const_value)(tokeniser) ||
1022
+ tokeniser.consumeKind("string") ||
1023
+ tokeniser.consume("null", "[", "{") ||
1024
+ tokeniser.error("No value for default");
1025
+ const expression = [def];
1026
+ if (def.value === "[") {
1027
+ const close =
1028
+ tokeniser.consume("]") ||
1029
+ tokeniser.error("Default sequence value must be empty");
1030
+ expression.push(close);
1031
+ } else if (def.value === "{") {
1032
+ const close =
1033
+ tokeniser.consume("}") ||
1034
+ tokeniser.error("Default dictionary value must be empty");
1035
+ expression.push(close);
1036
+ }
1037
+ return new Default({
1038
+ source: tokeniser.source,
1039
+ tokens: { assign },
1040
+ expression,
1041
+ });
1042
+ }
1043
+
1044
+ constructor({ source, tokens, expression }) {
1045
+ super({ source, tokens });
1046
+ expression.parent = this;
1047
+ Object.defineProperty(this, "expression", { value: expression });
1048
+ }
1049
+
1050
+ get type() {
1051
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.const_data)(this.expression[0]).type;
1052
+ }
1053
+ get value() {
1054
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.const_data)(this.expression[0]).value;
1055
+ }
1056
+ get negative() {
1057
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.const_data)(this.expression[0]).negative;
1058
+ }
1059
+
1060
+ /** @param {import("../writer.js").Writer} w */
1061
+ write(w) {
1062
+ return w.ts.wrap([
1063
+ w.token(this.tokens.assign),
1064
+ ...this.expression.map((t) => w.token(t)),
1065
+ ]);
1066
+ }
1067
+ }
1068
+
1069
+
1070
+ /***/ }),
1071
+
1072
+ /***/ "./lib/productions/dictionary.js":
1073
+ /*!***************************************!*\
1074
+ !*** ./lib/productions/dictionary.js ***!
1075
+ \***************************************/
1076
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
1077
+
1078
+ __webpack_require__.r(__webpack_exports__);
1079
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1080
+ /* harmony export */ Dictionary: () => (/* binding */ Dictionary)
1081
+ /* harmony export */ });
1082
+ /* harmony import */ var _container_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./container.js */ "./lib/productions/container.js");
1083
+ /* harmony import */ var _field_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./field.js */ "./lib/productions/field.js");
1084
+
1085
+
1086
+
1087
+ class Dictionary extends _container_js__WEBPACK_IMPORTED_MODULE_0__.Container {
1088
+ /**
1089
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1090
+ * @param {object} [options]
1091
+ * @param {import("./container.js").AllowedMember[]} [options.extMembers]
1092
+ * @param {import("../tokeniser.js").Token} [options.partial]
1093
+ */
1094
+ static parse(tokeniser, { extMembers = [], partial } = {}) {
1095
+ const tokens = { partial };
1096
+ tokens.base = tokeniser.consume("dictionary");
1097
+ if (!tokens.base) {
1098
+ return;
1099
+ }
1100
+ return _container_js__WEBPACK_IMPORTED_MODULE_0__.Container.parse(
1101
+ tokeniser,
1102
+ new Dictionary({ source: tokeniser.source, tokens }),
1103
+ {
1104
+ inheritable: !partial,
1105
+ allowedMembers: [...extMembers, [_field_js__WEBPACK_IMPORTED_MODULE_1__.Field.parse]],
1106
+ },
1107
+ );
1108
+ }
1109
+
1110
+ get type() {
1111
+ return "dictionary";
1112
+ }
1113
+ }
1114
+
1115
+
1116
+ /***/ }),
1117
+
1118
+ /***/ "./lib/productions/enum.js":
1119
+ /*!*********************************!*\
1120
+ !*** ./lib/productions/enum.js ***!
1121
+ \*********************************/
1122
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
1123
+
1124
+ __webpack_require__.r(__webpack_exports__);
1125
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1126
+ /* harmony export */ Enum: () => (/* binding */ Enum),
1127
+ /* harmony export */ EnumValue: () => (/* binding */ EnumValue)
1128
+ /* harmony export */ });
1129
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
1130
+ /* harmony import */ var _token_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./token.js */ "./lib/productions/token.js");
1131
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
1132
+
1133
+
1134
+
1135
+
1136
+ class EnumValue extends _token_js__WEBPACK_IMPORTED_MODULE_1__.WrappedToken {
1137
+ /**
1138
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1139
+ */
1140
+ static parse(tokeniser) {
1141
+ const value = tokeniser.consumeKind("string");
1142
+ if (value) {
1143
+ return new EnumValue({ source: tokeniser.source, tokens: { value } });
1144
+ }
1145
+ }
1146
+
1147
+ get type() {
1148
+ return "enum-value";
1149
+ }
1150
+ get value() {
1151
+ return super.value.slice(1, -1);
1152
+ }
1153
+
1154
+ /** @param {import("../writer.js").Writer} w */
1155
+ write(w) {
1156
+ const { parent } = this;
1157
+ return w.ts.wrap([
1158
+ w.ts.trivia(this.tokens.value.trivia),
1159
+ w.ts.definition(
1160
+ w.ts.wrap(['"', w.ts.name(this.value, { data: this, parent }), '"']),
1161
+ { data: this, parent },
1162
+ ),
1163
+ w.token(this.tokens.separator),
1164
+ ]);
1165
+ }
1166
+ }
1167
+
1168
+ class Enum extends _base_js__WEBPACK_IMPORTED_MODULE_2__.Base {
1169
+ /**
1170
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1171
+ */
1172
+ static parse(tokeniser) {
1173
+ /** @type {Base["tokens"]} */
1174
+ const tokens = {};
1175
+ tokens.base = tokeniser.consume("enum");
1176
+ if (!tokens.base) {
1177
+ return;
1178
+ }
1179
+ tokens.name =
1180
+ tokeniser.consumeKind("identifier") ||
1181
+ tokeniser.error("No name for enum");
1182
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_0__.autoParenter)(new Enum({ source: tokeniser.source, tokens }));
1183
+ tokeniser.current = ret.this;
1184
+ tokens.open = tokeniser.consume("{") || tokeniser.error("Bodyless enum");
1185
+ ret.values = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_0__.list)(tokeniser, {
1186
+ parser: EnumValue.parse,
1187
+ allowDangler: true,
1188
+ listName: "enumeration",
1189
+ });
1190
+ if (tokeniser.probeKind("string")) {
1191
+ tokeniser.error("No comma between enum values");
1192
+ }
1193
+ tokens.close =
1194
+ tokeniser.consume("}") || tokeniser.error("Unexpected value in enum");
1195
+ if (!ret.values.length) {
1196
+ tokeniser.error("No value in enum");
1197
+ }
1198
+ tokens.termination =
1199
+ tokeniser.consume(";") || tokeniser.error("No semicolon after enum");
1200
+ return ret.this;
1201
+ }
1202
+
1203
+ get type() {
1204
+ return "enum";
1205
+ }
1206
+ get name() {
1207
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_0__.unescape)(this.tokens.name.value);
1208
+ }
1209
+
1210
+ /** @param {import("../writer.js").Writer} w */
1211
+ write(w) {
1212
+ return w.ts.definition(
1213
+ w.ts.wrap([
1214
+ this.extAttrs.write(w),
1215
+ w.token(this.tokens.base),
1216
+ w.name_token(this.tokens.name, { data: this }),
1217
+ w.token(this.tokens.open),
1218
+ w.ts.wrap(this.values.map((v) => v.write(w))),
1219
+ w.token(this.tokens.close),
1220
+ w.token(this.tokens.termination),
1221
+ ]),
1222
+ { data: this },
1223
+ );
1224
+ }
1225
+ }
1226
+
1227
+
1228
+ /***/ }),
1229
+
1230
+ /***/ "./lib/productions/extended-attributes.js":
1231
+ /*!************************************************!*\
1232
+ !*** ./lib/productions/extended-attributes.js ***!
1233
+ \************************************************/
1234
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
1235
+
1236
+ __webpack_require__.r(__webpack_exports__);
1237
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1238
+ /* harmony export */ ExtendedAttributeParameters: () => (/* binding */ ExtendedAttributeParameters),
1239
+ /* harmony export */ ExtendedAttributes: () => (/* binding */ ExtendedAttributes),
1240
+ /* harmony export */ SimpleExtendedAttribute: () => (/* binding */ SimpleExtendedAttribute)
1241
+ /* harmony export */ });
1242
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
1243
+ /* harmony import */ var _array_base_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./array-base.js */ "./lib/productions/array-base.js");
1244
+ /* harmony import */ var _token_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./token.js */ "./lib/productions/token.js");
1245
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
1246
+ /* harmony import */ var _error_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../error.js */ "./lib/error.js");
1247
+
1248
+
1249
+
1250
+
1251
+
1252
+
1253
+ /**
1254
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1255
+ * @param {string} tokenName
1256
+ */
1257
+ function tokens(tokeniser, tokenName) {
1258
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.list)(tokeniser, {
1259
+ parser: _token_js__WEBPACK_IMPORTED_MODULE_2__.WrappedToken.parser(tokeniser, tokenName),
1260
+ listName: tokenName + " list",
1261
+ });
1262
+ }
1263
+
1264
+ const extAttrValueSyntax = ["identifier", "decimal", "integer", "string"];
1265
+
1266
+ const shouldBeLegacyPrefixed = [
1267
+ "NoInterfaceObject",
1268
+ "LenientSetter",
1269
+ "LenientThis",
1270
+ "TreatNonObjectAsNull",
1271
+ "Unforgeable",
1272
+ ];
1273
+
1274
+ const renamedLegacies = new Map([
1275
+ .../** @type {[string, string][]} */ (
1276
+ shouldBeLegacyPrefixed.map((name) => [name, `Legacy${name}`])
1277
+ ),
1278
+ ["NamedConstructor", "LegacyFactoryFunction"],
1279
+ ["OverrideBuiltins", "LegacyOverrideBuiltIns"],
1280
+ ["TreatNullAs", "LegacyNullToEmptyString"],
1281
+ ]);
1282
+
1283
+ /**
1284
+ * This will allow a set of extended attribute values to be parsed.
1285
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1286
+ */
1287
+ function extAttrListItems(tokeniser) {
1288
+ for (const syntax of extAttrValueSyntax) {
1289
+ const toks = tokens(tokeniser, syntax);
1290
+ if (toks.length) {
1291
+ return toks;
1292
+ }
1293
+ }
1294
+ tokeniser.error(
1295
+ `Expected identifiers, strings, decimals, or integers but none found`,
1296
+ );
1297
+ }
1298
+
1299
+ class ExtendedAttributeParameters extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
1300
+ /**
1301
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1302
+ */
1303
+ static parse(tokeniser) {
1304
+ const tokens = { assign: tokeniser.consume("=") };
1305
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.autoParenter)(
1306
+ new ExtendedAttributeParameters({ source: tokeniser.source, tokens }),
1307
+ );
1308
+ ret.list = [];
1309
+ if (tokens.assign) {
1310
+ tokens.asterisk = tokeniser.consume("*");
1311
+ if (tokens.asterisk) {
1312
+ return ret.this;
1313
+ }
1314
+ tokens.secondaryName = tokeniser.consumeKind(...extAttrValueSyntax);
1315
+ }
1316
+ tokens.open = tokeniser.consume("(");
1317
+ if (tokens.open) {
1318
+ ret.list = ret.rhsIsList
1319
+ ? // [Exposed=(Window,Worker)]
1320
+ extAttrListItems(tokeniser)
1321
+ : // [LegacyFactoryFunction=Audio(DOMString src)] or [Constructor(DOMString str)]
1322
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.argument_list)(tokeniser);
1323
+ tokens.close =
1324
+ tokeniser.consume(")") ||
1325
+ tokeniser.error("Unexpected token in extended attribute argument list");
1326
+ } else if (tokens.assign && !tokens.secondaryName) {
1327
+ tokeniser.error("No right hand side to extended attribute assignment");
1328
+ }
1329
+ return ret.this;
1330
+ }
1331
+
1332
+ get rhsIsList() {
1333
+ return (
1334
+ this.tokens.assign && !this.tokens.asterisk && !this.tokens.secondaryName
1335
+ );
1336
+ }
1337
+
1338
+ get rhsType() {
1339
+ if (this.rhsIsList) {
1340
+ return this.list[0].tokens.value.type + "-list";
1341
+ }
1342
+ if (this.tokens.asterisk) {
1343
+ return "*";
1344
+ }
1345
+ if (this.tokens.secondaryName) {
1346
+ return this.tokens.secondaryName.type;
1347
+ }
1348
+ return null;
1349
+ }
1350
+
1351
+ /** @param {import("../writer.js").Writer} w */
1352
+ write(w) {
1353
+ const { rhsType } = this;
1354
+ return w.ts.wrap([
1355
+ w.token(this.tokens.assign),
1356
+ w.token(this.tokens.asterisk),
1357
+ w.reference_token(this.tokens.secondaryName, this.parent),
1358
+ w.token(this.tokens.open),
1359
+ ...this.list.map((p) => {
1360
+ return rhsType === "identifier-list"
1361
+ ? w.identifier(p, this.parent)
1362
+ : p.write(w);
1363
+ }),
1364
+ w.token(this.tokens.close),
1365
+ ]);
1366
+ }
1367
+ }
1368
+
1369
+ class SimpleExtendedAttribute extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
1370
+ /**
1371
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1372
+ */
1373
+ static parse(tokeniser) {
1374
+ const name = tokeniser.consumeKind("identifier");
1375
+ if (name) {
1376
+ return new SimpleExtendedAttribute({
1377
+ source: tokeniser.source,
1378
+ tokens: { name },
1379
+ params: ExtendedAttributeParameters.parse(tokeniser),
1380
+ });
1381
+ }
1382
+ }
1383
+
1384
+ constructor({ source, tokens, params }) {
1385
+ super({ source, tokens });
1386
+ params.parent = this;
1387
+ Object.defineProperty(this, "params", { value: params });
1388
+ }
1389
+
1390
+ get type() {
1391
+ return "extended-attribute";
1392
+ }
1393
+ get name() {
1394
+ return this.tokens.name.value;
1395
+ }
1396
+ get rhs() {
1397
+ const { rhsType: type, tokens, list } = this.params;
1398
+ if (!type) {
1399
+ return null;
1400
+ }
1401
+ const value = this.params.rhsIsList
1402
+ ? list
1403
+ : this.params.tokens.secondaryName
1404
+ ? (0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.unescape)(tokens.secondaryName.value)
1405
+ : null;
1406
+ return { type, value };
1407
+ }
1408
+ get arguments() {
1409
+ const { rhsIsList, list } = this.params;
1410
+ if (!list || rhsIsList) {
1411
+ return [];
1412
+ }
1413
+ return list;
1414
+ }
1415
+
1416
+ *validate(defs) {
1417
+ const { name } = this;
1418
+ if (name === "LegacyNoInterfaceObject") {
1419
+ const message = `\`[LegacyNoInterfaceObject]\` extended attribute is an \
1420
+ undesirable feature that may be removed from Web IDL in the future. Refer to the \
1421
+ [relevant upstream PR](https://github.com/whatwg/webidl/pull/609) for more \
1422
+ information.`;
1423
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_4__.validationError)(
1424
+ this.tokens.name,
1425
+ this,
1426
+ "no-nointerfaceobject",
1427
+ message,
1428
+ { level: "warning" },
1429
+ );
1430
+ } else if (renamedLegacies.has(name)) {
1431
+ const message = `\`[${name}]\` extended attribute is a legacy feature \
1432
+ that is now renamed to \`[${renamedLegacies.get(name)}]\`. Refer to the \
1433
+ [relevant upstream PR](https://github.com/whatwg/webidl/pull/870) for more \
1434
+ information.`;
1435
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_4__.validationError)(this.tokens.name, this, "renamed-legacy", message, {
1436
+ level: "warning",
1437
+ autofix: renameLegacyExtendedAttribute(this),
1438
+ });
1439
+ }
1440
+ for (const arg of this.arguments) {
1441
+ yield* arg.validate(defs);
1442
+ }
1443
+ }
1444
+
1445
+ /** @param {import("../writer.js").Writer} w */
1446
+ write(w) {
1447
+ return w.ts.wrap([
1448
+ w.ts.trivia(this.tokens.name.trivia),
1449
+ w.ts.extendedAttribute(
1450
+ w.ts.wrap([
1451
+ w.ts.extendedAttributeReference(this.name),
1452
+ this.params.write(w),
1453
+ ]),
1454
+ ),
1455
+ w.token(this.tokens.separator),
1456
+ ]);
1457
+ }
1458
+ }
1459
+
1460
+ /**
1461
+ * @param {SimpleExtendedAttribute} extAttr
1462
+ */
1463
+ function renameLegacyExtendedAttribute(extAttr) {
1464
+ return () => {
1465
+ const { name } = extAttr;
1466
+ extAttr.tokens.name.value = renamedLegacies.get(name);
1467
+ if (name === "TreatNullAs") {
1468
+ extAttr.params.tokens = {};
1469
+ }
1470
+ };
1471
+ }
1472
+
1473
+ // Note: we parse something simpler than the official syntax. It's all that ever
1474
+ // seems to be used
1475
+ class ExtendedAttributes extends _array_base_js__WEBPACK_IMPORTED_MODULE_1__.ArrayBase {
1476
+ /**
1477
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1478
+ */
1479
+ static parse(tokeniser) {
1480
+ const tokens = {};
1481
+ tokens.open = tokeniser.consume("[");
1482
+ const ret = new ExtendedAttributes({ source: tokeniser.source, tokens });
1483
+ if (!tokens.open) return ret;
1484
+ ret.push(
1485
+ ...(0,_helpers_js__WEBPACK_IMPORTED_MODULE_3__.list)(tokeniser, {
1486
+ parser: SimpleExtendedAttribute.parse,
1487
+ listName: "extended attribute",
1488
+ }),
1489
+ );
1490
+ tokens.close =
1491
+ tokeniser.consume("]") ||
1492
+ tokeniser.error(
1493
+ "Expected a closing token for the extended attribute list",
1494
+ );
1495
+ if (!ret.length) {
1496
+ tokeniser.unconsume(tokens.close.index);
1497
+ tokeniser.error("An extended attribute list must not be empty");
1498
+ }
1499
+ if (tokeniser.probe("[")) {
1500
+ tokeniser.error(
1501
+ "Illegal double extended attribute lists, consider merging them",
1502
+ );
1503
+ }
1504
+ return ret;
1505
+ }
1506
+
1507
+ *validate(defs) {
1508
+ for (const extAttr of this) {
1509
+ yield* extAttr.validate(defs);
1510
+ }
1511
+ }
1512
+
1513
+ /** @param {import("../writer.js").Writer} w */
1514
+ write(w) {
1515
+ if (!this.length) return "";
1516
+ return w.ts.wrap([
1517
+ w.token(this.tokens.open),
1518
+ ...this.map((ea) => ea.write(w)),
1519
+ w.token(this.tokens.close),
1520
+ ]);
1521
+ }
1522
+ }
1523
+
1524
+
1525
+ /***/ }),
1526
+
1527
+ /***/ "./lib/productions/field.js":
1528
+ /*!**********************************!*\
1529
+ !*** ./lib/productions/field.js ***!
1530
+ \**********************************/
1531
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
1532
+
1533
+ __webpack_require__.r(__webpack_exports__);
1534
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1535
+ /* harmony export */ Field: () => (/* binding */ Field)
1536
+ /* harmony export */ });
1537
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
1538
+ /* harmony import */ var _tokeniser_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../tokeniser.js */ "./lib/tokeniser.js");
1539
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
1540
+ /* harmony import */ var _extended_attributes_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./extended-attributes.js */ "./lib/productions/extended-attributes.js");
1541
+ /* harmony import */ var _default_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./default.js */ "./lib/productions/default.js");
1542
+
1543
+
1544
+
1545
+
1546
+
1547
+
1548
+ class Field extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
1549
+ /**
1550
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1551
+ */
1552
+ static parse(tokeniser) {
1553
+ /** @type {Base["tokens"]} */
1554
+ const tokens = {};
1555
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.autoParenter)(new Field({ source: tokeniser.source, tokens }));
1556
+ ret.extAttrs = _extended_attributes_js__WEBPACK_IMPORTED_MODULE_3__.ExtendedAttributes.parse(tokeniser);
1557
+ tokens.required = tokeniser.consume("required");
1558
+ ret.idlType =
1559
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.type_with_extended_attributes)(tokeniser, "dictionary-type") ||
1560
+ tokeniser.error("Dictionary member lacks a type");
1561
+ tokens.name =
1562
+ tokeniser.consumeKind("identifier") ||
1563
+ tokeniser.consume(..._tokeniser_js__WEBPACK_IMPORTED_MODULE_1__.argumentNameKeywords) ||
1564
+ tokeniser.error("Dictionary member lacks a name");
1565
+ ret.default = _default_js__WEBPACK_IMPORTED_MODULE_4__.Default.parse(tokeniser);
1566
+ if (tokens.required && ret.default)
1567
+ tokeniser.error("Required member must not have a default");
1568
+ tokens.termination =
1569
+ tokeniser.consume(";") ||
1570
+ tokeniser.error("Unterminated dictionary member, expected `;`");
1571
+ return ret.this;
1572
+ }
1573
+
1574
+ get type() {
1575
+ return "field";
1576
+ }
1577
+ get name() {
1578
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.unescape)(this.tokens.name.value);
1579
+ }
1580
+ get required() {
1581
+ return !!this.tokens.required;
1582
+ }
1583
+
1584
+ *validate(defs) {
1585
+ yield* this.idlType.validate(defs);
1586
+ }
1587
+
1588
+ /** @param {import("../writer.js").Writer} w */
1589
+ write(w) {
1590
+ const { parent } = this;
1591
+ return w.ts.definition(
1592
+ w.ts.wrap([
1593
+ this.extAttrs.write(w),
1594
+ w.token(this.tokens.required),
1595
+ w.ts.type(this.idlType.write(w)),
1596
+ w.name_token(this.tokens.name, { data: this, parent }),
1597
+ this.default ? this.default.write(w) : "",
1598
+ w.token(this.tokens.termination),
1599
+ ]),
1600
+ { data: this, parent },
1601
+ );
1602
+ }
1603
+ }
1604
+
1605
+
1606
+ /***/ }),
1607
+
1608
+ /***/ "./lib/productions/helpers.js":
1609
+ /*!************************************!*\
1610
+ !*** ./lib/productions/helpers.js ***!
1611
+ \************************************/
1612
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
1613
+
1614
+ __webpack_require__.r(__webpack_exports__);
1615
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1616
+ /* harmony export */ argument_list: () => (/* binding */ argument_list),
1617
+ /* harmony export */ autoParenter: () => (/* binding */ autoParenter),
1618
+ /* harmony export */ autofixAddExposedWindow: () => (/* binding */ autofixAddExposedWindow),
1619
+ /* harmony export */ const_data: () => (/* binding */ const_data),
1620
+ /* harmony export */ const_value: () => (/* binding */ const_value),
1621
+ /* harmony export */ findLastIndex: () => (/* binding */ findLastIndex),
1622
+ /* harmony export */ getFirstToken: () => (/* binding */ getFirstToken),
1623
+ /* harmony export */ getLastIndentation: () => (/* binding */ getLastIndentation),
1624
+ /* harmony export */ getMemberIndentation: () => (/* binding */ getMemberIndentation),
1625
+ /* harmony export */ list: () => (/* binding */ list),
1626
+ /* harmony export */ parseCallback: () => (/* binding */ parseCallback),
1627
+ /* harmony export */ parseInterface: () => (/* binding */ parseInterface),
1628
+ /* harmony export */ parsePartial: () => (/* binding */ parsePartial),
1629
+ /* harmony export */ primitive_type: () => (/* binding */ primitive_type),
1630
+ /* harmony export */ return_type: () => (/* binding */ return_type),
1631
+ /* harmony export */ stringifier: () => (/* binding */ stringifier),
1632
+ /* harmony export */ type_with_extended_attributes: () => (/* binding */ type_with_extended_attributes),
1633
+ /* harmony export */ unescape: () => (/* binding */ unescape)
1634
+ /* harmony export */ });
1635
+ /* harmony import */ var _type_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./type.js */ "./lib/productions/type.js");
1636
+ /* harmony import */ var _argument_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./argument.js */ "./lib/productions/argument.js");
1637
+ /* harmony import */ var _extended_attributes_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./extended-attributes.js */ "./lib/productions/extended-attributes.js");
1638
+ /* harmony import */ var _operation_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./operation.js */ "./lib/productions/operation.js");
1639
+ /* harmony import */ var _attribute_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./attribute.js */ "./lib/productions/attribute.js");
1640
+ /* harmony import */ var _tokeniser_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../tokeniser.js */ "./lib/tokeniser.js");
1641
+ /* harmony import */ var _callback_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./callback.js */ "./lib/productions/callback.js");
1642
+ /* harmony import */ var _interface_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./interface.js */ "./lib/productions/interface.js");
1643
+ /* harmony import */ var _mixin_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./mixin.js */ "./lib/productions/mixin.js");
1644
+ /* harmony import */ var _callback_interface_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./callback-interface.js */ "./lib/productions/callback-interface.js");
1645
+ /* harmony import */ var _dictionary_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./dictionary.js */ "./lib/productions/dictionary.js");
1646
+ /* harmony import */ var _namespace_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./namespace.js */ "./lib/productions/namespace.js");
1647
+
1648
+
1649
+
1650
+
1651
+
1652
+
1653
+
1654
+
1655
+
1656
+
1657
+
1658
+
1659
+
1660
+ /**
1661
+ * @param {string} identifier
1662
+ */
1663
+ function unescape(identifier) {
1664
+ return identifier.startsWith("_") ? identifier.slice(1) : identifier;
1665
+ }
1666
+
1667
+ /** @typedef {'callbackInterface'|'dictionary'|'interface'|'mixin'|'namespace'} ExtendableInterfaces */
1668
+ /** @typedef {{ extMembers?: import("./container.js").AllowedMember[]}} Extension */
1669
+ /** @typedef {Partial<Record<ExtendableInterfaces, Extension>>} Extensions */
1670
+
1671
+ /**
1672
+ * Parses comma-separated list
1673
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1674
+ * @param {object} args
1675
+ * @param {Function} args.parser parser function for each item
1676
+ * @param {boolean} [args.allowDangler] whether to allow dangling comma
1677
+ * @param {string} [args.listName] the name to be shown on error messages
1678
+ */
1679
+ function list(tokeniser, { parser, allowDangler, listName = "list" }) {
1680
+ const first = parser(tokeniser);
1681
+ if (!first) {
1682
+ return [];
1683
+ }
1684
+ first.tokens.separator = tokeniser.consume(",");
1685
+ const items = [first];
1686
+ while (first.tokens.separator) {
1687
+ const item = parser(tokeniser);
1688
+ if (!item) {
1689
+ if (!allowDangler) {
1690
+ tokeniser.error(`Trailing comma in ${listName}`);
1691
+ }
1692
+ break;
1693
+ }
1694
+ item.tokens.separator = tokeniser.consume(",");
1695
+ items.push(item);
1696
+ if (!item.tokens.separator) break;
1697
+ }
1698
+ return items;
1699
+ }
1700
+
1701
+ /**
1702
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1703
+ */
1704
+ function const_value(tokeniser) {
1705
+ return (
1706
+ tokeniser.consumeKind("decimal", "integer", "string") ||
1707
+ tokeniser.consume("true", "false", "Infinity", "-Infinity", "NaN")
1708
+ );
1709
+ }
1710
+
1711
+ /**
1712
+ * @param {object} token
1713
+ * @param {string} token.type
1714
+ * @param {string} token.value
1715
+ */
1716
+ function const_data({ type, value }) {
1717
+ switch (type) {
1718
+ case "decimal":
1719
+ case "integer":
1720
+ return { type: "number", value };
1721
+ case "string":
1722
+ return { type: "string", value: value.slice(1, -1) };
1723
+ }
1724
+
1725
+ switch (value) {
1726
+ case "true":
1727
+ case "false":
1728
+ return { type: "boolean", value: value === "true" };
1729
+ case "Infinity":
1730
+ case "-Infinity":
1731
+ return { type: "Infinity", negative: value.startsWith("-") };
1732
+ case "[":
1733
+ return { type: "sequence", value: [] };
1734
+ case "{":
1735
+ return { type: "dictionary" };
1736
+ default:
1737
+ return { type: value };
1738
+ }
1739
+ }
1740
+
1741
+ /**
1742
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1743
+ */
1744
+ function primitive_type(tokeniser) {
1745
+ function integer_type() {
1746
+ const prefix = tokeniser.consume("unsigned");
1747
+ const base = tokeniser.consume("short", "long", "String", "number");
1748
+ if (base) {
1749
+ const postfix = tokeniser.consume("long");
1750
+ return new _type_js__WEBPACK_IMPORTED_MODULE_0__.Type({ source, tokens: { prefix, base, postfix } });
1751
+ }
1752
+ if (prefix) tokeniser.error("Failed to parse integer type");
1753
+ }
1754
+
1755
+ function decimal_type() {
1756
+ const prefix = tokeniser.consume("unrestricted");
1757
+ const base = tokeniser.consume("float", "double");
1758
+ if (base) {
1759
+ return new _type_js__WEBPACK_IMPORTED_MODULE_0__.Type({ source, tokens: { prefix, base } });
1760
+ }
1761
+ if (prefix) tokeniser.error("Failed to parse float type");
1762
+ }
1763
+
1764
+ const { source } = tokeniser;
1765
+ const num_type = integer_type() || decimal_type();
1766
+ if (num_type) return num_type;
1767
+ const base = tokeniser.consume(
1768
+ "bigint",
1769
+ "boolean",
1770
+ "byte",
1771
+ "octet",
1772
+ "undefined",
1773
+ );
1774
+ if (base) {
1775
+ return new _type_js__WEBPACK_IMPORTED_MODULE_0__.Type({ source, tokens: { base } });
1776
+ }
1777
+ }
1778
+
1779
+ /**
1780
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1781
+ */
1782
+ function argument_list(tokeniser) {
1783
+ return list(tokeniser, {
1784
+ parser: _argument_js__WEBPACK_IMPORTED_MODULE_1__.Argument.parse,
1785
+ listName: "arguments list",
1786
+ });
1787
+ }
1788
+
1789
+ /**
1790
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1791
+ * @param {string=} typeName (TODO: See Type.type for more details)
1792
+ */
1793
+ function type_with_extended_attributes(tokeniser, typeName) {
1794
+ const extAttrs = _extended_attributes_js__WEBPACK_IMPORTED_MODULE_2__.ExtendedAttributes.parse(tokeniser);
1795
+ const ret = _type_js__WEBPACK_IMPORTED_MODULE_0__.Type.parse(tokeniser, typeName);
1796
+ if (ret) autoParenter(ret).extAttrs = extAttrs;
1797
+ return ret;
1798
+ }
1799
+
1800
+ /**
1801
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1802
+ * @param {string=} typeName (TODO: See Type.type for more details)
1803
+ */
1804
+ function return_type(tokeniser, typeName) {
1805
+ const startPosition = tokeniser.position;
1806
+ do {
1807
+ const openRT = tokeniser.consume("(");
1808
+ if (!openRT) {
1809
+ tokeniser.unconsume(startPosition);
1810
+ break;
1811
+ }
1812
+ const extAttrs = _extended_attributes_js__WEBPACK_IMPORTED_MODULE_2__.ExtendedAttributes.parse(tokeniser);
1813
+ if (!extAttrs) {
1814
+ tokeniser.unconsume(startPosition);
1815
+ break;
1816
+ }
1817
+ const typ = _type_js__WEBPACK_IMPORTED_MODULE_0__.Type.parse(tokeniser, typeName || "return-type");
1818
+ if (!typ) {
1819
+ tokeniser.unconsume(startPosition);
1820
+ break;
1821
+ }
1822
+ const closeRT = tokeniser.consume(")");
1823
+ if (!closeRT) {
1824
+ tokeniser.unconsume(startPosition);
1825
+ break;
1826
+ }
1827
+ autoParenter(typ).extAttrs = extAttrs;
1828
+ typ.tokens.openRT = openRT;
1829
+ typ.tokens.closeRT = closeRT;
1830
+ return typ;
1831
+ } while (false);
1832
+ const typ = _type_js__WEBPACK_IMPORTED_MODULE_0__.Type.parse(tokeniser, typeName || "return-type");
1833
+ if (typ) {
1834
+ return typ;
1835
+ }
1836
+ const voidToken = tokeniser.consume("void");
1837
+ if (voidToken) {
1838
+ const ret = new _type_js__WEBPACK_IMPORTED_MODULE_0__.Type({
1839
+ source: tokeniser.source,
1840
+ tokens: { base: voidToken },
1841
+ });
1842
+ ret.type = "return-type";
1843
+ return ret;
1844
+ }
1845
+ }
1846
+
1847
+ /**
1848
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
1849
+ */
1850
+ function stringifier(tokeniser) {
1851
+ const special = tokeniser.consume("stringifier");
1852
+ if (!special) return;
1853
+ const member =
1854
+ _attribute_js__WEBPACK_IMPORTED_MODULE_4__.Attribute.parse(tokeniser, { special }) ||
1855
+ _operation_js__WEBPACK_IMPORTED_MODULE_3__.Operation.parse(tokeniser, { special }) ||
1856
+ tokeniser.error("Unterminated stringifier");
1857
+ return member;
1858
+ }
1859
+
1860
+ /**
1861
+ * @param {string} str
1862
+ */
1863
+ function getLastIndentation(str) {
1864
+ const lines = str.split("\n");
1865
+ // the first line visually binds to the preceding token
1866
+ if (lines.length) {
1867
+ const match = lines[lines.length - 1].match(/^\s+/);
1868
+ if (match) {
1869
+ return match[0];
1870
+ }
1871
+ }
1872
+ return "";
1873
+ }
1874
+
1875
+ /**
1876
+ * @param {string} parentTrivia
1877
+ */
1878
+ function getMemberIndentation(parentTrivia) {
1879
+ const indentation = getLastIndentation(parentTrivia);
1880
+ const indentCh = indentation.includes("\t") ? "\t" : " ";
1881
+ return indentation + indentCh;
1882
+ }
1883
+
1884
+ /**
1885
+ * @param {import("./interface.js").Interface} def
1886
+ */
1887
+ function autofixAddExposedWindow(def) {
1888
+ return () => {
1889
+ if (def.extAttrs.length) {
1890
+ const tokeniser = new _tokeniser_js__WEBPACK_IMPORTED_MODULE_5__.Tokeniser("Exposed=Window,");
1891
+ const exposed = _extended_attributes_js__WEBPACK_IMPORTED_MODULE_2__.SimpleExtendedAttribute.parse(tokeniser);
1892
+ exposed.tokens.separator = tokeniser.consume(",");
1893
+ const existing = def.extAttrs[0];
1894
+ if (!/^\s/.test(existing.tokens.name.trivia)) {
1895
+ existing.tokens.name.trivia = ` ${existing.tokens.name.trivia}`;
1896
+ }
1897
+ def.extAttrs.unshift(exposed);
1898
+ } else {
1899
+ autoParenter(def).extAttrs = _extended_attributes_js__WEBPACK_IMPORTED_MODULE_2__.ExtendedAttributes.parse(
1900
+ new _tokeniser_js__WEBPACK_IMPORTED_MODULE_5__.Tokeniser("[Exposed=Window]"),
1901
+ );
1902
+ const trivia = def.tokens.base.trivia;
1903
+ def.extAttrs.tokens.open.trivia = trivia;
1904
+ def.tokens.base.trivia = `\n${getLastIndentation(trivia)}`;
1905
+ }
1906
+ };
1907
+ }
1908
+
1909
+ /**
1910
+ * Get the first syntax token for the given IDL object.
1911
+ * @param {*} data
1912
+ */
1913
+ function getFirstToken(data) {
1914
+ if (data.extAttrs.length) {
1915
+ return data.extAttrs.tokens.open;
1916
+ }
1917
+ if (data.type === "operation" && !data.special) {
1918
+ return getFirstToken(data.idlType);
1919
+ }
1920
+ const tokens = Object.values(data.tokens).sort((x, y) => x.index - y.index);
1921
+ return tokens[0];
1922
+ }
1923
+
1924
+ /**
1925
+ * @template T
1926
+ * @param {T[]} array
1927
+ * @param {(item: T) => boolean} predicate
1928
+ */
1929
+ function findLastIndex(array, predicate) {
1930
+ const index = array.slice().reverse().findIndex(predicate);
1931
+ if (index === -1) {
1932
+ return index;
1933
+ }
1934
+ return array.length - index - 1;
1935
+ }
1936
+
1937
+ /**
1938
+ * Returns a proxy that auto-assign `parent` field.
1939
+ * @template {Record<string | symbol, any>} T
1940
+ * @param {T} data
1941
+ * @param {*} [parent] The object that will be assigned to `parent`.
1942
+ * If absent, it will be `data` by default.
1943
+ * @return {T}
1944
+ */
1945
+ function autoParenter(data, parent) {
1946
+ if (!parent) {
1947
+ // Defaults to `data` unless specified otherwise.
1948
+ parent = data;
1949
+ }
1950
+ if (!data) {
1951
+ // This allows `autoParenter(undefined)` which again allows
1952
+ // `autoParenter(parse())` where the function may return nothing.
1953
+ return data;
1954
+ }
1955
+ const proxy = new Proxy(data, {
1956
+ get(target, p) {
1957
+ const value = target[p];
1958
+ if (Array.isArray(value) && p !== "source") {
1959
+ // Wraps the array so that any added items will also automatically
1960
+ // get their `parent` values.
1961
+ return autoParenter(value, target);
1962
+ }
1963
+ return value;
1964
+ },
1965
+ set(target, p, value) {
1966
+ // @ts-ignore https://github.com/microsoft/TypeScript/issues/47357
1967
+ target[p] = value;
1968
+ if (!value) {
1969
+ return true;
1970
+ } else if (Array.isArray(value)) {
1971
+ // Assigning an array will add `parent` to its items.
1972
+ for (const item of value) {
1973
+ if (typeof item.parent !== "undefined") {
1974
+ item.parent = parent;
1975
+ }
1976
+ }
1977
+ } else if (typeof value.parent !== "undefined") {
1978
+ value.parent = parent;
1979
+ }
1980
+ return true;
1981
+ },
1982
+ });
1983
+ return proxy;
1984
+ }
1985
+
1986
+ /**
1987
+ * Parser options.
1988
+ * @typedef {Object} ParserOptions
1989
+ * @property {string} [sourceName]
1990
+ * @property {boolean} [concrete]
1991
+ * @property {Function[]} [productions]
1992
+ * @property {Extensions} [extensions]
1993
+ */
1994
+
1995
+ /**
1996
+ * @param {Tokeniser} tokeniser
1997
+ * @param {ParserOptions} options
1998
+ */
1999
+ function parseCallback(tokeniser, options) {
2000
+ const callback = tokeniser.consume("callback");
2001
+ if (!callback) return;
2002
+ if (tokeniser.probe("interface")) {
2003
+ return _callback_interface_js__WEBPACK_IMPORTED_MODULE_9__.CallbackInterface.parse(tokeniser, callback, {
2004
+ ...options?.extensions?.callbackInterface,
2005
+ });
2006
+ }
2007
+ return _callback_js__WEBPACK_IMPORTED_MODULE_6__.CallbackFunction.parse(tokeniser, callback);
2008
+ }
2009
+
2010
+ /**
2011
+ * @param {Tokeniser} tokeniser
2012
+ * @param {ParserOptions} options
2013
+ */
2014
+ function parseInterface(tokeniser, options, opts) {
2015
+ const base = tokeniser.consume("interface");
2016
+ if (!base) return;
2017
+ return (
2018
+ _mixin_js__WEBPACK_IMPORTED_MODULE_8__.Mixin.parse(tokeniser, base, {
2019
+ ...opts,
2020
+ ...options?.extensions?.mixin,
2021
+ }) ||
2022
+ _interface_js__WEBPACK_IMPORTED_MODULE_7__.Interface.parse(tokeniser, base, {
2023
+ ...opts,
2024
+ ...options?.extensions?.interface,
2025
+ }) ||
2026
+ tokeniser.error("Interface has no proper body")
2027
+ );
2028
+ }
2029
+
2030
+ /**
2031
+ * @param {Tokeniser} tokeniser
2032
+ * @param {ParserOptions} options
2033
+ */
2034
+ function parsePartial(tokeniser, options) {
2035
+ const partial = tokeniser.consume("partial");
2036
+ if (!partial) return;
2037
+ return (
2038
+ _dictionary_js__WEBPACK_IMPORTED_MODULE_10__.Dictionary.parse(tokeniser, {
2039
+ partial,
2040
+ ...options?.extensions?.dictionary,
2041
+ }) ||
2042
+ parseInterface(tokeniser, options, { partial }) ||
2043
+ _namespace_js__WEBPACK_IMPORTED_MODULE_11__.Namespace.parse(tokeniser, {
2044
+ partial,
2045
+ ...options?.extensions?.namespace,
2046
+ }) ||
2047
+ tokeniser.error("Partial doesn't apply to anything")
2048
+ );
2049
+ }
2050
+
2051
+
2052
+ /***/ }),
2053
+
2054
+ /***/ "./lib/productions/import.js":
2055
+ /*!***********************************!*\
2056
+ !*** ./lib/productions/import.js ***!
2057
+ \***********************************/
2058
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2059
+
2060
+ __webpack_require__.r(__webpack_exports__);
2061
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2062
+ /* harmony export */ Import: () => (/* binding */ Import)
2063
+ /* harmony export */ });
2064
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
2065
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
2066
+
2067
+
2068
+
2069
+ class Import extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
2070
+ static parse(tokeniser) {
2071
+ const importKeyword = tokeniser.consume("import");
2072
+ if (!importKeyword) {
2073
+ return;
2074
+ }
2075
+ const tokens = { import: importKeyword };
2076
+ tokens.name =
2077
+ tokeniser.consumeKind("string") ||
2078
+ tokeniser.error("Incomplete import statement");
2079
+ tokens.termination =
2080
+ tokeniser.consume(";") ||
2081
+ tokeniser.error("No terminating ; for import statement");
2082
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.autoParenter)(new Import({ source: tokeniser.source, tokens }));
2083
+ ret.nameValue = tokens.name.value;
2084
+ return ret.this;
2085
+ }
2086
+
2087
+ get type() {
2088
+ return "import";
2089
+ }
2090
+ get target() {
2091
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(this.tokens.target.value);
2092
+ }
2093
+ get import() {
2094
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(this.tokens.importName.value);
2095
+ }
2096
+
2097
+ write(w) {
2098
+ return w.ts.definition(
2099
+ w.ts.wrap([
2100
+ w.token(this.tokens.import),
2101
+ w.reference_token(this.tokens.name, this),
2102
+ w.token(this.tokens.termination),
2103
+ ]),
2104
+ { data: this },
2105
+ );
2106
+ }
2107
+ }
2108
+
2109
+
2110
+ /***/ }),
2111
+
2112
+ /***/ "./lib/productions/includes.js":
2113
+ /*!*************************************!*\
2114
+ !*** ./lib/productions/includes.js ***!
2115
+ \*************************************/
2116
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2117
+
2118
+ __webpack_require__.r(__webpack_exports__);
2119
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2120
+ /* harmony export */ Includes: () => (/* binding */ Includes)
2121
+ /* harmony export */ });
2122
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
2123
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
2124
+
2125
+
2126
+
2127
+ class Includes extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
2128
+ /**
2129
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
2130
+ */
2131
+ static parse(tokeniser) {
2132
+ const target = tokeniser.consumeKind("identifier");
2133
+ if (!target) {
2134
+ return;
2135
+ }
2136
+ const tokens = { target };
2137
+ tokens.includes = tokeniser.consume("includes");
2138
+ if (!tokens.includes) {
2139
+ tokeniser.unconsume(target.index);
2140
+ return;
2141
+ }
2142
+ tokens.mixin =
2143
+ tokeniser.consumeKind("identifier") ||
2144
+ tokeniser.error("Incomplete includes statement");
2145
+ tokens.termination =
2146
+ tokeniser.consume(";") ||
2147
+ tokeniser.error("No terminating ; for includes statement");
2148
+ return new Includes({ source: tokeniser.source, tokens });
2149
+ }
2150
+
2151
+ get type() {
2152
+ return "includes";
2153
+ }
2154
+ get target() {
2155
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(this.tokens.target.value);
2156
+ }
2157
+ get includes() {
2158
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(this.tokens.mixin.value);
2159
+ }
2160
+
2161
+ /** @param {import("../writer.js").Writer} w */
2162
+ write(w) {
2163
+ return w.ts.definition(
2164
+ w.ts.wrap([
2165
+ this.extAttrs.write(w),
2166
+ w.reference_token(this.tokens.target, this),
2167
+ w.token(this.tokens.includes),
2168
+ w.reference_token(this.tokens.mixin, this),
2169
+ w.token(this.tokens.termination),
2170
+ ]),
2171
+ { data: this },
2172
+ );
2173
+ }
2174
+ }
2175
+
2176
+
2177
+ /***/ }),
2178
+
2179
+ /***/ "./lib/productions/interface.js":
2180
+ /*!**************************************!*\
2181
+ !*** ./lib/productions/interface.js ***!
2182
+ \**************************************/
2183
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2184
+
2185
+ __webpack_require__.r(__webpack_exports__);
2186
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2187
+ /* harmony export */ Interface: () => (/* binding */ Interface)
2188
+ /* harmony export */ });
2189
+ /* harmony import */ var _container_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./container.js */ "./lib/productions/container.js");
2190
+ /* harmony import */ var _attribute_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./attribute.js */ "./lib/productions/attribute.js");
2191
+ /* harmony import */ var _operation_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./operation.js */ "./lib/productions/operation.js");
2192
+ /* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./constant.js */ "./lib/productions/constant.js");
2193
+ /* harmony import */ var _iterable_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./iterable.js */ "./lib/productions/iterable.js");
2194
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
2195
+ /* harmony import */ var _error_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../error.js */ "./lib/error.js");
2196
+ /* harmony import */ var _validators_interface_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../validators/interface.js */ "./lib/validators/interface.js");
2197
+ /* harmony import */ var _constructor_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./constructor.js */ "./lib/productions/constructor.js");
2198
+ /* harmony import */ var _tokeniser_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../tokeniser.js */ "./lib/tokeniser.js");
2199
+ /* harmony import */ var _extended_attributes_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./extended-attributes.js */ "./lib/productions/extended-attributes.js");
2200
+
2201
+
2202
+
2203
+
2204
+
2205
+
2206
+
2207
+
2208
+
2209
+
2210
+
2211
+
2212
+ /**
2213
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
2214
+ */
2215
+ function static_member(tokeniser) {
2216
+ const special = tokeniser.consume("static");
2217
+ if (!special) return;
2218
+ const member =
2219
+ _attribute_js__WEBPACK_IMPORTED_MODULE_1__.Attribute.parse(tokeniser, { special }) ||
2220
+ _operation_js__WEBPACK_IMPORTED_MODULE_2__.Operation.parse(tokeniser, { special }) ||
2221
+ tokeniser.error("No body in static member");
2222
+ return member;
2223
+ }
2224
+
2225
+ class Interface extends _container_js__WEBPACK_IMPORTED_MODULE_0__.Container {
2226
+ /**
2227
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
2228
+ * @param {import("../tokeniser.js").Token} base
2229
+ * @param {object} [options]
2230
+ * @param {import("./container.js").AllowedMember[]} [options.extMembers]
2231
+ * @param {import("../tokeniser.js").Token|null} [options.partial]
2232
+ */
2233
+ static parse(tokeniser, base, { extMembers = [], partial = null } = {}) {
2234
+ const tokens = { partial, base };
2235
+ return _container_js__WEBPACK_IMPORTED_MODULE_0__.Container.parse(
2236
+ tokeniser,
2237
+ new Interface({ source: tokeniser.source, tokens }),
2238
+ {
2239
+ inheritable: !partial,
2240
+ allowedMembers: [
2241
+ ...extMembers,
2242
+ [_constant_js__WEBPACK_IMPORTED_MODULE_3__.Constant.parse],
2243
+ [_constructor_js__WEBPACK_IMPORTED_MODULE_8__.Constructor.parse],
2244
+ [static_member],
2245
+ [_helpers_js__WEBPACK_IMPORTED_MODULE_5__.stringifier],
2246
+ [_iterable_js__WEBPACK_IMPORTED_MODULE_4__.IterableLike.parse],
2247
+ [_attribute_js__WEBPACK_IMPORTED_MODULE_1__.Attribute.parse],
2248
+ [_operation_js__WEBPACK_IMPORTED_MODULE_2__.Operation.parse],
2249
+ ],
2250
+ },
2251
+ );
2252
+ }
2253
+
2254
+ get type() {
2255
+ return "interface";
2256
+ }
2257
+
2258
+ *validate(defs) {
2259
+ yield* this.extAttrs.validate(defs);
2260
+ if (
2261
+ !this.partial &&
2262
+ this.extAttrs.every((extAttr) => extAttr.name !== "Exposed")
2263
+ ) {
2264
+ const message = `Interfaces must have \`[Exposed]\` extended attribute. \
2265
+ To fix, add, for example, \`[Exposed=Window]\`. Please also consider carefully \
2266
+ if your interface should also be exposed in a Worker scope. Refer to the \
2267
+ [WebIDL spec section on Exposed](https://heycam.github.io/webidl/#Exposed) \
2268
+ for more information.`;
2269
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_6__.validationError)(
2270
+ this.tokens.name,
2271
+ this,
2272
+ "require-exposed",
2273
+ message,
2274
+ {
2275
+ autofix: (0,_helpers_js__WEBPACK_IMPORTED_MODULE_5__.autofixAddExposedWindow)(this),
2276
+ },
2277
+ );
2278
+ }
2279
+ const oldConstructors = this.extAttrs.filter(
2280
+ (extAttr) => extAttr.name === "Constructor",
2281
+ );
2282
+ for (const constructor of oldConstructors) {
2283
+ const message = `Constructors should now be represented as a \`constructor()\` operation on the interface \
2284
+ instead of \`[Constructor]\` extended attribute. Refer to the \
2285
+ [WebIDL spec section on constructor operations](https://heycam.github.io/webidl/#idl-constructors) \
2286
+ for more information.`;
2287
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_6__.validationError)(
2288
+ constructor.tokens.name,
2289
+ this,
2290
+ "constructor-member",
2291
+ message,
2292
+ {
2293
+ autofix: autofixConstructor(this, constructor),
2294
+ },
2295
+ );
2296
+ }
2297
+
2298
+ const isGlobal = this.extAttrs.some((extAttr) => extAttr.name === "Global");
2299
+ if (isGlobal) {
2300
+ const factoryFunctions = this.extAttrs.filter(
2301
+ (extAttr) => extAttr.name === "LegacyFactoryFunction",
2302
+ );
2303
+ for (const named of factoryFunctions) {
2304
+ const message = `Interfaces marked as \`[Global]\` cannot have factory functions.`;
2305
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_6__.validationError)(
2306
+ named.tokens.name,
2307
+ this,
2308
+ "no-constructible-global",
2309
+ message,
2310
+ );
2311
+ }
2312
+
2313
+ const constructors = this.members.filter(
2314
+ (member) => member.type === "constructor",
2315
+ );
2316
+ for (const named of constructors) {
2317
+ const message = `Interfaces marked as \`[Global]\` cannot have constructors.`;
2318
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_6__.validationError)(
2319
+ named.tokens.base,
2320
+ this,
2321
+ "no-constructible-global",
2322
+ message,
2323
+ );
2324
+ }
2325
+ }
2326
+
2327
+ yield* super.validate(defs);
2328
+ if (!this.partial) {
2329
+ yield* (0,_validators_interface_js__WEBPACK_IMPORTED_MODULE_7__.checkInterfaceMemberDuplication)(defs, this);
2330
+ }
2331
+ }
2332
+ }
2333
+
2334
+ function autofixConstructor(interfaceDef, constructorExtAttr) {
2335
+ interfaceDef = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_5__.autoParenter)(interfaceDef);
2336
+ return () => {
2337
+ const indentation = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_5__.getLastIndentation)(
2338
+ interfaceDef.extAttrs.tokens.open.trivia,
2339
+ );
2340
+ const memberIndent = interfaceDef.members.length
2341
+ ? (0,_helpers_js__WEBPACK_IMPORTED_MODULE_5__.getLastIndentation)((0,_helpers_js__WEBPACK_IMPORTED_MODULE_5__.getFirstToken)(interfaceDef.members[0]).trivia)
2342
+ : (0,_helpers_js__WEBPACK_IMPORTED_MODULE_5__.getMemberIndentation)(indentation);
2343
+ const constructorOp = _constructor_js__WEBPACK_IMPORTED_MODULE_8__.Constructor.parse(
2344
+ new _tokeniser_js__WEBPACK_IMPORTED_MODULE_9__.Tokeniser(`\n${memberIndent}constructor();`),
2345
+ );
2346
+ constructorOp.extAttrs = new _extended_attributes_js__WEBPACK_IMPORTED_MODULE_10__.ExtendedAttributes({
2347
+ source: interfaceDef.source,
2348
+ tokens: {},
2349
+ });
2350
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_5__.autoParenter)(constructorOp).arguments = constructorExtAttr.arguments;
2351
+
2352
+ const existingIndex = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_5__.findLastIndex)(
2353
+ interfaceDef.members,
2354
+ (m) => m.type === "constructor",
2355
+ );
2356
+ interfaceDef.members.splice(existingIndex + 1, 0, constructorOp);
2357
+
2358
+ const { close } = interfaceDef.tokens;
2359
+ if (!close.trivia.includes("\n")) {
2360
+ close.trivia += `\n${indentation}`;
2361
+ }
2362
+
2363
+ const { extAttrs } = interfaceDef;
2364
+ const index = extAttrs.indexOf(constructorExtAttr);
2365
+ const removed = extAttrs.splice(index, 1);
2366
+ if (!extAttrs.length) {
2367
+ extAttrs.tokens.open = extAttrs.tokens.close = undefined;
2368
+ } else if (extAttrs.length === index) {
2369
+ extAttrs[index - 1].tokens.separator = undefined;
2370
+ } else if (!extAttrs[index].tokens.name.trivia.trim()) {
2371
+ extAttrs[index].tokens.name.trivia = removed[0].tokens.name.trivia;
2372
+ }
2373
+ };
2374
+ }
2375
+
2376
+
2377
+ /***/ }),
2378
+
2379
+ /***/ "./lib/productions/iterable.js":
2380
+ /*!*************************************!*\
2381
+ !*** ./lib/productions/iterable.js ***!
2382
+ \*************************************/
2383
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2384
+
2385
+ __webpack_require__.r(__webpack_exports__);
2386
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2387
+ /* harmony export */ IterableLike: () => (/* binding */ IterableLike)
2388
+ /* harmony export */ });
2389
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
2390
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
2391
+
2392
+
2393
+
2394
+ class IterableLike extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
2395
+ /**
2396
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
2397
+ */
2398
+ static parse(tokeniser) {
2399
+ const start_position = tokeniser.position;
2400
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.autoParenter)(
2401
+ new IterableLike({ source: tokeniser.source, tokens: {} }),
2402
+ );
2403
+ const { tokens } = ret;
2404
+ tokens.readonly = tokeniser.consume("readonly");
2405
+ if (!tokens.readonly) {
2406
+ tokens.async = tokeniser.consume("async");
2407
+ }
2408
+ tokens.base = tokens.readonly
2409
+ ? tokeniser.consume("maplike", "setlike")
2410
+ : tokens.async
2411
+ ? tokeniser.consume("iterable")
2412
+ : tokeniser.consume("iterable", "maplike", "setlike");
2413
+ if (!tokens.base) {
2414
+ tokeniser.unconsume(start_position);
2415
+ return;
2416
+ }
2417
+
2418
+ const { type } = ret;
2419
+ const secondTypeRequired = type === "maplike";
2420
+ const secondTypeAllowed = secondTypeRequired || type === "iterable";
2421
+ const argumentAllowed = ret.async && type === "iterable";
2422
+
2423
+ tokens.open =
2424
+ tokeniser.consume("<") ||
2425
+ tokeniser.error(`Missing less-than sign \`<\` in ${type} declaration`);
2426
+ const first =
2427
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.type_with_extended_attributes)(tokeniser) ||
2428
+ tokeniser.error(`Missing a type argument in ${type} declaration`);
2429
+ ret.idlType = [first];
2430
+ ret.arguments = [];
2431
+
2432
+ if (secondTypeAllowed) {
2433
+ first.tokens.separator = tokeniser.consume(",");
2434
+ if (first.tokens.separator) {
2435
+ ret.idlType.push((0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.type_with_extended_attributes)(tokeniser));
2436
+ } else if (secondTypeRequired) {
2437
+ tokeniser.error(`Missing second type argument in ${type} declaration`);
2438
+ }
2439
+ }
2440
+
2441
+ tokens.close =
2442
+ tokeniser.consume(">") ||
2443
+ tokeniser.error(`Missing greater-than sign \`>\` in ${type} declaration`);
2444
+
2445
+ if (tokeniser.probe("(")) {
2446
+ if (argumentAllowed) {
2447
+ tokens.argsOpen = tokeniser.consume("(");
2448
+ ret.arguments.push(...(0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.argument_list)(tokeniser));
2449
+ tokens.argsClose =
2450
+ tokeniser.consume(")") ||
2451
+ tokeniser.error("Unterminated async iterable argument list");
2452
+ } else {
2453
+ tokeniser.error(`Arguments are only allowed for \`async iterable\``);
2454
+ }
2455
+ }
2456
+
2457
+ tokens.termination =
2458
+ tokeniser.consume(";") ||
2459
+ tokeniser.error(`Missing semicolon after ${type} declaration`);
2460
+
2461
+ return ret.this;
2462
+ }
2463
+
2464
+ get type() {
2465
+ return this.tokens.base.value;
2466
+ }
2467
+ get readonly() {
2468
+ return !!this.tokens.readonly;
2469
+ }
2470
+ get async() {
2471
+ return !!this.tokens.async;
2472
+ }
2473
+
2474
+ *validate(defs) {
2475
+ for (const type of this.idlType) {
2476
+ yield* type.validate(defs);
2477
+ }
2478
+ for (const argument of this.arguments) {
2479
+ yield* argument.validate(defs);
2480
+ }
2481
+ }
2482
+
2483
+ /** @param {import("../writer.js").Writer} w */
2484
+ write(w) {
2485
+ return w.ts.definition(
2486
+ w.ts.wrap([
2487
+ this.extAttrs.write(w),
2488
+ w.token(this.tokens.readonly),
2489
+ w.token(this.tokens.async),
2490
+ w.token(this.tokens.base, w.ts.generic),
2491
+ w.token(this.tokens.open),
2492
+ w.ts.wrap(this.idlType.map((t) => t.write(w))),
2493
+ w.token(this.tokens.close),
2494
+ w.token(this.tokens.argsOpen),
2495
+ w.ts.wrap(this.arguments.map((arg) => arg.write(w))),
2496
+ w.token(this.tokens.argsClose),
2497
+ w.token(this.tokens.termination),
2498
+ ]),
2499
+ { data: this, parent: this.parent },
2500
+ );
2501
+ }
2502
+ }
2503
+
2504
+
2505
+ /***/ }),
2506
+
2507
+ /***/ "./lib/productions/mixin.js":
2508
+ /*!**********************************!*\
2509
+ !*** ./lib/productions/mixin.js ***!
2510
+ \**********************************/
2511
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2512
+
2513
+ __webpack_require__.r(__webpack_exports__);
2514
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2515
+ /* harmony export */ Mixin: () => (/* binding */ Mixin)
2516
+ /* harmony export */ });
2517
+ /* harmony import */ var _container_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./container.js */ "./lib/productions/container.js");
2518
+ /* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constant.js */ "./lib/productions/constant.js");
2519
+ /* harmony import */ var _attribute_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./attribute.js */ "./lib/productions/attribute.js");
2520
+ /* harmony import */ var _operation_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./operation.js */ "./lib/productions/operation.js");
2521
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
2522
+
2523
+
2524
+
2525
+
2526
+
2527
+
2528
+ class Mixin extends _container_js__WEBPACK_IMPORTED_MODULE_0__.Container {
2529
+ /**
2530
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
2531
+ * @param {import("../tokeniser.js").Token} base
2532
+ * @param {object} [options]
2533
+ * @param {import("./container.js").AllowedMember[]} [options.extMembers]
2534
+ * @param {import("../tokeniser.js").Token} [options.partial]
2535
+ */
2536
+ static parse(tokeniser, base, { extMembers = [], partial } = {}) {
2537
+ const tokens = { partial, base };
2538
+ tokens.mixin = tokeniser.consume("mixin");
2539
+ if (!tokens.mixin) {
2540
+ return;
2541
+ }
2542
+ return _container_js__WEBPACK_IMPORTED_MODULE_0__.Container.parse(
2543
+ tokeniser,
2544
+ new Mixin({ source: tokeniser.source, tokens }),
2545
+ {
2546
+ allowedMembers: [
2547
+ ...extMembers,
2548
+ [_constant_js__WEBPACK_IMPORTED_MODULE_1__.Constant.parse],
2549
+ [_helpers_js__WEBPACK_IMPORTED_MODULE_4__.stringifier],
2550
+ [_attribute_js__WEBPACK_IMPORTED_MODULE_2__.Attribute.parse, { noInherit: true }],
2551
+ [_operation_js__WEBPACK_IMPORTED_MODULE_3__.Operation.parse, { regular: true }],
2552
+ ],
2553
+ },
2554
+ );
2555
+ }
2556
+
2557
+ get type() {
2558
+ return "interface mixin";
2559
+ }
2560
+ }
2561
+
2562
+
2563
+ /***/ }),
2564
+
2565
+ /***/ "./lib/productions/namespace.js":
2566
+ /*!**************************************!*\
2567
+ !*** ./lib/productions/namespace.js ***!
2568
+ \**************************************/
2569
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2570
+
2571
+ __webpack_require__.r(__webpack_exports__);
2572
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2573
+ /* harmony export */ Namespace: () => (/* binding */ Namespace)
2574
+ /* harmony export */ });
2575
+ /* harmony import */ var _container_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./container.js */ "./lib/productions/container.js");
2576
+ /* harmony import */ var _attribute_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./attribute.js */ "./lib/productions/attribute.js");
2577
+ /* harmony import */ var _operation_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./operation.js */ "./lib/productions/operation.js");
2578
+ /* harmony import */ var _error_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../error.js */ "./lib/error.js");
2579
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
2580
+ /* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./constant.js */ "./lib/productions/constant.js");
2581
+ /* harmony import */ var _version_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./version.js */ "./lib/productions/version.js");
2582
+ /* harmony import */ var _dictionary_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./dictionary.js */ "./lib/productions/dictionary.js");
2583
+ /* harmony import */ var _enum_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./enum.js */ "./lib/productions/enum.js");
2584
+ /* harmony import */ var _typedef_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./typedef.js */ "./lib/productions/typedef.js");
2585
+
2586
+
2587
+
2588
+
2589
+
2590
+
2591
+
2592
+
2593
+
2594
+
2595
+
2596
+ class Namespace extends _container_js__WEBPACK_IMPORTED_MODULE_0__.Container {
2597
+ /**
2598
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
2599
+ * @param {object} [options]
2600
+ * @param {import("./container.js").AllowedMember[]} [options.extMembers]
2601
+ * @param {import("../tokeniser.js").Token} [options.partial]
2602
+ */
2603
+ static parse(tokeniser, { extMembers = [], partial } = {}) {
2604
+ const tokens = { partial };
2605
+ tokens.base = tokeniser.consume("namespace");
2606
+ if (!tokens.base) {
2607
+ return;
2608
+ }
2609
+ return _container_js__WEBPACK_IMPORTED_MODULE_0__.Container.parse(
2610
+ tokeniser,
2611
+ new Namespace({ source: tokeniser.source, tokens }),
2612
+ {
2613
+ allowedMembers: [
2614
+ ...extMembers,
2615
+ [_helpers_js__WEBPACK_IMPORTED_MODULE_4__.parseCallback],
2616
+ [_helpers_js__WEBPACK_IMPORTED_MODULE_4__.parseInterface],
2617
+ [_helpers_js__WEBPACK_IMPORTED_MODULE_4__.parsePartial],
2618
+ [Namespace.parse],
2619
+ [_dictionary_js__WEBPACK_IMPORTED_MODULE_7__.Dictionary.parse],
2620
+ [_enum_js__WEBPACK_IMPORTED_MODULE_8__.Enum.parse],
2621
+ [_typedef_js__WEBPACK_IMPORTED_MODULE_9__.Typedef.parse],
2622
+ [_version_js__WEBPACK_IMPORTED_MODULE_6__.Version.parse],
2623
+ [_attribute_js__WEBPACK_IMPORTED_MODULE_1__.Attribute.parse, { noInherit: true, readonly: true }],
2624
+ [_constant_js__WEBPACK_IMPORTED_MODULE_5__.Constant.parse],
2625
+ [_operation_js__WEBPACK_IMPORTED_MODULE_2__.Operation.parse, { regular: true }],
2626
+ ],
2627
+ },
2628
+ );
2629
+ }
2630
+
2631
+ get type() {
2632
+ return "namespace";
2633
+ }
2634
+
2635
+ *validate(defs) {
2636
+ if (
2637
+ !this.partial &&
2638
+ this.extAttrs.every((extAttr) => extAttr.name !== "Exposed")
2639
+ ) {
2640
+ const message = `Namespaces must have [Exposed] extended attribute. \
2641
+ To fix, add, for example, [Exposed=Window]. Please also consider carefully \
2642
+ if your namespace should also be exposed in a Worker scope. Refer to the \
2643
+ [WebIDL spec section on Exposed](https://heycam.github.io/webidl/#Exposed) \
2644
+ for more information.`;
2645
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_3__.validationError)(
2646
+ this.tokens.name,
2647
+ this,
2648
+ "require-exposed",
2649
+ message,
2650
+ {
2651
+ autofix: (0,_helpers_js__WEBPACK_IMPORTED_MODULE_4__.autofixAddExposedWindow)(this),
2652
+ },
2653
+ );
2654
+ }
2655
+ yield* super.validate(defs);
2656
+ }
2657
+ }
2658
+
2659
+
2660
+ /***/ }),
2661
+
2662
+ /***/ "./lib/productions/operation.js":
2663
+ /*!**************************************!*\
2664
+ !*** ./lib/productions/operation.js ***!
2665
+ \**************************************/
2666
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2667
+
2668
+ __webpack_require__.r(__webpack_exports__);
2669
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2670
+ /* harmony export */ Operation: () => (/* binding */ Operation)
2671
+ /* harmony export */ });
2672
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
2673
+ /* harmony import */ var _tokeniser_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../tokeniser.js */ "./lib/tokeniser.js");
2674
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
2675
+ /* harmony import */ var _error_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../error.js */ "./lib/error.js");
2676
+
2677
+
2678
+
2679
+
2680
+
2681
+ class Operation extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
2682
+ /**
2683
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
2684
+ * @param {object} [options]
2685
+ * @param {import("../tokeniser.js").Token} [options.special]
2686
+ * @param {boolean} [options.regular]
2687
+ * @param {boolean} [options.noneOnFail]
2688
+ */
2689
+ static parse(tokeniser, { special, regular, noneOnFail } = {}) {
2690
+ const begin_position = tokeniser.position;
2691
+ const tokens = { special };
2692
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.autoParenter)(
2693
+ new Operation({ source: tokeniser.source, tokens }),
2694
+ );
2695
+ if (special && special.value === "stringifier") {
2696
+ tokens.termination = tokeniser.consume(";");
2697
+ if (tokens.termination) {
2698
+ ret.arguments = [];
2699
+ return ret;
2700
+ }
2701
+ }
2702
+ if (!special && !regular) {
2703
+ tokens.special = tokeniser.consume("getter", "setter", "deleter");
2704
+ }
2705
+ const async_position = tokeniser.position;
2706
+ tokens.async = tokeniser.consume("async");
2707
+ if (tokens.async && tokens.special && tokens.special.value !== "static") {
2708
+ if (noneOnFail) {
2709
+ tokeniser.unconsume(begin_position);
2710
+ return;
2711
+ } else {
2712
+ tokeniser.unconsume(async_position);
2713
+ tokeniser.error("Async is not allowed here");
2714
+ }
2715
+ }
2716
+ ret.idlType = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.return_type)(tokeniser);
2717
+ if (!ret.idlType) {
2718
+ if (noneOnFail) {
2719
+ tokeniser.unconsume(begin_position);
2720
+ return;
2721
+ } else tokeniser.error("Missing return type");
2722
+ }
2723
+ tokens.name =
2724
+ tokeniser.consumeKind("identifier") ||
2725
+ tokeniser.consume(..._tokeniser_js__WEBPACK_IMPORTED_MODULE_1__.argumentNameKeywords);
2726
+ tokens.open = tokeniser.consume("(");
2727
+ if (!tokens.open) {
2728
+ if (noneOnFail) {
2729
+ tokeniser.unconsume(begin_position);
2730
+ return;
2731
+ } else tokeniser.error("Invalid operation");
2732
+ }
2733
+ ret.arguments = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.argument_list)(tokeniser);
2734
+ tokens.close = tokeniser.consume(")");
2735
+ if (!tokens.close) {
2736
+ if (noneOnFail) {
2737
+ tokeniser.unconsume(begin_position);
2738
+ return;
2739
+ } else tokeniser.error("Unterminated operation");
2740
+ }
2741
+ tokens.termination = tokeniser.consume(";");
2742
+ if (!tokens.termination) {
2743
+ if (noneOnFail) {
2744
+ tokeniser.unconsume(begin_position);
2745
+ return;
2746
+ } else tokeniser.error("Unterminated operation, expected `;`");
2747
+ }
2748
+ return ret.this;
2749
+ }
2750
+
2751
+ get type() {
2752
+ return "operation";
2753
+ }
2754
+ get name() {
2755
+ const { name } = this.tokens;
2756
+ if (!name) {
2757
+ return "";
2758
+ }
2759
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.unescape)(name.value);
2760
+ }
2761
+ get special() {
2762
+ if (!this.tokens.special) {
2763
+ return "";
2764
+ }
2765
+ return this.tokens.special.value;
2766
+ }
2767
+ get async() {
2768
+ return !!this.tokens.async;
2769
+ }
2770
+
2771
+ *validate(defs) {
2772
+ yield* this.extAttrs.validate(defs);
2773
+ if (!this.name && ["", "static"].includes(this.special)) {
2774
+ const message = `Regular or static operations must have both a return type and an identifier.`;
2775
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_3__.validationError)(this.tokens.open, this, "incomplete-op", message);
2776
+ }
2777
+ if (this.async && this.special && this.special !== "static") {
2778
+ const message = `Operations with ${this.special} special must not be async.`;
2779
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_3__.validationError)(this.tokens.open, this, "incomplete-op", message);
2780
+ }
2781
+ if (this.idlType) {
2782
+ yield* this.idlType.validate(defs);
2783
+ }
2784
+ for (const argument of this.arguments) {
2785
+ yield* argument.validate(defs);
2786
+ }
2787
+ }
2788
+
2789
+ /** @param {import("../writer.js").Writer} w */
2790
+ write(w) {
2791
+ const { parent } = this;
2792
+ const body = this.idlType
2793
+ ? [
2794
+ w.ts.type(this.idlType.write(w)),
2795
+ w.name_token(this.tokens.name, { data: this, parent }),
2796
+ w.token(this.tokens.open),
2797
+ w.ts.wrap(this.arguments.map((arg) => arg.write(w))),
2798
+ w.token(this.tokens.close),
2799
+ ]
2800
+ : [];
2801
+ return w.ts.definition(
2802
+ w.ts.wrap([
2803
+ this.extAttrs.write(w),
2804
+ this.tokens.name
2805
+ ? w.token(this.tokens.special)
2806
+ : w.token(this.tokens.special, w.ts.nameless, { data: this, parent }),
2807
+ w.token(this.tokens.async),
2808
+ ...body,
2809
+ w.token(this.tokens.termination),
2810
+ ]),
2811
+ { data: this, parent },
2812
+ );
2813
+ }
2814
+ }
2815
+
2816
+
2817
+ /***/ }),
2818
+
2819
+ /***/ "./lib/productions/package.js":
2820
+ /*!************************************!*\
2821
+ !*** ./lib/productions/package.js ***!
2822
+ \************************************/
2823
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2824
+
2825
+ __webpack_require__.r(__webpack_exports__);
2826
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2827
+ /* harmony export */ Package: () => (/* binding */ Package)
2828
+ /* harmony export */ });
2829
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
2830
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
2831
+
2832
+
2833
+
2834
+ class Package extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
2835
+ static parse(tokeniser) {
2836
+ const packageKeyword = tokeniser.consume("package");
2837
+ if (!packageKeyword) {
2838
+ return;
2839
+ }
2840
+ const tokens = { base: packageKeyword };
2841
+ tokens.name =
2842
+ tokeniser.consumeKind("string") || tokeniser.error("No name for package");
2843
+ tokens.termination =
2844
+ tokeniser.consume(";") || tokeniser.error("No semicolon after package");
2845
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.autoParenter)(new Package({ source: tokeniser.source, tokens }));
2846
+ ret.nameValue = tokens.name.value;
2847
+ return ret.this;
2848
+ }
2849
+
2850
+ get type() {
2851
+ return "package";
2852
+ }
2853
+ get name() {
2854
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(this.tokens.name.value);
2855
+ }
2856
+
2857
+ write(w) {
2858
+ return w.ts.definition(
2859
+ w.ts.wrap([
2860
+ w.token(this.tokens.base),
2861
+ w.reference_token(this.tokens.name, this),
2862
+ w.token(this.tokens.termination),
2863
+ ]),
2864
+ { data: this },
2865
+ );
2866
+ }
2867
+ }
2868
+
2869
+
2870
+ /***/ }),
2871
+
2872
+ /***/ "./lib/productions/parser-state.js":
2873
+ /*!*****************************************!*\
2874
+ !*** ./lib/productions/parser-state.js ***!
2875
+ \*****************************************/
2876
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2877
+
2878
+ __webpack_require__.r(__webpack_exports__);
2879
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2880
+ /* harmony export */ ParserState: () => (/* binding */ ParserState)
2881
+ /* harmony export */ });
2882
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
2883
+
2884
+
2885
+ const genericsHolder = new Set([
2886
+ "FrozenArray",
2887
+ "ObservableArray",
2888
+ "Promise",
2889
+ "sequence",
2890
+ "record",
2891
+ ]);
2892
+
2893
+ class ParserState extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
2894
+ static get generics() {
2895
+ return genericsHolder;
2896
+ }
2897
+
2898
+ /**
2899
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
2900
+ */
2901
+ static update(tokeniser) {
2902
+ const startPosition = tokeniser.position;
2903
+ do {
2904
+ /** @type {Base["tokens"]} */
2905
+ const tokens = {};
2906
+ tokens.open1 = tokeniser.consume("[");
2907
+ if (!tokens.open1) break;
2908
+
2909
+ tokens.open2 = tokeniser.consume("[");
2910
+ if (!tokens.open2) break;
2911
+
2912
+ tokens.mode =
2913
+ tokeniser.consumeKind("identifier") ||
2914
+ tokeniser.error("Parser state mode-identifier expected");
2915
+
2916
+ if (tokens.mode.value === "generics") {
2917
+ ParserState.updateGenerics(tokeniser, tokens);
2918
+ } else
2919
+ tokeniser.error(
2920
+ `Parser state mode not supported: ${tokens.mode.value}`,
2921
+ );
2922
+
2923
+ tokens.close1 =
2924
+ tokeniser.consume("]") ||
2925
+ tokeniser.error("Parser state terminator expected");
2926
+
2927
+ tokens.close2 =
2928
+ tokeniser.consume("]") ||
2929
+ tokeniser.error("Parser state terminator expected");
2930
+
2931
+ return new ParserState({
2932
+ source: tokeniser.source,
2933
+ tokens,
2934
+ });
2935
+ } while (false);
2936
+
2937
+ tokeniser.unconsume(startPosition);
2938
+ }
2939
+
2940
+ /**
2941
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
2942
+ * @param {Base["tokens"]} tokens
2943
+ */
2944
+ static updateGenerics(tokeniser, tokens) {
2945
+ tokens.operation1 =
2946
+ tokeniser.consumeKind("other") ||
2947
+ tokeniser.error("Parser state generic operation required");
2948
+ let operation = tokens.operation1.value;
2949
+ tokens.operation2 =
2950
+ tokeniser.consume("=") ||
2951
+ tokeniser.error("Parser state generic operation required");
2952
+ operation += tokens.operation2.value;
2953
+
2954
+ for (let i = 0; ; ++i) {
2955
+ if (tokeniser.probe("]")) break;
2956
+
2957
+ const subtype =
2958
+ tokeniser.consumeKind("identifier") ||
2959
+ tokeniser.error(
2960
+ `Parser state generic ${operation} requires an identifier`,
2961
+ );
2962
+
2963
+ switch (operation) {
2964
+ case "+=":
2965
+ ParserState.generics.add(subtype.value);
2966
+ break;
2967
+ case "-=":
2968
+ ParserState.generics.delete(subtype.value);
2969
+ break;
2970
+ default:
2971
+ tokeniser.error(
2972
+ `Unknown parser state generic operation: ${operation}`,
2973
+ );
2974
+ }
2975
+ const delimeter = tokeniser.consume(",");
2976
+
2977
+ tokens[`subtype_${i}`] = subtype;
2978
+ tokens[`delimeter_${i}`] = delimeter;
2979
+
2980
+ if (!delimeter) break;
2981
+ }
2982
+ }
2983
+
2984
+ /** @param {import("../writer.js").Writer} w */
2985
+ write(w) {
2986
+ return w.ts.wrap([
2987
+ ...Object.values(this.tokens).map((token) => w.token(token)),
2988
+ ]);
2989
+ }
2990
+ }
2991
+
2992
+
2993
+ /***/ }),
2994
+
2995
+ /***/ "./lib/productions/token.js":
2996
+ /*!**********************************!*\
2997
+ !*** ./lib/productions/token.js ***!
2998
+ \**********************************/
2999
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
3000
+
3001
+ __webpack_require__.r(__webpack_exports__);
3002
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3003
+ /* harmony export */ Eof: () => (/* binding */ Eof),
3004
+ /* harmony export */ WrappedToken: () => (/* binding */ WrappedToken)
3005
+ /* harmony export */ });
3006
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
3007
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
3008
+
3009
+
3010
+
3011
+ class WrappedToken extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
3012
+ /**
3013
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
3014
+ * @param {string} type
3015
+ */
3016
+ static parser(tokeniser, type) {
3017
+ return () => {
3018
+ const value = tokeniser.consumeKind(type);
3019
+ if (value) {
3020
+ return new WrappedToken({
3021
+ source: tokeniser.source,
3022
+ tokens: { value },
3023
+ });
3024
+ }
3025
+ };
3026
+ }
3027
+
3028
+ get value() {
3029
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(this.tokens.value.value);
3030
+ }
3031
+
3032
+ /** @param {import("../writer.js").Writer} w */
3033
+ write(w) {
3034
+ return w.ts.wrap([
3035
+ w.token(this.tokens.value),
3036
+ w.token(this.tokens.separator),
3037
+ ]);
3038
+ }
3039
+ }
3040
+
3041
+ class Eof extends WrappedToken {
3042
+ /**
3043
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
3044
+ */
3045
+ static parse(tokeniser) {
3046
+ const value = tokeniser.consumeKind("eof");
3047
+ if (value) {
3048
+ return new Eof({ source: tokeniser.source, tokens: { value } });
3049
+ }
3050
+ }
3051
+
3052
+ get type() {
3053
+ return "eof";
3054
+ }
3055
+ }
3056
+
3057
+
3058
+ /***/ }),
3059
+
3060
+ /***/ "./lib/productions/type.js":
3061
+ /*!*********************************!*\
3062
+ !*** ./lib/productions/type.js ***!
3063
+ \*********************************/
3064
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
3065
+
3066
+ __webpack_require__.r(__webpack_exports__);
3067
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3068
+ /* harmony export */ Type: () => (/* binding */ Type)
3069
+ /* harmony export */ });
3070
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
3071
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
3072
+ /* harmony import */ var _tokeniser_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../tokeniser.js */ "./lib/tokeniser.js");
3073
+ /* harmony import */ var _error_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../error.js */ "./lib/error.js");
3074
+ /* harmony import */ var _validators_helpers_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../validators/helpers.js */ "./lib/validators/helpers.js");
3075
+ /* harmony import */ var _extended_attributes_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./extended-attributes.js */ "./lib/productions/extended-attributes.js");
3076
+ /* harmony import */ var _parser_state_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./parser-state.js */ "./lib/productions/parser-state.js");
3077
+
3078
+
3079
+
3080
+
3081
+
3082
+
3083
+
3084
+
3085
+ /**
3086
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
3087
+ * @param {string} typeName
3088
+ */
3089
+ function generic_type(tokeniser, typeName) {
3090
+ let base = tokeniser.consume(..._parser_state_js__WEBPACK_IMPORTED_MODULE_6__.ParserState.generics.values());
3091
+ if (!base) {
3092
+ const tokenizerPosition = tokeniser.position;
3093
+ base = tokeniser.consumeKind("identifier");
3094
+ if (base && !_parser_state_js__WEBPACK_IMPORTED_MODULE_6__.ParserState.generics.has(base.value)) {
3095
+ tokeniser.unconsume(tokenizerPosition);
3096
+ base = undefined;
3097
+ }
3098
+ }
3099
+ if (!base) {
3100
+ return;
3101
+ }
3102
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.autoParenter)(
3103
+ new Type({ source: tokeniser.source, tokens: { base } }),
3104
+ );
3105
+ ret.tokens.open =
3106
+ tokeniser.consume("<") ||
3107
+ tokeniser.error(`No opening bracket after ${base.value}`);
3108
+ switch (base.value) {
3109
+ case "Promise": {
3110
+ if (tokeniser.probe("["))
3111
+ tokeniser.error("Promise type cannot have extended attribute");
3112
+ const subtype =
3113
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.return_type)(tokeniser, typeName) ||
3114
+ tokeniser.error("Missing Promise subtype");
3115
+ ret.subtype.push(subtype);
3116
+ break;
3117
+ }
3118
+ case "sequence":
3119
+ case "FrozenArray":
3120
+ case "ObservableArray": {
3121
+ const subtype =
3122
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.type_with_extended_attributes)(tokeniser, typeName) ||
3123
+ tokeniser.error(`Missing ${base.value} subtype`);
3124
+ ret.subtype.push(subtype);
3125
+ break;
3126
+ }
3127
+ case "record": {
3128
+ const keyType =
3129
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.type_with_extended_attributes)(tokeniser, typeName) ||
3130
+ tokeniser.error("Error parsing generic type record");
3131
+ keyType.tokens.separator =
3132
+ tokeniser.consume(",") ||
3133
+ tokeniser.error("Missing comma after record key type");
3134
+ const valueType =
3135
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.type_with_extended_attributes)(tokeniser, typeName) ||
3136
+ tokeniser.error("Error parsing generic type record");
3137
+ ret.subtype.push(keyType, valueType);
3138
+ break;
3139
+ }
3140
+ default: {
3141
+ ret.subtype = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.list)(tokeniser, {
3142
+ parser: () => {
3143
+ if (tokeniser.probe(",")) return;
3144
+ return (
3145
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.type_with_extended_attributes)(tokeniser, typeName) ||
3146
+ tokeniser.error(`Missing ${base.value} subtype`)
3147
+ );
3148
+ },
3149
+ });
3150
+ break;
3151
+ }
3152
+ }
3153
+ if (!ret.idlType) tokeniser.error(`Error parsing generic type ${base.value}`);
3154
+ ret.tokens.close =
3155
+ tokeniser.consume(">") ||
3156
+ tokeniser.error(`Missing closing bracket after ${base.value}`);
3157
+ return ret.this;
3158
+ }
3159
+
3160
+ /**
3161
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
3162
+ */
3163
+ function type_suffix(tokeniser, obj) {
3164
+ const nullable = tokeniser.consume("?");
3165
+ if (nullable) {
3166
+ obj.tokens.nullable = nullable;
3167
+ }
3168
+ if (tokeniser.probe("?")) tokeniser.error("Can't nullable more than once");
3169
+ }
3170
+
3171
+ /**
3172
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
3173
+ * @param {string} typeName
3174
+ */
3175
+ function single_type(tokeniser, typeName) {
3176
+ let ret = generic_type(tokeniser, typeName) || (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.primitive_type)(tokeniser);
3177
+ if (!ret) {
3178
+ const base =
3179
+ tokeniser.consumeKind("identifier") ||
3180
+ tokeniser.consume(..._tokeniser_js__WEBPACK_IMPORTED_MODULE_2__.typeNameKeywords);
3181
+ if (!base) {
3182
+ return;
3183
+ }
3184
+ ret = new Type({ source: tokeniser.source, tokens: { base } });
3185
+ if (tokeniser.probe("<"))
3186
+ tokeniser.error(`Unsupported generic type ${base.value}`);
3187
+ }
3188
+ if (ret.generic === "Promise" && tokeniser.probe("?")) {
3189
+ tokeniser.error("Promise type cannot be nullable");
3190
+ }
3191
+ ret.type = typeName || null;
3192
+ type_suffix(tokeniser, ret);
3193
+ if (ret.nullable && ret.idlType === "any")
3194
+ tokeniser.error("Type `any` cannot be made nullable");
3195
+ return ret;
3196
+ }
3197
+
3198
+ /**
3199
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
3200
+ * @param {string} type
3201
+ */
3202
+ function union_type(tokeniser, type) {
3203
+ const tokens = {};
3204
+ tokens.open = tokeniser.consume("(");
3205
+ if (!tokens.open) return;
3206
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.autoParenter)(new Type({ source: tokeniser.source, tokens }));
3207
+ ret.type = type || null;
3208
+ while (true) {
3209
+ const typ =
3210
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.type_with_extended_attributes)(tokeniser, type) ||
3211
+ tokeniser.error("No type after open parenthesis or 'or' in union type");
3212
+ if (typ.idlType === "any")
3213
+ tokeniser.error("Type `any` cannot be included in a union type");
3214
+ if (typ.generic === "Promise")
3215
+ tokeniser.error("Type `Promise` cannot be included in a union type");
3216
+ ret.subtype.push(typ);
3217
+ const or = tokeniser.consume("or");
3218
+ if (or) {
3219
+ typ.tokens.separator = or;
3220
+ } else break;
3221
+ }
3222
+ if (ret.idlType.length < 2) {
3223
+ tokeniser.error(
3224
+ "At least two types are expected in a union type but found less",
3225
+ );
3226
+ }
3227
+ tokens.close =
3228
+ tokeniser.consume(")") || tokeniser.error("Unterminated union type");
3229
+ type_suffix(tokeniser, ret);
3230
+ return ret.this;
3231
+ }
3232
+
3233
+ class Type extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
3234
+ /**
3235
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
3236
+ * @param {string} typeName
3237
+ */
3238
+ static parse(tokeniser, typeName) {
3239
+ return single_type(tokeniser, typeName) || union_type(tokeniser, typeName);
3240
+ }
3241
+
3242
+ constructor({ source, tokens }) {
3243
+ super({ source, tokens });
3244
+ Object.defineProperty(this, "subtype", { value: [], writable: true });
3245
+ this.extAttrs = new _extended_attributes_js__WEBPACK_IMPORTED_MODULE_5__.ExtendedAttributes({ source, tokens: {} });
3246
+ }
3247
+
3248
+ get generic() {
3249
+ if (this.subtype.length && this.tokens.base) {
3250
+ return this.tokens.base.value;
3251
+ }
3252
+ return "";
3253
+ }
3254
+ get nullable() {
3255
+ return Boolean(this.tokens.nullable);
3256
+ }
3257
+ get union() {
3258
+ return Boolean(this.subtype.length) && !this.tokens.base;
3259
+ }
3260
+ get idlType() {
3261
+ if (this.subtype.length) {
3262
+ return this.subtype;
3263
+ }
3264
+ // Adding prefixes/postfixes for "unrestricted float", etc.
3265
+ const name = [this.tokens.prefix, this.tokens.base, this.tokens.postfix]
3266
+ .filter((t) => t)
3267
+ .map((t) => t.value)
3268
+ .join(" ");
3269
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(name);
3270
+ }
3271
+
3272
+ *validate(defs) {
3273
+ yield* this.extAttrs.validate(defs);
3274
+
3275
+ if (this.idlType === "BufferSource") {
3276
+ // XXX: For now this is a hack. Consider moving parents' extAttrs into types as the spec says:
3277
+ // https://webidl.spec.whatwg.org/#idl-annotated-types
3278
+ for (const extAttrs of [this.extAttrs, this.parent?.extAttrs]) {
3279
+ for (const extAttr of extAttrs) {
3280
+ if (extAttr.name !== "AllowShared") {
3281
+ continue;
3282
+ }
3283
+ const message = `\`[AllowShared] BufferSource\` is now replaced with AllowSharedBufferSource.`;
3284
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_3__.validationError)(
3285
+ this.tokens.base,
3286
+ this,
3287
+ "migrate-allowshared",
3288
+ message,
3289
+ { autofix: replaceAllowShared(this, extAttr, extAttrs) },
3290
+ );
3291
+ }
3292
+ }
3293
+ }
3294
+
3295
+ if (this.idlType === "void") {
3296
+ const message = `\`void\` is now replaced by \`undefined\`. Refer to the \
3297
+ [relevant GitHub issue](https://github.com/whatwg/webidl/issues/60) \
3298
+ for more information.`;
3299
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_3__.validationError)(this.tokens.base, this, "replace-void", message, {
3300
+ autofix: replaceVoid(this),
3301
+ });
3302
+ }
3303
+
3304
+ /*
3305
+ * If a union is nullable, its subunions cannot include a dictionary
3306
+ * If not, subunions may include dictionaries if each union is not nullable
3307
+ */
3308
+ const typedef = !this.union && defs.unique.get(this.idlType);
3309
+ const target = this.union
3310
+ ? this
3311
+ : typedef && typedef.type === "typedef"
3312
+ ? typedef.idlType
3313
+ : undefined;
3314
+ if (target && this.nullable) {
3315
+ // do not allow any dictionary
3316
+ const { reference } = (0,_validators_helpers_js__WEBPACK_IMPORTED_MODULE_4__.idlTypeIncludesDictionary)(target, defs) || {};
3317
+ if (reference) {
3318
+ const targetToken = (this.union ? reference : this).tokens.base;
3319
+ const message = "Nullable union cannot include a dictionary type.";
3320
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_3__.validationError)(
3321
+ targetToken,
3322
+ this,
3323
+ "no-nullable-union-dict",
3324
+ message,
3325
+ );
3326
+ }
3327
+ } else {
3328
+ // allow some dictionary
3329
+ for (const subtype of this.subtype) {
3330
+ yield* subtype.validate(defs);
3331
+ }
3332
+ }
3333
+ }
3334
+
3335
+ /** @param {import("../writer.js").Writer} w */
3336
+ write(w) {
3337
+ const type_body = () => {
3338
+ if (this.union || this.generic) {
3339
+ return w.ts.wrap([
3340
+ w.token(this.tokens.base, w.ts.generic),
3341
+ w.token(this.tokens.open),
3342
+ ...this.subtype.map((t) => t.write(w)),
3343
+ w.token(this.tokens.close),
3344
+ ]);
3345
+ }
3346
+ const firstToken = this.tokens.prefix || this.tokens.base;
3347
+ const prefix = this.tokens.prefix
3348
+ ? [this.tokens.prefix.value, w.ts.trivia(this.tokens.base.trivia)]
3349
+ : [];
3350
+ const ref = w.reference(
3351
+ w.ts.wrap([
3352
+ ...prefix,
3353
+ this.tokens.base.value,
3354
+ w.token(this.tokens.postfix),
3355
+ ]),
3356
+ {
3357
+ unescaped: /** @type {string} (because it's not union) */ (
3358
+ this.idlType
3359
+ ),
3360
+ context: this,
3361
+ },
3362
+ );
3363
+ return w.ts.wrap([w.ts.trivia(firstToken.trivia), ref]);
3364
+ };
3365
+ return w.ts.wrap([
3366
+ w.token(this.tokens.openRT),
3367
+ this.extAttrs.write(w),
3368
+ type_body(),
3369
+ w.token(this.tokens.nullable),
3370
+ w.token(this.tokens.closeRT),
3371
+ w.token(this.tokens.separator),
3372
+ ]);
3373
+ }
3374
+ }
3375
+
3376
+ /**
3377
+ * @param {Type} type
3378
+ * @param {import("./extended-attributes.js").SimpleExtendedAttribute} extAttr
3379
+ * @param {ExtendedAttributes} extAttrs
3380
+ */
3381
+ function replaceAllowShared(type, extAttr, extAttrs) {
3382
+ return () => {
3383
+ const index = extAttrs.indexOf(extAttr);
3384
+ extAttrs.splice(index, 1);
3385
+ if (!extAttrs.length && type.tokens.base.trivia.match(/^\s$/)) {
3386
+ type.tokens.base.trivia = ""; // (let's not remove comments)
3387
+ }
3388
+
3389
+ type.tokens.base.value = "AllowSharedBufferSource";
3390
+ };
3391
+ }
3392
+
3393
+ /**
3394
+ * @param {Type} type
3395
+ */
3396
+ function replaceVoid(type) {
3397
+ return () => {
3398
+ type.tokens.base.value = "undefined";
3399
+ };
3400
+ }
3401
+
3402
+
3403
+ /***/ }),
3404
+
3405
+ /***/ "./lib/productions/typedef.js":
3406
+ /*!************************************!*\
3407
+ !*** ./lib/productions/typedef.js ***!
3408
+ \************************************/
3409
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
3410
+
3411
+ __webpack_require__.r(__webpack_exports__);
3412
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3413
+ /* harmony export */ Typedef: () => (/* binding */ Typedef)
3414
+ /* harmony export */ });
3415
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
3416
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
3417
+
3418
+
3419
+
3420
+ class Typedef extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
3421
+ /**
3422
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
3423
+ */
3424
+ static parse(tokeniser) {
3425
+ /** @type {Base["tokens"]} */
3426
+ const tokens = {};
3427
+ const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.autoParenter)(new Typedef({ source: tokeniser.source, tokens }));
3428
+ tokens.base = tokeniser.consume("typedef");
3429
+ if (!tokens.base) {
3430
+ return;
3431
+ }
3432
+ ret.idlType =
3433
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.type_with_extended_attributes)(tokeniser, "typedef-type") ||
3434
+ tokeniser.error("Typedef lacks a type");
3435
+ tokens.name =
3436
+ tokeniser.consumeKind("identifier") ||
3437
+ tokeniser.error("Typedef lacks a name");
3438
+ tokeniser.current = ret.this;
3439
+ tokens.termination =
3440
+ tokeniser.consume(";") ||
3441
+ tokeniser.error("Unterminated typedef, expected `;`");
3442
+ return ret.this;
3443
+ }
3444
+
3445
+ get type() {
3446
+ return "typedef";
3447
+ }
3448
+ get name() {
3449
+ return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(this.tokens.name.value);
3450
+ }
3451
+
3452
+ *validate(defs) {
3453
+ yield* this.idlType.validate(defs);
3454
+ }
3455
+
3456
+ /** @param {import("../writer.js").Writer} w */
3457
+ write(w) {
3458
+ return w.ts.definition(
3459
+ w.ts.wrap([
3460
+ this.extAttrs.write(w),
3461
+ w.token(this.tokens.base),
3462
+ w.ts.type(this.idlType.write(w)),
3463
+ w.name_token(this.tokens.name, { data: this }),
3464
+ w.token(this.tokens.termination),
3465
+ ]),
3466
+ { data: this },
3467
+ );
3468
+ }
3469
+ }
3470
+
3471
+
3472
+ /***/ }),
3473
+
3474
+ /***/ "./lib/productions/version.js":
3475
+ /*!************************************!*\
3476
+ !*** ./lib/productions/version.js ***!
3477
+ \************************************/
3478
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
3479
+
3480
+ __webpack_require__.r(__webpack_exports__);
3481
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3482
+ /* harmony export */ Version: () => (/* binding */ Version)
3483
+ /* harmony export */ });
3484
+ /* harmony import */ var _base_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./base.js */ "./lib/productions/base.js");
3485
+ /* harmony import */ var _extended_attributes_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./extended-attributes.js */ "./lib/productions/extended-attributes.js");
3486
+ /* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helpers.js */ "./lib/productions/helpers.js");
3487
+
3488
+
3489
+
3490
+
3491
+ class Version extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
3492
+ /**
3493
+ * @param {import("../tokeniser.js").Tokeniser} tokeniser
3494
+ */
3495
+ static parse(tokeniser) {
3496
+ const startTokeniserPosition = tokeniser.position;
3497
+ const extAttrs = _extended_attributes_js__WEBPACK_IMPORTED_MODULE_1__.ExtendedAttributes.parse(tokeniser);
3498
+
3499
+ /** @type {Base["tokens"]} */
3500
+ const tokens = {};
3501
+ tokens.base = tokeniser.consume("version");
3502
+ if (!tokens.base) {
3503
+ tokeniser.unconsume(startTokeniserPosition);
3504
+ return;
3505
+ }
3506
+
3507
+ let value = "";
3508
+ for (let i = 0; i < 10; ++i) {
3509
+ tokens.termination = tokeniser.consume(";");
3510
+ if (tokens.termination) {
3511
+ break;
3512
+ }
3513
+ const token =
3514
+ tokeniser.consumeKind("decimal") ||
3515
+ tokeniser.consumeKind("integer") ||
3516
+ tokeniser.consumeKind("identifier") ||
3517
+ tokeniser.consumeKind("other") ||
3518
+ tokeniser.error("version lacks a value");
3519
+
3520
+ tokens[`value${i}`] = token;
3521
+ value += token.value;
3522
+ }
3523
+
3524
+ if (!tokens.termination || !value) {
3525
+ tokeniser.error("Malformed version value");
3526
+ }
3527
+
3528
+ const ret = new Version({ source: tokeniser.source, tokens });
3529
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.autoParenter)(ret).value = value.split(".");
3530
+ (0,_helpers_js__WEBPACK_IMPORTED_MODULE_2__.autoParenter)(ret).extAttrs = extAttrs;
3531
+ return ret;
3532
+ }
3533
+
3534
+ get type() {
3535
+ return "version";
3536
+ }
3537
+
3538
+ /** @param {import("../writer.js").Writer} w */
3539
+ write(w) {
3540
+ const { parent } = this;
3541
+ const valueTokens = [];
3542
+ for (let i = 0; i < 10; ++i) {
3543
+ valueTokens.push(w.token(this.tokens[`value${i}`]));
3544
+ }
3545
+ return w.ts.definition(
3546
+ w.ts.wrap([
3547
+ this.extAttrs.write(w),
3548
+ w.token(this.tokens.base),
3549
+ ...valueTokens,
3550
+ w.token(this.tokens.termination),
3551
+ ]),
3552
+ { data: this, parent },
3553
+ );
3554
+ }
3555
+ }
3556
+
3557
+
3558
+ /***/ }),
3559
+
3560
+ /***/ "./lib/tokeniser.js":
3561
+ /*!**************************!*\
3562
+ !*** ./lib/tokeniser.js ***!
3563
+ \**************************/
3564
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
3565
+
3566
+ __webpack_require__.r(__webpack_exports__);
3567
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3568
+ /* harmony export */ Tokeniser: () => (/* binding */ Tokeniser),
3569
+ /* harmony export */ WebIDLParseError: () => (/* binding */ WebIDLParseError),
3570
+ /* harmony export */ argumentNameKeywords: () => (/* binding */ argumentNameKeywords),
3571
+ /* harmony export */ stringTypes: () => (/* binding */ stringTypes),
3572
+ /* harmony export */ typeNameKeywords: () => (/* binding */ typeNameKeywords)
3573
+ /* harmony export */ });
3574
+ /* harmony import */ var _error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./error.js */ "./lib/error.js");
3575
+ /* harmony import */ var _productions_helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./productions/helpers.js */ "./lib/productions/helpers.js");
3576
+
3577
+
3578
+
3579
+ // These regular expressions use the sticky flag so they will only match at
3580
+ // the current location (ie. the offset of lastIndex).
3581
+ const tokenRe = {
3582
+ // This expression uses a lookahead assertion to catch false matches
3583
+ // against integers early.
3584
+ decimal:
3585
+ /-?(?=[0-9]*\.|[0-9]+[eE])(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0-9]+)?|[0-9]+[Ee][-+]?[0-9]+)/y,
3586
+ integer: /-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/y,
3587
+ identifier: /[_-]?[A-Za-z](\.?[0-9A-Z_a-z-])*/y,
3588
+ string: /"(\\"|[^"])*"/y,
3589
+ whitespace: /[\t\n\r ]+/y,
3590
+ comment: /\/\/.*|\/\*[\s\S]*?\*\//y,
3591
+ other: /[^\t\n\r 0-9A-Za-z]/y,
3592
+ };
3593
+
3594
+ const typeNameKeywords = [
3595
+ "ArrayBuffer",
3596
+ "SharedArrayBuffer",
3597
+ "DataView",
3598
+ "Int8Array",
3599
+ "Int16Array",
3600
+ "Int32Array",
3601
+ "Uint8Array",
3602
+ "Uint16Array",
3603
+ "Uint32Array",
3604
+ "Uint8ClampedArray",
3605
+ "BigInt64Array",
3606
+ "BigUint64Array",
3607
+ "Float16Array",
3608
+ "Float32Array",
3609
+ "Float64Array",
3610
+ "any",
3611
+ "object",
3612
+ "symbol",
3613
+ ];
3614
+
3615
+ const stringTypes = ["ByteString", "DOMString", "String", "USVString"];
3616
+
3617
+ const argumentNameKeywords = [
3618
+ "async",
3619
+ "attribute",
3620
+ "callback",
3621
+ "const",
3622
+ "constructor",
3623
+ "deleter",
3624
+ "dictionary",
3625
+ "enum",
3626
+ "getter",
3627
+ "includes",
3628
+ "inherit",
3629
+ "interface",
3630
+ "iterable",
3631
+ "maplike",
3632
+ "namespace",
3633
+ "partial",
3634
+ "required",
3635
+ "setlike",
3636
+ "setter",
3637
+ "static",
3638
+ "stringifier",
3639
+ "typedef",
3640
+ "unrestricted",
3641
+ "package",
3642
+ "import",
3643
+ "version",
3644
+ ];
3645
+
3646
+ const nonRegexTerminals = [
3647
+ "-Infinity",
3648
+ "FrozenArray",
3649
+ "Infinity",
3650
+ "NaN",
3651
+ "ObservableArray",
3652
+ "Promise",
3653
+ "bigint",
3654
+ "boolean",
3655
+ "byte",
3656
+ "double",
3657
+ "false",
3658
+ "float",
3659
+ "long",
3660
+ "mixin",
3661
+ "null",
3662
+ "octet",
3663
+ "optional",
3664
+ "or",
3665
+ "readonly",
3666
+ "record",
3667
+ "sequence",
3668
+ "short",
3669
+ "true",
3670
+ "undefined",
3671
+ "unsigned",
3672
+ "void",
3673
+ ].concat(argumentNameKeywords);
3674
+
3675
+ const punctuations = [
3676
+ "(",
3677
+ ")",
3678
+ ",",
3679
+ "...",
3680
+ ":",
3681
+ ";",
3682
+ "<",
3683
+ "=",
3684
+ ">",
3685
+ "?",
3686
+ "*",
3687
+ "[",
3688
+ "]",
3689
+ "{",
3690
+ "}",
3691
+ ];
3692
+
3693
+ const reserved = [
3694
+ // "constructor" is now a keyword
3695
+ "_constructor",
3696
+ "toString",
3697
+ "_toString",
3698
+ ];
3699
+
3700
+ /**
3701
+ * @typedef {ArrayItemType<ReturnType<typeof tokenise>>} Token
3702
+ * @param {string} str
3703
+ */
3704
+ function tokenise(str) {
3705
+ const tokens = [];
3706
+ let lastCharIndex = 0;
3707
+ let trivia = "";
3708
+ let line = 1;
3709
+ let index = 0;
3710
+ while (lastCharIndex < str.length) {
3711
+ const nextChar = str.charAt(lastCharIndex);
3712
+ let result = -1;
3713
+
3714
+ if (/[\t\n\r ]/.test(nextChar)) {
3715
+ result = attemptTokenMatch("whitespace", { noFlushTrivia: true });
3716
+ } else if (nextChar === "/") {
3717
+ result = attemptTokenMatch("comment", { noFlushTrivia: true });
3718
+ }
3719
+
3720
+ if (result !== -1) {
3721
+ const currentTrivia = tokens.pop().value;
3722
+ line += (currentTrivia.match(/\n/g) || []).length;
3723
+ trivia += currentTrivia;
3724
+ index -= 1;
3725
+ } else if (/[-0-9.A-Z_a-z]/.test(nextChar)) {
3726
+ result = attemptTokenMatch("decimal");
3727
+ if (result === -1) {
3728
+ result = attemptTokenMatch("integer");
3729
+ }
3730
+ if (result === -1) {
3731
+ result = attemptTokenMatch("identifier");
3732
+ const lastIndex = tokens.length - 1;
3733
+ const token = tokens[lastIndex];
3734
+ if (result !== -1) {
3735
+ if (reserved.includes(token.value)) {
3736
+ const message = `${(0,_productions_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(
3737
+ token.value,
3738
+ )} is a reserved identifier and must not be used.`;
3739
+ throw new WebIDLParseError(
3740
+ (0,_error_js__WEBPACK_IMPORTED_MODULE_0__.syntaxError)(tokens, lastIndex, null, message),
3741
+ );
3742
+ } else if (nonRegexTerminals.includes(token.value)) {
3743
+ token.type = "inline";
3744
+ }
3745
+ }
3746
+ }
3747
+ } else if (nextChar === '"') {
3748
+ result = attemptTokenMatch("string");
3749
+ }
3750
+
3751
+ for (const punctuation of punctuations) {
3752
+ if (str.startsWith(punctuation, lastCharIndex)) {
3753
+ tokens.push({
3754
+ type: "inline",
3755
+ value: punctuation,
3756
+ trivia,
3757
+ line,
3758
+ index,
3759
+ });
3760
+ trivia = "";
3761
+ lastCharIndex += punctuation.length;
3762
+ result = lastCharIndex;
3763
+ break;
3764
+ }
3765
+ }
3766
+
3767
+ // other as the last try
3768
+ if (result === -1) {
3769
+ result = attemptTokenMatch("other");
3770
+ }
3771
+ if (result === -1) {
3772
+ throw new Error("Token stream not progressing");
3773
+ }
3774
+ lastCharIndex = result;
3775
+ index += 1;
3776
+ }
3777
+
3778
+ // remaining trivia as eof
3779
+ tokens.push({
3780
+ type: "eof",
3781
+ value: "",
3782
+ trivia,
3783
+ line,
3784
+ index,
3785
+ });
3786
+
3787
+ return tokens;
3788
+
3789
+ /**
3790
+ * @param {keyof typeof tokenRe} type
3791
+ * @param {object} options
3792
+ * @param {boolean} [options.noFlushTrivia]
3793
+ */
3794
+ function attemptTokenMatch(type, { noFlushTrivia } = {}) {
3795
+ const re = tokenRe[type];
3796
+ re.lastIndex = lastCharIndex;
3797
+ const result = re.exec(str);
3798
+ if (result) {
3799
+ tokens.push({ type, value: result[0], trivia, line, index });
3800
+ if (!noFlushTrivia) {
3801
+ trivia = "";
3802
+ }
3803
+ return re.lastIndex;
3804
+ }
3805
+ return -1;
3806
+ }
3807
+ }
3808
+
3809
+ class Tokeniser {
3810
+ /**
3811
+ * @param {string} idl
3812
+ */
3813
+ constructor(idl) {
3814
+ this.source = tokenise(idl);
3815
+ this.position = 0;
3816
+ }
3817
+
3818
+ /**
3819
+ * @param {string} message
3820
+ * @return {never}
3821
+ */
3822
+ error(message) {
3823
+ throw new WebIDLParseError(
3824
+ (0,_error_js__WEBPACK_IMPORTED_MODULE_0__.syntaxError)(this.source, this.position, this.current, message),
3825
+ );
3826
+ }
3827
+
3828
+ /**
3829
+ * @param {string} type
3830
+ */
3831
+ probeKind(type) {
3832
+ return (
3833
+ this.source.length > this.position &&
3834
+ this.source[this.position].type === type
3835
+ );
3836
+ }
3837
+
3838
+ /**
3839
+ * @param {string} value
3840
+ */
3841
+ probe(value) {
3842
+ return (
3843
+ this.probeKind("inline") && this.source[this.position].value === value
3844
+ );
3845
+ }
3846
+
3847
+ /**
3848
+ * @param {...string} candidates
3849
+ */
3850
+ consumeKind(...candidates) {
3851
+ for (const type of candidates) {
3852
+ if (!this.probeKind(type)) continue;
3853
+ const token = this.source[this.position];
3854
+ this.position++;
3855
+ return token;
3856
+ }
3857
+ }
3858
+
3859
+ /**
3860
+ * @param {...string} candidates
3861
+ */
3862
+ consume(...candidates) {
3863
+ if (!this.probeKind("inline")) return;
3864
+ const token = this.source[this.position];
3865
+ for (const value of candidates) {
3866
+ if (token.value !== value) continue;
3867
+ this.position++;
3868
+ return token;
3869
+ }
3870
+ }
3871
+
3872
+ /**
3873
+ * @param {string} value
3874
+ */
3875
+ consumeIdentifier(value) {
3876
+ if (!this.probeKind("identifier")) {
3877
+ return;
3878
+ }
3879
+ if (this.source[this.position].value !== value) {
3880
+ return;
3881
+ }
3882
+ return this.consumeKind("identifier");
3883
+ }
3884
+
3885
+ /**
3886
+ * @param {number} position
3887
+ */
3888
+ unconsume(position) {
3889
+ this.position = position;
3890
+ }
3891
+ }
3892
+
3893
+ class WebIDLParseError extends Error {
3894
+ /**
3895
+ * @param {object} options
3896
+ * @param {string} options.message
3897
+ * @param {string} options.bareMessage
3898
+ * @param {string} options.context
3899
+ * @param {number} options.line
3900
+ * @param {*} options.sourceName
3901
+ * @param {string} options.input
3902
+ * @param {*[]} options.tokens
3903
+ */
3904
+ constructor({
3905
+ message,
3906
+ bareMessage,
3907
+ context,
3908
+ line,
3909
+ sourceName,
3910
+ input,
3911
+ tokens,
3912
+ }) {
3913
+ super(message);
3914
+
3915
+ this.name = "WebIDLParseError"; // not to be mangled
3916
+ this.bareMessage = bareMessage;
3917
+ this.context = context;
3918
+ this.line = line;
3919
+ this.sourceName = sourceName;
3920
+ this.input = input;
3921
+ this.tokens = tokens;
3922
+ }
3923
+ }
3924
+
3925
+
3926
+ /***/ }),
3927
+
3928
+ /***/ "./lib/validator.js":
3929
+ /*!**************************!*\
3930
+ !*** ./lib/validator.js ***!
3931
+ \**************************/
3932
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
3933
+
3934
+ __webpack_require__.r(__webpack_exports__);
3935
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3936
+ /* harmony export */ validate: () => (/* binding */ validate)
3937
+ /* harmony export */ });
3938
+ /* harmony import */ var _error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./error.js */ "./lib/error.js");
3939
+
3940
+
3941
+ function getMixinMap(all, unique) {
3942
+ const map = new Map();
3943
+ const includes = all.filter((def) => def.type === "includes");
3944
+ for (const include of includes) {
3945
+ const mixin = unique.get(include.includes);
3946
+ if (!mixin) {
3947
+ continue;
3948
+ }
3949
+ const array = map.get(include.target);
3950
+ if (array) {
3951
+ array.push(mixin);
3952
+ } else {
3953
+ map.set(include.target, [mixin]);
3954
+ }
3955
+ }
3956
+ return map;
3957
+ }
3958
+
3959
+ /**
3960
+ * @typedef {ReturnType<typeof groupDefinitions>} Definitions
3961
+ */
3962
+ function groupDefinitions(all) {
3963
+ const unique = new Map();
3964
+ const duplicates = new Set();
3965
+ const partials = new Map();
3966
+ for (const def of all) {
3967
+ if (def.partial) {
3968
+ const array = partials.get(def.name);
3969
+ if (array) {
3970
+ array.push(def);
3971
+ } else {
3972
+ partials.set(def.name, [def]);
3973
+ }
3974
+ continue;
3975
+ }
3976
+ if (!def.name) {
3977
+ continue;
3978
+ }
3979
+ if (!unique.has(def.name)) {
3980
+ unique.set(def.name, def);
3981
+ } else {
3982
+ duplicates.add(def);
3983
+ }
3984
+ }
3985
+ return {
3986
+ all,
3987
+ unique,
3988
+ partials,
3989
+ duplicates,
3990
+ mixinMap: getMixinMap(all, unique),
3991
+ cache: {
3992
+ typedefIncludesDictionary: new WeakMap(),
3993
+ dictionaryIncludesRequiredField: new WeakMap(),
3994
+ },
3995
+ };
3996
+ }
3997
+
3998
+ function* checkDuplicatedNames({ unique, duplicates }) {
3999
+ for (const dup of duplicates) {
4000
+ const { name } = dup;
4001
+ const message = `The name "${name}" of type "${
4002
+ unique.get(name).type
4003
+ }" was already seen`;
4004
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_0__.validationError)(dup.tokens.name, dup, "no-duplicate", message);
4005
+ }
4006
+ }
4007
+
4008
+ function* validateIterable(ast) {
4009
+ const defs = groupDefinitions(ast);
4010
+ for (const def of defs.all) {
4011
+ if (def.validate) {
4012
+ yield* def.validate(defs);
4013
+ }
4014
+ }
4015
+ yield* checkDuplicatedNames(defs);
4016
+ }
4017
+
4018
+ // Remove this once all of our support targets expose `.flat()` by default
4019
+ function flatten(array) {
4020
+ if (array.flat) {
4021
+ return array.flat();
4022
+ }
4023
+ return [].concat(...array);
4024
+ }
4025
+
4026
+ /**
4027
+ * @param {import("./productions/base.js").Base[]} ast
4028
+ * @return {import("./error.js").WebIDLErrorData[]} validation errors
4029
+ */
4030
+ function validate(ast) {
4031
+ return [...validateIterable(flatten(ast))];
4032
+ }
4033
+
4034
+
4035
+ /***/ }),
4036
+
4037
+ /***/ "./lib/validators/helpers.js":
4038
+ /*!***********************************!*\
4039
+ !*** ./lib/validators/helpers.js ***!
4040
+ \***********************************/
4041
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
4042
+
4043
+ __webpack_require__.r(__webpack_exports__);
4044
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4045
+ /* harmony export */ dictionaryIncludesRequiredField: () => (/* binding */ dictionaryIncludesRequiredField),
4046
+ /* harmony export */ idlTypeIncludesDictionary: () => (/* binding */ idlTypeIncludesDictionary),
4047
+ /* harmony export */ idlTypeIncludesEnforceRange: () => (/* binding */ idlTypeIncludesEnforceRange)
4048
+ /* harmony export */ });
4049
+ /**
4050
+ * @typedef {import("../validator.js").Definitions} Definitions
4051
+ * @typedef {import("../productions/dictionary.js").Dictionary} Dictionary
4052
+ * @typedef {import("../../lib/productions/type").Type} Type
4053
+ *
4054
+ * @param {Type} idlType
4055
+ * @param {Definitions} defs
4056
+ * @param {object} [options]
4057
+ * @param {boolean} [options.useNullableInner] use when the input idlType is nullable and you want to use its inner type
4058
+ * @return {{ reference: *, dictionary: Dictionary }} the type reference that ultimately includes dictionary.
4059
+ */
4060
+ function idlTypeIncludesDictionary(
4061
+ idlType,
4062
+ defs,
4063
+ { useNullableInner } = {},
4064
+ ) {
4065
+ if (!idlType.union) {
4066
+ const def = defs.unique.get(idlType.idlType);
4067
+ if (!def) {
4068
+ return;
4069
+ }
4070
+ if (def.type === "typedef") {
4071
+ const { typedefIncludesDictionary } = defs.cache;
4072
+ if (typedefIncludesDictionary.has(def)) {
4073
+ // Note that this also halts when it met indeterminate state
4074
+ // to prevent infinite recursion
4075
+ return typedefIncludesDictionary.get(def);
4076
+ }
4077
+ defs.cache.typedefIncludesDictionary.set(def, undefined); // indeterminate state
4078
+ const result = idlTypeIncludesDictionary(def.idlType, defs);
4079
+ defs.cache.typedefIncludesDictionary.set(def, result);
4080
+ if (result) {
4081
+ return {
4082
+ reference: idlType,
4083
+ dictionary: result.dictionary,
4084
+ };
4085
+ }
4086
+ }
4087
+ if (def.type === "dictionary" && (useNullableInner || !idlType.nullable)) {
4088
+ return {
4089
+ reference: idlType,
4090
+ dictionary: def,
4091
+ };
4092
+ }
4093
+ }
4094
+ for (const subtype of idlType.subtype) {
4095
+ const result = idlTypeIncludesDictionary(subtype, defs);
4096
+ if (result) {
4097
+ if (subtype.union) {
4098
+ return result;
4099
+ }
4100
+ return {
4101
+ reference: subtype,
4102
+ dictionary: result.dictionary,
4103
+ };
4104
+ }
4105
+ }
4106
+ }
4107
+
4108
+ /**
4109
+ * @param {Dictionary} dict dictionary type
4110
+ * @param {Definitions} defs
4111
+ * @return {boolean}
4112
+ */
4113
+ function dictionaryIncludesRequiredField(dict, defs) {
4114
+ if (defs.cache.dictionaryIncludesRequiredField.has(dict)) {
4115
+ return defs.cache.dictionaryIncludesRequiredField.get(dict);
4116
+ }
4117
+ // Set cached result to indeterminate to short-circuit circular definitions.
4118
+ // The final result will be updated to true or false.
4119
+ defs.cache.dictionaryIncludesRequiredField.set(dict, undefined);
4120
+ let result = dict.members.some((field) => field.required);
4121
+ if (!result && dict.inheritance) {
4122
+ const superdict = defs.unique.get(dict.inheritance);
4123
+ if (!superdict) {
4124
+ // Assume required members in the supertype if it is unknown.
4125
+ result = true;
4126
+ } else if (dictionaryIncludesRequiredField(superdict, defs)) {
4127
+ result = true;
4128
+ }
4129
+ }
4130
+ defs.cache.dictionaryIncludesRequiredField.set(dict, result);
4131
+ return result;
4132
+ }
4133
+
4134
+ /**
4135
+ * For now this only checks the most frequent cases:
4136
+ * 1. direct inclusion of [EnforceRange]
4137
+ * 2. typedef of that
4138
+ *
4139
+ * More complex cases with dictionaries and records are not covered yet.
4140
+ *
4141
+ * @param {Type} idlType
4142
+ * @param {Definitions} defs
4143
+ */
4144
+ function idlTypeIncludesEnforceRange(idlType, defs) {
4145
+ if (idlType.union) {
4146
+ // TODO: This should ideally be checked too
4147
+ return false;
4148
+ }
4149
+
4150
+ if (idlType.extAttrs.some((e) => e.name === "EnforceRange")) {
4151
+ return true;
4152
+ }
4153
+
4154
+ const def = defs.unique.get(idlType.idlType);
4155
+ if (def?.type !== "typedef") {
4156
+ return false;
4157
+ }
4158
+
4159
+ return def.idlType.extAttrs.some((e) => e.name === "EnforceRange");
4160
+ }
4161
+
4162
+
4163
+ /***/ }),
4164
+
4165
+ /***/ "./lib/validators/interface.js":
4166
+ /*!*************************************!*\
4167
+ !*** ./lib/validators/interface.js ***!
4168
+ \*************************************/
4169
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
4170
+
4171
+ __webpack_require__.r(__webpack_exports__);
4172
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4173
+ /* harmony export */ checkInterfaceMemberDuplication: () => (/* binding */ checkInterfaceMemberDuplication)
4174
+ /* harmony export */ });
4175
+ /* harmony import */ var _error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../error.js */ "./lib/error.js");
4176
+
4177
+
4178
+ /**
4179
+ * @param {import("../validator.js").Definitions} defs
4180
+ * @param {import("../productions/container.js").Container} i
4181
+ */
4182
+ function* checkInterfaceMemberDuplication(defs, i) {
4183
+ const opNames = groupOperationNames(i);
4184
+ const partials = defs.partials.get(i.name) || [];
4185
+ const mixins = defs.mixinMap.get(i.name) || [];
4186
+ for (const ext of [...partials, ...mixins]) {
4187
+ const additions = getOperations(ext);
4188
+ const statics = additions.filter((a) => a.special === "static");
4189
+ const nonstatics = additions.filter((a) => a.special !== "static");
4190
+ yield* checkAdditions(statics, opNames.statics, ext, i);
4191
+ yield* checkAdditions(nonstatics, opNames.nonstatics, ext, i);
4192
+ statics.forEach((op) => opNames.statics.add(op.name));
4193
+ nonstatics.forEach((op) => opNames.nonstatics.add(op.name));
4194
+ }
4195
+
4196
+ /**
4197
+ * @param {import("../productions/operation.js").Operation[]} additions
4198
+ * @param {Set<string>} existings
4199
+ * @param {import("../productions/container.js").Container} ext
4200
+ * @param {import("../productions/container.js").Container} base
4201
+ */
4202
+ function* checkAdditions(additions, existings, ext, base) {
4203
+ for (const addition of additions) {
4204
+ const { name } = addition;
4205
+ if (name && existings.has(name)) {
4206
+ const isStatic = addition.special === "static" ? "static " : "";
4207
+ const message = `The ${isStatic}operation "${name}" has already been defined for the base interface "${base.name}" either in itself or in a mixin`;
4208
+ yield (0,_error_js__WEBPACK_IMPORTED_MODULE_0__.validationError)(
4209
+ addition.tokens.name,
4210
+ ext,
4211
+ "no-cross-overload",
4212
+ message,
4213
+ );
4214
+ }
4215
+ }
4216
+ }
4217
+
4218
+ /**
4219
+ * @param {import("../productions/container.js").Container} i
4220
+ * @returns {import("../productions/operation.js").Operation[]}
4221
+ */
4222
+ function getOperations(i) {
4223
+ return i.members.filter(({ type }) => type === "operation");
4224
+ }
4225
+
4226
+ /**
4227
+ * @param {import("../productions/container.js").Container} i
4228
+ */
4229
+ function groupOperationNames(i) {
4230
+ const ops = getOperations(i);
4231
+ return {
4232
+ statics: new Set(
4233
+ ops.filter((op) => op.special === "static").map((op) => op.name),
4234
+ ),
4235
+ nonstatics: new Set(
4236
+ ops.filter((op) => op.special !== "static").map((op) => op.name),
4237
+ ),
4238
+ };
4239
+ }
4240
+ }
4241
+
4242
+
4243
+ /***/ }),
4244
+
4245
+ /***/ "./lib/webidl2.js":
4246
+ /*!************************!*\
4247
+ !*** ./lib/webidl2.js ***!
4248
+ \************************/
4249
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
4250
+
4251
+ __webpack_require__.r(__webpack_exports__);
4252
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4253
+ /* harmony export */ parse: () => (/* binding */ parse)
4254
+ /* harmony export */ });
4255
+ /* harmony import */ var _tokeniser_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./tokeniser.js */ "./lib/tokeniser.js");
4256
+ /* harmony import */ var _productions_enum_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./productions/enum.js */ "./lib/productions/enum.js");
4257
+ /* harmony import */ var _productions_includes_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./productions/includes.js */ "./lib/productions/includes.js");
4258
+ /* harmony import */ var _productions_package_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./productions/package.js */ "./lib/productions/package.js");
4259
+ /* harmony import */ var _productions_version_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./productions/version.js */ "./lib/productions/version.js");
4260
+ /* harmony import */ var _productions_import_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./productions/import.js */ "./lib/productions/import.js");
4261
+ /* harmony import */ var _productions_extended_attributes_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./productions/extended-attributes.js */ "./lib/productions/extended-attributes.js");
4262
+ /* harmony import */ var _productions_typedef_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./productions/typedef.js */ "./lib/productions/typedef.js");
4263
+ /* harmony import */ var _productions_dictionary_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./productions/dictionary.js */ "./lib/productions/dictionary.js");
4264
+ /* harmony import */ var _productions_namespace_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./productions/namespace.js */ "./lib/productions/namespace.js");
4265
+ /* harmony import */ var _productions_token_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./productions/token.js */ "./lib/productions/token.js");
4266
+ /* harmony import */ var _productions_parser_state_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./productions/parser-state.js */ "./lib/productions/parser-state.js");
4267
+ /* harmony import */ var _productions_attribute_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./productions/attribute.js */ "./lib/productions/attribute.js");
4268
+ /* harmony import */ var _productions_constant_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./productions/constant.js */ "./lib/productions/constant.js");
4269
+ /* harmony import */ var _productions_operation_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./productions/operation.js */ "./lib/productions/operation.js");
4270
+ /* harmony import */ var _productions_helpers_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./productions/helpers.js */ "./lib/productions/helpers.js");
4271
+
4272
+
4273
+
4274
+
4275
+
4276
+
4277
+
4278
+
4279
+
4280
+
4281
+
4282
+
4283
+
4284
+
4285
+
4286
+
4287
+
4288
+ /** @typedef {import("./productions/helpers.js").ParserOptions} ParserOptions */
4289
+
4290
+ /**
4291
+ * @param {Tokeniser} tokeniser
4292
+ * @param {ParserOptions} options
4293
+ */
4294
+ function parseByTokens(tokeniser, options) {
4295
+ const source = tokeniser.source;
4296
+
4297
+ function definition() {
4298
+ if (options.productions) {
4299
+ for (const production of options.productions) {
4300
+ const result = production(tokeniser);
4301
+ if (result) {
4302
+ return result;
4303
+ }
4304
+ }
4305
+ }
4306
+
4307
+ return (
4308
+ (0,_productions_helpers_js__WEBPACK_IMPORTED_MODULE_15__.parseCallback)(tokeniser, options) ||
4309
+ (0,_productions_helpers_js__WEBPACK_IMPORTED_MODULE_15__.parseInterface)(tokeniser, options) ||
4310
+ (0,_productions_helpers_js__WEBPACK_IMPORTED_MODULE_15__.parsePartial)(tokeniser, options) ||
4311
+ _productions_dictionary_js__WEBPACK_IMPORTED_MODULE_8__.Dictionary.parse(tokeniser, options?.extensions?.dictionary) ||
4312
+ _productions_enum_js__WEBPACK_IMPORTED_MODULE_1__.Enum.parse(tokeniser) ||
4313
+ _productions_typedef_js__WEBPACK_IMPORTED_MODULE_7__.Typedef.parse(tokeniser) ||
4314
+ _productions_includes_js__WEBPACK_IMPORTED_MODULE_2__.Includes.parse(tokeniser) ||
4315
+ _productions_package_js__WEBPACK_IMPORTED_MODULE_3__.Package.parse(tokeniser) ||
4316
+ _productions_import_js__WEBPACK_IMPORTED_MODULE_5__.Import.parse(tokeniser) ||
4317
+ _productions_namespace_js__WEBPACK_IMPORTED_MODULE_9__.Namespace.parse(tokeniser, options?.extensions?.namespace) ||
4318
+ _productions_version_js__WEBPACK_IMPORTED_MODULE_4__.Version.parse(tokeniser) ||
4319
+ _productions_attribute_js__WEBPACK_IMPORTED_MODULE_12__.Attribute.parse(tokeniser, { noInherit: true, readonly: true }) ||
4320
+ _productions_constant_js__WEBPACK_IMPORTED_MODULE_13__.Constant.parse(tokeniser) ||
4321
+ _productions_operation_js__WEBPACK_IMPORTED_MODULE_14__.Operation.parse(tokeniser, { regular: true, noneOnFail: true })
4322
+ );
4323
+ }
4324
+
4325
+ function definitions() {
4326
+ if (!source.length) return [];
4327
+ const defs = [];
4328
+ while (true) {
4329
+ const psu1 = _productions_parser_state_js__WEBPACK_IMPORTED_MODULE_11__.ParserState.update(tokeniser);
4330
+ if (psu1) defs.push(psu1);
4331
+ const ea = _productions_extended_attributes_js__WEBPACK_IMPORTED_MODULE_6__.ExtendedAttributes.parse(tokeniser);
4332
+ const def = definition();
4333
+ if (!def) {
4334
+ if (ea.length) tokeniser.error("Stray extended attributes");
4335
+ break;
4336
+ }
4337
+ (0,_productions_helpers_js__WEBPACK_IMPORTED_MODULE_15__.autoParenter)(def).extAttrs = ea;
4338
+ defs.push(def);
4339
+
4340
+ const psu2 = _productions_parser_state_js__WEBPACK_IMPORTED_MODULE_11__.ParserState.update(tokeniser);
4341
+ if (psu2) defs.push(psu2);
4342
+ }
4343
+ const eof = _productions_token_js__WEBPACK_IMPORTED_MODULE_10__.Eof.parse(tokeniser);
4344
+ if (options.concrete) {
4345
+ defs.push(eof);
4346
+ }
4347
+ return defs;
4348
+ }
4349
+
4350
+ const res = definitions();
4351
+ if (tokeniser.position < source.length)
4352
+ tokeniser.error("Unrecognised tokens");
4353
+ return res;
4354
+ }
4355
+
4356
+ /**
4357
+ * @param {string} str
4358
+ * @param {ParserOptions} [options]
4359
+ */
4360
+ function parse(str, options = {}) {
4361
+ const tokeniser = new _tokeniser_js__WEBPACK_IMPORTED_MODULE_0__.Tokeniser(str);
4362
+ if (typeof options.sourceName !== "undefined") {
4363
+ // @ts-ignore (See Tokeniser.source in supplement.d.ts)
4364
+ tokeniser.source.name = options.sourceName;
4365
+ }
4366
+ return parseByTokens(tokeniser, options);
4367
+ }
4368
+
4369
+
4370
+ /***/ }),
4371
+
4372
+ /***/ "./lib/writer.js":
4373
+ /*!***********************!*\
4374
+ !*** ./lib/writer.js ***!
4375
+ \***********************/
4376
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
4377
+
4378
+ __webpack_require__.r(__webpack_exports__);
4379
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4380
+ /* harmony export */ Writer: () => (/* binding */ Writer),
4381
+ /* harmony export */ write: () => (/* binding */ write)
4382
+ /* harmony export */ });
4383
+ function noop(arg) {
4384
+ return arg;
4385
+ }
4386
+
4387
+ const templates = {
4388
+ wrap: (items) => items.join(""),
4389
+ trivia: noop,
4390
+ name: noop,
4391
+ reference: noop,
4392
+ type: noop,
4393
+ generic: noop,
4394
+ nameless: noop,
4395
+ inheritance: noop,
4396
+ definition: noop,
4397
+ extendedAttribute: noop,
4398
+ extendedAttributeReference: noop,
4399
+ };
4400
+
4401
+ class Writer {
4402
+ constructor(ts) {
4403
+ this.ts = Object.assign({}, templates, ts);
4404
+ }
4405
+
4406
+ /**
4407
+ * @param {string} raw
4408
+ * @param {object} options
4409
+ * @param {string} [options.unescaped]
4410
+ * @param {import("./productions/base.js").Base} [options.context]
4411
+ * @returns
4412
+ */
4413
+ reference(raw, { unescaped, context }) {
4414
+ if (!unescaped) {
4415
+ unescaped = raw.startsWith("_") ? raw.slice(1) : raw;
4416
+ }
4417
+ return this.ts.reference(raw, unescaped, context);
4418
+ }
4419
+
4420
+ /**
4421
+ * @param {import("./tokeniser.js").Token} t
4422
+ * @param {Function} wrapper
4423
+ * @param {...any} args
4424
+ * @returns
4425
+ */
4426
+ token(t, wrapper = noop, ...args) {
4427
+ if (!t) {
4428
+ return "";
4429
+ }
4430
+ const value = wrapper(t.value, ...args);
4431
+ return this.ts.wrap([this.ts.trivia(t.trivia), value]);
4432
+ }
4433
+
4434
+ reference_token(t, context) {
4435
+ return this.token(t, this.reference.bind(this), { context });
4436
+ }
4437
+
4438
+ name_token(t, arg) {
4439
+ return this.token(t, this.ts.name, arg);
4440
+ }
4441
+
4442
+ identifier(id, context) {
4443
+ return this.ts.wrap([
4444
+ this.reference_token(id.tokens.value, context),
4445
+ this.token(id.tokens.separator),
4446
+ ]);
4447
+ }
4448
+ }
4449
+
4450
+ function write(ast, { templates: ts = templates } = {}) {
4451
+ ts = Object.assign({}, templates, ts);
4452
+
4453
+ const w = new Writer(ts);
4454
+
4455
+ return ts.wrap(ast.map((it) => it.write(w)));
4456
+ }
4457
+
4458
+
4459
+ /***/ })
4460
+
4461
+ /******/ });
4462
+ /************************************************************************/
4463
+ /******/ // The module cache
4464
+ /******/ var __webpack_module_cache__ = {};
4465
+ /******/
4466
+ /******/ // The require function
4467
+ /******/ function __webpack_require__(moduleId) {
4468
+ /******/ // Check if module is in cache
4469
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
4470
+ /******/ if (cachedModule !== undefined) {
4471
+ /******/ return cachedModule.exports;
4472
+ /******/ }
4473
+ /******/ // Create a new module (and put it into the cache)
4474
+ /******/ var module = __webpack_module_cache__[moduleId] = {
4475
+ /******/ // no module.id needed
4476
+ /******/ // no module.loaded needed
4477
+ /******/ exports: {}
4478
+ /******/ };
4479
+ /******/
4480
+ /******/ // Execute the module function
4481
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
4482
+ /******/
4483
+ /******/ // Return the exports of the module
4484
+ /******/ return module.exports;
4485
+ /******/ }
4486
+ /******/
4487
+ /************************************************************************/
4488
+ /******/ /* webpack/runtime/define property getters */
4489
+ /******/ (() => {
4490
+ /******/ // define getter functions for harmony exports
4491
+ /******/ __webpack_require__.d = (exports, definition) => {
4492
+ /******/ for(var key in definition) {
4493
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
4494
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
4495
+ /******/ }
4496
+ /******/ }
4497
+ /******/ };
4498
+ /******/ })();
4499
+ /******/
4500
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
4501
+ /******/ (() => {
4502
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
4503
+ /******/ })();
4504
+ /******/
4505
+ /******/ /* webpack/runtime/make namespace object */
4506
+ /******/ (() => {
4507
+ /******/ // define __esModule on exports
4508
+ /******/ __webpack_require__.r = (exports) => {
4509
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
4510
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4511
+ /******/ }
4512
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
4513
+ /******/ };
4514
+ /******/ })();
4515
+ /******/
4516
+ /************************************************************************/
4517
+ var __webpack_exports__ = {};
4518
+ /*!******************!*\
4519
+ !*** ./index.js ***!
4520
+ \******************/
4521
+ __webpack_require__.r(__webpack_exports__);
4522
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4523
+ /* harmony export */ WebIDLParseError: () => (/* reexport safe */ _lib_tokeniser_js__WEBPACK_IMPORTED_MODULE_3__.WebIDLParseError),
4524
+ /* harmony export */ parse: () => (/* reexport safe */ _lib_webidl2_js__WEBPACK_IMPORTED_MODULE_0__.parse),
4525
+ /* harmony export */ validate: () => (/* reexport safe */ _lib_validator_js__WEBPACK_IMPORTED_MODULE_2__.validate),
4526
+ /* harmony export */ write: () => (/* reexport safe */ _lib_writer_js__WEBPACK_IMPORTED_MODULE_1__.write)
4527
+ /* harmony export */ });
4528
+ /* harmony import */ var _lib_webidl2_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./lib/webidl2.js */ "./lib/webidl2.js");
4529
+ /* harmony import */ var _lib_writer_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./lib/writer.js */ "./lib/writer.js");
4530
+ /* harmony import */ var _lib_validator_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./lib/validator.js */ "./lib/validator.js");
4531
+ /* harmony import */ var _lib_tokeniser_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./lib/tokeniser.js */ "./lib/tokeniser.js");
4532
+
4533
+
4534
+
4535
+
4536
+
4537
+
4538
+
4539
+
4540
+
4541
+ if (false) {}
4542
+
4543
+ /******/ return __webpack_exports__;
4544
+ /******/ })()
4545
+ ;
4546
+ });
4547
+ //# sourceMappingURL=webidl2.js.map