mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Much better comment preservation (#22141)
* Retain comments on (and produce sourcemaps on) the equals token in initializers * Improved comments/sourcemaps for await, yield, while, and for * Retain comments on block curly-braces * Emit comments for if statements * Improved switch case comment emit * Improve comment and sourcemap emit for try/catch, throw, and continue statements * Improve sourcemap emit and comments for with statements * More accurate sourcemaps+comments emit for new, typeof, void, and delete * Improve comment emit for element access expressions * Preserve more comments on imports and exports * Make function a bit more defensive like other usages of emitTrailingCommentsOfPosition * Support preserving comments within empty lists * Handle leading comments of tokens, conditionally indent leading comments * Stop heuristically sourcemapping tokens When the transform was trivial it worked, but was unneeded, but when it was complex, it was brittle - best leave source mapping up to the transformers * Fix unneeded +1 * Tighten up element access comments * Handle comments on parenthesized expression tokens * Fix nit
This commit is contained in:
1 parent
25525bc9d6
commit
1c93744a9c
951 files changed
+22314
-25785
No files matched your search
@@ -0,0 +1,6 @@
|
||||
// @target: esnext
|
||||
async function foo() {
|
||||
/*comment1*/ await 1;
|
||||
await /*comment2*/ 2;
|
||||
await 3 /*comment3*/
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
foo: for (;;) {
|
||||
/*1*/ continue /*2*/ foo /*3*/;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/*0*/ Array /*1*/[ /*2*/ "toString" /*3*/ ] /*4*/; /*5*/
|
||||
|
||||
/*0*/ Array
|
||||
// single line
|
||||
/*1*/[ /*2*/ "toString"
|
||||
// single line
|
||||
/*3*/ ] /*4*/
|
||||
@@ -0,0 +1,10 @@
|
||||
declare var a;
|
||||
|
||||
a(/*1*/);
|
||||
a(
|
||||
/*first*/
|
||||
// foo
|
||||
/*middle*/
|
||||
// bar
|
||||
/*last*/
|
||||
);
|
||||
@@ -0,0 +1,7 @@
|
||||
// @target: es6
|
||||
declare var a;
|
||||
/*0*/ for /*1*/ ( /*2*/ var /*3*/ x /*4*/ in /*5*/ a /*6*/) /*7*/ {}
|
||||
/*0*/ for /*1*/ ( /*2*/ var /*3*/ y /*4*/ of /*5*/ a /*6*/) /*7*/ {}
|
||||
/*0*/ for /*1*/ ( /*2*/ x /*3*/ in /*4*/ a /*5*/) /*6*/ {}
|
||||
/*0*/ for /*1*/ ( /*2*/ y /*3*/ of /*4*/ a /*5*/) /*6*/ {}
|
||||
/*0*/ for /*1*/ ( /*2*/ a /*3*/ ; /*4*/ a /*5*/ ; /*6*/ a /*7*/) /*8*/ {}
|
||||
@@ -0,0 +1,3 @@
|
||||
/*1*/ if /*2*/ ( /*3*/ true /*4*/ ) /*5*/ {}
|
||||
|
||||
/*1*/ if /*2*/ ( /*3*/ true /*4*/ ) /*5*/ {} /*6*/ else /*7*/ {}
|
||||
@@ -0,0 +1,15 @@
|
||||
// @target: esnext
|
||||
// @filename: include.d.ts
|
||||
declare module "foo";
|
||||
|
||||
// @filename: default.ts
|
||||
/*1*/ export /*2*/ default /*3*/ Array /*4*/;
|
||||
|
||||
// @filename: index.ts
|
||||
/*1*/ import /*2*/ D /*3*/, /*4*/ { /*5*/ A /*6*/, /*7*/ B /*8*/ as /*9*/ C /*10*/ } /*11*/ from /*12*/ "foo";
|
||||
/*1*/ import /*2*/ * /*3*/ as /*4*/ foo /*5*/ from /*6*/ "foo";
|
||||
|
||||
void D, A, C, foo; // Use the variables to prevent ellision
|
||||
|
||||
/*1*/ export /*2*/ { /*3*/ A /*4*/, /*5*/ B /*6*/ as /*7*/ C /*8*/ } /*9*/ from /*10*/ "foo";
|
||||
/*1*/ export /*2*/ * /*3*/ from /*4*/ "foo"
|
||||
@@ -0,0 +1,4 @@
|
||||
/*1*/ new /*2*/ Array /*3*/;
|
||||
/*1*/ typeof /*2*/ Array /*3*/;
|
||||
/*1*/ void /*2*/ Array /*3*/;
|
||||
/*1*/ delete /*2*/ Array.toString /*3*/;
|
||||
@@ -0,0 +1,10 @@
|
||||
/*1*/(/*2*/ "foo" /*3*/)/*4*/
|
||||
;
|
||||
|
||||
// open
|
||||
/*1*/(
|
||||
// next
|
||||
/*2*/"foo"
|
||||
//close
|
||||
/*3*/)/*4*/
|
||||
;
|
||||
@@ -0,0 +1,14 @@
|
||||
/*1*/Array/*2*/./*3*/toString/*4*/
|
||||
|
||||
/*1*/Array
|
||||
/*2*/./*3*/
|
||||
// Single-line comment
|
||||
toString/*4*/
|
||||
|
||||
/*1*/Array/*2*/./*3*/
|
||||
// Single-line comment
|
||||
toString/*4*/
|
||||
|
||||
/*1*/Array
|
||||
// Single-line comment
|
||||
/*2*/./*3*/toString/*4*/
|
||||
@@ -0,0 +1,7 @@
|
||||
/*-1*/ foo /*0*/ : /*1*/ switch /*2*/ ( /*3*/ false /*4*/ ) /*5*/ {
|
||||
/*6*/ case /*7*/ false /*8*/ : /*9*/
|
||||
/*10*/ break /*11*/ foo /*12*/;
|
||||
/*13*/ default /*14*/ : /*15*/
|
||||
/*16*/ case /*17*/ false /*18*/ : /*19*/ { /*20*/
|
||||
/*21*/ } /*22*/
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/*1*/ try /*2*/ { /*3*/
|
||||
/*4*/ throw /*5*/ "no" /*6*/;
|
||||
/*7*/} /*8*/ catch /*9*/ ( /*10*/ e /*11*/ ) /*12*/ { /*13*/
|
||||
|
||||
/*14*/} /*15*/ finally /*16*/ { /*17*/
|
||||
|
||||
/*18*/} /*19*/
|
||||
@@ -0,0 +1,6 @@
|
||||
var a = /*some comment*/ null;
|
||||
var b /*some comment*/ = null;
|
||||
var /*some comment*/ c = null;
|
||||
|
||||
// no space
|
||||
var a=/*some comment*/null;
|
||||
@@ -0,0 +1,3 @@
|
||||
/*a*/ while /*b*/ ( /*c*/ false /*d*/ ) /*e*/ {}
|
||||
|
||||
/*a*/ do /*b*/ {} /*c*/ while /*d*/ ( /*e*/ true /*f*/ );
|
||||
@@ -0,0 +1,2 @@
|
||||
// @ts-ignore
|
||||
/*1*/ with /*2*/ ( /*3*/ false /*4*/ ) /*5*/ {}
|
||||
@@ -0,0 +1,8 @@
|
||||
// @target: es6
|
||||
function * foo2() {
|
||||
/*comment1*/ yield 1;
|
||||
yield /*comment2*/ 2;
|
||||
yield 3 /*comment3*/
|
||||
yield */*comment4*/ [4];
|
||||
yield /*comment5*/* [5];
|
||||
}
|
||||
Reference in new issue
Block a user