Fable icon indicating copy to clipboard operation
Fable copied to clipboard

Sanitize names of fields?

Open alfonsogarciacaro opened this issue 3 years ago • 3 comments
trafficstars

So far Fable sanitizes the names of detached members but not of fields/attached members. This is because in JS you can use a string expression for object keys the so there's no restriction on characters. However, in Dart I'm having issues particularly with the @ char that F# uses for auto-generated fields. Not sure what's the best solution for this, either sanitizing in the Fable2Dart step or do it in the FSharp2Fable step for consistency with detached member sanitization. Is this an issue for Python/Rust @dbrattli @ncave?

A related task is to make name sanitization/keyword checking customizable by language. Right now is only done with JS in mind.

alfonsogarciacaro avatar May 06 '22 02:05 alfonsogarciacaro

@alfonsogarciacaro Yes, there is sanitization for all identifiers for Rust.

ncave avatar May 06 '22 22:05 ncave

I believe it's the same for Python, i.e sanitizing all identifiers. Python have no way of escaping them. I have a feeling that there's something not being sanitized, but cannot remember right now.

dbrattli avatar May 08 '22 14:05 dbrattli

Thanks for the replies! Sorry I was not clear enough, right now Fable does the following:

  • Sanitizes identifiers and detached members (that is, module functions) following JS rules: allowed chars and keywords
  • Keeps fields and attached members as they are (because they can be referenced with a string in JS).

This excludes mangling, name deduplication and overload suffixes.

Probably we should somehow unify these two points and let the languages decide on the sanitation rules.

alfonsogarciacaro avatar May 08 '22 16:05 alfonsogarciacaro