Skip to content
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

TypeScript: Issue with optional chaining inside templated string #1420

Closed
codebutler opened this issue Jan 29, 2020 · 6 comments · Fixed by #1475
Closed

TypeScript: Issue with optional chaining inside templated string #1420

codebutler opened this issue Jan 29, 2020 · 6 comments · Fixed by #1475
Assignees
Labels
bugfix-request A request for a bugfix to be developed.

Comments

@codebutler
Copy link

codebutler commented Jan 29, 2020

Name of the lexer
TypeScript

Code sample

// This is fine:
const x = `Hello world ${a.b}`;

// This breaks:
const y = `Hello world ${a?.b}`;

// Now Rouge thinks we're still inside a string...
console.log('hello world');

Screenshots
If applicable, add screenshots to help explain your problem.
image

@codebutler codebutler added the bugfix-request A request for a bugfix to be developed. label Jan 29, 2020
@pyrmont pyrmont self-assigned this Feb 5, 2020
@pyrmont
Copy link
Contributor

pyrmont commented Feb 5, 2020

@codebutler I think what's happening here is that the lexer is treating the ? after the a as a ternary operator. What does a? represent? Is it just a name?

@jneen
Copy link
Member

jneen commented Feb 5, 2020

As far as I can tell this is a stage 4 draft, not yet part of the spec: https://tc39.es/proposal-optional-chaining/

@codebutler
Copy link
Author

yes, this is the optional chaining operator. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

@jneen optional chaining is in wide use. it was added to typescript last year: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html

@pyrmont
Copy link
Contributor

pyrmont commented Feb 11, 2020

@codebutler Is your use case using it with the TypeScript lexer? This could be added specifically to that lexer (and then moved into the JavaScript one once it receives broader adoption and/or becomes part of the spec).

@codebutler
Copy link
Author

Yes, we are specifically seeing this with Typescript. I didn't realize it was a separate lexer.

@codebutler codebutler changed the title JavaScript: Issue with optional chaining inside templated string TypeScript: Issue with optional chaining inside templated string Feb 11, 2020
@pyrmont
Copy link
Contributor

pyrmont commented Feb 11, 2020

@codebutler No worries. Thanks for filing the bug! Will have a look into it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix-request A request for a bugfix to be developed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants