Skip to content

Trailing comment removed from object property with trailing comma #5644

@rafayepes

Description

@rafayepes

Choose one: is this a bug report or feature request? Bug

Had the following package json script: "build": "rimraf dist && babel ./src -d dist --ignore tests"

After installing babel-cli version "^6.24.1" as dependency, a comment is removed from object with trailing comma. Before the script was relying on global babel installation

$ babel --version
6.7.7 (babel-core 6.7.7)

Input Code

https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&targets=&browsers=&builtIns=false&debug=false&experimental=true&loose=false&spec=false&code=%0A%0Aconst%20foo%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%2F%2F%20Coment%201%0A%20%20%20%20'prop-1'%3A%20%7B%0A%20%20%20%20%20%20inner1%3A%20%22bar%22%2C%2F%2F%20Comment%202%0A%20%20%20%20%20%20inner2%3A%20'never'%2C%0A%20%20%20%20%20%20inner3%3A%20%5B%5D%2C%20%2F%2F%20Comment%203%3A%20Last%20in%20object%20prop.%20Appears%20after%20removing%20trailing%20comma%20in%20%22inner3%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%2F%2F%20Comment%204%0A%20%20%20%20'prop-2'%3A%200%2C%0A%20%20%7D%3B%0A%0A%0Aconst%20bar%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%2F%2F%20Coment%201%0A%20%20%20%20'prop-1'%3A%20%7B%0A%20%20%20%20%20%20inner1%3A%20%22bar%22%2C%2F%2F%20Comment%202%0A%20%20%20%20%20%20inner2%3A%20'never'%2C%0A%20%20%20%20%20%20inner3%3A%20%5B%5D%20%2F%2F%20Comment%203%3A%20Last%20in%20object%20prop.%20Appears%20after%20removing%20trailing%20comma%20in%20%22inner3%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%2F%2F%20Comment%204%0A%20%20%20%20'prop-2'%3A%200%2C%0A%20%20%7D%3B%0A

input

const foo = {
        
    // Coment 1
    'prop-1': {
      inner1: "bar",// Comment 2
      inner2: 'never',
      inner3: [], // Comment 3: Last in object prop. Appears after removing trailing comma in "inner3"
    },
    // Comment 4
    'prop-2': 0,
  };


const bar = {
        
    // Coment 1
    'prop-1': {
      inner1: "bar",// Comment 2
      inner2: 'never',
      inner3: [] // Comment 3: Last in object prop. Appears after removing trailing comma in "inner3"
    },
    // Comment 4
    'prop-2': 0,
  };

output

'use strict';

var foo = {

  // Coment 1
  'prop-1': {
    inner1: "bar", // Comment 2
    inner2: 'never',
    inner3: [] },
  // Comment 4
  'prop-2': 0
};

var bar = {

  // Coment 1
  'prop-1': {
    inner1: "bar", // Comment 2
    inner2: 'never',
    inner3: [] // Comment 3: Last in object prop. Appears after removing trailing comma in "inner3"
  },
  // Comment 4
  'prop-2': 0
};

Babel Configuration (.babelrc, package.json, cli command)

See REPL link.

Expected Behavior

Expect the "comment 3" to not be removed.

Current Behavior

The "comment 3" is removed when using trailing comma.

Your Environment

See REPL link.

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedA 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