fix(45336): add a blank line before the comment expression to avoid disrupting return statement (#46287)

This commit is contained in:
Oleksandr T 2021-10-12 02:41:49 +03:00 committed by GitHub
parent 68ff7380d2
commit 44deb84460
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 98 additions and 1 deletions

View file

@ -4147,7 +4147,8 @@ namespace ts {
// NoSubstitutionTemplateLiterals are directly emitted via emitLiteral()
Debug.assert(node.templateSpans.length !== 0);
return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0;
const span = node.templateSpans[0];
return node.head.text.length !== 0 || span.literal.text.length === 0 || !!length(getLeadingCommentRangesOfNode(span.expression, currentSourceFile));
}
/**

View file

@ -0,0 +1,27 @@
//// [templateStringWithCommentsInArrowFunction.ts]
const a = 1;
const f1 = () =>
`${
// a
a
}a`;
const f2 = () =>
`${
// a
a
}`;
//// [templateStringWithCommentsInArrowFunction.js]
var a = 1;
var f1 = function () {
return "" +
// a
a + "a";
};
var f2 = function () {
return "" +
// a
a;
};

View file

@ -0,0 +1,24 @@
=== tests/cases/conformance/es6/templates/templateStringWithCommentsInArrowFunction.ts ===
const a = 1;
>a : Symbol(a, Decl(templateStringWithCommentsInArrowFunction.ts, 0, 5))
const f1 = () =>
>f1 : Symbol(f1, Decl(templateStringWithCommentsInArrowFunction.ts, 1, 5))
`${
// a
a
>a : Symbol(a, Decl(templateStringWithCommentsInArrowFunction.ts, 0, 5))
}a`;
const f2 = () =>
>f2 : Symbol(f2, Decl(templateStringWithCommentsInArrowFunction.ts, 7, 5))
`${
// a
a
>a : Symbol(a, Decl(templateStringWithCommentsInArrowFunction.ts, 0, 5))
}`;

View file

@ -0,0 +1,31 @@
=== tests/cases/conformance/es6/templates/templateStringWithCommentsInArrowFunction.ts ===
const a = 1;
>a : 1
>1 : 1
const f1 = () =>
>f1 : () => string
>() => `${ // a a }a` : () => string
`${
>`${ // a a }a` : string
// a
a
>a : 1
}a`;
const f2 = () =>
>f2 : () => string
>() => `${ // a a }` : () => string
`${
>`${ // a a }` : string
// a
a
>a : 1
}`;

View file

@ -0,0 +1,14 @@
// @removeComments: false
const a = 1;
const f1 = () =>
`${
// a
a
}a`;
const f2 = () =>
`${
// a
a
}`;