babel / babel/babel

replaceWith on an import declaration removes comments

Open
#9,880 3 comments 0 reactions 0 assignees View on GitHub
area: comments
Dominant language
TypeScript
Stars
44k
Forks
6k
Avg merge
5d 15h
Merged PRs (30d)
23

Description

## Bug Report

**Current Behavior**
Comments are removed when a plugin uses `replaceWith` on an import declaration, for example in `babel-plugin-transform-es2015-modules-commonjs`.

**Input Code**
[REPL](https://babeljs.io/repl/#?babili=false&build=&builtIns=false&spec=false&loose=false&code_lz=JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AoAekrhiQGcZzyg&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=&prettier=false&targets=&version=7.4.3&externalPlugins=babel-plugin-transform-es2015-modules-commonjs%406.26.2)

**Expected behavior/code**
Comments preserved

**Environment**
REPL

Contributor guide

Open the contributing guide

Research direction

Reproduce the behavior using the linked Babel REPL and inspect the babel-plugin-transform-es2015-modules-commonjs path that calls replaceWith on an import declaration. Compare the transformed output with the input comments; done means those comments remain present after the import is replaced.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.