@idlizer/core 2.1.10-arktscgen-5 → 2.1.10-arktscgen-6
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.
- package/build/lib/src/Language.js +1 -1
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +16 -6
- package/build/lib/src/LanguageWriters/ArgConvertors.js +80 -92
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +8 -6
- package/build/lib/src/LanguageWriters/LanguageWriter.js +8 -2
- package/build/lib/src/LanguageWriters/common.d.ts +1 -0
- package/build/lib/src/LanguageWriters/common.js +2 -1
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +7 -1
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +53 -15
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +10 -8
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -1
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +25 -14
- package/build/lib/src/LanguageWriters/index.d.ts +4 -3
- package/build/lib/src/LanguageWriters/index.js +9 -11
- package/build/lib/src/LanguageWriters/nameConvertor.d.ts +2 -0
- package/build/lib/src/LanguageWriters/nameConvertor.js +11 -0
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +1 -8
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +52 -89
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +3 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +24 -7
- package/build/lib/src/config.d.ts +2 -1461
- package/build/lib/src/config.js +16 -32
- package/build/lib/src/configMerge.d.ts +3 -0
- package/build/lib/src/configMerge.js +63 -0
- package/build/lib/src/diagnostictypes.d.ts +1 -5
- package/build/lib/src/diagnostictypes.js +1 -27
- package/build/lib/src/from-idl/DtsPrinter.js +12 -5
- package/build/lib/src/from-idl/IDLLinter.d.ts +3 -4
- package/build/lib/src/from-idl/IDLLinter.js +30 -32
- package/build/lib/src/from-idl/deserialize.d.ts +3 -4
- package/build/lib/src/from-idl/deserialize.js +29 -641
- package/build/lib/src/from-idl/parser.d.ts +20 -2
- package/build/lib/src/from-idl/parser.js +97 -29
- package/build/lib/src/idl/builders.d.ts +43 -0
- package/build/lib/src/idl/builders.js +135 -0
- package/build/lib/src/idl/discriminators.d.ts +53 -0
- package/build/lib/src/idl/discriminators.js +232 -0
- package/build/lib/src/idl/dump.d.ts +48 -0
- package/build/lib/src/idl/dump.js +327 -0
- package/build/lib/src/idl/index.d.ts +9 -0
- package/build/lib/src/idl/index.js +23 -0
- package/build/lib/src/idl/keywords.d.ts +2 -0
- package/build/lib/src/{options.js → idl/keywords.js} +7 -3
- package/build/lib/src/idl/node.d.ts +233 -0
- package/build/lib/src/idl/node.js +103 -0
- package/build/lib/src/idl/stdlib.d.ts +34 -0
- package/build/lib/src/idl/stdlib.js +54 -0
- package/build/lib/src/idl/utils.d.ts +44 -0
- package/build/lib/src/idl/utils.js +215 -0
- package/build/lib/src/idl/visitors.d.ts +15 -0
- package/build/lib/src/idl/visitors.js +593 -0
- package/build/lib/src/index.d.ts +4 -2
- package/build/lib/src/index.js +5 -3
- package/build/lib/src/inputPaths.d.ts +11 -0
- package/build/lib/src/inputPaths.js +81 -0
- package/build/lib/src/languageSpecificKeywords.d.ts +0 -1
- package/build/lib/src/languageSpecificKeywords.js +0 -5
- package/build/lib/src/peer-generation/LayoutManager.d.ts +1 -1
- package/build/lib/src/peer-generation/Materialized.d.ts +8 -2
- package/build/lib/src/peer-generation/Materialized.js +24 -12
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +10 -15
- package/build/lib/src/peer-generation/PeerLibrary.js +35 -215
- package/build/lib/src/peer-generation/ReferenceResolver.d.ts +6 -1
- package/build/lib/src/peer-generation/ReferenceResolver.js +93 -2
- package/build/lib/src/peer-generation/idl/common.d.ts +6 -2
- package/build/lib/src/peer-generation/idl/common.js +7 -7
- package/build/lib/src/peer-generation/isMaterialized.js +2 -3
- package/build/lib/src/peer-generation/modules.js +2 -0
- package/build/lib/src/peer-generation/toDeclaration.d.ts +4 -0
- package/build/lib/src/peer-generation/toDeclaration.js +53 -0
- package/build/lib/src/peer-generation/unions.d.ts +1 -1
- package/build/lib/src/peer-generation/unions.js +15 -7
- package/build/lib/src/resolveNamedNode.d.ts +1 -0
- package/build/lib/src/resolveNamedNode.js +7 -0
- package/build/lib/src/transformers/FqnTransformer.d.ts +1 -1
- package/build/lib/src/transformers/FqnTransformer.js +20 -12
- package/build/lib/src/transformers/GenericTransformer.d.ts +4 -3
- package/build/lib/src/transformers/GenericTransformer.js +252 -158
- package/build/lib/src/transformers/IdlTransformer.d.ts +6 -0
- package/build/lib/src/transformers/IdlTransformer.js +7 -0
- package/build/lib/src/transformers/NullTransformer.d.ts +1 -1
- package/build/lib/src/transformers/NullTransformer.js +27 -21
- package/build/lib/src/transformers/OnSerializeTransformer.d.ts +1 -1
- package/build/lib/src/transformers/OnSerializeTransformer.js +28 -13
- package/build/lib/src/util.d.ts +4 -0
- package/build/lib/src/util.js +22 -0
- package/package.json +6 -7
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +0 -37
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +0 -210
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +0 -85
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +0 -306
- package/build/lib/src/from-idl/webidl2-utils.d.ts +0 -21
- package/build/lib/src/from-idl/webidl2-utils.js +0 -87
- package/build/lib/src/idl.d.ts +0 -444
- package/build/lib/src/idl.js +0 -1385
- package/build/lib/src/idlize.d.ts +0 -25
- package/build/lib/src/idlize.js +0 -198
- package/build/lib/src/options.d.ts +0 -13
- package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -20
- package/build/lib/src/peer-generation/BuilderClass.js +0 -68
- package/webidl2.js/dist/webidl2.js +0 -4622
- package/webidl2.js/package.json +0 -55
|
@@ -12,24 +12,11 @@
|
|
|
12
12
|
* See the License for the specific language governing permissions and
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
|
-
import * as webidl2 from "webidl2";
|
|
16
|
-
import * as fs from "fs";
|
|
17
|
-
import { isAttribute, isCallback, isClass, isConstant, isConstructor, isDictionary, isEnum, isInterface, isOperation, isOptional, isPromiseTypeDescription, isRecordTypeDescription, isSequenceTypeDescription, isSingleTypeDescription, isTypedef, isUnionTypeDescription, isUnspecifiedGenericTypeDescription } from "./webidl2-utils";
|
|
18
|
-
import { toString } from "./toString";
|
|
19
15
|
import * as idl from "../idl";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { DiagnosticMessageGroup, LoadingFatal, ParsingFatal, InternalFatal } from "../diagnosticmessages";
|
|
24
|
-
import { FatalParserException, Parser } from "./parser";
|
|
16
|
+
import { warn } from "../util";
|
|
17
|
+
import { DiagnosticMessageGroup } from "../diagnosticmessages";
|
|
18
|
+
import { Parser } from "./parser";
|
|
25
19
|
import { outputDiagnosticMessageFormatted } from "../formatter";
|
|
26
|
-
function getTokens(node) {
|
|
27
|
-
return node.tokens;
|
|
28
|
-
}
|
|
29
|
-
const extendedAttributesWithTypesValue = [
|
|
30
|
-
idl.IDLExtendedAttributes.TypeArguments,
|
|
31
|
-
idl.IDLExtendedAttributes.TypeParametersDefaults,
|
|
32
|
-
];
|
|
33
20
|
const syntheticTypes = new Map();
|
|
34
21
|
export function addSyntheticType(name, type) {
|
|
35
22
|
if (syntheticTypes.has(name)) {
|
|
@@ -40,495 +27,29 @@ export function addSyntheticType(name, type) {
|
|
|
40
27
|
export function resolveSyntheticType(type) {
|
|
41
28
|
return syntheticTypes.get(type.name);
|
|
42
29
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.namespacePathNames = [];
|
|
50
|
-
this.currentPackage = [];
|
|
51
|
-
this.genericsScopes = [];
|
|
52
|
-
}
|
|
53
|
-
///
|
|
54
|
-
withInfo(from, result) {
|
|
55
|
-
this.info.set(result, getTokens(from));
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
setPackage(pkg) {
|
|
59
|
-
this.currentPackage = pkg;
|
|
60
|
-
}
|
|
61
|
-
///
|
|
62
|
-
sanitizeTypeParameter(param) {
|
|
63
|
-
const extendsIdx = param.indexOf('extends');
|
|
64
|
-
if (extendsIdx !== -1) {
|
|
65
|
-
return param.substring(0, extendsIdx).trim();
|
|
66
|
-
}
|
|
67
|
-
const eqIdx = param.indexOf('=');
|
|
68
|
-
if (eqIdx !== -1) {
|
|
69
|
-
return param.substring(0, eqIdx).trim();
|
|
70
|
-
}
|
|
71
|
-
return param;
|
|
72
|
-
}
|
|
73
|
-
extractGenerics(extAttrs) {
|
|
74
|
-
var _a, _b;
|
|
75
|
-
return (_b = (_a = this.findExtendedAttribute(extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(",")) === null || _b === void 0 ? void 0 : _b.map(it => this.sanitizeTypeParameter(it));
|
|
76
|
-
}
|
|
77
|
-
///
|
|
78
|
-
toIDLNode(file, node) {
|
|
79
|
-
return this.toIDLNodeForward(file, node);
|
|
80
|
-
}
|
|
81
|
-
toIDLNodeForward(file, node) {
|
|
82
|
-
if (isEnum(node)) {
|
|
83
|
-
return this.toIDLEnum(file, node);
|
|
84
|
-
}
|
|
85
|
-
if (this.isImport(node)) {
|
|
86
|
-
return this.toIDLImport(node);
|
|
87
|
-
}
|
|
88
|
-
if (isClass(node)) {
|
|
89
|
-
return this.toIDLInterface(file, node);
|
|
90
|
-
}
|
|
91
|
-
if (isInterface(node)) {
|
|
92
|
-
return this.toIDLInterface(file, node);
|
|
93
|
-
}
|
|
94
|
-
if (isCallback(node)) {
|
|
95
|
-
return this.toIDLCallback(file, node);
|
|
96
|
-
}
|
|
97
|
-
if (isTypedef(node)) {
|
|
98
|
-
return this.toIDLTypedef(file, node);
|
|
99
|
-
}
|
|
100
|
-
if (isDictionary(node)) {
|
|
101
|
-
return this.toIDLDictionary(file, node);
|
|
102
|
-
}
|
|
103
|
-
if (this.isNamespace(node)) {
|
|
104
|
-
return this.toIDLNamespace(file, node);
|
|
105
|
-
}
|
|
106
|
-
if (this.isVersion(node)) {
|
|
107
|
-
return this.toIDLVersion(file, node);
|
|
108
|
-
}
|
|
109
|
-
if (isAttribute(node)) {
|
|
110
|
-
return this.toIDLProperty(file, node);
|
|
111
|
-
}
|
|
112
|
-
if (isOperation(node)) {
|
|
113
|
-
return this.toIDLMethod(file, node, true);
|
|
114
|
-
}
|
|
115
|
-
if (isConstant(node)) {
|
|
116
|
-
return this.toIDLConstant(file, node);
|
|
117
|
-
}
|
|
118
|
-
throw new Error(`unexpected node type: ${toString(node)}`);
|
|
119
|
-
}
|
|
120
|
-
toIDLImport(node) {
|
|
121
|
-
return this.withInfo(node, idl.createImport(node.clause.split("."), node.alias || undefined));
|
|
122
|
-
}
|
|
123
|
-
interfaceSubkind(node) {
|
|
124
|
-
var _a, _b;
|
|
125
|
-
const nodeIDLEntity = (_b = (_a = node.extAttrs.find(it => it.name === "Entity")) === null || _a === void 0 ? void 0 : _a.rhs) === null || _b === void 0 ? void 0 : _b.value;
|
|
126
|
-
switch (nodeIDLEntity) {
|
|
127
|
-
case idl.IDLEntity.Class: return idl.IDLInterfaceSubkind.Class;
|
|
128
|
-
case idl.IDLEntity.Literal: return idl.IDLInterfaceSubkind.AnonymousInterface;
|
|
129
|
-
case idl.IDLEntity.Tuple: return idl.IDLInterfaceSubkind.Tuple;
|
|
130
|
-
default: return idl.IDLInterfaceSubkind.Interface;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
toIDLInterface(file, node) {
|
|
134
|
-
const generics = this.extractGenerics(node.extAttrs);
|
|
135
|
-
this.enterGenericScope(generics);
|
|
136
|
-
const subkind = this.interfaceSubkind(node);
|
|
137
|
-
const result = idl.createInterface(node.name, subkind, (() => {
|
|
138
|
-
if (!node.inheritance) {
|
|
139
|
-
return [];
|
|
140
|
-
}
|
|
141
|
-
const implementations = [];
|
|
142
|
-
node.inheritance.forEach(it => {
|
|
143
|
-
const attributes = it.extAttrs;
|
|
144
|
-
const parentTypeArgs = this.extractTypeArguments(file, attributes !== null && attributes !== void 0 ? attributes : [], idl.IDLExtendedAttributes.TypeArguments);
|
|
145
|
-
const attrs = this.toExtendedAttributes(file, attributes !== null && attributes !== void 0 ? attributes : []); // ?.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments)
|
|
146
|
-
const ref = idl.createReferenceType(it.inheritance, parentTypeArgs, {
|
|
147
|
-
extendedAttributes: attrs
|
|
148
|
-
});
|
|
149
|
-
implementations.push(ref);
|
|
150
|
-
});
|
|
151
|
-
return implementations;
|
|
152
|
-
})(), node.members
|
|
153
|
-
.filter(isConstructor)
|
|
154
|
-
.map(it => this.toIDLConstructor(file, it)), [], node.members
|
|
155
|
-
.filter(isAttribute)
|
|
156
|
-
.map(it => this.toIDLProperty(file, it)), node.members
|
|
157
|
-
.filter(isOperation)
|
|
158
|
-
.filter(it => !this.isCallable(it))
|
|
159
|
-
.map(it => this.toIDLMethod(file, it, false)), node.members
|
|
160
|
-
.filter(isOperation)
|
|
161
|
-
.filter(it => this.isCallable(it))
|
|
162
|
-
.map(it => this.toIDLCallable(file, it)), generics, {
|
|
163
|
-
fileName: file,
|
|
164
|
-
documentation: this.makeDocs(node),
|
|
165
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
166
|
-
});
|
|
167
|
-
this.genericsScopes.pop();
|
|
168
|
-
this.info.set(result, getTokens(node));
|
|
169
|
-
if (node.extAttrs.find(it => it.name === "Synthetic")) {
|
|
170
|
-
const fqName = this.currentPackage.concat(this.namespacePathNames).concat([node.name]).join('.');
|
|
171
|
-
addSyntheticType(fqName, result);
|
|
172
|
-
}
|
|
173
|
-
return result;
|
|
174
|
-
}
|
|
175
|
-
toIDLType(file, type, extAttrs, suggestedName) {
|
|
176
|
-
var _a;
|
|
177
|
-
if (typeof type === "string") {
|
|
178
|
-
// is it IDLStringType?
|
|
179
|
-
const refType = idl.createReferenceType(type);
|
|
180
|
-
refType.fileName = file;
|
|
181
|
-
// Here is a bug: type.extAttrs are ignored, so typeArguments on ([TypeArguments="T"] Something) are always lost
|
|
182
|
-
// That must be fixed together with fixing non-generic placeholders on generic types in pipelines (like WrappedBuilder)
|
|
183
|
-
refType.typeArguments = this.extractTypeArguments(file, extAttrs, idl.IDLExtendedAttributes.TypeArguments);
|
|
184
|
-
return refType;
|
|
185
|
-
}
|
|
186
|
-
if (type.nullable) {
|
|
187
|
-
return this.withInfo(type, idl.createOptionalType(this.toIDLType(file, Object.assign(Object.assign({}, type), { nullable: false }), extAttrs)));
|
|
188
|
-
}
|
|
189
|
-
if (isUnionTypeDescription(type)) {
|
|
190
|
-
let types = type.idlType
|
|
191
|
-
.map(it => this.toIDLType(file, it, undefined))
|
|
192
|
-
.filter(isDefined);
|
|
193
|
-
if (types.includes(idl.IDLUndefinedType)) {
|
|
194
|
-
types = types.filter(it => it !== idl.IDLUndefinedType);
|
|
195
|
-
return this.withInfo(type, idl.createOptionalType(collapseTypes(types)));
|
|
196
|
-
}
|
|
197
|
-
const name = suggestedName !== null && suggestedName !== void 0 ? suggestedName : generateSyntheticUnionName(types);
|
|
198
|
-
return this.withInfo(type, idl.createUnionType(types, name));
|
|
199
|
-
}
|
|
200
|
-
if (isSingleTypeDescription(type)) {
|
|
201
|
-
// must match with primitive types in idl.ts
|
|
202
|
-
switch (type.idlType) {
|
|
203
|
-
case idl.IDLPointerType.name: return idl.IDLPointerType;
|
|
204
|
-
case idl.IDLVoidType.name: return idl.IDLVoidType;
|
|
205
|
-
case idl.IDLBooleanType.name: return idl.IDLBooleanType;
|
|
206
|
-
case idl.IDLObjectType.name: return idl.IDLObjectType;
|
|
207
|
-
case idl.IDLI8Type.name: return idl.IDLI8Type;
|
|
208
|
-
case idl.IDLU8Type.name: return idl.IDLU8Type;
|
|
209
|
-
case idl.IDLI16Type.name: return idl.IDLI16Type;
|
|
210
|
-
case idl.IDLU16Type.name: return idl.IDLU16Type;
|
|
211
|
-
case idl.IDLI32Type.name: return idl.IDLI32Type;
|
|
212
|
-
case idl.IDLU32Type.name: return idl.IDLU32Type;
|
|
213
|
-
case idl.IDLI64Type.name: return idl.IDLI64Type;
|
|
214
|
-
case idl.IDLU64Type.name: return idl.IDLU64Type;
|
|
215
|
-
case idl.IDLF32Type.name: return idl.IDLF32Type;
|
|
216
|
-
case idl.IDLF64Type.name: return idl.IDLF64Type;
|
|
217
|
-
case idl.IDLBigintType.name: return idl.IDLBigintType;
|
|
218
|
-
case idl.IDLNumberType.name: return idl.IDLNumberType;
|
|
219
|
-
case idl.IDLStringType.name: return idl.IDLStringType;
|
|
220
|
-
case idl.IDLAnyType.name: return idl.IDLAnyType;
|
|
221
|
-
case idl.IDLUndefinedType.name: return idl.IDLUndefinedType;
|
|
222
|
-
case idl.IDLUnknownType.name: return idl.IDLUnknownType;
|
|
223
|
-
case idl.IDLObjectType.name: return idl.IDLObjectType;
|
|
224
|
-
case idl.IDLThisType.name: return idl.IDLThisType;
|
|
225
|
-
case idl.IDLDate.name: return idl.IDLDate;
|
|
226
|
-
case idl.IDLBufferType.name: return idl.IDLBufferType;
|
|
227
|
-
case idl.IDLSerializerBuffer.name: return idl.IDLSerializerBuffer;
|
|
228
|
-
}
|
|
229
|
-
const combinedExtAttrs = ((_a = type.extAttrs) !== null && _a !== void 0 ? _a : []).concat(extAttrs !== null && extAttrs !== void 0 ? extAttrs : []);
|
|
230
|
-
let idlRefType;
|
|
231
|
-
if (this.genericsScopes.some(it => it.has(type.idlType))) {
|
|
232
|
-
idlRefType = idl.createTypeParameterReference(type.idlType);
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
const ref = idl.createReferenceType(type.idlType);
|
|
236
|
-
ref.typeArguments = this.extractTypeArguments(file, combinedExtAttrs, idl.IDLExtendedAttributes.TypeArguments);
|
|
237
|
-
idlRefType = ref;
|
|
238
|
-
}
|
|
239
|
-
idlRefType.fileName = file;
|
|
240
|
-
idlRefType.extendedAttributes = this.toExtendedAttributes(file, combinedExtAttrs);
|
|
241
|
-
return this.withInfo(type, idlRefType);
|
|
242
|
-
}
|
|
243
|
-
if (isSequenceTypeDescription(type) || isPromiseTypeDescription(type) || isRecordTypeDescription(type)) {
|
|
244
|
-
return this.withInfo(type, idl.createContainerType(type.generic, type.idlType.map(it => this.toIDLType(file, it, undefined))));
|
|
245
|
-
}
|
|
246
|
-
if (isUnspecifiedGenericTypeDescription(type)) {
|
|
247
|
-
return this.withInfo(type, idl.createUnspecifiedGenericType(type.generic, type.idlType.map(it => this.toIDLType(file, it, undefined))));
|
|
248
|
-
}
|
|
249
|
-
throw new Error(`unexpected type: ${toString(type)}`);
|
|
250
|
-
}
|
|
251
|
-
toIDLCallable(file, node) {
|
|
252
|
-
var _a;
|
|
253
|
-
if (!node.idlType) {
|
|
254
|
-
throw new Error(`method with no type ${toString(node)}`);
|
|
255
|
-
}
|
|
256
|
-
const generics = this.extractGenerics(node.extAttrs);
|
|
257
|
-
this.enterGenericScope(generics);
|
|
258
|
-
const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
|
|
259
|
-
if (idl.isReferenceType(returnType)) {
|
|
260
|
-
const returnTypeArgs = this.extractTypeArguments(file, node.extAttrs, idl.IDLExtendedAttributes.TypeArguments);
|
|
261
|
-
returnType.typeArguments = returnTypeArgs;
|
|
262
|
-
}
|
|
263
|
-
const result = this.withInfo(node, idl.createCallable((_a = node.name) !== null && _a !== void 0 ? _a : "", node.arguments.map(it => this.toIDLParameter(file, it)), returnType, {
|
|
264
|
-
isStatic: node.special === "static",
|
|
265
|
-
isAsync: node.async,
|
|
266
|
-
}, {
|
|
267
|
-
documentation: this.makeDocs(node),
|
|
268
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
269
|
-
}, generics));
|
|
270
|
-
this.genericsScopes.pop();
|
|
271
|
-
return result;
|
|
272
|
-
}
|
|
273
|
-
toIDLMethod(file, node, isFree = false) {
|
|
274
|
-
var _a;
|
|
275
|
-
if (!node.idlType) {
|
|
276
|
-
throw new Error(`method with no type ${toString(node)}`);
|
|
277
|
-
}
|
|
278
|
-
const generics = this.extractGenerics(node.extAttrs);
|
|
279
|
-
this.enterGenericScope(generics);
|
|
280
|
-
const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
|
|
281
|
-
const result = this.withInfo(node, idl.createMethod((_a = node.name) !== null && _a !== void 0 ? _a : "", node.arguments.map(it => this.toIDLParameter(file, it !== null && it !== void 0 ? it : new Map())), returnType, {
|
|
282
|
-
isStatic: node.special === "static",
|
|
283
|
-
isAsync: node.async,
|
|
284
|
-
isOptional: isOptional(node),
|
|
285
|
-
isFree
|
|
286
|
-
}, {
|
|
287
|
-
documentation: this.makeDocs(node),
|
|
288
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
289
|
-
}, generics));
|
|
290
|
-
this.genericsScopes.pop();
|
|
291
|
-
return result;
|
|
292
|
-
}
|
|
293
|
-
toIDLConstructor(file, node) {
|
|
294
|
-
return this.withInfo(node, idl.createConstructor(node.arguments.map(it => this.toIDLParameter(file, it)), undefined, {
|
|
295
|
-
documentation: this.makeDocs(node),
|
|
296
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
297
|
-
}));
|
|
298
|
-
}
|
|
299
|
-
toIDLParameter(file, node) {
|
|
300
|
-
return this.withInfo(node, idl.createParameter(node.name, this.toIDLType(file, node.idlType, node.extAttrs), node.optional, node.variadic, {
|
|
301
|
-
fileName: file,
|
|
302
|
-
}));
|
|
303
|
-
}
|
|
304
|
-
toIDLCallback(file, node) {
|
|
305
|
-
const generics = this.extractGenerics(node.extAttrs);
|
|
306
|
-
this.enterGenericScope(generics);
|
|
307
|
-
const result = idl.createCallback(node.name, node.arguments.map(it => this.toIDLParameter(file, it)), this.toIDLType(file, node.idlType, undefined), {
|
|
308
|
-
fileName: file,
|
|
309
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
310
|
-
documentation: this.makeDocs(node),
|
|
311
|
-
}, generics);
|
|
312
|
-
if (node.extAttrs.find(it => it.name === "Synthetic")) {
|
|
313
|
-
const fqName = this.currentPackage.concat(this.namespacePathNames).concat([node.name]).join('.');
|
|
314
|
-
addSyntheticType(fqName, result);
|
|
315
|
-
}
|
|
316
|
-
this.genericsScopes.pop();
|
|
317
|
-
return this.withInfo(node, result);
|
|
318
|
-
}
|
|
319
|
-
toIDLTypedef(file, node) {
|
|
320
|
-
const generics = this.extractGenerics(node.extAttrs);
|
|
321
|
-
this.enterGenericScope(generics);
|
|
322
|
-
const result = this.withInfo(node, idl.createTypedef(node.name, this.toIDLType(file, node.idlType, undefined, node.name), generics, {
|
|
323
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
324
|
-
documentation: this.makeDocs(node),
|
|
325
|
-
fileName: file,
|
|
326
|
-
}));
|
|
327
|
-
this.genericsScopes.pop();
|
|
328
|
-
return result;
|
|
329
|
-
}
|
|
330
|
-
toIDLConstant(file, node) {
|
|
331
|
-
return this.withInfo(node, idl.createConstant(node.name, this.toIDLType(file, node.idlType, undefined), this.constantValue(node)));
|
|
332
|
-
}
|
|
333
|
-
toIDLDictionary(file, node) {
|
|
334
|
-
const result = idl.createEnum(node.name, [], {
|
|
335
|
-
documentation: this.makeDocs(node),
|
|
336
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
337
|
-
fileName: file,
|
|
338
|
-
});
|
|
339
|
-
result.elements = node.members.map(it => this.toIDLEnumMember(file, it, result));
|
|
340
|
-
return this.withInfo(node, result);
|
|
341
|
-
}
|
|
342
|
-
toIDLNamespace(file, node) {
|
|
343
|
-
const namespace = idl.createNamespace(node.name, [], {
|
|
344
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
345
|
-
fileName: file
|
|
346
|
-
});
|
|
347
|
-
this.namespacePathNames.push(node.name);
|
|
348
|
-
namespace.members = node.members.map(it => this.toIDLNodeForward(file, it));
|
|
349
|
-
this.namespacePathNames.pop();
|
|
350
|
-
return this.withInfo(node, namespace);
|
|
351
|
-
}
|
|
352
|
-
toIDLVersion(file, node) {
|
|
353
|
-
return this.withInfo(node, idl.createVersion(node.value, {
|
|
354
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
355
|
-
fileName: file
|
|
356
|
-
}));
|
|
357
|
-
}
|
|
358
|
-
toIDLProperty(file, node) {
|
|
359
|
-
return this.withInfo(node, idl.createProperty(node.name, this.toIDLType(file, node.idlType, undefined), node.readonly, node.special === "static", isOptional(node), {
|
|
360
|
-
documentation: this.makeDocs(node),
|
|
361
|
-
fileName: file,
|
|
362
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs)
|
|
363
|
-
}));
|
|
364
|
-
}
|
|
365
|
-
toIDLEnumMember(file, node, parent) {
|
|
366
|
-
var _a, _b, _c;
|
|
367
|
-
let initializer = undefined;
|
|
368
|
-
if (((_a = node.default) === null || _a === void 0 ? void 0 : _a.type) == "string") {
|
|
369
|
-
initializer = this.unescapeString(node.default.value);
|
|
370
|
-
}
|
|
371
|
-
else if (((_b = node.default) === null || _b === void 0 ? void 0 : _b.type) == "number") {
|
|
372
|
-
initializer = +((_c = node.default) === null || _c === void 0 ? void 0 : _c.value);
|
|
373
|
-
}
|
|
374
|
-
else if (node.default == null) {
|
|
375
|
-
initializer = undefined;
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
throw new Error(`Not representable enum initializer: ${JSON.stringify(node.default)}. Found in ${file}`);
|
|
379
|
-
}
|
|
380
|
-
return this.withInfo(node, idl.createEnumMember(node.name, parent, this.toIDLType(file, node.idlType, undefined), initializer, {
|
|
381
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
382
|
-
}));
|
|
383
|
-
}
|
|
384
|
-
toExtendedAttributes(file, extAttrs) {
|
|
385
|
-
return extAttrs.map(it => {
|
|
386
|
-
return this.withInfo(it, {
|
|
387
|
-
name: it.name,
|
|
388
|
-
value: this.toExtendedAttributeValue(it),
|
|
389
|
-
typesValue: extendedAttributesWithTypesValue.includes(it.name)
|
|
390
|
-
? this.extractTypeArguments(file, extAttrs, it.name)
|
|
391
|
-
: undefined
|
|
392
|
-
});
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
toExtendedAttributeValue(attr) {
|
|
396
|
-
var _a, _b;
|
|
397
|
-
// TODO: be smarter about RHS.
|
|
398
|
-
if (((_a = attr.rhs) === null || _a === void 0 ? void 0 : _a.value) instanceof Array)
|
|
399
|
-
return attr.rhs.value.map(v => v.value).join(",");
|
|
400
|
-
if (typeof ((_b = attr.rhs) === null || _b === void 0 ? void 0 : _b.value) === 'string')
|
|
401
|
-
return this.unescapeString(attr.rhs.value);
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
toIDLEnum(file, node) {
|
|
405
|
-
const result = idl.createEnum(node.name, [], {
|
|
406
|
-
fileName: file,
|
|
407
|
-
documentation: this.makeDocs(node),
|
|
408
|
-
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
409
|
-
});
|
|
410
|
-
result.elements = node.values.map((it) => idl.createEnumMember(it.value, result, idl.IDLNumberType, undefined));
|
|
411
|
-
return this.withInfo(node, result);
|
|
412
|
-
}
|
|
413
|
-
///
|
|
414
|
-
isNamespace(node) {
|
|
415
|
-
return node.type === 'namespace';
|
|
416
|
-
}
|
|
417
|
-
isVersion(node) {
|
|
418
|
-
return node.type === 'version';
|
|
419
|
-
}
|
|
420
|
-
isPackage(node) {
|
|
421
|
-
return node.type === 'package';
|
|
422
|
-
}
|
|
423
|
-
isImport(node) {
|
|
424
|
-
return node.type === 'import';
|
|
425
|
-
}
|
|
426
|
-
isCallable(node) {
|
|
427
|
-
return node.extAttrs.some(it => it.name == idl.IDLExtendedAttributes.CallSignature);
|
|
30
|
+
export function toIdlType(fileName, content) {
|
|
31
|
+
const previousDiagnosticsCount = DiagnosticMessageGroup.allGroupsEntries.length;
|
|
32
|
+
try {
|
|
33
|
+
const idlType = new Parser(fileName, content).parseIDLType();
|
|
34
|
+
idlType.fileName = fileName;
|
|
35
|
+
return idlType;
|
|
428
36
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
let brackets = 0;
|
|
433
|
-
const result = [];
|
|
434
|
-
for (const letter of line) {
|
|
435
|
-
if (letter === ',' && brackets === 0) {
|
|
436
|
-
result.push(buffer);
|
|
437
|
-
buffer = '';
|
|
438
|
-
continue;
|
|
439
|
-
}
|
|
440
|
-
if (letter === '<') {
|
|
441
|
-
brackets += 1;
|
|
442
|
-
}
|
|
443
|
-
if (letter === '>') {
|
|
444
|
-
brackets -= 1;
|
|
445
|
-
}
|
|
446
|
-
buffer += letter;
|
|
447
|
-
}
|
|
448
|
-
if (buffer.length) {
|
|
449
|
-
result.push(buffer);
|
|
37
|
+
finally {
|
|
38
|
+
if (DiagnosticMessageGroup.allGroupsEntries.length != previousDiagnosticsCount) {
|
|
39
|
+
DiagnosticMessageGroup.allGroupsEntries.slice(previousDiagnosticsCount).map(it => outputDiagnosticMessageFormatted(it));
|
|
450
40
|
}
|
|
451
|
-
return result;
|
|
452
41
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
let value = this.toExtendedAttributeValue(attr);
|
|
459
|
-
return (_a = this.splitTypeArguments(value)) === null || _a === void 0 ? void 0 : _a.map(it => { var _a; return this.toIDLType(file, (_a = webidl2.parseType(it.replaceAll('\'', '"'), file)) !== null && _a !== void 0 ? _a : it); });
|
|
42
|
+
}
|
|
43
|
+
export function toIdlTypeList(fileName, content) {
|
|
44
|
+
const previousDiagnosticsCount = DiagnosticMessageGroup.allGroupsEntries.length;
|
|
45
|
+
try {
|
|
46
|
+
return new Parser(fileName, content).parseIDLTypeList();
|
|
460
47
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
return `"${node.value.value}"`;
|
|
465
|
-
case "number":
|
|
466
|
-
return node.value.value;
|
|
467
|
-
case "boolean":
|
|
468
|
-
return node.value.value.toString();
|
|
469
|
-
case "null":
|
|
470
|
-
return "null";
|
|
471
|
-
case "Infinity":
|
|
472
|
-
return "Infinity";
|
|
473
|
-
case "NaN":
|
|
474
|
-
return "NaN";
|
|
475
|
-
case "sequence":
|
|
476
|
-
return `[${node.value.value.join(',')}]`;
|
|
477
|
-
case "dictionary":
|
|
478
|
-
return `new Map()`;
|
|
479
|
-
default:
|
|
480
|
-
return "undefined";
|
|
48
|
+
finally {
|
|
49
|
+
if (DiagnosticMessageGroup.allGroupsEntries.length != previousDiagnosticsCount) {
|
|
50
|
+
DiagnosticMessageGroup.allGroupsEntries.slice(previousDiagnosticsCount).map(it => outputDiagnosticMessageFormatted(it));
|
|
481
51
|
}
|
|
482
52
|
}
|
|
483
|
-
unescapeString(value) {
|
|
484
|
-
if (!value.length || value[0] !== '"')
|
|
485
|
-
return value;
|
|
486
|
-
value = value.slice(1, -1);
|
|
487
|
-
value = value.replace(/\\((['"\\bfnrtv])|([0-7]{1-3})|x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/g, (_, all, c, oct, h2, u4) => {
|
|
488
|
-
if (c !== undefined) {
|
|
489
|
-
switch (c) {
|
|
490
|
-
case "'": return "'";
|
|
491
|
-
case '"': return '"';
|
|
492
|
-
case "\\": return "\\";
|
|
493
|
-
case "b": return "\b";
|
|
494
|
-
case "f": return "\f";
|
|
495
|
-
case "n": return "\n";
|
|
496
|
-
case "r": return "\r";
|
|
497
|
-
case "t": return "\t";
|
|
498
|
-
case "v": return "\v";
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
else if (oct !== undefined) {
|
|
502
|
-
return String.fromCharCode(parseInt(oct, 8));
|
|
503
|
-
}
|
|
504
|
-
else if (h2 !== undefined) {
|
|
505
|
-
return String.fromCharCode(parseInt(h2, 16));
|
|
506
|
-
}
|
|
507
|
-
else if (u4 !== undefined) {
|
|
508
|
-
return String.fromCharCode(parseInt(u4, 16));
|
|
509
|
-
}
|
|
510
|
-
throw new Error(`unknown escape sequence: ${_}`);
|
|
511
|
-
});
|
|
512
|
-
return value;
|
|
513
|
-
}
|
|
514
|
-
makeDocs(node) {
|
|
515
|
-
let docs = undefined;
|
|
516
|
-
node.extAttrs.forEach(it => {
|
|
517
|
-
var _a;
|
|
518
|
-
if (it.name == "Documentation")
|
|
519
|
-
docs = (_a = it.rhs) === null || _a === void 0 ? void 0 : _a.value;
|
|
520
|
-
});
|
|
521
|
-
return docs;
|
|
522
|
-
}
|
|
523
|
-
findExtendedAttribute(extAttrs, name) {
|
|
524
|
-
const attr = extAttrs.find(it => it.name === name);
|
|
525
|
-
return attr ? this.toExtendedAttributeValue(attr) : undefined;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
export function toIdlType(fileName, content) {
|
|
529
|
-
const lexicalInfo = new Map();
|
|
530
|
-
const deserializer = new IDLDeserializer(lexicalInfo);
|
|
531
|
-
return deserializer.toIDLType(fileName, webidl2.parseType(content, fileName));
|
|
532
53
|
}
|
|
533
54
|
const DifferenceFound = new DiagnosticMessageGroup("error", "DifferenceFound", "Difference found");
|
|
534
55
|
const noCompare = new Set(["parent", "fileName", "nodeLocation", "nameLocation", "valueLocation", "typesValue", "text"]);
|
|
@@ -607,6 +128,11 @@ function compareDeep(oldData, newData, paths) {
|
|
|
607
128
|
}
|
|
608
129
|
return [];
|
|
609
130
|
}
|
|
131
|
+
export function compareNodes(a, b) {
|
|
132
|
+
const paths = new Set();
|
|
133
|
+
compareDeep(a, b, paths);
|
|
134
|
+
return paths.size === 0;
|
|
135
|
+
}
|
|
610
136
|
export function compareParsingResults(oldFile, newFile) {
|
|
611
137
|
const paths = new Set();
|
|
612
138
|
compareDeep(oldFile, newFile, paths);
|
|
@@ -618,32 +144,16 @@ export function compareParsingResults(oldFile, newFile) {
|
|
|
618
144
|
export function parseIDLFile(fileName, content, quiet) {
|
|
619
145
|
const previousDiagnosticsCount = DiagnosticMessageGroup.allGroupsEntries.length;
|
|
620
146
|
try {
|
|
621
|
-
|
|
622
|
-
// Temporarily is set to use old parser by default
|
|
623
|
-
// Old parser has a bug, it ignores extended attributes on return types, but some pipelines depend on that behavior
|
|
624
|
-
// So pipelines and old parser must be fixed before permanent switch to a new parser
|
|
625
|
-
const mode = process.env.IDLPARSE;
|
|
626
|
-
if (mode === "compare" || mode === "old") {
|
|
627
|
-
newFile = parseIDLFileOld(fileName, content);
|
|
628
|
-
if (mode === "old") {
|
|
629
|
-
return newFile;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
const file = parseIDLFileNew(fileName, content, mode !== "compare");
|
|
633
|
-
if (mode === "compare") {
|
|
634
|
-
compareParsingResults(file, newFile);
|
|
635
|
-
return newFile;
|
|
636
|
-
}
|
|
637
|
-
return file;
|
|
147
|
+
return parseIDLFileNew(fileName, content);
|
|
638
148
|
}
|
|
639
149
|
finally {
|
|
640
150
|
if (!quiet && DiagnosticMessageGroup.allGroupsEntries.length != previousDiagnosticsCount) {
|
|
641
|
-
DiagnosticMessageGroup.allGroupsEntries.slice(previousDiagnosticsCount).
|
|
151
|
+
DiagnosticMessageGroup.allGroupsEntries.slice(previousDiagnosticsCount).forEach(it => outputDiagnosticMessageFormatted(it));
|
|
642
152
|
}
|
|
643
153
|
}
|
|
644
154
|
}
|
|
645
|
-
export function parseIDLFileNew(fileName, content
|
|
646
|
-
let file = new Parser(fileName, content).
|
|
155
|
+
export function parseIDLFileNew(fileName, content) {
|
|
156
|
+
let file = new Parser(fileName, content).parseIDLFile();
|
|
647
157
|
const ancestors = [];
|
|
648
158
|
const namespaces = [];
|
|
649
159
|
// Mimic old parser and deserialize.ts behavior:
|
|
@@ -651,15 +161,10 @@ export function parseIDLFileNew(fileName, content, registerSynthetics) {
|
|
|
651
161
|
// 2. Add `parent`.
|
|
652
162
|
// 3. Possibly register node with `addSyntheticType` if "Synthetic" is in attributes
|
|
653
163
|
idl.forEachChild(file, (node) => {
|
|
654
|
-
var _a;
|
|
655
164
|
if (idl.isPrimitiveType(node)) {
|
|
656
165
|
return;
|
|
657
166
|
}
|
|
658
167
|
node.fileName = fileName;
|
|
659
|
-
if (registerSynthetics && idl.isEntry(node) && ((_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.some(it => it.name === "Synthetic"))) {
|
|
660
|
-
const fqName = file.packageClause.concat(namespaces).concat([node.name]).join('.');
|
|
661
|
-
addSyntheticType(fqName, node);
|
|
662
|
-
}
|
|
663
168
|
if (ancestors.length) {
|
|
664
169
|
node.parent = ancestors[ancestors.length - 1];
|
|
665
170
|
}
|
|
@@ -678,121 +183,4 @@ export function parseIDLFileNew(fileName, content, registerSynthetics) {
|
|
|
678
183
|
});
|
|
679
184
|
return file;
|
|
680
185
|
}
|
|
681
|
-
function parseIDLFileOld(fileName, content) {
|
|
682
|
-
var _a, _b, _c;
|
|
683
|
-
const lexicalInfo = new Map();
|
|
684
|
-
const deserializer = new IDLDeserializer(lexicalInfo);
|
|
685
|
-
if (undefined === content) {
|
|
686
|
-
try {
|
|
687
|
-
content = fs.readFileSync(fileName).toString();
|
|
688
|
-
}
|
|
689
|
-
catch (e) {
|
|
690
|
-
content = "";
|
|
691
|
-
throw new FatalParserException([LoadingFatal.reportDiagnosticMessage([{ documentPath: fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "")]);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
let lines = (_b = content.match(/[^\r\n]*(\n|\r\n)?/g)) !== null && _b !== void 0 ? _b : [];
|
|
695
|
-
const offsets = prepareOffsets(lines);
|
|
696
|
-
lines = lines.map((s) => s.replace(/(\n|\r\n)$/, ""));
|
|
697
|
-
const parsed = { fileName, lines, offsets, lexicalInfo };
|
|
698
|
-
let packageClause = [];
|
|
699
|
-
let rawParsingResults;
|
|
700
|
-
try {
|
|
701
|
-
rawParsingResults = webidl2.parse(content);
|
|
702
|
-
}
|
|
703
|
-
catch (e) {
|
|
704
|
-
if (e.name == "WebIDLParseError") {
|
|
705
|
-
let tokens = e.tokens;
|
|
706
|
-
let range = tokens.length > 0 ? rangeForToken(offsets, tokens[0]) : undefined;
|
|
707
|
-
throw new FatalParserException([ParsingFatal.reportDiagnosticMessage([{ documentPath: fileName, range, lines }], e.bareMessage)]);
|
|
708
|
-
}
|
|
709
|
-
throw new FatalParserException([InternalFatal.reportDiagnosticMessage([{ documentPath: fileName, lines }], (_c = e.message) !== null && _c !== void 0 ? _c : "")]);
|
|
710
|
-
}
|
|
711
|
-
const entries = rawParsingResults
|
|
712
|
-
.filter(it => {
|
|
713
|
-
if (!it.type)
|
|
714
|
-
return false;
|
|
715
|
-
if (deserializer.isPackage(it)) {
|
|
716
|
-
packageClause = it.clause.split(".");
|
|
717
|
-
deserializer.setPackage(packageClause);
|
|
718
|
-
return false;
|
|
719
|
-
}
|
|
720
|
-
return true;
|
|
721
|
-
})
|
|
722
|
-
.map(it => deserializer.toIDLNode(fileName, it));
|
|
723
|
-
let file = idl.createFile(entries, fileName, packageClause);
|
|
724
|
-
file.text = content;
|
|
725
|
-
file = idl.linkParentBack(file);
|
|
726
|
-
idl.forEachChild(file, (node) => {
|
|
727
|
-
node.nodeLocation = locationForNode(parsed, node);
|
|
728
|
-
const nameLocation = locationForNode(parsed, node, "name");
|
|
729
|
-
if (nameLocation.range) {
|
|
730
|
-
node.nameLocation = nameLocation;
|
|
731
|
-
}
|
|
732
|
-
});
|
|
733
|
-
return file;
|
|
734
|
-
}
|
|
735
|
-
function prepareOffsets(lines) {
|
|
736
|
-
let offsets = [];
|
|
737
|
-
let offset = 0;
|
|
738
|
-
for (let line of lines) {
|
|
739
|
-
let plus = line.length;
|
|
740
|
-
offsets.push(offset);
|
|
741
|
-
offset += plus;
|
|
742
|
-
}
|
|
743
|
-
return offsets;
|
|
744
|
-
}
|
|
745
|
-
function locationForNode(parsed, node, component) {
|
|
746
|
-
if (node.kind == idl.IDLKind.File) {
|
|
747
|
-
return { documentPath: parsed.fileName, lines: parsed.lines };
|
|
748
|
-
}
|
|
749
|
-
return { documentPath: parsed.fileName, range: rangeForNode(parsed, node, component), lines: parsed.lines };
|
|
750
|
-
}
|
|
751
|
-
function rangeForNode(parsed, node, component) {
|
|
752
|
-
var _a;
|
|
753
|
-
let info = parsed.lexicalInfo.get(node);
|
|
754
|
-
if (info == null) {
|
|
755
|
-
// Proper solution will require fixes with inheritance tokens in Idlize/core and custom webidl2.js
|
|
756
|
-
// So now we are extracting from what we have
|
|
757
|
-
if (node.parent) {
|
|
758
|
-
return (_a = rangeForNode(parsed, node.parent, "inheritance")) !== null && _a !== void 0 ? _a : rangeForNode(parsed, node.parent);
|
|
759
|
-
}
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
let range;
|
|
763
|
-
for (let k of Object.keys(info)) {
|
|
764
|
-
if (component && k != component) {
|
|
765
|
-
continue;
|
|
766
|
-
}
|
|
767
|
-
let named = info[k];
|
|
768
|
-
if (named == null) {
|
|
769
|
-
continue;
|
|
770
|
-
}
|
|
771
|
-
if (named.value == null) {
|
|
772
|
-
if (k == "inheritance" && Array.isArray(named)) {
|
|
773
|
-
for (let inh of named) {
|
|
774
|
-
if (inh.inheritance == null) {
|
|
775
|
-
continue;
|
|
776
|
-
}
|
|
777
|
-
let newRange = rangeForToken(parsed.offsets, inh.inheritance);
|
|
778
|
-
range = range ? commonRange(range, newRange) : newRange;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
continue;
|
|
782
|
-
}
|
|
783
|
-
let newRange = rangeForToken(parsed.offsets, named);
|
|
784
|
-
range = range ? commonRange(range, newRange) : newRange;
|
|
785
|
-
}
|
|
786
|
-
return range;
|
|
787
|
-
}
|
|
788
|
-
function rangeForToken(offsets, token) {
|
|
789
|
-
let dif = token.value.length - 1;
|
|
790
|
-
if (dif < 0) {
|
|
791
|
-
dif = 0;
|
|
792
|
-
}
|
|
793
|
-
let endline = token.line + (token.value.match(/\n/g) || []).length;
|
|
794
|
-
let character = token.position - offsets[token.line - 1] + 1;
|
|
795
|
-
let endcharacter = token.position + dif - offsets[endline - 1] + 1;
|
|
796
|
-
return { start: { line: token.line, character: character }, end: { line: endline, character: endcharacter } };
|
|
797
|
-
}
|
|
798
186
|
//# sourceMappingURL=deserialize.js.map
|