-
Notifications
You must be signed in to change notification settings - Fork 1.9k
relay-compiler: Does not account for backslashes that are part of escape sequences. #2376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Did you know that template tags get to choose from the “cooked” and “raw” value of the template literal? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Raw_strings
This means that whenever you use a template tag you cannot reason about how escapes anymore. You have to read the source code for the template tag (these things tend not to be documented). The Relay compiler uses the raw value:
Which is why your example doesn’t work. It’s a clash of expectations, really. Now, in this particular, as far as I understand you use “explicit newlines” as you say because that’s how CoffeeScript compiles your code? Then it is actually CoffeeScript’s fault, as mentioned here: jashkenas/coffeescript#5019 (comment) Still, Relay should probably document how it handles escapes. (As a side note, I suspect that it is impossible to include a literal It’s also interesting to note that the |
Hi @amozoss , Did you find any solution for this issue? |
@shahsohil25 I've just been working around it for now by running the bash script below after I install node modules. I'm still on babel-plugin-relay version 1.6.0 so the script may not work with newer versions. I'm also using a forked version of relay-coffee-compiler with these changes amozoss/relay-coffee-compiler@c8bb481
Thanks @lydell for digging even deeper. Looks like the actual issue is in coffeescript. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
First off thanks for creating relay, its fabulous.
I'm having an issue related to graphql tagged template literals. I'm including explicit new line characters when forming my queries.
hello/Hello.js
schema.graphql
Looking at the graphql spec, the way I understand it is the newline characters shouldn't matter.
However, when using relay-compiler 1.5.0, I get the error
Parse error: Syntax Error: Cannot parse the unexpected character "\\".
I logged just before the error is thrown with
console.log(source)
which gave the output:$ ./node_modules/.bin/relay-compiler --src ./hello --schema ./schema.graphql
It looks like, its escaping backslashes, even when the backslash should be considered part of an escape sequence (such as
\n
). It also seemed, by looking at the lexer source code, that it handled unicode line feed (\u000a
) in the parser, but replacing\n
with\u000a
, had the same error.Any thoughts?
The text was updated successfully, but these errors were encountered: