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

Convert a TypeScript declare function with a body into a function. #12046

Closed
1 task done
sosukesuzuki opened this issue Sep 9, 2020 · 1 comment · Fixed by #12054
Closed
1 task done

Convert a TypeScript declare function with a body into a function. #12046

sosukesuzuki opened this issue Sep 9, 2020 · 1 comment · Fixed by #12054
Labels
Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@sosukesuzuki
Copy link
Member

sosukesuzuki commented Sep 9, 2020

Bug Report

  • I would like to work on a fix!

Current behavior

Convert a TypeScript declare function with a body into a function.

Try it out link

Output:

"use strict";

function foo() {}

Input Code

declare function foo() {}

Expected behavior

It should throw an error like tsc(TypeScript Playground). And it should support errorRecovery.

Also babel/parser should return a node of TSDeclareFunction instead of FunctionDeclaration(declare: true).

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  "presets": ["@babel/preset-typescript"]
}

Environment

I don't think environment information is needed because this issue is simple, but I will provide it if it is needed for you guys.

Possible Solution

Additional context

While working in Prettier, I notice that declare disappears. (Prettier Playground link)
It is possible to fix this issue on Prettier side, but I think this is the parser's responsibility.

@babel-bot
Copy link
Collaborator

Hey @sosukesuzuki! 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."

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 19, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants