@idlizer/core 2.1.10-arktscgen-5 → 2.1.10-arktscgen-7

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