From 8e796cdc0ac59d7cab7e9e845afc2f98ee89c3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 18 Jan 2022 20:52:21 +0900 Subject: [PATCH] fix(es/minifier): Don't emit invalid code (#3302) swc_ecma_minifier: - Add lots of debug assertions for invalid codes. - Remove all invalid AST nodes eagerly. - `pure`: Normalize `PatOrExpr`. - `analyzer`: Handle `PatOrExpr` correctly. --- ...eNameAndCommonRootES6_es2015.2.minified.js | 14 +- ...SameNameAndCommonRoot_es2015.2.minified.js | 14 +- ...SameNameAndCommonRoot_es2015.2.minified.js | 6 +- ...ithSameNameAndCommonRoot_es5.2.minified.js | 8 +- ...MemberTypeAnnotations_es2015.2.minified.js | 20 +- ...istMemberTypeAnnotations_es5.2.minified.js | 20 +- ...peParameterConstraint_es2015.2.minified.js | 20 +- ...nTypeParameterConstraint_es5.2.minified.js | 20 +- ...eTypeInTypeAnnotation_es2015.2.minified.js | 20 +- ...ibleTypeInTypeAnnotation_es5.2.minified.js | 20 +- ...SameNameAndCommonRoot_es2015.2.minified.js | 12 +- ...ithSameNameAndCommonRoot_es5.2.minified.js | 12 +- ...ndDifferentCommonRoot_es2015.2.minified.js | 12 +- ...meAndDifferentCommonRoot_es5.2.minified.js | 12 +- ...PropertyAssignments5_es6_es5.2.minified.js | 17 +- ...SameNameAndCommonRoot_es2015.2.minified.js | 18 +- ...SameNameAndCommonRoot_es2015.2.minified.js | 6 +- ...ithSameNameAndCommonRoot_es5.2.minified.js | 6 +- ...SameNameAndCommonRoot_es2015.2.minified.js | 12 +- ...ithSameNameAndCommonRoot_es5.2.minified.js | 12 +- ...AndNonExportedClasses_es2015.2.minified.js | 10 +- ...dNonExportedFunctions_es2015.2.minified.js | 14 +- ...dAndNonExportedFunctions_es5.2.minified.js | 14 +- ...dClassesOfTheSameName_es2015.2.minified.js | 10 +- ...ocalVarsOfTheSameName_es2015.2.minified.js | 33 +- ...edLocalVarsOfTheSameName_es5.2.minified.js | 25 +- ...ocalVarsOfTheSameName_es2015.2.minified.js | 36 +- ...edLocalVarsOfTheSameName_es5.2.minified.js | 20 +- ...NameAndSameCommonRoot_es2015.2.minified.js | 33 +- ...ameNameAndSameCommonRoot_es5.2.minified.js | 19 +- ...ypeGuardWithEnumUnion_es2015.2.minified.js | 6 +- .../TypeGuardWithEnumUnion_es5.2.minified.js | 6 +- ...orWithAnyAndEveryType_es2015.2.minified.js | 6 +- ...ratorWithAnyAndEveryType_es5.2.minified.js | 6 +- ...orWithInvalidOperands_es2015.2.minified.js | 6 +- ...ratorWithInvalidOperands_es5.2.minified.js | 6 +- ...ValueAndValidOperator_es2015.2.minified.js | 6 +- ...ullValueAndValidOperator_es5.2.minified.js | 6 +- ...atorWithNumberAndEnum_es2015.2.minified.js | 8 +- ...peratorWithNumberAndEnum_es5.2.minified.js | 8 +- ...ithStringAndEveryType_es2015.2.minified.js | 6 +- ...orWithStringAndEveryType_es5.2.minified.js | 6 +- ...atorWithTypeParameter_es2015.2.minified.js | 6 +- ...peratorWithTypeParameter_es5.2.minified.js | 6 +- ...ValueAndValidOperator_es2015.2.minified.js | 6 +- ...nedValueAndValidOperator_es5.2.minified.js | 6 +- ...rtAsPrimaryExpression_es2015.2.minified.js | 6 +- ...mportAsPrimaryExpression_es5.2.minified.js | 6 +- ...otAsPrimaryExpression_es2015.2.minified.js | 6 +- ...rtNotAsPrimaryExpression_es5.2.minified.js | 6 +- ...nabilityInInheritance_es2015.2.minified.js | 6 +- ...signabilityInInheritance_es5.2.minified.js | 6 +- ...ssignableToEveryType2_es2015.2.minified.js | 6 +- ...nyAssignableToEveryType2_es5.2.minified.js | 6 +- ...AssignableToEveryType_es2015.2.minified.js | 6 +- ...anyAssignableToEveryType_es5.2.minified.js | 6 +- ...pressionContextualTyping_es5.2.minified.js | 16 +- ...OperatorWithEnumUnion_es2015.2.minified.js | 8 +- ...ticOperatorWithEnumUnion_es5.2.minified.js | 8 +- ...meticOperatorWithEnum_es2015.2.minified.js | 6 +- ...ithmeticOperatorWithEnum_es5.2.minified.js | 6 +- ...orWithInvalidOperands_es2015.2.minified.js | 6 +- ...ratorWithInvalidOperands_es5.2.minified.js | 6 +- ...ValueAndValidOperands_es2015.2.minified.js | 6 +- ...ullValueAndValidOperands_es5.2.minified.js | 6 +- ...ValueAndValidOperands_es2015.2.minified.js | 6 +- ...nedValueAndValidOperands_es5.2.minified.js | 6 +- ...AssignmentPatternWithAny_es5.2.minified.js | 54 +- ...arrayLiteralInference_es2015.2.minified.js | 8 +- .../arrayLiteralInference_es5.2.minified.js | 8 +- ...arrowFunctionExpressions_es5.2.minified.js | 6 +- ...sParsingAsNamespace05_es2015.2.minified.js | 6 +- ...entsParsingAsNamespace05_es5.2.minified.js | 6 +- .../assignAnyToEveryType_es2015.2.minified.js | 6 +- .../assignAnyToEveryType_es5.2.minified.js | 6 +- .../assignEveryTypeToAny_es2015.2.minified.js | 6 +- .../assignEveryTypeToAny_es5.2.minified.js | 7 +- ...enthesizedIdentifiers_es2015.2.minified.js | 6 +- ...ParenthesizedIdentifiers_es5.2.minified.js | 6 +- .../assignments_es2015.2.minified.js | 6 +- .../assignments_es5.2.minified.js | 6 +- ...ctionDeclaration8_es2017_es5.2.minified.js | 15 +- ...FunctionDeclaration8_es5_es5.2.minified.js | 15 +- ...FunctionDeclaration8_es6_es5.2.minified.js | 15 +- ...bestCommonTypeOfTuple_es2015.2.minified.js | 8 +- .../bestCommonTypeOfTuple_es5.2.minified.js | 8 +- ...tOperatorWithEnumType_es2015.2.minified.js | 6 +- ...eNotOperatorWithEnumType_es5.2.minified.js | 6 +- ...peAnnotationInference_es2015.2.minified.js | 12 +- ...nTypeAnnotationInference_es5.2.minified.js | 6 +- .../castingTuple_es2015.2.minified.js | 10 +- .../castingTuple_es5.2.minified.js | 10 +- .../circularImportAlias_es2015.2.minified.js | 8 +- ...otAsPrimaryExpression_es2015.2.minified.js | 6 +- ...rtNotAsPrimaryExpression_es5.2.minified.js | 6 +- ...denticalPrimitiveType_es2015.2.minified.js | 6 +- ...thIdenticalPrimitiveType_es5.2.minified.js | 6 +- ...tionshipPrimitiveType_es2015.2.minified.js | 6 +- ...elationshipPrimitiveType_es5.2.minified.js | 6 +- ...tionshipTypeParameter_es2015.2.minified.js | 6 +- ...elationshipTypeParameter_es5.2.minified.js | 6 +- ...orWithOneOperandIsAny_es2015.2.minified.js | 6 +- ...ratorWithOneOperandIsAny_es5.2.minified.js | 6 +- ...rWithOneOperandIsNull_es2015.2.minified.js | 6 +- ...atorWithOneOperandIsNull_es5.2.minified.js | 6 +- ...OneOperandIsUndefined_es2015.2.minified.js | 6 +- ...ithOneOperandIsUndefined_es5.2.minified.js | 6 +- ...hSubtypeEnumAndNumber_es2015.2.minified.js | 6 +- ...WithSubtypeEnumAndNumber_es5.2.minified.js | 6 +- ...nmentLHSCanBeAssigned_es2015.2.minified.js | 6 +- ...signmentLHSCanBeAssigned_es5.2.minified.js | 6 +- ...ntLHSCannotBeAssigned_es2015.2.minified.js | 6 +- ...nmentLHSCannotBeAssigned_es5.2.minified.js | 6 +- ...ntWithInvalidOperands_es2015.2.minified.js | 6 +- ...nmentWithInvalidOperands_es5.2.minified.js | 6 +- ...nmentLHSCanBeAssigned_es2015.2.minified.js | 6 +- ...signmentLHSCanBeAssigned_es5.2.minified.js | 6 +- ...ntWithInvalidOperands_es2015.2.minified.js | 6 +- ...nmentWithInvalidOperands_es5.2.minified.js | 6 +- ...mentLHSCanBeAssigned1_es2015.2.minified.js | 6 +- ...ignmentLHSCanBeAssigned1_es5.2.minified.js | 6 +- ...ntLHSCannotBeAssigned_es2015.2.minified.js | 6 +- ...nmentLHSCannotBeAssigned_es5.2.minified.js | 6 +- ...putedPropertyNames20_ES5_es5.2.minified.js | 15 +- ...putedPropertyNames20_ES6_es5.2.minified.js | 15 +- ...putedPropertyNames23_ES5_es5.2.minified.js | 14 +- ...putedPropertyNames23_ES6_es5.2.minified.js | 14 +- ...putedPropertyNames26_ES5_es5.2.minified.js | 16 +- ...putedPropertyNames26_ES6_es5.2.minified.js | 16 +- ...putedPropertyNames46_ES5_es5.2.minified.js | 15 +- ...putedPropertyNames46_ES6_es5.2.minified.js | 15 +- ...edPropertyNames47_ES5_es2015.2.minified.js | 8 +- ...putedPropertyNames47_ES5_es5.2.minified.js | 20 +- ...edPropertyNames47_ES6_es2015.2.minified.js | 8 +- ...putedPropertyNames47_ES6_es5.2.minified.js | 20 +- ...edPropertyNames48_ES5_es2015.2.minified.js | 6 +- ...putedPropertyNames48_ES5_es5.2.minified.js | 6 +- ...edPropertyNames48_ES6_es2015.2.minified.js | 6 +- ...putedPropertyNames48_ES6_es5.2.minified.js | 6 +- ...tedPropertyNames7_ES5_es2015.2.minified.js | 6 +- ...mputedPropertyNames7_ES5_es5.2.minified.js | 18 +- ...tedPropertyNames7_ES6_es2015.2.minified.js | 6 +- ...mputedPropertyNames7_ES6_es5.2.minified.js | 18 +- ...rationsAndAssignments_es2015.2.minified.js | 12 +- ...clarationsAndAssignments_es5.2.minified.js | 6 +- ...TypeInvalidOperations_es2015.2.minified.js | 6 +- ...numTypeInvalidOperations_es5.2.minified.js | 6 +- ...tOperatorWithEnumType_es2015.2.minified.js | 6 +- ...mentOperatorWithEnumType_es5.2.minified.js | 6 +- ...tExportsCannotMerge01_es2015.2.minified.js | 6 +- ...aultExportsCannotMerge01_es5.2.minified.js | 6 +- ...PatternAndAssignment1ES5_es5.2.minified.js | 18 +- ...ndAssignment1ES5iterable_es5.2.minified.js | 18 +- ...PatternAndAssignment1ES6_es5.2.minified.js | 18 +- ...ingPatternAndAssignment4_es5.2.minified.js | 53 +- ...ructuringEvaluationOrder_es5.2.minified.js | 54 +- ...PatternAndAssignment7_es2015.2.minified.js | 6 +- ...ingPatternAndAssignment7_es5.2.minified.js | 6 +- ...ameterDeclaration1ES5_es2015.2.minified.js | 6 +- ...ParameterDeclaration1ES5_es5.2.minified.js | 6 +- ...claration1ES5iterable_es2015.2.minified.js | 6 +- ...rDeclaration1ES5iterable_es5.2.minified.js | 6 +- ...ameterDeclaration1ES6_es2015.2.minified.js | 6 +- ...ParameterDeclaration1ES6_es5.2.minified.js | 6 +- ...ameterDeclaration3ES5_es2015.2.minified.js | 8 +- ...ParameterDeclaration3ES5_es5.2.minified.js | 8 +- ...claration3ES5iterable_es2015.2.minified.js | 8 +- ...rDeclaration3ES5iterable_es5.2.minified.js | 8 +- ...ameterDeclaration3ES6_es2015.2.minified.js | 8 +- ...ParameterDeclaration3ES6_es5.2.minified.js | 8 +- ...gVariableDeclaration1ES5_es5.2.minified.js | 18 +- ...eDeclaration1ES5iterable_es5.2.minified.js | 18 +- ...gVariableDeclaration1ES6_es5.2.minified.js | 18 +- ...gWithLiteralInitializers_es5.2.minified.js | 23 +- ...AssignmentPatterns01_ES5_es5.2.minified.js | 54 +- ...ntPatterns01_ES5iterable_es5.2.minified.js | 54 +- ...AssignmentPatterns01_ES6_es5.2.minified.js | 54 +- ...nabilityInInheritance_es2015.2.minified.js | 8 +- ...signabilityInInheritance_es5.2.minified.js | 10 +- .../enumAssignability_es2015.2.minified.js | 8 +- .../enumAssignability_es5.2.minified.js | 8 +- ...peOfAnythingButNumber_es2015.2.minified.js | 8 +- ...btypeOfAnythingButNumber_es5.2.minified.js | 10 +- .../enumLiteralTypes1_es2015.2.minified.js | 6 +- .../enumLiteralTypes1_es5.2.minified.js | 6 +- .../enumLiteralTypes2_es2015.2.minified.js | 6 +- .../enumLiteralTypes2_es5.2.minified.js | 6 +- .../enumLiteralTypes3_es2015.2.minified.js | 6 +- .../enumLiteralTypes3_es5.2.minified.js | 6 +- ...lekindWithES5Target12_es2015.2.minified.js | 8 +- ...odulekindWithES5Target12_es5.2.minified.js | 8 +- ...ulekindWithES5Target5_es2015.2.minified.js | 8 +- ...modulekindWithES5Target5_es5.2.minified.js | 8 +- ...lekindWithES5Target12_es2015.2.minified.js | 8 +- ...odulekindWithES5Target12_es5.2.minified.js | 8 +- ...ulekindWithES5Target5_es2015.2.minified.js | 8 +- ...modulekindWithES5Target5_es5.2.minified.js | 8 +- ...ryTypeAssignableToAny_es2015.2.minified.js | 6 +- ...everyTypeAssignableToAny_es5.2.minified.js | 6 +- ...otationAndInitializer_es2015.2.minified.js | 14 +- ...AndInvalidInitializer_es2015.2.minified.js | 20 +- ...ionAndInvalidInitializer_es5.2.minified.js | 4 +- ...ryTypeWithInitializer_es2015.2.minified.js | 14 +- ...OperatorWithEnumUnion_es2015.2.minified.js | 8 +- ...ionOperatorWithEnumUnion_es5.2.minified.js | 8 +- ...ationOperatorWithEnum_es2015.2.minified.js | 6 +- ...ntiationOperatorWithEnum_es5.2.minified.js | 6 +- ...orWithInvalidOperands_es2015.2.minified.js | 6 +- ...ratorWithInvalidOperands_es5.2.minified.js | 6 +- ...ValueAndValidOperands_es2015.2.minified.js | 6 +- ...ullValueAndValidOperands_es5.2.minified.js | 6 +- ...ValueAndValidOperands_es2015.2.minified.js | 6 +- ...nedValueAndValidOperands_es5.2.minified.js | 6 +- ...ignmentAndDeclaration_es2015.2.minified.js | 6 +- ...AssignmentAndDeclaration_es5.2.minified.js | 7 +- ...ssignmentMergedModule_es2015.2.minified.js | 16 +- ...rtAssignmentMergedModule_es5.2.minified.js | 16 +- ...nmentTopLevelEnumdule_es2015.2.minified.js | 6 +- ...signmentTopLevelEnumdule_es5.2.minified.js | 6 +- .../exportCodeGen_es5.2.minified.js | 4 +- .../exportImportAlias_es2015.2.minified.js | 14 +- ...xportsAndImports1-amd_es2015.2.minified.js | 8 +- .../exportsAndImports1-amd_es5.2.minified.js | 10 +- ...xportsAndImports1-es6_es2015.2.minified.js | 8 +- .../exportsAndImports1-es6_es5.2.minified.js | 10 +- .../exportsAndImports1_es2015.2.minified.js | 8 +- .../exportsAndImports1_es5.2.minified.js | 10 +- ...xportsAndImports3-amd_es2015.2.minified.js | 8 +- .../exportsAndImports3-amd_es5.2.minified.js | 8 +- ...xportsAndImports3-es6_es2015.2.minified.js | 8 +- .../exportsAndImports3-es6_es5.2.minified.js | 8 +- .../exportsAndImports3_es2015.2.minified.js | 8 +- .../exportsAndImports3_es5.2.minified.js | 8 +- ...ilterNamespace_import_es2015.2.minified.js | 10 +- .../for-inStatements_es2015.2.minified.js | 6 +- .../for-inStatements_es5.2.minified.js | 6 +- .../for-of47_es2015.2.minified.js | 6 +- .../tsc-references/for-of47_es5.2.minified.js | 5 +- .../for-of48_es2015.2.minified.js | 6 +- .../tsc-references/for-of48_es5.2.minified.js | 5 +- ...tsMultipleInvalidDecl_es2015.2.minified.js | 13 +- .../forStatements_es2015.2.minified.js | 14 +- ...sionContextualTyping1_es2015.2.minified.js | 6 +- ...ressionContextualTyping1_es5.2.minified.js | 6 +- ...thOverloadedArguments_es2015.2.minified.js | 4 +- ...dWithOverloadedArguments_es5.2.minified.js | 4 +- ...TypeArgumentInference_es2015.2.minified.js | 1 - ...allTypeArgumentInference_es5.2.minified.js | 1 - ...icSignatureArguments3_es2015.2.minified.js | 8 +- ...nericSignatureArguments3_es5.2.minified.js | 8 +- .../ifDoWhileStatements_es2015.2.minified.js | 20 +- ...NotUsedAsValues_error_es2015.2.minified.js | 10 +- ...rtsNotUsedAsValues_error_es5.2.minified.js | 12 +- ...orWithInvalidOperands_es2015.2.minified.js | 6 +- ...ratorWithInvalidOperands_es5.2.minified.js | 6 +- ...TypeInvalidOperations_es2015.2.minified.js | 6 +- ...numTypeInvalidOperations_es5.2.minified.js | 6 +- ...tOperatorWithEnumType_es2015.2.minified.js | 6 +- ...mentOperatorWithEnumType_es5.2.minified.js | 6 +- ...nstanceofOperatorWithAny_es5.2.minified.js | 6 +- ...ectIntersectionErrors_es2015.2.minified.js | 6 +- ...ObjectIntersectionErrors_es5.2.minified.js | 6 +- ...ndsObjectIntersection_es2015.2.minified.js | 6 +- ...xtendsObjectIntersection_es5.2.minified.js | 6 +- ...thPropertyOfEveryType_es2015.2.minified.js | 6 +- ...eWithPropertyOfEveryType_es5.2.minified.js | 6 +- ...ionOfUnionOfUnitTypes_es2015.2.minified.js | 6 +- ...ectionOfUnionOfUnitTypes_es5.2.minified.js | 6 +- ...lidBooleanAssignments_es2015.2.minified.js | 6 +- ...nvalidBooleanAssignments_es5.2.minified.js | 6 +- ...nvalidEnumAssignments_es2015.2.minified.js | 8 +- .../invalidEnumAssignments_es5.2.minified.js | 8 +- ...mportAliasIdentifiers_es2015.2.minified.js | 6 +- ...idImportAliasIdentifiers_es5.2.minified.js | 6 +- ...eVariableDeclarations_es2015.2.minified.js | 12 +- .../invalidNestedModules_es2015.2.minified.js | 16 +- ...alidStringAssignments_es2015.2.minified.js | 6 +- ...invalidStringAssignments_es5.2.minified.js | 6 +- ...dUndefinedAssignments_es2015.2.minified.js | 6 +- ...alidUndefinedAssignments_es5.2.minified.js | 6 +- ...nvalidUndefinedValues_es2015.2.minified.js | 6 +- .../invalidUndefinedValues_es5.2.minified.js | 6 +- ...nvalidVoidAssignments_es2015.2.minified.js | 6 +- .../invalidVoidAssignments_es5.2.minified.js | 6 +- .../invalidVoidValues_es2015.2.minified.js | 6 +- .../invalidVoidValues_es5.2.minified.js | 6 +- .../iterableArrayPattern15_es5.2.minified.js | 21 +- .../iterableArrayPattern16_es5.2.minified.js | 21 +- .../iterableArrayPattern1_es5.2.minified.js | 54 +- .../iterableArrayPattern20_es5.2.minified.js | 21 +- .../iterableArrayPattern21_es5.2.minified.js | 62 +- .../iterableArrayPattern22_es5.2.minified.js | 33 +- .../iterableArrayPattern23_es5.2.minified.js | 64 +- .../iterableArrayPattern24_es5.2.minified.js | 32 +- .../iterableArrayPattern27_es5.2.minified.js | 17 +- .../iterableArrayPattern28_es5.2.minified.js | 17 +- .../iterableArrayPattern29_es5.2.minified.js | 17 +- .../iterableArrayPattern2_es5.2.minified.js | 30 +- .../iterableArrayPattern3_es5.2.minified.js | 54 +- .../iterableArrayPattern4_es5.2.minified.js | 30 +- .../iterableArrayPattern5_es5.2.minified.js | 54 +- .../iterableArrayPattern6_es5.2.minified.js | 30 +- .../iterableArrayPattern7_es5.2.minified.js | 54 +- .../iterableArrayPattern8_es5.2.minified.js | 30 +- .../iteratorSpreadInArray10_es5.2.minified.js | 32 +- .../iteratorSpreadInArray11_es5.2.minified.js | 31 +- .../iteratorSpreadInArray4_es5.2.minified.js | 30 +- .../iteratorSpreadInArray5_es5.2.minified.js | 30 +- .../iteratorSpreadInArray6_es5.2.minified.js | 30 +- .../iteratorSpreadInArray7_es5.2.minified.js | 30 +- .../iteratorSpreadInArray8_es5.2.minified.js | 32 +- .../iteratorSpreadInArray9_es5.2.minified.js | 32 +- .../iteratorSpreadInArray_es5.2.minified.js | 32 +- .../iteratorSpreadInCall10_es5.2.minified.js | 30 +- .../iteratorSpreadInCall11_es5.2.minified.js | 30 +- .../iteratorSpreadInCall2_es5.2.minified.js | 30 +- .../iteratorSpreadInCall3_es5.2.minified.js | 30 +- .../iteratorSpreadInCall4_es5.2.minified.js | 30 +- .../iteratorSpreadInCall_es5.2.minified.js | 30 +- .../jsDeclarationsEnums_es2015.2.minified.js | 20 +- .../jsDeclarationsEnums_es5.2.minified.js | 20 +- ...ationsTypeReferences4_es2015.2.minified.js | 12 +- ...larationsTypeReferences4_es5.2.minified.js | 7 +- ...keyofAndIndexedAccess_es2015.2.minified.js | 10 +- .../keyofAndIndexedAccess_es5.2.minified.js | 10 +- .../literalTypeWidening_es2015.2.minified.js | 6 +- .../literalTypeWidening_es5.2.minified.js | 6 +- .../literalTypes2_es2015.2.minified.js | 6 +- .../literalTypes2_es5.2.minified.js | 6 +- ...tOperatorWithEnumType_es2015.2.minified.js | 6 +- ...lNotOperatorWithEnumType_es5.2.minified.js | 6 +- ...lappingStringEnumKeys_es2015.2.minified.js | 8 +- ...verlappingStringEnumKeys_es5.2.minified.js | 8 +- ...ixinAbstractClasses.2_es2015.2.minified.js | 9 +- .../nameCollision_es2015.2.minified.js | 6 +- .../nameCollision_es5.2.minified.js | 6 +- .../namedTupleMembers_es5.2.minified.js | 14 +- ...eOperatorWithEnumType_es2015.2.minified.js | 6 +- ...gateOperatorWithEnumType_es5.2.minified.js | 6 +- ...ncheckedIndexedAccess_es2015.2.minified.js | 10 +- ...noUncheckedIndexedAccess_es5.2.minified.js | 10 +- ...nonInstantiatedModule_es2015.2.minified.js | 14 +- .../nonInstantiatedModule_es5.2.minified.js | 14 +- .../nonPrimitiveNarrow_es5.2.minified.js | 6 +- ...AssignableToEveryType_es2015.2.minified.js | 6 +- ...ullAssignableToEveryType_es5.2.minified.js | 6 +- ...verythingButUndefined_es2015.2.minified.js | 6 +- ...OfEverythingButUndefined_es5.2.minified.js | 6 +- ...arameterBindingPattern.2_es5.2.minified.js | 6 +- ...umberAssignableToEnum_es2015.2.minified.js | 6 +- .../numberAssignableToEnum_es5.2.minified.js | 6 +- .../objectTypesIdentity2_es2015.2.minified.js | 6 +- .../objectTypesIdentity2_es5.2.minified.js | 6 +- ...serComputedPropertyName2_es5.2.minified.js | 15 +- ...erComputedPropertyName41_es5.2.minified.js | 15 +- ...ES5ComputedPropertyName2_es5.2.minified.js | 15 +- .../parserEnum1_es2015.2.minified.js | 6 +- .../parserEnum1_es5.2.minified.js | 6 +- .../parserEnum2_es2015.2.minified.js | 6 +- .../parserEnum2_es5.2.minified.js | 6 +- .../parserEnum6_es2015.2.minified.js | 6 +- .../parserEnum6_es5.2.minified.js | 6 +- ...arserEnumDeclaration1_es2015.2.minified.js | 6 +- .../parserEnumDeclaration1_es5.2.minified.js | 6 +- ...arserEnumDeclaration3_es2015.2.minified.js | 6 +- .../parserEnumDeclaration3_es5.2.minified.js | 6 +- ...arserEnumDeclaration5_es2015.2.minified.js | 6 +- .../parserEnumDeclaration5_es5.2.minified.js | 6 +- ...arserEnumDeclaration6_es2015.2.minified.js | 6 +- .../parserEnumDeclaration6_es5.2.minified.js | 6 +- ...terfaceKeywordInEnum1_es2015.2.minified.js | 6 +- ...rInterfaceKeywordInEnum1_es5.2.minified.js | 6 +- ...nterfaceKeywordInEnum_es2015.2.minified.js | 6 +- ...erInterfaceKeywordInEnum_es5.2.minified.js | 6 +- .../parserRealSource13_es2015.2.minified.js | 28 +- .../parserRealSource13_es5.2.minified.js | 32 +- .../parserRealSource1_es2015.2.minified.js | 232 +- .../parserRealSource5_es2015.2.minified.js | 66 +- ...sOperatorWithEnumType_es2015.2.minified.js | 6 +- ...plusOperatorWithEnumType_es5.2.minified.js | 6 +- ...tiveTypesAreIdentical_es2015.2.minified.js | 6 +- ...rimtiveTypesAreIdentical_es5.2.minified.js | 6 +- .../propertyAccess_es2015.2.minified.js | 6 +- .../propertyAccess_es5.2.minified.js | 6 +- ...otAccessibleInClodule_es2015.2.minified.js | 7 +- ...icNotAccessibleInClodule_es5.2.minified.js | 8 +- ...ntWithAssignmentPattern3_es5.2.minified.js | 48 +- ...ntWithAssignmentPattern4_es5.2.minified.js | 34 +- .../scannerEnum1_es2015.2.minified.js | 6 +- .../scannerEnum1_es5.2.minified.js | 6 +- ...EnumInElementAccess01_es2015.2.minified.js | 6 +- ...ingEnumInElementAccess01_es5.2.minified.js | 6 +- ...ringEnumLiteralTypes1_es2015.2.minified.js | 6 +- .../stringEnumLiteralTypes1_es5.2.minified.js | 6 +- ...ringEnumLiteralTypes2_es2015.2.minified.js | 6 +- .../stringEnumLiteralTypes2_es5.2.minified.js | 6 +- ...ringEnumLiteralTypes3_es2015.2.minified.js | 6 +- .../stringEnumLiteralTypes3_es5.2.minified.js | 6 +- ...TypeIsSubtypeOfString_es2015.2.minified.js | 6 +- ...ralTypeIsSubtypeOfString_es5.2.minified.js | 6 +- .../subtypesOfAny_es2015.2.minified.js | 6 +- .../subtypesOfAny_es5.2.minified.js | 6 +- ...meterWithConstraints2_es2015.2.minified.js | 6 +- ...arameterWithConstraints2_es5.2.minified.js | 6 +- ...btypesOfTypeParameter_es2015.2.minified.js | 6 +- .../subtypesOfTypeParameter_es5.2.minified.js | 6 +- .../subtypesOfUnion_es2015.2.minified.js | 6 +- .../subtypesOfUnion_es5.2.minified.js | 6 +- .../symbolDeclarationEmit8_es5.2.minified.js | 15 +- .../symbolProperty52_es5.2.minified.js | 15 +- .../symbolProperty53_es5.2.minified.js | 15 +- .../symbolProperty54_es5.2.minified.js | 15 +- .../symbolProperty55_es5.2.minified.js | 16 +- .../symbolProperty56_es5.2.minified.js | 16 +- .../symbolProperty57_es5.2.minified.js | 15 +- .../symbolProperty58_es5.2.minified.js | 15 +- .../symbolType17_es5.2.minified.js | 6 +- .../symbolType3_es5.2.minified.js | 6 +- ...ateStringInInstanceOfES6_es5.2.minified.js | 5 +- ...mplateStringInInstanceOf_es5.2.minified.js | 5 +- ...emplateStringInTypeOfES6_es5.2.minified.js | 5 +- .../templateStringInTypeOf_es5.2.minified.js | 5 +- ...ithEmbeddedInstanceOfES6_es5.2.minified.js | 5 +- ...ngWithEmbeddedInstanceOf_es5.2.minified.js | 5 +- ...mbeddedTypeOfOperatorES6_es5.2.minified.js | 5 +- ...thEmbeddedTypeOfOperator_es5.2.minified.js | 5 +- .../thisTypeInFunctions_es2015.2.minified.js | 2 +- .../throwStatements_es2015.2.minified.js | 12 +- .../tsxEmit3x_es2015.2.minified.js | 14 +- .../tsxEmit3x_es5.2.minified.js | 10 +- .../typeAliases_es2015.2.minified.js | 6 +- .../typeAliases_es5.2.minified.js | 6 +- ...enceWithObjectLiteral_es2015.2.minified.js | 8 +- ...ferenceWithObjectLiteral_es5.2.minified.js | 8 +- ...mPropertyAssignment31_es2015.2.minified.js | 9 +- ...FromPropertyAssignment31_es5.2.minified.js | 9 +- ...mPropertyAssignment32_es2015.2.minified.js | 9 +- ...FromPropertyAssignment32_es5.2.minified.js | 9 +- ...mPropertyAssignment33_es2015.2.minified.js | 9 +- ...FromPropertyAssignment33_es5.2.minified.js | 9 +- ...eOfEqualEqualHasNoEffect_es5.2.minified.js | 6 +- ...ypeOfNotEqualHasNoEffect_es5.2.minified.js | 6 +- .../typeGuardsWithAny_es5.2.minified.js | 8 +- ...typeGuardsWithInstanceOf_es5.2.minified.js | 6 +- ...ypeofANonExportedType_es2015.2.minified.js | 16 +- .../typeofANonExportedType_es5.2.minified.js | 6 +- .../typeofAnExportedType_es2015.2.minified.js | 24 +- .../typeofAnExportedType_es5.2.minified.js | 6 +- ...fOperatorWithEnumType_es2015.2.minified.js | 6 +- ...peofOperatorWithEnumType_es5.2.minified.js | 6 +- ...AssignableToEveryType_es2015.2.minified.js | 6 +- ...nedAssignableToEveryType_es5.2.minified.js | 6 +- ...IsSubtypeOfEverything_es2015.2.minified.js | 6 +- ...nedIsSubtypeOfEverything_es5.2.minified.js | 8 +- ...ndIntersectionInference1_es5.2.minified.js | 6 +- ...stituentTypeIsSubtype_es2015.2.minified.js | 8 +- ...ConstituentTypeIsSubtype_es5.2.minified.js | 10 +- .../unionsOfTupleTypes1_es5.2.minified.js | 56 +- .../unknownType2_es2015.2.minified.js | 8 +- .../unknownType2_es5.2.minified.js | 8 +- .../validEnumAssignments_es2015.2.minified.js | 6 +- .../validEnumAssignments_es5.2.minified.js | 6 +- .../validNullAssignments_es2015.2.minified.js | 6 +- .../validNullAssignments_es5.2.minified.js | 6 +- ...alidNumberAssignments_es2015.2.minified.js | 6 +- .../validNumberAssignments_es5.2.minified.js | 6 +- ...dOperatorWithEnumType_es2015.2.minified.js | 6 +- ...voidOperatorWithEnumType_es5.2.minified.js | 6 +- crates/swc_ecma_minifier/src/analyzer/mod.rs | 15 + .../src/compress/hoist_decls.rs | 39 +- .../src/compress/optimize/iife.rs | 20 +- .../src/compress/optimize/join_vars.rs | 12 +- .../src/compress/optimize/mod.rs | 116 +- .../src/compress/optimize/sequences.rs | 71 +- .../src/compress/pure/mod.rs | 44 +- .../src/compress/util/mod.rs | 13 +- crates/swc_ecma_minifier/src/debug.rs | 10 +- crates/swc_ecma_minifier/src/util/unit.rs | 14 +- .../fixture/issues/firebase-core/1/output.js | 2 +- .../chunks/d6e1aeb5-38a8d7ae57119c23/input.js | 54623 ++++++++++++++++ .../d6e1aeb5-38a8d7ae57119c23/output.js | 15271 +++++ .../pages/index-cb36c1bf7f830e3c/input.js | 14209 ++++ .../pages/index-cb36c1bf7f830e3c/output.js | 5955 ++ .../tests/compress/fixture/reduced/1/input.js | 25 + .../compress/fixture/reduced/1/output.js | 23 + .../compress/fixture/reduced/config.json | 3 +- .../tests/projects/output/react-dom-17.0.2.js | 8 +- 487 files changed, 93631 insertions(+), 2341 deletions(-) create mode 100644 crates/swc_ecma_minifier/tests/compress/fixture/next/33265/static/chunks/d6e1aeb5-38a8d7ae57119c23/input.js create mode 100644 crates/swc_ecma_minifier/tests/compress/fixture/next/33265/static/chunks/d6e1aeb5-38a8d7ae57119c23/output.js create mode 100644 crates/swc_ecma_minifier/tests/compress/fixture/next/33265/static/chunks/pages/index-cb36c1bf7f830e3c/input.js create mode 100644 crates/swc_ecma_minifier/tests/compress/fixture/next/33265/static/chunks/pages/index-cb36c1bf7f830e3c/output.js create mode 100644 crates/swc_ecma_minifier/tests/compress/fixture/reduced/1/input.js create mode 100644 crates/swc_ecma_minifier/tests/compress/fixture/reduced/1/output.js diff --git a/crates/swc/tests/tsc-references/ClassAndModuleWithSameNameAndCommonRootES6_es2015.2.minified.js b/crates/swc/tests/tsc-references/ClassAndModuleWithSameNameAndCommonRootES6_es2015.2.minified.js index 4767d6d1dfd..7980620217d 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleWithSameNameAndCommonRootES6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleWithSameNameAndCommonRootES6_es2015.2.minified.js @@ -1,9 +1,11 @@ -var X, X1; -((X1 = X || (X = {})).Y || (X1.Y = {})).Point = class { - constructor(x, y){ - this.x = x, this.y = y; - } -}, (function(X2) { +var X; +!function(X1) { + (X1.Y || (X1.Y = {})).Point = class { + constructor(x, y){ + this.x = x, this.y = y; + } + }; +}(X || (X = {})), (function(X2) { var Y; let Point; (Point = (Y = X2.Y || (X2.Y = {})).Point || (Y.Point = {})).Origin = new Point(0, 0); diff --git a/crates/swc/tests/tsc-references/ClassAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js b/crates/swc/tests/tsc-references/ClassAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js index 4767d6d1dfd..7980620217d 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js @@ -1,9 +1,11 @@ -var X, X1; -((X1 = X || (X = {})).Y || (X1.Y = {})).Point = class { - constructor(x, y){ - this.x = x, this.y = y; - } -}, (function(X2) { +var X; +!function(X1) { + (X1.Y || (X1.Y = {})).Point = class { + constructor(x, y){ + this.x = x, this.y = y; + } + }; +}(X || (X = {})), (function(X2) { var Y; let Point; (Point = (Y = X2.Y || (X2.Y = {})).Point || (Y.Point = {})).Origin = new Point(0, 0); diff --git a/crates/swc/tests/tsc-references/EnumAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js b/crates/swc/tests/tsc-references/EnumAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js index 38aa435ac94..bd58891313b 100644 --- a/crates/swc/tests/tsc-references/EnumAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/EnumAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js @@ -1,5 +1,7 @@ -var enumdule, enumdule; -(enumdule = enumdule || (enumdule = {}))[enumdule.Red = 0] = "Red", enumdule[enumdule.Blue = 1] = "Blue", (enumdule || (enumdule = {})).Point = class { +var enumdule; +!function(enumdule) { + enumdule[enumdule.Red = 0] = "Red", enumdule[enumdule.Blue = 1] = "Blue"; +}(enumdule || (enumdule = {})), (enumdule || (enumdule = {})).Point = class { constructor(x, y){ this.x = x, this.y = y; } diff --git a/crates/swc/tests/tsc-references/EnumAndModuleWithSameNameAndCommonRoot_es5.2.minified.js b/crates/swc/tests/tsc-references/EnumAndModuleWithSameNameAndCommonRoot_es5.2.minified.js index 60020a9dc3c..de29b248fe8 100644 --- a/crates/swc/tests/tsc-references/EnumAndModuleWithSameNameAndCommonRoot_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/EnumAndModuleWithSameNameAndCommonRoot_es5.2.minified.js @@ -1,10 +1,12 @@ -var enumdule, enumdule; -(enumdule = enumdule || (enumdule = {}))[enumdule.Red = 0] = "Red", enumdule[enumdule.Blue = 1] = "Blue", (function(enumdule1) { +var enumdule; +!function(enumdule) { + enumdule[enumdule.Red = 0] = "Red", enumdule[enumdule.Blue = 1] = "Blue"; +}(enumdule || (enumdule = {})), (function(enumdule) { var Point = function(x, y) { "use strict"; (function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); })(this, Point), this.x = x, this.y = y; }; - enumdule1.Point = Point; + enumdule.Point = Point; })(enumdule || (enumdule = {})), enumdule.Red, new enumdule.Point(0, 0); diff --git a/crates/swc/tests/tsc-references/ExportInterfaceWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations_es2015.2.minified.js b/crates/swc/tests/tsc-references/ExportInterfaceWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations_es2015.2.minified.js index 8d14f90e040..1d7dbc149bf 100644 --- a/crates/swc/tests/tsc-references/ExportInterfaceWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ExportInterfaceWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations_es2015.2.minified.js @@ -1,9 +1,11 @@ -var A, A1; -(A1 = A || (A = {})).Origin = { - x: 0, - y: 0 -}, A1.Origin3d = { - x: 0, - y: 0, - z: 0 -}; +var A; +!function(A1) { + A1.Origin = { + x: 0, + y: 0 + }, A1.Origin3d = { + x: 0, + y: 0, + z: 0 + }; +}(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/ExportInterfaceWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations_es5.2.minified.js b/crates/swc/tests/tsc-references/ExportInterfaceWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations_es5.2.minified.js index 8d14f90e040..1d7dbc149bf 100644 --- a/crates/swc/tests/tsc-references/ExportInterfaceWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/ExportInterfaceWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations_es5.2.minified.js @@ -1,9 +1,11 @@ -var A, A1; -(A1 = A || (A = {})).Origin = { - x: 0, - y: 0 -}, A1.Origin3d = { - x: 0, - y: 0, - z: 0 -}; +var A; +!function(A1) { + A1.Origin = { + x: 0, + y: 0 + }, A1.Origin3d = { + x: 0, + y: 0, + z: 0 + }; +}(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/ExportInterfaceWithInaccessibleTypeInTypeParameterConstraint_es2015.2.minified.js b/crates/swc/tests/tsc-references/ExportInterfaceWithInaccessibleTypeInTypeParameterConstraint_es2015.2.minified.js index 8d14f90e040..1d7dbc149bf 100644 --- a/crates/swc/tests/tsc-references/ExportInterfaceWithInaccessibleTypeInTypeParameterConstraint_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ExportInterfaceWithInaccessibleTypeInTypeParameterConstraint_es2015.2.minified.js @@ -1,9 +1,11 @@ -var A, A1; -(A1 = A || (A = {})).Origin = { - x: 0, - y: 0 -}, A1.Origin3d = { - x: 0, - y: 0, - z: 0 -}; +var A; +!function(A1) { + A1.Origin = { + x: 0, + y: 0 + }, A1.Origin3d = { + x: 0, + y: 0, + z: 0 + }; +}(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/ExportInterfaceWithInaccessibleTypeInTypeParameterConstraint_es5.2.minified.js b/crates/swc/tests/tsc-references/ExportInterfaceWithInaccessibleTypeInTypeParameterConstraint_es5.2.minified.js index 8d14f90e040..1d7dbc149bf 100644 --- a/crates/swc/tests/tsc-references/ExportInterfaceWithInaccessibleTypeInTypeParameterConstraint_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/ExportInterfaceWithInaccessibleTypeInTypeParameterConstraint_es5.2.minified.js @@ -1,9 +1,11 @@ -var A, A1; -(A1 = A || (A = {})).Origin = { - x: 0, - y: 0 -}, A1.Origin3d = { - x: 0, - y: 0, - z: 0 -}; +var A; +!function(A1) { + A1.Origin = { + x: 0, + y: 0 + }, A1.Origin3d = { + x: 0, + y: 0, + z: 0 + }; +}(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/ExportVariableWithInaccessibleTypeInTypeAnnotation_es2015.2.minified.js b/crates/swc/tests/tsc-references/ExportVariableWithInaccessibleTypeInTypeAnnotation_es2015.2.minified.js index 8d14f90e040..1d7dbc149bf 100644 --- a/crates/swc/tests/tsc-references/ExportVariableWithInaccessibleTypeInTypeAnnotation_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ExportVariableWithInaccessibleTypeInTypeAnnotation_es2015.2.minified.js @@ -1,9 +1,11 @@ -var A, A1; -(A1 = A || (A = {})).Origin = { - x: 0, - y: 0 -}, A1.Origin3d = { - x: 0, - y: 0, - z: 0 -}; +var A; +!function(A1) { + A1.Origin = { + x: 0, + y: 0 + }, A1.Origin3d = { + x: 0, + y: 0, + z: 0 + }; +}(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/ExportVariableWithInaccessibleTypeInTypeAnnotation_es5.2.minified.js b/crates/swc/tests/tsc-references/ExportVariableWithInaccessibleTypeInTypeAnnotation_es5.2.minified.js index 8d14f90e040..1d7dbc149bf 100644 --- a/crates/swc/tests/tsc-references/ExportVariableWithInaccessibleTypeInTypeAnnotation_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/ExportVariableWithInaccessibleTypeInTypeAnnotation_es5.2.minified.js @@ -1,9 +1,11 @@ -var A, A1; -(A1 = A || (A = {})).Origin = { - x: 0, - y: 0 -}, A1.Origin3d = { - x: 0, - y: 0, - z: 0 -}; +var A; +!function(A1) { + A1.Origin = { + x: 0, + y: 0 + }, A1.Origin3d = { + x: 0, + y: 0, + z: 0 + }; +}(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js b/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js index 6a44ffcaef3..a8a6cef6765 100644 --- a/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndCommonRoot_es2015.2.minified.js @@ -1,13 +1,15 @@ -var A, B, A1; +var A, B; (A || (A = {})).Point = function() { return { x: 0, y: 0 }; -}, ((A1 = A || (A = {})).Point || (A1.Point = {})).Origin = { - x: 0, - y: 0 -}, A.Point, A.Point(), A.Point.Origin, (function(B1) { +}, (function(A1) { + (A1.Point || (A1.Point = {})).Origin = { + x: 0, + y: 0 + }; +})(A || (A = {})), A.Point, A.Point(), A.Point.Origin, (function(B1) { function Point() { return { x: 0, diff --git a/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndCommonRoot_es5.2.minified.js b/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndCommonRoot_es5.2.minified.js index 57aeabe973b..f74f29b3d7a 100644 --- a/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndCommonRoot_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndCommonRoot_es5.2.minified.js @@ -1,13 +1,15 @@ -var A, B, A1; +var A, B; (A || (A = {})).Point = function() { return { x: 0, y: 0 }; -}, ((A1 = A || (A = {})).Point || (A1.Point = {})).Origin = { - x: 0, - y: 0 -}, A.Point, A.Point(), A.Point.Origin, (function(B1) { +}, (function(A1) { + (A1.Point || (A1.Point = {})).Origin = { + x: 0, + y: 0 + }; +})(A || (A = {})), A.Point, A.Point(), A.Point.Origin, (function(B1) { var Point = function() { return { x: 0, diff --git a/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndDifferentCommonRoot_es2015.2.minified.js b/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndDifferentCommonRoot_es2015.2.minified.js index 499f5f2dc39..f73c89d15ec 100644 --- a/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndDifferentCommonRoot_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndDifferentCommonRoot_es2015.2.minified.js @@ -1,10 +1,12 @@ -var A, B, B1; +var A, B; (A || (A = {})).Point = function() { return { x: 0, y: 0 }; -}, ((B1 = B || (B = {})).Point || (B1.Point = {})).Origin = { - x: 0, - y: 0 -}, A.Point, B.Point.Origin; +}, (function(B1) { + (B1.Point || (B1.Point = {})).Origin = { + x: 0, + y: 0 + }; +})(B || (B = {})), A.Point, B.Point.Origin; diff --git a/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndDifferentCommonRoot_es5.2.minified.js b/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndDifferentCommonRoot_es5.2.minified.js index 499f5f2dc39..f73c89d15ec 100644 --- a/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndDifferentCommonRoot_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/FunctionAndModuleWithSameNameAndDifferentCommonRoot_es5.2.minified.js @@ -1,10 +1,12 @@ -var A, B, B1; +var A, B; (A || (A = {})).Point = function() { return { x: 0, y: 0 }; -}, ((B1 = B || (B = {})).Point || (B1.Point = {})).Origin = { - x: 0, - y: 0 -}, A.Point, B.Point.Origin; +}, (function(B1) { + (B1.Point || (B1.Point = {})).Origin = { + x: 0, + y: 0 + }; +})(B || (B = {})), A.Point, B.Point.Origin; diff --git a/crates/swc/tests/tsc-references/FunctionPropertyAssignments5_es6_es5.2.minified.js b/crates/swc/tests/tsc-references/FunctionPropertyAssignments5_es6_es5.2.minified.js index 41a5355c1c4..704255c6da9 100644 --- a/crates/swc/tests/tsc-references/FunctionPropertyAssignments5_es6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/FunctionPropertyAssignments5_es6_es5.2.minified.js @@ -1,6 +1,12 @@ -var obj, key, value; import regeneratorRuntime from "regenerator-runtime"; -obj = {}, key = foo(), value = regeneratorRuntime.mark(function _callee() { +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, foo(), regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -8,9 +14,4 @@ obj = {}, key = foo(), value = regeneratorRuntime.mark(function _callee() { return _ctx.stop(); } }, _callee); -}), key in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +})); diff --git a/crates/swc/tests/tsc-references/ModuleAndClassWithSameNameAndCommonRoot_es2015.2.minified.js b/crates/swc/tests/tsc-references/ModuleAndClassWithSameNameAndCommonRoot_es2015.2.minified.js index 3c17536633c..3e996b61e9d 100644 --- a/crates/swc/tests/tsc-references/ModuleAndClassWithSameNameAndCommonRoot_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ModuleAndClassWithSameNameAndCommonRoot_es2015.2.minified.js @@ -1,12 +1,14 @@ -var X, X1; -!function(X2) { +var X; +!function(X1) { var Y; let Point; - (Point = (Y = X2.Y || (X2.Y = {})).Point || (Y.Point = {})).Origin = new Point(0, 0); -}(X || (X = {})), ((X1 = X || (X = {})).Y || (X1.Y = {})).Point = class { - constructor(x, y){ - this.x = x, this.y = y; - } -}, (A || (A = {})).Instance = new A(); + (Point = (Y = X1.Y || (X1.Y = {})).Point || (Y.Point = {})).Origin = new Point(0, 0); +}(X || (X = {})), (function(X2) { + (X2.Y || (X2.Y = {})).Point = class { + constructor(x, y){ + this.x = x, this.y = y; + } + }; +})(X || (X = {})), (A || (A = {})).Instance = new A(); class A { } diff --git a/crates/swc/tests/tsc-references/ModuleAndEnumWithSameNameAndCommonRoot_es2015.2.minified.js b/crates/swc/tests/tsc-references/ModuleAndEnumWithSameNameAndCommonRoot_es2015.2.minified.js index 06d91cbf4c0..2c4a1093679 100644 --- a/crates/swc/tests/tsc-references/ModuleAndEnumWithSameNameAndCommonRoot_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ModuleAndEnumWithSameNameAndCommonRoot_es2015.2.minified.js @@ -1,6 +1,8 @@ -var enumdule, enumdule; +var enumdule; (enumdule || (enumdule = {})).Point = class { constructor(x, y){ this.x = x, this.y = y; } -}, (enumdule = enumdule || (enumdule = {}))[enumdule.Red = 0] = "Red", enumdule[enumdule.Blue = 1] = "Blue", enumdule.Red, new enumdule.Point(0, 0); +}, (function(enumdule) { + enumdule[enumdule.Red = 0] = "Red", enumdule[enumdule.Blue = 1] = "Blue"; +})(enumdule || (enumdule = {})), enumdule.Red, new enumdule.Point(0, 0); diff --git a/crates/swc/tests/tsc-references/ModuleAndEnumWithSameNameAndCommonRoot_es5.2.minified.js b/crates/swc/tests/tsc-references/ModuleAndEnumWithSameNameAndCommonRoot_es5.2.minified.js index c3bf32cf07a..4c0a827969e 100644 --- a/crates/swc/tests/tsc-references/ModuleAndEnumWithSameNameAndCommonRoot_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/ModuleAndEnumWithSameNameAndCommonRoot_es5.2.minified.js @@ -1,4 +1,4 @@ -var enumdule, enumdule; +var enumdule; !function(enumdule1) { var Point = function(x, y) { "use strict"; @@ -7,4 +7,6 @@ var enumdule, enumdule; })(this, Point), this.x = x, this.y = y; }; enumdule1.Point = Point; -}(enumdule || (enumdule = {})), (enumdule = enumdule || (enumdule = {}))[enumdule.Red = 0] = "Red", enumdule[enumdule.Blue = 1] = "Blue", enumdule.Red, new enumdule.Point(0, 0); +}(enumdule || (enumdule = {})), (function(enumdule) { + enumdule[enumdule.Red = 0] = "Red", enumdule[enumdule.Blue = 1] = "Blue"; +})(enumdule || (enumdule = {})), enumdule.Red, new enumdule.Point(0, 0); diff --git a/crates/swc/tests/tsc-references/ModuleAndFunctionWithSameNameAndCommonRoot_es2015.2.minified.js b/crates/swc/tests/tsc-references/ModuleAndFunctionWithSameNameAndCommonRoot_es2015.2.minified.js index e86b1a59fdf..a37a4fb5678 100644 --- a/crates/swc/tests/tsc-references/ModuleAndFunctionWithSameNameAndCommonRoot_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ModuleAndFunctionWithSameNameAndCommonRoot_es2015.2.minified.js @@ -1,8 +1,10 @@ -var A, B, A1; -((A1 = A || (A = {})).Point || (A1.Point = {})).Origin = { - x: 0, - y: 0 -}, (A || (A = {})).Point = function() { +var A, B; +!function(A1) { + (A1.Point || (A1.Point = {})).Origin = { + x: 0, + y: 0 + }; +}(A || (A = {})), (A || (A = {})).Point = function() { return { x: 0, y: 0 diff --git a/crates/swc/tests/tsc-references/ModuleAndFunctionWithSameNameAndCommonRoot_es5.2.minified.js b/crates/swc/tests/tsc-references/ModuleAndFunctionWithSameNameAndCommonRoot_es5.2.minified.js index 64a14c49d5a..7f6bb93989c 100644 --- a/crates/swc/tests/tsc-references/ModuleAndFunctionWithSameNameAndCommonRoot_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/ModuleAndFunctionWithSameNameAndCommonRoot_es5.2.minified.js @@ -1,8 +1,10 @@ -var A, B, A1; -((A1 = A || (A = {})).Point || (A1.Point = {})).Origin = { - x: 0, - y: 0 -}, (A || (A = {})).Point = function() { +var A, B; +!function(A1) { + (A1.Point || (A1.Point = {})).Origin = { + x: 0, + y: 0 + }; +}(A || (A = {})), (A || (A = {})).Point = function() { return { x: 0, y: 0 diff --git a/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedClasses_es2015.2.minified.js b/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedClasses_es2015.2.minified.js index 0e0c1a70d16..b98776fbd27 100644 --- a/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedClasses_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedClasses_es2015.2.minified.js @@ -1,4 +1,6 @@ -var A, A1; -(A = A1 || (A1 = {})).A = class { -}, A.AG = class { -}, new A1.A(), new A1.AG(), new A1.A2(), new A1.A2(); +var A; +!function(A1) { + A1.A = class { + }, A1.AG = class { + }; +}(A || (A = {})), new A.A(), new A.AG(), new A.A2(), new A.A2(); diff --git a/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedFunctions_es2015.2.minified.js b/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedFunctions_es2015.2.minified.js index 7d5153bf92e..10fba366b1c 100644 --- a/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedFunctions_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedFunctions_es2015.2.minified.js @@ -1,6 +1,8 @@ -var A, A1; -(A = A1 || (A1 = {})).fn = function(s) { - return !0; -}, A.fng = function(s) { - return null; -}, A1.fn, A1.fng, A1.fn2, A1.fng2; +var A; +!function(A1) { + A1.fn = function(s) { + return !0; + }, A1.fng = function(s) { + return null; + }; +}(A || (A = {})), A.fn, A.fng, A.fn2, A.fng2; diff --git a/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedFunctions_es5.2.minified.js b/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedFunctions_es5.2.minified.js index 9bde6e8fcc9..10fba366b1c 100644 --- a/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedFunctions_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/ModuleWithExportedAndNonExportedFunctions_es5.2.minified.js @@ -1,6 +1,8 @@ -var A, A1; -(A1 = A || (A = {})).fn = function(s) { - return !0; -}, A1.fng = function(s) { - return null; -}, A.fn, A.fng, A.fn2, A.fng2; +var A; +!function(A1) { + A1.fn = function(s) { + return !0; + }, A1.fng = function(s) { + return null; + }; +}(A || (A = {})), A.fn, A.fng, A.fn2, A.fng2; diff --git a/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName_es2015.2.minified.js b/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName_es2015.2.minified.js index 8b5e2abbb81..3c2b9a75822 100644 --- a/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName_es2015.2.minified.js @@ -1,7 +1,9 @@ -var A, X, X1; +var A, X; (A || (A = {})).Point = class { -}, (function(X2) { +}, (function(X1) { var Y; - ((Y = X2.Y || (X2.Y = {})).Z || (Y.Z = {})).Line = class { + ((Y = X1.Y || (X1.Y = {})).Z || (Y.Z = {})).Line = class { }; -})(X || (X = {})), (X1 = X || (X = {})).Y || (X1.Y = {}); +})(X || (X = {})), (function(X2) { + X2.Y || (X2.Y = {}); +})(X || (X = {})); diff --git a/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedLocalVarsOfTheSameName_es2015.2.minified.js b/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedLocalVarsOfTheSameName_es2015.2.minified.js index 9a4cf127dd6..84f39ad1de1 100644 --- a/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedLocalVarsOfTheSameName_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedLocalVarsOfTheSameName_es2015.2.minified.js @@ -1,19 +1,22 @@ -var A, A1; -((A = A2 || (A2 = {})).Utils || (A.Utils = {})).mirror = function(p) { - return { - x: p.y, - y: p.x +!function(A1) { + (A1.Utils || (A1.Utils = {})).mirror = function(p) { + return { + x: p.y, + y: p.x + }; + }, A1.Origin = { + x: 0, + y: 0 }; -}, A.Origin = { - x: 0, - y: 0 -}, ((A1 = A2 || (A2 = {})).Utils || (A1.Utils = {})).Plane = class { - constructor(tl, br){ - this.tl = tl, this.br = br; - } -}; -var A2, o, o, o = A2.Origin, o = A2.Utils.mirror(o); -new A2.Utils.Plane(o, { +}(A || (A = {})), (function(A2) { + (A2.Utils || (A2.Utils = {})).Plane = class { + constructor(tl, br){ + this.tl = tl, this.br = br; + } + }; +})(A || (A = {})); +var A, o, o, o = A.Origin, o = A.Utils.mirror(o); +new A.Utils.Plane(o, { x: 1, y: 1 }); diff --git a/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedLocalVarsOfTheSameName_es5.2.minified.js b/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedLocalVarsOfTheSameName_es5.2.minified.js index e769458e022..8b7ea98cf23 100644 --- a/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedLocalVarsOfTheSameName_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedAndNonExportedLocalVarsOfTheSameName_es5.2.minified.js @@ -1,13 +1,14 @@ -var A; -((A = A1 || (A1 = {})).Utils || (A.Utils = {})).mirror = function(p) { - return { - x: p.y, - y: p.x +!function(A1) { + (A1.Utils || (A1.Utils = {})).mirror = function(p) { + return { + x: p.y, + y: p.x + }; + }, A1.Origin = { + x: 0, + y: 0 }; -}, A.Origin = { - x: 0, - y: 0 -}, (function(A2) { +}(A || (A = {})), (function(A2) { var Utils, Plane; Utils = A2.Utils || (A2.Utils = {}), Plane = function(tl, br) { "use strict"; @@ -15,9 +16,9 @@ var A; if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); })(this, Plane), this.tl = tl, this.br = br; }, Utils.Plane = Plane; -})(A1 || (A1 = {})); -var A1, o, o, o = A1.Origin, o = A1.Utils.mirror(o); -new A1.Utils.Plane(o, { +})(A || (A = {})); +var A, o, o, o = A.Origin, o = A.Utils.mirror(o); +new A.Utils.Plane(o, { x: 1, y: 1 }); diff --git a/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedLocalVarsOfTheSameName_es2015.2.minified.js b/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedLocalVarsOfTheSameName_es2015.2.minified.js index 5ee200e566b..eee7bfc4561 100644 --- a/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedLocalVarsOfTheSameName_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedLocalVarsOfTheSameName_es2015.2.minified.js @@ -1,17 +1,21 @@ -var A, A1, A2; -((A1 = A || (A = {})).Utils || (A1.Utils = {})).mirror = function(p) { - return { - x: p.y, - y: p.x +export var A; +!function(A1) { + (A1.Utils || (A1.Utils = {})).mirror = function(p) { + return { + x: p.y, + y: p.x + }; + }, A1.Origin = { + x: 0, + y: 0 }; -}, A1.Origin = { - x: 0, - y: 0 -}, (A2 = A || (A = {})).Origin = { - x: 0, - y: 0 -}, (A2.Utils || (A2.Utils = {})).Plane = class { - constructor(tl, br){ - this.tl = tl, this.br = br; - } -}; +}(A || (A = {})), (function(A2) { + A2.Origin = { + x: 0, + y: 0 + }, (A2.Utils || (A2.Utils = {})).Plane = class { + constructor(tl, br){ + this.tl = tl, this.br = br; + } + }; +})(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedLocalVarsOfTheSameName_es5.2.minified.js b/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedLocalVarsOfTheSameName_es5.2.minified.js index a9cde778f5c..af2ef1cf05f 100644 --- a/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedLocalVarsOfTheSameName_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/TwoInternalModulesThatMergeEachWithExportedLocalVarsOfTheSameName_es5.2.minified.js @@ -1,13 +1,15 @@ -var A, A1; -((A1 = A || (A = {})).Utils || (A1.Utils = {})).mirror = function(p) { - return { - x: p.y, - y: p.x +export var A; +!function(A1) { + (A1.Utils || (A1.Utils = {})).mirror = function(p) { + return { + x: p.y, + y: p.x + }; + }, A1.Origin = { + x: 0, + y: 0 }; -}, A1.Origin = { - x: 0, - y: 0 -}, (function(A2) { +}(A || (A = {})), (function(A2) { var Utils, Plane; A2.Origin = { x: 0, diff --git a/crates/swc/tests/tsc-references/TwoInternalModulesWithTheSameNameAndSameCommonRoot_es2015.2.minified.js b/crates/swc/tests/tsc-references/TwoInternalModulesWithTheSameNameAndSameCommonRoot_es2015.2.minified.js index aa8645f41d4..f40e3617959 100644 --- a/crates/swc/tests/tsc-references/TwoInternalModulesWithTheSameNameAndSameCommonRoot_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/TwoInternalModulesWithTheSameNameAndSameCommonRoot_es2015.2.minified.js @@ -1,19 +1,22 @@ -var A, A1; -((A = A2 || (A2 = {})).Utils || (A.Utils = {})).mirror = function(p) { - return { - x: p.y, - y: p.x +!function(A1) { + (A1.Utils || (A1.Utils = {})).mirror = function(p) { + return { + x: p.y, + y: p.x + }; }; -}, (A1 = A2 || (A2 = {})).Origin = { - x: 0, - y: 0 -}, (A1.Utils || (A1.Utils = {})).Plane = class { - constructor(tl, br){ - this.tl = tl, this.br = br; - } -}; -var A2, o, o, o = A2.Origin, o = A2.Utils.mirror(o); -new A2.Utils.Plane(o, { +}(A || (A = {})), (function(A2) { + A2.Origin = { + x: 0, + y: 0 + }, (A2.Utils || (A2.Utils = {})).Plane = class { + constructor(tl, br){ + this.tl = tl, this.br = br; + } + }; +})(A || (A = {})); +var A, o, o, o = A.Origin, o = A.Utils.mirror(o); +new A.Utils.Plane(o, { x: 1, y: 1 }); diff --git a/crates/swc/tests/tsc-references/TwoInternalModulesWithTheSameNameAndSameCommonRoot_es5.2.minified.js b/crates/swc/tests/tsc-references/TwoInternalModulesWithTheSameNameAndSameCommonRoot_es5.2.minified.js index 52b2e79345d..b768a502ffc 100644 --- a/crates/swc/tests/tsc-references/TwoInternalModulesWithTheSameNameAndSameCommonRoot_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/TwoInternalModulesWithTheSameNameAndSameCommonRoot_es5.2.minified.js @@ -1,10 +1,11 @@ -var A; -((A = A1 || (A1 = {})).Utils || (A.Utils = {})).mirror = function(p) { - return { - x: p.y, - y: p.x +!function(A1) { + (A1.Utils || (A1.Utils = {})).mirror = function(p) { + return { + x: p.y, + y: p.x + }; }; -}, (function(A2) { +}(A || (A = {})), (function(A2) { var Utils, Plane; A2.Origin = { x: 0, @@ -15,9 +16,9 @@ var A; if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); })(this, Plane), this.tl = tl, this.br = br; }, Utils.Plane = Plane; -})(A1 || (A1 = {})); -var A1, o, o, o = A1.Origin, o = A1.Utils.mirror(o); -new A1.Utils.Plane(o, { +})(A || (A = {})); +var A, o, o, o = A.Origin, o = A.Utils.mirror(o); +new A.Utils.Plane(o, { x: 1, y: 1 }); diff --git a/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion_es2015.2.minified.js b/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion_es2015.2.minified.js index bd6e48ec684..6119af70ff9 100644 --- a/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion_es2015.2.minified.js @@ -1,2 +1,4 @@ -var Color, Color; -(Color = Color || (Color = {}))[Color.R = 0] = "R", Color[Color.G = 1] = "G", Color[Color.B = 2] = "B"; +var Color; +!function(Color) { + Color[Color.R = 0] = "R", Color[Color.G = 1] = "G", Color[Color.B = 2] = "B"; +}(Color || (Color = {})); diff --git a/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion_es5.2.minified.js b/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion_es5.2.minified.js index bd6e48ec684..6119af70ff9 100644 --- a/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/TypeGuardWithEnumUnion_es5.2.minified.js @@ -1,2 +1,4 @@ -var Color, Color; -(Color = Color || (Color = {}))[Color.R = 0] = "R", Color[Color.G = 1] = "G", Color[Color.B = 2] = "B"; +var Color; +!function(Color) { + Color[Color.R = 0] = "R", Color[Color.G = 1] = "G", Color[Color.B = 2] = "B"; +}(Color || (Color = {})); diff --git a/crates/swc/tests/tsc-references/additionOperatorWithAnyAndEveryType_es2015.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithAnyAndEveryType_es2015.2.minified.js index bdb677814fa..8e884fefe63 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithAnyAndEveryType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithAnyAndEveryType_es2015.2.minified.js @@ -1,5 +1,7 @@ -var E, E, M; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", (function(M1) { +var E, M; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), (function(M1) { var a; M1.a = a; })(M || (M = {})), new class { diff --git a/crates/swc/tests/tsc-references/additionOperatorWithAnyAndEveryType_es5.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithAnyAndEveryType_es5.2.minified.js index 926261e8ea2..c75f69edbad 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithAnyAndEveryType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithAnyAndEveryType_es5.2.minified.js @@ -1,4 +1,4 @@ -var E, M, E, C = function() { +var E, M, C = function() { "use strict"; var Constructor; function C() { @@ -18,7 +18,9 @@ var E, M, E, C = function() { } ]), C; }(); -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", (function(M1) { +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), (function(M1) { var a; M1.a = a; })(M || (M = {})), new C(), E.a; diff --git a/crates/swc/tests/tsc-references/additionOperatorWithInvalidOperands_es2015.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithInvalidOperands_es2015.2.minified.js index 29c1fdee019..caf67d9665a 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithInvalidOperands_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithInvalidOperands_es2015.2.minified.js @@ -1,8 +1,10 @@ -var E, E, M; +var E, M; class C { static foo() {} } -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", (function(M1) { +(function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +})(E || (E = {})), (function(M1) { var a; M1.a = a; })(M || (M = {})), {} + {}, E.a + new C(), E.a + C.foo(), E.a; diff --git a/crates/swc/tests/tsc-references/additionOperatorWithInvalidOperands_es5.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithInvalidOperands_es5.2.minified.js index 0a260d4411c..1832d0fd940 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithInvalidOperands_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithInvalidOperands_es5.2.minified.js @@ -1,4 +1,4 @@ -var E, M, E, C = function() { +var E, M, C = function() { "use strict"; var Constructor; function C() { @@ -18,7 +18,9 @@ var E, M, E, C = function() { } ]), C; }(); -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", (function(M1) { +(function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +})(E || (E = {})), (function(M1) { var a; M1.a = a; })(M || (M = {})), {} + {}, E.a + new C(), E.a + C.foo(), E.a; diff --git a/crates/swc/tests/tsc-references/additionOperatorWithNullValueAndValidOperator_es2015.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithNullValueAndValidOperator_es2015.2.minified.js index 7d8ab9c5bab..4764bf37a52 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithNullValueAndValidOperator_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithNullValueAndValidOperator_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", E.a, E.a, E.a, E.a; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), E.a, E.a, E.a, E.a; diff --git a/crates/swc/tests/tsc-references/additionOperatorWithNullValueAndValidOperator_es5.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithNullValueAndValidOperator_es5.2.minified.js index 7d8ab9c5bab..4764bf37a52 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithNullValueAndValidOperator_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithNullValueAndValidOperator_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", E.a, E.a, E.a, E.a; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), E.a, E.a, E.a, E.a; diff --git a/crates/swc/tests/tsc-references/additionOperatorWithNumberAndEnum_es2015.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithNumberAndEnum_es2015.2.minified.js index 6bac6255215..a4bace933bf 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithNumberAndEnum_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithNumberAndEnum_es2015.2.minified.js @@ -1,2 +1,6 @@ -var E, F, E, F; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (F = F || (F = {}))[F.c = 0] = "c", F[F.d = 1] = "d", E.a, E.a + E.b, E.a + E.b, E.a + F.c; +var E, F; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), (function(F) { + F[F.c = 0] = "c", F[F.d = 1] = "d"; +})(F || (F = {})), E.a, E.a + E.b, E.a + E.b, E.a + F.c; diff --git a/crates/swc/tests/tsc-references/additionOperatorWithNumberAndEnum_es5.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithNumberAndEnum_es5.2.minified.js index 6bac6255215..a4bace933bf 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithNumberAndEnum_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithNumberAndEnum_es5.2.minified.js @@ -1,2 +1,6 @@ -var E, F, E, F; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (F = F || (F = {}))[F.c = 0] = "c", F[F.d = 1] = "d", E.a, E.a + E.b, E.a + E.b, E.a + F.c; +var E, F; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), (function(F) { + F[F.c = 0] = "c", F[F.d = 1] = "d"; +})(F || (F = {})), E.a, E.a + E.b, E.a + E.b, E.a + F.c; diff --git a/crates/swc/tests/tsc-references/additionOperatorWithStringAndEveryType_es2015.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithStringAndEveryType_es2015.2.minified.js index 1c328f9a8e7..5ccee2f943b 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithStringAndEveryType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithStringAndEveryType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", E.a; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), E.a; diff --git a/crates/swc/tests/tsc-references/additionOperatorWithStringAndEveryType_es5.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithStringAndEveryType_es5.2.minified.js index 1c328f9a8e7..5ccee2f943b 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithStringAndEveryType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithStringAndEveryType_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", E.a; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), E.a; diff --git a/crates/swc/tests/tsc-references/additionOperatorWithTypeParameter_es2015.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithTypeParameter_es2015.2.minified.js index bd64e1c79db..a327b14d75c 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithTypeParameter_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithTypeParameter_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/additionOperatorWithTypeParameter_es5.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithTypeParameter_es5.2.minified.js index bd64e1c79db..a327b14d75c 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithTypeParameter_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithTypeParameter_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/additionOperatorWithUndefinedValueAndValidOperator_es2015.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithUndefinedValueAndValidOperator_es2015.2.minified.js index 7d8ab9c5bab..4764bf37a52 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithUndefinedValueAndValidOperator_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithUndefinedValueAndValidOperator_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", E.a, E.a, E.a, E.a; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), E.a, E.a, E.a, E.a; diff --git a/crates/swc/tests/tsc-references/additionOperatorWithUndefinedValueAndValidOperator_es5.2.minified.js b/crates/swc/tests/tsc-references/additionOperatorWithUndefinedValueAndValidOperator_es5.2.minified.js index 7d8ab9c5bab..4764bf37a52 100644 --- a/crates/swc/tests/tsc-references/additionOperatorWithUndefinedValueAndValidOperator_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/additionOperatorWithUndefinedValueAndValidOperator_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", E.a, E.a, E.a, E.a; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), E.a, E.a, E.a, E.a; diff --git a/crates/swc/tests/tsc-references/amdImportAsPrimaryExpression_es2015.2.minified.js b/crates/swc/tests/tsc-references/amdImportAsPrimaryExpression_es2015.2.minified.js index a20500b95d8..c9e71b3d99a 100644 --- a/crates/swc/tests/tsc-references/amdImportAsPrimaryExpression_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/amdImportAsPrimaryExpression_es2015.2.minified.js @@ -1,4 +1,6 @@ -var E1, E1; -(E1 = E1 || (E1 = {}))[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C"; +export var E1; +!function(E1) { + E1[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C"; +}(E1 || (E1 = {})); const foo = require("./foo_0"); foo.E1.A; diff --git a/crates/swc/tests/tsc-references/amdImportAsPrimaryExpression_es5.2.minified.js b/crates/swc/tests/tsc-references/amdImportAsPrimaryExpression_es5.2.minified.js index eaa1d1c23ee..6d0551921d9 100644 --- a/crates/swc/tests/tsc-references/amdImportAsPrimaryExpression_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/amdImportAsPrimaryExpression_es5.2.minified.js @@ -1,2 +1,4 @@ -var E1, E1; -(E1 = E1 || (E1 = {}))[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C", require("./foo_0").E1.A; +var E1; +!function(E1) { + E1[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C"; +}(E1 || (E1 = {})), require("./foo_0").E1.A; diff --git a/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression_es2015.2.minified.js b/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression_es2015.2.minified.js index d62f0a2dfc9..90544c6a856 100644 --- a/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression_es2015.2.minified.js @@ -1,7 +1,9 @@ -var E1, E1; +var E1; export class C1 { constructor(){ this.m1 = 42; } } -C1.s1 = !0, (E1 = E1 || (E1 = {}))[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C", require("./foo_0"); +C1.s1 = !0, (function(E1) { + E1[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C"; +})(E1 || (E1 = {})), require("./foo_0"); diff --git a/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression_es5.2.minified.js b/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression_es5.2.minified.js index 93e10575f68..ac365f3f62c 100644 --- a/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/amdImportNotAsPrimaryExpression_es5.2.minified.js @@ -1,7 +1,9 @@ -export var E1, E1, i, z, C1 = function() { +export var E1, i, z, C1 = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C1), this.m1 = 42; }; -C1.s1 = !0, E1 = E1 || (E1 = {}), E1[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C", require("./foo_0"); +C1.s1 = !0, (function(E1) { + E1[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C"; +})(E1 || (E1 = {})), require("./foo_0"); diff --git a/crates/swc/tests/tsc-references/anyAssignabilityInInheritance_es2015.2.minified.js b/crates/swc/tests/tsc-references/anyAssignabilityInInheritance_es2015.2.minified.js index f3aaac44eb1..d9eddc2fd6a 100644 --- a/crates/swc/tests/tsc-references/anyAssignabilityInInheritance_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/anyAssignabilityInInheritance_es2015.2.minified.js @@ -1,6 +1,8 @@ -var a, E, E; +var a, E; function f() {} -foo2(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), (E = E || (E = {}))[E.A = 0] = "A", foo3(a), (f || (f = {})).bar = 1, foo3(a); +foo2(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), foo3(a), (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), foo3(a), (f || (f = {})).bar = 1, foo3(a); class CC { } (CC || (CC = {})).bar = 1, foo3(a), foo3(a), foo3(a); diff --git a/crates/swc/tests/tsc-references/anyAssignabilityInInheritance_es5.2.minified.js b/crates/swc/tests/tsc-references/anyAssignabilityInInheritance_es5.2.minified.js index 2dd627e6557..6ddc2530adc 100644 --- a/crates/swc/tests/tsc-references/anyAssignabilityInInheritance_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/anyAssignabilityInInheritance_es5.2.minified.js @@ -12,8 +12,10 @@ var A2 = function() { _classCallCheck(this, A2); }; function f() {} -foo3(a), foo3(a), foo3(a), (E = E || (E = {}))[E.A = 0] = "A", foo3(a), (f || (f = {})).bar = 1, foo3(a); -var a, E, E, CC = function() { +foo3(a), foo3(a), foo3(a), (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), foo3(a), (f || (f = {})).bar = 1, foo3(a); +var a, E, CC = function() { "use strict"; _classCallCheck(this, CC); }; diff --git a/crates/swc/tests/tsc-references/anyAssignableToEveryType2_es2015.2.minified.js b/crates/swc/tests/tsc-references/anyAssignableToEveryType2_es2015.2.minified.js index 3f3700c80c3..65f9a16b279 100644 --- a/crates/swc/tests/tsc-references/anyAssignableToEveryType2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/anyAssignableToEveryType2_es2015.2.minified.js @@ -1,6 +1,8 @@ -var E, E; +var E; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (f || (f = {})).bar = 1; class c { } (c || (c = {})).bar = 1; diff --git a/crates/swc/tests/tsc-references/anyAssignableToEveryType2_es5.2.minified.js b/crates/swc/tests/tsc-references/anyAssignableToEveryType2_es5.2.minified.js index 13efea2d586..dae6c34036d 100644 --- a/crates/swc/tests/tsc-references/anyAssignableToEveryType2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/anyAssignableToEveryType2_es5.2.minified.js @@ -1,7 +1,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -var E, E, A = function() { +var E, A = function() { "use strict"; _classCallCheck(this, A); }, A2 = function() { @@ -9,7 +9,9 @@ var E, E, A = function() { _classCallCheck(this, A2); }; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (f || (f = {})).bar = 1; var c = function() { "use strict"; _classCallCheck(this, c); diff --git a/crates/swc/tests/tsc-references/anyAssignableToEveryType_es2015.2.minified.js b/crates/swc/tests/tsc-references/anyAssignableToEveryType_es2015.2.minified.js index 5f410993c04..4f81f678e53 100644 --- a/crates/swc/tests/tsc-references/anyAssignableToEveryType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/anyAssignableToEveryType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A"; +var E; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/anyAssignableToEveryType_es5.2.minified.js b/crates/swc/tests/tsc-references/anyAssignableToEveryType_es5.2.minified.js index f70e6cc54e8..9eba7da8a34 100644 --- a/crates/swc/tests/tsc-references/anyAssignableToEveryType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/anyAssignableToEveryType_es5.2.minified.js @@ -1,7 +1,9 @@ -var E, E, C = function() { +var E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -(E = E || (E = {}))[E.A = 0] = "A"; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/argumentExpressionContextualTyping_es5.2.minified.js b/crates/swc/tests/tsc-references/argumentExpressionContextualTyping_es5.2.minified.js index b7d59983502..1e1610929a3 100644 --- a/crates/swc/tests/tsc-references/argumentExpressionContextualTyping_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/argumentExpressionContextualTyping_es5.2.minified.js @@ -58,7 +58,7 @@ foo({ e: 3 } }); -var arr, array = [ +var array = [ "string", 1, !0 @@ -76,12 +76,14 @@ baz([ 1, !0 ].concat(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = array) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}())), foo({ + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(array))), foo({ x: [ "string", 1 diff --git a/crates/swc/tests/tsc-references/arithmeticOperatorWithEnumUnion_es2015.2.minified.js b/crates/swc/tests/tsc-references/arithmeticOperatorWithEnumUnion_es2015.2.minified.js index 53c1830cbd6..910245f466b 100644 --- a/crates/swc/tests/tsc-references/arithmeticOperatorWithEnumUnion_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/arithmeticOperatorWithEnumUnion_es2015.2.minified.js @@ -1,2 +1,6 @@ -var E, F, E, F; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (F = F || (F = {}))[F.c = 0] = "c", F[F.d = 1] = "d", E.a, E.a, E.a * E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a / E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a % E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a - E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a << E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >>> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a & E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a ^ E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a | E.b, E.a, E.b, E.b, E.b; +var E, F; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), (function(F) { + F[F.c = 0] = "c", F[F.d = 1] = "d"; +})(F || (F = {})), E.a, E.a, E.a * E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a / E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a % E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a - E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a << E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >>> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a & E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a ^ E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a | E.b, E.a, E.b, E.b, E.b; diff --git a/crates/swc/tests/tsc-references/arithmeticOperatorWithEnumUnion_es5.2.minified.js b/crates/swc/tests/tsc-references/arithmeticOperatorWithEnumUnion_es5.2.minified.js index 53c1830cbd6..910245f466b 100644 --- a/crates/swc/tests/tsc-references/arithmeticOperatorWithEnumUnion_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/arithmeticOperatorWithEnumUnion_es5.2.minified.js @@ -1,2 +1,6 @@ -var E, F, E, F; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (F = F || (F = {}))[F.c = 0] = "c", F[F.d = 1] = "d", E.a, E.a, E.a * E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a / E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a % E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a - E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a << E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >>> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a & E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a ^ E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a | E.b, E.a, E.b, E.b, E.b; +var E, F; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), (function(F) { + F[F.c = 0] = "c", F[F.d = 1] = "d"; +})(F || (F = {})), E.a, E.a, E.a * E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a / E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a % E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a - E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a << E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >>> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a & E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a ^ E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a | E.b, E.a, E.b, E.b, E.b; diff --git a/crates/swc/tests/tsc-references/arithmeticOperatorWithEnum_es2015.2.minified.js b/crates/swc/tests/tsc-references/arithmeticOperatorWithEnum_es2015.2.minified.js index 21a524fa931..217a4457595 100644 --- a/crates/swc/tests/tsc-references/arithmeticOperatorWithEnum_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/arithmeticOperatorWithEnum_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E.a, E.a, E.a * E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a / E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a % E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a - E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a << E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >>> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a & E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a ^ E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a | E.b, E.a, E.b, E.b, E.b; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), E.a, E.a, E.a * E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a / E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a % E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a - E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a << E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >>> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a & E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a ^ E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a | E.b, E.a, E.b, E.b, E.b; diff --git a/crates/swc/tests/tsc-references/arithmeticOperatorWithEnum_es5.2.minified.js b/crates/swc/tests/tsc-references/arithmeticOperatorWithEnum_es5.2.minified.js index 21a524fa931..217a4457595 100644 --- a/crates/swc/tests/tsc-references/arithmeticOperatorWithEnum_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/arithmeticOperatorWithEnum_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E.a, E.a, E.a * E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a / E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a % E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a - E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a << E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >>> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a & E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a ^ E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a | E.b, E.a, E.b, E.b, E.b; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), E.a, E.a, E.a * E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a / E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a % E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a - E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a << E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a >>> E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a & E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a ^ E.b, E.a, E.b, E.b, E.b, E.a, E.a, E.a | E.b, E.a, E.b, E.b, E.b; diff --git a/crates/swc/tests/tsc-references/arithmeticOperatorWithInvalidOperands_es2015.2.minified.js b/crates/swc/tests/tsc-references/arithmeticOperatorWithInvalidOperands_es2015.2.minified.js index e82d577c1a2..b0a6dcc9124 100644 --- a/crates/swc/tests/tsc-references/arithmeticOperatorWithInvalidOperands_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/arithmeticOperatorWithInvalidOperands_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b; diff --git a/crates/swc/tests/tsc-references/arithmeticOperatorWithInvalidOperands_es5.2.minified.js b/crates/swc/tests/tsc-references/arithmeticOperatorWithInvalidOperands_es5.2.minified.js index e82d577c1a2..b0a6dcc9124 100644 --- a/crates/swc/tests/tsc-references/arithmeticOperatorWithInvalidOperands_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/arithmeticOperatorWithInvalidOperands_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b, E.a, E.a, E.a, E.a, E.a, E.a, E.b, E.b, E.b, E.b, E.b, E.b; diff --git a/crates/swc/tests/tsc-references/arithmeticOperatorWithNullValueAndValidOperands_es2015.2.minified.js b/crates/swc/tests/tsc-references/arithmeticOperatorWithNullValueAndValidOperands_es2015.2.minified.js index 7ded5617b2f..0d5590b1584 100644 --- a/crates/swc/tests/tsc-references/arithmeticOperatorWithNullValueAndValidOperands_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/arithmeticOperatorWithNullValueAndValidOperands_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b; diff --git a/crates/swc/tests/tsc-references/arithmeticOperatorWithNullValueAndValidOperands_es5.2.minified.js b/crates/swc/tests/tsc-references/arithmeticOperatorWithNullValueAndValidOperands_es5.2.minified.js index 7ded5617b2f..0d5590b1584 100644 --- a/crates/swc/tests/tsc-references/arithmeticOperatorWithNullValueAndValidOperands_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/arithmeticOperatorWithNullValueAndValidOperands_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b; diff --git a/crates/swc/tests/tsc-references/arithmeticOperatorWithUndefinedValueAndValidOperands_es2015.2.minified.js b/crates/swc/tests/tsc-references/arithmeticOperatorWithUndefinedValueAndValidOperands_es2015.2.minified.js index 7ded5617b2f..0d5590b1584 100644 --- a/crates/swc/tests/tsc-references/arithmeticOperatorWithUndefinedValueAndValidOperands_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/arithmeticOperatorWithUndefinedValueAndValidOperands_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b; diff --git a/crates/swc/tests/tsc-references/arithmeticOperatorWithUndefinedValueAndValidOperands_es5.2.minified.js b/crates/swc/tests/tsc-references/arithmeticOperatorWithUndefinedValueAndValidOperands_es5.2.minified.js index 7ded5617b2f..0d5590b1584 100644 --- a/crates/swc/tests/tsc-references/arithmeticOperatorWithUndefinedValueAndValidOperands_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/arithmeticOperatorWithUndefinedValueAndValidOperands_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b, E.a, E.b; diff --git a/crates/swc/tests/tsc-references/arrayAssignmentPatternWithAny_es5.2.minified.js b/crates/swc/tests/tsc-references/arrayAssignmentPatternWithAny_es5.2.minified.js index 53f09dd0e0e..029a400ef70 100644 --- a/crates/swc/tests/tsc-references/arrayAssignmentPatternWithAny_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/arrayAssignmentPatternWithAny_es5.2.minified.js @@ -1,35 +1,37 @@ -var a, arr, i; +var a; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } -(i = 1, (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = a) || (function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ +(function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; try { - _n || null == _i.return || _i.return(); + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; } finally{ - if (_d) throw _e; + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } } + return _arr; } - return _arr; - } -})(arr, i) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})())[0]; + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})(a, 1)[0]; diff --git a/crates/swc/tests/tsc-references/arrayLiteralInference_es2015.2.minified.js b/crates/swc/tests/tsc-references/arrayLiteralInference_es2015.2.minified.js index 38af0824012..9409f79a13d 100644 --- a/crates/swc/tests/tsc-references/arrayLiteralInference_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/arrayLiteralInference_es2015.2.minified.js @@ -1,5 +1,9 @@ -var AppType, AppStyle, AppType, AppStyle; -(AppType = AppType || (AppType = {})).HeaderDetail = "HeaderDetail", AppType.HeaderMultiDetail = "HeaderMultiDetail", AppType.AdvancedList = "AdvancedList", AppType.Standard = "Standard", AppType.Relationship = "Relationship", AppType.Report = "Report", AppType.Composite = "Composite", AppType.ListOnly = "ListOnly", AppType.ModuleSettings = "ModuleSettings", (AppStyle = AppStyle || (AppStyle = {}))[AppStyle.Tree = 0] = "Tree", AppStyle[AppStyle.TreeEntity = 1] = "TreeEntity", AppStyle[AppStyle.Standard = 2] = "Standard", AppStyle[AppStyle.MiniApp = 3] = "MiniApp", AppStyle[AppStyle.PivotTable = 4] = "PivotTable", new Map([ +var AppType, AppStyle; +!function(AppType) { + AppType.HeaderDetail = "HeaderDetail", AppType.HeaderMultiDetail = "HeaderMultiDetail", AppType.AdvancedList = "AdvancedList", AppType.Standard = "Standard", AppType.Relationship = "Relationship", AppType.Report = "Report", AppType.Composite = "Composite", AppType.ListOnly = "ListOnly", AppType.ModuleSettings = "ModuleSettings"; +}(AppType || (AppType = {})), (function(AppStyle) { + AppStyle[AppStyle.Tree = 0] = "Tree", AppStyle[AppStyle.TreeEntity = 1] = "TreeEntity", AppStyle[AppStyle.Standard = 2] = "Standard", AppStyle[AppStyle.MiniApp = 3] = "MiniApp", AppStyle[AppStyle.PivotTable = 4] = "PivotTable"; +})(AppStyle || (AppStyle = {})), new Map([ [ AppType.Standard, [ diff --git a/crates/swc/tests/tsc-references/arrayLiteralInference_es5.2.minified.js b/crates/swc/tests/tsc-references/arrayLiteralInference_es5.2.minified.js index 38af0824012..9409f79a13d 100644 --- a/crates/swc/tests/tsc-references/arrayLiteralInference_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/arrayLiteralInference_es5.2.minified.js @@ -1,5 +1,9 @@ -var AppType, AppStyle, AppType, AppStyle; -(AppType = AppType || (AppType = {})).HeaderDetail = "HeaderDetail", AppType.HeaderMultiDetail = "HeaderMultiDetail", AppType.AdvancedList = "AdvancedList", AppType.Standard = "Standard", AppType.Relationship = "Relationship", AppType.Report = "Report", AppType.Composite = "Composite", AppType.ListOnly = "ListOnly", AppType.ModuleSettings = "ModuleSettings", (AppStyle = AppStyle || (AppStyle = {}))[AppStyle.Tree = 0] = "Tree", AppStyle[AppStyle.TreeEntity = 1] = "TreeEntity", AppStyle[AppStyle.Standard = 2] = "Standard", AppStyle[AppStyle.MiniApp = 3] = "MiniApp", AppStyle[AppStyle.PivotTable = 4] = "PivotTable", new Map([ +var AppType, AppStyle; +!function(AppType) { + AppType.HeaderDetail = "HeaderDetail", AppType.HeaderMultiDetail = "HeaderMultiDetail", AppType.AdvancedList = "AdvancedList", AppType.Standard = "Standard", AppType.Relationship = "Relationship", AppType.Report = "Report", AppType.Composite = "Composite", AppType.ListOnly = "ListOnly", AppType.ModuleSettings = "ModuleSettings"; +}(AppType || (AppType = {})), (function(AppStyle) { + AppStyle[AppStyle.Tree = 0] = "Tree", AppStyle[AppStyle.TreeEntity = 1] = "TreeEntity", AppStyle[AppStyle.Standard = 2] = "Standard", AppStyle[AppStyle.MiniApp = 3] = "MiniApp", AppStyle[AppStyle.PivotTable = 4] = "PivotTable"; +})(AppStyle || (AppStyle = {})), new Map([ [ AppType.Standard, [ diff --git a/crates/swc/tests/tsc-references/arrowFunctionExpressions_es5.2.minified.js b/crates/swc/tests/tsc-references/arrowFunctionExpressions_es5.2.minified.js index 4f0a459e0f4..3de98dd68db 100644 --- a/crates/swc/tests/tsc-references/arrowFunctionExpressions_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/arrowFunctionExpressions_es5.2.minified.js @@ -24,6 +24,10 @@ var MyClass = function() { } ], _defineProperties((Constructor = MyClass).prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), MyClass; }(); -(function() { +(m = 3, function() { + return function(n) { + return 3 + n; + }; +})()(4), (function() { return 0; })().toExponential(); diff --git a/crates/swc/tests/tsc-references/asiPreventsParsingAsNamespace05_es2015.2.minified.js b/crates/swc/tests/tsc-references/asiPreventsParsingAsNamespace05_es2015.2.minified.js index 989dffca4cb..24a036bce03 100644 --- a/crates/swc/tests/tsc-references/asiPreventsParsingAsNamespace05_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/asiPreventsParsingAsNamespace05_es2015.2.minified.js @@ -1,2 +1,4 @@ -var a, a1; -((a1 = a || (a = {})).b || (a1.b = {})).c = 20; +var a; +!function(a1) { + (a1.b || (a1.b = {})).c = 20; +}(a || (a = {})); diff --git a/crates/swc/tests/tsc-references/asiPreventsParsingAsNamespace05_es5.2.minified.js b/crates/swc/tests/tsc-references/asiPreventsParsingAsNamespace05_es5.2.minified.js index 989dffca4cb..24a036bce03 100644 --- a/crates/swc/tests/tsc-references/asiPreventsParsingAsNamespace05_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asiPreventsParsingAsNamespace05_es5.2.minified.js @@ -1,2 +1,4 @@ -var a, a1; -((a1 = a || (a = {})).b || (a1.b = {})).c = 20; +var a; +!function(a1) { + (a1.b || (a1.b = {})).c = 20; +}(a || (a = {})); diff --git a/crates/swc/tests/tsc-references/assignAnyToEveryType_es2015.2.minified.js b/crates/swc/tests/tsc-references/assignAnyToEveryType_es2015.2.minified.js index b05de4238e1..f70f4f7d888 100644 --- a/crates/swc/tests/tsc-references/assignAnyToEveryType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/assignAnyToEveryType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var x, E, M, E; -(E = E || (E = {}))[E.A = 0] = "A", E.A, (M || (M = {})).foo = 1, M = x; +var x, E, M; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), E.A, (M || (M = {})).foo = 1, M = x; diff --git a/crates/swc/tests/tsc-references/assignAnyToEveryType_es5.2.minified.js b/crates/swc/tests/tsc-references/assignAnyToEveryType_es5.2.minified.js index b227ca30233..e8b87f9d689 100644 --- a/crates/swc/tests/tsc-references/assignAnyToEveryType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/assignAnyToEveryType_es5.2.minified.js @@ -1,5 +1,7 @@ -var x, E, M, E; -(E = E || (E = {}))[E.A = 0] = "A", E.A; +var x, E, M; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), E.A; var C = function() { "use strict"; !function(instance, Constructor) { diff --git a/crates/swc/tests/tsc-references/assignEveryTypeToAny_es2015.2.minified.js b/crates/swc/tests/tsc-references/assignEveryTypeToAny_es2015.2.minified.js index 5f410993c04..4406cd14fc5 100644 --- a/crates/swc/tests/tsc-references/assignEveryTypeToAny_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/assignEveryTypeToAny_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A"; +var E; +(function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), E.A, E.A; diff --git a/crates/swc/tests/tsc-references/assignEveryTypeToAny_es5.2.minified.js b/crates/swc/tests/tsc-references/assignEveryTypeToAny_es5.2.minified.js index fc1b97acbb4..475a82ef4c0 100644 --- a/crates/swc/tests/tsc-references/assignEveryTypeToAny_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/assignEveryTypeToAny_es5.2.minified.js @@ -1,5 +1,8 @@ -(E = E || (E = {}))[E.A = 0] = "A"; -var E, E, C = function() { +var E; +(function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), E.A, E.A; +var C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); diff --git a/crates/swc/tests/tsc-references/assignmentToParenthesizedIdentifiers_es2015.2.minified.js b/crates/swc/tests/tsc-references/assignmentToParenthesizedIdentifiers_es2015.2.minified.js index c74809dfea7..8136a6b687f 100644 --- a/crates/swc/tests/tsc-references/assignmentToParenthesizedIdentifiers_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/assignmentToParenthesizedIdentifiers_es2015.2.minified.js @@ -1,4 +1,4 @@ -var x, M, M2, E, E; +var x, M, M2, E; function fn() {} x = 3 = "", (function(M1) { var y; @@ -23,7 +23,9 @@ x = 3 = "", (function(M1) { }, M2.M3 = { x: "" }, fn = ()=>3 -, (E = E || (E = {}))[E.A = 0] = "A", E = void 0 = void 0; +, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), E = void 0 = void 0; class C { } C = void 0; diff --git a/crates/swc/tests/tsc-references/assignmentToParenthesizedIdentifiers_es5.2.minified.js b/crates/swc/tests/tsc-references/assignmentToParenthesizedIdentifiers_es5.2.minified.js index bf10f5cec00..8878eb52b81 100644 --- a/crates/swc/tests/tsc-references/assignmentToParenthesizedIdentifiers_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/assignmentToParenthesizedIdentifiers_es5.2.minified.js @@ -23,8 +23,10 @@ x = 3 = "", (function(M1) { x: "" }, fn = function() { return 3; -}, (E = E || (E = {}))[E.A = 0] = "A", E = void 0 = void 0; -var E, x, M, M2, E, C = function() { +}, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), E = void 0 = void 0; +var x, M, M2, E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); diff --git a/crates/swc/tests/tsc-references/assignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/assignments_es2015.2.minified.js index 63fe8377e2d..0a0436fab4a 100644 --- a/crates/swc/tests/tsc-references/assignments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/assignments_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -M = null, (E = E || (E = {}))[E.A = 0] = "A", (E = null).A = null, I = null; +var E; +M = null, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), (E = null).A = null, I = null; diff --git a/crates/swc/tests/tsc-references/assignments_es5.2.minified.js b/crates/swc/tests/tsc-references/assignments_es5.2.minified.js index 4ce9328df8d..3d68e1f35fa 100644 --- a/crates/swc/tests/tsc-references/assignments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/assignments_es5.2.minified.js @@ -1,8 +1,10 @@ M = null; -var E, E, C = function() { +var E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -C = null, (E = E || (E = {}))[E.A = 0] = "A", (E = null).A = null, I = null; +C = null, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), (E = null).A = null, I = null; diff --git a/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es2017_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es2017_es5.2.minified.js index 5e72384e6de..98c99361ff0 100644 --- a/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es2017_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es2017_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -obj = {}, key = _await, value = foo, key in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, _await, foo); diff --git a/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es5_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es5_es5.2.minified.js index 5e72384e6de..98c99361ff0 100644 --- a/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es5_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -obj = {}, key = _await, value = foo, key in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, _await, foo); diff --git a/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es6_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es6_es5.2.minified.js index 5e72384e6de..98c99361ff0 100644 --- a/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncFunctionDeclaration8_es6_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -obj = {}, key = _await, value = foo, key in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, _await, foo); diff --git a/crates/swc/tests/tsc-references/bestCommonTypeOfTuple_es2015.2.minified.js b/crates/swc/tests/tsc-references/bestCommonTypeOfTuple_es2015.2.minified.js index 21f4c6c2fd6..1a255d1ee45 100644 --- a/crates/swc/tests/tsc-references/bestCommonTypeOfTuple_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/bestCommonTypeOfTuple_es2015.2.minified.js @@ -1,5 +1,9 @@ -var E1, E2, E1, E2, t1, t2, t3, t4; -(E1 = E1 || (E1 = {}))[E1.one = 0] = "one", (E2 = E2 || (E2 = {}))[E2.two = 0] = "two", t1 = [ +var E1, E2, t1, t2, t3, t4; +!function(E1) { + E1[E1.one = 0] = "one"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.two = 0] = "two"; +})(E2 || (E2 = {})), t1 = [ function(x) { return "foo"; }, diff --git a/crates/swc/tests/tsc-references/bestCommonTypeOfTuple_es5.2.minified.js b/crates/swc/tests/tsc-references/bestCommonTypeOfTuple_es5.2.minified.js index 21f4c6c2fd6..1a255d1ee45 100644 --- a/crates/swc/tests/tsc-references/bestCommonTypeOfTuple_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/bestCommonTypeOfTuple_es5.2.minified.js @@ -1,5 +1,9 @@ -var E1, E2, E1, E2, t1, t2, t3, t4; -(E1 = E1 || (E1 = {}))[E1.one = 0] = "one", (E2 = E2 || (E2 = {}))[E2.two = 0] = "two", t1 = [ +var E1, E2, t1, t2, t3, t4; +!function(E1) { + E1[E1.one = 0] = "one"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.two = 0] = "two"; +})(E2 || (E2 = {})), t1 = [ function(x) { return "foo"; }, diff --git a/crates/swc/tests/tsc-references/bitwiseNotOperatorWithEnumType_es2015.2.minified.js b/crates/swc/tests/tsc-references/bitwiseNotOperatorWithEnumType_es2015.2.minified.js index 4cd29c4974f..10d4b79d71e 100644 --- a/crates/swc/tests/tsc-references/bitwiseNotOperatorWithEnumType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/bitwiseNotOperatorWithEnumType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ENUM1.A, ENUM1.A + ENUM1.B, ENUM1.A + ENUM1.B, ENUM1.A, ENUM1.A, ENUM1.B; +var ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ENUM1.A, ENUM1.A + ENUM1.B, ENUM1.A + ENUM1.B, ENUM1.A, ENUM1.A, ENUM1.B; diff --git a/crates/swc/tests/tsc-references/bitwiseNotOperatorWithEnumType_es5.2.minified.js b/crates/swc/tests/tsc-references/bitwiseNotOperatorWithEnumType_es5.2.minified.js index 4cd29c4974f..10d4b79d71e 100644 --- a/crates/swc/tests/tsc-references/bitwiseNotOperatorWithEnumType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/bitwiseNotOperatorWithEnumType_es5.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ENUM1.A, ENUM1.A + ENUM1.B, ENUM1.A + ENUM1.B, ENUM1.A, ENUM1.A, ENUM1.B; +var ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ENUM1.A, ENUM1.A + ENUM1.B, ENUM1.A + ENUM1.B, ENUM1.A, ENUM1.A, ENUM1.B; diff --git a/crates/swc/tests/tsc-references/callSignatureWithoutReturnTypeAnnotationInference_es2015.2.minified.js b/crates/swc/tests/tsc-references/callSignatureWithoutReturnTypeAnnotationInference_es2015.2.minified.js index 3e6c7d64634..7fa7d217722 100644 --- a/crates/swc/tests/tsc-references/callSignatureWithoutReturnTypeAnnotationInference_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/callSignatureWithoutReturnTypeAnnotationInference_es2015.2.minified.js @@ -1,4 +1,4 @@ -var M, e1, M1, e1; +var M, e1; function foo3() { return foo3(); } @@ -9,9 +9,13 @@ foo3(), (function(x) { try {} catch (e) { return []; } finally{} -})(1), (M1 = M || (M = {})).x = 1, M1.C = class { -}, (m1 || (m1 = {})).y = 2; +})(1), (function(M1) { + M1.x = 1, M1.C = class { + }; +})(M || (M = {})), (m1 || (m1 = {})).y = 2; class c1 { constructor(x){} } -(c1 || (c1 = {})).x = 1, (e1 = e1 || (e1 = {}))[e1.A = 0] = "A", (e1 || (e1 = {})).y = 1; +(c1 || (c1 = {})).x = 1, (function(e1) { + e1[e1.A = 0] = "A"; +})(e1 || (e1 = {})), (e1 || (e1 = {})).y = 1; diff --git a/crates/swc/tests/tsc-references/callSignatureWithoutReturnTypeAnnotationInference_es5.2.minified.js b/crates/swc/tests/tsc-references/callSignatureWithoutReturnTypeAnnotationInference_es5.2.minified.js index 916a2b2317d..4a38d20dbfa 100644 --- a/crates/swc/tests/tsc-references/callSignatureWithoutReturnTypeAnnotationInference_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/callSignatureWithoutReturnTypeAnnotationInference_es5.2.minified.js @@ -12,7 +12,7 @@ foo3(), (function(x) { var obj; void 0 === x || (obj = x) && "undefined" != typeof Symbol && obj.constructor === Symbol; })(1); -var e1, C = function() { +var C = function() { "use strict"; _classCallCheck(this, C); }; @@ -31,4 +31,6 @@ var M, e1, c1 = function(x) { "use strict"; _classCallCheck(this, c1); }; -(c1 || (c1 = {})).x = 1, (e1 = e1 || (e1 = {}))[e1.A = 0] = "A", (e1 || (e1 = {})).y = 1; +(c1 || (c1 = {})).x = 1, (function(e1) { + e1[e1.A = 0] = "A"; +})(e1 || (e1 = {})), (e1 || (e1 = {})).y = 1; diff --git a/crates/swc/tests/tsc-references/castingTuple_es2015.2.minified.js b/crates/swc/tests/tsc-references/castingTuple_es2015.2.minified.js index 7143673bfa9..5c2a0a3af47 100644 --- a/crates/swc/tests/tsc-references/castingTuple_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/castingTuple_es2015.2.minified.js @@ -2,9 +2,13 @@ class C { } class D { } -(E1 = E1 || (E1 = {}))[E1.one = 0] = "one", (E2 = E2 || (E2 = {}))[E2.one = 0] = "one"; -var E1, E2, E1, E2, classCDATuple = [ +!function(E1) { + E1[E1.one = 0] = "one"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.one = 0] = "one"; +})(E2 || (E2 = {})); +var E1, E2, classCDATuple = [ new C(), new D() ]; -classCDATuple[2], classCDATuple[5], new C(), new C(), new D(), t4[2] = 10; +classCDATuple[2], classCDATuple[5], E1.one, E2.one, new C(), new C(), new D(), t4[2] = 10; diff --git a/crates/swc/tests/tsc-references/castingTuple_es5.2.minified.js b/crates/swc/tests/tsc-references/castingTuple_es5.2.minified.js index 1a3a90cf1fe..dbbbe44a02d 100644 --- a/crates/swc/tests/tsc-references/castingTuple_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/castingTuple_es5.2.minified.js @@ -44,7 +44,7 @@ function _createSuper(Derived) { })(self); }; } -var E1, E2, E1, A = function() { +var A = function() { "use strict"; _classCallCheck(this, A), this.a = 10; }, C = function() { @@ -70,8 +70,12 @@ var E1, E2, E1, A = function() { } return F; }(A); -(E1 = E1 || (E1 = {}))[E1.one = 0] = "one", (E2 = E2 || (E2 = {}))[E2.one = 0] = "one"; -var E2, classCDATuple = [ +!function(E1) { + E1[E1.one = 0] = "one"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.one = 0] = "one"; +})(E2 || (E2 = {})); +var E1, E2, classCDATuple = [ new C(), new D() ]; diff --git a/crates/swc/tests/tsc-references/circularImportAlias_es2015.2.minified.js b/crates/swc/tests/tsc-references/circularImportAlias_es2015.2.minified.js index bed08409189..0f86aa12e36 100644 --- a/crates/swc/tests/tsc-references/circularImportAlias_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/circularImportAlias_es2015.2.minified.js @@ -1,9 +1,11 @@ -var B, A, A1; +var B, A; !function(B1) { var a = A; B1.a = a; class D extends a.C { } B1.D = D; -}(B || (B = {})), (A1 = A || (A = {})).C = class { -}, A1.b = B, new B.a.C(); +}(B || (B = {})), (function(A1) { + A1.C = class { + }, A1.b = B; +})(A || (A = {})), new B.a.C(); diff --git a/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression_es2015.2.minified.js b/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression_es2015.2.minified.js index d62f0a2dfc9..90544c6a856 100644 --- a/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression_es2015.2.minified.js @@ -1,7 +1,9 @@ -var E1, E1; +var E1; export class C1 { constructor(){ this.m1 = 42; } } -C1.s1 = !0, (E1 = E1 || (E1 = {}))[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C", require("./foo_0"); +C1.s1 = !0, (function(E1) { + E1[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C"; +})(E1 || (E1 = {})), require("./foo_0"); diff --git a/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression_es5.2.minified.js b/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression_es5.2.minified.js index 93e10575f68..ac365f3f62c 100644 --- a/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/commonJSImportNotAsPrimaryExpression_es5.2.minified.js @@ -1,7 +1,9 @@ -export var E1, E1, i, z, C1 = function() { +export var E1, i, z, C1 = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C1), this.m1 = 42; }; -C1.s1 = !0, E1 = E1 || (E1 = {}), E1[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C", require("./foo_0"); +C1.s1 = !0, (function(E1) { + E1[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C"; +})(E1 || (E1 = {})), require("./foo_0"); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithIdenticalPrimitiveType_es2015.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithIdenticalPrimitiveType_es2015.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithIdenticalPrimitiveType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithIdenticalPrimitiveType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithIdenticalPrimitiveType_es5.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithIdenticalPrimitiveType_es5.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithIdenticalPrimitiveType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithIdenticalPrimitiveType_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipPrimitiveType_es2015.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipPrimitiveType_es2015.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipPrimitiveType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipPrimitiveType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipPrimitiveType_es5.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipPrimitiveType_es5.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipPrimitiveType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipPrimitiveType_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipTypeParameter_es2015.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipTypeParameter_es2015.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipTypeParameter_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipTypeParameter_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipTypeParameter_es5.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipTypeParameter_es5.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipTypeParameter_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithNoRelationshipTypeParameter_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsAny_es2015.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsAny_es2015.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsAny_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsAny_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsAny_es5.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsAny_es5.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsAny_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsAny_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsNull_es2015.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsNull_es2015.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsNull_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsNull_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsNull_es5.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsNull_es5.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsNull_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsNull_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsUndefined_es2015.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsUndefined_es2015.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsUndefined_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsUndefined_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsUndefined_es5.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsUndefined_es5.2.minified.js index ceca977f367..1723b644952 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsUndefined_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithOneOperandIsUndefined_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithSubtypeEnumAndNumber_es2015.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithSubtypeEnumAndNumber_es2015.2.minified.js index f2779da0b77..6703caa66da 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithSubtypeEnumAndNumber_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithSubtypeEnumAndNumber_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a; diff --git a/crates/swc/tests/tsc-references/comparisonOperatorWithSubtypeEnumAndNumber_es5.2.minified.js b/crates/swc/tests/tsc-references/comparisonOperatorWithSubtypeEnumAndNumber_es5.2.minified.js index f2779da0b77..6703caa66da 100644 --- a/crates/swc/tests/tsc-references/comparisonOperatorWithSubtypeEnumAndNumber_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/comparisonOperatorWithSubtypeEnumAndNumber_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a; +var E; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a, E.a; diff --git a/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCanBeAssigned_es2015.2.minified.js b/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCanBeAssigned_es2015.2.minified.js index 540b495ad26..a7adae21e37 100644 --- a/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCanBeAssigned_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCanBeAssigned_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, a, b, x1, x2, x3, x4, x5, x6, x7, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", x1 += a, x1 += b, x1 += !0, x1 += 0, x1 += "", x1 += E.a, x1 += {}, x1 += null, x1 += void 0, x2 += a, x2 += b, x2 += !0, x2 += 0, x2 += "", x2 += E.a, x2 += {}, x2 += null, x2 += void 0, x3 += a, x3 += 0, x3 += E.a, x3 += null, x3 += void 0, x4 += a, x4 += 0, x4 += E.a, x4 += null, x4 += void 0, x5 += a, x6 += a, x6 += "", x7 += a; +var E, a, b, x1, x2, x3, x4, x5, x6, x7; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), x1 += a, x1 += b, x1 += !0, x1 += 0, x1 += "", x1 += E.a, x1 += {}, x1 += null, x1 += void 0, x2 += a, x2 += b, x2 += !0, x2 += 0, x2 += "", x2 += E.a, x2 += {}, x2 += null, x2 += void 0, x3 += a, x3 += 0, x3 += E.a, x3 += null, x3 += void 0, x4 += a, x4 += 0, x4 += E.a, x4 += null, x4 += void 0, x5 += a, x6 += a, x6 += "", x7 += a; diff --git a/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCanBeAssigned_es5.2.minified.js b/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCanBeAssigned_es5.2.minified.js index 540b495ad26..a7adae21e37 100644 --- a/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCanBeAssigned_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCanBeAssigned_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, a, b, x1, x2, x3, x4, x5, x6, x7, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", x1 += a, x1 += b, x1 += !0, x1 += 0, x1 += "", x1 += E.a, x1 += {}, x1 += null, x1 += void 0, x2 += a, x2 += b, x2 += !0, x2 += 0, x2 += "", x2 += E.a, x2 += {}, x2 += null, x2 += void 0, x3 += a, x3 += 0, x3 += E.a, x3 += null, x3 += void 0, x4 += a, x4 += 0, x4 += E.a, x4 += null, x4 += void 0, x5 += a, x6 += a, x6 += "", x7 += a; +var E, a, b, x1, x2, x3, x4, x5, x6, x7; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), x1 += a, x1 += b, x1 += !0, x1 += 0, x1 += "", x1 += E.a, x1 += {}, x1 += null, x1 += void 0, x2 += a, x2 += b, x2 += !0, x2 += 0, x2 += "", x2 += E.a, x2 += {}, x2 += null, x2 += void 0, x3 += a, x3 += 0, x3 += E.a, x3 += null, x3 += void 0, x4 += a, x4 += 0, x4 += E.a, x4 += null, x4 += void 0, x5 += a, x6 += a, x6 += "", x7 += a; diff --git a/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCannotBeAssigned_es2015.2.minified.js b/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCannotBeAssigned_es2015.2.minified.js index 8bf1a3df061..25557a26612 100644 --- a/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCannotBeAssigned_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCannotBeAssigned_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, x1, x2, x3, x4, x5, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", x1 += "", x2 += "", x3 += "", x4 += "", x5 += ""; +var E, x1, x2, x3, x4, x5; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), x1 += "", x2 += "", x3 += "", x4 += "", x5 += ""; diff --git a/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCannotBeAssigned_es5.2.minified.js b/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCannotBeAssigned_es5.2.minified.js index 8bf1a3df061..25557a26612 100644 --- a/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCannotBeAssigned_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCannotBeAssigned_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, x1, x2, x3, x4, x5, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", x1 += "", x2 += "", x3 += "", x4 += "", x5 += ""; +var E, x1, x2, x3, x4, x5; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), x1 += "", x2 += "", x3 += "", x4 += "", x5 += ""; diff --git a/crates/swc/tests/tsc-references/compoundAdditionAssignmentWithInvalidOperands_es2015.2.minified.js b/crates/swc/tests/tsc-references/compoundAdditionAssignmentWithInvalidOperands_es2015.2.minified.js index b51db22d96c..443643e0bc7 100644 --- a/crates/swc/tests/tsc-references/compoundAdditionAssignmentWithInvalidOperands_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundAdditionAssignmentWithInvalidOperands_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, a, x1, x2, x3, x4, x5, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", x1 += a, x1 += !0, x1 += 0, x1 += E.a, x1 += {}, x1 += null, x1 += void 0, x2 += a, x2 += !0, x2 += 0, x2 += E.a, x2 += {}, x2 += null, x2 += void 0, x3 += a, x3 += !0, x3 += 0, x3 += E.a, x3 += {}, x3 += null, x3 += void 0, x4 += a, x4 += !0, x4 += {}, x5 += a, x5 += !0, x5 += {}; +var E, a, x1, x2, x3, x4, x5; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), x1 += a, x1 += !0, x1 += 0, x1 += E.a, x1 += {}, x1 += null, x1 += void 0, x2 += a, x2 += !0, x2 += 0, x2 += E.a, x2 += {}, x2 += null, x2 += void 0, x3 += a, x3 += !0, x3 += 0, x3 += E.a, x3 += {}, x3 += null, x3 += void 0, x4 += a, x4 += !0, x4 += {}, x5 += a, x5 += !0, x5 += {}; diff --git a/crates/swc/tests/tsc-references/compoundAdditionAssignmentWithInvalidOperands_es5.2.minified.js b/crates/swc/tests/tsc-references/compoundAdditionAssignmentWithInvalidOperands_es5.2.minified.js index b51db22d96c..443643e0bc7 100644 --- a/crates/swc/tests/tsc-references/compoundAdditionAssignmentWithInvalidOperands_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundAdditionAssignmentWithInvalidOperands_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, a, x1, x2, x3, x4, x5, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", x1 += a, x1 += !0, x1 += 0, x1 += E.a, x1 += {}, x1 += null, x1 += void 0, x2 += a, x2 += !0, x2 += 0, x2 += E.a, x2 += {}, x2 += null, x2 += void 0, x3 += a, x3 += !0, x3 += 0, x3 += E.a, x3 += {}, x3 += null, x3 += void 0, x4 += a, x4 += !0, x4 += {}, x5 += a, x5 += !0, x5 += {}; +var E, a, x1, x2, x3, x4, x5; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), x1 += a, x1 += !0, x1 += 0, x1 += E.a, x1 += {}, x1 += null, x1 += void 0, x2 += a, x2 += !0, x2 += 0, x2 += E.a, x2 += {}, x2 += null, x2 += void 0, x3 += a, x3 += !0, x3 += 0, x3 += E.a, x3 += {}, x3 += null, x3 += void 0, x4 += a, x4 += !0, x4 += {}, x5 += a, x5 += !0, x5 += {}; diff --git a/crates/swc/tests/tsc-references/compoundArithmeticAssignmentLHSCanBeAssigned_es2015.2.minified.js b/crates/swc/tests/tsc-references/compoundArithmeticAssignmentLHSCanBeAssigned_es2015.2.minified.js index 6e708914033..dd5176954bc 100644 --- a/crates/swc/tests/tsc-references/compoundArithmeticAssignmentLHSCanBeAssigned_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundArithmeticAssignmentLHSCanBeAssigned_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, a, b, c, x1, x2, x3, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", x1 *= a, x1 *= b, x1 *= c, x1 *= null, x1 *= void 0, x2 *= a, x2 *= b, x2 *= c, x2 *= null, x2 *= void 0, x3 *= a, x3 *= b, x3 *= c, x3 *= null, x3 *= void 0; +var E, a, b, c, x1, x2, x3; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), x1 *= a, x1 *= b, x1 *= c, x1 *= null, x1 *= void 0, x2 *= a, x2 *= b, x2 *= c, x2 *= null, x2 *= void 0, x3 *= a, x3 *= b, x3 *= c, x3 *= null, x3 *= void 0; diff --git a/crates/swc/tests/tsc-references/compoundArithmeticAssignmentLHSCanBeAssigned_es5.2.minified.js b/crates/swc/tests/tsc-references/compoundArithmeticAssignmentLHSCanBeAssigned_es5.2.minified.js index 6e708914033..dd5176954bc 100644 --- a/crates/swc/tests/tsc-references/compoundArithmeticAssignmentLHSCanBeAssigned_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundArithmeticAssignmentLHSCanBeAssigned_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, a, b, c, x1, x2, x3, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", x1 *= a, x1 *= b, x1 *= c, x1 *= null, x1 *= void 0, x2 *= a, x2 *= b, x2 *= c, x2 *= null, x2 *= void 0, x3 *= a, x3 *= b, x3 *= c, x3 *= null, x3 *= void 0; +var E, a, b, c, x1, x2, x3; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), x1 *= a, x1 *= b, x1 *= c, x1 *= null, x1 *= void 0, x2 *= a, x2 *= b, x2 *= c, x2 *= null, x2 *= void 0, x3 *= a, x3 *= b, x3 *= c, x3 *= null, x3 *= void 0; diff --git a/crates/swc/tests/tsc-references/compoundArithmeticAssignmentWithInvalidOperands_es2015.2.minified.js b/crates/swc/tests/tsc-references/compoundArithmeticAssignmentWithInvalidOperands_es2015.2.minified.js index e6799ecc61e..71bb376797b 100644 --- a/crates/swc/tests/tsc-references/compoundArithmeticAssignmentWithInvalidOperands_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundArithmeticAssignmentWithInvalidOperands_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, a, b, x1, x2, x3, x4, x5, x6, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", x1 *= a, x1 *= b, x1 *= !0, x1 *= 0, x1 *= "", x1 *= E.a, x1 *= {}, x1 *= null, x1 *= void 0, x2 *= a, x2 *= b, x2 *= !0, x2 *= 0, x2 *= "", x2 *= E.a, x2 *= {}, x2 *= null, x2 *= void 0, x3 *= a, x3 *= b, x3 *= !0, x3 *= 0, x3 *= "", x3 *= E.a, x3 *= {}, x3 *= null, x3 *= void 0, x4 *= a, x4 *= b, x4 *= !0, x4 *= 0, x4 *= "", x4 *= E.a, x4 *= {}, x4 *= null, x4 *= void 0, x5 *= b, x5 *= !0, x5 *= "", x5 *= {}, x6 *= b, x6 *= !0, x6 *= "", x6 *= {}; +var E, a, b, x1, x2, x3, x4, x5, x6; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), x1 *= a, x1 *= b, x1 *= !0, x1 *= 0, x1 *= "", x1 *= E.a, x1 *= {}, x1 *= null, x1 *= void 0, x2 *= a, x2 *= b, x2 *= !0, x2 *= 0, x2 *= "", x2 *= E.a, x2 *= {}, x2 *= null, x2 *= void 0, x3 *= a, x3 *= b, x3 *= !0, x3 *= 0, x3 *= "", x3 *= E.a, x3 *= {}, x3 *= null, x3 *= void 0, x4 *= a, x4 *= b, x4 *= !0, x4 *= 0, x4 *= "", x4 *= E.a, x4 *= {}, x4 *= null, x4 *= void 0, x5 *= b, x5 *= !0, x5 *= "", x5 *= {}, x6 *= b, x6 *= !0, x6 *= "", x6 *= {}; diff --git a/crates/swc/tests/tsc-references/compoundArithmeticAssignmentWithInvalidOperands_es5.2.minified.js b/crates/swc/tests/tsc-references/compoundArithmeticAssignmentWithInvalidOperands_es5.2.minified.js index e6799ecc61e..71bb376797b 100644 --- a/crates/swc/tests/tsc-references/compoundArithmeticAssignmentWithInvalidOperands_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundArithmeticAssignmentWithInvalidOperands_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, a, b, x1, x2, x3, x4, x5, x6, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", x1 *= a, x1 *= b, x1 *= !0, x1 *= 0, x1 *= "", x1 *= E.a, x1 *= {}, x1 *= null, x1 *= void 0, x2 *= a, x2 *= b, x2 *= !0, x2 *= 0, x2 *= "", x2 *= E.a, x2 *= {}, x2 *= null, x2 *= void 0, x3 *= a, x3 *= b, x3 *= !0, x3 *= 0, x3 *= "", x3 *= E.a, x3 *= {}, x3 *= null, x3 *= void 0, x4 *= a, x4 *= b, x4 *= !0, x4 *= 0, x4 *= "", x4 *= E.a, x4 *= {}, x4 *= null, x4 *= void 0, x5 *= b, x5 *= !0, x5 *= "", x5 *= {}, x6 *= b, x6 *= !0, x6 *= "", x6 *= {}; +var E, a, b, x1, x2, x3, x4, x5, x6; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), x1 *= a, x1 *= b, x1 *= !0, x1 *= 0, x1 *= "", x1 *= E.a, x1 *= {}, x1 *= null, x1 *= void 0, x2 *= a, x2 *= b, x2 *= !0, x2 *= 0, x2 *= "", x2 *= E.a, x2 *= {}, x2 *= null, x2 *= void 0, x3 *= a, x3 *= b, x3 *= !0, x3 *= 0, x3 *= "", x3 *= E.a, x3 *= {}, x3 *= null, x3 *= void 0, x4 *= a, x4 *= b, x4 *= !0, x4 *= 0, x4 *= "", x4 *= E.a, x4 *= {}, x4 *= null, x4 *= void 0, x5 *= b, x5 *= !0, x5 *= "", x5 *= {}, x6 *= b, x6 *= !0, x6 *= "", x6 *= {}; diff --git a/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCanBeAssigned1_es2015.2.minified.js b/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCanBeAssigned1_es2015.2.minified.js index 2d2e7e6fb57..076cd3a2c51 100644 --- a/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCanBeAssigned1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCanBeAssigned1_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, a, b, c, x1, x2, x3, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", x1 = Math.pow(x1, a) = Math.pow(x1, b), x1 = Math.pow(x1, c) = Math.pow(x1, null), x1 = Math.pow(x1, void 0), x2 = Math.pow(x2, a), x2 = Math.pow(x2, b), x2 = Math.pow(x2, c), x2 = Math.pow(x2, null), x2 = Math.pow(x2, void 0), x3 = Math.pow(x3, a), x3 = Math.pow(x3, b), x3 = Math.pow(x3, c), x3 = Math.pow(x3, null), x3 = Math.pow(x3, void 0); +var E, a, b, c, x1, x2, x3; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), x1 = Math.pow(x1, a) = Math.pow(x1, b), x1 = Math.pow(x1, c) = Math.pow(x1, null), x1 = Math.pow(x1, void 0), x2 = Math.pow(x2, a), x2 = Math.pow(x2, b), x2 = Math.pow(x2, c), x2 = Math.pow(x2, null), x2 = Math.pow(x2, void 0), x3 = Math.pow(x3, a), x3 = Math.pow(x3, b), x3 = Math.pow(x3, c), x3 = Math.pow(x3, null), x3 = Math.pow(x3, void 0); diff --git a/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCanBeAssigned1_es5.2.minified.js b/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCanBeAssigned1_es5.2.minified.js index 2d2e7e6fb57..076cd3a2c51 100644 --- a/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCanBeAssigned1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCanBeAssigned1_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, a, b, c, x1, x2, x3, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", x1 = Math.pow(x1, a) = Math.pow(x1, b), x1 = Math.pow(x1, c) = Math.pow(x1, null), x1 = Math.pow(x1, void 0), x2 = Math.pow(x2, a), x2 = Math.pow(x2, b), x2 = Math.pow(x2, c), x2 = Math.pow(x2, null), x2 = Math.pow(x2, void 0), x3 = Math.pow(x3, a), x3 = Math.pow(x3, b), x3 = Math.pow(x3, c), x3 = Math.pow(x3, null), x3 = Math.pow(x3, void 0); +var E, a, b, c, x1, x2, x3; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), x1 = Math.pow(x1, a) = Math.pow(x1, b), x1 = Math.pow(x1, c) = Math.pow(x1, null), x1 = Math.pow(x1, void 0), x2 = Math.pow(x2, a), x2 = Math.pow(x2, b), x2 = Math.pow(x2, c), x2 = Math.pow(x2, null), x2 = Math.pow(x2, void 0), x3 = Math.pow(x3, a), x3 = Math.pow(x3, b), x3 = Math.pow(x3, c), x3 = Math.pow(x3, null), x3 = Math.pow(x3, void 0); diff --git a/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCannotBeAssigned_es2015.2.minified.js b/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCannotBeAssigned_es2015.2.minified.js index c87dce857ac..c8d558f5380 100644 --- a/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCannotBeAssigned_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCannotBeAssigned_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, a, b, x1, x2, x3, x4, x5, x6, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", x1 = Math.pow(x1, a) = Math.pow(x1, b), x1 = Math.pow(x1, !0) = Math.pow(x1, 0), x1 = Math.pow(x1, "") = Math.pow(x1, E.a), x1 = Math.pow(x1, {}) = Math.pow(x1, null), x1 = Math.pow(x1, void 0), x2 = Math.pow(x2, a), x2 = Math.pow(x2, b), x2 = Math.pow(x2, !0), x2 = Math.pow(x2, 0), x2 = Math.pow(x2, ""), x2 = Math.pow(x2, E.a), x2 = Math.pow(x2, {}), x2 = Math.pow(x2, null), x2 = Math.pow(x2, void 0), x3 = Math.pow(x3, a), x3 = Math.pow(x3, b), x3 = Math.pow(x3, !0), x3 = Math.pow(x3, 0), x3 = Math.pow(x3, ""), x3 = Math.pow(x3, E.a), x3 = Math.pow(x3, {}), x3 = Math.pow(x3, null), x3 = Math.pow(x3, void 0), x4 = Math.pow(x4, a), x4 = Math.pow(x4, b), x4 = Math.pow(x4, !0), x4 = Math.pow(x4, 0), x4 = Math.pow(x4, ""), x4 = Math.pow(x4, E.a), x4 = Math.pow(x4, {}), x4 = Math.pow(x4, null), x4 = Math.pow(x4, void 0), x5 = Math.pow(x5, b), x5 = Math.pow(x5, !0), x5 = Math.pow(x5, ""), x5 = Math.pow(x5, {}), x6 = Math.pow(x6, b), x6 = Math.pow(x6, !0), x6 = Math.pow(x6, ""), x6 = Math.pow(x6, {}); +var E, a, b, x1, x2, x3, x4, x5, x6; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), x1 = Math.pow(x1, a) = Math.pow(x1, b), x1 = Math.pow(x1, !0) = Math.pow(x1, 0), x1 = Math.pow(x1, "") = Math.pow(x1, E.a), x1 = Math.pow(x1, {}) = Math.pow(x1, null), x1 = Math.pow(x1, void 0), x2 = Math.pow(x2, a), x2 = Math.pow(x2, b), x2 = Math.pow(x2, !0), x2 = Math.pow(x2, 0), x2 = Math.pow(x2, ""), x2 = Math.pow(x2, E.a), x2 = Math.pow(x2, {}), x2 = Math.pow(x2, null), x2 = Math.pow(x2, void 0), x3 = Math.pow(x3, a), x3 = Math.pow(x3, b), x3 = Math.pow(x3, !0), x3 = Math.pow(x3, 0), x3 = Math.pow(x3, ""), x3 = Math.pow(x3, E.a), x3 = Math.pow(x3, {}), x3 = Math.pow(x3, null), x3 = Math.pow(x3, void 0), x4 = Math.pow(x4, a), x4 = Math.pow(x4, b), x4 = Math.pow(x4, !0), x4 = Math.pow(x4, 0), x4 = Math.pow(x4, ""), x4 = Math.pow(x4, E.a), x4 = Math.pow(x4, {}), x4 = Math.pow(x4, null), x4 = Math.pow(x4, void 0), x5 = Math.pow(x5, b), x5 = Math.pow(x5, !0), x5 = Math.pow(x5, ""), x5 = Math.pow(x5, {}), x6 = Math.pow(x6, b), x6 = Math.pow(x6, !0), x6 = Math.pow(x6, ""), x6 = Math.pow(x6, {}); diff --git a/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCannotBeAssigned_es5.2.minified.js b/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCannotBeAssigned_es5.2.minified.js index c87dce857ac..c8d558f5380 100644 --- a/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCannotBeAssigned_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/compoundExponentiationAssignmentLHSCannotBeAssigned_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, a, b, x1, x2, x3, x4, x5, x6, E; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", x1 = Math.pow(x1, a) = Math.pow(x1, b), x1 = Math.pow(x1, !0) = Math.pow(x1, 0), x1 = Math.pow(x1, "") = Math.pow(x1, E.a), x1 = Math.pow(x1, {}) = Math.pow(x1, null), x1 = Math.pow(x1, void 0), x2 = Math.pow(x2, a), x2 = Math.pow(x2, b), x2 = Math.pow(x2, !0), x2 = Math.pow(x2, 0), x2 = Math.pow(x2, ""), x2 = Math.pow(x2, E.a), x2 = Math.pow(x2, {}), x2 = Math.pow(x2, null), x2 = Math.pow(x2, void 0), x3 = Math.pow(x3, a), x3 = Math.pow(x3, b), x3 = Math.pow(x3, !0), x3 = Math.pow(x3, 0), x3 = Math.pow(x3, ""), x3 = Math.pow(x3, E.a), x3 = Math.pow(x3, {}), x3 = Math.pow(x3, null), x3 = Math.pow(x3, void 0), x4 = Math.pow(x4, a), x4 = Math.pow(x4, b), x4 = Math.pow(x4, !0), x4 = Math.pow(x4, 0), x4 = Math.pow(x4, ""), x4 = Math.pow(x4, E.a), x4 = Math.pow(x4, {}), x4 = Math.pow(x4, null), x4 = Math.pow(x4, void 0), x5 = Math.pow(x5, b), x5 = Math.pow(x5, !0), x5 = Math.pow(x5, ""), x5 = Math.pow(x5, {}), x6 = Math.pow(x6, b), x6 = Math.pow(x6, !0), x6 = Math.pow(x6, ""), x6 = Math.pow(x6, {}); +var E, a, b, x1, x2, x3, x4, x5, x6; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), x1 = Math.pow(x1, a) = Math.pow(x1, b), x1 = Math.pow(x1, !0) = Math.pow(x1, 0), x1 = Math.pow(x1, "") = Math.pow(x1, E.a), x1 = Math.pow(x1, {}) = Math.pow(x1, null), x1 = Math.pow(x1, void 0), x2 = Math.pow(x2, a), x2 = Math.pow(x2, b), x2 = Math.pow(x2, !0), x2 = Math.pow(x2, 0), x2 = Math.pow(x2, ""), x2 = Math.pow(x2, E.a), x2 = Math.pow(x2, {}), x2 = Math.pow(x2, null), x2 = Math.pow(x2, void 0), x3 = Math.pow(x3, a), x3 = Math.pow(x3, b), x3 = Math.pow(x3, !0), x3 = Math.pow(x3, 0), x3 = Math.pow(x3, ""), x3 = Math.pow(x3, E.a), x3 = Math.pow(x3, {}), x3 = Math.pow(x3, null), x3 = Math.pow(x3, void 0), x4 = Math.pow(x4, a), x4 = Math.pow(x4, b), x4 = Math.pow(x4, !0), x4 = Math.pow(x4, 0), x4 = Math.pow(x4, ""), x4 = Math.pow(x4, E.a), x4 = Math.pow(x4, {}), x4 = Math.pow(x4, null), x4 = Math.pow(x4, void 0), x5 = Math.pow(x5, b), x5 = Math.pow(x5, !0), x5 = Math.pow(x5, ""), x5 = Math.pow(x5, {}), x6 = Math.pow(x6, b), x6 = Math.pow(x6, !0), x6 = Math.pow(x6, ""), x6 = Math.pow(x6, {}); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames20_ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames20_ES5_es5.2.minified.js index 41b8d79942e..5d5de9ef660 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames20_ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames20_ES5_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -obj = {}, value = 0, (key = this.bar) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, this.bar, 0); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames20_ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames20_ES6_es5.2.minified.js index 41b8d79942e..5d5de9ef660 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames20_ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames20_ES6_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -obj = {}, value = 0, (key = this.bar) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, this.bar, 0); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames23_ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames23_ES5_es5.2.minified.js index c61d78add2a..7d9562780e8 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames23_ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames23_ES5_es5.2.minified.js @@ -4,12 +4,14 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var obj, key, value, tmp = (obj = {}, value = 1, (key = this.bar()) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value, obj)[0], C = function() { +var tmp = function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, this.bar(), 1)[0], C = function() { "use strict"; var Constructor, protoProps, staticProps; function C() { diff --git a/crates/swc/tests/tsc-references/computedPropertyNames23_ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames23_ES6_es5.2.minified.js index c61d78add2a..7d9562780e8 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames23_ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames23_ES6_es5.2.minified.js @@ -4,12 +4,14 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var obj, key, value, tmp = (obj = {}, value = 1, (key = this.bar()) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value, obj)[0], C = function() { +var tmp = function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, this.bar(), 1)[0], C = function() { "use strict"; var Constructor, protoProps, staticProps; function C() { diff --git a/crates/swc/tests/tsc-references/computedPropertyNames26_ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames26_ES5_es5.2.minified.js index c44eb602a8a..c93f12f8981 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames26_ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames26_ES5_es5.2.minified.js @@ -20,7 +20,7 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var obj, key, value, Base = function() { +var Base = function() { "use strict"; function Base() { _classCallCheck(this, Base); @@ -33,12 +33,14 @@ var obj, key, value, Base = function() { } } ]), Base; -}(), tmp = (value = 1, (key = super.bar()) in (obj = {}) ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value, obj)[0], C = function(Base) { +}(), tmp = function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, super.bar(), 1)[0], C = function(Base) { "use strict"; !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames26_ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames26_ES6_es5.2.minified.js index c44eb602a8a..c93f12f8981 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames26_ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames26_ES6_es5.2.minified.js @@ -20,7 +20,7 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var obj, key, value, Base = function() { +var Base = function() { "use strict"; function Base() { _classCallCheck(this, Base); @@ -33,12 +33,14 @@ var obj, key, value, Base = function() { } } ]), Base; -}(), tmp = (value = 1, (key = super.bar()) in (obj = {}) ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value, obj)[0], C = function(Base) { +}(), tmp = function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, super.bar(), 1)[0], C = function(Base) { "use strict"; !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames46_ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames46_ES5_es5.2.minified.js index 1d8ec548b34..63ea06d84b7 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames46_ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames46_ES5_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -value = 0, (key = 0) in (obj = {}) ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, 0, 0); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames46_ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames46_ES6_es5.2.minified.js index 1d8ec548b34..63ea06d84b7 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames46_ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames46_ES6_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -value = 0, (key = 0) in (obj = {}) ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, 0, 0); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames47_ES5_es2015.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames47_ES5_es2015.2.minified.js index a5cab2cb4b8..79a59290a80 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames47_ES5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames47_ES5_es2015.2.minified.js @@ -1,2 +1,6 @@ -var E1, E2, E1, E2; -(E1 = E1 || (E1 = {}))[E1.x = 0] = "x", (E2 = E2 || (E2 = {}))[E2.x = 0] = "x", E1.x || E2.x; +var E1, E2; +!function(E1) { + E1[E1.x = 0] = "x"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.x = 0] = "x"; +})(E2 || (E2 = {})), E1.x || E2.x; diff --git a/crates/swc/tests/tsc-references/computedPropertyNames47_ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames47_ES5_es5.2.minified.js index 85c71e5976a..41c53e25399 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames47_ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames47_ES5_es5.2.minified.js @@ -1,7 +1,13 @@ -var E1, E2, obj, key, value, E1, E2; -(E1 = E1 || (E1 = {}))[E1.x = 0] = "x", (E2 = E2 || (E2 = {}))[E2.x = 0] = "x", obj = {}, value = 0, (key = E1.x || E2.x) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +var E1, E2; +!function(E1) { + E1[E1.x = 0] = "x"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.x = 0] = "x"; +})(E2 || (E2 = {})), (function(obj, key, value) { + key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value; +})({}, E1.x || E2.x, 0); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames47_ES6_es2015.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames47_ES6_es2015.2.minified.js index a5cab2cb4b8..79a59290a80 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames47_ES6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames47_ES6_es2015.2.minified.js @@ -1,2 +1,6 @@ -var E1, E2, E1, E2; -(E1 = E1 || (E1 = {}))[E1.x = 0] = "x", (E2 = E2 || (E2 = {}))[E2.x = 0] = "x", E1.x || E2.x; +var E1, E2; +!function(E1) { + E1[E1.x = 0] = "x"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.x = 0] = "x"; +})(E2 || (E2 = {})), E1.x || E2.x; diff --git a/crates/swc/tests/tsc-references/computedPropertyNames47_ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames47_ES6_es5.2.minified.js index 85c71e5976a..41c53e25399 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames47_ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames47_ES6_es5.2.minified.js @@ -1,7 +1,13 @@ -var E1, E2, obj, key, value, E1, E2; -(E1 = E1 || (E1 = {}))[E1.x = 0] = "x", (E2 = E2 || (E2 = {}))[E2.x = 0] = "x", obj = {}, value = 0, (key = E1.x || E2.x) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +var E1, E2; +!function(E1) { + E1[E1.x = 0] = "x"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.x = 0] = "x"; +})(E2 || (E2 = {})), (function(obj, key, value) { + key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value; +})({}, E1.x || E2.x, 0); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames48_ES5_es2015.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames48_ES5_es2015.2.minified.js index 40e3046509b..3acb6104840 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames48_ES5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames48_ES5_es2015.2.minified.js @@ -1,5 +1,7 @@ -var E, a, E; -(E = E || (E = {}))[E.x = 0] = "x", extractIndexer({ +var E, a; +!function(E) { + E[E.x = 0] = "x"; +}(E || (E = {})), extractIndexer({ [a]: "" }), extractIndexer({ [E.x]: "" diff --git a/crates/swc/tests/tsc-references/computedPropertyNames48_ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames48_ES5_es5.2.minified.js index daae5291aa4..daf240d5fd2 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames48_ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames48_ES5_es5.2.minified.js @@ -1,4 +1,4 @@ -var E, a, E; +var E, a; function _defineProperty(obj, key, value) { return key in obj ? Object.defineProperty(obj, key, { value: value, @@ -7,4 +7,6 @@ function _defineProperty(obj, key, value) { writable: !0 }) : obj[key] = value, obj; } -(E = E || (E = {}))[E.x = 0] = "x", extractIndexer(_defineProperty({}, a, "")), extractIndexer(_defineProperty({}, E.x, "")), extractIndexer(_defineProperty({}, 0, "")); +!function(E) { + E[E.x = 0] = "x"; +}(E || (E = {})), extractIndexer(_defineProperty({}, a, "")), extractIndexer(_defineProperty({}, E.x, "")), extractIndexer(_defineProperty({}, 0, "")); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames48_ES6_es2015.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames48_ES6_es2015.2.minified.js index 40e3046509b..3acb6104840 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames48_ES6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames48_ES6_es2015.2.minified.js @@ -1,5 +1,7 @@ -var E, a, E; -(E = E || (E = {}))[E.x = 0] = "x", extractIndexer({ +var E, a; +!function(E) { + E[E.x = 0] = "x"; +}(E || (E = {})), extractIndexer({ [a]: "" }), extractIndexer({ [E.x]: "" diff --git a/crates/swc/tests/tsc-references/computedPropertyNames48_ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames48_ES6_es5.2.minified.js index daae5291aa4..daf240d5fd2 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames48_ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames48_ES6_es5.2.minified.js @@ -1,4 +1,4 @@ -var E, a, E; +var E, a; function _defineProperty(obj, key, value) { return key in obj ? Object.defineProperty(obj, key, { value: value, @@ -7,4 +7,6 @@ function _defineProperty(obj, key, value) { writable: !0 }) : obj[key] = value, obj; } -(E = E || (E = {}))[E.x = 0] = "x", extractIndexer(_defineProperty({}, a, "")), extractIndexer(_defineProperty({}, E.x, "")), extractIndexer(_defineProperty({}, 0, "")); +!function(E) { + E[E.x = 0] = "x"; +}(E || (E = {})), extractIndexer(_defineProperty({}, a, "")), extractIndexer(_defineProperty({}, E.x, "")), extractIndexer(_defineProperty({}, 0, "")); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames7_ES5_es2015.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames7_ES5_es2015.2.minified.js index b0189329a59..4e753f6680e 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames7_ES5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames7_ES5_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.member = 0] = "member", E.member; +var E; +!function(E) { + E[E.member = 0] = "member"; +}(E || (E = {})), E.member; diff --git a/crates/swc/tests/tsc-references/computedPropertyNames7_ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames7_ES5_es5.2.minified.js index 75d80bcddb3..3102104de71 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames7_ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames7_ES5_es5.2.minified.js @@ -1,7 +1,11 @@ -var E, obj, key, value, E; -(E = E || (E = {}))[E.member = 0] = "member", obj = {}, value = 0, (key = E.member) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +var E; +!function(E) { + E[E.member = 0] = "member"; +}(E || (E = {})), (function(obj, key, value) { + key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value; +})({}, E.member, 0); diff --git a/crates/swc/tests/tsc-references/computedPropertyNames7_ES6_es2015.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames7_ES6_es2015.2.minified.js index b0189329a59..4e753f6680e 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames7_ES6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames7_ES6_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.member = 0] = "member", E.member; +var E; +!function(E) { + E[E.member = 0] = "member"; +}(E || (E = {})), E.member; diff --git a/crates/swc/tests/tsc-references/computedPropertyNames7_ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/computedPropertyNames7_ES6_es5.2.minified.js index 75d80bcddb3..3102104de71 100644 --- a/crates/swc/tests/tsc-references/computedPropertyNames7_ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/computedPropertyNames7_ES6_es5.2.minified.js @@ -1,7 +1,11 @@ -var E, obj, key, value, E; -(E = E || (E = {}))[E.member = 0] = "member", obj = {}, value = 0, (key = E.member) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +var E; +!function(E) { + E[E.member = 0] = "member"; +}(E || (E = {})), (function(obj, key, value) { + key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value; +})({}, E.member, 0); diff --git a/crates/swc/tests/tsc-references/declarationsAndAssignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/declarationsAndAssignments_es2015.2.minified.js index 42fd1661bc2..28cfce2e23a 100644 --- a/crates/swc/tests/tsc-references/declarationsAndAssignments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/declarationsAndAssignments_es2015.2.minified.js @@ -1,4 +1,4 @@ -var M, M1; +var M; function f14([a = 1, [b = "hello", { x , y: c = !1 }]]) {} function f17({ a ="" , b =0 , c =!1 }) {} f14([ @@ -26,10 +26,12 @@ f14([ y: !1 } ] -]), M1 = M || (M = {}), [M1.a, M1.b] = [ - 1, - 2 -], f17({}), f17({ +]), (function(M1) { + [M1.a, M1.b] = [ + 1, + 2 + ]; +})(M || (M = {})), f17({}), f17({ a: "hello" }), f17({ c: !0 diff --git a/crates/swc/tests/tsc-references/declarationsAndAssignments_es5.2.minified.js b/crates/swc/tests/tsc-references/declarationsAndAssignments_es5.2.minified.js index 10c2f32c413..afa555d11f5 100644 --- a/crates/swc/tests/tsc-references/declarationsAndAssignments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/declarationsAndAssignments_es5.2.minified.js @@ -1,4 +1,4 @@ -var M, M1; +var M; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; @@ -68,7 +68,9 @@ f14([ y: !1 } ] -]), (M1 = M || (M = {})).a = 1, M1.b = 2, f17({}), f17({ +]), (function(M1) { + M1.a = 1, M1.b = 2; +})(M || (M = {})), f17({}), f17({ a: "hello" }), f17({ c: !0 diff --git a/crates/swc/tests/tsc-references/decrementOperatorWithEnumTypeInvalidOperations_es2015.2.minified.js b/crates/swc/tests/tsc-references/decrementOperatorWithEnumTypeInvalidOperations_es2015.2.minified.js index 6c468164509..1db9d3dced6 100644 --- a/crates/swc/tests/tsc-references/decrementOperatorWithEnumTypeInvalidOperations_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/decrementOperatorWithEnumTypeInvalidOperations_es2015.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", --ENUM, --ENUM1, ENUM--, ENUM1--, --ENUM.A + ENUM.B, ENUM.A + ENUM.B--, --ENUM, --ENUM1, ENUM--, ENUM1--; +var ENUM, ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), --ENUM, --ENUM1, ENUM--, ENUM1--, --ENUM.A + ENUM.B, ENUM.A + ENUM.B--, --ENUM, --ENUM1, ENUM--, ENUM1--; diff --git a/crates/swc/tests/tsc-references/decrementOperatorWithEnumTypeInvalidOperations_es5.2.minified.js b/crates/swc/tests/tsc-references/decrementOperatorWithEnumTypeInvalidOperations_es5.2.minified.js index 6c468164509..1db9d3dced6 100644 --- a/crates/swc/tests/tsc-references/decrementOperatorWithEnumTypeInvalidOperations_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/decrementOperatorWithEnumTypeInvalidOperations_es5.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", --ENUM, --ENUM1, ENUM--, ENUM1--, --ENUM.A + ENUM.B, ENUM.A + ENUM.B--, --ENUM, --ENUM1, ENUM--, ENUM1--; +var ENUM, ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), --ENUM, --ENUM1, ENUM--, ENUM1--, --ENUM.A + ENUM.B, ENUM.A + ENUM.B--, --ENUM, --ENUM1, ENUM--, ENUM1--; diff --git a/crates/swc/tests/tsc-references/decrementOperatorWithEnumType_es2015.2.minified.js b/crates/swc/tests/tsc-references/decrementOperatorWithEnumType_es2015.2.minified.js index 983046c21e5..9cb88ae5c29 100644 --- a/crates/swc/tests/tsc-references/decrementOperatorWithEnumType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/decrementOperatorWithEnumType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", --ENUM1.A, ENUM1.A--, --ENUM1.A, ENUM1[A]--; +var ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), --ENUM1.A, ENUM1.A--, --ENUM1.A, ENUM1[A]--; diff --git a/crates/swc/tests/tsc-references/decrementOperatorWithEnumType_es5.2.minified.js b/crates/swc/tests/tsc-references/decrementOperatorWithEnumType_es5.2.minified.js index 983046c21e5..9cb88ae5c29 100644 --- a/crates/swc/tests/tsc-references/decrementOperatorWithEnumType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/decrementOperatorWithEnumType_es5.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", --ENUM1.A, ENUM1.A--, --ENUM1.A, ENUM1[A]--; +var ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), --ENUM1.A, ENUM1.A--, --ENUM1.A, ENUM1[A]--; diff --git a/crates/swc/tests/tsc-references/defaultExportsCannotMerge01_es2015.2.minified.js b/crates/swc/tests/tsc-references/defaultExportsCannotMerge01_es2015.2.minified.js index 132811488f3..724d9fc23f2 100644 --- a/crates/swc/tests/tsc-references/defaultExportsCannotMerge01_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/defaultExportsCannotMerge01_es2015.2.minified.js @@ -1,6 +1,8 @@ -var Decl, Decl1; +var Decl; import Entity from "m1"; export default function Decl() { return 0; }; -(Decl1 = Decl || (Decl = {})).x = 10, Decl1.y = 20, Entity(); +!function(Decl) { + Decl.x = 10, Decl.y = 20; +}(Decl || (Decl = {})), Entity(); diff --git a/crates/swc/tests/tsc-references/defaultExportsCannotMerge01_es5.2.minified.js b/crates/swc/tests/tsc-references/defaultExportsCannotMerge01_es5.2.minified.js index 132811488f3..724d9fc23f2 100644 --- a/crates/swc/tests/tsc-references/defaultExportsCannotMerge01_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/defaultExportsCannotMerge01_es5.2.minified.js @@ -1,6 +1,8 @@ -var Decl, Decl1; +var Decl; import Entity from "m1"; export default function Decl() { return 0; }; -(Decl1 = Decl || (Decl = {})).x = 10, Decl1.y = 20, Entity(); +!function(Decl) { + Decl.x = 10, Decl.y = 20; +}(Decl || (Decl = {})), Entity(); diff --git a/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES5_es5.2.minified.js index dd9537c35e4..7386870dbe0 100644 --- a/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES5_es5.2.minified.js @@ -52,14 +52,18 @@ function foo() { } _undefined1[0], _undefined1[1]; var ref = _slicedToArray(foo(), 2); -ref[0], ref[1], (_arrayWithHoles(arr = foo()) || _iterableToArray(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest()).slice(0); -var arr, arr, ref1 = _slicedToArray(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = [ +ref[0], ref[1], (function(arr) { + return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); +})(foo()).slice(0); +var ref1 = _slicedToArray(function(arr) { + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}([ 1, 2, 3 -]) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}(), 2); +]), 2); ref1[0], ref1[1]; diff --git a/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES5iterable_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES5iterable_es5.2.minified.js index dd9537c35e4..7386870dbe0 100644 --- a/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES5iterable_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES5iterable_es5.2.minified.js @@ -52,14 +52,18 @@ function foo() { } _undefined1[0], _undefined1[1]; var ref = _slicedToArray(foo(), 2); -ref[0], ref[1], (_arrayWithHoles(arr = foo()) || _iterableToArray(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest()).slice(0); -var arr, arr, ref1 = _slicedToArray(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = [ +ref[0], ref[1], (function(arr) { + return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); +})(foo()).slice(0); +var ref1 = _slicedToArray(function(arr) { + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}([ 1, 2, 3 -]) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}(), 2); +]), 2); ref1[0], ref1[1]; diff --git a/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES6_es5.2.minified.js index dd9537c35e4..7386870dbe0 100644 --- a/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment1ES6_es5.2.minified.js @@ -52,14 +52,18 @@ function foo() { } _undefined1[0], _undefined1[1]; var ref = _slicedToArray(foo(), 2); -ref[0], ref[1], (_arrayWithHoles(arr = foo()) || _iterableToArray(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest()).slice(0); -var arr, arr, ref1 = _slicedToArray(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = [ +ref[0], ref[1], (function(arr) { + return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); +})(foo()).slice(0); +var ref1 = _slicedToArray(function(arr) { + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}([ 1, 2, 3 -]) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}(), 2); +]), 2); ref1[0], ref1[1]; diff --git a/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment4_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment4_es5.2.minified.js index d8d8ce4649e..615ef010eca 100644 --- a/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment4_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringArrayBindingPatternAndAssignment4_es5.2.minified.js @@ -1,35 +1,36 @@ -var arr, i; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } -(i = 1, (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = data) || (function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ +(function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; try { - _n || null == _i.return || _i.return(); + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; } finally{ - if (_d) throw _e; + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } } + return _arr; } - return _arr; - } -})(arr, i) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})())[0]; + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})(data, 1)[0]; diff --git a/crates/swc/tests/tsc-references/destructuringEvaluationOrder_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringEvaluationOrder_es5.2.minified.js index 13b13eeab2c..e78e0f338a9 100644 --- a/crates/swc/tests/tsc-references/destructuringEvaluationOrder_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringEvaluationOrder_es5.2.minified.js @@ -12,7 +12,7 @@ function _extends() { return target; }).apply(this, arguments); } -var arr, i, _typeof = function(obj) { +var _typeof = function(obj) { return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; }, trace = [], order = function(n) { return trace.push(n); @@ -52,35 +52,37 @@ var _ref1 = [ { x: 1 } -], __ref = (i = 2, function(arr) { - if (Array.isArray(arr)) return arr; -}(arr = _ref1) || function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ +], __ref = function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; try { - _n || null == _i.return || _i.return(); + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; } finally{ - if (_d) throw _e; + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } } + return _arr; } - return _arr; - } -}(arr, i) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr, i) || function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()), ref = __ref[0], ref = null !== ref ? ref : function(e) { + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(_ref1, 2), ref = __ref[0], ref = null !== ref ? ref : function(e) { throw e; }(new TypeError("Cannot destructure undefined")); __ref[1], _extends({}, _ref1[0]); diff --git a/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment7_es2015.2.minified.js b/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment7_es2015.2.minified.js index 8aaf0e3b596..552b1745679 100644 --- a/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment7_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment7_es2015.2.minified.js @@ -1,5 +1,7 @@ -var K, K; -(K = K || (K = {})).a = "a", K.b = "b"; +var K; +!function(K) { + K.a = "a", K.b = "b"; +}(K || (K = {})); const { [K.a]: aVal , [K.b]: bVal } = { [K.a]: 1, [K.b]: 1 diff --git a/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment7_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment7_es5.2.minified.js index 11657dda7dd..0318f4afa0d 100644 --- a/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment7_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment7_es5.2.minified.js @@ -6,8 +6,10 @@ function _defineProperty(obj, key, value) { writable: !0 }) : obj[key] = value, obj; } -(K = K || (K = {})).a = "a", K.b = "b"; -var K, K, ref = function() { +!function(K) { + K.a = "a", K.b = "b"; +}(K || (K = {})); +var K, ref = function() { var _obj; return _defineProperty(_obj = {}, K.a, 1), _defineProperty(_obj, K.b, 1), _obj; }(), aVal = ref[K.a], bVal = ref[K.b]; diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5_es2015.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5_es2015.2.minified.js index d9ff4b0a348..0629eaca8b1 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5_es2015.2.minified.js @@ -1,4 +1,4 @@ -var Foo, Foo; +var Foo; function a1([a, b, [[c]]]) {} function b2(z = null, o = { x: 0, @@ -33,7 +33,9 @@ a1([ }), b2("string", { x: 200, y: !0 -}), (Foo = Foo || (Foo = {}))[Foo.a = 0] = "a", c0({ +}), (function(Foo) { + Foo[Foo.a = 0] = "a"; +})(Foo || (Foo = {})), c0({ z: { x: 1, y: { diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5_es5.2.minified.js index 37fc6a660c9..96e18ffd97a 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5_es5.2.minified.js @@ -135,7 +135,9 @@ a1([ !1 ] ] -]), (Foo = Foo || (Foo = {}))[Foo.a = 0] = "a", c0({ +]), (function(Foo) { + Foo[Foo.a = 0] = "a"; +})(Foo || (Foo = {})), c0({ z: { x: 1, y: { @@ -178,7 +180,7 @@ a1([ !1, !0 ]); -var Foo, Foo, C2 = function() { +var Foo, C2 = function() { "use strict"; function C2() { _classCallCheck(this, C2); diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5iterable_es2015.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5iterable_es2015.2.minified.js index d9ff4b0a348..0629eaca8b1 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5iterable_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5iterable_es2015.2.minified.js @@ -1,4 +1,4 @@ -var Foo, Foo; +var Foo; function a1([a, b, [[c]]]) {} function b2(z = null, o = { x: 0, @@ -33,7 +33,9 @@ a1([ }), b2("string", { x: 200, y: !0 -}), (Foo = Foo || (Foo = {}))[Foo.a = 0] = "a", c0({ +}), (function(Foo) { + Foo[Foo.a = 0] = "a"; +})(Foo || (Foo = {})), c0({ z: { x: 1, y: { diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5iterable_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5iterable_es5.2.minified.js index 37fc6a660c9..96e18ffd97a 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5iterable_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES5iterable_es5.2.minified.js @@ -135,7 +135,9 @@ a1([ !1 ] ] -]), (Foo = Foo || (Foo = {}))[Foo.a = 0] = "a", c0({ +]), (function(Foo) { + Foo[Foo.a = 0] = "a"; +})(Foo || (Foo = {})), c0({ z: { x: 1, y: { @@ -178,7 +180,7 @@ a1([ !1, !0 ]); -var Foo, Foo, C2 = function() { +var Foo, C2 = function() { "use strict"; function C2() { _classCallCheck(this, C2); diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES6_es2015.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES6_es2015.2.minified.js index d9ff4b0a348..0629eaca8b1 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES6_es2015.2.minified.js @@ -1,4 +1,4 @@ -var Foo, Foo; +var Foo; function a1([a, b, [[c]]]) {} function b2(z = null, o = { x: 0, @@ -33,7 +33,9 @@ a1([ }), b2("string", { x: 200, y: !0 -}), (Foo = Foo || (Foo = {}))[Foo.a = 0] = "a", c0({ +}), (function(Foo) { + Foo[Foo.a = 0] = "a"; +})(Foo || (Foo = {})), c0({ z: { x: 1, y: { diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES6_es5.2.minified.js index 247e6c04fca..c64027e09e1 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration1ES6_es5.2.minified.js @@ -99,7 +99,9 @@ a1([ }), b2("string", { x: 200, y: !0 -}), (Foo = Foo || (Foo = {}))[Foo.a = 0] = "a", c0({ +}), (function(Foo) { + Foo[Foo.a = 0] = "a"; +})(Foo || (Foo = {})), c0({ z: { x: 1, y: { @@ -142,7 +144,7 @@ a1([ !1, !0 ]); -var Foo, Foo, C2 = function() { +var Foo, C2 = function() { "use strict"; function C2() { _classCallCheck(this, C2); diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5_es2015.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5_es2015.2.minified.js index 3212c5df5bd..0d9df2eb8a8 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5_es2015.2.minified.js @@ -1,4 +1,4 @@ -var E, E1, E, E1; +var E, E1; function a10([a, b, [[c]], ...x]) {} function foo(...a) {} function foo1(...a) {} @@ -21,4 +21,8 @@ a10([ ]), a10([ 1, 2 -]), foo("hello", 1, 2), foo("hello", "world"), (E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (E1 = E1 || (E1 = {}))[E1.a = 0] = "a", E1[E1.b = 1] = "b", foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); +]), foo("hello", 1, 2), foo("hello", "world"), (function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +})(E || (E = {})), (function(E1) { + E1[E1.a = 0] = "a", E1[E1.b = 1] = "b"; +})(E1 || (E1 = {})), foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5_es5.2.minified.js index 14a4e5604fc..38fc41d15ac 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5_es5.2.minified.js @@ -54,7 +54,7 @@ function a10(param) { var _param = _toArray(param), a = _param[0], b = _param[1], ref = _slicedToArray(_param[2], 1), ref1 = _slicedToArray(ref[0], 1); ref1[0], _param.slice(3); } -var E, E1, E, E1, array = [ +var E, E1, array = [ 1, 2, 3 @@ -107,4 +107,8 @@ function foo1() { })([ 1, 2 -]), foo("hello", 1, 2), foo("hello", "world"), (E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (E1 = E1 || (E1 = {}))[E1.a = 0] = "a", E1[E1.b = 1] = "b", foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); +]), foo("hello", 1, 2), foo("hello", "world"), (function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +})(E || (E = {})), (function(E1) { + E1[E1.a = 0] = "a", E1[E1.b = 1] = "b"; +})(E1 || (E1 = {})), foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5iterable_es2015.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5iterable_es2015.2.minified.js index 3212c5df5bd..0d9df2eb8a8 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5iterable_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5iterable_es2015.2.minified.js @@ -1,4 +1,4 @@ -var E, E1, E, E1; +var E, E1; function a10([a, b, [[c]], ...x]) {} function foo(...a) {} function foo1(...a) {} @@ -21,4 +21,8 @@ a10([ ]), a10([ 1, 2 -]), foo("hello", 1, 2), foo("hello", "world"), (E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (E1 = E1 || (E1 = {}))[E1.a = 0] = "a", E1[E1.b = 1] = "b", foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); +]), foo("hello", 1, 2), foo("hello", "world"), (function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +})(E || (E = {})), (function(E1) { + E1[E1.a = 0] = "a", E1[E1.b = 1] = "b"; +})(E1 || (E1 = {})), foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5iterable_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5iterable_es5.2.minified.js index 14a4e5604fc..38fc41d15ac 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5iterable_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES5iterable_es5.2.minified.js @@ -54,7 +54,7 @@ function a10(param) { var _param = _toArray(param), a = _param[0], b = _param[1], ref = _slicedToArray(_param[2], 1), ref1 = _slicedToArray(ref[0], 1); ref1[0], _param.slice(3); } -var E, E1, E, E1, array = [ +var E, E1, array = [ 1, 2, 3 @@ -107,4 +107,8 @@ function foo1() { })([ 1, 2 -]), foo("hello", 1, 2), foo("hello", "world"), (E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (E1 = E1 || (E1 = {}))[E1.a = 0] = "a", E1[E1.b = 1] = "b", foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); +]), foo("hello", 1, 2), foo("hello", "world"), (function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +})(E || (E = {})), (function(E1) { + E1[E1.a = 0] = "a", E1[E1.b = 1] = "b"; +})(E1 || (E1 = {})), foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES6_es2015.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES6_es2015.2.minified.js index 3212c5df5bd..0d9df2eb8a8 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES6_es2015.2.minified.js @@ -1,4 +1,4 @@ -var E, E1, E, E1; +var E, E1; function a10([a, b, [[c]], ...x]) {} function foo(...a) {} function foo1(...a) {} @@ -21,4 +21,8 @@ a10([ ]), a10([ 1, 2 -]), foo("hello", 1, 2), foo("hello", "world"), (E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (E1 = E1 || (E1 = {}))[E1.a = 0] = "a", E1[E1.b = 1] = "b", foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); +]), foo("hello", 1, 2), foo("hello", "world"), (function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +})(E || (E = {})), (function(E1) { + E1[E1.a = 0] = "a", E1[E1.b = 1] = "b"; +})(E1 || (E1 = {})), foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES6_es5.2.minified.js index 14a4e5604fc..38fc41d15ac 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration3ES6_es5.2.minified.js @@ -54,7 +54,7 @@ function a10(param) { var _param = _toArray(param), a = _param[0], b = _param[1], ref = _slicedToArray(_param[2], 1), ref1 = _slicedToArray(ref[0], 1); ref1[0], _param.slice(3); } -var E, E1, E, E1, array = [ +var E, E1, array = [ 1, 2, 3 @@ -107,4 +107,8 @@ function foo1() { })([ 1, 2 -]), foo("hello", 1, 2), foo("hello", "world"), (E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (E1 = E1 || (E1 = {}))[E1.a = 0] = "a", E1[E1.b = 1] = "b", foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); +]), foo("hello", 1, 2), foo("hello", "world"), (function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +})(E || (E = {})), (function(E1) { + E1[E1.a = 0] = "a", E1[E1.b = 1] = "b"; +})(E1 || (E1 = {})), foo1(1, 2, 3, E.a), foo1(1, 2, 3, E1.a, E.b); diff --git a/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES5_es5.2.minified.js index 6ee5868cbbe..f279286ddd1 100644 --- a/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES5_es5.2.minified.js @@ -42,7 +42,7 @@ var tmp = { (void 0 === tmp ? { b11: "string" } : tmp).b11; -var arr, ref = [ +var ref = [ void 0, void 0, void 0 @@ -50,16 +50,18 @@ var arr, ref = [ 1, "string" ].concat(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = [ + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}([ !0, !1, !0 -]) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()), 2); +])), 2); ref1[0], ref1[1]; var _e = _slicedToArray([ 1, diff --git a/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES5iterable_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES5iterable_es5.2.minified.js index 6ee5868cbbe..f279286ddd1 100644 --- a/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES5iterable_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES5iterable_es5.2.minified.js @@ -42,7 +42,7 @@ var tmp = { (void 0 === tmp ? { b11: "string" } : tmp).b11; -var arr, ref = [ +var ref = [ void 0, void 0, void 0 @@ -50,16 +50,18 @@ var arr, ref = [ 1, "string" ].concat(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = [ + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}([ !0, !1, !0 -]) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()), 2); +])), 2); ref1[0], ref1[1]; var _e = _slicedToArray([ 1, diff --git a/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES6_es5.2.minified.js index 6ee5868cbbe..f279286ddd1 100644 --- a/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES6_es5.2.minified.js @@ -42,7 +42,7 @@ var tmp = { (void 0 === tmp ? { b11: "string" } : tmp).b11; -var arr, ref = [ +var ref = [ void 0, void 0, void 0 @@ -50,16 +50,18 @@ var arr, ref = [ 1, "string" ].concat(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = [ + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}([ !0, !1, !0 -]) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()), 2); +])), 2); ref1[0], ref1[1]; var _e = _slicedToArray([ 1, diff --git a/crates/swc/tests/tsc-references/destructuringWithLiteralInitializers_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringWithLiteralInitializers_es5.2.minified.js index 8dd9e2ae113..810a4e29c6c 100644 --- a/crates/swc/tests/tsc-references/destructuringWithLiteralInitializers_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringWithLiteralInitializers_es5.2.minified.js @@ -1,4 +1,3 @@ -var param; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; @@ -36,11 +35,11 @@ function _unsupportedIterableToArray(o, minLen) { if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } } -function f2(param1) { - param1.x, param1.y; +function f2(param) { + param.x, param.y; } -function f3(param2) { - param2.x, param2.y; +function f3(param) { + param.x, param.y; } function f4() { var ref = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : { @@ -82,10 +81,12 @@ function g5() { var ref = _slicedToArray(arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [], 2); ref[0], ref[1]; } -(param = { +(function(param) { + param.x, param.y; +})({ x: 1, y: 1 -}).x, param.y, f2({ +}), f2({ x: 1 }), f2({ x: 1, @@ -127,14 +128,14 @@ function g5() { x: 1, y: 1 } -}), (function(param3) { - var _param = _slicedToArray(param3, 2); +}), (function(param) { + var _param = _slicedToArray(param, 2); _param[0], _param[1]; })([ 1, 1 -]), (function(param4) { - var _param = _slicedToArray(param4, 2); +]), (function(param) { + var _param = _slicedToArray(param, 2); _param[0], _param[1]; })([ 1, diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5_es5.2.minified.js index b0419bf2a55..481aebd573d 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5_es5.2.minified.js @@ -1,35 +1,37 @@ -var arr, i, a; +var a; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } -i = 0, (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = a) || (function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ +!function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; try { - _n || null == _i.return || _i.return(); + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; } finally{ - if (_d) throw _e; + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } } + return _arr; } - return _arr; - } -})(arr, i) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})(); + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(a, 0); diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable_es5.2.minified.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable_es5.2.minified.js index e73ccd5a032..481aebd573d 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable_es5.2.minified.js @@ -1,35 +1,37 @@ -var a, arr, i; +var a; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } -i = 0, (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = a) || (function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ +!function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; try { - _n || null == _i.return || _i.return(); + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; } finally{ - if (_d) throw _e; + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } } + return _arr; } - return _arr; - } -})(arr, i) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})(); + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(a, 0); diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES6_es5.2.minified.js index e73ccd5a032..481aebd573d 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES6_es5.2.minified.js @@ -1,35 +1,37 @@ -var a, arr, i; +var a; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } -i = 0, (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = a) || (function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ +!function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; try { - _n || null == _i.return || _i.return(); + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; } finally{ - if (_d) throw _e; + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } } + return _arr; } - return _arr; - } -})(arr, i) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})(); + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(a, 0); diff --git a/crates/swc/tests/tsc-references/enumAssignabilityInInheritance_es2015.2.minified.js b/crates/swc/tests/tsc-references/enumAssignabilityInInheritance_es2015.2.minified.js index cfdb0f1e52e..9477d9451ec 100644 --- a/crates/swc/tests/tsc-references/enumAssignabilityInInheritance_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/enumAssignabilityInInheritance_es2015.2.minified.js @@ -1,6 +1,10 @@ -var E, E, E2, E2; +var E, E2; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", foo(E.A), foo(1), foo(null), foo2(E.A), foo3(E.A), foo4(E.A), foo5(E.A), foo6(E.A), foo7(E.A), foo8(E.A), foo9(E.A), foo10(E.A), foo11(E.A), foo12(E.A), (E2 = E2 || (E2 = {}))[E2.A = 0] = "A", foo13(E.A), (f || (f = {})).bar = 1, foo14(E.A); +(function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), foo(E.A), foo(1), foo(null), foo2(E.A), foo3(E.A), foo4(E.A), foo5(E.A), foo6(E.A), foo7(E.A), foo8(E.A), foo9(E.A), foo10(E.A), foo11(E.A), foo12(E.A), (function(E2) { + E2[E2.A = 0] = "A"; +})(E2 || (E2 = {})), foo13(E.A), (f || (f = {})).bar = 1, foo14(E.A); class CC { } (CC || (CC = {})).bar = 1, foo15(E.A), foo16(E.A), foo16(E.A); diff --git a/crates/swc/tests/tsc-references/enumAssignabilityInInheritance_es5.2.minified.js b/crates/swc/tests/tsc-references/enumAssignabilityInInheritance_es5.2.minified.js index 75895e08662..921e5ddffc6 100644 --- a/crates/swc/tests/tsc-references/enumAssignabilityInInheritance_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/enumAssignabilityInInheritance_es5.2.minified.js @@ -1,7 +1,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -(E = E || (E = {}))[E.A = 0] = "A", foo(E.A), foo(1), foo(null), foo2(E.A), foo3(E.A), foo4(E.A), foo5(E.A), foo6(E.A), foo7(E.A), foo8(E.A); +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), foo(E.A), foo(1), foo(null), foo2(E.A), foo3(E.A), foo4(E.A), foo5(E.A), foo6(E.A), foo7(E.A), foo8(E.A); var A = function() { "use strict"; _classCallCheck(this, A); @@ -12,8 +14,10 @@ var A2 = function() { _classCallCheck(this, A2); }; function f() {} -foo10(E.A), foo11(E.A), foo12(E.A), (E2 = E2 || (E2 = {}))[E2.A = 0] = "A", foo13(E.A), (f || (f = {})).bar = 1, foo14(E.A); -var E, E, E2, E2, CC = function() { +foo10(E.A), foo11(E.A), foo12(E.A), (function(E2) { + E2[E2.A = 0] = "A"; +})(E2 || (E2 = {})), foo13(E.A), (f || (f = {})).bar = 1, foo14(E.A); +var E, E2, CC = function() { "use strict"; _classCallCheck(this, CC); }; diff --git a/crates/swc/tests/tsc-references/enumAssignability_es2015.2.minified.js b/crates/swc/tests/tsc-references/enumAssignability_es2015.2.minified.js index f75d63e5acb..f0f85126676 100644 --- a/crates/swc/tests/tsc-references/enumAssignability_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/enumAssignability_es2015.2.minified.js @@ -1,3 +1,7 @@ -(E = E || (E = {}))[E.A = 0] = "A", (F = F || (F = {}))[F.B = 0] = "B"; -var E, F, E, F, e = E.A, f = F.B; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (function(F) { + F[F.B = 0] = "B"; +})(F || (F = {})); +var E, F, e = E.A, f = F.B; f = f, f = 1; diff --git a/crates/swc/tests/tsc-references/enumAssignability_es5.2.minified.js b/crates/swc/tests/tsc-references/enumAssignability_es5.2.minified.js index 63472c8a92a..89907abfbbb 100644 --- a/crates/swc/tests/tsc-references/enumAssignability_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/enumAssignability_es5.2.minified.js @@ -1,5 +1,9 @@ -(E = E || (E = {}))[E.A = 0] = "A", (F = F || (F = {}))[F.B = 0] = "B"; -var E, F, E, F, Others, e = E.A, f = F.B; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (function(F) { + F[F.B = 0] = "B"; +})(F || (F = {})); +var E, F, Others, e = E.A, f = F.B; f = f, f = 1, (function(Others) { var C = function() { "use strict"; diff --git a/crates/swc/tests/tsc-references/enumIsNotASubtypeOfAnythingButNumber_es2015.2.minified.js b/crates/swc/tests/tsc-references/enumIsNotASubtypeOfAnythingButNumber_es2015.2.minified.js index 5a9adcdfe32..6d9b6a48db1 100644 --- a/crates/swc/tests/tsc-references/enumIsNotASubtypeOfAnythingButNumber_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/enumIsNotASubtypeOfAnythingButNumber_es2015.2.minified.js @@ -1,6 +1,10 @@ -var E, E2, E, E2; +var E, E2; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", (E2 = E2 || (E2 = {}))[E2.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (function(E2) { + E2[E2.A = 0] = "A"; +})(E2 || (E2 = {})), (f || (f = {})).bar = 1; class c { } (c || (c = {})).bar = 1; diff --git a/crates/swc/tests/tsc-references/enumIsNotASubtypeOfAnythingButNumber_es5.2.minified.js b/crates/swc/tests/tsc-references/enumIsNotASubtypeOfAnythingButNumber_es5.2.minified.js index e23b4ca10d6..ab7f15362ae 100644 --- a/crates/swc/tests/tsc-references/enumIsNotASubtypeOfAnythingButNumber_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/enumIsNotASubtypeOfAnythingButNumber_es5.2.minified.js @@ -1,8 +1,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -(E = E || (E = {}))[E.A = 0] = "A"; -var E, E, E2, E2, A = function() { +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); +var E, E2, A = function() { "use strict"; _classCallCheck(this, A); }, A2 = function() { @@ -10,7 +12,9 @@ var E, E, E2, E2, A = function() { _classCallCheck(this, A2); }; function f() {} -(E2 = E2 || (E2 = {}))[E2.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E2) { + E2[E2.A = 0] = "A"; +}(E2 || (E2 = {})), (f || (f = {})).bar = 1; var c = function() { "use strict"; _classCallCheck(this, c); diff --git a/crates/swc/tests/tsc-references/enumLiteralTypes1_es2015.2.minified.js b/crates/swc/tests/tsc-references/enumLiteralTypes1_es2015.2.minified.js index cde9d49f11a..681a63811ad 100644 --- a/crates/swc/tests/tsc-references/enumLiteralTypes1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/enumLiteralTypes1_es2015.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {}))[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +var Choice; +!function(Choice) { + Choice[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/enumLiteralTypes1_es5.2.minified.js b/crates/swc/tests/tsc-references/enumLiteralTypes1_es5.2.minified.js index cde9d49f11a..681a63811ad 100644 --- a/crates/swc/tests/tsc-references/enumLiteralTypes1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/enumLiteralTypes1_es5.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {}))[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +var Choice; +!function(Choice) { + Choice[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/enumLiteralTypes2_es2015.2.minified.js b/crates/swc/tests/tsc-references/enumLiteralTypes2_es2015.2.minified.js index cde9d49f11a..681a63811ad 100644 --- a/crates/swc/tests/tsc-references/enumLiteralTypes2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/enumLiteralTypes2_es2015.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {}))[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +var Choice; +!function(Choice) { + Choice[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/enumLiteralTypes2_es5.2.minified.js b/crates/swc/tests/tsc-references/enumLiteralTypes2_es5.2.minified.js index cde9d49f11a..681a63811ad 100644 --- a/crates/swc/tests/tsc-references/enumLiteralTypes2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/enumLiteralTypes2_es5.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {}))[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +var Choice; +!function(Choice) { + Choice[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/enumLiteralTypes3_es2015.2.minified.js b/crates/swc/tests/tsc-references/enumLiteralTypes3_es2015.2.minified.js index cde9d49f11a..681a63811ad 100644 --- a/crates/swc/tests/tsc-references/enumLiteralTypes3_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/enumLiteralTypes3_es2015.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {}))[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +var Choice; +!function(Choice) { + Choice[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/enumLiteralTypes3_es5.2.minified.js b/crates/swc/tests/tsc-references/enumLiteralTypes3_es5.2.minified.js index cde9d49f11a..681a63811ad 100644 --- a/crates/swc/tests/tsc-references/enumLiteralTypes3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/enumLiteralTypes3_es5.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {}))[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +var Choice; +!function(Choice) { + Choice[Choice.Unknown = 0] = "Unknown", Choice[Choice.Yes = 1] = "Yes", Choice[Choice.No = 2] = "No"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/es6modulekindWithES5Target12_es2015.2.minified.js b/crates/swc/tests/tsc-references/es6modulekindWithES5Target12_es2015.2.minified.js index d8d42434a55..219290a3d49 100644 --- a/crates/swc/tests/tsc-references/es6modulekindWithES5Target12_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/es6modulekindWithES5Target12_es2015.2.minified.js @@ -1,6 +1,10 @@ -var E, E, E; +var E; export class C { } -(C || (C = {})).x = 1, (E = E || (E = {}))[E.w = 1] = "w", (E = E || (E = {}))[E.x = 2] = "x", (E || (E = {})).y = 1, (E || (E = {})).z = 1, (N || (N = {})).x = 1; +(C || (C = {})).x = 1, (function(E) { + E[E.w = 1] = "w"; +})(E || (E = {})), (function(E) { + E[E.x = 2] = "x"; +})(E || (E = {})), (E || (E = {})).y = 1, (E || (E = {})).z = 1, (N || (N = {})).x = 1; export function F() {} (F || (F = {})).x = 1; diff --git a/crates/swc/tests/tsc-references/es6modulekindWithES5Target12_es5.2.minified.js b/crates/swc/tests/tsc-references/es6modulekindWithES5Target12_es5.2.minified.js index 097d5579278..a70286a2fe9 100644 --- a/crates/swc/tests/tsc-references/es6modulekindWithES5Target12_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/es6modulekindWithES5Target12_es5.2.minified.js @@ -1,9 +1,13 @@ -export var E, E, E, C = function() { +export var E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -(C || (C = {})).x = 1, E = E || (E = {}), E[E.w = 1] = "w", E = E || (E = {}), E[E.x = 2] = "x", (E || (E = {})).y = 1, (E || (E = {})).z = 1, (N || (N = {})).x = 1; +(C || (C = {})).x = 1, (function(E) { + E[E.w = 1] = "w"; +})(E || (E = {})), (function(E) { + E[E.x = 2] = "x"; +})(E || (E = {})), (E || (E = {})).y = 1, (E || (E = {})).z = 1, (N || (N = {})).x = 1; export function F() {} (F || (F = {})).x = 1; diff --git a/crates/swc/tests/tsc-references/es6modulekindWithES5Target5_es2015.2.minified.js b/crates/swc/tests/tsc-references/es6modulekindWithES5Target5_es2015.2.minified.js index 3fad8a36aa1..4a8d66023c2 100644 --- a/crates/swc/tests/tsc-references/es6modulekindWithES5Target5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/es6modulekindWithES5Target5_es2015.2.minified.js @@ -1,2 +1,6 @@ -var E1, E2, E1, E2; -(E1 = E1 || (E1 = {}))[E1.value1 = 0] = "value1", (E2 = E2 || (E2 = {}))[E2.value1 = 0] = "value1"; +var E1, E2; +!function(E1) { + E1[E1.value1 = 0] = "value1"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.value1 = 0] = "value1"; +})(E2 || (E2 = {})); diff --git a/crates/swc/tests/tsc-references/es6modulekindWithES5Target5_es5.2.minified.js b/crates/swc/tests/tsc-references/es6modulekindWithES5Target5_es5.2.minified.js index 3fad8a36aa1..4a8d66023c2 100644 --- a/crates/swc/tests/tsc-references/es6modulekindWithES5Target5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/es6modulekindWithES5Target5_es5.2.minified.js @@ -1,2 +1,6 @@ -var E1, E2, E1, E2; -(E1 = E1 || (E1 = {}))[E1.value1 = 0] = "value1", (E2 = E2 || (E2 = {}))[E2.value1 = 0] = "value1"; +var E1, E2; +!function(E1) { + E1[E1.value1 = 0] = "value1"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.value1 = 0] = "value1"; +})(E2 || (E2 = {})); diff --git a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target12_es2015.2.minified.js b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target12_es2015.2.minified.js index d8d42434a55..219290a3d49 100644 --- a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target12_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target12_es2015.2.minified.js @@ -1,6 +1,10 @@ -var E, E, E; +var E; export class C { } -(C || (C = {})).x = 1, (E = E || (E = {}))[E.w = 1] = "w", (E = E || (E = {}))[E.x = 2] = "x", (E || (E = {})).y = 1, (E || (E = {})).z = 1, (N || (N = {})).x = 1; +(C || (C = {})).x = 1, (function(E) { + E[E.w = 1] = "w"; +})(E || (E = {})), (function(E) { + E[E.x = 2] = "x"; +})(E || (E = {})), (E || (E = {})).y = 1, (E || (E = {})).z = 1, (N || (N = {})).x = 1; export function F() {} (F || (F = {})).x = 1; diff --git a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target12_es5.2.minified.js b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target12_es5.2.minified.js index 097d5579278..a70286a2fe9 100644 --- a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target12_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target12_es5.2.minified.js @@ -1,9 +1,13 @@ -export var E, E, E, C = function() { +export var E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -(C || (C = {})).x = 1, E = E || (E = {}), E[E.w = 1] = "w", E = E || (E = {}), E[E.x = 2] = "x", (E || (E = {})).y = 1, (E || (E = {})).z = 1, (N || (N = {})).x = 1; +(C || (C = {})).x = 1, (function(E) { + E[E.w = 1] = "w"; +})(E || (E = {})), (function(E) { + E[E.x = 2] = "x"; +})(E || (E = {})), (E || (E = {})).y = 1, (E || (E = {})).z = 1, (N || (N = {})).x = 1; export function F() {} (F || (F = {})).x = 1; diff --git a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target5_es2015.2.minified.js b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target5_es2015.2.minified.js index 3fad8a36aa1..4a8d66023c2 100644 --- a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target5_es2015.2.minified.js @@ -1,2 +1,6 @@ -var E1, E2, E1, E2; -(E1 = E1 || (E1 = {}))[E1.value1 = 0] = "value1", (E2 = E2 || (E2 = {}))[E2.value1 = 0] = "value1"; +var E1, E2; +!function(E1) { + E1[E1.value1 = 0] = "value1"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.value1 = 0] = "value1"; +})(E2 || (E2 = {})); diff --git a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target5_es5.2.minified.js b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target5_es5.2.minified.js index 3fad8a36aa1..4a8d66023c2 100644 --- a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target5_es5.2.minified.js @@ -1,2 +1,6 @@ -var E1, E2, E1, E2; -(E1 = E1 || (E1 = {}))[E1.value1 = 0] = "value1", (E2 = E2 || (E2 = {}))[E2.value1 = 0] = "value1"; +var E1, E2; +!function(E1) { + E1[E1.value1 = 0] = "value1"; +}(E1 || (E1 = {})), (function(E2) { + E2[E2.value1 = 0] = "value1"; +})(E2 || (E2 = {})); diff --git a/crates/swc/tests/tsc-references/everyTypeAssignableToAny_es2015.2.minified.js b/crates/swc/tests/tsc-references/everyTypeAssignableToAny_es2015.2.minified.js index 5f410993c04..4f81f678e53 100644 --- a/crates/swc/tests/tsc-references/everyTypeAssignableToAny_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/everyTypeAssignableToAny_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A"; +var E; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/everyTypeAssignableToAny_es5.2.minified.js b/crates/swc/tests/tsc-references/everyTypeAssignableToAny_es5.2.minified.js index f70e6cc54e8..9eba7da8a34 100644 --- a/crates/swc/tests/tsc-references/everyTypeAssignableToAny_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/everyTypeAssignableToAny_es5.2.minified.js @@ -1,7 +1,9 @@ -var E, E, C = function() { +var E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -(E = E || (E = {}))[E.A = 0] = "A"; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInitializer_es2015.2.minified.js b/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInitializer_es2015.2.minified.js index db03a154f8d..39bb9d32f24 100644 --- a/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInitializer_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInitializer_es2015.2.minified.js @@ -1,9 +1,11 @@ -var M, M1; +var M; class C { } -(M = M1 || (M1 = {})).A = class { -}, M.F2 = function(x) { - return x.toString(); -}, new Date(12), new Object(), new C(), new C(), new class { -}(), new C(), new M1.A(), (x)=>"this is a string" +(function(M1) { + M1.A = class { + }, M1.F2 = function(x) { + return x.toString(); + }; +})(M || (M = {})), new Date(12), new Object(), new C(), new C(), new class { +}(), new C(), new M.A(), (x)=>"this is a string" ; diff --git a/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInvalidInitializer_es2015.2.minified.js b/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInvalidInitializer_es2015.2.minified.js index 56b4282993e..7c524b7ee72 100644 --- a/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInvalidInitializer_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInvalidInitializer_es2015.2.minified.js @@ -1,12 +1,16 @@ -var M, N, M1, N1; +var M, N; class C { } class D { } -(M = M1 || (M1 = {})).A = class { -}, M.F2 = function(x) { - return x.toString(); -}, (N = N1 || (N1 = {})).A = class { -}, N.F2 = function(x) { - return x.toString(); -}, new D(), new D(), new C(), new C(), new N1.A(); +(function(M1) { + M1.A = class { + }, M1.F2 = function(x) { + return x.toString(); + }; +})(M || (M = {})), (function(N1) { + N1.A = class { + }, N1.F2 = function(x) { + return x.toString(); + }; +})(N || (N = {})), new D(), new D(), new C(), new C(), new N.A(); diff --git a/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInvalidInitializer_es5.2.minified.js b/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInvalidInitializer_es5.2.minified.js index a9c8ce944c3..9cea8073764 100644 --- a/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInvalidInitializer_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/everyTypeWithAnnotationAndInvalidInitializer_es5.2.minified.js @@ -8,7 +8,7 @@ var M, N, C = function() { "use strict"; _classCallCheck(this, D); }; -(function(M1) { +!function(M1) { var A = function() { "use strict"; _classCallCheck(this, A); @@ -16,7 +16,7 @@ var M, N, C = function() { M1.A = A, M1.F2 = function(x) { return x.toString(); }; -})(M || (M = {})), (function(N1) { +}(M || (M = {})), (function(N1) { var A = function() { "use strict"; _classCallCheck(this, A); diff --git a/crates/swc/tests/tsc-references/everyTypeWithInitializer_es2015.2.minified.js b/crates/swc/tests/tsc-references/everyTypeWithInitializer_es2015.2.minified.js index f7c2f0c6b72..aa0e85b6830 100644 --- a/crates/swc/tests/tsc-references/everyTypeWithInitializer_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/everyTypeWithInitializer_es2015.2.minified.js @@ -1,8 +1,10 @@ -var M, M1; +var M; class C { } -(M = M1 || (M1 = {})).A = class { -}, M.F2 = function(x) { - return x.toString(); -}, new Date(12), new Object(), new C(), new C(), new class { -}(), new M1.A(), M1.F2; +(function(M1) { + M1.A = class { + }, M1.F2 = function(x) { + return x.toString(); + }; +})(M || (M = {})), new Date(12), new Object(), new C(), new C(), new class { +}(), new M.A(), M.F2; diff --git a/crates/swc/tests/tsc-references/exponentiationOperatorWithEnumUnion_es2015.2.minified.js b/crates/swc/tests/tsc-references/exponentiationOperatorWithEnumUnion_es2015.2.minified.js index 44f5992b4f8..044cba8c15c 100644 --- a/crates/swc/tests/tsc-references/exponentiationOperatorWithEnumUnion_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exponentiationOperatorWithEnumUnion_es2015.2.minified.js @@ -1,2 +1,6 @@ -var E, F, E, F, a, b, c; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (F = F || (F = {}))[F.c = 0] = "c", F[F.d = 1] = "d", Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(a, c), Math.pow(b, c), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, E.b), Math.pow(E.a, 1), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(1, E.b); +var E, F, a, b, c; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), (function(F) { + F[F.c = 0] = "c", F[F.d = 1] = "d"; +})(F || (F = {})), Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(a, c), Math.pow(b, c), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, E.b), Math.pow(E.a, 1), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(1, E.b); diff --git a/crates/swc/tests/tsc-references/exponentiationOperatorWithEnumUnion_es5.2.minified.js b/crates/swc/tests/tsc-references/exponentiationOperatorWithEnumUnion_es5.2.minified.js index 44f5992b4f8..044cba8c15c 100644 --- a/crates/swc/tests/tsc-references/exponentiationOperatorWithEnumUnion_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exponentiationOperatorWithEnumUnion_es5.2.minified.js @@ -1,2 +1,6 @@ -var E, F, E, F, a, b, c; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", (F = F || (F = {}))[F.c = 0] = "c", F[F.d = 1] = "d", Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(a, c), Math.pow(b, c), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, E.b), Math.pow(E.a, 1), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(1, E.b); +var E, F, a, b, c; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), (function(F) { + F[F.c = 0] = "c", F[F.d = 1] = "d"; +})(F || (F = {})), Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(a, c), Math.pow(b, c), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, E.b), Math.pow(E.a, 1), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(1, E.b); diff --git a/crates/swc/tests/tsc-references/exponentiationOperatorWithEnum_es2015.2.minified.js b/crates/swc/tests/tsc-references/exponentiationOperatorWithEnum_es2015.2.minified.js index 64c1d8c8bae..8f73188a2fe 100644 --- a/crates/swc/tests/tsc-references/exponentiationOperatorWithEnum_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exponentiationOperatorWithEnum_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E, a, b, c; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(a, c), Math.pow(b, c), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, E.b), Math.pow(E.a, 1), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(1, E.b); +var E, a, b, c; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(a, c), Math.pow(b, c), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, E.b), Math.pow(E.a, 1), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(1, E.b); diff --git a/crates/swc/tests/tsc-references/exponentiationOperatorWithEnum_es5.2.minified.js b/crates/swc/tests/tsc-references/exponentiationOperatorWithEnum_es5.2.minified.js index 64c1d8c8bae..8f73188a2fe 100644 --- a/crates/swc/tests/tsc-references/exponentiationOperatorWithEnum_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exponentiationOperatorWithEnum_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E, a, b, c; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(a, c), Math.pow(b, c), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, E.b), Math.pow(E.a, 1), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(1, E.b); +var E, a, b, c; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +}(E || (E = {})), Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(a, c), Math.pow(b, c), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, E.b), Math.pow(E.a, 1), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(1, E.b); diff --git a/crates/swc/tests/tsc-references/exponentiationOperatorWithInvalidOperands_es2015.2.minified.js b/crates/swc/tests/tsc-references/exponentiationOperatorWithInvalidOperands_es2015.2.minified.js index 9c841ca32d3..8b7382d73cd 100644 --- a/crates/swc/tests/tsc-references/exponentiationOperatorWithInvalidOperands_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exponentiationOperatorWithInvalidOperands_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E, a, b, c, d, e, f; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", Math.pow(a, a), Math.pow(a, b), Math.pow(a, c), Math.pow(a, d), Math.pow(a, e), Math.pow(a, f), Math.pow(b, a), Math.pow(b, b), Math.pow(b, c), Math.pow(b, d), Math.pow(b, e), Math.pow(b, f), Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(c, d), Math.pow(c, e), Math.pow(c, f), Math.pow(d, a), Math.pow(d, b), Math.pow(d, c), Math.pow(d, d), Math.pow(d, e), Math.pow(d, f), Math.pow(e, a), Math.pow(e, b), Math.pow(e, c), Math.pow(e, d), Math.pow(e, e), Math.pow(e, f), Math.pow(f, a), Math.pow(f, b), Math.pow(f, c), Math.pow(f, d), Math.pow(f, e), Math.pow(f, f), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, c), Math.pow(E.a, d), Math.pow(E.a, e), Math.pow(E.a, f), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(c, E.b), Math.pow(d, E.b), Math.pow(e, E.b), Math.pow(f, E.b); +var E, a, b, c, d, e, f; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), Math.pow(a, a), Math.pow(a, b), Math.pow(a, c), Math.pow(a, d), Math.pow(a, e), Math.pow(a, f), Math.pow(b, a), Math.pow(b, b), Math.pow(b, c), Math.pow(b, d), Math.pow(b, e), Math.pow(b, f), Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(c, d), Math.pow(c, e), Math.pow(c, f), Math.pow(d, a), Math.pow(d, b), Math.pow(d, c), Math.pow(d, d), Math.pow(d, e), Math.pow(d, f), Math.pow(e, a), Math.pow(e, b), Math.pow(e, c), Math.pow(e, d), Math.pow(e, e), Math.pow(e, f), Math.pow(f, a), Math.pow(f, b), Math.pow(f, c), Math.pow(f, d), Math.pow(f, e), Math.pow(f, f), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, c), Math.pow(E.a, d), Math.pow(E.a, e), Math.pow(E.a, f), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(c, E.b), Math.pow(d, E.b), Math.pow(e, E.b), Math.pow(f, E.b); diff --git a/crates/swc/tests/tsc-references/exponentiationOperatorWithInvalidOperands_es5.2.minified.js b/crates/swc/tests/tsc-references/exponentiationOperatorWithInvalidOperands_es5.2.minified.js index 9c841ca32d3..8b7382d73cd 100644 --- a/crates/swc/tests/tsc-references/exponentiationOperatorWithInvalidOperands_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exponentiationOperatorWithInvalidOperands_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E, a, b, c, d, e, f; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c", Math.pow(a, a), Math.pow(a, b), Math.pow(a, c), Math.pow(a, d), Math.pow(a, e), Math.pow(a, f), Math.pow(b, a), Math.pow(b, b), Math.pow(b, c), Math.pow(b, d), Math.pow(b, e), Math.pow(b, f), Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(c, d), Math.pow(c, e), Math.pow(c, f), Math.pow(d, a), Math.pow(d, b), Math.pow(d, c), Math.pow(d, d), Math.pow(d, e), Math.pow(d, f), Math.pow(e, a), Math.pow(e, b), Math.pow(e, c), Math.pow(e, d), Math.pow(e, e), Math.pow(e, f), Math.pow(f, a), Math.pow(f, b), Math.pow(f, c), Math.pow(f, d), Math.pow(f, e), Math.pow(f, f), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, c), Math.pow(E.a, d), Math.pow(E.a, e), Math.pow(E.a, f), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(c, E.b), Math.pow(d, E.b), Math.pow(e, E.b), Math.pow(f, E.b); +var E, a, b, c, d, e, f; +!function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b", E[E.c = 2] = "c"; +}(E || (E = {})), Math.pow(a, a), Math.pow(a, b), Math.pow(a, c), Math.pow(a, d), Math.pow(a, e), Math.pow(a, f), Math.pow(b, a), Math.pow(b, b), Math.pow(b, c), Math.pow(b, d), Math.pow(b, e), Math.pow(b, f), Math.pow(c, a), Math.pow(c, b), Math.pow(c, c), Math.pow(c, d), Math.pow(c, e), Math.pow(c, f), Math.pow(d, a), Math.pow(d, b), Math.pow(d, c), Math.pow(d, d), Math.pow(d, e), Math.pow(d, f), Math.pow(e, a), Math.pow(e, b), Math.pow(e, c), Math.pow(e, d), Math.pow(e, e), Math.pow(e, f), Math.pow(f, a), Math.pow(f, b), Math.pow(f, c), Math.pow(f, d), Math.pow(f, e), Math.pow(f, f), Math.pow(E.a, a), Math.pow(E.a, b), Math.pow(E.a, c), Math.pow(E.a, d), Math.pow(E.a, e), Math.pow(E.a, f), Math.pow(a, E.b), Math.pow(b, E.b), Math.pow(c, E.b), Math.pow(d, E.b), Math.pow(e, E.b), Math.pow(f, E.b); diff --git a/crates/swc/tests/tsc-references/exponentiationOperatorWithNullValueAndValidOperands_es2015.2.minified.js b/crates/swc/tests/tsc-references/exponentiationOperatorWithNullValueAndValidOperands_es2015.2.minified.js index 21877f7f9f1..d0a3e57c065 100644 --- a/crates/swc/tests/tsc-references/exponentiationOperatorWithNullValueAndValidOperands_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exponentiationOperatorWithNullValueAndValidOperands_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E, a, b; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", Math.pow(null, a), Math.pow(null, b), Math.pow(null, E.a), Math.pow(a, null), Math.pow(b, null), Math.pow(E.b, null); +var E, a, b; +(function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +})(E || (E = {})), Math.pow(null, a), Math.pow(null, b), Math.pow(null, E.a), Math.pow(a, null), Math.pow(b, null), Math.pow(E.b, null); diff --git a/crates/swc/tests/tsc-references/exponentiationOperatorWithNullValueAndValidOperands_es5.2.minified.js b/crates/swc/tests/tsc-references/exponentiationOperatorWithNullValueAndValidOperands_es5.2.minified.js index 21877f7f9f1..d0a3e57c065 100644 --- a/crates/swc/tests/tsc-references/exponentiationOperatorWithNullValueAndValidOperands_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exponentiationOperatorWithNullValueAndValidOperands_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E, a, b; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", Math.pow(null, a), Math.pow(null, b), Math.pow(null, E.a), Math.pow(a, null), Math.pow(b, null), Math.pow(E.b, null); +var E, a, b; +(function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +})(E || (E = {})), Math.pow(null, a), Math.pow(null, b), Math.pow(null, E.a), Math.pow(a, null), Math.pow(b, null), Math.pow(E.b, null); diff --git a/crates/swc/tests/tsc-references/exponentiationOperatorWithUndefinedValueAndValidOperands_es2015.2.minified.js b/crates/swc/tests/tsc-references/exponentiationOperatorWithUndefinedValueAndValidOperands_es2015.2.minified.js index df4a8465eff..f040523b656 100644 --- a/crates/swc/tests/tsc-references/exponentiationOperatorWithUndefinedValueAndValidOperands_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exponentiationOperatorWithUndefinedValueAndValidOperands_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E, a, b; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", Math.pow(void 0, a), Math.pow(void 0, b), Math.pow(void 0, E.a), Math.pow(a, void 0), Math.pow(b, void 0), Math.pow(E.b, void 0); +var E, a, b; +(function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +})(E || (E = {})), Math.pow(void 0, a), Math.pow(void 0, b), Math.pow(void 0, E.a), Math.pow(a, void 0), Math.pow(b, void 0), Math.pow(E.b, void 0); diff --git a/crates/swc/tests/tsc-references/exponentiationOperatorWithUndefinedValueAndValidOperands_es5.2.minified.js b/crates/swc/tests/tsc-references/exponentiationOperatorWithUndefinedValueAndValidOperands_es5.2.minified.js index df4a8465eff..f040523b656 100644 --- a/crates/swc/tests/tsc-references/exponentiationOperatorWithUndefinedValueAndValidOperands_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exponentiationOperatorWithUndefinedValueAndValidOperands_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E, a, b; -(E = E || (E = {}))[E.a = 0] = "a", E[E.b = 1] = "b", Math.pow(void 0, a), Math.pow(void 0, b), Math.pow(void 0, E.a), Math.pow(a, void 0), Math.pow(b, void 0), Math.pow(E.b, void 0); +var E, a, b; +(function(E) { + E[E.a = 0] = "a", E[E.b = 1] = "b"; +})(E || (E = {})), Math.pow(void 0, a), Math.pow(void 0, b), Math.pow(void 0, E.a), Math.pow(a, void 0), Math.pow(b, void 0), Math.pow(E.b, void 0); diff --git a/crates/swc/tests/tsc-references/exportAssignmentAndDeclaration_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportAssignmentAndDeclaration_es2015.2.minified.js index 8269cecf5d6..51729da2453 100644 --- a/crates/swc/tests/tsc-references/exportAssignmentAndDeclaration_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportAssignmentAndDeclaration_es2015.2.minified.js @@ -1,3 +1,5 @@ -var E1, E1; -(E1 = E1 || (E1 = {}))[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C", module.exports = class { +export var E1; +!function(E1) { + E1[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C"; +}(E1 || (E1 = {})), module.exports = class { }; diff --git a/crates/swc/tests/tsc-references/exportAssignmentAndDeclaration_es5.2.minified.js b/crates/swc/tests/tsc-references/exportAssignmentAndDeclaration_es5.2.minified.js index 010e7361443..d1feac47001 100644 --- a/crates/swc/tests/tsc-references/exportAssignmentAndDeclaration_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exportAssignmentAndDeclaration_es5.2.minified.js @@ -1,5 +1,8 @@ -(E1 = E1 || (E1 = {}))[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C"; -var E1, E1, C1 = function() { +export var E1; +!function(E1) { + E1[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C"; +}(E1 || (E1 = {})); +var C1 = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); diff --git a/crates/swc/tests/tsc-references/exportAssignmentMergedModule_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportAssignmentMergedModule_es2015.2.minified.js index f153884e2d3..2b7f098ee00 100644 --- a/crates/swc/tests/tsc-references/exportAssignmentMergedModule_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportAssignmentMergedModule_es2015.2.minified.js @@ -1,9 +1,13 @@ -var Foo, Foo1, Foo2; -(Foo1 = Foo || (Foo = {})).a = function() { - return 5; -}, Foo1.b = !0, (Foo2 = Foo || (Foo = {})).c = function(a) { - return a; -}, (Foo2.Test || (Foo2.Test = {})).answer = 42, module.exports = Foo; +var Foo; +!function(Foo1) { + Foo1.a = function() { + return 5; + }, Foo1.b = !0; +}(Foo || (Foo = {})), (function(Foo2) { + Foo2.c = function(a) { + return a; + }, (Foo2.Test || (Foo2.Test = {})).answer = 42; +})(Foo || (Foo = {})), module.exports = Foo; const foo = require("./foo_0"); foo.a(), foo.b && (foo.Test.answer = foo.c(42)); export { }; diff --git a/crates/swc/tests/tsc-references/exportAssignmentMergedModule_es5.2.minified.js b/crates/swc/tests/tsc-references/exportAssignmentMergedModule_es5.2.minified.js index b9a3fef8cad..aa3778721e9 100644 --- a/crates/swc/tests/tsc-references/exportAssignmentMergedModule_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exportAssignmentMergedModule_es5.2.minified.js @@ -1,9 +1,13 @@ -var Foo, Foo1, Foo2; -(Foo1 = Foo || (Foo = {})).a = function() { - return 5; -}, Foo1.b = !0, (Foo2 = Foo || (Foo = {})).c = function(a) { - return a; -}, (Foo2.Test || (Foo2.Test = {})).answer = 42, module.exports = Foo; +var Foo; +!function(Foo1) { + Foo1.a = function() { + return 5; + }, Foo1.b = !0; +}(Foo || (Foo = {})), (function(Foo2) { + Foo2.c = function(a) { + return a; + }, (Foo2.Test || (Foo2.Test = {})).answer = 42; +})(Foo || (Foo = {})), module.exports = Foo; var foo = require("./foo_0"); foo.a(), foo.b && (foo.Test.answer = foo.c(42)); export { }; diff --git a/crates/swc/tests/tsc-references/exportAssignmentTopLevelEnumdule_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportAssignmentTopLevelEnumdule_es2015.2.minified.js index ddf649a2f52..94a53aab545 100644 --- a/crates/swc/tests/tsc-references/exportAssignmentTopLevelEnumdule_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportAssignmentTopLevelEnumdule_es2015.2.minified.js @@ -1,5 +1,7 @@ -var foo, color, foo; -(foo = foo || (foo = {}))[foo.red = 0] = "red", foo[foo.green = 1] = "green", foo[foo.blue = 2] = "blue", (foo || (foo = {})).answer = 42, module.exports = foo; +var foo, color; +!function(foo) { + foo[foo.red = 0] = "red", foo[foo.green = 1] = "green", foo[foo.blue = 2] = "blue"; +}(foo || (foo = {})), (foo || (foo = {})).answer = 42, module.exports = foo; const foo = require("./foo_0"); color === foo.green && (color = foo.answer); export { }; diff --git a/crates/swc/tests/tsc-references/exportAssignmentTopLevelEnumdule_es5.2.minified.js b/crates/swc/tests/tsc-references/exportAssignmentTopLevelEnumdule_es5.2.minified.js index 0ed3e1c320f..7e0ed445632 100644 --- a/crates/swc/tests/tsc-references/exportAssignmentTopLevelEnumdule_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exportAssignmentTopLevelEnumdule_es5.2.minified.js @@ -1,4 +1,6 @@ -(foo = foo || (foo = {}))[foo.red = 0] = "red", foo[foo.green = 1] = "green", foo[foo.blue = 2] = "blue", (foo || (foo = {})).answer = 42, module.exports = foo; -var foo, foo, color, foo = require("./foo_0"); +!function(foo) { + foo[foo.red = 0] = "red", foo[foo.green = 1] = "green", foo[foo.blue = 2] = "blue"; +}(foo || (foo = {})), (foo || (foo = {})).answer = 42, module.exports = foo; +var foo, color, foo = require("./foo_0"); color === foo.green && (color = foo.answer); export { }; diff --git a/crates/swc/tests/tsc-references/exportCodeGen_es5.2.minified.js b/crates/swc/tests/tsc-references/exportCodeGen_es5.2.minified.js index 39b8720194f..749309c527e 100644 --- a/crates/swc/tests/tsc-references/exportCodeGen_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exportCodeGen_es5.2.minified.js @@ -1,8 +1,8 @@ -var A, D, E, F; +var A1, D, E, F; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -(A || (A = {})).x = 12, (D || (D = {})).yes = function() { +(A = A1 || (A1 = {})).x = 12, (D || (D = {})).yes = function() { return !0; }, (function(E1) { (Color = Color = E1.Color || (E1.Color = {}))[Color.Red = 0] = "Red", E1.fn = function() {}; diff --git a/crates/swc/tests/tsc-references/exportImportAlias_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportImportAlias_es2015.2.minified.js index eff70d57be2..758f48980d2 100644 --- a/crates/swc/tests/tsc-references/exportImportAlias_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportImportAlias_es2015.2.minified.js @@ -1,9 +1,11 @@ -var A, A1, C, X, Z, K, M; -(A = A1 || (A1 = {})).x = "hello world", A.Point = class { - constructor(x, y){ - this.x = x, this.y = y; - } -}, (C || (C = {})).a = A1, C.a.x, new C.a.Point(0, 0), (function(X1) { +var A, C, X, Z, K, M; +!function(A1) { + A1.x = "hello world", A1.Point = class { + constructor(x, y){ + this.x = x, this.y = y; + } + }; +}(A || (A = {})), (C || (C = {})).a = A, C.a.x, new C.a.Point(0, 0), (function(X1) { function Y() { return 42; } diff --git a/crates/swc/tests/tsc-references/exportsAndImports1-amd_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports1-amd_es2015.2.minified.js index 517ab972b2a..3da7e62bc11 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports1-amd_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports1-amd_es2015.2.minified.js @@ -1,9 +1,13 @@ import { I, N, T } from "./t1"; -var E, D, E, D, M, v = 1; +var E, D, M, v = 1; function f() {} class C { } -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/exportsAndImports1-amd_es5.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports1-amd_es5.2.minified.js index 2833d3507d4..95942e8b646 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports1-amd_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports1-amd_es5.2.minified.js @@ -1,13 +1,17 @@ import { I, N, T } from "./t1"; -var D, E, D, M, v = 1; +var E, D, M, v = 1; function f() {} -var E, C = function() { +var C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/exportsAndImports1-es6_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports1-es6_es2015.2.minified.js index 517ab972b2a..3da7e62bc11 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports1-es6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports1-es6_es2015.2.minified.js @@ -1,9 +1,13 @@ import { I, N, T } from "./t1"; -var E, D, E, D, M, v = 1; +var E, D, M, v = 1; function f() {} class C { } -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/exportsAndImports1-es6_es5.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports1-es6_es5.2.minified.js index 2833d3507d4..95942e8b646 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports1-es6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports1-es6_es5.2.minified.js @@ -1,13 +1,17 @@ import { I, N, T } from "./t1"; -var D, E, D, M, v = 1; +var E, D, M, v = 1; function f() {} -var E, C = function() { +var C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/exportsAndImports1_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports1_es2015.2.minified.js index 517ab972b2a..3da7e62bc11 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports1_es2015.2.minified.js @@ -1,9 +1,13 @@ import { I, N, T } from "./t1"; -var E, D, E, D, M, v = 1; +var E, D, M, v = 1; function f() {} class C { } -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/exportsAndImports1_es5.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports1_es5.2.minified.js index 2833d3507d4..95942e8b646 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports1_es5.2.minified.js @@ -1,13 +1,17 @@ import { I, N, T } from "./t1"; -var D, E, D, M, v = 1; +var E, D, M, v = 1; function f() {} -var E, C = function() { +var C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/exportsAndImports3-amd_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports3-amd_es2015.2.minified.js index 7c02de1049c..0cc02f68aee 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports3-amd_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports3-amd_es2015.2.minified.js @@ -1,9 +1,13 @@ import { I1 as I, N1 as N, T1 as T } from "./t1"; -export var E, D, E, D, M, v = 1; +export var E, D, M, v = 1; export function f() {} export class C { } -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/exportsAndImports3-amd_es5.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports3-amd_es5.2.minified.js index 5508a28c2d6..37dde7c0608 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports3-amd_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports3-amd_es5.2.minified.js @@ -1,5 +1,5 @@ import { I1 as I, N1 as N, T1 as T } from "./t1"; -export var E, D, E, D, M, v = 1; +export var E, D, M, v = 1; export function f() {} export var C = function() { "use strict"; @@ -7,7 +7,11 @@ export var C = function() { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/exportsAndImports3-es6_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports3-es6_es2015.2.minified.js index 7c02de1049c..0cc02f68aee 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports3-es6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports3-es6_es2015.2.minified.js @@ -1,9 +1,13 @@ import { I1 as I, N1 as N, T1 as T } from "./t1"; -export var E, D, E, D, M, v = 1; +export var E, D, M, v = 1; export function f() {} export class C { } -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/exportsAndImports3-es6_es5.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports3-es6_es5.2.minified.js index 5508a28c2d6..37dde7c0608 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports3-es6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports3-es6_es5.2.minified.js @@ -1,5 +1,5 @@ import { I1 as I, N1 as N, T1 as T } from "./t1"; -export var E, D, E, D, M, v = 1; +export var E, D, M, v = 1; export function f() {} export var C = function() { "use strict"; @@ -7,7 +7,11 @@ export var C = function() { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/exportsAndImports3_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports3_es2015.2.minified.js index 7c02de1049c..0cc02f68aee 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports3_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports3_es2015.2.minified.js @@ -1,9 +1,13 @@ import { I1 as I, N1 as N, T1 as T } from "./t1"; -export var E, D, E, D, M, v = 1; +export var E, D, M, v = 1; export function f() {} export class C { } -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/exportsAndImports3_es5.2.minified.js b/crates/swc/tests/tsc-references/exportsAndImports3_es5.2.minified.js index 5508a28c2d6..37dde7c0608 100644 --- a/crates/swc/tests/tsc-references/exportsAndImports3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exportsAndImports3_es5.2.minified.js @@ -1,5 +1,5 @@ import { I1 as I, N1 as N, T1 as T } from "./t1"; -export var E, D, E, D, M, v = 1; +export var E, D, M, v = 1; export function f() {} export var C = function() { "use strict"; @@ -7,7 +7,11 @@ export var C = function() { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -E = E || (E = {}), E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", D = D || (D = {}), D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C", (function(M1) { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), (function(D) { + D[D.A = 0] = "A", D[D.B = 1] = "B", D[D.C = 2] = "C"; +})(D || (D = {})), (function(M1) { var x; M1.x = x; })(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/filterNamespace_import_es2015.2.minified.js b/crates/swc/tests/tsc-references/filterNamespace_import_es2015.2.minified.js index f7b6d7ab3b0..bc450e21ebd 100644 --- a/crates/swc/tests/tsc-references/filterNamespace_import_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/filterNamespace_import_es2015.2.minified.js @@ -1,5 +1,7 @@ -var ns, ns1; -(ns1 = ns || (ns = {})).Class = class { -}, ns1.Value = "", (ns1.nested || (ns1.nested = {})).NestedClass = class { -}, ns.Class, ns.Value; +var ns; +!function(ns1) { + ns1.Class = class { + }, ns1.Value = "", (ns1.nested || (ns1.nested = {})).NestedClass = class { + }; +}(ns || (ns = {})), ns.Class, ns.Value; export { }; diff --git a/crates/swc/tests/tsc-references/for-inStatements_es2015.2.minified.js b/crates/swc/tests/tsc-references/for-inStatements_es2015.2.minified.js index e2eea6dc198..cc851bff3e3 100644 --- a/crates/swc/tests/tsc-references/for-inStatements_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/for-inStatements_es2015.2.minified.js @@ -1,4 +1,4 @@ -var aString, anAny, c, d, e, i, M, Color, Color; +var aString, anAny, c, d, e, i, M, Color; for(aString in {}); for(anAny in {}); for(var x in {}); @@ -29,5 +29,7 @@ for(var x in i[42]); for(var x in (M || (M = {})).X = class { }, M); for(var x in M.X); -for(var x in (Color = Color || (Color = {}))[Color.Red = 0] = "Red", Color[Color.Blue = 1] = "Blue", Color); +for(var x in !function(Color) { + Color[Color.Red = 0] = "Red", Color[Color.Blue = 1] = "Blue"; +}(Color || (Color = {})), Color); for(var x in Color.Blue); diff --git a/crates/swc/tests/tsc-references/for-inStatements_es5.2.minified.js b/crates/swc/tests/tsc-references/for-inStatements_es5.2.minified.js index 7775f45ac41..6de19bb4af1 100644 --- a/crates/swc/tests/tsc-references/for-inStatements_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/for-inStatements_es5.2.minified.js @@ -60,7 +60,7 @@ for(var x in function(x1) { for(var x in function(x2, y) { return x2 + y; }); -var Color, aString, anAny, c, d, e, i, M, Color, A = function() { +var aString, anAny, c, d, e, i, M, Color, A = function() { "use strict"; function A() { _classCallCheck(this, A); @@ -147,5 +147,7 @@ for(var x in !function(M1) { M1.X = X; }(M || (M = {})), M); for(var x in M.X); -for(var x in (Color = Color || (Color = {}))[Color.Red = 0] = "Red", Color[Color.Blue = 1] = "Blue", Color); +for(var x in !function(Color) { + Color[Color.Red = 0] = "Red", Color[Color.Blue = 1] = "Blue"; +}(Color || (Color = {})), Color); for(var x in Color.Blue); diff --git a/crates/swc/tests/tsc-references/for-of47_es2015.2.minified.js b/crates/swc/tests/tsc-references/for-of47_es2015.2.minified.js index 3122e6cb39a..98081e9b001 100644 --- a/crates/swc/tests/tsc-references/for-of47_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/for-of47_es2015.2.minified.js @@ -1,5 +1,7 @@ -var x, y, E, E; -for ({ x , y: y = E.x } of ((E = E || (E = {}))[E.x = 0] = "x", [ +var x, y, E; +for ({ x , y: y = E.x } of (!function(E) { + E[E.x = 0] = "x"; +}(E || (E = {})), [ { x: "", y: !0 diff --git a/crates/swc/tests/tsc-references/for-of47_es5.2.minified.js b/crates/swc/tests/tsc-references/for-of47_es5.2.minified.js index f97376ae8f4..8fbff4ad3f7 100644 --- a/crates/swc/tests/tsc-references/for-of47_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/for-of47_es5.2.minified.js @@ -1,5 +1,6 @@ -var E; -(E = E || (E = {}))[E.x = 0] = "x"; +!function(E) { + E[E.x = 0] = "x"; +}(E || (E = {})); var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0; try { for(var E, ref, ref1, _step, _iterator = [ diff --git a/crates/swc/tests/tsc-references/for-of48_es2015.2.minified.js b/crates/swc/tests/tsc-references/for-of48_es2015.2.minified.js index 810f7a4d732..1a10038be5f 100644 --- a/crates/swc/tests/tsc-references/for-of48_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/for-of48_es2015.2.minified.js @@ -1,5 +1,7 @@ -var x, y, E, E; -for ({ x , y =E.x } of ((E = E || (E = {}))[E.x = 0] = "x", [ +var x, y, E; +for ({ x , y =E.x } of (!function(E) { + E[E.x = 0] = "x"; +}(E || (E = {})), [ { x: "", y: !0 diff --git a/crates/swc/tests/tsc-references/for-of48_es5.2.minified.js b/crates/swc/tests/tsc-references/for-of48_es5.2.minified.js index f97376ae8f4..8fbff4ad3f7 100644 --- a/crates/swc/tests/tsc-references/for-of48_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/for-of48_es5.2.minified.js @@ -1,5 +1,6 @@ -var E; -(E = E || (E = {}))[E.x = 0] = "x"; +!function(E) { + E[E.x = 0] = "x"; +}(E || (E = {})); var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0; try { for(var E, ref, ref1, _step, _iterator = [ diff --git a/crates/swc/tests/tsc-references/forStatementsMultipleInvalidDecl_es2015.2.minified.js b/crates/swc/tests/tsc-references/forStatementsMultipleInvalidDecl_es2015.2.minified.js index 3451091a114..1c9c18d645a 100644 --- a/crates/swc/tests/tsc-references/forStatementsMultipleInvalidDecl_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/forStatementsMultipleInvalidDecl_es2015.2.minified.js @@ -1,15 +1,16 @@ -var M, M1; class C { } class C2 extends C { } class D { } -for((M = M1 || (M1 = {})).A = class { -}, M.F2 = function(x) { - return x.toString(); -};;); -for(;;); +for(!function(M1) { + M1.A = class { + }, M1.F2 = function(x) { + return x.toString(); + }; +}(M || (M = {}));;); +for(var M;;); for(;;); for(new C();;); for(new D();;); diff --git a/crates/swc/tests/tsc-references/forStatements_es2015.2.minified.js b/crates/swc/tests/tsc-references/forStatements_es2015.2.minified.js index 8ae76d68541..aee892cfe2f 100644 --- a/crates/swc/tests/tsc-references/forStatements_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/forStatements_es2015.2.minified.js @@ -1,10 +1,12 @@ -var M, M1; class C { } -for((M = M1 || (M1 = {})).A = class { -}, M.F2 = function(x) { - return x.toString(); -};;); +!function(M1) { + M1.A = class { + }, M1.F2 = function(x) { + return x.toString(); + }; +}(M || (M = {})); +for(var M;;); for(;;); for(new Date(12);;); for(new Object();;); @@ -22,6 +24,6 @@ for(;;); for((x)=>2 ;;); for(;;); -for(new M1.A();;); +for(new M.A();;); for((x)=>"this is a string" ;;); diff --git a/crates/swc/tests/tsc-references/functionExpressionContextualTyping1_es2015.2.minified.js b/crates/swc/tests/tsc-references/functionExpressionContextualTyping1_es2015.2.minified.js index e6a1c40ce67..d7064d6e4dd 100644 --- a/crates/swc/tests/tsc-references/functionExpressionContextualTyping1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/functionExpressionContextualTyping1_es2015.2.minified.js @@ -1,3 +1,5 @@ -var E, E; -(E = E || (E = {}))[E.red = 0] = "red", E[E.blue = 1] = "blue", (num, str)=>(num.toExponential(), 0) +var E; +!function(E) { + E[E.red = 0] = "red", E[E.blue = 1] = "blue"; +}(E || (E = {})), (num, str)=>(num.toExponential(), 0) ; diff --git a/crates/swc/tests/tsc-references/functionExpressionContextualTyping1_es5.2.minified.js b/crates/swc/tests/tsc-references/functionExpressionContextualTyping1_es5.2.minified.js index 4707e2cccc9..c14d9a0c647 100644 --- a/crates/swc/tests/tsc-references/functionExpressionContextualTyping1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/functionExpressionContextualTyping1_es5.2.minified.js @@ -7,8 +7,10 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -(E = E || (E = {}))[E.red = 0] = "red", E[E.blue = 1] = "blue"; -var E, E, Class = function() { +!function(E) { + E[E.red = 0] = "red", E[E.blue = 1] = "blue"; +}(E || (E = {})); +var E, Class = function() { "use strict"; var Constructor, protoProps, staticProps; function Class() { diff --git a/crates/swc/tests/tsc-references/genericCallToOverloadedMethodWithOverloadedArguments_es2015.2.minified.js b/crates/swc/tests/tsc-references/genericCallToOverloadedMethodWithOverloadedArguments_es2015.2.minified.js index 1d293593144..d2ec46bb8de 100644 --- a/crates/swc/tests/tsc-references/genericCallToOverloadedMethodWithOverloadedArguments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/genericCallToOverloadedMethodWithOverloadedArguments_es2015.2.minified.js @@ -1,2 +1,2 @@ -var m1, m2, m3, m4, m5, m6; -m1 || (m1 = {}), (void 0).then(testFunction), m2 || (m2 = {}), (void 0).then(testFunction), m3 || (m3 = {}), (void 0).then(testFunction), m4 || (m4 = {}), (void 0).then(testFunction), m5 || (m5 = {}), (void 0).then(testFunction), m6 || (m6 = {}), (void 0).then(testFunction); +var m11, m21, m31, m41, m51, m6; +m1 = m11 || (m11 = {}), (void 0).then(testFunction), m2 = m21 || (m21 = {}), (void 0).then(testFunction), m3 = m31 || (m31 = {}), (void 0).then(testFunction), m4 = m41 || (m41 = {}), (void 0).then(testFunction), m5 = m51 || (m51 = {}), (void 0).then(testFunction), m6 || (m6 = {}), (void 0).then(testFunction); diff --git a/crates/swc/tests/tsc-references/genericCallToOverloadedMethodWithOverloadedArguments_es5.2.minified.js b/crates/swc/tests/tsc-references/genericCallToOverloadedMethodWithOverloadedArguments_es5.2.minified.js index 1d293593144..d2ec46bb8de 100644 --- a/crates/swc/tests/tsc-references/genericCallToOverloadedMethodWithOverloadedArguments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/genericCallToOverloadedMethodWithOverloadedArguments_es5.2.minified.js @@ -1,2 +1,2 @@ -var m1, m2, m3, m4, m5, m6; -m1 || (m1 = {}), (void 0).then(testFunction), m2 || (m2 = {}), (void 0).then(testFunction), m3 || (m3 = {}), (void 0).then(testFunction), m4 || (m4 = {}), (void 0).then(testFunction), m5 || (m5 = {}), (void 0).then(testFunction), m6 || (m6 = {}), (void 0).then(testFunction); +var m11, m21, m31, m41, m51, m6; +m1 = m11 || (m11 = {}), (void 0).then(testFunction), m2 = m21 || (m21 = {}), (void 0).then(testFunction), m3 = m31 || (m31 = {}), (void 0).then(testFunction), m4 = m41 || (m41 = {}), (void 0).then(testFunction), m5 = m51 || (m51 = {}), (void 0).then(testFunction), m6 || (m6 = {}), (void 0).then(testFunction); diff --git a/crates/swc/tests/tsc-references/genericCallTypeArgumentInference_es2015.2.minified.js b/crates/swc/tests/tsc-references/genericCallTypeArgumentInference_es2015.2.minified.js index 4d262436d77..9712f13ca8e 100644 --- a/crates/swc/tests/tsc-references/genericCallTypeArgumentInference_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/genericCallTypeArgumentInference_es2015.2.minified.js @@ -1,4 +1,3 @@ -""; var i, c = new class { foo(t, u) { return t; diff --git a/crates/swc/tests/tsc-references/genericCallTypeArgumentInference_es5.2.minified.js b/crates/swc/tests/tsc-references/genericCallTypeArgumentInference_es5.2.minified.js index 75220a06e81..551f8788948 100644 --- a/crates/swc/tests/tsc-references/genericCallTypeArgumentInference_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/genericCallTypeArgumentInference_es5.2.minified.js @@ -4,7 +4,6 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -""; var i, C = function() { "use strict"; var Constructor, protoProps, staticProps; diff --git a/crates/swc/tests/tsc-references/genericCallWithGenericSignatureArguments3_es2015.2.minified.js b/crates/swc/tests/tsc-references/genericCallWithGenericSignatureArguments3_es2015.2.minified.js index 118ea6fa504..9f8a31008b5 100644 --- a/crates/swc/tests/tsc-references/genericCallWithGenericSignatureArguments3_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/genericCallWithGenericSignatureArguments3_es2015.2.minified.js @@ -1,4 +1,4 @@ -var E, F, x, E, F; +var E, F, x; function foo(x, a, b) {} function foo2(x, a, b) {} foo("", (x)=>"" @@ -13,7 +13,11 @@ foo("", (x)=>"" , (x)=>"" ), foo(new Object(), (x)=>"" , (x)=>"" -), (E = E || (E = {}))[E.A = 0] = "A", (F = F || (F = {}))[F.A = 0] = "A", foo(E.A, (x)=>E.A +), (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), (function(F) { + F[F.A = 0] = "A"; +})(F || (F = {})), foo(E.A, (x)=>E.A , (x)=>F.A ), foo2("", (x)=>"" , (x)=>null diff --git a/crates/swc/tests/tsc-references/genericCallWithGenericSignatureArguments3_es5.2.minified.js b/crates/swc/tests/tsc-references/genericCallWithGenericSignatureArguments3_es5.2.minified.js index e96535bfe09..280c3047d6e 100644 --- a/crates/swc/tests/tsc-references/genericCallWithGenericSignatureArguments3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/genericCallWithGenericSignatureArguments3_es5.2.minified.js @@ -1,4 +1,4 @@ -var E, F, x, E, F; +var E, F, x; function foo(x, a, b) {} function foo2(x, a, b) {} foo("", function(x) { @@ -25,7 +25,11 @@ foo("", function(x) { return ""; }, function(x) { return ""; -}), (E = E || (E = {}))[E.A = 0] = "A", (F = F || (F = {}))[F.A = 0] = "A", foo(E.A, function(x) { +}), (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), (function(F) { + F[F.A = 0] = "A"; +})(F || (F = {})), foo(E.A, function(x) { return E.A; }, function(x) { return F.A; diff --git a/crates/swc/tests/tsc-references/ifDoWhileStatements_es2015.2.minified.js b/crates/swc/tests/tsc-references/ifDoWhileStatements_es2015.2.minified.js index 12249403e8f..83c18035c91 100644 --- a/crates/swc/tests/tsc-references/ifDoWhileStatements_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ifDoWhileStatements_es2015.2.minified.js @@ -2,13 +2,17 @@ class C { } class D { } -for((M = M1 || (M1 = {})).A = class { -}, M.F2 = function(x) { - return x.toString(); -}, (N = N1 || (N1 = {})).A = class { -}, N.F2 = function(x) { - return x.toString(); -};;); +for(!function(M1) { + M1.A = class { + }, M1.F2 = function(x) { + return x.toString(); + }; +}(M || (M = {})), (function(N1) { + N1.A = class { + }, N1.F2 = function(x) { + return x.toString(); + }; +})(N || (N = {}));;); for(;;); do ; while (null) @@ -42,7 +46,7 @@ while (new C()) for(new D(); new D();); do ; while (new D()) -for(var M, N, M1, N1, a = !0; a;); +for(var M, N, a = !0; a;); do ; while (a) do ; diff --git a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js index e6ecd4fb22b..773a96216d5 100644 --- a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js @@ -1,10 +1,12 @@ -var C, K, C, K; +var C, K; class _class { } export { _class as default }; export class A { } -(C = C || (C = {}))[C.One = 0] = "One", C[C.Two = 1] = "Two"; +!function(C) { + C[C.One = 0] = "One", C[C.Two = 1] = "Two"; +}(C || (C = {})); let a, b; console.log(a, b); let a, b; @@ -22,6 +24,8 @@ module.exports = H; const H = require("./h"); console.log({}); const H = require("./h"); -(K = K || (K = {}))[K.One = 0] = "One", K[K.Two = 1] = "Two", module.exports = K; +!function(K) { + K[K.One = 0] = "One", K[K.Two = 1] = "Two"; +}(K || (K = {})), module.exports = K; const K = require("./k"); K.One; diff --git a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js index 7668727edcc..cbdb2684365 100644 --- a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js @@ -10,7 +10,9 @@ export var A = function() { "use strict"; _classCallCheck(this, A); }; -(C = C || (C = {}))[C.One = 0] = "One", C[C.Two = 1] = "Two", console.log(a, b), console.log(a, b); +!function(C) { + C[C.One = 0] = "One", C[C.Two = 1] = "Two"; +}(C || (C = {})), console.log(a, b), console.log(a, b); var a = A; console.log(a, b), C.One; var c = C.Two, d = C.Two; @@ -20,9 +22,11 @@ var H = function() { _classCallCheck(this, H); }; module.exports = H; -var C, H = require("./h"); +var H = require("./h"); console.log({}); -var K, H = require("./h"); -(K = K || (K = {}))[K.One = 0] = "One", K[K.Two = 1] = "Two", module.exports = K; +var H = require("./h"); +!function(K) { + K[K.One = 0] = "One", K[K.Two = 1] = "Two"; +}(K || (K = {})), module.exports = K; var K = require("./k"); K.One; diff --git a/crates/swc/tests/tsc-references/inOperatorWithInvalidOperands_es2015.2.minified.js b/crates/swc/tests/tsc-references/inOperatorWithInvalidOperands_es2015.2.minified.js index ec706f88b5c..b311e2c2b36 100644 --- a/crates/swc/tests/tsc-references/inOperatorWithInvalidOperands_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/inOperatorWithInvalidOperands_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E, x, a1, a5, a6, b1, b2, b3, b4, b5; -(E = E || (E = {}))[E.a = 0] = "a", a1 in x, (void 0) in x, (void 0) in x, (void 0) in x, null in x, (void 0) in x, E.a in x, !1 in x, {} in x, a5 in x, a6 in x, x in b1, x in b2, x in b3, x in b4, x in b5, x in 0, x in !1, x in "", x in null, x in void 0, {} in ""; +var E, x, a1, a5, a6, b1, b2, b3, b4, b5; +!function(E) { + E[E.a = 0] = "a"; +}(E || (E = {})), a1 in x, (void 0) in x, (void 0) in x, (void 0) in x, null in x, (void 0) in x, E.a in x, !1 in x, {} in x, a5 in x, a6 in x, x in b1, x in b2, x in b3, x in b4, x in b5, x in 0, x in !1, x in "", x in null, x in void 0, {} in ""; diff --git a/crates/swc/tests/tsc-references/inOperatorWithInvalidOperands_es5.2.minified.js b/crates/swc/tests/tsc-references/inOperatorWithInvalidOperands_es5.2.minified.js index 99f5e7b4d0a..7a57b9aa31e 100644 --- a/crates/swc/tests/tsc-references/inOperatorWithInvalidOperands_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/inOperatorWithInvalidOperands_es5.2.minified.js @@ -1,7 +1,9 @@ -var E, x, a1, a2, a3, a4, a5, a6, b1, b2, b3, b4, b5, E, Foo = function() { +var E, x, a1, a2, a3, a4, a5, a6, b1, b2, b3, b4, b5, Foo = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, Foo); }; -(E = E || (E = {}))[E.a = 0] = "a", a1 in x, a2 in x, a3 in x, a4 in x, null in x, (void 0) in x, E.a in x, !1 in x, {} in x, a5 in x, a6 in x, x in b1, x in b2, x in b3, x in b4, x in b5, x in 0, x in !1, x in "", x in null, x in void 0, {} in ""; +!function(E) { + E[E.a = 0] = "a"; +}(E || (E = {})), a1 in x, a2 in x, a3 in x, a4 in x, null in x, (void 0) in x, E.a in x, !1 in x, {} in x, a5 in x, a6 in x, x in b1, x in b2, x in b3, x in b4, x in b5, x in 0, x in !1, x in "", x in null, x in void 0, {} in ""; diff --git a/crates/swc/tests/tsc-references/incrementOperatorWithEnumTypeInvalidOperations_es2015.2.minified.js b/crates/swc/tests/tsc-references/incrementOperatorWithEnumTypeInvalidOperations_es2015.2.minified.js index a2f1bdd3422..39951d0e7bf 100644 --- a/crates/swc/tests/tsc-references/incrementOperatorWithEnumTypeInvalidOperations_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/incrementOperatorWithEnumTypeInvalidOperations_es2015.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ++ENUM, ++ENUM1, ENUM++, ENUM1++, ++ENUM[1] + ENUM[2], ENUM[1] + ENUM[2]++, ++ENUM, ++ENUM1, ENUM++, ENUM1++; +var ENUM, ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ++ENUM, ++ENUM1, ENUM++, ENUM1++, ++ENUM[1] + ENUM[2], ENUM[1] + ENUM[2]++, ++ENUM, ++ENUM1, ENUM++, ENUM1++; diff --git a/crates/swc/tests/tsc-references/incrementOperatorWithEnumTypeInvalidOperations_es5.2.minified.js b/crates/swc/tests/tsc-references/incrementOperatorWithEnumTypeInvalidOperations_es5.2.minified.js index a2f1bdd3422..39951d0e7bf 100644 --- a/crates/swc/tests/tsc-references/incrementOperatorWithEnumTypeInvalidOperations_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/incrementOperatorWithEnumTypeInvalidOperations_es5.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ++ENUM, ++ENUM1, ENUM++, ENUM1++, ++ENUM[1] + ENUM[2], ENUM[1] + ENUM[2]++, ++ENUM, ++ENUM1, ENUM++, ENUM1++; +var ENUM, ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ++ENUM, ++ENUM1, ENUM++, ENUM1++, ++ENUM[1] + ENUM[2], ENUM[1] + ENUM[2]++, ++ENUM, ++ENUM1, ENUM++, ENUM1++; diff --git a/crates/swc/tests/tsc-references/incrementOperatorWithEnumType_es2015.2.minified.js b/crates/swc/tests/tsc-references/incrementOperatorWithEnumType_es2015.2.minified.js index 8cf5ddb6646..1ca5b60ba74 100644 --- a/crates/swc/tests/tsc-references/incrementOperatorWithEnumType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/incrementOperatorWithEnumType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ++ENUM1.B, ENUM1.B++, ++ENUM1.B, ENUM1.B++; +var ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ++ENUM1.B, ENUM1.B++, ++ENUM1.B, ENUM1.B++; diff --git a/crates/swc/tests/tsc-references/incrementOperatorWithEnumType_es5.2.minified.js b/crates/swc/tests/tsc-references/incrementOperatorWithEnumType_es5.2.minified.js index 8cf5ddb6646..1ca5b60ba74 100644 --- a/crates/swc/tests/tsc-references/incrementOperatorWithEnumType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/incrementOperatorWithEnumType_es5.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ++ENUM1.B, ENUM1.B++, ++ENUM1.B, ENUM1.B++; +var ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ++ENUM1.B, ENUM1.B++, ++ENUM1.B, ENUM1.B++; diff --git a/crates/swc/tests/tsc-references/instanceofOperatorWithAny_es5.2.minified.js b/crates/swc/tests/tsc-references/instanceofOperatorWithAny_es5.2.minified.js index 8a6eaf7ca31..3793424e123 100644 --- a/crates/swc/tests/tsc-references/instanceofOperatorWithAny_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/instanceofOperatorWithAny_es5.2.minified.js @@ -1,2 +1,4 @@ -var left, right, a; -left = a, right = a, null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] && right[Symbol.hasInstance](left); +var a; +!function(left, right) { + return null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right; +}(a, a); diff --git a/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersectionErrors_es2015.2.minified.js b/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersectionErrors_es2015.2.minified.js index b791125e3d9..8907147626d 100644 --- a/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersectionErrors_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersectionErrors_es2015.2.minified.js @@ -1,4 +1,4 @@ -var EX, EX; +var EX; class C1 extends Constructor() { } class C2 extends Constructor() { @@ -9,4 +9,6 @@ class C4 extends Constructor() { } class C5 extends Constructor() { } -(EX = EX || (EX = {}))[EX.A = 0] = "A", EX[EX.B = 1] = "B", EX[EX.C = 2] = "C"; +!function(EX) { + EX[EX.A = 0] = "A", EX[EX.B = 1] = "B", EX[EX.C = 2] = "C"; +}(EX || (EX = {})); diff --git a/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersectionErrors_es5.2.minified.js b/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersectionErrors_es5.2.minified.js index fcfe51b841a..86d56d39db5 100644 --- a/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersectionErrors_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersectionErrors_es5.2.minified.js @@ -44,7 +44,7 @@ function _createSuper(Derived) { })(self); }; } -var EX, EX, C1 = function(_super) { +var EX, C1 = function(_super) { "use strict"; _inherits(C1, _super); var _super1 = _createSuper(C1); @@ -85,4 +85,6 @@ var EX, EX, C1 = function(_super) { } return C5; }(Constructor()); -(EX = EX || (EX = {}))[EX.A = 0] = "A", EX[EX.B = 1] = "B", EX[EX.C = 2] = "C"; +!function(EX) { + EX[EX.A = 0] = "A", EX[EX.B = 1] = "B", EX[EX.C = 2] = "C"; +}(EX || (EX = {})); diff --git a/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersection_es2015.2.minified.js b/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersection_es2015.2.minified.js index bf6b60dc996..b358913a17f 100644 --- a/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersection_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersection_es2015.2.minified.js @@ -1,4 +1,4 @@ -var EX, EX; +var EX; class C1 extends Constructor() { } class C2 extends Constructor() { @@ -13,7 +13,9 @@ class C6 extends Constructor() { } class C7 extends Constructor() { } -(EX = EX || (EX = {}))[EX.A = 0] = "A", EX[EX.B = 1] = "B", EX[EX.C = 2] = "C"; +!function(EX) { + EX[EX.A = 0] = "A", EX[EX.B = 1] = "B", EX[EX.C = 2] = "C"; +}(EX || (EX = {})); class C20 extends Constructor() { } class C21 extends Constructor() { diff --git a/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersection_es5.2.minified.js b/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersection_es5.2.minified.js index 15a509bb21b..c7029714c49 100644 --- a/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersection_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/interfaceExtendsObjectIntersection_es5.2.minified.js @@ -44,7 +44,7 @@ function _createSuper(Derived) { })(self); }; } -var EX, EX, C1 = function(_super) { +var EX, C1 = function(_super) { "use strict"; _inherits(C1, _super); var _super1 = _createSuper(C1); @@ -101,7 +101,9 @@ var EX, EX, C1 = function(_super) { } return C7; }(Constructor()); -(EX = EX || (EX = {}))[EX.A = 0] = "A", EX[EX.B = 1] = "B", EX[EX.C = 2] = "C"; +!function(EX) { + EX[EX.A = 0] = "A", EX[EX.B = 1] = "B", EX[EX.C = 2] = "C"; +}(EX || (EX = {})); var C20 = function(_super) { "use strict"; _inherits(C20, _super); diff --git a/crates/swc/tests/tsc-references/interfaceWithPropertyOfEveryType_es2015.2.minified.js b/crates/swc/tests/tsc-references/interfaceWithPropertyOfEveryType_es2015.2.minified.js index 8486c5f78ab..6843e416fc9 100644 --- a/crates/swc/tests/tsc-references/interfaceWithPropertyOfEveryType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/interfaceWithPropertyOfEveryType_es2015.2.minified.js @@ -1,3 +1,5 @@ -var E, M, E; -(M || (M = {})).y = 1, (E = E || (E = {}))[E.A = 0] = "A", new class { +var M, E; +(M || (M = {})).y = 1, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), new class { }(), E.A; diff --git a/crates/swc/tests/tsc-references/interfaceWithPropertyOfEveryType_es5.2.minified.js b/crates/swc/tests/tsc-references/interfaceWithPropertyOfEveryType_es5.2.minified.js index c26c9767b91..b0e9163c415 100644 --- a/crates/swc/tests/tsc-references/interfaceWithPropertyOfEveryType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/interfaceWithPropertyOfEveryType_es5.2.minified.js @@ -1,7 +1,9 @@ -var E, M, E, C = function() { +var M, E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -(M || (M = {})).y = 1, (E = E || (E = {}))[E.A = 0] = "A", new C(), E.A; +(M || (M = {})).y = 1, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), new C(), E.A; diff --git a/crates/swc/tests/tsc-references/intersectionOfUnionOfUnitTypes_es2015.2.minified.js b/crates/swc/tests/tsc-references/intersectionOfUnionOfUnitTypes_es2015.2.minified.js index faec2542576..c5c0f7a5f5b 100644 --- a/crates/swc/tests/tsc-references/intersectionOfUnionOfUnitTypes_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/intersectionOfUnionOfUnitTypes_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D", E[E.E = 4] = "E", E[E.F = 5] = "F"; +var E; +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D", E[E.E = 4] = "E", E[E.F = 5] = "F"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/intersectionOfUnionOfUnitTypes_es5.2.minified.js b/crates/swc/tests/tsc-references/intersectionOfUnionOfUnitTypes_es5.2.minified.js index faec2542576..c5c0f7a5f5b 100644 --- a/crates/swc/tests/tsc-references/intersectionOfUnionOfUnitTypes_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/intersectionOfUnionOfUnitTypes_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D", E[E.E = 4] = "E", E[E.F = 5] = "F"; +var E; +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D", E[E.E = 4] = "E", E[E.F = 5] = "F"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/invalidBooleanAssignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/invalidBooleanAssignments_es2015.2.minified.js index bfa2c57a3aa..2231b33ce1b 100644 --- a/crates/swc/tests/tsc-references/invalidBooleanAssignments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidBooleanAssignments_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E, M; -(E = E || (E = {}))[E.A = 0] = "A", (M || (M = {})).a = 1, M = !0; +var E, M; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (M || (M = {})).a = 1, M = !0; diff --git a/crates/swc/tests/tsc-references/invalidBooleanAssignments_es5.2.minified.js b/crates/swc/tests/tsc-references/invalidBooleanAssignments_es5.2.minified.js index 71aad6356aa..560e96f4ade 100644 --- a/crates/swc/tests/tsc-references/invalidBooleanAssignments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidBooleanAssignments_es5.2.minified.js @@ -1,5 +1,7 @@ -var E, E, M; -(E = E || (E = {}))[E.A = 0] = "A"; +var E, M; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); var C = function() { "use strict"; !function(instance, Constructor) { diff --git a/crates/swc/tests/tsc-references/invalidEnumAssignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/invalidEnumAssignments_es2015.2.minified.js index 15fd0a36329..73f2415b1e3 100644 --- a/crates/swc/tests/tsc-references/invalidEnumAssignments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidEnumAssignments_es2015.2.minified.js @@ -1,2 +1,6 @@ -var E, E2, E, E2; -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", (E2 = E2 || (E2 = {}))[E2.A = 0] = "A", E2[E2.B = 1] = "B", E2.A, E.A; +var E, E2; +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B"; +}(E || (E = {})), (function(E2) { + E2[E2.A = 0] = "A", E2[E2.B = 1] = "B"; +})(E2 || (E2 = {})), E2.A, E.A; diff --git a/crates/swc/tests/tsc-references/invalidEnumAssignments_es5.2.minified.js b/crates/swc/tests/tsc-references/invalidEnumAssignments_es5.2.minified.js index 15fd0a36329..73f2415b1e3 100644 --- a/crates/swc/tests/tsc-references/invalidEnumAssignments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidEnumAssignments_es5.2.minified.js @@ -1,2 +1,6 @@ -var E, E2, E, E2; -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", (E2 = E2 || (E2 = {}))[E2.A = 0] = "A", E2[E2.B = 1] = "B", E2.A, E.A; +var E, E2; +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B"; +}(E || (E = {})), (function(E2) { + E2[E2.A = 0] = "A", E2[E2.B = 1] = "B"; +})(E2 || (E2 = {})), E2.A, E.A; diff --git a/crates/swc/tests/tsc-references/invalidImportAliasIdentifiers_es2015.2.minified.js b/crates/swc/tests/tsc-references/invalidImportAliasIdentifiers_es2015.2.minified.js index 3caf1c73b53..b2237d5137e 100644 --- a/crates/swc/tests/tsc-references/invalidImportAliasIdentifiers_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidImportAliasIdentifiers_es2015.2.minified.js @@ -1,3 +1,5 @@ -var E, E; -(E = E || (E = {}))[E.Red = 0] = "Red", E[E.Blue = 1] = "Blue"; +var E; +!function(E) { + E[E.Red = 0] = "Red", E[E.Blue = 1] = "Blue"; +}(E || (E = {})); export { }; diff --git a/crates/swc/tests/tsc-references/invalidImportAliasIdentifiers_es5.2.minified.js b/crates/swc/tests/tsc-references/invalidImportAliasIdentifiers_es5.2.minified.js index c45a298aa24..3256de8daaa 100644 --- a/crates/swc/tests/tsc-references/invalidImportAliasIdentifiers_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidImportAliasIdentifiers_es5.2.minified.js @@ -1,8 +1,10 @@ -var E, E, C = function() { +var E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -(E = E || (E = {}))[E.Red = 0] = "Red", E[E.Blue = 1] = "Blue"; +!function(E) { + E[E.Red = 0] = "Red", E[E.Blue = 1] = "Blue"; +}(E || (E = {})); export { }; diff --git a/crates/swc/tests/tsc-references/invalidMultipleVariableDeclarations_es2015.2.minified.js b/crates/swc/tests/tsc-references/invalidMultipleVariableDeclarations_es2015.2.minified.js index e8346edf1b9..b0c52c8c4a2 100644 --- a/crates/swc/tests/tsc-references/invalidMultipleVariableDeclarations_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidMultipleVariableDeclarations_es2015.2.minified.js @@ -1,11 +1,13 @@ -var M, M1; +var M; class C { } class C2 extends C { } class D { } -(M = M1 || (M1 = {})).A = class { -}, M.F2 = function(x) { - return x.toString(); -}, new C(), new D(), new C(), new C2(), new C(), new C2(), new D(), new D(), new Array(), M1.A; +(function(M1) { + M1.A = class { + }, M1.F2 = function(x) { + return x.toString(); + }; +})(M || (M = {})), new C(), new D(), new C(), new C2(), new C(), new C2(), new D(), new D(), new Array(), M.A; diff --git a/crates/swc/tests/tsc-references/invalidNestedModules_es2015.2.minified.js b/crates/swc/tests/tsc-references/invalidNestedModules_es2015.2.minified.js index 7765ceb9e0c..0fd768d38c5 100644 --- a/crates/swc/tests/tsc-references/invalidNestedModules_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidNestedModules_es2015.2.minified.js @@ -1,11 +1,15 @@ -var A, M2, A1, M21; -!function(A2) { +var A, M2; +!function(A1) { var B; - ((B = A2.B || (A2.B = {})).C || (B.C = {})).Point = class { + ((B = A1.B || (A1.B = {})).C || (B.C = {})).Point = class { }; -}(A || (A = {})), ((A1 = A || (A = {})).B || (A1.B = {})).C = class { -}, ((M21 = M2 || (M2 = {})).X || (M21.X = {})).Point = class { -}, (function(M22) { +}(A || (A = {})), (function(A2) { + (A2.B || (A2.B = {})).C = class { + }; +})(A || (A = {})), (function(M21) { + (M21.X || (M21.X = {})).Point = class { + }; +})(M2 || (M2 = {})), (function(M22) { var Point; (M22.X || (M22.X = {})).Point = Point; })(M2 || (M2 = {})); diff --git a/crates/swc/tests/tsc-references/invalidStringAssignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/invalidStringAssignments_es2015.2.minified.js index 43ab2b2344b..70d3793a09b 100644 --- a/crates/swc/tests/tsc-references/invalidStringAssignments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidStringAssignments_es2015.2.minified.js @@ -1,2 +1,4 @@ -var M, E, E; -(M || (M = {})).x = 1, M = "", (E = E || (E = {}))[E.A = 0] = "A"; +var M, E; +(M || (M = {})).x = 1, M = "", (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/invalidStringAssignments_es5.2.minified.js b/crates/swc/tests/tsc-references/invalidStringAssignments_es5.2.minified.js index e9620c96a9e..6252dab8be0 100644 --- a/crates/swc/tests/tsc-references/invalidStringAssignments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidStringAssignments_es5.2.minified.js @@ -1,7 +1,9 @@ -var M, E, E, C = function() { +var M, E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -(M || (M = {})).x = 1, M = "", (E = E || (E = {}))[E.A = 0] = "A"; +(M || (M = {})).x = 1, M = "", (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/invalidUndefinedAssignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/invalidUndefinedAssignments_es2015.2.minified.js index e9cba93c78e..6cedc6ec233 100644 --- a/crates/swc/tests/tsc-references/invalidUndefinedAssignments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidUndefinedAssignments_es2015.2.minified.js @@ -1,2 +1,4 @@ -var x, E, M, E; -(E = E || (E = {}))[E.A = 0] = "A", (E = x).A = x, I = x, (M || (M = {})).x = 1, M = x; +var x, E, M; +(function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), (E = x).A = x, I = x, (M || (M = {})).x = 1, M = x; diff --git a/crates/swc/tests/tsc-references/invalidUndefinedAssignments_es5.2.minified.js b/crates/swc/tests/tsc-references/invalidUndefinedAssignments_es5.2.minified.js index 70e3a461a0b..9599f3107ce 100644 --- a/crates/swc/tests/tsc-references/invalidUndefinedAssignments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidUndefinedAssignments_es5.2.minified.js @@ -1,5 +1,7 @@ -(E = E || (E = {}))[E.A = 0] = "A", (E = x).A = x; -var E, x, E, M, C = function() { +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (E = x).A = x; +var x, E, M, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); diff --git a/crates/swc/tests/tsc-references/invalidUndefinedValues_es2015.2.minified.js b/crates/swc/tests/tsc-references/invalidUndefinedValues_es2015.2.minified.js index 652bec0ec87..5ea4649a84a 100644 --- a/crates/swc/tests/tsc-references/invalidUndefinedValues_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidUndefinedValues_es2015.2.minified.js @@ -1,7 +1,9 @@ -var x, M, E, E; +var x, M, E; x = 1, x = "", x = !0, x = void 0, x = null, x = class { }, x = void 0, x = void 0, (M || (M = {})).x = 1, x = M, x = { f () {} }, x = function(a) { x = a; -}, (E = E || (E = {}))[E.A = 0] = "A", x = E, x = E.A; +}, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), x = E, x = E.A; diff --git a/crates/swc/tests/tsc-references/invalidUndefinedValues_es5.2.minified.js b/crates/swc/tests/tsc-references/invalidUndefinedValues_es5.2.minified.js index 8104c6ede93..c19ea9cf943 100644 --- a/crates/swc/tests/tsc-references/invalidUndefinedValues_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidUndefinedValues_es5.2.minified.js @@ -1,5 +1,5 @@ x = 1, x = "", x = !0, x = a, x = null; -var E, x, a, b, c, M, E, C = function() { +var x, a, b, c, M, E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); @@ -9,4 +9,6 @@ x = C, x = b, x = c, (M || (M = {})).x = 1, x = M, x = { f: function() {} }, x = function(a1) { x = a1; -}, (E = E || (E = {}))[E.A = 0] = "A", x = E, x = E.A; +}, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), x = E, x = E.A; diff --git a/crates/swc/tests/tsc-references/invalidVoidAssignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/invalidVoidAssignments_es2015.2.minified.js index 95ac123a689..a4f0a961f2f 100644 --- a/crates/swc/tests/tsc-references/invalidVoidAssignments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidVoidAssignments_es2015.2.minified.js @@ -1,4 +1,6 @@ -var x, M, E, E; -(M || (M = {})).x = 1, M = x, (E = E || (E = {}))[E.A = 0] = "A", x = E, x = E.A, x = { +var x, M, E; +(M || (M = {})).x = 1, M = x, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), x = E, x = E.A, x = { f () {} }; diff --git a/crates/swc/tests/tsc-references/invalidVoidAssignments_es5.2.minified.js b/crates/swc/tests/tsc-references/invalidVoidAssignments_es5.2.minified.js index 988351d1b62..e320bae6e73 100644 --- a/crates/swc/tests/tsc-references/invalidVoidAssignments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidVoidAssignments_es5.2.minified.js @@ -1,9 +1,11 @@ -var x, M, E, E, C = function() { +var x, M, E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -(M || (M = {})).x = 1, M = x, (E = E || (E = {}))[E.A = 0] = "A", x = E, x = E.A, x = { +(M || (M = {})).x = 1, M = x, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), x = E, x = E.A, x = { f: function() {} }; diff --git a/crates/swc/tests/tsc-references/invalidVoidValues_es2015.2.minified.js b/crates/swc/tests/tsc-references/invalidVoidValues_es2015.2.minified.js index c2c8c885845..d08930ae10f 100644 --- a/crates/swc/tests/tsc-references/invalidVoidValues_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidVoidValues_es2015.2.minified.js @@ -1,5 +1,7 @@ -var x, E, a, b, M, E; -x = 1, x = "", x = !0, (E = E || (E = {}))[E.A = 0] = "A", x = E, x = E.A, x = a, x = b, x = { +var x, E, a, b, M; +x = 1, x = "", x = !0, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), x = E, x = E.A, x = a, x = b, x = { f () {} }, (M || (M = {})).x = 1, x = M, x = function(a1) { x = a1; diff --git a/crates/swc/tests/tsc-references/invalidVoidValues_es5.2.minified.js b/crates/swc/tests/tsc-references/invalidVoidValues_es5.2.minified.js index 510e91ea6bd..28db972982a 100644 --- a/crates/swc/tests/tsc-references/invalidVoidValues_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/invalidVoidValues_es5.2.minified.js @@ -1,5 +1,7 @@ -x = 1, x = "", x = !0, (E = E || (E = {}))[E.A = 0] = "A", x = E, x = E.A; -var E, x, E, a, b, M, C = function() { +x = 1, x = "", x = !0, (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), x = E, x = E.A; +var x, E, a, b, M, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern15_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern15_es5.2.minified.js index 52ce88d1b13..2c4fbbebda3 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern15_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern15_es5.2.minified.js @@ -22,9 +22,6 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var arr, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; function _unsupportedIterableToArray(o, minLen) { if (o) { if ("string" == typeof o) return _arrayLikeToArray(o, minLen); @@ -60,12 +57,12 @@ var Bar = function() { } }(); return function() { - var self, call, result, Super = _getPrototypeOf(Derived); + var obj, self, call, result, Super = _getPrototypeOf(Derived); if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else result = Super.apply(this, arguments); - return self = this, (call = result) && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return self; })(self); @@ -125,9 +122,11 @@ var Bar = function() { }()); __tmp[0], __tmp[1]; }).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new FooIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new FooIterator)); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern16_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern16_es5.2.minified.js index 3bce46caf44..4e49a182bcc 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern16_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern16_es5.2.minified.js @@ -25,9 +25,6 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var arr, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; function _unsupportedIterableToArray(o, minLen) { if (o) { if ("string" == typeof o) return _arrayLikeToArray(o, minLen); @@ -62,12 +59,14 @@ function _unsupportedIterableToArray(o, minLen) { }()); __tmp[0], __tmp[1]; }).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new FooIteratorIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new FooIteratorIterator)); var Bar = function() { "use strict"; _classCallCheck(this, Bar); @@ -95,12 +94,12 @@ var Bar = function() { } }(); return function() { - var self, call, result, Super = _getPrototypeOf(Derived); + var obj, self, call, result, Super = _getPrototypeOf(Derived); if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else result = Super.apply(this, arguments); - return self = this, (call = result) && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return self; })(self); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern1_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern1_es5.2.minified.js index 5aa61872fbe..8fbce2bd676 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern1_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, i, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -34,33 +34,35 @@ var arr, i, tmp = Symbol.iterator, SymbolIterator = function() { } } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), SymbolIterator; -}(), ref = (i = 2, function(arr) { - if (Array.isArray(arr)) return arr; -}(arr = new SymbolIterator) || function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ +}(), ref = function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; try { - _n || null == _i.return || _i.return(); + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; } finally{ - if (_d) throw _e; + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } } + return _arr; } - return _arr; - } -}(arr, i) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr, i) || function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator, 2); ref[0], ref[1]; diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern20_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern20_es5.2.minified.js index 0163977d394..0cb722eaf11 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern20_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern20_es5.2.minified.js @@ -46,9 +46,6 @@ function _slicedToArray(arr, i) { throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); })(); } -var arr, _typeof = function(obj) { - return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; -}; function _unsupportedIterableToArray(o, minLen) { if (o) { if ("string" == typeof o) return _arrayLikeToArray(o, minLen); @@ -84,12 +81,12 @@ var Bar = function() { } }(); return function() { - var self, call, result, Super = _getPrototypeOf(Derived); + var obj, self, call, result, Super = _getPrototypeOf(Derived); if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else result = Super.apply(this, arguments); - return self = this, (call = result) && ("object" === _typeof(call) || "function" == typeof call) ? call : (function(self) { + return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : (function(self) { if (void 0 === self) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return self; })(self); @@ -130,9 +127,11 @@ var Bar = function() { var __tmp = _slicedToArray(_tmp, 2); void 0 === _slicedToArray(__tmp[0], 1)[0] && new Foo, void 0 === __tmp[1] && new Foo; }).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new FooArrayIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new FooArrayIterator)); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern21_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern21_es5.2.minified.js index 71201b1d538..bcbecbfb1a2 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern21_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern21_es5.2.minified.js @@ -3,36 +3,38 @@ function _arrayLikeToArray(arr, len) { for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } -var arr, i, ref = (i = 2, function(arr) { - if (Array.isArray(arr)) return arr; -}(arr = { +var ref = function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; + try { + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; + } finally{ + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } + } + return _arr; + } + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}({ 0: "", 1: !0 -}) || function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ - try { - _n || null == _i.return || _i.return(); - } finally{ - if (_d) throw _e; - } - } - return _arr; - } -}(arr, i) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr, i) || function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); +}, 2); ref[0], ref[1]; diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern22_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern22_es5.2.minified.js index 9fcd76742d6..1053411d6a3 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern22_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern22_es5.2.minified.js @@ -1,23 +1,24 @@ -var arr; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } -((function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = { +(function(arr) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})({ 0: "", 1: !0 -}) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})()).slice(0); +}).slice(0); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern23_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern23_es5.2.minified.js index 19c8d7b7e3c..5efc0df571e 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern23_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern23_es5.2.minified.js @@ -1,38 +1,40 @@ -var ref, arr, i; +var ref; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } -(ref = (i = 2, (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = { +(ref = (function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; + try { + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; + } finally{ + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } + } + return _arr; + } + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})({ 0: "", 1: !0 -}) || (function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ - try { - _n || null == _i.return || _i.return(); - } finally{ - if (_d) throw _e; - } - } - return _arr; - } -})(arr, i) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})()))[0], ref[1]; +}, 2))[0], ref[1]; diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern24_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern24_es5.2.minified.js index 1207df8b318..97ff2065127 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern24_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern24_es5.2.minified.js @@ -1,23 +1,25 @@ -var ref, arr; +var ref; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } (ref = (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})({ 0: "", 1: !0 -}) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})())[0], ref.slice(1); +}))[0], ref.slice(1); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern27_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern27_es5.2.minified.js index bc13d4b393c..c78168fa807 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern27_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern27_es5.2.minified.js @@ -1,4 +1,3 @@ -var arr; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; @@ -41,8 +40,14 @@ function _unsupportedIterableToArray(o, minLen) { var __tmp = _slicedToArray(_tmp, 2), ref = _slicedToArray(__tmp[0], 2), k1 = ref[0], v1 = ref[1], ref1 = _slicedToArray(__tmp[1], 2); ref1[0], ref1[1]; }).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new Map([ + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new Map([ [ "", 0 @@ -51,8 +56,4 @@ function _unsupportedIterableToArray(o, minLen) { "hello", 1 ] -])) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); +]))); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern28_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern28_es5.2.minified.js index 12a2b812ebc..f0dc08b858e 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern28_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern28_es5.2.minified.js @@ -1,4 +1,3 @@ -var arr; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; @@ -41,8 +40,14 @@ function _unsupportedIterableToArray(o, minLen) { var __tmp = _slicedToArray(_tmp, 2), ref = _slicedToArray(__tmp[0], 2), k1 = ref[0], v1 = ref[1], ref1 = _slicedToArray(__tmp[1], 2); ref1[0], ref1[1]; }).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new Map([ + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new Map([ [ "", 0 @@ -51,8 +56,4 @@ function _unsupportedIterableToArray(o, minLen) { "hello", !0 ] -])) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); +]))); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern29_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern29_es5.2.minified.js index 8375b85de19..ac8ee741b17 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern29_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern29_es5.2.minified.js @@ -1,4 +1,3 @@ -var arr; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; @@ -41,8 +40,14 @@ function _unsupportedIterableToArray(o, minLen) { var __tmp = _slicedToArray(_tmp, 2), ref = _slicedToArray(__tmp[0], 2), k1 = ref[0], v1 = ref[1], ref1 = _slicedToArray(__tmp[1], 2); ref1[0], ref1[1]; }).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new Map([ + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new Map([ [ "", !0 @@ -51,8 +56,4 @@ function _unsupportedIterableToArray(o, minLen) { "hello", !0 ] -])) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); +]))); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern2_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern2_es5.2.minified.js index c43a2cb03d5..1156e4aa39b 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern2_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -35,17 +35,19 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), SymbolIterator; }(), ref = function(arr) { - if (Array.isArray(arr)) return arr; -}(arr = new SymbolIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr, i) || function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}(); + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator); ref[0], ref.slice(1); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern3_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern3_es5.2.minified.js index 22c1f182085..af2f508e5cb 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern3_es5.2.minified.js @@ -22,7 +22,7 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var ref, arr, i, Bar = function() { +var ref, Bar = function() { "use strict"; _classCallCheck(this, Bar); }, Foo = function(Bar1) { @@ -88,32 +88,34 @@ var ref, arr, i, Bar = function() { } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), FooIterator; }(); -(ref = (i = 2, (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = new FooIterator) || (function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ +(ref = (function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; try { - _n || null == _i.return || _i.return(); + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; } finally{ - if (_d) throw _e; + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } } + return _arr; } - return _arr; - } -})(arr, i) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})()))[0], ref[1]; + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})(new FooIterator, 2))[0], ref[1]; diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern4_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern4_es5.2.minified.js index 7233ab24d12..578a6e5356f 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern4_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern4_es5.2.minified.js @@ -22,7 +22,7 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var ref, arr, Bar = function() { +var ref, Bar = function() { "use strict"; _classCallCheck(this, Bar); }, Foo = function(Bar1) { @@ -89,16 +89,18 @@ var ref, arr, Bar = function() { ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), FooIterator; }(); (ref = (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = new FooIterator) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})())[0], ref.slice(1); + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})(new FooIterator))[0], ref.slice(1); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern5_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern5_es5.2.minified.js index 22c1f182085..af2f508e5cb 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern5_es5.2.minified.js @@ -22,7 +22,7 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var ref, arr, i, Bar = function() { +var ref, Bar = function() { "use strict"; _classCallCheck(this, Bar); }, Foo = function(Bar1) { @@ -88,32 +88,34 @@ var ref, arr, i, Bar = function() { } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), FooIterator; }(); -(ref = (i = 2, (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = new FooIterator) || (function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ +(ref = (function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; try { - _n || null == _i.return || _i.return(); + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; } finally{ - if (_d) throw _e; + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } } + return _arr; } - return _arr; - } -})(arr, i) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})()))[0], ref[1]; + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})(new FooIterator, 2))[0], ref[1]; diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern6_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern6_es5.2.minified.js index 7233ab24d12..578a6e5356f 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern6_es5.2.minified.js @@ -22,7 +22,7 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var ref, arr, Bar = function() { +var ref, Bar = function() { "use strict"; _classCallCheck(this, Bar); }, Foo = function(Bar1) { @@ -89,16 +89,18 @@ var ref, arr, Bar = function() { ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), FooIterator; }(); (ref = (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = new FooIterator) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})())[0], ref.slice(1); + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})(new FooIterator))[0], ref.slice(1); diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern7_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern7_es5.2.minified.js index 22c1f182085..af2f508e5cb 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern7_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern7_es5.2.minified.js @@ -22,7 +22,7 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var ref, arr, i, Bar = function() { +var ref, Bar = function() { "use strict"; _classCallCheck(this, Bar); }, Foo = function(Bar1) { @@ -88,32 +88,34 @@ var ref, arr, i, Bar = function() { } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), FooIterator; }(); -(ref = (i = 2, (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = new FooIterator) || (function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ +(ref = (function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; try { - _n || null == _i.return || _i.return(); + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; } finally{ - if (_d) throw _e; + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } } + return _arr; } - return _arr; - } -})(arr, i) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})()))[0], ref[1]; + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})(new FooIterator, 2))[0], ref[1]; diff --git a/crates/swc/tests/tsc-references/iterableArrayPattern8_es5.2.minified.js b/crates/swc/tests/tsc-references/iterableArrayPattern8_es5.2.minified.js index 7233ab24d12..578a6e5356f 100644 --- a/crates/swc/tests/tsc-references/iterableArrayPattern8_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iterableArrayPattern8_es5.2.minified.js @@ -22,7 +22,7 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var ref, arr, Bar = function() { +var ref, Bar = function() { "use strict"; _classCallCheck(this, Bar); }, Foo = function(Bar1) { @@ -89,16 +89,18 @@ var ref, arr, Bar = function() { ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), FooIterator; }(); (ref = (function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = new FooIterator) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})())[0], ref.slice(1); + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})(new FooIterator))[0], ref.slice(1); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInArray10_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInArray10_es5.2.minified.js index e3d6aef627a..a1963775cda 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInArray10_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInArray10_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -26,17 +26,19 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), SymbolIterator; }(); -(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -})(arr = new SymbolIterator) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr) || (function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})(); +!function(arr) { + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInArray11_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInArray11_es5.2.minified.js index ec72a0a21de..878427d9a0a 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInArray11_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInArray11_es5.2.minified.js @@ -1,20 +1,21 @@ -var arr; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } -(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -})(arr = void 0) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr) || (function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})(); +!function(arr) { + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(void 0); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInArray4_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInArray4_es5.2.minified.js index b80e149f4c8..09f3e46e521 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInArray4_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInArray4_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -39,16 +39,18 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { 0, 1 ].concat(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new SymbolIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator)); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInArray5_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInArray5_es5.2.minified.js index b80e149f4c8..09f3e46e521 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInArray5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInArray5_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -39,16 +39,18 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { 0, 1 ].concat(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new SymbolIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator)); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInArray6_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInArray6_es5.2.minified.js index b80e149f4c8..09f3e46e521 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInArray6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInArray6_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -39,16 +39,18 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { 0, 1 ].concat(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new SymbolIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator)); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInArray7_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInArray7_es5.2.minified.js index a59658550ca..5b149a3bf09 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInArray7_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInArray7_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var array, arr, tmp = Symbol.iterator, SymbolIterator = function() { +var array, tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -36,16 +36,18 @@ var array, arr, tmp = Symbol.iterator, SymbolIterator = function() { ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), SymbolIterator; }(); array.concat(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new SymbolIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator)); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInArray8_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInArray8_es5.2.minified.js index d41b1ecb2d5..ba00ae5e166 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInArray8_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInArray8_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, SymbolIterator = function() { +var SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -29,17 +29,19 @@ var arr, SymbolIterator = function() { } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), SymbolIterator; }(); -(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -})(arr = new SymbolIterator) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr) || (function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})(); +!function(arr) { + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInArray9_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInArray9_es5.2.minified.js index f30aa75ee97..fe5551623c5 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInArray9_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInArray9_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -34,17 +34,19 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), SymbolIterator; }(); -(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -})(arr = new SymbolIterator) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr) || (function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})(); +!function(arr) { + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInArray_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInArray_es5.2.minified.js index f65412e326f..000b6182f06 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInArray_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInArray_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -35,17 +35,19 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), SymbolIterator; }(); -(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -})(arr = new SymbolIterator) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr) || (function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})(); +!function(arr) { + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInCall10_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInCall10_es5.2.minified.js index dfe2bbc1892..4b995d6a5da 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInCall10_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInCall10_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -38,16 +38,18 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { (function(s) { return s[0]; }).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new SymbolIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator)); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInCall11_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInCall11_es5.2.minified.js index 173f3653b05..69a3d9b8959 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInCall11_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInCall11_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -39,16 +39,18 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { for(var _len = arguments.length, s = new Array(_len), _key = 0; _key < _len; _key++)s[_key] = arguments[_key]; return s[0]; }).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new SymbolIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator)); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInCall2_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInCall2_es5.2.minified.js index 302eb6c679e..09962ebfaa9 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInCall2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInCall2_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -36,16 +36,18 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), SymbolIterator; }(); (function(s) {}).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new SymbolIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator)); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInCall3_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInCall3_es5.2.minified.js index c2eb9a922d2..037b933137a 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInCall3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInCall3_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -38,16 +38,18 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { (function() { for(var _len = arguments.length, s = new Array(_len), _key = 0; _key < _len; _key++)s[_key] = arguments[_key]; }).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new SymbolIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator)); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInCall4_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInCall4_es5.2.minified.js index 2ec7b76a655..65474ee9ddd 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInCall4_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInCall4_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -38,16 +38,18 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { (function(s1) { for(var _len = arguments.length, s = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++)s[_key - 1] = arguments[_key]; }).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new SymbolIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator)); diff --git a/crates/swc/tests/tsc-references/iteratorSpreadInCall_es5.2.minified.js b/crates/swc/tests/tsc-references/iteratorSpreadInCall_es5.2.minified.js index 302eb6c679e..09962ebfaa9 100644 --- a/crates/swc/tests/tsc-references/iteratorSpreadInCall_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/iteratorSpreadInCall_es5.2.minified.js @@ -9,7 +9,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var arr, tmp = Symbol.iterator, SymbolIterator = function() { +var tmp = Symbol.iterator, SymbolIterator = function() { "use strict"; var Constructor, protoProps, staticProps; function SymbolIterator() { @@ -36,16 +36,18 @@ var arr, tmp = Symbol.iterator, SymbolIterator = function() { ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), SymbolIterator; }(); (function(s) {}).apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = new SymbolIterator) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(new SymbolIterator)); diff --git a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.2.minified.js b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.2.minified.js index 05b312c9ffb..a912e875fa7 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.2.minified.js @@ -1,7 +1,21 @@ -var B, C, DD, E, F, G, H, I, J, K, L, B, G, H, I, J, K, L; -(B = B || (B = {}))[B.Member = 0] = "Member"; +var B, C, DD, E, F, G, H, I, J, K, L; +!function(B) { + B[B.Member = 0] = "Member"; +}(B || (B = {})); export { C }; export { DD as D }; export { E as EE }; export { F as FF }; -(G = G || (G = {}))[G.A = 1] = "A", G[G.B = 2] = "B", G[G.C = 3] = "C", (H = H || (H = {})).A = "a", H.B = "b", (I = I || (I = {}))[I.A = "a"] = "a", I[I.B = 0] = 0, I[I.C = 1] = "C", (J = J || (J = {}))[J.A = 1] = "A", J[J.B = 2] = "B", J[J.C = 3] = "C", (K = K || (K = {}))[K.None = 0] = "None", K[K.A = 1] = "A", K[K.B = 2] = "B", K[K.C = 4] = "C", K[K.Mask = 7] = "Mask", (L = L || (L = {}))[L.None = 0] = "None", L[L.A = 1] = "A", L[L.B = 2] = "B", L[L.C = 4] = "C", L[L.Mask = 7] = "Mask"; +!function(G) { + G[G.A = 1] = "A", G[G.B = 2] = "B", G[G.C = 3] = "C"; +}(G || (G = {})), (function(H) { + H.A = "a", H.B = "b"; +})(H || (H = {})), (function(I) { + I[I.A = "a"] = "a", I[I.B = 0] = 0, I[I.C = 1] = "C"; +})(I || (I = {})), (function(J) { + J[J.A = 1] = "A", J[J.B = 2] = "B", J[J.C = 3] = "C"; +})(J || (J = {})), (function(K) { + K[K.None = 0] = "None", K[K.A = 1] = "A", K[K.B = 2] = "B", K[K.C = 4] = "C", K[K.Mask = 7] = "Mask"; +})(K || (K = {})), (function(L) { + L[L.None = 0] = "None", L[L.A = 1] = "A", L[L.B = 2] = "B", L[L.C = 4] = "C", L[L.Mask = 7] = "Mask"; +})(L || (L = {})); diff --git a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.2.minified.js b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.2.minified.js index 05b312c9ffb..a912e875fa7 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.2.minified.js @@ -1,7 +1,21 @@ -var B, C, DD, E, F, G, H, I, J, K, L, B, G, H, I, J, K, L; -(B = B || (B = {}))[B.Member = 0] = "Member"; +var B, C, DD, E, F, G, H, I, J, K, L; +!function(B) { + B[B.Member = 0] = "Member"; +}(B || (B = {})); export { C }; export { DD as D }; export { E as EE }; export { F as FF }; -(G = G || (G = {}))[G.A = 1] = "A", G[G.B = 2] = "B", G[G.C = 3] = "C", (H = H || (H = {})).A = "a", H.B = "b", (I = I || (I = {}))[I.A = "a"] = "a", I[I.B = 0] = 0, I[I.C = 1] = "C", (J = J || (J = {}))[J.A = 1] = "A", J[J.B = 2] = "B", J[J.C = 3] = "C", (K = K || (K = {}))[K.None = 0] = "None", K[K.A = 1] = "A", K[K.B = 2] = "B", K[K.C = 4] = "C", K[K.Mask = 7] = "Mask", (L = L || (L = {}))[L.None = 0] = "None", L[L.A = 1] = "A", L[L.B = 2] = "B", L[L.C = 4] = "C", L[L.Mask = 7] = "Mask"; +!function(G) { + G[G.A = 1] = "A", G[G.B = 2] = "B", G[G.C = 3] = "C"; +}(G || (G = {})), (function(H) { + H.A = "a", H.B = "b"; +})(H || (H = {})), (function(I) { + I[I.A = "a"] = "a", I[I.B = 0] = 0, I[I.C = 1] = "C"; +})(I || (I = {})), (function(J) { + J[J.A = 1] = "A", J[J.B = 2] = "B", J[J.C = 3] = "C"; +})(J || (J = {})), (function(K) { + K[K.None = 0] = "None", K[K.A = 1] = "A", K[K.B = 2] = "B", K[K.C = 4] = "C", K[K.Mask = 7] = "Mask"; +})(K || (K = {})), (function(L) { + L[L.None = 0] = "None", L[L.A = 1] = "A", L[L.B = 2] = "B", L[L.C = 4] = "C", L[L.Mask = 7] = "Mask"; +})(L || (L = {})); diff --git a/crates/swc/tests/tsc-references/jsDeclarationsTypeReferences4_es2015.2.minified.js b/crates/swc/tests/tsc-references/jsDeclarationsTypeReferences4_es2015.2.minified.js index c25bcf0efb6..4ab531ad726 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsTypeReferences4_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsTypeReferences4_es2015.2.minified.js @@ -1,6 +1,8 @@ -var A, A1; export const Something = 2; -!function(B) { - const Something1 = require("fs").Something; - new Something1(); -}((A1 = A || (A = {})).B || (A1.B = {})); +export var A; +!function(A1) { + !function(B) { + const Something1 = require("fs").Something; + new Something1(); + }(A1.B || (A1.B = {})); +}(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/jsDeclarationsTypeReferences4_es5.2.minified.js b/crates/swc/tests/tsc-references/jsDeclarationsTypeReferences4_es5.2.minified.js index 133aa308c92..89f2d229420 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsTypeReferences4_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsTypeReferences4_es5.2.minified.js @@ -1,3 +1,4 @@ -var A, A1, Something = 2; -export { A1 as A }; -(A = A1 || (A1 = {})).B || (A.B = {}), new (require("fs")).Something(); +export var A, Something = 2; +!function(A1) { + A1.B || (A1.B = {}), new (require("fs")).Something(); +}(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/keyofAndIndexedAccess_es2015.2.minified.js b/crates/swc/tests/tsc-references/keyofAndIndexedAccess_es2015.2.minified.js index 14eba47f81f..2875827d267 100644 --- a/crates/swc/tests/tsc-references/keyofAndIndexedAccess_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/keyofAndIndexedAccess_es2015.2.minified.js @@ -1,5 +1,7 @@ -var E, E, Flag, Flag; -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C", one(()=>{}), on({ +var E, Flag; +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})), one(()=>{}), on({ test: ()=>{} }), on({ test: (x)=>{} @@ -25,4 +27,6 @@ new class extends SampleClass { foo: "bar" })); } -}({}), (Flag = Flag || (Flag = {})).FLAG_1 = "flag_1", Flag.FLAG_2 = "flag_2"; +}({}), (function(Flag) { + Flag.FLAG_1 = "flag_1", Flag.FLAG_2 = "flag_2"; +})(Flag || (Flag = {})); diff --git a/crates/swc/tests/tsc-references/keyofAndIndexedAccess_es5.2.minified.js b/crates/swc/tests/tsc-references/keyofAndIndexedAccess_es5.2.minified.js index 530f52f217f..c97a10c342d 100644 --- a/crates/swc/tests/tsc-references/keyofAndIndexedAccess_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/keyofAndIndexedAccess_es5.2.minified.js @@ -53,7 +53,7 @@ function _createSuper(Derived) { })(self); }; } -var Flag, E, Flag, E, Shape = function() { +var E, Flag, Shape = function() { "use strict"; _classCallCheck(this, Shape); }, TaggedShape = function(Shape1) { @@ -77,7 +77,9 @@ function getProperty(obj, key) { function setProperty(obj, key, value) { obj[key] = value; } -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})); var Component = function() { "use strict"; function Component() { @@ -238,7 +240,9 @@ var A = function() { } ]), AnotherSampleClass; }(SampleClass); -new AnotherSampleClass({}), (Flag = Flag || (Flag = {})).FLAG_1 = "flag_1", Flag.FLAG_2 = "flag_2"; +new AnotherSampleClass({}), (function(Flag) { + Flag.FLAG_1 = "flag_1", Flag.FLAG_2 = "flag_2"; +})(Flag || (Flag = {})); var Unbounded = function() { "use strict"; function Unbounded() { diff --git a/crates/swc/tests/tsc-references/literalTypeWidening_es2015.2.minified.js b/crates/swc/tests/tsc-references/literalTypeWidening_es2015.2.minified.js index 2a0fd351499..1fa5f7773e0 100644 --- a/crates/swc/tests/tsc-references/literalTypeWidening_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/literalTypeWidening_es2015.2.minified.js @@ -1,4 +1,4 @@ -var E, E; +var E; export function Set(...keys1) { const result = {}; return keys1.forEach((key)=>result[key] = !0 @@ -12,4 +12,6 @@ export const langCodes = keys(langCodeSet); langCodes.map((code)=>({ code }) -), (E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", f(E.A); +), (function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B"; +})(E || (E = {})), f(E.A); diff --git a/crates/swc/tests/tsc-references/literalTypeWidening_es5.2.minified.js b/crates/swc/tests/tsc-references/literalTypeWidening_es5.2.minified.js index 8742c4a8505..f35d9ea7c0e 100644 --- a/crates/swc/tests/tsc-references/literalTypeWidening_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/literalTypeWidening_es5.2.minified.js @@ -1,4 +1,4 @@ -var E, E; +var E; export function Set() { for(var _len = arguments.length, keys1 = new Array(_len), _key = 0; _key < _len; _key++)keys1[_key] = arguments[_key]; var result = {}; @@ -15,4 +15,6 @@ langCodes.map(function(code) { return { code: code }; -}), (E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", f(E.A); +}), (function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B"; +})(E || (E = {})), f(E.A); diff --git a/crates/swc/tests/tsc-references/literalTypes2_es2015.2.minified.js b/crates/swc/tests/tsc-references/literalTypes2_es2015.2.minified.js index d5e5bce5dc5..cf8401cb683 100644 --- a/crates/swc/tests/tsc-references/literalTypes2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/literalTypes2_es2015.2.minified.js @@ -1,5 +1,7 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +var E; +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})); const a = [ 1, 2 diff --git a/crates/swc/tests/tsc-references/literalTypes2_es5.2.minified.js b/crates/swc/tests/tsc-references/literalTypes2_es5.2.minified.js index 1566455c0ed..11d925f21c8 100644 --- a/crates/swc/tests/tsc-references/literalTypes2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/literalTypes2_es5.2.minified.js @@ -7,8 +7,10 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; -var E, E, cond, C1 = function() { +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})); +var E, cond, C1 = function() { "use strict"; _classCallCheck(this, C1), this.x1 = 1, this.x2 = -123, this.x3 = 7, this.x4 = "abc", this.x5 = "", this.x6 = "abcdef", this.x7 = !0, this.x8 = E.A, this.c1 = 1, this.c2 = -123, this.c3 = 7, this.c4 = "abc", this.c5 = "", this.c6 = "abcdef", this.c7 = !0, this.c8 = E.A; }, C2 = function() { diff --git a/crates/swc/tests/tsc-references/logicalNotOperatorWithEnumType_es2015.2.minified.js b/crates/swc/tests/tsc-references/logicalNotOperatorWithEnumType_es2015.2.minified.js index 000ecb41e19..d29c34dc3e5 100644 --- a/crates/swc/tests/tsc-references/logicalNotOperatorWithEnumType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/logicalNotOperatorWithEnumType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var ENUM, ENUM; -(ENUM = ENUM || (ENUM = {}))[ENUM.A = 0] = "A", ENUM[ENUM.B = 1] = "B", ENUM[ENUM.C = 2] = "C", ENUM.B, ENUM.B + ENUM.C, ENUM.B + ENUM.C, ENUM.B; +var ENUM; +!function(ENUM) { + ENUM[ENUM.A = 0] = "A", ENUM[ENUM.B = 1] = "B", ENUM[ENUM.C = 2] = "C"; +}(ENUM || (ENUM = {})), ENUM.B, ENUM.B + ENUM.C, ENUM.B + ENUM.C, ENUM.B; diff --git a/crates/swc/tests/tsc-references/logicalNotOperatorWithEnumType_es5.2.minified.js b/crates/swc/tests/tsc-references/logicalNotOperatorWithEnumType_es5.2.minified.js index 000ecb41e19..d29c34dc3e5 100644 --- a/crates/swc/tests/tsc-references/logicalNotOperatorWithEnumType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/logicalNotOperatorWithEnumType_es5.2.minified.js @@ -1,2 +1,4 @@ -var ENUM, ENUM; -(ENUM = ENUM || (ENUM = {}))[ENUM.A = 0] = "A", ENUM[ENUM.B = 1] = "B", ENUM[ENUM.C = 2] = "C", ENUM.B, ENUM.B + ENUM.C, ENUM.B + ENUM.C, ENUM.B; +var ENUM; +!function(ENUM) { + ENUM[ENUM.A = 0] = "A", ENUM[ENUM.B = 1] = "B", ENUM[ENUM.C = 2] = "C"; +}(ENUM || (ENUM = {})), ENUM.B, ENUM.B + ENUM.C, ENUM.B + ENUM.C, ENUM.B; diff --git a/crates/swc/tests/tsc-references/mappedTypeOverlappingStringEnumKeys_es2015.2.minified.js b/crates/swc/tests/tsc-references/mappedTypeOverlappingStringEnumKeys_es2015.2.minified.js index 5a143de2505..af19cf49339 100644 --- a/crates/swc/tests/tsc-references/mappedTypeOverlappingStringEnumKeys_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/mappedTypeOverlappingStringEnumKeys_es2015.2.minified.js @@ -1,2 +1,6 @@ -var TerrestrialAnimalTypes, AlienAnimalTypes, TerrestrialAnimalTypes, AlienAnimalTypes; -(TerrestrialAnimalTypes = TerrestrialAnimalTypes || (TerrestrialAnimalTypes = {})).CAT = "cat", TerrestrialAnimalTypes.DOG = "dog", (AlienAnimalTypes = AlienAnimalTypes || (AlienAnimalTypes = {})).CAT = "cat", TerrestrialAnimalTypes.CAT, AlienAnimalTypes.CAT; +var TerrestrialAnimalTypes, AlienAnimalTypes; +!function(TerrestrialAnimalTypes) { + TerrestrialAnimalTypes.CAT = "cat", TerrestrialAnimalTypes.DOG = "dog"; +}(TerrestrialAnimalTypes || (TerrestrialAnimalTypes = {})), (function(AlienAnimalTypes) { + AlienAnimalTypes.CAT = "cat"; +})(AlienAnimalTypes || (AlienAnimalTypes = {})), TerrestrialAnimalTypes.CAT, AlienAnimalTypes.CAT; diff --git a/crates/swc/tests/tsc-references/mappedTypeOverlappingStringEnumKeys_es5.2.minified.js b/crates/swc/tests/tsc-references/mappedTypeOverlappingStringEnumKeys_es5.2.minified.js index 5a143de2505..af19cf49339 100644 --- a/crates/swc/tests/tsc-references/mappedTypeOverlappingStringEnumKeys_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/mappedTypeOverlappingStringEnumKeys_es5.2.minified.js @@ -1,2 +1,6 @@ -var TerrestrialAnimalTypes, AlienAnimalTypes, TerrestrialAnimalTypes, AlienAnimalTypes; -(TerrestrialAnimalTypes = TerrestrialAnimalTypes || (TerrestrialAnimalTypes = {})).CAT = "cat", TerrestrialAnimalTypes.DOG = "dog", (AlienAnimalTypes = AlienAnimalTypes || (AlienAnimalTypes = {})).CAT = "cat", TerrestrialAnimalTypes.CAT, AlienAnimalTypes.CAT; +var TerrestrialAnimalTypes, AlienAnimalTypes; +!function(TerrestrialAnimalTypes) { + TerrestrialAnimalTypes.CAT = "cat", TerrestrialAnimalTypes.DOG = "dog"; +}(TerrestrialAnimalTypes || (TerrestrialAnimalTypes = {})), (function(AlienAnimalTypes) { + AlienAnimalTypes.CAT = "cat"; +})(AlienAnimalTypes || (AlienAnimalTypes = {})), TerrestrialAnimalTypes.CAT, AlienAnimalTypes.CAT; diff --git a/crates/swc/tests/tsc-references/mixinAbstractClasses.2_es2015.2.minified.js b/crates/swc/tests/tsc-references/mixinAbstractClasses.2_es2015.2.minified.js index a5460caabbf..f40c1e4e49c 100644 --- a/crates/swc/tests/tsc-references/mixinAbstractClasses.2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/mixinAbstractClasses.2_es2015.2.minified.js @@ -1,6 +1,7 @@ -var baseClass; -const MixedBase = (baseClass = class { -}, class extends baseClass { - mixinMethod() {} +const MixedBase = function(baseClass) { + return class extends baseClass { + mixinMethod() {} + }; +}(class { }); new MixedBase(); diff --git a/crates/swc/tests/tsc-references/nameCollision_es2015.2.minified.js b/crates/swc/tests/tsc-references/nameCollision_es2015.2.minified.js index d71910149d7..78bb46bd295 100644 --- a/crates/swc/tests/tsc-references/nameCollision_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/nameCollision_es2015.2.minified.js @@ -1,5 +1,7 @@ -var X, Y, D, X1; -(X1 = X || (X = {})).Y || (X1.Y = {}), (function(Y3) { +var X, Y, D; +!function(X1) { + X1.Y || (X1.Y = {}); +}(X || (X = {})), (function(Y3) { var Y1, Y2; let Y2, Y2; (Y2 = Y2 = (Y1 = Y2 = Y3.Y || (Y3.Y = {})).Y || (Y1.Y = {}))[Y2.Red = 0] = "Red", Y2[Y2.Blue = 1] = "Blue"; diff --git a/crates/swc/tests/tsc-references/nameCollision_es5.2.minified.js b/crates/swc/tests/tsc-references/nameCollision_es5.2.minified.js index 7479ca33d00..476bcfd64ca 100644 --- a/crates/swc/tests/tsc-references/nameCollision_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/nameCollision_es5.2.minified.js @@ -1,4 +1,4 @@ -var B, X, Y, D, X1; +var B, X, Y, D; !function(B) { var B1 = function() { "use strict"; @@ -6,7 +6,9 @@ var B, X, Y, D, X1; if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, B1); }; -}(B || (B = {})), (X1 = X || (X = {})).Y || (X1.Y = {}), (function(Y3) { +}(B || (B = {})), (function(X1) { + X1.Y || (X1.Y = {}); +})(X || (X = {})), (function(Y3) { var Y1, Y2, Y1, Y1; (Y1 = Y1 = (Y2 = Y1 = Y3.Y || (Y3.Y = {})).Y || (Y2.Y = {}))[Y1.Red = 0] = "Red", Y1[Y1.Blue = 1] = "Blue"; })(Y || (Y = {})), (D || (D = {})).E = "hello"; diff --git a/crates/swc/tests/tsc-references/namedTupleMembers_es5.2.minified.js b/crates/swc/tests/tsc-references/namedTupleMembers_es5.2.minified.js index 52b4be926a3..6e9a955f95d 100644 --- a/crates/swc/tests/tsc-references/namedTupleMembers_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/namedTupleMembers_es5.2.minified.js @@ -45,9 +45,11 @@ export var val = null; r = q = r, y = x = y; export var argumentsOfGAsFirstArgument = f(getArgsForInjection(g)); export var argumentsOfG = f.apply(void 0, function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -}(arr = getArgsForInjection(g)) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -}(arr) || _unsupportedIterableToArray(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); // captured arguments list re-spread + return (function(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr) || (function() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}(getArgsForInjection(g))); // captured arguments list re-spread diff --git a/crates/swc/tests/tsc-references/negateOperatorWithEnumType_es2015.2.minified.js b/crates/swc/tests/tsc-references/negateOperatorWithEnumType_es2015.2.minified.js index 10518a6b384..0d4e607cd1a 100644 --- a/crates/swc/tests/tsc-references/negateOperatorWithEnumType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/negateOperatorWithEnumType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ENUM1.B, ENUM1.B + ENUM1[""], ENUM1.B; +var ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ENUM1.B, ENUM1.B + ENUM1[""], ENUM1.B; diff --git a/crates/swc/tests/tsc-references/negateOperatorWithEnumType_es5.2.minified.js b/crates/swc/tests/tsc-references/negateOperatorWithEnumType_es5.2.minified.js index 10518a6b384..0d4e607cd1a 100644 --- a/crates/swc/tests/tsc-references/negateOperatorWithEnumType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/negateOperatorWithEnumType_es5.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ENUM1.B, ENUM1.B + ENUM1[""], ENUM1.B; +var ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ENUM1.B, ENUM1.B + ENUM1[""], ENUM1.B; diff --git a/crates/swc/tests/tsc-references/noUncheckedIndexedAccess_es2015.2.minified.js b/crates/swc/tests/tsc-references/noUncheckedIndexedAccess_es2015.2.minified.js index 9076a83500a..01e1ba3128d 100644 --- a/crates/swc/tests/tsc-references/noUncheckedIndexedAccess_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/noUncheckedIndexedAccess_es2015.2.minified.js @@ -1,4 +1,10 @@ -var NumericEnum1, NumericEnum2, StringEnum1, NumericEnum1, NumericEnum2, StringEnum1; -(NumericEnum1 = NumericEnum1 || (NumericEnum1 = {}))[NumericEnum1.A = 0] = "A", NumericEnum1[NumericEnum1.B = 1] = "B", NumericEnum1[NumericEnum1.C = 2] = "C", (NumericEnum2 = NumericEnum2 || (NumericEnum2 = {}))[NumericEnum2.A = 0] = "A", NumericEnum2[NumericEnum2.B = 1] = "B", NumericEnum2[NumericEnum2.C = 2] = "C", (StringEnum1 = StringEnum1 || (StringEnum1 = {})).A = "Alpha", StringEnum1.B = "Beta", strMap[0], strMap[0], strMap[0], strMap[0], strMap[NumericEnum1.A], strMap[NumericEnum2.A], strMap[StringEnum1.A], strMap[StringEnum1.A], strMap[NumericEnum1.A], strMap[NumericEnum2.A], strMap[null], strMap.baz = void 0, strMap.qua = void 0, strMap[0] = void 0, strMap[null] = void 0, numMap[0], numMap[0], numMap[0], numMap[NumericEnum1.A], numMap[NumericEnum2.A], symbolMap[s], symbolMap[s] = void 0, nonEmptyStringArray[0], nonEmptyStringArray[1], (key)=>{ +var NumericEnum1, NumericEnum2, StringEnum1; +(function(NumericEnum1) { + NumericEnum1[NumericEnum1.A = 0] = "A", NumericEnum1[NumericEnum1.B = 1] = "B", NumericEnum1[NumericEnum1.C = 2] = "C"; +})(NumericEnum1 || (NumericEnum1 = {})), (function(NumericEnum2) { + NumericEnum2[NumericEnum2.A = 0] = "A", NumericEnum2[NumericEnum2.B = 1] = "B", NumericEnum2[NumericEnum2.C = 2] = "C"; +})(NumericEnum2 || (NumericEnum2 = {})), (function(StringEnum1) { + StringEnum1.A = "Alpha", StringEnum1.B = "Beta"; +})(StringEnum1 || (StringEnum1 = {})), strMap[0], strMap[0], strMap[0], strMap[0], strMap[NumericEnum1.A], strMap[NumericEnum2.A], strMap[StringEnum1.A], strMap[StringEnum1.A], strMap[NumericEnum1.A], strMap[NumericEnum2.A], strMap[null], strMap.baz = void 0, strMap.qua = void 0, strMap[0] = void 0, strMap[null] = void 0, numMap[0], numMap[0], numMap[0], numMap[NumericEnum1.A], numMap[NumericEnum2.A], symbolMap[s], symbolMap[s] = void 0, nonEmptyStringArray[0], nonEmptyStringArray[1], (key)=>{ myRecord2[key] = void 0, myRecord2[key]; }; diff --git a/crates/swc/tests/tsc-references/noUncheckedIndexedAccess_es5.2.minified.js b/crates/swc/tests/tsc-references/noUncheckedIndexedAccess_es5.2.minified.js index 8957c77cb15..810892dfa93 100644 --- a/crates/swc/tests/tsc-references/noUncheckedIndexedAccess_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/noUncheckedIndexedAccess_es5.2.minified.js @@ -1,2 +1,8 @@ -var NumericEnum1, NumericEnum2, StringEnum1, NumericEnum1, NumericEnum2, StringEnum1; -(NumericEnum1 = NumericEnum1 || (NumericEnum1 = {}))[NumericEnum1.A = 0] = "A", NumericEnum1[NumericEnum1.B = 1] = "B", NumericEnum1[NumericEnum1.C = 2] = "C", (NumericEnum2 = NumericEnum2 || (NumericEnum2 = {}))[NumericEnum2.A = 0] = "A", NumericEnum2[NumericEnum2.B = 1] = "B", NumericEnum2[NumericEnum2.C = 2] = "C", (StringEnum1 = StringEnum1 || (StringEnum1 = {})).A = "Alpha", StringEnum1.B = "Beta", strMap[0], strMap[0], strMap[0], strMap[0], strMap[NumericEnum1.A], strMap[NumericEnum2.A], strMap[StringEnum1.A], strMap[StringEnum1.A], strMap[NumericEnum1.A], strMap[NumericEnum2.A], strMap[null], strMap.baz = void 0, strMap.qua = void 0, strMap[0] = void 0, strMap[null] = void 0, numMap[0], numMap[0], numMap[0], numMap[NumericEnum1.A], numMap[NumericEnum2.A], symbolMap[s], symbolMap[s] = void 0, nonEmptyStringArray[0], nonEmptyStringArray[1]; +var NumericEnum1, NumericEnum2, StringEnum1; +(function(NumericEnum1) { + NumericEnum1[NumericEnum1.A = 0] = "A", NumericEnum1[NumericEnum1.B = 1] = "B", NumericEnum1[NumericEnum1.C = 2] = "C"; +})(NumericEnum1 || (NumericEnum1 = {})), (function(NumericEnum2) { + NumericEnum2[NumericEnum2.A = 0] = "A", NumericEnum2[NumericEnum2.B = 1] = "B", NumericEnum2[NumericEnum2.C = 2] = "C"; +})(NumericEnum2 || (NumericEnum2 = {})), (function(StringEnum1) { + StringEnum1.A = "Alpha", StringEnum1.B = "Beta"; +})(StringEnum1 || (StringEnum1 = {})), strMap[0], strMap[0], strMap[0], strMap[0], strMap[NumericEnum1.A], strMap[NumericEnum2.A], strMap[StringEnum1.A], strMap[StringEnum1.A], strMap[NumericEnum1.A], strMap[NumericEnum2.A], strMap[null], strMap.baz = void 0, strMap.qua = void 0, strMap[0] = void 0, strMap[null] = void 0, numMap[0], numMap[0], numMap[0], numMap[NumericEnum1.A], numMap[NumericEnum2.A], symbolMap[s], symbolMap[s] = void 0, nonEmptyStringArray[0], nonEmptyStringArray[1]; diff --git a/crates/swc/tests/tsc-references/nonInstantiatedModule_es2015.2.minified.js b/crates/swc/tests/tsc-references/nonInstantiatedModule_es2015.2.minified.js index 6ea39dd9d53..a86987a559a 100644 --- a/crates/swc/tests/tsc-references/nonInstantiatedModule_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/nonInstantiatedModule_es2015.2.minified.js @@ -1,9 +1,11 @@ (M || (M = {})).a = 1; -var M, m, M2, M3, M21, m = M; -m.a, ((M21 = M2 || (M2 = {})).Point || (M21.Point = {})).Origin = function() { - return { - x: 0, - y: 0 +var M, m, M2, M3, m = M; +m.a, (function(M21) { + (M21.Point || (M21.Point = {})).Origin = function() { + return { + x: 0, + y: 0 + }; }; -}, (M3 || (M3 = {})).Utils = class { +})(M2 || (M2 = {})), (M3 || (M3 = {})).Utils = class { }; diff --git a/crates/swc/tests/tsc-references/nonInstantiatedModule_es5.2.minified.js b/crates/swc/tests/tsc-references/nonInstantiatedModule_es5.2.minified.js index 461781f436e..9a679eff023 100644 --- a/crates/swc/tests/tsc-references/nonInstantiatedModule_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/nonInstantiatedModule_es5.2.minified.js @@ -1,11 +1,13 @@ (M || (M = {})).a = 1; -var M, m, M2, M3, M21, m = M; -m.a, ((M21 = M2 || (M2 = {})).Point || (M21.Point = {})).Origin = function() { - return { - x: 0, - y: 0 +var M, m, M2, M3, m = M; +m.a, (function(M21) { + (M21.Point || (M21.Point = {})).Origin = function() { + return { + x: 0, + y: 0 + }; }; -}, (function(M31) { +})(M2 || (M2 = {})), (function(M31) { var Utils = function() { "use strict"; !function(instance, Constructor) { diff --git a/crates/swc/tests/tsc-references/nonPrimitiveNarrow_es5.2.minified.js b/crates/swc/tests/tsc-references/nonPrimitiveNarrow_es5.2.minified.js index 64b2f5edc2c..04f08d5de95 100644 --- a/crates/swc/tests/tsc-references/nonPrimitiveNarrow_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/nonPrimitiveNarrow_es5.2.minified.js @@ -1,7 +1,9 @@ -var a, b, left, right, Narrow = function() { +var a, b, Narrow = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, Narrow); }; -left = a, (null != (right = Narrow) && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right) && (a.narrowed, a = 123), "number" == typeof a && a.toFixed(), b.toString(); +(function(left, right) { + return null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right; +})(a, Narrow) && (a.narrowed, a = 123), "number" == typeof a && a.toFixed(), b.toString(); diff --git a/crates/swc/tests/tsc-references/nullAssignableToEveryType_es2015.2.minified.js b/crates/swc/tests/tsc-references/nullAssignableToEveryType_es2015.2.minified.js index 5f410993c04..4f81f678e53 100644 --- a/crates/swc/tests/tsc-references/nullAssignableToEveryType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/nullAssignableToEveryType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A"; +var E; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/nullAssignableToEveryType_es5.2.minified.js b/crates/swc/tests/tsc-references/nullAssignableToEveryType_es5.2.minified.js index f70e6cc54e8..9eba7da8a34 100644 --- a/crates/swc/tests/tsc-references/nullAssignableToEveryType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/nullAssignableToEveryType_es5.2.minified.js @@ -1,7 +1,9 @@ -var E, E, C = function() { +var E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -(E = E || (E = {}))[E.A = 0] = "A"; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/nullIsSubtypeOfEverythingButUndefined_es2015.2.minified.js b/crates/swc/tests/tsc-references/nullIsSubtypeOfEverythingButUndefined_es2015.2.minified.js index 01db8f87ba9..c77049a3b9e 100644 --- a/crates/swc/tests/tsc-references/nullIsSubtypeOfEverythingButUndefined_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/nullIsSubtypeOfEverythingButUndefined_es2015.2.minified.js @@ -1,6 +1,8 @@ -var E, E; +var E; function f() {} -new Date(), (E = E || (E = {}))[E.A = 0] = "A", E.A, (f || (f = {})).bar = 1; +new Date(), (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), E.A, (f || (f = {})).bar = 1; class c { } (c || (c = {})).bar = 1, new Object(); diff --git a/crates/swc/tests/tsc-references/nullIsSubtypeOfEverythingButUndefined_es5.2.minified.js b/crates/swc/tests/tsc-references/nullIsSubtypeOfEverythingButUndefined_es5.2.minified.js index 58d742adcdd..58bbd8dfbd1 100644 --- a/crates/swc/tests/tsc-references/nullIsSubtypeOfEverythingButUndefined_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/nullIsSubtypeOfEverythingButUndefined_es5.2.minified.js @@ -10,8 +10,10 @@ var C1 = function() { _classCallCheck(this, C2); }; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", (f || (f = {})).bar = 1; -var E, E, c = function() { +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), E.A, (f || (f = {})).bar = 1; +var E, c = function() { "use strict"; _classCallCheck(this, c); }; diff --git a/crates/swc/tests/tsc-references/nullishCoalescingOperatorInParameterBindingPattern.2_es5.2.minified.js b/crates/swc/tests/tsc-references/nullishCoalescingOperatorInParameterBindingPattern.2_es5.2.minified.js index cd6a13c43d3..85a5ab08e8e 100644 --- a/crates/swc/tests/tsc-references/nullishCoalescingOperatorInParameterBindingPattern.2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/nullishCoalescingOperatorInParameterBindingPattern.2_es5.2.minified.js @@ -1,2 +1,4 @@ -var param, ref, ref1, a = function() {}; -(void 0)[null !== (ref = a()) && void 0 !== ref ? ref : "d"], param[null !== (ref1 = a()) && void 0 !== ref1 ? ref1 : "d"], param.d; +var ref, ref1, a = function() {}; +(void 0)[null !== (ref = a()) && void 0 !== ref ? ref : "d"], (function(param) { + param[null !== (ref1 = a()) && void 0 !== ref1 ? ref1 : "d"], param.d; +})(); diff --git a/crates/swc/tests/tsc-references/numberAssignableToEnum_es2015.2.minified.js b/crates/swc/tests/tsc-references/numberAssignableToEnum_es2015.2.minified.js index 86a14832585..6d045d2c133 100644 --- a/crates/swc/tests/tsc-references/numberAssignableToEnum_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/numberAssignableToEnum_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, n, E; -(E = E || (E = {}))[E.A = 0] = "A", n = n; +var E, n; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), n = n; diff --git a/crates/swc/tests/tsc-references/numberAssignableToEnum_es5.2.minified.js b/crates/swc/tests/tsc-references/numberAssignableToEnum_es5.2.minified.js index 86a14832585..6d045d2c133 100644 --- a/crates/swc/tests/tsc-references/numberAssignableToEnum_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/numberAssignableToEnum_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, n, E; -(E = E || (E = {}))[E.A = 0] = "A", n = n; +var E, n; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), n = n; diff --git a/crates/swc/tests/tsc-references/objectTypesIdentity2_es2015.2.minified.js b/crates/swc/tests/tsc-references/objectTypesIdentity2_es2015.2.minified.js index 9b0af19df18..670bc37f0d8 100644 --- a/crates/swc/tests/tsc-references/objectTypesIdentity2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/objectTypesIdentity2_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A", E.A; +var E; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), E.A; diff --git a/crates/swc/tests/tsc-references/objectTypesIdentity2_es5.2.minified.js b/crates/swc/tests/tsc-references/objectTypesIdentity2_es5.2.minified.js index 1642b830254..a698909a98c 100644 --- a/crates/swc/tests/tsc-references/objectTypesIdentity2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/objectTypesIdentity2_es5.2.minified.js @@ -1,7 +1,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -var E, E, A = function() { +var E, A = function() { "use strict"; _classCallCheck(this, A); }, B = function() { @@ -11,4 +11,6 @@ var E, E, A = function() { "use strict"; _classCallCheck(this, C); }; -(E = E || (E = {}))[E.A = 0] = "A", E.A; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), E.A; diff --git a/crates/swc/tests/tsc-references/parserComputedPropertyName2_es5.2.minified.js b/crates/swc/tests/tsc-references/parserComputedPropertyName2_es5.2.minified.js index 8c10a27503a..48039d0fa58 100644 --- a/crates/swc/tests/tsc-references/parserComputedPropertyName2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserComputedPropertyName2_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -obj = {}, value = 1, (key = e) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, e, 1); diff --git a/crates/swc/tests/tsc-references/parserComputedPropertyName41_es5.2.minified.js b/crates/swc/tests/tsc-references/parserComputedPropertyName41_es5.2.minified.js index 77150f01e1c..883cf621570 100644 --- a/crates/swc/tests/tsc-references/parserComputedPropertyName41_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserComputedPropertyName41_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -value = !0, (key = 0 in []) in (obj = {}) ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, 0 in [], !0); diff --git a/crates/swc/tests/tsc-references/parserES5ComputedPropertyName2_es5.2.minified.js b/crates/swc/tests/tsc-references/parserES5ComputedPropertyName2_es5.2.minified.js index 8c10a27503a..48039d0fa58 100644 --- a/crates/swc/tests/tsc-references/parserES5ComputedPropertyName2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserES5ComputedPropertyName2_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -obj = {}, value = 1, (key = e) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, e, 1); diff --git a/crates/swc/tests/tsc-references/parserEnum1_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserEnum1_es2015.2.minified.js index 8f3ee507938..be5a6735660 100644 --- a/crates/swc/tests/tsc-references/parserEnum1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnum1_es2015.2.minified.js @@ -1,2 +1,4 @@ -var SignatureFlags, SignatureFlags; -(SignatureFlags = SignatureFlags || (SignatureFlags = {}))[SignatureFlags.None = 0] = "None", SignatureFlags[SignatureFlags.IsIndexer = 1] = "IsIndexer", SignatureFlags[SignatureFlags.IsStringIndexer = 2] = "IsStringIndexer", SignatureFlags[SignatureFlags.IsNumberIndexer = 4] = "IsNumberIndexer"; +export var SignatureFlags; +!function(SignatureFlags) { + SignatureFlags[SignatureFlags.None = 0] = "None", SignatureFlags[SignatureFlags.IsIndexer = 1] = "IsIndexer", SignatureFlags[SignatureFlags.IsStringIndexer = 2] = "IsStringIndexer", SignatureFlags[SignatureFlags.IsNumberIndexer = 4] = "IsNumberIndexer"; +}(SignatureFlags || (SignatureFlags = {})); diff --git a/crates/swc/tests/tsc-references/parserEnum1_es5.2.minified.js b/crates/swc/tests/tsc-references/parserEnum1_es5.2.minified.js index 8f3ee507938..be5a6735660 100644 --- a/crates/swc/tests/tsc-references/parserEnum1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnum1_es5.2.minified.js @@ -1,2 +1,4 @@ -var SignatureFlags, SignatureFlags; -(SignatureFlags = SignatureFlags || (SignatureFlags = {}))[SignatureFlags.None = 0] = "None", SignatureFlags[SignatureFlags.IsIndexer = 1] = "IsIndexer", SignatureFlags[SignatureFlags.IsStringIndexer = 2] = "IsStringIndexer", SignatureFlags[SignatureFlags.IsNumberIndexer = 4] = "IsNumberIndexer"; +export var SignatureFlags; +!function(SignatureFlags) { + SignatureFlags[SignatureFlags.None = 0] = "None", SignatureFlags[SignatureFlags.IsIndexer = 1] = "IsIndexer", SignatureFlags[SignatureFlags.IsStringIndexer = 2] = "IsStringIndexer", SignatureFlags[SignatureFlags.IsNumberIndexer = 4] = "IsNumberIndexer"; +}(SignatureFlags || (SignatureFlags = {})); diff --git a/crates/swc/tests/tsc-references/parserEnum2_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserEnum2_es2015.2.minified.js index 8f3ee507938..be5a6735660 100644 --- a/crates/swc/tests/tsc-references/parserEnum2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnum2_es2015.2.minified.js @@ -1,2 +1,4 @@ -var SignatureFlags, SignatureFlags; -(SignatureFlags = SignatureFlags || (SignatureFlags = {}))[SignatureFlags.None = 0] = "None", SignatureFlags[SignatureFlags.IsIndexer = 1] = "IsIndexer", SignatureFlags[SignatureFlags.IsStringIndexer = 2] = "IsStringIndexer", SignatureFlags[SignatureFlags.IsNumberIndexer = 4] = "IsNumberIndexer"; +export var SignatureFlags; +!function(SignatureFlags) { + SignatureFlags[SignatureFlags.None = 0] = "None", SignatureFlags[SignatureFlags.IsIndexer = 1] = "IsIndexer", SignatureFlags[SignatureFlags.IsStringIndexer = 2] = "IsStringIndexer", SignatureFlags[SignatureFlags.IsNumberIndexer = 4] = "IsNumberIndexer"; +}(SignatureFlags || (SignatureFlags = {})); diff --git a/crates/swc/tests/tsc-references/parserEnum2_es5.2.minified.js b/crates/swc/tests/tsc-references/parserEnum2_es5.2.minified.js index 8f3ee507938..be5a6735660 100644 --- a/crates/swc/tests/tsc-references/parserEnum2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnum2_es5.2.minified.js @@ -1,2 +1,4 @@ -var SignatureFlags, SignatureFlags; -(SignatureFlags = SignatureFlags || (SignatureFlags = {}))[SignatureFlags.None = 0] = "None", SignatureFlags[SignatureFlags.IsIndexer = 1] = "IsIndexer", SignatureFlags[SignatureFlags.IsStringIndexer = 2] = "IsStringIndexer", SignatureFlags[SignatureFlags.IsNumberIndexer = 4] = "IsNumberIndexer"; +export var SignatureFlags; +!function(SignatureFlags) { + SignatureFlags[SignatureFlags.None = 0] = "None", SignatureFlags[SignatureFlags.IsIndexer = 1] = "IsIndexer", SignatureFlags[SignatureFlags.IsStringIndexer = 2] = "IsStringIndexer", SignatureFlags[SignatureFlags.IsNumberIndexer = 4] = "IsNumberIndexer"; +}(SignatureFlags || (SignatureFlags = {})); diff --git a/crates/swc/tests/tsc-references/parserEnum6_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserEnum6_es2015.2.minified.js index 0a57c67acc3..5fa0a6009d6 100644 --- a/crates/swc/tests/tsc-references/parserEnum6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnum6_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +var E; +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/parserEnum6_es5.2.minified.js b/crates/swc/tests/tsc-references/parserEnum6_es5.2.minified.js index 0a57c67acc3..5fa0a6009d6 100644 --- a/crates/swc/tests/tsc-references/parserEnum6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnum6_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +var E; +!function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B", E[E.C = 2] = "C"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/parserEnumDeclaration1_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserEnumDeclaration1_es2015.2.minified.js index 3f831609d33..9f53b481902 100644 --- a/crates/swc/tests/tsc-references/parserEnumDeclaration1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnumDeclaration1_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.Foo = 1] = "Foo", E[E.Bar = 2] = "Bar"; +var E; +!function(E) { + E[E.Foo = 1] = "Foo", E[E.Bar = 2] = "Bar"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/parserEnumDeclaration1_es5.2.minified.js b/crates/swc/tests/tsc-references/parserEnumDeclaration1_es5.2.minified.js index 3f831609d33..9f53b481902 100644 --- a/crates/swc/tests/tsc-references/parserEnumDeclaration1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnumDeclaration1_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.Foo = 1] = "Foo", E[E.Bar = 2] = "Bar"; +var E; +!function(E) { + E[E.Foo = 1] = "Foo", E[E.Bar = 2] = "Bar"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/parserEnumDeclaration3_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserEnumDeclaration3_es2015.2.minified.js index d9a0be6e08a..e4cd7b765d1 100644 --- a/crates/swc/tests/tsc-references/parserEnumDeclaration3_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnumDeclaration3_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 1] = "A"; +var E; +!function(E) { + E[E.A = 1] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/parserEnumDeclaration3_es5.2.minified.js b/crates/swc/tests/tsc-references/parserEnumDeclaration3_es5.2.minified.js index d9a0be6e08a..e4cd7b765d1 100644 --- a/crates/swc/tests/tsc-references/parserEnumDeclaration3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnumDeclaration3_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 1] = "A"; +var E; +!function(E) { + E[E.A = 1] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/parserEnumDeclaration5_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserEnumDeclaration5_es2015.2.minified.js index 80fe57ca317..41007983b60 100644 --- a/crates/swc/tests/tsc-references/parserEnumDeclaration5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnumDeclaration5_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 1] = "A", E[E.B = 2] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D"; +var E; +!function(E) { + E[E.A = 1] = "A", E[E.B = 2] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/parserEnumDeclaration5_es5.2.minified.js b/crates/swc/tests/tsc-references/parserEnumDeclaration5_es5.2.minified.js index 80fe57ca317..41007983b60 100644 --- a/crates/swc/tests/tsc-references/parserEnumDeclaration5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnumDeclaration5_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 1] = "A", E[E.B = 2] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D"; +var E; +!function(E) { + E[E.A = 1] = "A", E[E.B = 2] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/parserEnumDeclaration6_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserEnumDeclaration6_es2015.2.minified.js index 80fe57ca317..41007983b60 100644 --- a/crates/swc/tests/tsc-references/parserEnumDeclaration6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnumDeclaration6_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 1] = "A", E[E.B = 2] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D"; +var E; +!function(E) { + E[E.A = 1] = "A", E[E.B = 2] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/parserEnumDeclaration6_es5.2.minified.js b/crates/swc/tests/tsc-references/parserEnumDeclaration6_es5.2.minified.js index 80fe57ca317..41007983b60 100644 --- a/crates/swc/tests/tsc-references/parserEnumDeclaration6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserEnumDeclaration6_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 1] = "A", E[E.B = 2] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D"; +var E; +!function(E) { + E[E.A = 1] = "A", E[E.B = 2] = "B", E[E.C = 2] = "C", E[E.D = 3] = "D"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum1_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum1_es2015.2.minified.js index 79c7ae0d4af..c9104f9579e 100644 --- a/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum1_es2015.2.minified.js @@ -1,3 +1,5 @@ "use strict"; -var Bar, Bar; -(Bar = Bar || (Bar = {}))[Bar.interface = 0] = "interface"; +var Bar; +!function(Bar) { + Bar[Bar.interface = 0] = "interface"; +}(Bar || (Bar = {})); diff --git a/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum1_es5.2.minified.js b/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum1_es5.2.minified.js index 79c7ae0d4af..c9104f9579e 100644 --- a/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum1_es5.2.minified.js @@ -1,3 +1,5 @@ "use strict"; -var Bar, Bar; -(Bar = Bar || (Bar = {}))[Bar.interface = 0] = "interface"; +var Bar; +!function(Bar) { + Bar[Bar.interface = 0] = "interface"; +}(Bar || (Bar = {})); diff --git a/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum_es2015.2.minified.js index 984ffc40d78..688d98db9ee 100644 --- a/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum_es2015.2.minified.js @@ -1,2 +1,4 @@ -var Bar, Bar; -(Bar = Bar || (Bar = {}))[Bar.interface = 0] = "interface"; +var Bar; +!function(Bar) { + Bar[Bar.interface = 0] = "interface"; +}(Bar || (Bar = {})); diff --git a/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum_es5.2.minified.js b/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum_es5.2.minified.js index 984ffc40d78..688d98db9ee 100644 --- a/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserInterfaceKeywordInEnum_es5.2.minified.js @@ -1,2 +1,4 @@ -var Bar, Bar; -(Bar = Bar || (Bar = {}))[Bar.interface = 0] = "interface"; +var Bar; +!function(Bar) { + Bar[Bar.interface = 0] = "interface"; +}(Bar || (Bar = {})); diff --git a/crates/swc/tests/tsc-references/parserRealSource13_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserRealSource13_es2015.2.minified.js index bb82c939908..cb3363375b2 100644 --- a/crates/swc/tests/tsc-references/parserRealSource13_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserRealSource13_es2015.2.minified.js @@ -1,13 +1,15 @@ -var TypeScript, TypeScript1; -!function(AstWalkerWithDetailCallback) { - function AstWalkerCallback(pre, ast, callback) { - var nodeType = ast.nodeType, callbackString = NodeType._map[nodeType] + "Callback"; - return callback[callbackString] ? callback[callbackString](pre, ast) : !callback.DefaultCallback || callback.DefaultCallback(pre, ast); - } - AstWalkerWithDetailCallback.walk = function(script, callback) { - var walker = TypeScript.getAstWalkerFactory().getWalker((cur, parent)=>(walker.options.goChildren = AstWalkerCallback(!0, cur, callback), cur) - , (cur, parent)=>(AstWalkerCallback(!1, cur, callback), cur) - ); - walker.walk(script, null); - }; -}((TypeScript1 = TypeScript || (TypeScript = {})).AstWalkerWithDetailCallback || (TypeScript1.AstWalkerWithDetailCallback = {})); +var TypeScript; +!function(TypeScript1) { + !function(AstWalkerWithDetailCallback) { + function AstWalkerCallback(pre, ast, callback) { + var nodeType = ast.nodeType, callbackString = NodeType._map[nodeType] + "Callback"; + return callback[callbackString] ? callback[callbackString](pre, ast) : !callback.DefaultCallback || callback.DefaultCallback(pre, ast); + } + AstWalkerWithDetailCallback.walk = function(script, callback) { + var pre = (cur, parent)=>(walker.options.goChildren = AstWalkerCallback(!0, cur, callback), cur) + , post = (cur, parent)=>(AstWalkerCallback(!1, cur, callback), cur) + , walker = TypeScript.getAstWalkerFactory().getWalker(pre, post); + walker.walk(script, null); + }; + }(TypeScript1.AstWalkerWithDetailCallback || (TypeScript1.AstWalkerWithDetailCallback = {})); +}(TypeScript || (TypeScript = {})); diff --git a/crates/swc/tests/tsc-references/parserRealSource13_es5.2.minified.js b/crates/swc/tests/tsc-references/parserRealSource13_es5.2.minified.js index 11ed7073d2a..8d61d31e6e5 100644 --- a/crates/swc/tests/tsc-references/parserRealSource13_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserRealSource13_es5.2.minified.js @@ -1,15 +1,17 @@ -var TypeScript, TypeScript1; -!function(AstWalkerWithDetailCallback) { - function AstWalkerCallback(pre, ast, callback) { - var nodeType = ast.nodeType, callbackString = NodeType._map[nodeType] + "Callback"; - return callback[callbackString] ? callback[callbackString](pre, ast) : !callback.DefaultCallback || callback.DefaultCallback(pre, ast); - } - AstWalkerWithDetailCallback.walk = function(script, callback) { - var walker = TypeScript.getAstWalkerFactory().getWalker(function(cur, parent) { - return walker.options.goChildren = AstWalkerCallback(!0, cur, callback), cur; - }, function(cur, parent) { - return AstWalkerCallback(!1, cur, callback), cur; - }); - walker.walk(script, null); - }; -}((TypeScript1 = TypeScript || (TypeScript = {})).AstWalkerWithDetailCallback || (TypeScript1.AstWalkerWithDetailCallback = {})); +var TypeScript; +!function(TypeScript1) { + !function(AstWalkerWithDetailCallback) { + function AstWalkerCallback(pre, ast, callback) { + var nodeType = ast.nodeType, callbackString = NodeType._map[nodeType] + "Callback"; + return callback[callbackString] ? callback[callbackString](pre, ast) : !callback.DefaultCallback || callback.DefaultCallback(pre, ast); + } + AstWalkerWithDetailCallback.walk = function(script, callback) { + var pre = function(cur, parent) { + return walker.options.goChildren = AstWalkerCallback(!0, cur, callback), cur; + }, post = function(cur, parent) { + return AstWalkerCallback(!1, cur, callback), cur; + }, walker = TypeScript.getAstWalkerFactory().getWalker(pre, post); + walker.walk(script, null); + }; + }(TypeScript1.AstWalkerWithDetailCallback || (TypeScript1.AstWalkerWithDetailCallback = {})); +}(TypeScript || (TypeScript = {})); diff --git a/crates/swc/tests/tsc-references/parserRealSource1_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserRealSource1_es2015.2.minified.js index 966bb82cbf9..2e661b95fc6 100644 --- a/crates/swc/tests/tsc-references/parserRealSource1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserRealSource1_es2015.2.minified.js @@ -1,117 +1,119 @@ -var TypeScript, TypeScript1; -(function(CompilerDiagnostics) { - var debug = CompilerDiagnostics.debug = !1, diagnosticWriter = CompilerDiagnostics.diagnosticWriter = null; - function Alert(output) { - diagnosticWriter && diagnosticWriter.Alert(output); - } - CompilerDiagnostics.analysisPass = 0, CompilerDiagnostics.Alert = Alert, CompilerDiagnostics.debugPrint = function(s) { - debug && Alert(s); - }, CompilerDiagnostics.assert = function(condition, s) { - debug && (condition || Alert(s)); - }; -})((TypeScript1 = TypeScript || (TypeScript = {})).CompilerDiagnostics || (TypeScript1.CompilerDiagnostics = {})), TypeScript1.NullLogger = class { - information() { - return !1; - } - debug() { - return !1; - } - warning() { - return !1; - } - error() { - return !1; - } - fatal() { - return !1; - } - log(s) {} -}, TypeScript1.LoggerAdapter = class { - information() { - return this._information; - } - debug() { - return this._debug; - } - warning() { - return this._warning; - } - error() { - return this._error; - } - fatal() { - return this._fatal; - } - log(s) { - this.logger.log(s); - } - constructor(logger){ - this.logger = logger, this._information = this.logger.information(), this._debug = this.logger.debug(), this._warning = this.logger.warning(), this._error = this.logger.error(), this._fatal = this.logger.fatal(); - } -}, TypeScript1.BufferedLogger = class { - information() { - return !1; - } - debug() { - return !1; - } - warning() { - return !1; - } - error() { - return !1; - } - fatal() { - return !1; - } - log(s) { - this.logContents.push(s); - } - constructor(){ - this.logContents = []; - } -}, TypeScript1.timeFunction = function(logger, funcDescription, func) { - var start = +new Date(), result = func(), end = +new Date(); - return logger.log(funcDescription + " completed in " + (end - start) + " msec"), result; -}, TypeScript1.stringToLiteral = function(value, length) { - var result = "", addChar = (index)=>{ - var ch = value.charCodeAt(index); - switch(ch){ - case 9: - result += "\\t"; - break; - case 10: - result += "\\n"; - break; - case 11: - result += "\\v"; - break; - case 12: - result += "\\f"; - break; - case 13: - result += "\\r"; - break; - case 34: - result += "\\\""; - break; - case 39: - result += "\\'"; - break; - case 92: - result += "\\"; - break; - default: - result += value.charAt(index); +var TypeScript; +!function(TypeScript1) { + !function(CompilerDiagnostics) { + var debug = CompilerDiagnostics.debug = !1, diagnosticWriter = CompilerDiagnostics.diagnosticWriter = null; + function Alert(output) { + diagnosticWriter && diagnosticWriter.Alert(output); } + CompilerDiagnostics.analysisPass = 0, CompilerDiagnostics.Alert = Alert, CompilerDiagnostics.debugPrint = function(s) { + debug && Alert(s); + }, CompilerDiagnostics.assert = function(condition, s) { + debug && (condition || Alert(s)); + }; + }(TypeScript1.CompilerDiagnostics || (TypeScript1.CompilerDiagnostics = {})), TypeScript1.NullLogger = class { + information() { + return !1; + } + debug() { + return !1; + } + warning() { + return !1; + } + error() { + return !1; + } + fatal() { + return !1; + } + log(s) {} + }, TypeScript1.LoggerAdapter = class { + information() { + return this._information; + } + debug() { + return this._debug; + } + warning() { + return this._warning; + } + error() { + return this._error; + } + fatal() { + return this._fatal; + } + log(s) { + this.logger.log(s); + } + constructor(logger){ + this.logger = logger, this._information = this.logger.information(), this._debug = this.logger.debug(), this._warning = this.logger.warning(), this._error = this.logger.error(), this._fatal = this.logger.fatal(); + } + }, TypeScript1.BufferedLogger = class { + information() { + return !1; + } + debug() { + return !1; + } + warning() { + return !1; + } + error() { + return !1; + } + fatal() { + return !1; + } + log(s) { + this.logContents.push(s); + } + constructor(){ + this.logContents = []; + } + }, TypeScript1.timeFunction = function(logger, funcDescription, func) { + var start = +new Date(), result = func(), end = +new Date(); + return logger.log(funcDescription + " completed in " + (end - start) + " msec"), result; + }, TypeScript1.stringToLiteral = function(value, length) { + var result = "", addChar = (index)=>{ + var ch = value.charCodeAt(index); + switch(ch){ + case 9: + result += "\\t"; + break; + case 10: + result += "\\n"; + break; + case 11: + result += "\\v"; + break; + case 12: + result += "\\f"; + break; + case 13: + result += "\\r"; + break; + case 34: + result += "\\\""; + break; + case 39: + result += "\\'"; + break; + case 92: + result += "\\"; + break; + default: + result += value.charAt(index); + } + }; + if (value.length > length) { + for(var mid = length >> 1, i = 0; i < mid; i++)addChar(i); + result += "(...)"; + for(var i = value.length - mid; i < value.length; i++)addChar(i); + } else { + length = value.length; + for(var i = 0; i < length; i++)addChar(i); + } + return result; }; - if (value.length > length) { - for(var mid = length >> 1, i = 0; i < mid; i++)addChar(i); - result += "(...)"; - for(var i = value.length - mid; i < value.length; i++)addChar(i); - } else { - length = value.length; - for(var i = 0; i < length; i++)addChar(i); - } - return result; -}; +}(TypeScript || (TypeScript = {})); diff --git a/crates/swc/tests/tsc-references/parserRealSource5_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserRealSource5_es2015.2.minified.js index 12677274d80..f57c41f6538 100644 --- a/crates/swc/tests/tsc-references/parserRealSource5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserRealSource5_es2015.2.minified.js @@ -1,33 +1,35 @@ -var TypeScript, TypeScript1; -(TypeScript1 = TypeScript || (TypeScript = {})).PrintContext = class { - increaseIndent() { - this.indentAmt++; - } - decreaseIndent() { - this.indentAmt--; - } - startLine() { - this.builder.length > 0 && CompilerDiagnostics.Alert(this.builder); - var indentString = this.indentStrings[this.indentAmt]; - if (void 0 === indentString) { - indentString = ""; - for(var i = 0; i < this.indentAmt; i++)indentString += this.indent1; - this.indentStrings[this.indentAmt] = indentString; +var TypeScript; +!function(TypeScript1) { + TypeScript1.PrintContext = class { + increaseIndent() { + this.indentAmt++; } - this.builder += indentString; - } - write(s) { - this.builder += s; - } - writeLine(s) { - this.builder += s, this.outfile.WriteLine(this.builder), this.builder = ""; - } - constructor(outfile, parser){ - this.outfile = outfile, this.parser = parser, this.builder = "", this.indent1 = " ", this.indentStrings = [], this.indentAmt = 0; - } -}, TypeScript1.prePrintAST = function(ast, parent, walker) { - var pc = walker.state; - return ast.print(pc), pc.increaseIndent(), ast; -}, TypeScript1.postPrintAST = function(ast, parent, walker) { - return walker.state.decreaseIndent(), ast; -}; + decreaseIndent() { + this.indentAmt--; + } + startLine() { + this.builder.length > 0 && CompilerDiagnostics.Alert(this.builder); + var indentString = this.indentStrings[this.indentAmt]; + if (void 0 === indentString) { + indentString = ""; + for(var i = 0; i < this.indentAmt; i++)indentString += this.indent1; + this.indentStrings[this.indentAmt] = indentString; + } + this.builder += indentString; + } + write(s) { + this.builder += s; + } + writeLine(s) { + this.builder += s, this.outfile.WriteLine(this.builder), this.builder = ""; + } + constructor(outfile, parser){ + this.outfile = outfile, this.parser = parser, this.builder = "", this.indent1 = " ", this.indentStrings = [], this.indentAmt = 0; + } + }, TypeScript1.prePrintAST = function(ast, parent, walker) { + var pc = walker.state; + return ast.print(pc), pc.increaseIndent(), ast; + }, TypeScript1.postPrintAST = function(ast, parent, walker) { + return walker.state.decreaseIndent(), ast; + }; +}(TypeScript || (TypeScript = {})); diff --git a/crates/swc/tests/tsc-references/plusOperatorWithEnumType_es2015.2.minified.js b/crates/swc/tests/tsc-references/plusOperatorWithEnumType_es2015.2.minified.js index 87ee734df8c..522fe8e5b9d 100644 --- a/crates/swc/tests/tsc-references/plusOperatorWithEnumType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/plusOperatorWithEnumType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ENUM1.A, ENUM[0] + ENUM1.B, ENUM1.B; +var ENUM, ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ENUM1.A, ENUM[0] + ENUM1.B, ENUM1.B; diff --git a/crates/swc/tests/tsc-references/plusOperatorWithEnumType_es5.2.minified.js b/crates/swc/tests/tsc-references/plusOperatorWithEnumType_es5.2.minified.js index 87ee734df8c..522fe8e5b9d 100644 --- a/crates/swc/tests/tsc-references/plusOperatorWithEnumType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/plusOperatorWithEnumType_es5.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ENUM1.A, ENUM[0] + ENUM1.B, ENUM1.B; +var ENUM, ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ENUM1.A, ENUM[0] + ENUM1.B, ENUM1.B; diff --git a/crates/swc/tests/tsc-references/primtiveTypesAreIdentical_es2015.2.minified.js b/crates/swc/tests/tsc-references/primtiveTypesAreIdentical_es2015.2.minified.js index 5f410993c04..4f81f678e53 100644 --- a/crates/swc/tests/tsc-references/primtiveTypesAreIdentical_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/primtiveTypesAreIdentical_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A"; +var E; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/primtiveTypesAreIdentical_es5.2.minified.js b/crates/swc/tests/tsc-references/primtiveTypesAreIdentical_es5.2.minified.js index 5f410993c04..4f81f678e53 100644 --- a/crates/swc/tests/tsc-references/primtiveTypesAreIdentical_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/primtiveTypesAreIdentical_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A"; +var E; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/propertyAccess_es2015.2.minified.js b/crates/swc/tests/tsc-references/propertyAccess_es2015.2.minified.js index 791b5281a73..1fa8a4dc623 100644 --- a/crates/swc/tests/tsc-references/propertyAccess_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/propertyAccess_es2015.2.minified.js @@ -1,5 +1,7 @@ -(Compass = Compass || (Compass = {}))[Compass.North = 0] = "North", Compass[Compass.South = 1] = "South", Compass[Compass.East = 2] = "East", Compass[Compass.West = 3] = "West"; -var Compass, Compass, bothIndex, stringOrNumber, someObject, numIndex = { +!function(Compass) { + Compass[Compass.North = 0] = "North", Compass[Compass.South = 1] = "South", Compass[Compass.East = 2] = "East", Compass[Compass.West = 3] = "West"; +}(Compass || (Compass = {})); +var Compass, bothIndex, stringOrNumber, someObject, numIndex = { 3: "three", three: "three" }, strIndex = { diff --git a/crates/swc/tests/tsc-references/propertyAccess_es5.2.minified.js b/crates/swc/tests/tsc-references/propertyAccess_es5.2.minified.js index 23e870d5dd3..03aaa1099d2 100644 --- a/crates/swc/tests/tsc-references/propertyAccess_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/propertyAccess_es5.2.minified.js @@ -11,7 +11,7 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var Compass, bothIndex, stringOrNumber, someObject, Compass, A = function() { +var Compass, bothIndex, stringOrNumber, someObject, A = function() { "use strict"; _classCallCheck(this, A); }, B = function(A1) { @@ -54,7 +54,9 @@ var Compass, bothIndex, stringOrNumber, someObject, Compass, A = function() { } return B; }(A); -(Compass = Compass || (Compass = {}))[Compass.North = 0] = "North", Compass[Compass.South = 1] = "South", Compass[Compass.East = 2] = "East", Compass[Compass.West = 3] = "West"; +!function(Compass) { + Compass[Compass.North = 0] = "North", Compass[Compass.South = 1] = "South", Compass[Compass.East = 2] = "East", Compass[Compass.West = 3] = "West"; +}(Compass || (Compass = {})); var numIndex = { 3: "three", three: "three" diff --git a/crates/swc/tests/tsc-references/protectedStaticNotAccessibleInClodule_es2015.2.minified.js b/crates/swc/tests/tsc-references/protectedStaticNotAccessibleInClodule_es2015.2.minified.js index 9c7b66ecdef..dad825dde44 100644 --- a/crates/swc/tests/tsc-references/protectedStaticNotAccessibleInClodule_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/protectedStaticNotAccessibleInClodule_es2015.2.minified.js @@ -1,4 +1,5 @@ -var C; -class C1 { +class C { } -(C = C1 || (C1 = {})).f = C1.foo, C.b = C1.bar; +!function(C1) { + C1.f = C.foo, C1.b = C.bar; +}(C || (C = {})); diff --git a/crates/swc/tests/tsc-references/protectedStaticNotAccessibleInClodule_es5.2.minified.js b/crates/swc/tests/tsc-references/protectedStaticNotAccessibleInClodule_es5.2.minified.js index 10a740411e3..c0514eddc02 100644 --- a/crates/swc/tests/tsc-references/protectedStaticNotAccessibleInClodule_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/protectedStaticNotAccessibleInClodule_es5.2.minified.js @@ -1,7 +1,9 @@ -var C, C1 = function() { +var C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C1); + }(this, C); }; -(C = C1 || (C1 = {})).f = C1.foo, C.b = C1.bar; +!function(C1) { + C1.f = C.foo, C1.b = C.bar; +}(C || (C = {})); diff --git a/crates/swc/tests/tsc-references/restElementWithAssignmentPattern3_es5.2.minified.js b/crates/swc/tests/tsc-references/restElementWithAssignmentPattern3_es5.2.minified.js index 97877bec2ab..dd2a69da3f9 100644 --- a/crates/swc/tests/tsc-references/restElementWithAssignmentPattern3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/restElementWithAssignmentPattern3_es5.2.minified.js @@ -1,4 +1,4 @@ -var ref, arr, arr, i; +var ref; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; @@ -18,26 +18,30 @@ function _unsupportedIterableToArray(o, minLen) { if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } } -(ref = (arr = (_arrayWithHoles(arr = [ +(ref = (function(arr, i) { + return _arrayWithHoles(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; + try { + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; + } finally{ + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } + } + return _arr; + } + })(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); +})((function(arr) { + return _arrayWithHoles(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); +})([ "", 1 -]) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest()).slice(0), i = 2, _arrayWithHoles(arr) || (function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ - try { - _n || null == _i.return || _i.return(); - } finally{ - if (_d) throw _e; - } - } - return _arr; - } -})(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest()))[0], ref[1]; +]).slice(0), 2))[0], ref[1]; diff --git a/crates/swc/tests/tsc-references/restElementWithAssignmentPattern4_es5.2.minified.js b/crates/swc/tests/tsc-references/restElementWithAssignmentPattern4_es5.2.minified.js index 9bdad693dc2..4351d1e17c9 100644 --- a/crates/swc/tests/tsc-references/restElementWithAssignmentPattern4_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/restElementWithAssignmentPattern4_es5.2.minified.js @@ -1,23 +1,25 @@ -var ref, arr; +var ref; function _arrayLikeToArray(arr, len) { (null == len || len > arr.length) && (len = arr.length); for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } -(ref = ((function(arr) { - if (Array.isArray(arr)) return arr; -})(arr = [ +(ref = (function(arr) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(iter) { + if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); + })(arr) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +})([ "", 1 -]) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); -})(arr) || (function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -})(arr, i) || (function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -})()).slice(0))[0], ref.b; +]).slice(0))[0], ref.b; diff --git a/crates/swc/tests/tsc-references/scannerEnum1_es2015.2.minified.js b/crates/swc/tests/tsc-references/scannerEnum1_es2015.2.minified.js index 1c24aa46f22..dce30ab099b 100644 --- a/crates/swc/tests/tsc-references/scannerEnum1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/scannerEnum1_es2015.2.minified.js @@ -1,2 +1,4 @@ -var CodeGenTarget, CodeGenTarget; -(CodeGenTarget = CodeGenTarget || (CodeGenTarget = {}))[CodeGenTarget.ES3 = 0] = "ES3", CodeGenTarget[CodeGenTarget.ES5 = 1] = "ES5"; +export var CodeGenTarget; +!function(CodeGenTarget) { + CodeGenTarget[CodeGenTarget.ES3 = 0] = "ES3", CodeGenTarget[CodeGenTarget.ES5 = 1] = "ES5"; +}(CodeGenTarget || (CodeGenTarget = {})); diff --git a/crates/swc/tests/tsc-references/scannerEnum1_es5.2.minified.js b/crates/swc/tests/tsc-references/scannerEnum1_es5.2.minified.js index 1c24aa46f22..dce30ab099b 100644 --- a/crates/swc/tests/tsc-references/scannerEnum1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/scannerEnum1_es5.2.minified.js @@ -1,2 +1,4 @@ -var CodeGenTarget, CodeGenTarget; -(CodeGenTarget = CodeGenTarget || (CodeGenTarget = {}))[CodeGenTarget.ES3 = 0] = "ES3", CodeGenTarget[CodeGenTarget.ES5 = 1] = "ES5"; +export var CodeGenTarget; +!function(CodeGenTarget) { + CodeGenTarget[CodeGenTarget.ES3 = 0] = "ES3", CodeGenTarget[CodeGenTarget.ES5 = 1] = "ES5"; +}(CodeGenTarget || (CodeGenTarget = {})); diff --git a/crates/swc/tests/tsc-references/stringEnumInElementAccess01_es2015.2.minified.js b/crates/swc/tests/tsc-references/stringEnumInElementAccess01_es2015.2.minified.js index 39d48f298d1..cf551e0596f 100644 --- a/crates/swc/tests/tsc-references/stringEnumInElementAccess01_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/stringEnumInElementAccess01_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {})).A = "a", E.B = "b", E.C = "c", item[e]; +var E; +!function(E) { + E.A = "a", E.B = "b", E.C = "c"; +}(E || (E = {})), item[e]; diff --git a/crates/swc/tests/tsc-references/stringEnumInElementAccess01_es5.2.minified.js b/crates/swc/tests/tsc-references/stringEnumInElementAccess01_es5.2.minified.js index 39d48f298d1..cf551e0596f 100644 --- a/crates/swc/tests/tsc-references/stringEnumInElementAccess01_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/stringEnumInElementAccess01_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {})).A = "a", E.B = "b", E.C = "c", item[e]; +var E; +!function(E) { + E.A = "a", E.B = "b", E.C = "c"; +}(E || (E = {})), item[e]; diff --git a/crates/swc/tests/tsc-references/stringEnumLiteralTypes1_es2015.2.minified.js b/crates/swc/tests/tsc-references/stringEnumLiteralTypes1_es2015.2.minified.js index 09cc5f3f717..f52b0fb1dce 100644 --- a/crates/swc/tests/tsc-references/stringEnumLiteralTypes1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/stringEnumLiteralTypes1_es2015.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {})).Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +var Choice; +!function(Choice) { + Choice.Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/stringEnumLiteralTypes1_es5.2.minified.js b/crates/swc/tests/tsc-references/stringEnumLiteralTypes1_es5.2.minified.js index 09cc5f3f717..f52b0fb1dce 100644 --- a/crates/swc/tests/tsc-references/stringEnumLiteralTypes1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/stringEnumLiteralTypes1_es5.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {})).Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +var Choice; +!function(Choice) { + Choice.Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/stringEnumLiteralTypes2_es2015.2.minified.js b/crates/swc/tests/tsc-references/stringEnumLiteralTypes2_es2015.2.minified.js index 09cc5f3f717..f52b0fb1dce 100644 --- a/crates/swc/tests/tsc-references/stringEnumLiteralTypes2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/stringEnumLiteralTypes2_es2015.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {})).Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +var Choice; +!function(Choice) { + Choice.Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/stringEnumLiteralTypes2_es5.2.minified.js b/crates/swc/tests/tsc-references/stringEnumLiteralTypes2_es5.2.minified.js index 09cc5f3f717..f52b0fb1dce 100644 --- a/crates/swc/tests/tsc-references/stringEnumLiteralTypes2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/stringEnumLiteralTypes2_es5.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {})).Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +var Choice; +!function(Choice) { + Choice.Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/stringEnumLiteralTypes3_es2015.2.minified.js b/crates/swc/tests/tsc-references/stringEnumLiteralTypes3_es2015.2.minified.js index 09cc5f3f717..f52b0fb1dce 100644 --- a/crates/swc/tests/tsc-references/stringEnumLiteralTypes3_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/stringEnumLiteralTypes3_es2015.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {})).Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +var Choice; +!function(Choice) { + Choice.Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/stringEnumLiteralTypes3_es5.2.minified.js b/crates/swc/tests/tsc-references/stringEnumLiteralTypes3_es5.2.minified.js index 09cc5f3f717..f52b0fb1dce 100644 --- a/crates/swc/tests/tsc-references/stringEnumLiteralTypes3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/stringEnumLiteralTypes3_es5.2.minified.js @@ -1,2 +1,4 @@ -var Choice, Choice; -(Choice = Choice || (Choice = {})).Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +var Choice; +!function(Choice) { + Choice.Unknown = "", Choice.Yes = "yes", Choice.No = "no"; +}(Choice || (Choice = {})); diff --git a/crates/swc/tests/tsc-references/stringLiteralTypeIsSubtypeOfString_es2015.2.minified.js b/crates/swc/tests/tsc-references/stringLiteralTypeIsSubtypeOfString_es2015.2.minified.js index 5f410993c04..4f81f678e53 100644 --- a/crates/swc/tests/tsc-references/stringLiteralTypeIsSubtypeOfString_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/stringLiteralTypeIsSubtypeOfString_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A"; +var E; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/stringLiteralTypeIsSubtypeOfString_es5.2.minified.js b/crates/swc/tests/tsc-references/stringLiteralTypeIsSubtypeOfString_es5.2.minified.js index e450f4b7b4d..1810c2365ed 100644 --- a/crates/swc/tests/tsc-references/stringLiteralTypeIsSubtypeOfString_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/stringLiteralTypeIsSubtypeOfString_es5.2.minified.js @@ -4,7 +4,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var E, E, C = function() { +var E, C = function() { "use strict"; var Constructor, protoProps, staticProps; function C() { @@ -136,4 +136,6 @@ var E, E, C = function() { } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), C; }(); -(E = E || (E = {}))[E.A = 0] = "A"; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/subtypesOfAny_es2015.2.minified.js b/crates/swc/tests/tsc-references/subtypesOfAny_es2015.2.minified.js index 3f3700c80c3..65f9a16b279 100644 --- a/crates/swc/tests/tsc-references/subtypesOfAny_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/subtypesOfAny_es2015.2.minified.js @@ -1,6 +1,8 @@ -var E, E; +var E; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (f || (f = {})).bar = 1; class c { } (c || (c = {})).bar = 1; diff --git a/crates/swc/tests/tsc-references/subtypesOfAny_es5.2.minified.js b/crates/swc/tests/tsc-references/subtypesOfAny_es5.2.minified.js index 13efea2d586..dae6c34036d 100644 --- a/crates/swc/tests/tsc-references/subtypesOfAny_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/subtypesOfAny_es5.2.minified.js @@ -1,7 +1,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -var E, E, A = function() { +var E, A = function() { "use strict"; _classCallCheck(this, A); }, A2 = function() { @@ -9,7 +9,9 @@ var E, E, A = function() { _classCallCheck(this, A2); }; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (f || (f = {})).bar = 1; var c = function() { "use strict"; _classCallCheck(this, c); diff --git a/crates/swc/tests/tsc-references/subtypesOfTypeParameterWithConstraints2_es2015.2.minified.js b/crates/swc/tests/tsc-references/subtypesOfTypeParameterWithConstraints2_es2015.2.minified.js index 3f3700c80c3..65f9a16b279 100644 --- a/crates/swc/tests/tsc-references/subtypesOfTypeParameterWithConstraints2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/subtypesOfTypeParameterWithConstraints2_es2015.2.minified.js @@ -1,6 +1,8 @@ -var E, E; +var E; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (f || (f = {})).bar = 1; class c { } (c || (c = {})).bar = 1; diff --git a/crates/swc/tests/tsc-references/subtypesOfTypeParameterWithConstraints2_es5.2.minified.js b/crates/swc/tests/tsc-references/subtypesOfTypeParameterWithConstraints2_es5.2.minified.js index 997771845c8..f65cb85ba50 100644 --- a/crates/swc/tests/tsc-references/subtypesOfTypeParameterWithConstraints2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/subtypesOfTypeParameterWithConstraints2_es5.2.minified.js @@ -1,7 +1,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -var E, E, C1 = function() { +var E, C1 = function() { "use strict"; _classCallCheck(this, C1); }, C2 = function() { @@ -9,7 +9,9 @@ var E, E, C1 = function() { _classCallCheck(this, C2); }; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (f || (f = {})).bar = 1; var c = function() { "use strict"; _classCallCheck(this, c); diff --git a/crates/swc/tests/tsc-references/subtypesOfTypeParameter_es2015.2.minified.js b/crates/swc/tests/tsc-references/subtypesOfTypeParameter_es2015.2.minified.js index 3f3700c80c3..65f9a16b279 100644 --- a/crates/swc/tests/tsc-references/subtypesOfTypeParameter_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/subtypesOfTypeParameter_es2015.2.minified.js @@ -1,6 +1,8 @@ -var E, E; +var E; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (f || (f = {})).bar = 1; class c { } (c || (c = {})).bar = 1; diff --git a/crates/swc/tests/tsc-references/subtypesOfTypeParameter_es5.2.minified.js b/crates/swc/tests/tsc-references/subtypesOfTypeParameter_es5.2.minified.js index 311d32f068d..2dcae3c8079 100644 --- a/crates/swc/tests/tsc-references/subtypesOfTypeParameter_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/subtypesOfTypeParameter_es5.2.minified.js @@ -11,7 +11,7 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var E, E, _typeof = function(obj) { +var E, _typeof = function(obj) { return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; }, C3 = function() { "use strict"; @@ -63,7 +63,9 @@ var E, E, _typeof = function(obj) { _classCallCheck(this, C2); }; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (f || (f = {})).bar = 1; var c = function() { "use strict"; _classCallCheck(this, c); diff --git a/crates/swc/tests/tsc-references/subtypesOfUnion_es2015.2.minified.js b/crates/swc/tests/tsc-references/subtypesOfUnion_es2015.2.minified.js index ff86d1459f3..f7931d001bc 100644 --- a/crates/swc/tests/tsc-references/subtypesOfUnion_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/subtypesOfUnion_es2015.2.minified.js @@ -1,6 +1,8 @@ -var E, E; +var E; function f() {} -(E = E || (E = {}))[E.e1 = 0] = "e1", E[E.e2 = 1] = "e2", (f || (f = {})).bar = 1; +!function(E) { + E[E.e1 = 0] = "e1", E[E.e2 = 1] = "e2"; +}(E || (E = {})), (f || (f = {})).bar = 1; class c { } (c || (c = {})).bar = 1; diff --git a/crates/swc/tests/tsc-references/subtypesOfUnion_es5.2.minified.js b/crates/swc/tests/tsc-references/subtypesOfUnion_es5.2.minified.js index 9a74586c3f2..6710a65d08c 100644 --- a/crates/swc/tests/tsc-references/subtypesOfUnion_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/subtypesOfUnion_es5.2.minified.js @@ -1,8 +1,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -(E = E || (E = {}))[E.e1 = 0] = "e1", E[E.e2 = 1] = "e2"; -var E, E, A = function() { +!function(E) { + E[E.e1 = 0] = "e1", E[E.e2 = 1] = "e2"; +}(E || (E = {})); +var E, A = function() { "use strict"; _classCallCheck(this, A); }, A2 = function() { diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit8_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit8_es5.2.minified.js index fd0aa828dc6..8a296716f08 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit8_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit8_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -obj = {}, value = 0, (key = Symbol.isConcatSpreadable) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, Symbol.isConcatSpreadable, 0); diff --git a/crates/swc/tests/tsc-references/symbolProperty52_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolProperty52_es5.2.minified.js index 04c5bac6bce..b11f208dc67 100644 --- a/crates/swc/tests/tsc-references/symbolProperty52_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolProperty52_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -obj = {}, value = 0, (key = Symbol.nonsense) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value, ({})[Symbol.nonsense]; +(function(obj, key, value) { + key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value; +})({}, Symbol.nonsense, 0), ({})[Symbol.nonsense]; diff --git a/crates/swc/tests/tsc-references/symbolProperty53_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolProperty53_es5.2.minified.js index 456b0d0a5a2..3f1c34680ab 100644 --- a/crates/swc/tests/tsc-references/symbolProperty53_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolProperty53_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -(obj = {}, value = 0, (key = Symbol.for) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value, obj)[Symbol.for]; +(function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +})({}, Symbol.for, 0)[Symbol.for]; diff --git a/crates/swc/tests/tsc-references/symbolProperty54_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolProperty54_es5.2.minified.js index 4dd0aef173d..5fc388ff060 100644 --- a/crates/swc/tests/tsc-references/symbolProperty54_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolProperty54_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -obj = {}, value = 0, (key = Symbol.prototype) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, Symbol.prototype, 0); diff --git a/crates/swc/tests/tsc-references/symbolProperty55_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolProperty55_es5.2.minified.js index 28fc11501a1..104a7afd18a 100644 --- a/crates/swc/tests/tsc-references/symbolProperty55_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolProperty55_es5.2.minified.js @@ -1,7 +1,9 @@ -var obj, key, value, M; -M || (M = {}), (obj = {}, value = 0, (key = Symbol.iterator) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value, obj)[(void 0).iterator]; +var M; +M || (M = {}), (function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +})({}, Symbol.iterator, 0)[(void 0).iterator]; diff --git a/crates/swc/tests/tsc-references/symbolProperty56_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolProperty56_es5.2.minified.js index 28fc11501a1..104a7afd18a 100644 --- a/crates/swc/tests/tsc-references/symbolProperty56_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolProperty56_es5.2.minified.js @@ -1,7 +1,9 @@ -var obj, key, value, M; -M || (M = {}), (obj = {}, value = 0, (key = Symbol.iterator) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value, obj)[(void 0).iterator]; +var M; +M || (M = {}), (function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +})({}, Symbol.iterator, 0)[(void 0).iterator]; diff --git a/crates/swc/tests/tsc-references/symbolProperty57_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolProperty57_es5.2.minified.js index f7972df508d..f7010bb2237 100644 --- a/crates/swc/tests/tsc-references/symbolProperty57_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolProperty57_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -(obj = {}, value = 0, (key = Symbol.iterator) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value, obj)[Symbol.nonsense]; +(function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +})({}, Symbol.iterator, 0)[Symbol.nonsense]; diff --git a/crates/swc/tests/tsc-references/symbolProperty58_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolProperty58_es5.2.minified.js index 6b3896d970a..7b48edaad65 100644 --- a/crates/swc/tests/tsc-references/symbolProperty58_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolProperty58_es5.2.minified.js @@ -1,7 +1,8 @@ -var obj, key, value; -obj = {}, value = 0, (key = Symbol.foo) in obj ? Object.defineProperty(obj, key, { - value: value, - enumerable: !0, - configurable: !0, - writable: !0 -}) : obj[key] = value; +!function(obj, key, value) { + return key in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value, obj; +}({}, Symbol.foo, 0); diff --git a/crates/swc/tests/tsc-references/symbolType17_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolType17_es5.2.minified.js index eb3722e13d6..e544a864fd0 100644 --- a/crates/swc/tests/tsc-references/symbolType17_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolType17_es5.2.minified.js @@ -1,2 +1,4 @@ -var x, obj; -void 0 === x || (obj = x) && "undefined" != typeof Symbol && obj.constructor === Symbol; +var x; +void 0 === x || (function(obj) { + return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; +})(x); diff --git a/crates/swc/tests/tsc-references/symbolType3_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolType3_es5.2.minified.js index c587e625f84..9396ee20e2d 100644 --- a/crates/swc/tests/tsc-references/symbolType3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolType3_es5.2.minified.js @@ -1,2 +1,4 @@ -var obj, s = Symbol(); -delete Symbol.iterator, (obj = Symbol.toStringTag) && "undefined" != typeof Symbol && obj.constructor === Symbol, ++s, --s, Symbol(), Symbol(), Symbol(), Symbol(), Symbol(); +var s = Symbol(); +delete Symbol.iterator, (function(obj) { + obj && "undefined" != typeof Symbol && obj.constructor === Symbol; +})(Symbol.toStringTag), ++s, --s, Symbol(), Symbol(), Symbol(), Symbol(), Symbol(); diff --git a/crates/swc/tests/tsc-references/templateStringInInstanceOfES6_es5.2.minified.js b/crates/swc/tests/tsc-references/templateStringInInstanceOfES6_es5.2.minified.js index e9303bf7107..279c900a640 100644 --- a/crates/swc/tests/tsc-references/templateStringInInstanceOfES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/templateStringInInstanceOfES6_es5.2.minified.js @@ -1,2 +1,3 @@ -var left, right; -left = "abc".concat(0, "def"), null != (right = String) && "undefined" != typeof Symbol && right[Symbol.hasInstance] && right[Symbol.hasInstance](left); +!function(left, right) { + return null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right; +}("abc".concat(0, "def"), String); diff --git a/crates/swc/tests/tsc-references/templateStringInInstanceOf_es5.2.minified.js b/crates/swc/tests/tsc-references/templateStringInInstanceOf_es5.2.minified.js index e9303bf7107..279c900a640 100644 --- a/crates/swc/tests/tsc-references/templateStringInInstanceOf_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/templateStringInInstanceOf_es5.2.minified.js @@ -1,2 +1,3 @@ -var left, right; -left = "abc".concat(0, "def"), null != (right = String) && "undefined" != typeof Symbol && right[Symbol.hasInstance] && right[Symbol.hasInstance](left); +!function(left, right) { + return null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right; +}("abc".concat(0, "def"), String); diff --git a/crates/swc/tests/tsc-references/templateStringInTypeOfES6_es5.2.minified.js b/crates/swc/tests/tsc-references/templateStringInTypeOfES6_es5.2.minified.js index 72a44dd16b7..cf966b1a633 100644 --- a/crates/swc/tests/tsc-references/templateStringInTypeOfES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/templateStringInTypeOfES6_es5.2.minified.js @@ -1,2 +1,3 @@ -var obj; -(obj = "abc".concat(123, "def")) && "undefined" != typeof Symbol && obj.constructor === Symbol; +!function(obj) { + obj && "undefined" != typeof Symbol && obj.constructor === Symbol; +}("abc".concat(123, "def")); diff --git a/crates/swc/tests/tsc-references/templateStringInTypeOf_es5.2.minified.js b/crates/swc/tests/tsc-references/templateStringInTypeOf_es5.2.minified.js index 72a44dd16b7..cf966b1a633 100644 --- a/crates/swc/tests/tsc-references/templateStringInTypeOf_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/templateStringInTypeOf_es5.2.minified.js @@ -1,2 +1,3 @@ -var obj; -(obj = "abc".concat(123, "def")) && "undefined" != typeof Symbol && obj.constructor === Symbol; +!function(obj) { + obj && "undefined" != typeof Symbol && obj.constructor === Symbol; +}("abc".concat(123, "def")); diff --git a/crates/swc/tests/tsc-references/templateStringWithEmbeddedInstanceOfES6_es5.2.minified.js b/crates/swc/tests/tsc-references/templateStringWithEmbeddedInstanceOfES6_es5.2.minified.js index 64dfde2760f..f4e3194df8e 100644 --- a/crates/swc/tests/tsc-references/templateStringWithEmbeddedInstanceOfES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/templateStringWithEmbeddedInstanceOfES6_es5.2.minified.js @@ -1,2 +1,3 @@ -var left, right; -"abc".concat((left = "hello", null != (right = String) && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right), "def"); +"abc".concat(function(left, right) { + return null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right; +}("hello", String), "def"); diff --git a/crates/swc/tests/tsc-references/templateStringWithEmbeddedInstanceOf_es5.2.minified.js b/crates/swc/tests/tsc-references/templateStringWithEmbeddedInstanceOf_es5.2.minified.js index 64dfde2760f..f4e3194df8e 100644 --- a/crates/swc/tests/tsc-references/templateStringWithEmbeddedInstanceOf_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/templateStringWithEmbeddedInstanceOf_es5.2.minified.js @@ -1,2 +1,3 @@ -var left, right; -"abc".concat((left = "hello", null != (right = String) && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right), "def"); +"abc".concat(function(left, right) { + return null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right; +}("hello", String), "def"); diff --git a/crates/swc/tests/tsc-references/templateStringWithEmbeddedTypeOfOperatorES6_es5.2.minified.js b/crates/swc/tests/tsc-references/templateStringWithEmbeddedTypeOfOperatorES6_es5.2.minified.js index e9a801fe859..7b5ad94c484 100644 --- a/crates/swc/tests/tsc-references/templateStringWithEmbeddedTypeOfOperatorES6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/templateStringWithEmbeddedTypeOfOperatorES6_es5.2.minified.js @@ -1,2 +1,3 @@ -var obj; -"abc".concat((obj = "hi", "undefined" != typeof Symbol && obj.constructor === Symbol) ? "symbol" : typeof obj, "def"); +"abc".concat(function(obj) { + return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; +}("hi"), "def"); diff --git a/crates/swc/tests/tsc-references/templateStringWithEmbeddedTypeOfOperator_es5.2.minified.js b/crates/swc/tests/tsc-references/templateStringWithEmbeddedTypeOfOperator_es5.2.minified.js index e9a801fe859..7b5ad94c484 100644 --- a/crates/swc/tests/tsc-references/templateStringWithEmbeddedTypeOfOperator_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/templateStringWithEmbeddedTypeOfOperator_es5.2.minified.js @@ -1,2 +1,3 @@ -var obj; -"abc".concat((obj = "hi", "undefined" != typeof Symbol && obj.constructor === Symbol) ? "symbol" : typeof obj, "def"); +"abc".concat(function(obj) { + return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; +}("hi"), "def"); diff --git a/crates/swc/tests/tsc-references/thisTypeInFunctions_es2015.2.minified.js b/crates/swc/tests/tsc-references/thisTypeInFunctions_es2015.2.minified.js index e25ec4bd6e0..e710c16de3f 100644 --- a/crates/swc/tests/tsc-references/thisTypeInFunctions_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/thisTypeInFunctions_es2015.2.minified.js @@ -62,7 +62,7 @@ let reconstructed = { explicitProperty: c.explicitProperty, explicitVoid: c.explicitVoid }; -reconstructed.explicitThis(10), reconstructed.explicitProperty(11), (0, reconstructed.explicitVoid)(12), (x)=>x + this.y +reconstructed.explicitThis(10), reconstructed.explicitProperty(11), (0, reconstructed.explicitVoid)(12), (x)=>x + 12 ; let explicitCFunction, explicitPropertyFunction; c.explicitC = explicitCFunction, c.explicitC = function(m) { diff --git a/crates/swc/tests/tsc-references/throwStatements_es2015.2.minified.js b/crates/swc/tests/tsc-references/throwStatements_es2015.2.minified.js index 1b7e1f0e18c..aee94a8b484 100644 --- a/crates/swc/tests/tsc-references/throwStatements_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/throwStatements_es2015.2.minified.js @@ -1,5 +1,7 @@ -var M, M1; -throw (M = M1 || (M1 = {})).A = class { -}, M.F2 = function(x) { - return x.toString(); -}, 9.9; +var M; +throw !function(M1) { + M1.A = class { + }, M1.F2 = function(x) { + return x.toString(); + }; +}(M || (M = {})), 9.9; diff --git a/crates/swc/tests/tsc-references/tsxEmit3x_es2015.2.minified.js b/crates/swc/tests/tsc-references/tsxEmit3x_es2015.2.minified.js index 38995ed195c..813233b3b2a 100644 --- a/crates/swc/tests/tsc-references/tsxEmit3x_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/tsxEmit3x_es2015.2.minified.js @@ -1,5 +1,9 @@ -var M, M1, M2; -(M2 = M || (M = {})).Foo = class { - constructor(){} -}, (M2.S || (M2.S = {})).Bar = class { -}, M1 = M || (M = {}), React.createElement(Foo, null), M1.S || (M1.S = {}), React.createElement(Foo, null), React.createElement(Bar, null), M || (M = {}), React.createElement(S.Bar, null), M || (M = {}), React.createElement(Foo, null); +var M; +!function(M1) { + M1.Foo = class { + constructor(){} + }, (M1.S || (M1.S = {})).Bar = class { + }; +}(M || (M = {})), (function(M2) { + React.createElement(Foo, null), M2.S || (M2.S = {}), React.createElement(Foo, null), React.createElement(Bar, null); +})(M || (M = {})), M || (M = {}), React.createElement(S.Bar, null), M || (M = {}), React.createElement(Foo, null); diff --git a/crates/swc/tests/tsc-references/tsxEmit3x_es5.2.minified.js b/crates/swc/tests/tsc-references/tsxEmit3x_es5.2.minified.js index 325ae0e8251..609a496582a 100644 --- a/crates/swc/tests/tsc-references/tsxEmit3x_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/tsxEmit3x_es5.2.minified.js @@ -1,14 +1,16 @@ -var M, M1; +var M; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -!function(M2) { +!function(M1) { var S, Bar, Foo = function() { "use strict"; _classCallCheck(this, Foo); }; - M2.Foo = Foo, S = M2.S || (M2.S = {}), Bar = function() { + M1.Foo = Foo, S = M1.S || (M1.S = {}), Bar = function() { "use strict"; _classCallCheck(this, Bar); }, S.Bar = Bar; -}(M || (M = {})), M1 = M || (M = {}), React.createElement(Foo, null), M1.S || (M1.S = {}), React.createElement(Foo, null), React.createElement(Bar, null), M || (M = {}), React.createElement(S.Bar, null), M || (M = {}), React.createElement(Foo, null); +}(M || (M = {})), (function(M2) { + React.createElement(Foo, null), M2.S || (M2.S = {}), React.createElement(Foo, null), React.createElement(Bar, null); +})(M || (M = {})), M || (M = {}), React.createElement(S.Bar, null), M || (M = {}), React.createElement(Foo, null); diff --git a/crates/swc/tests/tsc-references/typeAliases_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeAliases_es2015.2.minified.js index 488e71d2a50..e07a6742822 100644 --- a/crates/swc/tests/tsc-references/typeAliases_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeAliases_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, x13_1, x13_2, E, x; -foo13(x13_1, x13_2), foo13(x13_2, x13_1), (E = E || (E = {}))[E.x = 10] = "x", f15(E.x).toLowerCase(), f16(x); +var x13_1, x13_2, E, x; +foo13(x13_1, x13_2), foo13(x13_2, x13_1), (function(E) { + E[E.x = 10] = "x"; +})(E || (E = {})), f15(E.x).toLowerCase(), f16(x); diff --git a/crates/swc/tests/tsc-references/typeAliases_es5.2.minified.js b/crates/swc/tests/tsc-references/typeAliases_es5.2.minified.js index dd4559657a5..330b0c2939b 100644 --- a/crates/swc/tests/tsc-references/typeAliases_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeAliases_es5.2.minified.js @@ -1,7 +1,9 @@ -var E, x13_1, x13_2, E, x, C7 = function() { +var x13_1, x13_2, E, x, C7 = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C7); }; -foo13(x13_1, x13_2), foo13(x13_2, x13_1), (E = E || (E = {}))[E.x = 10] = "x", f15(E.x).toLowerCase(), f16(x); +foo13(x13_1, x13_2), foo13(x13_2, x13_1), (function(E) { + E[E.x = 10] = "x"; +})(E || (E = {})), f15(E.x).toLowerCase(), f16(x); diff --git a/crates/swc/tests/tsc-references/typeArgumentInferenceWithObjectLiteral_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeArgumentInferenceWithObjectLiteral_es2015.2.minified.js index c5d4b322773..7b0f98a5a2c 100644 --- a/crates/swc/tests/tsc-references/typeArgumentInferenceWithObjectLiteral_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeArgumentInferenceWithObjectLiteral_es2015.2.minified.js @@ -1,4 +1,4 @@ -var E1, E2, s, E1, E2; +var s, E1, E2; function foo(x) {} foo({ read: ()=>s @@ -8,7 +8,11 @@ foo({ write: (value)=>s = value , read: ()=>s -}), (E1 = E1 || (E1 = {}))[E1.X = 0] = "X", (E2 = E2 || (E2 = {}))[E2.X = 0] = "X", f1({ +}), (function(E1) { + E1[E1.X = 0] = "X"; +})(E1 || (E1 = {})), (function(E2) { + E2[E2.X = 0] = "X"; +})(E2 || (E2 = {})), f1({ w: (x)=>x , r: ()=>0 diff --git a/crates/swc/tests/tsc-references/typeArgumentInferenceWithObjectLiteral_es5.2.minified.js b/crates/swc/tests/tsc-references/typeArgumentInferenceWithObjectLiteral_es5.2.minified.js index 2c6d2c8e038..3baabadb279 100644 --- a/crates/swc/tests/tsc-references/typeArgumentInferenceWithObjectLiteral_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeArgumentInferenceWithObjectLiteral_es5.2.minified.js @@ -1,4 +1,4 @@ -var E1, E2, s, E1, E2; +var s, E1, E2; function foo(x) {} foo({ read: function() { @@ -14,7 +14,11 @@ foo({ read: function() { return s; } -}), (E1 = E1 || (E1 = {}))[E1.X = 0] = "X", (E2 = E2 || (E2 = {}))[E2.X = 0] = "X", f1({ +}), (function(E1) { + E1[E1.X = 0] = "X"; +})(E1 || (E1 = {})), (function(E2) { + E2[E2.X = 0] = "X"; +})(E2 || (E2 = {})), f1({ w: function(x) { return x; }, diff --git a/crates/swc/tests/tsc-references/typeFromPropertyAssignment31_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeFromPropertyAssignment31_es2015.2.minified.js index 6783ca5e6ae..b28f9f61da1 100644 --- a/crates/swc/tests/tsc-references/typeFromPropertyAssignment31_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeFromPropertyAssignment31_es2015.2.minified.js @@ -1,7 +1,8 @@ -var ExpandoMerge; -function ExpandoMerge1(n) { +function ExpandoMerge(n) { return n; } -ExpandoMerge1.p1 = 111, ExpandoMerge1.m = function(n) { +ExpandoMerge.p1 = 111, ExpandoMerge.m = function(n) { return n + 1; -}, (ExpandoMerge1 || (ExpandoMerge1 = {})).p2 = 222, ExpandoMerge1.p4 = 44444, ExpandoMerge1.p6 = 66666, ExpandoMerge1.p8 = !1, (ExpandoMerge = ExpandoMerge1 || (ExpandoMerge1 = {})).p3 = 333, ExpandoMerge.p4 = 4, ExpandoMerge.p5 = 5, ExpandoMerge.p6 = 6, ExpandoMerge.p7 = 7, ExpandoMerge.p8 = 6, ExpandoMerge.p9 = 7, ExpandoMerge1.p5 = 555555, ExpandoMerge1.p7 = 777777, ExpandoMerge1.p9 = !1, ExpandoMerge1.p1 + ExpandoMerge1.p2 + ExpandoMerge1.p3 + ExpandoMerge1.p4 + ExpandoMerge1.p5 + ExpandoMerge1.p6 + ExpandoMerge1.p7 + ExpandoMerge1.p8 + ExpandoMerge1.p9 + ExpandoMerge1.m(12) + ExpandoMerge1(1001); +}, (ExpandoMerge || (ExpandoMerge = {})).p2 = 222, ExpandoMerge.p4 = 44444, ExpandoMerge.p6 = 66666, ExpandoMerge.p8 = !1, (function(ExpandoMerge1) { + ExpandoMerge1.p3 = 333, ExpandoMerge1.p4 = 4, ExpandoMerge1.p5 = 5, ExpandoMerge1.p6 = 6, ExpandoMerge1.p7 = 7, ExpandoMerge1.p8 = 6, ExpandoMerge1.p9 = 7; +})(ExpandoMerge || (ExpandoMerge = {})), ExpandoMerge.p5 = 555555, ExpandoMerge.p7 = 777777, ExpandoMerge.p9 = !1, ExpandoMerge.p1 + ExpandoMerge.p2 + ExpandoMerge.p3 + ExpandoMerge.p4 + ExpandoMerge.p5 + ExpandoMerge.p6 + ExpandoMerge.p7 + ExpandoMerge.p8 + ExpandoMerge.p9 + ExpandoMerge.m(12) + ExpandoMerge(1001); diff --git a/crates/swc/tests/tsc-references/typeFromPropertyAssignment31_es5.2.minified.js b/crates/swc/tests/tsc-references/typeFromPropertyAssignment31_es5.2.minified.js index 6783ca5e6ae..b28f9f61da1 100644 --- a/crates/swc/tests/tsc-references/typeFromPropertyAssignment31_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeFromPropertyAssignment31_es5.2.minified.js @@ -1,7 +1,8 @@ -var ExpandoMerge; -function ExpandoMerge1(n) { +function ExpandoMerge(n) { return n; } -ExpandoMerge1.p1 = 111, ExpandoMerge1.m = function(n) { +ExpandoMerge.p1 = 111, ExpandoMerge.m = function(n) { return n + 1; -}, (ExpandoMerge1 || (ExpandoMerge1 = {})).p2 = 222, ExpandoMerge1.p4 = 44444, ExpandoMerge1.p6 = 66666, ExpandoMerge1.p8 = !1, (ExpandoMerge = ExpandoMerge1 || (ExpandoMerge1 = {})).p3 = 333, ExpandoMerge.p4 = 4, ExpandoMerge.p5 = 5, ExpandoMerge.p6 = 6, ExpandoMerge.p7 = 7, ExpandoMerge.p8 = 6, ExpandoMerge.p9 = 7, ExpandoMerge1.p5 = 555555, ExpandoMerge1.p7 = 777777, ExpandoMerge1.p9 = !1, ExpandoMerge1.p1 + ExpandoMerge1.p2 + ExpandoMerge1.p3 + ExpandoMerge1.p4 + ExpandoMerge1.p5 + ExpandoMerge1.p6 + ExpandoMerge1.p7 + ExpandoMerge1.p8 + ExpandoMerge1.p9 + ExpandoMerge1.m(12) + ExpandoMerge1(1001); +}, (ExpandoMerge || (ExpandoMerge = {})).p2 = 222, ExpandoMerge.p4 = 44444, ExpandoMerge.p6 = 66666, ExpandoMerge.p8 = !1, (function(ExpandoMerge1) { + ExpandoMerge1.p3 = 333, ExpandoMerge1.p4 = 4, ExpandoMerge1.p5 = 5, ExpandoMerge1.p6 = 6, ExpandoMerge1.p7 = 7, ExpandoMerge1.p8 = 6, ExpandoMerge1.p9 = 7; +})(ExpandoMerge || (ExpandoMerge = {})), ExpandoMerge.p5 = 555555, ExpandoMerge.p7 = 777777, ExpandoMerge.p9 = !1, ExpandoMerge.p1 + ExpandoMerge.p2 + ExpandoMerge.p3 + ExpandoMerge.p4 + ExpandoMerge.p5 + ExpandoMerge.p6 + ExpandoMerge.p7 + ExpandoMerge.p8 + ExpandoMerge.p9 + ExpandoMerge.m(12) + ExpandoMerge(1001); diff --git a/crates/swc/tests/tsc-references/typeFromPropertyAssignment32_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeFromPropertyAssignment32_es2015.2.minified.js index 4fbe10b3d73..62fac8caeaf 100644 --- a/crates/swc/tests/tsc-references/typeFromPropertyAssignment32_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeFromPropertyAssignment32_es2015.2.minified.js @@ -1,7 +1,8 @@ -var ExpandoMerge; -function ExpandoMerge1(n) { +function ExpandoMerge(n) { return n; } -ExpandoMerge1.p1 = 111, ExpandoMerge1.m = function(n) { +ExpandoMerge.p1 = 111, ExpandoMerge.m = function(n) { return n + 1; -}, ExpandoMerge1.p4 = 44444, ExpandoMerge1.p5 = 555555, ExpandoMerge1.p6 = 66666, ExpandoMerge1.p7 = 777777, ExpandoMerge1.p8 = !1, ExpandoMerge1.p9 = !1, ExpandoMerge1.p1 + ExpandoMerge1.p2 + ExpandoMerge1.p3 + ExpandoMerge1.p4 + ExpandoMerge1.p5 + ExpandoMerge1.p6 + ExpandoMerge1.p7 + ExpandoMerge1.p8 + ExpandoMerge1.p9 + ExpandoMerge1.m(12) + ExpandoMerge1(1001), (ExpandoMerge = ExpandoMerge1 || (ExpandoMerge1 = {})).p3 = 333, ExpandoMerge.p4 = 4, ExpandoMerge.p5 = 5, ExpandoMerge.p6 = 6, ExpandoMerge.p7 = 7, ExpandoMerge.p8 = 6, ExpandoMerge.p9 = 7, (ExpandoMerge1 || (ExpandoMerge1 = {})).p2 = 222; +}, ExpandoMerge.p4 = 44444, ExpandoMerge.p5 = 555555, ExpandoMerge.p6 = 66666, ExpandoMerge.p7 = 777777, ExpandoMerge.p8 = !1, ExpandoMerge.p9 = !1, ExpandoMerge.p1 + ExpandoMerge.p2 + ExpandoMerge.p3 + ExpandoMerge.p4 + ExpandoMerge.p5 + ExpandoMerge.p6 + ExpandoMerge.p7 + ExpandoMerge.p8 + ExpandoMerge.p9 + ExpandoMerge.m(12) + ExpandoMerge(1001), (function(ExpandoMerge1) { + ExpandoMerge1.p3 = 333, ExpandoMerge1.p4 = 4, ExpandoMerge1.p5 = 5, ExpandoMerge1.p6 = 6, ExpandoMerge1.p7 = 7, ExpandoMerge1.p8 = 6, ExpandoMerge1.p9 = 7; +})(ExpandoMerge || (ExpandoMerge = {})), (ExpandoMerge || (ExpandoMerge = {})).p2 = 222; diff --git a/crates/swc/tests/tsc-references/typeFromPropertyAssignment32_es5.2.minified.js b/crates/swc/tests/tsc-references/typeFromPropertyAssignment32_es5.2.minified.js index 4fbe10b3d73..62fac8caeaf 100644 --- a/crates/swc/tests/tsc-references/typeFromPropertyAssignment32_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeFromPropertyAssignment32_es5.2.minified.js @@ -1,7 +1,8 @@ -var ExpandoMerge; -function ExpandoMerge1(n) { +function ExpandoMerge(n) { return n; } -ExpandoMerge1.p1 = 111, ExpandoMerge1.m = function(n) { +ExpandoMerge.p1 = 111, ExpandoMerge.m = function(n) { return n + 1; -}, ExpandoMerge1.p4 = 44444, ExpandoMerge1.p5 = 555555, ExpandoMerge1.p6 = 66666, ExpandoMerge1.p7 = 777777, ExpandoMerge1.p8 = !1, ExpandoMerge1.p9 = !1, ExpandoMerge1.p1 + ExpandoMerge1.p2 + ExpandoMerge1.p3 + ExpandoMerge1.p4 + ExpandoMerge1.p5 + ExpandoMerge1.p6 + ExpandoMerge1.p7 + ExpandoMerge1.p8 + ExpandoMerge1.p9 + ExpandoMerge1.m(12) + ExpandoMerge1(1001), (ExpandoMerge = ExpandoMerge1 || (ExpandoMerge1 = {})).p3 = 333, ExpandoMerge.p4 = 4, ExpandoMerge.p5 = 5, ExpandoMerge.p6 = 6, ExpandoMerge.p7 = 7, ExpandoMerge.p8 = 6, ExpandoMerge.p9 = 7, (ExpandoMerge1 || (ExpandoMerge1 = {})).p2 = 222; +}, ExpandoMerge.p4 = 44444, ExpandoMerge.p5 = 555555, ExpandoMerge.p6 = 66666, ExpandoMerge.p7 = 777777, ExpandoMerge.p8 = !1, ExpandoMerge.p9 = !1, ExpandoMerge.p1 + ExpandoMerge.p2 + ExpandoMerge.p3 + ExpandoMerge.p4 + ExpandoMerge.p5 + ExpandoMerge.p6 + ExpandoMerge.p7 + ExpandoMerge.p8 + ExpandoMerge.p9 + ExpandoMerge.m(12) + ExpandoMerge(1001), (function(ExpandoMerge1) { + ExpandoMerge1.p3 = 333, ExpandoMerge1.p4 = 4, ExpandoMerge1.p5 = 5, ExpandoMerge1.p6 = 6, ExpandoMerge1.p7 = 7, ExpandoMerge1.p8 = 6, ExpandoMerge1.p9 = 7; +})(ExpandoMerge || (ExpandoMerge = {})), (ExpandoMerge || (ExpandoMerge = {})).p2 = 222; diff --git a/crates/swc/tests/tsc-references/typeFromPropertyAssignment33_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeFromPropertyAssignment33_es2015.2.minified.js index 29464dfecdb..d479a2e36a3 100644 --- a/crates/swc/tests/tsc-references/typeFromPropertyAssignment33_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeFromPropertyAssignment33_es2015.2.minified.js @@ -1,7 +1,8 @@ -var ExpandoMerge; -function ExpandoMerge1(n) { +function ExpandoMerge(n) { return n; } -(ExpandoMerge = ExpandoMerge1 || (ExpandoMerge1 = {})).p3 = 333, ExpandoMerge.p4 = 4, ExpandoMerge.p5 = 5, ExpandoMerge.p6 = 6, ExpandoMerge.p7 = 7, ExpandoMerge.p8 = 6, ExpandoMerge.p9 = 7, (ExpandoMerge1 || (ExpandoMerge1 = {})).p2 = 222, ExpandoMerge1.p1 = 111, ExpandoMerge1.m = function(n) { +!function(ExpandoMerge1) { + ExpandoMerge1.p3 = 333, ExpandoMerge1.p4 = 4, ExpandoMerge1.p5 = 5, ExpandoMerge1.p6 = 6, ExpandoMerge1.p7 = 7, ExpandoMerge1.p8 = 6, ExpandoMerge1.p9 = 7; +}(ExpandoMerge || (ExpandoMerge = {})), (ExpandoMerge || (ExpandoMerge = {})).p2 = 222, ExpandoMerge.p1 = 111, ExpandoMerge.m = function(n) { return n + 1; -}, ExpandoMerge1.p4 = 44444, ExpandoMerge1.p5 = 555555, ExpandoMerge1.p6 = 66666, ExpandoMerge1.p7 = 777777, ExpandoMerge1.p8 = !1, ExpandoMerge1.p9 = !1, ExpandoMerge1.p1 + ExpandoMerge1.p2 + ExpandoMerge1.p3 + ExpandoMerge1.p4 + ExpandoMerge1.p5 + ExpandoMerge1.p6 + ExpandoMerge1.p7 + ExpandoMerge1.p8 + ExpandoMerge1.p9 + ExpandoMerge1.m(12) + ExpandoMerge1(1001); +}, ExpandoMerge.p4 = 44444, ExpandoMerge.p5 = 555555, ExpandoMerge.p6 = 66666, ExpandoMerge.p7 = 777777, ExpandoMerge.p8 = !1, ExpandoMerge.p9 = !1, ExpandoMerge.p1 + ExpandoMerge.p2 + ExpandoMerge.p3 + ExpandoMerge.p4 + ExpandoMerge.p5 + ExpandoMerge.p6 + ExpandoMerge.p7 + ExpandoMerge.p8 + ExpandoMerge.p9 + ExpandoMerge.m(12) + ExpandoMerge(1001); diff --git a/crates/swc/tests/tsc-references/typeFromPropertyAssignment33_es5.2.minified.js b/crates/swc/tests/tsc-references/typeFromPropertyAssignment33_es5.2.minified.js index 29464dfecdb..d479a2e36a3 100644 --- a/crates/swc/tests/tsc-references/typeFromPropertyAssignment33_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeFromPropertyAssignment33_es5.2.minified.js @@ -1,7 +1,8 @@ -var ExpandoMerge; -function ExpandoMerge1(n) { +function ExpandoMerge(n) { return n; } -(ExpandoMerge = ExpandoMerge1 || (ExpandoMerge1 = {})).p3 = 333, ExpandoMerge.p4 = 4, ExpandoMerge.p5 = 5, ExpandoMerge.p6 = 6, ExpandoMerge.p7 = 7, ExpandoMerge.p8 = 6, ExpandoMerge.p9 = 7, (ExpandoMerge1 || (ExpandoMerge1 = {})).p2 = 222, ExpandoMerge1.p1 = 111, ExpandoMerge1.m = function(n) { +!function(ExpandoMerge1) { + ExpandoMerge1.p3 = 333, ExpandoMerge1.p4 = 4, ExpandoMerge1.p5 = 5, ExpandoMerge1.p6 = 6, ExpandoMerge1.p7 = 7, ExpandoMerge1.p8 = 6, ExpandoMerge1.p9 = 7; +}(ExpandoMerge || (ExpandoMerge = {})), (ExpandoMerge || (ExpandoMerge = {})).p2 = 222, ExpandoMerge.p1 = 111, ExpandoMerge.m = function(n) { return n + 1; -}, ExpandoMerge1.p4 = 44444, ExpandoMerge1.p5 = 555555, ExpandoMerge1.p6 = 66666, ExpandoMerge1.p7 = 777777, ExpandoMerge1.p8 = !1, ExpandoMerge1.p9 = !1, ExpandoMerge1.p1 + ExpandoMerge1.p2 + ExpandoMerge1.p3 + ExpandoMerge1.p4 + ExpandoMerge1.p5 + ExpandoMerge1.p6 + ExpandoMerge1.p7 + ExpandoMerge1.p8 + ExpandoMerge1.p9 + ExpandoMerge1.m(12) + ExpandoMerge1(1001); +}, ExpandoMerge.p4 = 44444, ExpandoMerge.p5 = 555555, ExpandoMerge.p6 = 66666, ExpandoMerge.p7 = 777777, ExpandoMerge.p8 = !1, ExpandoMerge.p9 = !1, ExpandoMerge.p1 + ExpandoMerge.p2 + ExpandoMerge.p3 + ExpandoMerge.p4 + ExpandoMerge.p5 + ExpandoMerge.p6 + ExpandoMerge.p7 + ExpandoMerge.p8 + ExpandoMerge.p9 + ExpandoMerge.m(12) + ExpandoMerge(1001); diff --git a/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfEqualEqualHasNoEffect_es5.2.minified.js b/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfEqualEqualHasNoEffect_es5.2.minified.js index e81a67b36fe..5e4a884fc2a 100644 --- a/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfEqualEqualHasNoEffect_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfEqualEqualHasNoEffect_es5.2.minified.js @@ -1,7 +1,9 @@ -var obj, strOrC, C = function() { +var strOrC, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -void 0 === strOrC || (obj = strOrC) && "undefined" != typeof Symbol && obj.constructor === Symbol; +void 0 === strOrC || (function(obj) { + return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; +})(strOrC); diff --git a/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfNotEqualHasNoEffect_es5.2.minified.js b/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfNotEqualHasNoEffect_es5.2.minified.js index e81a67b36fe..5e4a884fc2a 100644 --- a/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfNotEqualHasNoEffect_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeGuardOfFormTypeOfNotEqualHasNoEffect_es5.2.minified.js @@ -1,7 +1,9 @@ -var obj, strOrC, C = function() { +var strOrC, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -void 0 === strOrC || (obj = strOrC) && "undefined" != typeof Symbol && obj.constructor === Symbol; +void 0 === strOrC || (function(obj) { + return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; +})(strOrC); diff --git a/crates/swc/tests/tsc-references/typeGuardsWithAny_es5.2.minified.js b/crates/swc/tests/tsc-references/typeGuardsWithAny_es5.2.minified.js index 4118481574c..8e178ec05a5 100644 --- a/crates/swc/tests/tsc-references/typeGuardsWithAny_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeGuardsWithAny_es5.2.minified.js @@ -1,4 +1,6 @@ -var left, right; -left = { +var x = { p: 0 -}, null != (right = Object) && "undefined" != typeof Symbol && right[Symbol.hasInstance] && right[Symbol.hasInstance](left); +}; +(function(left, right) { + null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] && right[Symbol.hasInstance](left); +})(x, Object), x.p, x.p, x.p, x.p, x.p; diff --git a/crates/swc/tests/tsc-references/typeGuardsWithInstanceOf_es5.2.minified.js b/crates/swc/tests/tsc-references/typeGuardsWithInstanceOf_es5.2.minified.js index 0f76bf65222..227cd6a0df1 100644 --- a/crates/swc/tests/tsc-references/typeGuardsWithInstanceOf_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeGuardsWithInstanceOf_es5.2.minified.js @@ -4,8 +4,10 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -left = result, (null != (right = RegExp) && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right) || (result = result2); -var left, right, result, result2, C = function() { +!function(left, right) { + return null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? right[Symbol.hasInstance](left) : left instanceof right; +}(result, RegExp) && (result = result2); +var result, result2, C = function() { "use strict"; var Constructor, protoProps, staticProps; function C() { diff --git a/crates/swc/tests/tsc-references/typeofANonExportedType_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeofANonExportedType_es2015.2.minified.js index da9804de317..70e7af1fc31 100644 --- a/crates/swc/tests/tsc-references/typeofANonExportedType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeofANonExportedType_es2015.2.minified.js @@ -1,5 +1,11 @@ -var M, E, M1, E, foo; -function foo1() {} -(M1 = M || (M = {})).foo = "", M1.C = class { -}, (E = E || (E = {}))[E.A = 0] = "A", (foo = foo1 || (foo1 = {})).y = 1, foo.C = class { -}; +var M, E; +function foo() {} +!function(M1) { + M1.foo = "", M1.C = class { + }; +}(M || (M = {})), (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), (function(foo1) { + foo1.y = 1, foo1.C = class { + }; +})(foo || (foo = {})); diff --git a/crates/swc/tests/tsc-references/typeofANonExportedType_es5.2.minified.js b/crates/swc/tests/tsc-references/typeofANonExportedType_es5.2.minified.js index 25a30244c70..6210ab58a37 100644 --- a/crates/swc/tests/tsc-references/typeofANonExportedType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeofANonExportedType_es5.2.minified.js @@ -1,7 +1,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -var M, E, E, C = function() { +var M, E, C = function() { "use strict"; _classCallCheck(this, C); }; @@ -13,7 +13,9 @@ function foo() {} _classCallCheck(this, C1); }; M1.C = C1; -}(M || (M = {})), (E = E || (E = {}))[E.A = 0] = "A", (function(foo1) { +}(M || (M = {})), (function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), (function(foo1) { foo1.y = 1; var C2 = function() { "use strict"; diff --git a/crates/swc/tests/tsc-references/typeofAnExportedType_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeofAnExportedType_es2015.2.minified.js index 221e7ea71f4..07c62da9a81 100644 --- a/crates/swc/tests/tsc-references/typeofAnExportedType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeofAnExportedType_es2015.2.minified.js @@ -1,15 +1,19 @@ -var M, E, foo, r1, r2, c, c2, r3, r4, r4b, i, i2, r5, r5, M1, r6, r7, r8, r9, E, r10, r11, r12, r13, x = 1; -export { M1 as M }; +export var r1, r2, c, c2, r3, r4, r4b, i, i2, r5, r5, M, r6, r7, r8, r9, E, r10, r11, r12, r13, x = 1; export var y = { foo: "" }; export class C { } -(M = M1 || (M1 = {})).foo = "", M.C = class { -}; -export var Z = M1; -E = E || (E = {}), E[E.A = 0] = "A"; -function foo1() {} -export { foo1 as foo }; -(foo = foo1 || (foo1 = {})).y = 1, foo.C = class { -}; +!function(M1) { + M1.foo = "", M1.C = class { + }; +}(M || (M = {})); +export var Z = M; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); +export function foo() {} +!function(foo1) { + foo1.y = 1, foo1.C = class { + }; +}(foo || (foo = {})); diff --git a/crates/swc/tests/tsc-references/typeofAnExportedType_es5.2.minified.js b/crates/swc/tests/tsc-references/typeofAnExportedType_es5.2.minified.js index 5755e46d0f7..f9d7fdf6dae 100644 --- a/crates/swc/tests/tsc-references/typeofAnExportedType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeofAnExportedType_es5.2.minified.js @@ -1,7 +1,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -export var E, r1, r2, c, c2, r3, r4, r4b, i, i2, r5, r5, M, r6, r7, r8, r9, E, r10, r11, r12, r13, x = 1; +export var r1, r2, c, c2, r3, r4, r4b, i, i2, r5, r5, M, r6, r7, r8, r9, E, r10, r11, r12, r13, x = 1; export var y = { foo: "" }; @@ -18,7 +18,9 @@ export var C = function() { M1.C = C1; }(M || (M = {})); export var Z = M; -E = E || (E = {}), E[E.A = 0] = "A"; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); export function foo() {} !function(foo1) { foo1.y = 1; diff --git a/crates/swc/tests/tsc-references/typeofOperatorWithEnumType_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeofOperatorWithEnumType_es2015.2.minified.js index 5115ce30396..83390a13fb9 100644 --- a/crates/swc/tests/tsc-references/typeofOperatorWithEnumType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeofOperatorWithEnumType_es2015.2.minified.js @@ -1,4 +1,6 @@ -var ENUM1, ENUM, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ENUM1.A, ENUM[0] + ENUM1.B, ENUM[0] + ENUM1.B, ENUM1.B; +var ENUM, ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ENUM1.A, ENUM[0] + ENUM1.B, ENUM[0] + ENUM1.B, ENUM1.B; z: ; z: ; diff --git a/crates/swc/tests/tsc-references/typeofOperatorWithEnumType_es5.2.minified.js b/crates/swc/tests/tsc-references/typeofOperatorWithEnumType_es5.2.minified.js index b4b47c48085..a3247c7753e 100644 --- a/crates/swc/tests/tsc-references/typeofOperatorWithEnumType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeofOperatorWithEnumType_es5.2.minified.js @@ -1,6 +1,8 @@ -var ENUM1, ENUM, ENUM1, _typeof = function(obj) { +var ENUM, ENUM1, _typeof = function(obj) { return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; }; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", void 0 === ENUM || _typeof(ENUM), void 0 === ENUM1 || _typeof(ENUM1), _typeof(ENUM1.A), _typeof(ENUM[0] + ENUM1.B), _typeof(void 0 === ENUM ? "undefined" : _typeof(ENUM)), _typeof(_typeof(_typeof(ENUM[0] + ENUM1.B))), void 0 === ENUM || _typeof(ENUM), void 0 === ENUM1 || _typeof(ENUM1), _typeof(ENUM1.B), void 0 === ENUM || _typeof(ENUM); +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), void 0 === ENUM || _typeof(ENUM), void 0 === ENUM1 || _typeof(ENUM1), _typeof(ENUM1.A), _typeof(ENUM[0] + ENUM1.B), _typeof(void 0 === ENUM ? "undefined" : _typeof(ENUM)), _typeof(_typeof(_typeof(ENUM[0] + ENUM1.B))), void 0 === ENUM || _typeof(ENUM), void 0 === ENUM1 || _typeof(ENUM1), _typeof(ENUM1.B), void 0 === ENUM || _typeof(ENUM); z: void 0 === ENUM || _typeof(ENUM); z: void 0 === ENUM1 || _typeof(ENUM1); diff --git a/crates/swc/tests/tsc-references/undefinedAssignableToEveryType_es2015.2.minified.js b/crates/swc/tests/tsc-references/undefinedAssignableToEveryType_es2015.2.minified.js index 5f410993c04..4f81f678e53 100644 --- a/crates/swc/tests/tsc-references/undefinedAssignableToEveryType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/undefinedAssignableToEveryType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A"; +var E; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/undefinedAssignableToEveryType_es5.2.minified.js b/crates/swc/tests/tsc-references/undefinedAssignableToEveryType_es5.2.minified.js index f70e6cc54e8..9eba7da8a34 100644 --- a/crates/swc/tests/tsc-references/undefinedAssignableToEveryType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/undefinedAssignableToEveryType_es5.2.minified.js @@ -1,7 +1,9 @@ -var E, E, C = function() { +var E, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -(E = E || (E = {}))[E.A = 0] = "A"; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); diff --git a/crates/swc/tests/tsc-references/undefinedIsSubtypeOfEverything_es2015.2.minified.js b/crates/swc/tests/tsc-references/undefinedIsSubtypeOfEverything_es2015.2.minified.js index 3f3700c80c3..65f9a16b279 100644 --- a/crates/swc/tests/tsc-references/undefinedIsSubtypeOfEverything_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/undefinedIsSubtypeOfEverything_es2015.2.minified.js @@ -1,6 +1,8 @@ -var E, E; +var E; function f() {} -(E = E || (E = {}))[E.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), (f || (f = {})).bar = 1; class c { } (c || (c = {})).bar = 1; diff --git a/crates/swc/tests/tsc-references/undefinedIsSubtypeOfEverything_es5.2.minified.js b/crates/swc/tests/tsc-references/undefinedIsSubtypeOfEverything_es5.2.minified.js index f0e91475252..441ff7e1ac8 100644 --- a/crates/swc/tests/tsc-references/undefinedIsSubtypeOfEverything_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/undefinedIsSubtypeOfEverything_es5.2.minified.js @@ -44,7 +44,7 @@ function _createSuper(Derived) { })(self); }; } -var E, E, Base = function() { +var Base = function() { "use strict"; _classCallCheck(this, Base); }, D0 = function(Base1) { @@ -168,7 +168,9 @@ var E, E, Base = function() { } return D10; }(Base); -(E = E || (E = {}))[E.A = 0] = "A"; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})); var D11 = function(Base16) { "use strict"; _inherits(D11, Base16); @@ -180,7 +182,7 @@ var D11 = function(Base16) { }(Base); function f() {} (f || (f = {})).bar = 1; -var D12 = function(Base17) { +var E, D12 = function(Base17) { "use strict"; _inherits(D12, Base17); var _super = _createSuper(D12); diff --git a/crates/swc/tests/tsc-references/unionAndIntersectionInference1_es5.2.minified.js b/crates/swc/tests/tsc-references/unionAndIntersectionInference1_es5.2.minified.js index 89e50263146..1fd1ec12d0d 100644 --- a/crates/swc/tests/tsc-references/unionAndIntersectionInference1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/unionAndIntersectionInference1_es5.2.minified.js @@ -1,7 +1,7 @@ var y = void 0; -!function(something, haveValue, haveY) { - return something === y ? haveY(y) : haveValue(something); -}(Math.random() > 0.5 ? "hey!" : void 0, function(text) { +(function(something, haveValue, haveY) { + something === y ? haveY(y) : haveValue(something); +})(Math.random() > 0.5 ? "hey!" : void 0, function(text) { return "string"; }, function(y) { return "other one"; diff --git a/crates/swc/tests/tsc-references/unionSubtypeIfEveryConstituentTypeIsSubtype_es2015.2.minified.js b/crates/swc/tests/tsc-references/unionSubtypeIfEveryConstituentTypeIsSubtype_es2015.2.minified.js index 6c1bc53ca54..9573682cdfd 100644 --- a/crates/swc/tests/tsc-references/unionSubtypeIfEveryConstituentTypeIsSubtype_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/unionSubtypeIfEveryConstituentTypeIsSubtype_es2015.2.minified.js @@ -1,6 +1,10 @@ -var e, E2, e, E2; +var e, E2; function f() {} -(e = e || (e = {}))[e.e1 = 0] = "e1", e[e.e2 = 1] = "e2", (E2 = E2 || (E2 = {}))[E2.A = 0] = "A", (f || (f = {})).bar = 1; +!function(e) { + e[e.e1 = 0] = "e1", e[e.e2 = 1] = "e2"; +}(e || (e = {})), (function(E2) { + E2[E2.A = 0] = "A"; +})(E2 || (E2 = {})), (f || (f = {})).bar = 1; class c { } (c || (c = {})).bar = 1; diff --git a/crates/swc/tests/tsc-references/unionSubtypeIfEveryConstituentTypeIsSubtype_es5.2.minified.js b/crates/swc/tests/tsc-references/unionSubtypeIfEveryConstituentTypeIsSubtype_es5.2.minified.js index b7a3a9fdd03..c57b64ff93d 100644 --- a/crates/swc/tests/tsc-references/unionSubtypeIfEveryConstituentTypeIsSubtype_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/unionSubtypeIfEveryConstituentTypeIsSubtype_es5.2.minified.js @@ -1,8 +1,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -(e = e || (e = {}))[e.e1 = 0] = "e1", e[e.e2 = 1] = "e2"; -var e, e, E2, E2, A = function() { +!function(e) { + e[e.e1 = 0] = "e1", e[e.e2 = 1] = "e2"; +}(e || (e = {})); +var e, E2, A = function() { "use strict"; _classCallCheck(this, A); }, A2 = function() { @@ -10,7 +12,9 @@ var e, e, E2, E2, A = function() { _classCallCheck(this, A2); }; function f() {} -(E2 = E2 || (E2 = {}))[E2.A = 0] = "A", (f || (f = {})).bar = 1; +!function(E2) { + E2[E2.A = 0] = "A"; +}(E2 || (E2 = {})), (f || (f = {})).bar = 1; var c = function() { "use strict"; _classCallCheck(this, c); diff --git a/crates/swc/tests/tsc-references/unionsOfTupleTypes1_es5.2.minified.js b/crates/swc/tests/tsc-references/unionsOfTupleTypes1_es5.2.minified.js index 236d9a0e6e6..06800f7f0e9 100644 --- a/crates/swc/tests/tsc-references/unionsOfTupleTypes1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/unionsOfTupleTypes1_es5.2.minified.js @@ -3,35 +3,37 @@ function _arrayLikeToArray(arr, len) { for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } -var arr, i, _ex = (i = 2, function(arr) { - if (Array.isArray(arr)) return arr; -}(arr = [ - "hi" -]) || function(arr, i) { - var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; - if (null != _i) { - var _arr = [], _n = !0, _d = !1; - try { - for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); - } catch (err) { - _d = !0, _e = err; - } finally{ +var _ex = function(arr, i) { + return (function(arr) { + if (Array.isArray(arr)) return arr; + })(arr) || (function(arr, i) { + var _s, _e, _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; + if (null != _i) { + var _arr = [], _n = !0, _d = !1; try { - _n || null == _i.return || _i.return(); + for(_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !i || _arr.length !== i); _n = !0); + } catch (err) { + _d = !0, _e = err; } finally{ - if (_d) throw _e; + try { + _n || null == _i.return || _i.return(); + } finally{ + if (_d) throw _e; + } } + return _arr; } - return _arr; - } -}(arr, i) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -}(arr, i) || function() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -}()); + })(arr, i) || (function(o, minLen) { + if (o) { + if ("string" == typeof o) return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); + if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + })(arr, i) || (function() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + })(); +}([ + "hi" +], 2); _ex[0], _ex[1]; diff --git a/crates/swc/tests/tsc-references/unknownType2_es2015.2.minified.js b/crates/swc/tests/tsc-references/unknownType2_es2015.2.minified.js index f5d3edb9bbd..d1b81765355 100644 --- a/crates/swc/tests/tsc-references/unknownType2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/unknownType2_es2015.2.minified.js @@ -1,3 +1,7 @@ -var NumberEnum, StringEnum, NumberEnum, StringEnum; +var NumberEnum, StringEnum; const u = void 0; -5 === u && u.toString(10), !0 === u || !1 === u, (NumberEnum = NumberEnum || (NumberEnum = {}))[NumberEnum.A = 0] = "A", NumberEnum[NumberEnum.B = 1] = "B", NumberEnum[NumberEnum.C = 2] = "C", (StringEnum = StringEnum || (StringEnum = {})).A = "A", StringEnum.B = "B", StringEnum.C = "C", u === NumberEnum || u === StringEnum, NumberEnum.A, StringEnum.B; +5 === u && u.toString(10), !0 === u || !1 === u, (function(NumberEnum) { + NumberEnum[NumberEnum.A = 0] = "A", NumberEnum[NumberEnum.B = 1] = "B", NumberEnum[NumberEnum.C = 2] = "C"; +})(NumberEnum || (NumberEnum = {})), (function(StringEnum) { + StringEnum.A = "A", StringEnum.B = "B", StringEnum.C = "C"; +})(StringEnum || (StringEnum = {})), u === NumberEnum || u === StringEnum, NumberEnum.A, StringEnum.B; diff --git a/crates/swc/tests/tsc-references/unknownType2_es5.2.minified.js b/crates/swc/tests/tsc-references/unknownType2_es5.2.minified.js index 2b531fd1c62..7faf8731086 100644 --- a/crates/swc/tests/tsc-references/unknownType2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/unknownType2_es5.2.minified.js @@ -1,2 +1,6 @@ -var NumberEnum, StringEnum, NumberEnum, StringEnum, u = void 0; -5 === u && u.toString(10), !0 === u || !1 === u, (NumberEnum = NumberEnum || (NumberEnum = {}))[NumberEnum.A = 0] = "A", NumberEnum[NumberEnum.B = 1] = "B", NumberEnum[NumberEnum.C = 2] = "C", (StringEnum = StringEnum || (StringEnum = {})).A = "A", StringEnum.B = "B", StringEnum.C = "C", u === NumberEnum || u === StringEnum, NumberEnum.A, StringEnum.B; +var NumberEnum, StringEnum, u = void 0; +5 === u && u.toString(10), !0 === u || !1 === u, (function(NumberEnum) { + NumberEnum[NumberEnum.A = 0] = "A", NumberEnum[NumberEnum.B = 1] = "B", NumberEnum[NumberEnum.C = 2] = "C"; +})(NumberEnum || (NumberEnum = {})), (function(StringEnum) { + StringEnum.A = "A", StringEnum.B = "B", StringEnum.C = "C"; +})(StringEnum || (StringEnum = {})), u === NumberEnum || u === StringEnum, NumberEnum.A, StringEnum.B; diff --git a/crates/swc/tests/tsc-references/validEnumAssignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/validEnumAssignments_es2015.2.minified.js index e785289e755..6e6d3e3b103 100644 --- a/crates/swc/tests/tsc-references/validEnumAssignments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/validEnumAssignments_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, n, e, E; -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", n = e, n = E.A, E.A, e = e, e = E.A, e = E.B, e = n, e = null, e = void 0, e = 1, e = 1, e = 1, e = -1; +var E, n, e; +(function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B"; +})(E || (E = {})), n = e, n = E.A, E.A, e = e, e = E.A, e = E.B, e = n, e = null, e = void 0, e = 1, e = 1, e = 1, e = -1; diff --git a/crates/swc/tests/tsc-references/validEnumAssignments_es5.2.minified.js b/crates/swc/tests/tsc-references/validEnumAssignments_es5.2.minified.js index e785289e755..6e6d3e3b103 100644 --- a/crates/swc/tests/tsc-references/validEnumAssignments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/validEnumAssignments_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, n, e, E; -(E = E || (E = {}))[E.A = 0] = "A", E[E.B = 1] = "B", n = e, n = E.A, E.A, e = e, e = E.A, e = E.B, e = n, e = null, e = void 0, e = 1, e = 1, e = 1, e = -1; +var E, n, e; +(function(E) { + E[E.A = 0] = "A", E[E.B = 1] = "B"; +})(E || (E = {})), n = e, n = E.A, E.A, e = e, e = E.A, e = E.B, e = n, e = null, e = void 0, e = 1, e = 1, e = 1, e = -1; diff --git a/crates/swc/tests/tsc-references/validNullAssignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/validNullAssignments_es2015.2.minified.js index 3b3518c699a..04b168e5e7b 100644 --- a/crates/swc/tests/tsc-references/validNullAssignments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/validNullAssignments_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, M, E; -(E = E || (E = {}))[E.A = 0] = "A", E.A = null, I = null, (M || (M = {})).x = 1, M = null; +var E, M; +(function(E) { + E[E.A = 0] = "A"; +})(E || (E = {})), E.A = null, I = null, (M || (M = {})).x = 1, M = null; diff --git a/crates/swc/tests/tsc-references/validNullAssignments_es5.2.minified.js b/crates/swc/tests/tsc-references/validNullAssignments_es5.2.minified.js index b8721b8cbeb..d48b064bbe7 100644 --- a/crates/swc/tests/tsc-references/validNullAssignments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/validNullAssignments_es5.2.minified.js @@ -1,5 +1,7 @@ -var E, M, E; -(E = E || (E = {}))[E.A = 0] = "A", E.A = null; +var E, M; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), E.A = null; var C = function() { "use strict"; !function(instance, Constructor) { diff --git a/crates/swc/tests/tsc-references/validNumberAssignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/validNumberAssignments_es2015.2.minified.js index 9b0af19df18..670bc37f0d8 100644 --- a/crates/swc/tests/tsc-references/validNumberAssignments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/validNumberAssignments_es2015.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A", E.A; +var E; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), E.A; diff --git a/crates/swc/tests/tsc-references/validNumberAssignments_es5.2.minified.js b/crates/swc/tests/tsc-references/validNumberAssignments_es5.2.minified.js index 9b0af19df18..670bc37f0d8 100644 --- a/crates/swc/tests/tsc-references/validNumberAssignments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/validNumberAssignments_es5.2.minified.js @@ -1,2 +1,4 @@ -var E, E; -(E = E || (E = {}))[E.A = 0] = "A", E.A; +var E; +!function(E) { + E[E.A = 0] = "A"; +}(E || (E = {})), E.A; diff --git a/crates/swc/tests/tsc-references/voidOperatorWithEnumType_es2015.2.minified.js b/crates/swc/tests/tsc-references/voidOperatorWithEnumType_es2015.2.minified.js index 57c0449e7bb..3257e59b046 100644 --- a/crates/swc/tests/tsc-references/voidOperatorWithEnumType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/voidOperatorWithEnumType_es2015.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ENUM1.A, ENUM[0] + ENUM1.B, ENUM[0] + ENUM1.B, ENUM1.B; +var ENUM, ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ENUM1.A, ENUM[0] + ENUM1.B, ENUM[0] + ENUM1.B, ENUM1.B; diff --git a/crates/swc/tests/tsc-references/voidOperatorWithEnumType_es5.2.minified.js b/crates/swc/tests/tsc-references/voidOperatorWithEnumType_es5.2.minified.js index 57c0449e7bb..3257e59b046 100644 --- a/crates/swc/tests/tsc-references/voidOperatorWithEnumType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/voidOperatorWithEnumType_es5.2.minified.js @@ -1,2 +1,4 @@ -var ENUM1, ENUM, ENUM1; -(ENUM1 = ENUM1 || (ENUM1 = {}))[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = "", ENUM1.A, ENUM[0] + ENUM1.B, ENUM[0] + ENUM1.B, ENUM1.B; +var ENUM, ENUM1; +!function(ENUM1) { + ENUM1[ENUM1.A = 0] = "A", ENUM1[ENUM1.B = 1] = "B", ENUM1[ENUM1[""] = 2] = ""; +}(ENUM1 || (ENUM1 = {})), ENUM1.A, ENUM[0] + ENUM1.B, ENUM[0] + ENUM1.B, ENUM1.B; diff --git a/crates/swc_ecma_minifier/src/analyzer/mod.rs b/crates/swc_ecma_minifier/src/analyzer/mod.rs index 2f34f2ecb42..d49d286f0ad 100644 --- a/crates/swc_ecma_minifier/src/analyzer/mod.rs +++ b/crates/swc_ecma_minifier/src/analyzer/mod.rs @@ -676,6 +676,21 @@ where } } + fn visit_pat_or_expr(&mut self, n: &PatOrExpr) { + match n { + PatOrExpr::Expr(e) => { + if let Expr::Ident(i) = &**e { + self.visit_pat_id(&i) + } else { + e.visit_with(self); + } + } + PatOrExpr::Pat(p) => { + p.visit_with(self); + } + } + } + fn visit_prop(&mut self, n: &Prop) { let ctx = Ctx { in_update_arg: false, diff --git a/crates/swc_ecma_minifier/src/compress/hoist_decls.rs b/crates/swc_ecma_minifier/src/compress/hoist_decls.rs index 84be35ea5cb..bc23c471950 100644 --- a/crates/swc_ecma_minifier/src/compress/hoist_decls.rs +++ b/crates/swc_ecma_minifier/src/compress/hoist_decls.rs @@ -1,3 +1,4 @@ +use super::util::drop_invalid_stmts; use crate::{ analyzer::{ProgramData, UsageAnalyzer}, util::{is_hoisted_var_decl_without_init, sort::is_sorted_by_key, IsModuleItem}, @@ -127,17 +128,14 @@ impl Hoister<'_> { } } - match decl.init { - Some(init) => { - // - exprs.push(Box::new(Expr::Assign(AssignExpr { - span: decl.span, - left: PatOrExpr::Pat(Box::new(decl.name)), - op: op!("="), - right: init, - }))); - } - None => {} + if let Some(init) = decl.init { + // + exprs.push(Box::new(Expr::Assign(AssignExpr { + span: decl.span, + left: PatOrExpr::Pat(Box::new(decl.name)), + op: op!("="), + right: init, + }))); } } @@ -203,16 +201,13 @@ impl Hoister<'_> { Stmt::Decl(Decl::Var(..)) => new_stmts.push(T::from_stmt(stmt)), _ => { - match stmt { - Stmt::Throw(..) => { - fn_decls.push(T::from_stmt(Stmt::Decl(Decl::Var(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - declare: false, - decls: var_decls.take(), - })))); - } - _ => {} + if let Stmt::Throw(..) = stmt { + fn_decls.push(T::from_stmt(Stmt::Decl(Decl::Var(VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Var, + declare: false, + decls: var_decls.take(), + })))); } found_non_var_decl = true; new_stmts.push(T::from_stmt(stmt)) @@ -231,6 +226,8 @@ impl Hoister<'_> { })))); fn_decls.extend(new_stmts); + drop_invalid_stmts(&mut fn_decls); + *stmts = fn_decls; } } diff --git a/crates/swc_ecma_minifier/src/compress/optimize/iife.rs b/crates/swc_ecma_minifier/src/compress/optimize/iife.rs index 50945a9014a..d82f3cb1302 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/iife.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/iife.rs @@ -523,17 +523,15 @@ where fn can_inline_fn_like(&self, param_ids: &[Ident], body: &BlockStmt) -> bool { // Don't create top-level variables. - if !param_ids.is_empty() { - if self.ctx.in_top_level() && !self.options.module { - for pid in param_ids { - if let Some(usage) = self - .data - .as_ref() - .and_then(|data| data.vars.get(&pid.to_id())) - { - if usage.ref_count > 1 || usage.assign_count > 0 || usage.inline_prevented { - return false; - } + if !param_ids.is_empty() && self.ctx.in_top_level() { + for pid in param_ids { + if let Some(usage) = self + .data + .as_ref() + .and_then(|data| data.vars.get(&pid.to_id())) + { + if usage.ref_count > 1 || usage.assign_count > 0 || usage.inline_prevented { + return false; } } } diff --git a/crates/swc_ecma_minifier/src/compress/optimize/join_vars.rs b/crates/swc_ecma_minifier/src/compress/optimize/join_vars.rs index 41b41db0eb2..827125a5d40 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/join_vars.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/join_vars.rs @@ -1,5 +1,8 @@ use super::Optimizer; -use crate::{compress::util::is_directive, mode::Mode}; +use crate::{ + compress::util::{drop_invalid_stmts, is_directive}, + mode::Mode, +}; use swc_common::util::take::Take; use swc_ecma_ast::*; use swc_ecma_utils::StmtLike; @@ -104,7 +107,10 @@ where .map(|v| v.kind == VarDeclKind::Var) .unwrap_or(true) => { - stmt.init = cur.take().map(VarDeclOrExpr::VarDecl); + stmt.init = cur + .take() + .and_then(|v| if v.decls.is_empty() { None } else { Some(v) }) + .map(VarDeclOrExpr::VarDecl); new.push(T::from_stmt(Stmt::For(stmt))) } @@ -133,6 +139,8 @@ where new.extend(cur.take().map(Decl::Var).map(Stmt::Decl).map(T::from_stmt)); + drop_invalid_stmts(&mut new); + *stmts = new; } } diff --git a/crates/swc_ecma_minifier/src/compress/optimize/mod.rs b/crates/swc_ecma_minifier/src/compress/optimize/mod.rs index 6b94713ecf6..2312d6dfb00 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/mod.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] use self::util::MultiReplacer; -use super::util::is_fine_for_if_cons; +use super::util::{drop_invalid_stmts, is_fine_for_if_cons}; use crate::{ analyzer::{ProgramData, UsageAnalyzer}, compress::util::is_pure_undefined, @@ -242,7 +242,7 @@ where fn handle_stmt_likes(&mut self, stmts: &mut Vec) where T: StmtLike + ModuleItemLike + ModuleItemExt + VisitMutWith, - Vec: VisitMutWith + VisitWith, + Vec: VisitMutWith + VisitWith + VisitWith, { match self.data { Some(..) => {} @@ -260,8 +260,8 @@ where if stmts.len() >= 1 { // TODO: Handle multiple directives. - match stmts[0].as_stmt() { - Some(Stmt::Expr(ExprStmt { expr, .. })) => match &**expr { + if let Some(Stmt::Expr(ExprStmt { expr, .. })) = stmts[0].as_stmt() { + match &**expr { Expr::Lit(Lit::Str(v)) => { directive_count += 1; @@ -276,8 +276,7 @@ where } } _ => {} - }, - _ => {} + } } } @@ -313,25 +312,55 @@ where self.ctx.in_asm |= use_asm; + if cfg!(debug_assertions) { + stmts.visit_with(&mut AssertValid); + } + self.reorder_stmts(stmts); + if cfg!(debug_assertions) { + stmts.visit_with(&mut AssertValid); + } + self.merge_sequences_in_stmts(stmts); + if cfg!(debug_assertions) { + stmts.visit_with(&mut AssertValid); + } + self.merge_similar_ifs(stmts); + + if cfg!(debug_assertions) { + stmts.visit_with(&mut AssertValid); + } + self.join_vars(stmts); + if cfg!(debug_assertions) { + stmts.visit_with(&mut AssertValid); + } + self.make_sequences(stmts); + if cfg!(debug_assertions) { + stmts.visit_with(&mut AssertValid); + } + self.drop_else_token(stmts); + if cfg!(debug_assertions) { + stmts.visit_with(&mut AssertValid); + } + self.break_assignments_in_seqs(stmts); + if cfg!(debug_assertions) { + stmts.visit_with(&mut AssertValid); + } + // stmts.extend(self.append_stmts.drain(..).map(T::from_stmt)); - stmts.retain(|stmt| match stmt.as_stmt() { - Some(Stmt::Empty(..)) => false, - _ => true, - }); + drop_invalid_stmts(stmts); // debug_assert_eq!(self.prepend_stmts, vec![]); // self.prepend_stmts = prepend_stmts; @@ -1581,6 +1610,10 @@ where } self.prepend_stmts = prepend; + + if let BlockStmtOrExpr::BlockStmt(body) = &mut n.body { + drop_invalid_stmts(&mut body.stmts); + } } fn visit_mut_assign_expr(&mut self, e: &mut AssignExpr) { @@ -1949,7 +1982,7 @@ where } } - if cfg!(feature = "debug") && cfg!(debug_assertions) { + if cfg!(debug_assertions) { n.visit_with(&mut AssertValid); } } @@ -2039,12 +2072,12 @@ where let optimizer = &mut *self.with_ctx(ctx); n.params.visit_mut_with(optimizer); - match n.body.as_mut() { - Some(body) => { - // Bypass block scope handler. - body.visit_mut_children_with(optimizer); + if let Some(body) = n.body.as_mut() { + // Bypass block scope handler. + body.visit_mut_children_with(optimizer); + if cfg!(debug_assertions) { + body.visit_with(&mut AssertValid); } - None => {} } } @@ -2063,7 +2096,11 @@ where self.ctx.in_asm = old_in_asm; - if cfg!(feature = "debug") && cfg!(debug_assertions) { + if let Some(body) = &mut n.body { + drop_invalid_stmts(&mut body.stmts); + } + + if cfg!(debug_assertions) { n.visit_with(&mut AssertValid); } } @@ -2140,10 +2177,7 @@ where changed: false, }); - stmts.retain(|s| match s { - ModuleItem::Stmt(Stmt::Empty(..)) => false, - _ => true, - }); + drop_invalid_stmts(stmts); } fn visit_mut_new_expr(&mut self, n: &mut NewExpr) { @@ -2184,14 +2218,12 @@ where Some(VarDeclOrExpr::Expr(e)) => match &mut **e { Expr::Seq(SeqExpr { exprs, .. }) if exprs.is_empty() => { *n = None; - return; } _ => {} }, Some(VarDeclOrExpr::VarDecl(v)) => { if v.decls.is_empty() { *n = None; - return; } } _ => {} @@ -2230,7 +2262,7 @@ where _ => {} } - if cfg!(feature = "debug") && cfg!(debug_assertions) { + if cfg!(debug_assertions) { n.visit_with(&mut AssertValid); } } @@ -2335,6 +2367,20 @@ where ..self.ctx }; s.visit_mut_children_with(&mut *self.with_ctx(ctx)); + if self.prepend_stmts.is_empty() && self.append_stmts.is_empty() { + match s { + // We use var decl with no declarator to indicate we dropped an decl. + Stmt::Decl(Decl::Var(VarDecl { decls, .. })) if decls.is_empty() => { + *s = Stmt::Empty(EmptyStmt { span: DUMMY_SP }); + return; + } + _ => {} + } + + if cfg!(debug_assertions) { + s.visit_with(&mut AssertValid); + } + } if let Stmt::Labeled(LabeledStmt { label: Ident { @@ -2369,8 +2415,17 @@ where .into_iter() .chain(once(s.take())) .chain(self.append_stmts.take().into_iter()) + .filter(|s| match s { + Stmt::Empty(..) => false, + Stmt::Decl(Decl::Var(v)) => !v.decls.is_empty(), + _ => true, + }) .collect(), }); + + if cfg!(debug_assertions) { + s.visit_with(&mut AssertValid); + } } self.prepend_stmts = old_prepend; @@ -2438,6 +2493,10 @@ where _ => {} } + if cfg!(debug_assertions) { + s.visit_with(&mut AssertValid); + } + self.compress_if_without_alt(s); self.compress_if_stmt_as_cond(s); @@ -2456,7 +2515,7 @@ where } } - if cfg!(feature = "debug") && cfg!(debug_assertions) { + if cfg!(debug_assertions) { s.visit_with(&mut AssertValid); } } @@ -2473,10 +2532,7 @@ where self.with_ctx(ctx).merge_var_decls(stmts); - stmts.retain(|s| match s { - Stmt::Empty(..) => false, - _ => true, - }); + drop_invalid_stmts(stmts); if stmts.len() == 1 { match &stmts[0] { @@ -2492,7 +2548,7 @@ where } } - if cfg!(feature = "debug") && cfg!(debug_assertions) { + if cfg!(debug_assertions) { stmts.visit_with(&mut AssertValid); } } diff --git a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs index 9cefaf44605..fd3aef8eff0 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs @@ -500,45 +500,48 @@ where /// This method actually `hoist`s [VarDecl]s declared with `var`. fn extract_vars(&mut self, s: &mut Stmt) { let mut found_other = false; - match s { - Stmt::Block(bs) => { - // Extract variables without - for stmt in &mut bs.stmts { - match stmt { - Stmt::Decl(Decl::Var( - v @ VarDecl { - kind: VarDeclKind::Var, - .. - }, - )) => { - for decl in &mut v.decls { - if decl.init.is_some() { - continue; - } - self.changed = true; - tracing::debug!("sequences: Hoisting `var` without init"); - let s = Stmt::Decl(Decl::Var(VarDecl { - span: v.span, - kind: VarDeclKind::Var, - declare: false, - decls: vec![decl.take()], - })); - if found_other { - self.append_stmts.push(s); - } else { - self.prepend_stmts.push(s); - } + if let Stmt::Block(bs) = s { + // Extract variables without + for stmt in &mut bs.stmts { + match stmt { + Stmt::Decl(Decl::Var( + v @ VarDecl { + kind: VarDeclKind::Var, + .. + }, + )) => { + for decl in &mut v.decls { + if decl.init.is_some() { + continue; } + self.changed = true; + tracing::debug!("sequences: Hoisting `var` without init"); + let s = Stmt::Decl(Decl::Var(VarDecl { + span: v.span, + kind: VarDeclKind::Var, + declare: false, + decls: vec![decl.take()], + })); + if found_other { + self.append_stmts.push(s); + } else { + self.prepend_stmts.push(s); + } + } - v.decls.retain(|v| !v.name.is_invalid()); - } - _ => { - found_other = true; - } + v.decls.retain(|v| !v.name.is_invalid()); + } + _ => { + found_other = true; } } } - _ => {} + + bs.stmts.retain(|s| match s { + Stmt::Empty(..) => false, + Stmt::Decl(Decl::Var(v)) => !v.decls.is_empty(), + _ => true, + }); } } diff --git a/crates/swc_ecma_minifier/src/compress/pure/mod.rs b/crates/swc_ecma_minifier/src/compress/pure/mod.rs index 35494868779..0a7216f70b9 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/mod.rs @@ -382,21 +382,6 @@ where } } - fn visit_mut_super_prop_expr(&mut self, e: &mut SuperPropExpr) { - if let SuperProp::Computed(c) = &mut e.prop { - c.visit_mut_with(self); - - if let Some(ident) = self.optimize_property_of_member_expr(None, c) { - e.prop = SuperProp::Ident(ident); - return; - }; - - if let Some(ident) = self.handle_known_computed_member_expr(c) { - e.prop = SuperProp::Ident(ident) - }; - } - } - fn visit_mut_module_items(&mut self, items: &mut Vec) { self.visit_par(items); @@ -415,6 +400,20 @@ where e.args.visit_mut_with(self); } + fn visit_mut_pat_or_expr(&mut self, n: &mut PatOrExpr) { + n.visit_mut_children_with(self); + + match n { + PatOrExpr::Expr(e) => { + // + if let Expr::Ident(i) = &mut **e { + *n = PatOrExpr::Pat(i.clone().into()); + } + } + PatOrExpr::Pat(_) => {} + } + } + fn visit_mut_prop(&mut self, p: &mut Prop) { p.visit_mut_children_with(self); @@ -561,6 +560,21 @@ where } } + fn visit_mut_super_prop_expr(&mut self, e: &mut SuperPropExpr) { + if let SuperProp::Computed(c) = &mut e.prop { + c.visit_mut_with(self); + + if let Some(ident) = self.optimize_property_of_member_expr(None, c) { + e.prop = SuperProp::Ident(ident); + return; + }; + + if let Some(ident) = self.handle_known_computed_member_expr(c) { + e.prop = SuperProp::Ident(ident) + }; + } + } + /// We don't optimize [Tpl] contained in [TaggedTpl]. fn visit_mut_tagged_tpl(&mut self, n: &mut TaggedTpl) { n.tag.visit_mut_with(self); diff --git a/crates/swc_ecma_minifier/src/compress/util/mod.rs b/crates/swc_ecma_minifier/src/compress/util/mod.rs index 215c1b11f4f..b61d2f29209 100644 --- a/crates/swc_ecma_minifier/src/compress/util/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/util/mod.rs @@ -4,7 +4,7 @@ use swc_atoms::js_word; use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms::fixer; -use swc_ecma_utils::{ExprExt, Id, UsageFinder, Value}; +use swc_ecma_utils::{ExprExt, Id, StmtLike, UsageFinder, Value}; use swc_ecma_visit::{as_folder, noop_visit_mut_type, FoldWith, VisitMut, VisitMutWith, VisitWith}; use unicode_xid::UnicodeXID; @@ -615,3 +615,14 @@ pub(super) fn is_fine_for_if_cons(s: &Stmt) -> bool { _ => true, } } + +pub(super) fn drop_invalid_stmts(stmts: &mut Vec) +where + T: StmtLike, +{ + stmts.retain(|s| match s.as_stmt() { + Some(Stmt::Empty(..)) => false, + Some(Stmt::Decl(Decl::Var(v))) => !v.decls.is_empty(), + _ => true, + }); +} diff --git a/crates/swc_ecma_minifier/src/debug.rs b/crates/swc_ecma_minifier/src/debug.rs index caf27f47ed6..007e876c7a2 100644 --- a/crates/swc_ecma_minifier/src/debug.rs +++ b/crates/swc_ecma_minifier/src/debug.rs @@ -130,7 +130,7 @@ impl Visit for AssertValid { noop_visit_type!(); fn visit_invalid(&mut self, _: &Invalid) { - panic!("[SWC_RUN] Invalid node found"); + panic!("Invalid node found"); } fn visit_setter_prop(&mut self, p: &SetterProp) { @@ -142,4 +142,12 @@ impl Visit for AssertValid { assert_eq!(l.exprs.len() + 1, l.quasis.len()); } + + fn visit_var_declarators(&mut self, v: &[VarDeclarator]) { + v.visit_children_with(self); + + if v.is_empty() { + panic!("Found empty var declarators"); + } + } } diff --git a/crates/swc_ecma_minifier/src/util/unit.rs b/crates/swc_ecma_minifier/src/util/unit.rs index 8a7ab94f7e1..c54bb842a50 100644 --- a/crates/swc_ecma_minifier/src/util/unit.rs +++ b/crates/swc_ecma_minifier/src/util/unit.rs @@ -1,10 +1,10 @@ -use crate::debug::dump; +use crate::debug::{dump, AssertValid}; use std::fmt::Debug; use swc_common::Mark; use swc_ecma_ast::*; use swc_ecma_transforms::{fixer, hygiene}; use swc_ecma_utils::DropSpan; -use swc_ecma_visit::{as_folder, FoldWith, VisitMut, VisitMutWith}; +use swc_ecma_visit::{as_folder, FoldWith, VisitMut, VisitMutWith, VisitWith}; /// Indicates a unit of minifaction. pub(crate) trait CompileUnit: @@ -57,7 +57,10 @@ impl CompileUnit for Module { where V: VisitMut, { - self.visit_mut_with(&mut *visitor) + self.visit_mut_with(&mut *visitor); + if cfg!(debug_assertions) { + self.visit_with(&mut AssertValid); + } } fn remove_mark(&mut self) -> Mark { @@ -91,7 +94,10 @@ impl CompileUnit for FnExpr { where V: VisitMut, { - self.visit_mut_with(&mut *visitor) + self.visit_mut_with(&mut *visitor); + if cfg!(debug_assertions) { + self.visit_with(&mut AssertValid); + } } fn remove_mark(&mut self) -> Mark { diff --git a/crates/swc_ecma_minifier/tests/compress/fixture/issues/firebase-core/1/output.js b/crates/swc_ecma_minifier/tests/compress/fixture/issues/firebase-core/1/output.js index 9c8ab68f6e3..a4dec7a1402 100644 --- a/crates/swc_ecma_minifier/tests/compress/fixture/issues/firebase-core/1/output.js +++ b/crates/swc_ecma_minifier/tests/compress/fixture/issues/firebase-core/1/output.js @@ -193,7 +193,7 @@ function v() { this.s = this.s, this.o = this.o; } - v.prototype.s = !1, v.prototype.na = function() { + Math.random(), v.prototype.s = !1, v.prototype.na = function() { this.s || (this.s = !0, this.M()); }, v.prototype.M = function() { if (this.o) for(; this.o.length;)this.o.shift()(); diff --git a/crates/swc_ecma_minifier/tests/compress/fixture/next/33265/static/chunks/d6e1aeb5-38a8d7ae57119c23/input.js b/crates/swc_ecma_minifier/tests/compress/fixture/next/33265/static/chunks/d6e1aeb5-38a8d7ae57119c23/input.js new file mode 100644 index 00000000000..2065ed1b0d3 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/compress/fixture/next/33265/static/chunks/d6e1aeb5-38a8d7ae57119c23/input.js @@ -0,0 +1,54623 @@ +"use strict"; +(self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([[544],{ + +/***/ 5215: +/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { + +/* harmony import */ var global_window__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8908); +/* harmony import */ var global_window__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(global_window__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var global_document__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9144); +/* harmony import */ var global_document__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(global_document__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(7462); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(7326); +/* harmony import */ var _babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(4578); +/* harmony import */ var safe_json_parse_tuple__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5974); +/* harmony import */ var safe_json_parse_tuple__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(safe_json_parse_tuple__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var keycode__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(7537); +/* harmony import */ var keycode__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(keycode__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _videojs_xhr__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(9603); +/* harmony import */ var _videojs_xhr__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_videojs_xhr__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var videojs_vtt_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(3407); +/* harmony import */ var videojs_vtt_js__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(videojs_vtt_js__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _babel_runtime_helpers_construct__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(8852); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(136); +/* harmony import */ var _videojs_vhs_utils_es_resolve_url_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(779); +/* harmony import */ var m3u8_parser__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(9323); +/* harmony import */ var _videojs_vhs_utils_es_codecs_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(2260); +/* harmony import */ var _videojs_vhs_utils_es_media_types_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(8485); +/* harmony import */ var mpd_parser__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(973); +/* harmony import */ var mux_js_lib_tools_parse_sidx__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(4221); +/* harmony import */ var mux_js_lib_tools_parse_sidx__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(mux_js_lib_tools_parse_sidx__WEBPACK_IMPORTED_MODULE_10__); +/* harmony import */ var _videojs_vhs_utils_es_id3_helpers__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(8925); +/* harmony import */ var _videojs_vhs_utils_es_containers__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(6185); +/* harmony import */ var _videojs_vhs_utils_es_byte_helpers__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(562); +/* harmony import */ var mux_js_lib_utils_clock__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(1489); +/* harmony import */ var mux_js_lib_utils_clock__WEBPACK_IMPORTED_MODULE_14___default = /*#__PURE__*/__webpack_require__.n(mux_js_lib_utils_clock__WEBPACK_IMPORTED_MODULE_14__); +/** + * @license + * Video.js 7.17.0 + * Copyright Brightcove, Inc. + * Available under Apache License Version 2.0 + * + * + * Includes vtt.js + * Available under Apache License Version 2.0 + * + */ + + + + + + + + + + + + + + + + + + + + + + + +var version$5 = "7.17.0"; + +/** + * An Object that contains lifecycle hooks as keys which point to an array + * of functions that are run when a lifecycle is triggered + * + * @private + */ +var hooks_ = {}; +/** + * Get a list of hooks for a specific lifecycle + * + * @param {string} type + * the lifecyle to get hooks from + * + * @param {Function|Function[]} [fn] + * Optionally add a hook (or hooks) to the lifecycle that your are getting. + * + * @return {Array} + * an array of hooks, or an empty array if there are none. + */ + +var hooks = function hooks(type, fn) { + hooks_[type] = hooks_[type] || []; + + if (fn) { + hooks_[type] = hooks_[type].concat(fn); + } + + return hooks_[type]; +}; +/** + * Add a function hook to a specific videojs lifecycle. + * + * @param {string} type + * the lifecycle to hook the function to. + * + * @param {Function|Function[]} + * The function or array of functions to attach. + */ + + +var hook = function hook(type, fn) { + hooks(type, fn); +}; +/** + * Remove a hook from a specific videojs lifecycle. + * + * @param {string} type + * the lifecycle that the function hooked to + * + * @param {Function} fn + * The hooked function to remove + * + * @return {boolean} + * The function that was removed or undef + */ + + +var removeHook = function removeHook(type, fn) { + var index = hooks(type).indexOf(fn); + + if (index <= -1) { + return false; + } + + hooks_[type] = hooks_[type].slice(); + hooks_[type].splice(index, 1); + return true; +}; +/** + * Add a function hook that will only run once to a specific videojs lifecycle. + * + * @param {string} type + * the lifecycle to hook the function to. + * + * @param {Function|Function[]} + * The function or array of functions to attach. + */ + + +var hookOnce = function hookOnce(type, fn) { + hooks(type, [].concat(fn).map(function (original) { + var wrapper = function wrapper() { + removeHook(type, wrapper); + return original.apply(void 0, arguments); + }; + + return wrapper; + })); +}; + +/** + * @file fullscreen-api.js + * @module fullscreen-api + * @private + */ +/** + * Store the browser-specific methods for the fullscreen API. + * + * @type {Object} + * @see [Specification]{@link https://fullscreen.spec.whatwg.org} + * @see [Map Approach From Screenfull.js]{@link https://github.com/sindresorhus/screenfull.js} + */ + +var FullscreenApi = { + prefixed: true +}; // browser API methods + +var apiMap = [['requestFullscreen', 'exitFullscreen', 'fullscreenElement', 'fullscreenEnabled', 'fullscreenchange', 'fullscreenerror', 'fullscreen'], // WebKit +['webkitRequestFullscreen', 'webkitExitFullscreen', 'webkitFullscreenElement', 'webkitFullscreenEnabled', 'webkitfullscreenchange', 'webkitfullscreenerror', '-webkit-full-screen'], // Mozilla +['mozRequestFullScreen', 'mozCancelFullScreen', 'mozFullScreenElement', 'mozFullScreenEnabled', 'mozfullscreenchange', 'mozfullscreenerror', '-moz-full-screen'], // Microsoft +['msRequestFullscreen', 'msExitFullscreen', 'msFullscreenElement', 'msFullscreenEnabled', 'MSFullscreenChange', 'MSFullscreenError', '-ms-fullscreen']]; +var specApi = apiMap[0]; +var browserApi; // determine the supported set of functions + +for (var i = 0; i < apiMap.length; i++) { + // check for exitFullscreen function + if (apiMap[i][1] in (global_document__WEBPACK_IMPORTED_MODULE_1___default())) { + browserApi = apiMap[i]; + break; + } +} // map the browser API names to the spec API names + + +if (browserApi) { + for (var _i = 0; _i < browserApi.length; _i++) { + FullscreenApi[specApi[_i]] = browserApi[_i]; + } + + FullscreenApi.prefixed = browserApi[0] !== specApi[0]; +} + +/** + * @file create-logger.js + * @module create-logger + */ + +var history = []; +/** + * Log messages to the console and history based on the type of message + * + * @private + * @param {string} type + * The name of the console method to use. + * + * @param {Array} args + * The arguments to be passed to the matching console method. + */ + +var LogByTypeFactory = function LogByTypeFactory(name, log) { + return function (type, level, args) { + var lvl = log.levels[level]; + var lvlRegExp = new RegExp("^(" + lvl + ")$"); + + if (type !== 'log') { + // Add the type to the front of the message when it's not "log". + args.unshift(type.toUpperCase() + ':'); + } // Add console prefix after adding to history. + + + args.unshift(name + ':'); // Add a clone of the args at this point to history. + + if (history) { + history.push([].concat(args)); // only store 1000 history entries + + var splice = history.length - 1000; + history.splice(0, splice > 0 ? splice : 0); + } // If there's no console then don't try to output messages, but they will + // still be stored in history. + + + if (!(global_window__WEBPACK_IMPORTED_MODULE_0___default().console)) { + return; + } // Was setting these once outside of this function, but containing them + // in the function makes it easier to test cases where console doesn't exist + // when the module is executed. + + + var fn = (global_window__WEBPACK_IMPORTED_MODULE_0___default().console)[type]; + + if (!fn && type === 'debug') { + // Certain browsers don't have support for console.debug. For those, we + // should default to the closest comparable log. + fn = (global_window__WEBPACK_IMPORTED_MODULE_0___default().console.info) || (global_window__WEBPACK_IMPORTED_MODULE_0___default().console.log); + } // Bail out if there's no console or if this type is not allowed by the + // current logging level. + + + if (!fn || !lvl || !lvlRegExp.test(type)) { + return; + } + + fn[Array.isArray(args) ? 'apply' : 'call']((global_window__WEBPACK_IMPORTED_MODULE_0___default().console), args); + }; +}; + +function createLogger$1(name) { + // This is the private tracking variable for logging level. + var level = 'info'; // the curried logByType bound to the specific log and history + + var logByType; + /** + * Logs plain debug messages. Similar to `console.log`. + * + * Due to [limitations](https://github.com/jsdoc3/jsdoc/issues/955#issuecomment-313829149) + * of our JSDoc template, we cannot properly document this as both a function + * and a namespace, so its function signature is documented here. + * + * #### Arguments + * ##### *args + * Mixed[] + * + * Any combination of values that could be passed to `console.log()`. + * + * #### Return Value + * + * `undefined` + * + * @namespace + * @param {Mixed[]} args + * One or more messages or objects that should be logged. + */ + + var log = function log() { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + logByType('log', level, args); + }; // This is the logByType helper that the logging methods below use + + + logByType = LogByTypeFactory(name, log); + /** + * Create a new sublogger which chains the old name to the new name. + * + * For example, doing `videojs.log.createLogger('player')` and then using that logger will log the following: + * ```js + * mylogger('foo'); + * // > VIDEOJS: player: foo + * ``` + * + * @param {string} name + * The name to add call the new logger + * @return {Object} + */ + + log.createLogger = function (subname) { + return createLogger$1(name + ': ' + subname); + }; + /** + * Enumeration of available logging levels, where the keys are the level names + * and the values are `|`-separated strings containing logging methods allowed + * in that logging level. These strings are used to create a regular expression + * matching the function name being called. + * + * Levels provided by Video.js are: + * + * - `off`: Matches no calls. Any value that can be cast to `false` will have + * this effect. The most restrictive. + * - `all`: Matches only Video.js-provided functions (`debug`, `log`, + * `log.warn`, and `log.error`). + * - `debug`: Matches `log.debug`, `log`, `log.warn`, and `log.error` calls. + * - `info` (default): Matches `log`, `log.warn`, and `log.error` calls. + * - `warn`: Matches `log.warn` and `log.error` calls. + * - `error`: Matches only `log.error` calls. + * + * @type {Object} + */ + + + log.levels = { + all: 'debug|log|warn|error', + off: '', + debug: 'debug|log|warn|error', + info: 'log|warn|error', + warn: 'warn|error', + error: 'error', + DEFAULT: level + }; + /** + * Get or set the current logging level. + * + * If a string matching a key from {@link module:log.levels} is provided, acts + * as a setter. + * + * @param {string} [lvl] + * Pass a valid level to set a new logging level. + * + * @return {string} + * The current logging level. + */ + + log.level = function (lvl) { + if (typeof lvl === 'string') { + if (!log.levels.hasOwnProperty(lvl)) { + throw new Error("\"" + lvl + "\" in not a valid log level"); + } + + level = lvl; + } + + return level; + }; + /** + * Returns an array containing everything that has been logged to the history. + * + * This array is a shallow clone of the internal history record. However, its + * contents are _not_ cloned; so, mutating objects inside this array will + * mutate them in history. + * + * @return {Array} + */ + + + log.history = function () { + return history ? [].concat(history) : []; + }; + /** + * Allows you to filter the history by the given logger name + * + * @param {string} fname + * The name to filter by + * + * @return {Array} + * The filtered list to return + */ + + + log.history.filter = function (fname) { + return (history || []).filter(function (historyItem) { + // if the first item in each historyItem includes `fname`, then it's a match + return new RegExp(".*" + fname + ".*").test(historyItem[0]); + }); + }; + /** + * Clears the internal history tracking, but does not prevent further history + * tracking. + */ + + + log.history.clear = function () { + if (history) { + history.length = 0; + } + }; + /** + * Disable history tracking if it is currently enabled. + */ + + + log.history.disable = function () { + if (history !== null) { + history.length = 0; + history = null; + } + }; + /** + * Enable history tracking if it is currently disabled. + */ + + + log.history.enable = function () { + if (history === null) { + history = []; + } + }; + /** + * Logs error messages. Similar to `console.error`. + * + * @param {Mixed[]} args + * One or more messages or objects that should be logged as an error + */ + + + log.error = function () { + for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + args[_key2] = arguments[_key2]; + } + + return logByType('error', level, args); + }; + /** + * Logs warning messages. Similar to `console.warn`. + * + * @param {Mixed[]} args + * One or more messages or objects that should be logged as a warning. + */ + + + log.warn = function () { + for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { + args[_key3] = arguments[_key3]; + } + + return logByType('warn', level, args); + }; + /** + * Logs debug messages. Similar to `console.debug`, but may also act as a comparable + * log if `console.debug` is not available + * + * @param {Mixed[]} args + * One or more messages or objects that should be logged as debug. + */ + + + log.debug = function () { + for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { + args[_key4] = arguments[_key4]; + } + + return logByType('debug', level, args); + }; + + return log; +} + +/** + * @file log.js + * @module log + */ +var log$1 = createLogger$1('VIDEOJS'); +var createLogger = log$1.createLogger; + +/** + * @file obj.js + * @module obj + */ + +/** + * @callback obj:EachCallback + * + * @param {Mixed} value + * The current key for the object that is being iterated over. + * + * @param {string} key + * The current key-value for object that is being iterated over + */ + +/** + * @callback obj:ReduceCallback + * + * @param {Mixed} accum + * The value that is accumulating over the reduce loop. + * + * @param {Mixed} value + * The current key for the object that is being iterated over. + * + * @param {string} key + * The current key-value for object that is being iterated over + * + * @return {Mixed} + * The new accumulated value. + */ +var toString = Object.prototype.toString; +/** + * Get the keys of an Object + * + * @param {Object} + * The Object to get the keys from + * + * @return {string[]} + * An array of the keys from the object. Returns an empty array if the + * object passed in was invalid or had no keys. + * + * @private + */ + +var keys = function keys(object) { + return isObject(object) ? Object.keys(object) : []; +}; +/** + * Array-like iteration for objects. + * + * @param {Object} object + * The object to iterate over + * + * @param {obj:EachCallback} fn + * The callback function which is called for each key in the object. + */ + + +function each(object, fn) { + keys(object).forEach(function (key) { + return fn(object[key], key); + }); +} +/** + * Array-like reduce for objects. + * + * @param {Object} object + * The Object that you want to reduce. + * + * @param {Function} fn + * A callback function which is called for each key in the object. It + * receives the accumulated value and the per-iteration value and key + * as arguments. + * + * @param {Mixed} [initial = 0] + * Starting value + * + * @return {Mixed} + * The final accumulated value. + */ + +function reduce(object, fn, initial) { + if (initial === void 0) { + initial = 0; + } + + return keys(object).reduce(function (accum, key) { + return fn(accum, object[key], key); + }, initial); +} +/** + * Object.assign-style object shallow merge/extend. + * + * @param {Object} target + * @param {Object} ...sources + * @return {Object} + */ + +function assign(target) { + for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + sources[_key - 1] = arguments[_key]; + } + + if (Object.assign) { + return _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_15__/* ["default"].apply */ .Z.apply(void 0, [target].concat(sources)); + } + + sources.forEach(function (source) { + if (!source) { + return; + } + + each(source, function (value, key) { + target[key] = value; + }); + }); + return target; +} +/** + * Returns whether a value is an object of any kind - including DOM nodes, + * arrays, regular expressions, etc. Not functions, though. + * + * This avoids the gotcha where using `typeof` on a `null` value + * results in `'object'`. + * + * @param {Object} value + * @return {boolean} + */ + +function isObject(value) { + return !!value && typeof value === 'object'; +} +/** + * Returns whether an object appears to be a "plain" object - that is, a + * direct instance of `Object`. + * + * @param {Object} value + * @return {boolean} + */ + +function isPlain(value) { + return isObject(value) && toString.call(value) === '[object Object]' && value.constructor === Object; +} + +/** + * @file computed-style.js + * @module computed-style + */ +/** + * A safe getComputedStyle. + * + * This is needed because in Firefox, if the player is loaded in an iframe with + * `display:none`, then `getComputedStyle` returns `null`, so, we do a + * null-check to make sure that the player doesn't break in these cases. + * + * @function + * @param {Element} el + * The element you want the computed style of + * + * @param {string} prop + * The property name you want + * + * @see https://bugzilla.mozilla.org/show_bug.cgi?id=548397 + */ + +function computedStyle(el, prop) { + if (!el || !prop) { + return ''; + } + + if (typeof (global_window__WEBPACK_IMPORTED_MODULE_0___default().getComputedStyle) === 'function') { + var computedStyleValue; + + try { + computedStyleValue = global_window__WEBPACK_IMPORTED_MODULE_0___default().getComputedStyle(el); + } catch (e) { + return ''; + } + + return computedStyleValue ? computedStyleValue.getPropertyValue(prop) || computedStyleValue[prop] : ''; + } + + return ''; +} + +/** + * @file browser.js + * @module browser + */ +var USER_AGENT = (global_window__WEBPACK_IMPORTED_MODULE_0___default().navigator) && (global_window__WEBPACK_IMPORTED_MODULE_0___default().navigator.userAgent) || ''; +var webkitVersionMap = /AppleWebKit\/([\d.]+)/i.exec(USER_AGENT); +var appleWebkitVersion = webkitVersionMap ? parseFloat(webkitVersionMap.pop()) : null; +/** + * Whether or not this device is an iPod. + * + * @static + * @const + * @type {Boolean} + */ + +var IS_IPOD = /iPod/i.test(USER_AGENT); +/** + * The detected iOS version - or `null`. + * + * @static + * @const + * @type {string|null} + */ + +var IOS_VERSION = function () { + var match = USER_AGENT.match(/OS (\d+)_/i); + + if (match && match[1]) { + return match[1]; + } + + return null; +}(); +/** + * Whether or not this is an Android device. + * + * @static + * @const + * @type {Boolean} + */ + +var IS_ANDROID = /Android/i.test(USER_AGENT); +/** + * The detected Android version - or `null`. + * + * @static + * @const + * @type {number|string|null} + */ + +var ANDROID_VERSION = function () { + // This matches Android Major.Minor.Patch versions + // ANDROID_VERSION is Major.Minor as a Number, if Minor isn't available, then only Major is returned + var match = USER_AGENT.match(/Android (\d+)(?:\.(\d+))?(?:\.(\d+))*/i); + + if (!match) { + return null; + } + + var major = match[1] && parseFloat(match[1]); + var minor = match[2] && parseFloat(match[2]); + + if (major && minor) { + return parseFloat(match[1] + '.' + match[2]); + } else if (major) { + return major; + } + + return null; +}(); +/** + * Whether or not this is a native Android browser. + * + * @static + * @const + * @type {Boolean} + */ + +var IS_NATIVE_ANDROID = IS_ANDROID && ANDROID_VERSION < 5 && appleWebkitVersion < 537; +/** + * Whether or not this is Mozilla Firefox. + * + * @static + * @const + * @type {Boolean} + */ + +var IS_FIREFOX = /Firefox/i.test(USER_AGENT); +/** + * Whether or not this is Microsoft Edge. + * + * @static + * @const + * @type {Boolean} + */ + +var IS_EDGE = /Edg/i.test(USER_AGENT); +/** + * Whether or not this is Google Chrome. + * + * This will also be `true` for Chrome on iOS, which will have different support + * as it is actually Safari under the hood. + * + * @static + * @const + * @type {Boolean} + */ + +var IS_CHROME = !IS_EDGE && (/Chrome/i.test(USER_AGENT) || /CriOS/i.test(USER_AGENT)); +/** + * The detected Google Chrome version - or `null`. + * + * @static + * @const + * @type {number|null} + */ + +var CHROME_VERSION = function () { + var match = USER_AGENT.match(/(Chrome|CriOS)\/(\d+)/); + + if (match && match[2]) { + return parseFloat(match[2]); + } + + return null; +}(); +/** + * The detected Internet Explorer version - or `null`. + * + * @static + * @const + * @type {number|null} + */ + +var IE_VERSION = function () { + var result = /MSIE\s(\d+)\.\d/.exec(USER_AGENT); + var version = result && parseFloat(result[1]); + + if (!version && /Trident\/7.0/i.test(USER_AGENT) && /rv:11.0/.test(USER_AGENT)) { + // IE 11 has a different user agent string than other IE versions + version = 11.0; + } + + return version; +}(); +/** + * Whether or not this is desktop Safari. + * + * @static + * @const + * @type {Boolean} + */ + +var IS_SAFARI = /Safari/i.test(USER_AGENT) && !IS_CHROME && !IS_ANDROID && !IS_EDGE; +/** + * Whether or not this is a Windows machine. + * + * @static + * @const + * @type {Boolean} + */ + +var IS_WINDOWS = /Windows/i.test(USER_AGENT); +/** + * Whether or not this device is touch-enabled. + * + * @static + * @const + * @type {Boolean} + */ + +var TOUCH_ENABLED = Boolean(isReal() && ('ontouchstart' in (global_window__WEBPACK_IMPORTED_MODULE_0___default()) || (global_window__WEBPACK_IMPORTED_MODULE_0___default().navigator.maxTouchPoints) || (global_window__WEBPACK_IMPORTED_MODULE_0___default().DocumentTouch) && (global_window__WEBPACK_IMPORTED_MODULE_0___default().document) instanceof (global_window__WEBPACK_IMPORTED_MODULE_0___default().DocumentTouch))); +/** + * Whether or not this device is an iPad. + * + * @static + * @const + * @type {Boolean} + */ + +var IS_IPAD = /iPad/i.test(USER_AGENT) || IS_SAFARI && TOUCH_ENABLED && !/iPhone/i.test(USER_AGENT); +/** + * Whether or not this device is an iPhone. + * + * @static + * @const + * @type {Boolean} + */ +// The Facebook app's UIWebView identifies as both an iPhone and iPad, so +// to identify iPhones, we need to exclude iPads. +// http://artsy.github.io/blog/2012/10/18/the-perils-of-ios-user-agent-sniffing/ + +var IS_IPHONE = /iPhone/i.test(USER_AGENT) && !IS_IPAD; +/** + * Whether or not this is an iOS device. + * + * @static + * @const + * @type {Boolean} + */ + +var IS_IOS = IS_IPHONE || IS_IPAD || IS_IPOD; +/** + * Whether or not this is any flavor of Safari - including iOS. + * + * @static + * @const + * @type {Boolean} + */ + +var IS_ANY_SAFARI = (IS_SAFARI || IS_IOS) && !IS_CHROME; + +var browser = /*#__PURE__*/Object.freeze({ + __proto__: null, + IS_IPOD: IS_IPOD, + IOS_VERSION: IOS_VERSION, + IS_ANDROID: IS_ANDROID, + ANDROID_VERSION: ANDROID_VERSION, + IS_NATIVE_ANDROID: IS_NATIVE_ANDROID, + IS_FIREFOX: IS_FIREFOX, + IS_EDGE: IS_EDGE, + IS_CHROME: IS_CHROME, + CHROME_VERSION: CHROME_VERSION, + IE_VERSION: IE_VERSION, + IS_SAFARI: IS_SAFARI, + IS_WINDOWS: IS_WINDOWS, + TOUCH_ENABLED: TOUCH_ENABLED, + IS_IPAD: IS_IPAD, + IS_IPHONE: IS_IPHONE, + IS_IOS: IS_IOS, + IS_ANY_SAFARI: IS_ANY_SAFARI +}); + +/** + * @file dom.js + * @module dom + */ +/** + * Detect if a value is a string with any non-whitespace characters. + * + * @private + * @param {string} str + * The string to check + * + * @return {boolean} + * Will be `true` if the string is non-blank, `false` otherwise. + * + */ + +function isNonBlankString(str) { + // we use str.trim as it will trim any whitespace characters + // from the front or back of non-whitespace characters. aka + // Any string that contains non-whitespace characters will + // still contain them after `trim` but whitespace only strings + // will have a length of 0, failing this check. + return typeof str === 'string' && Boolean(str.trim()); +} +/** + * Throws an error if the passed string has whitespace. This is used by + * class methods to be relatively consistent with the classList API. + * + * @private + * @param {string} str + * The string to check for whitespace. + * + * @throws {Error} + * Throws an error if there is whitespace in the string. + */ + + +function throwIfWhitespace(str) { + // str.indexOf instead of regex because str.indexOf is faster performance wise. + if (str.indexOf(' ') >= 0) { + throw new Error('class has illegal whitespace characters'); + } +} +/** + * Produce a regular expression for matching a className within an elements className. + * + * @private + * @param {string} className + * The className to generate the RegExp for. + * + * @return {RegExp} + * The RegExp that will check for a specific `className` in an elements + * className. + */ + + +function classRegExp(className) { + return new RegExp('(^|\\s)' + className + '($|\\s)'); +} +/** + * Whether the current DOM interface appears to be real (i.e. not simulated). + * + * @return {boolean} + * Will be `true` if the DOM appears to be real, `false` otherwise. + */ + + +function isReal() { + // Both document and window will never be undefined thanks to `global`. + return (global_document__WEBPACK_IMPORTED_MODULE_1___default()) === (global_window__WEBPACK_IMPORTED_MODULE_0___default().document); +} +/** + * Determines, via duck typing, whether or not a value is a DOM element. + * + * @param {Mixed} value + * The value to check. + * + * @return {boolean} + * Will be `true` if the value is a DOM element, `false` otherwise. + */ + +function isEl(value) { + return isObject(value) && value.nodeType === 1; +} +/** + * Determines if the current DOM is embedded in an iframe. + * + * @return {boolean} + * Will be `true` if the DOM is embedded in an iframe, `false` + * otherwise. + */ + +function isInFrame() { + // We need a try/catch here because Safari will throw errors when attempting + // to get either `parent` or `self` + try { + return (global_window__WEBPACK_IMPORTED_MODULE_0___default().parent) !== (global_window__WEBPACK_IMPORTED_MODULE_0___default().self); + } catch (x) { + return true; + } +} +/** + * Creates functions to query the DOM using a given method. + * + * @private + * @param {string} method + * The method to create the query with. + * + * @return {Function} + * The query method + */ + +function createQuerier(method) { + return function (selector, context) { + if (!isNonBlankString(selector)) { + return (global_document__WEBPACK_IMPORTED_MODULE_1___default())[method](null); + } + + if (isNonBlankString(context)) { + context = global_document__WEBPACK_IMPORTED_MODULE_1___default().querySelector(context); + } + + var ctx = isEl(context) ? context : (global_document__WEBPACK_IMPORTED_MODULE_1___default()); + return ctx[method] && ctx[method](selector); + }; +} +/** + * Creates an element and applies properties, attributes, and inserts content. + * + * @param {string} [tagName='div'] + * Name of tag to be created. + * + * @param {Object} [properties={}] + * Element properties to be applied. + * + * @param {Object} [attributes={}] + * Element attributes to be applied. + * + * @param {module:dom~ContentDescriptor} content + * A content descriptor object. + * + * @return {Element} + * The element that was created. + */ + + +function createEl(tagName, properties, attributes, content) { + if (tagName === void 0) { + tagName = 'div'; + } + + if (properties === void 0) { + properties = {}; + } + + if (attributes === void 0) { + attributes = {}; + } + + var el = global_document__WEBPACK_IMPORTED_MODULE_1___default().createElement(tagName); + Object.getOwnPropertyNames(properties).forEach(function (propName) { + var val = properties[propName]; // See #2176 + // We originally were accepting both properties and attributes in the + // same object, but that doesn't work so well. + + if (propName.indexOf('aria-') !== -1 || propName === 'role' || propName === 'type') { + log$1.warn('Setting attributes in the second argument of createEl()\n' + 'has been deprecated. Use the third argument instead.\n' + ("createEl(type, properties, attributes). Attempting to set " + propName + " to " + val + ".")); + el.setAttribute(propName, val); // Handle textContent since it's not supported everywhere and we have a + // method for it. + } else if (propName === 'textContent') { + textContent(el, val); + } else if (el[propName] !== val || propName === 'tabIndex') { + el[propName] = val; + } + }); + Object.getOwnPropertyNames(attributes).forEach(function (attrName) { + el.setAttribute(attrName, attributes[attrName]); + }); + + if (content) { + appendContent(el, content); + } + + return el; +} +/** + * Injects text into an element, replacing any existing contents entirely. + * + * @param {Element} el + * The element to add text content into + * + * @param {string} text + * The text content to add. + * + * @return {Element} + * The element with added text content. + */ + +function textContent(el, text) { + if (typeof el.textContent === 'undefined') { + el.innerText = text; + } else { + el.textContent = text; + } + + return el; +} +/** + * Insert an element as the first child node of another + * + * @param {Element} child + * Element to insert + * + * @param {Element} parent + * Element to insert child into + */ + +function prependTo(child, parent) { + if (parent.firstChild) { + parent.insertBefore(child, parent.firstChild); + } else { + parent.appendChild(child); + } +} +/** + * Check if an element has a class name. + * + * @param {Element} element + * Element to check + * + * @param {string} classToCheck + * Class name to check for + * + * @return {boolean} + * Will be `true` if the element has a class, `false` otherwise. + * + * @throws {Error} + * Throws an error if `classToCheck` has white space. + */ + +function hasClass(element, classToCheck) { + throwIfWhitespace(classToCheck); + + if (element.classList) { + return element.classList.contains(classToCheck); + } + + return classRegExp(classToCheck).test(element.className); +} +/** + * Add a class name to an element. + * + * @param {Element} element + * Element to add class name to. + * + * @param {string} classToAdd + * Class name to add. + * + * @return {Element} + * The DOM element with the added class name. + */ + +function addClass(element, classToAdd) { + if (element.classList) { + element.classList.add(classToAdd); // Don't need to `throwIfWhitespace` here because `hasElClass` will do it + // in the case of classList not being supported. + } else if (!hasClass(element, classToAdd)) { + element.className = (element.className + ' ' + classToAdd).trim(); + } + + return element; +} +/** + * Remove a class name from an element. + * + * @param {Element} element + * Element to remove a class name from. + * + * @param {string} classToRemove + * Class name to remove + * + * @return {Element} + * The DOM element with class name removed. + */ + +function removeClass(element, classToRemove) { + // Protect in case the player gets disposed + if (!element) { + log$1.warn("removeClass was called with an element that doesn't exist"); + return null; + } + + if (element.classList) { + element.classList.remove(classToRemove); + } else { + throwIfWhitespace(classToRemove); + element.className = element.className.split(/\s+/).filter(function (c) { + return c !== classToRemove; + }).join(' '); + } + + return element; +} +/** + * The callback definition for toggleClass. + * + * @callback module:dom~PredicateCallback + * @param {Element} element + * The DOM element of the Component. + * + * @param {string} classToToggle + * The `className` that wants to be toggled + * + * @return {boolean|undefined} + * If `true` is returned, the `classToToggle` will be added to the + * `element`. If `false`, the `classToToggle` will be removed from + * the `element`. If `undefined`, the callback will be ignored. + */ + +/** + * Adds or removes a class name to/from an element depending on an optional + * condition or the presence/absence of the class name. + * + * @param {Element} element + * The element to toggle a class name on. + * + * @param {string} classToToggle + * The class that should be toggled. + * + * @param {boolean|module:dom~PredicateCallback} [predicate] + * See the return value for {@link module:dom~PredicateCallback} + * + * @return {Element} + * The element with a class that has been toggled. + */ + +function toggleClass(element, classToToggle, predicate) { + // This CANNOT use `classList` internally because IE11 does not support the + // second parameter to the `classList.toggle()` method! Which is fine because + // `classList` will be used by the add/remove functions. + var has = hasClass(element, classToToggle); + + if (typeof predicate === 'function') { + predicate = predicate(element, classToToggle); + } + + if (typeof predicate !== 'boolean') { + predicate = !has; + } // If the necessary class operation matches the current state of the + // element, no action is required. + + + if (predicate === has) { + return; + } + + if (predicate) { + addClass(element, classToToggle); + } else { + removeClass(element, classToToggle); + } + + return element; +} +/** + * Apply attributes to an HTML element. + * + * @param {Element} el + * Element to add attributes to. + * + * @param {Object} [attributes] + * Attributes to be applied. + */ + +function setAttributes(el, attributes) { + Object.getOwnPropertyNames(attributes).forEach(function (attrName) { + var attrValue = attributes[attrName]; + + if (attrValue === null || typeof attrValue === 'undefined' || attrValue === false) { + el.removeAttribute(attrName); + } else { + el.setAttribute(attrName, attrValue === true ? '' : attrValue); + } + }); +} +/** + * Get an element's attribute values, as defined on the HTML tag. + * + * Attributes are not the same as properties. They're defined on the tag + * or with setAttribute. + * + * @param {Element} tag + * Element from which to get tag attributes. + * + * @return {Object} + * All attributes of the element. Boolean attributes will be `true` or + * `false`, others will be strings. + */ + +function getAttributes(tag) { + var obj = {}; // known boolean attributes + // we can check for matching boolean properties, but not all browsers + // and not all tags know about these attributes, so, we still want to check them manually + + var knownBooleans = ',' + 'autoplay,controls,playsinline,loop,muted,default,defaultMuted' + ','; + + if (tag && tag.attributes && tag.attributes.length > 0) { + var attrs = tag.attributes; + + for (var i = attrs.length - 1; i >= 0; i--) { + var attrName = attrs[i].name; + var attrVal = attrs[i].value; // check for known booleans + // the matching element property will return a value for typeof + + if (typeof tag[attrName] === 'boolean' || knownBooleans.indexOf(',' + attrName + ',') !== -1) { + // the value of an included boolean attribute is typically an empty + // string ('') which would equal false if we just check for a false value. + // we also don't want support bad code like autoplay='false' + attrVal = attrVal !== null ? true : false; + } + + obj[attrName] = attrVal; + } + } + + return obj; +} +/** + * Get the value of an element's attribute. + * + * @param {Element} el + * A DOM element. + * + * @param {string} attribute + * Attribute to get the value of. + * + * @return {string} + * The value of the attribute. + */ + +function getAttribute(el, attribute) { + return el.getAttribute(attribute); +} +/** + * Set the value of an element's attribute. + * + * @param {Element} el + * A DOM element. + * + * @param {string} attribute + * Attribute to set. + * + * @param {string} value + * Value to set the attribute to. + */ + +function setAttribute(el, attribute, value) { + el.setAttribute(attribute, value); +} +/** + * Remove an element's attribute. + * + * @param {Element} el + * A DOM element. + * + * @param {string} attribute + * Attribute to remove. + */ + +function removeAttribute(el, attribute) { + el.removeAttribute(attribute); +} +/** + * Attempt to block the ability to select text. + */ + +function blockTextSelection() { + global_document__WEBPACK_IMPORTED_MODULE_1___default().body.focus(); + + (global_document__WEBPACK_IMPORTED_MODULE_1___default().onselectstart) = function () { + return false; + }; +} +/** + * Turn off text selection blocking. + */ + +function unblockTextSelection() { + (global_document__WEBPACK_IMPORTED_MODULE_1___default().onselectstart) = function () { + return true; + }; +} +/** + * Identical to the native `getBoundingClientRect` function, but ensures that + * the method is supported at all (it is in all browsers we claim to support) + * and that the element is in the DOM before continuing. + * + * This wrapper function also shims properties which are not provided by some + * older browsers (namely, IE8). + * + * Additionally, some browsers do not support adding properties to a + * `ClientRect`/`DOMRect` object; so, we shallow-copy it with the standard + * properties (except `x` and `y` which are not widely supported). This helps + * avoid implementations where keys are non-enumerable. + * + * @param {Element} el + * Element whose `ClientRect` we want to calculate. + * + * @return {Object|undefined} + * Always returns a plain object - or `undefined` if it cannot. + */ + +function getBoundingClientRect(el) { + if (el && el.getBoundingClientRect && el.parentNode) { + var rect = el.getBoundingClientRect(); + var result = {}; + ['bottom', 'height', 'left', 'right', 'top', 'width'].forEach(function (k) { + if (rect[k] !== undefined) { + result[k] = rect[k]; + } + }); + + if (!result.height) { + result.height = parseFloat(computedStyle(el, 'height')); + } + + if (!result.width) { + result.width = parseFloat(computedStyle(el, 'width')); + } + + return result; + } +} +/** + * Represents the position of a DOM element on the page. + * + * @typedef {Object} module:dom~Position + * + * @property {number} left + * Pixels to the left. + * + * @property {number} top + * Pixels from the top. + */ + +/** + * Get the position of an element in the DOM. + * + * Uses `getBoundingClientRect` technique from John Resig. + * + * @see http://ejohn.org/blog/getboundingclientrect-is-awesome/ + * + * @param {Element} el + * Element from which to get offset. + * + * @return {module:dom~Position} + * The position of the element that was passed in. + */ + +function findPosition(el) { + if (!el || el && !el.offsetParent) { + return { + left: 0, + top: 0, + width: 0, + height: 0 + }; + } + + var width = el.offsetWidth; + var height = el.offsetHeight; + var left = 0; + var top = 0; + + while (el.offsetParent && el !== (global_document__WEBPACK_IMPORTED_MODULE_1___default())[FullscreenApi.fullscreenElement]) { + left += el.offsetLeft; + top += el.offsetTop; + el = el.offsetParent; + } + + return { + left: left, + top: top, + width: width, + height: height + }; +} +/** + * Represents x and y coordinates for a DOM element or mouse pointer. + * + * @typedef {Object} module:dom~Coordinates + * + * @property {number} x + * x coordinate in pixels + * + * @property {number} y + * y coordinate in pixels + */ + +/** + * Get the pointer position within an element. + * + * The base on the coordinates are the bottom left of the element. + * + * @param {Element} el + * Element on which to get the pointer position on. + * + * @param {EventTarget~Event} event + * Event object. + * + * @return {module:dom~Coordinates} + * A coordinates object corresponding to the mouse position. + * + */ + +function getPointerPosition(el, event) { + var translated = { + x: 0, + y: 0 + }; + + if (IS_IOS) { + var item = el; + + while (item && item.nodeName.toLowerCase() !== 'html') { + var transform = computedStyle(item, 'transform'); + + if (/^matrix/.test(transform)) { + var values = transform.slice(7, -1).split(/,\s/).map(Number); + translated.x += values[4]; + translated.y += values[5]; + } else if (/^matrix3d/.test(transform)) { + var _values = transform.slice(9, -1).split(/,\s/).map(Number); + + translated.x += _values[12]; + translated.y += _values[13]; + } + + item = item.parentNode; + } + } + + var position = {}; + var boxTarget = findPosition(event.target); + var box = findPosition(el); + var boxW = box.width; + var boxH = box.height; + var offsetY = event.offsetY - (box.top - boxTarget.top); + var offsetX = event.offsetX - (box.left - boxTarget.left); + + if (event.changedTouches) { + offsetX = event.changedTouches[0].pageX - box.left; + offsetY = event.changedTouches[0].pageY + box.top; + + if (IS_IOS) { + offsetX -= translated.x; + offsetY -= translated.y; + } + } + + position.y = 1 - Math.max(0, Math.min(1, offsetY / boxH)); + position.x = Math.max(0, Math.min(1, offsetX / boxW)); + return position; +} +/** + * Determines, via duck typing, whether or not a value is a text node. + * + * @param {Mixed} value + * Check if this value is a text node. + * + * @return {boolean} + * Will be `true` if the value is a text node, `false` otherwise. + */ + +function isTextNode(value) { + return isObject(value) && value.nodeType === 3; +} +/** + * Empties the contents of an element. + * + * @param {Element} el + * The element to empty children from + * + * @return {Element} + * The element with no children + */ + +function emptyEl(el) { + while (el.firstChild) { + el.removeChild(el.firstChild); + } + + return el; +} +/** + * This is a mixed value that describes content to be injected into the DOM + * via some method. It can be of the following types: + * + * Type | Description + * -----------|------------- + * `string` | The value will be normalized into a text node. + * `Element` | The value will be accepted as-is. + * `TextNode` | The value will be accepted as-is. + * `Array` | A one-dimensional array of strings, elements, text nodes, or functions. These functions should return a string, element, or text node (any other return value, like an array, will be ignored). + * `Function` | A function, which is expected to return a string, element, text node, or array - any of the other possible values described above. This means that a content descriptor could be a function that returns an array of functions, but those second-level functions must return strings, elements, or text nodes. + * + * @typedef {string|Element|TextNode|Array|Function} module:dom~ContentDescriptor + */ + +/** + * Normalizes content for eventual insertion into the DOM. + * + * This allows a wide range of content definition methods, but helps protect + * from falling into the trap of simply writing to `innerHTML`, which could + * be an XSS concern. + * + * The content for an element can be passed in multiple types and + * combinations, whose behavior is as follows: + * + * @param {module:dom~ContentDescriptor} content + * A content descriptor value. + * + * @return {Array} + * All of the content that was passed in, normalized to an array of + * elements or text nodes. + */ + +function normalizeContent(content) { + // First, invoke content if it is a function. If it produces an array, + // that needs to happen before normalization. + if (typeof content === 'function') { + content = content(); + } // Next up, normalize to an array, so one or many items can be normalized, + // filtered, and returned. + + + return (Array.isArray(content) ? content : [content]).map(function (value) { + // First, invoke value if it is a function to produce a new value, + // which will be subsequently normalized to a Node of some kind. + if (typeof value === 'function') { + value = value(); + } + + if (isEl(value) || isTextNode(value)) { + return value; + } + + if (typeof value === 'string' && /\S/.test(value)) { + return global_document__WEBPACK_IMPORTED_MODULE_1___default().createTextNode(value); + } + }).filter(function (value) { + return value; + }); +} +/** + * Normalizes and appends content to an element. + * + * @param {Element} el + * Element to append normalized content to. + * + * @param {module:dom~ContentDescriptor} content + * A content descriptor value. + * + * @return {Element} + * The element with appended normalized content. + */ + +function appendContent(el, content) { + normalizeContent(content).forEach(function (node) { + return el.appendChild(node); + }); + return el; +} +/** + * Normalizes and inserts content into an element; this is identical to + * `appendContent()`, except it empties the element first. + * + * @param {Element} el + * Element to insert normalized content into. + * + * @param {module:dom~ContentDescriptor} content + * A content descriptor value. + * + * @return {Element} + * The element with inserted normalized content. + */ + +function insertContent(el, content) { + return appendContent(emptyEl(el), content); +} +/** + * Check if an event was a single left click. + * + * @param {EventTarget~Event} event + * Event object. + * + * @return {boolean} + * Will be `true` if a single left click, `false` otherwise. + */ + +function isSingleLeftClick(event) { + // Note: if you create something draggable, be sure to + // call it on both `mousedown` and `mousemove` event, + // otherwise `mousedown` should be enough for a button + if (event.button === undefined && event.buttons === undefined) { + // Why do we need `buttons` ? + // Because, middle mouse sometimes have this: + // e.button === 0 and e.buttons === 4 + // Furthermore, we want to prevent combination click, something like + // HOLD middlemouse then left click, that would be + // e.button === 0, e.buttons === 5 + // just `button` is not gonna work + // Alright, then what this block does ? + // this is for chrome `simulate mobile devices` + // I want to support this as well + return true; + } + + if (event.button === 0 && event.buttons === undefined) { + // Touch screen, sometimes on some specific device, `buttons` + // doesn't have anything (safari on ios, blackberry...) + return true; + } // `mouseup` event on a single left click has + // `button` and `buttons` equal to 0 + + + if (event.type === 'mouseup' && event.button === 0 && event.buttons === 0) { + return true; + } + + if (event.button !== 0 || event.buttons !== 1) { + // This is the reason we have those if else block above + // if any special case we can catch and let it slide + // we do it above, when get to here, this definitely + // is-not-left-click + return false; + } + + return true; +} +/** + * Finds a single DOM element matching `selector` within the optional + * `context` of another DOM element (defaulting to `document`). + * + * @param {string} selector + * A valid CSS selector, which will be passed to `querySelector`. + * + * @param {Element|String} [context=document] + * A DOM element within which to query. Can also be a selector + * string in which case the first matching element will be used + * as context. If missing (or no element matches selector), falls + * back to `document`. + * + * @return {Element|null} + * The element that was found or null. + */ + +var $ = createQuerier('querySelector'); +/** + * Finds a all DOM elements matching `selector` within the optional + * `context` of another DOM element (defaulting to `document`). + * + * @param {string} selector + * A valid CSS selector, which will be passed to `querySelectorAll`. + * + * @param {Element|String} [context=document] + * A DOM element within which to query. Can also be a selector + * string in which case the first matching element will be used + * as context. If missing (or no element matches selector), falls + * back to `document`. + * + * @return {NodeList} + * A element list of elements that were found. Will be empty if none + * were found. + * + */ + +var $$ = createQuerier('querySelectorAll'); + +var Dom = /*#__PURE__*/Object.freeze({ + __proto__: null, + isReal: isReal, + isEl: isEl, + isInFrame: isInFrame, + createEl: createEl, + textContent: textContent, + prependTo: prependTo, + hasClass: hasClass, + addClass: addClass, + removeClass: removeClass, + toggleClass: toggleClass, + setAttributes: setAttributes, + getAttributes: getAttributes, + getAttribute: getAttribute, + setAttribute: setAttribute, + removeAttribute: removeAttribute, + blockTextSelection: blockTextSelection, + unblockTextSelection: unblockTextSelection, + getBoundingClientRect: getBoundingClientRect, + findPosition: findPosition, + getPointerPosition: getPointerPosition, + isTextNode: isTextNode, + emptyEl: emptyEl, + normalizeContent: normalizeContent, + appendContent: appendContent, + insertContent: insertContent, + isSingleLeftClick: isSingleLeftClick, + $: $, + $$: $$ +}); + +/** + * @file setup.js - Functions for setting up a player without + * user interaction based on the data-setup `attribute` of the video tag. + * + * @module setup + */ +var _windowLoaded = false; +var videojs$1; +/** + * Set up any tags that have a data-setup `attribute` when the player is started. + */ + +var autoSetup = function autoSetup() { + if (videojs$1.options.autoSetup === false) { + return; + } + + var vids = Array.prototype.slice.call(global_document__WEBPACK_IMPORTED_MODULE_1___default().getElementsByTagName('video')); + var audios = Array.prototype.slice.call(global_document__WEBPACK_IMPORTED_MODULE_1___default().getElementsByTagName('audio')); + var divs = Array.prototype.slice.call(global_document__WEBPACK_IMPORTED_MODULE_1___default().getElementsByTagName('video-js')); + var mediaEls = vids.concat(audios, divs); // Check if any media elements exist + + if (mediaEls && mediaEls.length > 0) { + for (var i = 0, e = mediaEls.length; i < e; i++) { + var mediaEl = mediaEls[i]; // Check if element exists, has getAttribute func. + + if (mediaEl && mediaEl.getAttribute) { + // Make sure this player hasn't already been set up. + if (mediaEl.player === undefined) { + var options = mediaEl.getAttribute('data-setup'); // Check if data-setup attr exists. + // We only auto-setup if they've added the data-setup attr. + + if (options !== null) { + // Create new video.js instance. + videojs$1(mediaEl); + } + } // If getAttribute isn't defined, we need to wait for the DOM. + + } else { + autoSetupTimeout(1); + break; + } + } // No videos were found, so keep looping unless page is finished loading. + + } else if (!_windowLoaded) { + autoSetupTimeout(1); + } +}; +/** + * Wait until the page is loaded before running autoSetup. This will be called in + * autoSetup if `hasLoaded` returns false. + * + * @param {number} wait + * How long to wait in ms + * + * @param {module:videojs} [vjs] + * The videojs library function + */ + + +function autoSetupTimeout(wait, vjs) { + // Protect against breakage in non-browser environments + if (!isReal()) { + return; + } + + if (vjs) { + videojs$1 = vjs; + } + + global_window__WEBPACK_IMPORTED_MODULE_0___default().setTimeout(autoSetup, wait); +} +/** + * Used to set the internal tracking of window loaded state to true. + * + * @private + */ + + +function setWindowLoaded() { + _windowLoaded = true; + global_window__WEBPACK_IMPORTED_MODULE_0___default().removeEventListener('load', setWindowLoaded); +} + +if (isReal()) { + if ((global_document__WEBPACK_IMPORTED_MODULE_1___default().readyState) === 'complete') { + setWindowLoaded(); + } else { + /** + * Listen for the load event on window, and set _windowLoaded to true. + * + * We use a standard event listener here to avoid incrementing the GUID + * before any players are created. + * + * @listens load + */ + global_window__WEBPACK_IMPORTED_MODULE_0___default().addEventListener('load', setWindowLoaded); + } +} + +/** + * @file stylesheet.js + * @module stylesheet + */ +/** + * Create a DOM syle element given a className for it. + * + * @param {string} className + * The className to add to the created style element. + * + * @return {Element} + * The element that was created. + */ + +var createStyleElement = function createStyleElement(className) { + var style = global_document__WEBPACK_IMPORTED_MODULE_1___default().createElement('style'); + style.className = className; + return style; +}; +/** + * Add text to a DOM element. + * + * @param {Element} el + * The Element to add text content to. + * + * @param {string} content + * The text to add to the element. + */ + +var setTextContent = function setTextContent(el, content) { + if (el.styleSheet) { + el.styleSheet.cssText = content; + } else { + el.textContent = content; + } +}; + +/** + * @file guid.js + * @module guid + */ +// Default value for GUIDs. This allows us to reset the GUID counter in tests. +// +// The initial GUID is 3 because some users have come to rely on the first +// default player ID ending up as `vjs_video_3`. +// +// See: https://github.com/videojs/video.js/pull/6216 +var _initialGuid = 3; +/** + * Unique ID for an element or function + * + * @type {Number} + */ + +var _guid = _initialGuid; +/** + * Get a unique auto-incrementing ID by number that has not been returned before. + * + * @return {number} + * A new unique ID. + */ + +function newGUID() { + return _guid++; +} + +/** + * @file dom-data.js + * @module dom-data + */ +var FakeWeakMap; + +if (!(global_window__WEBPACK_IMPORTED_MODULE_0___default().WeakMap)) { + FakeWeakMap = /*#__PURE__*/function () { + function FakeWeakMap() { + this.vdata = 'vdata' + Math.floor((global_window__WEBPACK_IMPORTED_MODULE_0___default().performance) && global_window__WEBPACK_IMPORTED_MODULE_0___default().performance.now() || Date.now()); + this.data = {}; + } + + var _proto = FakeWeakMap.prototype; + + _proto.set = function set(key, value) { + var access = key[this.vdata] || newGUID(); + + if (!key[this.vdata]) { + key[this.vdata] = access; + } + + this.data[access] = value; + return this; + }; + + _proto.get = function get(key) { + var access = key[this.vdata]; // we have data, return it + + if (access) { + return this.data[access]; + } // we don't have data, return nothing. + // return undefined explicitly as that's the contract for this method + + + log$1('We have no data for this element', key); + return undefined; + }; + + _proto.has = function has(key) { + var access = key[this.vdata]; + return access in this.data; + }; + + _proto["delete"] = function _delete(key) { + var access = key[this.vdata]; + + if (access) { + delete this.data[access]; + delete key[this.vdata]; + } + }; + + return FakeWeakMap; + }(); +} +/** + * Element Data Store. + * + * Allows for binding data to an element without putting it directly on the + * element. Ex. Event listeners are stored here. + * (also from jsninja.com, slightly modified and updated for closure compiler) + * + * @type {Object} + * @private + */ + + +var DomData = (global_window__WEBPACK_IMPORTED_MODULE_0___default().WeakMap) ? new WeakMap() : new FakeWeakMap(); + +/** + * @file events.js. An Event System (John Resig - Secrets of a JS Ninja http://jsninja.com/) + * (Original book version wasn't completely usable, so fixed some things and made Closure Compiler compatible) + * This should work very similarly to jQuery's events, however it's based off the book version which isn't as + * robust as jquery's, so there's probably some differences. + * + * @file events.js + * @module events + */ +/** + * Clean up the listener cache and dispatchers + * + * @param {Element|Object} elem + * Element to clean up + * + * @param {string} type + * Type of event to clean up + */ + +function _cleanUpEvents(elem, type) { + if (!DomData.has(elem)) { + return; + } + + var data = DomData.get(elem); // Remove the events of a particular type if there are none left + + if (data.handlers[type].length === 0) { + delete data.handlers[type]; // data.handlers[type] = null; + // Setting to null was causing an error with data.handlers + // Remove the meta-handler from the element + + if (elem.removeEventListener) { + elem.removeEventListener(type, data.dispatcher, false); + } else if (elem.detachEvent) { + elem.detachEvent('on' + type, data.dispatcher); + } + } // Remove the events object if there are no types left + + + if (Object.getOwnPropertyNames(data.handlers).length <= 0) { + delete data.handlers; + delete data.dispatcher; + delete data.disabled; + } // Finally remove the element data if there is no data left + + + if (Object.getOwnPropertyNames(data).length === 0) { + DomData["delete"](elem); + } +} +/** + * Loops through an array of event types and calls the requested method for each type. + * + * @param {Function} fn + * The event method we want to use. + * + * @param {Element|Object} elem + * Element or object to bind listeners to + * + * @param {string} type + * Type of event to bind to. + * + * @param {EventTarget~EventListener} callback + * Event listener. + */ + + +function _handleMultipleEvents(fn, elem, types, callback) { + types.forEach(function (type) { + // Call the event method for each one of the types + fn(elem, type, callback); + }); +} +/** + * Fix a native event to have standard property values + * + * @param {Object} event + * Event object to fix. + * + * @return {Object} + * Fixed event object. + */ + + +function fixEvent(event) { + if (event.fixed_) { + return event; + } + + function returnTrue() { + return true; + } + + function returnFalse() { + return false; + } // Test if fixing up is needed + // Used to check if !event.stopPropagation instead of isPropagationStopped + // But native events return true for stopPropagation, but don't have + // other expected methods like isPropagationStopped. Seems to be a problem + // with the Javascript Ninja code. So we're just overriding all events now. + + + if (!event || !event.isPropagationStopped || !event.isImmediatePropagationStopped) { + var old = event || (global_window__WEBPACK_IMPORTED_MODULE_0___default().event); + event = {}; // Clone the old object so that we can modify the values event = {}; + // IE8 Doesn't like when you mess with native event properties + // Firefox returns false for event.hasOwnProperty('type') and other props + // which makes copying more difficult. + // TODO: Probably best to create a whitelist of event props + + for (var key in old) { + // Safari 6.0.3 warns you if you try to copy deprecated layerX/Y + // Chrome warns you if you try to copy deprecated keyboardEvent.keyLocation + // and webkitMovementX/Y + if (key !== 'layerX' && key !== 'layerY' && key !== 'keyLocation' && key !== 'webkitMovementX' && key !== 'webkitMovementY') { + // Chrome 32+ warns if you try to copy deprecated returnValue, but + // we still want to if preventDefault isn't supported (IE8). + if (!(key === 'returnValue' && old.preventDefault)) { + event[key] = old[key]; + } + } + } // The event occurred on this element + + + if (!event.target) { + event.target = event.srcElement || (global_document__WEBPACK_IMPORTED_MODULE_1___default()); + } // Handle which other element the event is related to + + + if (!event.relatedTarget) { + event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement; + } // Stop the default browser action + + + event.preventDefault = function () { + if (old.preventDefault) { + old.preventDefault(); + } + + event.returnValue = false; + old.returnValue = false; + event.defaultPrevented = true; + }; + + event.defaultPrevented = false; // Stop the event from bubbling + + event.stopPropagation = function () { + if (old.stopPropagation) { + old.stopPropagation(); + } + + event.cancelBubble = true; + old.cancelBubble = true; + event.isPropagationStopped = returnTrue; + }; + + event.isPropagationStopped = returnFalse; // Stop the event from bubbling and executing other handlers + + event.stopImmediatePropagation = function () { + if (old.stopImmediatePropagation) { + old.stopImmediatePropagation(); + } + + event.isImmediatePropagationStopped = returnTrue; + event.stopPropagation(); + }; + + event.isImmediatePropagationStopped = returnFalse; // Handle mouse position + + if (event.clientX !== null && event.clientX !== undefined) { + var doc = (global_document__WEBPACK_IMPORTED_MODULE_1___default().documentElement); + var body = (global_document__WEBPACK_IMPORTED_MODULE_1___default().body); + event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0); + event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0); + } // Handle key presses + + + event.which = event.charCode || event.keyCode; // Fix button for mouse clicks: + // 0 == left; 1 == middle; 2 == right + + if (event.button !== null && event.button !== undefined) { + // The following is disabled because it does not pass videojs-standard + // and... yikes. + + /* eslint-disable */ + event.button = event.button & 1 ? 0 : event.button & 4 ? 1 : event.button & 2 ? 2 : 0; + /* eslint-enable */ + } + } + + event.fixed_ = true; // Returns fixed-up instance + + return event; +} +/** + * Whether passive event listeners are supported + */ + +var _supportsPassive; + +var supportsPassive = function supportsPassive() { + if (typeof _supportsPassive !== 'boolean') { + _supportsPassive = false; + + try { + var opts = Object.defineProperty({}, 'passive', { + get: function get() { + _supportsPassive = true; + } + }); + global_window__WEBPACK_IMPORTED_MODULE_0___default().addEventListener('test', null, opts); + global_window__WEBPACK_IMPORTED_MODULE_0___default().removeEventListener('test', null, opts); + } catch (e) {// disregard + } + } + + return _supportsPassive; +}; +/** + * Touch events Chrome expects to be passive + */ + + +var passiveEvents = ['touchstart', 'touchmove']; +/** + * Add an event listener to element + * It stores the handler function in a separate cache object + * and adds a generic handler to the element's event, + * along with a unique id (guid) to the element. + * + * @param {Element|Object} elem + * Element or object to bind listeners to + * + * @param {string|string[]} type + * Type of event to bind to. + * + * @param {EventTarget~EventListener} fn + * Event listener. + */ + +function on(elem, type, fn) { + if (Array.isArray(type)) { + return _handleMultipleEvents(on, elem, type, fn); + } + + if (!DomData.has(elem)) { + DomData.set(elem, {}); + } + + var data = DomData.get(elem); // We need a place to store all our handler data + + if (!data.handlers) { + data.handlers = {}; + } + + if (!data.handlers[type]) { + data.handlers[type] = []; + } + + if (!fn.guid) { + fn.guid = newGUID(); + } + + data.handlers[type].push(fn); + + if (!data.dispatcher) { + data.disabled = false; + + data.dispatcher = function (event, hash) { + if (data.disabled) { + return; + } + + event = fixEvent(event); + var handlers = data.handlers[event.type]; + + if (handlers) { + // Copy handlers so if handlers are added/removed during the process it doesn't throw everything off. + var handlersCopy = handlers.slice(0); + + for (var m = 0, n = handlersCopy.length; m < n; m++) { + if (event.isImmediatePropagationStopped()) { + break; + } else { + try { + handlersCopy[m].call(elem, event, hash); + } catch (e) { + log$1.error(e); + } + } + } + } + }; + } + + if (data.handlers[type].length === 1) { + if (elem.addEventListener) { + var options = false; + + if (supportsPassive() && passiveEvents.indexOf(type) > -1) { + options = { + passive: true + }; + } + + elem.addEventListener(type, data.dispatcher, options); + } else if (elem.attachEvent) { + elem.attachEvent('on' + type, data.dispatcher); + } + } +} +/** + * Removes event listeners from an element + * + * @param {Element|Object} elem + * Object to remove listeners from. + * + * @param {string|string[]} [type] + * Type of listener to remove. Don't include to remove all events from element. + * + * @param {EventTarget~EventListener} [fn] + * Specific listener to remove. Don't include to remove listeners for an event + * type. + */ + +function off(elem, type, fn) { + // Don't want to add a cache object through getElData if not needed + if (!DomData.has(elem)) { + return; + } + + var data = DomData.get(elem); // If no events exist, nothing to unbind + + if (!data.handlers) { + return; + } + + if (Array.isArray(type)) { + return _handleMultipleEvents(off, elem, type, fn); + } // Utility function + + + var removeType = function removeType(el, t) { + data.handlers[t] = []; + + _cleanUpEvents(el, t); + }; // Are we removing all bound events? + + + if (type === undefined) { + for (var t in data.handlers) { + if (Object.prototype.hasOwnProperty.call(data.handlers || {}, t)) { + removeType(elem, t); + } + } + + return; + } + + var handlers = data.handlers[type]; // If no handlers exist, nothing to unbind + + if (!handlers) { + return; + } // If no listener was provided, remove all listeners for type + + + if (!fn) { + removeType(elem, type); + return; + } // We're only removing a single handler + + + if (fn.guid) { + for (var n = 0; n < handlers.length; n++) { + if (handlers[n].guid === fn.guid) { + handlers.splice(n--, 1); + } + } + } + + _cleanUpEvents(elem, type); +} +/** + * Trigger an event for an element + * + * @param {Element|Object} elem + * Element to trigger an event on + * + * @param {EventTarget~Event|string} event + * A string (the type) or an event object with a type attribute + * + * @param {Object} [hash] + * data hash to pass along with the event + * + * @return {boolean|undefined} + * Returns the opposite of `defaultPrevented` if default was + * prevented. Otherwise, returns `undefined` + */ + +function trigger(elem, event, hash) { + // Fetches element data and a reference to the parent (for bubbling). + // Don't want to add a data object to cache for every parent, + // so checking hasElData first. + var elemData = DomData.has(elem) ? DomData.get(elem) : {}; + var parent = elem.parentNode || elem.ownerDocument; // type = event.type || event, + // handler; + // If an event name was passed as a string, creates an event out of it + + if (typeof event === 'string') { + event = { + type: event, + target: elem + }; + } else if (!event.target) { + event.target = elem; + } // Normalizes the event properties. + + + event = fixEvent(event); // If the passed element has a dispatcher, executes the established handlers. + + if (elemData.dispatcher) { + elemData.dispatcher.call(elem, event, hash); + } // Unless explicitly stopped or the event does not bubble (e.g. media events) + // recursively calls this function to bubble the event up the DOM. + + + if (parent && !event.isPropagationStopped() && event.bubbles === true) { + trigger.call(null, parent, event, hash); // If at the top of the DOM, triggers the default action unless disabled. + } else if (!parent && !event.defaultPrevented && event.target && event.target[event.type]) { + if (!DomData.has(event.target)) { + DomData.set(event.target, {}); + } + + var targetData = DomData.get(event.target); // Checks if the target has a default action for this event. + + if (event.target[event.type]) { + // Temporarily disables event dispatching on the target as we have already executed the handler. + targetData.disabled = true; // Executes the default action. + + if (typeof event.target[event.type] === 'function') { + event.target[event.type](); + } // Re-enables event dispatching. + + + targetData.disabled = false; + } + } // Inform the triggerer if the default was prevented by returning false + + + return !event.defaultPrevented; +} +/** + * Trigger a listener only once for an event. + * + * @param {Element|Object} elem + * Element or object to bind to. + * + * @param {string|string[]} type + * Name/type of event + * + * @param {Event~EventListener} fn + * Event listener function + */ + +function one(elem, type, fn) { + if (Array.isArray(type)) { + return _handleMultipleEvents(one, elem, type, fn); + } + + var func = function func() { + off(elem, type, func); + fn.apply(this, arguments); + }; // copy the guid to the new function so it can removed using the original function's ID + + + func.guid = fn.guid = fn.guid || newGUID(); + on(elem, type, func); +} +/** + * Trigger a listener only once and then turn if off for all + * configured events + * + * @param {Element|Object} elem + * Element or object to bind to. + * + * @param {string|string[]} type + * Name/type of event + * + * @param {Event~EventListener} fn + * Event listener function + */ + +function any(elem, type, fn) { + var func = function func() { + off(elem, type, func); + fn.apply(this, arguments); + }; // copy the guid to the new function so it can removed using the original function's ID + + + func.guid = fn.guid = fn.guid || newGUID(); // multiple ons, but one off for everything + + on(elem, type, func); +} + +var Events = /*#__PURE__*/Object.freeze({ + __proto__: null, + fixEvent: fixEvent, + on: on, + off: off, + trigger: trigger, + one: one, + any: any +}); + +/** + * @file fn.js + * @module fn + */ +var UPDATE_REFRESH_INTERVAL = 30; +/** + * Bind (a.k.a proxy or context). A simple method for changing the context of + * a function. + * + * It also stores a unique id on the function so it can be easily removed from + * events. + * + * @function + * @param {Mixed} context + * The object to bind as scope. + * + * @param {Function} fn + * The function to be bound to a scope. + * + * @param {number} [uid] + * An optional unique ID for the function to be set + * + * @return {Function} + * The new function that will be bound into the context given + */ + +var bind = function bind(context, fn, uid) { + // Make sure the function has a unique ID + if (!fn.guid) { + fn.guid = newGUID(); + } // Create the new function that changes the context + + + var bound = fn.bind(context); // Allow for the ability to individualize this function + // Needed in the case where multiple objects might share the same prototype + // IF both items add an event listener with the same function, then you try to remove just one + // it will remove both because they both have the same guid. + // when using this, you need to use the bind method when you remove the listener as well. + // currently used in text tracks + + bound.guid = uid ? uid + '_' + fn.guid : fn.guid; + return bound; +}; +/** + * Wraps the given function, `fn`, with a new function that only invokes `fn` + * at most once per every `wait` milliseconds. + * + * @function + * @param {Function} fn + * The function to be throttled. + * + * @param {number} wait + * The number of milliseconds by which to throttle. + * + * @return {Function} + */ + +var throttle = function throttle(fn, wait) { + var last = global_window__WEBPACK_IMPORTED_MODULE_0___default().performance.now(); + + var throttled = function throttled() { + var now = global_window__WEBPACK_IMPORTED_MODULE_0___default().performance.now(); + + if (now - last >= wait) { + fn.apply(void 0, arguments); + last = now; + } + }; + + return throttled; +}; +/** + * Creates a debounced function that delays invoking `func` until after `wait` + * milliseconds have elapsed since the last time the debounced function was + * invoked. + * + * Inspired by lodash and underscore implementations. + * + * @function + * @param {Function} func + * The function to wrap with debounce behavior. + * + * @param {number} wait + * The number of milliseconds to wait after the last invocation. + * + * @param {boolean} [immediate] + * Whether or not to invoke the function immediately upon creation. + * + * @param {Object} [context=window] + * The "context" in which the debounced function should debounce. For + * example, if this function should be tied to a Video.js player, + * the player can be passed here. Alternatively, defaults to the + * global `window` object. + * + * @return {Function} + * A debounced function. + */ + +var debounce = function debounce(func, wait, immediate, context) { + if (context === void 0) { + context = (global_window__WEBPACK_IMPORTED_MODULE_0___default()); + } + + var timeout; + + var cancel = function cancel() { + context.clearTimeout(timeout); + timeout = null; + }; + /* eslint-disable consistent-this */ + + + var debounced = function debounced() { + var self = this; + var args = arguments; + + var _later = function later() { + timeout = null; + _later = null; + + if (!immediate) { + func.apply(self, args); + } + }; + + if (!timeout && immediate) { + func.apply(self, args); + } + + context.clearTimeout(timeout); + timeout = context.setTimeout(_later, wait); + }; + /* eslint-enable consistent-this */ + + + debounced.cancel = cancel; + return debounced; +}; + +/** + * @file src/js/event-target.js + */ +/** + * `EventTarget` is a class that can have the same API as the DOM `EventTarget`. It + * adds shorthand functions that wrap around lengthy functions. For example: + * the `on` function is a wrapper around `addEventListener`. + * + * @see [EventTarget Spec]{@link https://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget} + * @class EventTarget + */ + +var EventTarget$2 = function EventTarget() {}; +/** + * A Custom DOM event. + * + * @typedef {Object} EventTarget~Event + * @see [Properties]{@link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent} + */ + +/** + * All event listeners should follow the following format. + * + * @callback EventTarget~EventListener + * @this {EventTarget} + * + * @param {EventTarget~Event} event + * the event that triggered this function + * + * @param {Object} [hash] + * hash of data sent during the event + */ + +/** + * An object containing event names as keys and booleans as values. + * + * > NOTE: If an event name is set to a true value here {@link EventTarget#trigger} + * will have extra functionality. See that function for more information. + * + * @property EventTarget.prototype.allowedEvents_ + * @private + */ + + +EventTarget$2.prototype.allowedEvents_ = {}; +/** + * Adds an `event listener` to an instance of an `EventTarget`. An `event listener` is a + * function that will get called when an event with a certain name gets triggered. + * + * @param {string|string[]} type + * An event name or an array of event names. + * + * @param {EventTarget~EventListener} fn + * The function to call with `EventTarget`s + */ + +EventTarget$2.prototype.on = function (type, fn) { + // Remove the addEventListener alias before calling Events.on + // so we don't get into an infinite type loop + var ael = this.addEventListener; + + this.addEventListener = function () {}; + + on(this, type, fn); + this.addEventListener = ael; +}; +/** + * An alias of {@link EventTarget#on}. Allows `EventTarget` to mimic + * the standard DOM API. + * + * @function + * @see {@link EventTarget#on} + */ + + +EventTarget$2.prototype.addEventListener = EventTarget$2.prototype.on; +/** + * Removes an `event listener` for a specific event from an instance of `EventTarget`. + * This makes it so that the `event listener` will no longer get called when the + * named event happens. + * + * @param {string|string[]} type + * An event name or an array of event names. + * + * @param {EventTarget~EventListener} fn + * The function to remove. + */ + +EventTarget$2.prototype.off = function (type, fn) { + off(this, type, fn); +}; +/** + * An alias of {@link EventTarget#off}. Allows `EventTarget` to mimic + * the standard DOM API. + * + * @function + * @see {@link EventTarget#off} + */ + + +EventTarget$2.prototype.removeEventListener = EventTarget$2.prototype.off; +/** + * This function will add an `event listener` that gets triggered only once. After the + * first trigger it will get removed. This is like adding an `event listener` + * with {@link EventTarget#on} that calls {@link EventTarget#off} on itself. + * + * @param {string|string[]} type + * An event name or an array of event names. + * + * @param {EventTarget~EventListener} fn + * The function to be called once for each event name. + */ + +EventTarget$2.prototype.one = function (type, fn) { + // Remove the addEventListener aliasing Events.on + // so we don't get into an infinite type loop + var ael = this.addEventListener; + + this.addEventListener = function () {}; + + one(this, type, fn); + this.addEventListener = ael; +}; + +EventTarget$2.prototype.any = function (type, fn) { + // Remove the addEventListener aliasing Events.on + // so we don't get into an infinite type loop + var ael = this.addEventListener; + + this.addEventListener = function () {}; + + any(this, type, fn); + this.addEventListener = ael; +}; +/** + * This function causes an event to happen. This will then cause any `event listeners` + * that are waiting for that event, to get called. If there are no `event listeners` + * for an event then nothing will happen. + * + * If the name of the `Event` that is being triggered is in `EventTarget.allowedEvents_`. + * Trigger will also call the `on` + `uppercaseEventName` function. + * + * Example: + * 'click' is in `EventTarget.allowedEvents_`, so, trigger will attempt to call + * `onClick` if it exists. + * + * @param {string|EventTarget~Event|Object} event + * The name of the event, an `Event`, or an object with a key of type set to + * an event name. + */ + + +EventTarget$2.prototype.trigger = function (event) { + var type = event.type || event; // deprecation + // In a future version we should default target to `this` + // similar to how we default the target to `elem` in + // `Events.trigger`. Right now the default `target` will be + // `document` due to the `Event.fixEvent` call. + + if (typeof event === 'string') { + event = { + type: type + }; + } + + event = fixEvent(event); + + if (this.allowedEvents_[type] && this['on' + type]) { + this['on' + type](event); + } + + trigger(this, event); +}; +/** + * An alias of {@link EventTarget#trigger}. Allows `EventTarget` to mimic + * the standard DOM API. + * + * @function + * @see {@link EventTarget#trigger} + */ + + +EventTarget$2.prototype.dispatchEvent = EventTarget$2.prototype.trigger; +var EVENT_MAP; + +EventTarget$2.prototype.queueTrigger = function (event) { + var _this = this; + + // only set up EVENT_MAP if it'll be used + if (!EVENT_MAP) { + EVENT_MAP = new Map(); + } + + var type = event.type || event; + var map = EVENT_MAP.get(this); + + if (!map) { + map = new Map(); + EVENT_MAP.set(this, map); + } + + var oldTimeout = map.get(type); + map["delete"](type); + global_window__WEBPACK_IMPORTED_MODULE_0___default().clearTimeout(oldTimeout); + var timeout = global_window__WEBPACK_IMPORTED_MODULE_0___default().setTimeout(function () { + // if we cleared out all timeouts for the current target, delete its map + if (map.size === 0) { + map = null; + EVENT_MAP["delete"](_this); + } + + _this.trigger(event); + }, 0); + map.set(type, timeout); +}; + +/** + * @file mixins/evented.js + * @module evented + */ + +var objName = function objName(obj) { + if (typeof obj.name === 'function') { + return obj.name(); + } + + if (typeof obj.name === 'string') { + return obj.name; + } + + if (obj.name_) { + return obj.name_; + } + + if (obj.constructor && obj.constructor.name) { + return obj.constructor.name; + } + + return typeof obj; +}; +/** + * Returns whether or not an object has had the evented mixin applied. + * + * @param {Object} object + * An object to test. + * + * @return {boolean} + * Whether or not the object appears to be evented. + */ + + +var isEvented = function isEvented(object) { + return object instanceof EventTarget$2 || !!object.eventBusEl_ && ['on', 'one', 'off', 'trigger'].every(function (k) { + return typeof object[k] === 'function'; + }); +}; +/** + * Adds a callback to run after the evented mixin applied. + * + * @param {Object} object + * An object to Add + * @param {Function} callback + * The callback to run. + */ + + +var addEventedCallback = function addEventedCallback(target, callback) { + if (isEvented(target)) { + callback(); + } else { + if (!target.eventedCallbacks) { + target.eventedCallbacks = []; + } + + target.eventedCallbacks.push(callback); + } +}; +/** + * Whether a value is a valid event type - non-empty string or array. + * + * @private + * @param {string|Array} type + * The type value to test. + * + * @return {boolean} + * Whether or not the type is a valid event type. + */ + + +var isValidEventType = function isValidEventType(type) { + return (// The regex here verifies that the `type` contains at least one non- + // whitespace character. + typeof type === 'string' && /\S/.test(type) || Array.isArray(type) && !!type.length + ); +}; +/** + * Validates a value to determine if it is a valid event target. Throws if not. + * + * @private + * @throws {Error} + * If the target does not appear to be a valid event target. + * + * @param {Object} target + * The object to test. + * + * @param {Object} obj + * The evented object we are validating for + * + * @param {string} fnName + * The name of the evented mixin function that called this. + */ + + +var validateTarget = function validateTarget(target, obj, fnName) { + if (!target || !target.nodeName && !isEvented(target)) { + throw new Error("Invalid target for " + objName(obj) + "#" + fnName + "; must be a DOM node or evented object."); + } +}; +/** + * Validates a value to determine if it is a valid event target. Throws if not. + * + * @private + * @throws {Error} + * If the type does not appear to be a valid event type. + * + * @param {string|Array} type + * The type to test. + * + * @param {Object} obj +* The evented object we are validating for + * + * @param {string} fnName + * The name of the evented mixin function that called this. + */ + + +var validateEventType = function validateEventType(type, obj, fnName) { + if (!isValidEventType(type)) { + throw new Error("Invalid event type for " + objName(obj) + "#" + fnName + "; must be a non-empty string or array."); + } +}; +/** + * Validates a value to determine if it is a valid listener. Throws if not. + * + * @private + * @throws {Error} + * If the listener is not a function. + * + * @param {Function} listener + * The listener to test. + * + * @param {Object} obj + * The evented object we are validating for + * + * @param {string} fnName + * The name of the evented mixin function that called this. + */ + + +var validateListener = function validateListener(listener, obj, fnName) { + if (typeof listener !== 'function') { + throw new Error("Invalid listener for " + objName(obj) + "#" + fnName + "; must be a function."); + } +}; +/** + * Takes an array of arguments given to `on()` or `one()`, validates them, and + * normalizes them into an object. + * + * @private + * @param {Object} self + * The evented object on which `on()` or `one()` was called. This + * object will be bound as the `this` value for the listener. + * + * @param {Array} args + * An array of arguments passed to `on()` or `one()`. + * + * @param {string} fnName + * The name of the evented mixin function that called this. + * + * @return {Object} + * An object containing useful values for `on()` or `one()` calls. + */ + + +var normalizeListenArgs = function normalizeListenArgs(self, args, fnName) { + // If the number of arguments is less than 3, the target is always the + // evented object itself. + var isTargetingSelf = args.length < 3 || args[0] === self || args[0] === self.eventBusEl_; + var target; + var type; + var listener; + + if (isTargetingSelf) { + target = self.eventBusEl_; // Deal with cases where we got 3 arguments, but we are still listening to + // the evented object itself. + + if (args.length >= 3) { + args.shift(); + } + + type = args[0]; + listener = args[1]; + } else { + target = args[0]; + type = args[1]; + listener = args[2]; + } + + validateTarget(target, self, fnName); + validateEventType(type, self, fnName); + validateListener(listener, self, fnName); + listener = bind(self, listener); + return { + isTargetingSelf: isTargetingSelf, + target: target, + type: type, + listener: listener + }; +}; +/** + * Adds the listener to the event type(s) on the target, normalizing for + * the type of target. + * + * @private + * @param {Element|Object} target + * A DOM node or evented object. + * + * @param {string} method + * The event binding method to use ("on" or "one"). + * + * @param {string|Array} type + * One or more event type(s). + * + * @param {Function} listener + * A listener function. + */ + + +var listen = function listen(target, method, type, listener) { + validateTarget(target, target, method); + + if (target.nodeName) { + Events[method](target, type, listener); + } else { + target[method](type, listener); + } +}; +/** + * Contains methods that provide event capabilities to an object which is passed + * to {@link module:evented|evented}. + * + * @mixin EventedMixin + */ + + +var EventedMixin = { + /** + * Add a listener to an event (or events) on this object or another evented + * object. + * + * @param {string|Array|Element|Object} targetOrType + * If this is a string or array, it represents the event type(s) + * that will trigger the listener. + * + * Another evented object can be passed here instead, which will + * cause the listener to listen for events on _that_ object. + * + * In either case, the listener's `this` value will be bound to + * this object. + * + * @param {string|Array|Function} typeOrListener + * If the first argument was a string or array, this should be the + * listener function. Otherwise, this is a string or array of event + * type(s). + * + * @param {Function} [listener] + * If the first argument was another evented object, this will be + * the listener function. + */ + on: function on() { + var _this = this; + + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + var _normalizeListenArgs = normalizeListenArgs(this, args, 'on'), + isTargetingSelf = _normalizeListenArgs.isTargetingSelf, + target = _normalizeListenArgs.target, + type = _normalizeListenArgs.type, + listener = _normalizeListenArgs.listener; + + listen(target, 'on', type, listener); // If this object is listening to another evented object. + + if (!isTargetingSelf) { + // If this object is disposed, remove the listener. + var removeListenerOnDispose = function removeListenerOnDispose() { + return _this.off(target, type, listener); + }; // Use the same function ID as the listener so we can remove it later it + // using the ID of the original listener. + + + removeListenerOnDispose.guid = listener.guid; // Add a listener to the target's dispose event as well. This ensures + // that if the target is disposed BEFORE this object, we remove the + // removal listener that was just added. Otherwise, we create a memory leak. + + var removeRemoverOnTargetDispose = function removeRemoverOnTargetDispose() { + return _this.off('dispose', removeListenerOnDispose); + }; // Use the same function ID as the listener so we can remove it later + // it using the ID of the original listener. + + + removeRemoverOnTargetDispose.guid = listener.guid; + listen(this, 'on', 'dispose', removeListenerOnDispose); + listen(target, 'on', 'dispose', removeRemoverOnTargetDispose); + } + }, + + /** + * Add a listener to an event (or events) on this object or another evented + * object. The listener will be called once per event and then removed. + * + * @param {string|Array|Element|Object} targetOrType + * If this is a string or array, it represents the event type(s) + * that will trigger the listener. + * + * Another evented object can be passed here instead, which will + * cause the listener to listen for events on _that_ object. + * + * In either case, the listener's `this` value will be bound to + * this object. + * + * @param {string|Array|Function} typeOrListener + * If the first argument was a string or array, this should be the + * listener function. Otherwise, this is a string or array of event + * type(s). + * + * @param {Function} [listener] + * If the first argument was another evented object, this will be + * the listener function. + */ + one: function one() { + var _this2 = this; + + for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + args[_key2] = arguments[_key2]; + } + + var _normalizeListenArgs2 = normalizeListenArgs(this, args, 'one'), + isTargetingSelf = _normalizeListenArgs2.isTargetingSelf, + target = _normalizeListenArgs2.target, + type = _normalizeListenArgs2.type, + listener = _normalizeListenArgs2.listener; // Targeting this evented object. + + + if (isTargetingSelf) { + listen(target, 'one', type, listener); // Targeting another evented object. + } else { + // TODO: This wrapper is incorrect! It should only + // remove the wrapper for the event type that called it. + // Instead all listners are removed on the first trigger! + // see https://github.com/videojs/video.js/issues/5962 + var wrapper = function wrapper() { + _this2.off(target, type, wrapper); + + for (var _len3 = arguments.length, largs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { + largs[_key3] = arguments[_key3]; + } + + listener.apply(null, largs); + }; // Use the same function ID as the listener so we can remove it later + // it using the ID of the original listener. + + + wrapper.guid = listener.guid; + listen(target, 'one', type, wrapper); + } + }, + + /** + * Add a listener to an event (or events) on this object or another evented + * object. The listener will only be called once for the first event that is triggered + * then removed. + * + * @param {string|Array|Element|Object} targetOrType + * If this is a string or array, it represents the event type(s) + * that will trigger the listener. + * + * Another evented object can be passed here instead, which will + * cause the listener to listen for events on _that_ object. + * + * In either case, the listener's `this` value will be bound to + * this object. + * + * @param {string|Array|Function} typeOrListener + * If the first argument was a string or array, this should be the + * listener function. Otherwise, this is a string or array of event + * type(s). + * + * @param {Function} [listener] + * If the first argument was another evented object, this will be + * the listener function. + */ + any: function any() { + var _this3 = this; + + for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { + args[_key4] = arguments[_key4]; + } + + var _normalizeListenArgs3 = normalizeListenArgs(this, args, 'any'), + isTargetingSelf = _normalizeListenArgs3.isTargetingSelf, + target = _normalizeListenArgs3.target, + type = _normalizeListenArgs3.type, + listener = _normalizeListenArgs3.listener; // Targeting this evented object. + + + if (isTargetingSelf) { + listen(target, 'any', type, listener); // Targeting another evented object. + } else { + var wrapper = function wrapper() { + _this3.off(target, type, wrapper); + + for (var _len5 = arguments.length, largs = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { + largs[_key5] = arguments[_key5]; + } + + listener.apply(null, largs); + }; // Use the same function ID as the listener so we can remove it later + // it using the ID of the original listener. + + + wrapper.guid = listener.guid; + listen(target, 'any', type, wrapper); + } + }, + + /** + * Removes listener(s) from event(s) on an evented object. + * + * @param {string|Array|Element|Object} [targetOrType] + * If this is a string or array, it represents the event type(s). + * + * Another evented object can be passed here instead, in which case + * ALL 3 arguments are _required_. + * + * @param {string|Array|Function} [typeOrListener] + * If the first argument was a string or array, this may be the + * listener function. Otherwise, this is a string or array of event + * type(s). + * + * @param {Function} [listener] + * If the first argument was another evented object, this will be + * the listener function; otherwise, _all_ listeners bound to the + * event type(s) will be removed. + */ + off: function off$1(targetOrType, typeOrListener, listener) { + // Targeting this evented object. + if (!targetOrType || isValidEventType(targetOrType)) { + off(this.eventBusEl_, targetOrType, typeOrListener); // Targeting another evented object. + } else { + var target = targetOrType; + var type = typeOrListener; // Fail fast and in a meaningful way! + + validateTarget(target, this, 'off'); + validateEventType(type, this, 'off'); + validateListener(listener, this, 'off'); // Ensure there's at least a guid, even if the function hasn't been used + + listener = bind(this, listener); // Remove the dispose listener on this evented object, which was given + // the same guid as the event listener in on(). + + this.off('dispose', listener); + + if (target.nodeName) { + off(target, type, listener); + off(target, 'dispose', listener); + } else if (isEvented(target)) { + target.off(type, listener); + target.off('dispose', listener); + } + } + }, + + /** + * Fire an event on this evented object, causing its listeners to be called. + * + * @param {string|Object} event + * An event type or an object with a type property. + * + * @param {Object} [hash] + * An additional object to pass along to listeners. + * + * @return {boolean} + * Whether or not the default behavior was prevented. + */ + trigger: function trigger$1(event, hash) { + validateTarget(this.eventBusEl_, this, 'trigger'); + var type = event && typeof event !== 'string' ? event.type : event; + + if (!isValidEventType(type)) { + var error = "Invalid event type for " + objName(this) + "#trigger; " + 'must be a non-empty string or object with a type key that has a non-empty value.'; + + if (event) { + (this.log || log$1).error(error); + } else { + throw new Error(error); + } + } + + return trigger(this.eventBusEl_, event, hash); + } +}; +/** + * Applies {@link module:evented~EventedMixin|EventedMixin} to a target object. + * + * @param {Object} target + * The object to which to add event methods. + * + * @param {Object} [options={}] + * Options for customizing the mixin behavior. + * + * @param {string} [options.eventBusKey] + * By default, adds a `eventBusEl_` DOM element to the target object, + * which is used as an event bus. If the target object already has a + * DOM element that should be used, pass its key here. + * + * @return {Object} + * The target object. + */ + +function evented(target, options) { + if (options === void 0) { + options = {}; + } + + var _options = options, + eventBusKey = _options.eventBusKey; // Set or create the eventBusEl_. + + if (eventBusKey) { + if (!target[eventBusKey].nodeName) { + throw new Error("The eventBusKey \"" + eventBusKey + "\" does not refer to an element."); + } + + target.eventBusEl_ = target[eventBusKey]; + } else { + target.eventBusEl_ = createEl('span', { + className: 'vjs-event-bus' + }); + } + + assign(target, EventedMixin); + + if (target.eventedCallbacks) { + target.eventedCallbacks.forEach(function (callback) { + callback(); + }); + } // When any evented object is disposed, it removes all its listeners. + + + target.on('dispose', function () { + target.off(); + [target, target.el_, target.eventBusEl_].forEach(function (val) { + if (val && DomData.has(val)) { + DomData["delete"](val); + } + }); + global_window__WEBPACK_IMPORTED_MODULE_0___default().setTimeout(function () { + target.eventBusEl_ = null; + }, 0); + }); + return target; +} + +/** + * @file mixins/stateful.js + * @module stateful + */ +/** + * Contains methods that provide statefulness to an object which is passed + * to {@link module:stateful}. + * + * @mixin StatefulMixin + */ + +var StatefulMixin = { + /** + * A hash containing arbitrary keys and values representing the state of + * the object. + * + * @type {Object} + */ + state: {}, + + /** + * Set the state of an object by mutating its + * {@link module:stateful~StatefulMixin.state|state} object in place. + * + * @fires module:stateful~StatefulMixin#statechanged + * @param {Object|Function} stateUpdates + * A new set of properties to shallow-merge into the plugin state. + * Can be a plain object or a function returning a plain object. + * + * @return {Object|undefined} + * An object containing changes that occurred. If no changes + * occurred, returns `undefined`. + */ + setState: function setState(stateUpdates) { + var _this = this; + + // Support providing the `stateUpdates` state as a function. + if (typeof stateUpdates === 'function') { + stateUpdates = stateUpdates(); + } + + var changes; + each(stateUpdates, function (value, key) { + // Record the change if the value is different from what's in the + // current state. + if (_this.state[key] !== value) { + changes = changes || {}; + changes[key] = { + from: _this.state[key], + to: value + }; + } + + _this.state[key] = value; + }); // Only trigger "statechange" if there were changes AND we have a trigger + // function. This allows us to not require that the target object be an + // evented object. + + if (changes && isEvented(this)) { + /** + * An event triggered on an object that is both + * {@link module:stateful|stateful} and {@link module:evented|evented} + * indicating that its state has changed. + * + * @event module:stateful~StatefulMixin#statechanged + * @type {Object} + * @property {Object} changes + * A hash containing the properties that were changed and + * the values they were changed `from` and `to`. + */ + this.trigger({ + changes: changes, + type: 'statechanged' + }); + } + + return changes; + } +}; +/** + * Applies {@link module:stateful~StatefulMixin|StatefulMixin} to a target + * object. + * + * If the target object is {@link module:evented|evented} and has a + * `handleStateChanged` method, that method will be automatically bound to the + * `statechanged` event on itself. + * + * @param {Object} target + * The object to be made stateful. + * + * @param {Object} [defaultState] + * A default set of properties to populate the newly-stateful object's + * `state` property. + * + * @return {Object} + * Returns the `target`. + */ + +function stateful(target, defaultState) { + assign(target, StatefulMixin); // This happens after the mixing-in because we need to replace the `state` + // added in that step. + + target.state = assign({}, target.state, defaultState); // Auto-bind the `handleStateChanged` method of the target object if it exists. + + if (typeof target.handleStateChanged === 'function' && isEvented(target)) { + target.on('statechanged', target.handleStateChanged); + } + + return target; +} + +/** + * @file string-cases.js + * @module to-lower-case + */ + +/** + * Lowercase the first letter of a string. + * + * @param {string} string + * String to be lowercased + * + * @return {string} + * The string with a lowercased first letter + */ +var toLowerCase = function toLowerCase(string) { + if (typeof string !== 'string') { + return string; + } + + return string.replace(/./, function (w) { + return w.toLowerCase(); + }); +}; +/** + * Uppercase the first letter of a string. + * + * @param {string} string + * String to be uppercased + * + * @return {string} + * The string with an uppercased first letter + */ + +var toTitleCase$1 = function toTitleCase(string) { + if (typeof string !== 'string') { + return string; + } + + return string.replace(/./, function (w) { + return w.toUpperCase(); + }); +}; +/** + * Compares the TitleCase versions of the two strings for equality. + * + * @param {string} str1 + * The first string to compare + * + * @param {string} str2 + * The second string to compare + * + * @return {boolean} + * Whether the TitleCase versions of the strings are equal + */ + +var titleCaseEquals = function titleCaseEquals(str1, str2) { + return toTitleCase$1(str1) === toTitleCase$1(str2); +}; + +/** + * @file merge-options.js + * @module merge-options + */ +/** + * Merge two objects recursively. + * + * Performs a deep merge like + * {@link https://lodash.com/docs/4.17.10#merge|lodash.merge}, but only merges + * plain objects (not arrays, elements, or anything else). + * + * Non-plain object values will be copied directly from the right-most + * argument. + * + * @static + * @param {Object[]} sources + * One or more objects to merge into a new object. + * + * @return {Object} + * A new object that is the merged result of all sources. + */ + +function mergeOptions$3() { + var result = {}; + + for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) { + sources[_key] = arguments[_key]; + } + + sources.forEach(function (source) { + if (!source) { + return; + } + + each(source, function (value, key) { + if (!isPlain(value)) { + result[key] = value; + return; + } + + if (!isPlain(result[key])) { + result[key] = {}; + } + + result[key] = mergeOptions$3(result[key], value); + }); + }); + return result; +} + +var MapSham = /*#__PURE__*/function () { + function MapSham() { + this.map_ = {}; + } + + var _proto = MapSham.prototype; + + _proto.has = function has(key) { + return key in this.map_; + }; + + _proto["delete"] = function _delete(key) { + var has = this.has(key); + delete this.map_[key]; + return has; + }; + + _proto.set = function set(key, value) { + this.map_[key] = value; + return this; + }; + + _proto.forEach = function forEach(callback, thisArg) { + for (var key in this.map_) { + callback.call(thisArg, this.map_[key], key, this); + } + }; + + return MapSham; +}(); + +var Map$1 = (global_window__WEBPACK_IMPORTED_MODULE_0___default().Map) ? (global_window__WEBPACK_IMPORTED_MODULE_0___default().Map) : MapSham; + +var SetSham = /*#__PURE__*/function () { + function SetSham() { + this.set_ = {}; + } + + var _proto = SetSham.prototype; + + _proto.has = function has(key) { + return key in this.set_; + }; + + _proto["delete"] = function _delete(key) { + var has = this.has(key); + delete this.set_[key]; + return has; + }; + + _proto.add = function add(key) { + this.set_[key] = 1; + return this; + }; + + _proto.forEach = function forEach(callback, thisArg) { + for (var key in this.set_) { + callback.call(thisArg, key, key, this); + } + }; + + return SetSham; +}(); + +var Set = (global_window__WEBPACK_IMPORTED_MODULE_0___default().Set) ? (global_window__WEBPACK_IMPORTED_MODULE_0___default().Set) : SetSham; + +/** + * Player Component - Base class for all UI objects + * + * @file component.js + */ +/** + * Base class for all UI Components. + * Components are UI objects which represent both a javascript object and an element + * in the DOM. They can be children of other components, and can have + * children themselves. + * + * Components can also use methods from {@link EventTarget} + */ + +var Component$1 = /*#__PURE__*/function () { + /** + * A callback that is called when a component is ready. Does not have any + * paramters and any callback value will be ignored. + * + * @callback Component~ReadyCallback + * @this Component + */ + + /** + * Creates an instance of this class. + * + * @param {Player} player + * The `Player` that this class should be attached to. + * + * @param {Object} [options] + * The key/value store of player options. + * + * @param {Object[]} [options.children] + * An array of children objects to intialize this component with. Children objects have + * a name property that will be used if more than one component of the same type needs to be + * added. + * + * @param {Component~ReadyCallback} [ready] + * Function that gets called when the `Component` is ready. + */ + function Component(player, options, ready) { + // The component might be the player itself and we can't pass `this` to super + if (!player && this.play) { + this.player_ = player = this; // eslint-disable-line + } else { + this.player_ = player; + } + + this.isDisposed_ = false; // Hold the reference to the parent component via `addChild` method + + this.parentComponent_ = null; // Make a copy of prototype.options_ to protect against overriding defaults + + this.options_ = mergeOptions$3({}, this.options_); // Updated options with supplied options + + options = this.options_ = mergeOptions$3(this.options_, options); // Get ID from options or options element if one is supplied + + this.id_ = options.id || options.el && options.el.id; // If there was no ID from the options, generate one + + if (!this.id_) { + // Don't require the player ID function in the case of mock players + var id = player && player.id && player.id() || 'no_player'; + this.id_ = id + "_component_" + newGUID(); + } + + this.name_ = options.name || null; // Create element if one wasn't provided in options + + if (options.el) { + this.el_ = options.el; + } else if (options.createEl !== false) { + this.el_ = this.createEl(); + } // if evented is anything except false, we want to mixin in evented + + + if (options.evented !== false) { + // Make this an evented object and use `el_`, if available, as its event bus + evented(this, { + eventBusKey: this.el_ ? 'el_' : null + }); + this.handleLanguagechange = this.handleLanguagechange.bind(this); + this.on(this.player_, 'languagechange', this.handleLanguagechange); + } + + stateful(this, this.constructor.defaultState); + this.children_ = []; + this.childIndex_ = {}; + this.childNameIndex_ = {}; + this.setTimeoutIds_ = new Set(); + this.setIntervalIds_ = new Set(); + this.rafIds_ = new Set(); + this.namedRafs_ = new Map$1(); + this.clearingTimersOnDispose_ = false; // Add any child components in options + + if (options.initChildren !== false) { + this.initChildren(); + } // Don't want to trigger ready here or it will go before init is actually + // finished for all children that run this constructor + + + this.ready(ready); + + if (options.reportTouchActivity !== false) { + this.enableTouchActivity(); + } + } + /** + * Dispose of the `Component` and all child components. + * + * @fires Component#dispose + */ + + + var _proto = Component.prototype; + + _proto.dispose = function dispose() { + // Bail out if the component has already been disposed. + if (this.isDisposed_) { + return; + } + + if (this.readyQueue_) { + this.readyQueue_.length = 0; + } + /** + * Triggered when a `Component` is disposed. + * + * @event Component#dispose + * @type {EventTarget~Event} + * + * @property {boolean} [bubbles=false] + * set to false so that the dispose event does not + * bubble up + */ + + + this.trigger({ + type: 'dispose', + bubbles: false + }); + this.isDisposed_ = true; // Dispose all children. + + if (this.children_) { + for (var i = this.children_.length - 1; i >= 0; i--) { + if (this.children_[i].dispose) { + this.children_[i].dispose(); + } + } + } // Delete child references + + + this.children_ = null; + this.childIndex_ = null; + this.childNameIndex_ = null; + this.parentComponent_ = null; + + if (this.el_) { + // Remove element from DOM + if (this.el_.parentNode) { + this.el_.parentNode.removeChild(this.el_); + } + + this.el_ = null; + } // remove reference to the player after disposing of the element + + + this.player_ = null; + } + /** + * Determine whether or not this component has been disposed. + * + * @return {boolean} + * If the component has been disposed, will be `true`. Otherwise, `false`. + */ + ; + + _proto.isDisposed = function isDisposed() { + return Boolean(this.isDisposed_); + } + /** + * Return the {@link Player} that the `Component` has attached to. + * + * @return {Player} + * The player that this `Component` has attached to. + */ + ; + + _proto.player = function player() { + return this.player_; + } + /** + * Deep merge of options objects with new options. + * > Note: When both `obj` and `options` contain properties whose values are objects. + * The two properties get merged using {@link module:mergeOptions} + * + * @param {Object} obj + * The object that contains new options. + * + * @return {Object} + * A new object of `this.options_` and `obj` merged together. + */ + ; + + _proto.options = function options(obj) { + if (!obj) { + return this.options_; + } + + this.options_ = mergeOptions$3(this.options_, obj); + return this.options_; + } + /** + * Get the `Component`s DOM element + * + * @return {Element} + * The DOM element for this `Component`. + */ + ; + + _proto.el = function el() { + return this.el_; + } + /** + * Create the `Component`s DOM element. + * + * @param {string} [tagName] + * Element's DOM node type. e.g. 'div' + * + * @param {Object} [properties] + * An object of properties that should be set. + * + * @param {Object} [attributes] + * An object of attributes that should be set. + * + * @return {Element} + * The element that gets created. + */ + ; + + _proto.createEl = function createEl$1(tagName, properties, attributes) { + return createEl(tagName, properties, attributes); + } + /** + * Localize a string given the string in english. + * + * If tokens are provided, it'll try and run a simple token replacement on the provided string. + * The tokens it looks for look like `{1}` with the index being 1-indexed into the tokens array. + * + * If a `defaultValue` is provided, it'll use that over `string`, + * if a value isn't found in provided language files. + * This is useful if you want to have a descriptive key for token replacement + * but have a succinct localized string and not require `en.json` to be included. + * + * Currently, it is used for the progress bar timing. + * ```js + * { + * "progress bar timing: currentTime={1} duration={2}": "{1} of {2}" + * } + * ``` + * It is then used like so: + * ```js + * this.localize('progress bar timing: currentTime={1} duration{2}', + * [this.player_.currentTime(), this.player_.duration()], + * '{1} of {2}'); + * ``` + * + * Which outputs something like: `01:23 of 24:56`. + * + * + * @param {string} string + * The string to localize and the key to lookup in the language files. + * @param {string[]} [tokens] + * If the current item has token replacements, provide the tokens here. + * @param {string} [defaultValue] + * Defaults to `string`. Can be a default value to use for token replacement + * if the lookup key is needed to be separate. + * + * @return {string} + * The localized string or if no localization exists the english string. + */ + ; + + _proto.localize = function localize(string, tokens, defaultValue) { + if (defaultValue === void 0) { + defaultValue = string; + } + + var code = this.player_.language && this.player_.language(); + var languages = this.player_.languages && this.player_.languages(); + var language = languages && languages[code]; + var primaryCode = code && code.split('-')[0]; + var primaryLang = languages && languages[primaryCode]; + var localizedString = defaultValue; + + if (language && language[string]) { + localizedString = language[string]; + } else if (primaryLang && primaryLang[string]) { + localizedString = primaryLang[string]; + } + + if (tokens) { + localizedString = localizedString.replace(/\{(\d+)\}/g, function (match, index) { + var value = tokens[index - 1]; + var ret = value; + + if (typeof value === 'undefined') { + ret = match; + } + + return ret; + }); + } + + return localizedString; + } + /** + * Handles language change for the player in components. Should be overriden by sub-components. + * + * @abstract + */ + ; + + _proto.handleLanguagechange = function handleLanguagechange() {} + /** + * Return the `Component`s DOM element. This is where children get inserted. + * This will usually be the the same as the element returned in {@link Component#el}. + * + * @return {Element} + * The content element for this `Component`. + */ + ; + + _proto.contentEl = function contentEl() { + return this.contentEl_ || this.el_; + } + /** + * Get this `Component`s ID + * + * @return {string} + * The id of this `Component` + */ + ; + + _proto.id = function id() { + return this.id_; + } + /** + * Get the `Component`s name. The name gets used to reference the `Component` + * and is set during registration. + * + * @return {string} + * The name of this `Component`. + */ + ; + + _proto.name = function name() { + return this.name_; + } + /** + * Get an array of all child components + * + * @return {Array} + * The children + */ + ; + + _proto.children = function children() { + return this.children_; + } + /** + * Returns the child `Component` with the given `id`. + * + * @param {string} id + * The id of the child `Component` to get. + * + * @return {Component|undefined} + * The child `Component` with the given `id` or undefined. + */ + ; + + _proto.getChildById = function getChildById(id) { + return this.childIndex_[id]; + } + /** + * Returns the child `Component` with the given `name`. + * + * @param {string} name + * The name of the child `Component` to get. + * + * @return {Component|undefined} + * The child `Component` with the given `name` or undefined. + */ + ; + + _proto.getChild = function getChild(name) { + if (!name) { + return; + } + + return this.childNameIndex_[name]; + } + /** + * Returns the descendant `Component` following the givent + * descendant `names`. For instance ['foo', 'bar', 'baz'] would + * try to get 'foo' on the current component, 'bar' on the 'foo' + * component and 'baz' on the 'bar' component and return undefined + * if any of those don't exist. + * + * @param {...string[]|...string} names + * The name of the child `Component` to get. + * + * @return {Component|undefined} + * The descendant `Component` following the given descendant + * `names` or undefined. + */ + ; + + _proto.getDescendant = function getDescendant() { + for (var _len = arguments.length, names = new Array(_len), _key = 0; _key < _len; _key++) { + names[_key] = arguments[_key]; + } + + // flatten array argument into the main array + names = names.reduce(function (acc, n) { + return acc.concat(n); + }, []); + var currentChild = this; + + for (var i = 0; i < names.length; i++) { + currentChild = currentChild.getChild(names[i]); + + if (!currentChild || !currentChild.getChild) { + return; + } + } + + return currentChild; + } + /** + * Add a child `Component` inside the current `Component`. + * + * + * @param {string|Component} child + * The name or instance of a child to add. + * + * @param {Object} [options={}] + * The key/value store of options that will get passed to children of + * the child. + * + * @param {number} [index=this.children_.length] + * The index to attempt to add a child into. + * + * @return {Component} + * The `Component` that gets added as a child. When using a string the + * `Component` will get created by this process. + */ + ; + + _proto.addChild = function addChild(child, options, index) { + if (options === void 0) { + options = {}; + } + + if (index === void 0) { + index = this.children_.length; + } + + var component; + var componentName; // If child is a string, create component with options + + if (typeof child === 'string') { + componentName = toTitleCase$1(child); + var componentClassName = options.componentClass || componentName; // Set name through options + + options.name = componentName; // Create a new object & element for this controls set + // If there's no .player_, this is a player + + var ComponentClass = Component.getComponent(componentClassName); + + if (!ComponentClass) { + throw new Error("Component " + componentClassName + " does not exist"); + } // data stored directly on the videojs object may be + // misidentified as a component to retain + // backwards-compatibility with 4.x. check to make sure the + // component class can be instantiated. + + + if (typeof ComponentClass !== 'function') { + return null; + } + + component = new ComponentClass(this.player_ || this, options); // child is a component instance + } else { + component = child; + } + + if (component.parentComponent_) { + component.parentComponent_.removeChild(component); + } + + this.children_.splice(index, 0, component); + component.parentComponent_ = this; + + if (typeof component.id === 'function') { + this.childIndex_[component.id()] = component; + } // If a name wasn't used to create the component, check if we can use the + // name function of the component + + + componentName = componentName || component.name && toTitleCase$1(component.name()); + + if (componentName) { + this.childNameIndex_[componentName] = component; + this.childNameIndex_[toLowerCase(componentName)] = component; + } // Add the UI object's element to the container div (box) + // Having an element is not required + + + if (typeof component.el === 'function' && component.el()) { + // If inserting before a component, insert before that component's element + var refNode = null; + + if (this.children_[index + 1]) { + // Most children are components, but the video tech is an HTML element + if (this.children_[index + 1].el_) { + refNode = this.children_[index + 1].el_; + } else if (isEl(this.children_[index + 1])) { + refNode = this.children_[index + 1]; + } + } + + this.contentEl().insertBefore(component.el(), refNode); + } // Return so it can stored on parent object if desired. + + + return component; + } + /** + * Remove a child `Component` from this `Component`s list of children. Also removes + * the child `Component`s element from this `Component`s element. + * + * @param {Component} component + * The child `Component` to remove. + */ + ; + + _proto.removeChild = function removeChild(component) { + if (typeof component === 'string') { + component = this.getChild(component); + } + + if (!component || !this.children_) { + return; + } + + var childFound = false; + + for (var i = this.children_.length - 1; i >= 0; i--) { + if (this.children_[i] === component) { + childFound = true; + this.children_.splice(i, 1); + break; + } + } + + if (!childFound) { + return; + } + + component.parentComponent_ = null; + this.childIndex_[component.id()] = null; + this.childNameIndex_[toTitleCase$1(component.name())] = null; + this.childNameIndex_[toLowerCase(component.name())] = null; + var compEl = component.el(); + + if (compEl && compEl.parentNode === this.contentEl()) { + this.contentEl().removeChild(component.el()); + } + } + /** + * Add and initialize default child `Component`s based upon options. + */ + ; + + _proto.initChildren = function initChildren() { + var _this = this; + + var children = this.options_.children; + + if (children) { + // `this` is `parent` + var parentOptions = this.options_; + + var handleAdd = function handleAdd(child) { + var name = child.name; + var opts = child.opts; // Allow options for children to be set at the parent options + // e.g. videojs(id, { controlBar: false }); + // instead of videojs(id, { children: { controlBar: false }); + + if (parentOptions[name] !== undefined) { + opts = parentOptions[name]; + } // Allow for disabling default components + // e.g. options['children']['posterImage'] = false + + + if (opts === false) { + return; + } // Allow options to be passed as a simple boolean if no configuration + // is necessary. + + + if (opts === true) { + opts = {}; + } // We also want to pass the original player options + // to each component as well so they don't need to + // reach back into the player for options later. + + + opts.playerOptions = _this.options_.playerOptions; // Create and add the child component. + // Add a direct reference to the child by name on the parent instance. + // If two of the same component are used, different names should be supplied + // for each + + var newChild = _this.addChild(name, opts); + + if (newChild) { + _this[name] = newChild; + } + }; // Allow for an array of children details to passed in the options + + + var workingChildren; + var Tech = Component.getComponent('Tech'); + + if (Array.isArray(children)) { + workingChildren = children; + } else { + workingChildren = Object.keys(children); + } + + workingChildren // children that are in this.options_ but also in workingChildren would + // give us extra children we do not want. So, we want to filter them out. + .concat(Object.keys(this.options_).filter(function (child) { + return !workingChildren.some(function (wchild) { + if (typeof wchild === 'string') { + return child === wchild; + } + + return child === wchild.name; + }); + })).map(function (child) { + var name; + var opts; + + if (typeof child === 'string') { + name = child; + opts = children[name] || _this.options_[name] || {}; + } else { + name = child.name; + opts = child; + } + + return { + name: name, + opts: opts + }; + }).filter(function (child) { + // we have to make sure that child.name isn't in the techOrder since + // techs are registerd as Components but can't aren't compatible + // See https://github.com/videojs/video.js/issues/2772 + var c = Component.getComponent(child.opts.componentClass || toTitleCase$1(child.name)); + return c && !Tech.isTech(c); + }).forEach(handleAdd); + } + } + /** + * Builds the default DOM class name. Should be overriden by sub-components. + * + * @return {string} + * The DOM class name for this object. + * + * @abstract + */ + ; + + _proto.buildCSSClass = function buildCSSClass() { + // Child classes can include a function that does: + // return 'CLASS NAME' + this._super(); + return ''; + } + /** + * Bind a listener to the component's ready state. + * Different from event listeners in that if the ready event has already happened + * it will trigger the function immediately. + * + * @return {Component} + * Returns itself; method can be chained. + */ + ; + + _proto.ready = function ready(fn, sync) { + if (sync === void 0) { + sync = false; + } + + if (!fn) { + return; + } + + if (!this.isReady_) { + this.readyQueue_ = this.readyQueue_ || []; + this.readyQueue_.push(fn); + return; + } + + if (sync) { + fn.call(this); + } else { + // Call the function asynchronously by default for consistency + this.setTimeout(fn, 1); + } + } + /** + * Trigger all the ready listeners for this `Component`. + * + * @fires Component#ready + */ + ; + + _proto.triggerReady = function triggerReady() { + this.isReady_ = true; // Ensure ready is triggered asynchronously + + this.setTimeout(function () { + var readyQueue = this.readyQueue_; // Reset Ready Queue + + this.readyQueue_ = []; + + if (readyQueue && readyQueue.length > 0) { + readyQueue.forEach(function (fn) { + fn.call(this); + }, this); + } // Allow for using event listeners also + + /** + * Triggered when a `Component` is ready. + * + * @event Component#ready + * @type {EventTarget~Event} + */ + + + this.trigger('ready'); + }, 1); + } + /** + * Find a single DOM element matching a `selector`. This can be within the `Component`s + * `contentEl()` or another custom context. + * + * @param {string} selector + * A valid CSS selector, which will be passed to `querySelector`. + * + * @param {Element|string} [context=this.contentEl()] + * A DOM element within which to query. Can also be a selector string in + * which case the first matching element will get used as context. If + * missing `this.contentEl()` gets used. If `this.contentEl()` returns + * nothing it falls back to `document`. + * + * @return {Element|null} + * the dom element that was found, or null + * + * @see [Information on CSS Selectors](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_Started/Selectors) + */ + ; + + _proto.$ = function $$1(selector, context) { + return $(selector, context || this.contentEl()); + } + /** + * Finds all DOM element matching a `selector`. This can be within the `Component`s + * `contentEl()` or another custom context. + * + * @param {string} selector + * A valid CSS selector, which will be passed to `querySelectorAll`. + * + * @param {Element|string} [context=this.contentEl()] + * A DOM element within which to query. Can also be a selector string in + * which case the first matching element will get used as context. If + * missing `this.contentEl()` gets used. If `this.contentEl()` returns + * nothing it falls back to `document`. + * + * @return {NodeList} + * a list of dom elements that were found + * + * @see [Information on CSS Selectors](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_Started/Selectors) + */ + ; + + _proto.$$ = function $$$1(selector, context) { + return $$(selector, context || this.contentEl()); + } + /** + * Check if a component's element has a CSS class name. + * + * @param {string} classToCheck + * CSS class name to check. + * + * @return {boolean} + * - True if the `Component` has the class. + * - False if the `Component` does not have the class` + */ + ; + + _proto.hasClass = function hasClass$1(classToCheck) { + return hasClass(this.el_, classToCheck); + } + /** + * Add a CSS class name to the `Component`s element. + * + * @param {string} classToAdd + * CSS class name to add + */ + ; + + _proto.addClass = function addClass$1(classToAdd) { + addClass(this.el_, classToAdd); + } + /** + * Remove a CSS class name from the `Component`s element. + * + * @param {string} classToRemove + * CSS class name to remove + */ + ; + + _proto.removeClass = function removeClass$1(classToRemove) { + removeClass(this.el_, classToRemove); + } + /** + * Add or remove a CSS class name from the component's element. + * - `classToToggle` gets added when {@link Component#hasClass} would return false. + * - `classToToggle` gets removed when {@link Component#hasClass} would return true. + * + * @param {string} classToToggle + * The class to add or remove based on (@link Component#hasClass} + * + * @param {boolean|Dom~predicate} [predicate] + * An {@link Dom~predicate} function or a boolean + */ + ; + + _proto.toggleClass = function toggleClass$1(classToToggle, predicate) { + toggleClass(this.el_, classToToggle, predicate); + } + /** + * Show the `Component`s element if it is hidden by removing the + * 'vjs-hidden' class name from it. + */ + ; + + _proto.show = function show() { + this.removeClass('vjs-hidden'); + } + /** + * Hide the `Component`s element if it is currently showing by adding the + * 'vjs-hidden` class name to it. + */ + ; + + _proto.hide = function hide() { + this.addClass('vjs-hidden'); + } + /** + * Lock a `Component`s element in its visible state by adding the 'vjs-lock-showing' + * class name to it. Used during fadeIn/fadeOut. + * + * @private + */ + ; + + _proto.lockShowing = function lockShowing() { + this.addClass('vjs-lock-showing'); + } + /** + * Unlock a `Component`s element from its visible state by removing the 'vjs-lock-showing' + * class name from it. Used during fadeIn/fadeOut. + * + * @private + */ + ; + + _proto.unlockShowing = function unlockShowing() { + this.removeClass('vjs-lock-showing'); + } + /** + * Get the value of an attribute on the `Component`s element. + * + * @param {string} attribute + * Name of the attribute to get the value from. + * + * @return {string|null} + * - The value of the attribute that was asked for. + * - Can be an empty string on some browsers if the attribute does not exist + * or has no value + * - Most browsers will return null if the attibute does not exist or has + * no value. + * + * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute} + */ + ; + + _proto.getAttribute = function getAttribute$1(attribute) { + return getAttribute(this.el_, attribute); + } + /** + * Set the value of an attribute on the `Component`'s element + * + * @param {string} attribute + * Name of the attribute to set. + * + * @param {string} value + * Value to set the attribute to. + * + * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute} + */ + ; + + _proto.setAttribute = function setAttribute$1(attribute, value) { + setAttribute(this.el_, attribute, value); + } + /** + * Remove an attribute from the `Component`s element. + * + * @param {string} attribute + * Name of the attribute to remove. + * + * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute} + */ + ; + + _proto.removeAttribute = function removeAttribute$1(attribute) { + removeAttribute(this.el_, attribute); + } + /** + * Get or set the width of the component based upon the CSS styles. + * See {@link Component#dimension} for more detailed information. + * + * @param {number|string} [num] + * The width that you want to set postfixed with '%', 'px' or nothing. + * + * @param {boolean} [skipListeners] + * Skip the componentresize event trigger + * + * @return {number|string} + * The width when getting, zero if there is no width. Can be a string + * postpixed with '%' or 'px'. + */ + ; + + _proto.width = function width(num, skipListeners) { + return this.dimension('width', num, skipListeners); + } + /** + * Get or set the height of the component based upon the CSS styles. + * See {@link Component#dimension} for more detailed information. + * + * @param {number|string} [num] + * The height that you want to set postfixed with '%', 'px' or nothing. + * + * @param {boolean} [skipListeners] + * Skip the componentresize event trigger + * + * @return {number|string} + * The width when getting, zero if there is no width. Can be a string + * postpixed with '%' or 'px'. + */ + ; + + _proto.height = function height(num, skipListeners) { + return this.dimension('height', num, skipListeners); + } + /** + * Set both the width and height of the `Component` element at the same time. + * + * @param {number|string} width + * Width to set the `Component`s element to. + * + * @param {number|string} height + * Height to set the `Component`s element to. + */ + ; + + _proto.dimensions = function dimensions(width, height) { + // Skip componentresize listeners on width for optimization + this.width(width, true); + this.height(height); + } + /** + * Get or set width or height of the `Component` element. This is the shared code + * for the {@link Component#width} and {@link Component#height}. + * + * Things to know: + * - If the width or height in an number this will return the number postfixed with 'px'. + * - If the width/height is a percent this will return the percent postfixed with '%' + * - Hidden elements have a width of 0 with `window.getComputedStyle`. This function + * defaults to the `Component`s `style.width` and falls back to `window.getComputedStyle`. + * See [this]{@link http://www.foliotek.com/devblog/getting-the-width-of-a-hidden-element-with-jquery-using-width/} + * for more information + * - If you want the computed style of the component, use {@link Component#currentWidth} + * and {@link {Component#currentHeight} + * + * @fires Component#componentresize + * + * @param {string} widthOrHeight + 8 'width' or 'height' + * + * @param {number|string} [num] + 8 New dimension + * + * @param {boolean} [skipListeners] + * Skip componentresize event trigger + * + * @return {number} + * The dimension when getting or 0 if unset + */ + ; + + _proto.dimension = function dimension(widthOrHeight, num, skipListeners) { + if (num !== undefined) { + // Set to zero if null or literally NaN (NaN !== NaN) + if (num === null || num !== num) { + num = 0; + } // Check if using css width/height (% or px) and adjust + + + if (('' + num).indexOf('%') !== -1 || ('' + num).indexOf('px') !== -1) { + this.el_.style[widthOrHeight] = num; + } else if (num === 'auto') { + this.el_.style[widthOrHeight] = ''; + } else { + this.el_.style[widthOrHeight] = num + 'px'; + } // skipListeners allows us to avoid triggering the resize event when setting both width and height + + + if (!skipListeners) { + /** + * Triggered when a component is resized. + * + * @event Component#componentresize + * @type {EventTarget~Event} + */ + this.trigger('componentresize'); + } + + return; + } // Not setting a value, so getting it + // Make sure element exists + + + if (!this.el_) { + return 0; + } // Get dimension value from style + + + var val = this.el_.style[widthOrHeight]; + var pxIndex = val.indexOf('px'); + + if (pxIndex !== -1) { + // Return the pixel value with no 'px' + return parseInt(val.slice(0, pxIndex), 10); + } // No px so using % or no style was set, so falling back to offsetWidth/height + // If component has display:none, offset will return 0 + // TODO: handle display:none and no dimension style using px + + + return parseInt(this.el_['offset' + toTitleCase$1(widthOrHeight)], 10); + } + /** + * Get the computed width or the height of the component's element. + * + * Uses `window.getComputedStyle`. + * + * @param {string} widthOrHeight + * A string containing 'width' or 'height'. Whichever one you want to get. + * + * @return {number} + * The dimension that gets asked for or 0 if nothing was set + * for that dimension. + */ + ; + + _proto.currentDimension = function currentDimension(widthOrHeight) { + var computedWidthOrHeight = 0; + + if (widthOrHeight !== 'width' && widthOrHeight !== 'height') { + throw new Error('currentDimension only accepts width or height value'); + } + + computedWidthOrHeight = computedStyle(this.el_, widthOrHeight); // remove 'px' from variable and parse as integer + + computedWidthOrHeight = parseFloat(computedWidthOrHeight); // if the computed value is still 0, it's possible that the browser is lying + // and we want to check the offset values. + // This code also runs wherever getComputedStyle doesn't exist. + + if (computedWidthOrHeight === 0 || isNaN(computedWidthOrHeight)) { + var rule = "offset" + toTitleCase$1(widthOrHeight); + computedWidthOrHeight = this.el_[rule]; + } + + return computedWidthOrHeight; + } + /** + * An object that contains width and height values of the `Component`s + * computed style. Uses `window.getComputedStyle`. + * + * @typedef {Object} Component~DimensionObject + * + * @property {number} width + * The width of the `Component`s computed style. + * + * @property {number} height + * The height of the `Component`s computed style. + */ + + /** + * Get an object that contains computed width and height values of the + * component's element. + * + * Uses `window.getComputedStyle`. + * + * @return {Component~DimensionObject} + * The computed dimensions of the component's element. + */ + ; + + _proto.currentDimensions = function currentDimensions() { + return { + width: this.currentDimension('width'), + height: this.currentDimension('height') + }; + } + /** + * Get the computed width of the component's element. + * + * Uses `window.getComputedStyle`. + * + * @return {number} + * The computed width of the component's element. + */ + ; + + _proto.currentWidth = function currentWidth() { + return this.currentDimension('width'); + } + /** + * Get the computed height of the component's element. + * + * Uses `window.getComputedStyle`. + * + * @return {number} + * The computed height of the component's element. + */ + ; + + _proto.currentHeight = function currentHeight() { + return this.currentDimension('height'); + } + /** + * Set the focus to this component + */ + ; + + _proto.focus = function focus() { + this.el_.focus(); + } + /** + * Remove the focus from this component + */ + ; + + _proto.blur = function blur() { + this.el_.blur(); + } + /** + * When this Component receives a `keydown` event which it does not process, + * it passes the event to the Player for handling. + * + * @param {EventTarget~Event} event + * The `keydown` event that caused this function to be called. + */ + ; + + _proto.handleKeyDown = function handleKeyDown(event) { + if (this.player_) { + // We only stop propagation here because we want unhandled events to fall + // back to the browser. + event.stopPropagation(); + this.player_.handleKeyDown(event); + } + } + /** + * Many components used to have a `handleKeyPress` method, which was poorly + * named because it listened to a `keydown` event. This method name now + * delegates to `handleKeyDown`. This means anyone calling `handleKeyPress` + * will not see their method calls stop working. + * + * @param {EventTarget~Event} event + * The event that caused this function to be called. + */ + ; + + _proto.handleKeyPress = function handleKeyPress(event) { + this.handleKeyDown(event); + } + /** + * Emit a 'tap' events when touch event support gets detected. This gets used to + * support toggling the controls through a tap on the video. They get enabled + * because every sub-component would have extra overhead otherwise. + * + * @private + * @fires Component#tap + * @listens Component#touchstart + * @listens Component#touchmove + * @listens Component#touchleave + * @listens Component#touchcancel + * @listens Component#touchend + */ + ; + + _proto.emitTapEvents = function emitTapEvents() { + // Track the start time so we can determine how long the touch lasted + var touchStart = 0; + var firstTouch = null; // Maximum movement allowed during a touch event to still be considered a tap + // Other popular libs use anywhere from 2 (hammer.js) to 15, + // so 10 seems like a nice, round number. + + var tapMovementThreshold = 10; // The maximum length a touch can be while still being considered a tap + + var touchTimeThreshold = 200; + var couldBeTap; + this.on('touchstart', function (event) { + // If more than one finger, don't consider treating this as a click + if (event.touches.length === 1) { + // Copy pageX/pageY from the object + firstTouch = { + pageX: event.touches[0].pageX, + pageY: event.touches[0].pageY + }; // Record start time so we can detect a tap vs. "touch and hold" + + touchStart = global_window__WEBPACK_IMPORTED_MODULE_0___default().performance.now(); // Reset couldBeTap tracking + + couldBeTap = true; + } + }); + this.on('touchmove', function (event) { + // If more than one finger, don't consider treating this as a click + if (event.touches.length > 1) { + couldBeTap = false; + } else if (firstTouch) { + // Some devices will throw touchmoves for all but the slightest of taps. + // So, if we moved only a small distance, this could still be a tap + var xdiff = event.touches[0].pageX - firstTouch.pageX; + var ydiff = event.touches[0].pageY - firstTouch.pageY; + var touchDistance = Math.sqrt(xdiff * xdiff + ydiff * ydiff); + + if (touchDistance > tapMovementThreshold) { + couldBeTap = false; + } + } + }); + + var noTap = function noTap() { + couldBeTap = false; + }; // TODO: Listen to the original target. http://youtu.be/DujfpXOKUp8?t=13m8s + + + this.on('touchleave', noTap); + this.on('touchcancel', noTap); // When the touch ends, measure how long it took and trigger the appropriate + // event + + this.on('touchend', function (event) { + firstTouch = null; // Proceed only if the touchmove/leave/cancel event didn't happen + + if (couldBeTap === true) { + // Measure how long the touch lasted + var touchTime = global_window__WEBPACK_IMPORTED_MODULE_0___default().performance.now() - touchStart; // Make sure the touch was less than the threshold to be considered a tap + + if (touchTime < touchTimeThreshold) { + // Don't let browser turn this into a click + event.preventDefault(); + /** + * Triggered when a `Component` is tapped. + * + * @event Component#tap + * @type {EventTarget~Event} + */ + + this.trigger('tap'); // It may be good to copy the touchend event object and change the + // type to tap, if the other event properties aren't exact after + // Events.fixEvent runs (e.g. event.target) + } + } + }); + } + /** + * This function reports user activity whenever touch events happen. This can get + * turned off by any sub-components that wants touch events to act another way. + * + * Report user touch activity when touch events occur. User activity gets used to + * determine when controls should show/hide. It is simple when it comes to mouse + * events, because any mouse event should show the controls. So we capture mouse + * events that bubble up to the player and report activity when that happens. + * With touch events it isn't as easy as `touchstart` and `touchend` toggle player + * controls. So touch events can't help us at the player level either. + * + * User activity gets checked asynchronously. So what could happen is a tap event + * on the video turns the controls off. Then the `touchend` event bubbles up to + * the player. Which, if it reported user activity, would turn the controls right + * back on. We also don't want to completely block touch events from bubbling up. + * Furthermore a `touchmove` event and anything other than a tap, should not turn + * controls back on. + * + * @listens Component#touchstart + * @listens Component#touchmove + * @listens Component#touchend + * @listens Component#touchcancel + */ + ; + + _proto.enableTouchActivity = function enableTouchActivity() { + // Don't continue if the root player doesn't support reporting user activity + if (!this.player() || !this.player().reportUserActivity) { + return; + } // listener for reporting that the user is active + + + var report = bind(this.player(), this.player().reportUserActivity); + var touchHolding; + this.on('touchstart', function () { + report(); // For as long as the they are touching the device or have their mouse down, + // we consider them active even if they're not moving their finger or mouse. + // So we want to continue to update that they are active + + this.clearInterval(touchHolding); // report at the same interval as activityCheck + + touchHolding = this.setInterval(report, 250); + }); + + var touchEnd = function touchEnd(event) { + report(); // stop the interval that maintains activity if the touch is holding + + this.clearInterval(touchHolding); + }; + + this.on('touchmove', report); + this.on('touchend', touchEnd); + this.on('touchcancel', touchEnd); + } + /** + * A callback that has no parameters and is bound into `Component`s context. + * + * @callback Component~GenericCallback + * @this Component + */ + + /** + * Creates a function that runs after an `x` millisecond timeout. This function is a + * wrapper around `window.setTimeout`. There are a few reasons to use this one + * instead though: + * 1. It gets cleared via {@link Component#clearTimeout} when + * {@link Component#dispose} gets called. + * 2. The function callback will gets turned into a {@link Component~GenericCallback} + * + * > Note: You can't use `window.clearTimeout` on the id returned by this function. This + * will cause its dispose listener not to get cleaned up! Please use + * {@link Component#clearTimeout} or {@link Component#dispose} instead. + * + * @param {Component~GenericCallback} fn + * The function that will be run after `timeout`. + * + * @param {number} timeout + * Timeout in milliseconds to delay before executing the specified function. + * + * @return {number} + * Returns a timeout ID that gets used to identify the timeout. It can also + * get used in {@link Component#clearTimeout} to clear the timeout that + * was set. + * + * @listens Component#dispose + * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout} + */ + ; + + _proto.setTimeout = function setTimeout(fn, timeout) { + var _this2 = this; + + // declare as variables so they are properly available in timeout function + // eslint-disable-next-line + var timeoutId; + fn = bind(this, fn); + this.clearTimersOnDispose_(); + timeoutId = global_window__WEBPACK_IMPORTED_MODULE_0___default().setTimeout(function () { + if (_this2.setTimeoutIds_.has(timeoutId)) { + _this2.setTimeoutIds_["delete"](timeoutId); + } + + fn(); + }, timeout); + this.setTimeoutIds_.add(timeoutId); + return timeoutId; + } + /** + * Clears a timeout that gets created via `window.setTimeout` or + * {@link Component#setTimeout}. If you set a timeout via {@link Component#setTimeout} + * use this function instead of `window.clearTimout`. If you don't your dispose + * listener will not get cleaned up until {@link Component#dispose}! + * + * @param {number} timeoutId + * The id of the timeout to clear. The return value of + * {@link Component#setTimeout} or `window.setTimeout`. + * + * @return {number} + * Returns the timeout id that was cleared. + * + * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearTimeout} + */ + ; + + _proto.clearTimeout = function clearTimeout(timeoutId) { + if (this.setTimeoutIds_.has(timeoutId)) { + this.setTimeoutIds_["delete"](timeoutId); + global_window__WEBPACK_IMPORTED_MODULE_0___default().clearTimeout(timeoutId); + } + + return timeoutId; + } + /** + * Creates a function that gets run every `x` milliseconds. This function is a wrapper + * around `window.setInterval`. There are a few reasons to use this one instead though. + * 1. It gets cleared via {@link Component#clearInterval} when + * {@link Component#dispose} gets called. + * 2. The function callback will be a {@link Component~GenericCallback} + * + * @param {Component~GenericCallback} fn + * The function to run every `x` seconds. + * + * @param {number} interval + * Execute the specified function every `x` milliseconds. + * + * @return {number} + * Returns an id that can be used to identify the interval. It can also be be used in + * {@link Component#clearInterval} to clear the interval. + * + * @listens Component#dispose + * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval} + */ + ; + + _proto.setInterval = function setInterval(fn, interval) { + fn = bind(this, fn); + this.clearTimersOnDispose_(); + var intervalId = global_window__WEBPACK_IMPORTED_MODULE_0___default().setInterval(fn, interval); + this.setIntervalIds_.add(intervalId); + return intervalId; + } + /** + * Clears an interval that gets created via `window.setInterval` or + * {@link Component#setInterval}. If you set an inteval via {@link Component#setInterval} + * use this function instead of `window.clearInterval`. If you don't your dispose + * listener will not get cleaned up until {@link Component#dispose}! + * + * @param {number} intervalId + * The id of the interval to clear. The return value of + * {@link Component#setInterval} or `window.setInterval`. + * + * @return {number} + * Returns the interval id that was cleared. + * + * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearInterval} + */ + ; + + _proto.clearInterval = function clearInterval(intervalId) { + if (this.setIntervalIds_.has(intervalId)) { + this.setIntervalIds_["delete"](intervalId); + global_window__WEBPACK_IMPORTED_MODULE_0___default().clearInterval(intervalId); + } + + return intervalId; + } + /** + * Queues up a callback to be passed to requestAnimationFrame (rAF), but + * with a few extra bonuses: + * + * - Supports browsers that do not support rAF by falling back to + * {@link Component#setTimeout}. + * + * - The callback is turned into a {@link Component~GenericCallback} (i.e. + * bound to the component). + * + * - Automatic cancellation of the rAF callback is handled if the component + * is disposed before it is called. + * + * @param {Component~GenericCallback} fn + * A function that will be bound to this component and executed just + * before the browser's next repaint. + * + * @return {number} + * Returns an rAF ID that gets used to identify the timeout. It can + * also be used in {@link Component#cancelAnimationFrame} to cancel + * the animation frame callback. + * + * @listens Component#dispose + * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame} + */ + ; + + _proto.requestAnimationFrame = function requestAnimationFrame(fn) { + var _this3 = this; + + // Fall back to using a timer. + if (!this.supportsRaf_) { + return this.setTimeout(fn, 1000 / 60); + } + + this.clearTimersOnDispose_(); // declare as variables so they are properly available in rAF function + // eslint-disable-next-line + + var id; + fn = bind(this, fn); + id = global_window__WEBPACK_IMPORTED_MODULE_0___default().requestAnimationFrame(function () { + if (_this3.rafIds_.has(id)) { + _this3.rafIds_["delete"](id); + } + + fn(); + }); + this.rafIds_.add(id); + return id; + } + /** + * Request an animation frame, but only one named animation + * frame will be queued. Another will never be added until + * the previous one finishes. + * + * @param {string} name + * The name to give this requestAnimationFrame + * + * @param {Component~GenericCallback} fn + * A function that will be bound to this component and executed just + * before the browser's next repaint. + */ + ; + + _proto.requestNamedAnimationFrame = function requestNamedAnimationFrame(name, fn) { + var _this4 = this; + + if (this.namedRafs_.has(name)) { + return; + } + + this.clearTimersOnDispose_(); + fn = bind(this, fn); + var id = this.requestAnimationFrame(function () { + fn(); + + if (_this4.namedRafs_.has(name)) { + _this4.namedRafs_["delete"](name); + } + }); + this.namedRafs_.set(name, id); + return name; + } + /** + * Cancels a current named animation frame if it exists. + * + * @param {string} name + * The name of the requestAnimationFrame to cancel. + */ + ; + + _proto.cancelNamedAnimationFrame = function cancelNamedAnimationFrame(name) { + if (!this.namedRafs_.has(name)) { + return; + } + + this.cancelAnimationFrame(this.namedRafs_.get(name)); + this.namedRafs_["delete"](name); + } + /** + * Cancels a queued callback passed to {@link Component#requestAnimationFrame} + * (rAF). + * + * If you queue an rAF callback via {@link Component#requestAnimationFrame}, + * use this function instead of `window.cancelAnimationFrame`. If you don't, + * your dispose listener will not get cleaned up until {@link Component#dispose}! + * + * @param {number} id + * The rAF ID to clear. The return value of {@link Component#requestAnimationFrame}. + * + * @return {number} + * Returns the rAF ID that was cleared. + * + * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/window/cancelAnimationFrame} + */ + ; + + _proto.cancelAnimationFrame = function cancelAnimationFrame(id) { + // Fall back to using a timer. + if (!this.supportsRaf_) { + return this.clearTimeout(id); + } + + if (this.rafIds_.has(id)) { + this.rafIds_["delete"](id); + global_window__WEBPACK_IMPORTED_MODULE_0___default().cancelAnimationFrame(id); + } + + return id; + } + /** + * A function to setup `requestAnimationFrame`, `setTimeout`, + * and `setInterval`, clearing on dispose. + * + * > Previously each timer added and removed dispose listeners on it's own. + * For better performance it was decided to batch them all, and use `Set`s + * to track outstanding timer ids. + * + * @private + */ + ; + + _proto.clearTimersOnDispose_ = function clearTimersOnDispose_() { + var _this5 = this; + + if (this.clearingTimersOnDispose_) { + return; + } + + this.clearingTimersOnDispose_ = true; + this.one('dispose', function () { + [['namedRafs_', 'cancelNamedAnimationFrame'], ['rafIds_', 'cancelAnimationFrame'], ['setTimeoutIds_', 'clearTimeout'], ['setIntervalIds_', 'clearInterval']].forEach(function (_ref) { + var idName = _ref[0], + cancelName = _ref[1]; + + // for a `Set` key will actually be the value again + // so forEach((val, val) =>` but for maps we want to use + // the key. + _this5[idName].forEach(function (val, key) { + return _this5[cancelName](key); + }); + }); + _this5.clearingTimersOnDispose_ = false; + }); + } + /** + * Register a `Component` with `videojs` given the name and the component. + * + * > NOTE: {@link Tech}s should not be registered as a `Component`. {@link Tech}s + * should be registered using {@link Tech.registerTech} or + * {@link videojs:videojs.registerTech}. + * + * > NOTE: This function can also be seen on videojs as + * {@link videojs:videojs.registerComponent}. + * + * @param {string} name + * The name of the `Component` to register. + * + * @param {Component} ComponentToRegister + * The `Component` class to register. + * + * @return {Component} + * The `Component` that was registered. + */ + ; + + Component.registerComponent = function registerComponent(name, ComponentToRegister) { + if (typeof name !== 'string' || !name) { + throw new Error("Illegal component name, \"" + name + "\"; must be a non-empty string."); + } + + var Tech = Component.getComponent('Tech'); // We need to make sure this check is only done if Tech has been registered. + + var isTech = Tech && Tech.isTech(ComponentToRegister); + var isComp = Component === ComponentToRegister || Component.prototype.isPrototypeOf(ComponentToRegister.prototype); + + if (isTech || !isComp) { + var reason; + + if (isTech) { + reason = 'techs must be registered using Tech.registerTech()'; + } else { + reason = 'must be a Component subclass'; + } + + throw new Error("Illegal component, \"" + name + "\"; " + reason + "."); + } + + name = toTitleCase$1(name); + + if (!Component.components_) { + Component.components_ = {}; + } + + var Player = Component.getComponent('Player'); + + if (name === 'Player' && Player && Player.players) { + var players = Player.players; + var playerNames = Object.keys(players); // If we have players that were disposed, then their name will still be + // in Players.players. So, we must loop through and verify that the value + // for each item is not null. This allows registration of the Player component + // after all players have been disposed or before any were created. + + if (players && playerNames.length > 0 && playerNames.map(function (pname) { + return players[pname]; + }).every(Boolean)) { + throw new Error('Can not register Player component after player has been created.'); + } + } + + Component.components_[name] = ComponentToRegister; + Component.components_[toLowerCase(name)] = ComponentToRegister; + return ComponentToRegister; + } + /** + * Get a `Component` based on the name it was registered with. + * + * @param {string} name + * The Name of the component to get. + * + * @return {Component} + * The `Component` that got registered under the given name. + */ + ; + + Component.getComponent = function getComponent(name) { + if (!name || !Component.components_) { + return; + } + + return Component.components_[name]; + }; + + return Component; +}(); +/** + * Whether or not this component supports `requestAnimationFrame`. + * + * This is exposed primarily for testing purposes. + * + * @private + * @type {Boolean} + */ + + +Component$1.prototype.supportsRaf_ = typeof (global_window__WEBPACK_IMPORTED_MODULE_0___default().requestAnimationFrame) === 'function' && typeof (global_window__WEBPACK_IMPORTED_MODULE_0___default().cancelAnimationFrame) === 'function'; +Component$1.registerComponent('Component', Component$1); + +/** + * @file time-ranges.js + * @module time-ranges + */ +/** + * Returns the time for the specified index at the start or end + * of a TimeRange object. + * + * @typedef {Function} TimeRangeIndex + * + * @param {number} [index=0] + * The range number to return the time for. + * + * @return {number} + * The time offset at the specified index. + * + * @deprecated The index argument must be provided. + * In the future, leaving it out will throw an error. + */ + +/** + * An object that contains ranges of time. + * + * @typedef {Object} TimeRange + * + * @property {number} length + * The number of time ranges represented by this object. + * + * @property {module:time-ranges~TimeRangeIndex} start + * Returns the time offset at which a specified time range begins. + * + * @property {module:time-ranges~TimeRangeIndex} end + * Returns the time offset at which a specified time range ends. + * + * @see https://developer.mozilla.org/en-US/docs/Web/API/TimeRanges + */ + +/** + * Check if any of the time ranges are over the maximum index. + * + * @private + * @param {string} fnName + * The function name to use for logging + * + * @param {number} index + * The index to check + * + * @param {number} maxIndex + * The maximum possible index + * + * @throws {Error} if the timeRanges provided are over the maxIndex + */ + +function rangeCheck(fnName, index, maxIndex) { + if (typeof index !== 'number' || index < 0 || index > maxIndex) { + throw new Error("Failed to execute '" + fnName + "' on 'TimeRanges': The index provided (" + index + ") is non-numeric or out of bounds (0-" + maxIndex + ")."); + } +} +/** + * Get the time for the specified index at the start or end + * of a TimeRange object. + * + * @private + * @param {string} fnName + * The function name to use for logging + * + * @param {string} valueIndex + * The property that should be used to get the time. should be + * 'start' or 'end' + * + * @param {Array} ranges + * An array of time ranges + * + * @param {Array} [rangeIndex=0] + * The index to start the search at + * + * @return {number} + * The time that offset at the specified index. + * + * @deprecated rangeIndex must be set to a value, in the future this will throw an error. + * @throws {Error} if rangeIndex is more than the length of ranges + */ + + +function getRange(fnName, valueIndex, ranges, rangeIndex) { + rangeCheck(fnName, rangeIndex, ranges.length - 1); + return ranges[rangeIndex][valueIndex]; +} +/** + * Create a time range object given ranges of time. + * + * @private + * @param {Array} [ranges] + * An array of time ranges. + */ + + +function createTimeRangesObj(ranges) { + var timeRangesObj; + + if (ranges === undefined || ranges.length === 0) { + timeRangesObj = { + length: 0, + start: function start() { + throw new Error('This TimeRanges object is empty'); + }, + end: function end() { + throw new Error('This TimeRanges object is empty'); + } + }; + } else { + timeRangesObj = { + length: ranges.length, + start: getRange.bind(null, 'start', 0, ranges), + end: getRange.bind(null, 'end', 1, ranges) + }; + } + + if ((global_window__WEBPACK_IMPORTED_MODULE_0___default().Symbol) && (global_window__WEBPACK_IMPORTED_MODULE_0___default().Symbol.iterator)) { + timeRangesObj[(global_window__WEBPACK_IMPORTED_MODULE_0___default().Symbol.iterator)] = function () { + return (ranges || []).values(); + }; + } + + return timeRangesObj; +} +/** + * Create a `TimeRange` object which mimics an + * {@link https://developer.mozilla.org/en-US/docs/Web/API/TimeRanges|HTML5 TimeRanges instance}. + * + * @param {number|Array[]} start + * The start of a single range (a number) or an array of ranges (an + * array of arrays of two numbers each). + * + * @param {number} end + * The end of a single range. Cannot be used with the array form of + * the `start` argument. + */ + + +function createTimeRanges(start, end) { + if (Array.isArray(start)) { + return createTimeRangesObj(start); + } else if (start === undefined || end === undefined) { + return createTimeRangesObj(); + } + + return createTimeRangesObj([[start, end]]); +} + +/** + * @file buffer.js + * @module buffer + */ +/** + * Compute the percentage of the media that has been buffered. + * + * @param {TimeRange} buffered + * The current `TimeRange` object representing buffered time ranges + * + * @param {number} duration + * Total duration of the media + * + * @return {number} + * Percent buffered of the total duration in decimal form. + */ + +function bufferedPercent(buffered, duration) { + var bufferedDuration = 0; + var start; + var end; + + if (!duration) { + return 0; + } + + if (!buffered || !buffered.length) { + buffered = createTimeRanges(0, 0); + } + + for (var i = 0; i < buffered.length; i++) { + start = buffered.start(i); + end = buffered.end(i); // buffered end can be bigger than duration by a very small fraction + + if (end > duration) { + end = duration; + } + + bufferedDuration += end - start; + } + + return bufferedDuration / duration; +} + +/** + * @file media-error.js + */ +/** + * A Custom `MediaError` class which mimics the standard HTML5 `MediaError` class. + * + * @param {number|string|Object|MediaError} value + * This can be of multiple types: + * - number: should be a standard error code + * - string: an error message (the code will be 0) + * - Object: arbitrary properties + * - `MediaError` (native): used to populate a video.js `MediaError` object + * - `MediaError` (video.js): will return itself if it's already a + * video.js `MediaError` object. + * + * @see [MediaError Spec]{@link https://dev.w3.org/html5/spec-author-view/video.html#mediaerror} + * @see [Encrypted MediaError Spec]{@link https://www.w3.org/TR/2013/WD-encrypted-media-20130510/#error-codes} + * + * @class MediaError + */ + +function MediaError(value) { + // Allow redundant calls to this constructor to avoid having `instanceof` + // checks peppered around the code. + if (value instanceof MediaError) { + return value; + } + + if (typeof value === 'number') { + this.code = value; + } else if (typeof value === 'string') { + // default code is zero, so this is a custom error + this.message = value; + } else if (isObject(value)) { + // We assign the `code` property manually because native `MediaError` objects + // do not expose it as an own/enumerable property of the object. + if (typeof value.code === 'number') { + this.code = value.code; + } + + assign(this, value); + } + + if (!this.message) { + this.message = MediaError.defaultMessages[this.code] || ''; + } +} +/** + * The error code that refers two one of the defined `MediaError` types + * + * @type {Number} + */ + + +MediaError.prototype.code = 0; +/** + * An optional message that to show with the error. Message is not part of the HTML5 + * video spec but allows for more informative custom errors. + * + * @type {String} + */ + +MediaError.prototype.message = ''; +/** + * An optional status code that can be set by plugins to allow even more detail about + * the error. For example a plugin might provide a specific HTTP status code and an + * error message for that code. Then when the plugin gets that error this class will + * know how to display an error message for it. This allows a custom message to show + * up on the `Player` error overlay. + * + * @type {Array} + */ + +MediaError.prototype.status = null; +/** + * Errors indexed by the W3C standard. The order **CANNOT CHANGE**! See the + * specification listed under {@link MediaError} for more information. + * + * @enum {array} + * @readonly + * @property {string} 0 - MEDIA_ERR_CUSTOM + * @property {string} 1 - MEDIA_ERR_ABORTED + * @property {string} 2 - MEDIA_ERR_NETWORK + * @property {string} 3 - MEDIA_ERR_DECODE + * @property {string} 4 - MEDIA_ERR_SRC_NOT_SUPPORTED + * @property {string} 5 - MEDIA_ERR_ENCRYPTED + */ + +MediaError.errorTypes = ['MEDIA_ERR_CUSTOM', 'MEDIA_ERR_ABORTED', 'MEDIA_ERR_NETWORK', 'MEDIA_ERR_DECODE', 'MEDIA_ERR_SRC_NOT_SUPPORTED', 'MEDIA_ERR_ENCRYPTED']; +/** + * The default `MediaError` messages based on the {@link MediaError.errorTypes}. + * + * @type {Array} + * @constant + */ + +MediaError.defaultMessages = { + 1: 'You aborted the media playback', + 2: 'A network error caused the media download to fail part-way.', + 3: 'The media playback was aborted due to a corruption problem or because the media used features your browser did not support.', + 4: 'The media could not be loaded, either because the server or network failed or because the format is not supported.', + 5: 'The media is encrypted and we do not have the keys to decrypt it.' +}; // Add types as properties on MediaError +// e.g. MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = 4; + +for (var errNum = 0; errNum < MediaError.errorTypes.length; errNum++) { + MediaError[MediaError.errorTypes[errNum]] = errNum; // values should be accessible on both the class and instance + + MediaError.prototype[MediaError.errorTypes[errNum]] = errNum; +} // jsdocs for instance/static members added above + +/** + * Returns whether an object is `Promise`-like (i.e. has a `then` method). + * + * @param {Object} value + * An object that may or may not be `Promise`-like. + * + * @return {boolean} + * Whether or not the object is `Promise`-like. + */ +function isPromise(value) { + return value !== undefined && value !== null && typeof value.then === 'function'; +} +/** + * Silence a Promise-like object. + * + * This is useful for avoiding non-harmful, but potentially confusing "uncaught + * play promise" rejection error messages. + * + * @param {Object} value + * An object that may or may not be `Promise`-like. + */ + +function silencePromise(value) { + if (isPromise(value)) { + value.then(null, function (e) {}); + } +} + +/** + * @file text-track-list-converter.js Utilities for capturing text track state and + * re-creating tracks based on a capture. + * + * @module text-track-list-converter + */ + +/** + * Examine a single {@link TextTrack} and return a JSON-compatible javascript object that + * represents the {@link TextTrack}'s state. + * + * @param {TextTrack} track + * The text track to query. + * + * @return {Object} + * A serializable javascript representation of the TextTrack. + * @private + */ +var trackToJson_ = function trackToJson_(track) { + var ret = ['kind', 'label', 'language', 'id', 'inBandMetadataTrackDispatchType', 'mode', 'src'].reduce(function (acc, prop, i) { + if (track[prop]) { + acc[prop] = track[prop]; + } + + return acc; + }, { + cues: track.cues && Array.prototype.map.call(track.cues, function (cue) { + return { + startTime: cue.startTime, + endTime: cue.endTime, + text: cue.text, + id: cue.id + }; + }) + }); + return ret; +}; +/** + * Examine a {@link Tech} and return a JSON-compatible javascript array that represents the + * state of all {@link TextTrack}s currently configured. The return array is compatible with + * {@link text-track-list-converter:jsonToTextTracks}. + * + * @param {Tech} tech + * The tech object to query + * + * @return {Array} + * A serializable javascript representation of the {@link Tech}s + * {@link TextTrackList}. + */ + + +var textTracksToJson = function textTracksToJson(tech) { + var trackEls = tech.$$('track'); + var trackObjs = Array.prototype.map.call(trackEls, function (t) { + return t.track; + }); + var tracks = Array.prototype.map.call(trackEls, function (trackEl) { + var json = trackToJson_(trackEl.track); + + if (trackEl.src) { + json.src = trackEl.src; + } + + return json; + }); + return tracks.concat(Array.prototype.filter.call(tech.textTracks(), function (track) { + return trackObjs.indexOf(track) === -1; + }).map(trackToJson_)); +}; +/** + * Create a set of remote {@link TextTrack}s on a {@link Tech} based on an array of javascript + * object {@link TextTrack} representations. + * + * @param {Array} json + * An array of `TextTrack` representation objects, like those that would be + * produced by `textTracksToJson`. + * + * @param {Tech} tech + * The `Tech` to create the `TextTrack`s on. + */ + + +var jsonToTextTracks = function jsonToTextTracks(json, tech) { + json.forEach(function (track) { + var addedTrack = tech.addRemoteTextTrack(track).track; + + if (!track.src && track.cues) { + track.cues.forEach(function (cue) { + return addedTrack.addCue(cue); + }); + } + }); + return tech.textTracks(); +}; + +var textTrackConverter = { + textTracksToJson: textTracksToJson, + jsonToTextTracks: jsonToTextTracks, + trackToJson_: trackToJson_ +}; + +var MODAL_CLASS_NAME = 'vjs-modal-dialog'; +/** + * The `ModalDialog` displays over the video and its controls, which blocks + * interaction with the player until it is closed. + * + * Modal dialogs include a "Close" button and will close when that button + * is activated - or when ESC is pressed anywhere. + * + * @extends Component + */ + +var ModalDialog = /*#__PURE__*/function (_Component) { + (0,_babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__/* ["default"] */ .Z)(ModalDialog, _Component); + + /** + * Create an instance of this class. + * + * @param {Player} player + * The `Player` that this class should be attached to. + * + * @param {Object} [options] + * The key/value store of player options. + * + * @param {Mixed} [options.content=undefined] + * Provide customized content for this modal. + * + * @param {string} [options.description] + * A text description for the modal, primarily for accessibility. + * + * @param {boolean} [options.fillAlways=false] + * Normally, modals are automatically filled only the first time + * they open. This tells the modal to refresh its content + * every time it opens. + * + * @param {string} [options.label] + * A text label for the modal, primarily for accessibility. + * + * @param {boolean} [options.pauseOnOpen=true] + * If `true`, playback will will be paused if playing when + * the modal opens, and resumed when it closes. + * + * @param {boolean} [options.temporary=true] + * If `true`, the modal can only be opened once; it will be + * disposed as soon as it's closed. + * + * @param {boolean} [options.uncloseable=false] + * If `true`, the user will not be able to close the modal + * through the UI in the normal ways. Programmatic closing is + * still possible. + */ + function ModalDialog(player, options) { + var _this; + + _this = _Component.call(this, player, options) || this; + + _this.handleKeyDown_ = function (e) { + return _this.handleKeyDown(e); + }; + + _this.close_ = function (e) { + return _this.close(e); + }; + + _this.opened_ = _this.hasBeenOpened_ = _this.hasBeenFilled_ = false; + + _this.closeable(!_this.options_.uncloseable); + + _this.content(_this.options_.content); // Make sure the contentEl is defined AFTER any children are initialized + // because we only want the contents of the modal in the contentEl + // (not the UI elements like the close button). + + + _this.contentEl_ = createEl('div', { + className: MODAL_CLASS_NAME + "-content" + }, { + role: 'document' + }); + _this.descEl_ = createEl('p', { + className: MODAL_CLASS_NAME + "-description vjs-control-text", + id: _this.el().getAttribute('aria-describedby') + }); + textContent(_this.descEl_, _this.description()); + + _this.el_.appendChild(_this.descEl_); + + _this.el_.appendChild(_this.contentEl_); + + return _this; + } + /** + * Create the `ModalDialog`'s DOM element + * + * @return {Element} + * The DOM element that gets created. + */ + + + var _proto = ModalDialog.prototype; + + _proto.createEl = function createEl() { + return _Component.prototype.createEl.call(this, 'div', { + className: this.buildCSSClass(), + tabIndex: -1 + }, { + 'aria-describedby': this.id() + "_description", + 'aria-hidden': 'true', + 'aria-label': this.label(), + 'role': 'dialog' + }); + }; + + _proto.dispose = function dispose() { + this.contentEl_ = null; + this.descEl_ = null; + this.previouslyActiveEl_ = null; + + _Component.prototype.dispose.call(this); + } + /** + * Builds the default DOM `className`. + * + * @return {string} + * The DOM `className` for this object. + */ + ; + + _proto.buildCSSClass = function buildCSSClass() { + return MODAL_CLASS_NAME + " vjs-hidden " + _Component.prototype.buildCSSClass.call(this); + } + /** + * Returns the label string for this modal. Primarily used for accessibility. + * + * @return {string} + * the localized or raw label of this modal. + */ + ; + + _proto.label = function label() { + return this.localize(this.options_.label || 'Modal Window'); + } + /** + * Returns the description string for this modal. Primarily used for + * accessibility. + * + * @return {string} + * The localized or raw description of this modal. + */ + ; + + _proto.description = function description() { + var desc = this.options_.description || this.localize('This is a modal window.'); // Append a universal closeability message if the modal is closeable. + + if (this.closeable()) { + desc += ' ' + this.localize('This modal can be closed by pressing the Escape key or activating the close button.'); + } + + return desc; + } + /** + * Opens the modal. + * + * @fires ModalDialog#beforemodalopen + * @fires ModalDialog#modalopen + */ + ; + + _proto.open = function open() { + if (!this.opened_) { + var player = this.player(); + /** + * Fired just before a `ModalDialog` is opened. + * + * @event ModalDialog#beforemodalopen + * @type {EventTarget~Event} + */ + + this.trigger('beforemodalopen'); + this.opened_ = true; // Fill content if the modal has never opened before and + // never been filled. + + if (this.options_.fillAlways || !this.hasBeenOpened_ && !this.hasBeenFilled_) { + this.fill(); + } // If the player was playing, pause it and take note of its previously + // playing state. + + + this.wasPlaying_ = !player.paused(); + + if (this.options_.pauseOnOpen && this.wasPlaying_) { + player.pause(); + } + + this.on('keydown', this.handleKeyDown_); // Hide controls and note if they were enabled. + + this.hadControls_ = player.controls(); + player.controls(false); + this.show(); + this.conditionalFocus_(); + this.el().setAttribute('aria-hidden', 'false'); + /** + * Fired just after a `ModalDialog` is opened. + * + * @event ModalDialog#modalopen + * @type {EventTarget~Event} + */ + + this.trigger('modalopen'); + this.hasBeenOpened_ = true; + } + } + /** + * If the `ModalDialog` is currently open or closed. + * + * @param {boolean} [value] + * If given, it will open (`true`) or close (`false`) the modal. + * + * @return {boolean} + * the current open state of the modaldialog + */ + ; + + _proto.opened = function opened(value) { + if (typeof value === 'boolean') { + this[value ? 'open' : 'close'](); + } + + return this.opened_; + } + /** + * Closes the modal, does nothing if the `ModalDialog` is + * not open. + * + * @fires ModalDialog#beforemodalclose + * @fires ModalDialog#modalclose + */ + ; + + _proto.close = function close() { + if (!this.opened_) { + return; + } + + var player = this.player(); + /** + * Fired just before a `ModalDialog` is closed. + * + * @event ModalDialog#beforemodalclose + * @type {EventTarget~Event} + */ + + this.trigger('beforemodalclose'); + this.opened_ = false; + + if (this.wasPlaying_ && this.options_.pauseOnOpen) { + player.play(); + } + + this.off('keydown', this.handleKeyDown_); + + if (this.hadControls_) { + player.controls(true); + } + + this.hide(); + this.el().setAttribute('aria-hidden', 'true'); + /** + * Fired just after a `ModalDialog` is closed. + * + * @event ModalDialog#modalclose + * @type {EventTarget~Event} + */ + + this.trigger('modalclose'); + this.conditionalBlur_(); + + if (this.options_.temporary) { + this.dispose(); + } + } + /** + * Check to see if the `ModalDialog` is closeable via the UI. + * + * @param {boolean} [value] + * If given as a boolean, it will set the `closeable` option. + * + * @return {boolean} + * Returns the final value of the closable option. + */ + ; + + _proto.closeable = function closeable(value) { + if (typeof value === 'boolean') { + var closeable = this.closeable_ = !!value; + var close = this.getChild('closeButton'); // If this is being made closeable and has no close button, add one. + + if (closeable && !close) { + // The close button should be a child of the modal - not its + // content element, so temporarily change the content element. + var temp = this.contentEl_; + this.contentEl_ = this.el_; + close = this.addChild('closeButton', { + controlText: 'Close Modal Dialog' + }); + this.contentEl_ = temp; + this.on(close, 'close', this.close_); + } // If this is being made uncloseable and has a close button, remove it. + + + if (!closeable && close) { + this.off(close, 'close', this.close_); + this.removeChild(close); + close.dispose(); + } + } + + return this.closeable_; + } + /** + * Fill the modal's content element with the modal's "content" option. + * The content element will be emptied before this change takes place. + */ + ; + + _proto.fill = function fill() { + this.fillWith(this.content()); + } + /** + * Fill the modal's content element with arbitrary content. + * The content element will be emptied before this change takes place. + * + * @fires ModalDialog#beforemodalfill + * @fires ModalDialog#modalfill + * + * @param {Mixed} [content] + * The same rules apply to this as apply to the `content` option. + */ + ; + + _proto.fillWith = function fillWith(content) { + var contentEl = this.contentEl(); + var parentEl = contentEl.parentNode; + var nextSiblingEl = contentEl.nextSibling; + /** + * Fired just before a `ModalDialog` is filled with content. + * + * @event ModalDialog#beforemodalfill + * @type {EventTarget~Event} + */ + + this.trigger('beforemodalfill'); + this.hasBeenFilled_ = true; // Detach the content element from the DOM before performing + // manipulation to avoid modifying the live DOM multiple times. + + parentEl.removeChild(contentEl); + this.empty(); + insertContent(contentEl, content); + /** + * Fired just after a `ModalDialog` is filled with content. + * + * @event ModalDialog#modalfill + * @type {EventTarget~Event} + */ + + this.trigger('modalfill'); // Re-inject the re-filled content element. + + if (nextSiblingEl) { + parentEl.insertBefore(contentEl, nextSiblingEl); + } else { + parentEl.appendChild(contentEl); + } // make sure that the close button is last in the dialog DOM + + + var closeButton = this.getChild('closeButton'); + + if (closeButton) { + parentEl.appendChild(closeButton.el_); + } + } + /** + * Empties the content element. This happens anytime the modal is filled. + * + * @fires ModalDialog#beforemodalempty + * @fires ModalDialog#modalempty + */ + ; + + _proto.empty = function empty() { + /** + * Fired just before a `ModalDialog` is emptied. + * + * @event ModalDialog#beforemodalempty + * @type {EventTarget~Event} + */ + this.trigger('beforemodalempty'); + emptyEl(this.contentEl()); + /** + * Fired just after a `ModalDialog` is emptied. + * + * @event ModalDialog#modalempty + * @type {EventTarget~Event} + */ + + this.trigger('modalempty'); + } + /** + * Gets or sets the modal content, which gets normalized before being + * rendered into the DOM. + * + * This does not update the DOM or fill the modal, but it is called during + * that process. + * + * @param {Mixed} [value] + * If defined, sets the internal content value to be used on the + * next call(s) to `fill`. This value is normalized before being + * inserted. To "clear" the internal content value, pass `null`. + * + * @return {Mixed} + * The current content of the modal dialog + */ + ; + + _proto.content = function content(value) { + if (typeof value !== 'undefined') { + this.content_ = value; + } + + return this.content_; + } + /** + * conditionally focus the modal dialog if focus was previously on the player. + * + * @private + */ + ; + + _proto.conditionalFocus_ = function conditionalFocus_() { + var activeEl = (global_document__WEBPACK_IMPORTED_MODULE_1___default().activeElement); + var playerEl = this.player_.el_; + this.previouslyActiveEl_ = null; + + if (playerEl.contains(activeEl) || playerEl === activeEl) { + this.previouslyActiveEl_ = activeEl; + this.focus(); + } + } + /** + * conditionally blur the element and refocus the last focused element + * + * @private + */ + ; + + _proto.conditionalBlur_ = function conditionalBlur_() { + if (this.previouslyActiveEl_) { + this.previouslyActiveEl_.focus(); + this.previouslyActiveEl_ = null; + } + } + /** + * Keydown handler. Attached when modal is focused. + * + * @listens keydown + */ + ; + + _proto.handleKeyDown = function handleKeyDown(event) { + // Do not allow keydowns to reach out of the modal dialog. + event.stopPropagation(); + + if (keycode__WEBPACK_IMPORTED_MODULE_3___default().isEventKey(event, 'Escape') && this.closeable()) { + event.preventDefault(); + this.close(); + return; + } // exit early if it isn't a tab key + + + if (!keycode__WEBPACK_IMPORTED_MODULE_3___default().isEventKey(event, 'Tab')) { + return; + } + + var focusableEls = this.focusableEls_(); + var activeEl = this.el_.querySelector(':focus'); + var focusIndex; + + for (var i = 0; i < focusableEls.length; i++) { + if (activeEl === focusableEls[i]) { + focusIndex = i; + break; + } + } + + if ((global_document__WEBPACK_IMPORTED_MODULE_1___default().activeElement) === this.el_) { + focusIndex = 0; + } + + if (event.shiftKey && focusIndex === 0) { + focusableEls[focusableEls.length - 1].focus(); + event.preventDefault(); + } else if (!event.shiftKey && focusIndex === focusableEls.length - 1) { + focusableEls[0].focus(); + event.preventDefault(); + } + } + /** + * get all focusable elements + * + * @private + */ + ; + + _proto.focusableEls_ = function focusableEls_() { + var allChildren = this.el_.querySelectorAll('*'); + return Array.prototype.filter.call(allChildren, function (child) { + return (child instanceof (global_window__WEBPACK_IMPORTED_MODULE_0___default().HTMLAnchorElement) || child instanceof (global_window__WEBPACK_IMPORTED_MODULE_0___default().HTMLAreaElement)) && child.hasAttribute('href') || (child instanceof (global_window__WEBPACK_IMPORTED_MODULE_0___default().HTMLInputElement) || child instanceof (global_window__WEBPACK_IMPORTED_MODULE_0___default().HTMLSelectElement) || child instanceof (global_window__WEBPACK_IMPORTED_MODULE_0___default().HTMLTextAreaElement) || child instanceof (global_window__WEBPACK_IMPORTED_MODULE_0___default().HTMLButtonElement)) && !child.hasAttribute('disabled') || child instanceof (global_window__WEBPACK_IMPORTED_MODULE_0___default().HTMLIFrameElement) || child instanceof (global_window__WEBPACK_IMPORTED_MODULE_0___default().HTMLObjectElement) || child instanceof (global_window__WEBPACK_IMPORTED_MODULE_0___default().HTMLEmbedElement) || child.hasAttribute('tabindex') && child.getAttribute('tabindex') !== -1 || child.hasAttribute('contenteditable'); + }); + }; + + return ModalDialog; +}(Component$1); +/** + * Default options for `ModalDialog` default options. + * + * @type {Object} + * @private + */ + + +ModalDialog.prototype.options_ = { + pauseOnOpen: true, + temporary: true +}; +Component$1.registerComponent('ModalDialog', ModalDialog); + +/** + * Common functionaliy between {@link TextTrackList}, {@link AudioTrackList}, and + * {@link VideoTrackList} + * + * @extends EventTarget + */ + +var TrackList = /*#__PURE__*/function (_EventTarget) { + (0,_babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__/* ["default"] */ .Z)(TrackList, _EventTarget); + + /** + * Create an instance of this class + * + * @param {Track[]} tracks + * A list of tracks to initialize the list with. + * + * @abstract + */ + function TrackList(tracks) { + var _this; + + if (tracks === void 0) { + tracks = []; + } + + _this = _EventTarget.call(this) || this; + _this.tracks_ = []; + /** + * @memberof TrackList + * @member {number} length + * The current number of `Track`s in the this Trackist. + * @instance + */ + + Object.defineProperty((0,_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__/* ["default"] */ .Z)(_this), 'length', { + get: function get() { + return this.tracks_.length; + } + }); + + for (var i = 0; i < tracks.length; i++) { + _this.addTrack(tracks[i]); + } + + return _this; + } + /** + * Add a {@link Track} to the `TrackList` + * + * @param {Track} track + * The audio, video, or text track to add to the list. + * + * @fires TrackList#addtrack + */ + + + var _proto = TrackList.prototype; + + _proto.addTrack = function addTrack(track) { + var _this2 = this; + + var index = this.tracks_.length; + + if (!('' + index in this)) { + Object.defineProperty(this, index, { + get: function get() { + return this.tracks_[index]; + } + }); + } // Do not add duplicate tracks + + + if (this.tracks_.indexOf(track) === -1) { + this.tracks_.push(track); + /** + * Triggered when a track is added to a track list. + * + * @event TrackList#addtrack + * @type {EventTarget~Event} + * @property {Track} track + * A reference to track that was added. + */ + + this.trigger({ + track: track, + type: 'addtrack', + target: this + }); + } + /** + * Triggered when a track label is changed. + * + * @event TrackList#addtrack + * @type {EventTarget~Event} + * @property {Track} track + * A reference to track that was added. + */ + + + track.labelchange_ = function () { + _this2.trigger({ + track: track, + type: 'labelchange', + target: _this2 + }); + }; + + if (isEvented(track)) { + track.addEventListener('labelchange', track.labelchange_); + } + } + /** + * Remove a {@link Track} from the `TrackList` + * + * @param {Track} rtrack + * The audio, video, or text track to remove from the list. + * + * @fires TrackList#removetrack + */ + ; + + _proto.removeTrack = function removeTrack(rtrack) { + var track; + + for (var i = 0, l = this.length; i < l; i++) { + if (this[i] === rtrack) { + track = this[i]; + + if (track.off) { + track.off(); + } + + this.tracks_.splice(i, 1); + break; + } + } + + if (!track) { + return; + } + /** + * Triggered when a track is removed from track list. + * + * @event TrackList#removetrack + * @type {EventTarget~Event} + * @property {Track} track + * A reference to track that was removed. + */ + + + this.trigger({ + track: track, + type: 'removetrack', + target: this + }); + } + /** + * Get a Track from the TrackList by a tracks id + * + * @param {string} id - the id of the track to get + * @method getTrackById + * @return {Track} + * @private + */ + ; + + _proto.getTrackById = function getTrackById(id) { + var result = null; + + for (var i = 0, l = this.length; i < l; i++) { + var track = this[i]; + + if (track.id === id) { + result = track; + break; + } + } + + return result; + }; + + return TrackList; +}(EventTarget$2); +/** + * Triggered when a different track is selected/enabled. + * + * @event TrackList#change + * @type {EventTarget~Event} + */ + +/** + * Events that can be called with on + eventName. See {@link EventHandler}. + * + * @property {Object} TrackList#allowedEvents_ + * @private + */ + + +TrackList.prototype.allowedEvents_ = { + change: 'change', + addtrack: 'addtrack', + removetrack: 'removetrack', + labelchange: 'labelchange' +}; // emulate attribute EventHandler support to allow for feature detection + +for (var event in TrackList.prototype.allowedEvents_) { + TrackList.prototype['on' + event] = null; +} + +/** + * Anywhere we call this function we diverge from the spec + * as we only support one enabled audiotrack at a time + * + * @param {AudioTrackList} list + * list to work on + * + * @param {AudioTrack} track + * The track to skip + * + * @private + */ + +var disableOthers$1 = function disableOthers(list, track) { + for (var i = 0; i < list.length; i++) { + if (!Object.keys(list[i]).length || track.id === list[i].id) { + continue; + } // another audio track is enabled, disable it + + + list[i].enabled = false; + } +}; +/** + * The current list of {@link AudioTrack} for a media file. + * + * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist} + * @extends TrackList + */ + + +var AudioTrackList = /*#__PURE__*/function (_TrackList) { + (0,_babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__/* ["default"] */ .Z)(AudioTrackList, _TrackList); + + /** + * Create an instance of this class. + * + * @param {AudioTrack[]} [tracks=[]] + * A list of `AudioTrack` to instantiate the list with. + */ + function AudioTrackList(tracks) { + var _this; + + if (tracks === void 0) { + tracks = []; + } + + // make sure only 1 track is enabled + // sorted from last index to first index + for (var i = tracks.length - 1; i >= 0; i--) { + if (tracks[i].enabled) { + disableOthers$1(tracks, tracks[i]); + break; + } + } + + _this = _TrackList.call(this, tracks) || this; + _this.changing_ = false; + return _this; + } + /** + * Add an {@link AudioTrack} to the `AudioTrackList`. + * + * @param {AudioTrack} track + * The AudioTrack to add to the list + * + * @fires TrackList#addtrack + */ + + + var _proto = AudioTrackList.prototype; + + _proto.addTrack = function addTrack(track) { + var _this2 = this; + + if (track.enabled) { + disableOthers$1(this, track); + } + + _TrackList.prototype.addTrack.call(this, track); // native tracks don't have this + + + if (!track.addEventListener) { + return; + } + + track.enabledChange_ = function () { + // when we are disabling other tracks (since we don't support + // more than one track at a time) we will set changing_ + // to true so that we don't trigger additional change events + if (_this2.changing_) { + return; + } + + _this2.changing_ = true; + disableOthers$1(_this2, track); + _this2.changing_ = false; + + _this2.trigger('change'); + }; + /** + * @listens AudioTrack#enabledchange + * @fires TrackList#change + */ + + + track.addEventListener('enabledchange', track.enabledChange_); + }; + + _proto.removeTrack = function removeTrack(rtrack) { + _TrackList.prototype.removeTrack.call(this, rtrack); + + if (rtrack.removeEventListener && rtrack.enabledChange_) { + rtrack.removeEventListener('enabledchange', rtrack.enabledChange_); + rtrack.enabledChange_ = null; + } + }; + + return AudioTrackList; +}(TrackList); + +/** + * Un-select all other {@link VideoTrack}s that are selected. + * + * @param {VideoTrackList} list + * list to work on + * + * @param {VideoTrack} track + * The track to skip + * + * @private + */ + +var disableOthers = function disableOthers(list, track) { + for (var i = 0; i < list.length; i++) { + if (!Object.keys(list[i]).length || track.id === list[i].id) { + continue; + } // another video track is enabled, disable it + + + list[i].selected = false; + } +}; +/** + * The current list of {@link VideoTrack} for a video. + * + * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotracklist} + * @extends TrackList + */ + + +var VideoTrackList = /*#__PURE__*/function (_TrackList) { + (0,_babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__/* ["default"] */ .Z)(VideoTrackList, _TrackList); + + /** + * Create an instance of this class. + * + * @param {VideoTrack[]} [tracks=[]] + * A list of `VideoTrack` to instantiate the list with. + */ + function VideoTrackList(tracks) { + var _this; + + if (tracks === void 0) { + tracks = []; + } + + // make sure only 1 track is enabled + // sorted from last index to first index + for (var i = tracks.length - 1; i >= 0; i--) { + if (tracks[i].selected) { + disableOthers(tracks, tracks[i]); + break; + } + } + + _this = _TrackList.call(this, tracks) || this; + _this.changing_ = false; + /** + * @member {number} VideoTrackList#selectedIndex + * The current index of the selected {@link VideoTrack`}. + */ + + Object.defineProperty((0,_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__/* ["default"] */ .Z)(_this), 'selectedIndex', { + get: function get() { + for (var _i = 0; _i < this.length; _i++) { + if (this[_i].selected) { + return _i; + } + } + + return -1; + }, + set: function set() {} + }); + return _this; + } + /** + * Add a {@link VideoTrack} to the `VideoTrackList`. + * + * @param {VideoTrack} track + * The VideoTrack to add to the list + * + * @fires TrackList#addtrack + */ + + + var _proto = VideoTrackList.prototype; + + _proto.addTrack = function addTrack(track) { + var _this2 = this; + + if (track.selected) { + disableOthers(this, track); + } + + _TrackList.prototype.addTrack.call(this, track); // native tracks don't have this + + + if (!track.addEventListener) { + return; + } + + track.selectedChange_ = function () { + if (_this2.changing_) { + return; + } + + _this2.changing_ = true; + disableOthers(_this2, track); + _this2.changing_ = false; + + _this2.trigger('change'); + }; + /** + * @listens VideoTrack#selectedchange + * @fires TrackList#change + */ + + + track.addEventListener('selectedchange', track.selectedChange_); + }; + + _proto.removeTrack = function removeTrack(rtrack) { + _TrackList.prototype.removeTrack.call(this, rtrack); + + if (rtrack.removeEventListener && rtrack.selectedChange_) { + rtrack.removeEventListener('selectedchange', rtrack.selectedChange_); + rtrack.selectedChange_ = null; + } + }; + + return VideoTrackList; +}(TrackList); + +/** + * The current list of {@link TextTrack} for a media file. + * + * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttracklist} + * @extends TrackList + */ + +var TextTrackList = /*#__PURE__*/function (_TrackList) { + (0,_babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__/* ["default"] */ .Z)(TextTrackList, _TrackList); + + function TextTrackList() { + return _TrackList.apply(this, arguments) || this; + } + + var _proto = TextTrackList.prototype; + + /** + * Add a {@link TextTrack} to the `TextTrackList` + * + * @param {TextTrack} track + * The text track to add to the list. + * + * @fires TrackList#addtrack + */ + _proto.addTrack = function addTrack(track) { + var _this = this; + + _TrackList.prototype.addTrack.call(this, track); + + if (!this.queueChange_) { + this.queueChange_ = function () { + return _this.queueTrigger('change'); + }; + } + + if (!this.triggerSelectedlanguagechange) { + this.triggerSelectedlanguagechange_ = function () { + return _this.trigger('selectedlanguagechange'); + }; + } + /** + * @listens TextTrack#modechange + * @fires TrackList#change + */ + + + track.addEventListener('modechange', this.queueChange_); + var nonLanguageTextTrackKind = ['metadata', 'chapters']; + + if (nonLanguageTextTrackKind.indexOf(track.kind) === -1) { + track.addEventListener('modechange', this.triggerSelectedlanguagechange_); + } + }; + + _proto.removeTrack = function removeTrack(rtrack) { + _TrackList.prototype.removeTrack.call(this, rtrack); // manually remove the event handlers we added + + + if (rtrack.removeEventListener) { + if (this.queueChange_) { + rtrack.removeEventListener('modechange', this.queueChange_); + } + + if (this.selectedlanguagechange_) { + rtrack.removeEventListener('modechange', this.triggerSelectedlanguagechange_); + } + } + }; + + return TextTrackList; +}(TrackList); + +/** + * @file html-track-element-list.js + */ + +/** + * The current list of {@link HtmlTrackElement}s. + */ +var HtmlTrackElementList = /*#__PURE__*/function () { + /** + * Create an instance of this class. + * + * @param {HtmlTrackElement[]} [tracks=[]] + * A list of `HtmlTrackElement` to instantiate the list with. + */ + function HtmlTrackElementList(trackElements) { + if (trackElements === void 0) { + trackElements = []; + } + + this.trackElements_ = []; + /** + * @memberof HtmlTrackElementList + * @member {number} length + * The current number of `Track`s in the this Trackist. + * @instance + */ + + Object.defineProperty(this, 'length', { + get: function get() { + return this.trackElements_.length; + } + }); + + for (var i = 0, length = trackElements.length; i < length; i++) { + this.addTrackElement_(trackElements[i]); + } + } + /** + * Add an {@link HtmlTrackElement} to the `HtmlTrackElementList` + * + * @param {HtmlTrackElement} trackElement + * The track element to add to the list. + * + * @private + */ + + + var _proto = HtmlTrackElementList.prototype; + + _proto.addTrackElement_ = function addTrackElement_(trackElement) { + var index = this.trackElements_.length; + + if (!('' + index in this)) { + Object.defineProperty(this, index, { + get: function get() { + return this.trackElements_[index]; + } + }); + } // Do not add duplicate elements + + + if (this.trackElements_.indexOf(trackElement) === -1) { + this.trackElements_.push(trackElement); + } + } + /** + * Get an {@link HtmlTrackElement} from the `HtmlTrackElementList` given an + * {@link TextTrack}. + * + * @param {TextTrack} track + * The track associated with a track element. + * + * @return {HtmlTrackElement|undefined} + * The track element that was found or undefined. + * + * @private + */ + ; + + _proto.getTrackElementByTrack_ = function getTrackElementByTrack_(track) { + var trackElement_; + + for (var i = 0, length = this.trackElements_.length; i < length; i++) { + if (track === this.trackElements_[i].track) { + trackElement_ = this.trackElements_[i]; + break; + } + } + + return trackElement_; + } + /** + * Remove a {@link HtmlTrackElement} from the `HtmlTrackElementList` + * + * @param {HtmlTrackElement} trackElement + * The track element to remove from the list. + * + * @private + */ + ; + + _proto.removeTrackElement_ = function removeTrackElement_(trackElement) { + for (var i = 0, length = this.trackElements_.length; i < length; i++) { + if (trackElement === this.trackElements_[i]) { + if (this.trackElements_[i].track && typeof this.trackElements_[i].track.off === 'function') { + this.trackElements_[i].track.off(); + } + + if (typeof this.trackElements_[i].off === 'function') { + this.trackElements_[i].off(); + } + + this.trackElements_.splice(i, 1); + break; + } + } + }; + + return HtmlTrackElementList; +}(); + +/** + * @file text-track-cue-list.js + */ + +/** + * @typedef {Object} TextTrackCueList~TextTrackCue + * + * @property {string} id + * The unique id for this text track cue + * + * @property {number} startTime + * The start time for this text track cue + * + * @property {number} endTime + * The end time for this text track cue + * + * @property {boolean} pauseOnExit + * Pause when the end time is reached if true. + * + * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackcue} + */ + +/** + * A List of TextTrackCues. + * + * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackcuelist} + */ +var TextTrackCueList = /*#__PURE__*/function () { + /** + * Create an instance of this class.. + * + * @param {Array} cues + * A list of cues to be initialized with + */ + function TextTrackCueList(cues) { + TextTrackCueList.prototype.setCues_.call(this, cues); + /** + * @memberof TextTrackCueList + * @member {number} length + * The current number of `TextTrackCue`s in the TextTrackCueList. + * @instance + */ + + Object.defineProperty(this, 'length', { + get: function get() { + return this.length_; + } + }); + } + /** + * A setter for cues in this list. Creates getters + * an an index for the cues. + * + * @param {Array} cues + * An array of cues to set + * + * @private + */ + + + var _proto = TextTrackCueList.prototype; + + _proto.setCues_ = function setCues_(cues) { + var oldLength = this.length || 0; + var i = 0; + var l = cues.length; + this.cues_ = cues; + this.length_ = cues.length; + + var defineProp = function defineProp(index) { + if (!('' + index in this)) { + Object.defineProperty(this, '' + index, { + get: function get() { + return this.cues_[index]; + } + }); + } + }; + + if (oldLength < l) { + i = oldLength; + + for (; i < l; i++) { + defineProp.call(this, i); + } + } + } + /** + * Get a `TextTrackCue` that is currently in the `TextTrackCueList` by id. + * + * @param {string} id + * The id of the cue that should be searched for. + * + * @return {TextTrackCueList~TextTrackCue|null} + * A single cue or null if none was found. + */ + ; + + _proto.getCueById = function getCueById(id) { + var result = null; + + for (var i = 0, l = this.length; i < l; i++) { + var cue = this[i]; + + if (cue.id === id) { + result = cue; + break; + } + } + + return result; + }; + + return TextTrackCueList; +}(); + +/** + * @file track-kinds.js + */ + +/** + * All possible `VideoTrackKind`s + * + * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-videotrack-kind + * @typedef VideoTrack~Kind + * @enum + */ +var VideoTrackKind = { + alternative: 'alternative', + captions: 'captions', + main: 'main', + sign: 'sign', + subtitles: 'subtitles', + commentary: 'commentary' +}; +/** + * All possible `AudioTrackKind`s + * + * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-audiotrack-kind + * @typedef AudioTrack~Kind + * @enum + */ + +var AudioTrackKind = { + 'alternative': 'alternative', + 'descriptions': 'descriptions', + 'main': 'main', + 'main-desc': 'main-desc', + 'translation': 'translation', + 'commentary': 'commentary' +}; +/** + * All possible `TextTrackKind`s + * + * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-texttrack-kind + * @typedef TextTrack~Kind + * @enum + */ + +var TextTrackKind = { + subtitles: 'subtitles', + captions: 'captions', + descriptions: 'descriptions', + chapters: 'chapters', + metadata: 'metadata' +}; +/** + * All possible `TextTrackMode`s + * + * @see https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackmode + * @typedef TextTrack~Mode + * @enum + */ + +var TextTrackMode = { + disabled: 'disabled', + hidden: 'hidden', + showing: 'showing' +}; + +/** + * A Track class that contains all of the common functionality for {@link AudioTrack}, + * {@link VideoTrack}, and {@link TextTrack}. + * + * > Note: This class should not be used directly + * + * @see {@link https://html.spec.whatwg.org/multipage/embedded-content.html} + * @extends EventTarget + * @abstract + */ + +var Track = /*#__PURE__*/function (_EventTarget) { + (0,_babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__/* ["default"] */ .Z)(Track, _EventTarget); + + /** + * Create an instance of this class. + * + * @param {Object} [options={}] + * Object of option names and values + * + * @param {string} [options.kind=''] + * A valid kind for the track type you are creating. + * + * @param {string} [options.id='vjs_track_' + Guid.newGUID()] + * A unique id for this AudioTrack. + * + * @param {string} [options.label=''] + * The menu label for this track. + * + * @param {string} [options.language=''] + * A valid two character language code. + * + * @abstract + */ + function Track(options) { + var _this; + + if (options === void 0) { + options = {}; + } + + _this = _EventTarget.call(this) || this; + var trackProps = { + id: options.id || 'vjs_track_' + newGUID(), + kind: options.kind || '', + language: options.language || '' + }; + var label = options.label || ''; + /** + * @memberof Track + * @member {string} id + * The id of this track. Cannot be changed after creation. + * @instance + * + * @readonly + */ + + /** + * @memberof Track + * @member {string} kind + * The kind of track that this is. Cannot be changed after creation. + * @instance + * + * @readonly + */ + + /** + * @memberof Track + * @member {string} language + * The two letter language code for this track. Cannot be changed after + * creation. + * @instance + * + * @readonly + */ + + var _loop = function _loop(key) { + Object.defineProperty((0,_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__/* ["default"] */ .Z)(_this), key, { + get: function get() { + return trackProps[key]; + }, + set: function set() {} + }); + }; + + for (var key in trackProps) { + _loop(key); + } + /** + * @memberof Track + * @member {string} label + * The label of this track. Cannot be changed after creation. + * @instance + * + * @fires Track#labelchange + */ + + + Object.defineProperty((0,_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__/* ["default"] */ .Z)(_this), 'label', { + get: function get() { + return label; + }, + set: function set(newLabel) { + if (newLabel !== label) { + label = newLabel; + /** + * An event that fires when label changes on this track. + * + * > Note: This is not part of the spec! + * + * @event Track#labelchange + * @type {EventTarget~Event} + */ + + this.trigger('labelchange'); + } + } + }); + return _this; + } + + return Track; +}(EventTarget$2); + +/** + * @file url.js + * @module url + */ +/** + * @typedef {Object} url:URLObject + * + * @property {string} protocol + * The protocol of the url that was parsed. + * + * @property {string} hostname + * The hostname of the url that was parsed. + * + * @property {string} port + * The port of the url that was parsed. + * + * @property {string} pathname + * The pathname of the url that was parsed. + * + * @property {string} search + * The search query of the url that was parsed. + * + * @property {string} hash + * The hash of the url that was parsed. + * + * @property {string} host + * The host of the url that was parsed. + */ + +/** + * Resolve and parse the elements of a URL. + * + * @function + * @param {String} url + * The url to parse + * + * @return {url:URLObject} + * An object of url details + */ + +var parseUrl = function parseUrl(url) { + // This entire method can be replace with URL once we are able to drop IE11 + var props = ['protocol', 'hostname', 'port', 'pathname', 'search', 'hash', 'host']; // add the url to an anchor and let the browser parse the URL + + var a = global_document__WEBPACK_IMPORTED_MODULE_1___default().createElement('a'); + a.href = url; // Copy the specific URL properties to a new object + // This is also needed for IE because the anchor loses its + // properties when it's removed from the dom + + var details = {}; + + for (var i = 0; i < props.length; i++) { + details[props[i]] = a[props[i]]; + } // IE adds the port to the host property unlike everyone else. If + // a port identifier is added for standard ports, strip it. + + + if (details.protocol === 'http:') { + details.host = details.host.replace(/:80$/, ''); + } + + if (details.protocol === 'https:') { + details.host = details.host.replace(/:443$/, ''); + } + + if (!details.protocol) { + details.protocol = (global_window__WEBPACK_IMPORTED_MODULE_0___default().location.protocol); + } + /* istanbul ignore if */ + + + if (!details.host) { + details.host = (global_window__WEBPACK_IMPORTED_MODULE_0___default().location.host); + } + + return details; +}; +/** + * Get absolute version of relative URL. Used to tell Flash the correct URL. + * + * @function + * @param {string} url + * URL to make absolute + * + * @return {string} + * Absolute URL + * + * @see http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue + */ + +var getAbsoluteURL = function getAbsoluteURL(url) { + // Check if absolute URL + if (!url.match(/^https?:\/\//)) { + // Convert to absolute URL. Flash hosted off-site needs an absolute URL. + // add the url to an anchor and let the browser parse the URL + var a = global_document__WEBPACK_IMPORTED_MODULE_1___default().createElement('a'); + a.href = url; + url = a.href; + } + + return url; +}; +/** + * Returns the extension of the passed file name. It will return an empty string + * if passed an invalid path. + * + * @function + * @param {string} path + * The fileName path like '/path/to/file.mp4' + * + * @return {string} + * The extension in lower case or an empty string if no + * extension could be found. + */ + +var getFileExtension = function getFileExtension(path) { + if (typeof path === 'string') { + var splitPathRe = /^(\/?)([\s\S]*?)((?:\.{1,2}|[^\/]+?)(\.([^\.\/\?]+)))(?:[\/]*|[\?].*)$/; + var pathParts = splitPathRe.exec(path); + + if (pathParts) { + return pathParts.pop().toLowerCase(); + } + } + + return ''; +}; +/** + * Returns whether the url passed is a cross domain request or not. + * + * @function + * @param {string} url + * The url to check. + * + * @param {Object} [winLoc] + * the domain to check the url against, defaults to window.location + * + * @param {string} [winLoc.protocol] + * The window location protocol defaults to window.location.protocol + * + * @param {string} [winLoc.host] + * The window location host defaults to window.location.host + * + * @return {boolean} + * Whether it is a cross domain request or not. + */ + +var isCrossOrigin = function isCrossOrigin(url, winLoc) { + if (winLoc === void 0) { + winLoc = (global_window__WEBPACK_IMPORTED_MODULE_0___default().location); + } + + var urlInfo = parseUrl(url); // IE8 protocol relative urls will return ':' for protocol + + var srcProtocol = urlInfo.protocol === ':' ? winLoc.protocol : urlInfo.protocol; // Check if url is for another domain/origin + // IE8 doesn't know location.origin, so we won't rely on it here + + var crossOrigin = srcProtocol + urlInfo.host !== winLoc.protocol + winLoc.host; + return crossOrigin; +}; + +var Url = /*#__PURE__*/Object.freeze({ + __proto__: null, + parseUrl: parseUrl, + getAbsoluteURL: getAbsoluteURL, + getFileExtension: getFileExtension, + isCrossOrigin: isCrossOrigin +}); + +/** + * Takes a webvtt file contents and parses it into cues + * + * @param {string} srcContent + * webVTT file contents + * + * @param {TextTrack} track + * TextTrack to add cues to. Cues come from the srcContent. + * + * @private + */ + +var parseCues = function parseCues(srcContent, track) { + var parser = new (global_window__WEBPACK_IMPORTED_MODULE_0___default().WebVTT.Parser)((global_window__WEBPACK_IMPORTED_MODULE_0___default()), (global_window__WEBPACK_IMPORTED_MODULE_0___default().vttjs), global_window__WEBPACK_IMPORTED_MODULE_0___default().WebVTT.StringDecoder()); + var errors = []; + + parser.oncue = function (cue) { + track.addCue(cue); + }; + + parser.onparsingerror = function (error) { + errors.push(error); + }; + + parser.onflush = function () { + track.trigger({ + type: 'loadeddata', + target: track + }); + }; + + parser.parse(srcContent); + + if (errors.length > 0) { + if ((global_window__WEBPACK_IMPORTED_MODULE_0___default().console) && (global_window__WEBPACK_IMPORTED_MODULE_0___default().console.groupCollapsed)) { + global_window__WEBPACK_IMPORTED_MODULE_0___default().console.groupCollapsed("Text Track parsing errors for " + track.src); + } + + errors.forEach(function (error) { + return log$1.error(error); + }); + + if ((global_window__WEBPACK_IMPORTED_MODULE_0___default().console) && (global_window__WEBPACK_IMPORTED_MODULE_0___default().console.groupEnd)) { + global_window__WEBPACK_IMPORTED_MODULE_0___default().console.groupEnd(); + } + } + + parser.flush(); +}; +/** + * Load a `TextTrack` from a specified url. + * + * @param {string} src + * Url to load track from. + * + * @param {TextTrack} track + * Track to add cues to. Comes from the content at the end of `url`. + * + * @private + */ + + +var loadTrack = function loadTrack(src, track) { + var opts = { + uri: src + }; + var crossOrigin = isCrossOrigin(src); + + if (crossOrigin) { + opts.cors = crossOrigin; + } + + var withCredentials = track.tech_.crossOrigin() === 'use-credentials'; + + if (withCredentials) { + opts.withCredentials = withCredentials; + } + + _videojs_xhr__WEBPACK_IMPORTED_MODULE_4___default()(opts, bind(this, function (err, response, responseBody) { + if (err) { + return log$1.error(err, response); + } + + track.loaded_ = true; // Make sure that vttjs has loaded, otherwise, wait till it finished loading + // NOTE: this is only used for the alt/video.novtt.js build + + if (typeof (global_window__WEBPACK_IMPORTED_MODULE_0___default().WebVTT) !== 'function') { + if (track.tech_) { + // to prevent use before define eslint error, we define loadHandler + // as a let here + track.tech_.any(['vttjsloaded', 'vttjserror'], function (event) { + if (event.type === 'vttjserror') { + log$1.error("vttjs failed to load, stopping trying to process " + track.src); + return; + } + + return parseCues(responseBody, track); + }); + } + } else { + parseCues(responseBody, track); + } + })); +}; +/** + * A representation of a single `TextTrack`. + * + * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrack} + * @extends Track + */ + + +var TextTrack = /*#__PURE__*/function (_Track) { + (0,_babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__/* ["default"] */ .Z)(TextTrack, _Track); + + /** + * Create an instance of this class. + * + * @param {Object} options={} + * Object of option names and values + * + * @param {Tech} options.tech + * A reference to the tech that owns this TextTrack. + * + * @param {TextTrack~Kind} [options.kind='subtitles'] + * A valid text track kind. + * + * @param {TextTrack~Mode} [options.mode='disabled'] + * A valid text track mode. + * + * @param {string} [options.id='vjs_track_' + Guid.newGUID()] + * A unique id for this TextTrack. + * + * @param {string} [options.label=''] + * The menu label for this track. + * + * @param {string} [options.language=''] + * A valid two character language code. + * + * @param {string} [options.srclang=''] + * A valid two character language code. An alternative, but deprioritized + * version of `options.language` + * + * @param {string} [options.src] + * A url to TextTrack cues. + * + * @param {boolean} [options.default] + * If this track should default to on or off. + */ + function TextTrack(options) { + var _this; + + if (options === void 0) { + options = {}; + } + + if (!options.tech) { + throw new Error('A tech was not provided.'); + } + + var settings = mergeOptions$3(options, { + kind: TextTrackKind[options.kind] || 'subtitles', + language: options.language || options.srclang || '' + }); + var mode = TextTrackMode[settings.mode] || 'disabled'; + var default_ = settings["default"]; + + if (settings.kind === 'metadata' || settings.kind === 'chapters') { + mode = 'hidden'; + } + + _this = _Track.call(this, settings) || this; + _this.tech_ = settings.tech; + _this.cues_ = []; + _this.activeCues_ = []; + _this.preload_ = _this.tech_.preloadTextTracks !== false; + var cues = new TextTrackCueList(_this.cues_); + var activeCues = new TextTrackCueList(_this.activeCues_); + var changed = false; + var timeupdateHandler = bind((0,_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__/* ["default"] */ .Z)(_this), function () { + if (!this.tech_.isReady_ || this.tech_.isDisposed()) { + return; + } // Accessing this.activeCues for the side-effects of updating itself + // due to its nature as a getter function. Do not remove or cues will + // stop updating! + // Use the setter to prevent deletion from uglify (pure_getters rule) + + + this.activeCues = this.activeCues; + + if (changed) { + this.trigger('cuechange'); + changed = false; + } + }); + + var disposeHandler = function disposeHandler() { + _this.tech_.off('timeupdate', timeupdateHandler); + }; + + _this.tech_.one('dispose', disposeHandler); + + if (mode !== 'disabled') { + _this.tech_.on('timeupdate', timeupdateHandler); + } + + Object.defineProperties((0,_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__/* ["default"] */ .Z)(_this), { + /** + * @memberof TextTrack + * @member {boolean} default + * If this track was set to be on or off by default. Cannot be changed after + * creation. + * @instance + * + * @readonly + */ + "default": { + get: function get() { + return default_; + }, + set: function set() {} + }, + + /** + * @memberof TextTrack + * @member {string} mode + * Set the mode of this TextTrack to a valid {@link TextTrack~Mode}. Will + * not be set if setting to an invalid mode. + * @instance + * + * @fires TextTrack#modechange + */ + mode: { + get: function get() { + return mode; + }, + set: function set(newMode) { + if (!TextTrackMode[newMode]) { + return; + } + + if (mode === newMode) { + return; + } + + mode = newMode; + + if (!this.preload_ && mode !== 'disabled' && this.cues.length === 0) { + // On-demand load. + loadTrack(this.src, this); + } + + this.tech_.off('timeupdate', timeupdateHandler); + + if (mode !== 'disabled') { + this.tech_.on('timeupdate', timeupdateHandler); + } + /** + * An event that fires when mode changes on this track. This allows + * the TextTrackList that holds this track to act accordingly. + * + * > Note: This is not part of the spec! + * + * @event TextTrack#modechange + * @type {EventTarget~Event} + */ + + + this.trigger('modechange'); + } + }, + + /** + * @memberof TextTrack + * @member {TextTrackCueList} cues + * The text track cue list for this TextTrack. + * @instance + */ + cues: { + get: function get() { + if (!this.loaded_) { + return null; + } + + return cues; + }, + set: function set() {} + }, + + /** + * @memberof TextTrack + * @member {TextTrackCueList} activeCues + * The list text track cues that are currently active for this TextTrack. + * @instance + */ + activeCues: { + get: function get() { + if (!this.loaded_) { + return null; + } // nothing to do + + + if (this.cues.length === 0) { + return activeCues; + } + + var ct = this.tech_.currentTime(); + var active = []; + + for (var i = 0, l = this.cues.length; i < l; i++) { + var cue = this.cues[i]; + + if (cue.startTime <= ct && cue.endTime >= ct) { + active.push(cue); + } else if (cue.startTime === cue.endTime && cue.startTime <= ct && cue.startTime + 0.5 >= ct) { + active.push(cue); + } + } + + changed = false; + + if (active.length !== this.activeCues_.length) { + changed = true; + } else { + for (var _i = 0; _i < active.length; _i++) { + if (this.activeCues_.indexOf(active[_i]) === -1) { + changed = true; + } + } + } + + this.activeCues_ = active; + activeCues.setCues_(this.activeCues_); + return activeCues; + }, + // /!\ Keep this setter empty (see the timeupdate handler above) + set: function set() {} + } + }); + + if (settings.src) { + _this.src = settings.src; + + if (!_this.preload_) { + // Tracks will load on-demand. + // Act like we're loaded for other purposes. + _this.loaded_ = true; + } + + if (_this.preload_ || settings.kind !== 'subtitles' && settings.kind !== 'captions') { + loadTrack(_this.src, (0,_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__/* ["default"] */ .Z)(_this)); + } + } else { + _this.loaded_ = true; + } + + return _this; + } + /** + * Add a cue to the internal list of cues. + * + * @param {TextTrack~Cue} cue + * The cue to add to our internal list + */ + + + var _proto = TextTrack.prototype; + + _proto.addCue = function addCue(originalCue) { + var cue = originalCue; + + if ((global_window__WEBPACK_IMPORTED_MODULE_0___default().vttjs) && !(originalCue instanceof (global_window__WEBPACK_IMPORTED_MODULE_0___default().vttjs.VTTCue))) { + cue = new (global_window__WEBPACK_IMPORTED_MODULE_0___default().vttjs.VTTCue)(originalCue.startTime, originalCue.endTime, originalCue.text); + + for (var prop in originalCue) { + if (!(prop in cue)) { + cue[prop] = originalCue[prop]; + } + } // make sure that `id` is copied over + + + cue.id = originalCue.id; + cue.originalCue_ = originalCue; + } + + var tracks = this.tech_.textTracks(); + + for (var i = 0; i < tracks.length; i++) { + if (tracks[i] !== this) { + tracks[i].removeCue(cue); + } + } + + this.cues_.push(cue); + this.cues.setCues_(this.cues_); + } + /** + * Remove a cue from our internal list + * + * @param {TextTrack~Cue} removeCue + * The cue to remove from our internal list + */ + ; + + _proto.removeCue = function removeCue(_removeCue) { + var i = this.cues_.length; + + while (i--) { + var cue = this.cues_[i]; + + if (cue === _removeCue || cue.originalCue_ && cue.originalCue_ === _removeCue) { + this.cues_.splice(i, 1); + this.cues.setCues_(this.cues_); + break; + } + } + }; + + return TextTrack; +}(Track); +/** + * cuechange - One or more cues in the track have become active or stopped being active. + */ + + +TextTrack.prototype.allowedEvents_ = { + cuechange: 'cuechange' +}; + +/** + * A representation of a single `AudioTrack`. If it is part of an {@link AudioTrackList} + * only one `AudioTrack` in the list will be enabled at a time. + * + * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotrack} + * @extends Track + */ + +var AudioTrack = /*#__PURE__*/function (_Track) { + (0,_babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__/* ["default"] */ .Z)(AudioTrack, _Track); + + /** + * Create an instance of this class. + * + * @param {Object} [options={}] + * Object of option names and values + * + * @param {AudioTrack~Kind} [options.kind=''] + * A valid audio track kind + * + * @param {string} [options.id='vjs_track_' + Guid.newGUID()] + * A unique id for this AudioTrack. + * + * @param {string} [options.label=''] + * The menu label for this track. + * + * @param {string} [options.language=''] + * A valid two character language code. + * + * @param {boolean} [options.enabled] + * If this track is the one that is currently playing. If this track is part of + * an {@link AudioTrackList}, only one {@link AudioTrack} will be enabled. + */ + function AudioTrack(options) { + var _this; + + if (options === void 0) { + options = {}; + } + + var settings = mergeOptions$3(options, { + kind: AudioTrackKind[options.kind] || '' + }); + _this = _Track.call(this, settings) || this; + var enabled = false; + /** + * @memberof AudioTrack + * @member {boolean} enabled + * If this `AudioTrack` is enabled or not. When setting this will + * fire {@link AudioTrack#enabledchange} if the state of enabled is changed. + * @instance + * + * @fires VideoTrack#selectedchange + */ + + Object.defineProperty((0,_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__/* ["default"] */ .Z)(_this), 'enabled', { + get: function get() { + return enabled; + }, + set: function set(newEnabled) { + // an invalid or unchanged value + if (typeof newEnabled !== 'boolean' || newEnabled === enabled) { + return; + } + + enabled = newEnabled; + /** + * An event that fires when enabled changes on this track. This allows + * the AudioTrackList that holds this track to act accordingly. + * + * > Note: This is not part of the spec! Native tracks will do + * this internally without an event. + * + * @event AudioTrack#enabledchange + * @type {EventTarget~Event} + */ + + this.trigger('enabledchange'); + } + }); // if the user sets this track to selected then + // set selected to that true value otherwise + // we keep it false + + if (settings.enabled) { + _this.enabled = settings.enabled; + } + + _this.loaded_ = true; + return _this; + } + + return AudioTrack; +}(Track); + +/** + * A representation of a single `VideoTrack`. + * + * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotrack} + * @extends Track + */ + +var VideoTrack = /*#__PURE__*/function (_Track) { + (0,_babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__/* ["default"] */ .Z)(VideoTrack, _Track); + + /** + * Create an instance of this class. + * + * @param {Object} [options={}] + * Object of option names and values + * + * @param {string} [options.kind=''] + * A valid {@link VideoTrack~Kind} + * + * @param {string} [options.id='vjs_track_' + Guid.newGUID()] + * A unique id for this AudioTrack. + * + * @param {string} [options.label=''] + * The menu label for this track. + * + * @param {string} [options.language=''] + * A valid two character language code. + * + * @param {boolean} [options.selected] + * If this track is the one that is currently playing. + */ + function VideoTrack(options) { + var _this; + + if (options === void 0) { + options = {}; + } + + var settings = mergeOptions$3(options, { + kind: VideoTrackKind[options.kind] || '' + }); + _this = _Track.call(this, settings) || this; + var selected = false; + /** + * @memberof VideoTrack + * @member {boolean} selected + * If this `VideoTrack` is selected or not. When setting this will + * fire {@link VideoTrack#selectedchange} if the state of selected changed. + * @instance + * + * @fires VideoTrack#selectedchange + */ + + Object.defineProperty((0,_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__/* ["default"] */ .Z)(_this), 'selected', { + get: function get() { + return selected; + }, + set: function set(newSelected) { + // an invalid or unchanged value + if (typeof newSelected !== 'boolean' || newSelected === selected) { + return; + } + + selected = newSelected; + /** + * An event that fires when selected changes on this track. This allows + * the VideoTrackList that holds this track to act accordingly. + * + * > Note: This is not part of the spec! Native tracks will do + * this internally without an event. + * + * @event VideoTrack#selectedchange + * @type {EventTarget~Event} + */ + + this.trigger('selectedchange'); + } + }); // if the user sets this track to selected then + // set selected to that true value otherwise + // we keep it false + + if (settings.selected) { + _this.selected = settings.selected; + } + + return _this; + } + + return VideoTrack; +}(Track); + +/** + * @memberof HTMLTrackElement + * @typedef {HTMLTrackElement~ReadyState} + * @enum {number} + */ + +var NONE = 0; +var LOADING = 1; +var LOADED = 2; +var ERROR = 3; +/** + * A single track represented in the DOM. + * + * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#htmltrackelement} + * @extends EventTarget + */ + +var HTMLTrackElement = /*#__PURE__*/function (_EventTarget) { + (0,_babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__/* ["default"] */ .Z)(HTMLTrackElement, _EventTarget); + + /** + * Create an instance of this class. + * + * @param {Object} options={} + * Object of option names and values + * + * @param {Tech} options.tech + * A reference to the tech that owns this HTMLTrackElement. + * + * @param {TextTrack~Kind} [options.kind='subtitles'] + * A valid text track kind. + * + * @param {TextTrack~Mode} [options.mode='disabled'] + * A valid text track mode. + * + * @param {string} [options.id='vjs_track_' + Guid.newGUID()] + * A unique id for this TextTrack. + * + * @param {string} [options.label=''] + * The menu label for this track. + * + * @param {string} [options.language=''] + * A valid two character language code. + * + * @param {string} [options.srclang=''] + * A valid two character language code. An alternative, but deprioritized + * version of `options.language` + * + * @param {string} [options.src] + * A url to TextTrack cues. + * + * @param {boolean} [options.default] + * If this track should default to on or off. + */ + function HTMLTrackElement(options) { + var _this; + + if (options === void 0) { + options = {}; + } + + _this = _EventTarget.call(this) || this; + var readyState; + var track = new TextTrack(options); + _this.kind = track.kind; + _this.src = track.src; + _this.srclang = track.language; + _this.label = track.label; + _this["default"] = track["default"]; + Object.defineProperties((0,_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__/* ["default"] */ .Z)(_this), { + /** + * @memberof HTMLTrackElement + * @member {HTMLTrackElement~ReadyState} readyState + * The current ready state of the track element. + * @instance + */ + readyState: { + get: function get() { + return readyState; + } + }, + + /** + * @memberof HTMLTrackElement + * @member {TextTrack} track + * The underlying TextTrack object. + * @instance + * + */ + track: { + get: function get() { + return track; + } + } + }); + readyState = NONE; + /** + * @listens TextTrack#loadeddata + * @fires HTMLTrackElement#load + */ + + track.addEventListener('loadeddata', function () { + readyState = LOADED; + + _this.trigger({ + type: 'load', + target: (0,_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_17__/* ["default"] */ .Z)(_this) + }); + }); + return _this; + } + + return HTMLTrackElement; +}(EventTarget$2); + +HTMLTrackElement.prototype.allowedEvents_ = { + load: 'load' +}; +HTMLTrackElement.NONE = NONE; +HTMLTrackElement.LOADING = LOADING; +HTMLTrackElement.LOADED = LOADED; +HTMLTrackElement.ERROR = ERROR; + +/* + * This file contains all track properties that are used in + * player.js, tech.js, html5.js and possibly other techs in the future. + */ + +var NORMAL = { + audio: { + ListClass: AudioTrackList, + TrackClass: AudioTrack, + capitalName: 'Audio' + }, + video: { + ListClass: VideoTrackList, + TrackClass: VideoTrack, + capitalName: 'Video' + }, + text: { + ListClass: TextTrackList, + TrackClass: TextTrack, + capitalName: 'Text' + } +}; +Object.keys(NORMAL).forEach(function (type) { + NORMAL[type].getterName = type + "Tracks"; + NORMAL[type].privateName = type + "Tracks_"; +}); +var REMOTE = { + remoteText: { + ListClass: TextTrackList, + TrackClass: TextTrack, + capitalName: 'RemoteText', + getterName: 'remoteTextTracks', + privateName: 'remoteTextTracks_' + }, + remoteTextEl: { + ListClass: HtmlTrackElementList, + TrackClass: HTMLTrackElement, + capitalName: 'RemoteTextTrackEls', + getterName: 'remoteTextTrackEls', + privateName: 'remoteTextTrackEls_' + } +}; + +var ALL = (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_15__/* ["default"] */ .Z)({}, NORMAL, REMOTE); + +REMOTE.names = Object.keys(REMOTE); +NORMAL.names = Object.keys(NORMAL); +ALL.names = [].concat(REMOTE.names).concat(NORMAL.names); + +/** + * An Object containing a structure like: `{src: 'url', type: 'mimetype'}` or string + * that just contains the src url alone. + * * `var SourceObject = {src: 'http://ex.com/video.mp4', type: 'video/mp4'};` + * `var SourceString = 'http://example.com/some-video.mp4';` + * + * @typedef {Object|string} Tech~SourceObject + * + * @property {string} src + * The url to the source + * + * @property {string} type + * The mime type of the source + */ + +/** + * A function used by {@link Tech} to create a new {@link TextTrack}. + * + * @private + * + * @param {Tech} self + * An instance of the Tech class. + * + * @param {string} kind + * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata) + * + * @param {string} [label] + * Label to identify the text track + * + * @param {string} [language] + * Two letter language abbreviation + * + * @param {Object} [options={}] + * An object with additional text track options + * + * @return {TextTrack} + * The text track that was created. + */ + +function createTrackHelper(self, kind, label, language, options) { + if (options === void 0) { + options = {}; + } + + var tracks = self.textTracks(); + options.kind = kind; + + if (label) { + options.label = label; + } + + if (language) { + options.language = language; + } + + options.tech = self; + var track = new ALL.text.TrackClass(options); + tracks.addTrack(track); + return track; +} +/** + * This is the base class for media playback technology controllers, such as + * {@link HTML5} + * + * @extends Component + */ + + +var Tech = /*#__PURE__*/function (_Component) { + (0,_babel_runtime_helpers_inheritsLoose__WEBPACK_IMPORTED_MODULE_16__/* ["default"] */ .Z)(Tech, _Component); + + /** + * Create an instance of this Tech. + * + * @param {Object} [options] + * The key/value store of player options. + * + * @param {Component~ReadyCallback} ready + * Callback function to call when the `HTML5` Tech is ready. + */ + function Tech(options, ready) { + var _this; + + if (options === void 0) { + options = {}; + } + + if (ready === void 0) { + ready = function ready() {}; + } + + // we don't want the tech to report user activity automatically. + // This is done manually in addControlsListeners + options.reportTouchActivity = false; + _this = _Component.call(this, null, options, ready) || this; + + _this.onDurationChange_ = function (e) { + return _this.onDurationChange(e); + }; + + _this.trackProgress_ = function (e) { + return _this.trackProgress(e); + }; + + _this.trackCurrentTime_ = function (e) { + return _this.trackCurrentTime(e); + }; + + _this.stopTrackingCurrentTime_ = function (e) { + return _this.stopTrackingCurrentTime(e); + }; + + _this.disposeSourceHandler_ = function (e) { + return _this.disposeSourceHandler(e); + }; // keep track of whether the current source has played at all to + // implement a very limited played() + + + _this.hasStarted_ = false; + + _this.on('playing', function () { + this.hasStarted_ = true; + }); + + _this.on('loadstart', function () { + this.hasStarted_ = false; + }); + + ALL.names.forEach(function (name) { + var props = ALL[name]; + + if (options && options[props.getterName]) { + _this[props.privateName] = options[props.getterName]; + } + }); // Manually track progress in cases where the browser/tech doesn't report it. + + if (!_this.featuresProgressEvents) { + _this.manualProgressOn(); + } // Manually track timeupdates in cases where the browser/tech doesn't report it. + + + if (!_this.featuresTimeupdateEvents) { + _this.manualTimeUpdatesOn(); + } + + ['Text', 'Audio', 'Video'].forEach(function (track) { + if (options["native" + track + "Tracks"] === false) { + _this["featuresNative" + track + "Tracks"] = false; + } + }); + + if (options.nativeCaptions === false || options.nativeTextTracks === false) { + _this.featuresNativeTextTracks = false; + } else if (options.nativeCaptions === true || options.nativeTextTracks === true) { + _this.featuresNativeTextTracks = true; + } + + if (!_this.featuresNativeTextTracks) { + _this.emulateTextTracks(); + } + + _this.preloadTextTracks = options.preloadTextTracks !== false; + _this.autoRemoteTextTracks_ = new ALL.text.ListClass(); + + _this.initTrackListeners(); // Turn on component tap events only if not using native controls + + + if (!options.nativeControlsForTouch) { + _this.emitTapEvents(); + } + + if (_this.constructor) { + _this.name_ = _this.constructor.name || 'Unknown Tech'; + } + + return _this; + } + /** + * A special function to trigger source set in a way that will allow player + * to re-trigger if the player or tech are not ready yet. + * + * @fires Tech#sourceset + * @param {string} src The source string at the time of the source changing. + */ + + + var _proto = Tech.prototype; + + _proto.triggerSourceset = function triggerSourceset(src) { + var _this2 = this; + + if (!this.isReady_) { + // on initial ready we have to trigger source set + // 1ms after ready so that player can watch for it. + this.one('ready', function () { + return _this2.setTimeout(function () { + return _this2.triggerSourceset(src); + }, 1); + }); + } + /** + * Fired when the source is set on the tech causing the media element + * to reload. + * + * @see {@link Player#event:sourceset} + * @event Tech#sourceset + * @type {EventTarget~Event} + */ + + + this.trigger({ + src: src, + type: 'sourceset' + }); + } + /* Fallbacks for unsupported event types + ================================================================================ */ + + /** + * Polyfill the `progress` event for browsers that don't support it natively. + * + * @see {@link Tech#trackProgress} + */ + ; + + _proto.manualProgressOn = function manualProgressOn() { + this.on('durationchange', this.onDurationChange_); + this.manualProgress = true; // Trigger progress watching when a source begins loading + + this.one('ready', this.trackProgress_); + } + /** + * Turn off the polyfill for `progress` events that was created in + * {@link Tech#manualProgressOn} + */ + ; + + _proto.manualProgressOff = function manualProgressOff() { + this.manualProgress = false; + this.stopTrackingProgress(); + this.off('durationchange', this.onDurationChange_); + } + /** + * This is used to trigger a `progress` event when the buffered percent changes. It + * sets an interval function that will be called every 500 milliseconds to check if the + * buffer end percent has changed. + * + * > This function is called by {@link Tech#manualProgressOn} + * + * @param {EventTarget~Event} event + * The `ready` event that caused this to run. + * + * @listens Tech#ready + * @fires Tech#progress + */ + ; + + _proto.trackProgress = function trackProgress(event) { + this.stopTrackingProgress(); + this.progressInterval = this.setInterval(bind(this, function () { + // Don't trigger unless buffered amount is greater than last time + var numBufferedPercent = this.bufferedPercent(); + + if (this.bufferedPercent_ !== numBufferedPercent) { + /** + * See {@link Player#progress} + * + * @event Tech#progress + * @type {EventTarget~Event} + */ + this.trigger('progress'); + } + + this.bufferedPercent_ = numBufferedPercent; + + if (numBufferedPercent === 1) { + this.stopTrackingProgress(); + } + }), 500); + } + /** + * Update our internal duration on a `durationchange` event by calling + * {@link Tech#duration}. + * + * @param {EventTarget~Event} event + * The `durationchange` event that caused this to run. + * + * @listens Tech#durationchange + */ + ; + + _proto.onDurationChange = function onDurationChange(event) { + this.duration_ = this.duration(); + } + /** + * Get and create a `TimeRange` object for buffering. + * + * @return {TimeRange} + * The time range object that was created. + */ + ; + + _proto.buffered = function buffered() { + return createTimeRanges(0, 0); + } + /** + * Get the percentage of the current video that is currently buffered. + * + * @return {number} + * A number from 0 to 1 that represents the decimal percentage of the + * video that is buffered. + * + */ + ; + + _proto.bufferedPercent = function bufferedPercent$1() { + return bufferedPercent(this.buffered(), this.duration_); + } + /** + * Turn off the polyfill for `progress` events that was created in + * {@link Tech#manualProgressOn} + * Stop manually tracking progress events by clearing the interval that was set in + * {@link Tech#trackProgress}. + */ + ; + + _proto.stopTrackingProgress = function stopTrackingProgress() { + this.clearInterval(this.progressInterval); + } + /** + * Polyfill the `timeupdate` event for browsers that don't support it. + * + * @see {@link Tech#trackCurrentTime} + */ + ; + + _proto.manualTimeUpdatesOn = function manualTimeUpdatesOn() { + this.manualTimeUpdates = true; + this.on('play', this.trackCurrentTime_); + this.on('pause', this.stopTrackingCurrentTime_); + } + /** + * Turn off the polyfill for `timeupdate` events that was created in + * {@link Tech#manualTimeUpdatesOn} + */ + ; + + _proto.manualTimeUpdatesOff = function manualTimeUpdatesOff() { + this.manualTimeUpdates = false; + this.stopTrackingCurrentTime(); + this.off('play', this.trackCurrentTime_); + this.off('pause', this.stopTrackingCurrentTime_); + } + /** + * Sets up an interval function to track current time and trigger `timeupdate` every + * 250 milliseconds. + * + * @listens Tech#play + * @triggers Tech#timeupdate + */ + ; + + _proto.trackCurrentTime = function trackCurrentTime() { + if (this.currentTimeInterval) { + this.stopTrackingCurrentTime(); + } + + this.currentTimeInterval = this.setInterval(function () { + /** + * Triggered at an interval of 250ms to indicated that time is passing in the video. + * + * @event Tech#timeupdate + * @type {EventTarget~Event} + */ + this.trigger({ + type: 'timeupdate', + target: this, + manuallyTriggered: true + }); // 42 = 24 fps // 250 is what Webkit uses // FF uses 15 + }, 250); + } + /** + * Stop the interval function created in {@link Tech#trackCurrentTime} so that the + * `timeupdate` event is no longer triggered. + * + * @listens {Tech#pause} + */ + ; + + _proto.stopTrackingCurrentTime = function stopTrackingCurrentTime() { + this.clearInterval(this.currentTimeInterval); // #1002 - if the video ends right before the next timeupdate would happen, + // the progress bar won't make it all the way to the end + + this.trigger({ + type: 'timeupdate', + target: this, + manuallyTriggered: true + }); + } + /** + * Turn off all event polyfills, clear the `Tech`s {@link AudioTrackList}, + * {@link VideoTrackList}, and {@link TextTrackList}, and dispose of this Tech. + * + * @fires Component#dispose + */ + ; + + _proto.dispose = function dispose() { + // clear out all tracks because we can't reuse them between techs + this.clearTracks(NORMAL.names); // Turn off any manual progress or timeupdate tracking + + if (this.manualProgress) { + this.manualProgressOff(); + } + + if (this.manualTimeUpdates) { + this.manualTimeUpdatesOff(); + } + + _Component.prototype.dispose.call(this); + } + /** + * Clear out a single `TrackList` or an array of `TrackLists` given their names. + * + * > Note: Techs without source handlers should call this between sources for `video` + * & `audio` tracks. You don't want to use them between tracks! + * + * @param {string[]|string} types + * TrackList names to clear, valid names are `video`, `audio`, and + * `text`. + */ + ; + + _proto.clearTracks = function clearTracks(types) { + var _this3 = this; + + types = [].concat(types); // clear out all tracks because we can't reuse them between techs + + types.forEach(function (type) { + var list = _this3[type + "Tracks"]() || []; + var i = list.length; + + while (i--) { + var track = list[i]; + + if (type === 'text') { + _this3.removeRemoteTextTrack(track); + } + + list.removeTrack(track); + } + }); + } + /** + * Remove any TextTracks added via addRemoteTextTrack that are + * flagged for automatic garbage collection + */ + ; + + _proto.cleanupAutoTextTracks = function cleanupAutoTextTracks() { + var list = this.autoRemoteTextTracks_ || []; + var i = list.length; + + while (i--) { + var track = list[i]; + this.removeRemoteTextTrack(track); + } + } + /** + * Reset the tech, which will removes all sources and reset the internal readyState. + * + * @abstract + */ + ; + + _proto.reset = function reset() {} + /** + * Get the value of `crossOrigin` from the tech. + * + * @abstract + * + * @see {Html5#crossOrigin} + */ + ; + + _proto.crossOrigin = function crossOrigin() {} + /** + * Set the value of `crossOrigin` on the tech. + * + * @abstract + * + * @param {string} crossOrigin the crossOrigin value + * @see {Html5#setCrossOrigin} + */ + ; + + _proto.setCrossOrigin = function setCrossOrigin() {} + /** + * Get or set an error on the Tech. + * + * @param {MediaError} [err] + * Error to set on the Tech + * + * @return {MediaError|null} + * The current error object on the tech, or null if there isn't one. + */ + ; + + _proto.error = function error(err) { + if (err !== undefined) { + this.error_ = new MediaError(err); + this.trigger('error'); + } + + return this.error_; + } + /** + * Returns the `TimeRange`s that have been played through for the current source. + * + * > NOTE: This implementation is incomplete. It does not track the played `TimeRange`. + * It only checks whether the source has played at all or not. + * + * @return {TimeRange} + * - A single time range if this video has played + * - An empty set of ranges if not. + */ + ; + + _proto.played = function played() { + if (this.hasStarted_) { + return createTimeRanges(0, 0); + } + + return createTimeRanges(); + } + /** + * Start playback + * + * @abstract + * + * @see {Html5#play} + */ + ; + + _proto.play = function play() {} + /** + * Set whether we are scrubbing or not + * + * @abstract + * + * @see {Html5#setScrubbing} + */ + ; + + _proto.setScrubbing = function setScrubbing() {} + /** + * Get whether we are scrubbing or not + * + * @abstract + * + * @see {Html5#scrubbing} + */ + ; + + _proto.scrubbing = function scrubbing() {} + /** + * Causes a manual time update to occur if {@link Tech#manualTimeUpdatesOn} was + * previously called. + * + * @fires Tech#timeupdate + */ + ; + + _proto.setCurrentTime = function setCurrentTime() { + // improve the accuracy of manual timeupdates + if (this.manualTimeUpdates) { + /** + * A manual `timeupdate` event. + * + * @event Tech#timeupdate + * @type {EventTarget~Event} + */ + this.trigger({ + type: 'timeupdate', + target: this, + manuallyTriggered: true + }); + } + } + /** + * Turn on listeners for {@link VideoTrackList}, {@link {AudioTrackList}, and + * {@link TextTrackList} events. + * + * This adds {@link EventTarget~EventListeners} for `addtrack`, and `removetrack`. + * + * @fires Tech#audiotrackchange + * @fires Tech#videotrackchange + * @fires Tech#texttrackchange + */ + ; + + _proto.initTrackListeners = function initTrackListeners() { + var _this4 = this; + + /** + * Triggered when tracks are added or removed on the Tech {@link AudioTrackList} + * + * @event Tech#audiotrackchange + * @type {EventTarget~Event} + */ + + /** + * Triggered when tracks are added or removed on the Tech {@link VideoTrackList} + * + * @event Tech#videotrackchange + * @type {EventTarget~Event} + */ + + /** + * Triggered when tracks are added or removed on the Tech {@link TextTrackList} + * + * @event Tech#texttrackchange + * @type {EventTarget~Event} + */ + NORMAL.names.forEach(function (name) { + var props = NORMAL[name]; + + var trackListChanges = function trackListChanges() { + _this4.trigger(name + "trackchange"); + }; + + var tracks = _this4[props.getterName](); + + tracks.addEventListener('removetrack', trackListChanges); + tracks.addEventListener('addtrack', trackListChanges); + + _this4.on('dispose', function () { + tracks.removeEventListener('removetrack', trackListChanges); + tracks.removeEventListener('addtrack', trackListChanges); + }); + }); + } + /** + * Emulate TextTracks using vtt.js if necessary + * + * @fires Tech#vttjsloaded + * @fires Tech#vttjserror + */ + ; + + _proto.addWebVttScript_ = function addWebVttScript_() { + var _this5 = this; + + if ((global_window__WEBPACK_IMPORTED_MODULE_0___default().WebVTT)) { + return; + } // Initially, Tech.el_ is a child of a dummy-div wait until the Component system + // signals that the Tech is ready at which point Tech.el_ is part of the DOM + // before inserting the WebVTT script + + + if (global_document__WEBPACK_IMPORTED_MODULE_1___default().body.contains(this.el())) { + // load via require if available and vtt.js script location was not passed in + // as an option. novtt builds will turn the above require call into an empty object + // which will cause this if check to always fail. + if (!this.options_['vtt.js'] && isPlain((videojs_vtt_js__WEBPACK_IMPORTED_MODULE_5___default())) && Object.keys((videojs_vtt_js__WEBPACK_IMPORTED_MODULE_5___default())).length > 0) { + this.trigger('vttjsloaded'); + return; + } // load vtt.js via the script location option or the cdn of no location was + // passed in + + + var script = global_document__WEBPACK_IMPORTED_MODULE_1___default().createElement('script'); + script.src = this.options_['vtt.js'] || 'https://vjs.zencdn.net/vttjs/0.14.1/vtt.min.js'; + + script.onload = function () { + /** + * Fired when vtt.js is loaded. + * + * @event Tech#vttjsloaded + * @type {EventTarget~Event} + */ + _this5.trigger('vttjsloaded'); + }; + + script.onerror = function () { + /** + * Fired when vtt.js was not loaded due to an error + * + * @event Tech#vttjsloaded + * @type {EventTarget~Event} + */ + _this5.trigger('vttjserror'); + }; + + this.on('dispose', function () { + script.onload = null; + script.onerror = null; + }); // but have not loaded yet and we set it to true before the inject so that + // we don't overwrite the injected window.WebVTT if it loads right away + + (global_window__WEBPACK_IMPORTED_MODULE_0___default().WebVTT) = true; + this.el().parentNode.appendChild(script); + } else { + this.ready(this.addWebVttScript_); + } + } + /** + * Emulate texttracks + * + */ + ; + + _proto.emulateTextTracks = function emulateTextTracks() { + var _this6 = this; + + var tracks = this.textTracks(); + var remoteTracks = this.remoteTextTracks(); + + var handleAddTrack = function handleAddTrack(e) { + return tracks.addTrack(e.track); + }; + + var handleRemoveTrack = function handleRemoveTrack(e) { + return tracks.removeTrack(e.track); + }; + + remoteTracks.on('addtrack', handleAddTrack); + remoteTracks.on('removetrack', handleRemoveTrack); + this.addWebVttScript_(); + + var updateDisplay = function updateDisplay() { + return _this6.trigger('texttrackchange'); + }; + + var textTracksChanges = function textTracksChanges() { + updateDisplay(); + + for (var i = 0; i < tracks.length; i++) { + var track = tracks[i]; + track.removeEventListener('cuechange', updateDisplay); + + if (track.mode === 'showing') { + track.addEventListener('cuechange', updateDisplay); + } + } + }; + + textTracksChanges(); + tracks.addEventListener('change', textTracksChanges); + tracks.addEventListener('addtrack', textTracksChanges); + tracks.addEventListener('removetrack', textTracksChanges); + this.on('dispose', function () { + remoteTracks.off('addtrack', handleAddTrack); + remoteTracks.off('removetrack', handleRemoveTrack); + tracks.removeEventListener('change', textTracksChanges); + tracks.removeEventListener('addtrack', textTracksChanges); + tracks.removeEventListener('removetrack', textTracksChanges); + + for (var i = 0; i < tracks.length; i++) { + var track = tracks[i]; + track.removeEventListener('cuechange', updateDisplay); + } + }); + } + /** + * Create and returns a remote {@link TextTrack} object. + * + * @param {string} kind + * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata) + * + * @param {string} [label] + * Label to identify the text track + * + * @param {string} [language] + * Two letter language abbreviation + * + * @return {TextTrack} + * The TextTrack that gets created. + */ + ; + + _proto.addTextTrack = function addTextTrack(kind, label, language) { + if (!kind) { + throw new Error('TextTrack kind is required but was not provided'); + } + + return createTrackHelper(this, kind, label, language); + } + /** + * Create an emulated TextTrack for use by addRemoteTextTrack + * + * This is intended to be overridden by classes that inherit from + * Tech in order to create native or custom TextTracks. + * + * @param {Object} options + * The object should contain the options to initialize the TextTrack with. + * + * @param {string} [options.kind] + * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata). + * + * @param {string} [options.label]. + * Label to identify the text track + * + * @param {string} [options.language] + * Two letter language abbreviation. + * + * @return {HTMLTrackElement} + * The track element that gets created. + */ + ; + + _proto.createRemoteTextTrack = function createRemoteTextTrack(options) { + var track = mergeOptions$3(options, { + tech: this + }); + return new REMOTE.remoteTextEl.TrackClass(track); + } + /** + * Creates a remote text track object and returns an html track element. + * + * > Note: This can be an emulated {@link HTMLTrackElement} or a native one. + * + * @param {Object} options + * See {@link Tech#createRemoteTextTrack} for more detailed properties. + * + * @param {boolean} [manualCleanup=true] + * - When false: the TextTrack will be automatically removed from the video + * element whenever the source changes + * - When True: The TextTrack will have to be cleaned up manually + * + * @return {HTMLTrackElement} + * An Html Track Element. + * + * @deprecated The default functionality for this function will be equivalent + * to "manualCleanup=false" in the future. The manualCleanup parameter will + * also be removed. + */ + ; + + _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) { + var _this7 = this; + + if (options === void 0) { + options = {}; + } + + var htmlTrackElement = this.createRemoteTextTrack(options); + + if (manualCleanup !== true && manualCleanup !== false) { + // deprecation warning + log$1.warn('Calling addRemoteTextTrack without explicitly setting the "manualCleanup" parameter to `true` is deprecated and default to `false` in future version of video.js'); + manualCleanup = true; + } // store HTMLTrackElement and TextTrack to remote list + + + this.remoteTextTrackEls().addTrackElement_(htmlTrackElement); + this.remoteTextTracks().addTrack(htmlTrackElement.track); + + if (manualCleanup !== true) { + // create the TextTrackList if it doesn't exist + this.ready(function () { + return _this7.autoRemoteTextTracks_.addTrack(htmlTrackElement.track); + }); + } + + return htmlTrackElement; + } + /** + * Remove a remote text track from the remote `TextTrackList`. + * + * @param {TextTrack} track + * `TextTrack` to remove from the `TextTrackList` + */ + ; + + _proto.removeRemoteTextTrack = function removeRemoteTextTrack(track) { + var trackElement = this.remoteTextTrackEls().getTrackElementByTrack_(track); // remove HTMLTrackElement and TextTrack from remote list + + this.remoteTextTrackEls().removeTrackElement_(trackElement); + this.remoteTextTracks().removeTrack(track); + this.autoRemoteTextTracks_.removeTrack(track); + } + /** + * Gets available media playback quality metrics as specified by the W3C's Media + * Playback Quality API. + * + * @see [Spec]{@link https://wicg.github.io/media-playback-quality} + * + * @return {Object} + * An object with supported media playback quality metrics + * + * @abstract + */ + ; + + _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() { + return {}; + } + /** + * Attempt to create a floating video window always on top of other windows + * so that users may continue consuming media while they interact with other + * content sites, or applications on their device. + * + * @see [Spec]{@link https://wicg.github.io/picture-in-picture} + * + * @return {Promise|undefined} + * A promise with a Picture-in-Picture window if the browser supports + * Promises (or one was passed in as an option). It returns undefined + * otherwise. + * + * @abstract + */ + ; + + _proto.requestPictureInPicture = function requestPictureInPicture() { + var PromiseClass = this.options_.Promise || (global_window__WEBPACK_IMPORTED_MODULE_0___default().Promise); + + if (PromiseClass) { + return PromiseClass.reject(); + } + } + /** + * A method to check for the value of the 'disablePictureInPicture'