question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]Same function declaration will cause SyntaxError

See original GitHub issue

Bug Report

  • I would like to work on a fix!

Current behavior

See this

Input Code

function foo() {}

function foo() {}

Will get SyntaxError: Identifier 'foo' has already been declared error

Expected behavior

No error. Because this is a valid javascript syntax and can be executed without any error thrown

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

See REPL above

Environment

REPL
  • Babel version(s): REPL
  • Node/npm version: REPL
  • OS: Windows 10
  • Monorepo: no
  • How you are using Babel: REPL

Possible Solution

Additional context

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
NE-SmallTowncommented, Nov 13, 2020

Our goal is to align to the specification so that when gradually disabling Babel transform over time your code doesn’t suddenly start failing.

That’s fair.

By the way, could we add more info when throw the error? For example, change “SyntaxError: Identifier ‘foo’ has already been declared” to “SyntaxError: Identifier ‘foo’ has already been declared, this is not allowed in a ESM

1reaction
nicolo-ribaudocommented, Nov 13, 2020

You are saying that it’s possible for Babel to accept invalid code and still produce code that runs.

That’s true, but it’s out of scope for the project. Our goal is to align to the specification so that when gradually disabling Babel transform over time your code doesn’t suddenly start failing.

It’s not ok to silently shallow an error, because that error is mandated by the spec.

That said, you can pass the errorRecovery: true parser option which doesn’t throw for early errors: https://runkit.com/nicolo-ribaudo/babel-babel-12354

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: function statement requires a name - JavaScript
The JavaScript exception "function statement requires a name" occurs when there is a function statement in the code that requires a name.
Read more >
What is the "Function statement requires a name" syntax error?
The JavaScript exception SyntaxError - Function statement requires a name occurs when a function statement (or function declaration) requires a name but is ......
Read more >
Structure member assignment causing syntax error when not ...
C code has to be inside a function. You can declare a global outside of a function but you can't write an assignment...
Read more >
Functions - F# | Microsoft Learn
Non-recursive function definition. let [inline] function-name ... However, the compiler will attempt to make the function as generic as ...
Read more >
Version 1 - History - Changes in Virtuemart 109 - Changes in ...
various fixes to make VirtueMart compatible to Joomla! ... number not checked on form submit, another bug, same reason: payment method can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found