Skip to content

Improve Escape Sequences in String Literals #660

@InsertCreativityHere

Description

@InsertCreativityHere

Continued from #659.

Currently, the Slice compiler handles escape sequences like NodeJS does.
If it sees a backslash in a string literal, we remove the backslash and the character immediately after it gets kept as a literal character.
For instance: [deprecated("This is bad, use \"Foo\" instead.")].

This works perfectly for the two cases Slice cares about: \" -> " and \\ -> \,
and is consistent with how we support escaping keywords for identifiers: \struct -> struct.

But it leaves other cases that might be surprising to some users:
\n -> n (instead of a newline character)
\p -> p (it's useless to escape p here)


Should we emit an error/warning when users do this explaining the Slice behavior?
Or should we alter the Slice behavior to handle these differently?

I think the current behavior is fine (NodeJS does it, and it's consistent with identifiers),
but I open this issue to discuss alternatives.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions