question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unterminated template when parsing template literals with multiple newlines (regression from v1)

See original GitHub issue

Initial checklist

Affected packages and versions

@mdx-js/mdx

Link to runnable example

https://stackblitz.com/edit/github-rumgbj?file=index.js

Steps to reproduce

Add an extra \n between .foo and .bar styles in the linked stackblitz example

Expected behavior

It should compile successfully. We are using this pattern in Storybook’s starter template:

https://raw.githubusercontent.com/storybookjs/storybook/next/lib/cli/src/frameworks/common/Introduction.stories.mdx

Actual behavior

It will crash with

Could not parse expression with acorn: Unterminated template

Or perhaps this is an intentional breaking change in MDXv2?

Runtime

No response

Package manager

No response

OS

No response

Build and bundle tools

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shilmancommented, Feb 28, 2022

Hi @wooorm thanks so much for getting back to me.

I updated the example to make it a little more readable and realized it was not exactly what I wanted to convey (though the behavior is the same).

Original (broken)

<style>{`
  .foo {}

  .bar {}
`}</style>

The “original” version worked with MDXv1 and we shipped it to tens of thousands of users as part of the example template in Storybook Docs. Now in MDXv2 it’s broken. It feels like a regression to me, but if that’s the expected behavior I’m totally fine with it – I realize that’s what major versions are for.

Updated1 (works)

<style>{`
  .foo {}
  .bar {}
`}</style>

Updated2 (also works)

<style>
  {`
    .foo {}
  
    .bar {}
  `}
</style>

Discussion

Both updated versions work. I could update our template accordingly, and provide migration instructions or potentially even ship a codemod to update users’ code accordingly.

Before I do that, however, I want to confirm:

  • That this original example should not work in MDXv2, i.e. it’s expected behavior and not a regression
  • Do you have a preference between Updated1 and Updated2? (I’m guessing Updated2 is more idiomatic MDX, but not entirely sure)

Thanks again for your help! And congratulations on the v2 release–super excited to get this into users’ hands!!! 🎉

0reactions
wooormcommented, Apr 8, 2022

@brendonco you’re probably better off asking questions about storybook betas in storybook repos

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: unterminated string literal - JavaScript | MDN
The JavaScript error "unterminated string literal" occurs when there is an unterminated ... Instead, use the + operator, a backslash, or template literals....
Read more >
javascript - "Unterminated template literal" syntax error when ...
I'm using ES6 template literals to construct some HTML in strings, and so far it has been working fine. However, as soon as...
Read more >
CoffeeScript
''' and """ strings are now output as more readable JavaScript template literals, or backtick ( ` ) strings, with actual newlines rather...
Read more >
How to Create Multi-Line String with Template Literals
It's super easy now to create multi-line strings with Template Literals in JavaScript. ... I mean the output of the string is spanning...
Read more >
Template literals (Template strings) - JavaScript
To escape a backtick in a template literal, put a backslash ( \ ) before the backtick. `\`` === '`' // --> true....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found