babel / babylon

PSA: moved into babel/babel as @babel/parser -->

Home Page:https://github.com/babel/babel/tree/master/packages/babel-parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ESTree plugin not able to convert StringLiteral in TS shorthand module dec

JamesHenry opened this issue · comments

When using the TypeScript and ESTree plugins together, the id of the TypeScript shorthand module declaration source below is coming through as a StringLiteral, instead of a Literal.

Input Code

declare module "hot-new-module";

Babylon/Babel Configuration

{
  "sourceType": "module",
  "plugins": ["typescript", "estree"]
}

Expected Behavior

Current (red) vs Expected (green) Behavior

{
  "type": "File",
  "start": 0,
  "end": 32,
  "loc": {
    "start": {
      "line": 1,
      "column": 0
    },
    "end": {
      "line": 1,
      "column": 32
    }
  },
  "program": {
    "type": "Program",
    "start": 0,
    "end": 32,
    "loc": {
      "start": {
        "line": 1,
        "column": 0
      },
      "end": {
        "line": 1,
        "column": 32
      }
    },
    "sourceType": "module",
    "body": [
      {
        "type": "TSModuleDeclaration",
        "start": 0,
        "end": 32,
        "loc": {
          "start": {
            "line": 1,
            "column": 0
          },
          "end": {
            "line": 1,
            "column": 32
          }
        },
        "id": {
-        "type": "StringLiteral",
+        "type": "Literal",
          "start": 15,
          "end": 31,
          "loc": {
            "start": {
              "line": 1,
              "column": 15
            },
            "end": {
              "line": 1,
              "column": 31
            }
          },
          "value": "hot-new-module",
          "raw": "\"hot-new-module\""
        },
        "declare": true
      }
    ]
  }
}
commented

Hey @JamesHenry! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

I have a fix ready for this

Fixed by #684, thanks @JamesHenry!