Skip to content

Incorrect placement of JSDoc comments #8437

@zavr-1

Description

@zavr-1

Bug Report

Current Behavior
The JSDoc for a function is moved to a random place.

Input Code

/**
 * Pretend this works.
 */
const makeMarker = () => {

}

/**
 * Make a rule for initial replacement of markers.
 * @param {Marker} marker A marker used to cut and paste portions of text to exclude them from processing by other rules.
 * @returns {Rule} A rule to cut matched chunks.
 */
const makeCutRule = (marker) => {
  const { re, map, getReplacement, name } = marker
  const rule = {
    re,
    replacement(match) {
      const { lastIndex } = marker
      map[lastIndex] = match
      marker.lastIndex += 1
      const m = getReplacement(name, lastIndex)
      return m
    },
  }
  return rule
}

/**
 * Make a rule for pasting markers back.
 * @param {Marker} marker A marker used to cut and paste portions of text to exclude them from processing by other rules.
 * @returns {Rule} A rule to paste previously replaced chunks.
 */
const makePasteRule = (marker) => {
  const { regExp: re, map } = marker
  const rule = {
    re,
    replacement(match, index) {
      const m = map[index]
      delete map[index]
      return m
    },
  }
  return rule
}

export { makeMarker as default, makeCutRule, makePasteRule }

Output Code

"use strict";

exports.__esModule = true;
exports.makePasteRule = exports.makeCutRule = exports.default = void 0;

/**
 * Pretend this works.
 */
const makeMarker = () => {};
/**
 * Make a rule for initial replacement of markers.
 * @param {Marker} marker A marker used to cut and paste portions of text to exclude them from processing by other rules.
 * @returns {Rule} A rule to cut matched chunks.
 */


exports.default = makeMarker;

const makeCutRule = marker => {
  const {
    re,
    map,
    getReplacement,
    name
  } = marker;
  const rule = {
    re,

    replacement(match) {
      const {
        lastIndex
      } = marker;
      map[lastIndex] = match;
      marker.lastIndex += 1;
      const m = getReplacement(name, lastIndex);
      return m;
    }

  };
  return rule;
};
/**
 * Make a rule for pasting markers back.
 * @param {Marker} marker A marker used to cut and paste portions of text to exclude them from processing by other rules.
 * @returns {Rule} A rule to paste previously replaced chunks.
 */


exports.makeCutRule = makeCutRule;

const makePasteRule = marker => {
  const {
    regExp: re,
    map
  } = marker;
  const rule = {
    re,

    replacement(match, index) {
      const m = map[index];
      delete map[index];
      return m;
    }

  };
  return rule;
};

exports.makePasteRule = makePasteRule;
//# sourceMappingURL=markers.1.js.map

Expected behavior/code
I expect JSDoc comments to remain attached to the functions.

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

{
  "plugins": [
    "@babel/plugin-syntax-object-rest-spread",
    ["@babel/plugin-transform-modules-commonjs", { "loose": true, "noInterop": true }]
  ],
}

Environment

  • Babel version(s): [7.0.0-beta.56]
  • Node/npm version: [e.g. Node v8.11.3]
  • OS: [e.g. OSX 10.11.6]
  • Monorepo [e.g. no]
  • How you are using Babel: [e.g. cli]

Additional context/Screenshots

test

test

test

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions