Remove target=es3 (#57525)

This commit is contained in:
Jake Bailey
2024-02-27 11:40:18 -08:00
committed by GitHub
parent 23156cb970
commit 65de938e4e
397 changed files with 324 additions and 2291 deletions
-1
View File
@@ -50,7 +50,6 @@ export * from "../transformers/esnext";
export * from "../transformers/jsx";
export * from "../transformers/es2016";
export * from "../transformers/es2015";
export * from "../transformers/es5";
export * from "../transformers/generators";
export * from "../transformers/module/module";
export * from "../transformers/module/system";
+3 -3
View File
@@ -2573,14 +2573,14 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
// Provide specialized messages to help the user understand why we think they're in
// strict mode.
if (getContainingClass(node)) {
return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES3_or_ES5_Class_definitions_are_automatically_in_strict_mode;
return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES5_Class_definitions_are_automatically_in_strict_mode;
}
if (file.externalModuleIndicator) {
return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES3_or_ES5_Modules_are_automatically_in_strict_mode;
return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES5_Modules_are_automatically_in_strict_mode;
}
return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES3_or_ES5;
return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES5;
}
function checkStrictModeFunctionDeclaration(node: FunctionDeclaration) {
+15 -40
View File
@@ -6571,7 +6571,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return parentName;
}
const memberName = symbolName(type.symbol);
if (isIdentifierText(memberName, ScriptTarget.ES3)) {
if (isIdentifierText(memberName, ScriptTarget.ES5)) {
return appendReferenceToType(
parentName as TypeReferenceNode | ImportTypeNode,
factory.createTypeReferenceNode(memberName, /*typeArguments*/ undefined),
@@ -29269,10 +29269,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (container) {
if (languageVersion < ScriptTarget.ES2015) {
if (container.kind === SyntaxKind.ArrowFunction) {
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES5_Consider_using_a_standard_function_expression);
}
else if (hasSyntacticModifier(container, ModifierFlags.Async)) {
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_async_function_or_method_in_ES3_and_ES5_Consider_using_a_standard_function_or_method);
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_async_function_or_method_in_ES5_Consider_using_a_standard_function_or_method);
}
}
@@ -34408,8 +34408,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
// For ES3 or decorators with only two parameters we supply only two arguments
return languageVersion === ScriptTarget.ES3 || signature.parameters.length <= 2 ? 2 : 3;
// For decorators with only two parameters we supply only two arguments
return signature.parameters.length <= 2 ? 2 : 3;
case SyntaxKind.Parameter:
return 3;
default:
@@ -35166,13 +35166,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[] | undefined, checkMode: CheckMode): Signature {
if (node.arguments && languageVersion < ScriptTarget.ES5) {
const spreadIndex = getSpreadArgumentIndex(node.arguments);
if (spreadIndex >= 0) {
error(node.arguments[spreadIndex], Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher);
}
}
let expressionType = checkNonNullExpression(node.expression);
if (expressionType === silentNeverType) {
return silentNeverSignature;
@@ -36990,8 +36983,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (!isClassLike(node.parent)) break;
// A method or accessor declaration decorator will have either two or three arguments (see
// `PropertyDecorator` and `MethodDecorator` in core.d.ts). If we are emitting decorators for
// ES3, we will only pass two arguments.
// `PropertyDecorator` and `MethodDecorator` in core.d.ts).
const targetType = getParentTypeOfClassElement(node);
const targetParam = createParameter("target" as __String, targetType);
@@ -37002,7 +36994,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const returnType = isPropertyDeclaration(node) ? voidType :
createTypedPropertyDescriptorType(getTypeOfNode(node));
const hasPropDesc = languageVersion !== ScriptTarget.ES3 && (!isPropertyDeclaration(parent) || hasAccessorModifier(parent));
const hasPropDesc = !isPropertyDeclaration(parent) || hasAccessorModifier(parent);
if (hasPropDesc) {
const descriptorType = createTypedPropertyDescriptorType(getTypeOfNode(node));
const descriptorParam = createParameter("descriptor" as __String, descriptorType);
@@ -37074,8 +37066,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
error(
func,
isImportCall(func) ?
Diagnostics.A_dynamic_import_call_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option :
Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option,
Diagnostics.A_dynamic_import_call_in_ES5_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option :
Diagnostics.An_async_function_or_method_in_ES5_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option,
);
}
@@ -41465,7 +41457,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const promiseConstructorName = getEntityNameFromTypeNode(returnTypeNode);
if (promiseConstructorName === undefined) {
reportErrorForInvalidReturnType(Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, returnTypeNode, returnTypeErrorLocation, typeToString(returnType));
reportErrorForInvalidReturnType(Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, returnTypeNode, returnTypeErrorLocation, typeToString(returnType));
return;
}
@@ -41473,10 +41465,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const promiseConstructorType = promiseConstructorSymbol ? getTypeOfSymbol(promiseConstructorSymbol) : errorType;
if (isErrorType(promiseConstructorType)) {
if (promiseConstructorName.kind === SyntaxKind.Identifier && promiseConstructorName.escapedText === "Promise" && getTargetType(returnType) === getGlobalPromiseType(/*reportErrors*/ false)) {
error(returnTypeErrorLocation, Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option);
error(returnTypeErrorLocation, Diagnostics.An_async_function_or_method_in_ES5_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option);
}
else {
reportErrorForInvalidReturnType(Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, returnTypeNode, returnTypeErrorLocation, entityNameToString(promiseConstructorName));
reportErrorForInvalidReturnType(Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, returnTypeNode, returnTypeErrorLocation, entityNameToString(promiseConstructorName));
}
return;
}
@@ -41485,11 +41477,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (globalPromiseConstructorLikeType === emptyObjectType) {
// If we couldn't resolve the global PromiseConstructorLike type we cannot verify
// compatibility with __awaiter.
reportErrorForInvalidReturnType(Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, returnTypeNode, returnTypeErrorLocation, entityNameToString(promiseConstructorName));
reportErrorForInvalidReturnType(Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, returnTypeNode, returnTypeErrorLocation, entityNameToString(promiseConstructorName));
return;
}
const headMessage = Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value;
const headMessage = Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_because_it_does_not_refer_to_a_Promise_compatible_constructor_value;
const errorInfo = () => returnTypeNode === returnTypeErrorLocation ? undefined : chainDiagnosticMessages(/*details*/ undefined, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type);
if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, returnTypeErrorLocation, headMessage, errorInfo)) {
return;
@@ -43265,7 +43257,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
let arrayType = inputType;
let reportedError = false;
let hasStringConstituent = false;
// If strings are permitted, remove any string-like constituents from the array type.
@@ -43287,13 +43278,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
hasStringConstituent = arrayType !== inputType;
if (hasStringConstituent) {
if (languageVersion < ScriptTarget.ES5) {
if (errorNode) {
error(errorNode, Diagnostics.Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher);
reportedError = true;
}
}
// Now that we've removed all the StringLike types, if no constituents remain, then the entire
// arrayOrStringType was a string.
if (arrayType.flags & TypeFlags.Never) {
@@ -43303,7 +43287,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
if (!isArrayLikeType(arrayType)) {
if (errorNode && !reportedError) {
if (errorNode) {
// Which error we report depends on whether we allow strings or if there was a
// string constituent. For example, if the input type is number | string, we
// want to say that number is not an array type. But if the input was just
@@ -46198,10 +46182,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
grammarErrorOnFirstToken(node, Diagnostics.An_export_declaration_cannot_have_modifiers);
}
if (node.moduleSpecifier && node.exportClause && isNamedExports(node.exportClause) && length(node.exportClause.elements) && languageVersion === ScriptTarget.ES3) {
checkExternalEmitHelpers(node, ExternalEmitHelpers.CreateBinding);
}
checkGrammarExportDeclaration(node);
if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) {
if (node.exportClause && !isNamespaceExport(node.exportClause)) {
@@ -49039,8 +49019,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return ["__classPrivateFieldSet"];
case ExternalEmitHelpers.ClassPrivateFieldIn:
return ["__classPrivateFieldIn"];
case ExternalEmitHelpers.CreateBinding:
return ["__createBinding"];
case ExternalEmitHelpers.SetFunctionName:
return ["__setFunctionName"];
case ExternalEmitHelpers.PropKey:
@@ -50122,9 +50100,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function checkGrammarAccessor(accessor: AccessorDeclaration): boolean {
if (!(accessor.flags & NodeFlags.Ambient) && (accessor.parent.kind !== SyntaxKind.TypeLiteral) && (accessor.parent.kind !== SyntaxKind.InterfaceDeclaration)) {
if (languageVersion < ScriptTarget.ES5) {
return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
}
if (languageVersion < ScriptTarget.ES2015 && isPrivateIdentifier(accessor.name)) {
return grammarErrorOnNode(accessor.name, Diagnostics.Private_identifiers_are_only_available_when_targeting_ECMAScript_2015_and_higher);
}
+9 -13
View File
@@ -163,7 +163,7 @@
"category": "Error",
"code": 1054
},
"Type '{0}' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.": {
"Type '{0}' is not a valid async function return type in ES5 because it does not refer to a Promise-compatible constructor value.": {
"category": "Error",
"code": 1055
},
@@ -799,15 +799,15 @@
"category": "Error",
"code": 1249
},
"Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'.": {
"Function declarations are not allowed inside blocks in strict mode when targeting 'ES5'.": {
"category": "Error",
"code": 1250
},
"Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode.": {
"Function declarations are not allowed inside blocks in strict mode when targeting 'ES5'. Class definitions are automatically in strict mode.": {
"category": "Error",
"code": 1251
},
"Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Modules are automatically in strict mode.": {
"Function declarations are not allowed inside blocks in strict mode when targeting 'ES5'. Modules are automatically in strict mode.": {
"category": "Error",
"code": 1252
},
@@ -2420,7 +2420,7 @@
"category": "Error",
"code": 2495
},
"The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.": {
"The 'arguments' object cannot be referenced in an arrow function in ES5. Consider using a standard function expression.": {
"category": "Error",
"code": 2496
},
@@ -2520,7 +2520,7 @@
"category": "Error",
"code": 2520
},
"The 'arguments' object cannot be referenced in an async function or method in ES3 and ES5. Consider using a standard function or method.": {
"The 'arguments' object cannot be referenced in an async function or method in ES5. Consider using a standard function or method.": {
"category": "Error",
"code": 2522
},
@@ -3135,7 +3135,7 @@
"category": "Error",
"code": 2704
},
"An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.": {
"An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.": {
"category": "Error",
"code": 2705
},
@@ -3163,7 +3163,7 @@
"category": "Error",
"code": 2711
},
"A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.": {
"A dynamic import call in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.": {
"category": "Error",
"code": 2712
},
@@ -4229,10 +4229,6 @@
"category": "Error",
"code": 5047
},
"Option '{0}' cannot be specified when option 'target' is 'ES3'.": {
"category": "Error",
"code": 5048
},
"Option '{0} can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": {
"category": "Error",
"code": 5051
@@ -5065,7 +5061,7 @@
"category": "Message",
"code": 6171
},
"Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'.": {
"Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5'.": {
"category": "Message",
"code": 6179
},
-11
View File
@@ -129,7 +129,6 @@ export interface EmitHelperFactory {
// ES2015 Generator Helpers
createGeneratorHelper(body: FunctionExpression): Expression;
// ES Module Helpers
createCreateBindingHelper(module: Expression, inputName: Expression, outputName: Expression | undefined): Expression;
createImportStarHelper(expression: Expression): Expression;
createImportStarCallbackHelper(): Expression;
createImportDefaultHelper(expression: Expression): Expression;
@@ -180,7 +179,6 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel
// ES2015 Generator Helpers
createGeneratorHelper,
// ES Module Helpers
createCreateBindingHelper,
createImportStarHelper,
createImportStarCallbackHelper,
createImportDefaultHelper,
@@ -608,15 +606,6 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel
// ES Module Helpers
function createCreateBindingHelper(module: Expression, inputName: Expression, outputName: Expression | undefined) {
context.requestEmitHelper(createBindingHelper);
return factory.createCallExpression(
getUnscopedHelperName("__createBinding"),
/*typeArguments*/ undefined,
[factory.createIdentifier("exports"), module, inputName, ...(outputName ? [outputName] : [])],
);
}
function createImportStarHelper(expression: Expression) {
context.requestEmitHelper(importStarHelper);
return factory.createCallExpression(
+1 -1
View File
@@ -6042,7 +6042,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
node.path = "" as Path;
node.resolvedPath = "" as Path;
node.originalFileName = "";
node.languageVersion = 0;
node.languageVersion = ScriptTarget.ES5;
node.languageVariant = 0;
node.scriptKind = 0;
node.isDeclarationFile = false;
-4
View File
@@ -4366,10 +4366,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
}
if (options.useDefineForClassFields && languageVersion === ScriptTarget.ES3) {
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_when_option_target_is_ES3, "useDefineForClassFields");
}
if (options.checkJs && !getAllowJSCompilerOption(options)) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs"));
}
+2 -29
View File
@@ -274,31 +274,6 @@ const textToToken = new Map(Object.entries({
"`": SyntaxKind.BacktickToken,
}));
/*
As per ECMAScript Language Specification 3th Edition, Section 7.6: Identifiers
IdentifierStart ::
Can contain Unicode 3.0.0 categories:
Uppercase letter (Lu),
Lowercase letter (Ll),
Titlecase letter (Lt),
Modifier letter (Lm),
Other letter (Lo), or
Letter number (Nl).
IdentifierPart :: =
Can contain IdentifierStart + Unicode 3.0.0 categories:
Non-spacing mark (Mn),
Combining spacing mark (Mc),
Decimal number (Nd), or
Connector punctuation (Pc).
Codepoint ranges for ES3 Identifiers are extracted from the Unicode 3.0.0 specification at:
http://www.unicode.org/Public/3.0-Update/UnicodeData-3.0.0.txt
*/
// dprint-ignore
const unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500 ];
// dprint-ignore
const unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500 ];
/*
As per ECMAScript Language Specification 5th Edition, Section 7.6: ISyntaxToken Names and Identifiers
IdentifierStart ::
@@ -382,15 +357,13 @@ function lookupInUnicodeMap(code: number, map: readonly number[]): boolean {
/** @internal */ export function isUnicodeIdentifierStart(code: number, languageVersion: ScriptTarget | undefined) {
return languageVersion! >= ScriptTarget.ES2015 ?
lookupInUnicodeMap(code, unicodeESNextIdentifierStart) :
languageVersion === ScriptTarget.ES5 ? lookupInUnicodeMap(code, unicodeES5IdentifierStart) :
lookupInUnicodeMap(code, unicodeES3IdentifierStart);
lookupInUnicodeMap(code, unicodeES5IdentifierStart);
}
function isUnicodeIdentifierPart(code: number, languageVersion: ScriptTarget | undefined) {
return languageVersion! >= ScriptTarget.ES2015 ?
lookupInUnicodeMap(code, unicodeESNextIdentifierPart) :
languageVersion === ScriptTarget.ES5 ? lookupInUnicodeMap(code, unicodeES5IdentifierPart) :
lookupInUnicodeMap(code, unicodeES3IdentifierPart);
lookupInUnicodeMap(code, unicodeES5IdentifierPart);
}
function makeReverseMap(source: Map<string, number>): string[] {
-7
View File
@@ -55,7 +55,6 @@ import {
transformECMAScriptModule,
Transformer,
TransformerFactory,
transformES5,
transformES2015,
transformES2016,
transformES2017,
@@ -178,12 +177,6 @@ function getScriptTransformers(compilerOptions: CompilerOptions, customTransform
transformers.push(getModuleTransformer(moduleKind));
// The ES5 transformer is last so that it can substitute expressions like `exports.default`
// for ES3.
if (languageVersion < ScriptTarget.ES5) {
transformers.push(transformES5);
}
addRange(transformers, customTransformers && map(customTransformers.after, wrapScriptTransformerFactory));
return transformers;
}
-146
View File
@@ -1,146 +0,0 @@
import {
Bundle,
chainBundle,
EmitHint,
Expression,
getOriginalNodeId,
Identifier,
identifierToKeywordKind,
isIdentifier,
isPrivateIdentifier,
isPropertyAccessExpression,
isPropertyAssignment,
JsxClosingElement,
JsxEmit,
JsxOpeningElement,
JsxSelfClosingElement,
Node,
PropertyAccessExpression,
PropertyAssignment,
setTextRange,
SourceFile,
SyntaxKind,
TransformationContext,
} from "../_namespaces/ts";
/**
* Transforms ES5 syntax into ES3 syntax.
*
* @param context Context and state information for the transformation.
*
* @internal
*/
export function transformES5(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
const { factory } = context;
const compilerOptions = context.getCompilerOptions();
// enable emit notification only if using --jsx preserve or react-native
let previousOnEmitNode: (hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) => void;
let noSubstitution: boolean[];
if (compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) {
previousOnEmitNode = context.onEmitNode;
context.onEmitNode = onEmitNode;
context.enableEmitNotification(SyntaxKind.JsxOpeningElement);
context.enableEmitNotification(SyntaxKind.JsxClosingElement);
context.enableEmitNotification(SyntaxKind.JsxSelfClosingElement);
noSubstitution = [];
}
const previousOnSubstituteNode = context.onSubstituteNode;
context.onSubstituteNode = onSubstituteNode;
context.enableSubstitution(SyntaxKind.PropertyAccessExpression);
context.enableSubstitution(SyntaxKind.PropertyAssignment);
return chainBundle(context, transformSourceFile);
/**
* Transforms an ES5 source file to ES3.
*
* @param node A SourceFile
*/
function transformSourceFile(node: SourceFile) {
return node;
}
/**
* Called by the printer just before a node is printed.
*
* @param hint A hint as to the intended usage of the node.
* @param node The node to emit.
* @param emitCallback A callback used to emit the node.
*/
function onEmitNode(hint: EmitHint, node: Node, emitCallback: (emitContext: EmitHint, node: Node) => void) {
switch (node.kind) {
case SyntaxKind.JsxOpeningElement:
case SyntaxKind.JsxClosingElement:
case SyntaxKind.JsxSelfClosingElement:
const tagName = (node as JsxOpeningElement | JsxClosingElement | JsxSelfClosingElement).tagName;
noSubstitution[getOriginalNodeId(tagName)] = true;
break;
}
previousOnEmitNode(hint, node, emitCallback);
}
/**
* Hooks node substitutions.
*
* @param hint A hint as to the intended usage of the node.
* @param node The node to substitute.
*/
function onSubstituteNode(hint: EmitHint, node: Node) {
if (node.id && noSubstitution && noSubstitution[node.id]) {
return previousOnSubstituteNode(hint, node);
}
node = previousOnSubstituteNode(hint, node);
if (isPropertyAccessExpression(node)) {
return substitutePropertyAccessExpression(node);
}
else if (isPropertyAssignment(node)) {
return substitutePropertyAssignment(node);
}
return node;
}
/**
* Substitutes a PropertyAccessExpression whose name is a reserved word.
*
* @param node A PropertyAccessExpression
*/
function substitutePropertyAccessExpression(node: PropertyAccessExpression): Expression {
if (isPrivateIdentifier(node.name)) {
return node;
}
const literalName = trySubstituteReservedName(node.name);
if (literalName) {
return setTextRange(factory.createElementAccessExpression(node.expression, literalName), node);
}
return node;
}
/**
* Substitutes a PropertyAssignment whose name is a reserved word.
*
* @param node A PropertyAssignment
*/
function substitutePropertyAssignment(node: PropertyAssignment): PropertyAssignment {
const literalName = isIdentifier(node.name) && trySubstituteReservedName(node.name);
if (literalName) {
return factory.updatePropertyAssignment(node, literalName, node.initializer);
}
return node;
}
/**
* If an identifier name is a reserved word, returns a string literal for the name.
*
* @param name An Identifier
*/
function trySubstituteReservedName(name: Identifier) {
const token = identifierToKeywordKind(name);
if (token !== undefined && token >= SyntaxKind.FirstReservedWord && token <= SyntaxKind.LastReservedWord) {
return setTextRange(factory.createStringLiteralFromNode(name), name);
}
return undefined;
}
}
@@ -641,15 +641,13 @@ export function transformLegacyDecorators(context: TransformationContext): (x: S
const prefix = getClassMemberPrefix(node, member);
const memberName = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ !hasSyntacticModifier(member, ModifierFlags.Ambient));
const descriptor = languageVersion > ScriptTarget.ES3
? isPropertyDeclaration(member) && !hasAccessorModifier(member)
// We emit `void 0` here to indicate to `__decorate` that it can invoke `Object.defineProperty` directly, but that it
// should not invoke `Object.getOwnPropertyDescriptor`.
? factory.createVoidZero()
// We emit `null` here to indicate to `__decorate` that it can invoke `Object.getOwnPropertyDescriptor` directly.
// We have this extra argument here so that we can inject an explicit property descriptor at a later date.
: factory.createNull()
: undefined;
const descriptor = isPropertyDeclaration(member) && !hasAccessorModifier(member)
// We emit `void 0` here to indicate to `__decorate` that it can invoke `Object.defineProperty` directly, but that it
// should not invoke `Object.getOwnPropertyDescriptor`.
? factory.createVoidZero()
// We emit `null` here to indicate to `__decorate` that it can invoke `Object.getOwnPropertyDescriptor` directly.
// We have this extra argument here so that we can inject an explicit property descriptor at a later date.
: factory.createNull();
const helper = emitHelpers().createDecorateHelper(
decoratorExpressions,
+29 -55
View File
@@ -1598,39 +1598,24 @@ export function transformModule(context: TransformationContext): (x: SourceFile
);
}
for (const specifier of node.exportClause.elements) {
if (languageVersion === ScriptTarget.ES3) {
statements.push(
setOriginalNode(
setTextRange(
factory.createExpressionStatement(
emitHelpers().createCreateBindingHelper(generatedName, factory.createStringLiteralFromNode(specifier.propertyName || specifier.name), specifier.propertyName ? factory.createStringLiteralFromNode(specifier.name) : undefined),
),
specifier,
const exportNeedsImportDefault = !!getESModuleInterop(compilerOptions) &&
!(getInternalEmitFlags(node) & InternalEmitFlags.NeverApplyImportHelper) &&
idText(specifier.propertyName || specifier.name) === "default";
const exportedValue = factory.createPropertyAccessExpression(
exportNeedsImportDefault ? emitHelpers().createImportDefaultHelper(generatedName) : generatedName,
specifier.propertyName || specifier.name,
);
statements.push(
setOriginalNode(
setTextRange(
factory.createExpressionStatement(
createExportExpression(factory.getExportName(specifier), exportedValue, /*location*/ undefined, /*liveBinding*/ true),
),
specifier,
),
);
}
else {
const exportNeedsImportDefault = !!getESModuleInterop(compilerOptions) &&
!(getInternalEmitFlags(node) & InternalEmitFlags.NeverApplyImportHelper) &&
idText(specifier.propertyName || specifier.name) === "default";
const exportedValue = factory.createPropertyAccessExpression(
exportNeedsImportDefault ? emitHelpers().createImportDefaultHelper(generatedName) : generatedName,
specifier.propertyName || specifier.name,
);
statements.push(
setOriginalNode(
setTextRange(
factory.createExpressionStatement(
createExportExpression(factory.getExportName(specifier), exportedValue, /*location*/ undefined, /*liveBinding*/ true),
),
specifier,
),
specifier,
),
);
}
specifier,
),
);
}
return singleOrMany(statements);
@@ -2085,30 +2070,19 @@ export function transformModule(context: TransformationContext): (x: SourceFile
}
function createUnderscoreUnderscoreESModule() {
let statement: Statement;
if (languageVersion === ScriptTarget.ES3) {
statement = factory.createExpressionStatement(
createExportExpression(
factory.createIdentifier("__esModule"),
factory.createTrue(),
),
);
}
else {
statement = factory.createExpressionStatement(
factory.createCallExpression(
factory.createPropertyAccessExpression(factory.createIdentifier("Object"), "defineProperty"),
/*typeArguments*/ undefined,
[
factory.createIdentifier("exports"),
factory.createStringLiteral("__esModule"),
factory.createObjectLiteralExpression([
factory.createPropertyAssignment("value", factory.createTrue()),
]),
],
),
);
}
const statement = factory.createExpressionStatement(
factory.createCallExpression(
factory.createPropertyAccessExpression(factory.createIdentifier("Object"), "defineProperty"),
/*typeArguments*/ undefined,
[
factory.createIdentifier("exports"),
factory.createStringLiteral("__esModule"),
factory.createObjectLiteralExpression([
factory.createPropertyAssignment("value", factory.createTrue()),
]),
],
),
);
setEmitFlags(statement, EmitFlags.CustomPrologue);
return statement;
}
@@ -2140,7 +2114,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
*/
function createExportExpression(name: Identifier, value: Expression, location?: TextRange, liveBinding?: boolean) {
return setTextRange(
liveBinding && languageVersion !== ScriptTarget.ES3 ? factory.createCallExpression(
liveBinding ? factory.createCallExpression(
factory.createPropertyAccessExpression(
factory.createIdentifier("Object"),
"defineProperty",
+4 -4
View File
@@ -7365,6 +7365,7 @@ export const enum ScriptKind {
}
export const enum ScriptTarget {
/** @deprecated */
ES3 = 0,
ES5 = 1,
ES2015 = 2,
@@ -8152,10 +8153,9 @@ export const enum ExternalEmitHelpers {
ClassPrivateFieldGet = 1 << 19, // __classPrivateFieldGet (used by the class private field transformation)
ClassPrivateFieldSet = 1 << 20, // __classPrivateFieldSet (used by the class private field transformation)
ClassPrivateFieldIn = 1 << 21, // __classPrivateFieldIn (used by the class private field transformation)
CreateBinding = 1 << 22, // __createBinding (use by the module transform for (re)exports and namespace imports)
SetFunctionName = 1 << 23, // __setFunctionName (used by class fields and ECMAScript decorators)
PropKey = 1 << 24, // __propKey (used by class fields and ECMAScript decorators)
AddDisposableResourceAndDisposeResources = 1 << 25, // __addDisposableResource and __disposeResources (used by ESNext transformations)
SetFunctionName = 1 << 22, // __setFunctionName (used by class fields and ECMAScript decorators)
PropKey = 1 << 23, // __propKey (used by class fields and ECMAScript decorators)
AddDisposableResourceAndDisposeResources = 1 << 24, // __addDisposableResource and __disposeResources (used by ESNext transformations)
FirstEmitHelper = Extends,
LastEmitHelper = AddDisposableResourceAndDisposeResources,
+2 -1
View File
@@ -8622,7 +8622,8 @@ export const computedOptions = createComputedCompilerOptions({
target: {
dependencies: ["module"],
computeValue: compilerOptions => {
return compilerOptions.target ??
const target = compilerOptions.target === ScriptTarget.ES3 ? undefined : compilerOptions.target;
return target ??
((compilerOptions.module === ModuleKind.Node16 && ScriptTarget.ES2022) ||
(compilerOptions.module === ModuleKind.NodeNext && ScriptTarget.ESNext) ||
ScriptTarget.ES5);
+1
View File
@@ -3772,6 +3772,7 @@ export const enum NewLineKind {
}
export const enum ScriptTarget {
/** @deprecated */
ES3 = "ES3",
ES5 = "ES5",
ES6 = "ES6",
@@ -24,7 +24,7 @@ describe("unittests:: services:: DocumentRegistry", () => {
assert(f1 === f2, "Expected to have the same document instance");
// change value of compilation setting that is used during production of AST - new document is required
compilerOptions.target = ts.ScriptTarget.ES3;
compilerOptions.target = ts.ScriptTarget.ESNext;
const f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), /* version */ "1");
assert(f1 !== f3, "Changed target: Expected to have different instances of document");
@@ -20,7 +20,7 @@ describe("unittests:: services:: Transpile", () => {
transpileOptions.compilerOptions = {};
}
if (transpileOptions.compilerOptions.target === undefined) {
transpileOptions.compilerOptions.target = ts.ScriptTarget.ES3;
transpileOptions.compilerOptions.target = ts.ScriptTarget.ES5;
}
if (transpileOptions.compilerOptions.newLine === undefined) {
+2 -2
View File
@@ -592,13 +592,13 @@ module MyModule {
// https://github.com/Microsoft/TypeScript/issues/24709
testBaseline("issue24709", () => {
const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ true);
const transformed = ts.transform(ts.createSourceFile("source.ts", "class X { echo(x: string) { return x; } }", ts.ScriptTarget.ES3), [transformSourceFile]);
const transformed = ts.transform(ts.createSourceFile("source.ts", "class X { echo(x: string) { return x; } }", ts.ScriptTarget.ES5), [transformSourceFile]);
const transformedSourceFile = transformed.transformed[0];
transformed.dispose();
const host = new fakes.CompilerHost(fs);
host.getSourceFile = () => transformedSourceFile;
const program = ts.createProgram(["source.ts"], {
target: ts.ScriptTarget.ES3,
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.None,
noLib: true,
}, host);
+1 -1
View File
@@ -282,7 +282,7 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
fs: () => projFs,
commandLineArgs: ["--b", "tests", "--verbose"],
modifyFs: fs => {
fs.writeFileSync("tests/tsconfig.base.json", jsonToReadableText({ compilerOptions: { target: "es3" } }));
fs.writeFileSync("tests/tsconfig.base.json", jsonToReadableText({ compilerOptions: { target: "es5" } }));
replaceText(fs, "tests/tsconfig.json", `"references": [`, `"extends": "./tsconfig.base.json", "references": [`);
},
edits: [{