Skip to content

Commit ca3c1ed

Browse files
author
Yui T
committed
Address the issue that arrow function doesn't have arguments objects
1 parent 2e2559b commit ca3c1ed

File tree

5 files changed

+1924
-1909
lines changed

5 files changed

+1924
-1909
lines changed

src/compiler/checker.ts

+10
Original file line numberDiff line numberDiff line change
@@ -4836,6 +4836,16 @@ module ts {
48364836
function checkIdentifier(node: Identifier): Type {
48374837
var symbol = getResolvedSymbol(node);
48384838

4839+
// As noted in ECMAScript 6 language spec, arrow functions never have an arguments objects.
4840+
// Although in down-level emit of arrow function, we emit it using function expression which means that
4841+
// arguments objects will be inner bound while emitting arrow function natively in ES6, arguments objects
4842+
// will be bound to non-arrow function that contain this arrow function. This results in inconsistent bahaviour.
4843+
// To avoid that we will give an error to users if they use arguments objects in arrow function so that they
4844+
// can explicitly bound arguments objects
4845+
if (symbol === argumentsSymbol && getContainingFunction(node).kind === SyntaxKind.ArrowFunction) {
4846+
error(node, Diagnostics.An_argument_object_has_different_behaviour_across_Javascript_versions_Use_function_expression_or_rest_parameters_instead);
4847+
}
4848+
48394849
if (symbol.flags & SymbolFlags.Import) {
48404850
var symbolLinks = getSymbolLinks(symbol);
48414851
if (!symbolLinks.referenced) {

src/compiler/diagnosticInformationMap.generated.ts

+1
Original file line numberDiff line numberDiff line change
@@ -452,5 +452,6 @@ module ts {
452452
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
453453
yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported.", isEarly: true },
454454
Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported.", isEarly: true },
455+
An_argument_object_has_different_behaviour_across_Javascript_versions_Use_function_expression_or_rest_parameters_instead: { code: 9002, category: DiagnosticCategory.Error, key: "An argument object has different behaviour across Javascript versions. Use function expression or rest parameters instead" },
455456
};
456457
}

0 commit comments

Comments
 (0)