diff --git a/tsc/internal/transformers/utilities.go b/tsc/internal/transformers/utilities.go index af826b85a6c20..a3954a039c736 100644 --- a/tsc/internal/transformers/utilities.go +++ b/tsc/internal/transformers/utilities.go @@ -134,7 +134,7 @@ func convertBindingElementToArrayAssignmentElement(emitContext *printer.EmitCont func convertBindingElementToObjectAssignmentElement(emitContext *printer.EmitContext, element *ast.BindingElement) *ast.ObjectLiteralElement { if element.DotDotDotToken != nil { - spread := emitContext.Factory.NewSpreadAssignment(element.Name()) + spread := emitContext.Factory.NewSpreadAssignment(convertBindingNameToAssignmentElementTarget(emitContext, element.Name())) emitContext.SetOriginal(spread, element.AsNode()) emitContext.AssignCommentAndSourceMapRanges(spread, element.AsNode()) return spread diff --git a/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).errors.txt b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).errors.txt new file mode 100644 index 0000000000000..0fa935fc77566 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).errors.txt @@ -0,0 +1,9 @@ +commonjsExportNestedRestBinding.ts(2,18): error TS1003: Identifier expected. + + +==== commonjsExportNestedRestBinding.ts (1 errors) ==== + declare const source: any; + export const {...{object}} = source; + ~ +!!! error TS1003: Identifier expected. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).js b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).js new file mode 100644 index 0000000000000..281d4a95c92a4 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/commonjsExportNestedRestBinding.ts] //// + +//// [commonjsExportNestedRestBinding.ts] +declare const source: any; +export const {...{object}} = source; + + +//// [commonjsExportNestedRestBinding.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.object = void 0; +({ ...{ object: exports.object } } = source); diff --git a/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).symbols b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).symbols new file mode 100644 index 0000000000000..8857b19f93ad8 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).symbols @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/commonjsExportNestedRestBinding.ts] //// + +=== commonjsExportNestedRestBinding.ts === +declare const source: any; +>source : Symbol(source, Decl(commonjsExportNestedRestBinding.ts, 0, 13)) + +export const {...{object}} = source; +>object : Symbol(object, Decl(commonjsExportNestedRestBinding.ts, 1, 18)) +>source : Symbol(source, Decl(commonjsExportNestedRestBinding.ts, 0, 13)) + diff --git a/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).types b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).types new file mode 100644 index 0000000000000..a869d0743426f --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=es2018).types @@ -0,0 +1,11 @@ +//// [tests/cases/compiler/commonjsExportNestedRestBinding.ts] //// + +=== commonjsExportNestedRestBinding.ts === +declare const source: any; +>source : any + +export const {...{object}} = source; +> : any +>object : any +>source : any + diff --git a/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).errors.txt b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).errors.txt new file mode 100644 index 0000000000000..0fa935fc77566 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).errors.txt @@ -0,0 +1,9 @@ +commonjsExportNestedRestBinding.ts(2,18): error TS1003: Identifier expected. + + +==== commonjsExportNestedRestBinding.ts (1 errors) ==== + declare const source: any; + export const {...{object}} = source; + ~ +!!! error TS1003: Identifier expected. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).js b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).js new file mode 100644 index 0000000000000..281d4a95c92a4 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/commonjsExportNestedRestBinding.ts] //// + +//// [commonjsExportNestedRestBinding.ts] +declare const source: any; +export const {...{object}} = source; + + +//// [commonjsExportNestedRestBinding.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.object = void 0; +({ ...{ object: exports.object } } = source); diff --git a/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).symbols b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).symbols new file mode 100644 index 0000000000000..8857b19f93ad8 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).symbols @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/commonjsExportNestedRestBinding.ts] //// + +=== commonjsExportNestedRestBinding.ts === +declare const source: any; +>source : Symbol(source, Decl(commonjsExportNestedRestBinding.ts, 0, 13)) + +export const {...{object}} = source; +>object : Symbol(object, Decl(commonjsExportNestedRestBinding.ts, 1, 18)) +>source : Symbol(source, Decl(commonjsExportNestedRestBinding.ts, 0, 13)) + diff --git a/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).types b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).types new file mode 100644 index 0000000000000..a869d0743426f --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/commonjsExportNestedRestBinding(target=esnext).types @@ -0,0 +1,11 @@ +//// [tests/cases/compiler/commonjsExportNestedRestBinding.ts] //// + +=== commonjsExportNestedRestBinding.ts === +declare const source: any; +>source : any + +export const {...{object}} = source; +> : any +>object : any +>source : any + diff --git a/tsc/testdata/tests/cases/compiler/commonjsExportNestedRestBinding.ts b/tsc/testdata/tests/cases/compiler/commonjsExportNestedRestBinding.ts new file mode 100644 index 0000000000000..d99fc6f8ee73f --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/commonjsExportNestedRestBinding.ts @@ -0,0 +1,5 @@ +// @target: es2018, esnext +// @module: commonjs + +declare const source: any; +export const {...{object}} = source;