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

Single quotes not correct when inside of template quotes. #1259

Closed
nhumrich opened this issue Dec 8, 2020 · 1 comment · Fixed by #1287
Closed

Single quotes not correct when inside of template quotes. #1259

nhumrich opened this issue Dec 8, 2020 · 1 comment · Fixed by #1287
Assignees
Labels
Milestone

Comments

@nhumrich
Copy link

nhumrich commented Dec 8, 2020

Describe the bug
When any string started with template quotes: ` starts with a single quote ', the single quotes are not correct in the final compiled code.

Example 1:

sql`'#ERROR'`

produces:

function _templateObject() {
    var data = _taggedTemplateLiteral([
        '#ERRORR''
    ]);
    _templateObject = function _templateObject() {
        return data;
    };
    return data;
}

Note the extra R' at the end, and wrong quotes on the outside:

 '#ERRORR''

It should be

 "'#ERROR"

Or the below even works fine.

`'#ERROR'`

Example 2:

throw new BadRequestError(
          `'remote_field' is required with the summary_function: '${this.config.summary_function}'`
        )

Produces the following:

throw new _errors.BadRequestError('remote_field' is required with the summary_function:  ''.concat(this.config.summary_function, "\'"));

but it should be:

throw new _errors.BadRequestError("'remote_field' is required with the summary_function:  ".concat(this.config.summary_function, "\'"));

(again, even ` would work here instead of double quotes)

Config

   {
  "exclude": [".*[.]js$", ".*[.]map$"],
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": true,
      "dynamicImport": false
    }
  },
  "module": {
    "type": "commonjs",
    "strict": false,
    "strictMode": false,
    "lazy": false,
    "noInterop": false
  }
}

Version
The version of @swc/core:

@swc/cli: 0.1.27
@swc/core: 1.2.40
@nhumrich nhumrich added the C-bug label Dec 8, 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 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