diff --git a/tsc/internal/transformers/estransforms/esdecorator.go b/tsc/internal/transformers/estransforms/esdecorator.go index dc2e6edee8a4d..c84b40a279adf 100644 --- a/tsc/internal/transformers/estransforms/esdecorator.go +++ b/tsc/internal/transformers/estransforms/esdecorator.go @@ -2198,7 +2198,6 @@ func (tx *esDecoratorTransformer) visitAssignmentRestElement(node *ast.Node) *as } func (tx *esDecoratorTransformer) visitArrayAssignmentElement(node *ast.Node) *ast.Node { - debug.Assert(ast.IsArrayBindingOrAssignmentElement(node)) if ast.IsSpreadElement(node) { return tx.visitAssignmentRestElement(node) } diff --git a/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.errors.txt b/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.errors.txt new file mode 100644 index 0000000000000..c2721c0d30269 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.errors.txt @@ -0,0 +1,21 @@ +malformedSuperDestructuringInDecoratedClassStaticBlock.ts(1,3): error TS2304: Cannot find name 'c'. +malformedSuperDestructuringInDecoratedClassStaticBlock.ts(2,15): error TS2304: Cannot find name 'B'. +malformedSuperDestructuringInDecoratedClassStaticBlock.ts(2,33): error TS1005: ',' expected. +malformedSuperDestructuringInDecoratedClassStaticBlock.ts(2,33): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +malformedSuperDestructuringInDecoratedClassStaticBlock.ts(2,33): error TS2493: Tuple type '[number]' of length '1' has no element at index '1'. + + +==== malformedSuperDestructuringInDecoratedClassStaticBlock.ts (5 errors) ==== + (@c + ~ +!!! error TS2304: Cannot find name 'c'. + class extends B{static{[super.x 0]=[1];}}); + ~ +!!! error TS2304: Cannot find name 'B'. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. + ~ +!!! error TS2493: Tuple type '[number]' of length '1' has no element at index '1'. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.js b/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.js new file mode 100644 index 0000000000000..f5ec3c111a55b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.js @@ -0,0 +1,69 @@ +//// [tests/cases/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.ts] //// + +//// [malformedSuperDestructuringInDecoratedClassStaticBlock.ts] +(@c +class extends B{static{[super.x 0]=[1];}}); + + +//// [malformedSuperDestructuringInDecoratedClassStaticBlock.js] +"use strict"; +var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { + function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } + var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; + var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; + var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); + var _, done = false; + for (var i = decorators.length - 1; i >= 0; i--) { + var context = {}; + for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; + for (var p in contextIn.access) context.access[p] = contextIn.access[p]; + context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; + var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); + if (kind === "accessor") { + if (result === void 0) continue; + if (result === null || typeof result !== "object") throw new TypeError("Object expected"); + if (_ = accept(result.get)) descriptor.get = _; + if (_ = accept(result.set)) descriptor.set = _; + if (_ = accept(result.init)) initializers.unshift(_); + } + else if (_ = accept(result)) { + if (kind === "field") initializers.unshift(_); + else descriptor[key] = _; + } + } + if (target) Object.defineProperty(target, contextIn.name, descriptor); + done = true; +}; +var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { + var useValue = arguments.length > 2; + for (var i = 0; i < initializers.length; i++) { + value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); + } + return useValue ? value : void 0; +}; +var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) { + if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : ""; + return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name }); +}; +((() => { + let _classDecorators = [c]; + let _classDescriptor; + let _classExtraInitializers = []; + let _classThis; + let _classSuper = B; + var class_1 = class extends _classSuper { + static { _classThis = this; } + static { __setFunctionName(_classThis, ""); } + static { + const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; + __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); + class_1 = _classThis = _classDescriptor.value; + if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); + } + static { [({ set value(_a) { Reflect.set(_classSuper, "x", _a, _classThis); } }).value, 0] = [1]; } + static { + __runInitializers(_classThis, _classExtraInitializers); + } + }; + return class_1 = _classThis; +})()); diff --git a/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.symbols b/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.symbols new file mode 100644 index 0000000000000..2236e58a24f6a --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.symbols @@ -0,0 +1,7 @@ +//// [tests/cases/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.ts] //// + +=== malformedSuperDestructuringInDecoratedClassStaticBlock.ts === + +(@c +class extends B{static{[super.x 0]=[1];}}); + diff --git a/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.types b/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.types new file mode 100644 index 0000000000000..5275e4b12feec --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.types @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.ts] //// + +=== malformedSuperDestructuringInDecoratedClassStaticBlock.ts === +(@c +>(@cclass extends B{static{[super.x 0]=[1];}}) : typeof (Anonymous class) +>@cclass extends B{static{[super.x 0]=[1];}} : typeof (Anonymous class) +>c : any + +class extends B{static{[super.x 0]=[1];}}); +>B : any +>[super.x 0]=[1] : [number] +>[super.x 0] : [any, number] +>super.x : any +>super : any +>x : any +>0 : 0 +>[1] : [number] +>1 : 1 + diff --git a/tsc/testdata/tests/cases/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.ts b/tsc/testdata/tests/cases/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.ts new file mode 100644 index 0000000000000..94a90e170fbc7 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/malformedSuperDestructuringInDecoratedClassStaticBlock.ts @@ -0,0 +1,4 @@ +// @target: es2022 + +(@c +class extends B{static{[super.x 0]=[1];}});