Skip to content

Commit 961216a

Browse files
committed
Updated compiler
1 parent 5861c12 commit 961216a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

specification/compiler/model/metamodel.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export abstract class BaseType {
152152
variantName?: string
153153
}
154154

155-
export type Variants = ExternalTag | InternalTag
155+
export type Variants = ExternalTag | InternalTag | Container
156156

157157
export class ExternalTag {
158158
kind: 'external_tag'
@@ -163,6 +163,10 @@ export class InternalTag {
163163
tag: string // Name of the property that holds the variant tag
164164
}
165165

166+
export class Container {
167+
kind: 'container'
168+
}
169+
166170
/**
167171
* Inherits clause (aka extends or implements) for an interface or request
168172
*/
@@ -275,7 +279,7 @@ export class TypeAlias extends BaseType {
275279
/** generic parameters: either concrete types or open parameters from the enclosing type */
276280
generics?: ValueOf[]
277281
/** Identify typed_key unions (external) and variant inventories (internal) */
278-
variants?: Variants
282+
variants?: InternalTag | ExternalTag
279283
}
280284

281285
// ------------------------------------------------------------------------------------------------

specification/compiler/model/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ export function modelTypeAlias (declaration: TypeAliasDeclaration): model.TypeAl
381381
if (alias.kind === 'union_of') {
382382
const variants = parseVariantsTag(declaration.getJsDocs())
383383
if (variants != null) {
384+
assert(
385+
variants.kind === 'internal_tag' || variants.kind === 'external_tag',
386+
'Type Aliases can only have internal or external variants'
387+
)
384388
typeAlias.variants = variants
385389
}
386390
}
@@ -668,6 +672,10 @@ export function parseVariantsTag (jsDoc: JSDoc[]): model.Variants | undefined {
668672
return { kind: 'external_tag' }
669673
}
670674

675+
if (type === 'container') {
676+
return { kind: 'container' }
677+
}
678+
671679
assert(type === 'internal', `Bad variant type: ${type}`)
672680
assert(typeof value === 'string', 'Internal variant requires a tag definition')
673681
const [tag, property] = value.split('=')

0 commit comments

Comments
 (0)