fix(45336): add a blank line before the comment expression to avoid disrupting return statement (#46287)
This commit is contained in:
parent
68ff7380d2
commit
44deb84460
|
@ -4147,7 +4147,8 @@ namespace ts {
|
||||||
// NoSubstitutionTemplateLiterals are directly emitted via emitLiteral()
|
// NoSubstitutionTemplateLiterals are directly emitted via emitLiteral()
|
||||||
Debug.assert(node.templateSpans.length !== 0);
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
|
@ -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))
|
||||||
|
|
||||||
|
}`;
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
}`;
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// @removeComments: false
|
||||||
|
|
||||||
|
const a = 1;
|
||||||
|
const f1 = () =>
|
||||||
|
`${
|
||||||
|
// a
|
||||||
|
a
|
||||||
|
}a`;
|
||||||
|
|
||||||
|
const f2 = () =>
|
||||||
|
`${
|
||||||
|
// a
|
||||||
|
a
|
||||||
|
}`;
|
Loading…
Reference in a new issue