Skip to content

[Bug]: Babel unable to parse export declare const of a negative number literal in a .d.ts file  #15337

@karmeleon

Description

@karmeleon

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

REPL link

Configuration file name

No response

Configuration

No response

Current and expected behavior

  1. Write a .ts file that contains an export of a negative number (e.g. export const SOME_NUMBER = -1;)
  2. Use tsc to generate a type definition file of the .ts file, resulting in export declare const SOME_NUMBER = -1;
  3. Run Babel against the code

Expected:
Babel parses the typedef file successfully

Actual:
Babel returns an error:

/repl.tsx: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference. (1:38)

Babel can correctly parse a declared export of a positive number or zero, as well as the original export of a negative number in the .ts file.

Environment

Reproduces in REPL

Discoverd on:

  • Babel versions:
    • @babel/core@7.20.12
    • @babel/parser@7.20.7
  • Node version: v16.13.2
  • Yarn v3.2.0
  • Lerna 3.16.4
  • Ubuntu 18.04.5 LTS

Possible solution

No response

Additional context

Originally discovered by attempting to use jscodeshift to modify a .d.ts file containing a negative number, but successfully isolated to Babel.

Metadata

Metadata

Assignees

Labels

area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions