mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 20:32:44 +00:00 
			
		
		
		
	 3ceedbd16a
			
		
	
	
		3ceedbd16a
		
	
	
	
	
		
			
			See: https://tc39.es/ecma262/#sec-runtime-semantics-propertydefinitionevaluation PropertyDefinition : ... AssignmentExpression Also add a test for this in array spreading, which already had this in place.
		
			
				
	
	
		
			45 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| describe("errors", () => {
 | |
|     test("cannot spread number in array", () => {
 | |
|         expect(() => {
 | |
|             [...1];
 | |
|         }).toThrowWithMessage(TypeError, "1 is not iterable");
 | |
|     });
 | |
| 
 | |
|     test("cannot spread object in array", () => {
 | |
|         expect(() => {
 | |
|             [...{}];
 | |
|         }).toThrowWithMessage(TypeError, "[object Object] is not iterable");
 | |
|     });
 | |
| });
 | |
| 
 | |
| test("basic functionality", () => {
 | |
|     expect([1, ...[2, 3], 4]).toEqual([1, 2, 3, 4]);
 | |
| 
 | |
|     let a = [2, 3];
 | |
|     expect([1, ...a, 4]).toEqual([1, 2, 3, 4]);
 | |
| 
 | |
|     let obj = { a: [2, 3] };
 | |
|     expect([1, ...obj.a, 4]).toEqual([1, 2, 3, 4]);
 | |
| 
 | |
|     expect([...[], ...[...[1, 2, 3]], 4]).toEqual([1, 2, 3, 4]);
 | |
| });
 | |
| 
 | |
| test("allows assignment expressions", () => {
 | |
|     expect("([ ...a = { hello: 'world' } ])").toEval();
 | |
|     expect("([ ...a += 'hello' ])").toEval();
 | |
|     expect("([ ...a -= 'hello' ])").toEval();
 | |
|     expect("([ ...a **= 'hello' ])").toEval();
 | |
|     expect("([ ...a *= 'hello' ])").toEval();
 | |
|     expect("([ ...a /= 'hello' ])").toEval();
 | |
|     expect("([ ...a %= 'hello' ])").toEval();
 | |
|     expect("([ ...a <<= 'hello' ])").toEval();
 | |
|     expect("([ ...a >>= 'hello' ])").toEval();
 | |
|     expect("([ ...a >>>= 'hello' ])").toEval();
 | |
|     expect("([ ...a &= 'hello' ])").toEval();
 | |
|     expect("([ ...a ^= 'hello' ])").toEval();
 | |
|     expect("([ ...a |= 'hello' ])").toEval();
 | |
|     expect("([ ...a &&= 'hello' ])").toEval();
 | |
|     expect("([ ...a ||= 'hello' ])").toEval();
 | |
|     expect("([ ...a ??= 'hello' ])").toEval();
 | |
|     expect("function* test() { return ([ ...yield a ]); }").toEval();
 | |
| });
 |