mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Fixes JSX attribute escaping when parent pointers are missing (#35743)
* Fixes JSX attribute escaping when parent pointers are missing * Fix whitespace change
This commit is contained in:
@@ -11,56 +11,58 @@ namespace ts {
|
||||
|
||||
describe("printFile", () => {
|
||||
const printsCorrectly = makePrintsCorrectly("printsFileCorrectly");
|
||||
// Avoid eagerly creating the sourceFile so that `createSourceFile` doesn't run unless one of these tests is run.
|
||||
let sourceFile: SourceFile;
|
||||
before(() => {
|
||||
sourceFile = createSourceFile("source.ts", `
|
||||
interface A<T> {
|
||||
// comment1
|
||||
readonly prop?: T;
|
||||
describe("comment handling", () => {
|
||||
// Avoid eagerly creating the sourceFile so that `createSourceFile` doesn't run unless one of these tests is run.
|
||||
let sourceFile: SourceFile;
|
||||
before(() => {
|
||||
sourceFile = createSourceFile("source.ts", `
|
||||
interface A<T> {
|
||||
// comment1
|
||||
readonly prop?: T;
|
||||
|
||||
// comment2
|
||||
method(): void;
|
||||
// comment2
|
||||
method(): void;
|
||||
|
||||
// comment3
|
||||
new <T>(): A<T>;
|
||||
// comment3
|
||||
new <T>(): A<T>;
|
||||
|
||||
// comment4
|
||||
<T>(): A<T>;
|
||||
}
|
||||
// comment4
|
||||
<T>(): A<T>;
|
||||
}
|
||||
|
||||
// comment5
|
||||
type B = number | string | object;
|
||||
type C = A<number> & { x: string; }; // comment6
|
||||
// comment5
|
||||
type B = number | string | object;
|
||||
type C = A<number> & { x: string; }; // comment6
|
||||
|
||||
// comment7
|
||||
enum E1 {
|
||||
// comment8
|
||||
first
|
||||
}
|
||||
// comment7
|
||||
enum E1 {
|
||||
// comment8
|
||||
first
|
||||
}
|
||||
|
||||
const enum E2 {
|
||||
second
|
||||
}
|
||||
const enum E2 {
|
||||
second
|
||||
}
|
||||
|
||||
// comment9
|
||||
console.log(1 + 2);
|
||||
// comment9
|
||||
console.log(1 + 2);
|
||||
|
||||
// comment10
|
||||
function functionWithDefaultArgValue(argument: string = "defaultValue"): void { }
|
||||
`, ScriptTarget.ES2015);
|
||||
// comment10
|
||||
function functionWithDefaultArgValue(argument: string = "defaultValue"): void { }
|
||||
`, ScriptTarget.ES2015);
|
||||
});
|
||||
printsCorrectly("default", {}, printer => printer.printFile(sourceFile));
|
||||
printsCorrectly("removeComments", { removeComments: true }, printer => printer.printFile(sourceFile));
|
||||
});
|
||||
printsCorrectly("default", {}, printer => printer.printFile(sourceFile));
|
||||
printsCorrectly("removeComments", { removeComments: true }, printer => printer.printFile(sourceFile));
|
||||
|
||||
// github #14948
|
||||
// https://github.com/microsoft/TypeScript/issues/14948
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
printsCorrectly("templateLiteral", {}, printer => printer.printFile(createSourceFile("source.ts", "let greeting = `Hi ${name}, how are you?`;", ScriptTarget.ES2017)));
|
||||
|
||||
// github #18071
|
||||
// https://github.com/microsoft/TypeScript/issues/18071
|
||||
printsCorrectly("regularExpressionLiteral", {}, printer => printer.printFile(createSourceFile("source.ts", "let regex = /abc/;", ScriptTarget.ES2017)));
|
||||
|
||||
// github #22239
|
||||
// https://github.com/microsoft/TypeScript/issues/22239
|
||||
printsCorrectly("importStatementRemoveComments", { removeComments: true }, printer => printer.printFile(createSourceFile("source.ts", "import {foo} from 'foo';", ScriptTarget.ESNext)));
|
||||
printsCorrectly("classHeritageClauses", {}, printer => printer.printFile(createSourceFile(
|
||||
"source.ts",
|
||||
@@ -68,16 +70,28 @@ namespace ts {
|
||||
ScriptTarget.ES2017
|
||||
)));
|
||||
|
||||
// github #35093
|
||||
// https://github.com/microsoft/TypeScript/issues/35093
|
||||
printsCorrectly("definiteAssignmentAssertions", {}, printer => printer.printFile(createSourceFile(
|
||||
"source.ts",
|
||||
`class A {
|
||||
prop!: string;
|
||||
}
|
||||
|
||||
|
||||
let x!: string;`,
|
||||
ScriptTarget.ES2017
|
||||
)));
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/35054
|
||||
printsCorrectly("jsx attribute escaping", {}, printer => {
|
||||
debugger;
|
||||
return printer.printFile(createSourceFile(
|
||||
"source.ts",
|
||||
String.raw`<a x='\\"'/>`,
|
||||
ScriptTarget.ESNext,
|
||||
/*setParentNodes*/ undefined,
|
||||
ScriptKind.TSX
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
describe("printBundle", () => {
|
||||
|
||||
Reference in New Issue
Block a user