dart-archive / js_facade_gen

Generates package:js Javascript interop facades for arbitrary TypeScript libraries
Apache License 2.0
161 stars 29 forks source link

Handle case where class name matches property name #20

Closed johnpryan closed 6 years ago

johnpryan commented 7 years ago

Some definition files use property names that are the same as the generated class name (aws-sdk.d.ts for instance). For example, to avoid analyzer warnings:

  external Credentials get Credentials;
  external set Credentials(Credentials v);

is generated, and needs to be changed (by hand) to

  external CredentialsType get Credentials;
  external set Credentials(CredentialsType v);
jacob314 commented 7 years ago

What do you think of instead of renaming the type renaming the method? I can automatically rename the method from external Credentials get Credentials; to external Credentials get JS$Credentials; for cases where the class name and method name conflict.

jacob314 commented 7 years ago

Generally, renaming the class would cause a ton of renames but renaming just the method should be more localized.

jacob314 commented 7 years ago

Actually there is a cleaner fix. No names need to change. We just need to import the current library with a prefix to avoid ambiguity. I will make the code generator do this manually but for now:

Try this manual edit of the generated file:

import "aws_sdk.dart" as aws_sdk;

external aws_sdk.Credentials get Credentials; external set Credentials(aws_sdk.Credentials v);

johnpryan commented 7 years ago

awesome - that's a nice solution

thosakwe commented 6 years ago

Should this issue be closed?

johnpryan commented 6 years ago

yep! closing

johnpryan commented 6 years ago

Although thinking more about this... manual edits are probably not the ideal solution