1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16// Object destructuring 17let { a, b, c } = { a: 100, b: 200, c: 'bar' }; // NOT OK 18let { a2, ...rest2 } = { a2: 1, b2: 2 }; // NOT OK 19let { a3, b3: { c3, d3: e3 } } = { a3: 1, b3: { c3: 3, d3: 'baz' }}; // NOT OK 20let { a4, b4: { ...rest4 } } = { a4: 1, b4: { c4: 3, d4: 'bah' }}; // NOT OK 21 22function getObject() { 23 return { a5: 1, b5: 2 }; 24} 25let { a5, b5 } = getObject(); // NOT OK 26 27// Array destructuring 28const [a6, b6, c6] = [10, 20, 30]; 29const [a7, b7, ...rest7] = [10, 20, 30, 40, 50]; // NOT OK 30const [a8, b8, [c8, e8]] = [10, 20, [300, 400], 50]; 31const [a9, b9, [c9, ...rest9]] = [10, 20, [30, 40, 50]]; // NOT OK 32 33let tuple: [number, string, number] = [1, '2', 3]; 34let [a10, , b10] = tuple; 35let [a11, ...rest11] = tuple; // NOT OK 36 37const getArray = (): number[] => [1, 2, 3]; 38let [a12, b12] = getArray(); 39 40const set: Set<number> = new Set([1, 2, 3, 4]); 41let [a13, b13, c13] = set; // NOT OK 42 43const map: Map<number, number> = new Map(); 44let [[a14, b14], [c14, d14]] = map; // NOT OK 45 46// Mixed destructuring 47let [a15, b15, [x15, { f15 }]] = [1, 2, [{ e15: 20 }, { f15: 5 }]]; // NOT OK 48let [a16, b16, {e16, e16: f16, ...g16}] = [1, 2, {e16: 10}]; // NOT OK 49{ let [a17, b17, ...{length}] = [1, 2, 3, 4]; } // NOT OK 50 51let { a18, b18: [c18, d18] } = { a18: 1, b18: [2, 3] }; // NOT OK 52let { 53 a19, 54 b19: { 55 c19, 56 d19: [e19, f19], 57 }, 58} = { a19: 10, b19: { c19: 'foo', d19: [30, 40] } }; // NOT OK 59