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

Invalid typescript syntax destroys file content #115

Closed
vsviridov opened this issue Jul 31, 2020 · 1 comment
Closed

Invalid typescript syntax destroys file content #115

vsviridov opened this issue Jul 31, 2020 · 1 comment

Comments

@vsviridov
Copy link

I've started using the new TypeScript support, and accidentally wrote following code:

<script type="ts">
   let export foo: string = ""
</script>

Notice that is said let export instead of export let.

When reformatted by my formatter - the code was destroyed (replaced with following:

{
      "type": "Script",
      "start": 0,
      "end": 499,
      "context": "default",
      "content": {
          "type": "Program",
          "start": 488,
          "end": 490,
          "loc": {
              "start": {
                  "line": 1,
                  "column": 0
              },
              "end": {
                  "line": 1,
                  "column": 490
              }
          },
          "body": [
              {
                  "type": "BlockStatement",
                  "start": 488,
                  "end": 490,
                  "loc": {
                      "start": {
                          "line": 1,
                          "column": 488
                      },
                      "end": {
                          "line": 1,
                          "column": 490
                      }
                  },
                  "body": []
              }
          ],
          "sourceType": "module"
      },
      "attributes": [
          {
              "type": "Attribute",
              "name": "lang",
              "value": [
                  {
                      "type": "Text",
                      "data": "ts",
                      "start": 6,
                      "end": 8
                  }
              ],
              "start": 0,
              "end": 9
          }
      ]
  }

Which is pretty annoying... If I run the prettier instance manually I do get the error, but I also get the stdout output with that JSON AST representation, because there's a console.log(JSON.stringify(node, null, 4)) in the plugin.js:457, which is interpreted by the formatter as the new file contents. At least redirect that output to stderr so it doesn't confuse the tooling.

@toerndev
Copy link
Contributor

Was going to report the same problem. I'm guessing that vscode treats stdout differently since more people aren't reporting this? I use the vim plugin w0rp/ale to call prettier via eslint-plugin-prettier. Removing the console.log in node_modules fixes the problem temporarily.

I hope no editors are relying on this output so it can be a quick fix. Would create a PR but it's just one line and I don't yet understand why the author put it there, so...

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

No branches or pull requests

3 participants