1
1
import { validationError } from "../error.js" ;
2
2
3
+ /**
4
+ * @param {import("../validator.js").Definitions } defs
5
+ * @param {import("../productions/container.js").Container } i
6
+ */
3
7
export function * checkInterfaceMemberDuplication ( defs , i ) {
4
- const opNames = new Set ( getOperations ( i ) . map ( ( op ) => op . name ) ) ;
8
+ const opNames = groupOperationNames ( i ) ;
5
9
const partials = defs . partials . get ( i . name ) || [ ] ;
6
10
const mixins = defs . mixinMap . get ( i . name ) || [ ] ;
7
11
for ( const ext of [ ...partials , ...mixins ] ) {
8
12
const additions = getOperations ( ext ) ;
9
- yield * forEachExtension ( additions , opNames , ext , i ) ;
10
- for ( const addition of additions ) {
11
- opNames . add ( addition . name ) ;
12
- }
13
+ const statics = additions . filter ( ( a ) => a . special === "static" ) ;
14
+ const nonstatics = additions . filter ( ( a ) => a . special !== "static" ) ;
15
+ yield * checkAdditions ( statics , opNames . statics , ext , i ) ;
16
+ yield * checkAdditions ( nonstatics , opNames . nonstatics , ext , i ) ;
17
+ statics . forEach ( ( op ) => opNames . statics . add ( op . name ) ) ;
18
+ nonstatics . forEach ( ( op ) => opNames . nonstatics . add ( op . name ) ) ;
13
19
}
14
20
15
- function * forEachExtension ( additions , existings , ext , base ) {
21
+ /**
22
+ * @param {import("../productions/operation.js").Operation[] } additions
23
+ * @param {Set<string> } existings
24
+ * @param {import("../productions/container.js").Container } ext
25
+ * @param {import("../productions/container.js").Container } base
26
+ */
27
+ function * checkAdditions ( additions , existings , ext , base ) {
16
28
for ( const addition of additions ) {
17
29
const { name } = addition ;
18
30
if ( name && existings . has ( name ) ) {
19
- const message = `The operation "${ name } " has already been defined for the base interface "${ base . name } " either in itself or in a mixin` ;
31
+ const isStatic = addition . special === "static" ? "static " : "" ;
32
+ const message = `The ${ isStatic } operation "${ name } " has already been defined for the base interface "${ base . name } " either in itself or in a mixin` ;
20
33
yield validationError (
21
34
addition . tokens . name ,
22
35
ext ,
@@ -27,7 +40,26 @@ export function* checkInterfaceMemberDuplication(defs, i) {
27
40
}
28
41
}
29
42
43
+ /**
44
+ * @param {import("../productions/container.js").Container } i
45
+ * @returns {import("../productions/operation.js").Operation[] }
46
+ */
30
47
function getOperations ( i ) {
31
48
return i . members . filter ( ( { type } ) => type === "operation" ) ;
32
49
}
50
+
51
+ /**
52
+ * @param {import("../productions/container.js").Container } i
53
+ */
54
+ function groupOperationNames ( i ) {
55
+ const ops = getOperations ( i ) ;
56
+ return {
57
+ statics : new Set (
58
+ ops . filter ( ( op ) => op . special === "static" ) . map ( ( op ) => op . name )
59
+ ) ,
60
+ nonstatics : new Set (
61
+ ops . filter ( ( op ) => op . special !== "static" ) . map ( ( op ) => op . name )
62
+ ) ,
63
+ } ;
64
+ }
33
65
}
0 commit comments