Skip to content

Commit 17bf498

Browse files
authored
fix(jsii-reflect): statically guarantee JsiiFeature subset (#4956)
When new a tool is using `jsii-reflect` to read a jsii assembly, it must declare what JSII features it supports. If the assembly uses new features that the tool doesn't support yet, the load will fail. However, `jsii-reflect` *itself* must also support those features, so the set of features that the tool declares must be a subset of the set of features that `jsii-reflect` itself supports. This used to be checked dynamically, but that is easy to get wrong. We can lift this information into the TypeScript type system, so that it becomes a type error to call `jsii-reflect` with features that it doesn't know about yet. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
1 parent 4fa0a4b commit 17bf498

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/jsii-reflect/lib/type-system.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export const JSII_REFLECT_SUPPORTED_ASSEMBLY_FEATURES: JsiiFeature[] = [
2626
'class-covariant-overrides',
2727
];
2828

29+
/**
30+
* All supported features as a type
31+
*/
32+
export type JsiiReflectSupportedAssemblyFeatures =
33+
(typeof JSII_REFLECT_SUPPORTED_ASSEMBLY_FEATURES)[number];
34+
2935
export class TypeSystem {
3036
/**
3137
* The "root" assemblies (ones that loaded explicitly via a "load" call).
@@ -368,7 +374,7 @@ export class TypeSystem {
368374
private loadAssembly(
369375
file: string,
370376
validate = true,
371-
supportedFeatures?: JsiiFeature[],
377+
supportedFeatures?: JsiiReflectSupportedAssemblyFeatures[],
372378
) {
373379
validateFeatureSubset(supportedFeatures);
374380
const contents = loadAssemblyFromFile(file, validate, supportedFeatures);

0 commit comments

Comments
 (0)