Skip to content

JSDoc type cast parentheses is removed  #4799

@mohsen1

Description

@mohsen1

Prettier 1.13.7
Playground link

--parser babylon

JSDoc @type allows casting types of a reference but it requires a pair parentheses around the target reference. Prettier should not remove it.

Input:

class Chunk {
    /**
	 * @returns {boolean} whether or not the Chunk will have a runtime
	 */
	hasRuntime() {
		for (const chunkGroup of this._groups) {
			// We only need to check the first one
			return (
				chunkGroup.isInitial() &&
				/** @type {Entrypoint} */ (chunkGroup).getRuntimeChunk() === this
            );
		}
		return false;
	}
}

Output:

class Chunk {
  /**
   * @returns {boolean} whether or not the Chunk will have a runtime
   */
  hasRuntime() {
    for (const chunkGroup of this._groups) {
      // We only need to check the first one
      return (
        chunkGroup.isInitial() &&
        /** @type {Entrypoint} */ (chunkGroup.getRuntimeChunk() === this)
      );
    }
    return false;
  }
}

Expected behavior:

class Chunk {
    /**
	 * @returns {boolean} whether or not the Chunk will have a runtime
	 */
	hasRuntime() {
		for (const chunkGroup of this._groups) {
			// We only need to check the first one
			return (
				chunkGroup.isInitial() &&
				/** @type {Entrypoint} */ (chunkGroup).getRuntimeChunk() === this
            );
		}
		return false;
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions