-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosThis issue has compiler-backed repros: https://aka.ms/ts-reprosHigh Priority
Milestone
Description
TypeScript Version: Since v3.8.3
Search Terms:
Arrow function, implicit return, line comments, optional chaining
Code
// Target: ES5
// arrow function, implicit return on 2nd line that starts with optional chaining, and has a line comment in between the lines.
const test = (names: string[]) =>
// testing 1 two
names?.filter(x => x);
console.log(test(["a"]));Expected behavior:
Something like:
"use strict";
var test = function (names) { // testing 1 two
return names === null ||
names === void 0 ? void 0 :
names.filter(function (x) { return x; }); };
console.log(test(["a"]));Actual behavior:
- the comment is being copied 3 times.
- the first line comment terminates the
return, making this function always returnundefined.
"use strict";
var test = function (names) { return
// testing 1 two
names === null ||
// testing 1 two
names === void 0 ? void 0 :
// testing 1 two
names.filter(function (x) { return x; }); };
console.log(test(["a"]));Playground Link:
https://www.typescriptlang.org/play?target=1&ts=3.8.3#code/MYewdgzgLgBFCm0YF4YAowEMC2iBcM0ATgJZgDmA2gLoCUKAfDAFAxswD0HciUZ5MAIxwA7iFbssuCAH4AdADMSAGwRE0AD0YwNtANzNmoSCGXw5ykOTQJoaSgCJMDuvqA
Related Issues:
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosThis issue has compiler-backed repros: https://aka.ms/ts-reprosHigh Priority