-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c00ea2
commit bdb60c6
Showing
18 changed files
with
267 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...-spread/test/fixtures/assumption-setSpreadProperties-with-useBuiltIns/assignment/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var x; | ||
var y; | ||
var z; | ||
|
||
z = { x, ...y }; | ||
|
||
z = { x, w: { ...y } }; |
10 changes: 10 additions & 0 deletions
10
...spread/test/fixtures/assumption-setSpreadProperties-with-useBuiltIns/assignment/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var x; | ||
var y; | ||
var z; | ||
z = Object.assign({ | ||
x | ||
}, y); | ||
z = { | ||
x, | ||
w: Object.assign({}, y) | ||
}; |
9 changes: 9 additions & 0 deletions
9
...t-spread/test/fixtures/assumption-setSpreadProperties-with-useBuiltIns/expression/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var log = []; | ||
|
||
var a = { | ||
...{ get foo() { log.push(1); } }, | ||
get bar() { log.push(2); } | ||
}; | ||
|
||
// Loose mode uses regular Get, not GetOwnProperty. | ||
expect(log).toEqual([1, 2]); |
16 changes: 16 additions & 0 deletions
16
...-spread/test/fixtures/assumption-setSpreadProperties-with-useBuiltIns/expression/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var a; | ||
var b; | ||
var c; | ||
var d; | ||
var x; | ||
var y; | ||
|
||
({ x, ...y, a, ...b, c }); | ||
|
||
({ ...Object.prototype }); | ||
|
||
({ ...{ foo: 'bar' } }); | ||
|
||
({ ...{ foo: 'bar' }, ...{ bar: 'baz' } }); | ||
|
||
({ ...{ get foo () { return 'foo' } } }); |
28 changes: 28 additions & 0 deletions
28
...spread/test/fixtures/assumption-setSpreadProperties-with-useBuiltIns/expression/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var a; | ||
var b; | ||
var c; | ||
var d; | ||
var x; | ||
var y; | ||
Object.assign(Object.assign(Object.assign({ | ||
x | ||
}, y), {}, { | ||
a | ||
}, b), {}, { | ||
c | ||
}); | ||
Object.assign({}, Object.prototype); | ||
Object.assign({}, { | ||
foo: 'bar' | ||
}); | ||
Object.assign(Object.assign({}, { | ||
foo: 'bar' | ||
}), { | ||
bar: 'baz' | ||
}); | ||
Object.assign({}, { | ||
get foo() { | ||
return 'foo'; | ||
} | ||
|
||
}); |
9 changes: 9 additions & 0 deletions
9
...ures/assumption-setSpreadProperties-with-useBuiltIns/no-getOwnPropertyDescriptors/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const oldGOPDs = Object.getOwnPropertyDescriptors; | ||
Object.getOwnPropertyDescriptors = null; | ||
|
||
try { | ||
({ ...{ a: 1 }, b: 1, ...{} }); | ||
} finally { | ||
Object.getOwnPropertyDescriptors = oldGOPDs; | ||
} | ||
|
43 changes: 43 additions & 0 deletions
43
...st/fixtures/assumption-setSpreadProperties-with-useBuiltIns/no-object-assign-exec/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use strict"; | ||
Object.defineProperty(Object.prototype, 'NOSET', { | ||
get(value) { | ||
// noop | ||
}, | ||
}); | ||
|
||
Object.defineProperty(Object.prototype, 'NOWRITE', { | ||
writable: false, | ||
value: 'abc', | ||
}); | ||
|
||
const obj = { 'NOSET': 123 }; | ||
// this won't work as expected if transformed as Object.assign (or equivalent) | ||
// because those trigger object setters (spread don't) | ||
expect(() => { | ||
const objSpread = { ...obj }; | ||
}).toThrow(); | ||
|
||
const obj2 = { 'NOWRITE': 456 }; | ||
// this throws `TypeError: Cannot assign to read only property 'NOWRITE'` | ||
// if transformed as Object.assign (or equivalent) because those use *assignment* for creating properties | ||
// (spread defines them) | ||
expect(() => { | ||
const obj2Spread = { ...obj2 }; | ||
}).toThrow(); | ||
|
||
const KEY = Symbol('key'); | ||
const obj3Spread = { ...{ get foo () { return 'bar' } }, [KEY]: 'symbol' }; | ||
expect(Object.getOwnPropertyDescriptor(obj3Spread, 'foo').value).toBe('bar'); | ||
expect(Object.getOwnPropertyDescriptor(obj3Spread, KEY).value).toBe('symbol'); | ||
|
||
const obj4Spread = { ...Object.prototype }; | ||
expect(Object.getOwnPropertyDescriptor(obj4Spread, 'hasOwnProperty')).toBeUndefined(); | ||
|
||
expect(() => ({ ...null, ...undefined })).not.toThrow(); | ||
|
||
const o = Object.create(null); | ||
o.a = 'foo'; | ||
o.__proto__ = []; | ||
const o2 = { ...o }; | ||
// Loose will do o2.__proto__ = [] | ||
expect(Array.isArray(Object.getPrototypeOf(o2))).toBe(true); |
9 changes: 9 additions & 0 deletions
9
...ct-rest-spread/test/fixtures/assumption-setSpreadProperties-with-useBuiltIns/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"plugins": [ | ||
["external-helpers", { "helperVersion": "7.100.0"}], | ||
["proposal-object-rest-spread", { "useBuiltIns": true }] | ||
], | ||
"assumptions": { | ||
"setSpreadProperties": true | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...posal-object-rest-spread/test/fixtures/assumption-setSpreadProperties/assignment/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var x; | ||
var y; | ||
var z; | ||
|
||
z = { x, ...y }; | ||
|
||
z = { x, w: { ...y } }; |
10 changes: 10 additions & 0 deletions
10
...osal-object-rest-spread/test/fixtures/assumption-setSpreadProperties/assignment/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var x; | ||
var y; | ||
var z; | ||
z = babelHelpers.extends({ | ||
x | ||
}, y); | ||
z = { | ||
x, | ||
w: babelHelpers.extends({}, y) | ||
}; |
9 changes: 9 additions & 0 deletions
9
...oposal-object-rest-spread/test/fixtures/assumption-setSpreadProperties/expression/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var log = []; | ||
|
||
var a = { | ||
...{ get foo() { log.push(1); } }, | ||
get bar() { log.push(2); } | ||
}; | ||
|
||
// Loose mode uses regular Get, not GetOwnProperty. | ||
expect(log).toEqual([1, 2]); |
16 changes: 16 additions & 0 deletions
16
...posal-object-rest-spread/test/fixtures/assumption-setSpreadProperties/expression/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var a; | ||
var b; | ||
var c; | ||
var d; | ||
var x; | ||
var y; | ||
|
||
({ x, ...y, a, ...b, c }); | ||
|
||
({ ...Object.prototype }); | ||
|
||
({ ...{ foo: 'bar' } }); | ||
|
||
({ ...{ foo: 'bar' }, ...{ bar: 'baz' } }); | ||
|
||
({ ...{ get foo () { return 'foo' } } }); |
28 changes: 28 additions & 0 deletions
28
...osal-object-rest-spread/test/fixtures/assumption-setSpreadProperties/expression/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var a; | ||
var b; | ||
var c; | ||
var d; | ||
var x; | ||
var y; | ||
babelHelpers.extends(babelHelpers.extends(babelHelpers.extends({ | ||
x | ||
}, y), {}, { | ||
a | ||
}, b), {}, { | ||
c | ||
}); | ||
babelHelpers.extends({}, Object.prototype); | ||
babelHelpers.extends({}, { | ||
foo: 'bar' | ||
}); | ||
babelHelpers.extends(babelHelpers.extends({}, { | ||
foo: 'bar' | ||
}), { | ||
bar: 'baz' | ||
}); | ||
babelHelpers.extends({}, { | ||
get foo() { | ||
return 'foo'; | ||
} | ||
|
||
}); |
9 changes: 9 additions & 0 deletions
9
...-spread/test/fixtures/assumption-setSpreadProperties/no-getOwnPropertyDescriptors/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const oldGOPDs = Object.getOwnPropertyDescriptors; | ||
Object.getOwnPropertyDescriptors = null; | ||
|
||
try { | ||
({ ...{ a: 1 }, b: 1, ...{} }); | ||
} finally { | ||
Object.getOwnPropertyDescriptors = oldGOPDs; | ||
} | ||
|
43 changes: 43 additions & 0 deletions
43
...ct-rest-spread/test/fixtures/assumption-setSpreadProperties/no-object-assign-exec/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use strict"; | ||
Object.defineProperty(Object.prototype, 'NOSET', { | ||
get(value) { | ||
// noop | ||
}, | ||
}); | ||
|
||
Object.defineProperty(Object.prototype, 'NOWRITE', { | ||
writable: false, | ||
value: 'abc', | ||
}); | ||
|
||
const obj = { 'NOSET': 123 }; | ||
// this won't work as expected if transformed as Object.assign (or equivalent) | ||
// because those trigger object setters (spread don't) | ||
expect(() => { | ||
const objSpread = { ...obj }; | ||
}).toThrow(); | ||
|
||
const obj2 = { 'NOWRITE': 456 }; | ||
// this throws `TypeError: Cannot assign to read only property 'NOWRITE'` | ||
// if transformed as Object.assign (or equivalent) because those use *assignment* for creating properties | ||
// (spread defines them) | ||
expect(() => { | ||
const obj2Spread = { ...obj2 }; | ||
}).toThrow(); | ||
|
||
const KEY = Symbol('key'); | ||
const obj3Spread = { ...{ get foo () { return 'bar' } }, [KEY]: 'symbol' }; | ||
expect(Object.getOwnPropertyDescriptor(obj3Spread, 'foo').value).toBe('bar'); | ||
expect(Object.getOwnPropertyDescriptor(obj3Spread, KEY).value).toBe('symbol'); | ||
|
||
const obj4Spread = { ...Object.prototype }; | ||
expect(Object.getOwnPropertyDescriptor(obj4Spread, 'hasOwnProperty')).toBeUndefined(); | ||
|
||
expect(() => ({ ...null, ...undefined })).not.toThrow(); | ||
|
||
const o = Object.create(null); | ||
o.a = 'foo'; | ||
o.__proto__ = []; | ||
const o2 = { ...o }; | ||
// Loose will do o2.__proto__ = [] | ||
expect(Array.isArray(Object.getPrototypeOf(o2))).toBe(true); |
9 changes: 9 additions & 0 deletions
9
...gin-proposal-object-rest-spread/test/fixtures/assumption-setSpreadProperties/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"plugins": [ | ||
["external-helpers", { "helperVersion": "7.100.0"}], | ||
"proposal-object-rest-spread" | ||
], | ||
"assumptions": { | ||
"setSpreadProperties": true | ||
} | ||
} |