From bb6dde794326838b2069c7f86fb900eee36027bc Mon Sep 17 00:00:00 2001 From: magic-akari Date: Sun, 12 Mar 2023 11:56:10 +0800 Subject: [PATCH] fix(es/compat): Handle `useDefineForClassFields: false` (#7055) **BREAKING CHANGE:** IMPORTANT NOTE: Users of decorators are recommended to configure `"useDefineForClassFields": false` to ensure that your code is properly transpiled. **Related issue:** - Closes https://github.com/swc-project/swc/issues/6985. --- crates/swc/src/builder.rs | 4 + crates/swc/src/config/mod.rs | 7 +- crates/swc/tests/exec.rs | 31 +- .../1592/{ => set_public_class_fields}/.swcrc | 3 +- .../{ => set_public_class_fields}/exec.ts | 0 .../{1 => set_public_class_fields}/.swcrc | 0 .../{1 => set_public_class_fields}/exec.ts | 0 .../fixture/issues-1xxx/1160/output/entry.ts | 4 + .../fixture/issues-1xxx/1219/output/index.ts | 5 +- .../fixture/issues-1xxx/1278/output/index.ts | 4 + .../issues-1xxx/1306/case1/output/index.ts | 13 +- .../issues-1xxx/1341/case1/output/index.ts | 3 +- .../fixture/issues-1xxx/1345/input/.swcrc | 3 +- .../issues-1xxx/1362/case1/input/.swcrc | 3 +- .../issues-1xxx/1421/case1/input/.swcrc | 3 +- .../issues-1xxx/1456/case1/input/.swcrc | 3 +- .../issues-1xxx/1456/case2/input/.swcrc | 3 +- .../issues-1xxx/1505/case1/output/index.ts | 3 +- .../issues-1xxx/1505/case3/output/index.tsx | 3 +- .../issues-1xxx/1505/case5/output/index.tsx | 3 +- .../issues-1xxx/1515/case1/output/input.ts | 9 +- .../issues-1xxx/1612/case1/output/index.ts | 13 +- .../1869/decorator/output/index.ts | 5 +- .../2011/no-minify/output/index.js | 3 +- .../issues-2xxx/2011/reduced/output/index.js | 5 +- .../fixture/issues-2xxx/2139/output/index.tsx | 9 +- .../fixture/issues-2xxx/2216/output/index.ts | 9 +- .../issues-2xxx/2990/1/output/index.ts | 4 + .../issues-2xxx/2990/2/output/index.ts | 10 + .../issues-3xxx/3055/1/output/index.ts | 4 +- .../fixture/issues-3xxx/3337/output/input.ts | 2 + .../issues-4xxx/4006/1/output/index.map | 2 +- .../issues-4xxx/4006/1/output/index.ts | 10 +- .../issues-4xxx/4063/1/output/index.ts | 6 +- .../issues-4xxx/4208/1/output/index.ts | 7 +- .../fixture/issues-5xxx/5258/output/index.ts | 5 +- .../fixture/issues-5xxx/5626/output/index.ts | 2 + .../issues-6xxx/6951/1/output/index.ts | 7 +- .../2020_JS/input/.swcrc | 11 + .../2020_JS/input/index.js | 6 + .../2020_JS/output/index.js | 17 + .../2020_TS/input/.swcrc | 11 + .../2020_TS/input/index.ts | 8 + .../2020_TS/output/index.ts | 22 + .../2022_JS/input/.swcrc | 11 + .../2022_JS/input/index.js | 6 + .../2022_JS/output/index.js | 6 + .../2022_TS/input/.swcrc | 11 + .../2022_TS/input/index.ts | 8 + .../2022_TS/output/index.ts | 12 + .../2020_JS/2022_JS/input/.swcrc | 11 + .../2020_JS/2022_JS/input/index.js | 6 + .../2020_JS/2022_JS/output/index.js | 11 + .../useSetForClassFields/2020_JS/input/.swcrc | 11 + .../2020_JS/input/index.js | 6 + .../2020_JS/output/index.js | 20 + .../useSetForClassFields/2020_TS/input/.swcrc | 11 + .../2020_TS/input/index.ts | 8 + .../2020_TS/output/index.js | 20 + .../2020_TS/output/index.ts | 21 + .../useSetForClassFields/2022_JS/input/.swcrc | 11 + .../2022_JS/input/index.js | 6 + .../2022_JS/output/index.js | 11 + .../useSetForClassFields/2022_TS/input/.swcrc | 11 + .../2022_TS/input/index.ts | 8 + .../2022_TS/output/index.ts | 12 + .../next.js/server/render/1/output/index.tsx | 14 + .../shared/lib/router/1/output/index.ts | 681 ++++---- .../tests/fixture/sourcemap/011/input/.swcrc | 1 + .../tests/fixture/sourcemap/012/input/.swcrc | 1 + .../tests/fixture/sourcemap/013/input/.swcrc | 1 + .../tests/fixture/sourcemap/014/input/.swcrc | 1 + crates/swc/tests/projects.rs | 5 + ...leAndExportedVarThatShareAName.1.normal.js | 20 +- ...ndNonExportedVarThatShareAName.1.normal.js | 20 +- .../accessorsOverrideProperty6.1.normal.js | 13 +- ...mdImportNotAsPrimaryExpression.1.normal.js | 4 +- ...rtyToPropertyDeclarationESNext.1.normal.js | 8 +- .../asyncAwaitNestedClasses_es5.1.normal.js | 76 +- .../asyncAwaitNestedClasses_es5.2.minified.js | 69 +- ...ssStaticBlock11(target=es2015).1.normal.js | 3 +- ...ssStaticBlock11(target=es2022).1.normal.js | 3 +- ...ssStaticBlock18(target=es2015).1.normal.js | 8 +- ...ssStaticBlock18(target=es2022).1.normal.js | 8 +- ...classStaticBlock18(target=es5).1.normal.js | 8 +- .../classStaticBlock27.1.normal.js | 4 +- .../classStaticBlock3.1.normal.js | 12 +- .../classStaticBlock3.2.minified.js | 12 +- .../classStaticBlock4.1.normal.js | 12 +- .../classStaticBlock4.2.minified.js | 12 +- ...assStaticBlock5(target=es2015).1.normal.js | 16 +- ...assStaticBlock5(target=es2022).1.normal.js | 16 +- ...sStaticBlock5(target=es2022).2.minified.js | 16 +- .../classStaticBlock5(target=es5).1.normal.js | 16 +- ...assStaticBlock9(target=es2015).1.normal.js | 8 +- ...assStaticBlock9(target=es2022).1.normal.js | 8 +- ...sStaticBlock9(target=es2022).2.minified.js | 8 +- .../classStaticBlock9(target=es5).1.normal.js | 8 +- .../classStaticBlockUseBeforeDef3.1.normal.js | 4 +- .../classWithPrivateProperty.1.normal.js | 8 +- .../classWithProtectedProperty.1.normal.js | 8 +- .../classWithPublicProperty.1.normal.js | 8 +- ...rBindingPattern(target=es2015).1.normal.js | 4 +- ...rBindingPattern(target=es2022).1.normal.js | 4 +- ...eterBindingPattern(target=es5).1.normal.js | 4 +- ...indingPattern.2(target=es2015).1.normal.js | 8 +- ...indingPattern.2(target=es2022).1.normal.js | 8 +- ...erBindingPattern.2(target=es5).1.normal.js | 8 +- ...eterInitializer(target=es2015).1.normal.js | 4 +- ...eterInitializer(target=es2022).1.normal.js | 4 +- ...rameterInitializer(target=es5).1.normal.js | 4 +- ...erInitializer.2(target=es2015).1.normal.js | 8 +- ...erInitializer.2(target=es2022).1.normal.js | 8 +- ...meterInitializer.2(target=es5).1.normal.js | 8 +- ...monJSImportAsPrimaryExpression.1.normal.js | 4 +- ...JSImportNotAsPrimaryExpression.1.normal.js | 4 +- ...ropertyNamesWithStaticProperty.1.normal.js | 4 +- ...sExpressionMethodDeclaration01.1.normal.js | 28 +- .../defineProperty(target=es2022).1.normal.js | 4 +- .../defineProperty(target=es5).1.normal.js | 4 +- ...onWithLiteralPropertyNameInES6.1.normal.js | 16 +- ...hStaticPropertyAssignmentInES6.1.normal.js | 8 +- ...eforeSuperCallWithDefineFields.1.normal.js | 4 +- .../errorSuperPropertyAccess.1.normal.js | 8 +- .../es6modulekindWithES5Target2.1.normal.js | 4 +- ...esnextmodulekindWithES5Target2.1.normal.js | 4 +- ...StaticPropertyAssignmentsInES6.1.normal.js | 4 +- .../tests/tsc-references/for-of27.1.normal.js | 4 + .../tests/tsc-references/for-of30.1.normal.js | 3 +- .../tsc-references/for-of30.2.minified.js | 8 +- .../generatedContextualTyping.1.normal.js | 468 +++--- .../importCallExpressionInAMD4.1.normal.js | 16 +- .../importCallExpressionInAMD4.2.minified.js | 8 +- .../importCallExpressionInCJS5.1.normal.js | 8 +- .../importCallExpressionInCJS5.2.minified.js | 4 +- .../importCallExpressionInSystem4.1.normal.js | 8 +- ...mportCallExpressionInSystem4.2.minified.js | 4 +- .../importCallExpressionInUMD4.1.normal.js | 8 +- .../importCallExpressionInUMD4.2.minified.js | 4 +- .../importImportOnlyModule.1.normal.js | 4 +- ...ingClassMembersFromAssignments.1.normal.js | 16 +- ...MemberWithComputedPropertyName.1.normal.js | 3 +- .../jsDeclarationsClasses.1.normal.js | 18 +- .../jsDeclarationsComputedNames.1.normal.js | 7 +- .../jsDeclarationsDefaultsErr.1.normal.js | 4 +- ...nsExportAssignedClassInstance2.1.normal.js | 4 +- ...nsExportAssignedClassInstance3.1.normal.js | 4 +- .../jsDeclarationsPrivateFields01.1.normal.js | 8 +- ...sDeclarationsPrivateFields01.2.minified.js | 7 +- ...sReusesExistingTypeAnnotations.1.normal.js | 10 +- .../mixinClassesAnnotated.1.normal.js | 4 +- .../mixinClassesAnonymous.1.normal.js | 4 +- ...lassExpressionMemberInFunction.1.normal.js | 4 +- .../tsc-references/newTarget.es5.1.normal.js | 8 +- .../tsc-references/newTarget.es6.1.normal.js | 8 +- .../tsc-references/overloadTag2.1.normal.js | 3 +- .../tsc-references/overloadTag2.2.minified.js | 4 +- .../tsc-references/override13.1.normal.js | 38 +- .../tsc-references/override13.2.minified.js | 26 + .../tsc-references/override14.1.normal.js | 4 +- .../override16(target=es2022).1.normal.js | 5 +- .../overrideInterfaceProperty.1.normal.js | 5 +- ...arserAccessibilityAfterStatic3.1.normal.js | 4 +- .../parserES5SymbolProperty6.1.normal.js | 7 +- ...very_IncompleteMemberVariable1.1.normal.js | 6 +- .../parserSymbolProperty5.1.normal.js | 4 + .../parserSymbolProperty6.1.normal.js | 7 +- ...privateNameAndObjectRestSpread.1.normal.js | 4 +- ...ivateNameAndObjectRestSpread.2.minified.js | 1 + ...aticInitializer(target=es2015).1.normal.js | 11 +- ...icInitializer(target=es2015).2.minified.js | 7 +- ...aticInitializer(target=es2022).1.normal.js | 12 +- ...icInitializer(target=es2022).2.minified.js | 11 +- .../privateNameCircularReference.1.normal.js | 7 +- ...privateNameCircularReference.2.minified.js | 1 + ...privateNameClassExpressionLoop.1.normal.js | 4 +- ...ivateNameClassExpressionLoop.2.minified.js | 5 +- ...edPropertyName1(target=es2015).1.normal.js | 9 +- ...PropertyName1(target=es2015).2.minified.js | 8 +- ...edPropertyName1(target=es2022).1.normal.js | 9 +- ...PropertyName1(target=es2022).2.minified.js | 8 +- ...edPropertyName2(target=es2015).1.normal.js | 4 +- ...PropertyName2(target=es2015).2.minified.js | 5 +- ...edPropertyName2(target=es2022).1.normal.js | 5 +- ...PropertyName2(target=es2022).2.minified.js | 5 +- ...edPropertyName3(target=es2015).1.normal.js | 3 +- ...PropertyName3(target=es2015).2.minified.js | 4 +- ...edPropertyName3(target=es2022).1.normal.js | 5 +- ...PropertyName3(target=es2022).2.minified.js | 5 +- .../privateNameDeclaration.1.normal.js | 4 +- .../privateNameDeclaration.2.minified.js | 1 + .../privateNameES5Ban(target=es5).1.normal.js | 4 +- ...rivateNameES5Ban(target=es5).2.minified.js | 1 + .../privateNameEmitHelpers.1.normal.js | 3 +- .../privateNameEmitHelpers.2.minified.js | 4 +- .../privateNameFieldAccess.1.normal.js | 4 +- .../privateNameFieldAccess.2.minified.js | 1 + .../privateNameFieldAssignment.1.normal.js | 3 +- ...privateNameFieldCallExpression.1.normal.js | 11 +- ...ivateNameFieldCallExpression.2.minified.js | 1 + ...rivateNameFieldClassExpression.1.normal.js | 23 +- ...vateNameFieldClassExpression.2.minified.js | 1 + ...ructuredBinding(target=es2015).1.normal.js | 4 +- ...cturedBinding(target=es2015).2.minified.js | 1 + ...ructuredBinding(target=es2022).1.normal.js | 5 +- ...cturedBinding(target=es2022).2.minified.js | 37 - .../privateNameFieldInitializer.1.normal.js | 4 +- .../privateNameFieldInitializer.2.minified.js | 1 + .../privateNameFieldUnaryMutation.1.normal.js | 3 +- .../privateNameFieldsESNext.1.normal.js | 12 +- ...ateNameInLhsReceiverExpression.1.normal.js | 9 +- ...ateNameMethodInStaticFieldInit.1.normal.js | 4 +- ...NameStaticFieldClassExpression.1.normal.js | 8 +- ...ructuredBinding(target=es2022).1.normal.js | 2 +- ...NameStaticMethodCallExpression.1.normal.js | 4 +- ...eStaticMethodInStaticFieldInit.1.normal.js | 4 +- .../privateNameUnused.1.normal.js | 7 +- .../privateNameUnused.2.minified.js | 7 +- ...sFieldsInEsNext(target=es2020).1.normal.js | 85 +- ...ieldsInEsNext(target=es2020).2.minified.js | 54 +- ...sFieldsInEsNext(target=es2022).1.normal.js | 100 +- ...ieldsInEsNext(target=es2022).2.minified.js | 66 +- .../privateNamesAndkeyof.1.normal.js | 4 +- .../privateNamesAndkeyof.2.minified.js | 1 + .../privateNamesAssertion.1.normal.js | 13 +- ...privateNamesConstructorChain-1.1.normal.js | 16 +- ...ivateNamesConstructorChain-1.2.minified.js | 1 + ...privateNamesConstructorChain-2.1.normal.js | 16 +- ...ivateNamesConstructorChain-2.2.minified.js | 11 +- ...teNamesIncompatibleModifiersJs.1.normal.js | 10 +- ...NamesIncompatibleModifiersJs.2.minified.js | 1 + .../privateNamesUseBeforeDef.1.normal.js | 31 +- .../privateNamesUseBeforeDef.2.minified.js | 1 + ...ivateStaticMemberAccessibility.1.normal.js | 6 +- .../propertyOverridesAccessors5.1.normal.js | 2 +- .../redefinedPararameterProperty.1.normal.js | 2 +- .../tsc-references/spreadMethods.1.normal.js | 4 +- .../spreadMethods.2.minified.js | 4 +- .../staticIndexSignature7.1.normal.js | 6 +- .../staticMemberInitialization.1.normal.js | 4 +- .../strictPropertyInitialization.1.normal.js | 19 +- ...strictPropertyInitialization.2.minified.js | 2 +- ...nStaticMembers1(target=es2015).1.normal.js | 202 ++- ...nStaticMembers1(target=es2021).1.normal.js | 202 ++- ...nStaticMembers1(target=es2022).1.normal.js | 202 ++- ...taticMembers1(target=es2022).2.minified.js | 144 +- ...erInStaticMembers1(target=es5).1.normal.js | 209 ++- ...InStaticMembers1(target=es5).2.minified.js | 35 +- .../symbolDeclarationEmit1.1.normal.js | 4 + .../symbolDeclarationEmit11.1.normal.js | 10 +- .../symbolDeclarationEmit12.1.normal.js | 13 +- .../symbolDeclarationEmit12.2.minified.js | 14 +- .../symbolDeclarationEmit2.1.normal.js | 7 +- .../symbolProperty10.1.normal.js | 4 + .../symbolProperty12.1.normal.js | 4 + .../symbolProperty13.1.normal.js | 4 + .../symbolProperty14.1.normal.js | 4 + .../symbolProperty16.1.normal.js | 4 + .../symbolProperty6.1.normal.js | 9 +- .../symbolProperty9.1.normal.js | 4 + ...nStaticMembers2(target=es2015).1.normal.js | 126 +- ...taticMembers2(target=es2015).2.minified.js | 10 +- ...nStaticMembers2(target=es2022).1.normal.js | 135 +- ...taticMembers2(target=es2022).2.minified.js | 126 +- .../thisAndSuperInStaticMembers4.1.normal.js | 32 +- .../thisTypeAccessibility.1.normal.js | 12 +- .../tsc-references/thisTypeErrors.1.normal.js | 4 +- .../tsxLibraryManagedAttributes.1.normal.js | 76 +- ...tInferenceWithClassExpression1.1.normal.js | 4 +- ...tInferenceWithClassExpression2.1.normal.js | 4 +- .../typeOfThisGeneral.1.normal.js | 20 +- .../typeOfThisInStaticMembers2.1.normal.js | 12 +- ...nStaticMembers3(target=es2015).1.normal.js | 20 +- ...nStaticMembers3(target=es2022).1.normal.js | 20 +- ...taticMembers3(target=es2022).2.minified.js | 20 +- ...isInStaticMembers3(target=es5).1.normal.js | 20 +- ...nStaticMembers5(target=es2015).1.normal.js | 4 +- ...nStaticMembers5(target=es2022).1.normal.js | 4 +- ...taticMembers5(target=es2022).2.minified.js | 8 + ...isInStaticMembers5(target=es5).1.normal.js | 8 +- .../typeOfThisInStaticMembers6.1.normal.js | 8 +- ...nStaticMembers7(target=es2015).1.normal.js | 20 +- ...nStaticMembers7(target=es2022).1.normal.js | 20 +- ...taticMembers7(target=es2022).2.minified.js | 20 +- ...isInStaticMembers7(target=es5).1.normal.js | 20 +- ...nStaticMembers8(target=es2015).1.normal.js | 50 +- ...nStaticMembers8(target=es2022).1.normal.js | 50 +- ...taticMembers8(target=es2022).2.minified.js | 30 +- ...isInStaticMembers8(target=es5).1.normal.js | 60 +- ...nStaticMembers9(target=es2015).1.normal.js | 50 +- ...nStaticMembers9(target=es2022).1.normal.js | 50 +- ...taticMembers9(target=es2022).2.minified.js | 30 +- ...isInStaticMembers9(target=es5).1.normal.js | 60 +- .../typeQueryOnClass.1.normal.js | 12 +- .../tsc-references/uniqueSymbols.1.normal.js | 61 +- .../uniqueSymbols.2.minified.js | 55 +- .../uniqueSymbolsDeclarations.1.normal.js | 61 +- .../uniqueSymbolsDeclarations.2.minified.js | 55 +- .../uniqueSymbolsDeclarationsInJs.1.normal.js | 24 +- ...niqueSymbolsDeclarationsInJs.2.minified.js | 17 +- .../tests/tsc-references/variance.1.normal.js | 4 +- .../tests/tsc-references/witness.1.normal.js | 4 +- .../full/react-autowhatever/1/output/index.js | 110 +- .../full/react-autowhatever/2/output/index.js | 90 +- .../next-39460/output/snippetSession.js | 1430 +++++++++-------- .../react-autowhatever/1/output/index.js | 102 +- .../regressions/1/full/output/index.js | 5 +- .../regressions/1/simplified/output/index.js | 5 +- .../deno-9220/case1/output/entry.inlined.ts | 3 + .../fixture/deno-9220/case1/output/entry.ts | 3 + .../fixture/deno-9591/output/entry.inlined.ts | 40 + .../tests/fixture/deno-9591/output/entry.ts | 40 + .../deno-9620/case1/output/entry.inlined.ts | 21 + .../fixture/deno-9620/case1/output/entry.ts | 21 + crates/swc_ecma_ast/src/expr.rs | 6 + crates/swc_ecma_preset_env/src/lib.rs | 9 + .../swc_ecma_transforms/tests/decorators.rs | 4 + .../src/class_fields_use_set.rs | 343 ++++ crates/swc_ecma_transforms_compat/src/lib.rs | 1 + .../tests/class_fields_use_set.rs | 21 + .../class_fields_use_set/basic/1/input.js | 8 + .../class_fields_use_set/basic/1/output.js | 13 + .../class_fields_use_set/basic/2/input.js | 6 + .../class_fields_use_set/basic/2/output.js | 12 + .../class_fields_use_set/basic/3/input.js | 12 + .../class_fields_use_set/basic/3/output.js | 13 + .../class_fields_use_set/basic/4/input.js | 15 + .../class_fields_use_set/basic/4/output.js | 24 + .../class_fields_use_set/basic/5/input.js | 8 + .../class_fields_use_set/basic/5/output.js | 15 + .../src/strip.rs | 51 +- .../tests/fixture/issue-3228/1/output.js | 12 +- .../tests/strip.rs | 100 +- crates/swc_ecma_utils/src/lib.rs | 38 + .../tests/pass/deno-001/full/output/entry.js | 20 + .../pass/deno-001/simple-1/output/entry.js | 12 + .../pass/deno-001/simple-2/output/entry.js | 17 +- .../pass/deno-001/simple-3/output/entry.js | 15 +- .../pass/deno-001/simple-4/output/entry.js | 15 +- 339 files changed, 5546 insertions(+), 2960 deletions(-) rename crates/swc/tests/exec/issues-1xxx/1592/{ => set_public_class_fields}/.swcrc (85%) rename crates/swc/tests/exec/issues-1xxx/1592/{ => set_public_class_fields}/exec.ts (100%) rename crates/swc/tests/exec/issues-2xxx/2655/{1 => set_public_class_fields}/.swcrc (100%) rename crates/swc/tests/exec/issues-2xxx/2655/{1 => set_public_class_fields}/exec.ts (100%) create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/input/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/output/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/input/index.ts create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/output/index.ts create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/input/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/output/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/input/index.ts create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/output/index.ts create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/input/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/output/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/input/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/output/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/input/index.ts create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/output/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/output/index.ts create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/input/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/output/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/input/index.ts create mode 100644 crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/output/index.ts create mode 100644 crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs create mode 100644 crates/swc_ecma_transforms_compat/tests/class_fields_use_set.rs create mode 100644 crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/1/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/1/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/2/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/2/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/3/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/3/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/4/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/4/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/5/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/5/output.js diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index ad4d02fbe98e..f9024d7fb86b 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -213,6 +213,10 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { feature_flag = enable_available_feature_from_es_version(self.target); Either::Right(chain!( + Optional::new( + compat::class_fields_use_set::class_fields_use_set(assumptions.pure_getters), + assumptions.set_public_class_fields, + ), Optional::new( compat::es2022::es2022( comments, diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index 3c795cbb86bb..ad8b84c457ed 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -363,10 +363,10 @@ impl Options { // variable management system based on the syntax contexts. if syntax.typescript() { assumptions.set_class_methods = !transform.use_define_for_class_fields.into_bool(); - assumptions.set_public_class_fields = - !transform.use_define_for_class_fields.into_bool(); } + assumptions.set_public_class_fields = !transform.use_define_for_class_fields.into_bool(); + program.visit_mut_with(&mut resolver( unresolved_mark, top_level_mark, @@ -669,7 +669,6 @@ impl Options { .into_bool(), ts_enum_is_readonly: assumptions.ts_enum_is_readonly, }, - use_define_for_class_fields: !assumptions.set_public_class_fields, import_export_assign_config, ..Default::default() }, @@ -1478,7 +1477,7 @@ pub struct TransformConfig { pub treat_const_enum_as_enum: BoolConfig, #[serde(default)] - pub use_define_for_class_fields: BoolConfig, + pub use_define_for_class_fields: BoolConfig, } #[derive(Debug, Default, Clone, Serialize, Deserialize, Merge)] diff --git a/crates/swc/tests/exec.rs b/crates/swc/tests/exec.rs index 2deeeeb0b3ee..13a2d499cb66 100644 --- a/crates/swc/tests/exec.rs +++ b/crates/swc/tests/exec.rs @@ -8,7 +8,10 @@ use std::{ use anyhow::{Context, Error}; use once_cell::sync::Lazy; use swc::{ - config::{Config, JsMinifyOptions, JscConfig, ModuleConfig, Options, SourceMapsConfig}, + config::{ + Config, JsMinifyOptions, JscConfig, ModuleConfig, Options, SourceMapsConfig, + TransformConfig, + }, try_with_handler, BoolOrDataConfig, Compiler, HandlerOpts, }; use swc_common::{errors::ColorConfig, SourceMap, GLOBALS}; @@ -113,10 +116,7 @@ fn init_helpers() -> Arc { } fn create_matrix(entry: &Path) -> Vec { - // use_define_for_class_fields: false - // force to use [[Set]] instead of [[Define]] - // EsVersion should be lower than EsVersion::Es2022 - let force_set_class_field = entry + let use_define_for_class_fields = entry .parent() .map(|parent| parent.join(".swcrc")) .and_then(|path| fs::read_to_string(path).ok()) @@ -133,8 +133,8 @@ fn create_matrix(entry: &Path) -> Vec { }) .and_then(|content| serde_json::from_value::(content).ok()) .and_then(|config| config.jsc.transform.into_inner()) - .map(|c| c.use_define_for_class_fields == false.into()) - .unwrap_or(false); + .map(|c| c.use_define_for_class_fields) + .unwrap_or_default(); [ EsVersion::Es2022, @@ -148,7 +148,6 @@ fn create_matrix(entry: &Path) -> Vec { EsVersion::Es5, ] .into_iter() - .filter(|e| !force_set_class_field || e < &EsVersion::Es2022) .matrix(|| { let default_es = Syntax::Es(EsConfig { ..Default::default() @@ -177,7 +176,11 @@ fn create_matrix(entry: &Path) -> Vec { config: Config { jsc: JscConfig { syntax: Some(syntax), - transform: None.into(), + transform: Some(TransformConfig { + use_define_for_class_fields, + ..Default::default() + }) + .into(), // true, false external_helpers: (!external_helpers).into(), target: Some(target), @@ -307,11 +310,19 @@ fn get_expected_stdout(input: &Path) -> Result { &Options { config: Config { jsc: JscConfig { - target: Some(EsVersion::Es2021), + target: Some(EsVersion::Es2022), syntax: Some(Syntax::Typescript(TsConfig { decorators: true, ..Default::default() })), + transform: Some(TransformConfig { + use_define_for_class_fields: (!input + .to_string_lossy() + .contains("set_public_class_fields")) + .into(), + ..Default::default() + }) + .into(), ..Default::default() }, module: match input.extension() { diff --git a/crates/swc/tests/exec/issues-1xxx/1592/.swcrc b/crates/swc/tests/exec/issues-1xxx/1592/set_public_class_fields/.swcrc similarity index 85% rename from crates/swc/tests/exec/issues-1xxx/1592/.swcrc rename to crates/swc/tests/exec/issues-1xxx/1592/set_public_class_fields/.swcrc index fbb208f453e1..815a691c0338 100644 --- a/crates/swc/tests/exec/issues-1xxx/1592/.swcrc +++ b/crates/swc/tests/exec/issues-1xxx/1592/set_public_class_fields/.swcrc @@ -12,7 +12,8 @@ }, "transform": { "legacyDecorator": true, - "decoratorMetadata": true + "decoratorMetadata": true, + "useDefineForClassFields": false } }, "module": { diff --git a/crates/swc/tests/exec/issues-1xxx/1592/exec.ts b/crates/swc/tests/exec/issues-1xxx/1592/set_public_class_fields/exec.ts similarity index 100% rename from crates/swc/tests/exec/issues-1xxx/1592/exec.ts rename to crates/swc/tests/exec/issues-1xxx/1592/set_public_class_fields/exec.ts diff --git a/crates/swc/tests/exec/issues-2xxx/2655/1/.swcrc b/crates/swc/tests/exec/issues-2xxx/2655/set_public_class_fields/.swcrc similarity index 100% rename from crates/swc/tests/exec/issues-2xxx/2655/1/.swcrc rename to crates/swc/tests/exec/issues-2xxx/2655/set_public_class_fields/.swcrc diff --git a/crates/swc/tests/exec/issues-2xxx/2655/1/exec.ts b/crates/swc/tests/exec/issues-2xxx/2655/set_public_class_fields/exec.ts similarity index 100% rename from crates/swc/tests/exec/issues-2xxx/2655/1/exec.ts rename to crates/swc/tests/exec/issues-2xxx/2655/set_public_class_fields/exec.ts diff --git a/crates/swc/tests/fixture/issues-1xxx/1160/output/entry.ts b/crates/swc/tests/fixture/issues-1xxx/1160/output/entry.ts index 47c111acb030..332ced800ee1 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1160/output/entry.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1160/output/entry.ts @@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); +const _defineProperty = require("@swc/helpers/lib/_define_property.js").default; const _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; const _tsMetadata = require("@swc/helpers/lib/_ts_metadata.js").default; var MyEnum; @@ -10,6 +11,9 @@ var MyEnum; MyEnum["y"] = "yyy"; })(MyEnum || (MyEnum = {})); class Xpto { + constructor(){ + _defineProperty(this, "value", void 0); + } } _tsDecorate([ Decorator(), diff --git a/crates/swc/tests/fixture/issues-1xxx/1219/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1219/output/index.ts index 03f5f5d4a30d..5af17e154f85 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1219/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1219/output/index.ts @@ -1,6 +1,7 @@ +import _define_property from "@swc/helpers/src/_define_property.mjs"; class Foo { constructor(){ - this.static = 5; - this.declare = 5; + _define_property(this, "static", 5); + _define_property(this, "declare", 5); } } diff --git a/crates/swc/tests/fixture/issues-1xxx/1278/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1278/output/index.ts index 8295065ec9df..ec942df13fbb 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1278/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1278/output/index.ts @@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); +const _defineProperty = require("@swc/helpers/lib/_define_property.js").default; const _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; const _tsMetadata = require("@swc/helpers/lib/_ts_metadata.js").default; function MyDecorator(klass) { @@ -11,6 +12,9 @@ function MyDecorator(klass) { }; } class MyClass { + constructor(){ + _defineProperty(this, "prop", void 0); + } } _tsDecorate([ MyDecorator(MyClass), diff --git a/crates/swc/tests/fixture/issues-1xxx/1306/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1306/case1/output/index.ts index ba8227dab46f..b03c90a3d989 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1306/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1306/case1/output/index.ts @@ -2,6 +2,7 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; +import _create_class from "@swc/helpers/src/_create_class.mjs"; var _name = /*#__PURE__*/ new WeakMap(); var Animal = /*#__PURE__*/ function() { "use strict"; @@ -13,9 +14,13 @@ var Animal = /*#__PURE__*/ function() { }); _class_private_field_set(this, _name, name); } - var _proto = Animal.prototype; - _proto.noise = function noise() { - return _class_private_field_get(this, _name).toUpperCase(); - }; + _create_class(Animal, [ + { + key: "noise", + value: function noise() { + return _class_private_field_get(this, _name).toUpperCase(); + } + } + ]); return Animal; }(); diff --git a/crates/swc/tests/fixture/issues-1xxx/1341/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1341/case1/output/index.ts index a286e6d96ca3..bdf7eb26e731 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1341/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1341/case1/output/index.ts @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; +const _defineProperty = require("@swc/helpers/lib/_define_property.js").default; class A { foo() { var _this = this; @@ -23,7 +24,7 @@ class A { })(); } constructor(){ - this.val = "1"; + _defineProperty(this, "val", "1"); } } new A().foo(); diff --git a/crates/swc/tests/fixture/issues-1xxx/1345/input/.swcrc b/crates/swc/tests/fixture/issues-1xxx/1345/input/.swcrc index 044d936cf8b3..39da08011741 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1345/input/.swcrc +++ b/crates/swc/tests/fixture/issues-1xxx/1345/input/.swcrc @@ -7,6 +7,7 @@ "dynamicImport": true }, "transform": { + "useDefineForClassFields": false, "legacyDecorator": true, "decoratorMetadata": true, "optimizer": { @@ -18,4 +19,4 @@ } } } -} +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-1xxx/1362/case1/input/.swcrc b/crates/swc/tests/fixture/issues-1xxx/1362/case1/input/.swcrc index 6b748bbd4168..a80ee8054225 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1362/case1/input/.swcrc +++ b/crates/swc/tests/fixture/issues-1xxx/1362/case1/input/.swcrc @@ -6,6 +6,7 @@ "decorators": true }, "transform": { + "useDefineForClassFields": false, "legacyDecorator": true, "decoratorMetadata": true }, @@ -14,4 +15,4 @@ "module": { "type": "commonjs" } -} +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-1xxx/1421/case1/input/.swcrc b/crates/swc/tests/fixture/issues-1xxx/1421/case1/input/.swcrc index 043b78b339af..f2c635470c59 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1421/case1/input/.swcrc +++ b/crates/swc/tests/fixture/issues-1xxx/1421/case1/input/.swcrc @@ -7,6 +7,7 @@ "dynamicImport": false }, "transform": { + "useDefineForClassFields": false, "legacyDecorator": true, "decoratorMetadata": true } @@ -14,4 +15,4 @@ "module": { "type": "commonjs" } -} +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-1xxx/1456/case1/input/.swcrc b/crates/swc/tests/fixture/issues-1xxx/1456/case1/input/.swcrc index 912d721c7e91..6f9b4e32e1fa 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1456/case1/input/.swcrc +++ b/crates/swc/tests/fixture/issues-1xxx/1456/case1/input/.swcrc @@ -6,6 +6,7 @@ "decorators": true }, "transform": { + "useDefineForClassFields": false, "legacyDecorator": true, "decoratorMetadata": true } @@ -16,4 +17,4 @@ "env": { "targets": "node 12" } -} +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-1xxx/1456/case2/input/.swcrc b/crates/swc/tests/fixture/issues-1xxx/1456/case2/input/.swcrc index 912d721c7e91..6f9b4e32e1fa 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1456/case2/input/.swcrc +++ b/crates/swc/tests/fixture/issues-1xxx/1456/case2/input/.swcrc @@ -6,6 +6,7 @@ "decorators": true }, "transform": { + "useDefineForClassFields": false, "legacyDecorator": true, "decoratorMetadata": true } @@ -16,4 +17,4 @@ "env": { "targets": "node 12" } -} +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-1xxx/1505/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1505/case1/output/index.ts index e4cf04d0f2d8..b2fa88eec544 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1505/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1505/case1/output/index.ts @@ -1,4 +1,5 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; import _inherits from "@swc/helpers/src/_inherits.mjs"; import _create_super from "@swc/helpers/src/_create_super.mjs"; var MyClass = function MyClass() { @@ -16,6 +17,6 @@ export var fn = function() { } return _class; }(MyClass); - _class.x = 5; + _define_property(_class, "x", 5); return _class; }; diff --git a/crates/swc/tests/fixture/issues-1xxx/1505/case3/output/index.tsx b/crates/swc/tests/fixture/issues-1xxx/1505/case3/output/index.tsx index 089842fc5335..e3bdcf964b77 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1505/case3/output/index.tsx +++ b/crates/swc/tests/fixture/issues-1xxx/1505/case3/output/index.tsx @@ -1,4 +1,5 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; import _inherits from "@swc/helpers/src/_inherits.mjs"; import _create_super from "@swc/helpers/src/_create_super.mjs"; var Component = function Component() { @@ -20,6 +21,6 @@ var withTeamsForUser = function(_WrappedComponent) { } return _class; }(Component); - _class.displayName = "x"; + _define_property(_class, "displayName", "x"); return _class; }; diff --git a/crates/swc/tests/fixture/issues-1xxx/1505/case5/output/index.tsx b/crates/swc/tests/fixture/issues-1xxx/1505/case5/output/index.tsx index 7c6635ad45c5..58cb85a979ce 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1505/case5/output/index.tsx +++ b/crates/swc/tests/fixture/issues-1xxx/1505/case5/output/index.tsx @@ -1,4 +1,5 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; import _inherits from "@swc/helpers/src/_inherits.mjs"; import _create_super from "@swc/helpers/src/_create_super.mjs"; var withTeamsForUser = function() { @@ -12,6 +13,6 @@ var withTeamsForUser = function() { } return _class; }(Component); - _class.displayName = "x"; + _define_property(_class, "displayName", "x"); return _class; }; diff --git a/crates/swc/tests/fixture/issues-1xxx/1515/case1/output/input.ts b/crates/swc/tests/fixture/issues-1xxx/1515/case1/output/input.ts index 6becf4281795..cf03241c703c 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1515/case1/output/input.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1515/case1/output/input.ts @@ -6,11 +6,12 @@ Object.defineProperty(exports, "ServiceError", { enumerable: true, get: ()=>ServiceError }); +const _defineProperty = require("@swc/helpers/lib/_define_property.js").default; class ServiceError extends Error { constructor(...args){ super(...args); - this.code = ServiceError.Code.badResponse; - this.name = "ServiceError.BadResponse"; + _defineProperty(this, "code", ServiceError.Code.badResponse); + _defineProperty(this, "name", "ServiceError.BadResponse"); } } (function(ServiceError1) { @@ -28,8 +29,8 @@ class ServiceError extends Error { constructor(...args){ super(...args); // Service was probably not registered, or using the wrong channel - this.code = 404; - this.name = "ServiceError.ServiceNotFound"; + _defineProperty(this, "code", 404); + _defineProperty(this, "name", "ServiceError.ServiceNotFound"); } } ServiceError1.ServiceNotFound = ServiceNotFound; diff --git a/crates/swc/tests/fixture/issues-1xxx/1612/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1612/case1/output/index.ts index f51f72eea4be..87f4c14bb9e9 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1612/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1612/case1/output/index.ts @@ -1,12 +1,17 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _create_class from "@swc/helpers/src/_create_class.mjs"; var Test = /*#__PURE__*/ function() { "use strict"; function Test() { _class_call_check(this, Test); } - var _proto = Test.prototype; - _proto.test = function test() { - a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1); - }; + _create_class(Test, [ + { + key: "test", + value: function test() { + a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1).a(1); + } + } + ]); return Test; }(); diff --git a/crates/swc/tests/fixture/issues-1xxx/1869/decorator/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1869/decorator/output/index.ts index 30150cea6560..a2f5ca0176ca 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1869/decorator/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1869/decorator/output/index.ts @@ -1,12 +1,13 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; import _ts_decorate from "@swc/helpers/src/_ts_decorate.mjs"; var _TestClass; var TestClass = (_TestClass = function TestClass() { "use strict"; _class_call_check(this, TestClass); -}, _TestClass.Something = "hello", _TestClass.SomeProperties = { +}, _define_property(_TestClass, "Something", "hello"), _define_property(_TestClass, "SomeProperties", { firstProp: _TestClass.Something -}, _TestClass); +}), _TestClass); TestClass = _ts_decorate([ someClassDecorator ], TestClass); diff --git a/crates/swc/tests/fixture/issues-2xxx/2011/no-minify/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2011/no-minify/output/index.js index ce560440ba7a..a231389b3606 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2011/no-minify/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2011/no-minify/output/index.js @@ -1,3 +1,4 @@ +import _define_property from "@swc/helpers/src/_define_property.mjs"; var _ClassB; var ClassA = function ClassA() { "use strict"; @@ -10,4 +11,4 @@ module.exports = (_ClassB = /*#__PURE__*/ function() { this.bb = new ClassB.MyA(); }; return ClassB; -}(), _ClassB.MyA = ClassA, _ClassB); +}(), _define_property(_ClassB, "MyA", ClassA), _ClassB); diff --git a/crates/swc/tests/fixture/issues-2xxx/2011/reduced/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2011/reduced/output/index.js index d853080ee285..0fd88a92eb20 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2011/reduced/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2011/reduced/output/index.js @@ -1,8 +1,9 @@ var t; -module.exports = ((t = function() { +import r from "@swc/helpers/src/_define_property.mjs"; +module.exports = (r(t = function() { "use strict"; function t() {} return t.prototype.it = function() { this.bb = new t.MyA(); }, t; -}()).MyA = function() {}, t); +}(), "MyA", function() {}), t); diff --git a/crates/swc/tests/fixture/issues-2xxx/2139/output/index.tsx b/crates/swc/tests/fixture/issues-2xxx/2139/output/index.tsx index dd271f8a57c3..60399d62422b 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2139/output/index.tsx +++ b/crates/swc/tests/fixture/issues-2xxx/2139/output/index.tsx @@ -1,3 +1,4 @@ +import _define_property from "@swc/helpers/src/_define_property.mjs"; class ReusablePayments extends PureComponent { componentDidMount() { this.setDefaultReusablePayment(); @@ -81,10 +82,10 @@ class ReusablePayments extends PureComponent { } constructor(...args){ super(...args); - this.handleSelectPayment = (selected)=>{ + _define_property(this, "handleSelectPayment", (selected)=>{ return this.props.onChange(selected); - }; - this.handleDeletePaymentSource = (id, deletePaymentSource)=>{ + }); + _define_property(this, "handleDeletePaymentSource", (id, deletePaymentSource)=>{ var _this_props = this.props, selectedReusablePayment = _this_props.selectedReusablePayment, onChange = _this_props.onChange; if (onChange && selectedReusablePayment && selectedReusablePayment.id === id) { this.setDefaultReusablePayment(selectedReusablePayment); @@ -94,7 +95,7 @@ class ReusablePayments extends PureComponent { id } }); - }; + }); } } export { ReusablePayments as default }; diff --git a/crates/swc/tests/fixture/issues-2xxx/2216/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2216/output/index.ts index c8d3c9da185c..5622aa581a56 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2216/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2216/output/index.ts @@ -1,7 +1,12 @@ +import _create_class from "@swc/helpers/src/_create_class.mjs"; export var ATestForSwc = /*#__PURE__*/ function() { "use strict"; function ATestForSwc() {} - var _proto = ATestForSwc.prototype; - _proto.testMethod = function testMethod() {}; + _create_class(ATestForSwc, [ + { + key: "testMethod", + value: function testMethod() {} + } + ]); return ATestForSwc; }(); diff --git a/crates/swc/tests/fixture/issues-2xxx/2990/1/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2990/1/output/index.ts index 018dc73b713c..20e99796c60b 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2990/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2990/1/output/index.ts @@ -1,2 +1,6 @@ +import _define_property from "@swc/helpers/src/_define_property.mjs"; class Game { + constructor(){ + _define_property(this, "private", void 0); + } } diff --git a/crates/swc/tests/fixture/issues-2xxx/2990/2/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2990/2/output/index.ts index f230fa0f41dd..5ca3940db8c2 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2990/2/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2990/2/output/index.ts @@ -1,2 +1,12 @@ +import _define_property from "@swc/helpers/src/_define_property.mjs"; class Foo { + constructor(){ + _define_property(this, "public", void 0); + _define_property(this, "protected", void 0); + _define_property(this, "private", void 0); + _define_property(this, "abstract", void 0); + _define_property(this, "readonly", void 0); + _define_property(this, "override", void 0); + _define_property(this, "static", void 0); + } } diff --git a/crates/swc/tests/fixture/issues-3xxx/3055/1/output/index.ts b/crates/swc/tests/fixture/issues-3xxx/3055/1/output/index.ts index 59c93e111a27..e2b2fe71ab11 100644 --- a/crates/swc/tests/fixture/issues-3xxx/3055/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-3xxx/3055/1/output/index.ts @@ -1,5 +1,6 @@ import _class_private_method_get from "@swc/helpers/src/_class_private_method_get.mjs"; import _class_private_method_init from "@swc/helpers/src/_class_private_method_init.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; var _link = /*#__PURE__*/ new WeakSet(); export class Node { link() { @@ -7,7 +8,8 @@ export class Node { } constructor(){ _class_private_method_init(this, _link); - this.childNodes = []; + _define_property(this, "childNodes", []); + _define_property(this, "parent", void 0); } } function link(parent) { diff --git a/crates/swc/tests/fixture/issues-3xxx/3337/output/input.ts b/crates/swc/tests/fixture/issues-3xxx/3337/output/input.ts index fb5989c545a9..505bf712af0a 100644 --- a/crates/swc/tests/fixture/issues-3xxx/3337/output/input.ts +++ b/crates/swc/tests/fixture/issues-3xxx/3337/output/input.ts @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); var _classCallCheck = require("@swc/helpers/lib/_class_call_check.js").default; +var _defineProperty = require("@swc/helpers/lib/_define_property.js").default; var _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; var _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; var _tsMetadata = require("@swc/helpers/lib/_ts_metadata.js").default; @@ -10,6 +11,7 @@ var _joiful = /*#__PURE__*/ _interopRequireWildcard(require("joiful")); var Schema = function Schema() { "use strict"; _classCallCheck(this, Schema); + _defineProperty(this, "id", void 0); }; _tsDecorate([ _joiful.string().guid().required(), diff --git a/crates/swc/tests/fixture/issues-4xxx/4006/1/output/index.map b/crates/swc/tests/fixture/issues-4xxx/4006/1/output/index.map index a023cab74b8a..87498ca1e57d 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4006/1/output/index.map +++ b/crates/swc/tests/fixture/issues-4xxx/4006/1/output/index.map @@ -1,5 +1,5 @@ { - "mappings": "AAAA,SAASA,IAAI,EAAEC,GAAG,EAAEC,UAAU,QAAQ,MAAM;AAE5C,OAAO,MAAMC,YAAYD;IAkBrBE,SAAS;QACL,OAAOJ,IAAI,CAAC,UAAU,EAAE,IAAI,CAACK,IAAI,CAAC,KAAK,CAAC;IAC5C;IAPAC,aAAc;QACV,KAAK;QACL,IAAI,CAACD,IAAI,GAAG;IAChB;AAKJ,CAAC;AArBYF,IAGFI,SAASN,GAAG,CAAC;;;;IAIpB,CAAC;AAPQE,IASFK,aAAa;IAChBH,MAAM;QAAEI,MAAMC;IAAO;AACzB;AAWJC,eAAeC,MAAM,CAAC,OAAOT", + "mappings": ";AAAA,SAASA,IAAI,EAAEC,GAAG,EAAEC,UAAU,QAAQ,MAAM;AAE5C,OAAO,MAAMC,YAAYD;IAkBrBE,SAAS;QACL,OAAOJ,IAAI,CAAC,UAAU,EAAE,IAAI,CAACK,IAAI,CAAC,KAAK,CAAC;IAC5C;IAPAC,aAAc;QACV,KAAK;QAbTD,uBAAAA,QAAAA,KAAAA;QAcI,IAAI,CAACA,IAAI,GAAG;IAChB;AAKJ,CAAC;AAlBG,iBAHSF,KAGFI,UAASN,GAAG,CAAC;;;;IAIpB,CAAC;AAED,iBATSE,KASFK,cAAa;IAChBH,MAAM;QAAEI,MAAMC;IAAO;AACzB;AAWJC,eAAeC,MAAM,CAAC,OAAOT", "names": [ "html", "css", diff --git a/crates/swc/tests/fixture/issues-4xxx/4006/1/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4006/1/output/index.ts index 67a3b9c141cc..21e128b30b82 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4006/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-4xxx/4006/1/output/index.ts @@ -1,3 +1,4 @@ +import _define_property from "@swc/helpers/src/_define_property.mjs"; import { html, css, LitElement } from "lit"; export class App extends LitElement { render() { @@ -5,17 +6,18 @@ export class App extends LitElement { } constructor(){ super(); + _define_property(this, "name", void 0); this.name = "Somebody"; } } -App.styles = css` +_define_property(App, "styles", css` p { color: blue; } - `; -App.properties = { + `); +_define_property(App, "properties", { name: { type: String } -}; +}); customElements.define("app", App); diff --git a/crates/swc/tests/fixture/issues-4xxx/4063/1/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4063/1/output/index.ts index 8ad0503ec86d..1b20a0e88329 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4063/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-4xxx/4063/1/output/index.ts @@ -1,8 +1,9 @@ define([ "require", "exports", + "@swc/helpers/src/_define_property.mjs", "@swc/helpers/src/_ts_decorate.mjs" -], function(require, exports, _tsDecorate) { +], function(require, exports, _defineProperty, _tsDecorate) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true @@ -11,6 +12,7 @@ define([ enumerable: true, get: ()=>_class }); + _defineProperty = _defineProperty.default; _tsDecorate = _tsDecorate.default; function state() {} class Controller { @@ -19,7 +21,7 @@ define([ onChange() {} constructor(...args){ super(...args); - this.isTest = false; + _defineProperty(this, "isTest", false); } } _tsDecorate([ diff --git a/crates/swc/tests/fixture/issues-4xxx/4208/1/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4208/1/output/index.ts index b819dc3bec73..2a0cd3f2cee9 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4208/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-4xxx/4208/1/output/index.ts @@ -1,12 +1,13 @@ import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; export var CompanyBgStore = function CompanyBgStore() { "use strict"; _class_call_check(this, CompanyBgStore); - this.corpName = 123; + _define_property(this, "corpName", 123); var _this = this; - this.getBusinessInfo = _async_to_generator(function() { + _define_property(this, "getBusinessInfo", _async_to_generator(function() { var corpName; var _arguments = arguments; return _ts_generator(this, function(_state) { @@ -16,5 +17,5 @@ export var CompanyBgStore = function CompanyBgStore() { 2 ]; }); - }); + })); }; diff --git a/crates/swc/tests/fixture/issues-5xxx/5258/output/index.ts b/crates/swc/tests/fixture/issues-5xxx/5258/output/index.ts index cf9c1f390b5c..893710d1d0f6 100644 --- a/crates/swc/tests/fixture/issues-5xxx/5258/output/index.ts +++ b/crates/swc/tests/fixture/issues-5xxx/5258/output/index.ts @@ -1,13 +1,15 @@ define([ "require", "exports", + "@swc/helpers/src/_define_property.mjs", "@swc/helpers/src/_ts_decorate.mjs" -], function(require, exports, _tsDecorate) { +], function(require, exports, _defineProperty, _tsDecorate) { "use strict"; Object.defineProperty(exports, "FileSystemError", { enumerable: true, get: ()=>FileSystemError }); + _defineProperty = _defineProperty.default; _tsDecorate = _tsDecorate.default; function es5ClassCompat(target) { function _() { @@ -39,6 +41,7 @@ define([ } constructor(uriOrMessage, code = FileSystemProviderErrorCode.Unknown, terminator){ super(URI.isUri(uriOrMessage) ? uriOrMessage.toString(true) : uriOrMessage); + _defineProperty(this, "code", void 0); this.code = terminator?.name ?? 'Unknown'; markAsFileSystemProviderError(this, code); if (typeof Object.setPrototypeOf === 'function') { diff --git a/crates/swc/tests/fixture/issues-5xxx/5626/output/index.ts b/crates/swc/tests/fixture/issues-5xxx/5626/output/index.ts index 30b64a296f90..3e90dcecc72d 100644 --- a/crates/swc/tests/fixture/issues-5xxx/5626/output/index.ts +++ b/crates/swc/tests/fixture/issues-5xxx/5626/output/index.ts @@ -1,4 +1,5 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; import _ts_decorate from "@swc/helpers/src/_ts_decorate.mjs"; import _ts_metadata from "@swc/helpers/src/_ts_metadata.mjs"; function Prop() { @@ -7,6 +8,7 @@ function Prop() { var Example = function Example() { "use strict"; _class_call_check(this, Example); + _define_property(this, "prop", void 0); }; export { Example as default }; _ts_decorate([ diff --git a/crates/swc/tests/fixture/issues-6xxx/6951/1/output/index.ts b/crates/swc/tests/fixture/issues-6xxx/6951/1/output/index.ts index 734109078ce7..36ffec360e3b 100644 --- a/crates/swc/tests/fixture/issues-6xxx/6951/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-6xxx/6951/1/output/index.ts @@ -1,12 +1,13 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; import _ts_decorate from "@swc/helpers/src/_ts_decorate.mjs"; var A = function A() { "use strict"; _class_call_check(this, A); - this.a = true; - this.b = false; + _define_property(this, "a", true); + _define_property(this, "b", false); }; -A.c = 1; +_define_property(A, "c", 1); _ts_decorate([ observable ], A.prototype, "a", void 0); diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/input/.swcrc new file mode 100644 index 000000000000..6e60a2210af6 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/input/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript" + }, + "target": "es2020", + "transform": { + "useDefineForClassFields": true + } + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/input/index.js b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/input/index.js new file mode 100644 index 000000000000..7dfd2a98d5cf --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/input/index.js @@ -0,0 +1,6 @@ +class Foo { + a = 1; + #b = 2; + static c = 3; + static #d = 4; +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/output/index.js new file mode 100644 index 000000000000..d7496e126716 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_JS/output/index.js @@ -0,0 +1,17 @@ +import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; +var _b = /*#__PURE__*/ new WeakMap(); +class Foo { + constructor(){ + _define_property(this, "a", 1); + _class_private_field_init(this, _b, { + writable: true, + value: 2 + }); + } +} +_define_property(Foo, "c", 3); +var _d = { + writable: true, + value: 4 +}; diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/input/.swcrc new file mode 100644 index 000000000000..21959304b2c2 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/input/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "es2020", + "transform": { + "useDefineForClassFields": true + } + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/input/index.ts b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/input/index.ts new file mode 100644 index 000000000000..c8557077a618 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/input/index.ts @@ -0,0 +1,8 @@ +class Foo { + a = 1; + #b = 2; + static c = 3; + static #d = 4; + + constructor(public foo:number) {} +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/output/index.ts b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/output/index.ts new file mode 100644 index 000000000000..b8e2c65a13e7 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2020_TS/output/index.ts @@ -0,0 +1,22 @@ +import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; +var _b = /*#__PURE__*/ new WeakMap(); +class Foo { + constructor(foo){ + _define_property(this, "foo", void 0); + _define_property(this, "a", void 0); + _class_private_field_init(this, _b, { + writable: true, + value: void 0 + }); + this.foo = foo; + this.a = 1; + _class_private_field_set(this, _b, 2); + } +} +_define_property(Foo, "c", 3); +var _d = { + writable: true, + value: 4 +}; diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/input/.swcrc new file mode 100644 index 000000000000..8d811c226f2d --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/input/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript" + }, + "target": "es2022", + "transform": { + "useDefineForClassFields": true + } + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/input/index.js b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/input/index.js new file mode 100644 index 000000000000..7dfd2a98d5cf --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/input/index.js @@ -0,0 +1,6 @@ +class Foo { + a = 1; + #b = 2; + static c = 3; + static #d = 4; +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/output/index.js new file mode 100644 index 000000000000..7dfd2a98d5cf --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_JS/output/index.js @@ -0,0 +1,6 @@ +class Foo { + a = 1; + #b = 2; + static c = 3; + static #d = 4; +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/input/.swcrc new file mode 100644 index 000000000000..d9fc163c2415 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/input/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "es2022", + "transform": { + "useDefineForClassFields": true + } + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/input/index.ts b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/input/index.ts new file mode 100644 index 000000000000..c8557077a618 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/input/index.ts @@ -0,0 +1,8 @@ +class Foo { + a = 1; + #b = 2; + static c = 3; + static #d = 4; + + constructor(public foo:number) {} +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/output/index.ts b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/output/index.ts new file mode 100644 index 000000000000..6596a36a174b --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useDefineForClassFields/2022_TS/output/index.ts @@ -0,0 +1,12 @@ +class Foo { + foo; + a; + #b; + static c = 3; + static #d = 4; + constructor(foo){ + this.foo = foo; + this.a = 1; + this.#b = 2; + } +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/input/.swcrc new file mode 100644 index 000000000000..44db79e605d3 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/input/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript" + }, + "target": "es2022", + "transform": { + "useDefineForClassFields": false + } + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/input/index.js b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/input/index.js new file mode 100644 index 000000000000..7dfd2a98d5cf --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/input/index.js @@ -0,0 +1,6 @@ +class Foo { + a = 1; + #b = 2; + static c = 3; + static #d = 4; +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/output/index.js new file mode 100644 index 000000000000..fe7e09fd793a --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/2022_JS/output/index.js @@ -0,0 +1,11 @@ +class Foo { + #b; + static{ + this.c = 3; + } + static #d = 4; + constructor(){ + this.a = 1; + this.#b = 2; + } +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/input/.swcrc new file mode 100644 index 000000000000..c32bd7eed571 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/input/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript" + }, + "target": "es2020", + "transform": { + "useDefineForClassFields": false + } + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/input/index.js b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/input/index.js new file mode 100644 index 000000000000..7dfd2a98d5cf --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/input/index.js @@ -0,0 +1,6 @@ +class Foo { + a = 1; + #b = 2; + static c = 3; + static #d = 4; +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/output/index.js new file mode 100644 index 000000000000..cd0728173c56 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_JS/output/index.js @@ -0,0 +1,20 @@ +import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; +var _b = /*#__PURE__*/ new WeakMap(); +class Foo { + constructor(){ + _class_private_field_init(this, _b, { + writable: true, + value: void 0 + }); + this.a = 1; + _class_private_field_set(this, _b, 2); + } +} +(()=>{ + Foo.c = 3; +})(); +var _d = { + writable: true, + value: 4 +}; diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/input/.swcrc new file mode 100644 index 000000000000..c69a2684de51 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/input/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "es2020", + "transform": { + "useDefineForClassFields": false + } + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/input/index.ts b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/input/index.ts new file mode 100644 index 000000000000..c8557077a618 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/input/index.ts @@ -0,0 +1,8 @@ +class Foo { + a = 1; + #b = 2; + static c = 3; + static #d = 4; + + constructor(public foo:number) {} +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/output/index.js new file mode 100644 index 000000000000..cd0728173c56 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/output/index.js @@ -0,0 +1,20 @@ +import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; +var _b = /*#__PURE__*/ new WeakMap(); +class Foo { + constructor(){ + _class_private_field_init(this, _b, { + writable: true, + value: void 0 + }); + this.a = 1; + _class_private_field_set(this, _b, 2); + } +} +(()=>{ + Foo.c = 3; +})(); +var _d = { + writable: true, + value: 4 +}; diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/output/index.ts b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/output/index.ts new file mode 100644 index 000000000000..341c6c4a0d3e --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2020_TS/output/index.ts @@ -0,0 +1,21 @@ +import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; +var _b = /*#__PURE__*/ new WeakMap(); +class Foo { + constructor(foo){ + _class_private_field_init(this, _b, { + writable: true, + value: void 0 + }); + this.foo = foo; + this.a = 1; + _class_private_field_set(this, _b, 2); + } +} +(()=>{ + Foo.c = 3; +})(); +var _d = { + writable: true, + value: 4 +}; diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/input/.swcrc new file mode 100644 index 000000000000..44db79e605d3 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/input/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript" + }, + "target": "es2022", + "transform": { + "useDefineForClassFields": false + } + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/input/index.js b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/input/index.js new file mode 100644 index 000000000000..7dfd2a98d5cf --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/input/index.js @@ -0,0 +1,6 @@ +class Foo { + a = 1; + #b = 2; + static c = 3; + static #d = 4; +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/output/index.js new file mode 100644 index 000000000000..fe7e09fd793a --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_JS/output/index.js @@ -0,0 +1,11 @@ +class Foo { + #b; + static{ + this.c = 3; + } + static #d = 4; + constructor(){ + this.a = 1; + this.#b = 2; + } +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/input/.swcrc new file mode 100644 index 000000000000..ecc47f44ec91 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/input/.swcrc @@ -0,0 +1,11 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "es2022", + "transform": { + "useDefineForClassFields": false + } + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/input/index.ts b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/input/index.ts new file mode 100644 index 000000000000..c8557077a618 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/input/index.ts @@ -0,0 +1,8 @@ +class Foo { + a = 1; + #b = 2; + static c = 3; + static #d = 4; + + constructor(public foo:number) {} +} diff --git a/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/output/index.ts b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/output/index.ts new file mode 100644 index 000000000000..1ab1094169d9 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6985/useSetForClassFields/2022_TS/output/index.ts @@ -0,0 +1,12 @@ +class Foo { + #b; + static{ + this.c = 3; + } + static #d = 4; + constructor(foo){ + this.foo = foo; + this.a = 1; + this.#b = 2; + } +} diff --git a/crates/swc/tests/fixture/next.js/server/render/1/output/index.tsx b/crates/swc/tests/fixture/next.js/server/render/1/output/index.tsx index a82be7768794..f8b92d659589 100644 --- a/crates/swc/tests/fixture/next.js/server/render/1/output/index.tsx +++ b/crates/swc/tests/fixture/next.js/server/render/1/output/index.tsx @@ -30,6 +30,20 @@ function noRouter() { throw new Error(message); } class ServerRouter { + route; + pathname; + query; + asPath; + basePath; + events; + isFallback; + locale; + isReady; + locales; + defaultLocale; + domainLocales; + isPreview; + isLocaleDomain; constructor(pathname, query, as, { isFallback }, isReady, basePath, locale, locales, defaultLocale, domainLocales, isPreview, isLocaleDomain){ this.route = pathname.replace(/\/$/, "") || "/"; this.pathname = pathname; diff --git a/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts b/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts index c1cfad6f6ef0..f0df6abe2148 100644 --- a/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts +++ b/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts @@ -1,363 +1,368 @@ import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _create_class from "@swc/helpers/src/_create_class.mjs"; import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; var Router = /*#__PURE__*/ function() { "use strict"; function Router() { _class_call_check(this, Router); } - var _proto = Router.prototype; - _proto.change = function change(method, url, as, options, forcedScroll) { - var _this = this; - return _async_to_generator(function() { - var shouldResolveHref, prevLocale, parsedAs, localePathResult, didNavigate, _this_locales, detectedDomain, asNoBasePath, _options_shallow, shallow, routeProps, cleanedAs, localeChange, parsed, pathname, query, pages, rewrites, ref, err, resolvedAs, rewritesResult, route, parsedAs1, asPathname, routeRegex, routeMatch, shouldInterpolate, interpolatedAs, missingParams, _self___NEXT_DATA___props, _self___NEXT_DATA___props_pageProps, routeInfo, error, props, __N_SSG, __N_SSP, destination, parsedHref, _prepareUrlAs, newUrl, newAs, notFoundRoute, _, isValidShallowRoute, _options_scroll, shouldScroll, resetScroll, err1; - return _ts_generator(this, function(_state) { - switch(_state.label){ - case 0: - if (!isLocalURL(url)) { - window.location.href = url; - return [ - 2, - false - ]; - } - shouldResolveHref = options._h || options._shouldResolveHref || pathNoQueryHash(url) === pathNoQueryHash(as); - // for static pages with query params in the URL we delay - // marking the router ready until after the query is updated - if (options._h) { - _this.isReady = true; - } - prevLocale = _this.locale; - if (process.env.__NEXT_I18N_SUPPORT) { - _this.locale = options.locale === false ? _this.defaultLocale : options.locale || _this.locale; - if (typeof options.locale === "undefined") { - options.locale = _this.locale; - } - parsedAs = parseRelativeUrl(hasBasePath(as) ? delBasePath(as) : as); - localePathResult = normalizeLocalePath(parsedAs.pathname, _this.locales); - if (localePathResult.detectedLocale) { - _this.locale = localePathResult.detectedLocale; - parsedAs.pathname = addBasePath(parsedAs.pathname); - as = formatWithValidation(parsedAs); - url = addBasePath(normalizeLocalePath(hasBasePath(url) ? delBasePath(url) : url, _this.locales).pathname); - } - didNavigate = false; - // we need to wrap this in the env check again since regenerator runtime - // moves this on its own due to the return - if (process.env.__NEXT_I18N_SUPPORT) { - ; - // if the locale isn't configured hard navigate to show 404 page - if (!((_this_locales = _this.locales) === null || _this_locales === void 0 ? void 0 : _this_locales.includes(_this.locale))) { - parsedAs.pathname = addLocale(parsedAs.pathname, _this.locale); - window.location.href = formatWithValidation(parsedAs); - // this was previously a return but was removed in favor - // of better dead code elimination with regenerator runtime - didNavigate = true; + _create_class(Router, [ + { + key: "change", + value: function change(method, url, as, options, forcedScroll) { + var _this = this; + return _async_to_generator(function() { + var shouldResolveHref, prevLocale, parsedAs, localePathResult, didNavigate, _this_locales, detectedDomain, asNoBasePath, _options_shallow, shallow, routeProps, cleanedAs, localeChange, parsed, pathname, query, pages, rewrites, ref, err, resolvedAs, rewritesResult, route, parsedAs1, asPathname, routeRegex, routeMatch, shouldInterpolate, interpolatedAs, missingParams, _self___NEXT_DATA___props, _self___NEXT_DATA___props_pageProps, routeInfo, error, props, __N_SSG, __N_SSP, destination, parsedHref, _prepareUrlAs, newUrl, newAs, notFoundRoute, _, isValidShallowRoute, _options_scroll, shouldScroll, resetScroll, err1; + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + if (!isLocalURL(url)) { + window.location.href = url; + return [ + 2, + false + ]; } - } - detectedDomain = detectDomainLocale(_this.domainLocales, undefined, _this.locale); - // we need to wrap this in the env check again since regenerator runtime - // moves this on its own due to the return - if (process.env.__NEXT_I18N_SUPPORT) { - // if we are navigating to a domain locale ensure we redirect to the - // correct domain - if (!didNavigate && detectedDomain && _this.isLocaleDomain && self.location.hostname !== detectedDomain.domain) { - asNoBasePath = delBasePath(as); - window.location.href = "http".concat(detectedDomain.http ? "" : "s", "://").concat(detectedDomain.domain).concat(addBasePath("".concat(_this.locale === detectedDomain.defaultLocale ? "" : "/".concat(_this.locale)).concat(asNoBasePath === "/" ? "" : asNoBasePath) || "/")); - // this was previously a return but was removed in favor - // of better dead code elimination with regenerator runtime - didNavigate = true; + shouldResolveHref = options._h || options._shouldResolveHref || pathNoQueryHash(url) === pathNoQueryHash(as); + // for static pages with query params in the URL we delay + // marking the router ready until after the query is updated + if (options._h) { + _this.isReady = true; + } + prevLocale = _this.locale; + if (process.env.__NEXT_I18N_SUPPORT) { + _this.locale = options.locale === false ? _this.defaultLocale : options.locale || _this.locale; + if (typeof options.locale === "undefined") { + options.locale = _this.locale; + } + parsedAs = parseRelativeUrl(hasBasePath(as) ? delBasePath(as) : as); + localePathResult = normalizeLocalePath(parsedAs.pathname, _this.locales); + if (localePathResult.detectedLocale) { + _this.locale = localePathResult.detectedLocale; + parsedAs.pathname = addBasePath(parsedAs.pathname); + as = formatWithValidation(parsedAs); + url = addBasePath(normalizeLocalePath(hasBasePath(url) ? delBasePath(url) : url, _this.locales).pathname); + } + didNavigate = false; + // we need to wrap this in the env check again since regenerator runtime + // moves this on its own due to the return + if (process.env.__NEXT_I18N_SUPPORT) { + ; + // if the locale isn't configured hard navigate to show 404 page + if (!((_this_locales = _this.locales) === null || _this_locales === void 0 ? void 0 : _this_locales.includes(_this.locale))) { + parsedAs.pathname = addLocale(parsedAs.pathname, _this.locale); + window.location.href = formatWithValidation(parsedAs); + // this was previously a return but was removed in favor + // of better dead code elimination with regenerator runtime + didNavigate = true; + } + } + detectedDomain = detectDomainLocale(_this.domainLocales, undefined, _this.locale); + // we need to wrap this in the env check again since regenerator runtime + // moves this on its own due to the return + if (process.env.__NEXT_I18N_SUPPORT) { + // if we are navigating to a domain locale ensure we redirect to the + // correct domain + if (!didNavigate && detectedDomain && _this.isLocaleDomain && self.location.hostname !== detectedDomain.domain) { + asNoBasePath = delBasePath(as); + window.location.href = "http".concat(detectedDomain.http ? "" : "s", "://").concat(detectedDomain.domain).concat(addBasePath("".concat(_this.locale === detectedDomain.defaultLocale ? "" : "/".concat(_this.locale)).concat(asNoBasePath === "/" ? "" : asNoBasePath) || "/")); + // this was previously a return but was removed in favor + // of better dead code elimination with regenerator runtime + didNavigate = true; + } + } + if (didNavigate) { + return [ + 2, + new Promise(function() {}) + ]; + } } - } - if (didNavigate) { + if (!options._h) { + _this.isSsr = false; + } + // marking route changes as a navigation start entry + if (ST) { + performance.mark("routeChange"); + } + _options_shallow = options.shallow, shallow = _options_shallow === void 0 ? false : _options_shallow; + routeProps = { + shallow: shallow + }; + if (_this._inFlightRoute) { + _this.abortComponentLoad(_this._inFlightRoute, routeProps); + } + as = addBasePath(addLocale(hasBasePath(as) ? delBasePath(as) : as, options.locale, _this.defaultLocale)); + cleanedAs = delLocale(hasBasePath(as) ? delBasePath(as) : as, _this.locale); + _this._inFlightRoute = as; + localeChange = prevLocale !== _this.locale; + // If the url change is only related to a hash change + // We should not proceed. We should only change the state. + // WARNING: `_h` is an internal option for handing Next.js client-side + // hydration. Your app should _never_ use this property. It may change at + // any time without notice. + if (!options._h && _this.onlyAHashChange(cleanedAs) && !localeChange) { + _this.asPath = cleanedAs; + Router.events.emit("hashChangeStart", as, routeProps); + // TODO: do we need the resolved href when only a hash change? + _this.changeState(method, url, as, options); + _this.scrollToHash(cleanedAs); + _this.notify(_this.components[_this.route], null); + Router.events.emit("hashChangeComplete", as, routeProps); + return [ + 2, + true + ]; + } + parsed = parseRelativeUrl(url); + pathname = parsed.pathname, query = parsed.query; + _state.label = 1; + case 1: + _state.trys.push([ + 1, + 4, + , + 5 + ]); + return [ + 4, + _this.pageLoader.getPageList() + ]; + case 2: + pages = _state.sent(); + return [ + 4, + getClientBuildManifest() + ]; + case 3: + ref = _state.sent(), rewrites = ref.__rewrites, ref; + return [ + 3, + 5 + ]; + case 4: + err = _state.sent(); + // If we fail to resolve the page list or client-build manifest, we must + // do a server-side transition: + window.location.href = as; return [ 2, - new Promise(function() {}) + false ]; - } - } - if (!options._h) { - _this.isSsr = false; - } - // marking route changes as a navigation start entry - if (ST) { - performance.mark("routeChange"); - } - _options_shallow = options.shallow, shallow = _options_shallow === void 0 ? false : _options_shallow; - routeProps = { - shallow: shallow - }; - if (_this._inFlightRoute) { - _this.abortComponentLoad(_this._inFlightRoute, routeProps); - } - as = addBasePath(addLocale(hasBasePath(as) ? delBasePath(as) : as, options.locale, _this.defaultLocale)); - cleanedAs = delLocale(hasBasePath(as) ? delBasePath(as) : as, _this.locale); - _this._inFlightRoute = as; - localeChange = prevLocale !== _this.locale; - // If the url change is only related to a hash change - // We should not proceed. We should only change the state. - // WARNING: `_h` is an internal option for handing Next.js client-side - // hydration. Your app should _never_ use this property. It may change at - // any time without notice. - if (!options._h && _this.onlyAHashChange(cleanedAs) && !localeChange) { - _this.asPath = cleanedAs; - Router.events.emit("hashChangeStart", as, routeProps); - // TODO: do we need the resolved href when only a hash change? - _this.changeState(method, url, as, options); - _this.scrollToHash(cleanedAs); - _this.notify(_this.components[_this.route], null); - Router.events.emit("hashChangeComplete", as, routeProps); - return [ - 2, - true - ]; - } - parsed = parseRelativeUrl(url); - pathname = parsed.pathname, query = parsed.query; - _state.label = 1; - case 1: - _state.trys.push([ - 1, - 4, - , - 5 - ]); - return [ - 4, - _this.pageLoader.getPageList() - ]; - case 2: - pages = _state.sent(); - return [ - 4, - getClientBuildManifest() - ]; - case 3: - ref = _state.sent(), rewrites = ref.__rewrites, ref; - return [ - 3, - 5 - ]; - case 4: - err = _state.sent(); - // If we fail to resolve the page list or client-build manifest, we must - // do a server-side transition: - window.location.href = as; - return [ - 2, - false - ]; - case 5: - // If asked to change the current URL we should reload the current page - // (not location.reload() but reload getInitialProps and other Next.js stuffs) - // We also need to set the method = replaceState always - // as this should not go into the history (That's how browsers work) - // We should compare the new asPath to the current asPath, not the url - if (!_this.urlIsNew(cleanedAs) && !localeChange) { - method = "replaceState"; - } - resolvedAs = as; - // url and as should always be prefixed with basePath by this - // point by either next/link or router.push/replace so strip the - // basePath from the pathname to match the pages dir 1-to-1 - pathname = pathname ? removePathTrailingSlash(delBasePath(pathname)) : pathname; - if (shouldResolveHref && pathname !== "/_error") { - options._shouldResolveHref = true; - if (process.env.__NEXT_HAS_REWRITES && as.startsWith("/")) { - rewritesResult = resolveRewrites(addBasePath(addLocale(cleanedAs, _this.locale)), pages, rewrites, query, function(p) { - return resolveDynamicRoute(p, pages); - }, _this.locales); - resolvedAs = rewritesResult.asPath; - if (rewritesResult.matchedPage && rewritesResult.resolvedHref) { - // if this directly matches a page we need to update the href to - // allow the correct page chunk to be loaded - pathname = rewritesResult.resolvedHref; - parsed.pathname = addBasePath(pathname); - url = formatWithValidation(parsed); + case 5: + // If asked to change the current URL we should reload the current page + // (not location.reload() but reload getInitialProps and other Next.js stuffs) + // We also need to set the method = replaceState always + // as this should not go into the history (That's how browsers work) + // We should compare the new asPath to the current asPath, not the url + if (!_this.urlIsNew(cleanedAs) && !localeChange) { + method = "replaceState"; } - } else { - parsed.pathname = resolveDynamicRoute(pathname, pages); - if (parsed.pathname !== pathname) { - pathname = parsed.pathname; - parsed.pathname = addBasePath(pathname); - url = formatWithValidation(parsed); + resolvedAs = as; + // url and as should always be prefixed with basePath by this + // point by either next/link or router.push/replace so strip the + // basePath from the pathname to match the pages dir 1-to-1 + pathname = pathname ? removePathTrailingSlash(delBasePath(pathname)) : pathname; + if (shouldResolveHref && pathname !== "/_error") { + options._shouldResolveHref = true; + if (process.env.__NEXT_HAS_REWRITES && as.startsWith("/")) { + rewritesResult = resolveRewrites(addBasePath(addLocale(cleanedAs, _this.locale)), pages, rewrites, query, function(p) { + return resolveDynamicRoute(p, pages); + }, _this.locales); + resolvedAs = rewritesResult.asPath; + if (rewritesResult.matchedPage && rewritesResult.resolvedHref) { + // if this directly matches a page we need to update the href to + // allow the correct page chunk to be loaded + pathname = rewritesResult.resolvedHref; + parsed.pathname = addBasePath(pathname); + url = formatWithValidation(parsed); + } + } else { + parsed.pathname = resolveDynamicRoute(pathname, pages); + if (parsed.pathname !== pathname) { + pathname = parsed.pathname; + parsed.pathname = addBasePath(pathname); + url = formatWithValidation(parsed); + } + } } - } - } - route = removePathTrailingSlash(pathname); - if (!isLocalURL(as)) { - if (process.env.NODE_ENV !== "production") { - throw new Error('Invalid href: "'.concat(url, '" and as: "').concat(as, '", received relative href and external as') + "\nSee more info: https://nextjs.org/docs/messages/invalid-relative-url-external-as"); - } - window.location.href = as; - return [ - 2, - false - ]; - } - resolvedAs = delLocale(delBasePath(resolvedAs), _this.locale); - if (isDynamicRoute(route)) { - parsedAs1 = parseRelativeUrl(resolvedAs); - asPathname = parsedAs1.pathname; - routeRegex = getRouteRegex(route); - routeMatch = getRouteMatcher(routeRegex)(asPathname); - shouldInterpolate = route === asPathname; - interpolatedAs = shouldInterpolate ? interpolateAs(route, asPathname, query) : {}; - if (!routeMatch || shouldInterpolate && !interpolatedAs.result) { - missingParams = Object.keys(routeRegex.groups).filter(function(param) { - return !query[param]; - }); - if (missingParams.length > 0) { + route = removePathTrailingSlash(pathname); + if (!isLocalURL(as)) { if (process.env.NODE_ENV !== "production") { - console.warn("".concat(shouldInterpolate ? "Interpolating href" : "Mismatching `as` and `href`", " failed to manually provide ") + "the params: ".concat(missingParams.join(", "), " in the `href`'s `query`")); + throw new Error('Invalid href: "'.concat(url, '" and as: "').concat(as, '", received relative href and external as') + "\nSee more info: https://nextjs.org/docs/messages/invalid-relative-url-external-as"); } - throw new Error((shouldInterpolate ? "The provided `href` (".concat(url, ") value is missing query values (").concat(missingParams.join(", "), ") to be interpolated properly. ") : "The provided `as` value (".concat(asPathname, ") is incompatible with the `href` value (").concat(route, "). ")) + "Read more: https://nextjs.org/docs/messages/".concat(shouldInterpolate ? "href-interpolation-failed" : "incompatible-href-as")); + window.location.href = as; + return [ + 2, + false + ]; } - } else if (shouldInterpolate) { - as = formatWithValidation(Object.assign({}, parsedAs1, { - pathname: interpolatedAs.result, - query: omitParmsFromQuery(query, interpolatedAs.params) - })); - } else { - // Merge params into `query`, overwriting any specified in search - Object.assign(query, routeMatch); - } - } - Router.events.emit("routeChangeStart", as, routeProps); - _state.label = 6; - case 6: - _state.trys.push([ - 6, - 15, - , - 16 - ]); - return [ - 4, - _this.getRouteInfo(route, pathname, query, as, resolvedAs, routeProps) - ]; - case 7: - routeInfo = _state.sent(); - error = routeInfo.error, props = routeInfo.props, __N_SSG = routeInfo.__N_SSG, __N_SSP = routeInfo.__N_SSP; - if (!((__N_SSG || __N_SSP) && props)) return [ - 3, - 13 - ]; - if (props.pageProps && props.pageProps.__N_REDIRECT) { - destination = props.pageProps.__N_REDIRECT; - // check if destination is internal (resolves to a page) and attempt - // client-navigation if it is falling back to hard navigation if - // it's not - if (destination.startsWith("/") && props.pageProps.__N_REDIRECT_BASE_PATH !== false) { - parsedHref = parseRelativeUrl(destination); - parsedHref.pathname = resolveDynamicRoute(parsedHref.pathname, pages); - _prepareUrlAs = prepareUrlAs(_this, destination, destination), newUrl = _prepareUrlAs.url, newAs = _prepareUrlAs.as; + resolvedAs = delLocale(delBasePath(resolvedAs), _this.locale); + if (isDynamicRoute(route)) { + parsedAs1 = parseRelativeUrl(resolvedAs); + asPathname = parsedAs1.pathname; + routeRegex = getRouteRegex(route); + routeMatch = getRouteMatcher(routeRegex)(asPathname); + shouldInterpolate = route === asPathname; + interpolatedAs = shouldInterpolate ? interpolateAs(route, asPathname, query) : {}; + if (!routeMatch || shouldInterpolate && !interpolatedAs.result) { + missingParams = Object.keys(routeRegex.groups).filter(function(param) { + return !query[param]; + }); + if (missingParams.length > 0) { + if (process.env.NODE_ENV !== "production") { + console.warn("".concat(shouldInterpolate ? "Interpolating href" : "Mismatching `as` and `href`", " failed to manually provide ") + "the params: ".concat(missingParams.join(", "), " in the `href`'s `query`")); + } + throw new Error((shouldInterpolate ? "The provided `href` (".concat(url, ") value is missing query values (").concat(missingParams.join(", "), ") to be interpolated properly. ") : "The provided `as` value (".concat(asPathname, ") is incompatible with the `href` value (").concat(route, "). ")) + "Read more: https://nextjs.org/docs/messages/".concat(shouldInterpolate ? "href-interpolation-failed" : "incompatible-href-as")); + } + } else if (shouldInterpolate) { + as = formatWithValidation(Object.assign({}, parsedAs1, { + pathname: interpolatedAs.result, + query: omitParmsFromQuery(query, interpolatedAs.params) + })); + } else { + // Merge params into `query`, overwriting any specified in search + Object.assign(query, routeMatch); + } + } + Router.events.emit("routeChangeStart", as, routeProps); + _state.label = 6; + case 6: + _state.trys.push([ + 6, + 15, + , + 16 + ]); + return [ + 4, + _this.getRouteInfo(route, pathname, query, as, resolvedAs, routeProps) + ]; + case 7: + routeInfo = _state.sent(); + error = routeInfo.error, props = routeInfo.props, __N_SSG = routeInfo.__N_SSG, __N_SSP = routeInfo.__N_SSP; + if (!((__N_SSG || __N_SSP) && props)) return [ + 3, + 13 + ]; + if (props.pageProps && props.pageProps.__N_REDIRECT) { + destination = props.pageProps.__N_REDIRECT; + // check if destination is internal (resolves to a page) and attempt + // client-navigation if it is falling back to hard navigation if + // it's not + if (destination.startsWith("/") && props.pageProps.__N_REDIRECT_BASE_PATH !== false) { + parsedHref = parseRelativeUrl(destination); + parsedHref.pathname = resolveDynamicRoute(parsedHref.pathname, pages); + _prepareUrlAs = prepareUrlAs(_this, destination, destination), newUrl = _prepareUrlAs.url, newAs = _prepareUrlAs.as; + return [ + 2, + _this.change(method, newUrl, newAs, options) + ]; + } + window.location.href = destination; + return [ + 2, + new Promise(function() {}) + ]; + } + _this.isPreview = !!props.__N_PREVIEW; + if (!(props.notFound === SSG_DATA_NOT_FOUND)) return [ + 3, + 13 + ]; + _state.label = 8; + case 8: + _state.trys.push([ + 8, + 10, + , + 11 + ]); + return [ + 4, + _this.fetchComponent("/404") + ]; + case 9: + _state.sent(); + notFoundRoute = "/404"; + return [ + 3, + 11 + ]; + case 10: + _ = _state.sent(); + notFoundRoute = "/_error"; + return [ + 3, + 11 + ]; + case 11: + return [ + 4, + _this.getRouteInfo(notFoundRoute, notFoundRoute, query, as, resolvedAs, { + shallow: false + }) + ]; + case 12: + routeInfo = _state.sent(); + _state.label = 13; + case 13: + Router.events.emit("beforeHistoryChange", as, routeProps); + _this.changeState(method, url, as, options); + if (options._h && pathname === "/_error" && ((_self___NEXT_DATA___props = self.__NEXT_DATA__.props) === null || _self___NEXT_DATA___props === void 0 ? void 0 : (_self___NEXT_DATA___props_pageProps = _self___NEXT_DATA___props.pageProps) === null || _self___NEXT_DATA___props_pageProps === void 0 ? void 0 : _self___NEXT_DATA___props_pageProps.statusCode) === 500 && (props === null || props === void 0 ? void 0 : props.pageProps)) { + // ensure statusCode is still correct for static 500 page + // when updating query information + props.pageProps.statusCode = 500; + } + isValidShallowRoute = options.shallow && _this.route === route; + shouldScroll = (_options_scroll = options.scroll) !== null && _options_scroll !== void 0 ? _options_scroll : !isValidShallowRoute; + resetScroll = shouldScroll ? { + x: 0, + y: 0 + } : null; + return [ + 4, + _this.set(route, pathname, query, cleanedAs, routeInfo, forcedScroll !== null && forcedScroll !== void 0 ? forcedScroll : resetScroll).catch(function(e) { + if (e.cancelled) error = error || e; + else throw e; + }) + ]; + case 14: + _state.sent(); + if (error) { + Router.events.emit("routeChangeError", error, cleanedAs, routeProps); + throw error; + } + if (process.env.__NEXT_I18N_SUPPORT) { + if (_this.locale) { + document.documentElement.lang = _this.locale; + } + } + Router.events.emit("routeChangeComplete", as, routeProps); return [ 2, - _this.change(method, newUrl, newAs, options) + true + ]; + case 15: + err1 = _state.sent(); + if (isError(err1) && err1.cancelled) { + return [ + 2, + false + ]; + } + throw err1; + case 16: + return [ + 2 ]; - } - window.location.href = destination; - return [ - 2, - new Promise(function() {}) - ]; - } - _this.isPreview = !!props.__N_PREVIEW; - if (!(props.notFound === SSG_DATA_NOT_FOUND)) return [ - 3, - 13 - ]; - _state.label = 8; - case 8: - _state.trys.push([ - 8, - 10, - , - 11 - ]); - return [ - 4, - _this.fetchComponent("/404") - ]; - case 9: - _state.sent(); - notFoundRoute = "/404"; - return [ - 3, - 11 - ]; - case 10: - _ = _state.sent(); - notFoundRoute = "/_error"; - return [ - 3, - 11 - ]; - case 11: - return [ - 4, - _this.getRouteInfo(notFoundRoute, notFoundRoute, query, as, resolvedAs, { - shallow: false - }) - ]; - case 12: - routeInfo = _state.sent(); - _state.label = 13; - case 13: - Router.events.emit("beforeHistoryChange", as, routeProps); - _this.changeState(method, url, as, options); - if (options._h && pathname === "/_error" && ((_self___NEXT_DATA___props = self.__NEXT_DATA__.props) === null || _self___NEXT_DATA___props === void 0 ? void 0 : (_self___NEXT_DATA___props_pageProps = _self___NEXT_DATA___props.pageProps) === null || _self___NEXT_DATA___props_pageProps === void 0 ? void 0 : _self___NEXT_DATA___props_pageProps.statusCode) === 500 && (props === null || props === void 0 ? void 0 : props.pageProps)) { - // ensure statusCode is still correct for static 500 page - // when updating query information - props.pageProps.statusCode = 500; - } - isValidShallowRoute = options.shallow && _this.route === route; - shouldScroll = (_options_scroll = options.scroll) !== null && _options_scroll !== void 0 ? _options_scroll : !isValidShallowRoute; - resetScroll = shouldScroll ? { - x: 0, - y: 0 - } : null; - return [ - 4, - _this.set(route, pathname, query, cleanedAs, routeInfo, forcedScroll !== null && forcedScroll !== void 0 ? forcedScroll : resetScroll).catch(function(e) { - if (e.cancelled) error = error || e; - else throw e; - }) - ]; - case 14: - _state.sent(); - if (error) { - Router.events.emit("routeChangeError", error, cleanedAs, routeProps); - throw error; - } - if (process.env.__NEXT_I18N_SUPPORT) { - if (_this.locale) { - document.documentElement.lang = _this.locale; - } - } - Router.events.emit("routeChangeComplete", as, routeProps); - return [ - 2, - true - ]; - case 15: - err1 = _state.sent(); - if (isError(err1) && err1.cancelled) { - return [ - 2, - false - ]; } - throw err1; - case 16: - return [ - 2 - ]; - } - }); - })(); - }; + }); + })(); + } + } + ]); return Router; }(); export { Router as default }; diff --git a/crates/swc/tests/fixture/sourcemap/011/input/.swcrc b/crates/swc/tests/fixture/sourcemap/011/input/.swcrc index 44899292f8e5..6033afdafd3d 100644 --- a/crates/swc/tests/fixture/sourcemap/011/input/.swcrc +++ b/crates/swc/tests/fixture/sourcemap/011/input/.swcrc @@ -8,6 +8,7 @@ "decorators": true }, "transform": { + "useDefineForClassFields": false, "legacyDecorator": true, "decoratorMetadata": true }, diff --git a/crates/swc/tests/fixture/sourcemap/012/input/.swcrc b/crates/swc/tests/fixture/sourcemap/012/input/.swcrc index 44899292f8e5..6033afdafd3d 100644 --- a/crates/swc/tests/fixture/sourcemap/012/input/.swcrc +++ b/crates/swc/tests/fixture/sourcemap/012/input/.swcrc @@ -8,6 +8,7 @@ "decorators": true }, "transform": { + "useDefineForClassFields": false, "legacyDecorator": true, "decoratorMetadata": true }, diff --git a/crates/swc/tests/fixture/sourcemap/013/input/.swcrc b/crates/swc/tests/fixture/sourcemap/013/input/.swcrc index 44899292f8e5..6033afdafd3d 100644 --- a/crates/swc/tests/fixture/sourcemap/013/input/.swcrc +++ b/crates/swc/tests/fixture/sourcemap/013/input/.swcrc @@ -8,6 +8,7 @@ "decorators": true }, "transform": { + "useDefineForClassFields": false, "legacyDecorator": true, "decoratorMetadata": true }, diff --git a/crates/swc/tests/fixture/sourcemap/014/input/.swcrc b/crates/swc/tests/fixture/sourcemap/014/input/.swcrc index 44899292f8e5..6033afdafd3d 100644 --- a/crates/swc/tests/fixture/sourcemap/014/input/.swcrc +++ b/crates/swc/tests/fixture/sourcemap/014/input/.swcrc @@ -8,6 +8,7 @@ "decorators": true }, "transform": { + "useDefineForClassFields": false, "legacyDecorator": true, "decoratorMetadata": true }, diff --git a/crates/swc/tests/projects.rs b/crates/swc/tests/projects.rs index 9ebbbd5584cc..f33a4d880985 100644 --- a/crates/swc/tests/projects.rs +++ b/crates/swc/tests/projects.rs @@ -916,6 +916,11 @@ fn issue_2224() { decorators: true, ..Default::default() })), + transform: Some(TransformConfig { + use_define_for_class_fields: false.into(), + ..Default::default() + }) + .into(), ..Default::default() }, ..Default::default() diff --git a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.1.normal.js b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.1.normal.js index 483af2852adc..a121ee5868cb 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.1.normal.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.1.normal.js @@ -6,10 +6,12 @@ var Point = function Point(x, y) { this.x = x; this.y = y; }; -Point.Origin = { - x: 0, - y: 0 -}; +(function() { + Point.Origin = { + x: 0, + y: 0 + }; +})(); (function(Point) { var Origin = Point.Origin = ""; })(Point || (Point = {})); @@ -21,10 +23,12 @@ var A; this.x = x; this.y = y; }; - Point.Origin = { - x: 0, - y: 0 - }; + (function() { + Point.Origin = { + x: 0, + y: 0 + }; + })(); A.Point = Point; (function(Point) { var Origin = Point.Origin = ""; diff --git a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.1.normal.js b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.1.normal.js index b075d77fba7d..8d0d89aa3070 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.1.normal.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.1.normal.js @@ -6,10 +6,12 @@ var Point = function Point(x, y) { this.x = x; this.y = y; }; -Point.Origin = { - x: 0, - y: 0 -}; +(function() { + Point.Origin = { + x: 0, + y: 0 + }; +})(); (function(Point) { var Origin = ""; // not an error, since not exported })(Point || (Point = {})); @@ -21,10 +23,12 @@ var A; this.x = x; this.y = y; }; - Point.Origin = { - x: 0, - y: 0 - }; + (function() { + Point.Origin = { + x: 0, + y: 0 + }; + })(); A.Point = Point; (function(Point) { var Origin = ""; // not an error since not exported diff --git a/crates/swc/tests/tsc-references/accessorsOverrideProperty6.1.normal.js b/crates/swc/tests/tsc-references/accessorsOverrideProperty6.1.normal.js index 37211859711c..ef2e400c3f31 100644 --- a/crates/swc/tests/tsc-references/accessorsOverrideProperty6.1.normal.js +++ b/crates/swc/tests/tsc-references/accessorsOverrideProperty6.1.normal.js @@ -1,6 +1,8 @@ //// [accessorsOverrideProperty6.ts] class A { - p = 'yep'; + constructor(){ + this.p = 'yep'; + } } class B extends A { get p() { @@ -8,14 +10,19 @@ class B extends A { } } class C { - p = 101; + constructor(){ + this.p = 101; + } } class D extends C { - _secret = 11; get p() { return this._secret; } set p(value) { this._secret = value; } + constructor(...args){ + super(...args); + this._secret = 11; + } } diff --git a/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression.1.normal.js b/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression.1.normal.js index 168556cabf48..f3c0e6b577fd 100644 --- a/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression.1.normal.js +++ b/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression.1.normal.js @@ -28,7 +28,9 @@ define([ _classCallCheck(this, C1); this.m1 = 42; }; - C1.s1 = true; + (function() { + C1.s1 = true; + })(); var E1; (function(E1) { E1[E1["A"] = 0] = "A"; diff --git a/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext.1.normal.js b/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext.1.normal.js index 782431ef6c47..f83b37cd3da0 100644 --- a/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext.1.normal.js +++ b/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext.1.normal.js @@ -1,5 +1,6 @@ //// [assignParameterPropertyToPropertyDeclarationESNext.ts] class C { + foo; qux; bar; quiz; @@ -36,13 +37,13 @@ class C { this.foo // ok ; } - foo; } class D extends C { quill = this.foo // ok ; } class E { + foo2; bar; foo1; constructor(foo2){ @@ -50,7 +51,6 @@ class E { this.bar = ()=>this.foo1 + this.foo2; this.foo1 = ''; } - foo2; } class F { Inner = class extends F { @@ -59,6 +59,7 @@ class F { p1 = 0; } class G { + p1; Inner; constructor(p1){ this.p1 = p1; @@ -66,9 +67,9 @@ class G { p2 = this.p1; }; } - p1; } class H { + p1; constructor(p1){ this.p1 = p1; this.p2 = ()=>{ @@ -78,5 +79,4 @@ class H { } p2; p3; - p1; } diff --git a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5.1.normal.js b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5.1.normal.js index a49e1914e846..4a27d76a8e58 100644 --- a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5.1.normal.js @@ -3,45 +3,49 @@ import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; -var _B; var A = function A() { "use strict"; _class_call_check(this, A); }; -A.B = (_B = /*#__PURE__*/ function() { - "use strict"; - function B() { - _class_call_check(this, B); - } - B.func2 = function func2() { - return new Promise(function(resolve) { - resolve(null); - }); - }; - return B; -}(), _B.C = /*#__PURE__*/ function() { - "use strict"; - function C() { - _class_call_check(this, C); - } - C.func = function func() { - return _async_to_generator(function() { - return _ts_generator(this, function(_state) { - switch(_state.label){ - case 0: - return [ - 4, - _B.func2() - ]; - case 1: - _state.sent(); - return [ - 2 - ]; - } +(function() { + var _B; + A.B = (_B = /*#__PURE__*/ function() { + "use strict"; + function B() { + _class_call_check(this, B); + } + B.func2 = function func2() { + return new Promise(function(resolve) { + resolve(null); }); - })(); - }; - return C; -}(), _B); + }; + return B; + }(), function() { + _B.C = /*#__PURE__*/ function() { + "use strict"; + function C() { + _class_call_check(this, C); + } + C.func = function func() { + return _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _B.func2() + ]; + case 1: + _state.sent(); + return [ + 2 + ]; + } + }); + })(); + }; + return C; + }(); + }(), _B); +})(); A.B.C.func(); diff --git a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5.2.minified.js index c995b3658bfa..83429be16037 100644 --- a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5.2.minified.js @@ -2,40 +2,43 @@ import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; -var _B, A = function A() { +var A = function A() { "use strict"; _class_call_check(this, A); }; -A.B = ((_B = function() { - "use strict"; - function B() { - _class_call_check(this, B); - } - return B.func2 = function() { - return new Promise(function(resolve) { - resolve(null); - }); - }, B; -}()).C = function() { - "use strict"; - function C() { - _class_call_check(this, C); - } - return C.func = function() { - return _async_to_generator(function() { - return _ts_generator(this, function(_state) { - switch(_state.label){ - case 0: - return [ - 4, - _B.func2() - ]; - case 1: - return _state.sent(), [ - 2 - ]; - } +!function() { + var _B; + A.B = ((_B = function() { + "use strict"; + function B() { + _class_call_check(this, B); + } + return B.func2 = function() { + return new Promise(function(resolve) { + resolve(null); }); - })(); - }, C; -}(), _B), A.B.C.func(); + }, B; + }()).C = function() { + "use strict"; + function C() { + _class_call_check(this, C); + } + return C.func = function() { + return _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _B.func2() + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })(); + }, C; + }(), _B); +}(), A.B.C.func(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock11(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock11(target=es2015).1.normal.js index 1b50754c7fe0..b79b3ca96a71 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock11(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock11(target=es2015).1.normal.js @@ -8,8 +8,9 @@ class C { constructor(x){ _class_private_field_init(this, _x, { writable: true, - value: 1 + value: void 0 }); + _class_private_field_set(this, _x, 1); _class_private_field_set(this, _x, x); } } diff --git a/crates/swc/tests/tsc-references/classStaticBlock11(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock11(target=es2022).1.normal.js index 81ca3c208013..25b5621362df 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock11(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock11(target=es2022).1.normal.js @@ -1,8 +1,9 @@ //// [classStaticBlock11.ts] let getX; class C { - #x = 1; + #x; constructor(x){ + this.#x = 1; this.#x = x; } static{ diff --git a/crates/swc/tests/tsc-references/classStaticBlock18(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock18(target=es2015).1.normal.js index 1b57660e300a..2e1f657f5158 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock18(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock18(target=es2015).1.normal.js @@ -2,10 +2,14 @@ function foo() { var _class; return _class = class { - }, _class.foo = 1, (()=>{ + }, (()=>{ + _class.foo = 1; + })(), (()=>{ var _class; const c = (_class = class { - }, _class.bar = 2, (()=>{ + }, (()=>{ + _class.bar = 2; + })(), (()=>{ // do })(), _class); })(), _class; diff --git a/crates/swc/tests/tsc-references/classStaticBlock18(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock18(target=es2022).1.normal.js index 244ead340a71..164dabb1a9ad 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock18(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock18(target=es2022).1.normal.js @@ -1,10 +1,14 @@ //// [classStaticBlock18.ts] function foo() { return class { - static foo = 1; + static{ + this.foo = 1; + } static{ const c = class { - static bar = 2; + static{ + this.bar = 2; + } static{ // do } diff --git a/crates/swc/tests/tsc-references/classStaticBlock18(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock18(target=es5).1.normal.js index a18ceb169209..a7403c7fc72e 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock18(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock18(target=es5).1.normal.js @@ -5,12 +5,16 @@ function foo() { return _class = function _class() { "use strict"; _class_call_check(this, _class); - }, _class.foo = 1, function() { + }, function() { + _class.foo = 1; + }(), function() { var _class; var c = (_class = function _class() { "use strict"; _class_call_check(this, _class); - }, _class.bar = 2, function() { + }, function() { + _class.bar = 2; + }(), function() { // do }(), _class); }(), _class; diff --git a/crates/swc/tests/tsc-references/classStaticBlock27.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock27.1.normal.js index f285123e77a7..d56ddd13ee54 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock27.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock27.1.normal.js @@ -5,7 +5,9 @@ var _Foo; void (_Foo = function Foo() { "use strict"; _class_call_check(this, Foo); -}, _Foo.prop = 1, function() { +}, function() { + _Foo.prop = 1; +}(), function() { console.log(_Foo.prop); _Foo.prop++; }(), function() { diff --git a/crates/swc/tests/tsc-references/classStaticBlock3.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock3.1.normal.js index cf4b63e32ad8..967cc1f1e769 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock3.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock3.1.normal.js @@ -1,13 +1,19 @@ //// [classStaticBlock3.ts] const a = 1; class C { - static f1 = 1; + static{ + this.f1 = 1; + } static{ console.log(C.f1, C.f2, C.f3); } - static f2 = 2; + static{ + this.f2 = 2; + } static{ console.log(C.f1, C.f2, C.f3); } - static f3 = 3; + static{ + this.f3 = 3; + } } diff --git a/crates/swc/tests/tsc-references/classStaticBlock3.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock3.2.minified.js index 07a404da67c3..ebfc0930eaa0 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock3.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock3.2.minified.js @@ -1,12 +1,18 @@ //// [classStaticBlock3.ts] class C { - static f1 = 1; + static{ + this.f1 = 1; + } static{ console.log(C.f1, C.f2, C.f3); } - static f2 = 2; + static{ + this.f2 = 2; + } static{ console.log(C.f1, C.f2, C.f3); } - static f3 = 3; + static{ + this.f3 = 3; + } } diff --git a/crates/swc/tests/tsc-references/classStaticBlock4.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock4.1.normal.js index 99d31fec4ed8..4073e3cf37ee 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock4.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock4.1.normal.js @@ -1,12 +1,18 @@ //// [classStaticBlock4.ts] class C { - static s1 = 1; + static{ + this.s1 = 1; + } static{ this.s1; C.s1; this.s2; C.s2; } - static s2 = 2; - static ss2 = this.s1; + static{ + this.s2 = 2; + } + static{ + this.ss2 = this.s1; + } } diff --git a/crates/swc/tests/tsc-references/classStaticBlock4.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock4.2.minified.js index 063b74aeee7b..8594da83dc55 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock4.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock4.2.minified.js @@ -1,9 +1,15 @@ //// [classStaticBlock4.ts] class C { - static s1 = 1; + static{ + this.s1 = 1; + } static{ this.s1, C.s1, this.s2, C.s2; } - static s2 = 2; - static ss2 = this.s1; + static{ + this.s2 = 2; + } + static{ + this.ss2 = this.s1; + } } diff --git a/crates/swc/tests/tsc-references/classStaticBlock5(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock5(target=es2015).1.normal.js index 393451dbf1d7..fa02420a33c2 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock5(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock5(target=es2015).1.normal.js @@ -3,12 +3,20 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class B { } -B.a = 1; -B.b = 2; +(()=>{ + B.a = 1; +})(); +(()=>{ + B.b = 2; +})(); class C extends B { } -C.b = 3; -C.c = _get(_get_prototype_of(C), "a", C); +(()=>{ + C.b = 3; +})(); +(()=>{ + C.c = _get(_get_prototype_of(C), "a", C); +})(); (()=>{ C.b; _get(_get_prototype_of(C), "b", C); diff --git a/crates/swc/tests/tsc-references/classStaticBlock5(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock5(target=es2022).1.normal.js index 46dc9ef36169..9efba44ac3e0 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock5(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock5(target=es2022).1.normal.js @@ -1,11 +1,19 @@ //// [classStaticBlock5.ts] class B { - static a = 1; - static b = 2; + static{ + this.a = 1; + } + static{ + this.b = 2; + } } class C extends B { - static b = 3; - static c = super.a; + static{ + this.b = 3; + } + static{ + this.c = super.a; + } static{ this.b; super.b; diff --git a/crates/swc/tests/tsc-references/classStaticBlock5(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock5(target=es2022).2.minified.js index 0c3c8886bc6a..0bfcebbe1892 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock5(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock5(target=es2022).2.minified.js @@ -1,11 +1,19 @@ //// [classStaticBlock5.ts] class B { - static a = 1; - static b = 2; + static{ + this.a = 1; + } + static{ + this.b = 2; + } } class C extends B { - static b = 3; - static c = super.a; + static{ + this.b = 3; + } + static{ + this.c = super.a; + } static{ this.b, super.b, super.a; } diff --git a/crates/swc/tests/tsc-references/classStaticBlock5(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock5(target=es5).1.normal.js index 4710e2fbf38b..f7487fe3a561 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock5(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock5(target=es5).1.normal.js @@ -8,8 +8,12 @@ var B = function B() { "use strict"; _class_call_check(this, B); }; -B.a = 1; -B.b = 2; +(function() { + B.a = 1; +})(); +(function() { + B.b = 2; +})(); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -20,8 +24,12 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C.b = 3; -C.c = _get(_get_prototype_of(C), "a", C); +(function() { + C.b = 3; +})(); +(function() { + C.c = _get(_get_prototype_of(C), "a", C); +})(); (function() { C.b; _get(_get_prototype_of(C), "b", C); diff --git a/crates/swc/tests/tsc-references/classStaticBlock9(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock9(target=es2015).1.normal.js index 2ce848110610..a947cb88b09f 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock9(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock9(target=es2015).1.normal.js @@ -1,8 +1,12 @@ //// [classStaticBlock9.ts] class A { } -A.bar = A.foo + 1; +(()=>{ + A.bar = A.foo + 1; +})(); (()=>{ A.foo + 2; })(); -A.foo = 1; +(()=>{ + A.foo = 1; +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock9(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock9(target=es2022).1.normal.js index 02e2aa41134d..9c22839c208d 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock9(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock9(target=es2022).1.normal.js @@ -1,8 +1,12 @@ //// [classStaticBlock9.ts] class A { - static bar = A.foo + 1; + static{ + this.bar = A.foo + 1; + } static{ A.foo + 2; } - static foo = 1; + static{ + this.foo = 1; + } } diff --git a/crates/swc/tests/tsc-references/classStaticBlock9(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock9(target=es2022).2.minified.js index a06d492ca451..2be2113955bc 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock9(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock9(target=es2022).2.minified.js @@ -1,8 +1,12 @@ //// [classStaticBlock9.ts] class A { - static bar = A.foo + 1; + static{ + this.bar = A.foo + 1; + } static{ A.foo; } - static foo = 1; + static{ + this.foo = 1; + } } diff --git a/crates/swc/tests/tsc-references/classStaticBlock9(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock9(target=es5).1.normal.js index 9629f71d268e..7930809388f9 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock9(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock9(target=es5).1.normal.js @@ -4,8 +4,12 @@ var A = function A() { "use strict"; _class_call_check(this, A); }; -A.bar = A.foo + 1; +(function() { + A.bar = A.foo + 1; +})(); (function() { A.foo + 2; })(); -A.foo = 1; +(function() { + A.foo = 1; +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlockUseBeforeDef3.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlockUseBeforeDef3.1.normal.js index 13875c33b267..bea8fc57cb54 100644 --- a/crates/swc/tests/tsc-references/classStaticBlockUseBeforeDef3.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlockUseBeforeDef3.1.normal.js @@ -41,7 +41,9 @@ var CFA = /*#__PURE__*/ function() { u = "BAR"; u; // should be "BAR" })(); -CFA.t = 1; +(function() { + CFA.t = 1; +})(); (function() { u; // should be "BAR" })(); diff --git a/crates/swc/tests/tsc-references/classWithPrivateProperty.1.normal.js b/crates/swc/tests/tsc-references/classWithPrivateProperty.1.normal.js index ad2b62b9fb63..61814075ee84 100644 --- a/crates/swc/tests/tsc-references/classWithPrivateProperty.1.normal.js +++ b/crates/swc/tests/tsc-references/classWithPrivateProperty.1.normal.js @@ -20,9 +20,11 @@ var C = /*#__PURE__*/ function() { }; return C; }(); -C.g = function() { - return ""; -}; +(function() { + C.g = function() { + return ""; + }; +})(); var c = new C(); var r1 = c.x; var r2 = c.a; diff --git a/crates/swc/tests/tsc-references/classWithProtectedProperty.1.normal.js b/crates/swc/tests/tsc-references/classWithProtectedProperty.1.normal.js index ec8feb09786b..96e42c1ddfb8 100644 --- a/crates/swc/tests/tsc-references/classWithProtectedProperty.1.normal.js +++ b/crates/swc/tests/tsc-references/classWithProtectedProperty.1.normal.js @@ -22,9 +22,11 @@ var C = /*#__PURE__*/ function() { }; return C; }(); -C.g = function() { - return ""; -}; +(function() { + C.g = function() { + return ""; + }; +})(); var D = /*#__PURE__*/ function(C1) { "use strict"; _inherits(D, C1); diff --git a/crates/swc/tests/tsc-references/classWithPublicProperty.1.normal.js b/crates/swc/tests/tsc-references/classWithPublicProperty.1.normal.js index b8592f4cbba1..26936f406e07 100644 --- a/crates/swc/tests/tsc-references/classWithPublicProperty.1.normal.js +++ b/crates/swc/tests/tsc-references/classWithPublicProperty.1.normal.js @@ -19,9 +19,11 @@ var C = /*#__PURE__*/ function() { }; return C; }(); -C.g = function() { - return ""; -}; +(function() { + C.g = function() { + return ""; + }; +})(); // all of these are valid var c = new C(); var r1 = c.x; diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es2015).1.normal.js index d315d77077c9..d346c6e9da98 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es2015).1.normal.js @@ -2,4 +2,6 @@ var _class; // https://github.com/microsoft/TypeScript/issues/36295 (({ [(_class = class { -}, _class.x = 1, _class).x]: b = "" })=>{})(); +}, (()=>{ + _class.x = 1; +})(), _class).x]: b = "" })=>{})(); diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es2022).1.normal.js index 1eaeb9c02608..d7a1d912b97e 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es2022).1.normal.js @@ -1,5 +1,7 @@ //// [classWithStaticFieldInParameterBindingPattern.ts] // https://github.com/microsoft/TypeScript/issues/36295 (({ [(class { - static x = 1; + static{ + this.x = 1; + } }).x]: b = "" })=>{})(); diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es5).1.normal.js index b1c97bcd7693..f60727cb01f6 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern(target=es5).1.normal.js @@ -6,5 +6,7 @@ var _class; var tmp = param[(_class = function _class() { "use strict"; _class_call_check(this, _class); - }, _class.x = 1, _class).x], b = tmp === void 0 ? "" : tmp; + }, function() { + _class.x = 1; + }(), _class).x], b = tmp === void 0 ? "" : tmp; })(); diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es2015).1.normal.js index 93638c754010..8104df2c7740 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es2015).1.normal.js @@ -4,11 +4,15 @@ var _class, _class1; class C { } (({ [(_class = class extends C { -}, _class.x = 1, _class).x]: b = "" })=>{ +}, (()=>{ + _class.x = 1; +})(), _class).x]: b = "" })=>{ var C1; })(); const x = ""; (({ [(_class1 = class extends C { -}, _class1.x = 1, _class1).x]: b = "" }, d = x)=>{ +}, (()=>{ + _class1.x = 1; +})(), _class1).x]: b = "" }, d = x)=>{ var x1; })(); diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es2022).1.normal.js index a56abfb805a3..276537cc89ce 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es2022).1.normal.js @@ -3,13 +3,17 @@ class C { } (({ [(class extends C { - static x = 1; + static{ + this.x = 1; + } }).x]: b = "" })=>{ var C1; })(); const x = ""; (({ [(class extends C { - static x = 1; + static{ + this.x = 1; + } }).x]: b = "" }, d = x)=>{ var x1; })(); diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es5).1.normal.js index 465cdd167bbb..f82b09ace444 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterBindingPattern.2(target=es5).1.normal.js @@ -18,7 +18,9 @@ var C = function C() { return _super.apply(this, arguments); } return _class; - }(C), _class.x = 1, _class).x], b = tmp === void 0 ? "" : tmp; + }(C), function() { + _class.x = 1; + }(), _class).x], b = tmp === void 0 ? "" : tmp; var C1; })(); var x = ""; @@ -32,6 +34,8 @@ var x = ""; return _super.apply(this, arguments); } return _class; - }(C), _class1.x = 1, _class1).x], b = tmp === void 0 ? "" : tmp, d = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : x; + }(C), function() { + _class1.x = 1; + }(), _class1).x], b = tmp === void 0 ? "" : tmp, d = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : x; var x1; })(); diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es2015).1.normal.js index aca9ed1a815b..15cd6420cca9 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es2015).1.normal.js @@ -2,4 +2,6 @@ var _class; // https://github.com/microsoft/TypeScript/issues/36295 ((b = (_class = class { -}, _class.x = 1, _class))=>{})(); +}, (()=>{ + _class.x = 1; +})(), _class))=>{})(); diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es2022).1.normal.js index 2fee8746d2c8..69790e448fc0 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es2022).1.normal.js @@ -1,5 +1,7 @@ //// [classWithStaticFieldInParameterInitializer.ts] // https://github.com/microsoft/TypeScript/issues/36295 ((b = class { - static x = 1; + static{ + this.x = 1; + } })=>{})(); diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es5).1.normal.js index 06bb3071e97e..1a7771b5d288 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer(target=es5).1.normal.js @@ -6,5 +6,7 @@ var _class; var b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : (_class = function _class() { "use strict"; _class_call_check(this, _class); - }, _class.x = 1, _class); + }, function() { + _class.x = 1; + }(), _class); })(); diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es2015).1.normal.js index 8082aa8df171..542d19f3b079 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es2015).1.normal.js @@ -4,11 +4,15 @@ var _class, _class1; class C { } ((b = (_class = class extends C { -}, _class.x = 1, _class))=>{ +}, (()=>{ + _class.x = 1; +})(), _class))=>{ var C1; })(); const x = ""; ((b = (_class1 = class extends C { -}, _class1.x = 1, _class1), d = x)=>{ +}, (()=>{ + _class1.x = 1; +})(), _class1), d = x)=>{ var x1; })(); diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es2022).1.normal.js index 847067ba5afc..0d06bc33ab93 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es2022).1.normal.js @@ -3,13 +3,17 @@ class C { } ((b = class extends C { - static x = 1; + static{ + this.x = 1; + } })=>{ var C1; })(); const x = ""; ((b = class extends C { - static x = 1; + static{ + this.x = 1; + } }, d = x)=>{ var x1; })(); diff --git a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es5).1.normal.js index 1a8e4d4aa18d..2d96bb4477ce 100644 --- a/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classWithStaticFieldInParameterInitializer.2(target=es5).1.normal.js @@ -18,7 +18,9 @@ var C = function C() { return _super.apply(this, arguments); } return _class; - }(C), _class.x = 1, _class); + }(C), function() { + _class.x = 1; + }(), _class); var C1; })(); var x = ""; @@ -32,6 +34,8 @@ var x = ""; return _super.apply(this, arguments); } return _class; - }(C), _class1.x = 1, _class1), d = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : x; + }(C), function() { + _class1.x = 1; + }(), _class1), d = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : x; var x1; })(); diff --git a/crates/swc/tests/tsc-references/commonJSImportAsPrimaryExpression.1.normal.js b/crates/swc/tests/tsc-references/commonJSImportAsPrimaryExpression.1.normal.js index e79ac34091cc..bde141df96cf 100644 --- a/crates/swc/tests/tsc-references/commonJSImportAsPrimaryExpression.1.normal.js +++ b/crates/swc/tests/tsc-references/commonJSImportAsPrimaryExpression.1.normal.js @@ -15,7 +15,9 @@ var C1 = function C1() { _classCallCheck(this, C1); this.m1 = 42; }; -C1.s1 = true; +(function() { + C1.s1 = true; +})(); //// [foo_1.ts] "use strict"; Object.defineProperty(exports, "__esModule", { diff --git a/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression.1.normal.js b/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression.1.normal.js index 544981bebae5..6d173b43d21d 100644 --- a/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression.1.normal.js +++ b/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression.1.normal.js @@ -23,7 +23,9 @@ var C1 = function C1() { _classCallCheck(this, C1); this.m1 = 42; }; -C1.s1 = true; +(function() { + C1.s1 = true; +})(); var E1; (function(E1) { E1[E1["A"] = 0] = "A"; diff --git a/crates/swc/tests/tsc-references/computedPropertyNamesWithStaticProperty.1.normal.js b/crates/swc/tests/tsc-references/computedPropertyNamesWithStaticProperty.1.normal.js index f5bdc90ab7c5..701cebb04d9e 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNamesWithStaticProperty.1.normal.js +++ b/crates/swc/tests/tsc-references/computedPropertyNamesWithStaticProperty.1.normal.js @@ -10,4 +10,6 @@ class C { } [_staticProp2]() {} } -C.staticProp = 10; +(()=>{ + C.staticProp = 10; +})(); diff --git a/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01.1.normal.js b/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01.1.normal.js index ed80c11523bf..beb8fe5edae3 100644 --- a/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01.1.normal.js +++ b/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01.1.normal.js @@ -20,20 +20,28 @@ function getFoo2() { return _class = function _class() { "use strict"; _class_call_check(this, _class); - }, _class.method1 = function(arg) { - arg.numProp = 10; - }, _class.method2 = function(arg) { - arg.strProp = "hello"; - }, _class; + }, function() { + _class.method1 = function(arg) { + arg.numProp = 10; + }; + }(), function() { + _class.method2 = function(arg) { + arg.strProp = "hello"; + }; + }(), _class; } function getFoo3() { var _class; return _class = function _class() { "use strict"; _class_call_check(this, _class); - }, _class.method1 = function(arg) { - arg.numProp = 10; - }, _class.method2 = function(arg) { - arg.strProp = "hello"; - }, _class; + }, function() { + _class.method1 = function(arg) { + arg.numProp = 10; + }; + }(), function() { + _class.method2 = function(arg) { + arg.strProp = "hello"; + }; + }(), _class; } diff --git a/crates/swc/tests/tsc-references/defineProperty(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/defineProperty(target=es2022).1.normal.js index 50e1072df5fe..fd54e1597599 100644 --- a/crates/swc/tests/tsc-references/defineProperty(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/defineProperty(target=es2022).1.normal.js @@ -2,6 +2,7 @@ var x = "p"; let _x = x; class A { + y; a; b; c; @@ -16,12 +17,12 @@ class A { this.z = this.y; } z; - y; } class B { a; } class C extends B { + ka; z; constructor(ka){ super(); @@ -30,5 +31,4 @@ class C extends B { this.ki = this.ka; } ki; - ka; } diff --git a/crates/swc/tests/tsc-references/defineProperty(target=es5).1.normal.js b/crates/swc/tests/tsc-references/defineProperty(target=es5).1.normal.js index d2d7360e0845..2a73509436f2 100644 --- a/crates/swc/tests/tsc-references/defineProperty(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/defineProperty(target=es5).1.normal.js @@ -12,13 +12,13 @@ var A = /*#__PURE__*/ function() { "use strict"; function A(y) { _class_call_check(this, A); + _define_property(this, "y", void 0); _define_property(this, "a", void 0); _define_property(this, "b", void 0); _define_property(this, "c", void 0); _define_property(this, "computed", void 0); _define_property(this, _x1, void 0); _define_property(this, "z", void 0); - _define_property(this, "y", void 0); this.y = y; this.a = this.y; this["computed"] = 13; @@ -46,9 +46,9 @@ var C = /*#__PURE__*/ function(B) { _class_call_check(this, C); var _this; _this = _super.call(this); + _define_property(_assert_this_initialized(_this), "ka", void 0); _define_property(_assert_this_initialized(_this), "z", void 0); _define_property(_assert_this_initialized(_this), "ki", void 0); - _define_property(_assert_this_initialized(_this), "ka", void 0); _this.ka = ka; _this.z = _this.ka; _this.ki = _this.ka; diff --git a/crates/swc/tests/tsc-references/emitClassDeclarationWithLiteralPropertyNameInES6.1.normal.js b/crates/swc/tests/tsc-references/emitClassDeclarationWithLiteralPropertyNameInES6.1.normal.js index 4605e9206fc5..45416afcc026 100644 --- a/crates/swc/tests/tsc-references/emitClassDeclarationWithLiteralPropertyNameInES6.1.normal.js +++ b/crates/swc/tests/tsc-references/emitClassDeclarationWithLiteralPropertyNameInES6.1.normal.js @@ -11,7 +11,15 @@ class B { this[20] = "twenty"; } } -B["hi"] = 10000; -B[22] = "twenty-two"; -B[0b101] = "binary"; -B[0o3235] = "octal"; +(()=>{ + B["hi"] = 10000; +})(); +(()=>{ + B[22] = "twenty-two"; +})(); +(()=>{ + B[0b101] = "binary"; +})(); +(()=>{ + B[0o3235] = "octal"; +})(); diff --git a/crates/swc/tests/tsc-references/emitClassDeclarationWithStaticPropertyAssignmentInES6.1.normal.js b/crates/swc/tests/tsc-references/emitClassDeclarationWithStaticPropertyAssignmentInES6.1.normal.js index c78af0ea304e..d6e2d73917f5 100644 --- a/crates/swc/tests/tsc-references/emitClassDeclarationWithStaticPropertyAssignmentInES6.1.normal.js +++ b/crates/swc/tests/tsc-references/emitClassDeclarationWithStaticPropertyAssignmentInES6.1.normal.js @@ -1,10 +1,14 @@ //// [emitClassDeclarationWithStaticPropertyAssignmentInES6.ts] class C { } -C.z = "Foo"; +(()=>{ + C.z = "Foo"; +})(); class D { constructor(){ this.x = 20000; } } -D.b = true; +(()=>{ + D.b = true; +})(); diff --git a/crates/swc/tests/tsc-references/emitStatementsBeforeSuperCallWithDefineFields.1.normal.js b/crates/swc/tests/tsc-references/emitStatementsBeforeSuperCallWithDefineFields.1.normal.js index 50b10a2281ab..630e33146377 100644 --- a/crates/swc/tests/tsc-references/emitStatementsBeforeSuperCallWithDefineFields.1.normal.js +++ b/crates/swc/tests/tsc-references/emitStatementsBeforeSuperCallWithDefineFields.1.normal.js @@ -7,8 +7,8 @@ class Sub extends Base { constructor(p){ console.log('hi'); super(); - _define_property(this, "field", void 0); _define_property(this, "p", void 0); + _define_property(this, "field", void 0); this.p = p; this.field = 0; } @@ -18,8 +18,8 @@ class Test extends Base { constructor(p){ 1; super(); - _define_property(this, "prop", void 0); _define_property(this, "p", void 0); + _define_property(this, "prop", void 0); this.p = p; this.prop = 1; } diff --git a/crates/swc/tests/tsc-references/errorSuperPropertyAccess.1.normal.js b/crates/swc/tests/tsc-references/errorSuperPropertyAccess.1.normal.js index f7b6a79d5a67..23f502f0929a 100644 --- a/crates/swc/tests/tsc-references/errorSuperPropertyAccess.1.normal.js +++ b/crates/swc/tests/tsc-references/errorSuperPropertyAccess.1.normal.js @@ -57,8 +57,12 @@ var SomeBase = /*#__PURE__*/ function() { SomeBase.publicStaticFunc = function publicStaticFunc() {}; return SomeBase; }(); -SomeBase.privateStaticMember = 0; -SomeBase.publicStaticMember = 0; +(function() { + SomeBase.privateStaticMember = 0; +})(); +(function() { + SomeBase.publicStaticMember = 0; +})(); //super.publicInstanceMemberNotFunction in constructor of derived class //super.publicInstanceMemberNotFunction in instance member function of derived class //super.publicInstanceMemberNotFunction in instance member accessor(get and set) of derived class diff --git a/crates/swc/tests/tsc-references/es6modulekindWithES5Target2.1.normal.js b/crates/swc/tests/tsc-references/es6modulekindWithES5Target2.1.normal.js index 4a3695092672..218127b3fc80 100644 --- a/crates/swc/tests/tsc-references/es6modulekindWithES5Target2.1.normal.js +++ b/crates/swc/tests/tsc-references/es6modulekindWithES5Target2.1.normal.js @@ -10,5 +10,7 @@ var C = /*#__PURE__*/ function() { _proto.method = function method() {}; return C; }(); -C.s = 0; +(function() { + C.s = 0; +})(); export { C as default }; diff --git a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target2.1.normal.js b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target2.1.normal.js index 6b2bd6590793..c41faa6523e0 100644 --- a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target2.1.normal.js +++ b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target2.1.normal.js @@ -10,5 +10,7 @@ var C = /*#__PURE__*/ function() { _proto.method = function method() {}; return C; }(); -C.s = 0; +(function() { + C.s = 0; +})(); export { C as default }; diff --git a/crates/swc/tests/tsc-references/exportDefaultClassWithStaticPropertyAssignmentsInES6.1.normal.js b/crates/swc/tests/tsc-references/exportDefaultClassWithStaticPropertyAssignmentsInES6.1.normal.js index 23b498d9773e..77a487b07419 100644 --- a/crates/swc/tests/tsc-references/exportDefaultClassWithStaticPropertyAssignmentsInES6.1.normal.js +++ b/crates/swc/tests/tsc-references/exportDefaultClassWithStaticPropertyAssignmentsInES6.1.normal.js @@ -1,5 +1,7 @@ //// [exportDefaultClassWithStaticPropertyAssignmentsInES6.ts] class _class { } -_class.z = "Foo"; +(()=>{ + _class.z = "Foo"; +})(); export { _class as default }; diff --git a/crates/swc/tests/tsc-references/for-of27.1.normal.js b/crates/swc/tests/tsc-references/for-of27.1.normal.js index 121d1bc5f2f7..082cae346a16 100644 --- a/crates/swc/tests/tsc-references/for-of27.1.normal.js +++ b/crates/swc/tests/tsc-references/for-of27.1.normal.js @@ -1,4 +1,8 @@ //// [for-of27.ts] +let prop; class StringIterator { } +(()=>{ + prop = Symbol.iterator; +})(); for (var v of new StringIterator){} diff --git a/crates/swc/tests/tsc-references/for-of30.1.normal.js b/crates/swc/tests/tsc-references/for-of30.1.normal.js index 42cdc54a48dc..1a9556d39dd0 100644 --- a/crates/swc/tests/tsc-references/for-of30.1.normal.js +++ b/crates/swc/tests/tsc-references/for-of30.1.normal.js @@ -1,5 +1,4 @@ //// [for-of30.ts] -let _Symbol_iterator = Symbol.iterator; class StringIterator { next() { return { @@ -7,7 +6,7 @@ class StringIterator { value: "" }; } - [_Symbol_iterator]() { + [Symbol.iterator]() { return this; } constructor(){ diff --git a/crates/swc/tests/tsc-references/for-of30.2.minified.js b/crates/swc/tests/tsc-references/for-of30.2.minified.js index 05e5ad5c8801..2eecbb367c0e 100644 --- a/crates/swc/tests/tsc-references/for-of30.2.minified.js +++ b/crates/swc/tests/tsc-references/for-of30.2.minified.js @@ -1,16 +1,16 @@ //// [for-of30.ts] -let _Symbol_iterator = Symbol.iterator; -for (var v of new class { +class StringIterator { next() { return { done: !1, value: "" }; } - [_Symbol_iterator]() { + [Symbol.iterator]() { return this; } constructor(){ this.return = 0; } -}); +} +for (var v of new StringIterator); diff --git a/crates/swc/tests/tsc-references/generatedContextualTyping.1.normal.js b/crates/swc/tests/tsc-references/generatedContextualTyping.1.normal.js index 5cf64f559377..9cd7bc3b5133 100644 --- a/crates/swc/tests/tsc-references/generatedContextualTyping.1.normal.js +++ b/crates/swc/tests/tsc-references/generatedContextualTyping.1.normal.js @@ -439,344 +439,416 @@ var x49 = function x49() { "use strict"; _class_call_check(this, x49); }; -x49.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x49.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x50 = function x50() { "use strict"; _class_call_check(this, x50); }; -x50.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x50.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x51 = function x51() { "use strict"; _class_call_check(this, x51); }; -x51.member = function named() { - return [ - d1, - d2 - ]; -}; +(function() { + x51.member = function named() { + return [ + d1, + d2 + ]; + }; +})(); var x52 = function x52() { "use strict"; _class_call_check(this, x52); }; -x52.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x52.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x53 = function x53() { "use strict"; _class_call_check(this, x53); }; -x53.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x53.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x54 = function x54() { "use strict"; _class_call_check(this, x54); }; -x54.member = function named() { - return [ - d1, - d2 - ]; -}; +(function() { + x54.member = function named() { + return [ + d1, + d2 + ]; + }; +})(); var x55 = function x55() { "use strict"; _class_call_check(this, x55); }; -x55.member = [ - d1, - d2 -]; +(function() { + x55.member = [ + d1, + d2 + ]; +})(); var x56 = function x56() { "use strict"; _class_call_check(this, x56); }; -x56.member = [ - d1, - d2 -]; +(function() { + x56.member = [ + d1, + d2 + ]; +})(); var x57 = function x57() { "use strict"; _class_call_check(this, x57); }; -x57.member = [ - d1, - d2 -]; +(function() { + x57.member = [ + d1, + d2 + ]; +})(); var x58 = function x58() { "use strict"; _class_call_check(this, x58); }; -x58.member = { - n: [ - d1, - d2 - ] -}; +(function() { + x58.member = { + n: [ + d1, + d2 + ] + }; +})(); var x59 = function x59() { "use strict"; _class_call_check(this, x59); }; -x59.member = function(n) { - var n; - return null; -}; +(function() { + x59.member = function(n) { + var n; + return null; + }; +})(); var x60 = function x60() { "use strict"; _class_call_check(this, x60); }; -x60.member = { - func: function(n) { - return [ - d1, - d2 - ]; - } -}; +(function() { + x60.member = { + func: function(n) { + return [ + d1, + d2 + ]; + } + }; +})(); var x61 = function x61() { "use strict"; _class_call_check(this, x61); }; -x61.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x61.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x62 = function x62() { "use strict"; _class_call_check(this, x62); }; -x62.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x62.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x63 = function x63() { "use strict"; _class_call_check(this, x63); }; -x63.member = function named() { - return [ - d1, - d2 - ]; -}; +(function() { + x63.member = function named() { + return [ + d1, + d2 + ]; + }; +})(); var x64 = function x64() { "use strict"; _class_call_check(this, x64); }; -x64.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x64.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x65 = function x65() { "use strict"; _class_call_check(this, x65); }; -x65.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x65.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x66 = function x66() { "use strict"; _class_call_check(this, x66); }; -x66.member = function named() { - return [ - d1, - d2 - ]; -}; +(function() { + x66.member = function named() { + return [ + d1, + d2 + ]; + }; +})(); var x67 = function x67() { "use strict"; _class_call_check(this, x67); }; -x67.member = [ - d1, - d2 -]; +(function() { + x67.member = [ + d1, + d2 + ]; +})(); var x68 = function x68() { "use strict"; _class_call_check(this, x68); }; -x68.member = [ - d1, - d2 -]; +(function() { + x68.member = [ + d1, + d2 + ]; +})(); var x69 = function x69() { "use strict"; _class_call_check(this, x69); }; -x69.member = [ - d1, - d2 -]; +(function() { + x69.member = [ + d1, + d2 + ]; +})(); var x70 = function x70() { "use strict"; _class_call_check(this, x70); }; -x70.member = { - n: [ - d1, - d2 - ] -}; +(function() { + x70.member = { + n: [ + d1, + d2 + ] + }; +})(); var x71 = function x71() { "use strict"; _class_call_check(this, x71); }; -x71.member = function(n) { - var n; - return null; -}; +(function() { + x71.member = function(n) { + var n; + return null; + }; +})(); var x72 = function x72() { "use strict"; _class_call_check(this, x72); }; -x72.member = { - func: function(n) { - return [ - d1, - d2 - ]; - } -}; +(function() { + x72.member = { + func: function(n) { + return [ + d1, + d2 + ]; + } + }; +})(); var x73 = function x73() { "use strict"; _class_call_check(this, x73); }; -x73.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x73.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x74 = function x74() { "use strict"; _class_call_check(this, x74); }; -x74.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x74.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x75 = function x75() { "use strict"; _class_call_check(this, x75); }; -x75.member = function named() { - return [ - d1, - d2 - ]; -}; +(function() { + x75.member = function named() { + return [ + d1, + d2 + ]; + }; +})(); var x76 = function x76() { "use strict"; _class_call_check(this, x76); }; -x76.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x76.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x77 = function x77() { "use strict"; _class_call_check(this, x77); }; -x77.member = function() { - return [ - d1, - d2 - ]; -}; +(function() { + x77.member = function() { + return [ + d1, + d2 + ]; + }; +})(); var x78 = function x78() { "use strict"; _class_call_check(this, x78); }; -x78.member = function named() { - return [ - d1, - d2 - ]; -}; +(function() { + x78.member = function named() { + return [ + d1, + d2 + ]; + }; +})(); var x79 = function x79() { "use strict"; _class_call_check(this, x79); }; -x79.member = [ - d1, - d2 -]; +(function() { + x79.member = [ + d1, + d2 + ]; +})(); var x80 = function x80() { "use strict"; _class_call_check(this, x80); }; -x80.member = [ - d1, - d2 -]; +(function() { + x80.member = [ + d1, + d2 + ]; +})(); var x81 = function x81() { "use strict"; _class_call_check(this, x81); }; -x81.member = [ - d1, - d2 -]; +(function() { + x81.member = [ + d1, + d2 + ]; +})(); var x82 = function x82() { "use strict"; _class_call_check(this, x82); }; -x82.member = { - n: [ - d1, - d2 - ] -}; +(function() { + x82.member = { + n: [ + d1, + d2 + ] + }; +})(); var x83 = function x83() { "use strict"; _class_call_check(this, x83); }; -x83.member = function(n) { - var n; - return null; -}; +(function() { + x83.member = function(n) { + var n; + return null; + }; +})(); var x84 = function x84() { "use strict"; _class_call_check(this, x84); }; -x84.member = { - func: function(n) { - return [ - d1, - d2 - ]; - } -}; +(function() { + x84.member = { + func: function(n) { + return [ + d1, + d2 + ]; + } + }; +})(); var x85 = function x85() { "use strict"; var parm = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : function() { diff --git a/crates/swc/tests/tsc-references/importCallExpressionInAMD4.1.normal.js b/crates/swc/tests/tsc-references/importCallExpressionInAMD4.1.normal.js index 9592e3ee5c8d..986390cfe0b6 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInAMD4.1.normal.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInAMD4.1.normal.js @@ -65,9 +65,6 @@ define([ }); _interopRequireWildcard = _interopRequireWildcard.default; class C { - myModule = new Promise((resolve, reject)=>require([ - "./0" - ], (m)=>resolve(/*#__PURE__*/ _interopRequireWildcard(m)), reject)); method() { const loadAsync = new Promise((resolve, reject)=>require([ "./0" @@ -82,11 +79,13 @@ define([ console.log(one.backup()); }); } + constructor(){ + this.myModule = new Promise((resolve, reject)=>require([ + "./0" + ], (m)=>resolve(/*#__PURE__*/ _interopRequireWildcard(m)), reject)); + } } class D { - myModule = new Promise((resolve, reject)=>require([ - "./0" - ], (m)=>resolve(/*#__PURE__*/ _interopRequireWildcard(m)), reject)); method() { const loadAsync = new Promise((resolve, reject)=>require([ "./0" @@ -101,5 +100,10 @@ define([ console.log(one.backup()); }); } + constructor(){ + this.myModule = new Promise((resolve, reject)=>require([ + "./0" + ], (m)=>resolve(/*#__PURE__*/ _interopRequireWildcard(m)), reject)); + } } }); diff --git a/crates/swc/tests/tsc-references/importCallExpressionInAMD4.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionInAMD4.2.minified.js index eebe6178ce82..3cb6c0d82cb2 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInAMD4.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInAMD4.2.minified.js @@ -58,9 +58,6 @@ define([ get: ()=>D }), _interopRequireWildcard = _interopRequireWildcard.default; class D { - myModule = new Promise((resolve, reject)=>require([ - "./0" - ], (m)=>resolve(_interopRequireWildcard(m)), reject)); method() { new Promise((resolve, reject)=>require([ "./0" @@ -72,5 +69,10 @@ define([ ], (m)=>resolve(_interopRequireWildcard(m)), reject))).backup()); }); } + constructor(){ + this.myModule = new Promise((resolve, reject)=>require([ + "./0" + ], (m)=>resolve(_interopRequireWildcard(m)), reject)); + } } }); diff --git a/crates/swc/tests/tsc-references/importCallExpressionInCJS5.1.normal.js b/crates/swc/tests/tsc-references/importCallExpressionInCJS5.1.normal.js index 58d092a6e831..a886303e5e38 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInCJS5.1.normal.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInCJS5.1.normal.js @@ -46,7 +46,6 @@ Object.defineProperty(exports, "D", { }); const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; class C { - myModule = Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("./0"))); method() { const loadAsync = Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("./0"))); this.myModule.then((Zero)=>{ @@ -57,9 +56,11 @@ class C { console.log(one.backup()); }); } + constructor(){ + this.myModule = Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("./0"))); + } } class D { - myModule = Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("./0"))); method() { const loadAsync = Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("./0"))); this.myModule.then((Zero)=>{ @@ -70,4 +71,7 @@ class D { console.log(one.backup()); }); } + constructor(){ + this.myModule = Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("./0"))); + } } diff --git a/crates/swc/tests/tsc-references/importCallExpressionInCJS5.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionInCJS5.2.minified.js index b9fa4e2bcfc3..17ff91ff34a1 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInCJS5.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInCJS5.2.minified.js @@ -42,7 +42,6 @@ Object.defineProperty(exports, "__esModule", { }); const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; class D { - myModule = Promise.resolve().then(()=>_interopRequireWildcard(require("./0"))); method() { Promise.resolve().then(()=>_interopRequireWildcard(require("./0"))), this.myModule.then((Zero)=>{ console.log(Zero.foo()); @@ -50,4 +49,7 @@ class D { console.log(err), console.log((await Promise.resolve().then(()=>_interopRequireWildcard(require("./1")))).backup()); }); } + constructor(){ + this.myModule = Promise.resolve().then(()=>_interopRequireWildcard(require("./0"))); + } } diff --git a/crates/swc/tests/tsc-references/importCallExpressionInSystem4.1.normal.js b/crates/swc/tests/tsc-references/importCallExpressionInSystem4.1.normal.js index 25e5b4e653a7..214cb525cbc6 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInSystem4.1.normal.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInSystem4.1.normal.js @@ -49,7 +49,6 @@ System.register([], function(_export, _context) { setters: [], execute: async function() { C = class C { - myModule = _context.import("./0"); method() { const loadAsync = _context.import("./0"); this.myModule.then((Zero)=>{ @@ -60,9 +59,11 @@ System.register([], function(_export, _context) { console.log(one.backup()); }); } + constructor(){ + this.myModule = _context.import("./0"); + } }; _export("D", D = class D { - myModule = _context.import("./0"); method() { const loadAsync = _context.import("./0"); this.myModule.then((Zero)=>{ @@ -73,6 +74,9 @@ System.register([], function(_export, _context) { console.log(one.backup()); }); } + constructor(){ + this.myModule = _context.import("./0"); + } }); } }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInSystem4.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionInSystem4.2.minified.js index 34c915555009..30f8a5a440b9 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInSystem4.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInSystem4.2.minified.js @@ -38,7 +38,6 @@ System.register([], function(_export, _context) { setters: [], execute: async function() { _export("D", class { - myModule = _context.import("./0"); method() { _context.import("./0"), this.myModule.then((Zero)=>{ console.log(Zero.foo()); @@ -46,6 +45,9 @@ System.register([], function(_export, _context) { console.log(err), console.log((await _context.import("./1")).backup()); }); } + constructor(){ + this.myModule = _context.import("./0"); + } }); } }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInUMD4.1.normal.js b/crates/swc/tests/tsc-references/importCallExpressionInUMD4.1.normal.js index 7e4cd34c6d29..275c8ae87676 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInUMD4.1.normal.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInUMD4.1.normal.js @@ -68,7 +68,6 @@ }); _interopRequireWildcard = _interopRequireWildcard.default; class C { - myModule = import("./0"); method() { const loadAsync = import("./0"); this.myModule.then((Zero)=>{ @@ -79,9 +78,11 @@ console.log(one.backup()); }); } + constructor(){ + this.myModule = import("./0"); + } } class D { - myModule = import("./0"); method() { const loadAsync = import("./0"); this.myModule.then((Zero)=>{ @@ -92,5 +93,8 @@ console.log(one.backup()); }); } + constructor(){ + this.myModule = import("./0"); + } } }); diff --git a/crates/swc/tests/tsc-references/importCallExpressionInUMD4.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionInUMD4.2.minified.js index dd9f8864755c..1ecb1ccf7fc7 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInUMD4.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInUMD4.2.minified.js @@ -57,7 +57,6 @@ get: ()=>D }), _interopRequireWildcard = _interopRequireWildcard.default; class D { - myModule = import("./0"); method() { import("./0"), this.myModule.then((Zero)=>{ console.log(Zero.foo()); @@ -65,5 +64,8 @@ console.log(err), console.log((await import("./1")).backup()); }); } + constructor(){ + this.myModule = import("./0"); + } } }); diff --git a/crates/swc/tests/tsc-references/importImportOnlyModule.1.normal.js b/crates/swc/tests/tsc-references/importImportOnlyModule.1.normal.js index 5d28e9c2e13d..aee5e3bc39e8 100644 --- a/crates/swc/tests/tsc-references/importImportOnlyModule.1.normal.js +++ b/crates/swc/tests/tsc-references/importImportOnlyModule.1.normal.js @@ -20,7 +20,9 @@ define([ _classCallCheck(this, C1); this.m1 = 42; }; - C1.s1 = true; + (function() { + C1.s1 = true; + })(); }); //// [foo_1.ts] define([ diff --git a/crates/swc/tests/tsc-references/inferringClassMembersFromAssignments.1.normal.js b/crates/swc/tests/tsc-references/inferringClassMembersFromAssignments.1.normal.js index 18dafe81f527..b02c2d0ae9ae 100644 --- a/crates/swc/tests/tsc-references/inferringClassMembersFromAssignments.1.normal.js +++ b/crates/swc/tests/tsc-references/inferringClassMembersFromAssignments.1.normal.js @@ -87,13 +87,15 @@ var C = /*#__PURE__*/ function() { }; return C; }(); -C.prop = function() { - if (Math.random()) { - C.inStaticPropertyDeclaration = 0; - } else { - C.inStaticPropertyDeclaration = "string"; - } -}; +(function() { + C.prop = function() { + if (Math.random()) { + C.inStaticPropertyDeclaration = 0; + } else { + C.inStaticPropertyDeclaration = "string"; + } + }; +})(); //// [b.ts] var c = new C(); var stringOrNumber; diff --git a/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName.1.normal.js b/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName.1.normal.js index 52005ae6fba5..3ad396bd2a7b 100644 --- a/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName.1.normal.js +++ b/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName.1.normal.js @@ -3,10 +3,9 @@ "use strict"; import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; var x = 1; -var _x = x; var C = function C() { _class_call_check(this, C); - this[_x] = true; + this[x] = true; var _ref = { a: 1, b: 2 diff --git a/crates/swc/tests/tsc-references/jsDeclarationsClasses.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsClasses.1.normal.js index b82e640a8c85..a2f7fad76905 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsClasses.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsClasses.1.normal.js @@ -12,15 +12,19 @@ export var B = function B() { "use strict"; _class_call_check(this, B); }; -B.cat = "cat"; +(function() { + B.cat = "cat"; +})(); export var C = function C() { "use strict"; _class_call_check(this, C); }; -C.Cls = function _class() { - "use strict"; - _class_call_check(this, _class); -}; +(function() { + C.Cls = function _class() { + "use strict"; + _class_call_check(this, _class); + }; +})(); export var D = function D(a, b) { "use strict"; _class_call_check(this, D); @@ -88,7 +92,9 @@ export var D = function D(a, b) { ]); return E; }(); -E.staticInitializedField = 12; +(function() { + E.staticInitializedField = 12; +})(); /** * @template T,U */ export var F = /*#__PURE__*/ function() { diff --git a/crates/swc/tests/tsc-references/jsDeclarationsComputedNames.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsComputedNames.1.normal.js index ec7ebe6940ef..3a93e08aef6a 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsComputedNames.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsComputedNames.1.normal.js @@ -16,11 +16,12 @@ module.exports = (_obj = {}, _define_property(_obj, TopLevelSym, function() { import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; var TopLevelSym = Symbol(); var InnerSym = Symbol(); -var _InnerSym = InnerSym; export var MyClass = function MyClass() { "use strict"; var _p = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : InnerSym; _class_call_check(this, MyClass); - this[_InnerSym] = "ok"; + this[InnerSym] = "ok"; }; -MyClass[TopLevelSym] = 12; +(function() { + MyClass[TopLevelSym] = 12; +})(); diff --git a/crates/swc/tests/tsc-references/jsDeclarationsDefaultsErr.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsDefaultsErr.1.normal.js index f1ff4c88d532..46310ab21ac0 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsDefaultsErr.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsDefaultsErr.1.normal.js @@ -6,7 +6,9 @@ var Cls = function Cls() { _class_call_check(this, Cls); this.x = 12; }; -Cls.y = "ok"; +(function() { + Cls.y = "ok"; +})(); export default Cls; /** * @typedef {string | number} default */ diff --git a/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance2.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance2.1.normal.js index 9575af9fbcc6..ac0b5e47dae6 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance2.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance2.1.normal.js @@ -5,5 +5,7 @@ var Foo = function Foo() { _class_call_check(this, Foo); this.member = 10; }; -Foo.stat = 10; +(function() { + Foo.stat = 10; +})(); module.exports = new Foo(); diff --git a/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance3.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance3.1.normal.js index 90651a086920..2f3a4888822a 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance3.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance3.1.normal.js @@ -5,6 +5,8 @@ var Foo = function Foo() { _class_call_check(this, Foo); this.member = 10; }; -Foo.stat = 10; +(function() { + Foo.stat = 10; +})(); module.exports = new Foo(); module.exports.additional = 20; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsPrivateFields01.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsPrivateFields01.1.normal.js index e3171228e1b1..9cc4d691dc36 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsPrivateFields01.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsPrivateFields01.1.normal.js @@ -1,8 +1,8 @@ //// [jsDeclarationsPrivateFields01.ts] //// [file.js] export class C { - #hello = "hello"; - #world = 100; + #hello; + #world; #calcHello() { return this.#hello; } @@ -15,4 +15,8 @@ export class C { getWorld() { return this.#world; } + constructor(){ + this.#hello = "hello"; + this.#world = 100; + } } diff --git a/crates/swc/tests/tsc-references/jsDeclarationsPrivateFields01.2.minified.js b/crates/swc/tests/tsc-references/jsDeclarationsPrivateFields01.2.minified.js index 92238cf37976..83365235cfbd 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsPrivateFields01.2.minified.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsPrivateFields01.2.minified.js @@ -1,8 +1,8 @@ //// [jsDeclarationsPrivateFields01.ts] //// [file.js] export class C { - #hello = "hello"; - #world = 100; + #hello; + #world; #calcHello() { return this.#hello; } @@ -15,4 +15,7 @@ export class C { getWorld() { return this.#world; } + constructor(){ + this.#hello = "hello", this.#world = 100; + } } diff --git a/crates/swc/tests/tsc-references/jsDeclarationsReusesExistingTypeAnnotations.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsReusesExistingTypeAnnotations.1.normal.js index be8899162b16..aa112d2540d8 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsReusesExistingTypeAnnotations.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsReusesExistingTypeAnnotations.1.normal.js @@ -1,9 +1,11 @@ //// [index.js] class С1 { - /** @type {string=} */ p1 = undefined; - /** @type {string | undefined} */ p2 = undefined; - /** @type {?string} */ p3 = null; - /** @type {string | null} */ p4 = null; + constructor(){ + /** @type {string=} */ this.p1 = undefined; + /** @type {string | undefined} */ this.p2 = undefined; + /** @type {?string} */ this.p3 = null; + /** @type {string | null} */ this.p4 = null; + } } class С2 { /** @type {string=} */ get p1() { diff --git a/crates/swc/tests/tsc-references/mixinClassesAnnotated.1.normal.js b/crates/swc/tests/tsc-references/mixinClassesAnnotated.1.normal.js index 2ae5bb4dab78..86b3e5d2f2db 100644 --- a/crates/swc/tests/tsc-references/mixinClassesAnnotated.1.normal.js +++ b/crates/swc/tests/tsc-references/mixinClassesAnnotated.1.normal.js @@ -37,7 +37,9 @@ var Printable = function(superClass) { }; return _class; }(superClass); - _class.message = "hello"; + (function() { + _class.message = "hello"; + })(); return _class; }; function Tagged(superClass) { diff --git a/crates/swc/tests/tsc-references/mixinClassesAnonymous.1.normal.js b/crates/swc/tests/tsc-references/mixinClassesAnonymous.1.normal.js index 17db12d1441b..4b5abdbf9bbd 100644 --- a/crates/swc/tests/tsc-references/mixinClassesAnonymous.1.normal.js +++ b/crates/swc/tests/tsc-references/mixinClassesAnonymous.1.normal.js @@ -37,7 +37,9 @@ var Printable = function(superClass) { }; return _class; }(superClass); - _class.message = "hello"; + (function() { + _class.message = "hello"; + })(); return _class; }; function Tagged(superClass) { diff --git a/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction.1.normal.js b/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction.1.normal.js index 9fa8e37b7c4e..544384183238 100644 --- a/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction.1.normal.js +++ b/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction.1.normal.js @@ -11,5 +11,7 @@ function g() { var _proto = C.prototype; _proto.foo = function foo() {}; return C; - }(), _C.prop2 = 43, _C); + }(), function() { + _C.prop2 = 43; + }(), _C); } diff --git a/crates/swc/tests/tsc-references/newTarget.es5.1.normal.js b/crates/swc/tests/tsc-references/newTarget.es5.1.normal.js index 51afde121097..327f0e74500b 100644 --- a/crates/swc/tests/tsc-references/newTarget.es5.1.normal.js +++ b/crates/swc/tests/tsc-references/newTarget.es5.1.normal.js @@ -15,9 +15,11 @@ var A = function A() { return _instanceof(_this, A) ? _this.constructor : void 0; }; }; -A.c = function _target() { - return _instanceof(this, _target) ? this.constructor : void 0; -}; +(function() { + A.c = function _target() { + return _instanceof(this, _target) ? this.constructor : void 0; + }; +})(); var B = /*#__PURE__*/ function _target(A) { "use strict"; _inherits(B, A); diff --git a/crates/swc/tests/tsc-references/newTarget.es6.1.normal.js b/crates/swc/tests/tsc-references/newTarget.es6.1.normal.js index 50f041f99fda..acc4dd781954 100644 --- a/crates/swc/tests/tsc-references/newTarget.es6.1.normal.js +++ b/crates/swc/tests/tsc-references/newTarget.es6.1.normal.js @@ -8,9 +8,11 @@ class A { const b = ()=>new.target; } } -A.c = function() { - return new.target; -}; +(()=>{ + A.c = function() { + return new.target; + }; +})(); class B extends A { constructor(){ super(); diff --git a/crates/swc/tests/tsc-references/overloadTag2.1.normal.js b/crates/swc/tests/tsc-references/overloadTag2.1.normal.js index 498629191d2e..116f5d36b1fb 100644 --- a/crates/swc/tests/tsc-references/overloadTag2.1.normal.js +++ b/crates/swc/tests/tsc-references/overloadTag2.1.normal.js @@ -1,6 +1,6 @@ //// [overloadTag2.js] export class Foo { - #a = true ? 1 : "1"; + #a; #b; /** * Should not have an implicit any error, because constructor's return type is always implicit @@ -20,6 +20,7 @@ export class Foo { * @constructor * @param {number | string} a */ constructor(a, b){ + this.#a = true ? 1 : "1"; this.#a = a; this.#b = b; } diff --git a/crates/swc/tests/tsc-references/overloadTag2.2.minified.js b/crates/swc/tests/tsc-references/overloadTag2.2.minified.js index 2d77f24c9981..f0ab80d00ddb 100644 --- a/crates/swc/tests/tsc-references/overloadTag2.2.minified.js +++ b/crates/swc/tests/tsc-references/overloadTag2.2.minified.js @@ -1,9 +1,9 @@ //// [overloadTag2.js] export class Foo { - #a = 1; + #a; #b; constructor(a, b){ - this.#a = a, this.#b = b; + this.#a = 1, this.#a = a, this.#b = b; } } new Foo(), new Foo('str'), new Foo(2), new Foo('str', 2); diff --git a/crates/swc/tests/tsc-references/override13.1.normal.js b/crates/swc/tests/tsc-references/override13.1.normal.js index 827572246873..774264c47fa6 100644 --- a/crates/swc/tests/tsc-references/override13.1.normal.js +++ b/crates/swc/tests/tsc-references/override13.1.normal.js @@ -1,23 +1,41 @@ //// [override13.ts] class Foo { - property = 1; - static staticProperty = 2; + static{ + this.staticProperty = 2; + } + constructor(){ + this.property = 1; + } } class SubFoo extends Foo { - property = 42; - staticProperty = 42; + constructor(...args){ + super(...args); + this.property = 42; + this.staticProperty = 42; + } } class StaticSubFoo extends Foo { - static property = 42; - static staticProperty = 42; + static{ + this.property = 42; + } + static{ + this.staticProperty = 42; + } } class Intermediate extends Foo { } class Derived extends Intermediate { - property = 42; - staticProperty = 42; + constructor(...args){ + super(...args); + this.property = 42; + this.staticProperty = 42; + } } class StaticDerived extends Intermediate { - static property = 42; - static staticProperty = 42; + static{ + this.property = 42; + } + static{ + this.staticProperty = 42; + } } diff --git a/crates/swc/tests/tsc-references/override13.2.minified.js b/crates/swc/tests/tsc-references/override13.2.minified.js index 3d2b0cbf25ce..160ef27079f9 100644 --- a/crates/swc/tests/tsc-references/override13.2.minified.js +++ b/crates/swc/tests/tsc-references/override13.2.minified.js @@ -1 +1,27 @@ //// [override13.ts] +class Foo { + static{ + this.staticProperty = 2; + } + constructor(){ + this.property = 1; + } +} +class StaticSubFoo extends Foo { + static{ + this.property = 42; + } + static{ + this.staticProperty = 42; + } +} +class Intermediate extends Foo { +} +class StaticDerived extends Intermediate { + static{ + this.property = 42; + } + static{ + this.staticProperty = 42; + } +} diff --git a/crates/swc/tests/tsc-references/override14.1.normal.js b/crates/swc/tests/tsc-references/override14.1.normal.js index 6993178f0a33..3f5845c3afbc 100644 --- a/crates/swc/tests/tsc-references/override14.1.normal.js +++ b/crates/swc/tests/tsc-references/override14.1.normal.js @@ -1,6 +1,8 @@ //// [override14.ts] class Foo { - property = 1; + constructor(){ + this.property = 1; + } } class SubFoo extends Foo { } diff --git a/crates/swc/tests/tsc-references/override16(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/override16(target=es2022).1.normal.js index bb3c8978347b..087936933588 100644 --- a/crates/swc/tests/tsc-references/override16(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/override16(target=es2022).1.normal.js @@ -2,5 +2,8 @@ class A { } class B extends A { - foo = "string"; + constructor(...args){ + super(...args); + this.foo = "string"; + } } diff --git a/crates/swc/tests/tsc-references/overrideInterfaceProperty.1.normal.js b/crates/swc/tests/tsc-references/overrideInterfaceProperty.1.normal.js index 580ae7919af0..c17dda81607f 100644 --- a/crates/swc/tests/tsc-references/overrideInterfaceProperty.1.normal.js +++ b/crates/swc/tests/tsc-references/overrideInterfaceProperty.1.normal.js @@ -6,5 +6,8 @@ class Sizz extends Mup { } } class Kasizz extends Mup { - size = -1; + constructor(...args){ + super(...args); + this.size = -1; + } } diff --git a/crates/swc/tests/tsc-references/parserAccessibilityAfterStatic3.1.normal.js b/crates/swc/tests/tsc-references/parserAccessibilityAfterStatic3.1.normal.js index ca2af143fae0..aa269b9ad72f 100644 --- a/crates/swc/tests/tsc-references/parserAccessibilityAfterStatic3.1.normal.js +++ b/crates/swc/tests/tsc-references/parserAccessibilityAfterStatic3.1.normal.js @@ -4,4 +4,6 @@ var Outer = function Outer() { "use strict"; _class_call_check(this, Outer); }; -Outer.public = 1; +(function() { + Outer.public = 1; +})(); diff --git a/crates/swc/tests/tsc-references/parserES5SymbolProperty6.1.normal.js b/crates/swc/tests/tsc-references/parserES5SymbolProperty6.1.normal.js index 9dcc04a9a412..73e377534f96 100644 --- a/crates/swc/tests/tsc-references/parserES5SymbolProperty6.1.normal.js +++ b/crates/swc/tests/tsc-references/parserES5SymbolProperty6.1.normal.js @@ -1,8 +1,11 @@ //// [parserES5SymbolProperty6.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; -var _Symbol_toStringTag = Symbol.toStringTag; +var prop; var C = function C() { "use strict"; _class_call_check(this, C); - this[_Symbol_toStringTag] = ""; + this[prop] = ""; }; +(function() { + prop = Symbol.toStringTag; +})(); diff --git a/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1.1.normal.js b/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1.1.normal.js index 93c234471950..0caff3e62c55 100644 --- a/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1.1.normal.js +++ b/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1.1.normal.js @@ -18,8 +18,10 @@ var Shapes; }; return Point; }(); - // Static member - Point.origin = new Point(0, 0); + (function() { + // Static member + Point.origin = new Point(0, 0); + })(); Shapes.Point = Point; })(Shapes || (Shapes = {})); // Local variables diff --git a/crates/swc/tests/tsc-references/parserSymbolProperty5.1.normal.js b/crates/swc/tests/tsc-references/parserSymbolProperty5.1.normal.js index 71707fd6276c..e6c5ed3b610a 100644 --- a/crates/swc/tests/tsc-references/parserSymbolProperty5.1.normal.js +++ b/crates/swc/tests/tsc-references/parserSymbolProperty5.1.normal.js @@ -1,3 +1,7 @@ //// [parserSymbolProperty5.ts] +let prop; class C { } +(()=>{ + prop = Symbol.toPrimitive; +})(); diff --git a/crates/swc/tests/tsc-references/parserSymbolProperty6.1.normal.js b/crates/swc/tests/tsc-references/parserSymbolProperty6.1.normal.js index e8169135febf..6965662c9bc6 100644 --- a/crates/swc/tests/tsc-references/parserSymbolProperty6.1.normal.js +++ b/crates/swc/tests/tsc-references/parserSymbolProperty6.1.normal.js @@ -1,7 +1,10 @@ //// [parserSymbolProperty6.ts] -let _Symbol_toStringTag = Symbol.toStringTag; +let prop; class C { constructor(){ - this[_Symbol_toStringTag] = ""; + this[prop] = ""; } } +(()=>{ + prop = Symbol.toStringTag; +})(); diff --git a/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.1.normal.js b/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.1.normal.js index a95b8ec3f968..1d20980369e3 100644 --- a/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.1.normal.js @@ -1,6 +1,7 @@ //// [privateNameAndObjectRestSpread.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_static_private_field_spec_get from "@swc/helpers/src/_class_static_private_field_spec_get.mjs"; import _extends from "@swc/helpers/src/_extends.mjs"; import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; @@ -20,8 +21,9 @@ class C { constructor(){ _class_private_field_init(this, _prop, { writable: true, - value: 1 + value: void 0 }); + _class_private_field_set(this, _prop, 1); } } var _propStatic = { diff --git a/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.2.minified.js b/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.2.minified.js index 1369738f046c..65ca71deb934 100644 --- a/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.2.minified.js @@ -1,6 +1,7 @@ //// [privateNameAndObjectRestSpread.ts] import "@swc/helpers/src/_class_private_field_get.mjs"; import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; import "@swc/helpers/src/_class_static_private_field_spec_get.mjs"; import "@swc/helpers/src/_extends.mjs"; import "@swc/helpers/src/_object_destructuring_empty.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2015).1.normal.js index 83d1e0473804..cc9948c52680 100644 --- a/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2015).1.normal.js @@ -1,16 +1,21 @@ //// [privateNameAndStaticInitializer.ts] import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; var _foo = /*#__PURE__*/ new WeakMap(), _prop = /*#__PURE__*/ new WeakMap(); class A { constructor(){ _class_private_field_init(this, _foo, { writable: true, - value: 1 + value: void 0 }); _class_private_field_init(this, _prop, { writable: true, - value: 2 + value: void 0 }); + _class_private_field_set(this, _foo, 1); + _class_private_field_set(this, _prop, 2); } } -A.inst = new A(); +(()=>{ + A.inst = new A(); +})(); diff --git a/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2015).2.minified.js index bee06d8fe390..c87d00d2ba45 100644 --- a/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2015).2.minified.js @@ -1,15 +1,16 @@ //// [privateNameAndStaticInitializer.ts] import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; var _foo = new WeakMap(), _prop = new WeakMap(); class A { constructor(){ _class_private_field_init(this, _foo, { writable: !0, - value: 1 + value: void 0 }), _class_private_field_init(this, _prop, { writable: !0, - value: 2 - }); + value: void 0 + }), _class_private_field_set(this, _foo, 1), _class_private_field_set(this, _prop, 2); } } A.inst = new A(); diff --git a/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2022).1.normal.js index 6706483b16f8..5fd0913a509d 100644 --- a/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2022).1.normal.js @@ -1,6 +1,12 @@ //// [privateNameAndStaticInitializer.ts] class A { - #foo = 1; - static inst = new A(); - #prop = 2; + #foo; + static{ + this.inst = new A(); + } + #prop; + constructor(){ + this.#foo = 1; + this.#prop = 2; + } } diff --git a/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2022).2.minified.js index 6706483b16f8..319a6f513d3b 100644 --- a/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameAndStaticInitializer(target=es2022).2.minified.js @@ -1,6 +1,11 @@ //// [privateNameAndStaticInitializer.ts] class A { - #foo = 1; - static inst = new A(); - #prop = 2; + #foo; + static{ + this.inst = new A(); + } + #prop; + constructor(){ + this.#foo = 1, this.#prop = 2; + } } diff --git a/crates/swc/tests/tsc-references/privateNameCircularReference.1.normal.js b/crates/swc/tests/tsc-references/privateNameCircularReference.1.normal.js index 36fa6ec5e03b..3a2e9b049126 100644 --- a/crates/swc/tests/tsc-references/privateNameCircularReference.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameCircularReference.1.normal.js @@ -1,17 +1,20 @@ //// [privateNameCircularReference.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; var _foo = /*#__PURE__*/ new WeakMap(), _bar = /*#__PURE__*/ new WeakMap(); class A { constructor(){ _class_private_field_init(this, _foo, { writable: true, - value: _class_private_field_get(this, _bar) + value: void 0 }); _class_private_field_init(this, _bar, { writable: true, - value: _class_private_field_get(this, _foo) + value: void 0 }); + _class_private_field_set(this, _foo, _class_private_field_get(this, _bar)); + _class_private_field_set(this, _bar, _class_private_field_get(this, _foo)); this["#baz"] = this["#baz"] // Error (should *not* be private name error) ; } diff --git a/crates/swc/tests/tsc-references/privateNameCircularReference.2.minified.js b/crates/swc/tests/tsc-references/privateNameCircularReference.2.minified.js index 9b11a9429f88..e032b63f4e63 100644 --- a/crates/swc/tests/tsc-references/privateNameCircularReference.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameCircularReference.2.minified.js @@ -1,3 +1,4 @@ //// [privateNameCircularReference.ts] import "@swc/helpers/src/_class_private_field_get.mjs"; import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNameClassExpressionLoop.1.normal.js b/crates/swc/tests/tsc-references/privateNameClassExpressionLoop.1.normal.js index 0555ecebc984..9480417bbd6f 100644 --- a/crates/swc/tests/tsc-references/privateNameClassExpressionLoop.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameClassExpressionLoop.1.normal.js @@ -1,5 +1,6 @@ //// [privateNameClassExpressionLoop.ts] import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_private_method_init from "@swc/helpers/src/_class_private_method_init.mjs"; const array = []; for(let i = 0; i < 10; ++i){ @@ -13,8 +14,9 @@ for(let i = 0; i < 10; ++i){ }); _class_private_field_init(this, _myField, { writable: true, - value: "hello" + value: void 0 }); + _class_private_field_set(this, _myField, "hello"); } }, _C)); function method() {} diff --git a/crates/swc/tests/tsc-references/privateNameClassExpressionLoop.2.minified.js b/crates/swc/tests/tsc-references/privateNameClassExpressionLoop.2.minified.js index a3dc5cf7a489..0ac5cb828ead 100644 --- a/crates/swc/tests/tsc-references/privateNameClassExpressionLoop.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameClassExpressionLoop.2.minified.js @@ -1,5 +1,6 @@ //// [privateNameClassExpressionLoop.ts] import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_private_method_init from "@swc/helpers/src/_class_private_method_init.mjs"; let array = []; for(let i = 0; i < 10; ++i){ @@ -15,8 +16,8 @@ for(let i = 0; i < 10; ++i){ set: set_accessor }), _class_private_field_init(this, _myField, { writable: !0, - value: "hello" - }); + value: void 0 + }), _class_private_field_set(this, _myField, "hello"); } })); } diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2015).1.normal.js index 3e0477f27c40..133fe56ce0d4 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2015).1.normal.js @@ -24,7 +24,7 @@ class A { constructor(){ _class_private_field_init(this, _a, { writable: true, - value: 'a' + value: void 0 }); _class_private_field_init(this, _b, { writable: true, @@ -32,7 +32,7 @@ class A { }); _class_private_field_init(this, _c, { writable: true, - value: 'c' + value: void 0 }); _class_private_field_init(this, _d, { writable: true, @@ -40,8 +40,11 @@ class A { }); _class_private_field_init(this, _e, { writable: true, - value: '' + value: void 0 }); + _class_private_field_set(this, _a, 'a'); + _class_private_field_set(this, _c, 'c'); + _class_private_field_set(this, _e, ''); _class_private_field_set(this, _b, 'b'); _class_private_field_set(this, _d, 'd'); } diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2015).2.minified.js index d03de9db7997..6a6877a627bd 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2015).2.minified.js @@ -19,19 +19,19 @@ new class { constructor(){ _class_private_field_init(this, _a, { writable: !0, - value: 'a' + value: void 0 }), _class_private_field_init(this, _b, { writable: !0, value: void 0 }), _class_private_field_init(this, _c, { writable: !0, - value: 'c' + value: void 0 }), _class_private_field_init(this, _d, { writable: !0, value: void 0 }), _class_private_field_init(this, _e, { writable: !0, - value: '' - }), _class_private_field_set(this, _b, 'b'), _class_private_field_set(this, _d, 'd'); + value: void 0 + }), _class_private_field_set(this, _a, 'a'), _class_private_field_set(this, _c, 'c'), _class_private_field_set(this, _e, ''), _class_private_field_set(this, _b, 'b'), _class_private_field_set(this, _d, 'd'); } }().test(); diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2022).1.normal.js index 8d7d03d61992..108792f16097 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2022).1.normal.js @@ -1,11 +1,14 @@ //// [privateNameComputedPropertyName1.ts] class A { - #a = 'a'; + #a; #b; - #c = 'c'; + #c; #d; - #e = ''; + #e; constructor(){ + this.#a = 'a'; + this.#c = 'c'; + this.#e = ''; this.#b = 'b'; this.#d = 'd'; } diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2022).2.minified.js index 44221aad0358..d7e9e9d7d972 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName1(target=es2022).2.minified.js @@ -1,12 +1,12 @@ //// [privateNameComputedPropertyName1.ts] new class { - #a = 'a'; + #a; #b; - #c = 'c'; + #c; #d; - #e = ''; + #e; constructor(){ - this.#b = 'b', this.#d = 'd'; + this.#a = 'a', this.#c = 'c', this.#e = '', this.#b = 'b', this.#d = 'd'; } test() { let data = { diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2015).1.normal.js index 5bf3774e47a1..34c788379348 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2015).1.normal.js @@ -1,6 +1,7 @@ //// [privateNameComputedPropertyName2.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; let getX; var _x = /*#__PURE__*/ new WeakMap(); let _tmp = (getX = (a)=>_class_private_field_get(a, _x), "_"); @@ -9,8 +10,9 @@ class A { constructor(){ _class_private_field_init(this, _x, { writable: true, - value: 100 + value: void 0 }); + _class_private_field_set(this, _x, 100); } } console.log(getX(new A)); diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2015).2.minified.js index c546a894638f..3c49d19ac1bb 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2015).2.minified.js @@ -1,13 +1,14 @@ //// [privateNameComputedPropertyName2.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; var _x = new WeakMap(); console.log(_class_private_field_get(new class { _() {} constructor(){ _class_private_field_init(this, _x, { writable: !0, - value: 100 - }); + value: void 0 + }), _class_private_field_set(this, _x, 100); } }, _x)); diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2022).1.normal.js index fcd9a7828585..d45daae5a075 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2022).1.normal.js @@ -1,7 +1,10 @@ //// [privateNameComputedPropertyName2.ts] let getX; class A { - #x = 100; + #x; [(getX = (a)=>a.#x, "_")]() {} + constructor(){ + this.#x = 100; + } } console.log(getX(new A)); diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2022).2.minified.js index fcd9a7828585..d45daae5a075 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName2(target=es2022).2.minified.js @@ -1,7 +1,10 @@ //// [privateNameComputedPropertyName2.ts] let getX; class A { - #x = 100; + #x; [(getX = (a)=>a.#x, "_")]() {} + constructor(){ + this.#x = 100; + } } console.log(getX(new A)); diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2015).1.normal.js index 396fe9014483..e5217a6f4187 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2015).1.normal.js @@ -15,8 +15,9 @@ class Foo { constructor(){ _class_private_field_init(this, _y, { writable: true, - value: 100 + value: void 0 }); + _class_private_field_set(this, _y, 100); } } return new Bar()[_class_private_field_get(obj, _name)](); diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2015).2.minified.js index dc74b05659c1..ffc387a1fe8d 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2015).2.minified.js @@ -14,8 +14,8 @@ console.log(new class { constructor(){ _class_private_field_init(this, _y, { writable: !0, - value: 100 - }); + value: void 0 + }), _class_private_field_set(this, _y, 100); } }()[_class_private_field_get(this, _name)](); } diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2022).1.normal.js index 1d67e7525643..15cd298e7ed6 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2022).1.normal.js @@ -7,10 +7,13 @@ class Foo { getValue(x) { const obj = this; class Bar { - #y = 100; + #y; [obj.#name]() { return x + this.#y; } + constructor(){ + this.#y = 100; + } } return new Bar()[obj.#name](); } diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2022).2.minified.js index 15b854057fdb..e7472b20dd14 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName3(target=es2022).2.minified.js @@ -7,10 +7,13 @@ console.log(new class { getValue(x) { let obj = this; class Bar { - #y = 100; + #y; [obj.#name]() { return x + this.#y; } + constructor(){ + this.#y = 100; + } } return new Bar()[obj.#name](); } diff --git a/crates/swc/tests/tsc-references/privateNameDeclaration.1.normal.js b/crates/swc/tests/tsc-references/privateNameDeclaration.1.normal.js index d5748d72c81c..67f641caf17b 100644 --- a/crates/swc/tests/tsc-references/privateNameDeclaration.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameDeclaration.1.normal.js @@ -1,5 +1,6 @@ //// [privateNameDeclaration.ts] import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; var _foo = /*#__PURE__*/ new WeakMap(), _bar = /*#__PURE__*/ new WeakMap(); class A { quux() {} @@ -10,8 +11,9 @@ class A { }); _class_private_field_init(this, _bar, { writable: true, - value: 6 + value: void 0 }); + _class_private_field_set(this, _bar, 6); this.qux = 6; } } diff --git a/crates/swc/tests/tsc-references/privateNameDeclaration.2.minified.js b/crates/swc/tests/tsc-references/privateNameDeclaration.2.minified.js index a6c740f0f65a..c5476740577a 100644 --- a/crates/swc/tests/tsc-references/privateNameDeclaration.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameDeclaration.2.minified.js @@ -1,2 +1,3 @@ //// [privateNameDeclaration.ts] import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNameES5Ban(target=es5).1.normal.js b/crates/swc/tests/tsc-references/privateNameES5Ban(target=es5).1.normal.js index a4a85999a2c2..bc16daac7d2a 100644 --- a/crates/swc/tests/tsc-references/privateNameES5Ban(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameES5Ban(target=es5).1.normal.js @@ -1,6 +1,7 @@ //// [privateNameES5Ban.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_private_method_init from "@swc/helpers/src/_class_private_method_init.mjs"; var _field = /*#__PURE__*/ new WeakMap(), _method = /*#__PURE__*/ new WeakSet(), _acc = /*#__PURE__*/ new WeakMap(); var A = function A() { @@ -13,8 +14,9 @@ var A = function A() { }); _class_private_field_init(this, _field, { writable: true, - value: 123 + value: void 0 }); + _class_private_field_set(this, _field, 123); }; var _sAcc = { get: get_sAcc, diff --git a/crates/swc/tests/tsc-references/privateNameES5Ban(target=es5).2.minified.js b/crates/swc/tests/tsc-references/privateNameES5Ban(target=es5).2.minified.js index 825c174f7fc7..0e498471a96c 100644 --- a/crates/swc/tests/tsc-references/privateNameES5Ban(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameES5Ban(target=es5).2.minified.js @@ -1,4 +1,5 @@ //// [privateNameES5Ban.ts] import "@swc/helpers/src/_class_call_check.mjs"; import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; import "@swc/helpers/src/_class_private_method_init.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNameEmitHelpers.1.normal.js b/crates/swc/tests/tsc-references/privateNameEmitHelpers.1.normal.js index 0d59b911f709..50ff3798a5d7 100644 --- a/crates/swc/tests/tsc-references/privateNameEmitHelpers.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameEmitHelpers.1.normal.js @@ -14,8 +14,9 @@ export class C { }); _class_private_field_init(this, _a, { writable: true, - value: 1 + value: void 0 }); + _class_private_field_set(this, _a, 1); } } function b() { diff --git a/crates/swc/tests/tsc-references/privateNameEmitHelpers.2.minified.js b/crates/swc/tests/tsc-references/privateNameEmitHelpers.2.minified.js index bf5423a930ca..943250dd5788 100644 --- a/crates/swc/tests/tsc-references/privateNameEmitHelpers.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameEmitHelpers.2.minified.js @@ -12,8 +12,8 @@ export class C { set: set_c }), _class_private_field_init(this, _a, { writable: !0, - value: 1 - }); + value: void 0 + }), _class_private_field_set(this, _a, 1); } } function set_c(v) { diff --git a/crates/swc/tests/tsc-references/privateNameFieldAccess.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldAccess.1.normal.js index 99f3a4510764..1e0120c5ac51 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldAccess.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldAccess.1.normal.js @@ -1,13 +1,15 @@ //// [privateNameFieldAccess.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; var _myField = /*#__PURE__*/ new WeakMap(); class A { constructor(){ _class_private_field_init(this, _myField, { writable: true, - value: "hello world" + value: void 0 }); + _class_private_field_set(this, _myField, "hello world"); console.log(_class_private_field_get(this, _myField)); } } diff --git a/crates/swc/tests/tsc-references/privateNameFieldAccess.2.minified.js b/crates/swc/tests/tsc-references/privateNameFieldAccess.2.minified.js index 11daa5a84745..732a184d5fb5 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldAccess.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameFieldAccess.2.minified.js @@ -1,3 +1,4 @@ //// [privateNameFieldAccess.ts] import "@swc/helpers/src/_class_private_field_get.mjs"; import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNameFieldAssignment.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldAssignment.1.normal.js index c05568ccf02f..20a140255e9c 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldAssignment.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldAssignment.1.normal.js @@ -11,8 +11,9 @@ class A { var _A_getInstance, _A_getInstance1, _A_getInstance2, _A_getInstance3, _A_getInstance4, _A_getInstance5, _A_getInstance6, _A_getInstance7, _A_getInstance8, _A_getInstance9, _A_getInstance10, _A_getInstance11; _class_private_field_init(this, _field, { writable: true, - value: 0 + value: void 0 }); + _class_private_field_set(this, _field, 0); _class_private_field_set(this, _field, 1); _class_private_field_set(this, _field, _class_private_field_get(this, _field) + 2); _class_private_field_set(this, _field, _class_private_field_get(this, _field) - 3); diff --git a/crates/swc/tests/tsc-references/privateNameFieldCallExpression.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldCallExpression.1.normal.js index 908da134d18c..dc8eac77709b 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldCallExpression.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldCallExpression.1.normal.js @@ -1,6 +1,7 @@ //// [privateNameFieldCallExpression.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; var _fieldFunc = /*#__PURE__*/ new WeakMap(), _fieldFunc2 = /*#__PURE__*/ new WeakMap(); class A { test() { @@ -26,14 +27,16 @@ class A { constructor(){ _class_private_field_init(this, _fieldFunc, { writable: true, - value: function() { - this.x = 10; - } + value: void 0 }); _class_private_field_init(this, _fieldFunc2, { writable: true, - value: function(a, ...b) {} + value: void 0 }); + _class_private_field_set(this, _fieldFunc, function() { + this.x = 10; + }); + _class_private_field_set(this, _fieldFunc2, function(a, ...b) {}); this.x = 1; } } diff --git a/crates/swc/tests/tsc-references/privateNameFieldCallExpression.2.minified.js b/crates/swc/tests/tsc-references/privateNameFieldCallExpression.2.minified.js index 1c3884972224..1b5331c29b48 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldCallExpression.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameFieldCallExpression.2.minified.js @@ -1,3 +1,4 @@ //// [privateNameFieldCallExpression.ts] import "@swc/helpers/src/_class_private_field_get.mjs"; import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNameFieldClassExpression.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldClassExpression.1.normal.js index af9c8c4b74dd..9d0eef8bb38c 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldClassExpression.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldClassExpression.1.normal.js @@ -1,21 +1,28 @@ //// [privateNameFieldClassExpression.ts] import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; -var _class, _Foo; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; var _foo = /*#__PURE__*/ new WeakMap(), _foo2 = /*#__PURE__*/ new WeakMap(); class B { constructor(){ _class_private_field_init(this, _foo, { writable: true, - value: (_class = class { - constructor(){ - console.log("hello"); - } - }, _class.test = 123, _class) + value: void 0 }); _class_private_field_init(this, _foo2, { writable: true, - value: (_Foo = class Foo { - }, _Foo.otherClass = 123, _Foo) + value: void 0 }); + var _class, _Foo; + _class_private_field_set(this, _foo, (_class = class { + constructor(){ + console.log("hello"); + } + }, (()=>{ + _class.test = 123; + })(), _class)); + _class_private_field_set(this, _foo2, (_Foo = class Foo { + }, (()=>{ + _Foo.otherClass = 123; + })(), _Foo)); } } diff --git a/crates/swc/tests/tsc-references/privateNameFieldClassExpression.2.minified.js b/crates/swc/tests/tsc-references/privateNameFieldClassExpression.2.minified.js index 7430ba0006c6..b02ed0ac7402 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldClassExpression.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameFieldClassExpression.2.minified.js @@ -1,2 +1,3 @@ //// [privateNameFieldClassExpression.ts] import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2015).1.normal.js index b9c1d769e88b..ae226d591790 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2015).1.normal.js @@ -1,5 +1,6 @@ //// [privateNameFieldDestructuredBinding.ts] import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_private_field_destructure from "@swc/helpers/src/_class_private_field_destructure.mjs"; var _field = /*#__PURE__*/ new WeakMap(); class A { @@ -23,8 +24,9 @@ class A { constructor(){ _class_private_field_init(this, _field, { writable: true, - value: 1 + value: void 0 }); + _class_private_field_set(this, _field, 1); this.otherObject = new A(); let y; ({ x: _class_private_field_destructure(this, _field).value , y } = this.testObject()); diff --git a/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2015).2.minified.js index d7593591e5a3..3f72896d52cf 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2015).2.minified.js @@ -1,3 +1,4 @@ //// [privateNameFieldDestructuredBinding.ts] import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; import "@swc/helpers/src/_class_private_field_destructure.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2022).1.normal.js index 709d003ac353..9d491045c839 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2022).1.normal.js @@ -1,7 +1,6 @@ //// [privateNameFieldDestructuredBinding.ts] class A { - #field = 1; - otherObject = new A(); + #field; testObject() { return { x: 10, @@ -15,6 +14,8 @@ class A { ]; } constructor(){ + this.#field = 1; + this.otherObject = new A(); let y; ({ x: this.#field , y } = this.testObject()); [this.#field, y] = this.testArray(); diff --git a/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2022).2.minified.js index 79337f90a16c..13c2e7932a2e 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameFieldDestructuredBinding(target=es2022).2.minified.js @@ -1,38 +1 @@ //// [privateNameFieldDestructuredBinding.ts] -class A { - #field = 1; - otherObject = new A(); - testObject() { - return { - x: 10, - y: 6 - }; - } - testArray() { - return [ - 10, - 11 - ]; - } - constructor(){ - let y; - ({ x: this.#field , y } = this.testObject()), [this.#field, y] = this.testArray(), ({ a: this.#field , b: [this.#field] } = { - a: 1, - b: [ - 2 - ] - }), [this.#field, [this.#field]] = [ - 1, - [ - 2 - ] - ], ({ a: this.#field = 1 , b: [this.#field = 1] } = { - b: [] - }), [this.#field = 2] = [], [this.otherObject.#field = 2] = []; - } - static test(_a) { - [_a.#field] = [ - 2 - ]; - } -} diff --git a/crates/swc/tests/tsc-references/privateNameFieldInitializer.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldInitializer.1.normal.js index 7e88e9889bee..6397495a450e 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldInitializer.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldInitializer.1.normal.js @@ -1,15 +1,17 @@ //// [privateNameFieldInitializer.ts] import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; var _field = /*#__PURE__*/ new WeakMap(), _uninitialized = /*#__PURE__*/ new WeakMap(); class A { constructor(){ _class_private_field_init(this, _field, { writable: true, - value: 10 + value: void 0 }); _class_private_field_init(this, _uninitialized, { writable: true, value: void 0 }); + _class_private_field_set(this, _field, 10); } } diff --git a/crates/swc/tests/tsc-references/privateNameFieldInitializer.2.minified.js b/crates/swc/tests/tsc-references/privateNameFieldInitializer.2.minified.js index 5f7182d984bf..7781349fa68f 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldInitializer.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameFieldInitializer.2.minified.js @@ -1,2 +1,3 @@ //// [privateNameFieldInitializer.ts] import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation.1.normal.js index c1c7406dd251..cd29c5171e6b 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation.1.normal.js @@ -34,8 +34,9 @@ class C { constructor(){ _class_private_field_init(this, _test, { writable: true, - value: 24 + value: void 0 }); + _class_private_field_set(this, _test, 24); _class_private_field_update(this, _test).value++; _class_private_field_update(this, _test).value--; ++_class_private_field_update(this, _test).value; diff --git a/crates/swc/tests/tsc-references/privateNameFieldsESNext.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldsESNext.1.normal.js index 927274b2e454..a3d280b7f456 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldsESNext.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldsESNext.1.normal.js @@ -1,8 +1,6 @@ //// [privateNameFieldsESNext.ts] class C { - a = 123; - #a = 10; - c = "hello"; + #a; #b; method() { console.log(this.#a); @@ -15,5 +13,11 @@ class C { console.log(this.#m); console.log(this.#x = "test"); } - #something = ()=>1234; + #something; + constructor(){ + this.a = 123; + this.#a = 10; + this.c = "hello"; + this.#something = ()=>1234; + } } diff --git a/crates/swc/tests/tsc-references/privateNameInLhsReceiverExpression.1.normal.js b/crates/swc/tests/tsc-references/privateNameInLhsReceiverExpression.1.normal.js index d4c303dc932b..783897474154 100644 --- a/crates/swc/tests/tsc-references/privateNameInLhsReceiverExpression.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameInLhsReceiverExpression.1.normal.js @@ -11,8 +11,9 @@ class Test { constructor(){ _class_private_field_init(this, _x, { writable: true, - value: 1 + value: void 0 }); + _class_private_field_set(this, _x, 1); this.s = "prop"; } })).s], _y, 1); @@ -20,8 +21,9 @@ class Test { constructor(){ _class_private_field_init(this, _x1, { writable: true, - value: 1 + value: void 0 }); + _class_private_field_set(this, _x1, 1); this.s = "prop"; } })).s], _y, _class_private_field_get(_obj__s, _y) + 1); @@ -29,7 +31,8 @@ class Test { constructor(){ _class_private_field_init(this, _y, { writable: true, - value: 123 + value: void 0 }); + _class_private_field_set(this, _y, 123); } } diff --git a/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit.1.normal.js b/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit.1.normal.js index 1e0fd3d39145..9926b20bb794 100644 --- a/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit.1.normal.js @@ -7,7 +7,9 @@ class C { _class_private_method_init(this, _method); } } -C.s = _class_private_method_get(_ref = new C(), _method, method).call(_ref); +(()=>{ + C.s = _class_private_method_get(_ref = new C(), _method, method).call(_ref); +})(); function method() { return 42; } diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression.1.normal.js index a9c22fbd7323..125b50525075 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression.1.normal.js @@ -16,10 +16,14 @@ var _foo = { console.log("hello"); new (_class_static_private_field_spec_get(B, B, _foo2))(); } - }, _class.test = 123, _class) + }, (()=>{ + _class.test = 123; + })(), _class) }; var _foo2 = { writable: true, value: (_Foo = class Foo { - }, _Foo.otherClass = 123, _Foo) + }, (()=>{ + _Foo.otherClass = 123; + })(), _Foo) }; diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding(target=es2022).1.normal.js index eb639582b2b2..635f619648cc 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding(target=es2022).1.normal.js @@ -1,7 +1,6 @@ //// [privateNameStaticFieldDestructuredBinding.ts] class A { static #field = 1; - otherClass = A; testObject() { return { x: 10, @@ -15,6 +14,7 @@ class A { ]; } constructor(){ + this.otherClass = A; let y; ({ x: A.#field , y } = this.testObject()); [A.#field, y] = this.testArray(); diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression.1.normal.js index cbafe6e5b791..ba5f717e1fc6 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression.1.normal.js @@ -22,7 +22,9 @@ class AA { return AA; } } -AA.x = 1; +(()=>{ + AA.x = 1; +})(); function method() { this.x = 10; } diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit.1.normal.js index 107dafc0bbc8..ca5257e73ea2 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit.1.normal.js @@ -2,7 +2,9 @@ import _class_static_private_method_get from "@swc/helpers/src/_class_static_private_method_get.mjs"; class C { } -C.s = _class_static_private_method_get(C, C, method).call(C); +(()=>{ + C.s = _class_static_private_method_get(C, C, method).call(C); +})(); function method() { return 42; } diff --git a/crates/swc/tests/tsc-references/privateNameUnused.1.normal.js b/crates/swc/tests/tsc-references/privateNameUnused.1.normal.js index 3c08ba1edd97..110f54607648 100644 --- a/crates/swc/tests/tsc-references/privateNameUnused.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameUnused.1.normal.js @@ -1,6 +1,7 @@ //// [privateNameUnused.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_private_method_get from "@swc/helpers/src/_class_private_method_get.mjs"; import _class_private_method_init from "@swc/helpers/src/_class_private_method_init.mjs"; var _used = /*#__PURE__*/ new WeakMap(), _unused = /*#__PURE__*/ new WeakMap(); @@ -8,12 +9,14 @@ export class A { constructor(){ _class_private_field_init(this, _used, { writable: true, - value: "used" + value: void 0 }); _class_private_field_init(this, _unused, { writable: true, - value: "unused" + value: void 0 }); + _class_private_field_set(this, _used, "used"); + _class_private_field_set(this, _unused, "unused"); console.log(_class_private_field_get(this, _used)); } } diff --git a/crates/swc/tests/tsc-references/privateNameUnused.2.minified.js b/crates/swc/tests/tsc-references/privateNameUnused.2.minified.js index 8979312dacff..b26518a82c03 100644 --- a/crates/swc/tests/tsc-references/privateNameUnused.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameUnused.2.minified.js @@ -1,6 +1,7 @@ //// [privateNameUnused.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_private_method_get from "@swc/helpers/src/_class_private_method_get.mjs"; import _class_private_method_init from "@swc/helpers/src/_class_private_method_init.mjs"; var _used = new WeakMap(), _unused = new WeakMap(); @@ -8,11 +9,11 @@ export class A { constructor(){ _class_private_field_init(this, _used, { writable: !0, - value: "used" + value: void 0 }), _class_private_field_init(this, _unused, { writable: !0, - value: "unused" - }), console.log(_class_private_field_get(this, _used)); + value: void 0 + }), _class_private_field_set(this, _used, "used"), _class_private_field_set(this, _unused, "unused"), console.log(_class_private_field_get(this, _used)); } } var _used1 = new WeakSet(), _unused1 = new WeakSet(); diff --git a/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2020).1.normal.js b/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2020).1.normal.js index 8518000f4669..05947de3336c 100644 --- a/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2020).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2020).1.normal.js @@ -1,58 +1,70 @@ //// [privateNameWhenNotUseDefineForClassFieldsInEsNext.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; -var _foo, _Inner, _foo1; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; var _prop = /*#__PURE__*/ new WeakMap(), _ref; class TestWithStatics { constructor(){ _class_private_field_init(this, _prop, { writable: true, - value: 0 + value: void 0 }); + _class_private_field_set(this, _prop, 0); } } -TestWithStatics.dd = _class_private_field_get(_ref = new TestWithStatics(), _prop) // OK -; -TestWithStatics["X_ z_ zz"] = (_foo = /*#__PURE__*/ new WeakMap(), _Inner = class Inner { - m() { - var _ref; - _class_private_field_get(_ref = new TestWithStatics(), _prop // OK - ); - } - static M() { - return class { +(()=>{ + TestWithStatics.dd = _class_private_field_get(_ref = new TestWithStatics(), _prop) // OK + ; +})(); +(()=>{ + var _foo, _Inner; + TestWithStatics["X_ z_ zz"] = (_foo = /*#__PURE__*/ new WeakMap(), _Inner = class Inner { + m() { + var _ref; + _class_private_field_get(_ref = new TestWithStatics(), _prop // OK + ); + } + static M() { + return class { + m() { + var _ref, _ref1; + _class_private_field_get(_ref = new TestWithStatics(), _prop // OK + ); + _class_private_field_get(_ref1 = new Inner(), _foo); // OK + } + }; + } + constructor(){ + _class_private_field_init(this, _foo, { + writable: true, + value: void 0 + }); + _class_private_field_set(this, _foo, 10); + } + }, (()=>{ + _Inner.C = class InnerInner { m() { var _ref, _ref1; _class_private_field_get(_ref = new TestWithStatics(), _prop // OK ); - _class_private_field_get(_ref1 = new Inner(), _foo); // OK + _class_private_field_get(_ref1 = new _Inner(), _foo); // OK } }; - } - constructor(){ - _class_private_field_init(this, _foo, { - writable: true, - value: 10 - }); - } -}, _Inner.C = class InnerInner { - m() { - var _ref, _ref1; - _class_private_field_get(_ref = new TestWithStatics(), _prop // OK - ); - _class_private_field_get(_ref1 = new _Inner(), _foo); // OK - } -}, _Inner); -var _prop1 = /*#__PURE__*/ new WeakMap(), _ref1; + })(), _Inner); +})(); +var _prop1 = /*#__PURE__*/ new WeakMap(); class TestNonStatics { constructor(){ + var _ref; _class_private_field_init(this, _prop1, { writable: true, - value: 0 + value: void 0 }); - this.dd = _class_private_field_get(_ref1 = new TestNonStatics(), _prop1) // OK + var _foo; + _class_private_field_set(this, _prop1, 0); + this.dd = _class_private_field_get(_ref = new TestNonStatics(), _prop1) // OK ; - this["X_ z_ zz"] = (_foo1 = /*#__PURE__*/ new WeakMap(), class Inner { + this["X_ z_ zz"] = (_foo = /*#__PURE__*/ new WeakMap(), class Inner { m() { var _ref; _class_private_field_get(_ref = new TestNonStatics(), _prop1 // Ok @@ -64,21 +76,22 @@ class TestNonStatics { var _ref, _ref1; _class_private_field_get(_ref = new TestNonStatics(), _prop1 // OK ); - _class_private_field_get(_ref1 = new Inner(), _foo1); // OK + _class_private_field_get(_ref1 = new Inner(), _foo); // OK } }; } constructor(){ - _class_private_field_init(this, _foo1, { + _class_private_field_init(this, _foo, { writable: true, - value: 10 + value: void 0 }); + _class_private_field_set(this, _foo, 10); this.C = class InnerInner { m() { var _ref, _ref1; _class_private_field_get(_ref = new TestNonStatics(), _prop1 // Ok ); - _class_private_field_get(_ref1 = new Inner(), _foo1); // Ok + _class_private_field_get(_ref1 = new Inner(), _foo); // Ok } }; } diff --git a/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2020).2.minified.js b/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2020).2.minified.js index 53d18e94f030..45981bd41372 100644 --- a/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2020).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2020).2.minified.js @@ -1,34 +1,38 @@ //// [privateNameWhenNotUseDefineForClassFieldsInEsNext.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; -var _foo, _Inner, _prop = new WeakMap(); +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; +var _prop = new WeakMap(); class TestWithStatics { constructor(){ _class_private_field_init(this, _prop, { writable: !0, - value: 0 - }); + value: void 0 + }), _class_private_field_set(this, _prop, 0); } } -TestWithStatics.dd = _class_private_field_get(new TestWithStatics(), _prop), TestWithStatics["X_ z_ zz"] = (_foo = new WeakMap(), (_Inner = class Inner { - m() { - _class_private_field_get(new TestWithStatics(), _prop); - } - static M() { - return class { - m() { - _class_private_field_get(new TestWithStatics(), _prop), _class_private_field_get(new Inner(), _foo); - } - }; - } - constructor(){ - _class_private_field_init(this, _foo, { - writable: !0, - value: 10 - }); - } -}).C = class { - m() { - _class_private_field_get(new TestWithStatics(), _prop), _class_private_field_get(new _Inner(), _foo); - } -}, _Inner); +TestWithStatics.dd = _class_private_field_get(new TestWithStatics(), _prop), (()=>{ + var _foo, _Inner; + TestWithStatics["X_ z_ zz"] = (_foo = new WeakMap(), (_Inner = class Inner { + m() { + _class_private_field_get(new TestWithStatics(), _prop); + } + static M() { + return class { + m() { + _class_private_field_get(new TestWithStatics(), _prop), _class_private_field_get(new Inner(), _foo); + } + }; + } + constructor(){ + _class_private_field_init(this, _foo, { + writable: !0, + value: void 0 + }), _class_private_field_set(this, _foo, 10); + } + }).C = class { + m() { + _class_private_field_get(new TestWithStatics(), _prop), _class_private_field_get(new _Inner(), _foo); + } + }, _Inner); +})(); diff --git a/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2022).1.normal.js index 102d93bfad7c..0263ed9ebb6e 100644 --- a/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2022).1.normal.js @@ -1,55 +1,75 @@ //// [privateNameWhenNotUseDefineForClassFieldsInEsNext.ts] class TestWithStatics { - #prop = 0; - static dd = new TestWithStatics().#prop; - static ["X_ z_ zz"] = class Inner { - #foo = 10; - m() { - new TestWithStatics().#prop // OK - ; - } - static C = class InnerInner { + #prop; + static{ + this.dd = new TestWithStatics().#prop // OK + ; + } + static{ + this["X_ z_ zz"] = class Inner { + #foo; m() { new TestWithStatics().#prop // OK ; - new Inner().#foo; // OK + } + static{ + this.C = class InnerInner { + m() { + new TestWithStatics().#prop // OK + ; + new Inner().#foo; // OK + } + }; + } + static M() { + return class { + m() { + new TestWithStatics().#prop // OK + ; + new Inner().#foo; // OK + } + }; + } + constructor(){ + this.#foo = 10; } }; - static M() { - return class { - m() { - new TestWithStatics().#prop // OK - ; - new Inner().#foo; // OK - } - }; - } - }; + } + constructor(){ + this.#prop = 0; + } } class TestNonStatics { - #prop = 0; - dd = new TestNonStatics().#prop; - ["X_ z_ zz"] = class Inner { - #foo = 10; - m() { - new TestNonStatics().#prop // Ok - ; - } - C = class InnerInner { + #prop; + constructor(){ + this.#prop = 0; + this.dd = new TestNonStatics().#prop // OK + ; + this["X_ z_ zz"] = class Inner { + #foo; m() { new TestNonStatics().#prop // Ok ; - new Inner().#foo; // Ok + } + static M() { + return class { + m() { + new TestNonStatics().#prop // OK + ; + new Inner().#foo; // OK + } + }; + } + constructor(){ + this.#foo = 10; + this.C = class InnerInner { + m() { + new TestNonStatics().#prop // Ok + ; + new Inner().#foo; // Ok + } + }; } }; - static M() { - return class { - m() { - new TestNonStatics().#prop // OK - ; - new Inner().#foo; // OK - } - }; - } - }; + } } diff --git a/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2022).2.minified.js index d3f304e1003e..ed621b00894b 100644 --- a/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameWhenNotUseDefineForClassFieldsInEsNext(target=es2022).2.minified.js @@ -1,45 +1,35 @@ //// [privateNameWhenNotUseDefineForClassFieldsInEsNext.ts] class TestWithStatics { - #prop = 0; - static dd = new TestWithStatics().#prop; - static "X_ z_ zz" = class Inner { - #foo = 10; - m() { - new TestWithStatics().#prop; - } - static C = class { + #prop; + static{ + this.dd = new TestWithStatics().#prop; + } + static{ + this["X_ z_ zz"] = class Inner { + #foo; m() { - new TestWithStatics().#prop, new Inner().#foo; + new TestWithStatics().#prop; } - }; - static M() { - return class { - m() { - new TestWithStatics().#prop, new Inner().#foo; - } - }; - } - }; -} -class TestNonStatics { - #prop = 0; - dd = new TestNonStatics().#prop; - "X_ z_ zz" = class Inner { - #foo = 10; - m() { - new TestNonStatics().#prop; - } - C = class { - m() { - new TestNonStatics().#prop, new Inner().#foo; + static{ + this.C = class { + m() { + new TestWithStatics().#prop, new Inner().#foo; + } + }; + } + static M() { + return class { + m() { + new TestWithStatics().#prop, new Inner().#foo; + } + }; + } + constructor(){ + this.#foo = 10; } }; - static M() { - return class { - m() { - new TestNonStatics().#prop, new Inner().#foo; - } - }; - } - }; + } + constructor(){ + this.#prop = 0; + } } diff --git a/crates/swc/tests/tsc-references/privateNamesAndkeyof.1.normal.js b/crates/swc/tests/tsc-references/privateNamesAndkeyof.1.normal.js index 72014d07a22f..d923b57a542a 100644 --- a/crates/swc/tests/tsc-references/privateNamesAndkeyof.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNamesAndkeyof.1.normal.js @@ -1,5 +1,6 @@ //// [privateNamesAndkeyof.ts] import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_private_method_init from "@swc/helpers/src/_class_private_method_init.mjs"; var _fooField = /*#__PURE__*/ new WeakMap(), _fooMethod = /*#__PURE__*/ new WeakSet(), _fooProp = /*#__PURE__*/ new WeakMap(); class A { @@ -11,8 +12,9 @@ class A { }); _class_private_field_init(this, _fooField, { writable: true, - value: 3 + value: void 0 }); + _class_private_field_set(this, _fooField, 3); this.bar = 3; this.baz = 3; } diff --git a/crates/swc/tests/tsc-references/privateNamesAndkeyof.2.minified.js b/crates/swc/tests/tsc-references/privateNamesAndkeyof.2.minified.js index 1800c89978d9..3bb21420ab7e 100644 --- a/crates/swc/tests/tsc-references/privateNamesAndkeyof.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNamesAndkeyof.2.minified.js @@ -1,3 +1,4 @@ //// [privateNamesAndkeyof.ts] import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; import "@swc/helpers/src/_class_private_method_init.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNamesAssertion.1.normal.js b/crates/swc/tests/tsc-references/privateNamesAssertion.1.normal.js index 0b1392a2b327..d30b6d790658 100644 --- a/crates/swc/tests/tsc-references/privateNamesAssertion.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNamesAssertion.1.normal.js @@ -1,14 +1,17 @@ //// [privateNamesAssertion.ts] class Foo { - #p1 = (v)=>{ - if (typeof v !== "string") { - throw new Error(); - } - }; + #p1; m1(v) { this.#p1(v); v; } + constructor(){ + this.#p1 = (v)=>{ + if (typeof v !== "string") { + throw new Error(); + } + }; + } } class Foo2 { #p1(v) { diff --git a/crates/swc/tests/tsc-references/privateNamesConstructorChain-1.1.normal.js b/crates/swc/tests/tsc-references/privateNamesConstructorChain-1.1.normal.js index f4defd1b4b60..8c168e730451 100644 --- a/crates/swc/tests/tsc-references/privateNamesConstructorChain-1.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNamesConstructorChain-1.1.normal.js @@ -1,6 +1,7 @@ //// [privateNamesConstructorChain-1.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_static_private_field_spec_get from "@swc/helpers/src/_class_static_private_field_spec_get.mjs"; var _foo = /*#__PURE__*/ new WeakMap(); class Parent { @@ -12,8 +13,9 @@ class Parent { constructor(){ _class_private_field_init(this, _foo, { writable: true, - value: 3 + value: void 0 }); + _class_private_field_set(this, _foo, 3); } } var _bar = { @@ -26,13 +28,13 @@ class Child extends Parent { super(...args); _class_private_field_init(this, _foo1, { writable: true, - value: "foo" - }) // OK (Child's #foo does not conflict, as `Parent`'s `#foo` is not accessible) - ; + value: void 0 // OK (Child's #foo does not conflict, as `Parent`'s `#foo` is not accessible) + }); _class_private_field_init(this, _bar1, { writable: true, - value: "bar" - }) // OK - ; + value: void 0 // OK + }); + _class_private_field_set(this, _foo1, "foo"); + _class_private_field_set(this, _bar1, "bar"); } } diff --git a/crates/swc/tests/tsc-references/privateNamesConstructorChain-1.2.minified.js b/crates/swc/tests/tsc-references/privateNamesConstructorChain-1.2.minified.js index f1f125496199..374a506a2323 100644 --- a/crates/swc/tests/tsc-references/privateNamesConstructorChain-1.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNamesConstructorChain-1.2.minified.js @@ -1,4 +1,5 @@ //// [privateNamesConstructorChain-1.ts] import "@swc/helpers/src/_class_private_field_get.mjs"; import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; import "@swc/helpers/src/_class_static_private_field_spec_get.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNamesConstructorChain-2.1.normal.js b/crates/swc/tests/tsc-references/privateNamesConstructorChain-2.1.normal.js index 9224a5b7f61c..b92a8dd1195c 100644 --- a/crates/swc/tests/tsc-references/privateNamesConstructorChain-2.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNamesConstructorChain-2.1.normal.js @@ -1,6 +1,7 @@ //// [privateNamesConstructorChain-2.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_static_private_field_spec_get from "@swc/helpers/src/_class_static_private_field_spec_get.mjs"; var _foo = /*#__PURE__*/ new WeakMap(); class Parent { @@ -12,8 +13,9 @@ class Parent { constructor(){ _class_private_field_init(this, _foo, { writable: true, - value: 3 + value: void 0 }); + _class_private_field_set(this, _foo, 3); } } var _bar = { @@ -26,14 +28,14 @@ class Child extends Parent { super(...args); _class_private_field_init(this, _foo1, { writable: true, - value: "foo" - }) // OK (Child's #foo does not conflict, as `Parent`'s `#foo` is not accessible) - ; + value: void 0 // OK (Child's #foo does not conflict, as `Parent`'s `#foo` is not accessible) + }); _class_private_field_init(this, _bar1, { writable: true, - value: "bar" - }) // OK - ; + value: void 0 // OK + }); + _class_private_field_set(this, _foo1, "foo"); + _class_private_field_set(this, _bar1, "bar"); } } new Parent().accessChildProps(); diff --git a/crates/swc/tests/tsc-references/privateNamesConstructorChain-2.2.minified.js b/crates/swc/tests/tsc-references/privateNamesConstructorChain-2.2.minified.js index 81b637cdf19d..96dbd161a0a2 100644 --- a/crates/swc/tests/tsc-references/privateNamesConstructorChain-2.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNamesConstructorChain-2.2.minified.js @@ -1,6 +1,7 @@ //// [privateNamesConstructorChain-2.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_static_private_field_spec_get from "@swc/helpers/src/_class_static_private_field_spec_get.mjs"; var _foo = new WeakMap(); class Parent { @@ -10,8 +11,8 @@ class Parent { constructor(){ _class_private_field_init(this, _foo, { writable: !0, - value: 3 - }); + value: void 0 + }), _class_private_field_set(this, _foo, 3); } } var _bar = { @@ -22,11 +23,11 @@ class Child extends Parent { constructor(...args){ super(...args), _class_private_field_init(this, _foo1, { writable: !0, - value: "foo" + value: void 0 }), _class_private_field_init(this, _bar1, { writable: !0, - value: "bar" - }); + value: void 0 + }), _class_private_field_set(this, _foo1, "foo"), _class_private_field_set(this, _bar1, "bar"); } } new Parent().accessChildProps(); diff --git a/crates/swc/tests/tsc-references/privateNamesIncompatibleModifiersJs.1.normal.js b/crates/swc/tests/tsc-references/privateNamesIncompatibleModifiersJs.1.normal.js index 84a839a2818f..7e12da454bb4 100644 --- a/crates/swc/tests/tsc-references/privateNamesIncompatibleModifiersJs.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNamesIncompatibleModifiersJs.1.normal.js @@ -1,5 +1,6 @@ //// [privateNamesIncompatibleModifiersJs.js] import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_private_method_init from "@swc/helpers/src/_class_private_method_init.mjs"; var /** * @public @@ -45,16 +46,19 @@ class A { }); _class_private_field_init(this, _a, { writable: true, - value: 1 + value: void 0 }); _class_private_field_init(this, _b, { writable: true, - value: 1 + value: void 0 }); _class_private_field_init(this, _c, { writable: true, - value: 1 + value: void 0 }); + _class_private_field_set(this, _a, 1); + _class_private_field_set(this, _b, 1); + _class_private_field_set(this, _c, 1); } } function aMethod() { diff --git a/crates/swc/tests/tsc-references/privateNamesIncompatibleModifiersJs.2.minified.js b/crates/swc/tests/tsc-references/privateNamesIncompatibleModifiersJs.2.minified.js index 23b20dbe87f1..07a781082660 100644 --- a/crates/swc/tests/tsc-references/privateNamesIncompatibleModifiersJs.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNamesIncompatibleModifiersJs.2.minified.js @@ -1,3 +1,4 @@ //// [privateNamesIncompatibleModifiersJs.js] import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; import "@swc/helpers/src/_class_private_method_init.mjs"; diff --git a/crates/swc/tests/tsc-references/privateNamesUseBeforeDef.1.normal.js b/crates/swc/tests/tsc-references/privateNamesUseBeforeDef.1.normal.js index a90adc78876c..f7175d8bfb74 100644 --- a/crates/swc/tests/tsc-references/privateNamesUseBeforeDef.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNamesUseBeforeDef.1.normal.js @@ -1,6 +1,7 @@ //// [privateNamesUseBeforeDef.ts] import _class_private_field_get from "@swc/helpers/src/_class_private_field_get.mjs"; import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; +import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _class_private_method_get from "@swc/helpers/src/_class_private_method_get.mjs"; import _class_private_method_init from "@swc/helpers/src/_class_private_method_init.mjs"; var _foo = /*#__PURE__*/ new WeakMap(), _bar = /*#__PURE__*/ new WeakMap(); @@ -8,13 +9,14 @@ class A { constructor(){ _class_private_field_init(this, _foo, { writable: true, - value: _class_private_field_get(this, _bar) - }) // Error - ; + value: void 0 // Error + }); _class_private_field_init(this, _bar, { writable: true, - value: 3 + value: void 0 }); + _class_private_field_set(this, _foo, _class_private_field_get(this, _bar)); + _class_private_field_set(this, _bar, 3); } } var _foo1 = /*#__PURE__*/ new WeakMap(), _bar1 = /*#__PURE__*/ new WeakSet(); @@ -23,9 +25,9 @@ class A2 { _class_private_method_init(this, _bar1); _class_private_field_init(this, _foo1, { writable: true, - value: _class_private_method_get(this, _bar1, bar).call(this) - }) // No Error - ; + value: void 0 // No Error + }); + _class_private_field_set(this, _foo1, _class_private_method_get(this, _bar1, bar).call(this)); } } function bar() { @@ -40,9 +42,9 @@ class A3 { }); _class_private_field_init(this, _foo2, { writable: true, - value: _class_private_field_get(this, _bar2) - }) // No Error - ; + value: void 0 // No Error + }); + _class_private_field_set(this, _foo2, _class_private_field_get(this, _bar2)); } } function get_bar() { @@ -53,12 +55,13 @@ class B { constructor(){ _class_private_field_init(this, _foo3, { writable: true, - value: _class_private_field_get(this, _bar3) - }) // Error - ; + value: void 0 // Error + }); _class_private_field_init(this, _bar3, { writable: true, - value: _class_private_field_get(this, _foo3) + value: void 0 }); + _class_private_field_set(this, _foo3, _class_private_field_get(this, _bar3)); + _class_private_field_set(this, _bar3, _class_private_field_get(this, _foo3)); } } diff --git a/crates/swc/tests/tsc-references/privateNamesUseBeforeDef.2.minified.js b/crates/swc/tests/tsc-references/privateNamesUseBeforeDef.2.minified.js index 746c64efc14c..176e815cb23b 100644 --- a/crates/swc/tests/tsc-references/privateNamesUseBeforeDef.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNamesUseBeforeDef.2.minified.js @@ -1,5 +1,6 @@ //// [privateNamesUseBeforeDef.ts] import "@swc/helpers/src/_class_private_field_get.mjs"; import "@swc/helpers/src/_class_private_field_init.mjs"; +import "@swc/helpers/src/_class_private_field_set.mjs"; import "@swc/helpers/src/_class_private_method_get.mjs"; import "@swc/helpers/src/_class_private_method_init.mjs"; diff --git a/crates/swc/tests/tsc-references/privateStaticMemberAccessibility.1.normal.js b/crates/swc/tests/tsc-references/privateStaticMemberAccessibility.1.normal.js index 98362d084789..bbffec8ca5f4 100644 --- a/crates/swc/tests/tsc-references/privateStaticMemberAccessibility.1.normal.js +++ b/crates/swc/tests/tsc-references/privateStaticMemberAccessibility.1.normal.js @@ -22,5 +22,7 @@ var Derived = /*#__PURE__*/ function(Base1) { } return Derived; }(Base); -Derived.bar = Base.foo // error -; +(function() { + Derived.bar = Base.foo // error + ; +})(); diff --git a/crates/swc/tests/tsc-references/propertyOverridesAccessors5.1.normal.js b/crates/swc/tests/tsc-references/propertyOverridesAccessors5.1.normal.js index fc564cb6b2b1..480dfbe3ac12 100644 --- a/crates/swc/tests/tsc-references/propertyOverridesAccessors5.1.normal.js +++ b/crates/swc/tests/tsc-references/propertyOverridesAccessors5.1.normal.js @@ -5,9 +5,9 @@ class A { } } class B extends A { + p; constructor(p){ super(); this.p = p; } - p; } diff --git a/crates/swc/tests/tsc-references/redefinedPararameterProperty.1.normal.js b/crates/swc/tests/tsc-references/redefinedPararameterProperty.1.normal.js index fb30f407d5af..aa3879284148 100644 --- a/crates/swc/tests/tsc-references/redefinedPararameterProperty.1.normal.js +++ b/crates/swc/tests/tsc-references/redefinedPararameterProperty.1.normal.js @@ -3,11 +3,11 @@ class Base { a = 1; } class Derived extends Base { + a; b; constructor(a){ super(); this.a = a; this.b = this.a /*undefined*/ ; } - a; } diff --git a/crates/swc/tests/tsc-references/spreadMethods.1.normal.js b/crates/swc/tests/tsc-references/spreadMethods.1.normal.js index 93fe5320dda8..1ddc6cbb44e6 100644 --- a/crates/swc/tests/tsc-references/spreadMethods.1.normal.js +++ b/crates/swc/tests/tsc-references/spreadMethods.1.normal.js @@ -1,10 +1,12 @@ //// [spreadMethods.ts] class K { - p = 12; m() {} get g() { return 0; } + constructor(){ + this.p = 12; + } } let k = new K(); let sk = { diff --git a/crates/swc/tests/tsc-references/spreadMethods.2.minified.js b/crates/swc/tests/tsc-references/spreadMethods.2.minified.js index bd74915ce770..8002927ab391 100644 --- a/crates/swc/tests/tsc-references/spreadMethods.2.minified.js +++ b/crates/swc/tests/tsc-references/spreadMethods.2.minified.js @@ -1,10 +1,12 @@ //// [spreadMethods.ts] let k = new class { - p = 12; m() {} get g() { return 0; } + constructor(){ + this.p = 12; + } }(), sk = { ...k }, ssk = { diff --git a/crates/swc/tests/tsc-references/staticIndexSignature7.1.normal.js b/crates/swc/tests/tsc-references/staticIndexSignature7.1.normal.js index 5f3714573371..69ed290532e5 100644 --- a/crates/swc/tests/tsc-references/staticIndexSignature7.1.normal.js +++ b/crates/swc/tests/tsc-references/staticIndexSignature7.1.normal.js @@ -4,8 +4,10 @@ var X = function X() { "use strict"; _class_call_check(this, X); }; -X.x = 12 // Should error, incompatible with index signature -; +(function() { + X.x = 12 // Should error, incompatible with index signature + ; +})(); var Y = /*#__PURE__*/ function() { "use strict"; function Y() { diff --git a/crates/swc/tests/tsc-references/staticMemberInitialization.1.normal.js b/crates/swc/tests/tsc-references/staticMemberInitialization.1.normal.js index 521dd530643e..1d1867a4baaf 100644 --- a/crates/swc/tests/tsc-references/staticMemberInitialization.1.normal.js +++ b/crates/swc/tests/tsc-references/staticMemberInitialization.1.normal.js @@ -4,6 +4,8 @@ var C = function C() { "use strict"; _class_call_check(this, C); }; -C.x = 1; +(function() { + C.x = 1; +})(); var c = new C(); var r = C.x; diff --git a/crates/swc/tests/tsc-references/strictPropertyInitialization.1.normal.js b/crates/swc/tests/tsc-references/strictPropertyInitialization.1.normal.js index 32ead08c50ca..49024e0c83ce 100644 --- a/crates/swc/tests/tsc-references/strictPropertyInitialization.1.normal.js +++ b/crates/swc/tests/tsc-references/strictPropertyInitialization.1.normal.js @@ -31,21 +31,24 @@ var _d = /*#__PURE__*/ new WeakMap(), _e = /*#__PURE__*/ new WeakMap(), _f1 = /* // Initializer satisfies strict initialization check class C4 { constructor(){ - this.a = 0; - this.b = 0; - this.c = "abc"; _class_private_field_init(this, _d, { writable: true, - value: 0 + value: void 0 }); _class_private_field_init(this, _e, { writable: true, - value: 0 + value: void 0 }); _class_private_field_init(this, _f1, { writable: true, - value: "abc" + value: void 0 }); + this.a = 0; + this.b = 0; + this.c = "abc"; + _class_private_field_set(this, _d, 0); + _class_private_field_set(this, _e, 0); + _class_private_field_set(this, _f1, "abc"); } } var _b = /*#__PURE__*/ new WeakMap(); @@ -140,8 +143,12 @@ var E; E["A"] = "A"; E["B"] = "B"; })(E || (E = {})); +let prop; class C13 { constructor(){ this[E.A] = 1; } } +(()=>{ + prop = E.A; +})(); diff --git a/crates/swc/tests/tsc-references/strictPropertyInitialization.2.minified.js b/crates/swc/tests/tsc-references/strictPropertyInitialization.2.minified.js index 471db9891cab..69ce0a444032 100644 --- a/crates/swc/tests/tsc-references/strictPropertyInitialization.2.minified.js +++ b/crates/swc/tests/tsc-references/strictPropertyInitialization.2.minified.js @@ -5,4 +5,4 @@ import "@swc/helpers/src/_class_private_field_init.mjs"; import "@swc/helpers/src/_class_private_field_set.mjs"; Symbol(), function(E) { E.A = "A", E.B = "B"; -}(E || (E = {})); +}(E || (E = {})), E.A; diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2015).1.normal.js index ae18c26c20b7..5a62307b0c7c 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2015).1.normal.js @@ -11,60 +11,62 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = [ - (()=>{ - var Reflect; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - var { Reflect } = { - Reflect: null - }; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - var [Reflect] = [ - null - ]; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - class Reflect { - } // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - function Reflect() {} // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - (class Reflect { - }); // no collision - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - (function Reflect() {}); // no collision - _get(_get_prototype_of(C), "w", C).call(C); - })() -]; +(()=>{ + C._ = [ + (()=>{ + var Reflect; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + var { Reflect } = { + Reflect: null + }; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + var [Reflect] = [ + null + ]; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + class Reflect { + } // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + function Reflect() {} // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + (class Reflect { + }); // no collision + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + (function Reflect() {}); // no collision + _get(_get_prototype_of(C), "w", C).call(C); + })() + ]; +})(); (()=>{ var { Reflect } = { Reflect: null @@ -126,7 +128,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; var Reflect = null; // collision (es2015-es2021 only) class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticField2.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -136,7 +140,9 @@ var { Reflect } = { }; // collision (es2015-es2021 only) class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticField3.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -146,7 +152,9 @@ var [Reflect] = [ ]; // collision (es2015-es2021 only) class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticBlock1.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -189,7 +197,9 @@ class Reflect { } // collision (es2015-es2021 only) class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classDeclInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -208,7 +218,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; function Reflect() {} // collision (es2015-es2021 only) class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [funcDeclInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -225,7 +237,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [valueNamespaceInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -244,7 +258,9 @@ var Reflect// collision (es2015-es2021 only) (function(Reflect) {})(Reflect || (Reflect = {})); class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [enumInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -266,7 +282,9 @@ var Reflect// collision (es2015-es2021 only) (function(Reflect) {})(Reflect || (Reflect = {})); class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [constEnumInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -285,7 +303,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namespaceImportInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -301,7 +321,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -317,7 +339,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfInterfaceInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -333,7 +357,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -349,7 +375,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfConstEnumInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -365,7 +393,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyNamedImportInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -381,7 +411,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [defaultImportInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -397,7 +429,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyDefaultImportInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -413,7 +447,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -429,7 +465,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [interfaceInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -445,7 +483,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [uninstantiatedNamespaceInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -463,7 +503,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; }); // no collision class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classExprInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -484,7 +526,9 @@ _Reflect = class Reflect { }, (()=>{ class C extends B { } - C._ = _get(_get_prototype_of(C), "w", C).call(C); + (()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); + })(); })(), _Reflect; export { }; //// [inContainingClassExprStaticBlock.ts] @@ -506,7 +550,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; (function Reflect() {}); // no collision class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [funcExprInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -524,7 +570,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; (function Reflect() { class C extends B { } - C._ = _get(_get_prototype_of(C), "w", C).call(C); + (()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); + })(); }); export { }; //// [inContainingFuncExprStaticBlock.ts] diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2021).1.normal.js b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2021).1.normal.js index ae18c26c20b7..5a62307b0c7c 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2021).1.normal.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2021).1.normal.js @@ -11,60 +11,62 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = [ - (()=>{ - var Reflect; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - var { Reflect } = { - Reflect: null - }; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - var [Reflect] = [ - null - ]; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - class Reflect { - } // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - function Reflect() {} // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - (class Reflect { - }); // no collision - _get(_get_prototype_of(C), "w", C).call(C); - })(), - (()=>{ - (function Reflect() {}); // no collision - _get(_get_prototype_of(C), "w", C).call(C); - })() -]; +(()=>{ + C._ = [ + (()=>{ + var Reflect; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + var { Reflect } = { + Reflect: null + }; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + var [Reflect] = [ + null + ]; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + class Reflect { + } // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + function Reflect() {} // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + (class Reflect { + }); // no collision + _get(_get_prototype_of(C), "w", C).call(C); + })(), + (()=>{ + (function Reflect() {}); // no collision + _get(_get_prototype_of(C), "w", C).call(C); + })() + ]; +})(); (()=>{ var { Reflect } = { Reflect: null @@ -126,7 +128,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; var Reflect = null; // collision (es2015-es2021 only) class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticField2.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -136,7 +140,9 @@ var { Reflect } = { }; // collision (es2015-es2021 only) class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticField3.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -146,7 +152,9 @@ var [Reflect] = [ ]; // collision (es2015-es2021 only) class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticBlock1.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -189,7 +197,9 @@ class Reflect { } // collision (es2015-es2021 only) class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classDeclInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -208,7 +218,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; function Reflect() {} // collision (es2015-es2021 only) class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [funcDeclInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -225,7 +237,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [valueNamespaceInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -244,7 +258,9 @@ var Reflect// collision (es2015-es2021 only) (function(Reflect) {})(Reflect || (Reflect = {})); class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [enumInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -266,7 +282,9 @@ var Reflect// collision (es2015-es2021 only) (function(Reflect) {})(Reflect || (Reflect = {})); class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [constEnumInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -285,7 +303,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namespaceImportInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -301,7 +321,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -317,7 +339,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfInterfaceInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -333,7 +357,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -349,7 +375,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfConstEnumInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -365,7 +393,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyNamedImportInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -381,7 +411,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [defaultImportInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -397,7 +429,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyDefaultImportInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -413,7 +447,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -429,7 +465,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [interfaceInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -445,7 +483,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [uninstantiatedNamespaceInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -463,7 +503,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; }); // no collision class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classExprInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -484,7 +526,9 @@ _Reflect = class Reflect { }, (()=>{ class C extends B { } - C._ = _get(_get_prototype_of(C), "w", C).call(C); + (()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); + })(); })(), _Reflect; export { }; //// [inContainingClassExprStaticBlock.ts] @@ -506,7 +550,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; (function Reflect() {}); // no collision class C extends B { } -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [funcExprInContainingScopeStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -524,7 +570,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; (function Reflect() { class C extends B { } - C._ = _get(_get_prototype_of(C), "w", C).call(C); + (()=>{ + C._ = _get(_get_prototype_of(C), "w", C).call(C); + })(); }); export { }; //// [inContainingFuncExprStaticBlock.ts] diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2022).1.normal.js index a1d179e82f90..f8b125ca005f 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2022).1.normal.js @@ -8,60 +8,62 @@ export default class { } //// [locals.ts] class C extends B { - static _ = [ - (()=>{ - var Reflect; // collision (es2015-es2021 only) - super.w(); - })(), - (()=>{ - var { Reflect } = { - Reflect: null - }; // collision (es2015-es2021 only) - super.w(); - })(), - (()=>{ - var [Reflect] = [ - null - ]; // collision (es2015-es2021 only) - super.w(); - })(), - (()=>{ - class Reflect { - } // collision (es2015-es2021 only) - super.w(); - })(), - (()=>{ - function Reflect() {} // collision (es2015-es2021 only) - super.w(); - })(), - (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - super.w(); - })(), - (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - super.w(); - })(), - (()=>{ - super.w(); - })(), - (()=>{ - super.w(); - })(), - (()=>{ - (class Reflect { - }); // no collision - super.w(); - })(), - (()=>{ - (function Reflect() {}); // no collision - super.w(); - })() - ]; + static{ + this._ = [ + (()=>{ + var Reflect; // collision (es2015-es2021 only) + super.w(); + })(), + (()=>{ + var { Reflect } = { + Reflect: null + }; // collision (es2015-es2021 only) + super.w(); + })(), + (()=>{ + var [Reflect] = [ + null + ]; // collision (es2015-es2021 only) + super.w(); + })(), + (()=>{ + class Reflect { + } // collision (es2015-es2021 only) + super.w(); + })(), + (()=>{ + function Reflect() {} // collision (es2015-es2021 only) + super.w(); + })(), + (()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + super.w(); + })(), + (()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + super.w(); + })(), + (()=>{ + super.w(); + })(), + (()=>{ + super.w(); + })(), + (()=>{ + (class Reflect { + }); // no collision + super.w(); + })(), + (()=>{ + (function Reflect() {}); // no collision + super.w(); + })() + ]; + } static{ var { Reflect } = { Reflect: null @@ -121,7 +123,9 @@ export { }; //// [varInContainingScopeStaticField1.ts] var Reflect = null; // collision (es2015-es2021 only) class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [varInContainingScopeStaticField2.ts] @@ -129,7 +133,9 @@ var { Reflect } = { Reflect: null }; // collision (es2015-es2021 only) class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [varInContainingScopeStaticField3.ts] @@ -137,7 +143,9 @@ var [Reflect] = [ null ]; // collision (es2015-es2021 only) class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [varInContainingScopeStaticBlock1.ts] @@ -172,7 +180,9 @@ export { }; class Reflect { } // collision (es2015-es2021 only) class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [classDeclInContainingScopeStaticBlock.ts] @@ -187,7 +197,9 @@ export { }; //// [funcDeclInContainingScopeStaticField.ts] function Reflect() {} // collision (es2015-es2021 only) class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [funcDeclInContainingScopeStaticBlock.ts] @@ -200,7 +212,9 @@ class C extends B { export { }; //// [valueNamespaceInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [valueNamespaceInContainingScopeStaticBlock.ts] @@ -215,7 +229,9 @@ var Reflect// collision (es2015-es2021 only) ; (function(Reflect) {})(Reflect || (Reflect = {})); class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [enumInContainingScopeStaticBlock.ts] @@ -233,7 +249,9 @@ var Reflect// collision (es2015-es2021 only) ; (function(Reflect) {})(Reflect || (Reflect = {})); class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [constEnumInContainingScopeStaticBlock.ts] @@ -248,7 +266,9 @@ class C extends B { export { }; //// [namespaceImportInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [namespaceImportInContainingScopeStaticBlock.ts] @@ -260,7 +280,9 @@ class C extends B { export { }; //// [namedImportInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [namedImportInContainingScopeStaticBlock.ts] @@ -272,7 +294,9 @@ class C extends B { export { }; //// [namedImportOfInterfaceInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [namedImportOfInterfaceInContainingScopeStaticBlock.ts] @@ -284,7 +308,9 @@ class C extends B { export { }; //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticBlock.ts] @@ -296,7 +322,9 @@ class C extends B { export { }; //// [namedImportOfConstEnumInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [namedImportOfConstEnumInContainingScopeStaticBlock.ts] @@ -308,7 +336,9 @@ class C extends B { export { }; //// [typeOnlyNamedImportInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [typeOnlyNamedImportInContainingScopeStaticBlock.ts] @@ -320,7 +350,9 @@ class C extends B { export { }; //// [defaultImportInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [defaultImportInContainingScopeStaticBlock.ts] @@ -332,7 +364,9 @@ class C extends B { export { }; //// [typeOnlyDefaultImportInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [typeOnlyDefaultImportInContainingScopeStaticBlock.ts] @@ -344,7 +378,9 @@ class C extends B { export { }; //// [typeInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [typeInContainingScopeStaticBlock.ts] @@ -356,7 +392,9 @@ class C extends B { export { }; //// [interfaceInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [interfaceInContainingScopeStaticBlock.ts] @@ -368,7 +406,9 @@ class C extends B { export { }; //// [uninstantiatedNamespaceInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [uninstantiatedNamespaceInContainingScopeStaticBlock.ts] @@ -382,7 +422,9 @@ export { }; (class Reflect { }); // no collision class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [classExprInContainingScopeStaticBlock.ts] @@ -398,7 +440,9 @@ export { }; (class Reflect { static{ class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } } }); @@ -417,7 +461,9 @@ export { }; //// [funcExprInContainingScopeStaticField.ts] (function Reflect() {}); // no collision class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [funcExprInContainingScopeStaticBlock.ts] @@ -431,7 +477,9 @@ export { }; //// [inContainingFuncExprStaticField.ts] (function Reflect() { class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } }); export { }; diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2022).2.minified.js index 9b9107fed8c9..c1d19685d30c 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2022).2.minified.js @@ -8,35 +8,37 @@ export default class { } //// [locals.ts] class C extends B { - static _ = [ - void super.w(), - (()=>{ - var { Reflect } = { - Reflect: null - }; - super.w(); - })(), - (()=>{ - var [Reflect] = [ - null - ]; - super.w(); - })(), - void super.w(), - void super.w(), - (()=>{ - let Reflect; - Reflect || (Reflect = {}), super.w(); - })(), - (()=>{ - let Reflect; - Reflect || (Reflect = {}), super.w(); - })(), - void super.w(), - void super.w(), - void super.w(), - void super.w() - ]; + static{ + this._ = [ + void super.w(), + (()=>{ + var { Reflect } = { + Reflect: null + }; + super.w(); + })(), + (()=>{ + var [Reflect] = [ + null + ]; + super.w(); + })(), + void super.w(), + void super.w(), + (()=>{ + let Reflect; + Reflect || (Reflect = {}), super.w(); + })(), + (()=>{ + let Reflect; + Reflect || (Reflect = {}), super.w(); + })(), + void super.w(), + void super.w(), + void super.w(), + void super.w() + ]; + } static{ var { Reflect } = { Reflect: null @@ -82,7 +84,9 @@ class C extends B { export { }; //// [varInContainingScopeStaticField1.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [varInContainingScopeStaticField2.ts] @@ -90,7 +94,9 @@ var { Reflect } = { Reflect: null }; class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [varInContainingScopeStaticField3.ts] @@ -98,7 +104,9 @@ var [Reflect] = [ null ]; class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [varInContainingScopeStaticBlock1.ts] @@ -130,7 +138,9 @@ class C extends B { export { }; //// [classDeclInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [classDeclInContainingScopeStaticBlock.ts] @@ -142,7 +152,9 @@ class C extends B { export { }; //// [funcDeclInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [funcDeclInContainingScopeStaticBlock.ts] @@ -154,7 +166,9 @@ class C extends B { export { }; //// [valueNamespaceInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [valueNamespaceInContainingScopeStaticBlock.ts] @@ -168,7 +182,9 @@ export { }; var Reflect; Reflect || (Reflect = {}); class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [enumInContainingScopeStaticBlock.ts] @@ -184,7 +200,9 @@ export { }; var Reflect; Reflect || (Reflect = {}); class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [constEnumInContainingScopeStaticBlock.ts] @@ -198,7 +216,9 @@ class C extends B { export { }; //// [namespaceImportInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [namespaceImportInContainingScopeStaticBlock.ts] @@ -210,7 +230,9 @@ class C extends B { export { }; //// [namedImportInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [namedImportInContainingScopeStaticBlock.ts] @@ -222,7 +244,9 @@ class C extends B { export { }; //// [namedImportOfInterfaceInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [namedImportOfInterfaceInContainingScopeStaticBlock.ts] @@ -234,7 +258,9 @@ class C extends B { export { }; //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticBlock.ts] @@ -246,7 +272,9 @@ class C extends B { export { }; //// [namedImportOfConstEnumInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [namedImportOfConstEnumInContainingScopeStaticBlock.ts] @@ -258,7 +286,9 @@ class C extends B { export { }; //// [typeOnlyNamedImportInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [typeOnlyNamedImportInContainingScopeStaticBlock.ts] @@ -270,7 +300,9 @@ class C extends B { export { }; //// [defaultImportInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [defaultImportInContainingScopeStaticBlock.ts] @@ -282,7 +314,9 @@ class C extends B { export { }; //// [typeOnlyDefaultImportInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [typeOnlyDefaultImportInContainingScopeStaticBlock.ts] @@ -294,7 +328,9 @@ class C extends B { export { }; //// [typeInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [typeInContainingScopeStaticBlock.ts] @@ -306,7 +342,9 @@ class C extends B { export { }; //// [interfaceInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [interfaceInContainingScopeStaticBlock.ts] @@ -318,7 +356,9 @@ class C extends B { export { }; //// [uninstantiatedNamespaceInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [uninstantiatedNamespaceInContainingScopeStaticBlock.ts] @@ -330,7 +370,9 @@ class C extends B { export { }; //// [classExprInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [classExprInContainingScopeStaticBlock.ts] @@ -346,7 +388,9 @@ export { }; export { }; //// [funcExprInContainingScopeStaticField.ts] class C extends B { - static _ = super.w(); + static{ + this._ = super.w(); + } } export { }; //// [funcExprInContainingScopeStaticBlock.ts] diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).1.normal.js b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).1.normal.js index 03a334e3ef75..9782e90a204b 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).1.normal.js @@ -28,64 +28,65 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = [ - function() { - var Reflect; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - }(), - function() { - var Reflect = { - Reflect: null - }.Reflect; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - }(), - function() { - var Reflect = null; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - }(), - function() { - var Reflect = function Reflect() { - "use strict"; - _class_call_check(this, Reflect); - } // collision (es2015-es2021 only) - ; - _get(_get_prototype_of(C), "w", C).call(C); - }(), - function() { - var Reflect = function Reflect() {} // collision (es2015-es2021 only) - ; - _get(_get_prototype_of(C), "w", C).call(C); - }(), - function() { - var Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - }(), - function() { - var Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - }(), - function() { - _get(_get_prototype_of(C), "w", C).call(C); - }(), - function() { - _get(_get_prototype_of(C), "w", C).call(C); - }(), - function() { - (function Reflect() { - "use strict"; - _class_call_check(this, Reflect); - }); // no collision - _get(_get_prototype_of(C), "w", C).call(C); - }(), - function() { - (function Reflect() {}); // no collision - _get(_get_prototype_of(C), "w", C).call(C); - }() -]; +(function() { + C._ = [ + function() { + var Reflect; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + }(), + function() { + var Reflect = { + Reflect: null + }.Reflect; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + }(), + function() { + var Reflect = null; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + }(), + function() { + var Reflect = function Reflect() { + "use strict"; + _class_call_check(this, Reflect); + } // collision (es2015-es2021 only) + ; + _get(_get_prototype_of(C), "w", C).call(C); + }(), + function() { + function Reflect() {} // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); + }(), + function() { + var Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); + }(), + function() { + var Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); + }(), + function() { + _get(_get_prototype_of(C), "w", C).call(C); + }(), + function() { + _get(_get_prototype_of(C), "w", C).call(C); + }(), + function() { + (function Reflect() { + "use strict"; + _class_call_check(this, Reflect); + }); // no collision + _get(_get_prototype_of(C), "w", C).call(C); + }(), + function() { + (function Reflect() {}); // no collision + _get(_get_prototype_of(C), "w", C).call(C); + }() + ]; +})(); (function() { var Reflect = { Reflect: null @@ -162,7 +163,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticField2.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -183,7 +186,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticField3.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -202,7 +207,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticBlock1.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -290,7 +297,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classDeclInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -334,7 +343,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [funcDeclInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -373,7 +384,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [valueNamespaceInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -414,7 +427,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [enumInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -458,7 +473,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [constEnumInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -499,7 +516,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namespaceImportInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -537,7 +556,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -575,7 +596,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfInterfaceInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -613,7 +636,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -651,7 +676,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfConstEnumInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -689,7 +716,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyNamedImportInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -727,7 +756,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [defaultImportInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -765,7 +796,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyDefaultImportInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -803,7 +836,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -841,7 +876,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [interfaceInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -879,7 +916,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [uninstantiatedNamespaceInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -921,7 +960,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classExprInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -968,7 +1009,9 @@ _Reflect = function Reflect() { } return C; }(B); - C._ = _get(_get_prototype_of(C), "w", C).call(C); + (function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); + })(); }(), _Reflect; export { }; //// [inContainingClassExprStaticBlock.ts] @@ -1014,7 +1057,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C._ = _get(_get_prototype_of(C), "w", C).call(C); +(function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [funcExprInContainingScopeStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -1054,7 +1099,9 @@ import _create_super from "@swc/helpers/src/_create_super.mjs"; } return C; }(B); - C._ = _get(_get_prototype_of(C), "w", C).call(C); + (function() { + C._ = _get(_get_prototype_of(C), "w", C).call(C); + })(); }); export { }; //// [inContainingFuncExprStaticBlock.ts] diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).2.minified.js b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).2.minified.js index cf243dbc7611..f13c7b12f330 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).2.minified.js @@ -27,25 +27,22 @@ var C = function(B1) { } return C; }(B); -C._ = [ - void _get(_get_prototype_of(C), "w", C).call(C), - void _get(_get_prototype_of(C), "w", C).call(C), - void _get(_get_prototype_of(C), "w", C).call(C), - void _get(_get_prototype_of(C), "w", C).call(C), - void _get(_get_prototype_of(C), "w", C).call(C), - function() { - var Reflect; - Reflect || (Reflect = {}), _get(_get_prototype_of(C), "w", C).call(C); - }(), - function() { - var Reflect; - Reflect || (Reflect = {}), _get(_get_prototype_of(C), "w", C).call(C); - }(), - void _get(_get_prototype_of(C), "w", C).call(C), - void _get(_get_prototype_of(C), "w", C).call(C), - void _get(_get_prototype_of(C), "w", C).call(C), - void _get(_get_prototype_of(C), "w", C).call(C) -], _get(_get_prototype_of(C), "w", C).call(C), _get(_get_prototype_of(C), "w", C).call(C), _get(_get_prototype_of(C), "w", C).call(C), _get(_get_prototype_of(C), "w", C).call(C), _get(_get_prototype_of(C), "w", C).call(C), function() { +!function() { + var Reflect, Reflect1; + C._ = [ + void _get(_get_prototype_of(C), "w", C).call(C), + void _get(_get_prototype_of(C), "w", C).call(C), + void _get(_get_prototype_of(C), "w", C).call(C), + void _get(_get_prototype_of(C), "w", C).call(C), + void _get(_get_prototype_of(C), "w", C).call(C), + void (Reflect || (Reflect = {}), _get(_get_prototype_of(C), "w", C).call(C)), + void (Reflect1 || (Reflect1 = {}), _get(_get_prototype_of(C), "w", C).call(C)), + void _get(_get_prototype_of(C), "w", C).call(C), + void _get(_get_prototype_of(C), "w", C).call(C), + void _get(_get_prototype_of(C), "w", C).call(C), + void _get(_get_prototype_of(C), "w", C).call(C) + ]; +}(), _get(_get_prototype_of(C), "w", C).call(C), _get(_get_prototype_of(C), "w", C).call(C), _get(_get_prototype_of(C), "w", C).call(C), _get(_get_prototype_of(C), "w", C).call(C), _get(_get_prototype_of(C), "w", C).call(C), function() { var Reflect; Reflect || (Reflect = {}), _get(_get_prototype_of(C), "w", C).call(C); }(), function() { diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit1.1.normal.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit1.1.normal.js index d724e69f1a77..90d0d696adcd 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit1.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit1.1.normal.js @@ -1,3 +1,7 @@ //// [symbolDeclarationEmit1.ts] +let prop; class C { } +(()=>{ + prop = Symbol.toPrimitive; +})(); diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit11.1.normal.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit11.1.normal.js index 773161b8694c..de73217ccbc2 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit11.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit11.1.normal.js @@ -1,5 +1,6 @@ //// [symbolDeclarationEmit11.ts] -let _Symbol_iterator = Symbol.iterator, _Symbol_isConcatSpreadable = Symbol.isConcatSpreadable, _Symbol_toPrimitive = Symbol.toPrimitive, _Symbol_toPrimitive1 = Symbol.toPrimitive; +let prop; +let _Symbol_isConcatSpreadable = Symbol.isConcatSpreadable, _Symbol_toPrimitive = Symbol.toPrimitive, _Symbol_toPrimitive1 = Symbol.toPrimitive; class C { static [_Symbol_isConcatSpreadable]() {} static get [_Symbol_toPrimitive]() { @@ -7,4 +8,9 @@ class C { } static set [_Symbol_toPrimitive1](x) {} } -C[_Symbol_iterator] = 0; +(()=>{ + prop = Symbol.iterator; +})(); +(()=>{ + C[prop] = 0; +})(); diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit12.1.normal.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit12.1.normal.js index 42fd837b29e1..6466921bd8a3 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit12.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit12.1.normal.js @@ -1,15 +1,20 @@ //// [symbolDeclarationEmit12.ts] var M; +let prop; (function(M) { + let _Symbol_toPrimitive = Symbol.toPrimitive, _Symbol_isConcatSpreadable = Symbol.isConcatSpreadable, _Symbol_toPrimitive1 = Symbol.toPrimitive, _Symbol_toPrimitive2 = Symbol.toPrimitive; class C { - [Symbol.toPrimitive](x) {} - [Symbol.isConcatSpreadable]() { + [_Symbol_toPrimitive](x) {} + [_Symbol_isConcatSpreadable]() { return undefined; } - get [Symbol.toPrimitive]() { + get [_Symbol_toPrimitive1]() { return undefined; } - set [Symbol.toPrimitive](x) {} + set [_Symbol_toPrimitive2](x) {} } + (()=>{ + prop = Symbol.iterator; + })(); M.C = C; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit12.2.minified.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit12.2.minified.js index 1a41453e9c62..fe0ed1bbd8fa 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit12.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit12.2.minified.js @@ -1,11 +1,11 @@ //// [symbolDeclarationEmit12.ts] var M; !function(M) { - class C { - [Symbol.toPrimitive](x) {} - [Symbol.isConcatSpreadable]() {} - get [Symbol.toPrimitive]() {} - set [Symbol.toPrimitive](x) {} - } - M.C = C; + let _Symbol_toPrimitive = Symbol.toPrimitive, _Symbol_isConcatSpreadable = Symbol.isConcatSpreadable, _Symbol_toPrimitive1 = Symbol.toPrimitive, _Symbol_toPrimitive2 = Symbol.toPrimitive; + M.C = class { + [_Symbol_toPrimitive](x) {} + [_Symbol_isConcatSpreadable]() {} + get [_Symbol_toPrimitive1]() {} + set [_Symbol_toPrimitive2](x) {} + }; }(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit2.1.normal.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit2.1.normal.js index cb90bdd5f275..bdd701b1e411 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit2.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit2.1.normal.js @@ -1,7 +1,10 @@ //// [symbolDeclarationEmit2.ts] -let _Symbol_toPrimitive = Symbol.toPrimitive; +let prop; class C { constructor(){ - this[_Symbol_toPrimitive] = ""; + this[prop] = ""; } } +(()=>{ + prop = Symbol.toPrimitive; +})(); diff --git a/crates/swc/tests/tsc-references/symbolProperty10.1.normal.js b/crates/swc/tests/tsc-references/symbolProperty10.1.normal.js index 2339a6ac3c73..7fd35e9645d3 100644 --- a/crates/swc/tests/tsc-references/symbolProperty10.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolProperty10.1.normal.js @@ -1,6 +1,10 @@ //// [symbolProperty10.ts] +let prop; class C { } +(()=>{ + prop = Symbol.iterator; +})(); var i; i = new C; var c = i; diff --git a/crates/swc/tests/tsc-references/symbolProperty12.1.normal.js b/crates/swc/tests/tsc-references/symbolProperty12.1.normal.js index c3231b30742e..41253fcdb331 100644 --- a/crates/swc/tests/tsc-references/symbolProperty12.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolProperty12.1.normal.js @@ -1,6 +1,10 @@ //// [symbolProperty12.ts] +let prop; class C { } +(()=>{ + prop = Symbol.iterator; +})(); var i; i = new C; var c = i; diff --git a/crates/swc/tests/tsc-references/symbolProperty13.1.normal.js b/crates/swc/tests/tsc-references/symbolProperty13.1.normal.js index 98d1ad06cdd4..0844c4dbd0a7 100644 --- a/crates/swc/tests/tsc-references/symbolProperty13.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolProperty13.1.normal.js @@ -1,6 +1,10 @@ //// [symbolProperty13.ts] +let prop; class C { } +(()=>{ + prop = Symbol.iterator; +})(); foo(new C); var i; bar(i); diff --git a/crates/swc/tests/tsc-references/symbolProperty14.1.normal.js b/crates/swc/tests/tsc-references/symbolProperty14.1.normal.js index 3aa40c9f8501..d92a1bfda5a6 100644 --- a/crates/swc/tests/tsc-references/symbolProperty14.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolProperty14.1.normal.js @@ -1,6 +1,10 @@ //// [symbolProperty14.ts] +let prop; class C { } +(()=>{ + prop = Symbol.iterator; +})(); foo(new C); var i; bar(i); diff --git a/crates/swc/tests/tsc-references/symbolProperty16.1.normal.js b/crates/swc/tests/tsc-references/symbolProperty16.1.normal.js index f8e42bc3e3e9..19e9ca5b9ba1 100644 --- a/crates/swc/tests/tsc-references/symbolProperty16.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolProperty16.1.normal.js @@ -1,6 +1,10 @@ //// [symbolProperty16.ts] +let prop; class C { } +(()=>{ + prop = Symbol.iterator; +})(); foo(new C); var i; bar(i); diff --git a/crates/swc/tests/tsc-references/symbolProperty6.1.normal.js b/crates/swc/tests/tsc-references/symbolProperty6.1.normal.js index 0186122674a9..c1ba25319604 100644 --- a/crates/swc/tests/tsc-references/symbolProperty6.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolProperty6.1.normal.js @@ -1,11 +1,16 @@ //// [symbolProperty6.ts] -let _Symbol_iterator = Symbol.iterator, _Symbol_toPrimitive = Symbol.toPrimitive, _Symbol_toStringTag = Symbol.toStringTag; +let prop, prop1; +let _Symbol_toPrimitive = Symbol.toPrimitive, _Symbol_toStringTag = Symbol.toStringTag; class C { [_Symbol_toPrimitive]() {} get [_Symbol_toStringTag]() { return 0; } constructor(){ - this[_Symbol_iterator] = 0; + this[prop] = 0; } } +(()=>{ + prop = Symbol.iterator; + prop1 = Symbol.unscopables; +})(); diff --git a/crates/swc/tests/tsc-references/symbolProperty9.1.normal.js b/crates/swc/tests/tsc-references/symbolProperty9.1.normal.js index e2590358faed..4a48cc568635 100644 --- a/crates/swc/tests/tsc-references/symbolProperty9.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolProperty9.1.normal.js @@ -1,6 +1,10 @@ //// [symbolProperty9.ts] +let prop; class C { } +(()=>{ + prop = Symbol.iterator; +})(); var i; i = new C; var c = i; diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js index fd4ca3f03588..ddc3482eabe0 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js @@ -14,42 +14,90 @@ class C extends B { this.z = super.f(); } } -C.x = undefined; -C.y1 = C.x; -C.y2 = C.x(); -C.y3 = C === null || C === void 0 ? void 0 : C.x(); -C.y4 = C["x"](); -C.y5 = C === null || C === void 0 ? void 0 : C["x"](); -C.z1 = _get(_get_prototype_of(C), "a", C); -C.z2 = _get(_get_prototype_of(C), "a", C); -C.z3 = _get(_get_prototype_of(C), "f", C).call(C); -C.z4 = _get(_get_prototype_of(C), "f", C).call(C); -C.z5 = _set(_get_prototype_of(C), "a", 0, C, true); -C.z6 = _update(_get_prototype_of(C), "a", C, true)._ += 1; -C.z7 = (()=>{ - _set(_get_prototype_of(C), "a", 0, C, true); -})(); -C.z8 = [_update(_get_prototype_of(C), "a", C, true)._] = [ - 0 -]; -C.z9 = [_update(_get_prototype_of(C), "a", C, true)._ = 0] = [ - 0 -]; -C.z10 = [..._update(_get_prototype_of(C), "a", C, true)._] = [ - 0 -]; -C.z11 = { x: _update(_get_prototype_of(C), "a", C, true)._ } = { - x: 0 -}; -C.z12 = { x: _update(_get_prototype_of(C), "a", C, true)._ = 0 } = { - x: 0 -}; -var _tmp; -C.z13 = (_tmp = { - x: 0 -}, _update(_get_prototype_of(C), "a", C, true)._ = _extends({}, _object_destructuring_empty(_tmp)), _tmp); -C.z14 = ++_update(_get_prototype_of(C), "a", C, true)._; -C.z15 = --_update(_get_prototype_of(C), "a", C, true)._; -C.z16 = ++_update(_get_prototype_of(C), "a", C, true)._; -C.z17 = _update(_get_prototype_of(C), "a", C, true)._++; -C.z18 = _get(_get_prototype_of(C), "a", C)``; +(()=>{ + C.x = undefined; +})(); +(()=>{ + C.y1 = C.x; +})(); +(()=>{ + C.y2 = C.x(); +})(); +(()=>{ + C.y3 = C === null || C === void 0 ? void 0 : C.x(); +})(); +(()=>{ + C.y4 = C["x"](); +})(); +(()=>{ + C.y5 = C === null || C === void 0 ? void 0 : C["x"](); +})(); +(()=>{ + C.z1 = _get(_get_prototype_of(C), "a", C); +})(); +(()=>{ + C.z2 = _get(_get_prototype_of(C), "a", C); +})(); +(()=>{ + C.z3 = _get(_get_prototype_of(C), "f", C).call(C); +})(); +(()=>{ + C.z4 = _get(_get_prototype_of(C), "f", C).call(C); +})(); +(()=>{ + C.z5 = _set(_get_prototype_of(C), "a", 0, C, true); +})(); +(()=>{ + C.z6 = _update(_get_prototype_of(C), "a", C, true)._ += 1; +})(); +(()=>{ + C.z7 = (()=>{ + _set(_get_prototype_of(C), "a", 0, C, true); + })(); +})(); +(()=>{ + C.z8 = [_update(_get_prototype_of(C), "a", C, true)._] = [ + 0 + ]; +})(); +(()=>{ + C.z9 = [_update(_get_prototype_of(C), "a", C, true)._ = 0] = [ + 0 + ]; +})(); +(()=>{ + C.z10 = [..._update(_get_prototype_of(C), "a", C, true)._] = [ + 0 + ]; +})(); +(()=>{ + C.z11 = { x: _update(_get_prototype_of(C), "a", C, true)._ } = { + x: 0 + }; +})(); +(()=>{ + C.z12 = { x: _update(_get_prototype_of(C), "a", C, true)._ = 0 } = { + x: 0 + }; +})(); +(()=>{ + var _tmp; + C.z13 = (_tmp = { + x: 0 + }, _update(_get_prototype_of(C), "a", C, true)._ = _extends({}, _object_destructuring_empty(_tmp)), _tmp); +})(); +(()=>{ + C.z14 = ++_update(_get_prototype_of(C), "a", C, true)._; +})(); +(()=>{ + C.z15 = --_update(_get_prototype_of(C), "a", C, true)._; +})(); +(()=>{ + C.z16 = ++_update(_get_prototype_of(C), "a", C, true)._; +})(); +(()=>{ + C.z17 = _update(_get_prototype_of(C), "a", C, true)._++; +})(); +(()=>{ + C.z18 = _get(_get_prototype_of(C), "a", C)``; +})(); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).2.minified.js index 44088d244164..7a44d70d08f3 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).2.minified.js @@ -1,5 +1,4 @@ //// [thisAndSuperInStaticMembers2.ts] -var _tmp; import _extends from "@swc/helpers/src/_extends.mjs"; import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; @@ -21,6 +20,9 @@ C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 x: 0 }, C.z12 = { x: _update(_get_prototype_of(C), "a", C, !0)._ = 0 } = { x: 0 -}, C.z13 = (_tmp = { - x: 0 -}, _update(_get_prototype_of(C), "a", C, !0)._ = _extends({}, _object_destructuring_empty(_tmp)), _tmp), C.z14 = ++_update(_get_prototype_of(C), "a", C, !0)._, C.z15 = --_update(_get_prototype_of(C), "a", C, !0)._, C.z16 = ++_update(_get_prototype_of(C), "a", C, !0)._, C.z17 = _update(_get_prototype_of(C), "a", C, !0)._++, C.z18 = _get(_get_prototype_of(C), "a", C)``; +}, (()=>{ + var _tmp; + C.z13 = (_tmp = { + x: 0 + }, _update(_get_prototype_of(C), "a", C, !0)._ = _extends({}, _object_destructuring_empty(_tmp)), _tmp); +})(), C.z14 = ++_update(_get_prototype_of(C), "a", C, !0)._, C.z15 = --_update(_get_prototype_of(C), "a", C, !0)._, C.z16 = ++_update(_get_prototype_of(C), "a", C, !0)._, C.z17 = _update(_get_prototype_of(C), "a", C, !0)._++, C.z18 = _get(_get_prototype_of(C), "a", C)``; diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2022).1.normal.js index e8c73b3311f1..5d969cb9514e 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2022).1.normal.js @@ -1,45 +1,96 @@ //// [thisAndSuperInStaticMembers2.ts] class C extends B { - static x = undefined; - static y1 = this.x; - static y2 = this.x(); - static y3 = this?.x(); - static y4 = this["x"](); - static y5 = this?.["x"](); - static z1 = super.a; - static z2 = super["a"]; - static z3 = super.f(); - static z4 = super["f"](); - static z5 = super.a = 0; - static z6 = super.a += 1; - static z7 = (()=>{ - super.a = 0; - })(); - static z8 = [super.a] = [ - 0 - ]; - static z9 = [super.a = 0] = [ - 0 - ]; - 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 z14 = ++super.a; - static z15 = --super.a; - static z16 = ++super["a"]; - static z17 = super.a++; - static z18 = super.a``; - // these should be unaffected - x = 1; - y = this.x; - z = super.f(); + static{ + this.x = undefined; + } + static{ + this.y1 = this.x; + } + static{ + this.y2 = this.x(); + } + static{ + this.y3 = this?.x(); + } + static{ + this.y4 = this["x"](); + } + static{ + this.y5 = this?.["x"](); + } + static{ + this.z1 = super.a; + } + static{ + this.z2 = super["a"]; + } + static{ + this.z3 = super.f(); + } + static{ + this.z4 = super["f"](); + } + static{ + this.z5 = super.a = 0; + } + static{ + this.z6 = super.a += 1; + } + static{ + this.z7 = (()=>{ + super.a = 0; + })(); + } + static{ + this.z8 = [super.a] = [ + 0 + ]; + } + static{ + this.z9 = [super.a = 0] = [ + 0 + ]; + } + static{ + this.z10 = [...super.a] = [ + 0 + ]; + } + static{ + this.z11 = { x: super.a } = { + x: 0 + }; + } + static{ + this.z12 = { x: super.a = 0 } = { + x: 0 + }; + } + static{ + this.z13 = { ...super.a } = { + x: 0 + }; + } + static{ + this.z14 = ++super.a; + } + static{ + this.z15 = --super.a; + } + static{ + this.z16 = ++super["a"]; + } + static{ + this.z17 = super.a++; + } + static{ + this.z18 = super.a``; + } + constructor(...args){ + super(...args); + // these should be unaffected + this.x = 1; + this.y = this.x; + this.z = super.f(); + } } diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2022).2.minified.js index 9a71be675154..f6a18965cfbd 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2022).2.minified.js @@ -1,42 +1,90 @@ //// [thisAndSuperInStaticMembers2.ts] class C extends B { - static x = void 0; - static y1 = this.x; - static y2 = this.x(); - static y3 = this?.x(); - static y4 = this.x(); - static y5 = this?.x(); - static z1 = super.a; - static z2 = super.a; - static z3 = super.f(); - static z4 = super.f(); - static z5 = super.a = 0; - static z6 = super.a += 1; - static z7 = void (super.a = 0); - static z8 = [super.a] = [ - 0 - ]; - static z9 = [super.a = 0] = [ - 0 - ]; - 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 z14 = ++super.a; - static z15 = --super.a; - static z16 = ++super.a; - static z17 = super.a++; - static z18 = super.a``; - x = 1; - y = this.x; - z = super.f(); + static{ + this.x = void 0; + } + static{ + this.y1 = this.x; + } + static{ + this.y2 = this.x(); + } + static{ + this.y3 = this?.x(); + } + static{ + this.y4 = this.x(); + } + static{ + this.y5 = this?.x(); + } + static{ + this.z1 = super.a; + } + static{ + this.z2 = super.a; + } + static{ + this.z3 = super.f(); + } + static{ + this.z4 = super.f(); + } + static{ + this.z5 = super.a = 0; + } + static{ + this.z6 = super.a += 1; + } + static{ + this.z7 = void (super.a = 0); + } + static{ + this.z8 = [super.a] = [ + 0 + ]; + } + static{ + this.z9 = [super.a = 0] = [ + 0 + ]; + } + static{ + this.z10 = [...super.a] = [ + 0 + ]; + } + static{ + this.z11 = { x: super.a } = { + x: 0 + }; + } + static{ + this.z12 = { x: super.a = 0 } = { + x: 0 + }; + } + static{ + this.z13 = { ...super.a } = { + x: 0 + }; + } + static{ + this.z14 = ++super.a; + } + static{ + this.z15 = --super.a; + } + static{ + this.z16 = ++super.a; + } + static{ + this.z17 = super.a++; + } + static{ + this.z18 = super.a``; + } + constructor(...args){ + super(...args), this.x = 1, this.y = this.x, this.z = super.f(); + } } diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4.1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4.1.normal.js index 93e075bbea26..57d948753f34 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4.1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4.1.normal.js @@ -21,11 +21,27 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -C.x = undefined; -C.y1 = C.x; -C.y2 = C.x(); -C.y3 = C === null || C === void 0 ? void 0 : C.x(); -C.y4 = C["x"](); -C.y5 = C === null || C === void 0 ? void 0 : C["x"](); -C.z3 = _get(_get_prototype_of(C), "f", C).call(C); -C.z4 = _get(_get_prototype_of(C), "f", C).call(C); +(function() { + C.x = undefined; +})(); +(function() { + C.y1 = C.x; +})(); +(function() { + C.y2 = C.x(); +})(); +(function() { + C.y3 = C === null || C === void 0 ? void 0 : C.x(); +})(); +(function() { + C.y4 = C["x"](); +})(); +(function() { + C.y5 = C === null || C === void 0 ? void 0 : C["x"](); +})(); +(function() { + C.z3 = _get(_get_prototype_of(C), "f", C).call(C); +})(); +(function() { + C.z4 = _get(_get_prototype_of(C), "f", C).call(C); +})(); diff --git a/crates/swc/tests/tsc-references/thisTypeAccessibility.1.normal.js b/crates/swc/tests/tsc-references/thisTypeAccessibility.1.normal.js index d9f8af3ffc24..a4f0584a8e3e 100644 --- a/crates/swc/tests/tsc-references/thisTypeAccessibility.1.normal.js +++ b/crates/swc/tests/tsc-references/thisTypeAccessibility.1.normal.js @@ -7,9 +7,15 @@ var MyClass = function MyClass() { this.pp = 123; this.ppp = 123; }; -MyClass.sp = 123; -MyClass.spp = 123; -MyClass.sppp = 123; +(function() { + MyClass.sp = 123; +})(); +(function() { + MyClass.spp = 123; +})(); +(function() { + MyClass.sppp = 123; +})(); var MyGenericClass = function MyGenericClass() { "use strict"; _class_call_check(this, MyGenericClass); diff --git a/crates/swc/tests/tsc-references/thisTypeErrors.1.normal.js b/crates/swc/tests/tsc-references/thisTypeErrors.1.normal.js index 0738f16693c9..a0702a9fc9b2 100644 --- a/crates/swc/tests/tsc-references/thisTypeErrors.1.normal.js +++ b/crates/swc/tests/tsc-references/thisTypeErrors.1.normal.js @@ -21,7 +21,9 @@ var C2 = /*#__PURE__*/ function() { }; return C2; }(); -C2.y = undefined; +(function() { + C2.y = undefined; +})(); var N1; (function(N1) { var x; diff --git a/crates/swc/tests/tsc-references/tsxLibraryManagedAttributes.1.normal.js b/crates/swc/tests/tsc-references/tsxLibraryManagedAttributes.1.normal.js index 5b162785b275..90d45ab26434 100644 --- a/crates/swc/tests/tsc-references/tsxLibraryManagedAttributes.1.normal.js +++ b/crates/swc/tests/tsc-references/tsxLibraryManagedAttributes.1.normal.js @@ -12,14 +12,18 @@ var Component = /*#__PURE__*/ function(ReactComponent1) { } return Component; }(ReactComponent); -Component.propTypes = { - foo: PropTypes.number, - bar: PropTypes.node, - baz: PropTypes.string.isRequired -}; -Component.defaultProps = { - foo: 42 -}; +(function() { + Component.propTypes = { + foo: PropTypes.number, + bar: PropTypes.node, + baz: PropTypes.string.isRequired + }; +})(); +(function() { + Component.defaultProps = { + foo: 42 + }; +})(); var a = /*#__PURE__*/ React.createElement(Component, { foo: 12, bar: "yes", @@ -57,10 +61,12 @@ var JustPropTypes = /*#__PURE__*/ function(ReactComponent1) { } return JustPropTypes; }(ReactComponent); -JustPropTypes.propTypes = { - foo: PropTypes.number, - bar: PropTypes.node.isRequired -}; +(function() { + JustPropTypes.propTypes = { + foo: PropTypes.number, + bar: PropTypes.node.isRequired + }; +})(); var g = /*#__PURE__*/ React.createElement(JustPropTypes, { foo: 12, bar: "ok" @@ -86,9 +92,11 @@ var JustDefaultProps = /*#__PURE__*/ function(ReactComponent1) { } return JustDefaultProps; }(ReactComponent); -JustDefaultProps.defaultProps = { - foo: 42 -}; +(function() { + JustDefaultProps.defaultProps = { + foo: 42 + }; +})(); var k = /*#__PURE__*/ React.createElement(JustDefaultProps, { foo: 12 }); @@ -109,14 +117,18 @@ var BothWithSpecifiedGeneric = /*#__PURE__*/ function(ReactComponent1) { } return BothWithSpecifiedGeneric; }(ReactComponent); -BothWithSpecifiedGeneric.propTypes = { - foo: PropTypes.string, - bar: PropTypes.node, - baz: PropTypes.number.isRequired -}; -BothWithSpecifiedGeneric.defaultProps = { - foo: "yo" -}; +(function() { + BothWithSpecifiedGeneric.propTypes = { + foo: PropTypes.string, + bar: PropTypes.node, + baz: PropTypes.number.isRequired + }; +})(); +(function() { + BothWithSpecifiedGeneric.defaultProps = { + foo: "yo" + }; +})(); var n = /*#__PURE__*/ React.createElement(BothWithSpecifiedGeneric, { foo: "fine", bar: "yes", @@ -154,10 +166,12 @@ var JustPropTypesWithSpecifiedGeneric = /*#__PURE__*/ function(ReactComponent1) } return JustPropTypesWithSpecifiedGeneric; }(ReactComponent); -JustPropTypesWithSpecifiedGeneric.propTypes = { - foo: PropTypes.string, - bar: PropTypes.node.isRequired -}; +(function() { + JustPropTypesWithSpecifiedGeneric.propTypes = { + foo: PropTypes.string, + bar: PropTypes.node.isRequired + }; +})(); var t = /*#__PURE__*/ React.createElement(JustPropTypesWithSpecifiedGeneric, { foo: "nice", bar: "ok" @@ -183,9 +197,11 @@ var JustDefaultPropsWithSpecifiedGeneric = /*#__PURE__*/ function(ReactComponent } return JustDefaultPropsWithSpecifiedGeneric; }(ReactComponent); -JustDefaultPropsWithSpecifiedGeneric.defaultProps = { - foo: "no" -}; +(function() { + JustDefaultPropsWithSpecifiedGeneric.defaultProps = { + foo: "no" + }; +})(); var x = /*#__PURE__*/ React.createElement(JustDefaultPropsWithSpecifiedGeneric, { foo: "eh" }); diff --git a/crates/swc/tests/tsc-references/typeArgumentInferenceWithClassExpression1.1.normal.js b/crates/swc/tests/tsc-references/typeArgumentInferenceWithClassExpression1.1.normal.js index 13ae7fae86ff..c1c768f2f876 100644 --- a/crates/swc/tests/tsc-references/typeArgumentInferenceWithClassExpression1.1.normal.js +++ b/crates/swc/tests/tsc-references/typeArgumentInferenceWithClassExpression1.1.normal.js @@ -11,4 +11,6 @@ function foo() { foo((_class = function _class() { "use strict"; _class_call_check(this, _class); -}, _class.prop = "hello", _class)).length; +}, function() { + _class.prop = "hello"; +}(), _class)).length; diff --git a/crates/swc/tests/tsc-references/typeArgumentInferenceWithClassExpression2.1.normal.js b/crates/swc/tests/tsc-references/typeArgumentInferenceWithClassExpression2.1.normal.js index 66b44037f7db..1acfedde8618 100644 --- a/crates/swc/tests/tsc-references/typeArgumentInferenceWithClassExpression2.1.normal.js +++ b/crates/swc/tests/tsc-references/typeArgumentInferenceWithClassExpression2.1.normal.js @@ -12,4 +12,6 @@ function foo() { foo((_class = function _class() { "use strict"; _class_call_check(this, _class); -}, _class.prop = "hello", _class)).length; +}, function() { + _class.prop = "hello"; +}(), _class)).length; diff --git a/crates/swc/tests/tsc-references/typeOfThisGeneral.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisGeneral.1.normal.js index 01586b7745f7..89eb53db0b75 100644 --- a/crates/swc/tests/tsc-references/typeOfThisGeneral.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisGeneral.1.normal.js @@ -1,6 +1,11 @@ //// [typeOfThisGeneral.ts] class MyTestClass { constructor(){ + this.someFunc = ()=>{ + //type of 'this' in member variable initializer is the class instance type + var t = this; + var t; + }; //type of 'this' in constructor body is the class instance type var p = this.canary; var p; @@ -25,11 +30,6 @@ class MyTestClass { p = v; v = p; } - someFunc = ()=>{ - //type of 'this' in member variable initializer is the class instance type - var t = this; - var t; - }; //type of 'this' in static function param list is constructor function type static staticFn(t = this) { var t; @@ -59,6 +59,11 @@ class MyTestClass { } class MyGenericTestClass { constructor(){ + this.someFunc = ()=>{ + //type of 'this' in member variable initializer is the class instance type + var t = this; + var t; + }; //type of 'this' in constructor body is the class instance type var p = this.canary; var p; @@ -83,11 +88,6 @@ class MyGenericTestClass { p = v; v = p; } - someFunc = ()=>{ - //type of 'this' in member variable initializer is the class instance type - var t = this; - var t; - }; //type of 'this' in static function param list is constructor function type static staticFn(t = this) { var t; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2.1.normal.js index d7f8d9992f10..58b819aeff78 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2.1.normal.js @@ -4,11 +4,15 @@ var C = function C() { "use strict"; _class_call_check(this, C); }; -C.foo = C // ok -; +(function() { + C.foo = C // ok + ; +})(); var C2 = function C2() { "use strict"; _class_call_check(this, C2); }; -C2.foo = C2 // ok -; +(function() { + C2.foo = C2 // ok + ; +})(); diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2015).1.normal.js index a1b54d4e861c..1af3bea20510 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2015).1.normal.js @@ -3,10 +3,20 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C { } -C.a = 1; -C.b = C.a + 1; +(()=>{ + C.a = 1; +})(); +(()=>{ + C.b = C.a + 1; +})(); class D extends C { } -D.c = 2; -D.d = D.c + 1; -D.e = _get(_get_prototype_of(D), "a", D) + D.c + 1; +(()=>{ + D.c = 2; +})(); +(()=>{ + D.d = D.c + 1; +})(); +(()=>{ + D.e = _get(_get_prototype_of(D), "a", D) + D.c + 1; +})(); diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2022).1.normal.js index d96f656c2b05..8648dda5fe42 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2022).1.normal.js @@ -1,10 +1,20 @@ //// [typeOfThisInStaticMembers3.ts] class C { - static a = 1; - static b = this.a + 1; + static{ + this.a = 1; + } + static{ + this.b = this.a + 1; + } } class D extends C { - static c = 2; - static d = this.c + 1; - static e = super.a + this.c + 1; + static{ + this.c = 2; + } + static{ + this.d = this.c + 1; + } + static{ + this.e = super.a + this.c + 1; + } } diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2022).2.minified.js index d96f656c2b05..8648dda5fe42 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es2022).2.minified.js @@ -1,10 +1,20 @@ //// [typeOfThisInStaticMembers3.ts] class C { - static a = 1; - static b = this.a + 1; + static{ + this.a = 1; + } + static{ + this.b = this.a + 1; + } } class D extends C { - static c = 2; - static d = this.c + 1; - static e = super.a + this.c + 1; + static{ + this.c = 2; + } + static{ + this.d = this.c + 1; + } + static{ + this.e = super.a + this.c + 1; + } } diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es5).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es5).1.normal.js index 7174a44e18a2..39f6b35908e5 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3(target=es5).1.normal.js @@ -8,8 +8,12 @@ var C = function C() { "use strict"; _class_call_check(this, C); }; -C.a = 1; -C.b = C.a + 1; +(function() { + C.a = 1; +})(); +(function() { + C.b = C.a + 1; +})(); var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); @@ -20,6 +24,12 @@ var D = /*#__PURE__*/ function(C) { } return D; }(C); -D.c = 2; -D.d = D.c + 1; -D.e = _get(_get_prototype_of(D), "a", D) + D.c + 1; +(function() { + D.c = 2; +})(); +(function() { + D.d = D.c + 1; +})(); +(function() { + D.e = _get(_get_prototype_of(D), "a", D) + D.c + 1; +})(); diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2015).1.normal.js index b905776f64e9..108212b5a8b7 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2015).1.normal.js @@ -4,4 +4,6 @@ class C { this.foo = foo; } } -C.create = ()=>new C("yep"); +(()=>{ + C.create = ()=>new C("yep"); +})(); diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2022).1.normal.js index 59ca69a392ba..161522235a40 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2022).1.normal.js @@ -1,6 +1,8 @@ //// [typeOfThisInStaticMembers5.ts] class C { - static create = ()=>new this("yep"); + static{ + this.create = ()=>new this("yep"); + } constructor(foo){ this.foo = foo; } diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2022).2.minified.js index 9c2cbc70706a..161522235a40 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es2022).2.minified.js @@ -1 +1,9 @@ //// [typeOfThisInStaticMembers5.ts] +class C { + static{ + this.create = ()=>new this("yep"); + } + constructor(foo){ + this.foo = foo; + } +} diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es5).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es5).1.normal.js index fa429c437fec..29670d7ccd86 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers5(target=es5).1.normal.js @@ -5,6 +5,8 @@ var C = function C(foo) { _class_call_check(this, C); this.foo = foo; }; -C.create = function() { - return new C("yep"); -}; +(function() { + C.create = function() { + return new C("yep"); + }; +})(); diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers6.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers6.1.normal.js index e0c0c3070d51..c19da7aa8ba9 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers6.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers6.1.normal.js @@ -6,7 +6,9 @@ var C = function C() { "use strict"; _class_call_check(this, C); }; -C.f = 1; +(function() { + C.f = 1; +})(); var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); @@ -17,4 +19,6 @@ var D = /*#__PURE__*/ function(C) { } return D; }(C); -D.c = super(); +(function() { + D.c = super(); +})(); diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2015).1.normal.js index 4c53843db6fc..8968884a82d8 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2015).1.normal.js @@ -3,10 +3,20 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C { } -C.a = 1; -C.b = C.a + 1; +(()=>{ + C.a = 1; +})(); +(()=>{ + C.b = C.a + 1; +})(); class D extends C { } -D.c = 2; -D.d = D.c + 1; -D.e = 1 + _get(_get_prototype_of(D), "a", D) + (D.c + 1) + 1; +(()=>{ + D.c = 2; +})(); +(()=>{ + D.d = D.c + 1; +})(); +(()=>{ + D.e = 1 + _get(_get_prototype_of(D), "a", D) + (D.c + 1) + 1; +})(); diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2022).1.normal.js index 8b1d1d1120b0..f9f8fd6f575d 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2022).1.normal.js @@ -1,10 +1,20 @@ //// [typeOfThisInStaticMembers7.ts] class C { - static a = 1; - static b = this.a + 1; + static{ + this.a = 1; + } + static{ + this.b = this.a + 1; + } } class D extends C { - static c = 2; - static d = this.c + 1; - static e = 1 + super.a + (this.c + 1) + 1; + static{ + this.c = 2; + } + static{ + this.d = this.c + 1; + } + static{ + this.e = 1 + super.a + (this.c + 1) + 1; + } } diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2022).2.minified.js index 8b1d1d1120b0..f9f8fd6f575d 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es2022).2.minified.js @@ -1,10 +1,20 @@ //// [typeOfThisInStaticMembers7.ts] class C { - static a = 1; - static b = this.a + 1; + static{ + this.a = 1; + } + static{ + this.b = this.a + 1; + } } class D extends C { - static c = 2; - static d = this.c + 1; - static e = 1 + super.a + (this.c + 1) + 1; + static{ + this.c = 2; + } + static{ + this.d = this.c + 1; + } + static{ + this.e = 1 + super.a + (this.c + 1) + 1; + } } diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es5).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es5).1.normal.js index f3d455253a4d..550a0e684618 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7(target=es5).1.normal.js @@ -8,8 +8,12 @@ var C = function C() { "use strict"; _class_call_check(this, C); }; -C.a = 1; -C.b = C.a + 1; +(function() { + C.a = 1; +})(); +(function() { + C.b = C.a + 1; +})(); var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); @@ -20,6 +24,12 @@ var D = /*#__PURE__*/ function(C) { } return D; }(C); -D.c = 2; -D.d = D.c + 1; -D.e = 1 + _get(_get_prototype_of(D), "a", D) + (D.c + 1) + 1; +(function() { + D.c = 2; +})(); +(function() { + D.d = D.c + 1; +})(); +(function() { + D.e = 1 + _get(_get_prototype_of(D), "a", D) + (D.c + 1) + 1; +})(); diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2015).1.normal.js index 1c369b70ff9d..e3df2f8c935b 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2015).1.normal.js @@ -1,26 +1,36 @@ //// [typeOfThisInStaticMembers8.ts] class C { } -C.f = 1; -C.arrowFunctionBoundary = ()=>C.f + 1; -C.functionExprBoundary = function() { - return this.f + 2; -}; -C.classExprBoundary = class { - constructor(){ - this.a = this.f + 3; - } -}; -C.functionAndClassDeclBoundary = (()=>{ - function foo() { - return this.f + 4; - } - class CC { - method() { - return this.f + 6; - } +(()=>{ + C.f = 1; +})(); +(()=>{ + C.arrowFunctionBoundary = ()=>C.f + 1; +})(); +(()=>{ + C.functionExprBoundary = function() { + return this.f + 2; + }; +})(); +(()=>{ + C.classExprBoundary = class { constructor(){ - this.a = this.f + 5; + this.a = this.f + 3; + } + }; +})(); +(()=>{ + C.functionAndClassDeclBoundary = (()=>{ + function foo() { + return this.f + 4; + } + class CC { + method() { + return this.f + 6; + } + constructor(){ + this.a = this.f + 5; + } } - } + })(); })(); diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2022).1.normal.js index bdbc8077c76a..dd2d1d3096fb 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2022).1.normal.js @@ -1,22 +1,36 @@ //// [typeOfThisInStaticMembers8.ts] class C { - static f = 1; - static arrowFunctionBoundary = ()=>this.f + 1; - static functionExprBoundary = function() { - return this.f + 2; - }; - static classExprBoundary = class { - a = this.f + 3; - }; - static functionAndClassDeclBoundary = (()=>{ - function foo() { - return this.f + 4; - } - class CC { - a = this.f + 5; - method() { - return this.f + 6; + static{ + this.f = 1; + } + static{ + this.arrowFunctionBoundary = ()=>this.f + 1; + } + static{ + this.functionExprBoundary = function() { + return this.f + 2; + }; + } + static{ + this.classExprBoundary = class { + constructor(){ + this.a = this.f + 3; } - } - })(); + }; + } + static{ + this.functionAndClassDeclBoundary = (()=>{ + function foo() { + return this.f + 4; + } + class CC { + method() { + return this.f + 6; + } + constructor(){ + this.a = this.f + 5; + } + } + })(); + } } diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2022).2.minified.js index 91b16c039369..5cccc6a3b677 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es2022).2.minified.js @@ -1,12 +1,24 @@ //// [typeOfThisInStaticMembers8.ts] class C { - static f = 1; - static arrowFunctionBoundary = ()=>this.f + 1; - static functionExprBoundary = function() { - return this.f + 2; - }; - static classExprBoundary = class { - a = this.f + 3; - }; - static functionAndClassDeclBoundary = void 0; + static{ + this.f = 1; + } + static{ + this.arrowFunctionBoundary = ()=>this.f + 1; + } + static{ + this.functionExprBoundary = function() { + return this.f + 2; + }; + } + static{ + this.classExprBoundary = class { + constructor(){ + this.a = this.f + 3; + } + }; + } + static{ + this.functionAndClassDeclBoundary = void 0; + } } diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es5).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es5).1.normal.js index 2c2506b91d62..d345078b9418 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers8(target=es5).1.normal.js @@ -4,32 +4,42 @@ var C = function C() { "use strict"; _class_call_check(this, C); }; -C.f = 1; -C.arrowFunctionBoundary = function() { - return C.f + 1; -}; -C.functionExprBoundary = function() { - return this.f + 2; -}; -C.classExprBoundary = function _class() { - "use strict"; - _class_call_check(this, _class); - this.a = this.f + 3; -}; -C.functionAndClassDeclBoundary = function() { - var foo = function foo() { - return this.f + 4; +(function() { + C.f = 1; +})(); +(function() { + C.arrowFunctionBoundary = function() { + return C.f + 1; + }; +})(); +(function() { + C.functionExprBoundary = function() { + return this.f + 2; }; - var CC = /*#__PURE__*/ function() { +})(); +(function() { + C.classExprBoundary = function _class() { "use strict"; - function CC() { - _class_call_check(this, CC); - this.a = this.f + 5; + _class_call_check(this, _class); + this.a = this.f + 3; + }; +})(); +(function() { + C.functionAndClassDeclBoundary = function() { + function foo() { + return this.f + 4; } - var _proto = CC.prototype; - _proto.method = function method() { - return this.f + 6; - }; - return CC; + var CC = /*#__PURE__*/ function() { + "use strict"; + function CC() { + _class_call_check(this, CC); + this.a = this.f + 5; + } + var _proto = CC.prototype; + _proto.method = function method() { + return this.f + 6; + }; + return CC; + }(); }(); -}(); +})(); diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2015).1.normal.js index 041ede61d8b6..5b206ed2fb88 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2015).1.normal.js @@ -3,28 +3,38 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C { } -C.f = 1; +(()=>{ + C.f = 1; +})(); class D extends C { } -D.arrowFunctionBoundary = ()=>_get(_get_prototype_of(D), "f", D) + 1; -D.functionExprBoundary = function() { - return _get(_get_prototype_of(D), "f", this) + 2; -}; -D.classExprBoundary = class { - constructor(){ - this.a = super.f + 3; - } -}; -D.functionAndClassDeclBoundary = (()=>{ - function foo() { - return _get(_get_prototype_of(D), "f", this) + 4; - } - class C { - method() { - return super.f + 6; - } +(()=>{ + D.arrowFunctionBoundary = ()=>_get(_get_prototype_of(D), "f", D) + 1; +})(); +(()=>{ + D.functionExprBoundary = function() { + return _get(_get_prototype_of(D), "f", this) + 2; + }; +})(); +(()=>{ + D.classExprBoundary = class { constructor(){ - this.a = super.f + 5; + this.a = super.f + 3; + } + }; +})(); +(()=>{ + D.functionAndClassDeclBoundary = (()=>{ + function foo() { + return _get(_get_prototype_of(D), "f", this) + 4; + } + class C { + method() { + return super.f + 6; + } + constructor(){ + this.a = super.f + 5; + } } - } + })(); })(); diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2022).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2022).1.normal.js index f3e66acbe17c..26532c041360 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2022).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2022).1.normal.js @@ -1,24 +1,38 @@ //// [typeOfThisInStaticMembers9.ts] class C { - static f = 1; + static{ + this.f = 1; + } } class D extends C { - static arrowFunctionBoundary = ()=>super.f + 1; - static functionExprBoundary = function() { - return super.f + 2; - }; - static classExprBoundary = class { - a = super.f + 3; - }; - static functionAndClassDeclBoundary = (()=>{ - function foo() { - return super.f + 4; - } - class C { - a = super.f + 5; - method() { - return super.f + 6; + static{ + this.arrowFunctionBoundary = ()=>super.f + 1; + } + static{ + this.functionExprBoundary = function() { + return super.f + 2; + }; + } + static{ + this.classExprBoundary = class { + constructor(){ + this.a = super.f + 3; } - } - })(); + }; + } + static{ + this.functionAndClassDeclBoundary = (()=>{ + function foo() { + return super.f + 4; + } + class C { + method() { + return super.f + 6; + } + constructor(){ + this.a = super.f + 5; + } + } + })(); + } } diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2022).2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2022).2.minified.js index 59ac42d9b857..9d7888da9637 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2022).2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es2022).2.minified.js @@ -1,14 +1,26 @@ //// [typeOfThisInStaticMembers9.ts] class C { - static f = 1; + static{ + this.f = 1; + } } class D extends C { - static arrowFunctionBoundary = ()=>super.f + 1; - static functionExprBoundary = function() { - return super.f + 2; - }; - static classExprBoundary = class { - a = super.f + 3; - }; - static functionAndClassDeclBoundary = void 0; + static{ + this.arrowFunctionBoundary = ()=>super.f + 1; + } + static{ + this.functionExprBoundary = function() { + return super.f + 2; + }; + } + static{ + this.classExprBoundary = class { + constructor(){ + this.a = super.f + 3; + } + }; + } + static{ + this.functionAndClassDeclBoundary = void 0; + } } diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es5).1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es5).1.normal.js index 7b371e9285bd..8bdc127d4b51 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9(target=es5).1.normal.js @@ -8,7 +8,9 @@ var C = function C() { "use strict"; _class_call_check(this, C); }; -C.f = 1; +(function() { + C.f = 1; +})(); var D = /*#__PURE__*/ function(C) { "use strict"; _inherits(D, C); @@ -19,31 +21,39 @@ var D = /*#__PURE__*/ function(C) { } return D; }(C); -D.arrowFunctionBoundary = function() { - return _get(_get_prototype_of(D), "f", D) + 1; -}; -D.functionExprBoundary = function() { - return _get(_get_prototype_of(D), "f", this) + 2; -}; -D.classExprBoundary = function _class() { - "use strict"; - _class_call_check(this, _class); - this.a = _get(_get_prototype_of(_class.prototype), "f", this) + 3; -}; -D.functionAndClassDeclBoundary = function() { - var foo = function foo() { - return _get(_get_prototype_of(D), "f", this) + 4; +(function() { + D.arrowFunctionBoundary = function() { + return _get(_get_prototype_of(D), "f", D) + 1; + }; +})(); +(function() { + D.functionExprBoundary = function() { + return _get(_get_prototype_of(D), "f", this) + 2; }; - var C = /*#__PURE__*/ function() { +})(); +(function() { + D.classExprBoundary = function _class() { "use strict"; - function C() { - _class_call_check(this, C); - this.a = _get(_get_prototype_of(C.prototype), "f", this) + 5; + _class_call_check(this, _class); + this.a = _get(_get_prototype_of(_class.prototype), "f", this) + 3; + }; +})(); +(function() { + D.functionAndClassDeclBoundary = function() { + function foo() { + return _get(_get_prototype_of(D), "f", this) + 4; } - var _proto = C.prototype; - _proto.method = function method() { - return _get(_get_prototype_of(C.prototype), "f", this) + 6; - }; - return C; + var C = /*#__PURE__*/ function() { + "use strict"; + function C() { + _class_call_check(this, C); + this.a = _get(_get_prototype_of(C.prototype), "f", this) + 5; + } + var _proto = C.prototype; + _proto.method = function method() { + return _get(_get_prototype_of(C.prototype), "f", this) + 6; + }; + return C; + }(); }(); -}(); +})(); diff --git a/crates/swc/tests/tsc-references/typeQueryOnClass.1.normal.js b/crates/swc/tests/tsc-references/typeQueryOnClass.1.normal.js index 48a3aa997a05..83763ac73aef 100644 --- a/crates/swc/tests/tsc-references/typeQueryOnClass.1.normal.js +++ b/crates/swc/tests/tsc-references/typeQueryOnClass.1.normal.js @@ -49,10 +49,14 @@ var C = /*#__PURE__*/ function() { ]); return C; }(); -C.sa = 1; -C.sb = function() { - return 1; -}; +(function() { + C.sa = 1; +})(); +(function() { + C.sb = function() { + return 1; + }; +})(); var c; // BUG 820454 var r1; diff --git a/crates/swc/tests/tsc-references/uniqueSymbols.1.normal.js b/crates/swc/tests/tsc-references/uniqueSymbols.1.normal.js index 9c8946afff04..0fb1feafc06c 100644 --- a/crates/swc/tests/tsc-references/uniqueSymbols.1.normal.js +++ b/crates/swc/tests/tsc-references/uniqueSymbols.1.normal.js @@ -74,11 +74,19 @@ async function* asyncGenFuncYieldVarCall() { } // classes class C { - static readonlyStaticCall = Symbol(); - static readonlyStaticTypeAndCall = Symbol(); - static readwriteStaticCall = Symbol(); - readonlyCall = Symbol(); - readwriteCall = Symbol(); + static{ + this.readonlyStaticCall = Symbol(); + } + static{ + this.readonlyStaticTypeAndCall = Symbol(); + } + static{ + this.readwriteStaticCall = Symbol(); + } + constructor(){ + this.readonlyCall = Symbol(); + this.readwriteCall = Symbol(); + } } const constInitToCReadonlyStaticCall = C.readonlyStaticCall; const constInitToCReadonlyStaticType = C.readonlyStaticType; @@ -146,18 +154,24 @@ const o2 = { }; // property initializers class C0 { - static a = s; - static b = N.s; - static c = N["s"]; - static d = s; - static e = N.s; - static f = N["s"]; - a = s; - b = N.s; - c = N["s"]; - d = s; - e = N.s; - f = N["s"]; + static{ + this.a = s; + } + static{ + this.b = N.s; + } + static{ + this.c = N["s"]; + } + static{ + this.d = s; + } + static{ + this.e = N.s; + } + static{ + this.f = N["s"]; + } method1() { return s; } @@ -173,6 +187,14 @@ class C0 { method5(p = s) { return p; } + constructor(){ + this.a = s; + this.b = N.s; + this.c = N["s"]; + this.d = s; + this.e = N.s; + this.f = N["s"]; + } } // non-widening positions // element access @@ -199,7 +221,12 @@ Math.random() * 2 ? N["s"] : "a"; [s]: "a", [N.s]: "b" }); +let prop, prop1; class C1 { + static{ + prop = N.s; + prop1 = N.s; + } } const o3 = { method1 () { diff --git a/crates/swc/tests/tsc-references/uniqueSymbols.2.minified.js b/crates/swc/tests/tsc-references/uniqueSymbols.2.minified.js index 6877e61c602d..150c1384a4b5 100644 --- a/crates/swc/tests/tsc-references/uniqueSymbols.2.minified.js +++ b/crates/swc/tests/tsc-references/uniqueSymbols.2.minified.js @@ -2,26 +2,39 @@ const constCall = Symbol(); Symbol(), Symbol(), Symbol(), constType, constType, constType, constType; class C { - static readonlyStaticCall = Symbol(); - static readonlyStaticTypeAndCall = Symbol(); - static readwriteStaticCall = Symbol(); - readonlyCall = Symbol(); - readwriteCall = Symbol(); + static{ + this.readonlyStaticCall = Symbol(); + } + static{ + this.readonlyStaticTypeAndCall = Symbol(); + } + static{ + this.readwriteStaticCall = Symbol(); + } + constructor(){ + this.readonlyCall = Symbol(), this.readwriteCall = Symbol(); + } } C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, i.readonlyType, i.readonlyType, i.readonlyType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, Promise.resolve(constCall), f(s), f(N.s), f(N.s), s, N.s, N.s, s, N.s, N.s, (p = s)=>p; class C0 { - static a = s; - static b = N.s; - static c = N.s; - static d = s; - static e = N.s; - static f = N.s; - a = s; - b = N.s; - c = N.s; - d = s; - e = N.s; - f = N.s; + static{ + this.a = s; + } + static{ + this.b = N.s; + } + static{ + this.c = N.s; + } + static{ + this.d = s; + } + static{ + this.e = N.s; + } + static{ + this.f = N.s; + } method1() { return s; } @@ -37,5 +50,13 @@ class C0 { method5(p = s) { return p; } + constructor(){ + this.a = s, this.b = N.s, this.c = N.s, this.d = s, this.e = N.s, this.f = N.s; + } } o[s], o[N.s], o[N.s], f(s), f(N.s), f(N.s), g(s), g(N.s), g(N.s), s, N.s, N.s, 2 * Math.random() && s, 2 * Math.random() && N.s, 2 * Math.random() && N.s, s, N.s; +class C1 { + static{ + N.s, N.s; + } +} diff --git a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations.1.normal.js b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations.1.normal.js index 97b8e0abd5a0..6ac03473085f 100644 --- a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations.1.normal.js +++ b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations.1.normal.js @@ -71,11 +71,19 @@ async function* asyncGenFuncYieldVarCall() { } // classes class C { - static readonlyStaticCall = Symbol(); - static readonlyStaticTypeAndCall = Symbol(); - static readwriteStaticCall = Symbol(); - readonlyCall = Symbol(); - readwriteCall = Symbol(); + static{ + this.readonlyStaticCall = Symbol(); + } + static{ + this.readonlyStaticTypeAndCall = Symbol(); + } + static{ + this.readwriteStaticCall = Symbol(); + } + constructor(){ + this.readonlyCall = Symbol(); + this.readwriteCall = Symbol(); + } } const constInitToCReadonlyStaticCall = C.readonlyStaticCall; const constInitToCReadonlyStaticType = C.readonlyStaticType; @@ -143,18 +151,24 @@ const o2 = { }; // property initializers class C0 { - static a = s; - static b = N.s; - static c = N["s"]; - static d = s; - static e = N.s; - static f = N["s"]; - a = s; - b = N.s; - c = N["s"]; - d = s; - e = N.s; - f = N["s"]; + static{ + this.a = s; + } + static{ + this.b = N.s; + } + static{ + this.c = N["s"]; + } + static{ + this.d = s; + } + static{ + this.e = N.s; + } + static{ + this.f = N["s"]; + } method1() { return s; } @@ -170,6 +184,14 @@ class C0 { method5(p = s) { return p; } + constructor(){ + this.a = s; + this.b = N.s; + this.c = N["s"]; + this.d = s; + this.e = N.s; + this.f = N["s"]; + } } // non-widening positions // element access @@ -196,7 +218,12 @@ Math.random() * 2 ? N["s"] : "a"; [s]: "a", [N.s]: "b" }); +let prop, prop1; class C1 { + static{ + prop = N.s; + prop1 = N.s; + } } const o4 = { method1 () { diff --git a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations.2.minified.js b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations.2.minified.js index 65073f33cc0e..3cd9279083ca 100644 --- a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations.2.minified.js +++ b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations.2.minified.js @@ -2,26 +2,39 @@ const constCall = Symbol(); Symbol(), Symbol(), Symbol(), constType, constType, constType, constType; class C { - static readonlyStaticCall = Symbol(); - static readonlyStaticTypeAndCall = Symbol(); - static readwriteStaticCall = Symbol(); - readonlyCall = Symbol(); - readwriteCall = Symbol(); + static{ + this.readonlyStaticCall = Symbol(); + } + static{ + this.readonlyStaticTypeAndCall = Symbol(); + } + static{ + this.readwriteStaticCall = Symbol(); + } + constructor(){ + this.readonlyCall = Symbol(), this.readwriteCall = Symbol(); + } } C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, i.readonlyType, i.readonlyType, i.readonlyType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, Promise.resolve(constCall), f(s), f(N.s), f(N.s), s, N.s, N.s, s, N.s, N.s, (p = s)=>p; class C0 { - static a = s; - static b = N.s; - static c = N.s; - static d = s; - static e = N.s; - static f = N.s; - a = s; - b = N.s; - c = N.s; - d = s; - e = N.s; - f = N.s; + static{ + this.a = s; + } + static{ + this.b = N.s; + } + static{ + this.c = N.s; + } + static{ + this.d = s; + } + static{ + this.e = N.s; + } + static{ + this.f = N.s; + } method1() { return s; } @@ -37,5 +50,13 @@ class C0 { method5(p = s) { return p; } + constructor(){ + this.a = s, this.b = N.s, this.c = N.s, this.d = s, this.e = N.s, this.f = N.s; + } } o[s], o[N.s], o[N.s], f(s), f(N.s), f(N.s), g(s), g(N.s), g(N.s), s, N.s, N.s, 2 * Math.random() && s, 2 * Math.random() && N.s, 2 * Math.random() && N.s, s, N.s; +class C1 { + static{ + N.s, N.s; + } +} diff --git a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs.1.normal.js b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs.1.normal.js index 92ba8551737e..bbd01fd59ecc 100644 --- a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs.1.normal.js +++ b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs.1.normal.js @@ -1,17 +1,25 @@ //// [uniqueSymbolsDeclarationsInJs.js] // classes class C { - /** + static{ + /** * @readonly - */ static readonlyStaticCall = Symbol(); - /** + */ this.readonlyStaticCall = Symbol(); + } + static{ + /** * @type {unique symbol} * @readonly - */ static readonlyStaticTypeAndCall = Symbol(); - static readwriteStaticCall = Symbol(); - /** + */ this.readonlyStaticTypeAndCall = Symbol(); + } + static{ + this.readwriteStaticCall = Symbol(); + } + constructor(){ + /** * @readonly - */ readonlyCall = Symbol(); - readwriteCall = Symbol(); + */ this.readonlyCall = Symbol(); + this.readwriteCall = Symbol(); + } } /** @type {unique symbol} */ const a = Symbol(); diff --git a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs.2.minified.js b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs.2.minified.js index 8628c54154f6..26a7e8892f03 100644 --- a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs.2.minified.js +++ b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs.2.minified.js @@ -1,9 +1,16 @@ //// [uniqueSymbolsDeclarationsInJs.js] class C { - static readonlyStaticCall = Symbol(); - static readonlyStaticTypeAndCall = Symbol(); - static readwriteStaticCall = Symbol(); - readonlyCall = Symbol(); - readwriteCall = Symbol(); + static{ + this.readonlyStaticCall = Symbol(); + } + static{ + this.readonlyStaticTypeAndCall = Symbol(); + } + static{ + this.readwriteStaticCall = Symbol(); + } + constructor(){ + this.readonlyCall = Symbol(), this.readwriteCall = Symbol(); + } } Symbol(); diff --git a/crates/swc/tests/tsc-references/variance.1.normal.js b/crates/swc/tests/tsc-references/variance.1.normal.js index 16f3be412a67..1afcf0c7d836 100644 --- a/crates/swc/tests/tsc-references/variance.1.normal.js +++ b/crates/swc/tests/tsc-references/variance.1.normal.js @@ -21,4 +21,6 @@ var Bar = /*#__PURE__*/ function() { }; return Bar; }(); -Bar.instance = []; +(function() { + Bar.instance = []; +})(); diff --git a/crates/swc/tests/tsc-references/witness.1.normal.js b/crates/swc/tests/tsc-references/witness.1.normal.js index c48eb628c53c..18fa5768840a 100644 --- a/crates/swc/tests/tsc-references/witness.1.normal.js +++ b/crates/swc/tests/tsc-references/witness.1.normal.js @@ -129,6 +129,8 @@ var C3 = function C3() { "use strict"; _class_call_check(this, C3); }; -C3.q = C3.q; +(function() { + C3.q = C3.q; +})(); var qq = C3.q; var qq; // Parentheses - tested a bunch above diff --git a/crates/swc/tests/vercel/full/react-autowhatever/1/output/index.js b/crates/swc/tests/vercel/full/react-autowhatever/1/output/index.js index 15b022c9d3a2..bdb7e1cea59f 100644 --- a/crates/swc/tests/vercel/full/react-autowhatever/1/output/index.js +++ b/crates/swc/tests/vercel/full/react-autowhatever/1/output/index.js @@ -4,61 +4,69 @@ Object.defineProperty(exports, "__esModule", { }), Object.defineProperty(exports, "default", { enumerable: !0, get: function() { - return c; + return p; } }); -var e = require("@swc/helpers/lib/_class_call_check.js").default, t = require("@swc/helpers/lib/_inherits.js").default, r = require("@swc/helpers/lib/_interop_require_default.js").default, i = require("@swc/helpers/lib/_interop_require_wildcard.js").default, n = require("@swc/helpers/lib/_object_spread.js").default, s = require("@swc/helpers/lib/_object_spread_props.js").default, u = require("@swc/helpers/lib/_create_super.js").default, d = require("react/jsx-runtime"), l = i(require("react")), a = r(require("prop-types")), c = function(r) { +var e = require("@swc/helpers/lib/_assert_this_initialized.js").default, t = require("@swc/helpers/lib/_class_call_check.js").default, r = require("@swc/helpers/lib/_create_class.js").default, i = require("@swc/helpers/lib/_define_property.js").default, s = require("@swc/helpers/lib/_inherits.js").default, n = require("@swc/helpers/lib/_interop_require_default.js").default, u = require("@swc/helpers/lib/_interop_require_wildcard.js").default, l = require("@swc/helpers/lib/_object_spread.js").default, d = require("@swc/helpers/lib/_object_spread_props.js").default, a = require("@swc/helpers/lib/_create_super.js").default, c = require("react/jsx-runtime"), o = u(require("react")), f = n(require("prop-types")), p = function(n) { "use strict"; - t(l, r); - var i = u(l); - function l() { - var t; - return e(this, l), t = i.apply(this, arguments), t.storeHighlightedItemReference = function(e) { - t.props.onHighlightedItemChange(null === e ? null : e.item); - }, t; + s(o, n); + var u = a(o); + function o() { + var r; + return t(this, o), r = u.apply(this, arguments), i(e(r), "storeHighlightedItemReference", function(e) { + r.props.onHighlightedItemChange(null === e ? null : e.item); + }), r; } - var a = l.prototype; - return a.shouldComponentUpdate = function(e) { - return !0; - }, a.render = function() { - var e = this, t = this.props, r = t.items, i = t.itemProps, u = t.renderItem, l = t.renderItemData, a = t.sectionIndex, c = t.highlightedItemIndex, o = t.getItemId, f = t.theme, p = t.keyPrefix, m = null === a ? p : "".concat(p, "section-").concat(a, "-"), h = "function" == typeof i; - return (0, d.jsx)("ul", s(n({ - role: "listbox" - }, f("".concat(m, "items-list"), "itemsList")), { - children: r.map(function(t, r) { - var p = r === c, I = "".concat(m, "item-").concat(r), g = h ? i({ - sectionIndex: a, - itemIndex: r - }) : i, q = n({ - id: o(a, r), - "aria-selected": p - }, f(I, "item", 0 === r && "itemFirst", p && "itemHighlighted"), g); - return p && (q.ref = e.storeHighlightedItemReference), (0, d.jsx)(Item, s(n({}, q), { - sectionIndex: a, - isHighlighted: p, - itemIndex: r, - item: t, - renderItem: u, - renderItemData: l + return r(o, [ + { + key: "shouldComponentUpdate", + value: function(e) { + return !0; + } + }, + { + key: "render", + value: function() { + var e = this, t = this.props, r = t.items, i = t.itemProps, s = t.renderItem, n = t.renderItemData, u = t.sectionIndex, a = t.highlightedItemIndex, o = t.getItemId, f = t.theme, p = t.keyPrefix, h = null === u ? p : "".concat(p, "section-").concat(u, "-"), m = "function" == typeof i; + return (0, c.jsx)("ul", d(l({ + role: "listbox" + }, f("".concat(h, "items-list"), "itemsList")), { + children: r.map(function(t, r) { + var p = r === a, I = "".concat(h, "item-").concat(r), _ = m ? i({ + sectionIndex: u, + itemIndex: r + }) : i, g = l({ + id: o(u, r), + "aria-selected": p + }, f(I, "item", 0 === r && "itemFirst", p && "itemHighlighted"), _); + return p && (g.ref = e.storeHighlightedItemReference), (0, c.jsx)(Item, d(l({}, g), { + sectionIndex: u, + isHighlighted: p, + itemIndex: r, + item: t, + renderItem: s, + renderItemData: n + })); + }) })); - }) - })); - }, l; -}(l.Component); -c.propTypes = { - items: a.default.array.isRequired, - itemProps: a.default.oneOfType([ - a.default.object, - a.default.func + } + } + ]), o; +}(o.Component); +i(p, "propTypes", { + items: f.default.array.isRequired, + itemProps: f.default.oneOfType([ + f.default.object, + f.default.func ]), - renderItem: a.default.func.isRequired, - renderItemData: a.default.object.isRequired, - sectionIndex: a.default.number, - highlightedItemIndex: a.default.number, - onHighlightedItemChange: a.default.func.isRequired, - getItemId: a.default.func.isRequired, - theme: a.default.func.isRequired, - keyPrefix: a.default.string.isRequired -}, c.defaultProps = { + renderItem: f.default.func.isRequired, + renderItemData: f.default.object.isRequired, + sectionIndex: f.default.number, + highlightedItemIndex: f.default.number, + onHighlightedItemChange: f.default.func.isRequired, + getItemId: f.default.func.isRequired, + theme: f.default.func.isRequired, + keyPrefix: f.default.string.isRequired +}), i(p, "defaultProps", { sectionIndex: null -}, new c(); +}), new p(); diff --git a/crates/swc/tests/vercel/full/react-autowhatever/2/output/index.js b/crates/swc/tests/vercel/full/react-autowhatever/2/output/index.js index 5c94c411fb47..a8bbef8df165 100644 --- a/crates/swc/tests/vercel/full/react-autowhatever/2/output/index.js +++ b/crates/swc/tests/vercel/full/react-autowhatever/2/output/index.js @@ -4,51 +4,59 @@ Object.defineProperty(exports, "__esModule", { }), Object.defineProperty(exports, "default", { enumerable: !0, get: function() { - return l; + return o; } }); -var e = require("@swc/helpers/lib/_class_call_check.js").default, t = require("@swc/helpers/lib/_inherits.js").default, r = require("@swc/helpers/lib/_interop_require_wildcard.js").default, i = require("@swc/helpers/lib/_object_spread.js").default, s = require("@swc/helpers/lib/_object_spread_props.js").default, n = require("@swc/helpers/lib/_create_super.js").default, c = require("react/jsx-runtime"), l = function(r) { +var e = require("@swc/helpers/lib/_assert_this_initialized.js").default, t = require("@swc/helpers/lib/_class_call_check.js").default, r = require("@swc/helpers/lib/_create_class.js").default, i = require("@swc/helpers/lib/_define_property.js").default, s = require("@swc/helpers/lib/_inherits.js").default, n = require("@swc/helpers/lib/_interop_require_wildcard.js").default, l = require("@swc/helpers/lib/_object_spread.js").default, c = require("@swc/helpers/lib/_object_spread_props.js").default, u = require("@swc/helpers/lib/_create_super.js").default, a = require("react/jsx-runtime"), o = function(n) { "use strict"; - t(o, r); - var l = n(o); - function o() { - var t; - return e(this, o), t = l.apply(this, arguments), t.storeHighlightedItemReference = function(e) { - t.props.onHighlightedItemChange(null === e ? null : e.item); - }, t; + s(d, n); + var o = u(d); + function d() { + var r; + return t(this, d), r = o.apply(this, arguments), i(e(r), "storeHighlightedItemReference", function(e) { + r.props.onHighlightedItemChange(null === e ? null : e.item); + }), r; } - var u = o.prototype; - return u.shouldComponentUpdate = function(e) { - return compareObjects(e, this.props, [ - "itemProps" - ]); - }, u.render = function() { - var e = this, t = this.props, r = t.items, n = t.itemProps, l = t.renderItem, o = t.renderItemData, u = t.sectionIndex, a = t.highlightedItemIndex, d = t.getItemId, p = t.theme, m = t.keyPrefix, h = null === u ? m : "".concat(m, "section-").concat(u, "-"), f = "function" == typeof n; - return (0, c.jsx)("ul", s(i({ - role: "listbox" - }, p("".concat(h, "items-list"), "itemsList")), { - children: r.map(function(t, r) { - var m = r === a, I = "".concat(h, "item-").concat(r), _ = f ? n({ - sectionIndex: u, - itemIndex: r - }) : n, g = i({ - id: d(u, r), - "aria-selected": m - }, p(I, "item", 0 === r && "itemFirst", m && "itemHighlighted"), _); - return m && (g.ref = e.storeHighlightedItemReference), (0, c.jsx)(Item, s(i({}, g), { - sectionIndex: u, - isHighlighted: m, - itemIndex: r, - item: t, - renderItem: l, - renderItemData: o + return r(d, [ + { + key: "shouldComponentUpdate", + value: function(e) { + return compareObjects(e, this.props, [ + "itemProps" + ]); + } + }, + { + key: "render", + value: function() { + var e = this, t = this.props, r = t.items, i = t.itemProps, s = t.renderItem, n = t.renderItemData, u = t.sectionIndex, o = t.highlightedItemIndex, d = t.getItemId, p = t.theme, h = t.keyPrefix, m = null === u ? h : "".concat(h, "section-").concat(u, "-"), f = "function" == typeof i; + return (0, a.jsx)("ul", c(l({ + role: "listbox" + }, p("".concat(m, "items-list"), "itemsList")), { + children: r.map(function(t, r) { + var h = r === o, _ = "".concat(m, "item-").concat(r), I = f ? i({ + sectionIndex: u, + itemIndex: r + }) : i, j = l({ + id: d(u, r), + "aria-selected": h + }, p(_, "item", 0 === r && "itemFirst", h && "itemHighlighted"), I); + return h && (j.ref = e.storeHighlightedItemReference), (0, a.jsx)(Item, c(l({}, j), { + sectionIndex: u, + isHighlighted: h, + itemIndex: r, + item: t, + renderItem: s, + renderItemData: n + })); + }) })); - }) - })); - }, o; -}(r(require("react")).Component); -l.propTypes = { + } + } + ]), d; +}(n(require("react")).Component); +i(o, "propTypes", { items: 500 -}, l.defaultProps = { +}), i(o, "defaultProps", { sectionIndex: null -}, new l(); +}), new o(); diff --git a/crates/swc/tests/vercel/loader-only/next-39460/output/snippetSession.js b/crates/swc/tests/vercel/loader-only/next-39460/output/snippetSession.js index babebf7a4542..499444081df7 100644 --- a/crates/swc/tests/vercel/loader-only/next-39460/output/snippetSession.js +++ b/crates/swc/tests/vercel/loader-only/next-39460/output/snippetSession.js @@ -31,328 +31,180 @@ export var OneSnippet = /*#__PURE__*/ function() { this._placeholderGroups = groupBy(_snippet.placeholders, Placeholder.compareByIndex); this._placeholderGroupsIdx = -1; } - var _proto = OneSnippet.prototype; - _proto.dispose = function dispose() { - if (this._placeholderDecorations) { - this._editor.deltaDecorations(_to_consumable_array(this._placeholderDecorations.values()), []); - } - this._placeholderGroups.length = 0; - }; - _proto._initDecorations = function _initDecorations() { - var _this = this; - if (this._placeholderDecorations) { - // already initialized - return; - } - this._placeholderDecorations = new Map(); - var model = this._editor.getModel(); - this._editor.changeDecorations(function(accessor) { - var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; - try { - // create a decoration for each placeholder - for(var _iterator = _this._snippet.placeholders[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ - var placeholder = _step.value; - var placeholderOffset = _this._snippet.offset(placeholder); - var placeholderLen = _this._snippet.fullLen(placeholder); - var range = Range.fromPositions(model.getPositionAt(_this._offset + placeholderOffset), model.getPositionAt(_this._offset + placeholderOffset + placeholderLen)); - var options = placeholder.isFinalTabstop ? OneSnippet._decor.inactiveFinal : OneSnippet._decor.inactive; - var handle = accessor.addDecoration(range, options); - _this._placeholderDecorations.set(placeholder, handle); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally{ - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally{ - if (_didIteratorError) { - throw _iteratorError; - } - } - } - }); - }; - _proto.move = function move(fwd) { - var _this = this; - if (!this._editor.hasModel()) { - return []; - } - this._initDecorations(); - // Transform placeholder text if necessary - if (this._placeholderGroupsIdx >= 0) { - var operations = []; - var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; - try { - for(var _iterator = this._placeholderGroups[this._placeholderGroupsIdx][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ - var placeholder = _step.value; - // Check if the placeholder has a transformation - if (placeholder.transform) { - var id = this._placeholderDecorations.get(placeholder); - var range = this._editor.getModel().getDecorationRange(id); - var currentValue = this._editor.getModel().getValueInRange(range); - var transformedValueLines = placeholder.transform.resolve(currentValue).split(/\r\n|\r|\n/); - // fix indentation for transformed lines - for(var i = 1; i < transformedValueLines.length; i++){ - transformedValueLines[i] = this._editor.getModel().normalizeIndentation(this._snippetLineLeadingWhitespace + transformedValueLines[i]); - } - operations.push(EditOperation.replace(range, transformedValueLines.join(this._editor.getModel().getEOL()))); - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally{ - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally{ - if (_didIteratorError) { - throw _iteratorError; - } + _create_class(OneSnippet, [ + { + key: "dispose", + value: function dispose() { + if (this._placeholderDecorations) { + this._editor.deltaDecorations(_to_consumable_array(this._placeholderDecorations.values()), []); } + this._placeholderGroups.length = 0; } - if (operations.length > 0) { - this._editor.executeEdits("snippet.placeholderTransform", operations); - } - } - var couldSkipThisPlaceholder = false; - if (fwd === true && this._placeholderGroupsIdx < this._placeholderGroups.length - 1) { - this._placeholderGroupsIdx += 1; - couldSkipThisPlaceholder = true; - } else if (fwd === false && this._placeholderGroupsIdx > 0) { - this._placeholderGroupsIdx -= 1; - couldSkipThisPlaceholder = true; - } else { - // the selection of the current placeholder might - // not acurate any more -> simply restore it - } - var newSelections = this._editor.getModel().changeDecorations(function(accessor) { - var activePlaceholders = new Set(); - // change stickiness to always grow when typing at its edges - // because these decorations represent the currently active - // tabstop. - // Special case #1: reaching the final tabstop - // Special case #2: placeholders enclosing active placeholders - var selections = []; - var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; - try { - for(var _iterator = _this._placeholderGroups[_this._placeholderGroupsIdx][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ - var placeholder = _step.value; - var id = _this._placeholderDecorations.get(placeholder); - var range = _this._editor.getModel().getDecorationRange(id); - selections.push(new Selection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn)); - // consider to skip this placeholder index when the decoration - // range is empty but when the placeholder wasn't. that's a strong - // hint that the placeholder has been deleted. (all placeholder must match this) - couldSkipThisPlaceholder = couldSkipThisPlaceholder && _this._hasPlaceholderBeenCollapsed(placeholder); - accessor.changeDecorationOptions(id, placeholder.isFinalTabstop ? OneSnippet._decor.activeFinal : OneSnippet._decor.active); - activePlaceholders.add(placeholder); - var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; + }, + { + key: "_initDecorations", + value: function _initDecorations() { + var _this = this; + if (this._placeholderDecorations) { + // already initialized + return; + } + this._placeholderDecorations = new Map(); + var model = this._editor.getModel(); + this._editor.changeDecorations(function(accessor) { + var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; try { - for(var _iterator1 = _this._snippet.enclosingPlaceholders(placeholder)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ - var enclosingPlaceholder = _step1.value; - var id1 = _this._placeholderDecorations.get(enclosingPlaceholder); - accessor.changeDecorationOptions(id1, enclosingPlaceholder.isFinalTabstop ? OneSnippet._decor.activeFinal : OneSnippet._decor.active); - activePlaceholders.add(enclosingPlaceholder); + // create a decoration for each placeholder + for(var _iterator = _this._snippet.placeholders[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ + var placeholder = _step.value; + var placeholderOffset = _this._snippet.offset(placeholder); + var placeholderLen = _this._snippet.fullLen(placeholder); + var range = Range.fromPositions(model.getPositionAt(_this._offset + placeholderOffset), model.getPositionAt(_this._offset + placeholderOffset + placeholderLen)); + var options = placeholder.isFinalTabstop ? OneSnippet._decor.inactiveFinal : OneSnippet._decor.inactive; + var handle = accessor.addDecoration(range, options); + _this._placeholderDecorations.set(placeholder, handle); } } catch (err) { - _didIteratorError1 = true; - _iteratorError1 = err; + _didIteratorError = true; + _iteratorError = err; } finally{ try { - if (!_iteratorNormalCompletion1 && _iterator1.return != null) { - _iterator1.return(); + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); } } finally{ - if (_didIteratorError1) { - throw _iteratorError1; + if (_didIteratorError) { + throw _iteratorError; } } } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally{ - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally{ - if (_didIteratorError) { - throw _iteratorError; - } - } - } - var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined; - try { - // change stickness to never grow when typing at its edges - // so that in-active tabstops never grow - for(var _iterator2 = _this._placeholderDecorations[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){ - var _step_value = _sliced_to_array(_step2.value, 2), placeholder1 = _step_value[0], id2 = _step_value[1]; - if (!activePlaceholders.has(placeholder1)) { - accessor.changeDecorationOptions(id2, placeholder1.isFinalTabstop ? OneSnippet._decor.inactiveFinal : OneSnippet._decor.inactive); - } - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally{ - try { - if (!_iteratorNormalCompletion2 && _iterator2.return != null) { - _iterator2.return(); - } - } finally{ - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - return selections; - }); - return !couldSkipThisPlaceholder ? newSelections !== null && newSelections !== void 0 ? newSelections : [] : this.move(fwd); - }; - _proto._hasPlaceholderBeenCollapsed = function _hasPlaceholderBeenCollapsed(placeholder) { - // A placeholder is empty when it wasn't empty when authored but - // when its tracking decoration is empty. This also applies to all - // potential parent placeholders - var marker = placeholder; - while(marker){ - if (_instanceof(marker, Placeholder)) { - var id = this._placeholderDecorations.get(marker); - var range = this._editor.getModel().getDecorationRange(id); - if (range.isEmpty() && marker.toString().length > 0) { - return true; - } + }); } - marker = marker.parent; - } - return false; - }; - _proto.computePossibleSelections = function computePossibleSelections() { - var result = new Map(); - var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; - try { - for(var _iterator = this._placeholderGroups[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ - var placeholdersWithEqualIndex = _step.value; - var ranges = void 0; - var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; - try { - for(var _iterator1 = placeholdersWithEqualIndex[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ - var placeholder = _step1.value; - if (placeholder.isFinalTabstop) { - break; - } - if (!ranges) { - ranges = []; - result.set(placeholder.index, ranges); - } - var id = this._placeholderDecorations.get(placeholder); - var range = this._editor.getModel().getDecorationRange(id); - if (!range) { - // one of the placeholder lost its decoration and - // therefore we bail out and pretend the placeholder - // (with its mirrors) doesn't exist anymore. - result.delete(placeholder.index); - break; - } - ranges.push(range); - } - } catch (err) { - _didIteratorError1 = true; - _iteratorError1 = err; - } finally{ + }, + { + key: "move", + value: function move(fwd) { + var _this = this; + if (!this._editor.hasModel()) { + return []; + } + this._initDecorations(); + // Transform placeholder text if necessary + if (this._placeholderGroupsIdx >= 0) { + var operations = []; + var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; try { - if (!_iteratorNormalCompletion1 && _iterator1.return != null) { - _iterator1.return(); + for(var _iterator = this._placeholderGroups[this._placeholderGroupsIdx][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ + var placeholder = _step.value; + // Check if the placeholder has a transformation + if (placeholder.transform) { + var id = this._placeholderDecorations.get(placeholder); + var range = this._editor.getModel().getDecorationRange(id); + var currentValue = this._editor.getModel().getValueInRange(range); + var transformedValueLines = placeholder.transform.resolve(currentValue).split(/\r\n|\r|\n/); + // fix indentation for transformed lines + for(var i = 1; i < transformedValueLines.length; i++){ + transformedValueLines[i] = this._editor.getModel().normalizeIndentation(this._snippetLineLeadingWhitespace + transformedValueLines[i]); + } + operations.push(EditOperation.replace(range, transformedValueLines.join(this._editor.getModel().getEOL()))); + } } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; } finally{ - if (_didIteratorError1) { - throw _iteratorError1; + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally{ + if (_didIteratorError) { + throw _iteratorError; + } } } + if (operations.length > 0) { + this._editor.executeEdits("snippet.placeholderTransform", operations); + } } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally{ - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally{ - if (_didIteratorError) { - throw _iteratorError; - } - } - } - return result; - }; - _proto.merge = function merge(others) { - var _this = this; - var model = this._editor.getModel(); - this._nestingLevel *= 10; - this._editor.changeDecorations(function(accessor) { - var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; - try { - // For each active placeholder take one snippet and merge it - // in that the placeholder (can be many for `$1foo$1foo`). Because - // everything is sorted by editor selection we can simply remove - // elements from the beginning of the array - for(var _iterator = _this._placeholderGroups[_this._placeholderGroupsIdx][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ - var placeholder = _step.value; - var nested = others.shift(); - console.assert(!nested._placeholderDecorations); - // Massage placeholder-indicies of the nested snippet to be - // sorted right after the insertion point. This ensures we move - // through the placeholders in the correct order - var indexLastPlaceholder = nested._snippet.placeholderInfo.last.index; - var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; + var couldSkipThisPlaceholder = false; + if (fwd === true && this._placeholderGroupsIdx < this._placeholderGroups.length - 1) { + this._placeholderGroupsIdx += 1; + couldSkipThisPlaceholder = true; + } else if (fwd === false && this._placeholderGroupsIdx > 0) { + this._placeholderGroupsIdx -= 1; + couldSkipThisPlaceholder = true; + } else { + // the selection of the current placeholder might + // not acurate any more -> simply restore it + } + var newSelections = this._editor.getModel().changeDecorations(function(accessor) { + var activePlaceholders = new Set(); + // change stickiness to always grow when typing at its edges + // because these decorations represent the currently active + // tabstop. + // Special case #1: reaching the final tabstop + // Special case #2: placeholders enclosing active placeholders + var selections = []; + var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; try { - for(var _iterator1 = nested._snippet.placeholderInfo.all[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ - var nestedPlaceholder = _step1.value; - if (nestedPlaceholder.isFinalTabstop) { - nestedPlaceholder.index = placeholder.index + (indexLastPlaceholder + 1) / _this._nestingLevel; - } else { - nestedPlaceholder.index = placeholder.index + nestedPlaceholder.index / _this._nestingLevel; + for(var _iterator = _this._placeholderGroups[_this._placeholderGroupsIdx][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ + var placeholder = _step.value; + var id = _this._placeholderDecorations.get(placeholder); + var range = _this._editor.getModel().getDecorationRange(id); + selections.push(new Selection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn)); + // consider to skip this placeholder index when the decoration + // range is empty but when the placeholder wasn't. that's a strong + // hint that the placeholder has been deleted. (all placeholder must match this) + couldSkipThisPlaceholder = couldSkipThisPlaceholder && _this._hasPlaceholderBeenCollapsed(placeholder); + accessor.changeDecorationOptions(id, placeholder.isFinalTabstop ? OneSnippet._decor.activeFinal : OneSnippet._decor.active); + activePlaceholders.add(placeholder); + var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; + try { + for(var _iterator1 = _this._snippet.enclosingPlaceholders(placeholder)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ + var enclosingPlaceholder = _step1.value; + var id1 = _this._placeholderDecorations.get(enclosingPlaceholder); + accessor.changeDecorationOptions(id1, enclosingPlaceholder.isFinalTabstop ? OneSnippet._decor.activeFinal : OneSnippet._decor.active); + activePlaceholders.add(enclosingPlaceholder); + } + } catch (err) { + _didIteratorError1 = true; + _iteratorError1 = err; + } finally{ + try { + if (!_iteratorNormalCompletion1 && _iterator1.return != null) { + _iterator1.return(); + } + } finally{ + if (_didIteratorError1) { + throw _iteratorError1; + } + } } } } catch (err) { - _didIteratorError1 = true; - _iteratorError1 = err; + _didIteratorError = true; + _iteratorError = err; } finally{ try { - if (!_iteratorNormalCompletion1 && _iterator1.return != null) { - _iterator1.return(); + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); } } finally{ - if (_didIteratorError1) { - throw _iteratorError1; + if (_didIteratorError) { + throw _iteratorError; } } } - _this._snippet.replace(placeholder, nested._snippet.children); - // Remove the placeholder at which position are inserting - // the snippet and also remove its decoration. - var id = _this._placeholderDecorations.get(placeholder); - accessor.removeDecoration(id); - _this._placeholderDecorations.delete(placeholder); var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined; try { - // For each *new* placeholder we create decoration to monitor - // how and if it grows/shrinks. - for(var _iterator2 = nested._snippet.placeholders[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){ - var placeholder1 = _step2.value; - var placeholderOffset = nested._snippet.offset(placeholder1); - var placeholderLen = nested._snippet.fullLen(placeholder1); - var range = Range.fromPositions(model.getPositionAt(nested._offset + placeholderOffset), model.getPositionAt(nested._offset + placeholderOffset + placeholderLen)); - var handle = accessor.addDecoration(range, OneSnippet._decor.inactive); - _this._placeholderDecorations.set(placeholder1, handle); + // change stickness to never grow when typing at its edges + // so that in-active tabstops never grow + for(var _iterator2 = _this._placeholderDecorations[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){ + var _step_value = _sliced_to_array(_step2.value, 2), placeholder1 = _step_value[0], id2 = _step_value[1]; + if (!activePlaceholders.has(placeholder1)) { + accessor.changeDecorationOptions(id2, placeholder1.isFinalTabstop ? OneSnippet._decor.inactiveFinal : OneSnippet._decor.inactive); + } } } catch (err) { _didIteratorError2 = true; @@ -368,26 +220,31 @@ export var OneSnippet = /*#__PURE__*/ function() { } } } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally{ - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally{ - if (_didIteratorError) { - throw _iteratorError; + return selections; + }); + return !couldSkipThisPlaceholder ? newSelections !== null && newSelections !== void 0 ? newSelections : [] : this.move(fwd); + } + }, + { + key: "_hasPlaceholderBeenCollapsed", + value: function _hasPlaceholderBeenCollapsed(placeholder) { + // A placeholder is empty when it wasn't empty when authored but + // when its tracking decoration is empty. This also applies to all + // potential parent placeholders + var marker = placeholder; + while(marker){ + if (_instanceof(marker, Placeholder)) { + var id = this._placeholderDecorations.get(marker); + var range = this._editor.getModel().getDecorationRange(id); + if (range.isEmpty() && marker.toString().length > 0) { + return true; + } } + marker = marker.parent; } + return false; } - // Last, re-create the placeholder groups by sorting placeholders by their index. - _this._placeholderGroups = groupBy(_this._snippet.placeholders, Placeholder.compareByIndex); - }); - }; - _create_class(OneSnippet, [ + }, { key: "isAtFirstPlaceholder", get: function get() { @@ -406,11 +263,171 @@ export var OneSnippet = /*#__PURE__*/ function() { return this._snippet.placeholders.length > 0; } }, + { + key: "computePossibleSelections", + value: function computePossibleSelections() { + var result = new Map(); + var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; + try { + for(var _iterator = this._placeholderGroups[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ + var placeholdersWithEqualIndex = _step.value; + var ranges = void 0; + var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; + try { + for(var _iterator1 = placeholdersWithEqualIndex[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ + var placeholder = _step1.value; + if (placeholder.isFinalTabstop) { + break; + } + if (!ranges) { + ranges = []; + result.set(placeholder.index, ranges); + } + var id = this._placeholderDecorations.get(placeholder); + var range = this._editor.getModel().getDecorationRange(id); + if (!range) { + // one of the placeholder lost its decoration and + // therefore we bail out and pretend the placeholder + // (with its mirrors) doesn't exist anymore. + result.delete(placeholder.index); + break; + } + ranges.push(range); + } + } catch (err) { + _didIteratorError1 = true; + _iteratorError1 = err; + } finally{ + try { + if (!_iteratorNormalCompletion1 && _iterator1.return != null) { + _iterator1.return(); + } + } finally{ + if (_didIteratorError1) { + throw _iteratorError1; + } + } + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally{ + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally{ + if (_didIteratorError) { + throw _iteratorError; + } + } + } + return result; + } + }, { key: "choice", get: function get() { return this._placeholderGroups[this._placeholderGroupsIdx][0].choice; } + }, + { + key: "merge", + value: function merge(others) { + var _this = this; + var model = this._editor.getModel(); + this._nestingLevel *= 10; + this._editor.changeDecorations(function(accessor) { + var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; + try { + // For each active placeholder take one snippet and merge it + // in that the placeholder (can be many for `$1foo$1foo`). Because + // everything is sorted by editor selection we can simply remove + // elements from the beginning of the array + for(var _iterator = _this._placeholderGroups[_this._placeholderGroupsIdx][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ + var placeholder = _step.value; + var nested = others.shift(); + console.assert(!nested._placeholderDecorations); + // Massage placeholder-indicies of the nested snippet to be + // sorted right after the insertion point. This ensures we move + // through the placeholders in the correct order + var indexLastPlaceholder = nested._snippet.placeholderInfo.last.index; + var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; + try { + for(var _iterator1 = nested._snippet.placeholderInfo.all[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ + var nestedPlaceholder = _step1.value; + if (nestedPlaceholder.isFinalTabstop) { + nestedPlaceholder.index = placeholder.index + (indexLastPlaceholder + 1) / _this._nestingLevel; + } else { + nestedPlaceholder.index = placeholder.index + nestedPlaceholder.index / _this._nestingLevel; + } + } + } catch (err) { + _didIteratorError1 = true; + _iteratorError1 = err; + } finally{ + try { + if (!_iteratorNormalCompletion1 && _iterator1.return != null) { + _iterator1.return(); + } + } finally{ + if (_didIteratorError1) { + throw _iteratorError1; + } + } + } + _this._snippet.replace(placeholder, nested._snippet.children); + // Remove the placeholder at which position are inserting + // the snippet and also remove its decoration. + var id = _this._placeholderDecorations.get(placeholder); + accessor.removeDecoration(id); + _this._placeholderDecorations.delete(placeholder); + var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined; + try { + // For each *new* placeholder we create decoration to monitor + // how and if it grows/shrinks. + for(var _iterator2 = nested._snippet.placeholders[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){ + var placeholder1 = _step2.value; + var placeholderOffset = nested._snippet.offset(placeholder1); + var placeholderLen = nested._snippet.fullLen(placeholder1); + var range = Range.fromPositions(model.getPositionAt(nested._offset + placeholderOffset), model.getPositionAt(nested._offset + placeholderOffset + placeholderLen)); + var handle = accessor.addDecoration(range, OneSnippet._decor.inactive); + _this._placeholderDecorations.set(placeholder1, handle); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally{ + try { + if (!_iteratorNormalCompletion2 && _iterator2.return != null) { + _iterator2.return(); + } + } finally{ + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally{ + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally{ + if (_didIteratorError) { + throw _iteratorError; + } + } + } + // Last, re-create the placeholder groups by sorting placeholders by their index. + _this._placeholderGroups = groupBy(_this._snippet.placeholders, Placeholder.compareByIndex); + }); + } } ]); return OneSnippet; @@ -455,166 +472,64 @@ export var SnippetSession = /*#__PURE__*/ function() { this._template = template; this._options = options; } - var _proto = SnippetSession.prototype; - _proto.dispose = function dispose1() { - dispose(this._snippets); - }; - _proto._logInfo = function _logInfo() { - return 'template="'.concat(this._template, '", merged_templates="').concat(this._templateMerges.join(" -> "), '"'); - }; - _proto.insert = function insert() { - var _this = this; - if (!this._editor.hasModel()) { - return; - } - // make insert edit and start with first selections - var _SnippetSession_createEditsAndSnippets = SnippetSession.createEditsAndSnippets(this._editor, this._template, this._options.overwriteBefore, this._options.overwriteAfter, false, this._options.adjustWhitespace, this._options.clipboardText, this._options.overtypingCapturer), edits = _SnippetSession_createEditsAndSnippets.edits, snippets = _SnippetSession_createEditsAndSnippets.snippets; - this._snippets = snippets; - this._editor.executeEdits("snippet", edits, function(undoEdits) { - if (_this._snippets[0].hasPlaceholder) { - return _this._move(true); - } else { - return undoEdits.filter(function(edit) { - return !!edit.identifier; - }) // only use our undo edits - .map(function(edit) { - return Selection.fromPositions(edit.range.getEndPosition()); - }); + _create_class(SnippetSession, [ + { + key: "dispose", + value: function dispose1() { + dispose(this._snippets); } - }); - this._editor.revealRange(this._editor.getSelections()[0]); - }; - _proto.merge = function merge(template) { - var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : _defaultOptions; - var _this = this; - if (!this._editor.hasModel()) { - return; - } - this._templateMerges.push([ - this._snippets[0]._nestingLevel, - this._snippets[0]._placeholderGroupsIdx, - template - ]); - var _SnippetSession_createEditsAndSnippets = SnippetSession.createEditsAndSnippets(this._editor, template, options.overwriteBefore, options.overwriteAfter, true, options.adjustWhitespace, options.clipboardText, options.overtypingCapturer), edits = _SnippetSession_createEditsAndSnippets.edits, snippets = _SnippetSession_createEditsAndSnippets.snippets; - this._editor.executeEdits("snippet", edits, function(undoEdits) { - var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; - try { - for(var _iterator = _this._snippets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ - var snippet = _step.value; - snippet.merge(snippets); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally{ - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally{ - if (_didIteratorError) { - throw _iteratorError; - } - } + }, + { + key: "_logInfo", + value: function _logInfo() { + return 'template="'.concat(this._template, '", merged_templates="').concat(this._templateMerges.join(" -> "), '"'); } - console.assert(snippets.length === 0); - if (_this._snippets[0].hasPlaceholder) { - return _this._move(undefined); - } else { - return undoEdits.filter(function(edit) { - return !!edit.identifier; - }) // only use our undo edits - .map(function(edit) { - return Selection.fromPositions(edit.range.getEndPosition()); + }, + { + key: "insert", + value: function insert() { + var _this = this; + if (!this._editor.hasModel()) { + return; + } + // make insert edit and start with first selections + var _SnippetSession_createEditsAndSnippets = SnippetSession.createEditsAndSnippets(this._editor, this._template, this._options.overwriteBefore, this._options.overwriteAfter, false, this._options.adjustWhitespace, this._options.clipboardText, this._options.overtypingCapturer), edits = _SnippetSession_createEditsAndSnippets.edits, snippets = _SnippetSession_createEditsAndSnippets.snippets; + this._snippets = snippets; + this._editor.executeEdits("snippet", edits, function(undoEdits) { + if (_this._snippets[0].hasPlaceholder) { + return _this._move(true); + } else { + return undoEdits.filter(function(edit) { + return !!edit.identifier; + }) // only use our undo edits + .map(function(edit) { + return Selection.fromPositions(edit.range.getEndPosition()); + }); + } }); + this._editor.revealRange(this._editor.getSelections()[0]); } - }); - }; - _proto.next = function next() { - var newSelections = this._move(true); - this._editor.setSelections(newSelections); - this._editor.revealPositionInCenterIfOutsideViewport(newSelections[0].getPosition()); - }; - _proto.prev = function prev() { - var newSelections = this._move(false); - this._editor.setSelections(newSelections); - this._editor.revealPositionInCenterIfOutsideViewport(newSelections[0].getPosition()); - }; - _proto._move = function _move(fwd) { - var selections = []; - var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; - try { - for(var _iterator = this._snippets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ - var snippet = _step.value; - var _selections; - var oneSelection = snippet.move(fwd); - (_selections = selections).push.apply(_selections, _to_consumable_array(oneSelection)); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally{ - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally{ - if (_didIteratorError) { - throw _iteratorError; - } - } - } - return selections; - }; - _proto.isSelectionWithinPlaceholders = function isSelectionWithinPlaceholders() { - if (!this.hasPlaceholder) { - return false; - } - var selections = this._editor.getSelections(); - if (selections.length < this._snippets.length) { - // this means we started snippet mode with N - // selections and have M (N > M) selections. - // So one snippet is without selection -> cancel - return false; - } - var allPossibleSelections = new Map(); - var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; - try { - var _loop = function() { - var snippet = _step.value; - var possibleSelections = snippet.computePossibleSelections(); - // for the first snippet find the placeholder (and its ranges) - // that contain at least one selection. for all remaining snippets - // the same placeholder (and their ranges) must be used. - if (allPossibleSelections.size === 0) { + }, + { + key: "merge", + value: function merge(template) { + var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : _defaultOptions; + var _this = this; + if (!this._editor.hasModel()) { + return; + } + this._templateMerges.push([ + this._snippets[0]._nestingLevel, + this._snippets[0]._placeholderGroupsIdx, + template + ]); + var _SnippetSession_createEditsAndSnippets = SnippetSession.createEditsAndSnippets(this._editor, template, options.overwriteBefore, options.overwriteAfter, true, options.adjustWhitespace, options.clipboardText, options.overtypingCapturer), edits = _SnippetSession_createEditsAndSnippets.edits, snippets = _SnippetSession_createEditsAndSnippets.snippets; + this._editor.executeEdits("snippet", edits, function(undoEdits) { var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; try { - for(var _iterator = possibleSelections[Symbol.iterator](), _step1; !(_iteratorNormalCompletion = (_step1 = _iterator.next()).done); _iteratorNormalCompletion = true){ - var _step_value = _sliced_to_array(_step1.value, 2), index = _step_value[0], ranges = _step_value[1]; - ranges.sort(Range.compareRangesUsingStarts); - var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; - try { - for(var _iterator1 = selections[Symbol.iterator](), _step2; !(_iteratorNormalCompletion1 = (_step2 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ - var selection = _step2.value; - if (ranges[0].containsRange(selection)) { - allPossibleSelections.set(index, []); - break; - } - } - } catch (err) { - _didIteratorError1 = true; - _iteratorError1 = err; - } finally{ - try { - if (!_iteratorNormalCompletion1 && _iterator1.return != null) { - _iterator1.return(); - } - } finally{ - if (_didIteratorError1) { - throw _iteratorError1; - } - } - } + for(var _iterator = _this._snippets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ + var snippet = _step.value; + snippet.merge(snippets); } } catch (err) { _didIteratorError = true; @@ -630,242 +545,65 @@ export var SnippetSession = /*#__PURE__*/ function() { } } } - } - if (allPossibleSelections.size === 0) { - // return false if we couldn't associate a selection to - // this (the first) snippet - return { - v: false - }; - } - // add selections from 'this' snippet so that we know all - // selections for this placeholder - allPossibleSelections.forEach(function(array, index) { - var _array; - (_array = array).push.apply(_array, _to_consumable_array(possibleSelections.get(index))); - }); - }; - for(var _iterator = this._snippets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ - var _ret = _loop(); - if (_type_of(_ret) === "object") return _ret.v; - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally{ - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally{ - if (_didIteratorError) { - throw _iteratorError; - } - } - } - // sort selections (and later placeholder-ranges). then walk both - // arrays and make sure the placeholder-ranges contain the corresponding - // selection - selections.sort(Range.compareRangesUsingStarts); - var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; - try { - for(var _iterator1 = allPossibleSelections[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ - var _step_value = _sliced_to_array(_step1.value, 2), index = _step_value[0], ranges = _step_value[1]; - if (ranges.length !== selections.length) { - allPossibleSelections.delete(index); - continue; - } - ranges.sort(Range.compareRangesUsingStarts); - for(var i = 0; i < ranges.length; i++){ - if (!ranges[i].containsRange(selections[i])) { - allPossibleSelections.delete(index); - continue; + console.assert(snippets.length === 0); + if (_this._snippets[0].hasPlaceholder) { + return _this._move(undefined); + } else { + return undoEdits.filter(function(edit) { + return !!edit.identifier; + }) // only use our undo edits + .map(function(edit) { + return Selection.fromPositions(edit.range.getEndPosition()); + }); } - } + }); } - } catch (err) { - _didIteratorError1 = true; - _iteratorError1 = err; - } finally{ - try { - if (!_iteratorNormalCompletion1 && _iterator1.return != null) { - _iterator1.return(); - } - } finally{ - if (_didIteratorError1) { - throw _iteratorError1; - } + }, + { + key: "next", + value: function next() { + var newSelections = this._move(true); + this._editor.setSelections(newSelections); + this._editor.revealPositionInCenterIfOutsideViewport(newSelections[0].getPosition()); } - } - // from all possible selections we have deleted those - // that don't match with the current selection. if we don't - // have any left, we don't have a selection anymore - return allPossibleSelections.size > 0; - }; - SnippetSession.adjustWhitespace = function adjustWhitespace(model, position, snippet, adjustIndentation, adjustNewlines) { - var line = model.getLineContent(position.lineNumber); - var lineLeadingWhitespace = getLeadingWhitespace(line, 0, position.column - 1); - // the snippet as inserted - var snippetTextString; - snippet.walk(function(marker) { - // all text elements that are not inside choice - if (!_instanceof(marker, Text) || _instanceof(marker.parent, Choice)) { - return true; + }, + { + key: "prev", + value: function prev() { + var newSelections = this._move(false); + this._editor.setSelections(newSelections); + this._editor.revealPositionInCenterIfOutsideViewport(newSelections[0].getPosition()); } - var lines = marker.value.split(/\r\n|\r|\n/); - if (adjustIndentation) { - // adjust indentation of snippet test - // -the snippet-start doesn't get extra-indented (lineLeadingWhitespace), only normalized - // -all N+1 lines get extra-indented and normalized - // -the text start get extra-indented and normalized when following a linebreak - var offset = snippet.offset(marker); - if (offset === 0) { - // snippet start - lines[0] = model.normalizeIndentation(lines[0]); - } else { - // check if text start is after a linebreak - snippetTextString = snippetTextString !== null && snippetTextString !== void 0 ? snippetTextString : snippet.toString(); - var prevChar = snippetTextString.charCodeAt(offset - 1); - if (prevChar === 10 /* LineFeed */ || prevChar === 13 /* CarriageReturn */ ) { - lines[0] = model.normalizeIndentation(lineLeadingWhitespace + lines[0]); + }, + { + key: "_move", + value: function _move(fwd) { + var selections = []; + var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; + try { + for(var _iterator = this._snippets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ + var snippet = _step.value; + var _selections; + var oneSelection = snippet.move(fwd); + (_selections = selections).push.apply(_selections, _to_consumable_array(oneSelection)); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally{ + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally{ + if (_didIteratorError) { + throw _iteratorError; + } } } - for(var i = 1; i < lines.length; i++){ - lines[i] = model.normalizeIndentation(lineLeadingWhitespace + lines[i]); - } - } - var newValue = lines.join(model.getEOL()); - if (newValue !== marker.value) { - marker.parent.replace(marker, [ - new Text(newValue) - ]); - snippetTextString = undefined; - } - return true; - }); - return lineLeadingWhitespace; - }; - SnippetSession.adjustSelection = function adjustSelection(model, selection, overwriteBefore, overwriteAfter) { - if (overwriteBefore !== 0 || overwriteAfter !== 0) { - // overwrite[Before|After] is compute using the position, not the whole - // selection. therefore we adjust the selection around that position - var positionLineNumber = selection.positionLineNumber, positionColumn = selection.positionColumn; - var positionColumnBefore = positionColumn - overwriteBefore; - var positionColumnAfter = positionColumn + overwriteAfter; - var range = model.validateRange({ - startLineNumber: positionLineNumber, - startColumn: positionColumnBefore, - endLineNumber: positionLineNumber, - endColumn: positionColumnAfter - }); - selection = Selection.createWithDirection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn, selection.getDirection()); - } - return selection; - }; - SnippetSession.createEditsAndSnippets = function createEditsAndSnippets(editor, template, overwriteBefore, overwriteAfter, enforceFinalTabstop, adjustWhitespace, clipboardText, overtypingCapturer) { - var edits = []; - var snippets = []; - if (!editor.hasModel()) { - return { - edits: edits, - snippets: snippets - }; - } - var model = editor.getModel(); - var workspaceService = editor.invokeWithinContext(function(accessor) { - return accessor.get(IWorkspaceContextService); - }); - var modelBasedVariableResolver = editor.invokeWithinContext(function(accessor) { - return new ModelBasedVariableResolver(accessor.get(ILabelService), model); - }); - var readClipboardText = function() { - return clipboardText; - }; - var delta = 0; - // know what text the overwrite[Before|After] extensions - // of the primary curser have selected because only when - // secondary selections extend to the same text we can grow them - var firstBeforeText = model.getValueInRange(SnippetSession.adjustSelection(model, editor.getSelection(), overwriteBefore, 0)); - var firstAfterText = model.getValueInRange(SnippetSession.adjustSelection(model, editor.getSelection(), 0, overwriteAfter)); - // remember the first non-whitespace column to decide if - // `keepWhitespace` should be overruled for secondary selections - var firstLineFirstNonWhitespace = model.getLineFirstNonWhitespaceColumn(editor.getSelection().positionLineNumber); - // sort selections by their start position but remeber - // the original index. that allows you to create correct - // offset-based selection logic without changing the - // primary selection - var indexedSelections = editor.getSelections().map(function(selection, idx) { - return { - selection: selection, - idx: idx - }; - }).sort(function(a, b) { - return Range.compareRangesUsingStarts(a.selection, b.selection); - }); - var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; - try { - for(var _iterator = indexedSelections[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ - var _step_value = _step.value, selection = _step_value.selection, idx = _step_value.idx; - // extend selection with the `overwriteBefore` and `overwriteAfter` and then - // compare if this matches the extensions of the primary selection - var extensionBefore = SnippetSession.adjustSelection(model, selection, overwriteBefore, 0); - var extensionAfter = SnippetSession.adjustSelection(model, selection, 0, overwriteAfter); - if (firstBeforeText !== model.getValueInRange(extensionBefore)) { - extensionBefore = selection; - } - if (firstAfterText !== model.getValueInRange(extensionAfter)) { - extensionAfter = selection; - } - // merge the before and after selection into one - var snippetSelection = selection.setStartPosition(extensionBefore.startLineNumber, extensionBefore.startColumn).setEndPosition(extensionAfter.endLineNumber, extensionAfter.endColumn); - var snippet = new SnippetParser().parse(template, true, enforceFinalTabstop); - // adjust the template string to match the indentation and - // whitespace rules of this insert location (can be different for each cursor) - // happens when being asked for (default) or when this is a secondary - // cursor and the leading whitespace is different - var start = snippetSelection.getStartPosition(); - var snippetLineLeadingWhitespace = SnippetSession.adjustWhitespace(model, start, snippet, adjustWhitespace || idx > 0 && firstLineFirstNonWhitespace !== model.getLineFirstNonWhitespaceColumn(selection.positionLineNumber), true); - snippet.resolveVariables(new CompositeSnippetVariableResolver([ - modelBasedVariableResolver, - new ClipboardBasedVariableResolver(readClipboardText, idx, indexedSelections.length, editor.getOption(70 /* multiCursorPaste */ ) === "spread"), - new SelectionBasedVariableResolver(model, selection, idx, overtypingCapturer), - new CommentBasedVariableResolver(model, selection), - new TimeBasedVariableResolver, - new WorkspaceBasedVariableResolver(workspaceService), - new RandomBasedVariableResolver - ])); - var offset = model.getOffsetAt(start) + delta; - delta += snippet.toString().length - model.getValueLengthInRange(snippetSelection); - // store snippets with the index of their originating selection. - // that ensures the primiary cursor stays primary despite not being - // the one with lowest start position - edits[idx] = EditOperation.replace(snippetSelection, snippet.toString()); - edits[idx].identifier = { - major: idx, - minor: 0 - }; // mark the edit so only our undo edits will be used to generate end cursors - snippets[idx] = new OneSnippet(editor, snippet, offset, snippetLineLeadingWhitespace); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally{ - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally{ - if (_didIteratorError) { - throw _iteratorError; - } + return selections; } - } - return { - edits: edits, - snippets: snippets - }; - }; - _create_class(SnippetSession, [ + }, { key: "isAtFirstPlaceholder", get: function get() { @@ -889,6 +627,318 @@ export var SnippetSession = /*#__PURE__*/ function() { get: function get() { return this._snippets[0].choice; } + }, + { + key: "isSelectionWithinPlaceholders", + value: function isSelectionWithinPlaceholders() { + if (!this.hasPlaceholder) { + return false; + } + var selections = this._editor.getSelections(); + if (selections.length < this._snippets.length) { + // this means we started snippet mode with N + // selections and have M (N > M) selections. + // So one snippet is without selection -> cancel + return false; + } + var allPossibleSelections = new Map(); + var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; + try { + var _loop = function() { + var snippet = _step.value; + var possibleSelections = snippet.computePossibleSelections(); + // for the first snippet find the placeholder (and its ranges) + // that contain at least one selection. for all remaining snippets + // the same placeholder (and their ranges) must be used. + if (allPossibleSelections.size === 0) { + var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; + try { + for(var _iterator = possibleSelections[Symbol.iterator](), _step1; !(_iteratorNormalCompletion = (_step1 = _iterator.next()).done); _iteratorNormalCompletion = true){ + var _step_value = _sliced_to_array(_step1.value, 2), index = _step_value[0], ranges = _step_value[1]; + ranges.sort(Range.compareRangesUsingStarts); + var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; + try { + for(var _iterator1 = selections[Symbol.iterator](), _step2; !(_iteratorNormalCompletion1 = (_step2 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ + var selection = _step2.value; + if (ranges[0].containsRange(selection)) { + allPossibleSelections.set(index, []); + break; + } + } + } catch (err) { + _didIteratorError1 = true; + _iteratorError1 = err; + } finally{ + try { + if (!_iteratorNormalCompletion1 && _iterator1.return != null) { + _iterator1.return(); + } + } finally{ + if (_didIteratorError1) { + throw _iteratorError1; + } + } + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally{ + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally{ + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } + if (allPossibleSelections.size === 0) { + // return false if we couldn't associate a selection to + // this (the first) snippet + return { + v: false + }; + } + // add selections from 'this' snippet so that we know all + // selections for this placeholder + allPossibleSelections.forEach(function(array, index) { + var _array; + (_array = array).push.apply(_array, _to_consumable_array(possibleSelections.get(index))); + }); + }; + for(var _iterator = this._snippets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ + var _ret = _loop(); + if (_type_of(_ret) === "object") return _ret.v; + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally{ + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally{ + if (_didIteratorError) { + throw _iteratorError; + } + } + } + // sort selections (and later placeholder-ranges). then walk both + // arrays and make sure the placeholder-ranges contain the corresponding + // selection + selections.sort(Range.compareRangesUsingStarts); + var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; + try { + for(var _iterator1 = allPossibleSelections[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ + var _step_value = _sliced_to_array(_step1.value, 2), index = _step_value[0], ranges = _step_value[1]; + if (ranges.length !== selections.length) { + allPossibleSelections.delete(index); + continue; + } + ranges.sort(Range.compareRangesUsingStarts); + for(var i = 0; i < ranges.length; i++){ + if (!ranges[i].containsRange(selections[i])) { + allPossibleSelections.delete(index); + continue; + } + } + } + } catch (err) { + _didIteratorError1 = true; + _iteratorError1 = err; + } finally{ + try { + if (!_iteratorNormalCompletion1 && _iterator1.return != null) { + _iterator1.return(); + } + } finally{ + if (_didIteratorError1) { + throw _iteratorError1; + } + } + } + // from all possible selections we have deleted those + // that don't match with the current selection. if we don't + // have any left, we don't have a selection anymore + return allPossibleSelections.size > 0; + } + } + ], [ + { + key: "adjustWhitespace", + value: function adjustWhitespace(model, position, snippet, adjustIndentation, adjustNewlines) { + var line = model.getLineContent(position.lineNumber); + var lineLeadingWhitespace = getLeadingWhitespace(line, 0, position.column - 1); + // the snippet as inserted + var snippetTextString; + snippet.walk(function(marker) { + // all text elements that are not inside choice + if (!_instanceof(marker, Text) || _instanceof(marker.parent, Choice)) { + return true; + } + var lines = marker.value.split(/\r\n|\r|\n/); + if (adjustIndentation) { + // adjust indentation of snippet test + // -the snippet-start doesn't get extra-indented (lineLeadingWhitespace), only normalized + // -all N+1 lines get extra-indented and normalized + // -the text start get extra-indented and normalized when following a linebreak + var offset = snippet.offset(marker); + if (offset === 0) { + // snippet start + lines[0] = model.normalizeIndentation(lines[0]); + } else { + // check if text start is after a linebreak + snippetTextString = snippetTextString !== null && snippetTextString !== void 0 ? snippetTextString : snippet.toString(); + var prevChar = snippetTextString.charCodeAt(offset - 1); + if (prevChar === 10 /* LineFeed */ || prevChar === 13 /* CarriageReturn */ ) { + lines[0] = model.normalizeIndentation(lineLeadingWhitespace + lines[0]); + } + } + for(var i = 1; i < lines.length; i++){ + lines[i] = model.normalizeIndentation(lineLeadingWhitespace + lines[i]); + } + } + var newValue = lines.join(model.getEOL()); + if (newValue !== marker.value) { + marker.parent.replace(marker, [ + new Text(newValue) + ]); + snippetTextString = undefined; + } + return true; + }); + return lineLeadingWhitespace; + } + }, + { + key: "adjustSelection", + value: function adjustSelection(model, selection, overwriteBefore, overwriteAfter) { + if (overwriteBefore !== 0 || overwriteAfter !== 0) { + // overwrite[Before|After] is compute using the position, not the whole + // selection. therefore we adjust the selection around that position + var positionLineNumber = selection.positionLineNumber, positionColumn = selection.positionColumn; + var positionColumnBefore = positionColumn - overwriteBefore; + var positionColumnAfter = positionColumn + overwriteAfter; + var range = model.validateRange({ + startLineNumber: positionLineNumber, + startColumn: positionColumnBefore, + endLineNumber: positionLineNumber, + endColumn: positionColumnAfter + }); + selection = Selection.createWithDirection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn, selection.getDirection()); + } + return selection; + } + }, + { + key: "createEditsAndSnippets", + value: function createEditsAndSnippets(editor, template, overwriteBefore, overwriteAfter, enforceFinalTabstop, adjustWhitespace, clipboardText, overtypingCapturer) { + var edits = []; + var snippets = []; + if (!editor.hasModel()) { + return { + edits: edits, + snippets: snippets + }; + } + var model = editor.getModel(); + var workspaceService = editor.invokeWithinContext(function(accessor) { + return accessor.get(IWorkspaceContextService); + }); + var modelBasedVariableResolver = editor.invokeWithinContext(function(accessor) { + return new ModelBasedVariableResolver(accessor.get(ILabelService), model); + }); + var readClipboardText = function() { + return clipboardText; + }; + var delta = 0; + // know what text the overwrite[Before|After] extensions + // of the primary curser have selected because only when + // secondary selections extend to the same text we can grow them + var firstBeforeText = model.getValueInRange(SnippetSession.adjustSelection(model, editor.getSelection(), overwriteBefore, 0)); + var firstAfterText = model.getValueInRange(SnippetSession.adjustSelection(model, editor.getSelection(), 0, overwriteAfter)); + // remember the first non-whitespace column to decide if + // `keepWhitespace` should be overruled for secondary selections + var firstLineFirstNonWhitespace = model.getLineFirstNonWhitespaceColumn(editor.getSelection().positionLineNumber); + // sort selections by their start position but remeber + // the original index. that allows you to create correct + // offset-based selection logic without changing the + // primary selection + var indexedSelections = editor.getSelections().map(function(selection, idx) { + return { + selection: selection, + idx: idx + }; + }).sort(function(a, b) { + return Range.compareRangesUsingStarts(a.selection, b.selection); + }); + var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; + try { + for(var _iterator = indexedSelections[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ + var _step_value = _step.value, selection = _step_value.selection, idx = _step_value.idx; + // extend selection with the `overwriteBefore` and `overwriteAfter` and then + // compare if this matches the extensions of the primary selection + var extensionBefore = SnippetSession.adjustSelection(model, selection, overwriteBefore, 0); + var extensionAfter = SnippetSession.adjustSelection(model, selection, 0, overwriteAfter); + if (firstBeforeText !== model.getValueInRange(extensionBefore)) { + extensionBefore = selection; + } + if (firstAfterText !== model.getValueInRange(extensionAfter)) { + extensionAfter = selection; + } + // merge the before and after selection into one + var snippetSelection = selection.setStartPosition(extensionBefore.startLineNumber, extensionBefore.startColumn).setEndPosition(extensionAfter.endLineNumber, extensionAfter.endColumn); + var snippet = new SnippetParser().parse(template, true, enforceFinalTabstop); + // adjust the template string to match the indentation and + // whitespace rules of this insert location (can be different for each cursor) + // happens when being asked for (default) or when this is a secondary + // cursor and the leading whitespace is different + var start = snippetSelection.getStartPosition(); + var snippetLineLeadingWhitespace = SnippetSession.adjustWhitespace(model, start, snippet, adjustWhitespace || idx > 0 && firstLineFirstNonWhitespace !== model.getLineFirstNonWhitespaceColumn(selection.positionLineNumber), true); + snippet.resolveVariables(new CompositeSnippetVariableResolver([ + modelBasedVariableResolver, + new ClipboardBasedVariableResolver(readClipboardText, idx, indexedSelections.length, editor.getOption(70 /* multiCursorPaste */ ) === "spread"), + new SelectionBasedVariableResolver(model, selection, idx, overtypingCapturer), + new CommentBasedVariableResolver(model, selection), + new TimeBasedVariableResolver, + new WorkspaceBasedVariableResolver(workspaceService), + new RandomBasedVariableResolver + ])); + var offset = model.getOffsetAt(start) + delta; + delta += snippet.toString().length - model.getValueLengthInRange(snippetSelection); + // store snippets with the index of their originating selection. + // that ensures the primiary cursor stays primary despite not being + // the one with lowest start position + edits[idx] = EditOperation.replace(snippetSelection, snippet.toString()); + edits[idx].identifier = { + major: idx, + minor: 0 + }; // mark the edit so only our undo edits will be used to generate end cursors + snippets[idx] = new OneSnippet(editor, snippet, offset, snippetLineLeadingWhitespace); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally{ + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally{ + if (_didIteratorError) { + throw _iteratorError; + } + } + } + return { + edits: edits, + snippets: snippets + }; + } } ]); return SnippetSession; diff --git a/crates/swc/tests/vercel/loader-only/react-autowhatever/1/output/index.js b/crates/swc/tests/vercel/loader-only/react-autowhatever/1/output/index.js index 3ee1d4440b6d..b3805d609c20 100644 --- a/crates/swc/tests/vercel/loader-only/react-autowhatever/1/output/index.js +++ b/crates/swc/tests/vercel/loader-only/react-autowhatever/1/output/index.js @@ -1,4 +1,7 @@ +import _assert_this_initialized from "@swc/helpers/src/_assert_this_initialized.mjs"; import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _create_class from "@swc/helpers/src/_create_class.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; import _inherits from "@swc/helpers/src/_inherits.mjs"; import _object_spread from "@swc/helpers/src/_object_spread.mjs"; import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs"; @@ -16,55 +19,62 @@ var ItemsList = /*#__PURE__*/ function(Component) { _class_call_check(this, ItemsList); var _this; _this = _super.apply(this, arguments); - _this.storeHighlightedItemReference = function(highlightedItem) { + _define_property(_assert_this_initialized(_this), "storeHighlightedItemReference", function(highlightedItem) { _this.props.onHighlightedItemChange(highlightedItem === null ? null : highlightedItem.item); - }; + }); return _this; } - var _proto = ItemsList.prototype; - _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { - return compareObjects(nextProps, this.props, [ - "itemProps" - ]); - }; - _proto.render = function render() { - var _this = this; - var _this_props = this.props, items = _this_props.items, itemProps = _this_props.itemProps, renderItem = _this_props.renderItem, renderItemData = _this_props.renderItemData, sectionIndex = _this_props.sectionIndex, highlightedItemIndex = _this_props.highlightedItemIndex, getItemId = _this_props.getItemId, theme = _this_props.theme, keyPrefix = _this_props.keyPrefix; - var sectionPrefix = sectionIndex === null ? keyPrefix : "".concat(keyPrefix, "section-").concat(sectionIndex, "-"); - var isItemPropsFunction = typeof itemProps === "function"; - return /*#__PURE__*/ _jsx("ul", _object_spread_props(_object_spread({ - role: "listbox" - }, theme("".concat(sectionPrefix, "items-list"), "itemsList")), { - children: items.map(function(item, itemIndex) { - var isFirst = itemIndex === 0; - var isHighlighted = itemIndex === highlightedItemIndex; - var itemKey = "".concat(sectionPrefix, "item-").concat(itemIndex); - var itemPropsObj = isItemPropsFunction ? itemProps({ - sectionIndex: sectionIndex, - itemIndex: itemIndex - }) : itemProps; - var allItemProps = _object_spread({ - id: getItemId(sectionIndex, itemIndex), - "aria-selected": isHighlighted - }, theme(itemKey, "item", isFirst && "itemFirst", isHighlighted && "itemHighlighted"), itemPropsObj); - if (isHighlighted) { - allItemProps.ref = _this.storeHighlightedItemReference; - } - // `key` is provided by theme() - /* eslint-disable react/jsx-key */ return /*#__PURE__*/ _jsx(Item, _object_spread_props(_object_spread({}, allItemProps), { - sectionIndex: sectionIndex, - isHighlighted: isHighlighted, - itemIndex: itemIndex, - item: item, - renderItem: renderItem, - renderItemData: renderItemData + _create_class(ItemsList, [ + { + key: "shouldComponentUpdate", + value: function shouldComponentUpdate(nextProps) { + return compareObjects(nextProps, this.props, [ + "itemProps" + ]); + } + }, + { + key: "render", + value: function render() { + var _this = this; + var _this_props = this.props, items = _this_props.items, itemProps = _this_props.itemProps, renderItem = _this_props.renderItem, renderItemData = _this_props.renderItemData, sectionIndex = _this_props.sectionIndex, highlightedItemIndex = _this_props.highlightedItemIndex, getItemId = _this_props.getItemId, theme = _this_props.theme, keyPrefix = _this_props.keyPrefix; + var sectionPrefix = sectionIndex === null ? keyPrefix : "".concat(keyPrefix, "section-").concat(sectionIndex, "-"); + var isItemPropsFunction = typeof itemProps === "function"; + return /*#__PURE__*/ _jsx("ul", _object_spread_props(_object_spread({ + role: "listbox" + }, theme("".concat(sectionPrefix, "items-list"), "itemsList")), { + children: items.map(function(item, itemIndex) { + var isFirst = itemIndex === 0; + var isHighlighted = itemIndex === highlightedItemIndex; + var itemKey = "".concat(sectionPrefix, "item-").concat(itemIndex); + var itemPropsObj = isItemPropsFunction ? itemProps({ + sectionIndex: sectionIndex, + itemIndex: itemIndex + }) : itemProps; + var allItemProps = _object_spread({ + id: getItemId(sectionIndex, itemIndex), + "aria-selected": isHighlighted + }, theme(itemKey, "item", isFirst && "itemFirst", isHighlighted && "itemHighlighted"), itemPropsObj); + if (isHighlighted) { + allItemProps.ref = _this.storeHighlightedItemReference; + } + // `key` is provided by theme() + /* eslint-disable react/jsx-key */ return /*#__PURE__*/ _jsx(Item, _object_spread_props(_object_spread({}, allItemProps), { + sectionIndex: sectionIndex, + isHighlighted: isHighlighted, + itemIndex: itemIndex, + item: item, + renderItem: renderItem, + renderItemData: renderItemData + })); + /* eslint-enable react/jsx-key */ }) })); - /* eslint-enable react/jsx-key */ }) - })); - }; + } + } + ]); return ItemsList; }(Component); -ItemsList.propTypes = { +_define_property(ItemsList, "propTypes", { items: PropTypes.array.isRequired, itemProps: PropTypes.oneOfType([ PropTypes.object, @@ -78,8 +88,8 @@ ItemsList.propTypes = { getItemId: PropTypes.func.isRequired, theme: PropTypes.func.isRequired, keyPrefix: PropTypes.string.isRequired -}; -ItemsList.defaultProps = { +}); +_define_property(ItemsList, "defaultProps", { sectionIndex: null -}; +}); export { ItemsList as default }; diff --git a/crates/swc/tests/vercel/loader-only/regressions/1/full/output/index.js b/crates/swc/tests/vercel/loader-only/regressions/1/full/output/index.js index 92a74320c890..30808fa8c552 100644 --- a/crates/swc/tests/vercel/loader-only/regressions/1/full/output/index.js +++ b/crates/swc/tests/vercel/loader-only/regressions/1/full/output/index.js @@ -1,5 +1,6 @@ import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; import { useEffect } from "react"; @@ -7,7 +8,7 @@ var Test = function Test(name) { "use strict"; _class_call_check(this, Test); var _this = this; - this.print = function() { + _define_property(this, "print", function() { var _ref = _async_to_generator(function(arg) { return _ts_generator(this, function(_state) { console.log(_this.name, arg); @@ -19,7 +20,7 @@ var Test = function Test(name) { return function(arg) { return _ref.apply(this, arguments); }; - }(); + }()); this.name = name; }; export default function Parent() { diff --git a/crates/swc/tests/vercel/loader-only/regressions/1/simplified/output/index.js b/crates/swc/tests/vercel/loader-only/regressions/1/simplified/output/index.js index 891d895486e8..97afb39bdd0a 100644 --- a/crates/swc/tests/vercel/loader-only/regressions/1/simplified/output/index.js +++ b/crates/swc/tests/vercel/loader-only/regressions/1/simplified/output/index.js @@ -1,11 +1,12 @@ import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import _define_property from "@swc/helpers/src/_define_property.mjs"; import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; var Test = function Test(name) { "use strict"; _class_call_check(this, Test); var _this = this; - this.print = function() { + _define_property(this, "print", function() { var _ref = _async_to_generator(function(arg) { return _ts_generator(this, function(_state) { console.log(_this.name, arg); @@ -17,7 +18,7 @@ var Test = function Test(name) { return function(arg) { return _ref.apply(this, arguments); }; - }(); + }()); this.name = name; }; function Parent() { diff --git a/crates/swc_bundler/tests/fixture/deno-9220/case1/output/entry.inlined.ts b/crates/swc_bundler/tests/fixture/deno-9220/case1/output/entry.inlined.ts index e8a41595a8f8..4a82270ffa06 100644 --- a/crates/swc_bundler/tests/fixture/deno-9220/case1/output/entry.inlined.ts +++ b/crates/swc_bundler/tests/fixture/deno-9220/case1/output/entry.inlined.ts @@ -1,4 +1,7 @@ class Image { + width; + height; + data; getPixel(x, y) { const index = x + y * this.width; const rntVal = { diff --git a/crates/swc_bundler/tests/fixture/deno-9220/case1/output/entry.ts b/crates/swc_bundler/tests/fixture/deno-9220/case1/output/entry.ts index e8a41595a8f8..4a82270ffa06 100644 --- a/crates/swc_bundler/tests/fixture/deno-9220/case1/output/entry.ts +++ b/crates/swc_bundler/tests/fixture/deno-9220/case1/output/entry.ts @@ -1,4 +1,7 @@ class Image { + width; + height; + data; getPixel(x, y) { const index = x + y * this.width; const rntVal = { diff --git a/crates/swc_bundler/tests/fixture/deno-9591/output/entry.inlined.ts b/crates/swc_bundler/tests/fixture/deno-9591/output/entry.inlined.ts index 304518515b96..04d2eccb57aa 100644 --- a/crates/swc_bundler/tests/fixture/deno-9591/output/entry.inlined.ts +++ b/crates/swc_bundler/tests/fixture/deno-9591/output/entry.inlined.ts @@ -1655,8 +1655,12 @@ function getLevelName(level) { throw new Error(`no level name found for level: ${level}`); } class LogRecord { + msg; #args; #datetime; + level; + levelName; + loggerName; constructor(options){ this.msg = options.msg; this.#args = [ @@ -1824,6 +1828,7 @@ function copyBytes(src, dst, off = 0) { } const DEFAULT_BUF_SIZE = 4096; class AbstractBufBase { + buf; usedBufferBytes = 0; err = null; size() { @@ -1837,6 +1842,7 @@ class AbstractBufBase { } } class BufWriterSync extends AbstractBufBase { + writer; static create(writer, size = 4096) { return writer instanceof BufWriterSync ? writer : new BufWriterSync(writer, size); } @@ -1894,6 +1900,9 @@ class BufWriterSync extends AbstractBufBase { } const DEFAULT_FORMATTER = "{levelName} {msg}"; class BaseHandler { + level; + levelName; + formatter; constructor(levelName, options = {}){ this.level = getLevelByName(levelName); this.levelName = levelName; @@ -1946,9 +1955,15 @@ class ConsoleHandler extends BaseHandler { } } class WriterHandler extends BaseHandler { + _writer; #encoder = new TextEncoder(); } class FileHandler extends WriterHandler { + _file; + _buf; + _filename; + _mode; + _openOptions; _encoder = new TextEncoder(); #unloadCallback = ()=>this.destroy(); constructor(levelName, options){ @@ -2052,6 +2067,8 @@ class RotatingFileHandler extends FileHandler { } } class LoggerConfig { + level; + handlers; } const DEFAULT_LEVEL = "INFO"; const DEFAULT_CONFIG = { @@ -3182,6 +3199,15 @@ function clean(version, optionsOrLoose) { return s ? s.version : null; } class SemVer { + raw; + loose; + options; + major; + minor; + patch; + version; + build; + prerelease; constructor(version, optionsOrLoose){ if (!optionsOrLoose || typeof optionsOrLoose !== "object") { optionsOrLoose = { @@ -3530,6 +3556,11 @@ function cmp(v1, operator, v2, optionsOrLoose) { } const ANY = {}; class Comparator { + semver; + operator; + value; + loose; + options; constructor(comp, optionsOrLoose){ if (!optionsOrLoose || typeof optionsOrLoose !== "object") { optionsOrLoose = { @@ -3619,6 +3650,12 @@ class Comparator { } } class Range { + range; + raw; + loose; + options; + includePrerelease; + set; constructor(range, optionsOrLoose){ if (!optionsOrLoose || typeof optionsOrLoose !== "object") { optionsOrLoose = { @@ -5243,6 +5280,8 @@ const ADL = { }; const RESOLVER = declResolver(ADL); class ADLMap { + data; + isEqual; constructor(data, isEqual){ this.data = data; this.isEqual = isEqual; @@ -5299,6 +5338,7 @@ class ADLMap { } } class Manifest { + filename; jsonBinding = createJsonBinding(RESOLVER, texprManifest()); tasks = new ADLMap([], (k1, k2)=>k1 === k2); constructor(dir, filename = ".manifest.json"){ diff --git a/crates/swc_bundler/tests/fixture/deno-9591/output/entry.ts b/crates/swc_bundler/tests/fixture/deno-9591/output/entry.ts index 16690993cf18..149a1f4bae86 100644 --- a/crates/swc_bundler/tests/fixture/deno-9591/output/entry.ts +++ b/crates/swc_bundler/tests/fixture/deno-9591/output/entry.ts @@ -1665,8 +1665,12 @@ function getLevelName(level) { throw new Error(`no level name found for level: ${level}`); } class LogRecord { + msg; #args; #datetime; + level; + levelName; + loggerName; constructor(options){ this.msg = options.msg; this.#args = [ @@ -1834,6 +1838,7 @@ function copyBytes(src, dst, off = 0) { } const DEFAULT_BUF_SIZE = 4096; class AbstractBufBase { + buf; usedBufferBytes = 0; err = null; size() { @@ -1847,6 +1852,7 @@ class AbstractBufBase { } } class BufWriterSync extends AbstractBufBase { + writer; static create(writer, size = DEFAULT_BUF_SIZE) { return writer instanceof BufWriterSync ? writer : new BufWriterSync(writer, size); } @@ -1904,6 +1910,9 @@ class BufWriterSync extends AbstractBufBase { } const DEFAULT_FORMATTER = "{levelName} {msg}"; class BaseHandler { + level; + levelName; + formatter; constructor(levelName, options = {}){ this.level = getLevelByName(levelName); this.levelName = levelName; @@ -1956,9 +1965,15 @@ class ConsoleHandler extends BaseHandler { } } class WriterHandler extends BaseHandler { + _writer; #encoder = new TextEncoder(); } class FileHandler extends WriterHandler { + _file; + _buf; + _filename; + _mode; + _openOptions; _encoder = new TextEncoder(); #unloadCallback = ()=>this.destroy(); constructor(levelName, options){ @@ -2062,6 +2077,8 @@ class RotatingFileHandler extends FileHandler { } } class LoggerConfig { + level; + handlers; } const DEFAULT_LEVEL = "INFO"; const DEFAULT_CONFIG = { @@ -3193,6 +3210,15 @@ function clean(version, optionsOrLoose) { return s ? s.version : null; } class SemVer { + raw; + loose; + options; + major; + minor; + patch; + version; + build; + prerelease; constructor(version, optionsOrLoose){ if (!optionsOrLoose || typeof optionsOrLoose !== "object") { optionsOrLoose = { @@ -3541,6 +3567,11 @@ function cmp(v1, operator, v2, optionsOrLoose) { } const ANY = {}; class Comparator { + semver; + operator; + value; + loose; + options; constructor(comp, optionsOrLoose){ if (!optionsOrLoose || typeof optionsOrLoose !== "object") { optionsOrLoose = { @@ -3630,6 +3661,12 @@ class Comparator { } } class Range { + range; + raw; + loose; + options; + includePrerelease; + set; constructor(range, optionsOrLoose){ if (!optionsOrLoose || typeof optionsOrLoose !== "object") { optionsOrLoose = { @@ -5254,6 +5291,8 @@ const ADL = { }; const RESOLVER = declResolver(ADL); class ADLMap { + data; + isEqual; constructor(data, isEqual){ this.data = data; this.isEqual = isEqual; @@ -5310,6 +5349,7 @@ class ADLMap { } } class Manifest { + filename; jsonBinding = createJsonBinding(RESOLVER, texprManifest()); tasks = new ADLMap([], (k1, k2)=>k1 === k2); constructor(dir, filename = ".manifest.json"){ diff --git a/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.inlined.ts b/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.inlined.ts index cad59a2f1b94..b9f386801f63 100644 --- a/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.inlined.ts +++ b/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.inlined.ts @@ -127,6 +127,7 @@ class StringReader extends Deno.Buffer { } } class MultiReader { + readers; currentIndex = 0; constructor(...readers){ this.readers = readers; @@ -1200,6 +1201,8 @@ const MIN_BUF_SIZE = 16; const CR = "\r".charCodeAt(0); const LF = "\n".charCodeAt(0); class BufferFullError extends Error { + partial; + name; constructor(partial){ super("Buffer full"); this.partial = partial; @@ -1208,11 +1211,14 @@ class BufferFullError extends Error { } class PartialReadError extends Deno.errors.UnexpectedEof { name = "PartialReadError"; + partial; constructor(){ super("Encountered UnexpectedEof, data only partially read"); } } class BufReader { + buf; + rd; r = 0; w = 0; eof = false; @@ -1433,6 +1439,7 @@ function charCode(s) { return s.charCodeAt(0); } class TextProtoReader { + r; constructor(r){ this.r = r; } @@ -1556,6 +1563,10 @@ function scanUntilBoundary(buf, dashBoundary, newLineDashBoundary, total, eof) { return buf.length; } class PartReader { + mr; + headers; + n; + total; constructor(mr, headers){ this.mr = mr; this.headers = headers; @@ -1590,6 +1601,8 @@ class PartReader { return nread; } close() {} + contentDisposition; + contentDispositionParams; getContentDispositionParams() { if (this.contentDispositionParams) return this.contentDispositionParams; const cd = this.headers.get("content-disposition"); @@ -1634,6 +1647,12 @@ function skipLWSPChar(u) { return ret.slice(0, j); } class MultipartReader { + boundary; + newLine; + newLineDashBoundary; + dashBoundaryDash; + dashBoundary; + bufReader; constructor(reader, boundary){ this.boundary = boundary; this.newLine = encoder.encode("\r\n"); @@ -1722,6 +1741,8 @@ class MultipartReader { } return multipartFormData(fileMap, valueMap); } + currentPart; + partsRead; async nextPart() { if (this.currentPart) { this.currentPart.close(); diff --git a/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.ts b/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.ts index 6aa3e06c0160..03ff71f993e8 100644 --- a/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.ts +++ b/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.ts @@ -127,6 +127,7 @@ class StringReader extends Deno.Buffer { } } class MultiReader { + readers; currentIndex = 0; constructor(...readers){ this.readers = readers; @@ -1210,6 +1211,8 @@ const MAX_CONSECUTIVE_EMPTY_READS = 100; const CR = "\r".charCodeAt(0); const LF = "\n".charCodeAt(0); class BufferFullError extends Error { + partial; + name; constructor(partial){ super("Buffer full"); this.partial = partial; @@ -1218,11 +1221,14 @@ class BufferFullError extends Error { } class PartialReadError extends Deno.errors.UnexpectedEof { name = "PartialReadError"; + partial; constructor(){ super("Encountered UnexpectedEof, data only partially read"); } } class BufReader { + buf; + rd; r = 0; w = 0; eof = false; @@ -1443,6 +1449,7 @@ function charCode(s) { return s.charCodeAt(0); } class TextProtoReader { + r; constructor(r){ this.r = r; } @@ -1566,6 +1573,10 @@ function scanUntilBoundary(buf, dashBoundary, newLineDashBoundary, total, eof) { return buf.length; } class PartReader { + mr; + headers; + n; + total; constructor(mr, headers){ this.mr = mr; this.headers = headers; @@ -1600,6 +1611,8 @@ class PartReader { return nread; } close() {} + contentDisposition; + contentDispositionParams; getContentDispositionParams() { if (this.contentDispositionParams) return this.contentDispositionParams; const cd = this.headers.get("content-disposition"); @@ -1644,6 +1657,12 @@ function skipLWSPChar(u) { return ret.slice(0, j); } class MultipartReader { + boundary; + newLine; + newLineDashBoundary; + dashBoundaryDash; + dashBoundary; + bufReader; constructor(reader, boundary){ this.boundary = boundary; this.newLine = encoder.encode("\r\n"); @@ -1732,6 +1751,8 @@ class MultipartReader { } return multipartFormData(fileMap, valueMap); } + currentPart; + partsRead; async nextPart() { if (this.currentPart) { this.currentPart.close(); diff --git a/crates/swc_ecma_ast/src/expr.rs b/crates/swc_ecma_ast/src/expr.rs index ce17cd8e5343..7f023d20ec27 100644 --- a/crates/swc_ecma_ast/src/expr.rs +++ b/crates/swc_ecma_ast/src/expr.rs @@ -340,6 +340,12 @@ pub struct ThisExpr { pub span: Span, } +impl Take for ThisExpr { + fn dummy() -> Self { + ThisExpr { span: DUMMY_SP } + } +} + /// Array literal. #[ast_node("ArrayExpression")] #[derive(Eq, Hash, EqIgnoreSpan)] diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 9ac8d7137f2a..664fa3952742 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -14,6 +14,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms::{ compat::{ bugfixes, + class_fields_use_set::class_fields_use_set, es2015::{self, generator::generator}, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es3, regexp::{self, regexp}, @@ -84,6 +85,14 @@ where }}; } + let pass = chain!( + pass, + Optional::new( + class_fields_use_set(assumptions.pure_getters), + assumptions.set_public_class_fields + ) + ); + let pass = { let enable_dot_all_regex = should_enable!(DotAllRegex, false); let enable_named_capturing_groups_regex = should_enable!(NamedCapturingGroupsRegex, false); diff --git a/crates/swc_ecma_transforms/tests/decorators.rs b/crates/swc_ecma_transforms/tests/decorators.rs index 0e60fa0ec205..a6ae3fb0f0cd 100644 --- a/crates/swc_ecma_transforms/tests/decorators.rs +++ b/crates/swc_ecma_transforms/tests/decorators.rs @@ -11,6 +11,7 @@ use swc_common::{chain, Mark}; use swc_ecma_parser::{EsConfig, Syntax, TsConfig}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ + class_fields_use_set::class_fields_use_set, es2015::{classes, function_name}, es2022::class_properties, }; @@ -38,6 +39,7 @@ fn syntax(decorators_before_export: bool) -> Syntax { fn tr(t: &Tester) -> impl Fold { chain!( decorators(Default::default()), + class_fields_use_set(true), class_properties(Some(t.comments.clone()), Default::default()), ) } @@ -66,6 +68,7 @@ fn simple_strip(t: &Tester, config: Config) -> impl Fold { }, top_level_mark ), + class_fields_use_set(true), class_properties( Some(t.comments.clone()), class_properties::Config { @@ -4484,6 +4487,7 @@ fn fixture_exec(input: PathBuf) { use_define_for_class_fields: false, }), strip(top_level_mark), + class_fields_use_set(true), ) }, &code, diff --git a/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs new file mode 100644 index 000000000000..cb934677b263 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs @@ -0,0 +1,343 @@ +use std::mem; + +use swc_common::{util::take::Take, DUMMY_SP}; +use swc_ecma_ast::*; +use swc_ecma_utils::{ + constructor::inject_after_super, default_constructor, is_literal, is_simple_pure_expr, + private_ident, prop_name_to_member_prop, ExprFactory, ModuleItemLike, StmtLike, +}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; + +/// # What does this module do? +/// +/// This module will transpile the class semantics +/// from `[[Define]]` to `[[Set]]`. +/// +/// +/// Note: class's native field is `[[Define]]` semantics. +/// +/// # Why is it needed? +/// The getter/setter from the super class won't be triggered in `[[Define]]` +/// semantics. +/// +/// Some decorators depend on super class getter/setter. +/// Therefore, scenarios like this will require `[[Set]]` semantics. +/// +/// ## Example +/// +/// ```JavaScript +/// class Foo { +/// a = 1; +/// #b = 2; +/// static c = 3; +/// static #d = 4; +/// } +/// ``` +/// +/// result: +/// +/// ```JavaScript +/// class Foo { +/// #b; +/// static { +/// this.c = 3; +/// } +/// static #d = 4; +/// constructor() { +/// this.a = 1; +/// this.#b = 2; +/// } +/// } +/// ``` +/// +/// The variable `a` will be relocated to the constructor. Although the variable +/// `#b` is not influenced by `[[Define]]` or `[[Set]]` semantics, its execution +/// order is associated with variable `a`, thus its initialization is moved into +/// the constructor. +/// +/// The static variable `c` is moved to the static block for `[[Set]]` semantic +/// conversion. Whereas, variable `#d` remains completely unaffected and +/// conserved in its original location. +/// +/// Furthermore, for class props that have side effects, an extraction and +/// conversion will be performed. +/// +/// For example, +/// +/// ```JavaScript +/// class Foo { +/// [foo()] = 1; +/// } +/// ``` +/// +/// result: +/// +/// ```JavaScript +/// let prop; +/// class Foo{ +/// static { +/// prop = foo(); +/// } +/// constructor() { +/// this[prop] = 1; +/// } +/// } +/// ``` +pub fn class_fields_use_set(pure_getters: bool) -> impl Fold + VisitMut { + as_folder(ClassFieldsUseSet { pure_getters }) +} + +#[derive(Debug)] +struct ClassFieldsUseSet { + pure_getters: bool, +} + +impl VisitMut for ClassFieldsUseSet { + noop_visit_mut_type!(); + + fn visit_mut_module_items(&mut self, n: &mut Vec) { + self.visit_mut_stmts_like(n); + } + + fn visit_mut_stmts(&mut self, n: &mut Vec) { + self.visit_mut_stmts_like(n); + } + + fn visit_mut_class(&mut self, n: &mut Class) { + n.visit_mut_children_with(self); + + let mut fields_handler = FieldsHandler::default(); + n.visit_mut_with(&mut fields_handler); + + let FieldsHandler { + constructor_inits, + constructor_found, + .. + } = fields_handler; + + if constructor_inits.is_empty() { + return; + } + + let mut constructor_handler = ConstructorHandler { + has_super: n.super_class.is_some(), + constructor_inits, + constructor_found, + }; + n.visit_mut_with(&mut constructor_handler); + } +} + +impl ClassFieldsUseSet { + fn visit_mut_stmts_like(&mut self, n: &mut Vec) + where + T: StmtLike + + ModuleItemLike + + VisitMutWith + + VisitMutWith + + From, + { + let mut stmts = Vec::with_capacity(n.len()); + + let mut computed_fields_handler = ComputedFieldsHandler { + var_decls: Default::default(), + static_init_blocks: Default::default(), + pure_getters: self.pure_getters, + }; + + for mut stmt in n.drain(..) { + stmt.visit_mut_with(&mut computed_fields_handler); + + let var_decls = computed_fields_handler.var_decls.take(); + + if !var_decls.is_empty() { + stmts.push(T::from( + VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Let, + declare: false, + decls: var_decls, + } + .into(), + )) + } + + stmt.visit_mut_with(self); + + stmts.push(stmt); + } + *n = stmts; + } +} + +#[derive(Debug, Default)] +struct FieldsHandler { + constructor_inits: Vec>, + constructor_found: bool, +} + +impl VisitMut for FieldsHandler { + noop_visit_mut_type!(); + + fn visit_mut_class(&mut self, n: &mut Class) { + n.body.visit_mut_with(self); + } + + fn visit_mut_class_member(&mut self, n: &mut ClassMember) { + match n { + ClassMember::Constructor(..) => self.constructor_found = true, + ClassMember::ClassProp(ClassProp { + ref span, + ref is_static, + key, + value, + .. + }) => { + if let Some(value) = value.take() { + let init_expr: Expr = AssignExpr { + span: *span, + op: op!("="), + left: MemberExpr { + span: DUMMY_SP, + obj: ThisExpr::dummy().into(), + prop: prop_name_to_member_prop(key.take()), + } + .into(), + right: value, + } + .into(); + + if *is_static { + *n = StaticBlock { + span: DUMMY_SP, + body: BlockStmt { + span: DUMMY_SP, + stmts: vec![init_expr.into_stmt()], + }, + } + .into(); + + return; + } else { + self.constructor_inits.push(init_expr.into()); + } + } + + n.take(); + } + ClassMember::PrivateProp(PrivateProp { + ref span, + is_static: false, + key, + value, + .. + }) => { + if let Some(value) = value.take() { + let init_expr: Expr = AssignExpr { + span: *span, + op: op!("="), + left: MemberExpr { + span: DUMMY_SP, + obj: ThisExpr::dummy().into(), + prop: MemberProp::PrivateName(key.clone()), + } + .into(), + right: value, + } + .into(); + + self.constructor_inits.push(init_expr.into()); + } + } + _ => {} + } + } +} + +#[derive(Debug, Default)] +struct ConstructorHandler { + has_super: bool, + constructor_inits: Vec>, + constructor_found: bool, +} + +impl VisitMut for ConstructorHandler { + noop_visit_mut_type!(); + + fn visit_mut_class(&mut self, n: &mut Class) { + if !self.constructor_found { + let mut constructor = default_constructor(self.has_super); + constructor.visit_mut_with(self); + n.body.push(constructor.into()); + } else { + n.body.visit_mut_children_with(self); + } + } + + fn visit_mut_constructor(&mut self, n: &mut Constructor) { + inject_after_super(n, self.constructor_inits.take()); + } +} + +#[derive(Debug)] +struct ComputedFieldsHandler { + var_decls: Vec, + static_init_blocks: Vec, + pure_getters: bool, +} + +impl VisitMut for ComputedFieldsHandler { + noop_visit_mut_type!(); + + fn visit_mut_class_prop(&mut self, n: &mut ClassProp) { + match &mut n.key { + PropName::Computed(ComputedPropName { expr, .. }) + if !is_literal(expr) && !is_simple_pure_expr(expr, self.pure_getters) => + { + let ref_key = private_ident!("prop"); + let mut computed_expr = Box::new(Expr::Ident(ref_key.clone())); + + mem::swap(expr, &mut computed_expr); + + self.var_decls.push(VarDeclarator { + span: DUMMY_SP, + name: ref_key.clone().into(), + init: None, + definite: false, + }); + + self.static_init_blocks.push({ + let assign_expr = + computed_expr.make_assign_to(op!("="), ref_key.as_pat_or_expr()); + + assign_expr.into_stmt() + }); + } + _ => (), + } + } + + fn visit_mut_class_member(&mut self, n: &mut ClassMember) { + if n.is_class_prop() { + n.visit_mut_children_with(self); + } + } + + fn visit_mut_class_members(&mut self, n: &mut Vec) { + n.visit_mut_children_with(self); + + if !self.static_init_blocks.is_empty() { + n.insert( + 0, + StaticBlock { + span: DUMMY_SP, + body: BlockStmt { + span: DUMMY_SP, + stmts: self.static_init_blocks.take(), + }, + } + .into(), + ); + } + } +} diff --git a/crates/swc_ecma_transforms_compat/src/lib.rs b/crates/swc_ecma_transforms_compat/src/lib.rs index 0eb2f13e3809..a9bcf99c5131 100644 --- a/crates/swc_ecma_transforms_compat/src/lib.rs +++ b/crates/swc_ecma_transforms_compat/src/lib.rs @@ -12,6 +12,7 @@ pub use self::{ #[macro_use] mod macros; pub mod bugfixes; +pub mod class_fields_use_set; pub mod es2015; pub mod es2016; pub mod es2017; diff --git a/crates/swc_ecma_transforms_compat/tests/class_fields_use_set.rs b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set.rs new file mode 100644 index 000000000000..55a74d27db8a --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set.rs @@ -0,0 +1,21 @@ +use std::path::PathBuf; + +use swc_ecma_parser::{EsConfig, Syntax}; +use swc_ecma_transforms_compat::class_fields_use_set::class_fields_use_set; +use swc_ecma_transforms_testing::test_fixture; + +#[testing::fixture("tests/class_fields_use_set/**/input.js")] +fn fixture(input: PathBuf) { + let parent = input.parent().unwrap(); + + let output = parent.join("output.js"); + test_fixture( + Syntax::Es(EsConfig { + ..Default::default() + }), + &|_| class_fields_use_set(true), + &input, + &output, + Default::default(), + ) +} diff --git a/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/1/input.js b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/1/input.js new file mode 100644 index 000000000000..d45a962b23ee --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/1/input.js @@ -0,0 +1,8 @@ +class Foo { + // Move class field into constructor + a = 1; + // Move private class field init into constructor to preserve execution order + #b = 2; + static c = 3; + static #d = 4; +} diff --git a/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/1/output.js b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/1/output.js new file mode 100644 index 000000000000..b5c56f327591 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/1/output.js @@ -0,0 +1,13 @@ +class Foo { + // Move private class field init into constructor to preserve execution order + #b; + static{ + this.c = 3; + } + static #d = 4; + constructor(){ + // Move class field into constructor + this.a = 1; + this.#b = 2; + } +} diff --git a/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/2/input.js b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/2/input.js new file mode 100644 index 000000000000..9d628fafd125 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/2/input.js @@ -0,0 +1,6 @@ +class Foo extends Bar { + a = 1; + #b = 2; + static c = 3; + static #d = 4; +} diff --git a/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/2/output.js b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/2/output.js new file mode 100644 index 000000000000..320ff9a0f84b --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/2/output.js @@ -0,0 +1,12 @@ +class Foo extends Bar { + #b; + static{ + this.c = 3; + } + static #d = 4; + constructor(...args){ + super(...args); + this.a = 1; + this.#b = 2; + } +} diff --git a/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/3/input.js b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/3/input.js new file mode 100644 index 000000000000..b68f7e9dc5fb --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/3/input.js @@ -0,0 +1,12 @@ +class Foo extends Bar { + a = 1; + #b = 2; + + constructor() { + super(); + console.log("constructor"); + } + + static c = 3; + static #d = 4; +} diff --git a/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/3/output.js b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/3/output.js new file mode 100644 index 000000000000..42f2cbb2193a --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/3/output.js @@ -0,0 +1,13 @@ +class Foo extends Bar { + #b; + constructor(){ + super(); + this.a = 1; + this.#b = 2; + console.log("constructor"); + } + static{ + this.c = 3; + } + static #d = 4; +} diff --git a/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/4/input.js b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/4/input.js new file mode 100644 index 000000000000..7f02e75fa6f8 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/4/input.js @@ -0,0 +1,15 @@ +class Foo { + a = 1; + #b = 2; + static c = 3; + static #d = 4; + + foo() { + class Bar { + a = 1; + #b = 2; + static c = 3; + static #d = 4; + } + } +} diff --git a/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/4/output.js b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/4/output.js new file mode 100644 index 000000000000..a745dac485a6 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/4/output.js @@ -0,0 +1,24 @@ +class Foo { + #b; + static{ + this.c = 3; + } + static #d = 4; + foo() { + class Bar { + #b; + static{ + this.c = 3; + } + static #d = 4; + constructor(){ + this.a = 1; + this.#b = 2; + } + } + } + constructor(){ + this.a = 1; + this.#b = 2; + } +} diff --git a/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/5/input.js b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/5/input.js new file mode 100644 index 000000000000..ca085587a4fe --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/5/input.js @@ -0,0 +1,8 @@ +class Foo { + [(console.log(1), 1)] = 1; + [Symbol.iterator] = 2; + static { + console.log("Foo"); + } + [(console.log(2), 2)] = 1; +} diff --git a/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/5/output.js b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/5/output.js new file mode 100644 index 000000000000..12998d48eeb9 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/class_fields_use_set/basic/5/output.js @@ -0,0 +1,15 @@ +let prop, prop1; +class Foo { + static{ + prop = (console.log(1), 1); + prop1 = (console.log(2), 2); + } + static{ + console.log("Foo"); + } + constructor(){ + this[prop] = 1; + this[Symbol.iterator] = 2; + this[prop1] = 1; + } +} diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs index b5b473e5c53d..a9fb6cb7d54c 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip.rs @@ -65,9 +65,10 @@ pub struct Config { /// When running `tsc` with configuration `"target": "", /// "useDefineForClassFields": true`, TS class fields are transformed to /// `Object.defineProperty()` statements. You must additionally apply the - /// [swc_ecma_transforms_compat::es2022::class_properties()] pass to + /// [swc_ecma_transforms_compat::class_fields_use_set::class_fields_use_set()] pass to /// get this backward-compatible output. #[serde(default)] + #[deprecated(note = "[[Define]] and [[Set]] are managed within swc_ecma_transforms_compat.")] pub use_define_for_class_fields: bool, /// Don't create `export {}`. @@ -1873,9 +1874,9 @@ where } _ => unreachable!("destructuring pattern inside TsParameterProperty"), }; - if self.config.use_define_for_class_fields { - extra_props.push(ident.id.clone()); - } + + extra_props.push(ident.id.clone()); + let assign_expr = Box::new(Expr::Assign(AssignExpr { span: ident.span.with_ctxt(SyntaxContext::empty()), left: PatOrExpr::Expr(Box::new( @@ -1962,23 +1963,26 @@ where inject_after_super(c, assign_exprs); if !extra_props.is_empty() { - class.body.extend(extra_props.into_iter().map(|prop| { - ClassMember::ClassProp(ClassProp { - key: PropName::Ident(prop), - value: None, - decorators: Vec::new(), - is_static: false, - type_ann: None, - span: DUMMY_SP, - accessibility: None, - is_abstract: false, - is_optional: false, - is_override: false, - readonly: false, - declare: false, - definite: false, - }) - })) + class.body.splice( + 0..0, + extra_props.into_iter().map(|prop| { + ClassMember::ClassProp(ClassProp { + key: PropName::Ident(prop), + value: None, + decorators: Vec::new(), + is_static: false, + type_ann: None, + span: DUMMY_SP, + accessibility: None, + is_abstract: false, + is_optional: false, + is_override: false, + readonly: false, + declare: false, + definite: false, + }) + }), + ); } } @@ -2011,11 +2015,6 @@ where is_abstract: true, .. }, ) => false, - ClassMember::ClassProp(ClassProp { - value: None, - ref decorators, - .. - }) if decorators.is_empty() && !self.config.use_define_for_class_fields => false, _ => true, }); diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3228/1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3228/1/output.js index 9599995530f5..8db04c182748 100644 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3228/1/output.js +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3228/1/output.js @@ -1,6 +1,10 @@ export class StaticTestClass { } -StaticTestClass.testProp = "Hello world!"; -StaticTestClass.testMethod = ()=>{ - console.log(StaticTestClass.testProp); -}; +(()=>{ + StaticTestClass.testProp = "Hello world!"; +})(); +(()=>{ + StaticTestClass.testMethod = ()=>{ + console.log(StaticTestClass.testProp); + }; +})(); diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 17ae9cf284a6..5d22a3ef7eed 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -4,10 +4,11 @@ use swc_common::{chain, comments::SingleThreadedComments, pass::Optional, Mark}; use swc_ecma_parser::{Syntax, TsConfig}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ + class_fields_use_set::class_fields_use_set, es2015::{block_scoping, destructuring, parameters}, es2017::async_to_generator, es2020::{nullish_coalescing, optional_chaining}, - es2022::class_properties, + es2022::{class_properties, static_blocks}, }; use swc_ecma_transforms_proposal::decorators; use swc_ecma_transforms_testing::{test, test_exec, test_fixture, Tester}; @@ -15,12 +16,13 @@ use swc_ecma_transforms_typescript::{strip, strip::strip_with_config, TsImportEx use swc_ecma_visit::Fold; fn tr() -> impl Fold { - tr_config(None, None) + tr_config(None, None, false) } fn tr_config( config: Option, decorators_config: Option, + use_define_for_class_fields: bool, ) -> impl Fold { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); @@ -29,6 +31,7 @@ fn tr_config( no_empty_export: true, ..Default::default() }); + chain!( Optional::new( decorators(decorators_config.unwrap_or_default()), @@ -36,16 +39,22 @@ fn tr_config( ), resolver(unresolved_mark, top_level_mark, true), strip_with_config(config, top_level_mark), + Optional::new(class_fields_use_set(true), !use_define_for_class_fields), ) } fn properties(t: &Tester, loose: bool) -> impl Fold { - class_properties( - Some(t.comments.clone()), - class_properties::Config { - set_public_fields: loose, - ..Default::default() - }, + let mark = Mark::new(); + chain!( + static_blocks(mark), + class_properties( + Some(t.comments.clone()), + class_properties::Config { + static_blocks_mark: mark, + set_public_fields: loose, + ..Default::default() + }, + ) ) } @@ -66,13 +75,19 @@ macro_rules! to { } macro_rules! test_with_config { + ($name:ident, $config:expr, SET, $from:expr, $to:expr) => { + test_with_config!($name, $config, false, $from, $to); + }; ($name:ident, $config:expr, $from:expr, $to:expr) => { + test_with_config!($name, $config, true, $from, $to); + }; + ($name:ident, $config:expr, $use_define:expr,$from:expr, $to:expr) => { test!( Syntax::Typescript(TsConfig { decorators: true, ..Default::default() }), - |_| tr_config(Some($config), None), + |_| tr_config(Some($config), None, $use_define), $name, $from, $to, @@ -714,7 +729,7 @@ test!( constructor(a) { } } - A.b = 'foo';" + (()=>{ A.b = 'foo'; })();" ); test!( @@ -3056,6 +3071,7 @@ test!( ..Default::default() }), None, + true, ) }, deno_7413_3, @@ -3200,11 +3216,11 @@ test!( }), |_| tr_config( Some(strip::Config { - use_define_for_class_fields: true, no_empty_export: true, ..Default::default() }), - None + None, + true ), compile_to_class_constructor_collision_ignores_types, r#" @@ -3234,7 +3250,7 @@ test!( decorators: true, ..Default::default() }), - |_| tr_config(None, Some(Default::default())), + |_| tr_config(None, Some(Default::default()), false), issue_367, " @@ -3588,7 +3604,6 @@ to!( test_with_config!( issue_1472_1_define, strip::Config { - use_define_for_class_fields: true, no_empty_export: true, ..Default::default() }, @@ -3602,13 +3617,13 @@ test_with_config!( ", " class A extends Object { + b; a; constructor(b = 2){ super(); this.b = b; this.a = 1; } - b; } " ); @@ -3617,9 +3632,9 @@ test_with_config!( issue_1472_1_no_define, strip::Config { no_empty_export: true, - use_define_for_class_fields: false, ..Default::default() }, + SET, " class A extends Object { a = 1; @@ -3648,13 +3663,19 @@ to!( } ", " - let _ref = (console.log(1), 'a'), _ref1 = (console.log(2), 'b'); + let prop, prop1; class A { constructor() { - this[_ref] = 1; + this[prop] = 1; } } - A[_ref1] = 2; + (()=>{ + prop = (console.log(1), 'a'); + prop1 = (console.log(2), 'b'); + })(); + (()=>{ + A[prop1] = 2; + })(); " ); @@ -3668,14 +3689,21 @@ to!( } ", " - let _ref = (console.log(1), 'a'), _ref1 = (console.log(2), 'b'), _tmp = (console.log(3), 'c'); + let prop, prop1; + let _tmp = (console.log(3), 'c'); class A { [_tmp]() {} constructor() { - this[_ref] = 1; + this[prop] = 1; } } - A[_ref1] = 2; + (()=>{ + prop = (console.log(1), 'a'); + prop1 = (console.log(2), 'b'); + })(); + (()=>{ + A[prop1] = 2; + })(); " ); @@ -3746,7 +3774,7 @@ to!( " var _class; const A = (_class = class {}, - _class.a = 1, + (()=>{ _class.a = 1; })(), _class); " ); @@ -4013,11 +4041,6 @@ to!( var _store = new WeakMap(), _body = new WeakMap(); export class Context { constructor(optionsOrContext){ - this.response = { - headers: new Headers() - }; - this.params = { - }; _classPrivateFieldInit(this, _store, { writable: true, value: void 0 @@ -4026,6 +4049,11 @@ to!( writable: true, value: void 0 }); + this.response = { + headers: new Headers() + }; + this.params = { + }; if (optionsOrContext instanceof Context) { Object.assign(this, optionsOrContext); this.customContext = this; @@ -4121,9 +4149,9 @@ to!( var _TestClass; var _class; let TestClass = _class = someClassDecorator((_class = (_TestClass = class TestClass { - }, _TestClass.Something = 'hello', _TestClass.SomeProperties = { + }, (()=>{ _TestClass.Something = 'hello'; })(), (()=>{ _TestClass.SomeProperties = { firstProp: _TestClass.Something - }, _TestClass)) || _class) || _class; + };})(), _TestClass)) || _class) || _class; function someClassDecorator(c) { return c; } @@ -4187,7 +4215,7 @@ class Foo { const identifier = 'bar'; class Foo { } -Foo.identifier = 5; +(()=>{ Foo.identifier = 5; })(); " ); @@ -4220,7 +4248,6 @@ to!( test_with_config!( deno_12532_declare_class_prop, strip::Config { - use_define_for_class_fields: true, no_empty_export: true, ..Default::default() }, @@ -4411,7 +4438,7 @@ let b = (_console_log = console.log(456), class { test!( Syntax::Typescript(TsConfig::default()), - |_| tr_config(None, None), + |_| tr_config(None, None, true), export_import_assign, r#" export import foo = require("foo"); @@ -4432,7 +4459,8 @@ test!( import_export_assign_config: TsImportExportAssignConfig::NodeNext, ..Default::default() }), - None + None, + true, ), node_next_1, r#" @@ -4456,7 +4484,8 @@ test!( import_export_assign_config: TsImportExportAssignConfig::NodeNext, ..Default::default() }), - None + None, + true ), node_next_2, r#" @@ -4477,7 +4506,6 @@ test!( test_with_config!( issue_6023, strip::Config { - use_define_for_class_fields: true, ..Default::default() }, " diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs index dd9b35680c7d..5c6e8750825d 100644 --- a/crates/swc_ecma_utils/src/lib.rs +++ b/crates/swc_ecma_utils/src/lib.rs @@ -1948,6 +1948,25 @@ impl Visit for LiteralVisitor { } } +pub fn is_simple_pure_expr(expr: &Expr, pure_getters: bool) -> bool { + match expr { + Expr::Ident(..) | Expr::This(..) | Expr::Lit(..) => true, + Expr::Member(m) if pure_getters => is_simple_pure_member_expr(m, pure_getters), + _ => false, + } +} + +pub fn is_simple_pure_member_expr(m: &MemberExpr, pure_getters: bool) -> bool { + match &m.prop { + MemberProp::Ident(..) | MemberProp::PrivateName(..) => { + is_simple_pure_expr(&m.obj, pure_getters) + } + MemberProp::Computed(c) => { + is_simple_pure_expr(&c.expr, pure_getters) && is_simple_pure_expr(&m.obj, pure_getters) + } + } +} + /// Used to determine super_class_ident pub fn alias_ident_for(expr: &Expr, default: &str) -> Ident { fn sym(expr: &Expr) -> Option { @@ -2066,6 +2085,25 @@ pub fn prop_name_to_expr_value(p: PropName) -> Expr { } } +pub fn prop_name_to_member_prop(prop_name: PropName) -> MemberProp { + match prop_name { + PropName::Ident(i) => MemberProp::Ident(i), + PropName::Str(s) => MemberProp::Computed(ComputedPropName { + span: DUMMY_SP, + expr: s.into(), + }), + PropName::Num(n) => MemberProp::Computed(ComputedPropName { + span: DUMMY_SP, + expr: n.into(), + }), + PropName::Computed(c) => MemberProp::Computed(c), + PropName::BigInt(b) => MemberProp::Computed(ComputedPropName { + span: DUMMY_SP, + expr: b.into(), + }), + } +} + pub fn default_constructor(has_super: bool) -> Constructor { trace!(has_super = has_super, "Creating a default constructor"); diff --git a/crates/swc_node_bundler/tests/pass/deno-001/full/output/entry.js b/crates/swc_node_bundler/tests/pass/deno-001/full/output/entry.js index 8f8e498d88e3..f2060d65d325 100644 --- a/crates/swc_node_bundler/tests/pass/deno-001/full/output/entry.js +++ b/crates/swc_node_bundler/tests/pass/deno-001/full/output/entry.js @@ -26,6 +26,8 @@ const MAX_CONSECUTIVE_EMPTY_READS = 100; const CR = "\r".charCodeAt(0); const LF = "\n".charCodeAt(0); class BufferFullError extends Error { + partial; + name; constructor(partial){ super("Buffer full"); this.partial = partial; @@ -34,11 +36,14 @@ class BufferFullError extends Error { } class PartialReadError extends Deno.errors.UnexpectedEof { name = "PartialReadError"; + partial; constructor(){ super("Encountered UnexpectedEof, data only partially read"); } } class BufReader { + buf; + rd; r = 0; w = 0; eof = false; @@ -219,6 +224,7 @@ class BufReader { } } class AbstractBufBase { + buf; usedBufferBytes = 0; err = null; size() { @@ -232,6 +238,7 @@ class AbstractBufBase { } } class BufWriter extends AbstractBufBase { + writer; static create(writer, size = DEFAULT_BUF_SIZE) { return writer instanceof BufWriter ? writer : new BufWriter(writer, size); } @@ -301,6 +308,7 @@ function charCode(s) { return s.charCodeAt(0); } class TextProtoReader { + r; constructor(r){ this.r = r; } @@ -598,6 +606,15 @@ async function writeResponse(w, r) { await writer.flush(); } class ServerRequest { + url; + method; + proto; + protoMinor; + protoMajor; + headers; + conn; + r; + w; done = deferred(); _contentLength = undefined; get contentLength() { @@ -695,6 +712,9 @@ async function readRequest(conn, bufr) { return req; } class Server { + listener; + closing; + connections; constructor(listener){ this.listener = listener; this.closing = false; diff --git a/crates/swc_node_bundler/tests/pass/deno-001/simple-1/output/entry.js b/crates/swc_node_bundler/tests/pass/deno-001/simple-1/output/entry.js index 567bc77c171b..baba1a91c204 100644 --- a/crates/swc_node_bundler/tests/pass/deno-001/simple-1/output/entry.js +++ b/crates/swc_node_bundler/tests/pass/deno-001/simple-1/output/entry.js @@ -235,6 +235,15 @@ async function writeResponse(w, r) { await writer.flush(); } class ServerRequest { + url; + method; + proto; + protoMinor; + protoMajor; + headers; + conn; + r; + w; done = deferred(); _contentLength = undefined; get contentLength() { @@ -332,6 +341,9 @@ async function readRequest(conn, bufr) { return req; } class Server { + listener; + closing; + connections; constructor(listener){ this.listener = listener; this.closing = false; diff --git a/crates/swc_node_bundler/tests/pass/deno-001/simple-2/output/entry.js b/crates/swc_node_bundler/tests/pass/deno-001/simple-2/output/entry.js index c108d814d753..1acbf8425932 100644 --- a/crates/swc_node_bundler/tests/pass/deno-001/simple-2/output/entry.js +++ b/crates/swc_node_bundler/tests/pass/deno-001/simple-2/output/entry.js @@ -1,12 +1,25 @@ +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; +} function deferred() {} class MuxAsyncIterator { constructor(){ - this.signal = deferred(); + _defineProperty(this, "signal", deferred()); } } class ServerRequest { constructor(){ - this.done = deferred(); + _defineProperty(this, "done", deferred()); } } console.log(ServerRequest); diff --git a/crates/swc_node_bundler/tests/pass/deno-001/simple-3/output/entry.js b/crates/swc_node_bundler/tests/pass/deno-001/simple-3/output/entry.js index b0c04ad21425..6470e9ee9a17 100644 --- a/crates/swc_node_bundler/tests/pass/deno-001/simple-3/output/entry.js +++ b/crates/swc_node_bundler/tests/pass/deno-001/simple-3/output/entry.js @@ -1,7 +1,20 @@ +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; +} function deferred() {} class MuxAsyncIterator { constructor(){ - this.signal = deferred(); + _defineProperty(this, "signal", deferred()); } } console.log(deferred, MuxAsyncIterator); diff --git a/crates/swc_node_bundler/tests/pass/deno-001/simple-4/output/entry.js b/crates/swc_node_bundler/tests/pass/deno-001/simple-4/output/entry.js index b0c04ad21425..6470e9ee9a17 100644 --- a/crates/swc_node_bundler/tests/pass/deno-001/simple-4/output/entry.js +++ b/crates/swc_node_bundler/tests/pass/deno-001/simple-4/output/entry.js @@ -1,7 +1,20 @@ +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; +} function deferred() {} class MuxAsyncIterator { constructor(){ - this.signal = deferred(); + _defineProperty(this, "signal", deferred()); } } console.log(deferred, MuxAsyncIterator);