winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.78k stars 189 forks source link

Support implicit `scope` parameter for imported JSII static methods and `in scope` explicit scoping for all static methods #6067

Open yoav-steinberg opened 3 months ago

yoav-steinberg commented 3 months ago

Use Case

When a JSII static methods is used to generate constructs (a factory) it usually accepts an scope as it's first argument. The scope is then used as the target scope for instances generated inside the static method. For example the CDK's [Bucket.fromBucketName](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html#static-fromwbrbucketwbrnamescope-id-bucketname) receives a scope as it's first argument.

Since wing supports passing the scope argument implicitly to static methods we can detect this and enable calling these imported methods with the implicit scope or using the wing in keyword to override the implicit scope:

// use implicit scope for imported JSII static methods
cdk.Bucket.fromBucketName("extern_bucket", "some_bucket");
// or use explicit scope syntax
cdk.Bucket.fromBucketName("extern_bucket", "some_bucket") in some_scope;

Note that supporting this requires adding the in explicit scoping specifier to all static methods in wing (not only JSII).

Proposed Solution

No response

Implementation Notes

No response

Component

Compiler

Community Notes

github-actions[bot] commented 1 week ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!