Skip to content

Remove target=es3 #57525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion src/compiler/_namespaces/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
55 changes: 15 additions & 40 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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,
);
}

Expand Down Expand Up @@ -41465,18 +41457,18 @@ 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;
}

const promiseConstructorSymbol = resolveEntityName(promiseConstructorName, SymbolFlags.Value, /*ignoreErrors*/ true);
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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}
Expand Down
22 changes: 9 additions & 13 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
},
Expand Down
Loading