Test:order of directives, initialisers, object spread destructuring

This commit is contained in:
Nathan Shively-Sanders 2017-04-13 10:35:50 -07:00
parent 5496096ee3
commit b2199bd23c
4 changed files with 171 additions and 0 deletions

View File

@ -0,0 +1,49 @@
//// [parameterInitializerBeforeDestructuringEmit.ts]
interface Foo {
bar?: any;
baz?: any;
}
function foobar({ bar = {}, ...opts }: Foo = {}) {
"use strict";
"Some other prologue";
opts.baz(bar);
}
class C {
constructor({ bar = {}, ...opts }: Foo = {}) {
"use strict";
"Some other prologue";
opts.baz(bar);
}
}
//// [parameterInitializerBeforeDestructuringEmit.js]
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
function foobar(_a) {
"use strict";
"Some other prologue";
if (_a === void 0) { _a = {}; }
var _b = _a.bar, bar = _b === void 0 ? {} : _b, opts = __rest(_a, ["bar"]);
opts.baz(bar);
}
var C = (function () {
function C(_a) {
"use strict";
"Some other prologue";
if (_a === void 0) { _a = {}; }
var _b = _a.bar, bar = _b === void 0 ? {} : _b, opts = __rest(_a, ["bar"]);
opts.baz(bar);
}
return C;
}());

View File

@ -0,0 +1,44 @@
=== tests/cases/compiler/parameterInitializerBeforeDestructuringEmit.ts ===
interface Foo {
>Foo : Symbol(Foo, Decl(parameterInitializerBeforeDestructuringEmit.ts, 0, 0))
bar?: any;
>bar : Symbol(Foo.bar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 0, 15))
baz?: any;
>baz : Symbol(Foo.baz, Decl(parameterInitializerBeforeDestructuringEmit.ts, 1, 14))
}
function foobar({ bar = {}, ...opts }: Foo = {}) {
>foobar : Symbol(foobar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 3, 1))
>bar : Symbol(bar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 5, 17))
>opts : Symbol(opts, Decl(parameterInitializerBeforeDestructuringEmit.ts, 5, 27))
>Foo : Symbol(Foo, Decl(parameterInitializerBeforeDestructuringEmit.ts, 0, 0))
"use strict";
"Some other prologue";
opts.baz(bar);
>opts.baz : Symbol(Foo.baz, Decl(parameterInitializerBeforeDestructuringEmit.ts, 1, 14))
>opts : Symbol(opts, Decl(parameterInitializerBeforeDestructuringEmit.ts, 5, 27))
>baz : Symbol(Foo.baz, Decl(parameterInitializerBeforeDestructuringEmit.ts, 1, 14))
>bar : Symbol(bar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 5, 17))
}
class C {
>C : Symbol(C, Decl(parameterInitializerBeforeDestructuringEmit.ts, 9, 1))
constructor({ bar = {}, ...opts }: Foo = {}) {
>bar : Symbol(bar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 12, 17))
>opts : Symbol(opts, Decl(parameterInitializerBeforeDestructuringEmit.ts, 12, 27))
>Foo : Symbol(Foo, Decl(parameterInitializerBeforeDestructuringEmit.ts, 0, 0))
"use strict";
"Some other prologue";
opts.baz(bar);
>opts.baz : Symbol(Foo.baz, Decl(parameterInitializerBeforeDestructuringEmit.ts, 1, 14))
>opts : Symbol(opts, Decl(parameterInitializerBeforeDestructuringEmit.ts, 12, 27))
>baz : Symbol(Foo.baz, Decl(parameterInitializerBeforeDestructuringEmit.ts, 1, 14))
>bar : Symbol(bar, Decl(parameterInitializerBeforeDestructuringEmit.ts, 12, 17))
}
}

View File

@ -0,0 +1,58 @@
=== tests/cases/compiler/parameterInitializerBeforeDestructuringEmit.ts ===
interface Foo {
>Foo : Foo
bar?: any;
>bar : any
baz?: any;
>baz : any
}
function foobar({ bar = {}, ...opts }: Foo = {}) {
>foobar : ({bar, ...opts}?: Foo) => void
>bar : any
>{} : {}
>opts : { baz?: any; }
>Foo : Foo
>{} : {}
"use strict";
>"use strict" : "use strict"
"Some other prologue";
>"Some other prologue" : "Some other prologue"
opts.baz(bar);
>opts.baz(bar) : any
>opts.baz : any
>opts : { baz?: any; }
>baz : any
>bar : any
}
class C {
>C : C
constructor({ bar = {}, ...opts }: Foo = {}) {
>bar : any
>{} : {}
>opts : { baz?: any; }
>Foo : Foo
>{} : {}
"use strict";
>"use strict" : "use strict"
"Some other prologue";
>"Some other prologue" : "Some other prologue"
opts.baz(bar);
>opts.baz(bar) : any
>opts.baz : any
>opts : { baz?: any; }
>baz : any
>bar : any
}
}

View File

@ -0,0 +1,20 @@
// @noImplicitUseStrict: false
// @alwaysStrict: true
interface Foo {
bar?: any;
baz?: any;
}
function foobar({ bar = {}, ...opts }: Foo = {}) {
"use strict";
"Some other prologue";
opts.baz(bar);
}
class C {
constructor({ bar = {}, ...opts }: Foo = {}) {
"use strict";
"Some other prologue";
opts.baz(bar);
}
}