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

Tagged template literal which starts and ends with quotation marks gives unterminated string #1280

Closed
lexanth opened this issue Dec 18, 2020 · 1 comment · Fixed by #1287
Closed
Assignees
Labels
Milestone

Comments

@lexanth
Copy link

lexanth commented Dec 18, 2020

Describe the bug
SWC fails to correctly transform a tagged template literal which starts and ends with a single quotation mark

Input code

import { T } from './i18n';

const myVar = T`'Hello'`;

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true,
      "dynamicImport": true
    }
  }
}

Actual output
Note the double "o" in "Hello" and the unterminated string

function _taggedTemplateLiteral(strings, raw) {
    if (!raw) {
        raw = strings.slice(0);
    }
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    var data = _taggedTemplateLiteral([
        'Helloo''
    ]);
    _templateObject = function _templateObject() {
        return data;
    };
    return data;
}
import { T } from './i18n';
var myVar = T(_templateObject());

Expected behavior
Double quotes around the single quotes and escape the single quotes

    var data = _taggedTemplateLiteral([
        "\'Hello\'"
    ]);

Version
The version of @swc/core: 1.2.40

Additional context
Removing either of the quotes in the template literal works fine - it uses double quotes and escapes the single quote.

@lexanth lexanth added the C-bug label Dec 18, 2020
@kdy1 kdy1 added this to the v1.2.41 milestone Dec 21, 2020
@kdy1 kdy1 self-assigned this Dec 21, 2020
kdy1 added a commit to kdy1/swc that referenced this issue Dec 21, 2020
kdy1 added a commit to kdy1/swc that referenced this issue Dec 21, 2020
kdy1 added a commit to kdy1/swc that referenced this issue Dec 21, 2020
kdy1 added a commit that referenced this issue Dec 21, 2020
swc_ecma_ast:
 - Add `Str.kind`.

swc_ecma_transforms:
 - Fix quotes in template literals. (#1280)

swc_ecma_codegen:
 - Fix escape of single quotes. (#1259)
 - Fix codegen of wrong escapes. (#1276)

swc:
 - Ensure that #1271 is about napi's deserialization.
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 26, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants