From 11d75ef4ce1d341c9cc26eb96e8dca41ba70843d Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 26 Jan 2015 14:34:22 -0800 Subject: [PATCH] Allow Symbol indexer in ES6 --- src/compiler/checker.ts | 24 ++++++++++++------- .../diagnosticInformationMap.generated.ts | 3 ++- src/compiler/diagnosticMessages.json | 7 +++++- src/compiler/utilities.ts | 7 ++++++ .../reference/arraySigChecking.errors.txt | 4 ++-- ...eReferenceWithoutTypeArgument.d.errors.txt | 4 ++-- ...ypeReferenceWithoutTypeArgument.errors.txt | 4 ++-- ...peReferenceWithoutTypeArgument2.errors.txt | 4 ++-- ...peReferenceWithoutTypeArgument3.errors.txt | 4 ++-- .../reference/indexTypeCheck.errors.txt | 4 ++-- .../parserES5SymbolIndexer1.errors.txt | 12 ++++++++++ .../parserES5SymbolIndexer2.errors.txt | 12 ++++++++++ .../parserES5SymbolIndexer3.errors.txt | 12 ++++++++++ .../parserIndexSignature6.errors.txt | 4 ++-- .../parserIndexSignature8.errors.txt | 8 +++---- .../reference/parserSymbolIndexer1.js | 6 +++++ .../reference/parserSymbolIndexer1.types | 8 +++++++ .../reference/parserSymbolIndexer2.js | 11 +++++++++ .../reference/parserSymbolIndexer2.types | 8 +++++++ .../reference/parserSymbolIndexer3.errors.txt | 9 +++++++ .../reference/parserSymbolIndexer4.js | 7 ++++++ .../reference/parserSymbolIndexer4.types | 8 +++++++ .../reference/parserSymbolIndexer5.errors.txt | 21 ++++++++++++++++ .../Symbols/parserES5SymbolIndexer1.ts | 4 ++++ .../Symbols/parserES5SymbolIndexer2.ts | 4 ++++ .../Symbols/parserES5SymbolIndexer3.ts | 4 ++++ .../Symbols/parserSymbolIndexer1.ts | 4 ++++ .../Symbols/parserSymbolIndexer2.ts | 4 ++++ .../Symbols/parserSymbolIndexer3.ts | 4 ++++ .../Symbols/parserSymbolIndexer4.ts | 4 ++++ .../Symbols/parserSymbolIndexer5.ts | 4 ++++ 31 files changed, 195 insertions(+), 28 deletions(-) create mode 100644 tests/baselines/reference/parserES5SymbolIndexer1.errors.txt create mode 100644 tests/baselines/reference/parserES5SymbolIndexer2.errors.txt create mode 100644 tests/baselines/reference/parserES5SymbolIndexer3.errors.txt create mode 100644 tests/baselines/reference/parserSymbolIndexer1.js create mode 100644 tests/baselines/reference/parserSymbolIndexer1.types create mode 100644 tests/baselines/reference/parserSymbolIndexer2.js create mode 100644 tests/baselines/reference/parserSymbolIndexer2.types create mode 100644 tests/baselines/reference/parserSymbolIndexer3.errors.txt create mode 100644 tests/baselines/reference/parserSymbolIndexer4.js create mode 100644 tests/baselines/reference/parserSymbolIndexer4.types create mode 100644 tests/baselines/reference/parserSymbolIndexer5.errors.txt create mode 100644 tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts create mode 100644 tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts create mode 100644 tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer3.ts create mode 100644 tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer1.ts create mode 100644 tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer2.ts create mode 100644 tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts create mode 100644 tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer4.ts create mode 100644 tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer5.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7c43b8bb233..56f5ec09001 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10472,25 +10472,33 @@ module ts { return grammarErrorOnNode(node, Diagnostics.An_index_signature_must_have_exactly_one_parameter); } } - else if (parameter.dotDotDotToken) { + if (parameter.dotDotDotToken) { return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.An_index_signature_cannot_have_a_rest_parameter); } - else if (parameter.flags & NodeFlags.Modifier) { + if (parameter.flags & NodeFlags.Modifier) { return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); } - else if (parameter.questionToken) { + if (parameter.questionToken) { return grammarErrorOnNode(parameter.questionToken, Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark); } - else if (parameter.initializer) { + if (parameter.initializer) { return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_an_initializer); } - else if (!parameter.type) { + if (!parameter.type) { return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); } - else if (parameter.type.kind !== SyntaxKind.StringKeyword && parameter.type.kind !== SyntaxKind.NumberKeyword) { - return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); + if (parameter.type.kind !== SyntaxKind.StringKeyword && parameter.type.kind !== SyntaxKind.NumberKeyword) { + if (isESSymbolTypeNode(parameter.type)) { + if (languageVersion < ScriptTarget.ES6) { + return grammarErrorOnNode(parameter.type, Diagnostics.Symbol_indexers_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + // No error for parameter type + } + else { + return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_must_be_string_number_or_Symbol); + } } - else if (!node.type) { + if (!node.type) { return grammarErrorOnNode(node, Diagnostics.An_index_signature_must_have_a_type_annotation); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 1188d346191..c6a7ad81334 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -19,7 +19,7 @@ module ts { An_index_signature_parameter_cannot_have_an_initializer: { code: 1020, category: DiagnosticCategory.Error, key: "An index signature parameter cannot have an initializer." }, An_index_signature_must_have_a_type_annotation: { code: 1021, category: DiagnosticCategory.Error, key: "An index signature must have a type annotation." }, An_index_signature_parameter_must_have_a_type_annotation: { code: 1022, category: DiagnosticCategory.Error, key: "An index signature parameter must have a type annotation." }, - An_index_signature_parameter_type_must_be_string_or_number: { code: 1023, category: DiagnosticCategory.Error, key: "An index signature parameter type must be 'string' or 'number'." }, + An_index_signature_parameter_type_must_be_string_number_or_Symbol: { code: 1023, category: DiagnosticCategory.Error, key: "An index signature parameter type must be 'string', 'number', or 'Symbol'." }, A_class_or_interface_declaration_can_only_have_one_extends_clause: { code: 1024, category: DiagnosticCategory.Error, key: "A class or interface declaration can only have one 'extends' clause." }, An_extends_clause_must_precede_an_implements_clause: { code: 1025, category: DiagnosticCategory.Error, key: "An 'extends' clause must precede an 'implements' clause." }, A_class_can_only_extend_a_single_class: { code: 1026, category: DiagnosticCategory.Error, key: "A class can only extend a single class." }, @@ -147,6 +147,7 @@ module ts { Merge_conflict_marker_encountered: { code: 1185, category: DiagnosticCategory.Error, key: "Merge conflict marker encountered." }, A_rest_element_cannot_have_an_initializer: { code: 1186, category: DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." }, + Symbol_indexers_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1188, category: DiagnosticCategory.Error, key: "'Symbol' indexers are only available when targeting ECMAScript 6 and higher.", isEarly: true }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b1a794716a4..0cf83d7b185 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -67,7 +67,7 @@ "category": "Error", "code": 1022 }, - "An index signature parameter type must be 'string' or 'number'.": { + "An index signature parameter type must be 'string', 'number', or 'Symbol'.": { "category": "Error", "code": 1023 }, @@ -579,6 +579,11 @@ "category": "Error", "code": 1187 }, + "'Symbol' indexers are only available when targeting ECMAScript 6 and higher.": { + "category": "Error", + "code": 1188, + "isEarly": true + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 5a50e2799dc..8c3dd112b15 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -835,6 +835,13 @@ module ts { return SyntaxKind.FirstTriviaToken <= token && token <= SyntaxKind.LastTriviaToken; } + export function isESSymbolTypeNode(node: Node): boolean { + return node.kind === SyntaxKind.TypeReference && + (node).typeArguments === undefined && + (node).typeName.kind === SyntaxKind.Identifier && + ((node).typeName).text === "Symbol"; + } + export function isModifier(token: SyntaxKind): boolean { switch (token) { case SyntaxKind.PublicKeyword: diff --git a/tests/baselines/reference/arraySigChecking.errors.txt b/tests/baselines/reference/arraySigChecking.errors.txt index b70b659773c..82a32dbda4d 100644 --- a/tests/baselines/reference/arraySigChecking.errors.txt +++ b/tests/baselines/reference/arraySigChecking.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/arraySigChecking.ts(11,17): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/compiler/arraySigChecking.ts(11,17): error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. tests/cases/compiler/arraySigChecking.ts(18,5): error TS2322: Type 'void[]' is not assignable to type 'string[]'. Type 'void' is not assignable to type 'string'. tests/cases/compiler/arraySigChecking.ts(22,1): error TS2322: Type 'number[][]' is not assignable to type 'number[][][]'. @@ -20,7 +20,7 @@ tests/cases/compiler/arraySigChecking.ts(22,1): error TS2322: Type 'number[][]' var foo: { [index: any]; }; // expect an error here ~~~~~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. } interface myInt { diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.errors.txt index 6c98d419dec..68543a10b01 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.errors.txt +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(10,21): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(11,22): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(11,26): error TS2314: Generic type 'C' requires 1 type argument(s). -tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(12,19): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(12,19): error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(12,22): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(12,26): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(14,23): error TS2314: Generic type 'C' requires 1 type argument(s). @@ -36,7 +36,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc !!! error TS2314: Generic type 'C' requires 1 type argument(s). declare var d: { [x: C]: C }; ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.errors.txt index d57f3c2fc0d..9076b86ff3e 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.errors.txt +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(10,13): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(11,14): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(11,18): error TS2314: Generic type 'C' requires 1 type argument(s). -tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(12,11): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(12,11): error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(12,14): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(12,18): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(14,13): error TS2314: Generic type 'C' requires 1 type argument(s). @@ -46,7 +46,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc !!! error TS2314: Generic type 'C' requires 1 type argument(s). var d: { [x: C]: C }; ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt index 745da9aa106..ca79c04f6ed 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(10,13): error TS2314: Generic type 'I' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(11,14): error TS2314: Generic type 'I' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(11,18): error TS2314: Generic type 'I' requires 1 type argument(s). -tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(12,11): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(12,11): error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(12,14): error TS2314: Generic type 'I' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(12,18): error TS2314: Generic type 'I' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(14,13): error TS2314: Generic type 'I' requires 1 type argument(s). @@ -46,7 +46,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc !!! error TS2314: Generic type 'I' requires 1 type argument(s). var d: { [x: I]: I }; ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. ~ !!! error TS2314: Generic type 'I' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.errors.txt index 1fec52356a2..7154a90cb8a 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.errors.txt +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(10,21): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(11,22): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(11,26): error TS2314: Generic type 'C' requires 1 type argument(s). -tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(12,19): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(12,19): error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(12,22): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(12,26): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(14,23): error TS2314: Generic type 'C' requires 1 type argument(s). @@ -36,7 +36,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc !!! error TS2314: Generic type 'C' requires 1 type argument(s). declare var d: { [x: C]: C }; ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/indexTypeCheck.errors.txt b/tests/baselines/reference/indexTypeCheck.errors.txt index 03d0e2ce8ed..0914ea9ca7b 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -4,7 +4,7 @@ tests/cases/compiler/indexTypeCheck.ts(17,2): error TS2413: Numeric index type ' tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'. tests/cases/compiler/indexTypeCheck.ts(27,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. tests/cases/compiler/indexTypeCheck.ts(32,3): error TS1096: An index signature must have exactly one parameter. -tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression argument must be of type 'string', 'number', or 'any'. @@ -58,7 +58,7 @@ tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression interface Magenta { [p:Purple]; // error ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. } var yellow: Yellow; diff --git a/tests/baselines/reference/parserES5SymbolIndexer1.errors.txt b/tests/baselines/reference/parserES5SymbolIndexer1.errors.txt new file mode 100644 index 00000000000..8128f95d3b6 --- /dev/null +++ b/tests/baselines/reference/parserES5SymbolIndexer1.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts(2,9): error TS1188: 'Symbol' indexers are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts(2,9): error TS2304: Cannot find name 'Symbol'. + + +==== tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts (2 errors) ==== + interface I { + [s: Symbol]: string; + ~~~~~~ +!!! error TS1188: 'Symbol' indexers are only available when targeting ECMAScript 6 and higher. + ~~~~~~ +!!! error TS2304: Cannot find name 'Symbol'. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5SymbolIndexer2.errors.txt b/tests/baselines/reference/parserES5SymbolIndexer2.errors.txt new file mode 100644 index 00000000000..b1904d0fe53 --- /dev/null +++ b/tests/baselines/reference/parserES5SymbolIndexer2.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts(2,9): error TS1188: 'Symbol' indexers are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts(2,9): error TS2304: Cannot find name 'Symbol'. + + +==== tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts (2 errors) ==== + class C { + [s: Symbol]: string; + ~~~~~~ +!!! error TS1188: 'Symbol' indexers are only available when targeting ECMAScript 6 and higher. + ~~~~~~ +!!! error TS2304: Cannot find name 'Symbol'. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5SymbolIndexer3.errors.txt b/tests/baselines/reference/parserES5SymbolIndexer3.errors.txt new file mode 100644 index 00000000000..bc1bc64aeda --- /dev/null +++ b/tests/baselines/reference/parserES5SymbolIndexer3.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer3.ts(2,9): error TS1188: 'Symbol' indexers are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer3.ts(2,9): error TS2304: Cannot find name 'Symbol'. + + +==== tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer3.ts (2 errors) ==== + var x: { + [s: Symbol]: string; + ~~~~~~ +!!! error TS1188: 'Symbol' indexers are only available when targeting ECMAScript 6 and higher. + ~~~~~~ +!!! error TS2304: Cannot find name 'Symbol'. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexSignature6.errors.txt b/tests/baselines/reference/parserIndexSignature6.errors.txt index db53f219832..eae5aae90c9 100644 --- a/tests/baselines/reference/parserIndexSignature6.errors.txt +++ b/tests/baselines/reference/parserIndexSignature6.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature6.ts(2,4): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature6.ts(2,4): error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. ==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature6.ts (1 errors) ==== interface I { [a:boolean] ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexSignature8.errors.txt b/tests/baselines/reference/parserIndexSignature8.errors.txt index 87369df1b76..859d373eca4 100644 --- a/tests/baselines/reference/parserIndexSignature8.errors.txt +++ b/tests/baselines/reference/parserIndexSignature8.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts(1,13): error TS1023: An index signature parameter type must be 'string' or 'number'. -tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts(2,14): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts(1,13): error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. +tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts(2,14): error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. ==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts (2 errors) ==== var foo: { [index: any]; }; // expect an error here ~~~~~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. var foo2: { [index: RegExp]; }; // expect an error here ~~~~~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be 'string', 'number', or 'Symbol'. \ No newline at end of file diff --git a/tests/baselines/reference/parserSymbolIndexer1.js b/tests/baselines/reference/parserSymbolIndexer1.js new file mode 100644 index 00000000000..4c99edda168 --- /dev/null +++ b/tests/baselines/reference/parserSymbolIndexer1.js @@ -0,0 +1,6 @@ +//// [parserSymbolIndexer1.ts] +interface I { + [s: Symbol]: string; +} + +//// [parserSymbolIndexer1.js] diff --git a/tests/baselines/reference/parserSymbolIndexer1.types b/tests/baselines/reference/parserSymbolIndexer1.types new file mode 100644 index 00000000000..86020c8cbdd --- /dev/null +++ b/tests/baselines/reference/parserSymbolIndexer1.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer1.ts === +interface I { +>I : I + + [s: Symbol]: string; +>s : Symbol +>Symbol : Symbol +} diff --git a/tests/baselines/reference/parserSymbolIndexer2.js b/tests/baselines/reference/parserSymbolIndexer2.js new file mode 100644 index 00000000000..1acae44ae2a --- /dev/null +++ b/tests/baselines/reference/parserSymbolIndexer2.js @@ -0,0 +1,11 @@ +//// [parserSymbolIndexer2.ts] +class C { + [s: Symbol]: string; +} + +//// [parserSymbolIndexer2.js] +var C = (function () { + function C() { + } + return C; +})(); diff --git a/tests/baselines/reference/parserSymbolIndexer2.types b/tests/baselines/reference/parserSymbolIndexer2.types new file mode 100644 index 00000000000..ffa9ff96346 --- /dev/null +++ b/tests/baselines/reference/parserSymbolIndexer2.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer2.ts === +class C { +>C : C + + [s: Symbol]: string; +>s : Symbol +>Symbol : Symbol +} diff --git a/tests/baselines/reference/parserSymbolIndexer3.errors.txt b/tests/baselines/reference/parserSymbolIndexer3.errors.txt new file mode 100644 index 00000000000..f5066a09ee9 --- /dev/null +++ b/tests/baselines/reference/parserSymbolIndexer3.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts(2,5): error TS1145: Modifiers not permitted on index signature members. + + +==== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts (1 errors) ==== + class C { + static [s: Symbol]: string; + ~~~~~~ +!!! error TS1145: Modifiers not permitted on index signature members. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserSymbolIndexer4.js b/tests/baselines/reference/parserSymbolIndexer4.js new file mode 100644 index 00000000000..607b1ada481 --- /dev/null +++ b/tests/baselines/reference/parserSymbolIndexer4.js @@ -0,0 +1,7 @@ +//// [parserSymbolIndexer4.ts] +var x: { + [s: Symbol]: string; +} + +//// [parserSymbolIndexer4.js] +var x; diff --git a/tests/baselines/reference/parserSymbolIndexer4.types b/tests/baselines/reference/parserSymbolIndexer4.types new file mode 100644 index 00000000000..0f632e5dc32 --- /dev/null +++ b/tests/baselines/reference/parserSymbolIndexer4.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer4.ts === +var x: { +>x : {} + + [s: Symbol]: string; +>s : Symbol +>Symbol : Symbol +} diff --git a/tests/baselines/reference/parserSymbolIndexer5.errors.txt b/tests/baselines/reference/parserSymbolIndexer5.errors.txt new file mode 100644 index 00000000000..611ad109a34 --- /dev/null +++ b/tests/baselines/reference/parserSymbolIndexer5.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer5.ts(2,6): error TS2304: Cannot find name 's'. +tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer5.ts(2,7): error TS1005: ']' expected. +tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer5.ts(2,15): error TS1005: ',' expected. +tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer5.ts(2,16): error TS1136: Property assignment expected. +tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer5.ts(3,1): error TS1005: ':' expected. + + +==== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer5.ts (5 errors) ==== + var x = { + [s: Symbol]: "" + ~ +!!! error TS2304: Cannot find name 's'. + ~ +!!! error TS1005: ']' expected. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1136: Property assignment expected. + } + ~ +!!! error TS1005: ':' expected. \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts b/tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts new file mode 100644 index 00000000000..f90f804a615 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts @@ -0,0 +1,4 @@ +//@target: ES5 +interface I { + [s: Symbol]: string; +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts b/tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts new file mode 100644 index 00000000000..1f13320f5d1 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts @@ -0,0 +1,4 @@ +//@target: ES5 +class C { + [s: Symbol]: string; +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer3.ts b/tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer3.ts new file mode 100644 index 00000000000..1e3829f9e40 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer3.ts @@ -0,0 +1,4 @@ +//@target: ES5 +var x: { + [s: Symbol]: string; +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer1.ts b/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer1.ts new file mode 100644 index 00000000000..668ebb496f4 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer1.ts @@ -0,0 +1,4 @@ +//@target: ES6 +interface I { + [s: Symbol]: string; +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer2.ts b/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer2.ts new file mode 100644 index 00000000000..cf4ee50974e --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer2.ts @@ -0,0 +1,4 @@ +//@target: ES6 +class C { + [s: Symbol]: string; +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts b/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts new file mode 100644 index 00000000000..f7f7154af35 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts @@ -0,0 +1,4 @@ +//@target: ES6 +class C { + static [s: Symbol]: string; +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer4.ts b/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer4.ts new file mode 100644 index 00000000000..99e8112ce55 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer4.ts @@ -0,0 +1,4 @@ +//@target: ES6 +var x: { + [s: Symbol]: string; +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer5.ts b/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer5.ts new file mode 100644 index 00000000000..8c468043a8f --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer5.ts @@ -0,0 +1,4 @@ +//@target: ES6 +var x = { + [s: Symbol]: "" +} \ No newline at end of file