Skip to content

Commit b2199bd

Browse files
committed
Test:order of directives, initialisers, object spread destructuring
1 parent 5496096 commit b2199bd

4 files changed

Lines changed: 171 additions & 0 deletions
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//// [parameterInitializerBeforeDestructuringEmit.ts]
2+
interface Foo {
3+
bar?: any;
4+
baz?: any;
5+
}
6+
7+
function foobar({ bar = {}, ...opts }: Foo = {}) {
8+
"use strict";
9+
"Some other prologue";
10+
opts.baz(bar);
11+
}
12+
13+
class C {
14+
constructor({ bar = {}, ...opts }: Foo = {}) {
15+
"use strict";
16+
"Some other prologue";
17+
opts.baz(bar);
18+
}
19+
}
20+
21+
22+
//// [parameterInitializerBeforeDestructuringEmit.js]
23+
"use strict";
24+
var __rest = (this && this.__rest) || function (s, e) {
25+
var t = {};
26+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
27+
t[p] = s[p];
28+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
29+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
30+
t[p[i]] = s[p[i]];
31+
return t;
32+
};
33+
function foobar(_a) {
34+
"use strict";
35+
"Some other prologue";
36+
if (_a === void 0) { _a = {}; }
37+
var _b = _a.bar, bar = _b === void 0 ? {} : _b, opts = __rest(_a, ["bar"]);
38+
opts.baz(bar);
39+
}
40+
var C = (function () {
41+
function C(_a) {
42+
"use strict";
43+
"Some other prologue";
44+
if (_a === void 0) { _a = {}; }
45+
var _b = _a.bar, bar = _b === void 0 ? {} : _b, opts = __rest(_a, ["bar"]);
46+
opts.baz(bar);
47+
}
48+
return C;
49+
}());
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
=== tests/cases/compiler/parameterInitializerBeforeDestructuringEmit.ts ===
2+
interface Foo {
3+
>Foo : Symbol(Foo, Decl(parameterInitializerBeforeDestructuringEmit.ts, 0, 0))
4+
5+
bar?: any;
6+
>bar : Symbol(Foo.bar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 0, 15))
7+
8+
baz?: any;
9+
>baz : Symbol(Foo.baz, Decl(parameterInitializerBeforeDestructuringEmit.ts, 1, 14))
10+
}
11+
12+
function foobar({ bar = {}, ...opts }: Foo = {}) {
13+
>foobar : Symbol(foobar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 3, 1))
14+
>bar : Symbol(bar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 5, 17))
15+
>opts : Symbol(opts, Decl(parameterInitializerBeforeDestructuringEmit.ts, 5, 27))
16+
>Foo : Symbol(Foo, Decl(parameterInitializerBeforeDestructuringEmit.ts, 0, 0))
17+
18+
"use strict";
19+
"Some other prologue";
20+
opts.baz(bar);
21+
>opts.baz : Symbol(Foo.baz, Decl(parameterInitializerBeforeDestructuringEmit.ts, 1, 14))
22+
>opts : Symbol(opts, Decl(parameterInitializerBeforeDestructuringEmit.ts, 5, 27))
23+
>baz : Symbol(Foo.baz, Decl(parameterInitializerBeforeDestructuringEmit.ts, 1, 14))
24+
>bar : Symbol(bar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 5, 17))
25+
}
26+
27+
class C {
28+
>C : Symbol(C, Decl(parameterInitializerBeforeDestructuringEmit.ts, 9, 1))
29+
30+
constructor({ bar = {}, ...opts }: Foo = {}) {
31+
>bar : Symbol(bar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 12, 17))
32+
>opts : Symbol(opts, Decl(parameterInitializerBeforeDestructuringEmit.ts, 12, 27))
33+
>Foo : Symbol(Foo, Decl(parameterInitializerBeforeDestructuringEmit.ts, 0, 0))
34+
35+
"use strict";
36+
"Some other prologue";
37+
opts.baz(bar);
38+
>opts.baz : Symbol(Foo.baz, Decl(parameterInitializerBeforeDestructuringEmit.ts, 1, 14))
39+
>opts : Symbol(opts, Decl(parameterInitializerBeforeDestructuringEmit.ts, 12, 27))
40+
>baz : Symbol(Foo.baz, Decl(parameterInitializerBeforeDestructuringEmit.ts, 1, 14))
41+
>bar : Symbol(bar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 12, 17))
42+
}
43+
}
44+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
=== tests/cases/compiler/parameterInitializerBeforeDestructuringEmit.ts ===
2+
interface Foo {
3+
>Foo : Foo
4+
5+
bar?: any;
6+
>bar : any
7+
8+
baz?: any;
9+
>baz : any
10+
}
11+
12+
function foobar({ bar = {}, ...opts }: Foo = {}) {
13+
>foobar : ({bar, ...opts}?: Foo) => void
14+
>bar : any
15+
>{} : {}
16+
>opts : { baz?: any; }
17+
>Foo : Foo
18+
>{} : {}
19+
20+
"use strict";
21+
>"use strict" : "use strict"
22+
23+
"Some other prologue";
24+
>"Some other prologue" : "Some other prologue"
25+
26+
opts.baz(bar);
27+
>opts.baz(bar) : any
28+
>opts.baz : any
29+
>opts : { baz?: any; }
30+
>baz : any
31+
>bar : any
32+
}
33+
34+
class C {
35+
>C : C
36+
37+
constructor({ bar = {}, ...opts }: Foo = {}) {
38+
>bar : any
39+
>{} : {}
40+
>opts : { baz?: any; }
41+
>Foo : Foo
42+
>{} : {}
43+
44+
"use strict";
45+
>"use strict" : "use strict"
46+
47+
"Some other prologue";
48+
>"Some other prologue" : "Some other prologue"
49+
50+
opts.baz(bar);
51+
>opts.baz(bar) : any
52+
>opts.baz : any
53+
>opts : { baz?: any; }
54+
>baz : any
55+
>bar : any
56+
}
57+
}
58+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @noImplicitUseStrict: false
2+
// @alwaysStrict: true
3+
interface Foo {
4+
bar?: any;
5+
baz?: any;
6+
}
7+
8+
function foobar({ bar = {}, ...opts }: Foo = {}) {
9+
"use strict";
10+
"Some other prologue";
11+
opts.baz(bar);
12+
}
13+
14+
class C {
15+
constructor({ bar = {}, ...opts }: Foo = {}) {
16+
"use strict";
17+
"Some other prologue";
18+
opts.baz(bar);
19+
}
20+
}

0 commit comments

Comments
 (0)