Skip to content

Commit 94d22b9

Browse files
committed
Refactor merge function to support optional parameter and update merge calls in emitDom for shallow merging
1 parent bff888b commit 94d22b9

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/build.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async function emitDom() {
150150
target.comment = descObject.__comment;
151151
}
152152
}
153-
idl = merge(idl, descriptions);
153+
idl = merge(idl, descriptions, {optional:true});
154154

155155
return idl;
156156
}
@@ -179,7 +179,7 @@ async function emitDom() {
179179
};
180180

181181
for (const w of widlStandardTypes) {
182-
webidl = merge(webidl, w.browser, true);
182+
webidl = merge(webidl, w.browser, {shallow: true});
183183
}
184184
for (const w of widlStandardTypes) {
185185
for (const partial of w.partialInterfaces) {
@@ -189,32 +189,32 @@ async function emitDom() {
189189
webidl.mixins!.mixin[partial.name];
190190
if (base) {
191191
if (base.exposed) resolveExposure(partial, base.exposed);
192-
merge(base.constants, partial.constants, true);
193-
merge(base.methods, partial.methods, true);
194-
merge(base.properties, partial.properties, true);
192+
merge(base.constants, partial.constants, {shallow: true});
193+
merge(base.methods, partial.methods, {shallow: true});
194+
merge(base.properties, partial.properties, {shallow: true});
195195
}
196196
}
197197
for (const partial of w.partialMixins) {
198198
const base = webidl.mixins!.mixin[partial.name];
199199
if (base) {
200200
if (base.exposed) resolveExposure(partial, base.exposed);
201-
merge(base.constants, partial.constants, true);
202-
merge(base.methods, partial.methods, true);
203-
merge(base.properties, partial.properties, true);
201+
merge(base.constants, partial.constants, {shallow: true});
202+
merge(base.methods, partial.methods, {shallow: true});
203+
merge(base.properties, partial.properties, {shallow: true});
204204
}
205205
}
206206
for (const partial of w.partialDictionaries) {
207207
const base = webidl.dictionaries!.dictionary[partial.name];
208208
if (base) {
209-
merge(base.members, partial.members, true);
209+
merge(base.members, partial.members, {shallow: true});
210210
}
211211
}
212212
for (const partial of w.partialNamespaces) {
213213
const base = webidl.namespaces?.find((n) => n.name === partial.name);
214214
if (base) {
215215
if (base.exposed) resolveExposure(partial, base.exposed);
216-
merge(base.methods, partial.methods, true);
217-
merge(base.properties, partial.properties, true);
216+
merge(base.methods, partial.methods, {shallow: true});
217+
merge(base.properties, partial.properties, {shallow: true});
218218
}
219219
}
220220
for (const include of w.includes) {

src/build/helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function exposesTo(o: { exposed?: string }, target: string[]): boolean {
118118
return o.exposed.split(" ").some((e) => target.includes(e));
119119
}
120120

121-
export function merge<T>(target: T, src: T, shallow?: boolean): T {
121+
export function merge<T>(target: T, src: T, { shallow = false, optional = false }: { shallow?: boolean, optional?: boolean } = { }): T {
122122
if (typeof target !== "object" || typeof src !== "object") {
123123
return src;
124124
}
@@ -145,10 +145,10 @@ export function merge<T>(target: T, src: T, shallow?: boolean): T {
145145
`Redundant merge value ${targetProp} in ${JSON.stringify(src)}`,
146146
);
147147
}
148-
target[k] = merge(targetProp, srcProp, shallow);
148+
target[k] = merge(targetProp, srcProp, { shallow, optional });
149149
}
150150
}
151-
} else {
151+
} else if (!optional || typeof src[k] !== "object") {
152152
target[k] = src[k];
153153
}
154154
}

0 commit comments

Comments
 (0)