Skip to content

Commit a94e61b

Browse files
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript into esSymbols
Conflicts: src/compiler/diagnosticInformationMap.generated.ts
2 parents 18276e5 + f2c98ba commit a94e61b

69 files changed

Lines changed: 2233 additions & 953 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/compiler/checker.ts

Lines changed: 158 additions & 132 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ module ts {
307307
The_0_operator_cannot_be_applied_to_type_symbol: { code: 2469, category: DiagnosticCategory.Error, key: "The '{0}' operator cannot be applied to type 'symbol'." },
308308
Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object: { code: 2470, category: DiagnosticCategory.Error, key: "'Symbol' reference does not refer to the global Symbol constructor object." },
309309
A_computed_property_name_of_the_form_0_must_be_of_type_symbol: { code: 2471, category: DiagnosticCategory.Error, key: "A computed property name of the form '{0}' must be of type 'symbol'." },
310+
Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2472, category: DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." },
310311
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
311312
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
312313
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
@@ -383,6 +384,7 @@ module ts {
383384
const_enum_member_initializer_was_evaluated_to_a_non_finite_value: { code: 4086, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to a non-finite value." },
384385
const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 4087, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." },
385386
Property_0_does_not_exist_on_const_enum_1: { code: 4088, category: DiagnosticCategory.Error, key: "Property '{0}' does not exist on 'const' enum '{1}'." },
387+
let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations: { code: 4089, category: DiagnosticCategory.Error, key: "'let' is not allowed to be used as a name in 'let' or 'const' declarations." },
386388
The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
387389
Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." },
388390
Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },

src/compiler/diagnosticMessages.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,10 @@
12201220
"category": "Error",
12211221
"code": 2471
12221222
},
1223+
"Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher.": {
1224+
"category": "Error",
1225+
"code": 2472
1226+
},
12231227

12241228
"Import declaration '{0}' is using private name '{1}'.": {
12251229
"category": "Error",
@@ -1525,6 +1529,10 @@
15251529
"category": "Error",
15261530
"code": 4088
15271531
},
1532+
"'let' is not allowed to be used as a name in 'let' or 'const' declarations.": {
1533+
"category": "Error",
1534+
"code": 4089
1535+
},
15281536
"The current host does not support the '{0}' option.": {
15291537
"category": "Error",
15301538
"code": 5001

src/compiler/emitter.ts

Lines changed: 94 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ module ts {
19981998
break;
19991999
}
20002000
// _a .. _h, _j ... _z, _0, _1, ...
2001-
name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0: 1) + CharacterCodes.a) : tempCount - 25);
2001+
name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + CharacterCodes.a) : tempCount - 25);
20022002
tempCount++;
20032003
}
20042004
var result = <Identifier>createNode(SyntaxKind.Identifier);
@@ -2427,22 +2427,10 @@ module ts {
24272427
return true;
24282428
}
24292429

2430-
function emitArrayLiteral(node: ArrayLiteralExpression) {
2431-
var elements = node.elements;
2432-
var length = elements.length;
2433-
if (length === 0) {
2434-
write("[]");
2435-
return;
2436-
}
2437-
if (languageVersion >= ScriptTarget.ES6) {
2438-
write("[");
2439-
emitList(elements, 0, elements.length, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0,
2440-
/*trailingComma*/ elements.hasTrailingComma);
2441-
write("]");
2442-
return;
2443-
}
2430+
function emitListWithSpread(elements: Expression[], multiLine: boolean, trailingComma: boolean) {
24442431
var pos = 0;
24452432
var group = 0;
2433+
var length = elements.length;
24462434
while (pos < length) {
24472435
// Emit using the pattern <group0>.concat(<group1>, <group2>, ...)
24482436
if (group === 1) {
@@ -2463,8 +2451,7 @@ module ts {
24632451
i++;
24642452
}
24652453
write("[");
2466-
emitList(elements, pos, i - pos, /*multiLine*/ (node.flags & NodeFlags.MultiLine) !== 0,
2467-
/*trailingComma*/ elements.hasTrailingComma);
2454+
emitList(elements, pos, i - pos, multiLine, trailingComma && i === length);
24682455
write("]");
24692456
pos = i;
24702457
}
@@ -2475,6 +2462,23 @@ module ts {
24752462
}
24762463
}
24772464

2465+
function emitArrayLiteral(node: ArrayLiteralExpression) {
2466+
var elements = node.elements;
2467+
if (elements.length === 0) {
2468+
write("[]");
2469+
}
2470+
else if (languageVersion >= ScriptTarget.ES6) {
2471+
write("[");
2472+
emitList(elements, 0, elements.length, /*multiLine*/ (node.flags & NodeFlags.MultiLine) !== 0,
2473+
/*trailingComma*/ elements.hasTrailingComma);
2474+
write("]");
2475+
}
2476+
else {
2477+
emitListWithSpread(elements, /*multiLine*/ (node.flags & NodeFlags.MultiLine) !== 0,
2478+
/*trailingComma*/ elements.hasTrailingComma);
2479+
}
2480+
}
2481+
24782482
function emitObjectLiteral(node: ObjectLiteralExpression) {
24792483
write("{");
24802484
var properties = node.properties;
@@ -2569,7 +2573,80 @@ module ts {
25692573
write("]");
25702574
}
25712575

2576+
function hasSpreadElement(elements: Expression[]) {
2577+
return forEach(elements, e => e.kind === SyntaxKind.SpreadElementExpression);
2578+
}
2579+
2580+
function skipParentheses(node: Expression): Expression {
2581+
while (node.kind === SyntaxKind.ParenthesizedExpression || node.kind === SyntaxKind.TypeAssertionExpression) {
2582+
node = (<ParenthesizedExpression | TypeAssertion>node).expression;
2583+
}
2584+
return node;
2585+
}
2586+
2587+
function emitCallTarget(node: Expression): Expression {
2588+
if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword || node.kind === SyntaxKind.SuperKeyword) {
2589+
emit(node);
2590+
return node;
2591+
}
2592+
var temp = createTempVariable(node);
2593+
recordTempDeclaration(temp);
2594+
write("(");
2595+
emit(temp);
2596+
write(" = ");
2597+
emit(node);
2598+
write(")");
2599+
return temp;
2600+
}
2601+
2602+
function emitCallWithSpread(node: CallExpression) {
2603+
var target: Expression;
2604+
var expr = skipParentheses(node.expression);
2605+
if (expr.kind === SyntaxKind.PropertyAccessExpression) {
2606+
// Target will be emitted as "this" argument
2607+
target = emitCallTarget((<PropertyAccessExpression>expr).expression);
2608+
write(".");
2609+
emit((<PropertyAccessExpression>expr).name);
2610+
}
2611+
else if (expr.kind === SyntaxKind.ElementAccessExpression) {
2612+
// Target will be emitted as "this" argument
2613+
target = emitCallTarget((<PropertyAccessExpression>expr).expression);
2614+
write("[");
2615+
emit((<ElementAccessExpression>expr).argumentExpression);
2616+
write("]");
2617+
}
2618+
else if (expr.kind === SyntaxKind.SuperKeyword) {
2619+
target = expr;
2620+
write("_super");
2621+
}
2622+
else {
2623+
emit(node.expression);
2624+
}
2625+
write(".apply(");
2626+
if (target) {
2627+
if (target.kind === SyntaxKind.SuperKeyword) {
2628+
// Calls of form super(...) and super.foo(...)
2629+
emitThis(target);
2630+
}
2631+
else {
2632+
// Calls of form obj.foo(...)
2633+
emit(target);
2634+
}
2635+
}
2636+
else {
2637+
// Calls of form foo(...)
2638+
write("void 0");
2639+
}
2640+
write(", ");
2641+
emitListWithSpread(node.arguments, /*multiLine*/ false, /*trailingComma*/ false);
2642+
write(")");
2643+
}
2644+
25722645
function emitCallExpression(node: CallExpression) {
2646+
if (languageVersion < ScriptTarget.ES6 && hasSpreadElement(node.arguments)) {
2647+
emitCallWithSpread(node);
2648+
return;
2649+
}
25732650
var superCall = false;
25742651
if (node.expression.kind === SyntaxKind.SuperKeyword) {
25752652
write("_super");

0 commit comments

Comments
 (0)