Fix comments after sread expression, spread assignment (#28482)

This commit is contained in:
Aziz Khambati
2018-11-15 03:50:07 +05:30
committed by Wesley Wigham
parent da37457c72
commit 24759b81e6
5 changed files with 593 additions and 2 deletions

View File

@@ -1858,7 +1858,7 @@ namespace ts {
}
function emitSpreadExpression(node: SpreadElement) {
writePunctuation("...");
emitTokenWithComment(SyntaxKind.DotDotDotToken, node.pos, writePunctuation, node);
emitExpression(node.expression);
}
@@ -2715,7 +2715,7 @@ namespace ts {
function emitSpreadAssignment(node: SpreadAssignment) {
if (node.expression) {
writePunctuation("...");
emitTokenWithComment(SyntaxKind.DotDotDotToken, node.pos, writePunctuation, node);
emitExpression(node.expression);
}
}

View File

@@ -0,0 +1,125 @@
//// [commentsAfterSpread.ts]
const identity = (a) => a;
const a = {
.../*#__PURE__*/identity({
b: 1
})
};
const b = {
...
/*#__PURE__*/identity({
b: 1
})
};
const c = {
...
/*#__PURE__*/
identity({
b: 1
})
};
const d = {
.../*#__PURE__*/
identity({
b: 1
})
};
function e (.../* comment e */args) {
const [ea, eb] = [.../* comment eab */args];
return args.length;
}
function f (
first,
.../* comment f */rest
) {
return rest.length;
}
function g (
first,
.../* comment g */
rest
) {
const [ga, gb] = [.../* comment gab */
rest
]
return rest.length;
}
const h = (.../* comment h */args) => args.length;
const i = (
first, .../* comment i */rest
) => rest.length;
const j = (
first,
.../* comment j */
rest
) => rest.length;
function k ({
first,
.../* comment k */rest
}) {
const { ka, kb, .../* comment kr */remaining } = rest;
const {
kc,
kd,
.../* comment kr2 */
remaining2
} = rest;
return { .../* comment return k */ remaining };
}
//// [commentsAfterSpread.js]
const identity = (a) => a;
const a = {
... /*#__PURE__*/identity({
b: 1
})
};
const b = {
...
/*#__PURE__*/ identity({
b: 1
})
};
const c = {
...
/*#__PURE__*/
identity({
b: 1
})
};
const d = {
... /*#__PURE__*/identity({
b: 1
})
};
function e(... /* comment e */args) {
const [ea, eb] = [... /* comment eab */args];
return args.length;
}
function f(first, ... /* comment f */rest) {
return rest.length;
}
function g(first, ... /* comment g */rest) {
const [ga, gb] = [... /* comment gab */rest
];
return rest.length;
}
const h = (... /* comment h */args) => args.length;
const i = (first, ... /* comment i */rest) => rest.length;
const j = (first, ... /* comment j */rest) => rest.length;
function k({ first, ... /* comment k */rest }) {
const { ka, kb, ... /* comment kr */remaining } = rest;
const { kc, kd, ... /* comment kr2 */remaining2 } = rest;
return { ... /* comment return k */remaining };
}

View File

@@ -0,0 +1,181 @@
=== tests/cases/compiler/commentsAfterSpread.ts ===
const identity = (a) => a;
>identity : Symbol(identity, Decl(commentsAfterSpread.ts, 0, 5))
>a : Symbol(a, Decl(commentsAfterSpread.ts, 0, 18))
>a : Symbol(a, Decl(commentsAfterSpread.ts, 0, 18))
const a = {
>a : Symbol(a, Decl(commentsAfterSpread.ts, 2, 5))
.../*#__PURE__*/identity({
>identity : Symbol(identity, Decl(commentsAfterSpread.ts, 0, 5))
b: 1
>b : Symbol(b, Decl(commentsAfterSpread.ts, 3, 28))
})
};
const b = {
>b : Symbol(b, Decl(commentsAfterSpread.ts, 8, 5))
...
/*#__PURE__*/identity({
>identity : Symbol(identity, Decl(commentsAfterSpread.ts, 0, 5))
b: 1
>b : Symbol(b, Decl(commentsAfterSpread.ts, 10, 25))
})
};
const c = {
>c : Symbol(c, Decl(commentsAfterSpread.ts, 15, 5))
...
/*#__PURE__*/
identity({
>identity : Symbol(identity, Decl(commentsAfterSpread.ts, 0, 5))
b: 1
>b : Symbol(b, Decl(commentsAfterSpread.ts, 18, 12))
})
};
const d = {
>d : Symbol(d, Decl(commentsAfterSpread.ts, 23, 5))
.../*#__PURE__*/
identity({
>identity : Symbol(identity, Decl(commentsAfterSpread.ts, 0, 5))
b: 1
>b : Symbol(b, Decl(commentsAfterSpread.ts, 25, 12))
})
};
function e (.../* comment e */args) {
>e : Symbol(e, Decl(commentsAfterSpread.ts, 28, 2))
>args : Symbol(args, Decl(commentsAfterSpread.ts, 30, 12))
const [ea, eb] = [.../* comment eab */args];
>ea : Symbol(ea, Decl(commentsAfterSpread.ts, 31, 9))
>eb : Symbol(eb, Decl(commentsAfterSpread.ts, 31, 12))
>args : Symbol(args, Decl(commentsAfterSpread.ts, 30, 12))
return args.length;
>args.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
>args : Symbol(args, Decl(commentsAfterSpread.ts, 30, 12))
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
}
function f (
>f : Symbol(f, Decl(commentsAfterSpread.ts, 33, 1))
first,
>first : Symbol(first, Decl(commentsAfterSpread.ts, 35, 12))
.../* comment f */rest
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 36, 8))
) {
return rest.length;
>rest.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 36, 8))
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
}
function g (
>g : Symbol(g, Decl(commentsAfterSpread.ts, 40, 1))
first,
>first : Symbol(first, Decl(commentsAfterSpread.ts, 42, 12))
.../* comment g */
rest
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 43, 8))
) {
const [ga, gb] = [.../* comment gab */
>ga : Symbol(ga, Decl(commentsAfterSpread.ts, 47, 9))
>gb : Symbol(gb, Decl(commentsAfterSpread.ts, 47, 12))
rest
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 43, 8))
]
return rest.length;
>rest.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 43, 8))
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
}
const h = (.../* comment h */args) => args.length;
>h : Symbol(h, Decl(commentsAfterSpread.ts, 53, 5))
>args : Symbol(args, Decl(commentsAfterSpread.ts, 53, 11))
>args.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
>args : Symbol(args, Decl(commentsAfterSpread.ts, 53, 11))
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
const i = (
>i : Symbol(i, Decl(commentsAfterSpread.ts, 55, 5))
first, .../* comment i */rest
>first : Symbol(first, Decl(commentsAfterSpread.ts, 55, 11))
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 56, 8))
) => rest.length;
>rest.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 56, 8))
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
const j = (
>j : Symbol(j, Decl(commentsAfterSpread.ts, 59, 5))
first,
>first : Symbol(first, Decl(commentsAfterSpread.ts, 59, 11))
.../* comment j */
rest
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 60, 8))
) => rest.length;
>rest.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 60, 8))
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
function k ({
>k : Symbol(k, Decl(commentsAfterSpread.ts, 63, 17))
first,
>first : Symbol(first, Decl(commentsAfterSpread.ts, 65, 13))
.../* comment k */rest
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 66, 8))
}) {
const { ka, kb, .../* comment kr */remaining } = rest;
>ka : Symbol(ka, Decl(commentsAfterSpread.ts, 69, 9))
>kb : Symbol(kb, Decl(commentsAfterSpread.ts, 69, 13))
>remaining : Symbol(remaining, Decl(commentsAfterSpread.ts, 69, 17))
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 66, 8))
const {
kc,
>kc : Symbol(kc, Decl(commentsAfterSpread.ts, 70, 9))
kd,
>kd : Symbol(kd, Decl(commentsAfterSpread.ts, 71, 7))
.../* comment kr2 */
remaining2
>remaining2 : Symbol(remaining2, Decl(commentsAfterSpread.ts, 72, 7))
} = rest;
>rest : Symbol(rest, Decl(commentsAfterSpread.ts, 66, 8))
return { .../* comment return k */ remaining };
>remaining : Symbol(remaining, Decl(commentsAfterSpread.ts, 69, 17))
}

View File

@@ -0,0 +1,206 @@
=== tests/cases/compiler/commentsAfterSpread.ts ===
const identity = (a) => a;
>identity : (a: any) => any
>(a) => a : (a: any) => any
>a : any
>a : any
const a = {
>a : any
>{ .../*#__PURE__*/identity({ b: 1 })} : any
.../*#__PURE__*/identity({
>identity({ b: 1 }) : any
>identity : (a: any) => any
>{ b: 1 } : { b: number; }
b: 1
>b : number
>1 : 1
})
};
const b = {
>b : any
>{ ... /*#__PURE__*/identity({ b: 1 })} : any
...
/*#__PURE__*/identity({
>identity({ b: 1 }) : any
>identity : (a: any) => any
>{ b: 1 } : { b: number; }
b: 1
>b : number
>1 : 1
})
};
const c = {
>c : any
>{ ... /*#__PURE__*/ identity({ b: 1 })} : any
...
/*#__PURE__*/
identity({
>identity({ b: 1 }) : any
>identity : (a: any) => any
>{ b: 1 } : { b: number; }
b: 1
>b : number
>1 : 1
})
};
const d = {
>d : any
>{ .../*#__PURE__*/ identity({ b: 1 })} : any
.../*#__PURE__*/
identity({
>identity({ b: 1 }) : any
>identity : (a: any) => any
>{ b: 1 } : { b: number; }
b: 1
>b : number
>1 : 1
})
};
function e (.../* comment e */args) {
>e : (...args: any[]) => number
>args : any[]
const [ea, eb] = [.../* comment eab */args];
>ea : any
>eb : any
>[.../* comment eab */args] : any[]
>.../* comment eab */args : any
>args : any[]
return args.length;
>args.length : number
>args : any[]
>length : number
}
function f (
>f : (first: any, ...rest: any[]) => number
first,
>first : any
.../* comment f */rest
>rest : any[]
) {
return rest.length;
>rest.length : number
>rest : any[]
>length : number
}
function g (
>g : (first: any, ...rest: any[]) => number
first,
>first : any
.../* comment g */
rest
>rest : any[]
) {
const [ga, gb] = [.../* comment gab */
>ga : any
>gb : any
>[.../* comment gab */ rest ] : any[]
>.../* comment gab */ rest : any
rest
>rest : any[]
]
return rest.length;
>rest.length : number
>rest : any[]
>length : number
}
const h = (.../* comment h */args) => args.length;
>h : (...args: any[]) => number
>(.../* comment h */args) => args.length : (...args: any[]) => number
>args : any[]
>args.length : number
>args : any[]
>length : number
const i = (
>i : (first: any, ...rest: any[]) => number
>( first, .../* comment i */rest) => rest.length : (first: any, ...rest: any[]) => number
first, .../* comment i */rest
>first : any
>rest : any[]
) => rest.length;
>rest.length : number
>rest : any[]
>length : number
const j = (
>j : (first: any, ...rest: any[]) => number
>( first, .../* comment j */ rest) => rest.length : (first: any, ...rest: any[]) => number
first,
>first : any
.../* comment j */
rest
>rest : any[]
) => rest.length;
>rest.length : number
>rest : any[]
>length : number
function k ({
>k : ({ first, ...rest }: { [x: string]: any; first: any; }) => { [x: string]: any; }
first,
>first : any
.../* comment k */rest
>rest : { [x: string]: any; }
}) {
const { ka, kb, .../* comment kr */remaining } = rest;
>ka : any
>kb : any
>remaining : { [x: string]: any; }
>rest : { [x: string]: any; }
const {
kc,
>kc : any
kd,
>kd : any
.../* comment kr2 */
remaining2
>remaining2 : { [x: string]: any; }
} = rest;
>rest : { [x: string]: any; }
return { .../* comment return k */ remaining };
>{ .../* comment return k */ remaining } : { [x: string]: any; }
>remaining : { [x: string]: any; }
}

View File

@@ -0,0 +1,79 @@
// @target: ESNEXT
const identity = (a) => a;
const a = {
.../*#__PURE__*/identity({
b: 1
})
};
const b = {
...
/*#__PURE__*/identity({
b: 1
})
};
const c = {
...
/*#__PURE__*/
identity({
b: 1
})
};
const d = {
.../*#__PURE__*/
identity({
b: 1
})
};
function e (.../* comment e */args) {
const [ea, eb] = [.../* comment eab */args];
return args.length;
}
function f (
first,
.../* comment f */rest
) {
return rest.length;
}
function g (
first,
.../* comment g */
rest
) {
const [ga, gb] = [.../* comment gab */
rest
]
return rest.length;
}
const h = (.../* comment h */args) => args.length;
const i = (
first, .../* comment i */rest
) => rest.length;
const j = (
first,
.../* comment j */
rest
) => rest.length;
function k ({
first,
.../* comment k */rest
}) {
const { ka, kb, .../* comment kr */remaining } = rest;
const {
kc,
kd,
.../* comment kr2 */
remaining2
} = rest;
return { .../* comment return k */ remaining };
}