Skip to content

Commit 60c9590

Browse files
committed
Use interfaces to schemas appear in output
Changes CustomElementDeclaration and CustomElementMixinDeclaration from intersection types to interfaces.
1 parent b606a66 commit 60c9590

File tree

2 files changed

+110
-56
lines changed

2 files changed

+110
-56
lines changed

schema.d.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ export interface SourceReference {
208208
* tagName, and another `Module` should contain the
209209
* `CustomElementExport`.
210210
*/
211-
export type CustomElementDeclaration = ClassDeclaration & CustomElement;
211+
// Note: this needs to be an interface to be included in the generated JSON
212+
// Schema output.
213+
export interface CustomElementDeclaration extends ClassDeclaration, CustomElement {}
212214

213215
/**
214216
* The additional fields that a custom element adds to classes and mixins.
@@ -249,18 +251,8 @@ export interface CustomElement extends ClassLike {
249251
* custom element class
250252
*/
251253
customElement: true;
252-
253-
members?: Array<CustomElementMember>;
254-
255-
/**
256-
* Whether the custom element is deprecated.
257-
* If the value is a string, it's the reason for the deprecation.
258-
*/
259-
deprecated?: boolean|string;
260254
}
261255

262-
export type CustomElementMember = CustomElementField | ClassMethod;
263-
264256
export interface Attribute {
265257
name: string;
266258

@@ -648,7 +640,9 @@ export interface MixinDeclaration extends ClassLike, FunctionLike {
648640
/**
649641
* A class mixin that also adds custom element related properties.
650642
*/
651-
export type CustomElementMixinDeclaration = MixinDeclaration & CustomElement;
643+
// Note: this needs to be an interface to be included in the generated JSON
644+
// Schema output.
645+
export interface CustomElementMixinDeclaration extends MixinDeclaration, CustomElement {}
652646

653647
export interface VariableDeclaration extends PropertyLike {
654648
kind: 'variable';

schema.json

Lines changed: 104 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@
269269
],
270270
"type": "object"
271271
},
272-
"CustomElement": {
273-
"description": "The additional fields that a custom element adds to classes and mixins.",
272+
"CustomElementDeclaration": {
273+
"description": "A description of a custom element class.\n\nCustom elements are JavaScript classes, so this extends from\n`ClassDeclaration` and adds custom-element-specific features like\nattributes, events, and slots.\n\nNote that `tagName` in this interface is optional. Tag names are not\nneccessarily part of a custom element class, but belong to the definition\n(often called the \"registration\") or the `customElements.define()` call.\n\nBecause classes and tag names can only be registered once, there's a\none-to-one relationship between classes and tag names. For ease of use,\nwe allow the tag name here.\n\nSome packages define and register custom elements in separate modules. In\nthese cases one `Module` should contain the `CustomElement` without a\ntagName, and another `Module` should contain the\n`CustomElementExport`.",
274274
"properties": {
275275
"attributes": {
276276
"description": "The attributes that this element is known to understand.",
@@ -305,7 +305,7 @@
305305
"type": "array"
306306
},
307307
"deprecated": {
308-
"description": "Whether the custom element is deprecated.\nIf the value is a string, it's the reason for the deprecation.",
308+
"description": "Whether the class or mixin is deprecated.\nIf the value is a string, it's the reason for the deprecation.",
309309
"type": [
310310
"string",
311311
"boolean"
@@ -322,11 +322,17 @@
322322
},
323323
"type": "array"
324324
},
325+
"kind": {
326+
"enum": [
327+
"class"
328+
],
329+
"type": "string"
330+
},
325331
"members": {
326332
"items": {
327333
"anyOf": [
328334
{
329-
"$ref": "#/definitions/CustomElementField"
335+
"$ref": "#/definitions/ClassField"
330336
},
331337
{
332338
"$ref": "#/definitions/ClassMethod"
@@ -370,6 +376,7 @@
370376
},
371377
"required": [
372378
"customElement",
379+
"kind",
373380
"name"
374381
],
375382
"type": "object"
@@ -406,61 +413,130 @@
406413
],
407414
"type": "object"
408415
},
409-
"CustomElementField": {
410-
"description": "Additional metadata for fields on custom elements.",
416+
"CustomElementMixinDeclaration": {
417+
"description": "A class mixin that also adds custom element related properties.",
411418
"properties": {
412-
"attribute": {
413-
"description": "The corresponding attribute name if there is one.",
414-
"type": "string"
419+
"attributes": {
420+
"description": "The attributes that this element is known to understand.",
421+
"items": {
422+
"$ref": "#/definitions/Attribute"
423+
},
424+
"type": "array"
415425
},
416-
"default": {
417-
"type": "string"
426+
"cssParts": {
427+
"items": {
428+
"$ref": "#/definitions/CssPart"
429+
},
430+
"type": "array"
431+
},
432+
"cssProperties": {
433+
"items": {
434+
"$ref": "#/definitions/CssCustomProperty"
435+
},
436+
"type": "array"
437+
},
438+
"customElement": {
439+
"description": "Distinguishes a regular JavaScript class from a\ncustom element class",
440+
"enum": [
441+
true
442+
],
443+
"type": "boolean"
444+
},
445+
"demos": {
446+
"items": {
447+
"$ref": "#/definitions/Demo"
448+
},
449+
"type": "array"
418450
},
419451
"deprecated": {
420-
"description": "Whether the property is deprecated.\nIf the value is a string, it's the reason for the deprecation.",
452+
"description": "Whether the class or mixin is deprecated.\nIf the value is a string, it's the reason for the deprecation.",
421453
"type": [
422454
"string",
423455
"boolean"
424456
]
425457
},
426458
"description": {
427-
"description": "A markdown description of the field.",
459+
"description": "A markdown description of the class.",
428460
"type": "string"
429461
},
430-
"inheritedFrom": {
431-
"$ref": "#/definitions/Reference"
462+
"events": {
463+
"description": "The events that this element fires.",
464+
"items": {
465+
"$ref": "#/definitions/Event"
466+
},
467+
"type": "array"
432468
},
433469
"kind": {
434470
"enum": [
435-
"field"
471+
"mixin"
436472
],
437473
"type": "string"
438474
},
475+
"members": {
476+
"items": {
477+
"anyOf": [
478+
{
479+
"$ref": "#/definitions/ClassField"
480+
},
481+
{
482+
"$ref": "#/definitions/ClassMethod"
483+
}
484+
]
485+
},
486+
"type": "array"
487+
},
488+
"mixins": {
489+
"description": "Any class mixins applied in the extends clause of this class.\n\nIf mixins are applied in the class definition, then the true superclass\nof this class is the result of applying mixins in order to the superclass.\n\nMixins must be listed in order of their application to the superclass or\nprevious mixin application. This means that the innermost mixin is listed\nfirst. This may read backwards from the common order in JavaScript, but\nmatches the order of language used to describe mixin application, like\n\"S with A, B\".",
490+
"items": {
491+
"$ref": "#/definitions/Reference"
492+
},
493+
"type": "array"
494+
},
439495
"name": {
440496
"type": "string"
441497
},
442-
"privacy": {
443-
"$ref": "#/definitions/Privacy"
498+
"parameters": {
499+
"items": {
500+
"$ref": "#/definitions/Parameter"
501+
},
502+
"type": "array"
444503
},
445-
"reflects": {
446-
"description": "If the property reflects to an attribute.\n\nIf this is true, `attribute` must be defined.",
447-
"type": "boolean"
504+
"return": {
505+
"properties": {
506+
"description": {
507+
"type": "string"
508+
},
509+
"type": {
510+
"$ref": "#/definitions/Type"
511+
}
512+
},
513+
"type": "object"
514+
},
515+
"slots": {
516+
"description": "The shadow dom content slots that this element accepts.",
517+
"items": {
518+
"$ref": "#/definitions/Slot"
519+
},
520+
"type": "array"
448521
},
449522
"source": {
450523
"$ref": "#/definitions/SourceReference"
451524
},
452-
"static": {
453-
"type": "boolean"
454-
},
455525
"summary": {
456526
"description": "A markdown summary suitable for display in a listing.",
457527
"type": "string"
458528
},
459-
"type": {
460-
"$ref": "#/definitions/Type"
529+
"superclass": {
530+
"$ref": "#/definitions/Reference",
531+
"description": "The superclass of this class.\n\nIf this class is defined with mixin\napplications, the prototype chain includes the mixin applications\nand the true superclass is computed from them."
532+
},
533+
"tagName": {
534+
"description": "An optional tag name that should be specified if this is a\nself-registering element.\n\nSelf-registering elements must also include a CustomElementExport\nin the module's exports.",
535+
"type": "string"
461536
}
462537
},
463538
"required": [
539+
"customElement",
464540
"kind",
465541
"name"
466542
],
@@ -615,26 +691,10 @@
615691
"$ref": "#/definitions/VariableDeclaration"
616692
},
617693
{
618-
"allOf": [
619-
{
620-
"$ref": "#/definitions/ClassDeclaration"
621-
},
622-
{
623-
"$ref": "#/definitions/CustomElement"
624-
}
625-
],
626-
"description": "A description of a custom element class.\n\nCustom elements are JavaScript classes, so this extends from\n`ClassDeclaration` and adds custom-element-specific features like\nattributes, events, and slots.\n\nNote that `tagName` in this interface is optional. Tag names are not\nneccessarily part of a custom element class, but belong to the definition\n(often called the \"registration\") or the `customElements.define()` call.\n\nBecause classes and tag names can only be registered once, there's a\none-to-one relationship between classes and tag names. For ease of use,\nwe allow the tag name here.\n\nSome packages define and register custom elements in separate modules. In\nthese cases one `Module` should contain the `CustomElement` without a\ntagName, and another `Module` should contain the\n`CustomElementExport`."
694+
"$ref": "#/definitions/CustomElementDeclaration"
627695
},
628696
{
629-
"allOf": [
630-
{
631-
"$ref": "#/definitions/MixinDeclaration"
632-
},
633-
{
634-
"$ref": "#/definitions/CustomElement"
635-
}
636-
],
637-
"description": "A class mixin that also adds custom element related properties."
697+
"$ref": "#/definitions/CustomElementMixinDeclaration"
638698
}
639699
]
640700
},

0 commit comments

Comments
 (0)