💻
How are you using Babel?
Programmatic API (babel.transform, babel.parse)
Input code
import * as babel from "@babel/core";
const source = `
export const foo: string;
`;
babel.parse(source, {
configFile: false,
filename: "source.d.ts",
plugins: ["@babel/plugin-syntax-typescript"],
});
Configuration file name
No response
Configuration
No response
Current and expected behavior
After updating @babel/parser from 7.17.3 to 7.17.7, parsing .d.ts files, as shown above, fails with the following error:
SyntaxError: C:\Users\Michal\Desktop\babel-repro\source.d.ts: Missing initializer in const declaration. (2:24)
1 |
> 2 | export const foo: string;
| ^
3 |
at instantiate (C:\Users\Michal\Desktop\babel-repro\node_modules\@babel\parser\lib\index.js:72:32)
at constructor (C:\Users\Michal\Desktop\babel-repro\node_modules\@babel\parser\lib\index.js:358:12)
at Object.raise (C:\Users\Michal\Desktop\babel-repro\node_modules\@babel\parser\lib\index.js:3334:19)
at Object.parseVar (C:\Users\Michal\Desktop\babel-repro\node_modules\@babel\parser\lib\index.js:15292:16)
at Object.parseVarStatement (C:\Users\Michal\Desktop\babel-repro\node_modules\@babel\parser\lib\index.js:15085:10)
at Object.parseVarStatement (C:\Users\Michal\Desktop\babel-repro\node_modules\@babel\parser\lib\index.js:10243:31)
at Object.parseStatementContent (C:\Users\Michal\Desktop\babel-repro\node_modules\@babel\parser\lib\index.js:14631:21)
at Object.parseStatementContent (C:\Users\Michal\Desktop\babel-repro\node_modules\@babel\parser\lib\index.js:10284:18)
at Object.parseStatement (C:\Users\Michal\Desktop\babel-repro\node_modules\@babel\parser\lib\index.js:14556:17)
at Object.parseExportDeclaration (C:\Users\Michal\Desktop\babel-repro\node_modules\@babel\parser\lib\index.js:15932:17) {
code: 'BABEL_PARSE_ERROR',
reasonCode: 'DeclarationMissingInitializer',
loc: Position { line: 2, column: 24, index: 25 },
pos: [Getter/Setter]
}
The official TypeScript compiler does not complain about this sample code.
Environment
System:
OS: Windows 10 10.0.19044
Binaries:
Node: 16.17.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.15.0 - ~\node_modules.bin\npm.CMD
npmPackages:
@babel/core: ^7.18.13 => 7.18.13
@babel/plugin-syntax-typescript: 7.16.7 => 7.16.7
Possible solution
No response
Additional context
No response
💻
How are you using Babel?
Programmatic API (
babel.transform,babel.parse)Input code
Configuration file name
No response
Configuration
No response
Current and expected behavior
After updating @babel/parser from 7.17.3 to 7.17.7, parsing .d.ts files, as shown above, fails with the following error:
The official TypeScript compiler does not complain about this sample code.
Environment
System:
OS: Windows 10 10.0.19044
Binaries:
Node: 16.17.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.15.0 - ~\node_modules.bin\npm.CMD
npmPackages:
@babel/core: ^7.18.13 => 7.18.13
@babel/plugin-syntax-typescript: 7.16.7 => 7.16.7
Possible solution
No response
Additional context
No response