From 3d4a760d3de82dbb87daf27e9bfb050cd1572589 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 15 Jul 2025 13:57:51 -0700 Subject: [PATCH 01/18] The object spread part of object rest/spread --- internal/ast/ast.go | 6 +- internal/compiler/emitter.go | 36 +++--- internal/compiler/program.go | 2 +- internal/printer/printer_test.go | 6 +- internal/transformers/chain.go | 11 +- internal/transformers/context.go | 31 +++++ internal/transformers/estransforms/async.go | 7 +- .../transformers/estransforms/classfields.go | 7 +- .../transformers/estransforms/classstatic.go | 7 +- .../transformers/estransforms/definitions.go | 22 ++-- .../transformers/estransforms/esdecorator.go | 7 +- .../estransforms/exponentiation.go | 7 +- .../transformers/estransforms/forawait.go | 7 +- .../estransforms/logicalassignment.go | 7 +- .../estransforms/nullishcoalescing.go | 7 +- .../estransforms/objectrestspread.go | 109 +++++++++++++++++- .../estransforms/optionalcatch.go | 7 +- .../estransforms/optionalchain.go | 6 +- internal/transformers/estransforms/using.go | 5 +- internal/transformers/jsxtransforms/jsx.go | 5 +- .../moduletransforms/commonjsmodule.go | 5 +- .../moduletransforms/commonjsmodule_test.go | 9 +- .../transformers/moduletransforms/esmodule.go | 6 +- .../moduletransforms/esmodule_test.go | 9 +- .../moduletransforms/impliedmodule.go | 16 +-- .../tstransforms/importelision.go | 6 +- .../tstransforms/importelision_test.go | 9 +- .../tstransforms/runtimesyntax.go | 5 +- .../tstransforms/runtimesyntax_test.go | 16 ++- .../transformers/tstransforms/typeeraser.go | 7 +- .../tstransforms/typeeraser_test.go | 6 +- 31 files changed, 295 insertions(+), 101 deletions(-) create mode 100644 internal/transformers/context.go diff --git a/internal/ast/ast.go b/internal/ast/ast.go index 3d344c6f9e..c9d30d85fb 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -2586,7 +2586,7 @@ func (node *ForInOrOfStatement) computeSubtreeFacts() SubtreeFacts { return propagateSubtreeFacts(node.Initializer) | propagateSubtreeFacts(node.Expression) | propagateSubtreeFacts(node.Statement) | - core.IfElse(node.AwaitModifier != nil, SubtreeContainsES2018, SubtreeFactsNone) + core.IfElse(node.AwaitModifier != nil, SubtreeContainsForAwaitOrAsyncGenerator, SubtreeFactsNone) } func IsForInStatement(node *Node) bool { @@ -5858,7 +5858,7 @@ func (node *YieldExpression) Clone(f NodeFactoryCoercible) *Node { } func (node *YieldExpression) computeSubtreeFacts() SubtreeFacts { - return propagateSubtreeFacts(node.Expression) | SubtreeContainsES2018 + return propagateSubtreeFacts(node.Expression) | SubtreeContainsForAwaitOrAsyncGenerator } // ArrowFunction @@ -6799,7 +6799,7 @@ func (node *SpreadAssignment) Clone(f NodeFactoryCoercible) *Node { } func (node *SpreadAssignment) computeSubtreeFacts() SubtreeFacts { - return propagateSubtreeFacts(node.Expression) | SubtreeContainsES2018 | SubtreeContainsObjectRestOrSpread + return propagateSubtreeFacts(node.Expression) | SubtreeContainsESObjectRestOrSpread | SubtreeContainsObjectRestOrSpread } func IsSpreadAssignment(node *Node) bool { diff --git a/internal/compiler/emitter.go b/internal/compiler/emitter.go index 2193e344bc..4d7388aaa6 100644 --- a/internal/compiler/emitter.go +++ b/internal/compiler/emitter.go @@ -1,6 +1,7 @@ package compiler import ( + "context" "encoding/base64" "github.com/microsoft/typescript-go/internal/ast" @@ -42,9 +43,9 @@ type emitter struct { sourceFile *ast.SourceFile } -func (e *emitter) emit() { +func (e *emitter) emit(ctx context.Context) { // !!! tracing - e.emitJSFile(e.sourceFile, e.paths.JsFilePath(), e.paths.SourceMapFilePath()) + e.emitJSFile(ctx, e.sourceFile, e.paths.JsFilePath(), e.paths.SourceMapFilePath()) e.emitDeclarationFile(e.sourceFile, e.paths.DeclarationFilePath(), e.paths.DeclarationMapPath()) e.emitBuildInfo(e.paths.BuildInfoPath()) } @@ -54,11 +55,11 @@ func (e *emitter) getDeclarationTransformers(emitContext *printer.EmitContext, d return []*declarations.DeclarationTransformer{transform} } -func getModuleTransformer(emitContext *printer.EmitContext, options *core.CompilerOptions, resolver binder.ReferenceResolver, getEmitModuleFormatOfFile func(file ast.HasFileName) core.ModuleKind) *transformers.Transformer { - switch options.GetEmitModuleKind() { +func getModuleTransformer(ctx context.Context, resolver binder.ReferenceResolver, getEmitModuleFormatOfFile func(file ast.HasFileName) core.ModuleKind) *transformers.Transformer { + switch transformers.GetCompilerOptionsFromContext(ctx).GetEmitModuleKind() { case core.ModuleKindPreserve: // `ESModuleTransformer` contains logic for preserving CJS input syntax in `--module preserve` - return moduletransforms.NewESModuleTransformer(emitContext, options, resolver, getEmitModuleFormatOfFile) + return moduletransforms.NewESModuleTransformer(ctx, resolver, getEmitModuleFormatOfFile) case core.ModuleKindESNext, core.ModuleKindES2022, @@ -68,14 +69,14 @@ func getModuleTransformer(emitContext *printer.EmitContext, options *core.Compil core.ModuleKindNode16, core.ModuleKindNodeNext, core.ModuleKindCommonJS: - return moduletransforms.NewImpliedModuleTransformer(emitContext, options, resolver, getEmitModuleFormatOfFile) + return moduletransforms.NewImpliedModuleTransformer(ctx, resolver, getEmitModuleFormatOfFile) default: - return moduletransforms.NewCommonJSModuleTransformer(emitContext, options, resolver, getEmitModuleFormatOfFile) + return moduletransforms.NewCommonJSModuleTransformer(ctx, resolver, getEmitModuleFormatOfFile) } } -func getScriptTransformers(emitContext *printer.EmitContext, host printer.EmitHost, sourceFile *ast.SourceFile) []*transformers.Transformer { +func getScriptTransformers(ctx context.Context, host printer.EmitHost, sourceFile *ast.SourceFile) []*transformers.Transformer { var tx []*transformers.Transformer options := host.Options() @@ -95,33 +96,33 @@ func getScriptTransformers(emitContext *printer.EmitContext, host printer.EmitHo // transform TypeScript syntax { // erase types - tx = append(tx, tstransforms.NewTypeEraserTransformer(emitContext, options)) + tx = append(tx, tstransforms.NewTypeEraserTransformer(ctx)) // elide imports if importElisionEnabled { - tx = append(tx, tstransforms.NewImportElisionTransformer(emitContext, options, emitResolver)) + tx = append(tx, tstransforms.NewImportElisionTransformer(ctx, emitResolver)) } // transform `enum`, `namespace`, and parameter properties - tx = append(tx, tstransforms.NewRuntimeSyntaxTransformer(emitContext, options, referenceResolver)) + tx = append(tx, tstransforms.NewRuntimeSyntaxTransformer(ctx, referenceResolver)) } // !!! transform legacy decorator syntax if options.GetJSXTransformEnabled() { - tx = append(tx, jsxtransforms.NewJSXTransformer(emitContext, options, emitResolver)) + tx = append(tx, jsxtransforms.NewJSXTransformer(ctx, emitResolver)) } - downleveler := estransforms.GetESTransformer(options, emitContext) + downleveler := estransforms.GetESTransformer(ctx) if downleveler != nil { tx = append(tx, downleveler) } // transform module syntax - tx = append(tx, getModuleTransformer(emitContext, options, referenceResolver, host.GetEmitModuleFormatOfFile)) + tx = append(tx, getModuleTransformer(ctx, referenceResolver, host.GetEmitModuleFormatOfFile)) return tx } -func (e *emitter) emitJSFile(sourceFile *ast.SourceFile, jsFilePath string, sourceMapFilePath string) { +func (e *emitter) emitJSFile(ctx context.Context, sourceFile *ast.SourceFile, jsFilePath string, sourceMapFilePath string) { options := e.host.Options() if sourceFile == nil || e.emitOnly != emitAll && e.emitOnly != emitOnlyJs || len(jsFilePath) == 0 { @@ -135,7 +136,10 @@ func (e *emitter) emitJSFile(sourceFile *ast.SourceFile, jsFilePath string, sour emitContext, putEmitContext := printer.GetEmitContext() defer putEmitContext() - for _, transformer := range getScriptTransformers(emitContext, e.host, sourceFile) { + ctx = transformers.WithCompilerOptions(ctx, e.host.Options()) + ctx = transformers.WithEmitContext(ctx, emitContext) + + for _, transformer := range getScriptTransformers(ctx, e.host, sourceFile) { sourceFile = transformer.TransformSourceFile(sourceFile) } diff --git a/internal/compiler/program.go b/internal/compiler/program.go index 1786078277..dab7569146 100644 --- a/internal/compiler/program.go +++ b/internal/compiler/program.go @@ -1224,7 +1224,7 @@ func (p *Program) Emit(options EmitOptions) *EmitResult { // attach writer and perform emit emitter.writer = writer emitter.paths = outputpaths.GetOutputPathsFor(sourceFile, host.Options(), host, options.forceDtsEmit) - emitter.emit() + emitter.emit(context.TODO()) emitter.writer = nil // put the writer back in the pool diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index da14de4ea3..c1743fa42b 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -1,6 +1,7 @@ package printer_test import ( + "context" "testing" "github.com/microsoft/typescript-go/internal/ast" @@ -8,6 +9,7 @@ import ( "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/testutil/emittestutil" "github.com/microsoft/typescript-go/internal/testutil/parsetestutil" + "github.com/microsoft/typescript-go/internal/transformers" "github.com/microsoft/typescript-go/internal/transformers/tstransforms" ) @@ -2503,7 +2505,9 @@ func TestPartiallyEmittedExpression(t *testing.T) { .expression;`, false /*jsx*/) emitContext := printer.NewEmitContext() - file = tstransforms.NewTypeEraserTransformer(emitContext, compilerOptions).TransformSourceFile(file) + ctx := transformers.WithCompilerOptions(context.Background(), compilerOptions) + ctx = transformers.WithEmitContext(ctx, emitContext) + file = tstransforms.NewTypeEraserTransformer(ctx).TransformSourceFile(file) emittestutil.CheckEmit(t, emitContext, file.AsSourceFile(), `return container.parent .left .expression diff --git a/internal/transformers/chain.go b/internal/transformers/chain.go index dcf7f3567a..d0e692c65e 100644 --- a/internal/transformers/chain.go +++ b/internal/transformers/chain.go @@ -1,8 +1,9 @@ package transformers import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/printer" ) type chainedTransformer struct { @@ -21,7 +22,7 @@ func (ch *chainedTransformer) visit(node *ast.Node) *ast.Node { return result.AsNode() } -type TransformerFactory = func(emitContext *printer.EmitContext) *Transformer +type TransformerFactory = func(context context.Context) *Transformer // Chains transforms in left-to-right order, running them one at a time in order (as opposed to interleaved at each node) // - the resulting combined transform only operates on SourceFile nodes @@ -32,13 +33,13 @@ func Chain(transforms ...TransformerFactory) TransformerFactory { } return transforms[0] } - return func(emitContext *printer.EmitContext) *Transformer { + return func(context context.Context) *Transformer { constructed := make([]*Transformer, 0, len(transforms)) for _, t := range transforms { // TODO: flatten nested chains? - constructed = append(constructed, t(emitContext)) + constructed = append(constructed, t(context)) } ch := &chainedTransformer{components: constructed} - return ch.NewTransformer(ch.visit, emitContext) + return ch.NewTransformer(ch.visit, GetEmitContextFromContext(context)) } } diff --git a/internal/transformers/context.go b/internal/transformers/context.go new file mode 100644 index 0000000000..8f1deed3d7 --- /dev/null +++ b/internal/transformers/context.go @@ -0,0 +1,31 @@ +package transformers + +import ( + "context" + + "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/printer" +) + +type transformContextKey int + +const ( + compilerOptionsKeyValue transformContextKey = iota + emitContextKeyValue +) + +func WithCompilerOptions(ctx context.Context, options *core.CompilerOptions) context.Context { + return context.WithValue(ctx, compilerOptionsKeyValue, options) +} + +func GetCompilerOptionsFromContext(ctx context.Context) *core.CompilerOptions { + return ctx.Value(compilerOptionsKeyValue).(*core.CompilerOptions) +} + +func WithEmitContext(ctx context.Context, emitContext *printer.EmitContext) context.Context { + return context.WithValue(ctx, emitContextKeyValue, emitContext) +} + +func GetEmitContextFromContext(ctx context.Context) *printer.EmitContext { + return ctx.Value(emitContextKeyValue).(*printer.EmitContext) +} diff --git a/internal/transformers/estransforms/async.go b/internal/transformers/estransforms/async.go index 15024fbcfe..7ba2c71f0c 100644 --- a/internal/transformers/estransforms/async.go +++ b/internal/transformers/estransforms/async.go @@ -1,8 +1,9 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -14,7 +15,7 @@ func (ch *asyncTransformer) visit(node *ast.Node) *ast.Node { return node // !!! } -func newAsyncTransformer(emitContext *printer.EmitContext) *transformers.Transformer { +func newAsyncTransformer(ctx context.Context) *transformers.Transformer { tx := &asyncTransformer{} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } diff --git a/internal/transformers/estransforms/classfields.go b/internal/transformers/estransforms/classfields.go index c4e43e15f9..dd3b39fafa 100644 --- a/internal/transformers/estransforms/classfields.go +++ b/internal/transformers/estransforms/classfields.go @@ -1,8 +1,9 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -14,7 +15,7 @@ func (ch *classFieldsTransformer) visit(node *ast.Node) *ast.Node { return node // !!! } -func newClassFieldsTransformer(emitContext *printer.EmitContext) *transformers.Transformer { +func newClassFieldsTransformer(ctx context.Context) *transformers.Transformer { tx := &classFieldsTransformer{} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } diff --git a/internal/transformers/estransforms/classstatic.go b/internal/transformers/estransforms/classstatic.go index d880de75fe..9a8b6c64b3 100644 --- a/internal/transformers/estransforms/classstatic.go +++ b/internal/transformers/estransforms/classstatic.go @@ -1,8 +1,9 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -14,7 +15,7 @@ func (ch *classStaticBlockTransformer) visit(node *ast.Node) *ast.Node { return node // !!! } -func newClassStaticBlockTransformer(emitContext *printer.EmitContext) *transformers.Transformer { +func newClassStaticBlockTransformer(ctx context.Context) *transformers.Transformer { tx := &classStaticBlockTransformer{} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } diff --git a/internal/transformers/estransforms/definitions.go b/internal/transformers/estransforms/definitions.go index d4c025285a..580055b32a 100644 --- a/internal/transformers/estransforms/definitions.go +++ b/internal/transformers/estransforms/definitions.go @@ -1,8 +1,9 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/core" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -22,25 +23,26 @@ var ( NewES2016Transformer = transformers.Chain(NewES2017Transformer, newExponentiationTransformer) ) -func GetESTransformer(options *core.CompilerOptions, emitContext *printer.EmitContext) *transformers.Transformer { +func GetESTransformer(ctx context.Context) *transformers.Transformer { + options := transformers.GetCompilerOptionsFromContext(ctx) switch options.GetEmitScriptTarget() { case core.ScriptTargetESNext: return nil // no transforms needed case /*core.ScriptTargetES2025,*/ core.ScriptTargetES2024, core.ScriptTargetES2023, core.ScriptTargetES2022: - return NewESNextTransformer(emitContext) + return NewESNextTransformer(ctx) case core.ScriptTargetES2021: - return NewES2022Transformer(emitContext) + return NewES2022Transformer(ctx) case core.ScriptTargetES2020: - return NewES2021Transformer(emitContext) + return NewES2021Transformer(ctx) case core.ScriptTargetES2019: - return NewES2020Transformer(emitContext) + return NewES2020Transformer(ctx) case core.ScriptTargetES2018: - return NewES2019Transformer(emitContext) + return NewES2019Transformer(ctx) case core.ScriptTargetES2017: - return NewES2018Transformer(emitContext) + return NewES2018Transformer(ctx) case core.ScriptTargetES2016: - return NewES2017Transformer(emitContext) + return NewES2017Transformer(ctx) default: // other, older, option, transform maximally - return NewES2016Transformer(emitContext) + return NewES2016Transformer(ctx) } } diff --git a/internal/transformers/estransforms/esdecorator.go b/internal/transformers/estransforms/esdecorator.go index 8a71913929..633a75964f 100644 --- a/internal/transformers/estransforms/esdecorator.go +++ b/internal/transformers/estransforms/esdecorator.go @@ -1,8 +1,9 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -14,7 +15,7 @@ func (ch *esDecoratorTransformer) visit(node *ast.Node) *ast.Node { return node // !!! } -func newESDecoratorTransformer(emitContext *printer.EmitContext) *transformers.Transformer { +func newESDecoratorTransformer(ctx context.Context) *transformers.Transformer { tx := &esDecoratorTransformer{} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } diff --git a/internal/transformers/estransforms/exponentiation.go b/internal/transformers/estransforms/exponentiation.go index e9362d3a43..135a8b749c 100644 --- a/internal/transformers/estransforms/exponentiation.go +++ b/internal/transformers/estransforms/exponentiation.go @@ -1,8 +1,9 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -85,7 +86,7 @@ func (ch *exponentiationTransformer) visitExponentiationExpression(node *ast.Bin return result } -func newExponentiationTransformer(emitContext *printer.EmitContext) *transformers.Transformer { +func newExponentiationTransformer(ctx context.Context) *transformers.Transformer { tx := &exponentiationTransformer{} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } diff --git a/internal/transformers/estransforms/forawait.go b/internal/transformers/estransforms/forawait.go index 8f6e9d5fb0..17d260356b 100644 --- a/internal/transformers/estransforms/forawait.go +++ b/internal/transformers/estransforms/forawait.go @@ -1,8 +1,9 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -14,7 +15,7 @@ func (ch *forawaitTransformer) visit(node *ast.Node) *ast.Node { return node // !!! } -func newforawaitTransformer(emitContext *printer.EmitContext) *transformers.Transformer { +func newforawaitTransformer(ctx context.Context) *transformers.Transformer { tx := &forawaitTransformer{} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } diff --git a/internal/transformers/estransforms/logicalassignment.go b/internal/transformers/estransforms/logicalassignment.go index 59bf4943fa..5794b8ffc6 100644 --- a/internal/transformers/estransforms/logicalassignment.go +++ b/internal/transformers/estransforms/logicalassignment.go @@ -1,8 +1,9 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -108,7 +109,7 @@ func (ch *logicalAssignmentTransformer) visitBinaryExpression(node *ast.BinaryEx ) } -func newLogicalAssignmentTransformer(emitContext *printer.EmitContext) *transformers.Transformer { +func newLogicalAssignmentTransformer(ctx context.Context) *transformers.Transformer { tx := &logicalAssignmentTransformer{} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } diff --git a/internal/transformers/estransforms/nullishcoalescing.go b/internal/transformers/estransforms/nullishcoalescing.go index 58cc4fa548..5faca899f0 100644 --- a/internal/transformers/estransforms/nullishcoalescing.go +++ b/internal/transformers/estransforms/nullishcoalescing.go @@ -1,8 +1,9 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -44,7 +45,7 @@ func (ch *nullishCoalescingTransformer) visitBinaryExpression(node *ast.BinaryEx } } -func newNullishCoalescingTransformer(emitContext *printer.EmitContext) *transformers.Transformer { +func newNullishCoalescingTransformer(ctx context.Context) *transformers.Transformer { tx := &nullishCoalescingTransformer{} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index 0b007f02c8..afe94d2898 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -1,20 +1,119 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/printer" + "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/transformers" ) type objectRestSpreadTransformer struct { transformers.Transformer + compilerOptions *core.CompilerOptions } func (ch *objectRestSpreadTransformer) visit(node *ast.Node) *ast.Node { - return node // !!! + if node.SubtreeFacts()&ast.SubtreeContainsESObjectRestOrSpread == 0 { + return node + } + switch node.Kind { + case ast.KindObjectLiteralExpression: + return ch.visitObjectLiteralExpression(node.AsObjectLiteralExpression()) + case ast.KindBinaryExpression: + return ch.visitBinaryExpression(node.AsBinaryExpression()) + // case ast.KindForOfStatement: + // return ch.visitForOftatement(node.AsForInOrOfStatement()) + // case ast.KindVariableStatement: + // return ch.visitVariableStatement(node.AsVariableStatement()) + default: + return ch.Visitor().VisitEachChild(node) + } +} + +func (ch *objectRestSpreadTransformer) visitBinaryExpression(node *ast.BinaryExpression) *ast.Node { + if !ast.IsDestructuringAssignment(node.AsNode()) || (node.Left.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread) == 0 { + return ch.Visitor().VisitEachChild(node.AsNode()) + } + // !!! + return node.AsNode() +} + +func (ch *objectRestSpreadTransformer) visitObjectLiteralExpression(node *ast.ObjectLiteralExpression) *ast.Node { + if (node.SubtreeFacts() & ast.SubtreeContainsObjectRestOrSpread) == 0 { + return ch.Visitor().VisitEachChild(node.AsNode()) + } + // spread elements emit like so: + // non-spread elements are chunked together into object literals, and then all are passed to __assign: + // { a, ...o, b } => __assign(__assign({a}, o), {b}); + // If the first element is a spread element, then the first argument to __assign is {}: + // { ...o, a, b, ...o2 } => __assign(__assign(__assign({}, o), {a, b}), o2) + // + // We cannot call __assign with more than two elements, since any element could cause side effects. For + // example: + // var k = { a: 1, b: 2 }; + // var o = { a: 3, ...k, b: k.a++ }; + // // expected: { a: 1, b: 1 } + // If we translate the above to `__assign({ a: 3 }, k, { b: k.a++ })`, the `k.a++` will evaluate before + // `k` is spread and we end up with `{ a: 2, b: 1 }`. + // + // This also occurs for spread elements, not just property assignments: + // var k = { a: 1, get b() { l = { z: 9 }; return 2; } }; + // var l = { c: 3 }; + // var o = { ...k, ...l }; + // // expected: { a: 1, b: 2, z: 9 } + // If we translate the above to `__assign({}, k, l)`, the `l` will evaluate before `k` is spread and we + // end up with `{ a: 1, b: 2, c: 3 }` + + objects := ch.chunkObjectLiteralElements(node.Properties) + if len(objects) > 0 && objects[0].Kind != ast.KindObjectLiteralExpression { + objects = append([]*ast.Node{ch.Factory().NewObjectLiteralExpression(ch.Factory().NewNodeList(nil), false)}, objects...) + } + expression := objects[0] + if len(objects) > 0 { + for i, obj := range objects { + if i == 0 { + continue + } + expression = ch.Factory().NewAssignHelper([]*ast.Node{expression, obj}, ch.compilerOptions.GetEmitScriptTarget()) + } + return expression + } + return ch.Factory().NewAssignHelper(objects, ch.compilerOptions.GetEmitScriptTarget()) +} + +func (ch *objectRestSpreadTransformer) chunkObjectLiteralElements(list *ast.NodeList) []*ast.Node { + if list == nil || len(list.Nodes) == 0 { + return nil + } + elements := list.Nodes + var chunkObject []*ast.Node + objects := make([]*ast.Node, 0, 1) + for _, e := range elements { + if e.Kind == ast.KindSpreadAssignment { + if len(chunkObject) > 0 { + objects = append(objects, ch.Factory().NewObjectLiteralExpression(ch.Factory().NewNodeList(chunkObject), false)) + chunkObject = nil + } + target := e.Expression() + objects = append(objects, ch.Visitor().Visit(target)) + } else { + var elem *ast.Node + if e.Kind == ast.KindPropertyAssignment { + elem = ch.Factory().NewPropertyAssignment(nil, e.Name(), nil, nil, ch.Visitor().Visit(e.Initializer())) + } else { + elem = ch.Visitor().Visit(e) + } + chunkObject = append(chunkObject, elem) + } + } + if len(chunkObject) > 0 { + objects = append(objects, ch.Factory().NewObjectLiteralExpression(ch.Factory().NewNodeList(chunkObject), false)) + } + return objects } -func newObjectRestSpreadTransformer(emitContext *printer.EmitContext) *transformers.Transformer { - tx := &objectRestSpreadTransformer{} - return tx.NewTransformer(tx.visit, emitContext) +func newObjectRestSpreadTransformer(ctx context.Context) *transformers.Transformer { + tx := &objectRestSpreadTransformer{compilerOptions: transformers.GetCompilerOptionsFromContext(ctx)} + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } diff --git a/internal/transformers/estransforms/optionalcatch.go b/internal/transformers/estransforms/optionalcatch.go index b8d76cac9a..9e0743d843 100644 --- a/internal/transformers/estransforms/optionalcatch.go +++ b/internal/transformers/estransforms/optionalcatch.go @@ -1,8 +1,9 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -32,7 +33,7 @@ func (ch *optionalCatchTransformer) visitCatchClause(node *ast.CatchClause) *ast return ch.Visitor().VisitEachChild(node.AsNode()) } -func newOptionalCatchTransformer(emitContext *printer.EmitContext) *transformers.Transformer { +func newOptionalCatchTransformer(ctx context.Context) *transformers.Transformer { tx := &optionalCatchTransformer{} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } diff --git a/internal/transformers/estransforms/optionalchain.go b/internal/transformers/estransforms/optionalchain.go index 46cf10145f..de82be0b3b 100644 --- a/internal/transformers/estransforms/optionalchain.go +++ b/internal/transformers/estransforms/optionalchain.go @@ -1,6 +1,8 @@ package estransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" @@ -229,7 +231,7 @@ func (ch *optionalChainTransformer) visitOptionalExpression(node *ast.Node, capt return target } -func newOptionalChainTransformer(emitContext *printer.EmitContext) *transformers.Transformer { +func newOptionalChainTransformer(ctx context.Context) *transformers.Transformer { tx := &optionalChainTransformer{} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } diff --git a/internal/transformers/estransforms/using.go b/internal/transformers/estransforms/using.go index 101176221c..bf2f48f317 100644 --- a/internal/transformers/estransforms/using.go +++ b/internal/transformers/estransforms/using.go @@ -1,6 +1,7 @@ package estransforms import ( + "context" "maps" "slices" @@ -19,9 +20,9 @@ type usingDeclarationTransformer struct { exportEqualsBinding *ast.IdentifierNode } -func newUsingDeclarationTransformer(emitContext *printer.EmitContext) *transformers.Transformer { +func newUsingDeclarationTransformer(ctx context.Context) *transformers.Transformer { tx := &usingDeclarationTransformer{} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } type usingKind uint diff --git a/internal/transformers/jsxtransforms/jsx.go b/internal/transformers/jsxtransforms/jsx.go index 54a2dcecf3..2159e3a01c 100644 --- a/internal/transformers/jsxtransforms/jsx.go +++ b/internal/transformers/jsxtransforms/jsx.go @@ -1,6 +1,7 @@ package jsxtransforms import ( + "context" "maps" "slices" "strconv" @@ -29,7 +30,9 @@ type JSXTransformer struct { currentSourceFile *ast.SourceFile } -func NewJSXTransformer(emitContext *printer.EmitContext, compilerOptions *core.CompilerOptions, emitResolver printer.EmitResolver) *transformers.Transformer { +func NewJSXTransformer(ctx context.Context, emitResolver printer.EmitResolver) *transformers.Transformer { + compilerOptions := transformers.GetCompilerOptionsFromContext(ctx) + emitContext := transformers.GetEmitContextFromContext(ctx) tx := &JSXTransformer{ compilerOptions: compilerOptions, emitResolver: emitResolver, diff --git a/internal/transformers/moduletransforms/commonjsmodule.go b/internal/transformers/moduletransforms/commonjsmodule.go index 434e89d6cf..2a6b10458f 100644 --- a/internal/transformers/moduletransforms/commonjsmodule.go +++ b/internal/transformers/moduletransforms/commonjsmodule.go @@ -1,6 +1,7 @@ package moduletransforms import ( + "context" "slices" "github.com/microsoft/typescript-go/internal/ast" @@ -29,7 +30,9 @@ type CommonJSModuleTransformer struct { currentNode *ast.Node // used for ancestor tracking via pushNode/popNode to detect expression identifiers } -func NewCommonJSModuleTransformer(emitContext *printer.EmitContext, compilerOptions *core.CompilerOptions, resolver binder.ReferenceResolver, getEmitModuleFormatOfFile func(file ast.HasFileName) core.ModuleKind) *transformers.Transformer { +func NewCommonJSModuleTransformer(ctx context.Context, resolver binder.ReferenceResolver, getEmitModuleFormatOfFile func(file ast.HasFileName) core.ModuleKind) *transformers.Transformer { + compilerOptions := transformers.GetCompilerOptionsFromContext(ctx) + emitContext := transformers.GetEmitContextFromContext(ctx) if resolver == nil { resolver = binder.NewReferenceResolver(compilerOptions, binder.ReferenceResolverHooks{}) } diff --git a/internal/transformers/moduletransforms/commonjsmodule_test.go b/internal/transformers/moduletransforms/commonjsmodule_test.go index 2e13a1fa95..749441c839 100644 --- a/internal/transformers/moduletransforms/commonjsmodule_test.go +++ b/internal/transformers/moduletransforms/commonjsmodule_test.go @@ -1,6 +1,7 @@ package moduletransforms_test import ( + "context" "testing" "github.com/microsoft/typescript-go/internal/ast" @@ -9,6 +10,7 @@ import ( "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/testutil/emittestutil" "github.com/microsoft/typescript-go/internal/testutil/parsetestutil" + "github.com/microsoft/typescript-go/internal/transformers" "github.com/microsoft/typescript-go/internal/transformers/moduletransforms" "github.com/microsoft/typescript-go/internal/transformers/tstransforms" ) @@ -1047,9 +1049,10 @@ exports.a = a;`, emitContext := printer.NewEmitContext() resolver := binder.NewReferenceResolver(compilerOptions, binder.ReferenceResolverHooks{}) - - file = tstransforms.NewRuntimeSyntaxTransformer(emitContext, compilerOptions, resolver).TransformSourceFile(file) - file = moduletransforms.NewCommonJSModuleTransformer(emitContext, compilerOptions, resolver, fakeGetEmitModuleFormatOfFile).TransformSourceFile(file) + ctx := transformers.WithCompilerOptions(context.Background(), compilerOptions) + ctx = transformers.WithEmitContext(ctx, emitContext) + file = tstransforms.NewRuntimeSyntaxTransformer(ctx, resolver).TransformSourceFile(file) + file = moduletransforms.NewCommonJSModuleTransformer(ctx, resolver, fakeGetEmitModuleFormatOfFile).TransformSourceFile(file) emittestutil.CheckEmit(t, emitContext, file, rec.output) }) } diff --git a/internal/transformers/moduletransforms/esmodule.go b/internal/transformers/moduletransforms/esmodule.go index 1ab1af2ee5..9b0eeb27d3 100644 --- a/internal/transformers/moduletransforms/esmodule.go +++ b/internal/transformers/moduletransforms/esmodule.go @@ -1,6 +1,7 @@ package moduletransforms import ( + "context" "slices" "github.com/microsoft/typescript-go/internal/ast" @@ -25,12 +26,13 @@ type importRequireStatements struct { requireHelperName *ast.IdentifierNode } -func NewESModuleTransformer(emitContext *printer.EmitContext, compilerOptions *core.CompilerOptions, resolver binder.ReferenceResolver, getEmitModuleFormatOfFile func(file ast.HasFileName) core.ModuleKind) *transformers.Transformer { +func NewESModuleTransformer(ctx context.Context, resolver binder.ReferenceResolver, getEmitModuleFormatOfFile func(file ast.HasFileName) core.ModuleKind) *transformers.Transformer { + compilerOptions := transformers.GetCompilerOptionsFromContext(ctx) if resolver == nil { resolver = binder.NewReferenceResolver(compilerOptions, binder.ReferenceResolverHooks{}) } tx := &ESModuleTransformer{compilerOptions: compilerOptions, resolver: resolver, getEmitModuleFormatOfFile: getEmitModuleFormatOfFile} - return tx.NewTransformer(tx.visit, emitContext) + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } // Visits source elements that are not top-level or top-level nested statements. diff --git a/internal/transformers/moduletransforms/esmodule_test.go b/internal/transformers/moduletransforms/esmodule_test.go index bb41650f10..47390bce18 100644 --- a/internal/transformers/moduletransforms/esmodule_test.go +++ b/internal/transformers/moduletransforms/esmodule_test.go @@ -1,6 +1,7 @@ package moduletransforms_test import ( + "context" "testing" "github.com/microsoft/typescript-go/internal/ast" @@ -9,6 +10,7 @@ import ( "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/testutil/emittestutil" "github.com/microsoft/typescript-go/internal/testutil/parsetestutil" + "github.com/microsoft/typescript-go/internal/transformers" "github.com/microsoft/typescript-go/internal/transformers/moduletransforms" "github.com/microsoft/typescript-go/internal/transformers/tstransforms" ) @@ -239,9 +241,10 @@ var __rewriteRelativeImportExtension;`, emitContext := printer.NewEmitContext() resolver := binder.NewReferenceResolver(compilerOptions, binder.ReferenceResolverHooks{}) - - file = tstransforms.NewRuntimeSyntaxTransformer(emitContext, compilerOptions, resolver).TransformSourceFile(file) - file = moduletransforms.NewESModuleTransformer(emitContext, compilerOptions, resolver, fakeGetEmitModuleFormatOfFile).TransformSourceFile(file) + ctx := transformers.WithCompilerOptions(context.Background(), compilerOptions) + ctx = transformers.WithEmitContext(ctx, emitContext) + file = tstransforms.NewRuntimeSyntaxTransformer(ctx, resolver).TransformSourceFile(file) + file = moduletransforms.NewESModuleTransformer(ctx, resolver, fakeGetEmitModuleFormatOfFile).TransformSourceFile(file) emittestutil.CheckEmit(t, emitContext, file, rec.output) }) } diff --git a/internal/transformers/moduletransforms/impliedmodule.go b/internal/transformers/moduletransforms/impliedmodule.go index 8ad007e6a5..a244177881 100644 --- a/internal/transformers/moduletransforms/impliedmodule.go +++ b/internal/transformers/moduletransforms/impliedmodule.go @@ -1,28 +1,30 @@ package moduletransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/binder" "github.com/microsoft/typescript-go/internal/core" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) type ImpliedModuleTransformer struct { transformers.Transformer - compilerOptions *core.CompilerOptions + ctx context.Context resolver binder.ReferenceResolver getEmitModuleFormatOfFile func(file ast.HasFileName) core.ModuleKind cjsTransformer *transformers.Transformer esmTransformer *transformers.Transformer } -func NewImpliedModuleTransformer(emitContext *printer.EmitContext, compilerOptions *core.CompilerOptions, resolver binder.ReferenceResolver, getEmitModuleFormatOfFile func(file ast.HasFileName) core.ModuleKind) *transformers.Transformer { +func NewImpliedModuleTransformer(ctx context.Context, resolver binder.ReferenceResolver, getEmitModuleFormatOfFile func(file ast.HasFileName) core.ModuleKind) *transformers.Transformer { + compilerOptions := transformers.GetCompilerOptionsFromContext(ctx) if resolver == nil { resolver = binder.NewReferenceResolver(compilerOptions, binder.ReferenceResolverHooks{}) } - tx := &ImpliedModuleTransformer{compilerOptions: compilerOptions, resolver: resolver, getEmitModuleFormatOfFile: getEmitModuleFormatOfFile} - return tx.NewTransformer(tx.visit, emitContext) + tx := &ImpliedModuleTransformer{ctx: ctx, resolver: resolver, getEmitModuleFormatOfFile: getEmitModuleFormatOfFile} + return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } func (tx *ImpliedModuleTransformer) visit(node *ast.Node) *ast.Node { @@ -43,12 +45,12 @@ func (tx *ImpliedModuleTransformer) visitSourceFile(node *ast.SourceFile) *ast.N var transformer *transformers.Transformer if format >= core.ModuleKindES2015 { if tx.esmTransformer == nil { - tx.esmTransformer = NewESModuleTransformer(tx.EmitContext(), tx.compilerOptions, tx.resolver, tx.getEmitModuleFormatOfFile) + tx.esmTransformer = NewESModuleTransformer(tx.ctx, tx.resolver, tx.getEmitModuleFormatOfFile) } transformer = tx.esmTransformer } else { if tx.cjsTransformer == nil { - tx.cjsTransformer = NewCommonJSModuleTransformer(tx.EmitContext(), tx.compilerOptions, tx.resolver, tx.getEmitModuleFormatOfFile) + tx.cjsTransformer = NewCommonJSModuleTransformer(tx.ctx, tx.resolver, tx.getEmitModuleFormatOfFile) } transformer = tx.cjsTransformer } diff --git a/internal/transformers/tstransforms/importelision.go b/internal/transformers/tstransforms/importelision.go index d13bddaba2..84b956c4b0 100644 --- a/internal/transformers/tstransforms/importelision.go +++ b/internal/transformers/tstransforms/importelision.go @@ -1,6 +1,8 @@ package tstransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/printer" @@ -14,7 +16,9 @@ type ImportElisionTransformer struct { emitResolver printer.EmitResolver } -func NewImportElisionTransformer(emitContext *printer.EmitContext, compilerOptions *core.CompilerOptions, resolver printer.EmitResolver) *transformers.Transformer { +func NewImportElisionTransformer(ctx context.Context, resolver printer.EmitResolver) *transformers.Transformer { + compilerOptions := transformers.GetCompilerOptionsFromContext(ctx) + emitContext := transformers.GetEmitContextFromContext(ctx) if compilerOptions.VerbatimModuleSyntax.IsTrue() { panic("ImportElisionTransformer should not be used with VerbatimModuleSyntax") } diff --git a/internal/transformers/tstransforms/importelision_test.go b/internal/transformers/tstransforms/importelision_test.go index f7d8b9c043..e36c9a4b16 100644 --- a/internal/transformers/tstransforms/importelision_test.go +++ b/internal/transformers/tstransforms/importelision_test.go @@ -1,6 +1,7 @@ package tstransforms_test import ( + "context" "testing" "github.com/microsoft/typescript-go/internal/ast" @@ -12,6 +13,7 @@ import ( "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/testutil/emittestutil" "github.com/microsoft/typescript-go/internal/testutil/parsetestutil" + "github.com/microsoft/typescript-go/internal/transformers" "github.com/microsoft/typescript-go/internal/transformers/tstransforms" "github.com/microsoft/typescript-go/internal/tsoptions" "github.com/microsoft/typescript-go/internal/tspath" @@ -244,9 +246,10 @@ func TestImportElision(t *testing.T) { emitResolver := c.GetEmitResolver() emitResolver.MarkLinkedReferencesRecursively(file) - emitContext := printer.NewEmitContext() - file = tstransforms.NewTypeEraserTransformer(emitContext, compilerOptions).TransformSourceFile(file) - file = tstransforms.NewImportElisionTransformer(emitContext, compilerOptions, emitResolver).TransformSourceFile(file) + ctx := transformers.WithCompilerOptions(context.Background(), compilerOptions) + ctx = transformers.WithEmitContext(ctx, printer.NewEmitContext()) + file = tstransforms.NewTypeEraserTransformer(ctx).TransformSourceFile(file) + file = tstransforms.NewImportElisionTransformer(ctx, emitResolver).TransformSourceFile(file) emittestutil.CheckEmit(t, nil, file, rec.output) }) } diff --git a/internal/transformers/tstransforms/runtimesyntax.go b/internal/transformers/tstransforms/runtimesyntax.go index 4c994085fd..5076682ec6 100644 --- a/internal/transformers/tstransforms/runtimesyntax.go +++ b/internal/transformers/tstransforms/runtimesyntax.go @@ -5,6 +5,7 @@ package tstransforms // !!! SourceMaps and Comments need to be validated import ( + "context" "slices" "github.com/microsoft/typescript-go/internal/ast" @@ -32,7 +33,9 @@ type RuntimeSyntaxTransformer struct { enumMemberCache map[*ast.EnumDeclarationNode]map[string]evaluator.Result } -func NewRuntimeSyntaxTransformer(emitContext *printer.EmitContext, compilerOptions *core.CompilerOptions, resolver binder.ReferenceResolver) *transformers.Transformer { +func NewRuntimeSyntaxTransformer(ctx context.Context, resolver binder.ReferenceResolver) *transformers.Transformer { + compilerOptions := transformers.GetCompilerOptionsFromContext(ctx) + emitContext := transformers.GetEmitContextFromContext(ctx) tx := &RuntimeSyntaxTransformer{compilerOptions: compilerOptions, resolver: resolver} return tx.NewTransformer(tx.visit, emitContext) } diff --git a/internal/transformers/tstransforms/runtimesyntax_test.go b/internal/transformers/tstransforms/runtimesyntax_test.go index dda47e6a92..c21458e6f0 100644 --- a/internal/transformers/tstransforms/runtimesyntax_test.go +++ b/internal/transformers/tstransforms/runtimesyntax_test.go @@ -1,6 +1,7 @@ package tstransforms_test import ( + "context" "testing" "github.com/microsoft/typescript-go/internal/binder" @@ -8,6 +9,7 @@ import ( "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/testutil/emittestutil" "github.com/microsoft/typescript-go/internal/testutil/parsetestutil" + "github.com/microsoft/typescript-go/internal/transformers" "github.com/microsoft/typescript-go/internal/transformers/tstransforms" ) @@ -237,7 +239,9 @@ var E; binder.BindSourceFile(file) emitContext := printer.NewEmitContext() resolver := binder.NewReferenceResolver(options, binder.ReferenceResolverHooks{}) - emittestutil.CheckEmit(t, emitContext, tstransforms.NewRuntimeSyntaxTransformer(emitContext, options, resolver).TransformSourceFile(file), rec.output) + ctx := transformers.WithCompilerOptions(context.Background(), options) + ctx = transformers.WithEmitContext(ctx, emitContext) + emittestutil.CheckEmit(t, emitContext, tstransforms.NewRuntimeSyntaxTransformer(ctx, resolver).TransformSourceFile(file), rec.output) }) } } @@ -414,8 +418,10 @@ func TestNamespaceTransformer(t *testing.T) { parsetestutil.CheckDiagnostics(t, file) binder.BindSourceFile(file) emitContext := printer.NewEmitContext() + ctx := transformers.WithCompilerOptions(context.Background(), options) + ctx = transformers.WithEmitContext(ctx, emitContext) resolver := binder.NewReferenceResolver(options, binder.ReferenceResolverHooks{}) - emittestutil.CheckEmit(t, emitContext, tstransforms.NewRuntimeSyntaxTransformer(emitContext, options, resolver).TransformSourceFile(file), rec.output) + emittestutil.CheckEmit(t, emitContext, tstransforms.NewRuntimeSyntaxTransformer(ctx, resolver).TransformSourceFile(file), rec.output) }) } } @@ -451,8 +457,10 @@ func TestParameterPropertyTransformer(t *testing.T) { binder.BindSourceFile(file) emitContext := printer.NewEmitContext() resolver := binder.NewReferenceResolver(options, binder.ReferenceResolverHooks{}) - file = tstransforms.NewTypeEraserTransformer(emitContext, options).TransformSourceFile(file) - file = tstransforms.NewRuntimeSyntaxTransformer(emitContext, options, resolver).TransformSourceFile(file) + ctx := transformers.WithCompilerOptions(context.Background(), options) + ctx = transformers.WithEmitContext(ctx, emitContext) + file = tstransforms.NewTypeEraserTransformer(ctx).TransformSourceFile(file) + file = tstransforms.NewRuntimeSyntaxTransformer(ctx, resolver).TransformSourceFile(file) emittestutil.CheckEmit(t, emitContext, file, rec.output) }) } diff --git a/internal/transformers/tstransforms/typeeraser.go b/internal/transformers/tstransforms/typeeraser.go index 1d0d96c83e..f116641233 100644 --- a/internal/transformers/tstransforms/typeeraser.go +++ b/internal/transformers/tstransforms/typeeraser.go @@ -1,9 +1,10 @@ package tstransforms import ( + "context" + "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/core" - "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -14,7 +15,9 @@ type TypeEraserTransformer struct { currentNode *ast.Node } -func NewTypeEraserTransformer(emitContext *printer.EmitContext, compilerOptions *core.CompilerOptions) *transformers.Transformer { +func NewTypeEraserTransformer(ctx context.Context) *transformers.Transformer { + compilerOptions := transformers.GetCompilerOptionsFromContext(ctx) + emitContext := transformers.GetEmitContextFromContext(ctx) tx := &TypeEraserTransformer{compilerOptions: compilerOptions} return tx.NewTransformer(tx.visit, emitContext) } diff --git a/internal/transformers/tstransforms/typeeraser_test.go b/internal/transformers/tstransforms/typeeraser_test.go index e57fbc8022..2d0cab8938 100644 --- a/internal/transformers/tstransforms/typeeraser_test.go +++ b/internal/transformers/tstransforms/typeeraser_test.go @@ -1,12 +1,14 @@ package tstransforms_test import ( + "context" "testing" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/testutil/emittestutil" "github.com/microsoft/typescript-go/internal/testutil/parsetestutil" + "github.com/microsoft/typescript-go/internal/transformers" "github.com/microsoft/typescript-go/internal/transformers/tstransforms" ) @@ -99,7 +101,9 @@ func TestTypeEraser(t *testing.T) { if rec.vms { compilerOptions.VerbatimModuleSyntax = core.TSTrue } - emittestutil.CheckEmit(t, nil, tstransforms.NewTypeEraserTransformer(printer.NewEmitContext(), compilerOptions).TransformSourceFile(file), rec.output) + ctx := transformers.WithCompilerOptions(context.Background(), compilerOptions) + ctx = transformers.WithEmitContext(ctx, printer.NewEmitContext()) + emittestutil.CheckEmit(t, nil, tstransforms.NewTypeEraserTransformer(ctx).TransformSourceFile(file), rec.output) }) } } From a18f5228d3f7e26863a87dec32d07e9ef86d2570 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 29 Jul 2025 15:05:56 -0700 Subject: [PATCH 02/18] Core res downlevel ported, still need to transform function-like params with rest --- internal/ast/utilities.go | 200 ++++++ internal/printer/factory.go | 39 ++ internal/printer/helpers.go | 17 + .../estransforms/objectrestspread.go | 616 +++++++++++++++++- internal/transformers/utilities.go | 9 + 5 files changed, 871 insertions(+), 10 deletions(-) diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index 5c5fd2314d..a0b0d804e0 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -7,6 +7,7 @@ import ( "sync" "sync/atomic" + "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/tspath" ) @@ -3633,3 +3634,202 @@ func GetSemanticJsxChildren(children []*JsxChild) []*JsxChild { } }) } + +func IsAssignmentPattern(node *Node) bool { + return node.Kind == KindArrayLiteralExpression || node.Kind == KindObjectLiteralExpression +} + +func GetElementsOfBindingOrAssignmentPattern(name *Node) []*Node { + switch name.Kind { + case KindObjectBindingPattern, KindArrayBindingPattern: + // `a` in `{a}` + // `a` in `[a]` + return name.AsBindingPattern().Elements.Nodes + case KindArrayLiteralExpression: + // `a` in `[a]` + return name.AsArrayLiteralExpression().Elements.Nodes + case KindObjectLiteralExpression: + // `a` in `{a}` + return name.AsObjectLiteralExpression().Properties.Nodes + } + return nil +} + +func IsDeclarationBindingElement(bindingElement *Node) bool { + switch bindingElement.Kind { + case KindVariableDeclaration, KindParameter, KindBindingElement: + return true + default: + return false + } +} + +/** + * Gets the name of an BindingOrAssignmentElement. + */ +func GetTargetOfBindingOrAssignmentElement(bindingElement *Node) *Node { + if IsDeclarationBindingElement(bindingElement) { + // `a` in `let { a } = ...` + // `a` in `let { a = 1 } = ...` + // `b` in `let { a: b } = ...` + // `b` in `let { a: b = 1 } = ...` + // `a` in `let { ...a } = ...` + // `{b}` in `let { a: {b} } = ...` + // `{b}` in `let { a: {b} = 1 } = ...` + // `[b]` in `let { a: [b] } = ...` + // `[b]` in `let { a: [b] = 1 } = ...` + // `a` in `let [a] = ...` + // `a` in `let [a = 1] = ...` + // `a` in `let [...a] = ...` + // `{a}` in `let [{a}] = ...` + // `{a}` in `let [{a} = 1] = ...` + // `[a]` in `let [[a]] = ...` + // `[a]` in `let [[a] = 1] = ...` + return bindingElement.Name() + } + + if IsObjectLiteralElement(bindingElement) { + switch bindingElement.Kind { + case KindPropertyAssignment: + // `b` in `({ a: b } = ...)` + // `b` in `({ a: b = 1 } = ...)` + // `{b}` in `({ a: {b} } = ...)` + // `{b}` in `({ a: {b} = 1 } = ...)` + // `[b]` in `({ a: [b] } = ...)` + // `[b]` in `({ a: [b] = 1 } = ...)` + // `b.c` in `({ a: b.c } = ...)` + // `b.c` in `({ a: b.c = 1 } = ...)` + // `b[0]` in `({ a: b[0] } = ...)` + // `b[0]` in `({ a: b[0] = 1 } = ...)` + return GetTargetOfBindingOrAssignmentElement(bindingElement.Initializer()) + case KindShorthandPropertyAssignment: + // `a` in `({ a } = ...)` + // `a` in `({ a = 1 } = ...)` + return bindingElement.Name() + case KindSpreadAssignment: + // `a` in `({ ...a } = ...)` + return GetTargetOfBindingOrAssignmentElement(bindingElement.AsSpreadAssignment().Expression) + } + + // no target + return nil + } + + if IsAssignmentExpression(bindingElement /*excludeCompoundAssignment*/, true) { + // `a` in `[a = 1] = ...` + // `{a}` in `[{a} = 1] = ...` + // `[a]` in `[[a] = 1] = ...` + // `a.b` in `[a.b = 1] = ...` + // `a[0]` in `[a[0] = 1] = ...` + return GetTargetOfBindingOrAssignmentElement(bindingElement.AsBinaryExpression().Left) + } + + if IsSpreadElement(bindingElement) { + // `a` in `[...a] = ...` + return GetTargetOfBindingOrAssignmentElement(bindingElement.AsSpreadElement().Expression) + } + + // `a` in `[a] = ...` + // `{a}` in `[{a}] = ...` + // `[a]` in `[[a]] = ...` + // `a.b` in `[a.b] = ...` + // `a[0]` in `[a[0]] = ...` + return bindingElement +} + +func TryGetPropertyNameOfBindingOrAssignmentElement(bindingElement *Node) *Node { + switch bindingElement.Kind { + case KindBindingElement: + // `a` in `let { a: b } = ...` + // `[a]` in `let { [a]: b } = ...` + // `"a"` in `let { "a": b } = ...` + // `1` in `let { 1: b } = ...` + if bindingElement.AsBindingElement().PropertyName != nil { + propertyName := bindingElement.AsBindingElement().PropertyName + // if ast.IsPrivateIdentifier(propertyName) { + // return Debug.failBadSyntaxKind(propertyName) // !!! + // } + if ast.IsComputedPropertyName(propertyName) && ast.IsStringOrNumericLiteralLike(propertyName.AsComputedPropertyName().Expression) { + return propertyName.AsComputedPropertyName().Expression + } + return propertyName + } + case KindPropertyAssignment: + // `a` in `({ a: b } = ...)` + // `[a]` in `({ [a]: b } = ...)` + // `"a"` in `({ "a": b } = ...)` + // `1` in `({ 1: b } = ...)` + if bindingElement.Name() != nil { + propertyName := bindingElement.Name() + // if ast.IsPrivateIdentifier(propertyName) { + // return Debug.failBadSyntaxKind(propertyName) // !!! + // } + if IsComputedPropertyName(propertyName) && IsStringOrNumericLiteralLike(propertyName.AsComputedPropertyName().Expression) { + return propertyName.AsComputedPropertyName().Expression + } + return propertyName + } + case KindSpreadAssignment: + // `a` in `({ ...a } = ...)` + // if ast.IsPrivateIdentifier(bindingElement.Name()) { + // return Debug.failBadSyntaxKind(bindingElement.Name()) // !!! + // } + return bindingElement.Name() + } + + target := GetTargetOfBindingOrAssignmentElement(bindingElement) + if target != nil && ast.IsPropertyName(target) { + return target + } + return nil +} + +/** + * Walk an AssignmentPattern to determine if it contains object rest (`...`) syntax. We cannot rely on + * propagation of `TransformFlags.ContainsObjectRestOrSpread` since it isn't propagated by default in + * ObjectLiteralExpression and ArrayLiteralExpression since we do not know whether they belong to an + * AssignmentPattern at the time the nodes are parsed. + */ +func ContainsObjectRestOrSpread(node *Node) bool { + if node.SubtreeFacts()&SubtreeContainsObjectRestOrSpread != 0 { + return true + } + if node.SubtreeFacts()&SubtreeContainsESObjectRestOrSpread != 0 { + // check for nested spread assignments, otherwise '{ x: { a, ...b } = foo } = c' + // will not be correctly interpreted by the rest/spread transformer + for _, element := range GetElementsOfBindingOrAssignmentPattern(node) { + target := GetTargetOfBindingOrAssignmentElement(element) + if target != nil && IsAssignmentPattern(target) { + if target.SubtreeFacts()&SubtreeContainsObjectRestOrSpread != 0 { + return true + } + if target.SubtreeFacts()&SubtreeContainsESObjectRestOrSpread != 0 { + if ContainsObjectRestOrSpread(target) { + return true + } + } + } + } + } + return false +} + +func IsEmptyObjectLiteral(expression *Node) bool { + return expression.Kind == KindObjectLiteralExpression && len(expression.AsObjectLiteralExpression().Properties.Nodes) == 0 +} + +func IsEmptyArrayLiteral(expression *Node) bool { + return expression.Kind == KindArrayLiteralExpression && len(expression.AsArrayLiteralExpression().Elements.Nodes) == 0 +} + +func GetRestIndicatorOfBindingOrAssignmentElement(bindingElement *Node) *Node { + switch bindingElement.Kind { + case ast.KindParameter: + return bindingElement.AsParameterDeclaration().DotDotDotToken + case ast.KindBindingElement: + return bindingElement.AsBindingElement().DotDotDotToken + case ast.KindSpreadElement, ast.KindSpreadAssignment: + return bindingElement + } + return nil +} diff --git a/internal/printer/factory.go b/internal/printer/factory.go index f4928c6174..4be9347413 100644 --- a/internal/printer/factory.go +++ b/internal/printer/factory.go @@ -552,6 +552,45 @@ func (f *NodeFactory) NewAssignHelper(attributesSegments []*ast.Expression, scri } // !!! ES2018 Destructuring Helpers + +func (f *NodeFactory) NewRestHelper(value *ast.Expression, elements []*ast.Node, computedTempVariables []*ast.Node, location core.TextRange) *ast.Expression { + f.emitContext.RequestEmitHelper(restHelper) + var propertyNames []*ast.Node + computedTempVariableOffset := 0 + for _, element := range elements { + propertyName := ast.TryGetPropertyNameOfBindingOrAssignmentElement(element) + if propertyName != nil { + if ast.IsComputedPropertyName(propertyName) { + // Debug.assertIsDefined(computedTempVariables, "Encountered computed property name but 'computedTempVariables' argument was not provided."); // !!! + temp := computedTempVariables[computedTempVariableOffset] + computedTempVariableOffset++ + // typeof _tmp === "symbol" ? _tmp : _tmp + "" + propertyNames = append(propertyNames, f.NewConditionalExpression( + f.NewTypeCheck(temp, "symbol"), + f.NewToken(ast.KindQuestionToken), + temp, + f.NewToken(ast.KindColonToken), + f.NewBinaryExpression(nil, temp, nil, f.NewToken(ast.KindPlusToken), f.NewStringLiteral("")), + )) + } else { + propertyNames = append(propertyNames, f.NewStringLiteralFromNode(propertyName)) + } + } + } + propNames := f.NewArrayLiteralExpression(f.NewNodeList(propertyNames)) + propNames.Loc = location + return f.NewCallExpression( + f.NewUnscopedHelperName("__rest"), + nil, + nil, + f.NewNodeList([]*ast.Node{ + value, + propNames, + }), + ast.NodeFlagsNone, + ) +} + // !!! ES2017 Helpers // ES2015 Helpers diff --git a/internal/printer/helpers.go b/internal/printer/helpers.go index 64c0774292..0b3918af7b 100644 --- a/internal/printer/helpers.go +++ b/internal/printer/helpers.go @@ -119,6 +119,23 @@ var assignHelper = &EmitHelper{ } // !!! ES2018 Destructuring Helpers +var restHelper = &EmitHelper{ + Name: "typescript:rest", + ImportName: "__rest", + Scoped: false, + Text: `var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +};`, +} + // !!! ES2017 Helpers // ES2015 Helpers diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index afe94d2898..00b238ac2a 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -8,9 +8,24 @@ import ( "github.com/microsoft/typescript-go/internal/transformers" ) +type pendingDecl struct { + pendingExpressions []*ast.Node + name *ast.Node + value *ast.Node + location core.TextRange + original *ast.Node +} + type objectRestSpreadTransformer struct { transformers.Transformer compilerOptions *core.CompilerOptions + + inExportedVariableStatement bool + + currentExpressions []*ast.Node + currentDeclarations []pendingDecl + hasTransformedPriorElement bool + emitBindingOrAssignment func(t *objectRestSpreadTransformer, target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node) } func (ch *objectRestSpreadTransformer) visit(node *ast.Node) *ast.Node { @@ -22,21 +37,491 @@ func (ch *objectRestSpreadTransformer) visit(node *ast.Node) *ast.Node { return ch.visitObjectLiteralExpression(node.AsObjectLiteralExpression()) case ast.KindBinaryExpression: return ch.visitBinaryExpression(node.AsBinaryExpression()) - // case ast.KindForOfStatement: - // return ch.visitForOftatement(node.AsForInOrOfStatement()) - // case ast.KindVariableStatement: - // return ch.visitVariableStatement(node.AsVariableStatement()) + case ast.KindForOfStatement: + return ch.visitForOftatement(node.AsForInOrOfStatement()) + case ast.KindVariableStatement: + return ch.visitVariableStatement(node.AsVariableStatement()) + case ast.KindVariableDeclaration: + return ch.visitVariableDeclaration(node.AsVariableDeclaration()) + case ast.KindCatchClause: + return ch.visitCatchClause(node.AsCatchClause()) default: return ch.Visitor().VisitEachChild(node) } } +func (ch *objectRestSpreadTransformer) visitCatchClause(node *ast.CatchClause) *ast.Node { + if node.VariableDeclaration != nil && ast.IsBindingPattern(node.VariableDeclaration.Name()) && node.VariableDeclaration.Name().SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 { + name := ch.Factory().NewGeneratedNameForNode(node.VariableDeclaration.Name()) + updatedDecl := ch.Factory().UpdateVariableDeclaration(node.VariableDeclaration.AsVariableDeclaration(), node.VariableDeclaration.Name(), nil, nil, name) + visitedBindings := ch.flattenDestructuringBinding(updatedDecl.AsVariableDeclaration(), false) + block := ch.Visitor().VisitNode(node.Block) + if visitedBindings != nil { + var decls []*ast.Node + if visitedBindings.Kind&ast.KindSyntaxList != 0 { + decls = visitedBindings.AsSyntaxList().Children + } else { + decls = []*ast.Node{visitedBindings} + } + newStatement := ch.Factory().NewVariableStatement(nil, ch.Factory().NewVariableDeclarationList(ast.NodeFlagsNone, ch.Factory().NewNodeList(decls))) + statements := []*ast.Node{newStatement} + if block.AsBlock().Statements != nil && len(block.AsBlock().Statements.Nodes) > 0 { + statements = append(statements, block.AsBlock().Statements.Nodes...) + } + statementList := ch.Factory().NewNodeList(statements) + statementList.Loc = block.AsBlock().Statements.Loc + + block = ch.Factory().UpdateBlock(block.AsBlock(), statementList) + } + return ch.Factory().UpdateCatchClause( + node, + ch.Factory().UpdateVariableDeclaration(node.VariableDeclaration.AsVariableDeclaration(), name, nil, nil, nil), + block, + ) + } + return ch.Visitor().VisitEachChild(node.AsNode()) +} + +func (ch *objectRestSpreadTransformer) visitVariableStatement(node *ast.VariableStatement) *ast.Node { + if ast.HasSyntacticModifier(node.AsNode(), ast.ModifierFlagsExport) { + oldInExportedVariableStatement := ch.inExportedVariableStatement + ch.inExportedVariableStatement = true + result := ch.Visitor().VisitEachChild(node.AsNode()) + ch.inExportedVariableStatement = oldInExportedVariableStatement + return result + } + return ch.Visitor().VisitEachChild(node.AsNode()) +} + +func (ch *objectRestSpreadTransformer) visitVariableDeclaration(node *ast.VariableDeclaration) *ast.Node { + if ch.inExportedVariableStatement { + ch.inExportedVariableStatement = false + result := ch.visitVariableDeclarationWorker(node, true) + ch.inExportedVariableStatement = true + return result + } + return ch.visitVariableDeclarationWorker(node, false) +} + +func (ch *objectRestSpreadTransformer) visitVariableDeclarationWorker(node *ast.VariableDeclaration, exported bool) *ast.Node { + // If we are here it is because the name contains a binding pattern with a rest somewhere in it. + if ast.IsBindingPattern(node.Name()) && node.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 { + return ch.flattenDestructuringBinding( + node, + exported, + ) + } + return ch.Visitor().VisitEachChild(node.AsNode()) +} + +func (ch *objectRestSpreadTransformer) flattenDestructuringBinding(node *ast.VariableDeclaration, skipInitializer bool) *ast.Node { + ch.hasTransformedPriorElement = false + ch.currentExpressions = nil + ch.emitBindingOrAssignment = (*objectRestSpreadTransformer).emitBinding + + initializer := getInitializerOfBindingOrAssignmentElement(node.AsNode()) + if initializer != nil && (ast.IsIdentifier(initializer) && bindingOrAssignmentElementAssignsToName(node.AsNode(), initializer.AsIdentifier().Text) || bindingOrAssignmentElementContainsNonLiteralComputedName(node.AsNode())) { + // If the right-hand value of the assignment is also an assignment target then + // we need to cache the right-hand value. + initializer = ch.ensureIdentifier(ch.Visitor().VisitNode(initializer), false, initializer.Loc, false) + node = ch.Factory().UpdateVariableDeclaration(node, node.Name(), nil, nil, initializer).AsVariableDeclaration() + } + + ch.flattenBindingOrAssignmentElement(node.AsNode(), nil, node.Loc, skipInitializer, false) + + if len(ch.currentExpressions) > 0 { + temp := ch.Factory().NewTempVariable() + ch.EmitContext().AddVariableDeclaration(temp) + last := &ch.currentDeclarations[len(ch.currentDeclarations)-1] + last.pendingExpressions = append(last.pendingExpressions, ch.Factory().NewAssignmentExpression(temp, last.value)) + last.pendingExpressions = append(last.pendingExpressions, ch.currentExpressions...) + last.value = temp + ch.currentExpressions = nil + } + decls := make([]*ast.Node, 0, len(ch.currentDeclarations)) + for _, pending := range ch.currentDeclarations { + expr := pending.value + if len(pending.pendingExpressions) > 0 { + expr = ch.Factory().InlineExpressions(append(pending.pendingExpressions, pending.value)) + } + decl := ch.Factory().NewVariableDeclaration( + pending.name, + nil, + nil, + expr, + ) + decl.Loc = pending.location + ch.EmitContext().SetOriginal(decl, pending.original) + decls = append(decls, decl) + } + ch.currentDeclarations = nil + if len(decls) == 1 { + return decls[0] + } + if len(decls) == 0 { + return nil + } + return ch.Factory().NewSyntaxList(decls) +} + +func (ch *objectRestSpreadTransformer) visitForOftatement(node *ast.ForInOrOfStatement) *ast.Node { + if node.Initializer.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 || (ast.IsAssignmentPattern(node.Initializer) && ast.ContainsObjectRestOrSpread(node.Initializer)) { + initializerWithoutParens := ast.SkipParentheses(node.Initializer) + if ast.IsVariableDeclarationList(initializerWithoutParens) || ast.IsAssignmentPattern(initializerWithoutParens) { + var bodyLocation core.TextRange + var statementsLocation core.TextRange + temp := ch.Factory().NewTempVariable() + res := ch.Visitor().VisitNode(ch.createForOfBindingStatement(initializerWithoutParens, temp)) + statements := make([]*ast.Node, 0, 1) + if res != nil { + statements = append(statements, res) + } + if ast.IsBlock(node.Statement) { + for _, statement := range node.Statement.AsBlock().Statements.Nodes { + visited := ch.Visitor().VisitEachChild(statement) + if visited != nil { + statements = append(statements, visited) + } + } + bodyLocation = node.Statement.Loc + statementsLocation = node.Statement.AsBlock().Statements.Loc + } else if node.Statement != nil { + statements = append(statements, ch.Visitor().VisitEachChild(node.Statement)) + bodyLocation = node.Statement.Loc + statementsLocation = node.Statement.Loc + } + + list := ch.Factory().NewVariableDeclarationList( + ast.NodeFlagsLet, + ch.Factory().NewNodeList([]*ast.Node{ch.Factory().NewVariableDeclaration(temp, nil, nil, nil)}), + ) + list.Loc = node.Initializer.Loc + + expr := ch.Visitor().VisitEachChild(node.Expression) + + statementsList := ch.Factory().NewNodeList(statements) + statementsList.Loc = statementsLocation + + block := ch.Factory().NewBlock(statementsList, true) + block.Loc = bodyLocation + + return ch.Factory().UpdateForInOrOfStatement( + node, + node.AwaitModifier, + list, + expr, + block, + ) + } + } + return ch.Visitor().VisitEachChild(node.AsNode()) +} + +func (ch *objectRestSpreadTransformer) createForOfBindingStatement(node *ast.Node, boundValue *ast.Node) *ast.Node { + if ast.IsVariableDeclarationList(node) { + firstDeclaration := node.AsVariableDeclarationList().Declarations.Nodes[0] + updatedDeclaration := ch.Factory().UpdateVariableDeclaration( + firstDeclaration.AsVariableDeclaration(), + firstDeclaration.Name(), + nil, + nil, + boundValue, + ) + statement := ch.Factory().NewVariableStatement( + nil, + ch.Factory().UpdateVariableDeclarationList( + node.AsVariableDeclarationList(), + ch.Factory().NewNodeList([]*ast.Node{updatedDeclaration}), + ), + ) + statement.Loc = node.Loc + return statement + } else { + updatedExpression := ch.Factory().NewAssignmentExpression(node, boundValue) + updatedExpression.Loc = node.Loc + statement := ch.Factory().NewExpressionStatement(updatedExpression) + statement.Loc = node.Loc + return statement + } +} + func (ch *objectRestSpreadTransformer) visitBinaryExpression(node *ast.BinaryExpression) *ast.Node { - if !ast.IsDestructuringAssignment(node.AsNode()) || (node.Left.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread) == 0 { + if !(ast.IsDestructuringAssignment(node.AsNode()) && ast.ContainsObjectRestOrSpread(node.Left)) { return ch.Visitor().VisitEachChild(node.AsNode()) } - // !!! - return node.AsNode() + return ch.flattenDestructuringAssignment( + node, + ) +} + +func (ch *objectRestSpreadTransformer) flattenDestructuringAssignment(node *ast.BinaryExpression) *ast.Node { + location := node.Loc + var value *ast.Node + if ast.IsDestructuringAssignment(node.AsNode()) { + value = node.Right + for ast.IsEmptyArrayLiteral(node.Left) || ast.IsEmptyObjectLiteral(node.Left) { + if ast.IsDestructuringAssignment(value) { + node = value.AsBinaryExpression() + location = node.Loc + value = node.Right + } else { + return ch.Visitor().VisitNode(value) + } + } + } + + oldExprs := ch.currentExpressions + ch.currentExpressions = nil + ch.hasTransformedPriorElement = false + ch.emitBindingOrAssignment = (*objectRestSpreadTransformer).emitAssignment + if value != nil { + value = ch.Visitor().VisitNode(value) + + if ast.IsIdentifier(value) && bindingOrAssignmentElementAssignsToName(node.AsNode(), value.AsIdentifier().Text) || bindingOrAssignmentElementContainsNonLiteralComputedName(node.AsNode()) { + // If the right-hand value of the assignment is also an assignment target then + // we need to cache the right-hand value. + value = ch.ensureIdentifier(value, false, location, true) + } else if ast.NodeIsSynthesized(node.AsNode()) { + // Generally, the source map location for a destructuring assignment is the root + // expression. + // + // However, if the root expression is synthesized (as in the case + // of the initializer when transforming a ForOfStatement), then the source map + // location should point to the right-hand value of the expression. + location = value.Loc + } + // !!! else if needsValue {} + } + + ch.flattenBindingOrAssignmentElement(node.AsNode(), value, location, ast.IsDestructuringAssignment(node.AsNode()), true) + + res := ch.Factory().InlineExpressions(ch.currentExpressions) + ch.currentExpressions = oldExprs + if res != nil { + return res + } + return ch.Factory().NewOmittedExpression() +} + +func (ch *objectRestSpreadTransformer) flattenBindingOrAssignmentElement(element *ast.Node, value *ast.Node, location core.TextRange, skipInitializer bool, hoist bool) { + bindingTarget := ast.GetTargetOfBindingOrAssignmentElement(element) + if !skipInitializer { + initializer := ch.Visitor().VisitNode(getInitializerOfBindingOrAssignmentElement(element)) + if initializer != nil { + // Combine value and initializer + if value != nil { + value = ch.createDefaultValueCheck(value, initializer, location, hoist) + // If 'value' is not a simple expression, it could contain side-effecting code that should evaluate before an object or array binding pattern. + if !transformers.IsSimpleCopiableExpression(initializer) && (ast.IsBindingPattern(bindingTarget) || ast.IsAssignmentPattern(bindingTarget)) { + value = ch.ensureIdentifier(value, true, location, hoist) + } + } else { + value = initializer + } + } else if value == nil { + // Use 'void 0' in absence of value and initializer + value = ch.Factory().NewVoidZeroExpression() + } + } + + if isObjectBindingOrAssignmentPattern(bindingTarget) { + ch.flattenObjectBindingOrAssignmentPattern(element, bindingTarget, value, location, hoist) + } else if isArrayBindingOrAssignmentPattern(bindingTarget) { + ch.flattenArrayBindingOrAssignmentPattern(element, bindingTarget, value, location, hoist) + } else { + ch.emitBindingOrAssignment(ch, bindingTarget, value, location, element) + } +} + +func (ch *objectRestSpreadTransformer) flattenObjectBindingOrAssignmentPattern(parent *ast.Node, pattern *ast.Node, value *ast.Node, location core.TextRange, hoist bool) { + elements := ast.GetElementsOfBindingOrAssignmentPattern(pattern) + numElements := len(elements) + if numElements != 1 { + // For anything other than a single-element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. Additionally, if we have zero elements + // we need to emit *something* to ensure that in case a 'var' keyword was already emitted, + // so in that case, we'll intentionally create that temporary. + reuseIdentifierExpressions := !ast.IsDeclarationBindingElement(parent) || numElements != 0 + value = ch.ensureIdentifier(value, reuseIdentifierExpressions, location, hoist) + } + var bindingElements []*ast.Node + var computedTempVariables []*ast.Node + for i, element := range elements { + if ast.GetRestIndicatorOfBindingOrAssignmentElement(element) == nil { + propertyName := ast.TryGetPropertyNameOfBindingOrAssignmentElement(element) + if element.SubtreeFacts()&(ast.SubtreeContainsRest|ast.SubtreeContainsObjectRestOrSpread) == 0 && ast.GetTargetOfBindingOrAssignmentElement(element).SubtreeFacts()&(ast.SubtreeContainsRest|ast.SubtreeContainsObjectRestOrSpread) == 0 && !ast.IsComputedPropertyName(propertyName) { + bindingElements = append(bindingElements, ch.Visitor().VisitNode(element)) + } else { + if len(bindingElements) > 0 { + ch.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) + bindingElements = nil + } + rhsValue := ch.createDestructuringPropertyAccess(value, propertyName, hoist) + if ast.IsComputedPropertyName(propertyName) { + computedTempVariables = append(computedTempVariables, rhsValue.AsElementAccessExpression().ArgumentExpression) + } + ch.flattenBindingOrAssignmentElement(element, rhsValue, element.Loc, false, hoist) + } + } else if i == numElements-1 { + if len(bindingElements) > 0 { + ch.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) + bindingElements = nil + } + rhsValue := ch.Factory().NewRestHelper(value, elements, computedTempVariables, pattern.Loc) + ch.flattenBindingOrAssignmentElement(element, rhsValue, element.Loc, false, hoist) + } + } + if len(bindingElements) > 0 { + ch.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) + } +} + +type restIdElemPair struct { + id *ast.Node + element *ast.Node +} + +func (ch *objectRestSpreadTransformer) flattenArrayBindingOrAssignmentPattern(parent *ast.Node, pattern *ast.Node, value *ast.Node, location core.TextRange, hoist bool) { + elements := ast.GetElementsOfBindingOrAssignmentPattern(pattern) + numElements := len(elements) + if numElements != 1 || core.Every(elements, ast.IsOmittedExpression) { + // For anything other than a single-element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. Additionally, if we have zero elements + // we need to emit *something* to ensure that in case a 'var' keyword was already emitted, + // so in that case, we'll intentionally create that temporary. + // Or all the elements of the binding pattern are omitted expression such as "var [,] = [1,2]", + // then we will create temporary variable. + reuseIdentifierExpressions := !ast.IsDeclarationBindingElement(parent) || numElements != 0 + value = ch.ensureIdentifier(value, reuseIdentifierExpressions, location, hoist) + } + var bindingElements []*ast.Node + var restContainingElements []restIdElemPair + for _, element := range elements { + // If an array pattern contains an ObjectRest, we must cache the result so that we + // can perform the ObjectRest destructuring in a different declaration + if element.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 || ch.hasTransformedPriorElement && !isSimpleBindingOrAssignmentElement(element) { + ch.hasTransformedPriorElement = true + temp := ch.Factory().NewTempVariable() + if hoist { + ch.EmitContext().AddVariableDeclaration(temp) + } + + restContainingElements = append(restContainingElements, restIdElemPair{temp, element}) + bindingElements = append(bindingElements, ch.Factory().NewBindingElement(nil, nil, temp, nil)) + } else { + bindingElements = append(bindingElements, element) + } + // !!! ??? other flatten levels? only objectRest currently in use + } + if len(bindingElements) > 0 { + ch.emitBindingOrAssignment(ch, ch.createArrayBindingOrAssignmentPattern(bindingElements), value, location, pattern) + } + if len(restContainingElements) > 0 { + for _, pair := range restContainingElements { + ch.flattenBindingOrAssignmentElement(pair.element, pair.id, pair.element.Loc, false, hoist) + } + } +} + +/** + * Creates either a PropertyAccessExpression or an ElementAccessExpression for the + * right-hand side of a transformed destructuring assignment. + * + * @link https://tc39.github.io/ecma262/#sec-runtime-semantics-keyeddestructuringassignmentevaluation + * + * @param flattenContext Options used to control flattening. + * @param value The RHS value that is the source of the property. + * @param propertyName The destructuring property name. + */ +func (ch *objectRestSpreadTransformer) createDestructuringPropertyAccess(value *ast.Node, propertyName *ast.Node, hoist bool) *ast.Node { + if ast.IsComputedPropertyName(propertyName) { + argumentExpression := ch.ensureIdentifier(ch.Visitor().VisitNode(propertyName.AsComputedPropertyName().Expression), false, propertyName.Loc, hoist) + return ch.Factory().NewElementAccessExpression( + value, + nil, + argumentExpression, + ast.NodeFlagsNone, + ) + } else if ast.IsStringOrNumericLiteralLike(propertyName) || ast.IsBigIntLiteral(propertyName) { + argumentExpression := propertyName.Clone(ch.Factory()) + return ch.Factory().NewElementAccessExpression( + value, + nil, + argumentExpression, + ast.NodeFlagsNone, + ) + } else { + name := ch.Factory().NewIdentifier(propertyName.AsIdentifier().Text) + return ch.Factory().NewPropertyAccessExpression( + value, + nil, + name, + ast.NodeFlagsNone, + ) + } +} + +func (ch *objectRestSpreadTransformer) createObjectBindingOrAssignmentPattern(elements []*ast.Node) *ast.Node { + return ch.Factory().NewBindingPattern(ast.KindObjectBindingPattern, ch.Factory().NewNodeList(elements)) +} + +func (ch *objectRestSpreadTransformer) createArrayBindingOrAssignmentPattern(elements []*ast.Node) *ast.Node { + return ch.Factory().NewBindingPattern(ast.KindArrayBindingPattern, ch.Factory().NewNodeList(elements)) +} + +func (ch *objectRestSpreadTransformer) emitExpression(node *ast.Node) { + ch.currentExpressions = append(ch.currentExpressions, node) +} + +func (ch *objectRestSpreadTransformer) emitAssignment(target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node) { + // Debug.assertNode(target, createAssignmentCallback ? isIdentifier : isExpression); // !!! + expr := ch.Factory().NewAssignmentExpression(ch.Visitor().VisitNode(target), value) + expr.Loc = location + ch.EmitContext().SetOriginal(expr, original) + ch.emitExpression(expr) +} + +func (ch *objectRestSpreadTransformer) emitBinding(target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node) { + // Debug.assertNode(target, isBindingName); // !!! + if len(ch.currentExpressions) > 0 { + value = ch.Factory().InlineExpressions(append(ch.currentExpressions, value)) + ch.currentExpressions = nil + } + ch.currentDeclarations = append(ch.currentDeclarations, pendingDecl{ + ch.currentExpressions, + target, + value, + location, + original, + }) +} + +func (ch *objectRestSpreadTransformer) ensureIdentifier(value *ast.Node, reuseIdentifierExpressions bool, location core.TextRange, hoist bool) *ast.Node { + if reuseIdentifierExpressions && ast.IsIdentifier(value) { + return value + } + + temp := ch.Factory().NewTempVariable() + if hoist { + ch.EmitContext().AddVariableDeclaration(temp) + assign := ch.Factory().NewAssignmentExpression(temp, value) + assign.Loc = location + ch.emitExpression(assign) + } else { + ch.emitBindingOrAssignment(ch, temp, value, location, nil) + } + return temp +} + +func (ch *objectRestSpreadTransformer) createDefaultValueCheck(value *ast.Expression, defaultValue *ast.Expression, location core.TextRange, hoist bool) *ast.Node { + value = ch.ensureIdentifier(value, true, location, hoist) + return ch.Factory().NewConditionalExpression( + ch.Factory().NewTypeCheck(value, "undefined"), + ch.Factory().NewToken(ast.KindQuestionToken), + defaultValue, + ch.Factory().NewToken(ast.KindColonToken), + value, + ) } func (ch *objectRestSpreadTransformer) visitObjectLiteralExpression(node *ast.ObjectLiteralExpression) *ast.Node { @@ -96,13 +581,13 @@ func (ch *objectRestSpreadTransformer) chunkObjectLiteralElements(list *ast.Node chunkObject = nil } target := e.Expression() - objects = append(objects, ch.Visitor().Visit(target)) + objects = append(objects, ch.Visitor().VisitNode(target)) } else { var elem *ast.Node if e.Kind == ast.KindPropertyAssignment { - elem = ch.Factory().NewPropertyAssignment(nil, e.Name(), nil, nil, ch.Visitor().Visit(e.Initializer())) + elem = ch.Factory().NewPropertyAssignment(nil, e.Name(), nil, nil, ch.Visitor().VisitNode(e.Initializer())) } else { - elem = ch.Visitor().Visit(e) + elem = ch.Visitor().VisitNode(e) } chunkObject = append(chunkObject, elem) } @@ -117,3 +602,114 @@ func newObjectRestSpreadTransformer(ctx context.Context) *transformers.Transform tx := &objectRestSpreadTransformer{compilerOptions: transformers.GetCompilerOptionsFromContext(ctx)} return tx.NewTransformer(tx.visit, transformers.GetEmitContextFromContext(ctx)) } + +func bindingOrAssignmentElementAssignsToName(element *ast.Node, name string) bool { + target := ast.GetTargetOfBindingOrAssignmentElement(element) + if target == nil { + return false + } + if ast.IsBindingPattern(target) || ast.IsAssignmentPattern(target) { + return bindingOrAssignmentPatternAssignsToName(target, name) + } else if ast.IsIdentifier(target) { + return target.AsIdentifier().Text == name + } + return false +} + +func bindingOrAssignmentPatternAssignsToName(pattern *ast.Node, name string) bool { + elements := ast.GetElementsOfBindingOrAssignmentPattern(pattern) + for _, element := range elements { + if bindingOrAssignmentElementAssignsToName(element, name) { + return true + } + } + return false +} + +func bindingOrAssignmentElementContainsNonLiteralComputedName(element *ast.Node) bool { + propertyName := ast.TryGetPropertyNameOfBindingOrAssignmentElement(element) + if propertyName != nil && ast.IsComputedPropertyName(propertyName) && !ast.IsLiteralExpression(propertyName.AsComputedPropertyName().Expression) { + return true + } + target := ast.GetTargetOfBindingOrAssignmentElement(element) + return target != nil && (ast.IsBindingPattern(target) || ast.IsAssignmentPattern(target)) && bindingOrAssignmentPatternContainsNonLiteralComputedName(target) +} + +func bindingOrAssignmentPatternContainsNonLiteralComputedName(pattern *ast.Node) bool { + elements := ast.GetElementsOfBindingOrAssignmentPattern(pattern) + for _, element := range elements { + if bindingOrAssignmentElementContainsNonLiteralComputedName(element) { + return true + } + } + return false +} + +func getInitializerOfBindingOrAssignmentElement(bindingElement *ast.Node) *ast.Node { + if ast.IsDeclarationBindingElement(bindingElement) { + // `1` in `let { a = 1 } = ...` + // `1` in `let { a: b = 1 } = ...` + // `1` in `let { a: {b} = 1 } = ...` + // `1` in `let { a: [b] = 1 } = ...` + // `1` in `let [a = 1] = ...` + // `1` in `let [{a} = 1] = ...` + // `1` in `let [[a] = 1] = ...` + return bindingElement.Initializer() + } + + if ast.IsPropertyAssignment(bindingElement) { + // `1` in `({ a: b = 1 } = ...)` + // `1` in `({ a: {b} = 1 } = ...)` + // `1` in `({ a: [b] = 1 } = ...)` + initializer := bindingElement.Initializer() + if ast.IsAssignmentExpression(initializer, true) { + return initializer.AsBinaryExpression().Right + } + return nil + } + + if ast.IsShorthandPropertyAssignment(bindingElement) { + // `1` in `({ a = 1 } = ...)` + return bindingElement.AsShorthandPropertyAssignment().ObjectAssignmentInitializer + } + + if ast.IsAssignmentExpression(bindingElement, true) { + // `1` in `[a = 1] = ...` + // `1` in `[{a} = 1] = ...` + // `1` in `[[a] = 1] = ...` + return bindingElement.AsBinaryExpression().Right + } + + if ast.IsSpreadElement(bindingElement) { + // Recovery consistent with existing emit. + return getInitializerOfBindingOrAssignmentElement(bindingElement.Expression()) + } + return nil +} + +func isObjectBindingOrAssignmentPattern(node *ast.Node) bool { + return node.Kind == ast.KindObjectBindingPattern || node.Kind == ast.KindObjectLiteralExpression +} + +func isArrayBindingOrAssignmentPattern(node *ast.Node) bool { + return node.Kind == ast.KindArrayBindingPattern || node.Kind == ast.KindArrayLiteralExpression +} + +func isSimpleBindingOrAssignmentElement(element *ast.Node) bool { + target := ast.GetTargetOfBindingOrAssignmentElement(element) + if target == nil || ast.IsOmittedExpression(target) { + return true + } + propertyName := ast.TryGetPropertyNameOfBindingOrAssignmentElement(element) + if propertyName != nil && !ast.IsPropertyNameLiteral(propertyName) { + return false + } + initializer := getInitializerOfBindingOrAssignmentElement(element) + if initializer != nil && !transformers.IsSimpleInlineableExpression(initializer) { + return false + } + if ast.IsBindingPattern(target) || ast.IsAssignmentPattern(target) { + return core.Every(ast.GetElementsOfBindingOrAssignmentPattern(target), isSimpleBindingOrAssignmentElement) + } + return ast.IsIdentifier(target) +} diff --git a/internal/transformers/utilities.go b/internal/transformers/utilities.go index 010af33d0a..56baf8e7f7 100644 --- a/internal/transformers/utilities.go +++ b/internal/transformers/utilities.go @@ -245,3 +245,12 @@ func IsSimpleCopiableExpression(expression *ast.Expression) bool { ast.IsKeywordKind(expression.Kind) || ast.IsIdentifier(expression) } + +/** + * A simple inlinable expression is an expression which can be copied into multiple locations + * without risk of repeating any sideeffects and whose value could not possibly change between + * any such locations + */ +func IsSimpleInlineableExpression(expression *ast.Expression) bool { + return !ast.IsIdentifier(expression) && IsSimpleCopiableExpression(expression) +} From 6d5334aa6f1c0ab3e1df2e868154575e2f9b1053 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 30 Jul 2025 11:42:14 -0700 Subject: [PATCH 03/18] Refactor flattenContext back into existence, but more go-like, small fixes --- internal/ast/utilities.go | 11 +- internal/printer/factory.go | 4 +- .../estransforms/objectrestspread.go | 133 ++++++++++-------- 3 files changed, 82 insertions(+), 66 deletions(-) diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index a0b0d804e0..a137425029 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -7,7 +7,6 @@ import ( "sync" "sync/atomic" - "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/tspath" ) @@ -3749,7 +3748,7 @@ func TryGetPropertyNameOfBindingOrAssignmentElement(bindingElement *Node) *Node // if ast.IsPrivateIdentifier(propertyName) { // return Debug.failBadSyntaxKind(propertyName) // !!! // } - if ast.IsComputedPropertyName(propertyName) && ast.IsStringOrNumericLiteralLike(propertyName.AsComputedPropertyName().Expression) { + if IsComputedPropertyName(propertyName) && IsStringOrNumericLiteralLike(propertyName.AsComputedPropertyName().Expression) { return propertyName.AsComputedPropertyName().Expression } return propertyName @@ -3778,7 +3777,7 @@ func TryGetPropertyNameOfBindingOrAssignmentElement(bindingElement *Node) *Node } target := GetTargetOfBindingOrAssignmentElement(bindingElement) - if target != nil && ast.IsPropertyName(target) { + if target != nil && IsPropertyName(target) { return target } return nil @@ -3824,11 +3823,11 @@ func IsEmptyArrayLiteral(expression *Node) bool { func GetRestIndicatorOfBindingOrAssignmentElement(bindingElement *Node) *Node { switch bindingElement.Kind { - case ast.KindParameter: + case KindParameter: return bindingElement.AsParameterDeclaration().DotDotDotToken - case ast.KindBindingElement: + case KindBindingElement: return bindingElement.AsBindingElement().DotDotDotToken - case ast.KindSpreadElement, ast.KindSpreadAssignment: + case KindSpreadElement, KindSpreadAssignment: return bindingElement } return nil diff --git a/internal/printer/factory.go b/internal/printer/factory.go index 4be9347413..46149e0213 100644 --- a/internal/printer/factory.go +++ b/internal/printer/factory.go @@ -551,7 +551,7 @@ func (f *NodeFactory) NewAssignHelper(attributesSegments []*ast.Expression, scri ) } -// !!! ES2018 Destructuring Helpers +// ES2018 Destructuring Helpers func (f *NodeFactory) NewRestHelper(value *ast.Expression, elements []*ast.Node, computedTempVariables []*ast.Node, location core.TextRange) *ast.Expression { f.emitContext.RequestEmitHelper(restHelper) @@ -577,7 +577,7 @@ func (f *NodeFactory) NewRestHelper(value *ast.Expression, elements []*ast.Node, } } } - propNames := f.NewArrayLiteralExpression(f.NewNodeList(propertyNames)) + propNames := f.NewArrayLiteralExpression(f.NewNodeList(propertyNames), false) propNames.Loc = location return f.NewCallExpression( f.NewUnscopedHelperName("__rest"), diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index 00b238ac2a..c08d208540 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -16,16 +16,39 @@ type pendingDecl struct { original *ast.Node } +type flattenContext struct { + currentExpressions []*ast.Node + currentDeclarations []pendingDecl + hasTransformedPriorElement bool + emitBindingOrAssignment func(t *objectRestSpreadTransformer, target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node) + hoistTempVariables bool +} + +type oldFlattenContext flattenContext + type objectRestSpreadTransformer struct { transformers.Transformer compilerOptions *core.CompilerOptions inExportedVariableStatement bool - currentExpressions []*ast.Node - currentDeclarations []pendingDecl - hasTransformedPriorElement bool - emitBindingOrAssignment func(t *objectRestSpreadTransformer, target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node) + ctx flattenContext +} + +func (ch *objectRestSpreadTransformer) enterFlattenContext( + emitBindingOrAssignment func(t *objectRestSpreadTransformer, target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node), + hoistTempVariables bool, +) oldFlattenContext { + old := ch.ctx + ch.ctx = flattenContext{ + emitBindingOrAssignment: emitBindingOrAssignment, + hoistTempVariables: hoistTempVariables, + } + return oldFlattenContext(old) +} + +func (ch *objectRestSpreadTransformer) exitFlattenContext(old oldFlattenContext) { + ch.ctx = flattenContext(old) } func (ch *objectRestSpreadTransformer) visit(node *ast.Node) *ast.Node { @@ -115,31 +138,29 @@ func (ch *objectRestSpreadTransformer) visitVariableDeclarationWorker(node *ast. } func (ch *objectRestSpreadTransformer) flattenDestructuringBinding(node *ast.VariableDeclaration, skipInitializer bool) *ast.Node { - ch.hasTransformedPriorElement = false - ch.currentExpressions = nil - ch.emitBindingOrAssignment = (*objectRestSpreadTransformer).emitBinding + old := ch.enterFlattenContext((*objectRestSpreadTransformer).emitBinding, false) + defer ch.exitFlattenContext(old) initializer := getInitializerOfBindingOrAssignmentElement(node.AsNode()) if initializer != nil && (ast.IsIdentifier(initializer) && bindingOrAssignmentElementAssignsToName(node.AsNode(), initializer.AsIdentifier().Text) || bindingOrAssignmentElementContainsNonLiteralComputedName(node.AsNode())) { // If the right-hand value of the assignment is also an assignment target then // we need to cache the right-hand value. - initializer = ch.ensureIdentifier(ch.Visitor().VisitNode(initializer), false, initializer.Loc, false) + initializer = ch.ensureIdentifier(ch.Visitor().VisitNode(initializer), false, initializer.Loc) node = ch.Factory().UpdateVariableDeclaration(node, node.Name(), nil, nil, initializer).AsVariableDeclaration() } - ch.flattenBindingOrAssignmentElement(node.AsNode(), nil, node.Loc, skipInitializer, false) + ch.flattenBindingOrAssignmentElement(node.AsNode(), nil, node.Loc, skipInitializer) - if len(ch.currentExpressions) > 0 { + if len(ch.ctx.currentExpressions) > 0 { temp := ch.Factory().NewTempVariable() ch.EmitContext().AddVariableDeclaration(temp) - last := &ch.currentDeclarations[len(ch.currentDeclarations)-1] + last := &ch.ctx.currentDeclarations[len(ch.ctx.currentDeclarations)-1] last.pendingExpressions = append(last.pendingExpressions, ch.Factory().NewAssignmentExpression(temp, last.value)) - last.pendingExpressions = append(last.pendingExpressions, ch.currentExpressions...) + last.pendingExpressions = append(last.pendingExpressions, ch.ctx.currentExpressions...) last.value = temp - ch.currentExpressions = nil } - decls := make([]*ast.Node, 0, len(ch.currentDeclarations)) - for _, pending := range ch.currentDeclarations { + decls := make([]*ast.Node, 0, len(ch.ctx.currentDeclarations)) + for _, pending := range ch.ctx.currentDeclarations { expr := pending.value if len(pending.pendingExpressions) > 0 { expr = ch.Factory().InlineExpressions(append(pending.pendingExpressions, pending.value)) @@ -154,7 +175,6 @@ func (ch *objectRestSpreadTransformer) flattenDestructuringBinding(node *ast.Var ch.EmitContext().SetOriginal(decl, pending.original) decls = append(decls, decl) } - ch.currentDeclarations = nil if len(decls) == 1 { return decls[0] } @@ -269,18 +289,16 @@ func (ch *objectRestSpreadTransformer) flattenDestructuringAssignment(node *ast. } } } + old := ch.enterFlattenContext((*objectRestSpreadTransformer).emitAssignment, true) + defer ch.exitFlattenContext(old) - oldExprs := ch.currentExpressions - ch.currentExpressions = nil - ch.hasTransformedPriorElement = false - ch.emitBindingOrAssignment = (*objectRestSpreadTransformer).emitAssignment if value != nil { value = ch.Visitor().VisitNode(value) if ast.IsIdentifier(value) && bindingOrAssignmentElementAssignsToName(node.AsNode(), value.AsIdentifier().Text) || bindingOrAssignmentElementContainsNonLiteralComputedName(node.AsNode()) { // If the right-hand value of the assignment is also an assignment target then // we need to cache the right-hand value. - value = ch.ensureIdentifier(value, false, location, true) + value = ch.ensureIdentifier(value, false, location) } else if ast.NodeIsSynthesized(node.AsNode()) { // Generally, the source map location for a destructuring assignment is the root // expression. @@ -293,27 +311,26 @@ func (ch *objectRestSpreadTransformer) flattenDestructuringAssignment(node *ast. // !!! else if needsValue {} } - ch.flattenBindingOrAssignmentElement(node.AsNode(), value, location, ast.IsDestructuringAssignment(node.AsNode()), true) + ch.flattenBindingOrAssignmentElement(node.AsNode(), value, location, ast.IsDestructuringAssignment(node.AsNode())) - res := ch.Factory().InlineExpressions(ch.currentExpressions) - ch.currentExpressions = oldExprs + res := ch.Factory().InlineExpressions(ch.ctx.currentExpressions) if res != nil { return res } return ch.Factory().NewOmittedExpression() } -func (ch *objectRestSpreadTransformer) flattenBindingOrAssignmentElement(element *ast.Node, value *ast.Node, location core.TextRange, skipInitializer bool, hoist bool) { +func (ch *objectRestSpreadTransformer) flattenBindingOrAssignmentElement(element *ast.Node, value *ast.Node, location core.TextRange, skipInitializer bool) { bindingTarget := ast.GetTargetOfBindingOrAssignmentElement(element) if !skipInitializer { initializer := ch.Visitor().VisitNode(getInitializerOfBindingOrAssignmentElement(element)) if initializer != nil { // Combine value and initializer if value != nil { - value = ch.createDefaultValueCheck(value, initializer, location, hoist) + value = ch.createDefaultValueCheck(value, initializer, location) // If 'value' is not a simple expression, it could contain side-effecting code that should evaluate before an object or array binding pattern. if !transformers.IsSimpleCopiableExpression(initializer) && (ast.IsBindingPattern(bindingTarget) || ast.IsAssignmentPattern(bindingTarget)) { - value = ch.ensureIdentifier(value, true, location, hoist) + value = ch.ensureIdentifier(value, true, location) } } else { value = initializer @@ -325,15 +342,15 @@ func (ch *objectRestSpreadTransformer) flattenBindingOrAssignmentElement(element } if isObjectBindingOrAssignmentPattern(bindingTarget) { - ch.flattenObjectBindingOrAssignmentPattern(element, bindingTarget, value, location, hoist) + ch.flattenObjectBindingOrAssignmentPattern(element, bindingTarget, value, location) } else if isArrayBindingOrAssignmentPattern(bindingTarget) { - ch.flattenArrayBindingOrAssignmentPattern(element, bindingTarget, value, location, hoist) + ch.flattenArrayBindingOrAssignmentPattern(element, bindingTarget, value, location) } else { - ch.emitBindingOrAssignment(ch, bindingTarget, value, location, element) + ch.ctx.emitBindingOrAssignment(ch, bindingTarget, value, location, element) } } -func (ch *objectRestSpreadTransformer) flattenObjectBindingOrAssignmentPattern(parent *ast.Node, pattern *ast.Node, value *ast.Node, location core.TextRange, hoist bool) { +func (ch *objectRestSpreadTransformer) flattenObjectBindingOrAssignmentPattern(parent *ast.Node, pattern *ast.Node, value *ast.Node, location core.TextRange) { elements := ast.GetElementsOfBindingOrAssignmentPattern(pattern) numElements := len(elements) if numElements != 1 { @@ -342,7 +359,7 @@ func (ch *objectRestSpreadTransformer) flattenObjectBindingOrAssignmentPattern(p // we need to emit *something* to ensure that in case a 'var' keyword was already emitted, // so in that case, we'll intentionally create that temporary. reuseIdentifierExpressions := !ast.IsDeclarationBindingElement(parent) || numElements != 0 - value = ch.ensureIdentifier(value, reuseIdentifierExpressions, location, hoist) + value = ch.ensureIdentifier(value, reuseIdentifierExpressions, location) } var bindingElements []*ast.Node var computedTempVariables []*ast.Node @@ -353,26 +370,26 @@ func (ch *objectRestSpreadTransformer) flattenObjectBindingOrAssignmentPattern(p bindingElements = append(bindingElements, ch.Visitor().VisitNode(element)) } else { if len(bindingElements) > 0 { - ch.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) + ch.ctx.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) bindingElements = nil } - rhsValue := ch.createDestructuringPropertyAccess(value, propertyName, hoist) + rhsValue := ch.createDestructuringPropertyAccess(value, propertyName) if ast.IsComputedPropertyName(propertyName) { computedTempVariables = append(computedTempVariables, rhsValue.AsElementAccessExpression().ArgumentExpression) } - ch.flattenBindingOrAssignmentElement(element, rhsValue, element.Loc, false, hoist) + ch.flattenBindingOrAssignmentElement(element, rhsValue, element.Loc, false) } } else if i == numElements-1 { if len(bindingElements) > 0 { - ch.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) + ch.ctx.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) bindingElements = nil } rhsValue := ch.Factory().NewRestHelper(value, elements, computedTempVariables, pattern.Loc) - ch.flattenBindingOrAssignmentElement(element, rhsValue, element.Loc, false, hoist) + ch.flattenBindingOrAssignmentElement(element, rhsValue, element.Loc, false) } } if len(bindingElements) > 0 { - ch.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) + ch.ctx.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) } } @@ -381,7 +398,7 @@ type restIdElemPair struct { element *ast.Node } -func (ch *objectRestSpreadTransformer) flattenArrayBindingOrAssignmentPattern(parent *ast.Node, pattern *ast.Node, value *ast.Node, location core.TextRange, hoist bool) { +func (ch *objectRestSpreadTransformer) flattenArrayBindingOrAssignmentPattern(parent *ast.Node, pattern *ast.Node, value *ast.Node, location core.TextRange) { elements := ast.GetElementsOfBindingOrAssignmentPattern(pattern) numElements := len(elements) if numElements != 1 || core.Every(elements, ast.IsOmittedExpression) { @@ -392,17 +409,17 @@ func (ch *objectRestSpreadTransformer) flattenArrayBindingOrAssignmentPattern(pa // Or all the elements of the binding pattern are omitted expression such as "var [,] = [1,2]", // then we will create temporary variable. reuseIdentifierExpressions := !ast.IsDeclarationBindingElement(parent) || numElements != 0 - value = ch.ensureIdentifier(value, reuseIdentifierExpressions, location, hoist) + value = ch.ensureIdentifier(value, reuseIdentifierExpressions, location) } var bindingElements []*ast.Node var restContainingElements []restIdElemPair for _, element := range elements { // If an array pattern contains an ObjectRest, we must cache the result so that we // can perform the ObjectRest destructuring in a different declaration - if element.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 || ch.hasTransformedPriorElement && !isSimpleBindingOrAssignmentElement(element) { - ch.hasTransformedPriorElement = true + if element.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 || ch.ctx.hasTransformedPriorElement && !isSimpleBindingOrAssignmentElement(element) { + ch.ctx.hasTransformedPriorElement = true temp := ch.Factory().NewTempVariable() - if hoist { + if ch.ctx.hoistTempVariables { ch.EmitContext().AddVariableDeclaration(temp) } @@ -414,11 +431,11 @@ func (ch *objectRestSpreadTransformer) flattenArrayBindingOrAssignmentPattern(pa // !!! ??? other flatten levels? only objectRest currently in use } if len(bindingElements) > 0 { - ch.emitBindingOrAssignment(ch, ch.createArrayBindingOrAssignmentPattern(bindingElements), value, location, pattern) + ch.ctx.emitBindingOrAssignment(ch, ch.createArrayBindingOrAssignmentPattern(bindingElements), value, location, pattern) } if len(restContainingElements) > 0 { for _, pair := range restContainingElements { - ch.flattenBindingOrAssignmentElement(pair.element, pair.id, pair.element.Loc, false, hoist) + ch.flattenBindingOrAssignmentElement(pair.element, pair.id, pair.element.Loc, false) } } } @@ -433,9 +450,9 @@ func (ch *objectRestSpreadTransformer) flattenArrayBindingOrAssignmentPattern(pa * @param value The RHS value that is the source of the property. * @param propertyName The destructuring property name. */ -func (ch *objectRestSpreadTransformer) createDestructuringPropertyAccess(value *ast.Node, propertyName *ast.Node, hoist bool) *ast.Node { +func (ch *objectRestSpreadTransformer) createDestructuringPropertyAccess(value *ast.Node, propertyName *ast.Node) *ast.Node { if ast.IsComputedPropertyName(propertyName) { - argumentExpression := ch.ensureIdentifier(ch.Visitor().VisitNode(propertyName.AsComputedPropertyName().Expression), false, propertyName.Loc, hoist) + argumentExpression := ch.ensureIdentifier(ch.Visitor().VisitNode(propertyName.AsComputedPropertyName().Expression), false, propertyName.Loc) return ch.Factory().NewElementAccessExpression( value, nil, @@ -470,7 +487,7 @@ func (ch *objectRestSpreadTransformer) createArrayBindingOrAssignmentPattern(ele } func (ch *objectRestSpreadTransformer) emitExpression(node *ast.Node) { - ch.currentExpressions = append(ch.currentExpressions, node) + ch.ctx.currentExpressions = append(ch.ctx.currentExpressions, node) } func (ch *objectRestSpreadTransformer) emitAssignment(target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node) { @@ -483,12 +500,12 @@ func (ch *objectRestSpreadTransformer) emitAssignment(target *ast.Node, value *a func (ch *objectRestSpreadTransformer) emitBinding(target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node) { // Debug.assertNode(target, isBindingName); // !!! - if len(ch.currentExpressions) > 0 { - value = ch.Factory().InlineExpressions(append(ch.currentExpressions, value)) - ch.currentExpressions = nil + if len(ch.ctx.currentExpressions) > 0 { + value = ch.Factory().InlineExpressions(append(ch.ctx.currentExpressions, value)) + ch.ctx.currentExpressions = nil } - ch.currentDeclarations = append(ch.currentDeclarations, pendingDecl{ - ch.currentExpressions, + ch.ctx.currentDeclarations = append(ch.ctx.currentDeclarations, pendingDecl{ + ch.ctx.currentExpressions, target, value, location, @@ -496,25 +513,25 @@ func (ch *objectRestSpreadTransformer) emitBinding(target *ast.Node, value *ast. }) } -func (ch *objectRestSpreadTransformer) ensureIdentifier(value *ast.Node, reuseIdentifierExpressions bool, location core.TextRange, hoist bool) *ast.Node { +func (ch *objectRestSpreadTransformer) ensureIdentifier(value *ast.Node, reuseIdentifierExpressions bool, location core.TextRange) *ast.Node { if reuseIdentifierExpressions && ast.IsIdentifier(value) { return value } temp := ch.Factory().NewTempVariable() - if hoist { + if ch.ctx.hoistTempVariables { ch.EmitContext().AddVariableDeclaration(temp) assign := ch.Factory().NewAssignmentExpression(temp, value) assign.Loc = location ch.emitExpression(assign) } else { - ch.emitBindingOrAssignment(ch, temp, value, location, nil) + ch.ctx.emitBindingOrAssignment(ch, temp, value, location, nil) } return temp } -func (ch *objectRestSpreadTransformer) createDefaultValueCheck(value *ast.Expression, defaultValue *ast.Expression, location core.TextRange, hoist bool) *ast.Node { - value = ch.ensureIdentifier(value, true, location, hoist) +func (ch *objectRestSpreadTransformer) createDefaultValueCheck(value *ast.Expression, defaultValue *ast.Expression, location core.TextRange) *ast.Node { + value = ch.ensureIdentifier(value, true, location) return ch.Factory().NewConditionalExpression( ch.Factory().NewTypeCheck(value, "undefined"), ch.Factory().NewToken(ast.KindQuestionToken), From 49ca9a116698419895987b0430164bd14d71d39e Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 14:08:26 -0700 Subject: [PATCH 04/18] Add missing non-debug !!!s --- internal/printer/factory.go | 9 + internal/printer/printer.go | 4 +- .../estransforms/objectrestspread.go | 387 ++++++++++++++++-- 3 files changed, 368 insertions(+), 32 deletions(-) diff --git a/internal/printer/factory.go b/internal/printer/factory.go index 46149e0213..67441d0796 100644 --- a/internal/printer/factory.go +++ b/internal/printer/factory.go @@ -2,6 +2,7 @@ package printer import ( "fmt" + "strconv" "strings" "github.com/microsoft/typescript-go/internal/ast" @@ -316,6 +317,14 @@ func (f *NodeFactory) NewFunctionCallCall(target *ast.Expression, thisArg *ast.E return f.NewMethodCall(target, f.NewIdentifier("call"), args) } +func (f *NodeFactory) NewArraySliceCall(array *ast.Expression, start int) *ast.Node { + var args []*ast.Node + if start != 0 { + args = append(args, f.NewNumericLiteral(strconv.Itoa(start))) + } + return f.NewMethodCall(array, f.NewIdentifier("slice"), args) +} + // Determines whether a node is a parenthesized expression that can be ignored when recreating outer expressions. // // A parenthesized expression can be ignored when all of the following are true: diff --git a/internal/printer/printer.go b/internal/printer/printer.go index 0a3a3e6ef4..6dd518ca0a 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -785,7 +785,9 @@ func (p *Printer) shouldEmitBlockFunctionBodyOnSingleLine(body *ast.Block) bool } func (p *Printer) shouldEmitOnNewLine(node *ast.Node, format ListFormat) bool { - // !!! if startsOnNewLine := getStartsOnNewLine(node); startsOnNewLine != nil { return *startsOnNewLine } + if p.emitContext.EmitFlags(node)&EFStartOnNewLine != 0 { + return true + } return format&LFPreferNewLine != 0 } diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index c08d208540..486b0336c5 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -2,9 +2,11 @@ package estransforms import ( "context" + "strconv" "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/printer" "github.com/microsoft/typescript-go/internal/transformers" ) @@ -16,7 +18,15 @@ type pendingDecl struct { original *ast.Node } +type flattenLevel int + +const ( + flattenLevelAll flattenLevel = iota + flattenLevelObjectRest +) + type flattenContext struct { + level flattenLevel currentExpressions []*ast.Node currentDeclarations []pendingDecl hasTransformedPriorElement bool @@ -32,15 +42,18 @@ type objectRestSpreadTransformer struct { inExportedVariableStatement bool - ctx flattenContext + ctx flattenContext + parametersWithPrecedingObjectRestOrSpread map[*ast.Node]struct{} } func (ch *objectRestSpreadTransformer) enterFlattenContext( + level flattenLevel, emitBindingOrAssignment func(t *objectRestSpreadTransformer, target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node), hoistTempVariables bool, ) oldFlattenContext { old := ch.ctx ch.ctx = flattenContext{ + level: level, emitBindingOrAssignment: emitBindingOrAssignment, hoistTempVariables: hoistTempVariables, } @@ -68,16 +81,312 @@ func (ch *objectRestSpreadTransformer) visit(node *ast.Node) *ast.Node { return ch.visitVariableDeclaration(node.AsVariableDeclaration()) case ast.KindCatchClause: return ch.visitCatchClause(node.AsCatchClause()) + case ast.KindParameter: + return ch.visitParameter(node.AsParameterDeclaration()) + case ast.KindConstructor: + return ch.visitContructorDeclaration(node.AsConstructorDeclaration()) + case ast.KindGetAccessor: + return ch.visitGetAccessorDeclaration(node.AsGetAccessorDeclaration()) + case ast.KindSetAccessor: + return ch.visitSetAccessorDeclaration(node.AsSetAccessorDeclaration()) + case ast.KindMethodDeclaration: + return ch.visitMethodDeclaration(node.AsMethodDeclaration()) + case ast.KindFunctionDeclaration: + return ch.visitFunctionDeclaration(node.AsFunctionDeclaration()) + case ast.KindArrowFunction: + return ch.visitArrowFunction(node.AsArrowFunction()) + case ast.KindFunctionExpression: + return ch.visitFunctionExpression(node.AsFunctionExpression()) default: return ch.Visitor().VisitEachChild(node) } } +func (ch *objectRestSpreadTransformer) visitParameter(node *ast.ParameterDeclaration) *ast.Node { + if ch.parametersWithPrecedingObjectRestOrSpread != nil { + if _, ok := ch.parametersWithPrecedingObjectRestOrSpread[node.AsNode()]; ok { + name := node.Name() + if ast.IsBindingPattern(name) { + name = ch.Factory().NewGeneratedNameForNode(node.AsNode()) + } + return ch.Factory().UpdateParameterDeclaration( + node, + nil, + node.DotDotDotToken, + name, + nil, + nil, + ch.Visitor().VisitNode(node.Initializer), + ) + } + } + if node.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 { + // Binding patterns are converted into a generated name and are + // evaluated inside the function body. + return ch.Factory().UpdateParameterDeclaration( + node, + nil, + node.DotDotDotToken, + ch.Factory().NewGeneratedNameForNode(node.AsNode()), + nil, + nil, + ch.Visitor().VisitNode(node.Initializer), + ) + } + return ch.Visitor().VisitEachChild(node.AsNode()) +} + +func (ch *objectRestSpreadTransformer) collectParametersWithPrecedingObjectRestOrSpread(node *ast.Node) map[*ast.Node]struct{} { + var result map[*ast.Node]struct{} + for _, parameter := range node.Parameters() { + if result != nil { + result[parameter] = struct{}{} + } else if parameter.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 { + result = make(map[*ast.Node]struct{}) + } + } + return result +} + +type oldParamScope map[*ast.Node]struct{} + +func (ch *objectRestSpreadTransformer) enterParameterListContext(node *ast.Node) oldParamScope { + old := ch.parametersWithPrecedingObjectRestOrSpread + ch.parametersWithPrecedingObjectRestOrSpread = ch.collectParametersWithPrecedingObjectRestOrSpread(node) + return oldParamScope(old) +} + +func (ch *objectRestSpreadTransformer) exitParameterListContext(scope oldParamScope) { + ch.parametersWithPrecedingObjectRestOrSpread = map[*ast.Node]struct{}(scope) +} + +func (ch *objectRestSpreadTransformer) visitContructorDeclaration(node *ast.ConstructorDeclaration) *ast.Node { + old := ch.enterParameterListContext(node.AsNode()) + defer ch.exitParameterListContext(old) + return ch.Factory().UpdateConstructorDeclaration( + node, + node.Modifiers(), + nil, + ch.Visitor().VisitNodes(node.Parameters), + nil, + ch.transformFunctionBody(node.AsNode()), + ) +} + +func (ch *objectRestSpreadTransformer) visitGetAccessorDeclaration(node *ast.GetAccessorDeclaration) *ast.Node { + old := ch.enterParameterListContext(node.AsNode()) + defer ch.exitParameterListContext(old) + return ch.Factory().UpdateGetAccessorDeclaration( + node, + node.Modifiers(), + ch.Visitor().VisitNode(node.Name()), + nil, + ch.Visitor().VisitNodes(node.Parameters), + nil, + ch.transformFunctionBody(node.AsNode()), + ) +} + +func (ch *objectRestSpreadTransformer) visitSetAccessorDeclaration(node *ast.SetAccessorDeclaration) *ast.Node { + old := ch.enterParameterListContext(node.AsNode()) + defer ch.exitParameterListContext(old) + return ch.Factory().UpdateSetAccessorDeclaration( + node, + node.Modifiers(), + ch.Visitor().VisitNode(node.Name()), + nil, + ch.Visitor().VisitNodes(node.Parameters), + nil, + ch.transformFunctionBody(node.AsNode()), + ) +} + +func (ch *objectRestSpreadTransformer) visitMethodDeclaration(node *ast.MethodDeclaration) *ast.Node { + old := ch.enterParameterListContext(node.AsNode()) + defer ch.exitParameterListContext(old) + return ch.Factory().UpdateMethodDeclaration( + node, + node.Modifiers(), + node.AsteriskToken, + ch.Visitor().VisitNode(node.Name()), + node.PostfixToken, + nil, + ch.Visitor().VisitNodes(node.Parameters), + nil, + ch.transformFunctionBody(node.AsNode()), + ) +} + +func (ch *objectRestSpreadTransformer) visitFunctionDeclaration(node *ast.FunctionDeclaration) *ast.Node { + old := ch.enterParameterListContext(node.AsNode()) + defer ch.exitParameterListContext(old) + return ch.Factory().UpdateFunctionDeclaration( + node, + node.Modifiers(), + node.AsteriskToken, + ch.Visitor().VisitNode(node.Name()), + nil, + ch.Visitor().VisitNodes(node.Parameters), + nil, + ch.transformFunctionBody(node.AsNode()), + ) +} + +func (ch *objectRestSpreadTransformer) visitArrowFunction(node *ast.ArrowFunction) *ast.Node { + old := ch.enterParameterListContext(node.AsNode()) + defer ch.exitParameterListContext(old) + return ch.Factory().UpdateArrowFunction( + node, + node.Modifiers(), + nil, + ch.Visitor().VisitNodes(node.Parameters), + nil, + node.EqualsGreaterThanToken, + ch.transformFunctionBody(node.AsNode()), + ) +} + +func (ch *objectRestSpreadTransformer) visitFunctionExpression(node *ast.FunctionExpression) *ast.Node { + old := ch.enterParameterListContext(node.AsNode()) + defer ch.exitParameterListContext(old) + return ch.Factory().UpdateFunctionExpression( + node, + node.Modifiers(), + node.AsteriskToken, + ch.Visitor().VisitNode(node.Name()), + nil, + ch.Visitor().VisitNodes(node.Parameters), + nil, + ch.transformFunctionBody(node.AsNode()), + ) +} + +func (ch *objectRestSpreadTransformer) transformFunctionBody(node *ast.Node) *ast.Node { + newStatements := ch.collectObjectRestAssignments(node) + body := ch.EmitContext().VisitFunctionBody(node.Body(), ch.Visitor()) + if len(newStatements) == 0 { + return body + } + + if body == nil { + body = ch.Factory().NewBlock(ch.Factory().NewNodeList([]*ast.Node{}), true) + } + var prefix []*ast.Node + var suffix []*ast.Node + if ast.IsBlock(body) { + custom := false + for i, statement := range body.AsBlock().Statements.Nodes { + if !custom && ast.IsPrologueDirective(statement) { + prefix = append(prefix, statement) + } else if ch.EmitContext().EmitFlags(statement)&printer.EFCustomPrologue != 0 { + custom = true + prefix = append(prefix, statement) + } else { + suffix = body.AsBlock().Statements.Nodes[i:] + break + } + } + } else { + list := ch.Factory().NewNodeList([]*ast.Node{}) + list.Loc = body.Loc + body = ch.Factory().NewBlock(list, true) + ret := ch.Factory().NewReturnStatement(body) + ret.Loc = body.Loc + suffix = append(suffix, ret) + } + + newStatementList := ch.Factory().NewNodeList(append(append(prefix, newStatements...), suffix...)) + newStatementList.Loc = body.AsBlock().Statements.Loc + return ch.Factory().UpdateBlock(body.AsBlock(), newStatementList) +} + +func (ch *objectRestSpreadTransformer) collectObjectRestAssignments(node *ast.Node) []*ast.Node { + containsPrecedingObjectRestOrSpread := false + var results []*ast.Node + for _, parameter := range node.Parameters() { + if containsPrecedingObjectRestOrSpread { + if ast.IsBindingPattern(parameter.Name()) { + // In cases where a binding pattern is simply '[]' or '{}', + // we usually don't want to emit a var declaration; however, in the presence + // of an initializer, we must emit that expression to preserve side effects. + if len(parameter.Name().AsBindingPattern().Elements.Nodes) > 0 { + declarations := ch.flattenDestructuringBinding(flattenLevelAll, parameter, ch.Factory().NewGeneratedNameForNode(parameter), false) + if declarations != nil { + declarationList := ch.Factory().NewVariableDeclarationList(ast.NodeFlagsNone, ch.Factory().NewNodeList([]*ast.Node{})) + decls := []*ast.Node{declarations} + if declarations.Kind == ast.KindSyntaxList { + decls = declarations.AsSyntaxList().Children + } + declarationList.AsVariableDeclarationList().Declarations.Nodes = append(declarationList.AsVariableDeclarationList().Declarations.Nodes, decls...) + statement := ch.Factory().NewVariableStatement(nil, declarationList) + ch.EmitContext().AddEmitFlags(statement, printer.EFCustomPrologue) + results = append(results, statement) + } + } else if parameter.Initializer() != nil { + name := ch.Factory().NewGeneratedNameForNode(parameter) + initializer := ch.Visitor().VisitNode(parameter.Initializer()) + assignment := ch.Factory().NewAssignmentExpression(name, initializer) + statement := ch.Factory().NewExpressionStatement(assignment) + ch.EmitContext().AddEmitFlags(statement, printer.EFCustomPrologue) + results = append(results, statement) + + } + } else if parameter.Initializer() != nil { + // Converts a parameter initializer into a function body statement, i.e.: + // + // function f(x = 1) { } + // + // becomes + // + // function f(x) { + // if (typeof x === "undefined") { x = 1; } + // } + name := parameter.Name().Clone(ch.Factory()) + name.Loc = parameter.Name().Loc + ch.EmitContext().AddEmitFlags(name, printer.EFNoSourceMap) + + initializer := ch.Visitor().VisitNode(parameter.Initializer()) + ch.EmitContext().AddEmitFlags(initializer, printer.EFNoSourceMap|printer.EFNoComments) + + assignment := ch.Factory().NewAssignmentExpression(name, initializer) + assignment.Loc = parameter.Loc + ch.EmitContext().AddEmitFlags(assignment, printer.EFNoComments) + + block := ch.Factory().NewBlock(ch.Factory().NewNodeList([]*ast.Node{ch.Factory().NewExpressionStatement(assignment)}), false) + block.Loc = parameter.Loc + ch.EmitContext().AddEmitFlags(block, printer.EFSingleLine|printer.EFNoTrailingSourceMap|printer.EFNoTokenSourceMaps|printer.EFNoComments) + + typeCheck := ch.Factory().NewTypeCheck(name.Clone(ch.Factory()), "undefined") + statement := ch.Factory().NewIfStatement(typeCheck, block, nil) + statement.Loc = parameter.Loc + ch.EmitContext().AddEmitFlags(statement, printer.EFNoTokenSourceMaps|printer.EFNoTrailingSourceMap|printer.EFCustomPrologue|printer.EFNoComments|printer.EFStartOnNewLine) + results = append(results, statement) + } + } else if parameter.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 { + containsPrecedingObjectRestOrSpread = true + declarations := ch.flattenDestructuringBinding(flattenLevelObjectRest, parameter, ch.Factory().NewGeneratedNameForNode(parameter), true) + if declarations != nil { + declarationList := ch.Factory().NewVariableDeclarationList(ast.NodeFlagsNone, ch.Factory().NewNodeList([]*ast.Node{})) + decls := []*ast.Node{declarations} + if declarations.Kind == ast.KindSyntaxList { + decls = declarations.AsSyntaxList().Children + } + declarationList.AsVariableDeclarationList().Declarations.Nodes = append(declarationList.AsVariableDeclarationList().Declarations.Nodes, decls...) + statement := ch.Factory().NewVariableStatement(nil, declarationList) + ch.EmitContext().AddEmitFlags(statement, printer.EFCustomPrologue) + results = append(results, statement) + } + } + } + + return results +} + func (ch *objectRestSpreadTransformer) visitCatchClause(node *ast.CatchClause) *ast.Node { if node.VariableDeclaration != nil && ast.IsBindingPattern(node.VariableDeclaration.Name()) && node.VariableDeclaration.Name().SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 { name := ch.Factory().NewGeneratedNameForNode(node.VariableDeclaration.Name()) updatedDecl := ch.Factory().UpdateVariableDeclaration(node.VariableDeclaration.AsVariableDeclaration(), node.VariableDeclaration.Name(), nil, nil, name) - visitedBindings := ch.flattenDestructuringBinding(updatedDecl.AsVariableDeclaration(), false) + visitedBindings := ch.flattenDestructuringBinding(flattenLevelObjectRest, updatedDecl, nil, false) block := ch.Visitor().VisitNode(node.Block) if visitedBindings != nil { var decls []*ast.Node @@ -130,26 +439,30 @@ func (ch *objectRestSpreadTransformer) visitVariableDeclarationWorker(node *ast. // If we are here it is because the name contains a binding pattern with a rest somewhere in it. if ast.IsBindingPattern(node.Name()) && node.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 { return ch.flattenDestructuringBinding( - node, + flattenLevelObjectRest, + node.AsNode(), + nil, exported, ) } return ch.Visitor().VisitEachChild(node.AsNode()) } -func (ch *objectRestSpreadTransformer) flattenDestructuringBinding(node *ast.VariableDeclaration, skipInitializer bool) *ast.Node { - old := ch.enterFlattenContext((*objectRestSpreadTransformer).emitBinding, false) +func (ch *objectRestSpreadTransformer) flattenDestructuringBinding(level flattenLevel, node *ast.Node, rvalue *ast.Node, skipInitializer bool) *ast.Node { + old := ch.enterFlattenContext(level, (*objectRestSpreadTransformer).emitBinding, false) defer ch.exitFlattenContext(old) - initializer := getInitializerOfBindingOrAssignmentElement(node.AsNode()) - if initializer != nil && (ast.IsIdentifier(initializer) && bindingOrAssignmentElementAssignsToName(node.AsNode(), initializer.AsIdentifier().Text) || bindingOrAssignmentElementContainsNonLiteralComputedName(node.AsNode())) { - // If the right-hand value of the assignment is also an assignment target then - // we need to cache the right-hand value. - initializer = ch.ensureIdentifier(ch.Visitor().VisitNode(initializer), false, initializer.Loc) - node = ch.Factory().UpdateVariableDeclaration(node, node.Name(), nil, nil, initializer).AsVariableDeclaration() + if ast.IsVariableDeclaration(node) { + initializer := getInitializerOfBindingOrAssignmentElement(node) + if initializer != nil && (ast.IsIdentifier(initializer) && bindingOrAssignmentElementAssignsToName(node, initializer.AsIdentifier().Text) || bindingOrAssignmentElementContainsNonLiteralComputedName(node)) { + // If the right-hand value of the assignment is also an assignment target then + // we need to cache the right-hand value. + initializer = ch.ensureIdentifier(ch.Visitor().VisitNode(initializer), false, initializer.Loc) + node = ch.Factory().UpdateVariableDeclaration(node.AsVariableDeclaration(), node.Name(), nil, nil, initializer) + } } - ch.flattenBindingOrAssignmentElement(node.AsNode(), nil, node.Loc, skipInitializer) + ch.flattenBindingOrAssignmentElement(node, rvalue, node.Loc, skipInitializer) if len(ch.ctx.currentExpressions) > 0 { temp := ch.Factory().NewTempVariable() @@ -289,7 +602,7 @@ func (ch *objectRestSpreadTransformer) flattenDestructuringAssignment(node *ast. } } } - old := ch.enterFlattenContext((*objectRestSpreadTransformer).emitAssignment, true) + old := ch.enterFlattenContext(flattenLevelObjectRest, (*objectRestSpreadTransformer).emitAssignment, true) defer ch.exitFlattenContext(old) if value != nil { @@ -299,7 +612,11 @@ func (ch *objectRestSpreadTransformer) flattenDestructuringAssignment(node *ast. // If the right-hand value of the assignment is also an assignment target then // we need to cache the right-hand value. value = ch.ensureIdentifier(value, false, location) - } else if ast.NodeIsSynthesized(node.AsNode()) { + } else { + value = ch.ensureIdentifier(value, true, location) + } + + if ast.NodeIsSynthesized(node.AsNode()) { // Generally, the source map location for a destructuring assignment is the root // expression. // @@ -308,7 +625,6 @@ func (ch *objectRestSpreadTransformer) flattenDestructuringAssignment(node *ast. // location should point to the right-hand value of the expression. location = value.Loc } - // !!! else if needsValue {} } ch.flattenBindingOrAssignmentElement(node.AsNode(), value, location, ast.IsDestructuringAssignment(node.AsNode())) @@ -366,7 +682,7 @@ func (ch *objectRestSpreadTransformer) flattenObjectBindingOrAssignmentPattern(p for i, element := range elements { if ast.GetRestIndicatorOfBindingOrAssignmentElement(element) == nil { propertyName := ast.TryGetPropertyNameOfBindingOrAssignmentElement(element) - if element.SubtreeFacts()&(ast.SubtreeContainsRest|ast.SubtreeContainsObjectRestOrSpread) == 0 && ast.GetTargetOfBindingOrAssignmentElement(element).SubtreeFacts()&(ast.SubtreeContainsRest|ast.SubtreeContainsObjectRestOrSpread) == 0 && !ast.IsComputedPropertyName(propertyName) { + if ch.ctx.level >= flattenLevelObjectRest && element.SubtreeFacts()&(ast.SubtreeContainsRest|ast.SubtreeContainsObjectRestOrSpread) == 0 && ast.GetTargetOfBindingOrAssignmentElement(element).SubtreeFacts()&(ast.SubtreeContainsRest|ast.SubtreeContainsObjectRestOrSpread) == 0 && !ast.IsComputedPropertyName(propertyName) { bindingElements = append(bindingElements, ch.Visitor().VisitNode(element)) } else { if len(bindingElements) > 0 { @@ -401,7 +717,7 @@ type restIdElemPair struct { func (ch *objectRestSpreadTransformer) flattenArrayBindingOrAssignmentPattern(parent *ast.Node, pattern *ast.Node, value *ast.Node, location core.TextRange) { elements := ast.GetElementsOfBindingOrAssignmentPattern(pattern) numElements := len(elements) - if numElements != 1 || core.Every(elements, ast.IsOmittedExpression) { + if numElements != 1 && (ch.ctx.level < flattenLevelObjectRest || numElements == 0) || core.Every(elements, ast.IsOmittedExpression) { // For anything other than a single-element destructuring we need to generate a temporary // to ensure value is evaluated exactly once. Additionally, if we have zero elements // we need to emit *something* to ensure that in case a 'var' keyword was already emitted, @@ -413,22 +729,31 @@ func (ch *objectRestSpreadTransformer) flattenArrayBindingOrAssignmentPattern(pa } var bindingElements []*ast.Node var restContainingElements []restIdElemPair - for _, element := range elements { - // If an array pattern contains an ObjectRest, we must cache the result so that we - // can perform the ObjectRest destructuring in a different declaration - if element.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 || ch.ctx.hasTransformedPriorElement && !isSimpleBindingOrAssignmentElement(element) { - ch.ctx.hasTransformedPriorElement = true - temp := ch.Factory().NewTempVariable() - if ch.ctx.hoistTempVariables { - ch.EmitContext().AddVariableDeclaration(temp) - } + for i, element := range elements { + if ch.ctx.level >= flattenLevelObjectRest { + // If an array pattern contains an ObjectRest, we must cache the result so that we + // can perform the ObjectRest destructuring in a different declaration + if element.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 || ch.ctx.hasTransformedPriorElement && !isSimpleBindingOrAssignmentElement(element) { + ch.ctx.hasTransformedPriorElement = true + temp := ch.Factory().NewTempVariable() + if ch.ctx.hoistTempVariables { + ch.EmitContext().AddVariableDeclaration(temp) + } - restContainingElements = append(restContainingElements, restIdElemPair{temp, element}) - bindingElements = append(bindingElements, ch.Factory().NewBindingElement(nil, nil, temp, nil)) - } else { - bindingElements = append(bindingElements, element) + restContainingElements = append(restContainingElements, restIdElemPair{temp, element}) + bindingElements = append(bindingElements, ch.Factory().NewBindingElement(nil, nil, temp, nil)) + } else { + bindingElements = append(bindingElements, element) + } + } else if ast.IsOmittedExpression(element) { + continue + } else if ast.GetRestIndicatorOfBindingOrAssignmentElement(element) == nil { + rhsValue := ch.Factory().NewElementAccessExpression(value, nil, ch.Factory().NewNumericLiteral(strconv.Itoa(i)), ast.NodeFlagsNone) + ch.flattenBindingOrAssignmentElement(element, rhsValue, element.Loc, false) + } else if i == numElements-1 { + rhsValue := ch.Factory().NewArraySliceCall(value, i) + ch.flattenBindingOrAssignmentElement(element, rhsValue, element.Loc, false) } - // !!! ??? other flatten levels? only objectRest currently in use } if len(bindingElements) > 0 { ch.ctx.emitBindingOrAssignment(ch, ch.createArrayBindingOrAssignmentPattern(bindingElements), value, location, pattern) From 93f769079bec128647265979516a4360fdfec5a7 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 14:26:13 -0700 Subject: [PATCH 05/18] Add missing ctor indirection --- .../estransforms/objectrestspread.go | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index 486b0336c5..c30e8c2f60 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -26,12 +26,14 @@ const ( ) type flattenContext struct { - level flattenLevel - currentExpressions []*ast.Node - currentDeclarations []pendingDecl - hasTransformedPriorElement bool - emitBindingOrAssignment func(t *objectRestSpreadTransformer, target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node) - hoistTempVariables bool + level flattenLevel + currentExpressions []*ast.Node + currentDeclarations []pendingDecl + hasTransformedPriorElement bool + emitBindingOrAssignment func(t *objectRestSpreadTransformer, target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node) + createArrayBindingOrAssignmentPattern func(t *objectRestSpreadTransformer, elements []*ast.Node) *ast.Node + createObjectBindingOrAssignmentPattern func(t *objectRestSpreadTransformer, elements []*ast.Node) *ast.Node + hoistTempVariables bool } type oldFlattenContext flattenContext @@ -49,13 +51,17 @@ type objectRestSpreadTransformer struct { func (ch *objectRestSpreadTransformer) enterFlattenContext( level flattenLevel, emitBindingOrAssignment func(t *objectRestSpreadTransformer, target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node), + createArrayBindingOrAssignmentPattern func(t *objectRestSpreadTransformer, elements []*ast.Node) *ast.Node, + createObjectBindingOrAssignmentPattern func(t *objectRestSpreadTransformer, elements []*ast.Node) *ast.Node, hoistTempVariables bool, ) oldFlattenContext { old := ch.ctx ch.ctx = flattenContext{ - level: level, - emitBindingOrAssignment: emitBindingOrAssignment, - hoistTempVariables: hoistTempVariables, + level: level, + emitBindingOrAssignment: emitBindingOrAssignment, + createArrayBindingOrAssignmentPattern: createArrayBindingOrAssignmentPattern, + createObjectBindingOrAssignmentPattern: createObjectBindingOrAssignmentPattern, + hoistTempVariables: hoistTempVariables, } return oldFlattenContext(old) } @@ -449,7 +455,7 @@ func (ch *objectRestSpreadTransformer) visitVariableDeclarationWorker(node *ast. } func (ch *objectRestSpreadTransformer) flattenDestructuringBinding(level flattenLevel, node *ast.Node, rvalue *ast.Node, skipInitializer bool) *ast.Node { - old := ch.enterFlattenContext(level, (*objectRestSpreadTransformer).emitBinding, false) + old := ch.enterFlattenContext(level, (*objectRestSpreadTransformer).emitBinding, (*objectRestSpreadTransformer).createArrayBindingPattern, (*objectRestSpreadTransformer).createObjectBindingPattern, false) defer ch.exitFlattenContext(old) if ast.IsVariableDeclaration(node) { @@ -602,7 +608,7 @@ func (ch *objectRestSpreadTransformer) flattenDestructuringAssignment(node *ast. } } } - old := ch.enterFlattenContext(flattenLevelObjectRest, (*objectRestSpreadTransformer).emitAssignment, true) + old := ch.enterFlattenContext(flattenLevelObjectRest, (*objectRestSpreadTransformer).emitAssignment, (*objectRestSpreadTransformer).createArrayAssignmentPattern, (*objectRestSpreadTransformer).createObjectAssignmentPattern, true) defer ch.exitFlattenContext(old) if value != nil { @@ -686,7 +692,7 @@ func (ch *objectRestSpreadTransformer) flattenObjectBindingOrAssignmentPattern(p bindingElements = append(bindingElements, ch.Visitor().VisitNode(element)) } else { if len(bindingElements) > 0 { - ch.ctx.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) + ch.ctx.emitBindingOrAssignment(ch, ch.ctx.createObjectBindingOrAssignmentPattern(ch, bindingElements), value, location, pattern) bindingElements = nil } rhsValue := ch.createDestructuringPropertyAccess(value, propertyName) @@ -697,7 +703,7 @@ func (ch *objectRestSpreadTransformer) flattenObjectBindingOrAssignmentPattern(p } } else if i == numElements-1 { if len(bindingElements) > 0 { - ch.ctx.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) + ch.ctx.emitBindingOrAssignment(ch, ch.ctx.createObjectBindingOrAssignmentPattern(ch, bindingElements), value, location, pattern) bindingElements = nil } rhsValue := ch.Factory().NewRestHelper(value, elements, computedTempVariables, pattern.Loc) @@ -705,7 +711,7 @@ func (ch *objectRestSpreadTransformer) flattenObjectBindingOrAssignmentPattern(p } } if len(bindingElements) > 0 { - ch.ctx.emitBindingOrAssignment(ch, ch.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern) + ch.ctx.emitBindingOrAssignment(ch, ch.ctx.createObjectBindingOrAssignmentPattern(ch, bindingElements), value, location, pattern) } } @@ -756,7 +762,7 @@ func (ch *objectRestSpreadTransformer) flattenArrayBindingOrAssignmentPattern(pa } } if len(bindingElements) > 0 { - ch.ctx.emitBindingOrAssignment(ch, ch.createArrayBindingOrAssignmentPattern(bindingElements), value, location, pattern) + ch.ctx.emitBindingOrAssignment(ch, ch.ctx.createArrayBindingOrAssignmentPattern(ch, bindingElements), value, location, pattern) } if len(restContainingElements) > 0 { for _, pair := range restContainingElements { @@ -803,14 +809,22 @@ func (ch *objectRestSpreadTransformer) createDestructuringPropertyAccess(value * } } -func (ch *objectRestSpreadTransformer) createObjectBindingOrAssignmentPattern(elements []*ast.Node) *ast.Node { +func (ch *objectRestSpreadTransformer) createObjectBindingPattern(elements []*ast.Node) *ast.Node { return ch.Factory().NewBindingPattern(ast.KindObjectBindingPattern, ch.Factory().NewNodeList(elements)) } -func (ch *objectRestSpreadTransformer) createArrayBindingOrAssignmentPattern(elements []*ast.Node) *ast.Node { +func (ch *objectRestSpreadTransformer) createArrayBindingPattern(elements []*ast.Node) *ast.Node { return ch.Factory().NewBindingPattern(ast.KindArrayBindingPattern, ch.Factory().NewNodeList(elements)) } +func (ch *objectRestSpreadTransformer) createObjectAssignmentPattern(elements []*ast.Node) *ast.Node { + return ch.Factory().NewObjectLiteralExpression(ch.Factory().NewNodeList(elements), false) +} + +func (ch *objectRestSpreadTransformer) createArrayAssignmentPattern(elements []*ast.Node) *ast.Node { + return ch.Factory().NewArrayLiteralExpression(ch.Factory().NewNodeList(elements), false) +} + func (ch *objectRestSpreadTransformer) emitExpression(node *ast.Node) { ch.ctx.currentExpressions = append(ch.ctx.currentExpressions, node) } From 83785d60bd703ba39371cf99bda8e052fe6d1a27 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 14:46:27 -0700 Subject: [PATCH 06/18] Another missing binding/assignment indirection that ends up being important --- .../estransforms/objectrestspread.go | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index c30e8c2f60..de7e9b7505 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -33,6 +33,7 @@ type flattenContext struct { emitBindingOrAssignment func(t *objectRestSpreadTransformer, target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node) createArrayBindingOrAssignmentPattern func(t *objectRestSpreadTransformer, elements []*ast.Node) *ast.Node createObjectBindingOrAssignmentPattern func(t *objectRestSpreadTransformer, elements []*ast.Node) *ast.Node + createArrayBindingOrAssignmentElement func(t *objectRestSpreadTransformer, expr *ast.Node) *ast.Node hoistTempVariables bool } @@ -53,6 +54,7 @@ func (ch *objectRestSpreadTransformer) enterFlattenContext( emitBindingOrAssignment func(t *objectRestSpreadTransformer, target *ast.Node, value *ast.Node, location core.TextRange, original *ast.Node), createArrayBindingOrAssignmentPattern func(t *objectRestSpreadTransformer, elements []*ast.Node) *ast.Node, createObjectBindingOrAssignmentPattern func(t *objectRestSpreadTransformer, elements []*ast.Node) *ast.Node, + createArrayBindingOrAssignmentElement func(t *objectRestSpreadTransformer, expr *ast.Node) *ast.Node, hoistTempVariables bool, ) oldFlattenContext { old := ch.ctx @@ -61,6 +63,7 @@ func (ch *objectRestSpreadTransformer) enterFlattenContext( emitBindingOrAssignment: emitBindingOrAssignment, createArrayBindingOrAssignmentPattern: createArrayBindingOrAssignmentPattern, createObjectBindingOrAssignmentPattern: createObjectBindingOrAssignmentPattern, + createArrayBindingOrAssignmentElement: createArrayBindingOrAssignmentElement, hoistTempVariables: hoistTempVariables, } return oldFlattenContext(old) @@ -268,9 +271,11 @@ func (ch *objectRestSpreadTransformer) visitFunctionExpression(node *ast.Functio } func (ch *objectRestSpreadTransformer) transformFunctionBody(node *ast.Node) *ast.Node { + body := ch.Visitor().VisitNode(node.Body()) + ch.EmitContext().StartLexicalEnvironment() newStatements := ch.collectObjectRestAssignments(node) - body := ch.EmitContext().VisitFunctionBody(node.Body(), ch.Visitor()) - if len(newStatements) == 0 { + extras := ch.EmitContext().EndLexicalEnvironment() + if len(newStatements) == 0 && len(extras) == 0 { return body } @@ -301,7 +306,7 @@ func (ch *objectRestSpreadTransformer) transformFunctionBody(node *ast.Node) *as suffix = append(suffix, ret) } - newStatementList := ch.Factory().NewNodeList(append(append(prefix, newStatements...), suffix...)) + newStatementList := ch.Factory().NewNodeList(append(append(append(prefix, extras...), newStatements...), suffix...)) newStatementList.Loc = body.AsBlock().Statements.Loc return ch.Factory().UpdateBlock(body.AsBlock(), newStatementList) } @@ -455,7 +460,7 @@ func (ch *objectRestSpreadTransformer) visitVariableDeclarationWorker(node *ast. } func (ch *objectRestSpreadTransformer) flattenDestructuringBinding(level flattenLevel, node *ast.Node, rvalue *ast.Node, skipInitializer bool) *ast.Node { - old := ch.enterFlattenContext(level, (*objectRestSpreadTransformer).emitBinding, (*objectRestSpreadTransformer).createArrayBindingPattern, (*objectRestSpreadTransformer).createObjectBindingPattern, false) + old := ch.enterFlattenContext(level, (*objectRestSpreadTransformer).emitBinding, (*objectRestSpreadTransformer).createArrayBindingPattern, (*objectRestSpreadTransformer).createObjectBindingPattern, (*objectRestSpreadTransformer).createArrayBindingElement, false) defer ch.exitFlattenContext(old) if ast.IsVariableDeclaration(node) { @@ -608,7 +613,7 @@ func (ch *objectRestSpreadTransformer) flattenDestructuringAssignment(node *ast. } } } - old := ch.enterFlattenContext(flattenLevelObjectRest, (*objectRestSpreadTransformer).emitAssignment, (*objectRestSpreadTransformer).createArrayAssignmentPattern, (*objectRestSpreadTransformer).createObjectAssignmentPattern, true) + old := ch.enterFlattenContext(flattenLevelObjectRest, (*objectRestSpreadTransformer).emitAssignment, (*objectRestSpreadTransformer).createArrayAssignmentPattern, (*objectRestSpreadTransformer).createObjectAssignmentPattern, (*objectRestSpreadTransformer).createArrayAssignmentElement, true) defer ch.exitFlattenContext(old) if value != nil { @@ -747,7 +752,7 @@ func (ch *objectRestSpreadTransformer) flattenArrayBindingOrAssignmentPattern(pa } restContainingElements = append(restContainingElements, restIdElemPair{temp, element}) - bindingElements = append(bindingElements, ch.Factory().NewBindingElement(nil, nil, temp, nil)) + bindingElements = append(bindingElements, ch.ctx.createArrayBindingOrAssignmentElement(ch, temp)) } else { bindingElements = append(bindingElements, element) } @@ -825,6 +830,14 @@ func (ch *objectRestSpreadTransformer) createArrayAssignmentPattern(elements []* return ch.Factory().NewArrayLiteralExpression(ch.Factory().NewNodeList(elements), false) } +func (ch *objectRestSpreadTransformer) createArrayAssignmentElement(expr *ast.Node) *ast.Node { + return expr +} + +func (ch *objectRestSpreadTransformer) createArrayBindingElement(expr *ast.Node) *ast.Node { + return ch.Factory().NewBindingElement(nil, nil, expr, nil) +} + func (ch *objectRestSpreadTransformer) emitExpression(node *ast.Node) { ch.ctx.currentExpressions = append(ch.ctx.currentExpressions, node) } From 3c55c1ad508fa33ad146480b7e744f76748abef6 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 14:56:15 -0700 Subject: [PATCH 07/18] Fix sequencing and nil crashes --- internal/transformers/estransforms/objectrestspread.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index de7e9b7505..9a7e34c67e 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -298,11 +298,11 @@ func (ch *objectRestSpreadTransformer) transformFunctionBody(node *ast.Node) *as } } } else { + ret := ch.Factory().NewReturnStatement(body) + ret.Loc = body.Loc list := ch.Factory().NewNodeList([]*ast.Node{}) list.Loc = body.Loc body = ch.Factory().NewBlock(list, true) - ret := ch.Factory().NewReturnStatement(body) - ret.Loc = body.Loc suffix = append(suffix, ret) } @@ -496,7 +496,9 @@ func (ch *objectRestSpreadTransformer) flattenDestructuringBinding(level flatten expr, ) decl.Loc = pending.location - ch.EmitContext().SetOriginal(decl, pending.original) + if pending.original != nil { + ch.EmitContext().SetOriginal(decl, pending.original) + } decls = append(decls, decl) } if len(decls) == 1 { From 6db0fc6faa62c75f72f86deb5be424317e2654cf Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 15:05:54 -0700 Subject: [PATCH 08/18] We supposedly dont support es5 so the helper should be unreachable, but tests still target es5, so get it right --- internal/transformers/estransforms/objectrestspread.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index 9a7e34c67e..ea216fff6b 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -78,6 +78,8 @@ func (ch *objectRestSpreadTransformer) visit(node *ast.Node) *ast.Node { return node } switch node.Kind { + case ast.KindSourceFile: + return ch.visitSourceFile(node.AsSourceFile()) case ast.KindObjectLiteralExpression: return ch.visitObjectLiteralExpression(node.AsObjectLiteralExpression()) case ast.KindBinaryExpression: @@ -111,6 +113,12 @@ func (ch *objectRestSpreadTransformer) visit(node *ast.Node) *ast.Node { } } +func (ch *objectRestSpreadTransformer) visitSourceFile(node *ast.SourceFile) *ast.Node { + visited := ch.Visitor().VisitEachChild(node.AsNode()) + ch.EmitContext().AddEmitHelper(visited.AsNode(), ch.EmitContext().ReadEmitHelpers()...) + return visited +} + func (ch *objectRestSpreadTransformer) visitParameter(node *ast.ParameterDeclaration) *ast.Node { if ch.parametersWithPrecedingObjectRestOrSpread != nil { if _, ok := ch.parametersWithPrecedingObjectRestOrSpread[node.AsNode()]; ok { From f9fb178ad1de44347bed714f80d9eeb48e6a6773 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 15:26:56 -0700 Subject: [PATCH 09/18] Detect rest in assignment expressions correctly, fix helper field name collection to skip the actual rest element --- internal/ast/ast.go | 2 +- internal/printer/factory.go | 5 ++++- internal/printer/printer.go | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/ast/ast.go b/internal/ast/ast.go index c9d30d85fb..0f83636dfb 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -3479,7 +3479,7 @@ func (node *BindingElement) computeSubtreeFacts() SubtreeFacts { return propagateSubtreeFacts(node.PropertyName) | propagateSubtreeFacts(node.name) | propagateSubtreeFacts(node.Initializer) | - core.IfElse(node.DotDotDotToken != nil, SubtreeContainsRest, SubtreeFactsNone) + core.IfElse(node.DotDotDotToken != nil, SubtreeContainsRest|SubtreeContainsESObjectRestOrSpread, SubtreeFactsNone) } func IsBindingElement(node *Node) bool { diff --git a/internal/printer/factory.go b/internal/printer/factory.go index 67441d0796..5860793d36 100644 --- a/internal/printer/factory.go +++ b/internal/printer/factory.go @@ -566,7 +566,10 @@ func (f *NodeFactory) NewRestHelper(value *ast.Expression, elements []*ast.Node, f.emitContext.RequestEmitHelper(restHelper) var propertyNames []*ast.Node computedTempVariableOffset := 0 - for _, element := range elements { + for i, element := range elements { + if i == len(elements)-1 { + break + } propertyName := ast.TryGetPropertyNameOfBindingOrAssignmentElement(element) if propertyName != nil { if ast.IsComputedPropertyName(propertyName) { diff --git a/internal/printer/printer.go b/internal/printer/printer.go index 6dd518ca0a..8d21243411 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -785,9 +785,10 @@ func (p *Printer) shouldEmitBlockFunctionBodyOnSingleLine(body *ast.Block) bool } func (p *Printer) shouldEmitOnNewLine(node *ast.Node, format ListFormat) bool { - if p.emitContext.EmitFlags(node)&EFStartOnNewLine != 0 { - return true - } + // !!! TODO: enable multiline emit + // if p.emitContext.EmitFlags(node)&EFStartOnNewLine != 0 { + // return true + // } return format&LFPreferNewLine != 0 } From 9cb689462230a2edb5abc65abce1ef538a88c889 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 15:44:19 -0700 Subject: [PATCH 10/18] Fix mistaken skipInitializers flag set crash --- .../transformers/estransforms/objectrestspread.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index ea216fff6b..caa7a2cc9a 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -329,7 +329,7 @@ func (ch *objectRestSpreadTransformer) collectObjectRestAssignments(node *ast.No // we usually don't want to emit a var declaration; however, in the presence // of an initializer, we must emit that expression to preserve side effects. if len(parameter.Name().AsBindingPattern().Elements.Nodes) > 0 { - declarations := ch.flattenDestructuringBinding(flattenLevelAll, parameter, ch.Factory().NewGeneratedNameForNode(parameter), false) + declarations := ch.flattenDestructuringBinding(flattenLevelAll, parameter, ch.Factory().NewGeneratedNameForNode(parameter), false, false) if declarations != nil { declarationList := ch.Factory().NewVariableDeclarationList(ast.NodeFlagsNone, ch.Factory().NewNodeList([]*ast.Node{})) decls := []*ast.Node{declarations} @@ -383,7 +383,7 @@ func (ch *objectRestSpreadTransformer) collectObjectRestAssignments(node *ast.No } } else if parameter.SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 { containsPrecedingObjectRestOrSpread = true - declarations := ch.flattenDestructuringBinding(flattenLevelObjectRest, parameter, ch.Factory().NewGeneratedNameForNode(parameter), true) + declarations := ch.flattenDestructuringBinding(flattenLevelObjectRest, parameter, ch.Factory().NewGeneratedNameForNode(parameter), false, true) if declarations != nil { declarationList := ch.Factory().NewVariableDeclarationList(ast.NodeFlagsNone, ch.Factory().NewNodeList([]*ast.Node{})) decls := []*ast.Node{declarations} @@ -405,7 +405,7 @@ func (ch *objectRestSpreadTransformer) visitCatchClause(node *ast.CatchClause) * if node.VariableDeclaration != nil && ast.IsBindingPattern(node.VariableDeclaration.Name()) && node.VariableDeclaration.Name().SubtreeFacts()&ast.SubtreeContainsObjectRestOrSpread != 0 { name := ch.Factory().NewGeneratedNameForNode(node.VariableDeclaration.Name()) updatedDecl := ch.Factory().UpdateVariableDeclaration(node.VariableDeclaration.AsVariableDeclaration(), node.VariableDeclaration.Name(), nil, nil, name) - visitedBindings := ch.flattenDestructuringBinding(flattenLevelObjectRest, updatedDecl, nil, false) + visitedBindings := ch.flattenDestructuringBinding(flattenLevelObjectRest, updatedDecl, nil, false, false) block := ch.Visitor().VisitNode(node.Block) if visitedBindings != nil { var decls []*ast.Node @@ -462,13 +462,14 @@ func (ch *objectRestSpreadTransformer) visitVariableDeclarationWorker(node *ast. node.AsNode(), nil, exported, + false, ) } return ch.Visitor().VisitEachChild(node.AsNode()) } -func (ch *objectRestSpreadTransformer) flattenDestructuringBinding(level flattenLevel, node *ast.Node, rvalue *ast.Node, skipInitializer bool) *ast.Node { - old := ch.enterFlattenContext(level, (*objectRestSpreadTransformer).emitBinding, (*objectRestSpreadTransformer).createArrayBindingPattern, (*objectRestSpreadTransformer).createObjectBindingPattern, (*objectRestSpreadTransformer).createArrayBindingElement, false) +func (ch *objectRestSpreadTransformer) flattenDestructuringBinding(level flattenLevel, node *ast.Node, rvalue *ast.Node, hoist bool, skipInitializer bool) *ast.Node { + old := ch.enterFlattenContext(level, (*objectRestSpreadTransformer).emitBinding, (*objectRestSpreadTransformer).createArrayBindingPattern, (*objectRestSpreadTransformer).createObjectBindingPattern, (*objectRestSpreadTransformer).createArrayBindingElement, hoist) defer ch.exitFlattenContext(old) if ast.IsVariableDeclaration(node) { From 8645a89c9672b5368c39fba10883f36d96b714d3 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 15:50:05 -0700 Subject: [PATCH 11/18] Lexical vs variable environment is more strictly named now, use the correct one --- internal/transformers/estransforms/objectrestspread.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index caa7a2cc9a..93a8cc8c17 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -279,10 +279,12 @@ func (ch *objectRestSpreadTransformer) visitFunctionExpression(node *ast.Functio } func (ch *objectRestSpreadTransformer) transformFunctionBody(node *ast.Node) *ast.Node { + ch.EmitContext().StartVariableEnvironment() body := ch.Visitor().VisitNode(node.Body()) - ch.EmitContext().StartLexicalEnvironment() + extras := ch.EmitContext().EndVariableEnvironment() + ch.EmitContext().StartVariableEnvironment() newStatements := ch.collectObjectRestAssignments(node) - extras := ch.EmitContext().EndLexicalEnvironment() + extras = ch.EmitContext().EndAndMergeVariableEnvironment(extras) if len(newStatements) == 0 && len(extras) == 0 { return body } From 42d5bf62aa96c490b5468589cde68c0879d570c7 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 16:01:25 -0700 Subject: [PATCH 12/18] Fix off by one in spread emit logic --- internal/transformers/estransforms/objectrestspread.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index 93a8cc8c17..c60aa98219 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -937,7 +937,7 @@ func (ch *objectRestSpreadTransformer) visitObjectLiteralExpression(node *ast.Ob objects = append([]*ast.Node{ch.Factory().NewObjectLiteralExpression(ch.Factory().NewNodeList(nil), false)}, objects...) } expression := objects[0] - if len(objects) > 0 { + if len(objects) > 1 { for i, obj := range objects { if i == 0 { continue From 6fa4dba401863c6e443e529b26cd85e14fe754fc Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 16:13:06 -0700 Subject: [PATCH 13/18] Fix initializers on parameters following destructured rest params --- internal/transformers/estransforms/objectrestspread.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index c60aa98219..da5640651d 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -74,7 +74,7 @@ func (ch *objectRestSpreadTransformer) exitFlattenContext(old oldFlattenContext) } func (ch *objectRestSpreadTransformer) visit(node *ast.Node) *ast.Node { - if node.SubtreeFacts()&ast.SubtreeContainsESObjectRestOrSpread == 0 { + if node.SubtreeFacts()&ast.SubtreeContainsESObjectRestOrSpread == 0 && ch.parametersWithPrecedingObjectRestOrSpread == nil { return node } switch node.Kind { @@ -133,7 +133,7 @@ func (ch *objectRestSpreadTransformer) visitParameter(node *ast.ParameterDeclara name, nil, nil, - ch.Visitor().VisitNode(node.Initializer), + nil, ) } } From 5943f57e5dc156d758576c4ce35d33551870b64c Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 17:30:42 -0700 Subject: [PATCH 14/18] Fix and comment on subtree fact flag usage a bit more - these are a little different from Strada in how they are calculated --- internal/ast/ast.go | 4 ++-- internal/ast/subtreefacts.go | 16 ++++++++-------- .../estransforms/objectrestspread.go | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/ast/ast.go b/internal/ast/ast.go index 0f83636dfb..00bc9259d7 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -3479,7 +3479,7 @@ func (node *BindingElement) computeSubtreeFacts() SubtreeFacts { return propagateSubtreeFacts(node.PropertyName) | propagateSubtreeFacts(node.name) | propagateSubtreeFacts(node.Initializer) | - core.IfElse(node.DotDotDotToken != nil, SubtreeContainsRest|SubtreeContainsESObjectRestOrSpread, SubtreeFactsNone) + core.IfElse(node.DotDotDotToken != nil, SubtreeContainsRestOrSpread, SubtreeFactsNone) } func IsBindingElement(node *Node) bool { @@ -6476,7 +6476,7 @@ func (node *SpreadElement) Clone(f NodeFactoryCoercible) *Node { } func (node *SpreadElement) computeSubtreeFacts() SubtreeFacts { - return propagateSubtreeFacts(node.Expression) + return propagateSubtreeFacts(node.Expression) | SubtreeContainsRestOrSpread } func IsSpreadElement(node *Node) bool { diff --git a/internal/ast/subtreefacts.go b/internal/ast/subtreefacts.go index 428fd68812..fcd6885044 100644 --- a/internal/ast/subtreefacts.go +++ b/internal/ast/subtreefacts.go @@ -20,7 +20,7 @@ const ( SubtreeContainsNullishCoalescing SubtreeContainsOptionalChaining SubtreeContainsMissingCatchClauseVariable - SubtreeContainsESObjectRestOrSpread + SubtreeContainsESObjectRestOrSpread // subtree has a `...` somewhere inside it, never cleared SubtreeContainsForAwaitOrAsyncGenerator SubtreeContainsAnyAwait SubtreeContainsExponentiationOperator @@ -30,8 +30,8 @@ const ( SubtreeContainsLexicalThis SubtreeContainsLexicalSuper - SubtreeContainsRest - SubtreeContainsObjectRestOrSpread + SubtreeContainsRestOrSpread // marker on any `...` - cleared on binding pattern exit + SubtreeContainsObjectRestOrSpread // marker on any `{...x}` - cleared on most scope exits SubtreeContainsAwait SubtreeContainsDynamicImport SubtreeContainsClassFields @@ -76,7 +76,7 @@ const ( SubtreeExclusionsVariableDeclarationList = SubtreeExclusionsNode | SubtreeContainsObjectRestOrSpread SubtreeExclusionsParameter = SubtreeExclusionsNode SubtreeExclusionsCatchClause = SubtreeExclusionsNode | SubtreeContainsObjectRestOrSpread - SubtreeExclusionsBindingPattern = SubtreeExclusionsNode | SubtreeContainsRest + SubtreeExclusionsBindingPattern = SubtreeExclusionsNode | SubtreeContainsRestOrSpread // Masks // - Additional bitmasks @@ -94,15 +94,15 @@ func propagateEraseableSyntaxSubtreeFacts(child *TypeNode) SubtreeFacts { func propagateObjectBindingElementSubtreeFacts(child *BindingElementNode) SubtreeFacts { facts := propagateSubtreeFacts(child) - if facts&SubtreeContainsRest != 0 { - facts &= ^SubtreeContainsRest - facts |= SubtreeContainsObjectRestOrSpread + if facts&SubtreeContainsRestOrSpread != 0 { + facts &= ^SubtreeContainsRestOrSpread + facts |= SubtreeContainsObjectRestOrSpread | SubtreeContainsESObjectRestOrSpread } return facts } func propagateBindingElementSubtreeFacts(child *BindingElementNode) SubtreeFacts { - return propagateSubtreeFacts(child) & ^SubtreeContainsRest + return propagateSubtreeFacts(child) & ^SubtreeContainsRestOrSpread } func propagateSubtreeFacts(child *Node) SubtreeFacts { diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index da5640651d..ac872a8086 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -706,7 +706,7 @@ func (ch *objectRestSpreadTransformer) flattenObjectBindingOrAssignmentPattern(p for i, element := range elements { if ast.GetRestIndicatorOfBindingOrAssignmentElement(element) == nil { propertyName := ast.TryGetPropertyNameOfBindingOrAssignmentElement(element) - if ch.ctx.level >= flattenLevelObjectRest && element.SubtreeFacts()&(ast.SubtreeContainsRest|ast.SubtreeContainsObjectRestOrSpread) == 0 && ast.GetTargetOfBindingOrAssignmentElement(element).SubtreeFacts()&(ast.SubtreeContainsRest|ast.SubtreeContainsObjectRestOrSpread) == 0 && !ast.IsComputedPropertyName(propertyName) { + if ch.ctx.level >= flattenLevelObjectRest && element.SubtreeFacts()&(ast.SubtreeContainsRestOrSpread|ast.SubtreeContainsObjectRestOrSpread) == 0 && ast.GetTargetOfBindingOrAssignmentElement(element).SubtreeFacts()&(ast.SubtreeContainsRestOrSpread|ast.SubtreeContainsObjectRestOrSpread) == 0 && !ast.IsComputedPropertyName(propertyName) { bindingElements = append(bindingElements, ch.Visitor().VisitNode(element)) } else { if len(bindingElements) > 0 { From a4387d1a6d1fef903dc939f513beb2dedfdedebe Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 17:41:27 -0700 Subject: [PATCH 15/18] Accept baselines --- .../anyAndUnknownHaveFalsyComponents.js | 29 +-- .../anyAndUnknownHaveFalsyComponents.js.diff | 41 ----- .../asyncFunctionTempVariableScoping.js | 16 +- .../asyncFunctionTempVariableScoping.js.diff | 30 ++-- .../contextualTypeObjectSpreadExpression.js | 13 +- ...ntextualTypeObjectSpreadExpression.js.diff | 20 --- .../declarationEmitKeywordDestructuring.js | 26 ++- ...eclarationEmitKeywordDestructuring.js.diff | 50 ------ ...declarationEmitReadonlyComputedProperty.js | 15 +- ...rationEmitReadonlyComputedProperty.js.diff | 22 +-- .../declarationEmitSpreadStringlyKeyedEnum.js | 13 +- ...arationEmitSpreadStringlyKeyedEnum.js.diff | 29 +-- ...ationEmitStringEnumUsedInNonlocalSpread.js | 16 +- ...EmitStringEnumUsedInNonlocalSpread.js.diff | 25 +-- ...iveInternalTypesProduceUniqueTypeParams.js | 13 +- ...ternalTypesProduceUniqueTypeParams.js.diff | 28 +-- ...ructuringAssignmentWithStrictNullChecks.js | 14 +- ...ringAssignmentWithStrictNullChecks.js.diff | 22 +-- .../compiler/destructuringFromUnionSpread.js | 13 +- .../destructuringFromUnionSpread.js.diff | 19 -- ...ingInitializerContextualTypeFromContext.js | 32 +++- ...itializerContextualTypeFromContext.js.diff | 36 +--- .../destructuringUnspreadableIntoRest.js | 27 ++- .../destructuringUnspreadableIntoRest.js.diff | 50 +----- ...ersWithLocalCollisions(module=commonjs).js | 2 +- ...thLocalCollisions(module=commonjs).js.diff | 3 +- ...lpersWithLocalCollisions(module=es2020).js | 2 +- ...WithLocalCollisions(module=es2020).js.diff | 3 +- ...lpersWithLocalCollisions(module=es2022).js | 2 +- ...WithLocalCollisions(module=es2022).js.diff | 3 +- ...tHelpersWithLocalCollisions(module=es6).js | 2 +- ...ersWithLocalCollisions(module=es6).js.diff | 3 +- ...lpersWithLocalCollisions(module=esnext).js | 2 +- ...WithLocalCollisions(module=esnext).js.diff | 3 +- ...lpersWithLocalCollisions(module=node16).js | 2 +- ...WithLocalCollisions(module=node16).js.diff | 3 +- ...lpersWithLocalCollisions(module=node18).js | 2 +- ...WithLocalCollisions(module=node18).js.diff | 3 +- ...ersWithLocalCollisions(module=nodenext).js | 2 +- ...thLocalCollisions(module=nodenext).js.diff | 3 +- ...HelpersWithLocalCollisions(module=none).js | 2 +- ...rsWithLocalCollisions(module=none).js.diff | 3 +- ...ersWithLocalCollisions(module=preserve).js | 2 +- ...thLocalCollisions(module=preserve).js.diff | 3 +- .../compiler/excessPropertyCheckWithSpread.js | 15 +- .../excessPropertyCheckWithSpread.js.diff | 21 --- .../compiler/excessPropertyCheckWithUnions.js | 13 +- .../excessPropertyCheckWithUnions.js.diff | 26 +-- ...xplicitAnyAfterSpreadNoImplicitAnyError.js | 13 +- ...itAnyAfterSpreadNoImplicitAnyError.js.diff | 20 --- ...tObjectRest(module=commonjs,target=es5).js | 3 +- ...ctRest(module=commonjs,target=es5).js.diff | 9 +- ...ortObjectRest(module=es2015,target=es5).js | 3 +- ...jectRest(module=es2015,target=es5).js.diff | 9 - ...ortObjectRest(module=esnext,target=es5).js | 3 +- ...jectRest(module=esnext,target=es5).js.diff | 9 - ...ructuringDoesNotElideFollowingStatement.js | 15 +- ...ringDoesNotElideFollowingStatement.js.diff | 23 --- .../compiler/genericIsNeverEmptyObject.js | 26 ++- .../genericIsNeverEmptyObject.js.diff | 41 ++--- .../genericObjectSpreadResultInSwitch.js | 13 +- .../genericObjectSpreadResultInSwitch.js.diff | 25 --- .../compiler/importHelpersBundler.js | 3 +- .../compiler/importHelpersBundler.js.diff | 12 -- .../submodule/compiler/importHelpersES6.js | 2 +- .../compiler/importHelpersES6.js.diff | 3 +- .../compiler/importHelpersNoHelpers.js | 4 +- .../compiler/importHelpersNoHelpers.js.diff | 6 +- .../importHelpersVerbatimModuleSyntax.js | 3 +- .../importHelpersVerbatimModuleSyntax.js.diff | 8 +- ...ersWithLocalCollisions(module=commonjs).js | 2 +- ...thLocalCollisions(module=commonjs).js.diff | 3 +- ...lpersWithLocalCollisions(module=es2015).js | 2 +- ...WithLocalCollisions(module=es2015).js.diff | 3 +- .../compiler/intersectionPropertyCheck.js | 13 +- .../intersectionPropertyCheck.js.diff | 23 +-- .../compiler/narrowingDestructuring.js | 22 ++- .../compiler/narrowingDestructuring.js.diff | 46 ----- .../compiler/narrowingRestGenericCall.js | 14 +- .../compiler/narrowingRestGenericCall.js.diff | 25 --- .../submodule/compiler/nestedObjectRest.js | 18 +- .../compiler/nestedObjectRest.js.diff | 27 +-- ...dingPattern_restElementWithPropertyName.js | 13 +- ...attern_restElementWithPropertyName.js.diff | 19 -- .../objectInstantiationFromUnionSpread.js | 15 +- ...objectInstantiationFromUnionSpread.js.diff | 22 +-- .../objectLiteralFreshnessWithSpread.js | 13 +- .../objectLiteralFreshnessWithSpread.js.diff | 20 --- .../submodule/compiler/objectRestSpread.js | 24 ++- .../compiler/objectRestSpread.js.diff | 36 +--- ...preadWithinMethodWithinObjectWithSpread.js | 23 ++- ...WithinMethodWithinObjectWithSpread.js.diff | 30 ---- .../compiler/restElementAssignable.js | 15 +- .../compiler/restElementAssignable.js.diff | 28 +-- .../restElementWithNumberPropertyName.js | 13 +- .../restElementWithNumberPropertyName.js.diff | 19 -- .../submodule/compiler/restIntersection.js | 13 +- .../compiler/restIntersection.js.diff | 21 --- .../compiler/restInvalidArgumentType.js | 49 +++-- .../compiler/restInvalidArgumentType.js.diff | 63 ------- .../restParameterTypeInstantiation.js | 14 +- .../restParameterTypeInstantiation.js.diff | 20 +-- .../restParameterWithBindingPattern3.js | 13 +- .../restParameterWithBindingPattern3.js.diff | 23 --- .../reference/submodule/compiler/restUnion.js | 17 +- .../submodule/compiler/restUnion.js.diff | 29 --- .../submodule/compiler/restUnion2.js | 15 +- .../submodule/compiler/restUnion2.js.diff | 23 --- .../submodule/compiler/restUnion3.js | 15 +- .../submodule/compiler/restUnion3.js.diff | 20 +-- ...reverseMappedTypeIntersectionConstraint.js | 13 +- ...seMappedTypeIntersectionConstraint.js.diff | 26 +-- .../spreadExpressionContextualType.js | 15 +- .../spreadExpressionContextualType.js.diff | 24 +-- ...adExpressionContextualTypeWithNamespace.js | 13 +- ...ressionContextualTypeWithNamespace.js.diff | 27 +-- .../compiler/spreadIdenticalTypesRemoved.js | 22 ++- .../spreadIdenticalTypesRemoved.js.diff | 29 +-- .../submodule/compiler/spreadIntersection.js | 15 +- .../compiler/spreadIntersection.js.diff | 24 --- .../compiler/spreadInvalidArgumentType.js | 49 +++-- .../spreadInvalidArgumentType.js.diff | 63 ------- ...tions(exactoptionalpropertytypes=false).js | 41 +++-- ...(exactoptionalpropertytypes=false).js.diff | 44 +---- ...ations(exactoptionalpropertytypes=true).js | 41 +++-- ...s(exactoptionalpropertytypes=true).js.diff | 44 +---- ...ithIndexDoesNotAddUndefinedToLocalIndex.js | 13 +- ...dexDoesNotAddUndefinedToLocalIndex.js.diff | 16 +- ...ObjectLiteralAssignableToIndexSignature.js | 23 ++- ...tLiteralAssignableToIndexSignature.js.diff | 29 +-- .../compiler/spreadTypeRemovesReadonly.js | 13 +- .../spreadTypeRemovesReadonly.js.diff | 21 --- .../compiler/strictOptionalProperties1.js | 15 +- .../strictOptionalProperties1.js.diff | 37 +--- ...aggedTemplateStringsWithCurriedFunction.js | 21 ++- ...TemplateStringsWithCurriedFunction.js.diff | 36 ++-- ...rivialSubtypeReductionNoStructuralCheck.js | 16 +- ...lSubtypeReductionNoStructuralCheck.js.diff | 29 --- ...ivialSubtypeReductionNoStructuralCheck2.js | 16 +- ...SubtypeReductionNoStructuralCheck2.js.diff | 29 --- .../compiler/tslibMultipleMissingHelper.js | 6 +- .../tslibMultipleMissingHelper.js.diff | 11 +- .../unionExcessPropsWithPartialMember.js | 13 +- .../unionExcessPropsWithPartialMember.js.diff | 16 +- .../compiler/unusedLocalsAndObjectSpread.js | 19 +- .../unusedLocalsAndObjectSpread.js.diff | 45 ----- .../compiler/unusedLocalsAndObjectSpread2.js | 17 +- .../unusedLocalsAndObjectSpread2.js.diff | 29 --- ...useBeforeDeclaration_propertyAssignment.js | 8 +- ...foreDeclaration_propertyAssignment.js.diff | 8 +- ...ratorParameterEvaluation(target=es2015).js | 2 +- ...ParameterEvaluation(target=es2015).js.diff | 2 +- ...ratorParameterEvaluation(target=es2017).js | 2 +- ...ParameterEvaluation(target=es2017).js.diff | 2 +- .../conformance/asyncWithVarShadowing_es6.js | 2 +- .../asyncWithVarShadowing_es6.js.diff | 2 +- ...ructuringEvaluationOrder(target=es2015).js | 15 +- ...ringEvaluationOrder(target=es2015).js.diff | 30 ---- ...estructuringEvaluationOrder(target=es5).js | 15 +- ...cturingEvaluationOrder(target=es5).js.diff | 30 ---- ...tPatternWithNestedSpread(target=es2015).js | 14 +- ...ernWithNestedSpread(target=es2015).js.diff | 21 --- ...mentPatternWithNestedSpread(target=es5).js | 14 +- ...atternWithNestedSpread(target=es5).js.diff | 21 --- ...uringObjectBindingPatternAndAssignment5.js | 14 +- ...ObjectBindingPatternAndAssignment5.js.diff | 24 --- .../conformance/destructuringSpread.js | 39 ++-- .../conformance/destructuringSpread.js.diff | 47 ----- .../conformance/elementAccessChain.3.js | 16 +- .../conformance/elementAccessChain.3.js.diff | 25 ++- ...ctionParameterObjectRestAndInitializers.js | 19 +- ...ParameterObjectRestAndInitializers.js.diff | 39 ++-- .../conformance/genericObjectRest.js | 29 ++- .../conformance/genericObjectRest.js.diff | 43 +---- .../conformance/intraExpressionInferences.js | 23 ++- .../intraExpressionInferences.js.diff | 41 +---- .../conformance/literalTypeWidening.js | 26 ++- .../conformance/literalTypeWidening.js.diff | 40 +---- .../conformance/mappedTypeConstraints.js | 13 +- .../conformance/mappedTypeConstraints.js.diff | 25 +-- .../noUncheckedIndexedAccessDestructuring.js | 17 +- ...ncheckedIndexedAccessDestructuring.js.diff | 42 +---- .../conformance/nonPrimitiveAccessProperty.js | 13 +- .../nonPrimitiveAccessProperty.js.diff | 23 --- .../conformance/objectLiteralNormalization.js | 15 +- .../objectLiteralNormalization.js.diff | 30 +--- .../submodule/conformance/objectRest.js | 49 +++-- .../submodule/conformance/objectRest.js.diff | 64 +------ .../submodule/conformance/objectRest2.js | 4 +- .../submodule/conformance/objectRest2.js.diff | 7 +- .../conformance/objectRestAssignment.js | 18 +- .../conformance/objectRestAssignment.js.diff | 32 ---- .../conformance/objectRestCatchES5.js | 15 +- .../conformance/objectRestCatchES5.js.diff | 23 --- .../submodule/conformance/objectRestForOf.js | 19 +- .../conformance/objectRestForOf.js.diff | 35 ---- .../conformance/objectRestNegative.js | 22 ++- .../conformance/objectRestNegative.js.diff | 32 +--- .../conformance/objectRestParameter.js | 33 +++- .../conformance/objectRestParameter.js.diff | 49 ----- .../conformance/objectRestParameterES5.js | 33 +++- .../objectRestParameterES5.js.diff | 49 ----- .../objectRestPropertyMustBeLast.js | 20 ++- .../objectRestPropertyMustBeLast.js.diff | 26 --- .../conformance/objectRestReadonly.js | 13 +- .../conformance/objectRestReadonly.js.diff | 25 --- .../submodule/conformance/objectSpread.js | 118 ++++++------ .../conformance/objectSpread.js.diff | 170 +----------------- .../objectSpreadComputedProperty.js | 17 +- .../objectSpreadComputedProperty.js.diff | 29 --- .../conformance/objectSpreadIndexSignature.js | 19 +- .../objectSpreadIndexSignature.js.diff | 27 +-- .../conformance/objectSpreadNegative.js | 51 +++--- .../conformance/objectSpreadNegative.js.diff | 83 +-------- .../conformance/objectSpreadNegativeParse.js | 19 +- .../objectSpreadNegativeParse.js.diff | 26 --- .../objectSpreadRepeatedComplexity.js | 149 +++++++-------- .../objectSpreadRepeatedComplexity.js.diff | 155 +--------------- .../objectSpreadRepeatedNullCheckPerf.js | 40 ++--- .../objectSpreadRepeatedNullCheckPerf.js.diff | 46 +---- .../conformance/objectSpreadStrictNull.js | 31 ++-- .../objectSpreadStrictNull.js.diff | 47 ----- .../privateNameAndObjectRestSpread.js | 19 +- .../privateNameAndObjectRestSpread.js.diff | 30 ++-- .../privateWriteOnlyAccessorRead.js | 18 +- .../privateWriteOnlyAccessorRead.js.diff | 25 ++- .../conformance/propertyAccessChain.3.js | 16 +- .../conformance/propertyAccessChain.3.js.diff | 25 ++- .../restPropertyWithBindingPattern.js | 20 ++- .../restPropertyWithBindingPattern.js.diff | 28 +-- .../spreadContextualTypedBindingPattern.js | 13 +- ...preadContextualTypedBindingPattern.js.diff | 20 --- .../submodule/conformance/spreadDuplicate.js | 27 ++- .../conformance/spreadDuplicate.js.diff | 33 +--- .../conformance/spreadDuplicateExact.js | 27 ++- .../conformance/spreadDuplicateExact.js.diff | 33 +--- .../conformance/spreadExcessProperty.js | 13 +- .../conformance/spreadExcessProperty.js.diff | 20 --- .../conformance/spreadNonPrimitive.js | 13 +- .../conformance/spreadNonPrimitive.js.diff | 19 -- .../conformance/spreadObjectOrFalsy.js | 27 ++- .../conformance/spreadObjectOrFalsy.js.diff | 49 +---- .../conformance/spreadOverwritesProperty.js | 21 ++- .../spreadOverwritesProperty.js.diff | 31 ---- .../spreadOverwritesPropertyStrict.js | 37 ++-- .../spreadOverwritesPropertyStrict.js.diff | 56 +----- .../conformance/spreadTypeVariable.js | 23 ++- .../conformance/spreadTypeVariable.js.diff | 41 ----- .../submodule/conformance/spreadUnion.js | 17 +- .../submodule/conformance/spreadUnion.js.diff | 27 --- .../submodule/conformance/spreadUnion2.js | 23 ++- .../conformance/spreadUnion2.js.diff | 34 ---- .../submodule/conformance/spreadUnion3.js | 19 +- .../conformance/spreadUnion3.js.diff | 34 ---- .../submodule/conformance/spreadUnion4.js | 13 +- .../conformance/spreadUnion4.js.diff | 19 -- ...AndSuperInStaticMembers1(target=es2015).js | 14 +- ...perInStaticMembers1(target=es2015).js.diff | 22 +-- ...AndSuperInStaticMembers2(target=es2015).js | 14 +- ...perInStaticMembers2(target=es2015).js.diff | 22 +-- .../trailingCommasInBindingPatterns.js | 16 +- .../trailingCommasInBindingPatterns.js.diff | 25 +-- .../tsxEmitSpreadAttribute(target=es2015).js | 2 +- ...EmitSpreadAttribute(target=es2015).js.diff | 11 -- ...ReactEmitSpreadAttribute(target=es2015).js | 2 +- ...EmitSpreadAttribute(target=es2015).js.diff | 11 -- .../submodule/conformance/unknownType1.js | 32 +++- .../conformance/unknownType1.js.diff | 49 +---- 268 files changed, 2135 insertions(+), 4101 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/compiler/anyAndUnknownHaveFalsyComponents.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/contextualTypeObjectSpreadExpression.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/declarationEmitKeywordDestructuring.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/destructuringFromUnionSpread.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithSpread.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/explicitAnyAfterSpreadNoImplicitAnyError.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/exportObjectRest(module=es2015,target=es5).js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/exportObjectRest(module=esnext,target=es5).js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/forLoopWithDestructuringDoesNotElideFollowingStatement.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/genericObjectSpreadResultInSwitch.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/importHelpersBundler.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/narrowingDestructuring.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/narrowingRestGenericCall.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/objectBindingPattern_restElementWithPropertyName.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/objectLiteralFreshnessWithSpread.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/objectSpreadWithinMethodWithinObjectWithSpread.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/restElementWithNumberPropertyName.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/restIntersection.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/restInvalidArgumentType.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern3.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/restUnion.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/restUnion2.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/spreadIntersection.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/spreadInvalidArgumentType.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/spreadTypeRemovesReadonly.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck2.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread2.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es2015).js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es5).js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es2015).js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es5).js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/destructuringObjectBindingPatternAndAssignment5.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/destructuringSpread.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/nonPrimitiveAccessProperty.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/objectRestAssignment.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/objectRestCatchES5.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/objectRestForOf.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/objectRestParameter.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/objectRestParameterES5.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/objectRestPropertyMustBeLast.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/objectRestReadonly.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/objectSpreadComputedProperty.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/objectSpreadNegativeParse.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/objectSpreadStrictNull.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/spreadContextualTypedBindingPattern.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/spreadExcessProperty.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/spreadNonPrimitive.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/spreadOverwritesProperty.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/spreadTypeVariable.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/spreadUnion.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/spreadUnion2.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/spreadUnion3.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/spreadUnion4.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/tsxEmitSpreadAttribute(target=es2015).js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/tsxReactEmitSpreadAttribute(target=es2015).js.diff diff --git a/testdata/baselines/reference/submodule/compiler/anyAndUnknownHaveFalsyComponents.js b/testdata/baselines/reference/submodule/compiler/anyAndUnknownHaveFalsyComponents.js index a6e70b4d03..e793b344ad 100644 --- a/testdata/baselines/reference/submodule/compiler/anyAndUnknownHaveFalsyComponents.js +++ b/testdata/baselines/reference/submodule/compiler/anyAndUnknownHaveFalsyComponents.js @@ -31,21 +31,26 @@ function foo2() { //// [anyAndUnknownHaveFalsyComponents.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; const y1 = x1 && 3; function foo1() { - return { - display: "block", - ...(isTreeHeader1 && { - display: "flex", - }) - }; + return __assign({ display: "block" }, (isTreeHeader1 && { + display: "flex", + })); } const y2 = x2 && 3; function foo2() { - return { - display: "block", - ...(isTreeHeader1 && { - display: "flex", - }) - }; + return __assign({ display: "block" }, (isTreeHeader1 && { + display: "flex", + })); } diff --git a/testdata/baselines/reference/submodule/compiler/anyAndUnknownHaveFalsyComponents.js.diff b/testdata/baselines/reference/submodule/compiler/anyAndUnknownHaveFalsyComponents.js.diff deleted file mode 100644 index 22f83fb0a8..0000000000 --- a/testdata/baselines/reference/submodule/compiler/anyAndUnknownHaveFalsyComponents.js.diff +++ /dev/null @@ -1,41 +0,0 @@ ---- old.anyAndUnknownHaveFalsyComponents.js -+++ new.anyAndUnknownHaveFalsyComponents.js -@@= skipped -30, +30 lines =@@ - - - //// [anyAndUnknownHaveFalsyComponents.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - const y1 = x1 && 3; - function foo1() { -- return __assign({ display: "block" }, (isTreeHeader1 && { -- display: "flex", -- })); -+ return { -+ display: "block", -+ ...(isTreeHeader1 && { -+ display: "flex", -+ }) -+ }; - } - const y2 = x2 && 3; - function foo2() { -- return __assign({ display: "block" }, (isTreeHeader1 && { -- display: "flex", -- })); -+ return { -+ display: "block", -+ ...(isTreeHeader1 && { -+ display: "flex", -+ }) -+ }; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/asyncFunctionTempVariableScoping.js b/testdata/baselines/reference/submodule/compiler/asyncFunctionTempVariableScoping.js index efe66eb792..2668ace0b0 100644 --- a/testdata/baselines/reference/submodule/compiler/asyncFunctionTempVariableScoping.js +++ b/testdata/baselines/reference/submodule/compiler/asyncFunctionTempVariableScoping.js @@ -6,5 +6,19 @@ async ({ foo, bar, ...rest }) => bar(await foo); //// [asyncFunctionTempVariableScoping.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; // https://github.com/Microsoft/TypeScript/issues/19187 -async ({ foo, bar, ...rest }) => bar(await foo); +async (_a) => { + var { foo, bar } = _a, rest = __rest(_a, ["foo", "bar"]); + return bar(await foo); +}; diff --git a/testdata/baselines/reference/submodule/compiler/asyncFunctionTempVariableScoping.js.diff b/testdata/baselines/reference/submodule/compiler/asyncFunctionTempVariableScoping.js.diff index 7fbfd45ed6..c50a92ee97 100644 --- a/testdata/baselines/reference/submodule/compiler/asyncFunctionTempVariableScoping.js.diff +++ b/testdata/baselines/reference/submodule/compiler/asyncFunctionTempVariableScoping.js.diff @@ -1,9 +1,10 @@ --- old.asyncFunctionTempVariableScoping.js +++ new.asyncFunctionTempVariableScoping.js -@@= skipped -6, +6 lines =@@ +@@= skipped -5, +5 lines =@@ + async ({ foo, bar, ...rest }) => bar(await foo); //// [asyncFunctionTempVariableScoping.js] - // https://github.com/Microsoft/TypeScript/issues/19187 +-// https://github.com/Microsoft/TypeScript/issues/19187 -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { @@ -13,19 +14,18 @@ - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) +@@= skipped -21, +11 lines =@@ + } + return t; + }; -(_a) => __awaiter(this, void 0, void 0, function* () { -- var { foo, bar } = _a, rest = __rest(_a, ["foo", "bar"]); ++// https://github.com/Microsoft/TypeScript/issues/19187 ++async (_a) => { + var { foo, bar } = _a, rest = __rest(_a, ["foo", "bar"]); - return bar(yield foo); -}); -+async ({ foo, bar, ...rest }) => bar(await foo); \ No newline at end of file ++ return bar(await foo); ++}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/contextualTypeObjectSpreadExpression.js b/testdata/baselines/reference/submodule/compiler/contextualTypeObjectSpreadExpression.js index 7a30205582..032928668e 100644 --- a/testdata/baselines/reference/submodule/compiler/contextualTypeObjectSpreadExpression.js +++ b/testdata/baselines/reference/submodule/compiler/contextualTypeObjectSpreadExpression.js @@ -9,5 +9,16 @@ i = { ...{ a: "a" } }; //// [contextualTypeObjectSpreadExpression.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; let i; -i = { ...{ a: "a" } }; +i = __assign({ a: "a" }); diff --git a/testdata/baselines/reference/submodule/compiler/contextualTypeObjectSpreadExpression.js.diff b/testdata/baselines/reference/submodule/compiler/contextualTypeObjectSpreadExpression.js.diff deleted file mode 100644 index a2079caada..0000000000 --- a/testdata/baselines/reference/submodule/compiler/contextualTypeObjectSpreadExpression.js.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.contextualTypeObjectSpreadExpression.js -+++ new.contextualTypeObjectSpreadExpression.js -@@= skipped -8, +8 lines =@@ - - - //// [contextualTypeObjectSpreadExpression.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - let i; --i = __assign({ a: "a" }); -+i = { ...{ a: "a" } }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitKeywordDestructuring.js b/testdata/baselines/reference/submodule/compiler/declarationEmitKeywordDestructuring.js index b8f070f58e..fc95fc9e5c 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitKeywordDestructuring.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitKeywordDestructuring.js @@ -32,19 +32,35 @@ function f5({ await: _await, ...rest }: P) { //// [declarationEmitKeywordDestructuring.js] -function f1({ enum: _enum, ...rest }) { +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +function f1(_a) { + var { enum: _enum } = _a, rest = __rest(_a, ["enum"]); return rest; } -function f2({ function: _function, ...rest }) { +function f2(_a) { + var { function: _function } = _a, rest = __rest(_a, ["function"]); return rest; } -function f3({ abstract: _abstract, ...rest }) { +function f3(_a) { + var { abstract: _abstract } = _a, rest = __rest(_a, ["abstract"]); return rest; } -function f4({ async: _async, ...rest }) { +function f4(_a) { + var { async: _async } = _a, rest = __rest(_a, ["async"]); return rest; } -function f5({ await: _await, ...rest }) { +function f5(_a) { + var { await: _await } = _a, rest = __rest(_a, ["await"]); return rest; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitKeywordDestructuring.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitKeywordDestructuring.js.diff deleted file mode 100644 index 56d5c810ff..0000000000 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitKeywordDestructuring.js.diff +++ /dev/null @@ -1,50 +0,0 @@ ---- old.declarationEmitKeywordDestructuring.js -+++ new.declarationEmitKeywordDestructuring.js -@@= skipped -31, +31 lines =@@ - - - //// [declarationEmitKeywordDestructuring.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --function f1(_a) { -- var { enum: _enum } = _a, rest = __rest(_a, ["enum"]); -- return rest; --} --function f2(_a) { -- var { function: _function } = _a, rest = __rest(_a, ["function"]); -- return rest; --} --function f3(_a) { -- var { abstract: _abstract } = _a, rest = __rest(_a, ["abstract"]); -- return rest; --} --function f4(_a) { -- var { async: _async } = _a, rest = __rest(_a, ["async"]); -- return rest; --} --function f5(_a) { -- var { await: _await } = _a, rest = __rest(_a, ["await"]); -+function f1({ enum: _enum, ...rest }) { -+ return rest; -+} -+function f2({ function: _function, ...rest }) { -+ return rest; -+} -+function f3({ abstract: _abstract, ...rest }) { -+ return rest; -+} -+function f4({ async: _async, ...rest }) { -+ return rest; -+} -+function f5({ await: _await, ...rest }) { - return rest; - } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitReadonlyComputedProperty.js b/testdata/baselines/reference/submodule/compiler/declarationEmitReadonlyComputedProperty.js index 10d86b5254..400dbba8f8 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitReadonlyComputedProperty.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitReadonlyComputedProperty.js @@ -33,12 +33,21 @@ function createInstance() { } //// [index.js] "use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.spread = void 0; const bug_1 = require("./bug"); -exports.spread = { - ...(0, bug_1.createInstance)(), -}; +exports.spread = __assign({}, (0, bug_1.createInstance)()); //// [bug.d.ts] diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitReadonlyComputedProperty.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitReadonlyComputedProperty.js.diff index 7751afc7b5..287db45c40 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitReadonlyComputedProperty.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitReadonlyComputedProperty.js.diff @@ -1,28 +1,12 @@ --- old.declarationEmitReadonlyComputedProperty.js +++ new.declarationEmitReadonlyComputedProperty.js -@@= skipped -32, +32 lines =@@ - } - //// [index.js] - "use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; +@@= skipped -45, +45 lines =@@ + }; Object.defineProperty(exports, "__esModule", { value: true }); exports.spread = void 0; -var bug_1 = require("./bug"); --exports.spread = __assign({}, (0, bug_1.createInstance)()); +const bug_1 = require("./bug"); -+exports.spread = { -+ ...(0, bug_1.createInstance)(), -+}; + exports.spread = __assign({}, (0, bug_1.createInstance)()); //// [bug.d.ts] diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitSpreadStringlyKeyedEnum.js b/testdata/baselines/reference/submodule/compiler/declarationEmitSpreadStringlyKeyedEnum.js index 4471a9b461..a41ed9e6ef 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitSpreadStringlyKeyedEnum.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitSpreadStringlyKeyedEnum.js @@ -6,6 +6,17 @@ export const SpotifyAgeGroupEnum = { ...AgeGroups }; //// [declarationEmitSpreadStringlyKeyedEnum.js] "use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.SpotifyAgeGroupEnum = void 0; var AgeGroups; @@ -18,7 +29,7 @@ var AgeGroups; AgeGroups[AgeGroups["45-59"] = 5] = "45-59"; AgeGroups[AgeGroups["60-150"] = 6] = "60-150"; })(AgeGroups || (AgeGroups = {})); -exports.SpotifyAgeGroupEnum = { ...AgeGroups }; +exports.SpotifyAgeGroupEnum = __assign({}, AgeGroups); //// [declarationEmitSpreadStringlyKeyedEnum.d.ts] diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitSpreadStringlyKeyedEnum.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitSpreadStringlyKeyedEnum.js.diff index 4651b56742..ad0166b32d 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitSpreadStringlyKeyedEnum.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitSpreadStringlyKeyedEnum.js.diff @@ -1,33 +1,6 @@ --- old.declarationEmitSpreadStringlyKeyedEnum.js +++ new.declarationEmitSpreadStringlyKeyedEnum.js -@@= skipped -5, +5 lines =@@ - - //// [declarationEmitSpreadStringlyKeyedEnum.js] - "use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - Object.defineProperty(exports, "__esModule", { value: true }); - exports.SpotifyAgeGroupEnum = void 0; - var AgeGroups; -@@= skipped -23, +12 lines =@@ - AgeGroups[AgeGroups["45-59"] = 5] = "45-59"; - AgeGroups[AgeGroups["60-150"] = 6] = "60-150"; - })(AgeGroups || (AgeGroups = {})); --exports.SpotifyAgeGroupEnum = __assign({}, AgeGroups); -+exports.SpotifyAgeGroupEnum = { ...AgeGroups }; - - - //// [declarationEmitSpreadStringlyKeyedEnum.d.ts] -@@= skipped -15, +15 lines =@@ +@@= skipped -43, +43 lines =@@ } export declare const SpotifyAgeGroupEnum: { [x: number]: string; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitStringEnumUsedInNonlocalSpread.js b/testdata/baselines/reference/submodule/compiler/declarationEmitStringEnumUsedInNonlocalSpread.js index 9933313c11..70287b0933 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitStringEnumUsedInNonlocalSpread.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitStringEnumUsedInNonlocalSpread.js @@ -51,15 +51,23 @@ class A { exports.A = A; //// [index.js] "use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.B = void 0; const class_1 = require("./class"); class B extends class_1.A { getA() { - return { - ...super.getA(), - a: '123', - }; + return __assign(__assign({}, super.getA()), { a: '123' }); } } exports.B = B; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitStringEnumUsedInNonlocalSpread.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitStringEnumUsedInNonlocalSpread.js.diff index a7ef624b2c..adc2d75099 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitStringEnumUsedInNonlocalSpread.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitStringEnumUsedInNonlocalSpread.js.diff @@ -21,31 +21,12 @@ }; } } - exports.A = A; - //// [index.js] - "use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; +@@= skipped -25, +30 lines =@@ + }; Object.defineProperty(exports, "__esModule", { value: true }); exports.B = void 0; -var class_1 = require("./class"); +const class_1 = require("./class"); class B extends class_1.A { getA() { -- return __assign(__assign({}, super.getA()), { a: '123' }); -+ return { -+ ...super.getA(), -+ a: '123', -+ }; - } - } - exports.B = B; \ No newline at end of file + return __assign(__assign({}, super.getA()), { a: '123' }); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.js b/testdata/baselines/reference/submodule/compiler/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.js index 0759b2e1a1..ab2eaf020d 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.js +++ b/testdata/baselines/reference/submodule/compiler/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.js @@ -44,6 +44,17 @@ void p3.result.three; //// [declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.js] "use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.testRecFun = exports.updateIfChanged = void 0; const updateIfChanged = (t) => { @@ -60,7 +71,7 @@ exports.updateIfChanged = updateIfChanged; const testRecFun = (parent) => { return { result: parent, - deeper: (child) => (0, exports.testRecFun)({ ...parent, ...child }) + deeper: (child) => (0, exports.testRecFun)(__assign(__assign({}, parent), child)) }; }; exports.testRecFun = testRecFun; diff --git a/testdata/baselines/reference/submodule/compiler/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.js.diff b/testdata/baselines/reference/submodule/compiler/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.js.diff index 88518482cb..139b7896cf 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.js.diff @@ -6,30 +6,10 @@ "use strict"; -// Note that both of the following have an `any` in their return type from where we bottom out the type printout -// for having too many instances of the same symbol nesting. --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - Object.defineProperty(exports, "__esModule", { value: true }); - exports.testRecFun = exports.updateIfChanged = void 0; - const updateIfChanged = (t) => { -@@= skipped -29, +16 lines =@@ - const testRecFun = (parent) => { - return { - result: parent, -- deeper: (child) => (0, exports.testRecFun)(__assign(__assign({}, parent), child)) -+ deeper: (child) => (0, exports.testRecFun)({ ...parent, ...child }) - }; - }; - exports.testRecFun = testRecFun; -@@= skipped -16, +16 lines =@@ + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -45, +43 lines =@@ //// [declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.d.ts] diff --git a/testdata/baselines/reference/submodule/compiler/destructuringAssignmentWithStrictNullChecks.js b/testdata/baselines/reference/submodule/compiler/destructuringAssignmentWithStrictNullChecks.js index 75bfa24be1..f1faa7368e 100644 --- a/testdata/baselines/reference/submodule/compiler/destructuringAssignmentWithStrictNullChecks.js +++ b/testdata/baselines/reference/submodule/compiler/destructuringAssignmentWithStrictNullChecks.js @@ -6,5 +6,17 @@ let bar: {}; //// [destructuringAssignmentWithStrictNullChecks.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a; let bar; -({ ...bar } = {}); +(_a = {}, bar = __rest(_a, [])); diff --git a/testdata/baselines/reference/submodule/compiler/destructuringAssignmentWithStrictNullChecks.js.diff b/testdata/baselines/reference/submodule/compiler/destructuringAssignmentWithStrictNullChecks.js.diff index f43838f776..5677b8d6b6 100644 --- a/testdata/baselines/reference/submodule/compiler/destructuringAssignmentWithStrictNullChecks.js.diff +++ b/testdata/baselines/reference/submodule/compiler/destructuringAssignmentWithStrictNullChecks.js.diff @@ -1,20 +1,10 @@ --- old.destructuringAssignmentWithStrictNullChecks.js +++ new.destructuringAssignmentWithStrictNullChecks.js -@@= skipped -5, +5 lines =@@ - - - //// [destructuringAssignmentWithStrictNullChecks.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; +@@= skipped -16, +16 lines =@@ + } + return t; + }; ++var _a; let bar; -(bar = __rest({}, [])); -+({ ...bar } = {}); \ No newline at end of file ++(_a = {}, bar = __rest(_a, [])); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/destructuringFromUnionSpread.js b/testdata/baselines/reference/submodule/compiler/destructuringFromUnionSpread.js index 9b654bc0f1..420a13ded7 100644 --- a/testdata/baselines/reference/submodule/compiler/destructuringFromUnionSpread.js +++ b/testdata/baselines/reference/submodule/compiler/destructuringFromUnionSpread.js @@ -9,4 +9,15 @@ const { a } = { ...x } // error //// [destructuringFromUnionSpread.js] -const { a } = { ...x }; // error +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +const { a } = __assign({}, x); // error diff --git a/testdata/baselines/reference/submodule/compiler/destructuringFromUnionSpread.js.diff b/testdata/baselines/reference/submodule/compiler/destructuringFromUnionSpread.js.diff deleted file mode 100644 index fb55f32960..0000000000 --- a/testdata/baselines/reference/submodule/compiler/destructuringFromUnionSpread.js.diff +++ /dev/null @@ -1,19 +0,0 @@ ---- old.destructuringFromUnionSpread.js -+++ new.destructuringFromUnionSpread.js -@@= skipped -8, +8 lines =@@ - - - //// [destructuringFromUnionSpread.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --const { a } = __assign({}, x); // error -+const { a } = { ...x }; // error \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/destructuringInitializerContextualTypeFromContext.js b/testdata/baselines/reference/submodule/compiler/destructuringInitializerContextualTypeFromContext.js index c1e65da33a..97d4281b50 100644 --- a/testdata/baselines/reference/submodule/compiler/destructuringInitializerContextualTypeFromContext.js +++ b/testdata/baselines/reference/submodule/compiler/destructuringInitializerContextualTypeFromContext.js @@ -28,6 +28,34 @@ f(([_1, _2 = undefined]) => undefined) //// [destructuringInitializerContextualTypeFromContext.js] -const Parent = ({ children, name = "Artemis", ...props }) => Child({ name, ...props }); -const Child = ({ children, name = "Artemis", ...props }) => `name: ${name} props: ${JSON.stringify(props)}`; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +const Parent = (_a) => { + var { children, name = "Artemis" } = _a, props = __rest(_a, ["children", "name"]); + return Child(__assign({ name }, props)); +}; +const Child = (_a) => { + var { children, name = "Artemis" } = _a, props = __rest(_a, ["children", "name"]); + return `name: ${name} props: ${JSON.stringify(props)}`; +}; f(([_1, _2 = undefined]) => undefined); diff --git a/testdata/baselines/reference/submodule/compiler/destructuringInitializerContextualTypeFromContext.js.diff b/testdata/baselines/reference/submodule/compiler/destructuringInitializerContextualTypeFromContext.js.diff index d7d9dcd940..0e60106225 100644 --- a/testdata/baselines/reference/submodule/compiler/destructuringInitializerContextualTypeFromContext.js.diff +++ b/testdata/baselines/reference/submodule/compiler/destructuringInitializerContextualTypeFromContext.js.diff @@ -5,36 +5,6 @@ //// [destructuringInitializerContextualTypeFromContext.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --const Parent = (_a) => { -- var { children, name = "Artemis" } = _a, props = __rest(_a, ["children", "name"]); -- return Child(__assign({ name }, props)); --}; --const Child = (_a) => { -- var { children, name = "Artemis" } = _a, props = __rest(_a, ["children", "name"]); -- return `name: ${name} props: ${JSON.stringify(props)}`; --}; -+const Parent = ({ children, name = "Artemis", ...props }) => Child({ name, ...props }); -+const Child = ({ children, name = "Artemis", ...props }) => `name: ${name} props: ${JSON.stringify(props)}`; - f(([_1, _2 = undefined]) => undefined); \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/destructuringUnspreadableIntoRest.js b/testdata/baselines/reference/submodule/compiler/destructuringUnspreadableIntoRest.js index 28c27b053d..3eee7515d4 100644 --- a/testdata/baselines/reference/submodule/compiler/destructuringUnspreadableIntoRest.js +++ b/testdata/baselines/reference/submodule/compiler/destructuringUnspreadableIntoRest.js @@ -91,6 +91,17 @@ function destructure(x: T) { //// [destructuringUnspreadableIntoRest.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; class A { publicProp; privateProp; @@ -105,10 +116,10 @@ class A { } set setter(_v) { } method() { - const { ...rest1 } = this; - const { ...rest2 } = this; - const { publicProp: _1, ...rest3 } = this; - const { publicProp: _2, ...rest4 } = this; + const rest1 = __rest(this, []); + const rest2 = __rest(this, []); + const _a = this, { publicProp: _1 } = _a, rest3 = __rest(_a, ["publicProp"]); + const _b = this, { publicProp: _2 } = _b, rest4 = __rest(_b, ["publicProp"]); rest1.publicProp; rest2.publicProp; rest3.publicProp; @@ -136,10 +147,10 @@ class A { } } function destructure(x) { - const { ...rest1 } = x; - const { ...rest2 } = x; - const { publicProp: _1, ...rest3 } = x; - const { publicProp: _2, ...rest4 } = x; + const rest1 = __rest(x, []); + const rest2 = __rest(x, []); + const { publicProp: _1 } = x, rest3 = __rest(x, ["publicProp"]); + const _a = x, { publicProp: _2 } = _a, rest4 = __rest(_a, ["publicProp"]); rest1.publicProp; rest2.publicProp; rest3.publicProp; diff --git a/testdata/baselines/reference/submodule/compiler/destructuringUnspreadableIntoRest.js.diff b/testdata/baselines/reference/submodule/compiler/destructuringUnspreadableIntoRest.js.diff index fc08aec567..41bae96494 100644 --- a/testdata/baselines/reference/submodule/compiler/destructuringUnspreadableIntoRest.js.diff +++ b/testdata/baselines/reference/submodule/compiler/destructuringUnspreadableIntoRest.js.diff @@ -1,54 +1,12 @@ --- old.destructuringUnspreadableIntoRest.js +++ new.destructuringUnspreadableIntoRest.js -@@= skipped -90, +90 lines =@@ - - - //// [destructuringUnspreadableIntoRest.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; +@@= skipped -102, +102 lines =@@ + return t; + }; class A { + publicProp; + privateProp; + protectedProp; constructor(publicProp, privateProp, protectedProp) { this.publicProp = publicProp; - this.privateProp = privateProp; -@@= skipped -22, +14 lines =@@ - } - set setter(_v) { } - method() { -- const rest1 = __rest(this, []); -- const rest2 = __rest(this, []); -- const _a = this, { publicProp: _1 } = _a, rest3 = __rest(_a, ["publicProp"]); -- const _b = this, { publicProp: _2 } = _b, rest4 = __rest(_b, ["publicProp"]); -+ const { ...rest1 } = this; -+ const { ...rest2 } = this; -+ const { publicProp: _1, ...rest3 } = this; -+ const { publicProp: _2, ...rest4 } = this; - rest1.publicProp; - rest2.publicProp; - rest3.publicProp; -@@= skipped -31, +31 lines =@@ - } - } - function destructure(x) { -- const rest1 = __rest(x, []); -- const rest2 = __rest(x, []); -- const { publicProp: _1 } = x, rest3 = __rest(x, ["publicProp"]); -- const _a = x, { publicProp: _2 } = _a, rest4 = __rest(_a, ["publicProp"]); -+ const { ...rest1 } = x; -+ const { ...rest2 } = x; -+ const { publicProp: _1, ...rest3 } = x; -+ const { publicProp: _2, ...rest4 } = x; - rest1.publicProp; - rest2.publicProp; - rest3.publicProp; \ No newline at end of file + this.privateProp = privateProp; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=commonjs).js b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=commonjs).js index dc23860f00..08abaa3d83 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=commonjs).js +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=commonjs).js @@ -18,4 +18,4 @@ class A { } exports.A = A; const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=commonjs).js.diff b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=commonjs).js.diff index af26c06e4d..0f8491c6db 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=commonjs).js.diff +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=commonjs).js.diff @@ -22,5 +22,4 @@ - dec -], A); const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2020).js b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2020).js index d03c41d64d..42e35b59c5 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2020).js +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2020).js @@ -14,4 +14,4 @@ const y = { ...o }; export class A { } const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2020).js.diff b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2020).js.diff index be7277dd46..3232c60574 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2020).js.diff +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2020).js.diff @@ -20,5 +20,4 @@ +export class A { +} const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2022).js b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2022).js index d03c41d64d..42e35b59c5 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2022).js +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2022).js @@ -14,4 +14,4 @@ const y = { ...o }; export class A { } const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2022).js.diff b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2022).js.diff index 1c88c86923..8254c062ad 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2022).js.diff +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es2022).js.diff @@ -20,5 +20,4 @@ +export class A { +} const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es6).js b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es6).js index d03c41d64d..42e35b59c5 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es6).js +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es6).js @@ -14,4 +14,4 @@ const y = { ...o }; export class A { } const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es6).js.diff b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es6).js.diff index 5eae9d708c..c59af0d24d 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es6).js.diff +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=es6).js.diff @@ -20,5 +20,4 @@ +export class A { +} const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=esnext).js b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=esnext).js index d03c41d64d..42e35b59c5 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=esnext).js +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=esnext).js @@ -14,4 +14,4 @@ const y = { ...o }; export class A { } const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=esnext).js.diff b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=esnext).js.diff index 3ae5bb47c2..e03559a83c 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=esnext).js.diff +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=esnext).js.diff @@ -20,5 +20,4 @@ +export class A { +} const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node16).js b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node16).js index dc23860f00..08abaa3d83 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node16).js +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node16).js @@ -18,4 +18,4 @@ class A { } exports.A = A; const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node16).js.diff b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node16).js.diff index 6f2aa0f2f7..929423ee34 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node16).js.diff +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node16).js.diff @@ -24,5 +24,4 @@ +} +exports.A = A; const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node18).js b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node18).js index dc23860f00..08abaa3d83 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node18).js +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node18).js @@ -18,4 +18,4 @@ class A { } exports.A = A; const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node18).js.diff b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node18).js.diff index 6ea32823cb..66178e26d6 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node18).js.diff +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=node18).js.diff @@ -24,5 +24,4 @@ +} +exports.A = A; const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=nodenext).js b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=nodenext).js index dc23860f00..08abaa3d83 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=nodenext).js +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=nodenext).js @@ -18,4 +18,4 @@ class A { } exports.A = A; const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=nodenext).js.diff b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=nodenext).js.diff index b7883ec3cb..3a741386c0 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=nodenext).js.diff +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=nodenext).js.diff @@ -24,5 +24,4 @@ +} +exports.A = A; const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=none).js b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=none).js index d03c41d64d..42e35b59c5 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=none).js +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=none).js @@ -14,4 +14,4 @@ const y = { ...o }; export class A { } const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=none).js.diff b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=none).js.diff index 73195c999f..3ea7892d24 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=none).js.diff +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=none).js.diff @@ -23,5 +23,4 @@ +export class A { +} const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=preserve).js b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=preserve).js index d03c41d64d..42e35b59c5 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=preserve).js +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=preserve).js @@ -14,4 +14,4 @@ const y = { ...o }; export class A { } const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=preserve).js.diff b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=preserve).js.diff index c34a45bb09..7c8d72d6c2 100644 --- a/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=preserve).js.diff +++ b/testdata/baselines/reference/submodule/compiler/emitHelpersWithLocalCollisions(module=preserve).js.diff @@ -20,5 +20,4 @@ +export class A { +} const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithSpread.js b/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithSpread.js index 3124252ef6..a05d342391 100644 --- a/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithSpread.js +++ b/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithSpread.js @@ -20,5 +20,16 @@ f({ a: 1, ...l, ...r }); //// [excessPropertyCheckWithSpread.js] -f({ a: 1, ...i }); -f({ a: 1, ...l, ...r }); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +f(__assign({ a: 1 }, i)); +f(__assign(__assign({ a: 1 }, l), r)); diff --git a/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithSpread.js.diff b/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithSpread.js.diff deleted file mode 100644 index a20b74c549..0000000000 --- a/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithSpread.js.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- old.excessPropertyCheckWithSpread.js -+++ new.excessPropertyCheckWithSpread.js -@@= skipped -19, +19 lines =@@ - - - //// [excessPropertyCheckWithSpread.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --f(__assign({ a: 1 }, i)); --f(__assign(__assign({ a: 1 }, l), r)); -+f({ a: 1, ...i }); -+f({ a: 1, ...l, ...r }); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithUnions.js b/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithUnions.js index 5636e1d844..269fade2d4 100644 --- a/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithUnions.js +++ b/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithUnions.js @@ -155,6 +155,17 @@ F2({ //// [excessPropertyCheckWithUnions.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; let wrong = { tag: "T", a1: "extra" }; wrong = { tag: "A", d20: 12 }; wrong = { tag: "D" }; @@ -173,7 +184,7 @@ let over; // these two are still errors despite their doubled up discriminants over = { a: 1, b: 1, first: "ok", second: "error" }; over = { a: 1, b: 1, first: "ok", third: "error" }; -let t2 = { ...t1 }; +let t2 = __assign({}, t1); t0 = t2; const abab = { kind: "A", diff --git a/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithUnions.js.diff b/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithUnions.js.diff index b1647100b5..05b1283df7 100644 --- a/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithUnions.js.diff +++ b/testdata/baselines/reference/submodule/compiler/excessPropertyCheckWithUnions.js.diff @@ -5,26 +5,6 @@ //// [excessPropertyCheckWithUnions.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - let wrong = { tag: "T", a1: "extra" }; - wrong = { tag: "A", d20: 12 }; - wrong = { tag: "D" }; -@@= skipped -30, +18 lines =@@ - // these two are still errors despite their doubled up discriminants - over = { a: 1, b: 1, first: "ok", second: "error" }; - over = { a: 1, b: 1, first: "ok", third: "error" }; --let t2 = __assign({}, t1); -+let t2 = { ...t1 }; - t0 = t2; - const abab = { - kind: "A", \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/explicitAnyAfterSpreadNoImplicitAnyError.js b/testdata/baselines/reference/submodule/compiler/explicitAnyAfterSpreadNoImplicitAnyError.js index 026b85681f..5cd098b2d1 100644 --- a/testdata/baselines/reference/submodule/compiler/explicitAnyAfterSpreadNoImplicitAnyError.js +++ b/testdata/baselines/reference/submodule/compiler/explicitAnyAfterSpreadNoImplicitAnyError.js @@ -6,5 +6,16 @@ let x: any; //// [explicitAnyAfterSpreadNoImplicitAnyError.js] -({ a: [], ...null }); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +(__assign({ a: [] }, null)); let x; diff --git a/testdata/baselines/reference/submodule/compiler/explicitAnyAfterSpreadNoImplicitAnyError.js.diff b/testdata/baselines/reference/submodule/compiler/explicitAnyAfterSpreadNoImplicitAnyError.js.diff deleted file mode 100644 index 22552dd439..0000000000 --- a/testdata/baselines/reference/submodule/compiler/explicitAnyAfterSpreadNoImplicitAnyError.js.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.explicitAnyAfterSpreadNoImplicitAnyError.js -+++ new.explicitAnyAfterSpreadNoImplicitAnyError.js -@@= skipped -5, +5 lines =@@ - - - //// [explicitAnyAfterSpreadNoImplicitAnyError.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --(__assign({ a: [] }, null)); -+({ a: [], ...null }); - let x; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=commonjs,target=es5).js b/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=commonjs,target=es5).js index a3be2646fa..0fd7238def 100644 --- a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=commonjs,target=es5).js +++ b/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=commonjs,target=es5).js @@ -5,6 +5,7 @@ export const { x, ...rest } = { x: 'x', y: 'y' }; //// [exportObjectRest.js] "use strict"; +var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.rest = exports.x = void 0; -({ x: exports.x, ...exports.rest } = { x: 'x', y: 'y' }); +({ x: exports.x } = (_a = { x: 'x', y: 'y' }, _a), exports.rest = __rest(_a, ["x"])); diff --git a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=commonjs,target=es5).js.diff b/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=commonjs,target=es5).js.diff index cfb9234895..f6bce51c12 100644 --- a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=commonjs,target=es5).js.diff +++ b/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=commonjs,target=es5).js.diff @@ -1,11 +1,8 @@ --- old.exportObjectRest(module=commonjs,target=es5).js +++ new.exportObjectRest(module=commonjs,target=es5).js -@@= skipped -4, +4 lines =@@ - - //// [exportObjectRest.js] - "use strict"; --var _a; +@@= skipped -7, +7 lines =@@ + var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.rest = exports.x = void 0; -exports.x = (_a = { x: 'x', y: 'y' }, _a).x, exports.rest = __rest(_a, ["x"]); -+({ x: exports.x, ...exports.rest } = { x: 'x', y: 'y' }); \ No newline at end of file ++({ x: exports.x } = (_a = { x: 'x', y: 'y' }, _a), exports.rest = __rest(_a, ["x"])); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=es2015,target=es5).js b/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=es2015,target=es5).js index a327741219..794a1a3acb 100644 --- a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=es2015,target=es5).js +++ b/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=es2015,target=es5).js @@ -4,4 +4,5 @@ export const { x, ...rest } = { x: 'x', y: 'y' }; //// [exportObjectRest.js] -export const { x, ...rest } = { x: 'x', y: 'y' }; +var _a; +export const { x } = (_a = { x: 'x', y: 'y' }, _a), rest = __rest(_a, ["x"]); diff --git a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=es2015,target=es5).js.diff b/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=es2015,target=es5).js.diff deleted file mode 100644 index d76b066c0f..0000000000 --- a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=es2015,target=es5).js.diff +++ /dev/null @@ -1,9 +0,0 @@ ---- old.exportObjectRest(module=es2015,target=es5).js -+++ new.exportObjectRest(module=es2015,target=es5).js -@@= skipped -3, +3 lines =@@ - export const { x, ...rest } = { x: 'x', y: 'y' }; - - //// [exportObjectRest.js] --var _a; --export const { x } = (_a = { x: 'x', y: 'y' }, _a), rest = __rest(_a, ["x"]); -+export const { x, ...rest } = { x: 'x', y: 'y' }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=esnext,target=es5).js b/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=esnext,target=es5).js index a327741219..794a1a3acb 100644 --- a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=esnext,target=es5).js +++ b/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=esnext,target=es5).js @@ -4,4 +4,5 @@ export const { x, ...rest } = { x: 'x', y: 'y' }; //// [exportObjectRest.js] -export const { x, ...rest } = { x: 'x', y: 'y' }; +var _a; +export const { x } = (_a = { x: 'x', y: 'y' }, _a), rest = __rest(_a, ["x"]); diff --git a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=esnext,target=es5).js.diff b/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=esnext,target=es5).js.diff deleted file mode 100644 index fdeae6fac4..0000000000 --- a/testdata/baselines/reference/submodule/compiler/exportObjectRest(module=esnext,target=es5).js.diff +++ /dev/null @@ -1,9 +0,0 @@ ---- old.exportObjectRest(module=esnext,target=es5).js -+++ new.exportObjectRest(module=esnext,target=es5).js -@@= skipped -3, +3 lines =@@ - export const { x, ...rest } = { x: 'x', y: 'y' }; - - //// [exportObjectRest.js] --var _a; --export const { x } = (_a = { x: 'x', y: 'y' }, _a), rest = __rest(_a, ["x"]); -+export const { x, ...rest } = { x: 'x', y: 'y' }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/forLoopWithDestructuringDoesNotElideFollowingStatement.js b/testdata/baselines/reference/submodule/compiler/forLoopWithDestructuringDoesNotElideFollowingStatement.js index b574e9e3b7..18a6d74095 100644 --- a/testdata/baselines/reference/submodule/compiler/forLoopWithDestructuringDoesNotElideFollowingStatement.js +++ b/testdata/baselines/reference/submodule/compiler/forLoopWithDestructuringDoesNotElideFollowingStatement.js @@ -6,6 +6,19 @@ for (let { a, ...rest } of array) void a //// [forLoopWithDestructuringDoesNotElideFollowingStatement.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; let array = [{ a: 0, b: 1 }]; -for (let { a, ...rest } of array) +for (let _a of array) { + let { a } = _a, rest = __rest(_a, ["a"]); void a; +} diff --git a/testdata/baselines/reference/submodule/compiler/forLoopWithDestructuringDoesNotElideFollowingStatement.js.diff b/testdata/baselines/reference/submodule/compiler/forLoopWithDestructuringDoesNotElideFollowingStatement.js.diff deleted file mode 100644 index ea2e506ff8..0000000000 --- a/testdata/baselines/reference/submodule/compiler/forLoopWithDestructuringDoesNotElideFollowingStatement.js.diff +++ /dev/null @@ -1,23 +0,0 @@ ---- old.forLoopWithDestructuringDoesNotElideFollowingStatement.js -+++ new.forLoopWithDestructuringDoesNotElideFollowingStatement.js -@@= skipped -5, +5 lines =@@ - void a - - //// [forLoopWithDestructuringDoesNotElideFollowingStatement.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - let array = [{ a: 0, b: 1 }]; --for (let _a of array) { -- let { a } = _a, rest = __rest(_a, ["a"]); -+for (let { a, ...rest } of array) - void a; --} \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/genericIsNeverEmptyObject.js b/testdata/baselines/reference/submodule/compiler/genericIsNeverEmptyObject.js index faf185e259..64a67ccc66 100644 --- a/testdata/baselines/reference/submodule/compiler/genericIsNeverEmptyObject.js +++ b/testdata/baselines/reference/submodule/compiler/genericIsNeverEmptyObject.js @@ -13,10 +13,32 @@ let o2: { b: string, x: number } = test(o1); //// [genericIsNeverEmptyObject.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; // Repro from #29067 function test(obj) { - let { a, ...rest } = obj; - return { ...rest, b: a }; + let { a } = obj, rest = __rest(obj, ["a"]); + return __assign(__assign({}, rest), { b: a }); } let o1 = { a: 'hello', x: 42 }; let o2 = test(o1); diff --git a/testdata/baselines/reference/submodule/compiler/genericIsNeverEmptyObject.js.diff b/testdata/baselines/reference/submodule/compiler/genericIsNeverEmptyObject.js.diff index d646870406..f4c36261ad 100644 --- a/testdata/baselines/reference/submodule/compiler/genericIsNeverEmptyObject.js.diff +++ b/testdata/baselines/reference/submodule/compiler/genericIsNeverEmptyObject.js.diff @@ -5,34 +5,15 @@ //// [genericIsNeverEmptyObject.js] -"use strict"; - // Repro from #29067 --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; +-// Repro from #29067 + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -24, +22 lines =@@ + } + return t; + }; ++// Repro from #29067 function test(obj) { -- let { a } = obj, rest = __rest(obj, ["a"]); -- return __assign(__assign({}, rest), { b: a }); -+ let { a, ...rest } = obj; -+ return { ...rest, b: a }; - } - let o1 = { a: 'hello', x: 42 }; - let o2 = test(o1); \ No newline at end of file + let { a } = obj, rest = __rest(obj, ["a"]); + return __assign(__assign({}, rest), { b: a }); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/genericObjectSpreadResultInSwitch.js b/testdata/baselines/reference/submodule/compiler/genericObjectSpreadResultInSwitch.js index fae50a67aa..0ca5446739 100644 --- a/testdata/baselines/reference/submodule/compiler/genericObjectSpreadResultInSwitch.js +++ b/testdata/baselines/reference/submodule/compiler/genericObjectSpreadResultInSwitch.js @@ -36,10 +36,21 @@ switch (params.tag) { } //// [genericObjectSpreadResultInSwitch.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; const getType = (params) => { const { // Omit - foo, ...rest } = params; + foo } = params, rest = __rest(params, ["foo"]); return rest; }; switch (params.tag) { diff --git a/testdata/baselines/reference/submodule/compiler/genericObjectSpreadResultInSwitch.js.diff b/testdata/baselines/reference/submodule/compiler/genericObjectSpreadResultInSwitch.js.diff deleted file mode 100644 index 53e064df97..0000000000 --- a/testdata/baselines/reference/submodule/compiler/genericObjectSpreadResultInSwitch.js.diff +++ /dev/null @@ -1,25 +0,0 @@ ---- old.genericObjectSpreadResultInSwitch.js -+++ new.genericObjectSpreadResultInSwitch.js -@@= skipped -35, +35 lines =@@ - } - - //// [genericObjectSpreadResultInSwitch.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - const getType = (params) => { - const { - // Omit -- foo } = params, rest = __rest(params, ["foo"]); -+ foo, ...rest } = params; - return rest; - }; - switch (params.tag) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersBundler.js b/testdata/baselines/reference/submodule/compiler/importHelpersBundler.js index e1a2194717..d60f462b51 100644 --- a/testdata/baselines/reference/submodule/compiler/importHelpersBundler.js +++ b/testdata/baselines/reference/submodule/compiler/importHelpersBundler.js @@ -44,7 +44,8 @@ export function foo(args: any) { //// [main.js] +import { __rest } from "tslib"; export function foo(args) { - const { bar, ...extraArgs } = args; + const { bar } = args, extraArgs = __rest(args, ["bar"]); return extraArgs; } diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersBundler.js.diff b/testdata/baselines/reference/submodule/compiler/importHelpersBundler.js.diff deleted file mode 100644 index 95fa683e9c..0000000000 --- a/testdata/baselines/reference/submodule/compiler/importHelpersBundler.js.diff +++ /dev/null @@ -1,12 +0,0 @@ ---- old.importHelpersBundler.js -+++ new.importHelpersBundler.js -@@= skipped -43, +43 lines =@@ - - - //// [main.js] --import { __rest } from "tslib"; - export function foo(args) { -- const { bar } = args, extraArgs = __rest(args, ["bar"]); -+ const { bar, ...extraArgs } = args; - return extraArgs; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersES6.js b/testdata/baselines/reference/submodule/compiler/importHelpersES6.js index 0d5e232c4d..6d03b088f8 100644 --- a/testdata/baselines/reference/submodule/compiler/importHelpersES6.js +++ b/testdata/baselines/reference/submodule/compiler/importHelpersES6.js @@ -30,4 +30,4 @@ export class A { g(u) { return #x in u; } } const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersES6.js.diff b/testdata/baselines/reference/submodule/compiler/importHelpersES6.js.diff index 9dfaf4bab9..215060a0db 100644 --- a/testdata/baselines/reference/submodule/compiler/importHelpersES6.js.diff +++ b/testdata/baselines/reference/submodule/compiler/importHelpersES6.js.diff @@ -27,5 +27,4 @@ + g(u) { return #x in u; } +} const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersNoHelpers.js b/testdata/baselines/reference/submodule/compiler/importHelpersNoHelpers.js index c25beb2060..67899671f1 100644 --- a/testdata/baselines/reference/submodule/compiler/importHelpersNoHelpers.js +++ b/testdata/baselines/reference/submodule/compiler/importHelpersNoHelpers.js @@ -59,8 +59,8 @@ class C { } } const o = { a: 1 }; -const y = { ...o }; -const { ...x } = y; +const y = tslib_1.__assign({}, o); +const x = tslib_1.__rest(y, []); //// [script.js] class A { } diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersNoHelpers.js.diff b/testdata/baselines/reference/submodule/compiler/importHelpersNoHelpers.js.diff index 1aa7e3a670..0ac6654328 100644 --- a/testdata/baselines/reference/submodule/compiler/importHelpersNoHelpers.js.diff +++ b/testdata/baselines/reference/submodule/compiler/importHelpersNoHelpers.js.diff @@ -35,10 +35,8 @@ + } +} const o = { a: 1 }; --const y = tslib_1.__assign({}, o); --const x = tslib_1.__rest(y, []); -+const y = { ...o }; -+const { ...x } = y; + const y = tslib_1.__assign({}, o); + const x = tslib_1.__rest(y, []); //// [script.js] -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersVerbatimModuleSyntax.js b/testdata/baselines/reference/submodule/compiler/importHelpersVerbatimModuleSyntax.js index b358c312a9..5221f3088a 100644 --- a/testdata/baselines/reference/submodule/compiler/importHelpersVerbatimModuleSyntax.js +++ b/testdata/baselines/reference/submodule/compiler/importHelpersVerbatimModuleSyntax.js @@ -45,8 +45,9 @@ export = foo; //// [main.cjs] +import tslib_1 = require("tslib"); function foo(args) { - const { bar, ...extraArgs } = args; + const { bar } = args, extraArgs = tslib_1.__rest(args, ["bar"]); return extraArgs; } module.exports = foo; diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersVerbatimModuleSyntax.js.diff b/testdata/baselines/reference/submodule/compiler/importHelpersVerbatimModuleSyntax.js.diff index ab5579a332..5ac3a46c10 100644 --- a/testdata/baselines/reference/submodule/compiler/importHelpersVerbatimModuleSyntax.js.diff +++ b/testdata/baselines/reference/submodule/compiler/importHelpersVerbatimModuleSyntax.js.diff @@ -5,9 +5,7 @@ //// [main.cjs] -const tslib_1 = require("tslib"); ++import tslib_1 = require("tslib"); function foo(args) { -- const { bar } = args, extraArgs = tslib_1.__rest(args, ["bar"]); -+ const { bar, ...extraArgs } = args; - return extraArgs; - } - module.exports = foo; \ No newline at end of file + const { bar } = args, extraArgs = tslib_1.__rest(args, ["bar"]); + return extraArgs; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=commonjs).js b/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=commonjs).js index ebfbc46bb0..5499da070a 100644 --- a/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=commonjs).js +++ b/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=commonjs).js @@ -26,4 +26,4 @@ class A { } exports.A = A; const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=commonjs).js.diff b/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=commonjs).js.diff index 8454fd26ed..c8299bf092 100644 --- a/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=commonjs).js.diff +++ b/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=commonjs).js.diff @@ -15,5 +15,4 @@ - dec -], A); const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=es2015).js b/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=es2015).js index bf5baceb90..36fb70701c 100644 --- a/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=es2015).js +++ b/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=es2015).js @@ -22,4 +22,4 @@ export declare function __awaiter(thisArg: any, _arguments: any, P: Function, ge export class A { } const o = { a: 1 }; -const y = { ...o }; +const y = Object.assign({}, o); diff --git a/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=es2015).js.diff b/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=es2015).js.diff index 9073ebfee1..1472b1baee 100644 --- a/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=es2015).js.diff +++ b/testdata/baselines/reference/submodule/compiler/importHelpersWithLocalCollisions(module=es2015).js.diff @@ -15,5 +15,4 @@ +export class A { +} const o = { a: 1 }; --const y = Object.assign({}, o); -+const y = { ...o }; \ No newline at end of file + const y = Object.assign({}, o); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/intersectionPropertyCheck.js b/testdata/baselines/reference/submodule/compiler/intersectionPropertyCheck.js index 0a362709ee..5a649b1f60 100644 --- a/testdata/baselines/reference/submodule/compiler/intersectionPropertyCheck.js +++ b/testdata/baselines/reference/submodule/compiler/intersectionPropertyCheck.js @@ -22,11 +22,22 @@ function test(value: T): Test { //// [intersectionPropertyCheck.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; let obj = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property let weak = wrong; // Nested weak object type function foo(x, y) { x = y; // Mismatched property in source intersection } function test(value) { - return { ...value, hi: true }; + return __assign(__assign({}, value), { hi: true }); } diff --git a/testdata/baselines/reference/submodule/compiler/intersectionPropertyCheck.js.diff b/testdata/baselines/reference/submodule/compiler/intersectionPropertyCheck.js.diff index 8dddfcf128..abe516b032 100644 --- a/testdata/baselines/reference/submodule/compiler/intersectionPropertyCheck.js.diff +++ b/testdata/baselines/reference/submodule/compiler/intersectionPropertyCheck.js.diff @@ -5,23 +5,6 @@ //// [intersectionPropertyCheck.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - let obj = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property - let weak = wrong; // Nested weak object type - function foo(x, y) { - x = y; // Mismatched property in source intersection - } - function test(value) { -- return __assign(__assign({}, value), { hi: true }); -+ return { ...value, hi: true }; - } \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/narrowingDestructuring.js b/testdata/baselines/reference/submodule/compiler/narrowingDestructuring.js index 3388fa19bb..62ee2a1ee4 100644 --- a/testdata/baselines/reference/submodule/compiler/narrowingDestructuring.js +++ b/testdata/baselines/reference/submodule/compiler/narrowingDestructuring.js @@ -43,6 +43,17 @@ function farr(x: //// [narrowingDestructuring.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; function func(value) { if (value.kind === "a") { value.a; @@ -56,18 +67,21 @@ function func(value) { function func2(value) { if (value.kind === "f") { const { f: f1 } = value; - const { f: { a, ...spread } } = value; + const _a = value.f, { a } = _a, spread = __rest(_a, ["a"]); value.f; } else { - const { g: { c, ...spread } } = value; + const _b = value.g, { c } = _b, spread = __rest(_b, ["c"]); value.g; } } function func3(t) { if (t.kind === "a") { - const { kind, ...r1 } = t; - const r2 = (({ kind, ...rest }) => rest)(t); + const { kind } = t, r1 = __rest(t, ["kind"]); + const r2 = ((_a) => { + var { kind } = _a, rest = __rest(_a, ["kind"]); + return rest; + })(t); } } function farr(x) { diff --git a/testdata/baselines/reference/submodule/compiler/narrowingDestructuring.js.diff b/testdata/baselines/reference/submodule/compiler/narrowingDestructuring.js.diff deleted file mode 100644 index 18bc4369db..0000000000 --- a/testdata/baselines/reference/submodule/compiler/narrowingDestructuring.js.diff +++ /dev/null @@ -1,46 +0,0 @@ ---- old.narrowingDestructuring.js -+++ new.narrowingDestructuring.js -@@= skipped -42, +42 lines =@@ - - - //// [narrowingDestructuring.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - function func(value) { - if (value.kind === "a") { - value.a; -@@= skipped -24, +13 lines =@@ - function func2(value) { - if (value.kind === "f") { - const { f: f1 } = value; -- const _a = value.f, { a } = _a, spread = __rest(_a, ["a"]); -+ const { f: { a, ...spread } } = value; - value.f; - } - else { -- const _b = value.g, { c } = _b, spread = __rest(_b, ["c"]); -+ const { g: { c, ...spread } } = value; - value.g; - } - } - function func3(t) { - if (t.kind === "a") { -- const { kind } = t, r1 = __rest(t, ["kind"]); -- const r2 = ((_a) => { -- var { kind } = _a, rest = __rest(_a, ["kind"]); -- return rest; -- })(t); -+ const { kind, ...r1 } = t; -+ const r2 = (({ kind, ...rest }) => rest)(t); - } - } - function farr(x) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/narrowingRestGenericCall.js b/testdata/baselines/reference/submodule/compiler/narrowingRestGenericCall.js index 03a0f17fde..91cd1f0f28 100644 --- a/testdata/baselines/reference/submodule/compiler/narrowingRestGenericCall.js +++ b/testdata/baselines/reference/submodule/compiler/narrowingRestGenericCall.js @@ -16,9 +16,21 @@ call(obj, ({foo, ...rest}) => { }); //// [narrowingRestGenericCall.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; function call(obj, cb) { cb(obj); } -call(obj, ({ foo, ...rest }) => { +call(obj, (_a) => { + var { foo } = _a, rest = __rest(_a, ["foo"]); console.log(rest.bar); }); diff --git a/testdata/baselines/reference/submodule/compiler/narrowingRestGenericCall.js.diff b/testdata/baselines/reference/submodule/compiler/narrowingRestGenericCall.js.diff deleted file mode 100644 index b1f0987e63..0000000000 --- a/testdata/baselines/reference/submodule/compiler/narrowingRestGenericCall.js.diff +++ /dev/null @@ -1,25 +0,0 @@ ---- old.narrowingRestGenericCall.js -+++ new.narrowingRestGenericCall.js -@@= skipped -15, +15 lines =@@ - }); - - //// [narrowingRestGenericCall.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - function call(obj, cb) { - cb(obj); - } --call(obj, (_a) => { -- var { foo } = _a, rest = __rest(_a, ["foo"]); -+call(obj, ({ foo, ...rest }) => { - console.log(rest.bar); - }); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/nestedObjectRest.js b/testdata/baselines/reference/submodule/compiler/nestedObjectRest.js index 304a34ca09..437607f3e0 100644 --- a/testdata/baselines/reference/submodule/compiler/nestedObjectRest.js +++ b/testdata/baselines/reference/submodule/compiler/nestedObjectRest.js @@ -8,8 +8,22 @@ var x, y; for ([{ ...y }] of [[{ abc: 1 }]]) ; //// [nestedObjectRest.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a, _b, _c; // https://github.com/microsoft/TypeScript/issues/43400 var x, y; -[{ ...x }] = [{ abc: 1 }]; -for ([{ ...y }] of [[{ abc: 1 }]]) +_a = [{ abc: 1 }], [_b] = _a, x = __rest(_b, []); +for (let _d of [[{ abc: 1 }]]) { + [_c] = _d, y = __rest(_c, []); ; +} diff --git a/testdata/baselines/reference/submodule/compiler/nestedObjectRest.js.diff b/testdata/baselines/reference/submodule/compiler/nestedObjectRest.js.diff index 1806c83b0b..a044f1e9c4 100644 --- a/testdata/baselines/reference/submodule/compiler/nestedObjectRest.js.diff +++ b/testdata/baselines/reference/submodule/compiler/nestedObjectRest.js.diff @@ -1,27 +1,18 @@ --- old.nestedObjectRest.js +++ new.nestedObjectRest.js -@@= skipped -7, +7 lines =@@ - for ([{ ...y }] of [[{ abc: 1 }]]) ; - - //// [nestedObjectRest.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; +@@= skipped -18, +18 lines =@@ + } + return t; + }; -var _a, _b; ++var _a, _b, _c; // https://github.com/microsoft/TypeScript/issues/43400 var x, y; -[_a] = [{ abc: 1 }], x = __rest(_a, []); -for (let _c of [[{ abc: 1 }]]) { - [_b] = _c, y = __rest(_b, []); -+[{ ...x }] = [{ abc: 1 }]; -+for ([{ ...y }] of [[{ abc: 1 }]]) ++_a = [{ abc: 1 }], [_b] = _a, x = __rest(_b, []); ++for (let _d of [[{ abc: 1 }]]) { ++ [_c] = _d, y = __rest(_c, []); ; --} \ No newline at end of file + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/objectBindingPattern_restElementWithPropertyName.js b/testdata/baselines/reference/submodule/compiler/objectBindingPattern_restElementWithPropertyName.js index 78414c9250..a79ecf7847 100644 --- a/testdata/baselines/reference/submodule/compiler/objectBindingPattern_restElementWithPropertyName.js +++ b/testdata/baselines/reference/submodule/compiler/objectBindingPattern_restElementWithPropertyName.js @@ -5,4 +5,15 @@ const { ...a: b } = {}; //// [objectBindingPattern_restElementWithPropertyName.js] -const { ...a: b } = {}; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +const b = __rest({}, []); diff --git a/testdata/baselines/reference/submodule/compiler/objectBindingPattern_restElementWithPropertyName.js.diff b/testdata/baselines/reference/submodule/compiler/objectBindingPattern_restElementWithPropertyName.js.diff deleted file mode 100644 index d029d3b3cc..0000000000 --- a/testdata/baselines/reference/submodule/compiler/objectBindingPattern_restElementWithPropertyName.js.diff +++ /dev/null @@ -1,19 +0,0 @@ ---- old.objectBindingPattern_restElementWithPropertyName.js -+++ new.objectBindingPattern_restElementWithPropertyName.js -@@= skipped -4, +4 lines =@@ - - - //// [objectBindingPattern_restElementWithPropertyName.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --const b = __rest({}, []); -+const { ...a: b } = {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/objectInstantiationFromUnionSpread.js b/testdata/baselines/reference/submodule/compiler/objectInstantiationFromUnionSpread.js index e254e2f55d..e2c3fab75f 100644 --- a/testdata/baselines/reference/submodule/compiler/objectInstantiationFromUnionSpread.js +++ b/testdata/baselines/reference/submodule/compiler/objectInstantiationFromUnionSpread.js @@ -23,9 +23,20 @@ function f2(a: Item[]) { //// [objectInstantiationFromUnionSpread.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; function f1(a) { - a.map(item => ({ ...item })).filter(value => { }); + a.map(item => (__assign({}, item))).filter(value => { }); } function f2(a) { - a.map(item => ({ ...item })).filter(value => { }); + a.map(item => (__assign({}, item))).filter(value => { }); } diff --git a/testdata/baselines/reference/submodule/compiler/objectInstantiationFromUnionSpread.js.diff b/testdata/baselines/reference/submodule/compiler/objectInstantiationFromUnionSpread.js.diff index dac1325cf9..687778aa18 100644 --- a/testdata/baselines/reference/submodule/compiler/objectInstantiationFromUnionSpread.js.diff +++ b/testdata/baselines/reference/submodule/compiler/objectInstantiationFromUnionSpread.js.diff @@ -5,22 +5,6 @@ //// [objectInstantiationFromUnionSpread.js] -// #40995 --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - function f1(a) { -- a.map(item => (__assign({}, item))).filter(value => { }); -+ a.map(item => ({ ...item })).filter(value => { }); - } - function f2(a) { -- a.map(item => (__assign({}, item))).filter(value => { }); -+ a.map(item => ({ ...item })).filter(value => { }); - } \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/objectLiteralFreshnessWithSpread.js b/testdata/baselines/reference/submodule/compiler/objectLiteralFreshnessWithSpread.js index ad6779e638..777f82a56d 100644 --- a/testdata/baselines/reference/submodule/compiler/objectLiteralFreshnessWithSpread.js +++ b/testdata/baselines/reference/submodule/compiler/objectLiteralFreshnessWithSpread.js @@ -6,5 +6,16 @@ let xx: { a, b } = { a: 1, ...x, z: 3 } // error for 'z', no error for 'extra' //// [objectLiteralFreshnessWithSpread.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; let x = { b: 1, extra: 2 }; -let xx = { a: 1, ...x, z: 3 }; // error for 'z', no error for 'extra' +let xx = __assign(__assign({ a: 1 }, x), { z: 3 }); // error for 'z', no error for 'extra' diff --git a/testdata/baselines/reference/submodule/compiler/objectLiteralFreshnessWithSpread.js.diff b/testdata/baselines/reference/submodule/compiler/objectLiteralFreshnessWithSpread.js.diff deleted file mode 100644 index c4057a6dad..0000000000 --- a/testdata/baselines/reference/submodule/compiler/objectLiteralFreshnessWithSpread.js.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.objectLiteralFreshnessWithSpread.js -+++ new.objectLiteralFreshnessWithSpread.js -@@= skipped -5, +5 lines =@@ - - - //// [objectLiteralFreshnessWithSpread.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - let x = { b: 1, extra: 2 }; --let xx = __assign(__assign({ a: 1 }, x), { z: 3 }); // error for 'z', no error for 'extra' -+let xx = { a: 1, ...x, z: 3 }; // error for 'z', no error for 'extra' \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/objectRestSpread.js b/testdata/baselines/reference/submodule/compiler/objectRestSpread.js index 655d705bb8..37423122c7 100644 --- a/testdata/baselines/reference/submodule/compiler/objectRestSpread.js +++ b/testdata/baselines/reference/submodule/compiler/objectRestSpread.js @@ -25,12 +25,20 @@ function test({ }) {} //// [objectRestSpread.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a, _b, _c, _d; let obj = {}; -({ ...obj }); -let { prop = { ...obj }, more = { ...obj } = { ...obj }, ['' + 'other']: other = { ...obj }, yetAnother: { nested: { ['nested' + 'prop']: nestedProp = { ...obj }, ...nestedRest } = { ...obj } } = { ...obj }, fn = async function* () { }, ...props } = {}; -({ - prop = { ...obj }, - ['' + 'other']: other = { ...obj }, - ...props -} = {}); -function test({ prop = { ...obj }, ...props }) { } +(Object.assign({}, obj)); +let _e = {}, { prop = Object.assign({}, obj), more = (_a = Object.assign({}, obj), obj = __rest(_a, [])) } = _e, _f = '' + 'other', _g = _e[_f], other = _g === void 0 ? Object.assign({}, obj) : _g, _h = _e.yetAnother, _j = _h === void 0 ? Object.assign({}, obj) : _h, _k = _j.nested, _l = _k === void 0 ? Object.assign({}, obj) : _k, _m = 'nested' + 'prop', _o = _l[_m], nestedProp = _o === void 0 ? Object.assign({}, obj) : _o, nestedRest = __rest(_l, [typeof _m === "symbol" ? _m : _m + ""]), { fn = async function* () { } } = _e, props = __rest(_e, ["prop", "more", typeof _f === "symbol" ? _f : _f + "", "yetAnother", "fn"]); +(_b = {}, { prop = Object.assign({}, obj) } = _b, _c = '' + 'other', _d = _b[_c], other = _d === void 0 ? Object.assign({}, obj) : _d, props = __rest(_b, ["prop", typeof _c === "symbol" ? _c : _c + ""])); +function test(_a) { var { prop = Object.assign({}, obj) } = _a, props = __rest(_a, ["prop"]); } diff --git a/testdata/baselines/reference/submodule/compiler/objectRestSpread.js.diff b/testdata/baselines/reference/submodule/compiler/objectRestSpread.js.diff index 2733621660..10d4f786f3 100644 --- a/testdata/baselines/reference/submodule/compiler/objectRestSpread.js.diff +++ b/testdata/baselines/reference/submodule/compiler/objectRestSpread.js.diff @@ -1,20 +1,9 @@ --- old.objectRestSpread.js +++ new.objectRestSpread.js -@@= skipped -24, +24 lines =@@ - }) {} - - //// [objectRestSpread.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; +@@= skipped -35, +35 lines =@@ + } + return t; + }; -var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } -var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { - if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); @@ -28,17 +17,10 @@ - function reject(value) { resume("throw", value); } - function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } -}; --var _a, _b, _c, _d; + var _a, _b, _c, _d; let obj = {}; --(Object.assign({}, obj)); + (Object.assign({}, obj)); -let _e = {}, { prop = Object.assign({}, obj) } = _e, _f = _e.more, more = _f === void 0 ? (_a = Object.assign({}, obj), obj = __rest(_a, []), _a) : _f, _g = '' + 'other', _h = _e[_g], other = _h === void 0 ? Object.assign({}, obj) : _h, _j = _e.yetAnother, _k = _j === void 0 ? Object.assign({}, obj) : _j, _l = _k.nested, _m = _l === void 0 ? Object.assign({}, obj) : _l, _o = 'nested' + 'prop', _p = _m[_o], nestedProp = _p === void 0 ? Object.assign({}, obj) : _p, nestedRest = __rest(_m, [typeof _o === "symbol" ? _o : _o + ""]), { fn = function () { return __asyncGenerator(this, arguments, function* () { }); } } = _e, props = __rest(_e, ["prop", "more", typeof _g === "symbol" ? _g : _g + "", "yetAnother", "fn"]); --(_b = {}, { prop = Object.assign({}, obj) } = _b, _c = '' + 'other', _d = _b[_c], other = _d === void 0 ? Object.assign({}, obj) : _d, props = __rest(_b, ["prop", typeof _c === "symbol" ? _c : _c + ""])); --function test(_a) { var { prop = Object.assign({}, obj) } = _a, props = __rest(_a, ["prop"]); } -+({ ...obj }); -+let { prop = { ...obj }, more = { ...obj } = { ...obj }, ['' + 'other']: other = { ...obj }, yetAnother: { nested: { ['nested' + 'prop']: nestedProp = { ...obj }, ...nestedRest } = { ...obj } } = { ...obj }, fn = async function* () { }, ...props } = {}; -+({ -+ prop = { ...obj }, -+ ['' + 'other']: other = { ...obj }, -+ ...props -+} = {}); -+function test({ prop = { ...obj }, ...props }) { } \ No newline at end of file ++let _e = {}, { prop = Object.assign({}, obj), more = (_a = Object.assign({}, obj), obj = __rest(_a, [])) } = _e, _f = '' + 'other', _g = _e[_f], other = _g === void 0 ? Object.assign({}, obj) : _g, _h = _e.yetAnother, _j = _h === void 0 ? Object.assign({}, obj) : _h, _k = _j.nested, _l = _k === void 0 ? Object.assign({}, obj) : _k, _m = 'nested' + 'prop', _o = _l[_m], nestedProp = _o === void 0 ? Object.assign({}, obj) : _o, nestedRest = __rest(_l, [typeof _m === "symbol" ? _m : _m + ""]), { fn = async function* () { } } = _e, props = __rest(_e, ["prop", "more", typeof _f === "symbol" ? _f : _f + "", "yetAnother", "fn"]); + (_b = {}, { prop = Object.assign({}, obj) } = _b, _c = '' + 'other', _d = _b[_c], other = _d === void 0 ? Object.assign({}, obj) : _d, props = __rest(_b, ["prop", typeof _c === "symbol" ? _c : _c + ""])); + function test(_a) { var { prop = Object.assign({}, obj) } = _a, props = __rest(_a, ["prop"]); } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/objectSpreadWithinMethodWithinObjectWithSpread.js b/testdata/baselines/reference/submodule/compiler/objectSpreadWithinMethodWithinObjectWithSpread.js index 6122fdc53e..b83cb77c43 100644 --- a/testdata/baselines/reference/submodule/compiler/objectSpreadWithinMethodWithinObjectWithSpread.js +++ b/testdata/baselines/reference/submodule/compiler/objectSpreadWithinMethodWithinObjectWithSpread.js @@ -14,13 +14,18 @@ const a = { //// [objectSpreadWithinMethodWithinObjectWithSpread.js] -const obj = {}; -const a = { - ...obj, - prop() { - return { - ...obj, - metadata: 213 - }; - } +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); }; +const obj = {}; +const a = __assign(__assign({}, obj), { prop() { + return __assign(__assign({}, obj), { metadata: 213 }); + } }); diff --git a/testdata/baselines/reference/submodule/compiler/objectSpreadWithinMethodWithinObjectWithSpread.js.diff b/testdata/baselines/reference/submodule/compiler/objectSpreadWithinMethodWithinObjectWithSpread.js.diff deleted file mode 100644 index 4ac09a0679..0000000000 --- a/testdata/baselines/reference/submodule/compiler/objectSpreadWithinMethodWithinObjectWithSpread.js.diff +++ /dev/null @@ -1,30 +0,0 @@ ---- old.objectSpreadWithinMethodWithinObjectWithSpread.js -+++ new.objectSpreadWithinMethodWithinObjectWithSpread.js -@@= skipped -13, +13 lines =@@ - - - //// [objectSpreadWithinMethodWithinObjectWithSpread.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - const obj = {}; --const a = __assign(__assign({}, obj), { prop() { -- return __assign(__assign({}, obj), { metadata: 213 }); -- } }); -+const a = { -+ ...obj, -+ prop() { -+ return { -+ ...obj, -+ metadata: 213 -+ }; -+ } -+}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/restElementAssignable.js b/testdata/baselines/reference/submodule/compiler/restElementAssignable.js index f1b392886f..4f8eab6bb4 100644 --- a/testdata/baselines/reference/submodule/compiler/restElementAssignable.js +++ b/testdata/baselines/reference/submodule/compiler/restElementAssignable.js @@ -19,15 +19,26 @@ //// [restElementAssignable.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; { - const { ...props } = {}; + const props = __rest({}, []); // Use to fail const t1 = props; // Working equivalent const t2 = {}; } { - const { ...props } = { a: 1, b: false, c: "str" }; + const props = __rest({ a: 1, b: false, c: "str" }, []); // Use to fail const t1 = props; // Working equivalent diff --git a/testdata/baselines/reference/submodule/compiler/restElementAssignable.js.diff b/testdata/baselines/reference/submodule/compiler/restElementAssignable.js.diff index 28849d4ed3..89ae16791e 100644 --- a/testdata/baselines/reference/submodule/compiler/restElementAssignable.js.diff +++ b/testdata/baselines/reference/submodule/compiler/restElementAssignable.js.diff @@ -5,28 +5,6 @@ //// [restElementAssignable.js] -"use strict"; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - { -- const props = __rest({}, []); -+ const { ...props } = {}; - // Use to fail - const t1 = props; - // Working equivalent - const t2 = {}; - } - { -- const props = __rest({ a: 1, b: false, c: "str" }, []); -+ const { ...props } = { a: 1, b: false, c: "str" }; - // Use to fail - const t1 = props; - // Working equivalent \ No newline at end of file + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/restElementWithNumberPropertyName.js b/testdata/baselines/reference/submodule/compiler/restElementWithNumberPropertyName.js index 28f52f3ca7..9c3847fd61 100644 --- a/testdata/baselines/reference/submodule/compiler/restElementWithNumberPropertyName.js +++ b/testdata/baselines/reference/submodule/compiler/restElementWithNumberPropertyName.js @@ -5,4 +5,15 @@ const { 0: a, ...b } = [0, 1, 2]; //// [restElementWithNumberPropertyName.js] -const { 0: a, ...b } = [0, 1, 2]; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +const _a = [0, 1, 2], { 0: a } = _a, b = __rest(_a, ["0"]); diff --git a/testdata/baselines/reference/submodule/compiler/restElementWithNumberPropertyName.js.diff b/testdata/baselines/reference/submodule/compiler/restElementWithNumberPropertyName.js.diff deleted file mode 100644 index 7788329cfb..0000000000 --- a/testdata/baselines/reference/submodule/compiler/restElementWithNumberPropertyName.js.diff +++ /dev/null @@ -1,19 +0,0 @@ ---- old.restElementWithNumberPropertyName.js -+++ new.restElementWithNumberPropertyName.js -@@= skipped -4, +4 lines =@@ - - - //// [restElementWithNumberPropertyName.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --const _a = [0, 1, 2], { 0: a } = _a, b = __rest(_a, ["0"]); -+const { 0: a, ...b } = [0, 1, 2]; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/restIntersection.js b/testdata/baselines/reference/submodule/compiler/restIntersection.js index 8f668108c7..10bf470f02 100644 --- a/testdata/baselines/reference/submodule/compiler/restIntersection.js +++ b/testdata/baselines/reference/submodule/compiler/restIntersection.js @@ -8,6 +8,17 @@ var {x, ...rest1 } = intersection; //// [restIntersection.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; var intersection; var rest1; -var { x, ...rest1 } = intersection; +var { x } = intersection, rest1 = __rest(intersection, ["x"]); diff --git a/testdata/baselines/reference/submodule/compiler/restIntersection.js.diff b/testdata/baselines/reference/submodule/compiler/restIntersection.js.diff deleted file mode 100644 index 5495a712ac..0000000000 --- a/testdata/baselines/reference/submodule/compiler/restIntersection.js.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- old.restIntersection.js -+++ new.restIntersection.js -@@= skipped -7, +7 lines =@@ - - - //// [restIntersection.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - var intersection; - var rest1; --var { x } = intersection, rest1 = __rest(intersection, ["x"]); -+var { x, ...rest1 } = intersection; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/restInvalidArgumentType.js b/testdata/baselines/reference/submodule/compiler/restInvalidArgumentType.js index 79bf359b41..2254315815 100644 --- a/testdata/baselines/reference/submodule/compiler/restInvalidArgumentType.js +++ b/testdata/baselines/reference/submodule/compiler/restInvalidArgumentType.js @@ -58,6 +58,17 @@ function f(p1: T, p2: T[]) { //// [restInvalidArgumentType.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; var E; (function (E) { E[E["v1"] = 0] = "v1"; @@ -82,23 +93,23 @@ function f(p1, p2) { var u; var n; var a; - var { ...r1 } = p1; // Error, generic type paramterre - var { ...r2 } = p2; // OK - var { ...r3 } = t; // Error, generic type paramter - var { ...r4 } = i; // Error, index access - var { ...r5 } = k; // Error, index - var { ...r6 } = mapped_generic; // Error, generic mapped object type - var { ...r7 } = mapped; // OK, non-generic mapped type - var { ...r8 } = union_generic; // Error, union with generic type parameter - var { ...r9 } = union_primitive; // Error, union with generic type parameter - var { ...r10 } = intersection_generic; // Error, intersection with generic type parameter - var { ...r11 } = intersection_primitive; // Error, intersection with generic type parameter - var { ...r12 } = num; // Error - var { ...r13 } = str; // Error - var { ...r14 } = u; // error, undefined-only not allowed - var { ...r15 } = n; // error, null-only not allowed - var { ...r16 } = a; // OK - var { ...r17 } = literal_string; // Error - var { ...r18 } = literal_number; // Error - var { ...r19 } = e; // Error, enum + var r1 = __rest(p1, []); // Error, generic type paramterre + var r2 = __rest(p2, []); // OK + var r3 = __rest(t, []); // Error, generic type paramter + var r4 = __rest(i, []); // Error, index access + var r5 = __rest(k, []); // Error, index + var r6 = __rest(mapped_generic, []); // Error, generic mapped object type + var r7 = __rest(mapped, []); // OK, non-generic mapped type + var r8 = __rest(union_generic, []); // Error, union with generic type parameter + var r9 = __rest(union_primitive, []); // Error, union with generic type parameter + var r10 = __rest(intersection_generic, []); // Error, intersection with generic type parameter + var r11 = __rest(intersection_primitive, []); // Error, intersection with generic type parameter + var r12 = __rest(num, []); // Error + var r13 = __rest(str, []); // Error + var r14 = __rest(u, []); // error, undefined-only not allowed + var r15 = __rest(n, []); // error, null-only not allowed + var r16 = __rest(a, []); // OK + var r17 = __rest(literal_string, []); // Error + var r18 = __rest(literal_number, []); // Error + var r19 = __rest(e, []); // Error, enum } diff --git a/testdata/baselines/reference/submodule/compiler/restInvalidArgumentType.js.diff b/testdata/baselines/reference/submodule/compiler/restInvalidArgumentType.js.diff deleted file mode 100644 index 0e7e508172..0000000000 --- a/testdata/baselines/reference/submodule/compiler/restInvalidArgumentType.js.diff +++ /dev/null @@ -1,63 +0,0 @@ ---- old.restInvalidArgumentType.js -+++ new.restInvalidArgumentType.js -@@= skipped -57, +57 lines =@@ - - - //// [restInvalidArgumentType.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - var E; - (function (E) { - E[E["v1"] = 0] = "v1"; -@@= skipped -35, +24 lines =@@ - var u; - var n; - var a; -- var r1 = __rest(p1, []); // Error, generic type paramterre -- var r2 = __rest(p2, []); // OK -- var r3 = __rest(t, []); // Error, generic type paramter -- var r4 = __rest(i, []); // Error, index access -- var r5 = __rest(k, []); // Error, index -- var r6 = __rest(mapped_generic, []); // Error, generic mapped object type -- var r7 = __rest(mapped, []); // OK, non-generic mapped type -- var r8 = __rest(union_generic, []); // Error, union with generic type parameter -- var r9 = __rest(union_primitive, []); // Error, union with generic type parameter -- var r10 = __rest(intersection_generic, []); // Error, intersection with generic type parameter -- var r11 = __rest(intersection_primitive, []); // Error, intersection with generic type parameter -- var r12 = __rest(num, []); // Error -- var r13 = __rest(str, []); // Error -- var r14 = __rest(u, []); // error, undefined-only not allowed -- var r15 = __rest(n, []); // error, null-only not allowed -- var r16 = __rest(a, []); // OK -- var r17 = __rest(literal_string, []); // Error -- var r18 = __rest(literal_number, []); // Error -- var r19 = __rest(e, []); // Error, enum -+ var { ...r1 } = p1; // Error, generic type paramterre -+ var { ...r2 } = p2; // OK -+ var { ...r3 } = t; // Error, generic type paramter -+ var { ...r4 } = i; // Error, index access -+ var { ...r5 } = k; // Error, index -+ var { ...r6 } = mapped_generic; // Error, generic mapped object type -+ var { ...r7 } = mapped; // OK, non-generic mapped type -+ var { ...r8 } = union_generic; // Error, union with generic type parameter -+ var { ...r9 } = union_primitive; // Error, union with generic type parameter -+ var { ...r10 } = intersection_generic; // Error, intersection with generic type parameter -+ var { ...r11 } = intersection_primitive; // Error, intersection with generic type parameter -+ var { ...r12 } = num; // Error -+ var { ...r13 } = str; // Error -+ var { ...r14 } = u; // error, undefined-only not allowed -+ var { ...r15 } = n; // error, null-only not allowed -+ var { ...r16 } = a; // OK -+ var { ...r17 } = literal_string; // Error -+ var { ...r18 } = literal_number; // Error -+ var { ...r19 } = e; // Error, enum - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/restParameterTypeInstantiation.js b/testdata/baselines/reference/submodule/compiler/restParameterTypeInstantiation.js index df67472538..c4e1667691 100644 --- a/testdata/baselines/reference/submodule/compiler/restParameterTypeInstantiation.js +++ b/testdata/baselines/reference/submodule/compiler/restParameterTypeInstantiation.js @@ -16,7 +16,19 @@ const result: number = removeF({ f: '', g: 3 }).g //// [restParameterTypeInstantiation.js] -const removeF = ({ f, ...rest }) => { +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +const removeF = (_a) => { + var { f } = _a, rest = __rest(_a, ["f"]); return rest; }; const result = removeF({ f: '', g: 3 }).g; diff --git a/testdata/baselines/reference/submodule/compiler/restParameterTypeInstantiation.js.diff b/testdata/baselines/reference/submodule/compiler/restParameterTypeInstantiation.js.diff index f2ddee1231..26c08689c4 100644 --- a/testdata/baselines/reference/submodule/compiler/restParameterTypeInstantiation.js.diff +++ b/testdata/baselines/reference/submodule/compiler/restParameterTypeInstantiation.js.diff @@ -6,20 +6,6 @@ //// [restParameterTypeInstantiation.js] -"use strict"; -// Repro from #33823 --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --const removeF = (_a) => { -- var { f } = _a, rest = __rest(_a, ["f"]); -+const removeF = ({ f, ...rest }) => { - return rest; - }; - const result = removeF({ f: '', g: 3 }).g; \ No newline at end of file + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern3.js b/testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern3.js index c0c04883f4..f1ca72cc7c 100644 --- a/testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern3.js +++ b/testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern3.js @@ -12,8 +12,19 @@ function d(...[a, , , d]: [boolean, string, number]) { } function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { } //// [restParameterWithBindingPattern3.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; function a(...[a = 1, b = true]) { } function b(...[...foo = []]) { } function c(...{ 0: a, length, 3: d }) { } function d(...[a, , , d]) { } -function e(...{ 0: a = 1, 1: b = true, ...rest: rest }) { } +function e(..._a) { var { 0: a = 1, 1: b = true } = _a, rest = __rest(_a, ["0", "1"]); } diff --git a/testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern3.js.diff b/testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern3.js.diff deleted file mode 100644 index c38d335161..0000000000 --- a/testdata/baselines/reference/submodule/compiler/restParameterWithBindingPattern3.js.diff +++ /dev/null @@ -1,23 +0,0 @@ ---- old.restParameterWithBindingPattern3.js -+++ new.restParameterWithBindingPattern3.js -@@= skipped -11, +11 lines =@@ - function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { } - - //// [restParameterWithBindingPattern3.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - function a(...[a = 1, b = true]) { } - function b(...[...foo = []]) { } - function c(...{ 0: a, length, 3: d }) { } - function d(...[a, , , d]) { } --function e(..._a) { var { 0: a = 1, 1: b = true } = _a, rest = __rest(_a, ["0", "1"]); } -+function e(...{ 0: a = 1, 1: b = true, ...rest: rest }) { } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/restUnion.js b/testdata/baselines/reference/submodule/compiler/restUnion.js index 3da6bea53d..1db3baf064 100644 --- a/testdata/baselines/reference/submodule/compiler/restUnion.js +++ b/testdata/baselines/reference/submodule/compiler/restUnion.js @@ -18,12 +18,23 @@ var {n, ...rest3 } = nullUnion; //// [restUnion.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; var union; var rest1; -var { a, ...rest1 } = union; +var { a } = union, rest1 = __rest(union, ["a"]); var undefinedUnion; var rest2; -var { n, ...rest2 } = undefinedUnion; +var { n } = undefinedUnion, rest2 = __rest(undefinedUnion, ["n"]); var nullUnion; var rest3; -var { n, ...rest3 } = nullUnion; +var { n } = nullUnion, rest3 = __rest(nullUnion, ["n"]); diff --git a/testdata/baselines/reference/submodule/compiler/restUnion.js.diff b/testdata/baselines/reference/submodule/compiler/restUnion.js.diff deleted file mode 100644 index 2d7635e9e2..0000000000 --- a/testdata/baselines/reference/submodule/compiler/restUnion.js.diff +++ /dev/null @@ -1,29 +0,0 @@ ---- old.restUnion.js -+++ new.restUnion.js -@@= skipped -17, +17 lines =@@ - - - //// [restUnion.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - var union; - var rest1; --var { a } = union, rest1 = __rest(union, ["a"]); -+var { a, ...rest1 } = union; - var undefinedUnion; - var rest2; --var { n } = undefinedUnion, rest2 = __rest(undefinedUnion, ["n"]); -+var { n, ...rest2 } = undefinedUnion; - var nullUnion; - var rest3; --var { n } = nullUnion, rest3 = __rest(nullUnion, ["n"]); -+var { n, ...rest3 } = nullUnion; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/restUnion2.js b/testdata/baselines/reference/submodule/compiler/restUnion2.js index bbf995987c..0fe7e0ff8c 100644 --- a/testdata/baselines/reference/submodule/compiler/restUnion2.js +++ b/testdata/baselines/reference/submodule/compiler/restUnion2.js @@ -12,7 +12,18 @@ var {...rest3 } = nullUnion; //// [restUnion2.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; var rest2; -var { ...rest2 } = undefinedUnion; +var rest2 = __rest(undefinedUnion, []); var rest3; -var { ...rest3 } = nullUnion; +var rest3 = __rest(nullUnion, []); diff --git a/testdata/baselines/reference/submodule/compiler/restUnion2.js.diff b/testdata/baselines/reference/submodule/compiler/restUnion2.js.diff deleted file mode 100644 index a07ef70e3f..0000000000 --- a/testdata/baselines/reference/submodule/compiler/restUnion2.js.diff +++ /dev/null @@ -1,23 +0,0 @@ ---- old.restUnion2.js -+++ new.restUnion2.js -@@= skipped -11, +11 lines =@@ - - - //// [restUnion2.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - var rest2; --var rest2 = __rest(undefinedUnion, []); -+var { ...rest2 } = undefinedUnion; - var rest3; --var rest3 = __rest(nullUnion, []); -+var { ...rest3 } = nullUnion; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/restUnion3.js b/testdata/baselines/reference/submodule/compiler/restUnion3.js index 428ee7bfef..fe689c9f37 100644 --- a/testdata/baselines/reference/submodule/compiler/restUnion3.js +++ b/testdata/baselines/reference/submodule/compiler/restUnion3.js @@ -11,7 +11,18 @@ var {...rest5 } = unionWithIntersection; //// [restUnion3.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; var rest4; -var { ...rest4 } = nullAndUndefinedUnion; +var rest4 = __rest(nullAndUndefinedUnion, []); var rest5; -var { ...rest5 } = unionWithIntersection; +var rest5 = __rest(unionWithIntersection, []); diff --git a/testdata/baselines/reference/submodule/compiler/restUnion3.js.diff b/testdata/baselines/reference/submodule/compiler/restUnion3.js.diff index a620b2c330..6492ea2183 100644 --- a/testdata/baselines/reference/submodule/compiler/restUnion3.js.diff +++ b/testdata/baselines/reference/submodule/compiler/restUnion3.js.diff @@ -5,20 +5,6 @@ //// [restUnion3.js] -"use strict"; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - var rest4; --var rest4 = __rest(nullAndUndefinedUnion, []); -+var { ...rest4 } = nullAndUndefinedUnion; - var rest5; --var rest5 = __rest(unionWithIntersection, []); -+var { ...rest5 } = unionWithIntersection; \ No newline at end of file + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/reverseMappedTypeIntersectionConstraint.js b/testdata/baselines/reference/submodule/compiler/reverseMappedTypeIntersectionConstraint.js index a4df33849f..3d554120f2 100644 --- a/testdata/baselines/reference/submodule/compiler/reverseMappedTypeIntersectionConstraint.js +++ b/testdata/baselines/reference/submodule/compiler/reverseMappedTypeIntersectionConstraint.js @@ -176,6 +176,17 @@ const config2 = createXMachine({ //// [reverseMappedTypeIntersectionConstraint.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; const inferredParams1 = createMachine({ entry: "foo", states: { @@ -226,7 +237,7 @@ function bar(props) { return foo(props); // no error because lack of excess property check by design } foo({ x: 1, y: 'foo' }); -foo({ ...{ x: 1, y: 'foo' } }); // no error because lack of excess property check by design +foo(__assign({ x: 1, y: 'foo' })); // no error because lack of excess property check by design baz({ x: 1 }); baz({ x: 1, z: 123 }); baz({ x: 1, y: 'foo' }); diff --git a/testdata/baselines/reference/submodule/compiler/reverseMappedTypeIntersectionConstraint.js.diff b/testdata/baselines/reference/submodule/compiler/reverseMappedTypeIntersectionConstraint.js.diff index a0a7853dfe..20cc76cba2 100644 --- a/testdata/baselines/reference/submodule/compiler/reverseMappedTypeIntersectionConstraint.js.diff +++ b/testdata/baselines/reference/submodule/compiler/reverseMappedTypeIntersectionConstraint.js.diff @@ -5,26 +5,6 @@ //// [reverseMappedTypeIntersectionConstraint.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - const inferredParams1 = createMachine({ - entry: "foo", - states: { -@@= skipped -62, +50 lines =@@ - return foo(props); // no error because lack of excess property check by design - } - foo({ x: 1, y: 'foo' }); --foo(__assign({ x: 1, y: 'foo' })); // no error because lack of excess property check by design -+foo({ ...{ x: 1, y: 'foo' } }); // no error because lack of excess property check by design - baz({ x: 1 }); - baz({ x: 1, z: 123 }); - baz({ x: 1, y: 'foo' }); \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualType.js b/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualType.js index 70564dc52b..eccdd2b694 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualType.js +++ b/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualType.js @@ -22,11 +22,22 @@ function test2(item: T): T { //// [spreadExpressionContextualType.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; function test(item) { - return { ...item }; + return __assign({}, item); } function test2(item) { - const x = { ...item }; + const x = __assign({}, item); return x; } diff --git a/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualType.js.diff b/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualType.js.diff index 1ee6411e98..297a601b0f 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualType.js.diff +++ b/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualType.js.diff @@ -6,26 +6,10 @@ //// [spreadExpressionContextualType.js] -"use strict"; -// Repro from #43966 --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - function test(item) { -- return __assign({}, item); -+ return { ...item }; - } - function test2(item) { -- const x = __assign({}, item); -+ const x = { ...item }; - return x; - } + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -23, +21 lines =@@ //// [spreadExpressionContextualType.d.ts] diff --git a/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualTypeWithNamespace.js b/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualTypeWithNamespace.js index d6c07da97e..132ae598ca 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualTypeWithNamespace.js +++ b/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualTypeWithNamespace.js @@ -50,6 +50,17 @@ exports.obj = obj; function exportedDirectly() { } //// [spreadExpressionContextualTypeWithNamespace_1.js] "use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; Object.defineProperty(exports, "__esModule", { value: true }); const stuff = require("./spreadExpressionContextualTypeWithNamespace_0"); stuff.func; @@ -57,7 +68,7 @@ stuff.klass; stuff.obj; stuff.exportedDirectly; function getStuff() { - const thing = { ...stuff }; + const thing = __assign({}, stuff); thing.func; thing.klass; thing.obj; diff --git a/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualTypeWithNamespace.js.diff b/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualTypeWithNamespace.js.diff index 7f7ca40767..e22623ce91 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualTypeWithNamespace.js.diff +++ b/testdata/baselines/reference/submodule/compiler/spreadExpressionContextualTypeWithNamespace.js.diff @@ -13,31 +13,12 @@ function func() { } class klass { } -@@= skipped -14, +14 lines =@@ - function exportedDirectly() { } - //// [spreadExpressionContextualTypeWithNamespace_1.js] - "use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; +@@= skipped -26, +26 lines =@@ + return __assign.apply(this, arguments); + }; Object.defineProperty(exports, "__esModule", { value: true }); -var stuff = require("./spreadExpressionContextualTypeWithNamespace_0"); +const stuff = require("./spreadExpressionContextualTypeWithNamespace_0"); stuff.func; stuff.klass; - stuff.obj; - stuff.exportedDirectly; - function getStuff() { -- const thing = __assign({}, stuff); -+ const thing = { ...stuff }; - thing.func; - thing.klass; - thing.obj; \ No newline at end of file + stuff.obj; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/spreadIdenticalTypesRemoved.js b/testdata/baselines/reference/submodule/compiler/spreadIdenticalTypesRemoved.js index 65992c8402..2880b86ff3 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadIdenticalTypesRemoved.js +++ b/testdata/baselines/reference/submodule/compiler/spreadIdenticalTypesRemoved.js @@ -30,16 +30,20 @@ function billOwner(pet: Animal2) { //// [spreadIdenticalTypesRemoved.js] -function clonePet(pet, fullCopy) { - return { - name: pet.name, - kind: pet.kind, - ...(fullCopy && pet), +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; }; + return __assign.apply(this, arguments); +}; +function clonePet(pet, fullCopy) { + return __assign({ name: pet.name, kind: pet.kind }, (fullCopy && pet)); } function billOwner(pet) { - return { - ...(pet.owner && pet), - paid: false - }; + return __assign(__assign({}, (pet.owner && pet)), { paid: false }); } diff --git a/testdata/baselines/reference/submodule/compiler/spreadIdenticalTypesRemoved.js.diff b/testdata/baselines/reference/submodule/compiler/spreadIdenticalTypesRemoved.js.diff index 2998959eb3..cd4ba40d2e 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadIdenticalTypesRemoved.js.diff +++ b/testdata/baselines/reference/submodule/compiler/spreadIdenticalTypesRemoved.js.diff @@ -5,29 +5,6 @@ //// [spreadIdenticalTypesRemoved.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - function clonePet(pet, fullCopy) { -- return __assign({ name: pet.name, kind: pet.kind }, (fullCopy && pet)); -+ return { -+ name: pet.name, -+ kind: pet.kind, -+ ...(fullCopy && pet), -+ }; - } - function billOwner(pet) { -- return __assign(__assign({}, (pet.owner && pet)), { paid: false }); -+ return { -+ ...(pet.owner && pet), -+ paid: false -+ }; - } \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/spreadIntersection.js b/testdata/baselines/reference/submodule/compiler/spreadIntersection.js index 42a7282418..fe2bcebcef 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadIntersection.js +++ b/testdata/baselines/reference/submodule/compiler/spreadIntersection.js @@ -10,8 +10,19 @@ var o2: { a: number, b: string, c: boolean }; var o2 = { ...intersection, c: false }; //// [spreadIntersection.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; var intersection; var o1; -var o1 = { ...intersection }; +var o1 = __assign({}, intersection); var o2; -var o2 = { ...intersection, c: false }; +var o2 = __assign(__assign({}, intersection), { c: false }); diff --git a/testdata/baselines/reference/submodule/compiler/spreadIntersection.js.diff b/testdata/baselines/reference/submodule/compiler/spreadIntersection.js.diff deleted file mode 100644 index 4bfc3a269d..0000000000 --- a/testdata/baselines/reference/submodule/compiler/spreadIntersection.js.diff +++ /dev/null @@ -1,24 +0,0 @@ ---- old.spreadIntersection.js -+++ new.spreadIntersection.js -@@= skipped -9, +9 lines =@@ - var o2 = { ...intersection, c: false }; - - //// [spreadIntersection.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - var intersection; - var o1; --var o1 = __assign({}, intersection); -+var o1 = { ...intersection }; - var o2; --var o2 = __assign(__assign({}, intersection), { c: false }); -+var o2 = { ...intersection, c: false }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/spreadInvalidArgumentType.js b/testdata/baselines/reference/submodule/compiler/spreadInvalidArgumentType.js index d3bcda4bf1..9bb5ccfb95 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadInvalidArgumentType.js +++ b/testdata/baselines/reference/submodule/compiler/spreadInvalidArgumentType.js @@ -60,6 +60,17 @@ function f(p1: T, p2: T[]) { //// [spreadInvalidArgumentType.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; var E; (function (E) { E[E["v1"] = 0] = "v1"; @@ -84,23 +95,23 @@ function f(p1, p2) { var n; var a; var e; - var o1 = { ...p1 }; // OK, generic type paramterre - var o2 = { ...p2 }; // OK - var o3 = { ...t }; // OK, generic type paramter - var o4 = { ...i }; // Error, index access - var o5 = { ...k }; // Error, index - var o6 = { ...mapped_generic }; // OK, generic mapped object type - var o7 = { ...mapped }; // OK, non-generic mapped type - var o8 = { ...union_generic }; // OK, union with generic type parameter - var o9 = { ...union_primitive }; // Error, union with generic type parameter - var o10 = { ...intersection_generic }; // OK, intersection with generic type parameter - var o11 = { ...intersection_primitive }; // Error, intersection with generic type parameter - var o12 = { ...num }; // Error - var o13 = { ...str }; // Error - var o14 = { ...u }; // error, undefined-only not allowed - var o15 = { ...n }; // error, null-only not allowed - var o16 = { ...a }; // OK - var o17 = { ...literal_string }; // Error - var o18 = { ...literal_number }; // Error - var o19 = { ...e }; // Error, enum + var o1 = __assign({}, p1); // OK, generic type paramterre + var o2 = __assign({}, p2); // OK + var o3 = __assign({}, t); // OK, generic type paramter + var o4 = __assign({}, i); // Error, index access + var o5 = __assign({}, k); // Error, index + var o6 = __assign({}, mapped_generic); // OK, generic mapped object type + var o7 = __assign({}, mapped); // OK, non-generic mapped type + var o8 = __assign({}, union_generic); // OK, union with generic type parameter + var o9 = __assign({}, union_primitive); // Error, union with generic type parameter + var o10 = __assign({}, intersection_generic); // OK, intersection with generic type parameter + var o11 = __assign({}, intersection_primitive); // Error, intersection with generic type parameter + var o12 = __assign({}, num); // Error + var o13 = __assign({}, str); // Error + var o14 = __assign({}, u); // error, undefined-only not allowed + var o15 = __assign({}, n); // error, null-only not allowed + var o16 = __assign({}, a); // OK + var o17 = __assign({}, literal_string); // Error + var o18 = __assign({}, literal_number); // Error + var o19 = __assign({}, e); // Error, enum } diff --git a/testdata/baselines/reference/submodule/compiler/spreadInvalidArgumentType.js.diff b/testdata/baselines/reference/submodule/compiler/spreadInvalidArgumentType.js.diff deleted file mode 100644 index 59fec8dcb8..0000000000 --- a/testdata/baselines/reference/submodule/compiler/spreadInvalidArgumentType.js.diff +++ /dev/null @@ -1,63 +0,0 @@ ---- old.spreadInvalidArgumentType.js -+++ new.spreadInvalidArgumentType.js -@@= skipped -59, +59 lines =@@ - - - //// [spreadInvalidArgumentType.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - var E; - (function (E) { - E[E["v1"] = 0] = "v1"; -@@= skipped -35, +24 lines =@@ - var n; - var a; - var e; -- var o1 = __assign({}, p1); // OK, generic type paramterre -- var o2 = __assign({}, p2); // OK -- var o3 = __assign({}, t); // OK, generic type paramter -- var o4 = __assign({}, i); // Error, index access -- var o5 = __assign({}, k); // Error, index -- var o6 = __assign({}, mapped_generic); // OK, generic mapped object type -- var o7 = __assign({}, mapped); // OK, non-generic mapped type -- var o8 = __assign({}, union_generic); // OK, union with generic type parameter -- var o9 = __assign({}, union_primitive); // Error, union with generic type parameter -- var o10 = __assign({}, intersection_generic); // OK, intersection with generic type parameter -- var o11 = __assign({}, intersection_primitive); // Error, intersection with generic type parameter -- var o12 = __assign({}, num); // Error -- var o13 = __assign({}, str); // Error -- var o14 = __assign({}, u); // error, undefined-only not allowed -- var o15 = __assign({}, n); // error, null-only not allowed -- var o16 = __assign({}, a); // OK -- var o17 = __assign({}, literal_string); // Error -- var o18 = __assign({}, literal_number); // Error -- var o19 = __assign({}, e); // Error, enum -+ var o1 = { ...p1 }; // OK, generic type paramterre -+ var o2 = { ...p2 }; // OK -+ var o3 = { ...t }; // OK, generic type paramter -+ var o4 = { ...i }; // Error, index access -+ var o5 = { ...k }; // Error, index -+ var o6 = { ...mapped_generic }; // OK, generic mapped object type -+ var o7 = { ...mapped }; // OK, non-generic mapped type -+ var o8 = { ...union_generic }; // OK, union with generic type parameter -+ var o9 = { ...union_primitive }; // Error, union with generic type parameter -+ var o10 = { ...intersection_generic }; // OK, intersection with generic type parameter -+ var o11 = { ...intersection_primitive }; // Error, intersection with generic type parameter -+ var o12 = { ...num }; // Error -+ var o13 = { ...str }; // Error -+ var o14 = { ...u }; // error, undefined-only not allowed -+ var o15 = { ...n }; // error, null-only not allowed -+ var o16 = { ...a }; // OK -+ var o17 = { ...literal_string }; // Error -+ var o18 = { ...literal_number }; // Error -+ var o19 = { ...e }; // Error, enum - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=false).js b/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=false).js index b241800756..007c8b3ce6 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=false).js +++ b/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=false).js @@ -23,18 +23,29 @@ const v_cba = { ...c, ...b, ...a }; //// [spreadObjectPermutations.js] -const v_a = { ...a }; -const v_b = { ...b }; -const v_c = { ...c }; -const v_ab = { ...a, ...b }; -const v_ac = { ...a, ...c }; -const v_ba = { ...b, ...a }; -const v_bc = { ...b, ...c }; -const v_ca = { ...c, ...a }; -const v_cb = { ...c, ...b }; -const v_abc = { ...a, ...b, ...c }; -const v_acb = { ...a, ...c, ...b }; -const v_bac = { ...b, ...a, ...c }; -const v_bca = { ...b, ...c, ...a }; -const v_cab = { ...c, ...a, ...b }; -const v_cba = { ...c, ...b, ...a }; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +const v_a = __assign({}, a); +const v_b = __assign({}, b); +const v_c = __assign({}, c); +const v_ab = __assign(__assign({}, a), b); +const v_ac = __assign(__assign({}, a), c); +const v_ba = __assign(__assign({}, b), a); +const v_bc = __assign(__assign({}, b), c); +const v_ca = __assign(__assign({}, c), a); +const v_cb = __assign(__assign({}, c), b); +const v_abc = __assign(__assign(__assign({}, a), b), c); +const v_acb = __assign(__assign(__assign({}, a), c), b); +const v_bac = __assign(__assign(__assign({}, b), a), c); +const v_bca = __assign(__assign(__assign({}, b), c), a); +const v_cab = __assign(__assign(__assign({}, c), a), b); +const v_cba = __assign(__assign(__assign({}, c), b), a); diff --git a/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=false).js.diff b/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=false).js.diff index b518577919..21f4da0cfd 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=false).js.diff +++ b/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=false).js.diff @@ -5,44 +5,6 @@ //// [spreadObjectPermutations.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --const v_a = __assign({}, a); --const v_b = __assign({}, b); --const v_c = __assign({}, c); --const v_ab = __assign(__assign({}, a), b); --const v_ac = __assign(__assign({}, a), c); --const v_ba = __assign(__assign({}, b), a); --const v_bc = __assign(__assign({}, b), c); --const v_ca = __assign(__assign({}, c), a); --const v_cb = __assign(__assign({}, c), b); --const v_abc = __assign(__assign(__assign({}, a), b), c); --const v_acb = __assign(__assign(__assign({}, a), c), b); --const v_bac = __assign(__assign(__assign({}, b), a), c); --const v_bca = __assign(__assign(__assign({}, b), c), a); --const v_cab = __assign(__assign(__assign({}, c), a), b); --const v_cba = __assign(__assign(__assign({}, c), b), a); -+const v_a = { ...a }; -+const v_b = { ...b }; -+const v_c = { ...c }; -+const v_ab = { ...a, ...b }; -+const v_ac = { ...a, ...c }; -+const v_ba = { ...b, ...a }; -+const v_bc = { ...b, ...c }; -+const v_ca = { ...c, ...a }; -+const v_cb = { ...c, ...b }; -+const v_abc = { ...a, ...b, ...c }; -+const v_acb = { ...a, ...c, ...b }; -+const v_bac = { ...b, ...a, ...c }; -+const v_bca = { ...b, ...c, ...a }; -+const v_cab = { ...c, ...a, ...b }; -+const v_cba = { ...c, ...b, ...a }; \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=true).js b/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=true).js index b241800756..007c8b3ce6 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=true).js +++ b/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=true).js @@ -23,18 +23,29 @@ const v_cba = { ...c, ...b, ...a }; //// [spreadObjectPermutations.js] -const v_a = { ...a }; -const v_b = { ...b }; -const v_c = { ...c }; -const v_ab = { ...a, ...b }; -const v_ac = { ...a, ...c }; -const v_ba = { ...b, ...a }; -const v_bc = { ...b, ...c }; -const v_ca = { ...c, ...a }; -const v_cb = { ...c, ...b }; -const v_abc = { ...a, ...b, ...c }; -const v_acb = { ...a, ...c, ...b }; -const v_bac = { ...b, ...a, ...c }; -const v_bca = { ...b, ...c, ...a }; -const v_cab = { ...c, ...a, ...b }; -const v_cba = { ...c, ...b, ...a }; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +const v_a = __assign({}, a); +const v_b = __assign({}, b); +const v_c = __assign({}, c); +const v_ab = __assign(__assign({}, a), b); +const v_ac = __assign(__assign({}, a), c); +const v_ba = __assign(__assign({}, b), a); +const v_bc = __assign(__assign({}, b), c); +const v_ca = __assign(__assign({}, c), a); +const v_cb = __assign(__assign({}, c), b); +const v_abc = __assign(__assign(__assign({}, a), b), c); +const v_acb = __assign(__assign(__assign({}, a), c), b); +const v_bac = __assign(__assign(__assign({}, b), a), c); +const v_bca = __assign(__assign(__assign({}, b), c), a); +const v_cab = __assign(__assign(__assign({}, c), a), b); +const v_cba = __assign(__assign(__assign({}, c), b), a); diff --git a/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=true).js.diff b/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=true).js.diff index fe474b2286..c1aa0c03fd 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=true).js.diff +++ b/testdata/baselines/reference/submodule/compiler/spreadObjectPermutations(exactoptionalpropertytypes=true).js.diff @@ -5,44 +5,6 @@ //// [spreadObjectPermutations.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --const v_a = __assign({}, a); --const v_b = __assign({}, b); --const v_c = __assign({}, c); --const v_ab = __assign(__assign({}, a), b); --const v_ac = __assign(__assign({}, a), c); --const v_ba = __assign(__assign({}, b), a); --const v_bc = __assign(__assign({}, b), c); --const v_ca = __assign(__assign({}, c), a); --const v_cb = __assign(__assign({}, c), b); --const v_abc = __assign(__assign(__assign({}, a), b), c); --const v_acb = __assign(__assign(__assign({}, a), c), b); --const v_bac = __assign(__assign(__assign({}, b), a), c); --const v_bca = __assign(__assign(__assign({}, b), c), a); --const v_cab = __assign(__assign(__assign({}, c), a), b); --const v_cba = __assign(__assign(__assign({}, c), b), a); -+const v_a = { ...a }; -+const v_b = { ...b }; -+const v_c = { ...c }; -+const v_ab = { ...a, ...b }; -+const v_ac = { ...a, ...c }; -+const v_ba = { ...b, ...a }; -+const v_bc = { ...b, ...c }; -+const v_ca = { ...c, ...a }; -+const v_cb = { ...c, ...b }; -+const v_abc = { ...a, ...b, ...c }; -+const v_acb = { ...a, ...c, ...b }; -+const v_bac = { ...b, ...a, ...c }; -+const v_bca = { ...b, ...c, ...a }; -+const v_cab = { ...c, ...a, ...b }; -+const v_cba = { ...c, ...b, ...a }; \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.js b/testdata/baselines/reference/submodule/compiler/spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.js index 02cdbd2b9f..9b84763c4e 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.js +++ b/testdata/baselines/reference/submodule/compiler/spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.js @@ -5,4 +5,15 @@ declare const m: { [k: string]: string }; const x: { [k: string]: string } = { ...m, ["a" + "b"]: "" }; //// [spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.js] -const x = { ...m, ["a" + "b"]: "" }; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +const x = __assign(__assign({}, m), { ["a" + "b"]: "" }); diff --git a/testdata/baselines/reference/submodule/compiler/spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.js.diff b/testdata/baselines/reference/submodule/compiler/spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.js.diff index c364819ca5..a7dfd2502e 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.js.diff +++ b/testdata/baselines/reference/submodule/compiler/spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.js.diff @@ -5,16 +5,6 @@ //// [spreadObjectWithIndexDoesNotAddUndefinedToLocalIndex.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --const x = __assign(__assign({}, m), { ["a" + "b"]: "" }); -+const x = { ...m, ["a" + "b"]: "" }; \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/spreadOfObjectLiteralAssignableToIndexSignature.js b/testdata/baselines/reference/submodule/compiler/spreadOfObjectLiteralAssignableToIndexSignature.js index e4771792e7..00189bc1a5 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadOfObjectLiteralAssignableToIndexSignature.js +++ b/testdata/baselines/reference/submodule/compiler/spreadOfObjectLiteralAssignableToIndexSignature.js @@ -16,12 +16,23 @@ recordsOfRecordsOrEmpty.propB = {...(foo && {foo})} // OK recordsOfRecordsOrEmpty.propC = {...(foo !== undefined && {foo})} // OK //// [spreadOfObjectLiteralAssignableToIndexSignature.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; const foo = {}; // OK const recordOfRecords = {}; -recordOfRecords.propA = { ...(foo !== undefined ? { foo } : {}) }; // OK -recordOfRecords.propB = { ...(foo && { foo }) }; // OK -recordOfRecords.propC = { ...(foo !== undefined && { foo }) }; // error'd in 3.7 beta, should be OK +recordOfRecords.propA = __assign({}, (foo !== undefined ? { foo } : {})); // OK +recordOfRecords.propB = __assign({}, (foo && { foo })); // OK +recordOfRecords.propC = __assign({}, (foo !== undefined && { foo })); // error'd in 3.7 beta, should be OK const recordsOfRecordsOrEmpty = {}; -recordsOfRecordsOrEmpty.propA = { ...(foo !== undefined ? { foo } : {}) }; // OK -recordsOfRecordsOrEmpty.propB = { ...(foo && { foo }) }; // OK -recordsOfRecordsOrEmpty.propC = { ...(foo !== undefined && { foo }) }; // OK +recordsOfRecordsOrEmpty.propA = __assign({}, (foo !== undefined ? { foo } : {})); // OK +recordsOfRecordsOrEmpty.propB = __assign({}, (foo && { foo })); // OK +recordsOfRecordsOrEmpty.propC = __assign({}, (foo !== undefined && { foo })); // OK diff --git a/testdata/baselines/reference/submodule/compiler/spreadOfObjectLiteralAssignableToIndexSignature.js.diff b/testdata/baselines/reference/submodule/compiler/spreadOfObjectLiteralAssignableToIndexSignature.js.diff index ecec11317b..633ab531b4 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadOfObjectLiteralAssignableToIndexSignature.js.diff +++ b/testdata/baselines/reference/submodule/compiler/spreadOfObjectLiteralAssignableToIndexSignature.js.diff @@ -5,29 +5,6 @@ //// [spreadOfObjectLiteralAssignableToIndexSignature.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - const foo = {}; // OK - const recordOfRecords = {}; --recordOfRecords.propA = __assign({}, (foo !== undefined ? { foo } : {})); // OK --recordOfRecords.propB = __assign({}, (foo && { foo })); // OK --recordOfRecords.propC = __assign({}, (foo !== undefined && { foo })); // error'd in 3.7 beta, should be OK -+recordOfRecords.propA = { ...(foo !== undefined ? { foo } : {}) }; // OK -+recordOfRecords.propB = { ...(foo && { foo }) }; // OK -+recordOfRecords.propC = { ...(foo !== undefined && { foo }) }; // error'd in 3.7 beta, should be OK - const recordsOfRecordsOrEmpty = {}; --recordsOfRecordsOrEmpty.propA = __assign({}, (foo !== undefined ? { foo } : {})); // OK --recordsOfRecordsOrEmpty.propB = __assign({}, (foo && { foo })); // OK --recordsOfRecordsOrEmpty.propC = __assign({}, (foo !== undefined && { foo })); // OK -+recordsOfRecordsOrEmpty.propA = { ...(foo !== undefined ? { foo } : {}) }; // OK -+recordsOfRecordsOrEmpty.propB = { ...(foo && { foo }) }; // OK -+recordsOfRecordsOrEmpty.propC = { ...(foo !== undefined && { foo }) }; // OK \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/spreadTypeRemovesReadonly.js b/testdata/baselines/reference/submodule/compiler/spreadTypeRemovesReadonly.js index c30fd57427..5a78509f61 100644 --- a/testdata/baselines/reference/submodule/compiler/spreadTypeRemovesReadonly.js +++ b/testdata/baselines/reference/submodule/compiler/spreadTypeRemovesReadonly.js @@ -11,6 +11,17 @@ clone.value = 'bar'; //// [spreadTypeRemovesReadonly.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; const data = { value: 'foo' }; -const clone = { ...data }; +const clone = __assign({}, data); clone.value = 'bar'; diff --git a/testdata/baselines/reference/submodule/compiler/spreadTypeRemovesReadonly.js.diff b/testdata/baselines/reference/submodule/compiler/spreadTypeRemovesReadonly.js.diff deleted file mode 100644 index 73c93fbaf8..0000000000 --- a/testdata/baselines/reference/submodule/compiler/spreadTypeRemovesReadonly.js.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- old.spreadTypeRemovesReadonly.js -+++ new.spreadTypeRemovesReadonly.js -@@= skipped -10, +10 lines =@@ - - - //// [spreadTypeRemovesReadonly.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - const data = { value: 'foo' }; --const clone = __assign({}, data); -+const clone = { ...data }; - clone.value = 'bar'; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/strictOptionalProperties1.js b/testdata/baselines/reference/submodule/compiler/strictOptionalProperties1.js index c5276fb604..7a29cbdbc8 100644 --- a/testdata/baselines/reference/submodule/compiler/strictOptionalProperties1.js +++ b/testdata/baselines/reference/submodule/compiler/strictOptionalProperties1.js @@ -238,6 +238,17 @@ type UC = UA & UB; // undefined //// [strictOptionalProperties1.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; function f1(obj) { let a = obj.a; // string | undefined let b = obj.b; // string | undefined @@ -318,7 +329,7 @@ function f6() { } const defaultProps = { foo: 'foo' }; const inputProps = { foo: undefined, bar: 'bar' }; -const completeProps = { ...defaultProps, ...inputProps }; +const completeProps = __assign(__assign({}, defaultProps), inputProps); // Example from #13195 const t1 = [1]; const t2 = [1, undefined]; @@ -326,7 +337,7 @@ const t3 = [1, "string", undefined]; const t4 = [1, undefined, undefined]; // Example from #13195 const x = { foo: undefined }; -const y = { foo: 123, ...x }; +const y = __assign({ foo: 123 }, x); f11(ox1); // string f11(ox2); // string | undefined f11(ox3); // string diff --git a/testdata/baselines/reference/submodule/compiler/strictOptionalProperties1.js.diff b/testdata/baselines/reference/submodule/compiler/strictOptionalProperties1.js.diff index e9d39b1de7..7680edf4b3 100644 --- a/testdata/baselines/reference/submodule/compiler/strictOptionalProperties1.js.diff +++ b/testdata/baselines/reference/submodule/compiler/strictOptionalProperties1.js.diff @@ -5,39 +5,10 @@ //// [strictOptionalProperties1.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - function f1(obj) { - let a = obj.a; // string | undefined - let b = obj.b; // string | undefined -@@= skipped -92, +80 lines =@@ - } - const defaultProps = { foo: 'foo' }; - const inputProps = { foo: undefined, bar: 'bar' }; --const completeProps = __assign(__assign({}, defaultProps), inputProps); -+const completeProps = { ...defaultProps, ...inputProps }; - // Example from #13195 - const t1 = [1]; - const t2 = [1, undefined]; -@@= skipped -8, +8 lines =@@ - const t4 = [1, undefined, undefined]; - // Example from #13195 - const x = { foo: undefined }; --const y = __assign({ foo: 123 }, x); -+const y = { foo: 123, ...x }; - f11(ox1); // string - f11(ox2); // string | undefined - f11(ox3); // string -@@= skipped -56, +56 lines =@@ + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -156, +155 lines =@@ declare function f4a(t1: [number, string?], t2: [number, string?, string?]): void; declare function f5(t: [number, string?, boolean?]): void; declare function f6(): void; diff --git a/testdata/baselines/reference/submodule/compiler/taggedTemplateStringsWithCurriedFunction.js b/testdata/baselines/reference/submodule/compiler/taggedTemplateStringsWithCurriedFunction.js index 4a82c416d7..a920b38ccd 100644 --- a/testdata/baselines/reference/submodule/compiler/taggedTemplateStringsWithCurriedFunction.js +++ b/testdata/baselines/reference/submodule/compiler/taggedTemplateStringsWithCurriedFunction.js @@ -13,10 +13,21 @@ f({ x: (() => 1)(), ...{ y: 1 } })``; //// [taggedTemplateStringsWithCurriedFunction.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; // Originated from #38558 const f = _ => (..._) => ""; -f({ ...{ x: 0 } }) ``; -f({ ...{ x: 0 } }) `x`; -f({ ...{ x: 0 } }) `x${f}x`; -f({ ...{ x: 0 }, y: (() => 1)() }) ``; -f({ x: (() => 1)(), ...{ y: 1 } }) ``; +f(__assign({ x: 0 })) ``; +f(__assign({ x: 0 })) `x`; +f(__assign({ x: 0 })) `x${f}x`; +f(__assign({ x: 0 }, { y: (() => 1)() })) ``; +f(__assign({ x: (() => 1)() }, { y: 1 })) ``; diff --git a/testdata/baselines/reference/submodule/compiler/taggedTemplateStringsWithCurriedFunction.js.diff b/testdata/baselines/reference/submodule/compiler/taggedTemplateStringsWithCurriedFunction.js.diff index a5ffa09fd8..b32a21039c 100644 --- a/testdata/baselines/reference/submodule/compiler/taggedTemplateStringsWithCurriedFunction.js.diff +++ b/testdata/baselines/reference/submodule/compiler/taggedTemplateStringsWithCurriedFunction.js.diff @@ -1,28 +1,18 @@ --- old.taggedTemplateStringsWithCurriedFunction.js +++ new.taggedTemplateStringsWithCurriedFunction.js -@@= skipped -13, +13 lines =@@ +@@= skipped -12, +12 lines =@@ + //// [taggedTemplateStringsWithCurriedFunction.js] - // Originated from #38558 --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; +-// Originated from #38558 + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -12, +11 lines =@@ + }; + return __assign.apply(this, arguments); + }; ++// Originated from #38558 const f = _ => (..._) => ""; --f(__assign({ x: 0 })) ``; --f(__assign({ x: 0 })) `x`; --f(__assign({ x: 0 })) `x${f}x`; --f(__assign({ x: 0 }, { y: (() => 1)() })) ``; --f(__assign({ x: (() => 1)() }, { y: 1 })) ``; -+f({ ...{ x: 0 } }) ``; -+f({ ...{ x: 0 } }) `x`; -+f({ ...{ x: 0 } }) `x${f}x`; -+f({ ...{ x: 0 }, y: (() => 1)() }) ``; -+f({ x: (() => 1)(), ...{ y: 1 } }) ``; \ No newline at end of file + f(__assign({ x: 0 })) ``; + f(__assign({ x: 0 })) `x`; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck.js b/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck.js index a6b527086b..457cca76ea 100644 --- a/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck.js +++ b/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck.js @@ -17,14 +17,22 @@ export interface WizardStepProps { //// [trivialSubtypeReductionNoStructuralCheck.js] "use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.Wizard = void 0; class Wizard { get steps() { - return { - wizard: this, - ...props, - }; + return __assign({ wizard: this }, props); } } exports.Wizard = Wizard; diff --git a/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck.js.diff b/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck.js.diff deleted file mode 100644 index 9be419b266..0000000000 --- a/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck.js.diff +++ /dev/null @@ -1,29 +0,0 @@ ---- old.trivialSubtypeReductionNoStructuralCheck.js -+++ new.trivialSubtypeReductionNoStructuralCheck.js -@@= skipped -16, +16 lines =@@ - - //// [trivialSubtypeReductionNoStructuralCheck.js] - "use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - Object.defineProperty(exports, "__esModule", { value: true }); - exports.Wizard = void 0; - class Wizard { - get steps() { -- return __assign({ wizard: this }, props); -+ return { -+ wizard: this, -+ ...props, -+ }; - } - } - exports.Wizard = Wizard; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck2.js b/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck2.js index f3868f3bed..39a5951efb 100644 --- a/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck2.js +++ b/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck2.js @@ -17,14 +17,22 @@ export interface WizardStepProps { //// [trivialSubtypeReductionNoStructuralCheck2.js] "use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.Wizard = void 0; class Wizard { get steps() { - return { - wizard: this, - ...props, - }; + return __assign({ wizard: this }, props); } } exports.Wizard = Wizard; diff --git a/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck2.js.diff b/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck2.js.diff deleted file mode 100644 index d64e1664f2..0000000000 --- a/testdata/baselines/reference/submodule/compiler/trivialSubtypeReductionNoStructuralCheck2.js.diff +++ /dev/null @@ -1,29 +0,0 @@ ---- old.trivialSubtypeReductionNoStructuralCheck2.js -+++ new.trivialSubtypeReductionNoStructuralCheck2.js -@@= skipped -16, +16 lines =@@ - - //// [trivialSubtypeReductionNoStructuralCheck2.js] - "use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - Object.defineProperty(exports, "__esModule", { value: true }); - exports.Wizard = void 0; - class Wizard { - get steps() { -- return __assign({ wizard: this }, props); -+ return { -+ wizard: this, -+ ...props, -+ }; - } - } - exports.Wizard = Wizard; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/tslibMultipleMissingHelper.js b/testdata/baselines/reference/submodule/compiler/tslibMultipleMissingHelper.js index 28e0990c4a..1831cec2e0 100644 --- a/testdata/baselines/reference/submodule/compiler/tslibMultipleMissingHelper.js +++ b/testdata/baselines/reference/submodule/compiler/tslibMultipleMissingHelper.js @@ -50,11 +50,13 @@ async function bar() { } //// [other.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +const tslib_1 = require("tslib"); exports.noop = noop; exports.spread = spread; async function noop() { } -function spread({ a, ...rest }) { - return { c: "c", ...rest }; +function spread(_a) { + var { a } = _a, rest = tslib_1.__rest(_a, ["a"]); + return Object.assign({ c: "c" }, rest); } //// [index.js] "use strict"; diff --git a/testdata/baselines/reference/submodule/compiler/tslibMultipleMissingHelper.js.diff b/testdata/baselines/reference/submodule/compiler/tslibMultipleMissingHelper.js.diff index 18cd9487ff..39c2223b3d 100644 --- a/testdata/baselines/reference/submodule/compiler/tslibMultipleMissingHelper.js.diff +++ b/testdata/baselines/reference/submodule/compiler/tslibMultipleMissingHelper.js.diff @@ -16,19 +16,18 @@ //// [other.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); ++const tslib_1 = require("tslib"); exports.noop = noop; exports.spread = spread; -const tslib_1 = require("tslib"); -function noop() { - return tslib_1.__awaiter(this, void 0, void 0, function* () { }); -} --function spread(_a) { -- var { a } = _a, rest = tslib_1.__rest(_a, ["a"]); -- return Object.assign({ c: "c" }, rest); +async function noop() { } -+function spread({ a, ...rest }) { -+ return { c: "c", ...rest }; - } + function spread(_a) { + var { a } = _a, rest = tslib_1.__rest(_a, ["a"]); + return Object.assign({ c: "c" }, rest); +@@= skipped -23, +16 lines =@@ //// [index.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/testdata/baselines/reference/submodule/compiler/unionExcessPropsWithPartialMember.js b/testdata/baselines/reference/submodule/compiler/unionExcessPropsWithPartialMember.js index 9f378e6123..de6d4eeafa 100644 --- a/testdata/baselines/reference/submodule/compiler/unionExcessPropsWithPartialMember.js +++ b/testdata/baselines/reference/submodule/compiler/unionExcessPropsWithPartialMember.js @@ -18,4 +18,15 @@ ab = {...a, y: (null as any as string | undefined)}; // Should be allowed, since //// [unionExcessPropsWithPartialMember.js] -ab = { ...a, y: null }; // Should be allowed, since `y` is missing on `A` +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +ab = __assign(__assign({}, a), { y: null }); // Should be allowed, since `y` is missing on `A` diff --git a/testdata/baselines/reference/submodule/compiler/unionExcessPropsWithPartialMember.js.diff b/testdata/baselines/reference/submodule/compiler/unionExcessPropsWithPartialMember.js.diff index ce9a93c396..651634dcb6 100644 --- a/testdata/baselines/reference/submodule/compiler/unionExcessPropsWithPartialMember.js.diff +++ b/testdata/baselines/reference/submodule/compiler/unionExcessPropsWithPartialMember.js.diff @@ -5,16 +5,6 @@ //// [unionExcessPropsWithPartialMember.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --ab = __assign(__assign({}, a), { y: null }); // Should be allowed, since `y` is missing on `A` -+ab = { ...a, y: null }; // Should be allowed, since `y` is missing on `A` \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread.js b/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread.js index 7dce1d4b5f..47ba322577 100644 --- a/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread.js +++ b/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread.js @@ -33,27 +33,38 @@ function four() { //// [unusedLocalsAndObjectSpread.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; function one() { const foo = { a: 1, b: 2 }; // 'a' is declared but never used - const { a, ...bar } = foo; + const { a } = foo, bar = __rest(foo, ["a"]); console.log(bar); } function two() { const foo = { a: 1, b: 2 }; // '_' is declared but never used - const { a: _, ...bar } = foo; + const { a: _ } = foo, bar = __rest(foo, ["a"]); console.log(bar); } function three() { const foo = { a: 1, b: 2 }; // 'a' is declared but never used - const { a, ...bar } = foo; // bar should be unused + const { a } = foo, bar = __rest(foo, ["a"]); // bar should be unused //console.log(bar); } function four() { const foo = { a: 1, b: 2 }; // '_' is declared but never used - const { a: _, ...bar } = foo; // bar should be unused + const { a: _ } = foo, bar = __rest(foo, ["a"]); // bar should be unused //console.log(bar); } diff --git a/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread.js.diff b/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread.js.diff deleted file mode 100644 index d9ec9ee880..0000000000 --- a/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread.js.diff +++ /dev/null @@ -1,45 +0,0 @@ ---- old.unusedLocalsAndObjectSpread.js -+++ new.unusedLocalsAndObjectSpread.js -@@= skipped -32, +32 lines =@@ - - - //// [unusedLocalsAndObjectSpread.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - function one() { - const foo = { a: 1, b: 2 }; - // 'a' is declared but never used -- const { a } = foo, bar = __rest(foo, ["a"]); -+ const { a, ...bar } = foo; - console.log(bar); - } - function two() { - const foo = { a: 1, b: 2 }; - // '_' is declared but never used -- const { a: _ } = foo, bar = __rest(foo, ["a"]); -+ const { a: _, ...bar } = foo; - console.log(bar); - } - function three() { - const foo = { a: 1, b: 2 }; - // 'a' is declared but never used -- const { a } = foo, bar = __rest(foo, ["a"]); // bar should be unused -+ const { a, ...bar } = foo; // bar should be unused - //console.log(bar); - } - function four() { - const foo = { a: 1, b: 2 }; - // '_' is declared but never used -- const { a: _ } = foo, bar = __rest(foo, ["a"]); // bar should be unused -+ const { a: _, ...bar } = foo; // bar should be unused - //console.log(bar); - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread2.js b/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread2.js index eee4672de1..743258d13d 100644 --- a/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread2.js +++ b/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread2.js @@ -20,12 +20,23 @@ export const asdf = 123; //// [unusedLocalsAndObjectSpread2.js] "use strict"; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.asdf = void 0; const { children, // here! -active: _a, // here! -...rest } = props; +active: _a } = props, // here! +rest = __rest(props, ["children", "active"]); function foo() { - const { children, active: _a, ...rest } = props; + const { children, active: _a } = props, rest = __rest(props, ["children", "active"]); } exports.asdf = 123; diff --git a/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread2.js.diff b/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread2.js.diff deleted file mode 100644 index 45ea998e18..0000000000 --- a/testdata/baselines/reference/submodule/compiler/unusedLocalsAndObjectSpread2.js.diff +++ /dev/null @@ -1,29 +0,0 @@ ---- old.unusedLocalsAndObjectSpread2.js -+++ new.unusedLocalsAndObjectSpread2.js -@@= skipped -19, +19 lines =@@ - - //// [unusedLocalsAndObjectSpread2.js] - "use strict"; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - Object.defineProperty(exports, "__esModule", { value: true }); - exports.asdf = void 0; - const { children, // here! --active: _a } = props, // here! --rest = __rest(props, ["children", "active"]); -+active: _a, // here! -+...rest } = props; - function foo() { -- const { children, active: _a } = props, rest = __rest(props, ["children", "active"]); -+ const { children, active: _a, ...rest } = props; - } - exports.asdf = 123; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/useBeforeDeclaration_propertyAssignment.js b/testdata/baselines/reference/submodule/compiler/useBeforeDeclaration_propertyAssignment.js index 0648ecbb1a..e8e6baccc4 100644 --- a/testdata/baselines/reference/submodule/compiler/useBeforeDeclaration_propertyAssignment.js +++ b/testdata/baselines/reference/submodule/compiler/useBeforeDeclaration_propertyAssignment.js @@ -21,7 +21,7 @@ class D { //// [useBeforeDeclaration_propertyAssignment.js] export class C { - a = { b: this.b, ...this.c, [this.b]: `${this.c}` }; + a = Object.assign(Object.assign({ b: this.b }, this.c), { [this.b]: `${this.c}` }); b = 0; c = { c: this.b }; } @@ -31,9 +31,7 @@ class D { }; static B = class { }; - static C = { - [D.D]: 1, - ...{ get [D.D]() { return 0; } } // should be an error - }; + static C = Object.assign({ [D.D]: 1 }, { get [D.D]() { return 0; } } // should be an error + ); static D = ''; } diff --git a/testdata/baselines/reference/submodule/compiler/useBeforeDeclaration_propertyAssignment.js.diff b/testdata/baselines/reference/submodule/compiler/useBeforeDeclaration_propertyAssignment.js.diff index 8c17b5bdb4..38d6ab40fe 100644 --- a/testdata/baselines/reference/submodule/compiler/useBeforeDeclaration_propertyAssignment.js.diff +++ b/testdata/baselines/reference/submodule/compiler/useBeforeDeclaration_propertyAssignment.js.diff @@ -9,7 +9,7 @@ - this.b = 0; - this.c = { c: this.b }; - } -+ a = { b: this.b, ...this.c, [this.b]: `${this.c}` }; ++ a = Object.assign(Object.assign({ b: this.b }, this.c), { [this.b]: `${this.c}` }); + b = 0; + c = { c: this.b }; } @@ -19,10 +19,8 @@ + }; + static B = class { + }; -+ static C = { -+ [D.D]: 1, -+ ...{ get [D.D]() { return 0; } } // should be an error -+ }; ++ static C = Object.assign({ [D.D]: 1 }, { get [D.D]() { return 0; } } // should be an error ++ ); + static D = ''; } -D.A = class extends D.B { diff --git a/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2015).js b/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2015).js index 1e72faf417..d229a4f1b5 100644 --- a/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2015).js +++ b/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2015).js @@ -16,5 +16,5 @@ class Sub extends Super { async function* f1(x, y = z) { } async function* f2({ [z]: x }) { } class Sub extends Super { - async *m(x, y = z, { ...w }) { super.foo(); } + async *m(x, y = z, _a) { var w = __rest(_a, []); super.foo(); } } diff --git a/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2015).js.diff b/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2015).js.diff index 5647e533fb..4c159d62b2 100644 --- a/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2015).js.diff +++ b/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2015).js.diff @@ -12,5 +12,5 @@ - m(x_1) { const _super = Object.create(null, { - foo: { get: () => super.foo } - }); return __asyncGenerator(this, arguments, function* m_1(x, y = z, _a) { var w = __rest(_a, []); _super.foo.call(this); }); } -+ async *m(x, y = z, { ...w }) { super.foo(); } ++ async *m(x, y = z, _a) { var w = __rest(_a, []); super.foo(); } } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2017).js b/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2017).js index 1e72faf417..d229a4f1b5 100644 --- a/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2017).js +++ b/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2017).js @@ -16,5 +16,5 @@ class Sub extends Super { async function* f1(x, y = z) { } async function* f2({ [z]: x }) { } class Sub extends Super { - async *m(x, y = z, { ...w }) { super.foo(); } + async *m(x, y = z, _a) { var w = __rest(_a, []); super.foo(); } } diff --git a/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2017).js.diff b/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2017).js.diff index 0a5b1eb920..4323ec12bd 100644 --- a/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2017).js.diff +++ b/testdata/baselines/reference/submodule/conformance/asyncGeneratorParameterEvaluation(target=es2017).js.diff @@ -12,5 +12,5 @@ - m(x_1) { const _super = Object.create(null, { - foo: { get: () => super.foo } - }); return __asyncGenerator(this, arguments, function* m_1(x, y = z, _a) { var w = __rest(_a, []); _super.foo.call(this); }); } -+ async *m(x, y = z, { ...w }) { super.foo(); } ++ async *m(x, y = z, _a) { var w = __rest(_a, []); super.foo(); } } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/asyncWithVarShadowing_es6.js b/testdata/baselines/reference/submodule/conformance/asyncWithVarShadowing_es6.js index 4f047831bf..466b00ef0a 100644 --- a/testdata/baselines/reference/submodule/conformance/asyncWithVarShadowing_es6.js +++ b/testdata/baselines/reference/submodule/conformance/asyncWithVarShadowing_es6.js @@ -256,7 +256,7 @@ async function fn10(x) { var { z: { x } = y } = y; } async function fn11(x) { - var { ...x } = y; + var x = __rest(y, []); } async function fn12(x) { var [x] = y; diff --git a/testdata/baselines/reference/submodule/conformance/asyncWithVarShadowing_es6.js.diff b/testdata/baselines/reference/submodule/conformance/asyncWithVarShadowing_es6.js.diff index ebe3013028..0b4545897f 100644 --- a/testdata/baselines/reference/submodule/conformance/asyncWithVarShadowing_es6.js.diff +++ b/testdata/baselines/reference/submodule/conformance/asyncWithVarShadowing_es6.js.diff @@ -306,7 +306,7 @@ + var { z: { x } = y } = y; +} +async function fn11(x) { -+ var { ...x } = y; ++ var x = __rest(y, []); +} +async function fn12(x) { + var [x] = y; diff --git a/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es2015).js b/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es2015).js index 7e9c09ffef..49607c6b7b 100644 --- a/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es2015).js +++ b/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es2015).js @@ -24,6 +24,17 @@ let [{ ...a }, b = a]: any[] = [{ x: 1 }] //// [destructuringEvaluationOrder.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; // https://github.com/microsoft/TypeScript/issues/39205 let trace = []; let order = (n) => trace.push(n); @@ -34,7 +45,7 @@ let [{ [order(1)]: y } = order(0)] = [{}]; // order(0) should evaluate first (destructuring of object literal {}) // order(1) should evaluate next (initializer because property is undefined) // order(2) should evaluate last (evaluate object binding pattern from initializer) -let { [order(0)]: { [order(2)]: z } = order(1), ...w } = {}; +let _a = {}, _b = order(0), _c = _a[_b], _d = _c === void 0 ? order(1) : _c, _e = order(2), z = _d[_e], w = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); // https://github.com/microsoft/TypeScript/issues/39181 // b = a must occur *after* 'a' has been assigned -let [{ ...a }, b = a] = [{ x: 1 }]; +let [_f, _g] = [{ x: 1 }], a = __rest(_f, []), b = _g === void 0 ? a : _g; diff --git a/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es2015).js.diff b/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es2015).js.diff deleted file mode 100644 index acd90c399f..0000000000 --- a/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es2015).js.diff +++ /dev/null @@ -1,30 +0,0 @@ ---- old.destructuringEvaluationOrder(target=es2015).js -+++ new.destructuringEvaluationOrder(target=es2015).js -@@= skipped -23, +23 lines =@@ - - - //// [destructuringEvaluationOrder.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - // https://github.com/microsoft/TypeScript/issues/39205 - let trace = []; - let order = (n) => trace.push(n); -@@= skipped -21, +10 lines =@@ - // order(0) should evaluate first (destructuring of object literal {}) - // order(1) should evaluate next (initializer because property is undefined) - // order(2) should evaluate last (evaluate object binding pattern from initializer) --let _a = {}, _b = order(0), _c = _a[_b], _d = _c === void 0 ? order(1) : _c, _e = order(2), z = _d[_e], w = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); -+let { [order(0)]: { [order(2)]: z } = order(1), ...w } = {}; - // https://github.com/microsoft/TypeScript/issues/39181 - // b = a must occur *after* 'a' has been assigned --let [_f, _g] = [{ x: 1 }], a = __rest(_f, []), b = _g === void 0 ? a : _g; -+let [{ ...a }, b = a] = [{ x: 1 }]; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es5).js b/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es5).js index 7e9c09ffef..49607c6b7b 100644 --- a/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es5).js +++ b/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es5).js @@ -24,6 +24,17 @@ let [{ ...a }, b = a]: any[] = [{ x: 1 }] //// [destructuringEvaluationOrder.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; // https://github.com/microsoft/TypeScript/issues/39205 let trace = []; let order = (n) => trace.push(n); @@ -34,7 +45,7 @@ let [{ [order(1)]: y } = order(0)] = [{}]; // order(0) should evaluate first (destructuring of object literal {}) // order(1) should evaluate next (initializer because property is undefined) // order(2) should evaluate last (evaluate object binding pattern from initializer) -let { [order(0)]: { [order(2)]: z } = order(1), ...w } = {}; +let _a = {}, _b = order(0), _c = _a[_b], _d = _c === void 0 ? order(1) : _c, _e = order(2), z = _d[_e], w = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); // https://github.com/microsoft/TypeScript/issues/39181 // b = a must occur *after* 'a' has been assigned -let [{ ...a }, b = a] = [{ x: 1 }]; +let [_f, _g] = [{ x: 1 }], a = __rest(_f, []), b = _g === void 0 ? a : _g; diff --git a/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es5).js.diff b/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es5).js.diff deleted file mode 100644 index 6dc6262dbf..0000000000 --- a/testdata/baselines/reference/submodule/conformance/destructuringEvaluationOrder(target=es5).js.diff +++ /dev/null @@ -1,30 +0,0 @@ ---- old.destructuringEvaluationOrder(target=es5).js -+++ new.destructuringEvaluationOrder(target=es5).js -@@= skipped -23, +23 lines =@@ - - - //// [destructuringEvaluationOrder.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - // https://github.com/microsoft/TypeScript/issues/39205 - let trace = []; - let order = (n) => trace.push(n); -@@= skipped -21, +10 lines =@@ - // order(0) should evaluate first (destructuring of object literal {}) - // order(1) should evaluate next (initializer because property is undefined) - // order(2) should evaluate last (evaluate object binding pattern from initializer) --let _a = {}, _b = order(0), _c = _a[_b], _d = _c === void 0 ? order(1) : _c, _e = order(2), z = _d[_e], w = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); -+let { [order(0)]: { [order(2)]: z } = order(1), ...w } = {}; - // https://github.com/microsoft/TypeScript/issues/39181 - // b = a must occur *after* 'a' has been assigned --let [_f, _g] = [{ x: 1 }], a = __rest(_f, []), b = _g === void 0 ? a : _g; -+let [{ ...a }, b = a] = [{ x: 1 }]; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es2015).js b/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es2015).js index 8c3eb60281..1ab05a9a55 100644 --- a/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es2015).js +++ b/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es2015).js @@ -6,5 +6,17 @@ let a: any, b: any, c: any = {x: {a: 1, y: 2}}, d: any; //// [destructuringObjectAssignmentPatternWithNestedSpread.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a, _b; let a, b, c = { x: { a: 1, y: 2 } }, d; -({ x: { a, ...b } = d } = c); +(_a = c.x, _b = _a === void 0 ? d : _a, { a } = _b, b = __rest(_b, ["a"])); diff --git a/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es2015).js.diff b/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es2015).js.diff deleted file mode 100644 index 038f6198ba..0000000000 --- a/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es2015).js.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- old.destructuringObjectAssignmentPatternWithNestedSpread(target=es2015).js -+++ new.destructuringObjectAssignmentPatternWithNestedSpread(target=es2015).js -@@= skipped -5, +5 lines =@@ - - - //// [destructuringObjectAssignmentPatternWithNestedSpread.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --var _a, _b; - let a, b, c = { x: { a: 1, y: 2 } }, d; --(_a = c.x, _b = _a === void 0 ? d : _a, { a } = _b, b = __rest(_b, ["a"])); -+({ x: { a, ...b } = d } = c); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es5).js b/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es5).js index 8c3eb60281..1ab05a9a55 100644 --- a/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es5).js +++ b/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es5).js @@ -6,5 +6,17 @@ let a: any, b: any, c: any = {x: {a: 1, y: 2}}, d: any; //// [destructuringObjectAssignmentPatternWithNestedSpread.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a, _b; let a, b, c = { x: { a: 1, y: 2 } }, d; -({ x: { a, ...b } = d } = c); +(_a = c.x, _b = _a === void 0 ? d : _a, { a } = _b, b = __rest(_b, ["a"])); diff --git a/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es5).js.diff b/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es5).js.diff deleted file mode 100644 index fce95fe5c0..0000000000 --- a/testdata/baselines/reference/submodule/conformance/destructuringObjectAssignmentPatternWithNestedSpread(target=es5).js.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- old.destructuringObjectAssignmentPatternWithNestedSpread(target=es5).js -+++ new.destructuringObjectAssignmentPatternWithNestedSpread(target=es5).js -@@= skipped -5, +5 lines =@@ - - - //// [destructuringObjectAssignmentPatternWithNestedSpread.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --var _a, _b; - let a, b, c = { x: { a: 1, y: 2 } }, d; --(_a = c.x, _b = _a === void 0 ? d : _a, { a } = _b, b = __rest(_b, ["a"])); -+({ x: { a, ...b } = d } = c); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/destructuringObjectBindingPatternAndAssignment5.js b/testdata/baselines/reference/submodule/conformance/destructuringObjectBindingPatternAndAssignment5.js index c9577028b5..c96d4b7009 100644 --- a/testdata/baselines/reference/submodule/conformance/destructuringObjectBindingPatternAndAssignment5.js +++ b/testdata/baselines/reference/submodule/conformance/destructuringObjectBindingPatternAndAssignment5.js @@ -9,8 +9,20 @@ function a () { //// [destructuringObjectBindingPatternAndAssignment5.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; function a() { + var _a; let x; let y; - ({ x, ...y } = {}); + (_a = {}, { x } = _a, y = __rest(_a, ["x"])); } diff --git a/testdata/baselines/reference/submodule/conformance/destructuringObjectBindingPatternAndAssignment5.js.diff b/testdata/baselines/reference/submodule/conformance/destructuringObjectBindingPatternAndAssignment5.js.diff deleted file mode 100644 index 8565cd5a06..0000000000 --- a/testdata/baselines/reference/submodule/conformance/destructuringObjectBindingPatternAndAssignment5.js.diff +++ /dev/null @@ -1,24 +0,0 @@ ---- old.destructuringObjectBindingPatternAndAssignment5.js -+++ new.destructuringObjectBindingPatternAndAssignment5.js -@@= skipped -8, +8 lines =@@ - - - //// [destructuringObjectBindingPatternAndAssignment5.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - function a() { -- var _a; - let x; - let y; -- (_a = {}, { x } = _a, y = __rest(_a, ["x"])); -+ ({ x, ...y } = {}); - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/destructuringSpread.js b/testdata/baselines/reference/submodule/conformance/destructuringSpread.js index 18cd727ac9..c27b19a244 100644 --- a/testdata/baselines/reference/submodule/conformance/destructuringSpread.js +++ b/testdata/baselines/reference/submodule/conformance/destructuringSpread.js @@ -31,27 +31,20 @@ const { c, d, e, f, g } = { //// [destructuringSpread.js] -const { x } = { - ...{}, - x: 0 -}; -const { y } = { - y: 0, - ...{} -}; -const { z, a, b } = { - z: 0, - ...{ a: 0, b: 0 } -}; -const { c, d, e, f, g } = { - ...{ - ...{ - ...{ - c: 0, - }, - d: 0 - }, - e: 0 - }, - f: 0 +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); }; +const { x } = __assign({}, { x: 0 }); +const { y } = __assign({ y: 0 }, {}); +const { z, a, b } = __assign({ z: 0 }, { a: 0, b: 0 }); +const { c, d, e, f, g } = __assign(__assign({}, __assign(__assign({}, __assign({ + c: 0, +}, { d: 0 })), { e: 0 })), { f: 0 }); diff --git a/testdata/baselines/reference/submodule/conformance/destructuringSpread.js.diff b/testdata/baselines/reference/submodule/conformance/destructuringSpread.js.diff deleted file mode 100644 index 91cb8c7d84..0000000000 --- a/testdata/baselines/reference/submodule/conformance/destructuringSpread.js.diff +++ /dev/null @@ -1,47 +0,0 @@ ---- old.destructuringSpread.js -+++ new.destructuringSpread.js -@@= skipped -30, +30 lines =@@ - - - //// [destructuringSpread.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --const { x } = __assign({}, { x: 0 }); --const { y } = __assign({ y: 0 }, {}); --const { z, a, b } = __assign({ z: 0 }, { a: 0, b: 0 }); --const { c, d, e, f, g } = __assign(__assign({}, __assign(__assign({}, __assign({ -- c: 0, --}, { d: 0 })), { e: 0 })), { f: 0 }); -+const { x } = { -+ ...{}, -+ x: 0 -+}; -+const { y } = { -+ y: 0, -+ ...{} -+}; -+const { z, a, b } = { -+ z: 0, -+ ...{ a: 0, b: 0 } -+}; -+const { c, d, e, f, g } = { -+ ...{ -+ ...{ -+ ...{ -+ c: 0, -+ }, -+ d: 0 -+ }, -+ e: 0 -+ }, -+ f: 0 -+}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/elementAccessChain.3.js b/testdata/baselines/reference/submodule/conformance/elementAccessChain.3.js index b3c183b138..0185a342a4 100644 --- a/testdata/baselines/reference/submodule/conformance/elementAccessChain.3.js +++ b/testdata/baselines/reference/submodule/conformance/elementAccessChain.3.js @@ -32,6 +32,18 @@ for (obj?.a["b"] of []); //// [elementAccessChain.3.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a, _b; (obj === null || obj === void 0 ? void 0 : obj["a"])++; (obj === null || obj === void 0 ? void 0 : obj.a["b"])++; (obj === null || obj === void 0 ? void 0 : obj["a"])--; @@ -54,7 +66,7 @@ for (obj === null || obj === void 0 ? void 0 : obj.a["b"] of []) ; ({ a: obj === null || obj === void 0 ? void 0 : obj["a"] } = { a: 1 }); ({ a: obj === null || obj === void 0 ? void 0 : obj.a["b"] } = { a: 1 }); -({ ...obj === null || obj === void 0 ? void 0 : obj["a"] } = { a: 1 }); -({ ...obj === null || obj === void 0 ? void 0 : obj.a["b"] } = { a: 1 }); +(_a = { a: 1 }, (obj === null || obj === void 0 ? void 0 : obj["a"]) = __rest(_a, [])); +(_b = { a: 1 }, (obj === null || obj === void 0 ? void 0 : obj.a["b"]) = __rest(_b, [])); [...obj === null || obj === void 0 ? void 0 : obj["a"]] = []; [...obj === null || obj === void 0 ? void 0 : obj.a["b"]] = []; diff --git a/testdata/baselines/reference/submodule/conformance/elementAccessChain.3.js.diff b/testdata/baselines/reference/submodule/conformance/elementAccessChain.3.js.diff index bb01ed2cc2..cb9656718f 100644 --- a/testdata/baselines/reference/submodule/conformance/elementAccessChain.3.js.diff +++ b/testdata/baselines/reference/submodule/conformance/elementAccessChain.3.js.diff @@ -5,21 +5,18 @@ //// [elementAccessChain.3.js] -"use strict"; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) +@@= skipped -12, +11 lines =@@ + } + return t; + }; ++var _a, _b; (obj === null || obj === void 0 ? void 0 : obj["a"])++; (obj === null || obj === void 0 ? void 0 : obj.a["b"])++; (obj === null || obj === void 0 ? void 0 : obj["a"])--; -@@= skipped -20, +8 lines =@@ +@@= skipped -8, +9 lines =@@ ++(obj === null || obj === void 0 ? void 0 : obj.a["b"]); --(obj === null || obj === void 0 ? void 0 : obj["a"]); --(obj === null || obj === void 0 ? void 0 : obj.a["b"]); @@ -40,7 +37,7 @@ ({ a: obj === null || obj === void 0 ? void 0 : obj.a["b"] } = { a: 1 }); -(obj === null || obj === void 0 ? void 0 : obj["a"] = __rest({ a: 1 }, [])); -(obj === null || obj === void 0 ? void 0 : obj.a["b"] = __rest({ a: 1 }, [])); -+({ ...obj === null || obj === void 0 ? void 0 : obj["a"] } = { a: 1 }); -+({ ...obj === null || obj === void 0 ? void 0 : obj.a["b"] } = { a: 1 }); ++(_a = { a: 1 }, (obj === null || obj === void 0 ? void 0 : obj["a"]) = __rest(_a, [])); ++(_b = { a: 1 }, (obj === null || obj === void 0 ? void 0 : obj.a["b"]) = __rest(_b, [])); [...obj === null || obj === void 0 ? void 0 : obj["a"]] = []; [...obj === null || obj === void 0 ? void 0 : obj.a["b"]] = []; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/functionParameterObjectRestAndInitializers.js b/testdata/baselines/reference/submodule/conformance/functionParameterObjectRestAndInitializers.js index 32755117c4..c0231ba210 100644 --- a/testdata/baselines/reference/submodule/conformance/functionParameterObjectRestAndInitializers.js +++ b/testdata/baselines/reference/submodule/conformance/functionParameterObjectRestAndInitializers.js @@ -13,10 +13,25 @@ function g({a, ...x}, b = ({a}, b = a) => {}) { //// [functionParameterObjectRestAndInitializers.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; // https://github.com/microsoft/TypeScript/issues/47079 -function f({ a, ...x }, b = a) { +function f(_a, b) { + var { a } = _a, x = __rest(_a, ["a"]); + if (b === void 0) { b = a; } return b; } -function g({ a, ...x }, b = ({ a }, b = a) => { }) { +function g(_a, b) { + var { a } = _a, x = __rest(_a, ["a"]); + if (b === void 0) { b = ({ a }, b = a) => { }; } return b; } diff --git a/testdata/baselines/reference/submodule/conformance/functionParameterObjectRestAndInitializers.js.diff b/testdata/baselines/reference/submodule/conformance/functionParameterObjectRestAndInitializers.js.diff index 9329a5ae61..ec747a5711 100644 --- a/testdata/baselines/reference/submodule/conformance/functionParameterObjectRestAndInitializers.js.diff +++ b/testdata/baselines/reference/submodule/conformance/functionParameterObjectRestAndInitializers.js.diff @@ -1,29 +1,18 @@ --- old.functionParameterObjectRestAndInitializers.js +++ new.functionParameterObjectRestAndInitializers.js -@@= skipped -13, +13 lines =@@ +@@= skipped -12, +12 lines =@@ + //// [functionParameterObjectRestAndInitializers.js] - // https://github.com/microsoft/TypeScript/issues/47079 --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --function f(_a, b) { -- var { a } = _a, x = __rest(_a, ["a"]); -- if (b === void 0) { b = a; } -+function f({ a, ...x }, b = a) { - return b; - } --function g(_a, b) { -- var { a } = _a, x = __rest(_a, ["a"]); -- if (b === void 0) { b = ({ a }, b = a) => { }; } -+function g({ a, ...x }, b = ({ a }, b = a) => { }) { - return b; - } \ No newline at end of file +-// https://github.com/microsoft/TypeScript/issues/47079 + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) +@@= skipped -12, +11 lines =@@ + } + return t; + }; ++// https://github.com/microsoft/TypeScript/issues/47079 + function f(_a, b) { + var { a } = _a, x = __rest(_a, ["a"]); + if (b === void 0) { b = a; } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/genericObjectRest.js b/testdata/baselines/reference/submodule/conformance/genericObjectRest.js index 43d6eaa0b1..4c7703eb1e 100644 --- a/testdata/baselines/reference/submodule/conformance/genericObjectRest.js +++ b/testdata/baselines/reference/submodule/conformance/genericObjectRest.js @@ -31,23 +31,34 @@ function f4(obj: Item, k1: K1, k2: //// [genericObjectRest.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; const a = 'a'; function f1(obj) { - let { ...r0 } = obj; - let { a: a1, ...r1 } = obj; - let { a: a2, b: b2, ...r2 } = obj; - let { 'a': a3, ...r3 } = obj; - let { ['a']: a4, ...r4 } = obj; - let { [a]: a5, ...r5 } = obj; + let r0 = __rest(obj, []); + let { a: a1 } = obj, r1 = __rest(obj, ["a"]); + let { a: a2, b: b2 } = obj, r2 = __rest(obj, ["a", "b"]); + let { 'a': a3 } = obj, r3 = __rest(obj, ['a']); + let { ['a']: a4 } = obj, r4 = __rest(obj, ['a']); + let _a = obj, _b = a, a5 = _a[_b], r5 = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); } const sa = Symbol(); const sb = Symbol(); function f2(obj) { - let { [sa]: a1, [sb]: b1, ...r1 } = obj; + let _a = obj, _b = sa, a1 = _a[_b], _c = sb, b1 = _a[_c], r1 = __rest(_a, [typeof _b === "symbol" ? _b : _b + "", typeof _c === "symbol" ? _c : _c + ""]); } function f3(obj, k1, k2) { - let { [k1]: a1, [k2]: a2, ...r1 } = obj; + let _a = obj, _b = k1, a1 = _a[_b], _c = k2, a2 = _a[_c], r1 = __rest(_a, [typeof _b === "symbol" ? _b : _b + "", typeof _c === "symbol" ? _c : _c + ""]); } function f4(obj, k1, k2) { - let { [k1]: a1, [k2]: a2, ...r1 } = obj; + let _a = obj, _b = k1, a1 = _a[_b], _c = k2, a2 = _a[_c], r1 = __rest(_a, [typeof _b === "symbol" ? _b : _b + "", typeof _c === "symbol" ? _c : _c + ""]); } diff --git a/testdata/baselines/reference/submodule/conformance/genericObjectRest.js.diff b/testdata/baselines/reference/submodule/conformance/genericObjectRest.js.diff index 850db6fbab..8ac5ef17d1 100644 --- a/testdata/baselines/reference/submodule/conformance/genericObjectRest.js.diff +++ b/testdata/baselines/reference/submodule/conformance/genericObjectRest.js.diff @@ -5,43 +5,6 @@ //// [genericObjectRest.js] -"use strict"; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - const a = 'a'; - function f1(obj) { -- let r0 = __rest(obj, []); -- let { a: a1 } = obj, r1 = __rest(obj, ["a"]); -- let { a: a2, b: b2 } = obj, r2 = __rest(obj, ["a", "b"]); -- let { 'a': a3 } = obj, r3 = __rest(obj, ['a']); -- let { ['a']: a4 } = obj, r4 = __rest(obj, ['a']); -- let _a = obj, _b = a, a5 = _a[_b], r5 = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); -+ let { ...r0 } = obj; -+ let { a: a1, ...r1 } = obj; -+ let { a: a2, b: b2, ...r2 } = obj; -+ let { 'a': a3, ...r3 } = obj; -+ let { ['a']: a4, ...r4 } = obj; -+ let { [a]: a5, ...r5 } = obj; - } - const sa = Symbol(); - const sb = Symbol(); - function f2(obj) { -- let _a = obj, _b = sa, a1 = _a[_b], _c = sb, b1 = _a[_c], r1 = __rest(_a, [typeof _b === "symbol" ? _b : _b + "", typeof _c === "symbol" ? _c : _c + ""]); -+ let { [sa]: a1, [sb]: b1, ...r1 } = obj; - } - function f3(obj, k1, k2) { -- let _a = obj, _b = k1, a1 = _a[_b], _c = k2, a2 = _a[_c], r1 = __rest(_a, [typeof _b === "symbol" ? _b : _b + "", typeof _c === "symbol" ? _c : _c + ""]); -+ let { [k1]: a1, [k2]: a2, ...r1 } = obj; - } - function f4(obj, k1, k2) { -- let _a = obj, _b = k1, a1 = _a[_b], _c = k2, a2 = _a[_c], r1 = __rest(_a, [typeof _b === "symbol" ? _b : _b + "", typeof _c === "symbol" ? _c : _c + ""]); -+ let { [k1]: a1, [k2]: a2, ...r1 } = obj; - } \ No newline at end of file + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/intraExpressionInferences.js b/testdata/baselines/reference/submodule/conformance/intraExpressionInferences.js index 09be27c991..843e24d2e5 100644 --- a/testdata/baselines/reference/submodule/conformance/intraExpressionInferences.js +++ b/testdata/baselines/reference/submodule/conformance/intraExpressionInferences.js @@ -334,6 +334,17 @@ const distantRes = distant({ //// [intraExpressionInferences.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; callIt({ produce: () => 0, consume: n => n.toFixed() @@ -446,14 +457,12 @@ branch({ let test1 = u; } }); -Foo({ - ...{ - a: (x) => 10, - b: (arg) => { - arg.toString(); - }, +Foo(__assign({ + a: (x) => 10, + b: (arg) => { + arg.toString(); }, -}); +})); const resNested = nested({ prop: { produce: (a) => [a], diff --git a/testdata/baselines/reference/submodule/conformance/intraExpressionInferences.js.diff b/testdata/baselines/reference/submodule/conformance/intraExpressionInferences.js.diff index 0d88f32d8f..a0543b05b7 100644 --- a/testdata/baselines/reference/submodule/conformance/intraExpressionInferences.js.diff +++ b/testdata/baselines/reference/submodule/conformance/intraExpressionInferences.js.diff @@ -6,21 +6,10 @@ //// [intraExpressionInferences.js] -"use strict"; -// Repros from #47599 --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - callIt({ - produce: () => 0, - consume: n => n.toFixed() -@@= skipped -71, +58 lines =@@ + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -71, +69 lines =@@ }); // Repro from #41712 class Wrapper { @@ -28,27 +17,7 @@ } createMappingComponent({ setup() { -@@= skipped -53, +54 lines =@@ - let test1 = u; - } - }); --Foo(__assign({ -- a: (x) => 10, -- b: (arg) => { -- arg.toString(); -+Foo({ -+ ...{ -+ a: (x) => 10, -+ b: (arg) => { -+ arg.toString(); -+ }, - }, --})); -+}); - const resNested = nested({ - prop: { - produce: (a) => [a], -@@= skipped -60, +62 lines =@@ +@@= skipped -113, +114 lines =@@ //// [intraExpressionInferences.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/literalTypeWidening.js b/testdata/baselines/reference/submodule/conformance/literalTypeWidening.js index 42075bd00f..4946011c78 100644 --- a/testdata/baselines/reference/submodule/conformance/literalTypeWidening.js +++ b/testdata/baselines/reference/submodule/conformance/literalTypeWidening.js @@ -148,6 +148,28 @@ const b: E.A = a; //// [literalTypeWidening.js] "use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.langCodes = void 0; exports.Set = Set; @@ -248,8 +270,8 @@ exports.langCodes = keys(langCodeSet); const arr = exports.langCodes.map(code => ({ code })); // Repro from #29081 function test(obj) { - let { a, ...rest } = obj; - return { a: 'hello', ...rest }; + let { a } = obj, rest = __rest(obj, ["a"]); + return __assign({ a: 'hello' }, rest); } var E; (function (E) { diff --git a/testdata/baselines/reference/submodule/conformance/literalTypeWidening.js.diff b/testdata/baselines/reference/submodule/conformance/literalTypeWidening.js.diff index fb82c3d92f..3a211fb855 100644 --- a/testdata/baselines/reference/submodule/conformance/literalTypeWidening.js.diff +++ b/testdata/baselines/reference/submodule/conformance/literalTypeWidening.js.diff @@ -5,44 +5,14 @@ //// [literalTypeWidening.js] "use strict"; -// Widening vs. non-widening literal types --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - Object.defineProperty(exports, "__esModule", { value: true }); + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -27, +26 lines =@@ exports.langCodes = void 0; exports.Set = Set; exports.keys = keys; +// Widening vs. non-widening literal types function f1() { const c1 = "hello"; // Widening type "hello" - let v1 = c1; // Type string -@@= skipped -122, +100 lines =@@ - const arr = exports.langCodes.map(code => ({ code })); - // Repro from #29081 - function test(obj) { -- let { a } = obj, rest = __rest(obj, ["a"]); -- return __assign({ a: 'hello' }, rest); -+ let { a, ...rest } = obj; -+ return { a: 'hello', ...rest }; - } - var E; - (function (E) { \ No newline at end of file + let v1 = c1; // Type string \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/mappedTypeConstraints.js b/testdata/baselines/reference/submodule/conformance/mappedTypeConstraints.js index 6e49fd3f2a..140904df30 100644 --- a/testdata/baselines/reference/submodule/conformance/mappedTypeConstraints.js +++ b/testdata/baselines/reference/submodule/conformance/mappedTypeConstraints.js @@ -38,6 +38,17 @@ const modifier = (targetProps: T) => { //// [mappedTypeConstraints.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; function f0(obj) { obj.b; } @@ -57,6 +68,6 @@ function f4(obj) { obj.c; } const modifier = (targetProps) => { - let { bar, ...rest } = targetProps; + let { bar } = targetProps, rest = __rest(targetProps, ["bar"]); rest.foo; }; diff --git a/testdata/baselines/reference/submodule/conformance/mappedTypeConstraints.js.diff b/testdata/baselines/reference/submodule/conformance/mappedTypeConstraints.js.diff index 991a6baa2e..c9c010b016 100644 --- a/testdata/baselines/reference/submodule/conformance/mappedTypeConstraints.js.diff +++ b/testdata/baselines/reference/submodule/conformance/mappedTypeConstraints.js.diff @@ -5,25 +5,6 @@ //// [mappedTypeConstraints.js] -"use strict"; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - function f0(obj) { - obj.b; - } -@@= skipped -31, +19 lines =@@ - obj.c; - } - const modifier = (targetProps) => { -- let { bar } = targetProps, rest = __rest(targetProps, ["bar"]); -+ let { bar, ...rest } = targetProps; - rest.foo; - }; \ No newline at end of file + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/noUncheckedIndexedAccessDestructuring.js b/testdata/baselines/reference/submodule/conformance/noUncheckedIndexedAccessDestructuring.js index 27ab87d3bd..765f31f6b0 100644 --- a/testdata/baselines/reference/submodule/conformance/noUncheckedIndexedAccessDestructuring.js +++ b/testdata/baselines/reference/submodule/conformance/noUncheckedIndexedAccessDestructuring.js @@ -76,6 +76,17 @@ declare let target_string_arr: string[]; //// [noUncheckedIndexedAccessDestructuring.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; // Declaration forms for array destructuring // Destructuring from a simple array -> include undefined const [s1] = strArray; @@ -88,7 +99,7 @@ const [, , ...s3] = strArray; s3.push(undefined); // Should error, 'undefined' not part of s2's element type const { t1 } = strMap; t1.toString(); // Should error, t1 possibly undefined -const { ...t2 } = strMap; +const t2 = __rest(strMap, []); t2.z.toString(); // Should error { const { x, y, z } = numMapPoint; @@ -97,13 +108,13 @@ t2.z.toString(); // Should error z.toFixed(); // Should error } { - const { x, ...q } = numMapPoint; + const { x } = numMapPoint, q = __rest(numMapPoint, ["x"]); x.toFixed(); // Should OK q.y.toFixed(); // Should OK q.z.toFixed(); // Should error } { - const { x, ...q } = numMapPoint; + const { x } = numMapPoint, q = __rest(numMapPoint, ["x"]); x. toFixed(); // Should OK q. diff --git a/testdata/baselines/reference/submodule/conformance/noUncheckedIndexedAccessDestructuring.js.diff b/testdata/baselines/reference/submodule/conformance/noUncheckedIndexedAccessDestructuring.js.diff index 452a90e272..a21197fd26 100644 --- a/testdata/baselines/reference/submodule/conformance/noUncheckedIndexedAccessDestructuring.js.diff +++ b/testdata/baselines/reference/submodule/conformance/noUncheckedIndexedAccessDestructuring.js.diff @@ -5,42 +5,6 @@ //// [noUncheckedIndexedAccessDestructuring.js] -"use strict"; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - // Declaration forms for array destructuring - // Destructuring from a simple array -> include undefined - const [s1] = strArray; -@@= skipped -24, +12 lines =@@ - s3.push(undefined); // Should error, 'undefined' not part of s2's element type - const { t1 } = strMap; - t1.toString(); // Should error, t1 possibly undefined --const t2 = __rest(strMap, []); -+const { ...t2 } = strMap; - t2.z.toString(); // Should error - { - const { x, y, z } = numMapPoint; -@@= skipped -9, +9 lines =@@ - z.toFixed(); // Should error - } - { -- const { x } = numMapPoint, q = __rest(numMapPoint, ["x"]); -+ const { x, ...q } = numMapPoint; - x.toFixed(); // Should OK - q.y.toFixed(); // Should OK - q.z.toFixed(); // Should error - } - { -- const { x } = numMapPoint, q = __rest(numMapPoint, ["x"]); -+ const { x, ...q } = numMapPoint; - x. - toFixed(); // Should OK - q. \ No newline at end of file + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nonPrimitiveAccessProperty.js b/testdata/baselines/reference/submodule/conformance/nonPrimitiveAccessProperty.js index 2b1798b515..edb595eec6 100644 --- a/testdata/baselines/reference/submodule/conformance/nonPrimitiveAccessProperty.js +++ b/testdata/baselines/reference/submodule/conformance/nonPrimitiveAccessProperty.js @@ -10,8 +10,19 @@ var { ...rest } = a; // ok //// [nonPrimitiveAccessProperty.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; var a; a.toString(); a.nonExist(); // error var { destructuring } = a; // error -var { ...rest } = a; // ok +var rest = __rest(a, []); // ok diff --git a/testdata/baselines/reference/submodule/conformance/nonPrimitiveAccessProperty.js.diff b/testdata/baselines/reference/submodule/conformance/nonPrimitiveAccessProperty.js.diff deleted file mode 100644 index f275ac7879..0000000000 --- a/testdata/baselines/reference/submodule/conformance/nonPrimitiveAccessProperty.js.diff +++ /dev/null @@ -1,23 +0,0 @@ ---- old.nonPrimitiveAccessProperty.js -+++ new.nonPrimitiveAccessProperty.js -@@= skipped -9, +9 lines =@@ - - - //// [nonPrimitiveAccessProperty.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - var a; - a.toString(); - a.nonExist(); // error - var { destructuring } = a; // error --var rest = __rest(a, []); // ok -+var { ...rest } = a; // ok \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectLiteralNormalization.js b/testdata/baselines/reference/submodule/conformance/objectLiteralNormalization.js index 7c014e4f41..d84e8bb11b 100644 --- a/testdata/baselines/reference/submodule/conformance/objectLiteralNormalization.js +++ b/testdata/baselines/reference/submodule/conformance/objectLiteralNormalization.js @@ -53,6 +53,17 @@ let e4 = f({ a: 2 }, data); //// [objectLiteralNormalization.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; // Object literals in unions are normalized upon widening let a1 = [{ a: 0 }, { a: 1, b: "x" }, { a: 2, b: "y", c: true }][0]; a1.a; // number @@ -70,8 +81,8 @@ a2 = { a: "def" }; a2 = {}; a2 = { a: "def", b: 20 }; // Error a2 = { a: 1 }; // Error -let b2 = { ...b1, z: 55 }; -let b3 = { ...b2 }; +let b2 = __assign(__assign({}, b1), { z: 55 }); +let b3 = __assign({}, b2); let c1 = !true ? {} : opts; let c2 = !true ? opts : {}; let c3 = !true ? { a: 0, b: 0 } : {}; diff --git a/testdata/baselines/reference/submodule/conformance/objectLiteralNormalization.js.diff b/testdata/baselines/reference/submodule/conformance/objectLiteralNormalization.js.diff index b8ac7aff8f..3680df2e6d 100644 --- a/testdata/baselines/reference/submodule/conformance/objectLiteralNormalization.js.diff +++ b/testdata/baselines/reference/submodule/conformance/objectLiteralNormalization.js.diff @@ -5,32 +5,10 @@ //// [objectLiteralNormalization.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - // Object literals in unions are normalized upon widening - let a1 = [{ a: 0 }, { a: 1, b: "x" }, { a: 2, b: "y", c: true }][0]; - a1.a; // number -@@= skipped -29, +17 lines =@@ - a2 = {}; - a2 = { a: "def", b: 20 }; // Error - a2 = { a: 1 }; // Error --let b2 = __assign(__assign({}, b1), { z: 55 }); --let b3 = __assign({}, b2); -+let b2 = { ...b1, z: 55 }; -+let b3 = { ...b2 }; - let c1 = !true ? {} : opts; - let c2 = !true ? opts : {}; - let c3 = !true ? { a: 0, b: 0 } : {}; -@@= skipped -22, +22 lines =@@ + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -51, +50 lines =@@ //// [objectLiteralNormalization.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/objectRest.js b/testdata/baselines/reference/submodule/conformance/objectRest.js index d1171c241d..0d444b7cc1 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRest.js +++ b/testdata/baselines/reference/submodule/conformance/objectRest.js @@ -50,22 +50,34 @@ var noContextualType = ({ aNumber = 12, ...notEmptyObject }) => aNumber + notEmp //// [objectRest.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a, _b, _c, _d, _e; var o = { a: 1, b: 'no' }; -var { ...clone } = o; -var { a, ...justB } = o; -var { a, b: renamed, ...empty } = o; -var { ['b']: renamed, ...justA } = o; -var { 'b': renamed, ...justA } = o; -var { b: { '0': n, '1': oooo }, ...justA } = o; +var clone = __rest(o, []); +var { a } = o, justB = __rest(o, ["a"]); +var { a, b: renamed } = o, empty = __rest(o, ["a", "b"]); +var { ['b']: renamed } = o, justA = __rest(o, ['b']); +var { 'b': renamed } = o, justA = __rest(o, ['b']); +var { b: { '0': n, '1': oooo } } = o, justA = __rest(o, ["b"]); let o2 = { c: 'terrible idea?', d: 'yes' }; -var { d: renamed, ...d } = o2; +var { d: renamed } = o2, d = __rest(o2, ["d"]); let nestedrest; -var { x, n1: { y, n2: { z, n3: { ...nr } } }, ...restrest } = nestedrest; +var { x } = nestedrest, _f = nestedrest.n1, { y } = _f, _g = _f.n2, { z } = _g, nr = __rest(_g.n3, []), restrest = __rest(nestedrest, ["x", "n1"]); let complex; -var { x: { ka, ...nested }, y: other, ...rest } = complex; -({ x: { ka, ...nested }, y: other, ...rest } = complex); -var { x, ...fresh } = { x: 1, y: 2 }; -({ x, ...fresh } = { x: 1, y: 2 }); +var _h = complex.x, { ka } = _h, nested = __rest(_h, ["ka"]), { y: other } = complex, rest = __rest(complex, ["x", "y"]); +(_a = complex.x, { ka } = _a, nested = __rest(_a, ["ka"]), { y: other } = complex, rest = __rest(complex, ["x", "y"])); +var _j = { x: 1, y: 2 }, { x } = _j, fresh = __rest(_j, ["x"]); +(_b = { x: 1, y: 2 }, { x } = _b, fresh = __rest(_b, ["x"])); class Removable { x; y; @@ -77,11 +89,14 @@ class Removable { remainder; } var removable = new Removable(); -var { removed, ...removableRest } = removable; +var { removed } = removable, removableRest = __rest(removable, ["removed"]); var i = removable; -var { removed, ...removableRest2 } = i; +var { removed } = i, removableRest2 = __rest(i, ["removed"]); let computed = 'b'; let computed2 = 'a'; -var { [computed]: stillNotGreat, [computed2]: soSo, ...o } = o; -({ [computed]: stillNotGreat, [computed2]: soSo, ...o } = o); -var noContextualType = ({ aNumber = 12, ...notEmptyObject }) => aNumber + notEmptyObject.anythingGoes; +var _k = o, _l = computed, stillNotGreat = _k[_l], _m = computed2, soSo = _k[_m], o = __rest(_k, [typeof _l === "symbol" ? _l : _l + "", typeof _m === "symbol" ? _m : _m + ""]); +(_c = o, _d = computed, stillNotGreat = _c[_d], _e = computed2, soSo = _c[_e], o = __rest(_c, [typeof _d === "symbol" ? _d : _d + "", typeof _e === "symbol" ? _e : _e + ""])); +var noContextualType = (_a) => { + var { aNumber = 12 } = _a, notEmptyObject = __rest(_a, ["aNumber"]); + return aNumber + notEmptyObject.anythingGoes; +}; diff --git a/testdata/baselines/reference/submodule/conformance/objectRest.js.diff b/testdata/baselines/reference/submodule/conformance/objectRest.js.diff index 904414e84a..2a5bce6435 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRest.js.diff +++ b/testdata/baselines/reference/submodule/conformance/objectRest.js.diff @@ -1,49 +1,8 @@ --- old.objectRest.js +++ new.objectRest.js -@@= skipped -49, +49 lines =@@ - - - //// [objectRest.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --var _a, _b, _c, _d, _e; - var o = { a: 1, b: 'no' }; --var clone = __rest(o, []); --var { a } = o, justB = __rest(o, ["a"]); --var { a, b: renamed } = o, empty = __rest(o, ["a", "b"]); --var { ['b']: renamed } = o, justA = __rest(o, ['b']); --var { 'b': renamed } = o, justA = __rest(o, ['b']); --var { b: { '0': n, '1': oooo } } = o, justA = __rest(o, ["b"]); -+var { ...clone } = o; -+var { a, ...justB } = o; -+var { a, b: renamed, ...empty } = o; -+var { ['b']: renamed, ...justA } = o; -+var { 'b': renamed, ...justA } = o; -+var { b: { '0': n, '1': oooo }, ...justA } = o; - let o2 = { c: 'terrible idea?', d: 'yes' }; --var { d: renamed } = o2, d = __rest(o2, ["d"]); -+var { d: renamed, ...d } = o2; - let nestedrest; --var { x } = nestedrest, _f = nestedrest.n1, { y } = _f, _g = _f.n2, { z } = _g, nr = __rest(_g.n3, []), restrest = __rest(nestedrest, ["x", "n1"]); -+var { x, n1: { y, n2: { z, n3: { ...nr } } }, ...restrest } = nestedrest; - let complex; --var _h = complex.x, { ka } = _h, nested = __rest(_h, ["ka"]), { y: other } = complex, rest = __rest(complex, ["x", "y"]); --(_a = complex.x, { ka } = _a, nested = __rest(_a, ["ka"]), { y: other } = complex, rest = __rest(complex, ["x", "y"])); --var _j = { x: 1, y: 2 }, { x } = _j, fresh = __rest(_j, ["x"]); --(_b = { x: 1, y: 2 }, { x } = _b, fresh = __rest(_b, ["x"])); -+var { x: { ka, ...nested }, y: other, ...rest } = complex; -+({ x: { ka, ...nested }, y: other, ...rest } = complex); -+var { x, ...fresh } = { x: 1, y: 2 }; -+({ x, ...fresh } = { x: 1, y: 2 }); +@@= skipped -78, +78 lines =@@ + var _j = { x: 1, y: 2 }, { x } = _j, fresh = __rest(_j, ["x"]); + (_b = { x: 1, y: 2 }, { x } = _b, fresh = __rest(_b, ["x"])); class Removable { + x; + y; @@ -55,19 +14,4 @@ + remainder; } var removable = new Removable(); --var { removed } = removable, removableRest = __rest(removable, ["removed"]); -+var { removed, ...removableRest } = removable; - var i = removable; --var { removed } = i, removableRest2 = __rest(i, ["removed"]); -+var { removed, ...removableRest2 } = i; - let computed = 'b'; - let computed2 = 'a'; --var _k = o, _l = computed, stillNotGreat = _k[_l], _m = computed2, soSo = _k[_m], o = __rest(_k, [typeof _l === "symbol" ? _l : _l + "", typeof _m === "symbol" ? _m : _m + ""]); --(_c = o, _d = computed, stillNotGreat = _c[_d], _e = computed2, soSo = _c[_e], o = __rest(_c, [typeof _d === "symbol" ? _d : _d + "", typeof _e === "symbol" ? _e : _e + ""])); --var noContextualType = (_a) => { -- var { aNumber = 12 } = _a, notEmptyObject = __rest(_a, ["aNumber"]); -- return aNumber + notEmptyObject.anythingGoes; --}; -+var { [computed]: stillNotGreat, [computed2]: soSo, ...o } = o; -+({ [computed]: stillNotGreat, [computed2]: soSo, ...o } = o); -+var noContextualType = ({ aNumber = 12, ...notEmptyObject }) => aNumber + notEmptyObject.anythingGoes; \ No newline at end of file + var { removed } = removable, removableRest = __rest(removable, ["removed"]); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectRest2.js b/testdata/baselines/reference/submodule/conformance/objectRest2.js index 2832355ae1..a95ea5fcd8 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRest2.js +++ b/testdata/baselines/reference/submodule/conformance/objectRest2.js @@ -21,9 +21,7 @@ function rootConnection(name) { return { resolve: async (context, args) => { const { objects } = await { objects: 12 }; - return { - ...connectionFromArray(objects, args) - }; + return Object.assign({}, connectionFromArray(objects, args)); } }; } diff --git a/testdata/baselines/reference/submodule/conformance/objectRest2.js.diff b/testdata/baselines/reference/submodule/conformance/objectRest2.js.diff index 64b8c77bf7..d0682b9dc2 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRest2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/objectRest2.js.diff @@ -17,13 +17,10 @@ return { - resolve: (context, args) => __awaiter(this, void 0, void 0, function* () { - const { objects } = yield { objects: 12 }; -- return Object.assign({}, connectionFromArray(objects, args)); -- }) + resolve: async (context, args) => { + const { objects } = await { objects: 12 }; -+ return { -+ ...connectionFromArray(objects, args) -+ }; + return Object.assign({}, connectionFromArray(objects, args)); +- }) + } }; } diff --git a/testdata/baselines/reference/submodule/conformance/objectRestAssignment.js b/testdata/baselines/reference/submodule/conformance/objectRestAssignment.js index 1f27cb9ab7..d0536481c2 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRestAssignment.js +++ b/testdata/baselines/reference/submodule/conformance/objectRestAssignment.js @@ -17,14 +17,26 @@ var { a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit; //// [objectRestAssignment.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a, _b, _c; let ka; let nested; let other; let rest; let complex; -({ x: { ka, ...nested }, y: other, ...rest } = complex); +(_a = complex.x, { ka } = _a, nested = __rest(_a, ["ka"]), { y: other } = complex, rest = __rest(complex, ["x", "y"])); // should be: let overEmit; // var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); -var { a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit; -({ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit); +var [_d, ...y] = overEmit.a, nested2 = __rest(_d, []), _e = overEmit.b, { z } = _e, c = __rest(_e, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); +([_b, ...y] = overEmit.a, nested2 = __rest(_b, []), _c = overEmit.b, { z } = _c, c = __rest(_c, ["z"]), rest2 = __rest(overEmit, ["a", "b"])); diff --git a/testdata/baselines/reference/submodule/conformance/objectRestAssignment.js.diff b/testdata/baselines/reference/submodule/conformance/objectRestAssignment.js.diff deleted file mode 100644 index e7aa8bd15c..0000000000 --- a/testdata/baselines/reference/submodule/conformance/objectRestAssignment.js.diff +++ /dev/null @@ -1,32 +0,0 @@ ---- old.objectRestAssignment.js -+++ new.objectRestAssignment.js -@@= skipped -16, +16 lines =@@ - - - //// [objectRestAssignment.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --var _a, _b, _c; - let ka; - let nested; - let other; - let rest; - let complex; --(_a = complex.x, { ka } = _a, nested = __rest(_a, ["ka"]), { y: other } = complex, rest = __rest(complex, ["x", "y"])); -+({ x: { ka, ...nested }, y: other, ...rest } = complex); - // should be: - let overEmit; - // var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); --var [_d, ...y] = overEmit.a, nested2 = __rest(_d, []), _e = overEmit.b, { z } = _e, c = __rest(_e, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); --([_b, ...y] = overEmit.a, nested2 = __rest(_b, []), _c = overEmit.b, { z } = _c, c = __rest(_c, ["z"]), rest2 = __rest(overEmit, ["a", "b"])); -+var { a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit; -+({ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectRestCatchES5.js b/testdata/baselines/reference/submodule/conformance/objectRestCatchES5.js index 8aad755592..5a797a8660 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRestCatchES5.js +++ b/testdata/baselines/reference/submodule/conformance/objectRestCatchES5.js @@ -5,6 +5,19 @@ let a = 1, b = 2; try {} catch ({ a, ...b }) {} //// [objectRestCatchES5.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; let a = 1, b = 2; try { } -catch ({ a, ...b }) { } +catch (_a) { + var { a } = _a, b = __rest(_a, ["a"]); +} diff --git a/testdata/baselines/reference/submodule/conformance/objectRestCatchES5.js.diff b/testdata/baselines/reference/submodule/conformance/objectRestCatchES5.js.diff deleted file mode 100644 index 2888176d4c..0000000000 --- a/testdata/baselines/reference/submodule/conformance/objectRestCatchES5.js.diff +++ /dev/null @@ -1,23 +0,0 @@ ---- old.objectRestCatchES5.js -+++ new.objectRestCatchES5.js -@@= skipped -4, +4 lines =@@ - try {} catch ({ a, ...b }) {} - - //// [objectRestCatchES5.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - let a = 1, b = 2; - try { } --catch (_a) { -- var { a } = _a, b = __rest(_a, ["a"]); --} -+catch ({ a, ...b }) { } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectRestForOf.js b/testdata/baselines/reference/submodule/conformance/objectRestForOf.js index e72e71e86d..cc70886115 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRestForOf.js +++ b/testdata/baselines/reference/submodule/conformance/objectRestForOf.js @@ -17,16 +17,29 @@ for (const norest of array.map(a => ({ ...a, x: 'a string' }))) { //// [objectRestForOf.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; let array; -for (let { x, ...restOf } of array) { +for (let _a of array) { + let { x } = _a, restOf = __rest(_a, ["x"]); [x, restOf]; } let xx; let rrestOff; -for ({ x: xx, ...rrestOff } of array) { +for (let _b of array) { + ({ x: xx } = _b, rrestOff = __rest(_b, ["x"])); [xx, rrestOff]; } -for (const norest of array.map(a => ({ ...a, x: 'a string' }))) { +for (const norest of array.map(a => (Object.assign(Object.assign({}, a), { x: 'a string' })))) { [norest.x, norest.y]; // x is now a string. who knows why. } diff --git a/testdata/baselines/reference/submodule/conformance/objectRestForOf.js.diff b/testdata/baselines/reference/submodule/conformance/objectRestForOf.js.diff deleted file mode 100644 index 71c7aa9cce..0000000000 --- a/testdata/baselines/reference/submodule/conformance/objectRestForOf.js.diff +++ /dev/null @@ -1,35 +0,0 @@ ---- old.objectRestForOf.js -+++ new.objectRestForOf.js -@@= skipped -16, +16 lines =@@ - - - //// [objectRestForOf.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - let array; --for (let _a of array) { -- let { x } = _a, restOf = __rest(_a, ["x"]); -+for (let { x, ...restOf } of array) { - [x, restOf]; - } - let xx; - let rrestOff; --for (let _b of array) { -- ({ x: xx } = _b, rrestOff = __rest(_b, ["x"])); -+for ({ x: xx, ...rrestOff } of array) { - [xx, rrestOff]; - } --for (const norest of array.map(a => (Object.assign(Object.assign({}, a), { x: 'a string' })))) { -+for (const norest of array.map(a => ({ ...a, x: 'a string' }))) { - [norest.x, norest.y]; - // x is now a string. who knows why. - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectRestNegative.js b/testdata/baselines/reference/submodule/conformance/objectRestNegative.js index b8b5ab8f73..4b2c1d8a52 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRestNegative.js +++ b/testdata/baselines/reference/submodule/conformance/objectRestNegative.js @@ -21,16 +21,28 @@ let rest: { b: string } //// [objectRestNegative.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; let o = { a: 1, b: 'no' }; -var { ...mustBeLast, a } = o; +var { a } = o; var b; let notAssignable; -({ b, ...notAssignable } = o); -function stillMustBeLast({ ...mustBeLast, a }) { +({ b } = o, notAssignable = __rest(o, ["b"])); +function stillMustBeLast(_a) { + var { a } = _a; } function generic(t) { - let { x, ...rest } = t; + let { x } = t, rest = __rest(t, ["x"]); return rest; } let rest; -({ a, ...rest.b + rest.b } = o); +({ a } = o, (rest.b + rest.b) = __rest(o, ["a"])); diff --git a/testdata/baselines/reference/submodule/conformance/objectRestNegative.js.diff b/testdata/baselines/reference/submodule/conformance/objectRestNegative.js.diff index 5351c32336..7bd24d353f 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRestNegative.js.diff +++ b/testdata/baselines/reference/submodule/conformance/objectRestNegative.js.diff @@ -1,36 +1,8 @@ --- old.objectRestNegative.js +++ new.objectRestNegative.js -@@= skipped -20, +20 lines =@@ - - - //// [objectRestNegative.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - let o = { a: 1, b: 'no' }; --var { a } = o; -+var { ...mustBeLast, a } = o; - var b; - let notAssignable; --({ b } = o, notAssignable = __rest(o, ["b"])); --function stillMustBeLast(_a) { -- var { a } = _a; -+({ b, ...notAssignable } = o); -+function stillMustBeLast({ ...mustBeLast, a }) { - } - function generic(t) { -- let { x } = t, rest = __rest(t, ["x"]); -+ let { x, ...rest } = t; +@@= skipped -44, +44 lines =@@ return rest; } let rest; -({ a } = o, rest.b + rest.b = __rest(o, ["a"])); -+({ a, ...rest.b + rest.b } = o); \ No newline at end of file ++({ a } = o, (rest.b + rest.b) = __rest(o, ["a"])); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectRestParameter.js b/testdata/baselines/reference/submodule/conformance/objectRestParameter.js index e2fa4d7363..ed9ba45b74 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRestParameter.js +++ b/testdata/baselines/reference/submodule/conformance/objectRestParameter.js @@ -24,19 +24,40 @@ foobar({ bar: { greeting: 'hello' } }); //// [objectRestParameter.js] -function cloneAgain({ a, ...clone }) { +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +function cloneAgain(_a) { + var { a } = _a, clone = __rest(_a, ["a"]); } -suddenly(({ x: a, ...rest }) => rest.y); -suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka); +suddenly((_a) => { + var { x: a } = _a, rest = __rest(_a, ["x"]); + return rest.y; +}); +suddenly((_a = { x: { z: 1, ka: 1 }, y: 'noo' }) => { + var _b = _a.x, { z = 12 } = _b, nested = __rest(_b, ["z"]), rest = __rest(_a, ["x"]); + return rest.y + nested.ka; +}); class C { - m({ a, ...clone }) { + m(_a) { + var { a } = _a, clone = __rest(_a, ["a"]); // actually, never mind, don't clone } - set p({ a, ...clone }) { + set p(_a) { + var { a } = _a, clone = __rest(_a, ["a"]); // actually, never mind, don't clone } } -function foobar({ bar = {}, ...opts } = {}) { +function foobar(_a = {}) { + var { bar = {} } = _a, opts = __rest(_a, ["bar"]); } foobar(); foobar({ baz: 'hello' }); diff --git a/testdata/baselines/reference/submodule/conformance/objectRestParameter.js.diff b/testdata/baselines/reference/submodule/conformance/objectRestParameter.js.diff deleted file mode 100644 index 710f9e9e30..0000000000 --- a/testdata/baselines/reference/submodule/conformance/objectRestParameter.js.diff +++ /dev/null @@ -1,49 +0,0 @@ ---- old.objectRestParameter.js -+++ new.objectRestParameter.js -@@= skipped -23, +23 lines =@@ - - - //// [objectRestParameter.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --function cloneAgain(_a) { -- var { a } = _a, clone = __rest(_a, ["a"]); -+function cloneAgain({ a, ...clone }) { - } --suddenly((_a) => { -- var { x: a } = _a, rest = __rest(_a, ["x"]); -- return rest.y; --}); --suddenly((_a = { x: { z: 1, ka: 1 }, y: 'noo' }) => { -- var _b = _a.x, { z = 12 } = _b, nested = __rest(_b, ["z"]), rest = __rest(_a, ["x"]); -- return rest.y + nested.ka; --}); -+suddenly(({ x: a, ...rest }) => rest.y); -+suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka); - class C { -- m(_a) { -- var { a } = _a, clone = __rest(_a, ["a"]); -+ m({ a, ...clone }) { - // actually, never mind, don't clone - } -- set p(_a) { -- var { a } = _a, clone = __rest(_a, ["a"]); -+ set p({ a, ...clone }) { - // actually, never mind, don't clone - } - } --function foobar(_a = {}) { -- var { bar = {} } = _a, opts = __rest(_a, ["bar"]); -+function foobar({ bar = {}, ...opts } = {}) { - } - foobar(); - foobar({ baz: 'hello' }); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectRestParameterES5.js b/testdata/baselines/reference/submodule/conformance/objectRestParameterES5.js index a61fea0af8..85d8bf58bb 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRestParameterES5.js +++ b/testdata/baselines/reference/submodule/conformance/objectRestParameterES5.js @@ -24,19 +24,40 @@ foobar({ bar: { greeting: 'hello' } }); //// [objectRestParameterES5.js] -function cloneAgain({ a, ...clone }) { +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +function cloneAgain(_a) { + var { a } = _a, clone = __rest(_a, ["a"]); } -suddenly(({ x: a, ...rest }) => rest.y); -suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka); +suddenly((_a) => { + var { x: a } = _a, rest = __rest(_a, ["x"]); + return rest.y; +}); +suddenly((_a = { x: { z: 1, ka: 1 }, y: 'noo' }) => { + var _b = _a.x, { z = 12 } = _b, nested = __rest(_b, ["z"]), rest = __rest(_a, ["x"]); + return rest.y + nested.ka; +}); class C { - m({ a, ...clone }) { + m(_a) { + var { a } = _a, clone = __rest(_a, ["a"]); // actually, never mind, don't clone } - set p({ a, ...clone }) { + set p(_a) { + var { a } = _a, clone = __rest(_a, ["a"]); // actually, never mind, don't clone } } -function foobar({ bar = {}, ...opts } = {}) { +function foobar(_a = {}) { + var { bar = {} } = _a, opts = __rest(_a, ["bar"]); } foobar(); foobar({ baz: 'hello' }); diff --git a/testdata/baselines/reference/submodule/conformance/objectRestParameterES5.js.diff b/testdata/baselines/reference/submodule/conformance/objectRestParameterES5.js.diff deleted file mode 100644 index b4aa99e831..0000000000 --- a/testdata/baselines/reference/submodule/conformance/objectRestParameterES5.js.diff +++ /dev/null @@ -1,49 +0,0 @@ ---- old.objectRestParameterES5.js -+++ new.objectRestParameterES5.js -@@= skipped -23, +23 lines =@@ - - - //// [objectRestParameterES5.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --function cloneAgain(_a) { -- var { a } = _a, clone = __rest(_a, ["a"]); -+function cloneAgain({ a, ...clone }) { - } --suddenly((_a) => { -- var { x: a } = _a, rest = __rest(_a, ["x"]); -- return rest.y; --}); --suddenly((_a = { x: { z: 1, ka: 1 }, y: 'noo' }) => { -- var _b = _a.x, { z = 12 } = _b, nested = __rest(_b, ["z"]), rest = __rest(_a, ["x"]); -- return rest.y + nested.ka; --}); -+suddenly(({ x: a, ...rest }) => rest.y); -+suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka); - class C { -- m(_a) { -- var { a } = _a, clone = __rest(_a, ["a"]); -+ m({ a, ...clone }) { - // actually, never mind, don't clone - } -- set p(_a) { -- var { a } = _a, clone = __rest(_a, ["a"]); -+ set p({ a, ...clone }) { - // actually, never mind, don't clone - } - } --function foobar(_a = {}) { -- var { bar = {} } = _a, opts = __rest(_a, ["bar"]); -+function foobar({ bar = {}, ...opts } = {}) { - } - foobar(); - foobar({ baz: 'hello' }); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectRestPropertyMustBeLast.js b/testdata/baselines/reference/submodule/conformance/objectRestPropertyMustBeLast.js index 08414cb57a..bd1657ef1f 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRestPropertyMustBeLast.js +++ b/testdata/baselines/reference/submodule/conformance/objectRestPropertyMustBeLast.js @@ -9,7 +9,19 @@ var {...a, x, ...b } = { x: 1 }; // Error, rest must be last property //// [objectRestPropertyMustBeLast.js] -var { ...a, x } = { x: 1 }; // Error, rest must be last property -({ ...a, x } = { x: 1 }); // Error, rest must be last property -var { ...a, x, ...b } = { x: 1 }; // Error, rest must be last property -({ ...a, x, ...b } = { x: 1 }); // Error, rest must be last property +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a, _b; +var _c = { x: 1 }, { x } = _c; // Error, rest must be last property +(_a = { x: 1 }, { x } = _a); // Error, rest must be last property +var _d = { x: 1 }, { x } = _d, b = __rest(_d, ["a", "x"]); // Error, rest must be last property +(_b = { x: 1 }, { x } = _b, b = __rest(_b, ["x"])); // Error, rest must be last property diff --git a/testdata/baselines/reference/submodule/conformance/objectRestPropertyMustBeLast.js.diff b/testdata/baselines/reference/submodule/conformance/objectRestPropertyMustBeLast.js.diff deleted file mode 100644 index 2ef688b1b8..0000000000 --- a/testdata/baselines/reference/submodule/conformance/objectRestPropertyMustBeLast.js.diff +++ /dev/null @@ -1,26 +0,0 @@ ---- old.objectRestPropertyMustBeLast.js -+++ new.objectRestPropertyMustBeLast.js -@@= skipped -8, +8 lines =@@ - - - //// [objectRestPropertyMustBeLast.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --var _a, _b; --var _c = { x: 1 }, { x } = _c; // Error, rest must be last property --(_a = { x: 1 }, { x } = _a); // Error, rest must be last property --var _d = { x: 1 }, { x } = _d, b = __rest(_d, ["a", "x"]); // Error, rest must be last property --(_b = { x: 1 }, { x } = _b, b = __rest(_b, ["x"])); // Error, rest must be last property -+var { ...a, x } = { x: 1 }; // Error, rest must be last property -+({ ...a, x } = { x: 1 }); // Error, rest must be last property -+var { ...a, x, ...b } = { x: 1 }; // Error, rest must be last property -+({ ...a, x, ...b } = { x: 1 }); // Error, rest must be last property \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectRestReadonly.js b/testdata/baselines/reference/submodule/conformance/objectRestReadonly.js index 7a9352087b..b8ef0ab419 100644 --- a/testdata/baselines/reference/submodule/conformance/objectRestReadonly.js +++ b/testdata/baselines/reference/submodule/conformance/objectRestReadonly.js @@ -20,10 +20,21 @@ delete rest.baz //// [objectRestReadonly.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; const obj = { foo: 'bar', baz: 'qux', quux: 'quuz', }; -const { foo, ...rest } = obj; +const { foo } = obj, rest = __rest(obj, ["foo"]); delete rest.baz; diff --git a/testdata/baselines/reference/submodule/conformance/objectRestReadonly.js.diff b/testdata/baselines/reference/submodule/conformance/objectRestReadonly.js.diff deleted file mode 100644 index 61f6c95ad6..0000000000 --- a/testdata/baselines/reference/submodule/conformance/objectRestReadonly.js.diff +++ /dev/null @@ -1,25 +0,0 @@ ---- old.objectRestReadonly.js -+++ new.objectRestReadonly.js -@@= skipped -19, +19 lines =@@ - - - //// [objectRestReadonly.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - const obj = { - foo: 'bar', - baz: 'qux', - quux: 'quuz', - }; --const { foo } = obj, rest = __rest(obj, ["foo"]); -+const { foo, ...rest } = obj; - delete rest.baz; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectSpread.js b/testdata/baselines/reference/submodule/conformance/objectSpread.js index 47b9c12ebd..dc168f2390 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpread.js +++ b/testdata/baselines/reference/submodule/conformance/objectSpread.js @@ -146,113 +146,111 @@ function genericSpread(t: T, u: U, v: T | U, w: T | { s: string }, obj: { //// [objectSpread.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; let o = { a: 1, b: 'no' }; let o2 = { b: 'yes', c: true }; let swap = { a: 'yes', b: -1 }; -let addAfter = { ...o, c: false }; -let addBefore = { c: false, ...o }; -let override = { ...o, b: 'override' }; -let nested = { ...{ a: 3, ...{ b: false, c: 'overriden' } }, c: 'whatever' }; -let combined = { ...o, ...o2 }; -let combinedAfter = { ...o, ...o2, b: 'ok' }; -let combinedNestedChangeType = { ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 }; -let propertyNested = { a: { ...o } }; +let addAfter = __assign(__assign({}, o), { c: false }); +let addBefore = __assign({ c: false }, o); +let override = __assign(__assign({}, o), { b: 'override' }); +let nested = __assign(__assign({}, __assign({ a: 3 }, { b: false, c: 'overriden' })), { c: 'whatever' }); +let combined = __assign(__assign({}, o), o2); +let combinedAfter = __assign(__assign(__assign({}, o), o2), { b: 'ok' }); +let combinedNestedChangeType = __assign(__assign({}, __assign({ a: 1 }, { b: false, c: 'overriden' })), { c: -1 }); +let propertyNested = { a: __assign({}, o) }; // accessors don't copy the descriptor // (which means that readonly getters become read/write properties) let op = { get a() { return 6; } }; -let getter = { ...op, c: 7 }; +let getter = __assign(__assign({}, op), { c: 7 }); getter.a = 12; // functions result in { } -let spreadFunc = { ...(function () { }) }; +let spreadFunc = __assign({}, (function () { })); function from16326(header, authToken) { - return { - ...this.header, - ...header, - ...authToken && { authToken } - }; + return __assign(__assign(__assign({}, this.header), header), authToken && { authToken }); } // boolean && T results in Partial function conditionalSpreadBoolean(b) { let o = { x: 12, y: 13 }; - o = { - ...o, - ...b && { x: 14 } - }; - let o2 = { ...b && { x: 21 } }; + o = __assign(__assign({}, o), b && { x: 14 }); + let o2 = __assign({}, b && { x: 21 }); return o; } function conditionalSpreadNumber(nt) { let o = { x: 15, y: 16 }; - o = { - ...o, - ...nt && { x: nt } - }; - let o2 = { ...nt && { x: nt } }; + o = __assign(__assign({}, o), nt && { x: nt }); + let o2 = __assign({}, nt && { x: nt }); return o; } function conditionalSpreadString(st) { let o = { x: 'hi', y: 17 }; - o = { - ...o, - ...st && { x: st } - }; - let o2 = { ...st && { x: st } }; + o = __assign(__assign({}, o), st && { x: st }); + let o2 = __assign({}, st && { x: st }); return o; } // any results in any let anything; -let spreadAny = { ...anything }; +let spreadAny = __assign({}, anything); // methods are not enumerable class C { p = 1; m() { } } let c = new C(); -let spreadC = { ...c }; +let spreadC = __assign({}, c); // own methods are enumerable -let cplus = { ...c, plus() { return this.p + 1; } }; +let cplus = __assign(__assign({}, c), { plus() { return this.p + 1; } }); cplus.plus(); // new field's type conflicting with existing field is OK -let changeTypeAfter = { ...o, a: 'wrong type?' }; -let changeTypeBoth = { ...o, ...swap }; +let changeTypeAfter = __assign(__assign({}, o), { a: 'wrong type?' }); +let changeTypeBoth = __assign(__assign({}, o), swap); // optional function container(definiteBoolean, definiteString, optionalString, optionalNumber) { - let optionalUnionStops = { ...definiteBoolean, ...definiteString, ...optionalNumber }; - let optionalUnionDuplicates = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; - let allOptional = { ...optionalString, ...optionalNumber }; + let optionalUnionStops = __assign(__assign(__assign({}, definiteBoolean), definiteString), optionalNumber); + let optionalUnionDuplicates = __assign(__assign(__assign(__assign({}, definiteBoolean), definiteString), optionalString), optionalNumber); + let allOptional = __assign(__assign({}, optionalString), optionalNumber); // computed property - let computedFirst = { ['before everything']: 12, ...o, b: 'yes' }; - let computedAfter = { ...o, b: 'yeah', ['at the end']: 14 }; + let computedFirst = __assign(__assign({ ['before everything']: 12 }, o), { b: 'yes' }); + let computedAfter = __assign(__assign({}, o), { b: 'yeah', ['at the end']: 14 }); } // shortcut syntax let a = 12; -let shortCutted = { ...o, a }; +let shortCutted = __assign(__assign({}, o), { a }); // non primitive -let spreadNonPrimitive = { ...{} }; +let spreadNonPrimitive = __assign({}, {}); // generic spreads function f(t, u) { - return { ...t, ...u, id: 'id' }; + return __assign(__assign(__assign({}, t), u), { id: 'id' }); } let exclusive = f({ a: 1, b: 'yes' }, { c: 'no', d: false }); let overlap = f({ a: 1 }, { a: 2, b: 'extra' }); let overlapConflict = f({ a: 1 }, { a: 'mismatch' }); let overwriteId = f({ a: 1, id: true }, { c: 1, d: 'no' }); function genericSpread(t, u, v, w, obj) { - let x01 = { ...t }; - let x02 = { ...t, ...t }; - let x03 = { ...t, ...u }; - let x04 = { ...u, ...t }; - let x05 = { a: 5, b: 'hi', ...t }; - let x06 = { ...t, a: 5, b: 'hi' }; - let x07 = { a: 5, b: 'hi', ...t, c: true, ...obj }; - let x09 = { a: 5, ...t, b: 'hi', c: true, ...obj }; - let x10 = { a: 5, ...t, b: 'hi', ...u, ...obj }; - let x11 = { ...v }; - let x12 = { ...v, ...obj }; - let x13 = { ...w }; - let x14 = { ...w, ...obj }; - let x15 = { ...t, ...v }; - let x16 = { ...t, ...w }; - let x17 = { ...t, ...w, ...obj }; - let x18 = { ...t, ...v, ...w }; + let x01 = __assign({}, t); + let x02 = __assign(__assign({}, t), t); + let x03 = __assign(__assign({}, t), u); + let x04 = __assign(__assign({}, u), t); + let x05 = __assign({ a: 5, b: 'hi' }, t); + let x06 = __assign(__assign({}, t), { a: 5, b: 'hi' }); + let x07 = __assign(__assign(__assign({ a: 5, b: 'hi' }, t), { c: true }), obj); + let x09 = __assign(__assign(__assign({ a: 5 }, t), { b: 'hi', c: true }), obj); + let x10 = __assign(__assign(__assign(__assign({ a: 5 }, t), { b: 'hi' }), u), obj); + let x11 = __assign({}, v); + let x12 = __assign(__assign({}, v), obj); + let x13 = __assign({}, w); + let x14 = __assign(__assign({}, w), obj); + let x15 = __assign(__assign({}, t), v); + let x16 = __assign(__assign({}, t), w); + let x17 = __assign(__assign(__assign({}, t), w), obj); + let x18 = __assign(__assign(__assign({}, t), v), w); } diff --git a/testdata/baselines/reference/submodule/conformance/objectSpread.js.diff b/testdata/baselines/reference/submodule/conformance/objectSpread.js.diff index 4d571383c3..0fe7ac28a8 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpread.js.diff +++ b/testdata/baselines/reference/submodule/conformance/objectSpread.js.diff @@ -1,94 +1,7 @@ --- old.objectSpread.js +++ new.objectSpread.js -@@= skipped -145, +145 lines =@@ - - - //// [objectSpread.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - let o = { a: 1, b: 'no' }; - let o2 = { b: 'yes', c: true }; - let swap = { a: 'yes', b: -1 }; --let addAfter = __assign(__assign({}, o), { c: false }); --let addBefore = __assign({ c: false }, o); --let override = __assign(__assign({}, o), { b: 'override' }); --let nested = __assign(__assign({}, __assign({ a: 3 }, { b: false, c: 'overriden' })), { c: 'whatever' }); --let combined = __assign(__assign({}, o), o2); --let combinedAfter = __assign(__assign(__assign({}, o), o2), { b: 'ok' }); --let combinedNestedChangeType = __assign(__assign({}, __assign({ a: 1 }, { b: false, c: 'overriden' })), { c: -1 }); --let propertyNested = { a: __assign({}, o) }; -+let addAfter = { ...o, c: false }; -+let addBefore = { c: false, ...o }; -+let override = { ...o, b: 'override' }; -+let nested = { ...{ a: 3, ...{ b: false, c: 'overriden' } }, c: 'whatever' }; -+let combined = { ...o, ...o2 }; -+let combinedAfter = { ...o, ...o2, b: 'ok' }; -+let combinedNestedChangeType = { ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 }; -+let propertyNested = { a: { ...o } }; - // accessors don't copy the descriptor - // (which means that readonly getters become read/write properties) - let op = { get a() { return 6; } }; --let getter = __assign(__assign({}, op), { c: 7 }); -+let getter = { ...op, c: 7 }; - getter.a = 12; - // functions result in { } --let spreadFunc = __assign({}, (function () { })); -+let spreadFunc = { ...(function () { }) }; - function from16326(header, authToken) { -- return __assign(__assign(__assign({}, this.header), header), authToken && { authToken }); -+ return { -+ ...this.header, -+ ...header, -+ ...authToken && { authToken } -+ }; - } - // boolean && T results in Partial - function conditionalSpreadBoolean(b) { - let o = { x: 12, y: 13 }; -- o = __assign(__assign({}, o), b && { x: 14 }); -- let o2 = __assign({}, b && { x: 21 }); -+ o = { -+ ...o, -+ ...b && { x: 14 } -+ }; -+ let o2 = { ...b && { x: 21 } }; - return o; - } - function conditionalSpreadNumber(nt) { - let o = { x: 15, y: 16 }; -- o = __assign(__assign({}, o), nt && { x: nt }); -- let o2 = __assign({}, nt && { x: nt }); -+ o = { -+ ...o, -+ ...nt && { x: nt } -+ }; -+ let o2 = { ...nt && { x: nt } }; - return o; - } - function conditionalSpreadString(st) { - let o = { x: 'hi', y: 17 }; -- o = __assign(__assign({}, o), st && { x: st }); -- let o2 = __assign({}, st && { x: st }); -+ o = { -+ ...o, -+ ...st && { x: st } -+ }; -+ let o2 = { ...st && { x: st } }; - return o; - } - // any results in any - let anything; --let spreadAny = __assign({}, anything); -+let spreadAny = { ...anything }; +@@= skipped -201, +201 lines =@@ + let spreadAny = __assign({}, anything); // methods are not enumerable class C { - constructor() { @@ -97,81 +10,4 @@ + p = 1; m() { } } - let c = new C(); --let spreadC = __assign({}, c); -+let spreadC = { ...c }; - // own methods are enumerable --let cplus = __assign(__assign({}, c), { plus() { return this.p + 1; } }); -+let cplus = { ...c, plus() { return this.p + 1; } }; - cplus.plus(); - // new field's type conflicting with existing field is OK --let changeTypeAfter = __assign(__assign({}, o), { a: 'wrong type?' }); --let changeTypeBoth = __assign(__assign({}, o), swap); -+let changeTypeAfter = { ...o, a: 'wrong type?' }; -+let changeTypeBoth = { ...o, ...swap }; - // optional - function container(definiteBoolean, definiteString, optionalString, optionalNumber) { -- let optionalUnionStops = __assign(__assign(__assign({}, definiteBoolean), definiteString), optionalNumber); -- let optionalUnionDuplicates = __assign(__assign(__assign(__assign({}, definiteBoolean), definiteString), optionalString), optionalNumber); -- let allOptional = __assign(__assign({}, optionalString), optionalNumber); -+ let optionalUnionStops = { ...definiteBoolean, ...definiteString, ...optionalNumber }; -+ let optionalUnionDuplicates = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; -+ let allOptional = { ...optionalString, ...optionalNumber }; - // computed property -- let computedFirst = __assign(__assign({ ['before everything']: 12 }, o), { b: 'yes' }); -- let computedAfter = __assign(__assign({}, o), { b: 'yeah', ['at the end']: 14 }); -+ let computedFirst = { ['before everything']: 12, ...o, b: 'yes' }; -+ let computedAfter = { ...o, b: 'yeah', ['at the end']: 14 }; - } - // shortcut syntax - let a = 12; --let shortCutted = __assign(__assign({}, o), { a }); -+let shortCutted = { ...o, a }; - // non primitive --let spreadNonPrimitive = __assign({}, {}); -+let spreadNonPrimitive = { ...{} }; - // generic spreads - function f(t, u) { -- return __assign(__assign(__assign({}, t), u), { id: 'id' }); -+ return { ...t, ...u, id: 'id' }; - } - let exclusive = f({ a: 1, b: 'yes' }, { c: 'no', d: false }); - let overlap = f({ a: 1 }, { a: 2, b: 'extra' }); - let overlapConflict = f({ a: 1 }, { a: 'mismatch' }); - let overwriteId = f({ a: 1, id: true }, { c: 1, d: 'no' }); - function genericSpread(t, u, v, w, obj) { -- let x01 = __assign({}, t); -- let x02 = __assign(__assign({}, t), t); -- let x03 = __assign(__assign({}, t), u); -- let x04 = __assign(__assign({}, u), t); -- let x05 = __assign({ a: 5, b: 'hi' }, t); -- let x06 = __assign(__assign({}, t), { a: 5, b: 'hi' }); -- let x07 = __assign(__assign(__assign({ a: 5, b: 'hi' }, t), { c: true }), obj); -- let x09 = __assign(__assign(__assign({ a: 5 }, t), { b: 'hi', c: true }), obj); -- let x10 = __assign(__assign(__assign(__assign({ a: 5 }, t), { b: 'hi' }), u), obj); -- let x11 = __assign({}, v); -- let x12 = __assign(__assign({}, v), obj); -- let x13 = __assign({}, w); -- let x14 = __assign(__assign({}, w), obj); -- let x15 = __assign(__assign({}, t), v); -- let x16 = __assign(__assign({}, t), w); -- let x17 = __assign(__assign(__assign({}, t), w), obj); -- let x18 = __assign(__assign(__assign({}, t), v), w); -+ let x01 = { ...t }; -+ let x02 = { ...t, ...t }; -+ let x03 = { ...t, ...u }; -+ let x04 = { ...u, ...t }; -+ let x05 = { a: 5, b: 'hi', ...t }; -+ let x06 = { ...t, a: 5, b: 'hi' }; -+ let x07 = { a: 5, b: 'hi', ...t, c: true, ...obj }; -+ let x09 = { a: 5, ...t, b: 'hi', c: true, ...obj }; -+ let x10 = { a: 5, ...t, b: 'hi', ...u, ...obj }; -+ let x11 = { ...v }; -+ let x12 = { ...v, ...obj }; -+ let x13 = { ...w }; -+ let x14 = { ...w, ...obj }; -+ let x15 = { ...t, ...v }; -+ let x16 = { ...t, ...w }; -+ let x17 = { ...t, ...w, ...obj }; -+ let x18 = { ...t, ...v, ...w }; - } \ No newline at end of file + let c = new C(); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadComputedProperty.js b/testdata/baselines/reference/submodule/conformance/objectSpreadComputedProperty.js index f7685ec568..07cbee3e76 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadComputedProperty.js +++ b/testdata/baselines/reference/submodule/conformance/objectSpreadComputedProperty.js @@ -13,12 +13,23 @@ function f() { //// [objectSpreadComputedProperty.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; // fixes #12200 function f() { let n = 12; let m = 13; let a = null; - const o1 = { ...{}, [n]: n }; - const o2 = { ...{}, [a]: n }; - const o3 = { [a]: n, ...{}, [n]: n, ...{}, [m]: m }; + const o1 = __assign({}, { [n]: n }); + const o2 = __assign({}, { [a]: n }); + const o3 = __assign(__assign(__assign(__assign({ [a]: n }, {}), { [n]: n }), {}), { [m]: m }); } diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadComputedProperty.js.diff b/testdata/baselines/reference/submodule/conformance/objectSpreadComputedProperty.js.diff deleted file mode 100644 index 8c67d1c927..0000000000 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadComputedProperty.js.diff +++ /dev/null @@ -1,29 +0,0 @@ ---- old.objectSpreadComputedProperty.js -+++ new.objectSpreadComputedProperty.js -@@= skipped -12, +12 lines =@@ - - - //// [objectSpreadComputedProperty.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - // fixes #12200 - function f() { - let n = 12; - let m = 13; - let a = null; -- const o1 = __assign({}, { [n]: n }); -- const o2 = __assign({}, { [a]: n }); -- const o3 = __assign(__assign(__assign(__assign({ [a]: n }, {}), { [n]: n }), {}), { [m]: m }); -+ const o1 = { ...{}, [n]: n }; -+ const o2 = { ...{}, [a]: n }; -+ const o3 = { [a]: n, ...{}, [n]: n, ...{}, [m]: m }; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadIndexSignature.js b/testdata/baselines/reference/submodule/conformance/objectSpreadIndexSignature.js index 15e59c86f2..4b369fb469 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadIndexSignature.js +++ b/testdata/baselines/reference/submodule/conformance/objectSpreadIndexSignature.js @@ -20,12 +20,23 @@ writable.a = 0; // should be ok. //// [objectSpreadIndexSignature.js] -let i = { ...indexed1, b: 11 }; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +let i = __assign(__assign({}, indexed1), { b: 11 }); // only indexed has indexer, so i[101]: any i[101]; -let ii = { ...indexed1, ...indexed2 }; +let ii = __assign(__assign({}, indexed1), indexed2); // both have indexer, so i[1001]: number | boolean ii[1001]; -indexed3 = { ...b ? indexed3 : undefined }; -var writable = { ...roindex }; +indexed3 = __assign({}, b ? indexed3 : undefined); +var writable = __assign({}, roindex); writable.a = 0; // should be ok. diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadIndexSignature.js.diff b/testdata/baselines/reference/submodule/conformance/objectSpreadIndexSignature.js.diff index 135dad60eb..e048c79ea4 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadIndexSignature.js.diff +++ b/testdata/baselines/reference/submodule/conformance/objectSpreadIndexSignature.js.diff @@ -5,27 +5,6 @@ //// [objectSpreadIndexSignature.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --let i = __assign(__assign({}, indexed1), { b: 11 }); -+let i = { ...indexed1, b: 11 }; - // only indexed has indexer, so i[101]: any - i[101]; --let ii = __assign(__assign({}, indexed1), indexed2); -+let ii = { ...indexed1, ...indexed2 }; - // both have indexer, so i[1001]: number | boolean - ii[1001]; --indexed3 = __assign({}, b ? indexed3 : undefined); --var writable = __assign({}, roindex); -+indexed3 = { ...b ? indexed3 : undefined }; -+var writable = { ...roindex }; - writable.a = 0; // should be ok. \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadNegative.js b/testdata/baselines/reference/submodule/conformance/objectSpreadNegative.js index 774d0e4b36..0c2fc1b5d6 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadNegative.js +++ b/testdata/baselines/reference/submodule/conformance/objectSpreadNegative.js @@ -78,6 +78,17 @@ spreadObj.a; // error 'a' is not in {} //// [objectSpreadNegative.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; let o = { a: 1, b: 'no' }; /// private propagates class PrivateOptionalX { @@ -86,42 +97,42 @@ class PrivateOptionalX { class PublicX { x; } -let o2 = { ...publicX, ...privateOptionalX }; +let o2 = __assign(__assign({}, publicX), privateOptionalX); let sn = o2.x; // error, x is private -let allOptional = { ...optionalString, ...optionalNumber }; +let allOptional = __assign(__assign({}, optionalString), optionalNumber); ; ; -let spread = { ...{ b: true }, ...{ s: "foo" } }; +let spread = __assign({ b: true }, { s: "foo" }); spread = { s: "foo" }; // error, missing 'b' let b = { b: false }; spread = b; // error, missing 's' // literal repeats are not allowed, but spread repeats are fine -let duplicated = { b: 'bad', ...o, b: 'bad', ...o2, b: 'bad' }; -let duplicatedSpread = { ...o, ...o }; +let duplicated = __assign(__assign(__assign(__assign({ b: 'bad' }, o), { b: 'bad' }), o2), { b: 'bad' }); +let duplicatedSpread = __assign(__assign({}, o), o); // Note: ignore changes the order that properties are printed -let ignore = { b: 'ignored', ...o }; +let ignore = __assign({ b: 'ignored' }, o); let o3 = { a: 1, b: 'no' }; let o4 = { b: 'yes', c: true }; -let combinedBefore = { b: 'ok', ...o3, ...o4 }; -let combinedMid = { ...o3, b: 'ok', ...o4 }; -let combinedNested = { ...{ a: 4, ...{ b: false, c: 'overriden' } }, d: 'actually new', ...{ a: 5, d: 'maybe new' } }; -let changeTypeBefore = { a: 'wrong type?', ...o3 }; -let computedMiddle = { ...o3, ['in the middle']: 13, b: 'maybe?', ...o4 }; +let combinedBefore = __assign(__assign({ b: 'ok' }, o3), o4); +let combinedMid = __assign(__assign(__assign({}, o3), { b: 'ok' }), o4); +let combinedNested = __assign(__assign(__assign({}, __assign({ a: 4 }, { b: false, c: 'overriden' })), { d: 'actually new' }), { a: 5, d: 'maybe new' }); +let changeTypeBefore = __assign({ a: 'wrong type?' }, o3); +let computedMiddle = __assign(__assign(__assign({}, o3), { ['in the middle']: 13, b: 'maybe?' }), o4); // primitives are not allowed, except for falsy ones -let spreadNum = { ...12 }; -let spreadSum = { ...1 + 1 }; -let spreadZero = { ...0 }; +let spreadNum = __assign({}, 12); +let spreadSum = __assign({}, 1 + 1); +let spreadZero = __assign({}, 0); spreadZero.toFixed(); // error, no methods even from a falsy number -let spreadBool = { ...true }; +let spreadBool = __assign({}, true); spreadBool.valueOf(); -let spreadStr = { ...'foo' }; +let spreadStr = __assign({}, 'foo'); spreadStr.length; // error, no 'length' spreadStr.charAt(1); // error, no methods either // functions are skipped -let spreadFunc = { ...function () { } }; +let spreadFunc = __assign({}, function () { }); spreadFunc(); // error, no call signature // write-only properties get skipped -let setterOnly = { ...{ set b(bad) { } } }; +let setterOnly = __assign({ set b(bad) { } }); setterOnly.b = 12; // error, 'b' does not exist // methods are skipped because they aren't enumerable class C { @@ -129,9 +140,9 @@ class C { m() { } } let c = new C(); -let spreadC = { ...c }; +let spreadC = __assign({}, c); spreadC.m(); // error 'm' is not in '{ ... c }' // non primitive let obj = { a: 123 }; -let spreadObj = { ...obj }; +let spreadObj = __assign({}, obj); spreadObj.a; // error 'a' is not in {} diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadNegative.js.diff b/testdata/baselines/reference/submodule/conformance/objectSpreadNegative.js.diff index 0bf176ac94..9ed9fb9f3a 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadNegative.js.diff +++ b/testdata/baselines/reference/submodule/conformance/objectSpreadNegative.js.diff @@ -1,20 +1,6 @@ --- old.objectSpreadNegative.js +++ new.objectSpreadNegative.js -@@= skipped -77, +77 lines =@@ - - - //// [objectSpreadNegative.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; +@@= skipped -91, +91 lines =@@ let o = { a: 1, b: 'no' }; /// private propagates class PrivateOptionalX { @@ -23,62 +9,9 @@ class PublicX { + x; } --let o2 = __assign(__assign({}, publicX), privateOptionalX); -+let o2 = { ...publicX, ...privateOptionalX }; + let o2 = __assign(__assign({}, publicX), privateOptionalX); let sn = o2.x; // error, x is private --let allOptional = __assign(__assign({}, optionalString), optionalNumber); --; --; --let spread = __assign({ b: true }, { s: "foo" }); -+let allOptional = { ...optionalString, ...optionalNumber }; -+; -+; -+let spread = { ...{ b: true }, ...{ s: "foo" } }; - spread = { s: "foo" }; // error, missing 'b' - let b = { b: false }; - spread = b; // error, missing 's' - // literal repeats are not allowed, but spread repeats are fine --let duplicated = __assign(__assign(__assign(__assign({ b: 'bad' }, o), { b: 'bad' }), o2), { b: 'bad' }); --let duplicatedSpread = __assign(__assign({}, o), o); -+let duplicated = { b: 'bad', ...o, b: 'bad', ...o2, b: 'bad' }; -+let duplicatedSpread = { ...o, ...o }; - // Note: ignore changes the order that properties are printed --let ignore = __assign({ b: 'ignored' }, o); -+let ignore = { b: 'ignored', ...o }; - let o3 = { a: 1, b: 'no' }; - let o4 = { b: 'yes', c: true }; --let combinedBefore = __assign(__assign({ b: 'ok' }, o3), o4); --let combinedMid = __assign(__assign(__assign({}, o3), { b: 'ok' }), o4); --let combinedNested = __assign(__assign(__assign({}, __assign({ a: 4 }, { b: false, c: 'overriden' })), { d: 'actually new' }), { a: 5, d: 'maybe new' }); --let changeTypeBefore = __assign({ a: 'wrong type?' }, o3); --let computedMiddle = __assign(__assign(__assign({}, o3), { ['in the middle']: 13, b: 'maybe?' }), o4); -+let combinedBefore = { b: 'ok', ...o3, ...o4 }; -+let combinedMid = { ...o3, b: 'ok', ...o4 }; -+let combinedNested = { ...{ a: 4, ...{ b: false, c: 'overriden' } }, d: 'actually new', ...{ a: 5, d: 'maybe new' } }; -+let changeTypeBefore = { a: 'wrong type?', ...o3 }; -+let computedMiddle = { ...o3, ['in the middle']: 13, b: 'maybe?', ...o4 }; - // primitives are not allowed, except for falsy ones --let spreadNum = __assign({}, 12); --let spreadSum = __assign({}, 1 + 1); --let spreadZero = __assign({}, 0); -+let spreadNum = { ...12 }; -+let spreadSum = { ...1 + 1 }; -+let spreadZero = { ...0 }; - spreadZero.toFixed(); // error, no methods even from a falsy number --let spreadBool = __assign({}, true); -+let spreadBool = { ...true }; - spreadBool.valueOf(); --let spreadStr = __assign({}, 'foo'); -+let spreadStr = { ...'foo' }; - spreadStr.length; // error, no 'length' - spreadStr.charAt(1); // error, no methods either - // functions are skipped --let spreadFunc = __assign({}, function () { }); -+let spreadFunc = { ...function () { } }; - spreadFunc(); // error, no call signature - // write-only properties get skipped --let setterOnly = __assign({ set b(bad) { } }); -+let setterOnly = { ...{ set b(bad) { } } }; +@@= skipped -42, +44 lines =@@ setterOnly.b = 12; // error, 'b' does not exist // methods are skipped because they aren't enumerable class C { @@ -88,12 +21,4 @@ + p = 1; m() { } } - let c = new C(); --let spreadC = __assign({}, c); -+let spreadC = { ...c }; - spreadC.m(); // error 'm' is not in '{ ... c }' - // non primitive - let obj = { a: 123 }; --let spreadObj = __assign({}, obj); -+let spreadObj = { ...obj }; - spreadObj.a; // error 'a' is not in {} \ No newline at end of file + let c = new C(); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadNegativeParse.js b/testdata/baselines/reference/submodule/conformance/objectSpreadNegativeParse.js index 3a066bd9fc..f714a7a92a 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadNegativeParse.js +++ b/testdata/baselines/reference/submodule/conformance/objectSpreadNegativeParse.js @@ -8,8 +8,19 @@ let o10 = { ...get x() { return 12; }}; //// [objectSpreadNegativeParse.js] -let o7 = { ...o ? : }; -let o8 = { ... * o }; -let o9 = { ...matchMedia() }, {}; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +let o7 = __assign({}, o ? : ); +let o8 = __assign({}, * o); +let o9 = __assign({}, matchMedia()), {}; ; -let o10 = { ...get, x() { return 12; } }; +let o10 = __assign(__assign({}, get), { x() { return 12; } }); diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadNegativeParse.js.diff b/testdata/baselines/reference/submodule/conformance/objectSpreadNegativeParse.js.diff deleted file mode 100644 index ef137c3bcc..0000000000 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadNegativeParse.js.diff +++ /dev/null @@ -1,26 +0,0 @@ ---- old.objectSpreadNegativeParse.js -+++ new.objectSpreadNegativeParse.js -@@= skipped -7, +7 lines =@@ - - - //// [objectSpreadNegativeParse.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --let o7 = __assign({}, o ? : ); --let o8 = __assign({}, * o); --let o9 = __assign({}, matchMedia()), {}; -+let o7 = { ...o ? : }; -+let o8 = { ... * o }; -+let o9 = { ...matchMedia() }, {}; - ; --let o10 = __assign(__assign({}, get), { x() { return 12; } }); -+let o10 = { ...get, x() { return 12; } }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedComplexity.js b/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedComplexity.js index 6f87e8f97b..9628551740 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedComplexity.js +++ b/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedComplexity.js @@ -87,86 +87,75 @@ function f(cnd: Record){ } //// [objectSpreadRepeatedComplexity.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; function f(cnd) { // Type is a union of 2^(n-1) members, where n is the number of spread objects - return { - // Without this one, it collapses to {} ? - ...(cnd[1] && - cnd[2] && { - prop0: 0, - }), - // With one prop each, it collapses to a single object (#34853?) - ...(cnd[3] && { - prop3a: 1, - prop3b: 1, - }), - ...(cnd[4] && { - prop4a: 1, - prop4b: 1, - }), - ...(cnd[5] && { - prop5a: 1, - prop5b: 1, - }), - ...(cnd[6] && { - prop6a: 1, - prop6b: 1, - }), - ...(cnd[7] && { - prop7a: 1, - prop7b: 1, - }), - ...(cnd[8] && { - prop8a: 1, - prop8b: 1, - }), - ...(cnd[9] && { - prop9a: 1, - prop9b: 1, - }), - ...(cnd[10] && { - prop10a: 1, - prop10b: 1, - }), - ...(cnd[11] && { - prop11a: 1, - prop11b: 1, - }), - ...(cnd[12] && { - prop12a: 1, - prop12b: 1, - }), - ...(cnd[13] && { - prop13a: 1, - prop13b: 1, - }), - ...(cnd[14] && { - prop14a: 1, - prop14b: 1, - }), - ...(cnd[15] && { - prop15a: 1, - prop15b: 1, - }), - ...(cnd[16] && { - prop16a: 1, - prop16b: 1, - }), - ...(cnd[17] && { - prop17a: 1, - prop17b: 1, - }), - ...(cnd[18] && { - prop18a: 1, - prop18b: 1, - }), - ...(cnd[19] && { - prop19a: 1, - prop19b: 1, - }), - ...(cnd[20] && { - prop20a: 1, - prop20b: 1, - }), - }; + return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, (cnd[1] && + cnd[2] && { + prop0: 0, + })), (cnd[3] && { + prop3a: 1, + prop3b: 1, + })), (cnd[4] && { + prop4a: 1, + prop4b: 1, + })), (cnd[5] && { + prop5a: 1, + prop5b: 1, + })), (cnd[6] && { + prop6a: 1, + prop6b: 1, + })), (cnd[7] && { + prop7a: 1, + prop7b: 1, + })), (cnd[8] && { + prop8a: 1, + prop8b: 1, + })), (cnd[9] && { + prop9a: 1, + prop9b: 1, + })), (cnd[10] && { + prop10a: 1, + prop10b: 1, + })), (cnd[11] && { + prop11a: 1, + prop11b: 1, + })), (cnd[12] && { + prop12a: 1, + prop12b: 1, + })), (cnd[13] && { + prop13a: 1, + prop13b: 1, + })), (cnd[14] && { + prop14a: 1, + prop14b: 1, + })), (cnd[15] && { + prop15a: 1, + prop15b: 1, + })), (cnd[16] && { + prop16a: 1, + prop16b: 1, + })), (cnd[17] && { + prop17a: 1, + prop17b: 1, + })), (cnd[18] && { + prop18a: 1, + prop18b: 1, + })), (cnd[19] && { + prop19a: 1, + prop19b: 1, + })), (cnd[20] && { + prop20a: 1, + prop20b: 1, + })); } diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedComplexity.js.diff b/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedComplexity.js.diff index 5f5ac75633..6ead0d08b3 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedComplexity.js.diff +++ b/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedComplexity.js.diff @@ -5,155 +5,6 @@ //// [objectSpreadRepeatedComplexity.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - function f(cnd) { - // Type is a union of 2^(n-1) members, where n is the number of spread objects -- return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, (cnd[1] && -- cnd[2] && { -- prop0: 0, -- })), (cnd[3] && { -- prop3a: 1, -- prop3b: 1, -- })), (cnd[4] && { -- prop4a: 1, -- prop4b: 1, -- })), (cnd[5] && { -- prop5a: 1, -- prop5b: 1, -- })), (cnd[6] && { -- prop6a: 1, -- prop6b: 1, -- })), (cnd[7] && { -- prop7a: 1, -- prop7b: 1, -- })), (cnd[8] && { -- prop8a: 1, -- prop8b: 1, -- })), (cnd[9] && { -- prop9a: 1, -- prop9b: 1, -- })), (cnd[10] && { -- prop10a: 1, -- prop10b: 1, -- })), (cnd[11] && { -- prop11a: 1, -- prop11b: 1, -- })), (cnd[12] && { -- prop12a: 1, -- prop12b: 1, -- })), (cnd[13] && { -- prop13a: 1, -- prop13b: 1, -- })), (cnd[14] && { -- prop14a: 1, -- prop14b: 1, -- })), (cnd[15] && { -- prop15a: 1, -- prop15b: 1, -- })), (cnd[16] && { -- prop16a: 1, -- prop16b: 1, -- })), (cnd[17] && { -- prop17a: 1, -- prop17b: 1, -- })), (cnd[18] && { -- prop18a: 1, -- prop18b: 1, -- })), (cnd[19] && { -- prop19a: 1, -- prop19b: 1, -- })), (cnd[20] && { -- prop20a: 1, -- prop20b: 1, -- })); -+ return { -+ // Without this one, it collapses to {} ? -+ ...(cnd[1] && -+ cnd[2] && { -+ prop0: 0, -+ }), -+ // With one prop each, it collapses to a single object (#34853?) -+ ...(cnd[3] && { -+ prop3a: 1, -+ prop3b: 1, -+ }), -+ ...(cnd[4] && { -+ prop4a: 1, -+ prop4b: 1, -+ }), -+ ...(cnd[5] && { -+ prop5a: 1, -+ prop5b: 1, -+ }), -+ ...(cnd[6] && { -+ prop6a: 1, -+ prop6b: 1, -+ }), -+ ...(cnd[7] && { -+ prop7a: 1, -+ prop7b: 1, -+ }), -+ ...(cnd[8] && { -+ prop8a: 1, -+ prop8b: 1, -+ }), -+ ...(cnd[9] && { -+ prop9a: 1, -+ prop9b: 1, -+ }), -+ ...(cnd[10] && { -+ prop10a: 1, -+ prop10b: 1, -+ }), -+ ...(cnd[11] && { -+ prop11a: 1, -+ prop11b: 1, -+ }), -+ ...(cnd[12] && { -+ prop12a: 1, -+ prop12b: 1, -+ }), -+ ...(cnd[13] && { -+ prop13a: 1, -+ prop13b: 1, -+ }), -+ ...(cnd[14] && { -+ prop14a: 1, -+ prop14b: 1, -+ }), -+ ...(cnd[15] && { -+ prop15a: 1, -+ prop15b: 1, -+ }), -+ ...(cnd[16] && { -+ prop16a: 1, -+ prop16b: 1, -+ }), -+ ...(cnd[17] && { -+ prop17a: 1, -+ prop17b: 1, -+ }), -+ ...(cnd[18] && { -+ prop18a: 1, -+ prop18b: 1, -+ }), -+ ...(cnd[19] && { -+ prop19a: 1, -+ prop19b: 1, -+ }), -+ ...(cnd[20] && { -+ prop20a: 1, -+ prop20b: 1, -+ }), -+ }; - } \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedNullCheckPerf.js b/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedNullCheckPerf.js index 12503cc4f7..e852ae60d2 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedNullCheckPerf.js +++ b/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedNullCheckPerf.js @@ -64,34 +64,18 @@ function parseWithSpread(config: Record): Props { parseWithSpread({ a: 1, b: 2, z: 26 }) //// [objectSpreadRepeatedNullCheckPerf.js] -function parseWithSpread(config) { - return { - ...config.a !== undefined && { a: config.a.toString() }, - ...config.b !== undefined && { b: config.b.toString() }, - ...config.c !== undefined && { c: config.c.toString() }, - ...config.d !== undefined && { d: config.d.toString() }, - ...config.e !== undefined && { e: config.e.toString() }, - ...config.f !== undefined && { f: config.f.toString() }, - ...config.g !== undefined && { g: config.g.toString() }, - ...config.h !== undefined && { h: config.h.toString() }, - ...config.i !== undefined && { i: config.i.toString() }, - ...config.j !== undefined && { j: config.j.toString() }, - ...config.k !== undefined && { k: config.k.toString() }, - ...config.l !== undefined && { l: config.l.toString() }, - ...config.m !== undefined && { m: config.m.toString() }, - ...config.n !== undefined && { n: config.n.toString() }, - ...config.o !== undefined && { o: config.o.toString() }, - ...config.p !== undefined && { p: config.p.toString() }, - ...config.q !== undefined && { q: config.q.toString() }, - ...config.r !== undefined && { r: config.r.toString() }, - ...config.s !== undefined && { s: config.s.toString() }, - ...config.t !== undefined && { t: config.t.toString() }, - ...config.u !== undefined && { u: config.u.toString() }, - ...config.v !== undefined && { v: config.v.toString() }, - ...config.w !== undefined && { w: config.w.toString() }, - ...config.x !== undefined && { x: config.x.toString() }, - ...config.y !== undefined && { y: config.y.toString() }, - ...config.z !== undefined && { z: config.z.toString() } +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; }; + return __assign.apply(this, arguments); +}; +function parseWithSpread(config) { + return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, config.a !== undefined && { a: config.a.toString() }), config.b !== undefined && { b: config.b.toString() }), config.c !== undefined && { c: config.c.toString() }), config.d !== undefined && { d: config.d.toString() }), config.e !== undefined && { e: config.e.toString() }), config.f !== undefined && { f: config.f.toString() }), config.g !== undefined && { g: config.g.toString() }), config.h !== undefined && { h: config.h.toString() }), config.i !== undefined && { i: config.i.toString() }), config.j !== undefined && { j: config.j.toString() }), config.k !== undefined && { k: config.k.toString() }), config.l !== undefined && { l: config.l.toString() }), config.m !== undefined && { m: config.m.toString() }), config.n !== undefined && { n: config.n.toString() }), config.o !== undefined && { o: config.o.toString() }), config.p !== undefined && { p: config.p.toString() }), config.q !== undefined && { q: config.q.toString() }), config.r !== undefined && { r: config.r.toString() }), config.s !== undefined && { s: config.s.toString() }), config.t !== undefined && { t: config.t.toString() }), config.u !== undefined && { u: config.u.toString() }), config.v !== undefined && { v: config.v.toString() }), config.w !== undefined && { w: config.w.toString() }), config.x !== undefined && { x: config.x.toString() }), config.y !== undefined && { y: config.y.toString() }), config.z !== undefined && { z: config.z.toString() }); } parseWithSpread({ a: 1, b: 2, z: 26 }); diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedNullCheckPerf.js.diff b/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedNullCheckPerf.js.diff index 64d6e7e727..c3ddfb3cb3 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedNullCheckPerf.js.diff +++ b/testdata/baselines/reference/submodule/conformance/objectSpreadRepeatedNullCheckPerf.js.diff @@ -5,46 +5,6 @@ //// [objectSpreadRepeatedNullCheckPerf.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - function parseWithSpread(config) { -- return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, config.a !== undefined && { a: config.a.toString() }), config.b !== undefined && { b: config.b.toString() }), config.c !== undefined && { c: config.c.toString() }), config.d !== undefined && { d: config.d.toString() }), config.e !== undefined && { e: config.e.toString() }), config.f !== undefined && { f: config.f.toString() }), config.g !== undefined && { g: config.g.toString() }), config.h !== undefined && { h: config.h.toString() }), config.i !== undefined && { i: config.i.toString() }), config.j !== undefined && { j: config.j.toString() }), config.k !== undefined && { k: config.k.toString() }), config.l !== undefined && { l: config.l.toString() }), config.m !== undefined && { m: config.m.toString() }), config.n !== undefined && { n: config.n.toString() }), config.o !== undefined && { o: config.o.toString() }), config.p !== undefined && { p: config.p.toString() }), config.q !== undefined && { q: config.q.toString() }), config.r !== undefined && { r: config.r.toString() }), config.s !== undefined && { s: config.s.toString() }), config.t !== undefined && { t: config.t.toString() }), config.u !== undefined && { u: config.u.toString() }), config.v !== undefined && { v: config.v.toString() }), config.w !== undefined && { w: config.w.toString() }), config.x !== undefined && { x: config.x.toString() }), config.y !== undefined && { y: config.y.toString() }), config.z !== undefined && { z: config.z.toString() }); -+ return { -+ ...config.a !== undefined && { a: config.a.toString() }, -+ ...config.b !== undefined && { b: config.b.toString() }, -+ ...config.c !== undefined && { c: config.c.toString() }, -+ ...config.d !== undefined && { d: config.d.toString() }, -+ ...config.e !== undefined && { e: config.e.toString() }, -+ ...config.f !== undefined && { f: config.f.toString() }, -+ ...config.g !== undefined && { g: config.g.toString() }, -+ ...config.h !== undefined && { h: config.h.toString() }, -+ ...config.i !== undefined && { i: config.i.toString() }, -+ ...config.j !== undefined && { j: config.j.toString() }, -+ ...config.k !== undefined && { k: config.k.toString() }, -+ ...config.l !== undefined && { l: config.l.toString() }, -+ ...config.m !== undefined && { m: config.m.toString() }, -+ ...config.n !== undefined && { n: config.n.toString() }, -+ ...config.o !== undefined && { o: config.o.toString() }, -+ ...config.p !== undefined && { p: config.p.toString() }, -+ ...config.q !== undefined && { q: config.q.toString() }, -+ ...config.r !== undefined && { r: config.r.toString() }, -+ ...config.s !== undefined && { s: config.s.toString() }, -+ ...config.t !== undefined && { t: config.t.toString() }, -+ ...config.u !== undefined && { u: config.u.toString() }, -+ ...config.v !== undefined && { v: config.v.toString() }, -+ ...config.w !== undefined && { w: config.w.toString() }, -+ ...config.x !== undefined && { x: config.x.toString() }, -+ ...config.y !== undefined && { y: config.y.toString() }, -+ ...config.z !== undefined && { z: config.z.toString() } -+ }; - } - parseWithSpread({ a: 1, b: 2, z: 26 }); \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadStrictNull.js b/testdata/baselines/reference/submodule/conformance/objectSpreadStrictNull.js index 9a3eb03e6c..4264a5a5da 100644 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadStrictNull.js +++ b/testdata/baselines/reference/submodule/conformance/objectSpreadStrictNull.js @@ -47,23 +47,34 @@ function g(fields: Fields, partialFields: Partial, nearlyPartialFields: //// [objectSpreadStrictNull.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; function f(definiteBoolean, definiteString, optionalString, optionalNumber, undefinedString, undefinedNumber) { // optional - let optionalUnionStops = { ...definiteBoolean, ...definiteString, ...optionalNumber }; - let optionalUnionDuplicates = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; - let allOptional = { ...optionalString, ...optionalNumber }; + let optionalUnionStops = __assign(__assign(__assign({}, definiteBoolean), definiteString), optionalNumber); + let optionalUnionDuplicates = __assign(__assign(__assign(__assign({}, definiteBoolean), definiteString), optionalString), optionalNumber); + let allOptional = __assign(__assign({}, optionalString), optionalNumber); // undefined - let undefinedUnionStops = { ...definiteBoolean, ...definiteString, ...undefinedNumber }; - let undefinedUnionDuplicates = { ...definiteBoolean, ...definiteString, ...undefinedString, ...undefinedNumber }; - let allUndefined = { ...undefinedString, ...undefinedNumber }; - let undefinedWithOptionalContinues = { ...definiteBoolean, ...undefinedString, ...optionalNumber }; + let undefinedUnionStops = __assign(__assign(__assign({}, definiteBoolean), definiteString), undefinedNumber); + let undefinedUnionDuplicates = __assign(__assign(__assign(__assign({}, definiteBoolean), definiteString), undefinedString), undefinedNumber); + let allUndefined = __assign(__assign({}, undefinedString), undefinedNumber); + let undefinedWithOptionalContinues = __assign(__assign(__assign({}, definiteBoolean), undefinedString), optionalNumber); } const m = { title: "The Matrix", yearReleased: 1999 }; // should error here because title: undefined is not assignable to string -const x = { ...m, title: undefined }; +const x = __assign(__assign({}, m), { title: undefined }); function g(fields, partialFields, nearlyPartialFields) { // ok, undefined is stripped from optional properties when spread - fields = { ...fields, ...partialFields }; + fields = __assign(__assign({}, fields), partialFields); // error: not optional, undefined remains - fields = { ...fields, ...nearlyPartialFields }; + fields = __assign(__assign({}, fields), nearlyPartialFields); } diff --git a/testdata/baselines/reference/submodule/conformance/objectSpreadStrictNull.js.diff b/testdata/baselines/reference/submodule/conformance/objectSpreadStrictNull.js.diff deleted file mode 100644 index 475d62eaea..0000000000 --- a/testdata/baselines/reference/submodule/conformance/objectSpreadStrictNull.js.diff +++ /dev/null @@ -1,47 +0,0 @@ ---- old.objectSpreadStrictNull.js -+++ new.objectSpreadStrictNull.js -@@= skipped -46, +46 lines =@@ - - - //// [objectSpreadStrictNull.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - function f(definiteBoolean, definiteString, optionalString, optionalNumber, undefinedString, undefinedNumber) { - // optional -- let optionalUnionStops = __assign(__assign(__assign({}, definiteBoolean), definiteString), optionalNumber); -- let optionalUnionDuplicates = __assign(__assign(__assign(__assign({}, definiteBoolean), definiteString), optionalString), optionalNumber); -- let allOptional = __assign(__assign({}, optionalString), optionalNumber); -+ let optionalUnionStops = { ...definiteBoolean, ...definiteString, ...optionalNumber }; -+ let optionalUnionDuplicates = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; -+ let allOptional = { ...optionalString, ...optionalNumber }; - // undefined -- let undefinedUnionStops = __assign(__assign(__assign({}, definiteBoolean), definiteString), undefinedNumber); -- let undefinedUnionDuplicates = __assign(__assign(__assign(__assign({}, definiteBoolean), definiteString), undefinedString), undefinedNumber); -- let allUndefined = __assign(__assign({}, undefinedString), undefinedNumber); -- let undefinedWithOptionalContinues = __assign(__assign(__assign({}, definiteBoolean), undefinedString), optionalNumber); -+ let undefinedUnionStops = { ...definiteBoolean, ...definiteString, ...undefinedNumber }; -+ let undefinedUnionDuplicates = { ...definiteBoolean, ...definiteString, ...undefinedString, ...undefinedNumber }; -+ let allUndefined = { ...undefinedString, ...undefinedNumber }; -+ let undefinedWithOptionalContinues = { ...definiteBoolean, ...undefinedString, ...optionalNumber }; - } - const m = { title: "The Matrix", yearReleased: 1999 }; - // should error here because title: undefined is not assignable to string --const x = __assign(__assign({}, m), { title: undefined }); -+const x = { ...m, title: undefined }; - function g(fields, partialFields, nearlyPartialFields) { - // ok, undefined is stripped from optional properties when spread -- fields = __assign(__assign({}, fields), partialFields); -+ fields = { ...fields, ...partialFields }; - // error: not optional, undefined remains -- fields = __assign(__assign({}, fields), nearlyPartialFields); -+ fields = { ...fields, ...nearlyPartialFields }; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/privateNameAndObjectRestSpread.js b/testdata/baselines/reference/submodule/conformance/privateNameAndObjectRestSpread.js index b0d25e6476..e41c5b451c 100644 --- a/testdata/baselines/reference/submodule/conformance/privateNameAndObjectRestSpread.js +++ b/testdata/baselines/reference/submodule/conformance/privateNameAndObjectRestSpread.js @@ -19,17 +19,28 @@ class C { } //// [privateNameAndObjectRestSpread.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; class C { #prop = 1; static #propStatic = 1; method(other) { - const obj = { ...other }; + const obj = Object.assign({}, other); obj.#prop; - const { ...rest } = other; + const rest = __rest(other, []); rest.#prop; - const statics = { ...C }; + const statics = Object.assign({}, C); statics.#propStatic; - const { ...sRest } = C; + const sRest = __rest(C, []); sRest.#propStatic; } } diff --git a/testdata/baselines/reference/submodule/conformance/privateNameAndObjectRestSpread.js.diff b/testdata/baselines/reference/submodule/conformance/privateNameAndObjectRestSpread.js.diff index 0eb7ef43cc..d22ac614b7 100644 --- a/testdata/baselines/reference/submodule/conformance/privateNameAndObjectRestSpread.js.diff +++ b/testdata/baselines/reference/submodule/conformance/privateNameAndObjectRestSpread.js.diff @@ -10,17 +10,13 @@ - if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); - return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); -}; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) +@@= skipped -17, +11 lines =@@ + } + return t; + }; -var _a, _C_prop, _C_propStatic; class C { - constructor() { @@ -29,21 +25,19 @@ + #prop = 1; + static #propStatic = 1; method(other) { -- const obj = Object.assign({}, other); + const obj = Object.assign({}, other); - __classPrivateFieldGet(obj, _C_prop, "f"); -- const rest = __rest(other, []); ++ obj.#prop; + const rest = __rest(other, []); - __classPrivateFieldGet(rest, _C_prop, "f"); - const statics = Object.assign({}, _a); - __classPrivateFieldGet(statics, _a, "f", _C_propStatic); - const sRest = __rest(_a, []); - __classPrivateFieldGet(sRest, _a, "f", _C_propStatic); -+ const obj = { ...other }; -+ obj.#prop; -+ const { ...rest } = other; + rest.#prop; -+ const statics = { ...C }; ++ const statics = Object.assign({}, C); + statics.#propStatic; -+ const { ...sRest } = C; ++ const sRest = __rest(C, []); + sRest.#propStatic; } } diff --git a/testdata/baselines/reference/submodule/conformance/privateWriteOnlyAccessorRead.js b/testdata/baselines/reference/submodule/conformance/privateWriteOnlyAccessorRead.js index 7544d3f1b3..c43b2bbe51 100644 --- a/testdata/baselines/reference/submodule/conformance/privateWriteOnlyAccessorRead.js +++ b/testdata/baselines/reference/submodule/conformance/privateWriteOnlyAccessorRead.js @@ -37,23 +37,33 @@ new Test().m(); //// [privateWriteOnlyAccessorRead.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; class Test { set #value(v) { } set #valueRest(v) { } set #valueOne(v) { } set #valueCompound(v) { } m() { + var _a, _b; const foo = { bar: 1 }; console.log(this.#value); // error this.#value = { foo }; // ok this.#value = { foo }; // ok this.#value.foo = foo; // error ({ o: this.#value } = { o: { foo } }); //ok - ({ ...this.#value } = { foo }); //ok + (_a = { foo }, this.#value = __rest(_a, [])); //ok ({ foo: this.#value.foo } = { foo }); //error - ({ - foo: { ...this.#value.foo }, - } = { foo }); //error + (_b = { foo }, this.#value.foo = __rest(_b.foo, [])); //error let r = { o: this.#value }; //error [this.#valueOne, ...this.#valueRest] = [1, 2, 3]; let arr = [ diff --git a/testdata/baselines/reference/submodule/conformance/privateWriteOnlyAccessorRead.js.diff b/testdata/baselines/reference/submodule/conformance/privateWriteOnlyAccessorRead.js.diff index a86464eb92..ffefeacace 100644 --- a/testdata/baselines/reference/submodule/conformance/privateWriteOnlyAccessorRead.js.diff +++ b/testdata/baselines/reference/submodule/conformance/privateWriteOnlyAccessorRead.js.diff @@ -15,17 +15,13 @@ - if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); - return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; -}; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) +@@= skipped -22, +11 lines =@@ + } + return t; + }; -var _Test_instances, _Test_value_set, _Test_valueRest_set, _Test_valueOne_set, _Test_valueCompound_set; class Test { - constructor() { @@ -37,6 +33,7 @@ + set #valueCompound(v) { } m() { - var _a, _b, _c, _d; ++ var _a, _b; const foo = { bar: 1 }; - console.log(__classPrivateFieldGet(this, _Test_instances, "a")); // error - __classPrivateFieldSet(this, _Test_instances, { foo }, "a", _Test_value_set); // ok @@ -53,11 +50,9 @@ + this.#value = { foo }; // ok + this.#value.foo = foo; // error + ({ o: this.#value } = { o: { foo } }); //ok -+ ({ ...this.#value } = { foo }); //ok ++ (_a = { foo }, this.#value = __rest(_a, [])); //ok + ({ foo: this.#value.foo } = { foo }); //error -+ ({ -+ foo: { ...this.#value.foo }, -+ } = { foo }); //error ++ (_b = { foo }, this.#value.foo = __rest(_b.foo, [])); //error + let r = { o: this.#value }; //error + [this.#valueOne, ...this.#valueRest] = [1, 2, 3]; let arr = [ diff --git a/testdata/baselines/reference/submodule/conformance/propertyAccessChain.3.js b/testdata/baselines/reference/submodule/conformance/propertyAccessChain.3.js index b7ac876bcf..348c97328e 100644 --- a/testdata/baselines/reference/submodule/conformance/propertyAccessChain.3.js +++ b/testdata/baselines/reference/submodule/conformance/propertyAccessChain.3.js @@ -32,6 +32,18 @@ for (obj?.a.b of []); //// [propertyAccessChain.3.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a, _b; (obj === null || obj === void 0 ? void 0 : obj.a)++; (obj === null || obj === void 0 ? void 0 : obj.a.b)++; (obj === null || obj === void 0 ? void 0 : obj.a)--; @@ -54,7 +66,7 @@ for (obj === null || obj === void 0 ? void 0 : obj.a.b of []) ; ({ a: obj === null || obj === void 0 ? void 0 : obj.a } = { a: 1 }); ({ a: obj === null || obj === void 0 ? void 0 : obj.a.b } = { a: 1 }); -({ ...obj === null || obj === void 0 ? void 0 : obj.a } = { a: 1 }); -({ ...obj === null || obj === void 0 ? void 0 : obj.a.b } = { a: 1 }); +(_a = { a: 1 }, (obj === null || obj === void 0 ? void 0 : obj.a) = __rest(_a, [])); +(_b = { a: 1 }, (obj === null || obj === void 0 ? void 0 : obj.a.b) = __rest(_b, [])); [...obj === null || obj === void 0 ? void 0 : obj.a] = []; [...obj === null || obj === void 0 ? void 0 : obj.a.b] = []; diff --git a/testdata/baselines/reference/submodule/conformance/propertyAccessChain.3.js.diff b/testdata/baselines/reference/submodule/conformance/propertyAccessChain.3.js.diff index 063462ee25..840ceecf8c 100644 --- a/testdata/baselines/reference/submodule/conformance/propertyAccessChain.3.js.diff +++ b/testdata/baselines/reference/submodule/conformance/propertyAccessChain.3.js.diff @@ -5,21 +5,18 @@ //// [propertyAccessChain.3.js] -"use strict"; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) +@@= skipped -12, +11 lines =@@ + } + return t; + }; ++var _a, _b; (obj === null || obj === void 0 ? void 0 : obj.a)++; (obj === null || obj === void 0 ? void 0 : obj.a.b)++; (obj === null || obj === void 0 ? void 0 : obj.a)--; -@@= skipped -20, +8 lines =@@ +@@= skipped -8, +9 lines =@@ ++(obj === null || obj === void 0 ? void 0 : obj.a.b); --(obj === null || obj === void 0 ? void 0 : obj.a); --(obj === null || obj === void 0 ? void 0 : obj.a.b); @@ -40,7 +37,7 @@ ({ a: obj === null || obj === void 0 ? void 0 : obj.a.b } = { a: 1 }); -(obj === null || obj === void 0 ? void 0 : obj.a = __rest({ a: 1 }, [])); -(obj === null || obj === void 0 ? void 0 : obj.a.b = __rest({ a: 1 }, [])); -+({ ...obj === null || obj === void 0 ? void 0 : obj.a } = { a: 1 }); -+({ ...obj === null || obj === void 0 ? void 0 : obj.a.b } = { a: 1 }); ++(_a = { a: 1 }, (obj === null || obj === void 0 ? void 0 : obj.a) = __rest(_a, [])); ++(_b = { a: 1 }, (obj === null || obj === void 0 ? void 0 : obj.a.b) = __rest(_b, [])); [...obj === null || obj === void 0 ? void 0 : obj.a] = []; [...obj === null || obj === void 0 ? void 0 : obj.a.b] = []; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/restPropertyWithBindingPattern.js b/testdata/baselines/reference/submodule/conformance/restPropertyWithBindingPattern.js index 88aaaba193..0128e27665 100644 --- a/testdata/baselines/reference/submodule/conformance/restPropertyWithBindingPattern.js +++ b/testdata/baselines/reference/submodule/conformance/restPropertyWithBindingPattern.js @@ -7,7 +7,19 @@ ({...([])} = {}); //// [restPropertyWithBindingPattern.js] -({ ...{} } = {}); -({ ...({}) } = {}); -({ ...[] } = {}); -({ ...([]) } = {}); +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a, _b, _c, _d, _e, _f; +(_a = {}, _b = __rest(_a, [])); +(_c = {}, ({}) = __rest(_c, [])); +(_d = {}, _e = __rest(_d, [])); +(_f = {}, ([]) = __rest(_f, [])); diff --git a/testdata/baselines/reference/submodule/conformance/restPropertyWithBindingPattern.js.diff b/testdata/baselines/reference/submodule/conformance/restPropertyWithBindingPattern.js.diff index 1b41ab3546..2c92fc6e8c 100644 --- a/testdata/baselines/reference/submodule/conformance/restPropertyWithBindingPattern.js.diff +++ b/testdata/baselines/reference/submodule/conformance/restPropertyWithBindingPattern.js.diff @@ -1,26 +1,16 @@ --- old.restPropertyWithBindingPattern.js +++ new.restPropertyWithBindingPattern.js -@@= skipped -6, +6 lines =@@ - ({...([])} = {}); - - //// [restPropertyWithBindingPattern.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; +@@= skipped -17, +17 lines =@@ + } + return t; + }; -var _a, _b; -(_a = __rest({}, [])); -(({}) = __rest({}, [])); -(_b = __rest({}, [])); -(([]) = __rest({}, [])); -+({ ...{} } = {}); -+({ ...({}) } = {}); -+({ ...[] } = {}); -+({ ...([]) } = {}); \ No newline at end of file ++var _a, _b, _c, _d, _e, _f; ++(_a = {}, _b = __rest(_a, [])); ++(_c = {}, ({}) = __rest(_c, [])); ++(_d = {}, _e = __rest(_d, [])); ++(_f = {}, ([]) = __rest(_f, [])); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/spreadContextualTypedBindingPattern.js b/testdata/baselines/reference/submodule/conformance/spreadContextualTypedBindingPattern.js index 8bc0a1a0cc..fa896d2877 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadContextualTypedBindingPattern.js +++ b/testdata/baselines/reference/submodule/conformance/spreadContextualTypedBindingPattern.js @@ -15,5 +15,16 @@ const { naam, age } = {...bob, ...alice} //// [spreadContextualTypedBindingPattern.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; // [ts] Initializer provides no value for this binding element and the binding element has no default value. -const { naam, age } = { ...bob, ...alice }; +const { naam, age } = __assign(__assign({}, bob), alice); diff --git a/testdata/baselines/reference/submodule/conformance/spreadContextualTypedBindingPattern.js.diff b/testdata/baselines/reference/submodule/conformance/spreadContextualTypedBindingPattern.js.diff deleted file mode 100644 index 09523e5bf6..0000000000 --- a/testdata/baselines/reference/submodule/conformance/spreadContextualTypedBindingPattern.js.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.spreadContextualTypedBindingPattern.js -+++ new.spreadContextualTypedBindingPattern.js -@@= skipped -14, +14 lines =@@ - - - //// [spreadContextualTypedBindingPattern.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - // [ts] Initializer provides no value for this binding element and the binding element has no default value. --const { naam, age } = __assign(__assign({}, bob), alice); -+const { naam, age } = { ...bob, ...alice }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/spreadDuplicate.js b/testdata/baselines/reference/submodule/conformance/spreadDuplicate.js index c51f494b5f..22c70bbd70 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadDuplicate.js +++ b/testdata/baselines/reference/submodule/conformance/spreadDuplicate.js @@ -22,14 +22,25 @@ let d2 = { a: 123, ...(t ? d : {}) }; // string | number //// [spreadDuplicate.js] -let a1 = { a: 123, ...a }; // string (Error) -let b1 = { a: 123, ...b }; // string | number -let c1 = { a: 123, ...c }; // string | undefined (Error) -let d1 = { a: 123, ...d }; // string | number -let a2 = { a: 123, ...(t ? a : {}) }; // string | number -let b2 = { a: 123, ...(t ? b : {}) }; // string | number -let c2 = { a: 123, ...(t ? c : {}) }; // string | number -let d2 = { a: 123, ...(t ? d : {}) }; // string | number +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +let a1 = __assign({ a: 123 }, a); // string (Error) +let b1 = __assign({ a: 123 }, b); // string | number +let c1 = __assign({ a: 123 }, c); // string | undefined (Error) +let d1 = __assign({ a: 123 }, d); // string | number +let a2 = __assign({ a: 123 }, (t ? a : {})); // string | number +let b2 = __assign({ a: 123 }, (t ? b : {})); // string | number +let c2 = __assign({ a: 123 }, (t ? c : {})); // string | number +let d2 = __assign({ a: 123 }, (t ? d : {})); // string | number //// [spreadDuplicate.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/spreadDuplicate.js.diff b/testdata/baselines/reference/submodule/conformance/spreadDuplicate.js.diff index 16c4afe709..0f68da2259 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadDuplicate.js.diff +++ b/testdata/baselines/reference/submodule/conformance/spreadDuplicate.js.diff @@ -6,33 +6,10 @@ //// [spreadDuplicate.js] -"use strict"; -// Repro from #44438 --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --let a1 = __assign({ a: 123 }, a); // string (Error) --let b1 = __assign({ a: 123 }, b); // string | number --let c1 = __assign({ a: 123 }, c); // string | undefined (Error) --let d1 = __assign({ a: 123 }, d); // string | number --let a2 = __assign({ a: 123 }, (t ? a : {})); // string | number --let b2 = __assign({ a: 123 }, (t ? b : {})); // string | number --let c2 = __assign({ a: 123 }, (t ? c : {})); // string | number --let d2 = __assign({ a: 123 }, (t ? d : {})); // string | number -+let a1 = { a: 123, ...a }; // string (Error) -+let b1 = { a: 123, ...b }; // string | number -+let c1 = { a: 123, ...c }; // string | undefined (Error) -+let d1 = { a: 123, ...d }; // string | number -+let a2 = { a: 123, ...(t ? a : {}) }; // string | number -+let b2 = { a: 123, ...(t ? b : {}) }; // string | number -+let c2 = { a: 123, ...(t ? c : {}) }; // string | number -+let d2 = { a: 123, ...(t ? d : {}) }; // string | number + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -24, +22 lines =@@ //// [spreadDuplicate.d.ts] @@ -40,7 +17,7 @@ declare let a: { a: string; }; -@@= skipped -39, +27 lines =@@ +@@= skipped -15, +16 lines =@@ declare let t: boolean; declare let a1: { a: string; diff --git a/testdata/baselines/reference/submodule/conformance/spreadDuplicateExact.js b/testdata/baselines/reference/submodule/conformance/spreadDuplicateExact.js index 5037ddc04b..d1e0079cb8 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadDuplicateExact.js +++ b/testdata/baselines/reference/submodule/conformance/spreadDuplicateExact.js @@ -22,14 +22,25 @@ let d2 = { a: 123, ...(t ? d : {}) }; // string | number | undefined //// [spreadDuplicateExact.js] -let a1 = { a: 123, ...a }; // string (Error) -let b1 = { a: 123, ...b }; // string | number -let c1 = { a: 123, ...c }; // string | undefined (Error) -let d1 = { a: 123, ...d }; // string | number | undefined -let a2 = { a: 123, ...(t ? a : {}) }; // string | number -let b2 = { a: 123, ...(t ? b : {}) }; // string | number -let c2 = { a: 123, ...(t ? c : {}) }; // string | number | undefined -let d2 = { a: 123, ...(t ? d : {}) }; // string | number | undefined +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +let a1 = __assign({ a: 123 }, a); // string (Error) +let b1 = __assign({ a: 123 }, b); // string | number +let c1 = __assign({ a: 123 }, c); // string | undefined (Error) +let d1 = __assign({ a: 123 }, d); // string | number | undefined +let a2 = __assign({ a: 123 }, (t ? a : {})); // string | number +let b2 = __assign({ a: 123 }, (t ? b : {})); // string | number +let c2 = __assign({ a: 123 }, (t ? c : {})); // string | number | undefined +let d2 = __assign({ a: 123 }, (t ? d : {})); // string | number | undefined //// [spreadDuplicateExact.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/spreadDuplicateExact.js.diff b/testdata/baselines/reference/submodule/conformance/spreadDuplicateExact.js.diff index 4ff348bd99..e966f9295f 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadDuplicateExact.js.diff +++ b/testdata/baselines/reference/submodule/conformance/spreadDuplicateExact.js.diff @@ -6,33 +6,10 @@ //// [spreadDuplicateExact.js] -"use strict"; -// Repro from #44438 --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --let a1 = __assign({ a: 123 }, a); // string (Error) --let b1 = __assign({ a: 123 }, b); // string | number --let c1 = __assign({ a: 123 }, c); // string | undefined (Error) --let d1 = __assign({ a: 123 }, d); // string | number | undefined --let a2 = __assign({ a: 123 }, (t ? a : {})); // string | number --let b2 = __assign({ a: 123 }, (t ? b : {})); // string | number --let c2 = __assign({ a: 123 }, (t ? c : {})); // string | number | undefined --let d2 = __assign({ a: 123 }, (t ? d : {})); // string | number | undefined -+let a1 = { a: 123, ...a }; // string (Error) -+let b1 = { a: 123, ...b }; // string | number -+let c1 = { a: 123, ...c }; // string | undefined (Error) -+let d1 = { a: 123, ...d }; // string | number | undefined -+let a2 = { a: 123, ...(t ? a : {}) }; // string | number -+let b2 = { a: 123, ...(t ? b : {}) }; // string | number -+let c2 = { a: 123, ...(t ? c : {}) }; // string | number | undefined -+let d2 = { a: 123, ...(t ? d : {}) }; // string | number | undefined + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -24, +22 lines =@@ //// [spreadDuplicateExact.d.ts] @@ -40,7 +17,7 @@ declare let a: { a: string; }; -@@= skipped -39, +27 lines =@@ +@@= skipped -15, +16 lines =@@ declare let t: boolean; declare let a1: { a: string; diff --git a/testdata/baselines/reference/submodule/conformance/spreadExcessProperty.js b/testdata/baselines/reference/submodule/conformance/spreadExcessProperty.js index cc60ff1cc5..19898b769e 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadExcessProperty.js +++ b/testdata/baselines/reference/submodule/conformance/spreadExcessProperty.js @@ -7,5 +7,16 @@ const a1: A = { ...extra1 }; // spread should not give excess property errors //// [spreadExcessProperty.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; const extra1 = { a: "a", b: "b", extra: "extra" }; -const a1 = { ...extra1 }; // spread should not give excess property errors +const a1 = __assign({}, extra1); // spread should not give excess property errors diff --git a/testdata/baselines/reference/submodule/conformance/spreadExcessProperty.js.diff b/testdata/baselines/reference/submodule/conformance/spreadExcessProperty.js.diff deleted file mode 100644 index 6e9d1bd670..0000000000 --- a/testdata/baselines/reference/submodule/conformance/spreadExcessProperty.js.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.spreadExcessProperty.js -+++ new.spreadExcessProperty.js -@@= skipped -6, +6 lines =@@ - - - //// [spreadExcessProperty.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - const extra1 = { a: "a", b: "b", extra: "extra" }; --const a1 = __assign({}, extra1); // spread should not give excess property errors -+const a1 = { ...extra1 }; // spread should not give excess property errors \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/spreadNonPrimitive.js b/testdata/baselines/reference/submodule/conformance/spreadNonPrimitive.js index c52fabe866..8c89051ad7 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadNonPrimitive.js +++ b/testdata/baselines/reference/submodule/conformance/spreadNonPrimitive.js @@ -6,4 +6,15 @@ const x: { a: number, b: number } = { a: 1, ...o, b: 2 }; //// [spreadNonPrimitive.js] -const x = { a: 1, ...o, b: 2 }; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +const x = __assign(__assign({ a: 1 }, o), { b: 2 }); diff --git a/testdata/baselines/reference/submodule/conformance/spreadNonPrimitive.js.diff b/testdata/baselines/reference/submodule/conformance/spreadNonPrimitive.js.diff deleted file mode 100644 index 38bd94c8a2..0000000000 --- a/testdata/baselines/reference/submodule/conformance/spreadNonPrimitive.js.diff +++ /dev/null @@ -1,19 +0,0 @@ ---- old.spreadNonPrimitive.js -+++ new.spreadNonPrimitive.js -@@= skipped -5, +5 lines =@@ - - - //// [spreadNonPrimitive.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --const x = __assign(__assign({ a: 1 }, o), { b: 2 }); -+const x = { a: 1, ...o, b: 2 }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/spreadObjectOrFalsy.js b/testdata/baselines/reference/submodule/conformance/spreadObjectOrFalsy.js index 127c238252..37e964da53 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadObjectOrFalsy.js +++ b/testdata/baselines/reference/submodule/conformance/spreadObjectOrFalsy.js @@ -54,30 +54,39 @@ class Foo { //// [spreadObjectOrFalsy.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; function f1(a) { - return { ...a }; // Error + return __assign({}, a); // Error } function f2(a) { - return { ...a }; + return __assign({}, a); } function f3(a) { - return { ...a }; // Error + return __assign({}, a); // Error } function f4(a) { - return { ...a }; + return __assign({}, a); } function f5(a) { - return { ...a }; + return __assign({}, a); } function f6(a) { - return { ...a }; + return __assign({}, a); } // Repro from #46976 function g1(a) { const { z } = a; - return { - ...z - }; + return __assign({}, z); } class Foo { data; diff --git a/testdata/baselines/reference/submodule/conformance/spreadObjectOrFalsy.js.diff b/testdata/baselines/reference/submodule/conformance/spreadObjectOrFalsy.js.diff index ad293c9e65..18d5b1d590 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadObjectOrFalsy.js.diff +++ b/testdata/baselines/reference/submodule/conformance/spreadObjectOrFalsy.js.diff @@ -5,55 +5,18 @@ //// [spreadObjectOrFalsy.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - function f1(a) { -- return __assign({}, a); // Error -+ return { ...a }; // Error - } - function f2(a) { -- return __assign({}, a); -+ return { ...a }; - } - function f3(a) { -- return __assign({}, a); // Error -+ return { ...a }; // Error - } - function f4(a) { -- return __assign({}, a); -+ return { ...a }; - } - function f5(a) { -- return __assign({}, a); -+ return { ...a }; - } - function f6(a) { -- return __assign({}, a); -+ return { ...a }; - } - // Repro from #46976 - function g1(a) { - const { z } = a; -- return __assign({}, z); -+ return { -+ ...z -+ }; + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -36, +35 lines =@@ + return __assign({}, z); } class Foo { + data; bar() { if (this.hasData()) { this.data.toLocaleLowerCase(); -@@= skipped -49, +40 lines =@@ +@@= skipped -13, +14 lines =@@ //// [spreadObjectOrFalsy.d.ts] declare function f1(a: T & undefined): any; diff --git a/testdata/baselines/reference/submodule/conformance/spreadOverwritesProperty.js b/testdata/baselines/reference/submodule/conformance/spreadOverwritesProperty.js index 172a1007dc..8a0545073a 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadOverwritesProperty.js +++ b/testdata/baselines/reference/submodule/conformance/spreadOverwritesProperty.js @@ -17,12 +17,23 @@ function h(obj: { x: number }) { //// [spreadOverwritesProperty.js] -var unused1 = { b: 1, ...ab }; -var unused2 = { ...ab, ...ab }; -var unused3 = { b: 1, ...abq }; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var unused1 = __assign({ b: 1 }, ab); +var unused2 = __assign(__assign({}, ab), ab); +var unused3 = __assign({ b: 1 }, abq); function g(obj) { - return { x: 1, ...obj }; + return __assign({ x: 1 }, obj); } function h(obj) { - return { x: 1, ...obj }; + return __assign({ x: 1 }, obj); } diff --git a/testdata/baselines/reference/submodule/conformance/spreadOverwritesProperty.js.diff b/testdata/baselines/reference/submodule/conformance/spreadOverwritesProperty.js.diff deleted file mode 100644 index 2a6a17a87b..0000000000 --- a/testdata/baselines/reference/submodule/conformance/spreadOverwritesProperty.js.diff +++ /dev/null @@ -1,31 +0,0 @@ ---- old.spreadOverwritesProperty.js -+++ new.spreadOverwritesProperty.js -@@= skipped -16, +16 lines =@@ - - - //// [spreadOverwritesProperty.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --var unused1 = __assign({ b: 1 }, ab); --var unused2 = __assign(__assign({}, ab), ab); --var unused3 = __assign({ b: 1 }, abq); -+var unused1 = { b: 1, ...ab }; -+var unused2 = { ...ab, ...ab }; -+var unused3 = { b: 1, ...abq }; - function g(obj) { -- return __assign({ x: 1 }, obj); -+ return { x: 1, ...obj }; - } - function h(obj) { -- return __assign({ x: 1 }, obj); -+ return { x: 1, ...obj }; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/spreadOverwritesPropertyStrict.js b/testdata/baselines/reference/submodule/conformance/spreadOverwritesPropertyStrict.js index f348deac6b..695bc27a44 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadOverwritesPropertyStrict.js +++ b/testdata/baselines/reference/submodule/conformance/spreadOverwritesPropertyStrict.js @@ -37,32 +37,43 @@ function m(anyoptional: { a?: any }) { //// [spreadOverwritesPropertyStrict.js] -var unused1 = { b: 1, ...ab }; // error -var unused2 = { ...ab, ...ab }; // ok, overwritten error doesn't apply to spreads -var unused3 = { b: 1, ...abq }; // ok, abq might have b: undefined -var unused4 = { ...ab, b: 1 }; // ok, we don't care that b in ab is overwritten -var unused5 = { ...abq, b: 1 }; // ok +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var unused1 = __assign({ b: 1 }, ab); // error +var unused2 = __assign(__assign({}, ab), ab); // ok, overwritten error doesn't apply to spreads +var unused3 = __assign({ b: 1 }, abq); // ok, abq might have b: undefined +var unused4 = __assign(__assign({}, ab), { b: 1 }); // ok, we don't care that b in ab is overwritten +var unused5 = __assign(__assign({}, abq), { b: 1 }); // ok function g(obj) { - return { x: 1, ...obj }; // ok, obj might have x: undefined + return __assign({ x: 1 }, obj); // ok, obj might have x: undefined } function f(obj) { - return { x: 1, ...obj }; // ok, obj might be undefined + return __assign({ x: 1 }, obj); // ok, obj might be undefined } function h(obj) { - return { x: 1, ...obj }; // error + return __assign({ x: 1 }, obj); // error } function i(b, t) { - return { command: "hi", ...(b ? t : {}) }; // ok + return __assign({ command: "hi" }, (b ? t : {})); // ok } function j() { - return { ...{ command: "hi" }, ...{ command: "bye" } }; // ok + return __assign({ command: "hi" }, { command: "bye" }); // ok } function k(t) { - return { command: "hi", ...{ spoiler: true }, spoiler2: true, ...t }; // error + return __assign(__assign(__assign({ command: "hi" }, { spoiler: true }), { spoiler2: true }), t); // error } function l(anyrequired) { - return { a: 'zzz', ...anyrequired }; // error + return __assign({ a: 'zzz' }, anyrequired); // error } function m(anyoptional) { - return { a: 'zzz', ...anyoptional }; // ok + return __assign({ a: 'zzz' }, anyoptional); // ok } diff --git a/testdata/baselines/reference/submodule/conformance/spreadOverwritesPropertyStrict.js.diff b/testdata/baselines/reference/submodule/conformance/spreadOverwritesPropertyStrict.js.diff index 8ed249cfeb..7787c37eab 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadOverwritesPropertyStrict.js.diff +++ b/testdata/baselines/reference/submodule/conformance/spreadOverwritesPropertyStrict.js.diff @@ -5,56 +5,6 @@ //// [spreadOverwritesPropertyStrict.js] -"use strict"; --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --var unused1 = __assign({ b: 1 }, ab); // error --var unused2 = __assign(__assign({}, ab), ab); // ok, overwritten error doesn't apply to spreads --var unused3 = __assign({ b: 1 }, abq); // ok, abq might have b: undefined --var unused4 = __assign(__assign({}, ab), { b: 1 }); // ok, we don't care that b in ab is overwritten --var unused5 = __assign(__assign({}, abq), { b: 1 }); // ok -+var unused1 = { b: 1, ...ab }; // error -+var unused2 = { ...ab, ...ab }; // ok, overwritten error doesn't apply to spreads -+var unused3 = { b: 1, ...abq }; // ok, abq might have b: undefined -+var unused4 = { ...ab, b: 1 }; // ok, we don't care that b in ab is overwritten -+var unused5 = { ...abq, b: 1 }; // ok - function g(obj) { -- return __assign({ x: 1 }, obj); // ok, obj might have x: undefined -+ return { x: 1, ...obj }; // ok, obj might have x: undefined - } - function f(obj) { -- return __assign({ x: 1 }, obj); // ok, obj might be undefined -+ return { x: 1, ...obj }; // ok, obj might be undefined - } - function h(obj) { -- return __assign({ x: 1 }, obj); // error -+ return { x: 1, ...obj }; // error - } - function i(b, t) { -- return __assign({ command: "hi" }, (b ? t : {})); // ok -+ return { command: "hi", ...(b ? t : {}) }; // ok - } - function j() { -- return __assign({ command: "hi" }, { command: "bye" }); // ok -+ return { ...{ command: "hi" }, ...{ command: "bye" } }; // ok - } - function k(t) { -- return __assign(__assign(__assign({ command: "hi" }, { spoiler: true }), { spoiler2: true }), t); // error -+ return { command: "hi", ...{ spoiler: true }, spoiler2: true, ...t }; // error - } - function l(anyrequired) { -- return __assign({ a: 'zzz' }, anyrequired); // error -+ return { a: 'zzz', ...anyrequired }; // error - } - function m(anyoptional) { -- return __assign({ a: 'zzz' }, anyoptional); // ok -+ return { a: 'zzz', ...anyoptional }; // ok - } \ No newline at end of file + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/spreadTypeVariable.js b/testdata/baselines/reference/submodule/conformance/spreadTypeVariable.js index 39a38655d7..d3049f6497 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadTypeVariable.js +++ b/testdata/baselines/reference/submodule/conformance/spreadTypeVariable.js @@ -28,21 +28,32 @@ function f6(arg: T) { //// [spreadTypeVariable.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; function f1(arg) { - return { ...arg }; + return __assign({}, arg); } function f2(arg) { - return { ...arg }; + return __assign({}, arg); } function f3(arg) { - return { ...arg }; + return __assign({}, arg); } function f4(arg) { - return { ...arg }; + return __assign({}, arg); } function f5(arg) { - return { ...arg }; + return __assign({}, arg); } function f6(arg) { - return { ...arg }; + return __assign({}, arg); } diff --git a/testdata/baselines/reference/submodule/conformance/spreadTypeVariable.js.diff b/testdata/baselines/reference/submodule/conformance/spreadTypeVariable.js.diff deleted file mode 100644 index 26f8cf24c3..0000000000 --- a/testdata/baselines/reference/submodule/conformance/spreadTypeVariable.js.diff +++ /dev/null @@ -1,41 +0,0 @@ ---- old.spreadTypeVariable.js -+++ new.spreadTypeVariable.js -@@= skipped -27, +27 lines =@@ - - - //// [spreadTypeVariable.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - function f1(arg) { -- return __assign({}, arg); -+ return { ...arg }; - } - function f2(arg) { -- return __assign({}, arg); -+ return { ...arg }; - } - function f3(arg) { -- return __assign({}, arg); -+ return { ...arg }; - } - function f4(arg) { -- return __assign({}, arg); -+ return { ...arg }; - } - function f5(arg) { -- return __assign({}, arg); -+ return { ...arg }; - } - function f6(arg) { -- return __assign({}, arg); -+ return { ...arg }; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/spreadUnion.js b/testdata/baselines/reference/submodule/conformance/spreadUnion.js index 825d7ae8b9..6d65812e87 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadUnion.js +++ b/testdata/baselines/reference/submodule/conformance/spreadUnion.js @@ -13,10 +13,21 @@ var o5: { a: number } | { b: string } | { a: number, b: string }; var o5 = { ...union, ...union }; //// [spreadUnion.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; var union; var o3; -var o3 = { ...union }; +var o3 = __assign({}, union); var o4; -var o4 = { ...union, a: false }; +var o4 = __assign(__assign({}, union), { a: false }); var o5; -var o5 = { ...union, ...union }; +var o5 = __assign(__assign({}, union), union); diff --git a/testdata/baselines/reference/submodule/conformance/spreadUnion.js.diff b/testdata/baselines/reference/submodule/conformance/spreadUnion.js.diff deleted file mode 100644 index 59029b9e90..0000000000 --- a/testdata/baselines/reference/submodule/conformance/spreadUnion.js.diff +++ /dev/null @@ -1,27 +0,0 @@ ---- old.spreadUnion.js -+++ new.spreadUnion.js -@@= skipped -12, +12 lines =@@ - var o5 = { ...union, ...union }; - - //// [spreadUnion.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - var union; - var o3; --var o3 = __assign({}, union); -+var o3 = { ...union }; - var o4; --var o4 = __assign(__assign({}, union), { a: false }); -+var o4 = { ...union, a: false }; - var o5; --var o5 = __assign(__assign({}, union), union); -+var o5 = { ...union, ...union }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/spreadUnion2.js b/testdata/baselines/reference/submodule/conformance/spreadUnion2.js index c0950ef012..627f615c63 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadUnion2.js +++ b/testdata/baselines/reference/submodule/conformance/spreadUnion2.js @@ -23,14 +23,25 @@ var o5 = { ...nullUnion, ...nullUnion }; //// [spreadUnion2.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; var o1; -var o1 = { ...undefinedUnion }; +var o1 = __assign({}, undefinedUnion); var o2; -var o2 = { ...nullUnion }; +var o2 = __assign({}, nullUnion); var o3; -var o3 = { ...undefinedUnion, ...nullUnion }; -var o3 = { ...nullUnion, ...undefinedUnion }; +var o3 = __assign(__assign({}, undefinedUnion), nullUnion); +var o3 = __assign(__assign({}, nullUnion), undefinedUnion); var o4; -var o4 = { ...undefinedUnion, ...undefinedUnion }; +var o4 = __assign(__assign({}, undefinedUnion), undefinedUnion); var o5; -var o5 = { ...nullUnion, ...nullUnion }; +var o5 = __assign(__assign({}, nullUnion), nullUnion); diff --git a/testdata/baselines/reference/submodule/conformance/spreadUnion2.js.diff b/testdata/baselines/reference/submodule/conformance/spreadUnion2.js.diff deleted file mode 100644 index 0c5323c978..0000000000 --- a/testdata/baselines/reference/submodule/conformance/spreadUnion2.js.diff +++ /dev/null @@ -1,34 +0,0 @@ ---- old.spreadUnion2.js -+++ new.spreadUnion2.js -@@= skipped -22, +22 lines =@@ - - - //// [spreadUnion2.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - var o1; --var o1 = __assign({}, undefinedUnion); -+var o1 = { ...undefinedUnion }; - var o2; --var o2 = __assign({}, nullUnion); -+var o2 = { ...nullUnion }; - var o3; --var o3 = __assign(__assign({}, undefinedUnion), nullUnion); --var o3 = __assign(__assign({}, nullUnion), undefinedUnion); -+var o3 = { ...undefinedUnion, ...nullUnion }; -+var o3 = { ...nullUnion, ...undefinedUnion }; - var o4; --var o4 = __assign(__assign({}, undefinedUnion), undefinedUnion); -+var o4 = { ...undefinedUnion, ...undefinedUnion }; - var o5; --var o5 = __assign(__assign({}, nullUnion), nullUnion); -+var o5 = { ...nullUnion, ...nullUnion }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/spreadUnion3.js b/testdata/baselines/reference/submodule/conformance/spreadUnion3.js index 13901da17c..b1938ba964 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadUnion3.js +++ b/testdata/baselines/reference/submodule/conformance/spreadUnion3.js @@ -22,16 +22,27 @@ var y = { ...nullAndUndefinedUnion }; //// [spreadUnion3.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; function f(x) { - return { y: 123, ...x }; // y: string | number + return __assign({ y: 123 }, x); // y: string | number } f(undefined); function g(t) { - let b = { ...t }; + let b = __assign({}, t); let c = b.a; // might not have 'a' } g(); g(undefined); g(null); -var x = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion }; -var y = { ...nullAndUndefinedUnion }; +var x = __assign(__assign({}, nullAndUndefinedUnion), nullAndUndefinedUnion); +var y = __assign({}, nullAndUndefinedUnion); diff --git a/testdata/baselines/reference/submodule/conformance/spreadUnion3.js.diff b/testdata/baselines/reference/submodule/conformance/spreadUnion3.js.diff deleted file mode 100644 index f2e5ba822a..0000000000 --- a/testdata/baselines/reference/submodule/conformance/spreadUnion3.js.diff +++ /dev/null @@ -1,34 +0,0 @@ ---- old.spreadUnion3.js -+++ new.spreadUnion3.js -@@= skipped -21, +21 lines =@@ - - - //// [spreadUnion3.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; - function f(x) { -- return __assign({ y: 123 }, x); // y: string | number -+ return { y: 123, ...x }; // y: string | number - } - f(undefined); - function g(t) { -- let b = __assign({}, t); -+ let b = { ...t }; - let c = b.a; // might not have 'a' - } - g(); - g(undefined); - g(null); --var x = __assign(__assign({}, nullAndUndefinedUnion), nullAndUndefinedUnion); --var y = __assign({}, nullAndUndefinedUnion); -+var x = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion }; -+var y = { ...nullAndUndefinedUnion }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/spreadUnion4.js b/testdata/baselines/reference/submodule/conformance/spreadUnion4.js index 160a62d8e4..8315f9908e 100644 --- a/testdata/baselines/reference/submodule/conformance/spreadUnion4.js +++ b/testdata/baselines/reference/submodule/conformance/spreadUnion4.js @@ -8,4 +8,15 @@ const c = { ...a, ...b }; //// [spreadUnion4.js] -const c = { ...a, ...b }; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +const c = __assign(__assign({}, a), b); diff --git a/testdata/baselines/reference/submodule/conformance/spreadUnion4.js.diff b/testdata/baselines/reference/submodule/conformance/spreadUnion4.js.diff deleted file mode 100644 index 8752b33e06..0000000000 --- a/testdata/baselines/reference/submodule/conformance/spreadUnion4.js.diff +++ /dev/null @@ -1,19 +0,0 @@ ---- old.spreadUnion4.js -+++ new.spreadUnion4.js -@@= skipped -7, +7 lines =@@ - - - //// [spreadUnion4.js] --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --const c = __assign(__assign({}, a), b); -+const c = { ...a, ...b }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers1(target=es2015).js b/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers1(target=es2015).js index 1ed7df38df..75b1a6bf67 100644 --- a/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers1(target=es2015).js +++ b/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers1(target=es2015).js @@ -42,6 +42,18 @@ class C extends B { //// [thisAndSuperInStaticMembers1.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a; class C extends B { static x = undefined; static y1 = this.x; @@ -61,7 +73,7 @@ class C extends B { static z10 = [...super.a] = [0]; static z11 = { x: super.a } = { x: 0 }; static z12 = { x: super.a = 0 } = { x: 0 }; - static z13 = { ...super.a } = { x: 0 }; + static z13 = (_a = { x: 0 }, super.a = __rest(_a, [])); static z14 = ++super.a; static z15 = --super.a; static z16 = ++super[("a")]; diff --git a/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers1(target=es2015).js.diff b/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers1(target=es2015).js.diff index 23a2b96902..227a69ee38 100644 --- a/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers1(target=es2015).js.diff +++ b/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers1(target=es2015).js.diff @@ -1,21 +1,9 @@ --- old.thisAndSuperInStaticMembers1(target=es2015).js +++ new.thisAndSuperInStaticMembers1(target=es2015).js -@@= skipped -41, +41 lines =@@ - - - //// [thisAndSuperInStaticMembers1.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --var _a; +@@= skipped -53, +53 lines =@@ + return t; + }; + var _a; -var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; -class C extends (_c = B) { - constructor() { @@ -59,7 +47,7 @@ + static z10 = [...super.a] = [0]; + static z11 = { x: super.a } = { x: 0 }; + static z12 = { x: super.a = 0 } = { x: 0 }; -+ static z13 = { ...super.a } = { x: 0 }; ++ static z13 = (_a = { x: 0 }, super.a = __rest(_a, [])); + static z14 = ++super.a; + static z15 = --super.a; + static z16 = ++super[("a")]; diff --git a/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers2(target=es2015).js b/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers2(target=es2015).js index fa69f47702..bba21cdc35 100644 --- a/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers2(target=es2015).js +++ b/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers2(target=es2015).js @@ -42,6 +42,18 @@ class C extends B { //// [thisAndSuperInStaticMembers2.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a; class C extends B { static x = undefined; static y1 = this.x; @@ -61,7 +73,7 @@ class C extends B { static z10 = [...super.a] = [0]; static z11 = { x: super.a } = { x: 0 }; static z12 = { x: super.a = 0 } = { x: 0 }; - static z13 = { ...super.a } = { x: 0 }; + static z13 = (_a = { x: 0 }, super.a = __rest(_a, [])); static z14 = ++super.a; static z15 = --super.a; static z16 = ++super[("a")]; diff --git a/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers2(target=es2015).js.diff b/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers2(target=es2015).js.diff index 5f39f02ee6..303250c3db 100644 --- a/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers2(target=es2015).js.diff +++ b/testdata/baselines/reference/submodule/conformance/thisAndSuperInStaticMembers2(target=es2015).js.diff @@ -1,21 +1,9 @@ --- old.thisAndSuperInStaticMembers2(target=es2015).js +++ new.thisAndSuperInStaticMembers2(target=es2015).js -@@= skipped -41, +41 lines =@@ - - - //// [thisAndSuperInStaticMembers2.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; --var _a; +@@= skipped -53, +53 lines =@@ + return t; + }; + var _a; -var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; -class C extends (_c = B) { - constructor() { @@ -44,7 +32,7 @@ + static z10 = [...super.a] = [0]; + static z11 = { x: super.a } = { x: 0 }; + static z12 = { x: super.a = 0 } = { x: 0 }; -+ static z13 = { ...super.a } = { x: 0 }; ++ static z13 = (_a = { x: 0 }, super.a = __rest(_a, [])); + static z14 = ++super.a; + static z15 = --super.a; + static z16 = ++super[("a")]; diff --git a/testdata/baselines/reference/submodule/conformance/trailingCommasInBindingPatterns.js b/testdata/baselines/reference/submodule/conformance/trailingCommasInBindingPatterns.js index 55208349e0..baf10f3294 100644 --- a/testdata/baselines/reference/submodule/conformance/trailingCommasInBindingPatterns.js +++ b/testdata/baselines/reference/submodule/conformance/trailingCommasInBindingPatterns.js @@ -16,11 +16,23 @@ let g, h; //// [trailingCommasInBindingPatterns.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a; const [...a,] = []; -const { ...b, } = {}; +const b = __rest({}, []); let c, d; ([...c,] = []); -({ ...d, } = {}); +(_a = {}, d = __rest(_a, [])); // Allowed for non-rest elements const [e,] = []; const { f, } = {}; diff --git a/testdata/baselines/reference/submodule/conformance/trailingCommasInBindingPatterns.js.diff b/testdata/baselines/reference/submodule/conformance/trailingCommasInBindingPatterns.js.diff index e53d0bdd98..70b9349e70 100644 --- a/testdata/baselines/reference/submodule/conformance/trailingCommasInBindingPatterns.js.diff +++ b/testdata/baselines/reference/submodule/conformance/trailingCommasInBindingPatterns.js.diff @@ -1,27 +1,16 @@ --- old.trailingCommasInBindingPatterns.js +++ new.trailingCommasInBindingPatterns.js -@@= skipped -15, +15 lines =@@ - - - //// [trailingCommasInBindingPatterns.js] --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; +@@= skipped -26, +26 lines =@@ + } + return t; + }; ++var _a; const [...a,] = []; --const b = __rest({}, []); -+const { ...b, } = {}; + const b = __rest({}, []); let c, d; ([...c,] = []); -(d = __rest({}, [])); -+({ ...d, } = {}); ++(_a = {}, d = __rest(_a, [])); // Allowed for non-rest elements const [e,] = []; const { f, } = {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/tsxEmitSpreadAttribute(target=es2015).js b/testdata/baselines/reference/submodule/conformance/tsxEmitSpreadAttribute(target=es2015).js index fe5af8ffb5..6fe0b56e61 100644 --- a/testdata/baselines/reference/submodule/conformance/tsxEmitSpreadAttribute(target=es2015).js +++ b/testdata/baselines/reference/submodule/conformance/tsxEmitSpreadAttribute(target=es2015).js @@ -67,7 +67,7 @@ export function T5(a, b, c, d) { return React.createElement("div", Object.assign({ className: "T5" }, a, b, { c, d }), "T5"); } export function T6(a, b, c, d) { - return React.createElement("div", Object.assign({ className: "T6" }, a, b, { ...c, ...d }), "T6"); + return React.createElement("div", Object.assign({ className: "T6" }, a, b, Object.assign(Object.assign({}, c), d)), "T6"); } export function T7(a, b, c, d) { return React.createElement("div", Object.assign({ className: "T7" }, { __proto__: null, dir: 'rtl' }), "T7"); diff --git a/testdata/baselines/reference/submodule/conformance/tsxEmitSpreadAttribute(target=es2015).js.diff b/testdata/baselines/reference/submodule/conformance/tsxEmitSpreadAttribute(target=es2015).js.diff deleted file mode 100644 index a00112c989..0000000000 --- a/testdata/baselines/reference/submodule/conformance/tsxEmitSpreadAttribute(target=es2015).js.diff +++ /dev/null @@ -1,11 +0,0 @@ ---- old.tsxEmitSpreadAttribute(target=es2015).js -+++ new.tsxEmitSpreadAttribute(target=es2015).js -@@= skipped -66, +66 lines =@@ - return React.createElement("div", Object.assign({ className: "T5" }, a, b, { c, d }), "T5"); - } - export function T6(a, b, c, d) { -- return React.createElement("div", Object.assign({ className: "T6" }, a, b, Object.assign(Object.assign({}, c), d)), "T6"); -+ return React.createElement("div", Object.assign({ className: "T6" }, a, b, { ...c, ...d }), "T6"); - } - export function T7(a, b, c, d) { - return React.createElement("div", Object.assign({ className: "T7" }, { __proto__: null, dir: 'rtl' }), "T7"); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/tsxReactEmitSpreadAttribute(target=es2015).js b/testdata/baselines/reference/submodule/conformance/tsxReactEmitSpreadAttribute(target=es2015).js index 89ae8bd5cc..7fd95bd3d0 100644 --- a/testdata/baselines/reference/submodule/conformance/tsxReactEmitSpreadAttribute(target=es2015).js +++ b/testdata/baselines/reference/submodule/conformance/tsxReactEmitSpreadAttribute(target=es2015).js @@ -73,7 +73,7 @@ export function T5(a, b, c, d) { return _jsx("div", Object.assign({ className: "T5" }, a, b, { c, d }, { children: "T5" })); } export function T6(a, b, c, d) { - return _jsx("div", Object.assign({ className: "T6" }, a, b, { ...c, ...d }, { children: "T6" })); + return _jsx("div", Object.assign({ className: "T6" }, a, b, Object.assign(Object.assign({}, c), d), { children: "T6" })); } export function T7(a, b, c, d) { return _jsx("div", { children: "T7" }); diff --git a/testdata/baselines/reference/submodule/conformance/tsxReactEmitSpreadAttribute(target=es2015).js.diff b/testdata/baselines/reference/submodule/conformance/tsxReactEmitSpreadAttribute(target=es2015).js.diff deleted file mode 100644 index eb7ce0adcf..0000000000 --- a/testdata/baselines/reference/submodule/conformance/tsxReactEmitSpreadAttribute(target=es2015).js.diff +++ /dev/null @@ -1,11 +0,0 @@ ---- old.tsxReactEmitSpreadAttribute(target=es2015).js -+++ new.tsxReactEmitSpreadAttribute(target=es2015).js -@@= skipped -72, +72 lines =@@ - return _jsx("div", Object.assign({ className: "T5" }, a, b, { c, d }, { children: "T5" })); - } - export function T6(a, b, c, d) { -- return _jsx("div", Object.assign({ className: "T6" }, a, b, Object.assign(Object.assign({}, c), d), { children: "T6" })); -+ return _jsx("div", Object.assign({ className: "T6" }, a, b, { ...c, ...d }, { children: "T6" })); - } - export function T7(a, b, c, d) { - return _jsx("div", { children: "T7" }); \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/unknownType1.js b/testdata/baselines/reference/submodule/conformance/unknownType1.js index ca3071808b..f6eb5781a4 100644 --- a/testdata/baselines/reference/submodule/conformance/unknownType1.js +++ b/testdata/baselines/reference/submodule/conformance/unknownType1.js @@ -186,6 +186,28 @@ function oops(arg: T): {} { //// [unknownType1.js] +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; // Only equality operators are allowed with unknown function f10(x) { x == 5; @@ -257,17 +279,17 @@ function f25() { } // Spread of unknown causes result to be unknown function f26(x, y, z) { - let o1 = { a: 42, ...x }; // { a: number } - let o2 = { a: 42, ...x, ...y }; // unknown - let o3 = { a: 42, ...x, ...y, ...z }; // any - let o4 = { a: 42, ...z }; // any + let o1 = __assign({ a: 42 }, x); // { a: number } + let o2 = __assign(__assign({ a: 42 }, x), y); // unknown + let o3 = __assign(__assign(__assign({ a: 42 }, x), y), z); // any + let o4 = __assign({ a: 42 }, z); // any } // Functions with unknown return type don't need return expressions function f27() { } // Rest type cannot be created from unknown function f28(x) { - let { ...a } = x; // Error + let a = __rest(x, []); // Error } // Class properties of type unknown don't need definite assignment class C1 { diff --git a/testdata/baselines/reference/submodule/conformance/unknownType1.js.diff b/testdata/baselines/reference/submodule/conformance/unknownType1.js.diff index f2b747d325..85b2f620b2 100644 --- a/testdata/baselines/reference/submodule/conformance/unknownType1.js.diff +++ b/testdata/baselines/reference/submodule/conformance/unknownType1.js.diff @@ -6,51 +6,10 @@ //// [unknownType1.js] -"use strict"; -// In an intersection everything absorbs unknown --var __assign = (this && this.__assign) || function () { -- __assign = Object.assign || function(t) { -- for (var s, i = 1, n = arguments.length; i < n; i++) { -- s = arguments[i]; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) -- t[p] = s[p]; -- } -- return t; -- }; -- return __assign.apply(this, arguments); --}; --var __rest = (this && this.__rest) || function (s, e) { -- var t = {}; -- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) -- t[p] = s[p]; -- if (s != null && typeof Object.getOwnPropertySymbols === "function") -- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { -- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) -- t[p[i]] = s[p[i]]; -- } -- return t; --}; - // Only equality operators are allowed with unknown - function f10(x) { - x == 5; -@@= skipped -95, +71 lines =@@ - } - // Spread of unknown causes result to be unknown - function f26(x, y, z) { -- let o1 = __assign({ a: 42 }, x); // { a: number } -- let o2 = __assign(__assign({ a: 42 }, x), y); // unknown -- let o3 = __assign(__assign(__assign({ a: 42 }, x), y), z); // any -- let o4 = __assign({ a: 42 }, z); // any -+ let o1 = { a: 42, ...x }; // { a: number } -+ let o2 = { a: 42, ...x, ...y }; // unknown -+ let o3 = { a: 42, ...x, ...y, ...z }; // any -+ let o4 = { a: 42, ...z }; // any - } - // Functions with unknown return type don't need return expressions - function f27() { - } - // Rest type cannot be created from unknown - function f28(x) { -- let a = __rest(x, []); // Error -+ let { ...a } = x; // Error + var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { +@@= skipped -109, +107 lines =@@ } // Class properties of type unknown don't need definite assignment class C1 { From 5549c5fcad90b12b1bbe99fc29f9a315730ad84f Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 17:46:42 -0700 Subject: [PATCH 16/18] Fix lints --- internal/printer/printer_test.go | 3 +-- .../transformers/moduletransforms/commonjsmodule_test.go | 3 +-- internal/transformers/moduletransforms/esmodule_test.go | 3 +-- internal/transformers/tstransforms/importelision_test.go | 3 +-- internal/transformers/tstransforms/runtimesyntax_test.go | 7 +++---- internal/transformers/tstransforms/typeeraser_test.go | 3 +-- 6 files changed, 8 insertions(+), 14 deletions(-) diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index c1743fa42b..1a07a11808 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -1,7 +1,6 @@ package printer_test import ( - "context" "testing" "github.com/microsoft/typescript-go/internal/ast" @@ -2505,7 +2504,7 @@ func TestPartiallyEmittedExpression(t *testing.T) { .expression;`, false /*jsx*/) emitContext := printer.NewEmitContext() - ctx := transformers.WithCompilerOptions(context.Background(), compilerOptions) + ctx := transformers.WithCompilerOptions(t.Context(), compilerOptions) ctx = transformers.WithEmitContext(ctx, emitContext) file = tstransforms.NewTypeEraserTransformer(ctx).TransformSourceFile(file) emittestutil.CheckEmit(t, emitContext, file.AsSourceFile(), `return container.parent diff --git a/internal/transformers/moduletransforms/commonjsmodule_test.go b/internal/transformers/moduletransforms/commonjsmodule_test.go index 749441c839..0d0a1bed38 100644 --- a/internal/transformers/moduletransforms/commonjsmodule_test.go +++ b/internal/transformers/moduletransforms/commonjsmodule_test.go @@ -1,7 +1,6 @@ package moduletransforms_test import ( - "context" "testing" "github.com/microsoft/typescript-go/internal/ast" @@ -1049,7 +1048,7 @@ exports.a = a;`, emitContext := printer.NewEmitContext() resolver := binder.NewReferenceResolver(compilerOptions, binder.ReferenceResolverHooks{}) - ctx := transformers.WithCompilerOptions(context.Background(), compilerOptions) + ctx := transformers.WithCompilerOptions(t.Context(), compilerOptions) ctx = transformers.WithEmitContext(ctx, emitContext) file = tstransforms.NewRuntimeSyntaxTransformer(ctx, resolver).TransformSourceFile(file) file = moduletransforms.NewCommonJSModuleTransformer(ctx, resolver, fakeGetEmitModuleFormatOfFile).TransformSourceFile(file) diff --git a/internal/transformers/moduletransforms/esmodule_test.go b/internal/transformers/moduletransforms/esmodule_test.go index 47390bce18..6e72fbe974 100644 --- a/internal/transformers/moduletransforms/esmodule_test.go +++ b/internal/transformers/moduletransforms/esmodule_test.go @@ -1,7 +1,6 @@ package moduletransforms_test import ( - "context" "testing" "github.com/microsoft/typescript-go/internal/ast" @@ -241,7 +240,7 @@ var __rewriteRelativeImportExtension;`, emitContext := printer.NewEmitContext() resolver := binder.NewReferenceResolver(compilerOptions, binder.ReferenceResolverHooks{}) - ctx := transformers.WithCompilerOptions(context.Background(), compilerOptions) + ctx := transformers.WithCompilerOptions(t.Context(), compilerOptions) ctx = transformers.WithEmitContext(ctx, emitContext) file = tstransforms.NewRuntimeSyntaxTransformer(ctx, resolver).TransformSourceFile(file) file = moduletransforms.NewESModuleTransformer(ctx, resolver, fakeGetEmitModuleFormatOfFile).TransformSourceFile(file) diff --git a/internal/transformers/tstransforms/importelision_test.go b/internal/transformers/tstransforms/importelision_test.go index e36c9a4b16..a949b3169f 100644 --- a/internal/transformers/tstransforms/importelision_test.go +++ b/internal/transformers/tstransforms/importelision_test.go @@ -1,7 +1,6 @@ package tstransforms_test import ( - "context" "testing" "github.com/microsoft/typescript-go/internal/ast" @@ -246,7 +245,7 @@ func TestImportElision(t *testing.T) { emitResolver := c.GetEmitResolver() emitResolver.MarkLinkedReferencesRecursively(file) - ctx := transformers.WithCompilerOptions(context.Background(), compilerOptions) + ctx := transformers.WithCompilerOptions(t.Context(), compilerOptions) ctx = transformers.WithEmitContext(ctx, printer.NewEmitContext()) file = tstransforms.NewTypeEraserTransformer(ctx).TransformSourceFile(file) file = tstransforms.NewImportElisionTransformer(ctx, emitResolver).TransformSourceFile(file) diff --git a/internal/transformers/tstransforms/runtimesyntax_test.go b/internal/transformers/tstransforms/runtimesyntax_test.go index c21458e6f0..28b49f3c66 100644 --- a/internal/transformers/tstransforms/runtimesyntax_test.go +++ b/internal/transformers/tstransforms/runtimesyntax_test.go @@ -1,7 +1,6 @@ package tstransforms_test import ( - "context" "testing" "github.com/microsoft/typescript-go/internal/binder" @@ -239,7 +238,7 @@ var E; binder.BindSourceFile(file) emitContext := printer.NewEmitContext() resolver := binder.NewReferenceResolver(options, binder.ReferenceResolverHooks{}) - ctx := transformers.WithCompilerOptions(context.Background(), options) + ctx := transformers.WithCompilerOptions(t.Context(), options) ctx = transformers.WithEmitContext(ctx, emitContext) emittestutil.CheckEmit(t, emitContext, tstransforms.NewRuntimeSyntaxTransformer(ctx, resolver).TransformSourceFile(file), rec.output) }) @@ -418,7 +417,7 @@ func TestNamespaceTransformer(t *testing.T) { parsetestutil.CheckDiagnostics(t, file) binder.BindSourceFile(file) emitContext := printer.NewEmitContext() - ctx := transformers.WithCompilerOptions(context.Background(), options) + ctx := transformers.WithCompilerOptions(t.Context(), options) ctx = transformers.WithEmitContext(ctx, emitContext) resolver := binder.NewReferenceResolver(options, binder.ReferenceResolverHooks{}) emittestutil.CheckEmit(t, emitContext, tstransforms.NewRuntimeSyntaxTransformer(ctx, resolver).TransformSourceFile(file), rec.output) @@ -457,7 +456,7 @@ func TestParameterPropertyTransformer(t *testing.T) { binder.BindSourceFile(file) emitContext := printer.NewEmitContext() resolver := binder.NewReferenceResolver(options, binder.ReferenceResolverHooks{}) - ctx := transformers.WithCompilerOptions(context.Background(), options) + ctx := transformers.WithCompilerOptions(t.Context(), options) ctx = transformers.WithEmitContext(ctx, emitContext) file = tstransforms.NewTypeEraserTransformer(ctx).TransformSourceFile(file) file = tstransforms.NewRuntimeSyntaxTransformer(ctx, resolver).TransformSourceFile(file) diff --git a/internal/transformers/tstransforms/typeeraser_test.go b/internal/transformers/tstransforms/typeeraser_test.go index 2d0cab8938..e13dc0890f 100644 --- a/internal/transformers/tstransforms/typeeraser_test.go +++ b/internal/transformers/tstransforms/typeeraser_test.go @@ -1,7 +1,6 @@ package tstransforms_test import ( - "context" "testing" "github.com/microsoft/typescript-go/internal/core" @@ -101,7 +100,7 @@ func TestTypeEraser(t *testing.T) { if rec.vms { compilerOptions.VerbatimModuleSyntax = core.TSTrue } - ctx := transformers.WithCompilerOptions(context.Background(), compilerOptions) + ctx := transformers.WithCompilerOptions(t.Context(), compilerOptions) ctx = transformers.WithEmitContext(ctx, printer.NewEmitContext()) emittestutil.CheckEmit(t, nil, tstransforms.NewTypeEraserTransformer(ctx).TransformSourceFile(file), rec.output) }) From 8acf8d038e10a22bbbbbeba03945cdd24aa32918 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 18:00:02 -0700 Subject: [PATCH 17/18] ctx is now threaded here, no need to TODO --- internal/compiler/program.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/compiler/program.go b/internal/compiler/program.go index 6fe2c200f2..386bbf3b87 100644 --- a/internal/compiler/program.go +++ b/internal/compiler/program.go @@ -1326,7 +1326,7 @@ func (p *Program) Emit(ctx context.Context, options EmitOptions) *EmitResult { // attach writer and perform emit emitter.writer = writer emitter.paths = outputpaths.GetOutputPathsFor(sourceFile, host.Options(), host, options.EmitOnly == EmitOnlyForcedDts) - emitter.emit(context.TODO()) + emitter.emit(ctx) emitter.writer = nil // put the writer back in the pool From 9ef5d808905794461cd67c6a8625e5b6bf1b2302 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Aug 2025 18:04:51 -0700 Subject: [PATCH 18/18] FullSignature change reconcile --- internal/transformers/estransforms/objectrestspread.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/transformers/estransforms/objectrestspread.go b/internal/transformers/estransforms/objectrestspread.go index ac872a8086..0ffdac3c8b 100644 --- a/internal/transformers/estransforms/objectrestspread.go +++ b/internal/transformers/estransforms/objectrestspread.go @@ -186,6 +186,7 @@ func (ch *objectRestSpreadTransformer) visitContructorDeclaration(node *ast.Cons nil, ch.Visitor().VisitNodes(node.Parameters), nil, + nil, ch.transformFunctionBody(node.AsNode()), ) } @@ -200,6 +201,7 @@ func (ch *objectRestSpreadTransformer) visitGetAccessorDeclaration(node *ast.Get nil, ch.Visitor().VisitNodes(node.Parameters), nil, + nil, ch.transformFunctionBody(node.AsNode()), ) } @@ -214,6 +216,7 @@ func (ch *objectRestSpreadTransformer) visitSetAccessorDeclaration(node *ast.Set nil, ch.Visitor().VisitNodes(node.Parameters), nil, + nil, ch.transformFunctionBody(node.AsNode()), ) } @@ -230,6 +233,7 @@ func (ch *objectRestSpreadTransformer) visitMethodDeclaration(node *ast.MethodDe nil, ch.Visitor().VisitNodes(node.Parameters), nil, + nil, ch.transformFunctionBody(node.AsNode()), ) } @@ -245,6 +249,7 @@ func (ch *objectRestSpreadTransformer) visitFunctionDeclaration(node *ast.Functi nil, ch.Visitor().VisitNodes(node.Parameters), nil, + nil, ch.transformFunctionBody(node.AsNode()), ) } @@ -258,6 +263,7 @@ func (ch *objectRestSpreadTransformer) visitArrowFunction(node *ast.ArrowFunctio nil, ch.Visitor().VisitNodes(node.Parameters), nil, + nil, node.EqualsGreaterThanToken, ch.transformFunctionBody(node.AsNode()), ) @@ -274,6 +280,7 @@ func (ch *objectRestSpreadTransformer) visitFunctionExpression(node *ast.Functio nil, ch.Visitor().VisitNodes(node.Parameters), nil, + nil, ch.transformFunctionBody(node.AsNode()), ) }