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

Auto-indent changes multiline strings #164

Closed
trbrc opened this issue Oct 5, 2015 · 3 comments
Closed

Auto-indent changes multiline strings #164

trbrc opened this issue Oct 5, 2015 · 3 comments

Comments

@trbrc
Copy link

trbrc commented Oct 5, 2015

The auto-indent feature adds indentation to the contents of multiline strings.

export const myTemplateString = `
Template string content
`;

export const myEscapedString = "\
Escaped string content\
";

$ rollup -f iife -n strings strings.js

(function (exports) { 'use strict';

    const myTemplateString = `
    Template string content
    `;

    const myEscapedString = "\
    Escaped string content\
    ";

    exports.myTemplateString = myTemplateString;
    exports.myEscapedString = myEscapedString;

})((this.strings = {}));

A workaround would be to use the indent: false option, but as far as I can tell that's not possible with the CLI. Since the defaults are indent: true, rollup is currently subtly breaking such code out of the box. A better solution would be to make the auto-indent feature treat these cases as an exception.

I suggest that the output should be:

(function (exports) { 'use strict';

    const myTemplateString = `
Template string content
`;

    const myEscapedString = "\
Escaped string content\
";

    exports.myTemplateString = myTemplateString;
    exports.myEscapedString = myEscapedString;

})((this.strings = {}));
@Victorystick
Copy link
Contributor

That's definitely a bug. Thanks for reporting it. I'm not sure how to best fix the general case of indented template strings, but we should make sure to have a CLI option, such as --no-indent.

Rich-Harris added a commit that referenced this issue Oct 5, 2015
@Rich-Harris
Copy link
Contributor

magic-string does allow you to pass an exclude option to magicString.indent(...), for exactly this reason. I just had a quick look now and it looks like there'll be a bit of an art to rigging it up, but it's definitely solvable. We should expose that CLI option anyway though

@Rich-Harris
Copy link
Contributor

Fixed by 4fcbba6, which I've rolled into #163 – will release as 0.18.0 as soon as I've tied down one loose end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants