Merge branch 'master' into fixArrowBindingPattern

This commit is contained in:
Ron Buckton 2015-04-10 09:54:13 -07:00
commit 042b96592a
277 changed files with 5916 additions and 932 deletions

View File

@ -25,7 +25,7 @@ Your pull request should:
* Tests should include reasonable permutations of the target fix/change
* Include baseline changes with your change
* All changed code must have 100% code coverage
* Follow the code conventions descriped in [Coding guidlines](https://github.com/Microsoft/TypeScript/wiki/Coding-guidlines)
* Follow the code conventions descriped in [Coding guidelines](https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines)
* To avoid line ending issues, set `autocrlf = input` and `whitespace = cr-at-eol` in your git configuration
## Running the Tests

View File

@ -2078,15 +2078,20 @@ module ts {
}
}
else {
// For an array binding element the specified or inferred type of the parent must be an array-like type
if (!isArrayLikeType(parentType)) {
error(pattern, Diagnostics.Type_0_is_not_an_array_type, typeToString(parentType));
return unknownType;
}
// This elementType will be used if the specific property corresponding to this index is not
// present (aka the tuple element property). This call also checks that the parentType is in
// fact an iterable or array (depending on target language).
let elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false);
if (!declaration.dotDotDotToken) {
if (elementType.flags & TypeFlags.Any) {
return elementType;
}
// Use specific property type when parent is a tuple or numeric index type when parent is an array
let propName = "" + indexOf(pattern.elements, declaration);
type = isTupleLikeType(parentType) ? getTypeOfPropertyOfType(parentType, propName) : getIndexTypeOfType(parentType, IndexKind.Number);
type = isTupleLikeType(parentType)
? getTypeOfPropertyOfType(parentType, propName)
: elementType;
if (!type) {
if (isTupleType(parentType)) {
error(declaration, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(parentType), (<TupleType>parentType).elementTypes.length, pattern.elements.length);
@ -2099,7 +2104,7 @@ module ts {
}
else {
// Rest element has an array type with the same element type as the parent type
type = createArrayType(getIndexTypeOfType(parentType, IndexKind.Number));
type = createArrayType(elementType);
}
}
return type;
@ -2188,7 +2193,34 @@ module ts {
hasSpreadElement = true;
}
});
return !elementTypes.length ? anyArrayType : hasSpreadElement ? createArrayType(getUnionType(elementTypes)) : createTupleType(elementTypes);
if (!elementTypes.length) {
return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType;
}
else if (hasSpreadElement) {
let unionOfElements = getUnionType(elementTypes);
if (languageVersion >= ScriptTarget.ES6) {
// If the user has something like:
//
// function fun(...[a, ...b]) { }
//
// Normally, in ES6, the implied type of an array binding pattern with a rest element is
// an iterable. However, there is a requirement in our type system that all rest
// parameters be array types. To satisfy this, we have an exception to the rule that
// says the type of an array binding pattern with a rest element is an array type
// if it is *itself* in a rest parameter. It will still be compatible with a spreaded
// iterable argument, but within the function it will be an array.
let parent = pattern.parent;
let isRestParameter = parent.kind === SyntaxKind.Parameter &&
pattern === (<ParameterDeclaration>parent).name &&
(<ParameterDeclaration>parent).dotDotDotToken !== undefined;
return isRestParameter ? createArrayType(unionOfElements) : createIterableType(unionOfElements);
}
return createArrayType(unionOfElements);
}
// If the pattern has at least one element, and no rest element, then it should imply a tuple type.
return createTupleType(elementTypes);
}
// Return the type implied by a binding pattern. This is the type implied purely by the binding pattern itself
@ -3461,6 +3493,10 @@ module ts {
return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"));
}
function createIterableType(elementType: Type): Type {
return globalIterableType !== emptyObjectType ? createTypeReference(<GenericType>globalIterableType, [elementType]) : emptyObjectType;
}
function createArrayType(elementType: Type): Type {
// globalArrayType will be undefined if we get here during creation of the Array type. This for example happens if
// user code augments the Array type with call or construct signatures that have an array type as the return type.
@ -5546,7 +5582,7 @@ module ts {
needToCaptureLexicalThis = false;
while (container && container.kind === SyntaxKind.ArrowFunction) {
container = getSuperContainer(container, /*includeFunctions*/ true);
needToCaptureLexicalThis = true;
needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6;
}
// topmost container must be something that is directly nested in the class declaration
@ -5968,12 +6004,14 @@ module ts {
}
function checkSpreadElementExpression(node: SpreadElementExpression, contextualMapper?: TypeMapper): Type {
let type = checkExpressionCached(node.expression, contextualMapper);
if (!isArrayLikeType(type)) {
error(node.expression, Diagnostics.Type_0_is_not_an_array_type, typeToString(type));
return unknownType;
}
return type;
// It is usually not safe to call checkExpressionCached if we can be contextually typing.
// You can tell that we are contextually typing because of the contextualMapper parameter.
// While it is true that a spread element can have a contextual type, it does not do anything
// with this type. It is neither affected by it, nor does it propagate it to its operand.
// So the fact that contextualMapper is passed is not important, because the operand of a spread
// element is not contextually typed.
let arrayOrIterableType = checkExpressionCached(node.expression, contextualMapper);
return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, /*allowStringInput*/ false);
}
function checkArrayLiteral(node: ArrayLiteralExpression, contextualMapper?: TypeMapper): Type {
@ -5981,18 +6019,13 @@ module ts {
if (!elements.length) {
return createArrayType(undefinedType);
}
let hasSpreadElement: boolean = false;
let hasSpreadElement = false;
let elementTypes: Type[] = [];
forEach(elements, e => {
for (let e of elements) {
let type = checkExpression(e, contextualMapper);
if (e.kind === SyntaxKind.SpreadElementExpression) {
elementTypes.push(getIndexTypeOfType(type, IndexKind.Number) || anyType);
hasSpreadElement = true;
}
else {
elementTypes.push(type);
}
});
elementTypes.push(type);
hasSpreadElement = hasSpreadElement || e.kind === SyntaxKind.SpreadElementExpression;
}
if (!hasSpreadElement) {
let contextualType = getContextualType(node);
if (contextualType && contextualTypeIsTupleLikeType(contextualType) || isAssignmentTarget(node)) {
@ -6615,7 +6648,7 @@ module ts {
for (let i = 0; i < args.length; i++) {
let arg = args[i];
if (arg.kind !== SyntaxKind.OmittedExpression) {
let paramType = getTypeAtPosition(signature, arg.kind === SyntaxKind.SpreadElementExpression ? -1 : i);
let paramType = getTypeAtPosition(signature, i);
let argType: Type;
if (i === 0 && args[i].parent.kind === SyntaxKind.TaggedTemplateExpression) {
argType = globalTemplateStringsArrayType;
@ -6638,7 +6671,7 @@ module ts {
// No need to check for omitted args and template expressions, their exlusion value is always undefined
if (excludeArgument[i] === false) {
let arg = args[i];
let paramType = getTypeAtPosition(signature, arg.kind === SyntaxKind.SpreadElementExpression ? -1 : i);
let paramType = getTypeAtPosition(signature, i);
inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType);
}
}
@ -6671,7 +6704,7 @@ module ts {
let arg = args[i];
if (arg.kind !== SyntaxKind.OmittedExpression) {
// Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter)
let paramType = getTypeAtPosition(signature, arg.kind === SyntaxKind.SpreadElementExpression ? -1 : i);
let paramType = getTypeAtPosition(signature, i);
// A tagged template expression provides a special first argument, and string literals get string literal types
// unless we're reporting errors
let argType = i === 0 && node.kind === SyntaxKind.TaggedTemplateExpression ? globalTemplateStringsArrayType :
@ -7145,14 +7178,9 @@ module ts {
}
function getTypeAtPosition(signature: Signature, pos: number): Type {
if (pos >= 0) {
return signature.hasRestParameter ?
pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) :
pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType;
}
return signature.hasRestParameter ?
getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]) :
anyArrayType;
pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) :
pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType;
}
function assignContextualParameterTypes(signature: Signature, context: Signature, mapper: TypeMapper) {
@ -7588,11 +7616,10 @@ module ts {
}
function checkArrayLiteralAssignment(node: ArrayLiteralExpression, sourceType: Type, contextualMapper?: TypeMapper): Type {
// TODOO(andersh): Allow iterable source type in ES6
if (!isArrayLikeType(sourceType)) {
error(node, Diagnostics.Type_0_is_not_an_array_type, typeToString(sourceType));
return sourceType;
}
// This elementType will be used if the specific property corresponding to this index is not
// present (aka the tuple element property). This call also checks that the parentType is in
// fact an iterable or array (depending on target language).
let elementType = checkIteratedTypeOrElementType(sourceType, node, /*allowStringInput*/ false);
let elements = node.elements;
for (let i = 0; i < elements.length; i++) {
let e = elements[i];
@ -7600,8 +7627,9 @@ module ts {
if (e.kind !== SyntaxKind.SpreadElementExpression) {
let propName = "" + i;
let type = sourceType.flags & TypeFlags.Any ? sourceType :
isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) :
getIndexTypeOfType(sourceType, IndexKind.Number);
isTupleLikeType(sourceType)
? getTypeOfPropertyOfType(sourceType, propName)
: elementType;
if (type) {
checkDestructuringAssignment(e, type, contextualMapper);
}
@ -7616,7 +7644,7 @@ module ts {
}
else {
if (i === elements.length - 1) {
checkReferenceAssignment((<SpreadElementExpression>e).expression, sourceType, contextualMapper);
checkReferenceAssignment((<SpreadElementExpression>e).expression, createArrayType(elementType), contextualMapper);
}
else {
error(e, Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
@ -9373,29 +9401,41 @@ module ts {
function checkRightHandSideOfForOf(rhsExpression: Expression): Type {
let expressionType = getTypeOfExpression(rhsExpression);
return languageVersion >= ScriptTarget.ES6
? checkIteratedType(expressionType, rhsExpression)
: checkElementTypeOfArrayOrString(expressionType, rhsExpression);
return checkIteratedTypeOrElementType(expressionType, rhsExpression, /*allowStringInput*/ true);
}
function checkIteratedTypeOrElementType(inputType: Type, errorNode: Node, allowStringInput: boolean): Type {
if (languageVersion >= ScriptTarget.ES6) {
return checkIteratedType(inputType, errorNode) || anyType;
}
if (allowStringInput) {
return checkElementTypeOfArrayOrString(inputType, errorNode);
}
if (isArrayLikeType(inputType)) {
return getIndexTypeOfType(inputType, IndexKind.Number);
}
error(errorNode, Diagnostics.Type_0_is_not_an_array_type, typeToString(inputType));
return unknownType;
}
/**
* When expressionForError is undefined, it means we should not report any errors.
* When errorNode is undefined, it means we should not report any errors.
*/
function checkIteratedType(iterable: Type, expressionForError: Expression): Type {
function checkIteratedType(iterable: Type, errorNode: Node): Type {
Debug.assert(languageVersion >= ScriptTarget.ES6);
let iteratedType = getIteratedType(iterable, expressionForError);
let iteratedType = getIteratedType(iterable, errorNode);
// Now even though we have extracted the iteratedType, we will have to validate that the type
// passed in is actually an Iterable.
if (expressionForError && iteratedType) {
let completeIterableType = globalIterableType !== emptyObjectType
? createTypeReference(<GenericType>globalIterableType, [iteratedType])
: emptyObjectType;
checkTypeAssignableTo(iterable, completeIterableType, expressionForError);
if (errorNode && iteratedType) {
checkTypeAssignableTo(iterable, createIterableType(iteratedType), errorNode);
}
return iteratedType;
function getIteratedType(iterable: Type, expressionForError: Expression) {
function getIteratedType(iterable: Type, errorNode: Node) {
// We want to treat type as an iterable, and get the type it is an iterable of. The iterable
// must have the following structure (annotated with the names of the variables below):
//
@ -9426,6 +9466,12 @@ module ts {
return undefined;
}
// As an optimization, if the type is instantiated directly using the globalIterableType (Iterable<number>),
// then just grab its type argument.
if ((iterable.flags & TypeFlags.Reference) && (<GenericType>iterable).target === globalIterableType) {
return (<GenericType>iterable).typeArguments[0];
}
let iteratorFunction = getTypeOfPropertyOfType(iterable, getPropertyNameForKnownSymbolName("iterator"));
if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, TypeFlags.Any)) {
return undefined;
@ -9433,8 +9479,8 @@ module ts {
let iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, SignatureKind.Call) : emptyArray;
if (iteratorFunctionSignatures.length === 0) {
if (expressionForError) {
error(expressionForError, Diagnostics.The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
if (errorNode) {
error(errorNode, Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
}
return undefined;
}
@ -9451,8 +9497,8 @@ module ts {
let iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, SignatureKind.Call) : emptyArray;
if (iteratorNextFunctionSignatures.length === 0) {
if (expressionForError) {
error(expressionForError, Diagnostics.The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method);
if (errorNode) {
error(errorNode, Diagnostics.An_iterator_must_have_a_next_method);
}
return undefined;
}
@ -9464,8 +9510,8 @@ module ts {
let iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value");
if (!iteratorNextValue) {
if (expressionForError) {
error(expressionForError, Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
if (errorNode) {
error(errorNode, Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
}
return undefined;
}
@ -9491,7 +9537,7 @@ module ts {
* 1. Some constituent is neither a string nor an array.
* 2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
*/
function checkElementTypeOfArrayOrString(arrayOrStringType: Type, expressionForError: Expression): Type {
function checkElementTypeOfArrayOrString(arrayOrStringType: Type, errorNode: Node): Type {
Debug.assert(languageVersion < ScriptTarget.ES6);
// After we remove all types that are StringLike, we will know if there was a string constituent
@ -9502,7 +9548,7 @@ module ts {
let reportedError = false;
if (hasStringConstituent) {
if (languageVersion < ScriptTarget.ES5) {
error(expressionForError, Diagnostics.Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher);
error(errorNode, Diagnostics.Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher);
reportedError = true;
}
@ -9522,7 +9568,7 @@ module ts {
let diagnostic = hasStringConstituent
? Diagnostics.Type_0_is_not_an_array_type
: Diagnostics.Type_0_is_not_an_array_type_or_a_string_type;
error(expressionForError, diagnostic, typeToString(arrayType));
error(errorNode, diagnostic, typeToString(arrayType));
}
return hasStringConstituent ? stringType : unknownType;
}

View File

@ -434,7 +434,7 @@ module ts {
return path.replace(/\\/g, "/");
}
// Returns length of path root (i.e. length of "/", "x:/", "//server/share/")
// Returns length of path root (i.e. length of "/", "x:/", "//server/share/, file:///user/files")
export function getRootLength(path: string): number {
if (path.charCodeAt(0) === CharacterCodes.slash) {
if (path.charCodeAt(1) !== CharacterCodes.slash) return 1;
@ -448,6 +448,8 @@ module ts {
if (path.charCodeAt(2) === CharacterCodes.slash) return 3;
return 2;
}
let idx = path.indexOf('://');
if (idx !== -1) return idx + 3
return 0;
}

View File

@ -344,8 +344,8 @@ module ts {
The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant: { code: 2485, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...of' statement cannot be a previously defined constant." },
The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant: { code: 2486, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot be a previously defined constant." },
Invalid_left_hand_side_in_for_of_statement: { code: 2487, category: DiagnosticCategory.Error, key: "Invalid left-hand side in 'for...of' statement." },
The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator: { code: 2488, category: DiagnosticCategory.Error, key: "The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator." },
The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method: { code: 2489, category: DiagnosticCategory.Error, key: "The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method." },
Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator: { code: 2488, category: DiagnosticCategory.Error, key: "Type must have a '[Symbol.iterator]()' method that returns an iterator." },
An_iterator_must_have_a_next_method: { code: 2489, category: DiagnosticCategory.Error, key: "An iterator must have a 'next()' method." },
The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property: { code: 2490, category: DiagnosticCategory.Error, key: "The type returned by the 'next()' method of an iterator must have a 'value' property." },
The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern: { code: 2491, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot be a destructuring pattern." },
Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: DiagnosticCategory.Error, key: "Cannot redeclare identifier '{0}' in catch clause" },

View File

@ -1367,11 +1367,11 @@
"category": "Error",
"code": 2487
},
"The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator.": {
"Type must have a '[Symbol.iterator]()' method that returns an iterator.": {
"category": "Error",
"code": 2488
},
"The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method.": {
"An iterator must have a 'next()' method.": {
"category": "Error",
"code": 2489
},

View File

@ -5309,7 +5309,7 @@ module ts {
break;
}
let range = { pos: triviaScanner.getTokenPos(), end: triviaScanner.getTextPos() };
let range = { pos: triviaScanner.getTokenPos(), end: triviaScanner.getTextPos(), kind: triviaScanner.getToken() };
let comment = sourceText.substring(range.pos, range.end);
let referencePathMatchResult = getFileReferenceFromReferencePath(comment, range);

View File

@ -523,6 +523,7 @@ module ts {
let nextChar = text.charCodeAt(pos + 1);
let hasTrailingNewLine = false;
if (nextChar === CharacterCodes.slash || nextChar === CharacterCodes.asterisk) {
let kind = nextChar === CharacterCodes.slash ? SyntaxKind.SingleLineCommentTrivia : SyntaxKind.MultiLineCommentTrivia;
let startPos = pos;
pos += 2;
if (nextChar === CharacterCodes.slash) {
@ -548,7 +549,7 @@ module ts {
result = [];
}
result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine });
result.push({ pos: startPos, end: pos, hasTrailingNewLine, kind });
}
continue;
}

View File

@ -985,6 +985,7 @@ module ts {
export interface CommentRange extends TextRange {
hasTrailingNewLine?: boolean;
kind: SyntaxKind;
}
// Source files are declarations when they are external modules.

View File

@ -160,6 +160,14 @@ module ts {
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
}
export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFile): number {
if (nodeIsMissing(node) || !node.decorators) {
return getTokenPosOfNode(node, sourceFile);
}
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.decorators.end);
}
export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node): string {
if (nodeIsMissing(node)) {
return "";
@ -780,6 +788,8 @@ module ts {
return node === (<TemplateSpan>parent).expression;
case SyntaxKind.ComputedPropertyName:
return node === (<ComputedPropertyName>parent).expression;
case SyntaxKind.Decorator:
return true;
default:
if (isExpression(parent)) {
return true;

View File

@ -336,6 +336,9 @@ module Harness.LanguageService {
getOccurrencesAtPosition(fileName: string, position: number): ts.ReferenceEntry[] {
return unwrapJSONCallResult(this.shim.getOccurrencesAtPosition(fileName, position));
}
getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): ts.DocumentHighlights[] {
return unwrapJSONCallResult(this.shim.getDocumentHighlights(fileName, position, JSON.stringify(filesToSearch)));
}
getNavigateToItems(searchValue: string): ts.NavigateToItem[] {
return unwrapJSONCallResult(this.shim.getNavigateToItems(searchValue));
}

View File

@ -52,6 +52,7 @@ class TypeWriterWalker {
case ts.SyntaxKind.PostfixUnaryExpression:
case ts.SyntaxKind.BinaryExpression:
case ts.SyntaxKind.ConditionalExpression:
case ts.SyntaxKind.SpreadElementExpression:
this.log(node, this.getTypeOfNode(node));
break;

2
src/lib/core.d.ts vendored
View File

@ -823,7 +823,7 @@ interface RegExp {
*/
test(string: string): boolean;
/** Returns a copy of the text of the regular expression pattern. Read-only. The rgExp argument is a Regular expression object. It can be a variable name or a literal. */
/** Returns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal. */
source: string;
/** Returns a Boolean value indicating the state of the global flag (g) used with a regular expression. Default is false. Read-only. */

31
src/lib/es6.d.ts vendored
View File

@ -50,26 +50,21 @@ interface SymbolConstructor {
*/
isConcatSpreadable: symbol;
/**
* A Boolean value that if true indicates that an object may be used as a regular expression.
*/
isRegExp: symbol;
/**
* A method that returns the default iterator for an object.Called by the semantics of the
* for-of statement.
* for-of statement.
*/
iterator: symbol;
/**
* A method that converts an object to a corresponding primitive value.Called by the ToPrimitive
* abstract operation.
* abstract operation.
*/
toPrimitive: symbol;
/**
* A String value that is used in the creation of the default string description of an object.
* Called by the built- in method Object.prototype.toString.
* A String value that is used in the creation of the default string description of an object.
* Called by the built-in method Object.prototype.toString.
*/
toStringTag: symbol;
@ -111,7 +106,7 @@ interface ObjectConstructor {
getOwnPropertySymbols(o: any): symbol[];
/**
* Returns true if the values are the same value, false otherwise.
* Returns true if the values are the same value, false otherwise.
* @param value1 The first value.
* @param value2 The second value.
*/
@ -598,8 +593,6 @@ interface Math {
}
interface RegExp {
[Symbol.isRegExp]: boolean;
/**
* Matches a string with a regular expression, and returns an array containing the results of
* that search.
@ -631,6 +624,20 @@ interface RegExp {
*/
split(string: string, limit?: number): string[];
/**
* Returns a string indicating the flags of the regular expression in question. This field is read-only.
* The characters in this string are sequenced and concatenated in the following order:
*
* - "g" for global
* - "i" for ignoreCase
* - "m" for multiline
* - "u" for unicode
* - "y" for sticky
*
* If no flags are set, the value is the empty string.
*/
flags: string;
/**
* Returns a Boolean value indicating the state of the sticky flag (y) used with a regular
* expression. Default is false. Read-only.

View File

@ -104,7 +104,7 @@ module ts.server {
var response: T = JSON.parse(responseBody);
}
catch (e) {
throw new Error("Malformed response: Failed to parse server response: " + lastMessage + ". \r\n Error detailes: " + e.message);
throw new Error("Malformed response: Failed to parse server response: " + lastMessage + ". \r\n Error details: " + e.message);
}
// verify the sequence numbers
@ -446,6 +446,7 @@ module ts.server {
if (!response.body) {
return undefined;
}
var helpItems: protocol.SignatureHelpItems = response.body;
var span = helpItems.applicableSpan;
var start = this.lineOffsetToPosition(fileName, span.start);
@ -465,6 +466,29 @@ module ts.server {
}
getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[] {
var lineOffset = this.positionToOneBasedLineOffset(fileName, position);
var args: protocol.FileLocationRequestArgs = {
file: fileName,
line: lineOffset.line,
offset: lineOffset.offset,
};
var request = this.processRequest<protocol.OccurrencesRequest>(CommandNames.Occurrences, args);
var response = this.processResponse<protocol.OccurrencesResponse>(request);
return response.body.map(entry => {
var fileName = entry.file;
var start = this.lineOffsetToPosition(fileName, entry.start);
var end = this.lineOffsetToPosition(fileName, entry.end);
return {
fileName,
textSpan: ts.createTextSpanFromBounds(start, end),
isWriteAccess: entry.isWriteAccess,
};
});
}
getDocumentHighlights(fileName: string, position: number): DocumentHighlights[] {
throw new Error("Not Implemented Yet.");
}

View File

@ -165,6 +165,25 @@ declare module ts.server.protocol {
body?: FileSpan[];
}
/**
* Get occurrences request; value of command field is
* "occurrences". Return response giving spans that are relevant
* in the file at a given line and column.
*/
export interface OccurrencesRequest extends FileLocationRequest {
}
export interface OccurrencesResponseItem extends FileSpan {
/**
* True if the occurrence is a write location, false otherwise.
*/
isWriteAccess: boolean;
}
export interface OccurrencesResponse extends Response {
body?: OccurrencesResponseItem[];
}
/**
* Find references request; value of command field is
* "references". Return response giving the file locations that

View File

@ -89,6 +89,7 @@ module ts.server {
export var Geterr = "geterr";
export var NavBar = "navbar";
export var Navto = "navto";
export var Occurrences = "occurrences";
export var Open = "open";
export var Quickinfo = "quickinfo";
export var References = "references";
@ -117,7 +118,7 @@ module ts.server {
constructor(private host: ServerHost, private logger: Logger) {
this.projectService =
new ProjectService(host, logger, (eventName,project,fileName) => {
new ProjectService(host, logger, (eventName, project, fileName) => {
this.handleEvent(eventName, project, fileName);
});
}
@ -262,7 +263,7 @@ module ts.server {
}
}
getDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] {
getDefinition({ line, offset, file: fileName }: protocol.FileLocationRequestArgs): protocol.FileSpan[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@ -284,7 +285,37 @@ module ts.server {
}));
}
getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody {
getOccurrences({ line, offset, file: fileName }: protocol.FileLocationRequestArgs): protocol.OccurrencesResponseItem[] {
fileName = ts.normalizePath(fileName);
let project = this.projectService.getProjectForFile(fileName);
if (!project) {
throw Errors.NoProject;
}
let { compilerService } = project;
let position = compilerService.host.lineOffsetToPosition(fileName, line, offset);
let occurrences = compilerService.languageService.getOccurrencesAtPosition(fileName, position);
if (!occurrences) {
return undefined;
}
return occurrences.map(occurrence => {
let { fileName, isWriteAccess, textSpan } = occurrence;
let start = compilerService.host.positionToLineOffset(fileName, textSpan.start);
let end = compilerService.host.positionToLineOffset(fileName, ts.textSpanEnd(textSpan));
return {
start,
end,
file: fileName,
isWriteAccess
}
});
}
getRenameLocations({line, offset, file: fileName, findInComments, findInStrings }: protocol.RenameRequestArgs): protocol.RenameResponseBody {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@ -352,7 +383,7 @@ module ts.server {
return { info: renameInfo, locs: bakedRenameLocs };
}
getReferences(line: number, offset: number, fileName: string): protocol.ReferencesResponseBody {
getReferences({ line, offset, file: fileName }: protocol.FileLocationRequestArgs): protocol.ReferencesResponseBody {
// TODO: get all projects for this file; report refs for all projects deleting duplicates
// can avoid duplicates by eliminating same ref file from subsequent projects
var file = ts.normalizePath(fileName);
@ -378,7 +409,7 @@ module ts.server {
var nameSpan = nameInfo.textSpan;
var nameColStart = compilerService.host.positionToLineOffset(file, nameSpan.start).offset;
var nameText = compilerService.host.getScriptSnapshot(file).getText(nameSpan.start, ts.textSpanEnd(nameSpan));
var bakedRefs: protocol.ReferencesResponseItem[] = references.map((ref) => {
var bakedRefs: protocol.ReferencesResponseItem[] = references.map(ref => {
var start = compilerService.host.positionToLineOffset(ref.fileName, ref.textSpan.start);
var refLineSpan = compilerService.host.lineToTextSpan(ref.fileName, start.line - 1);
var snap = compilerService.host.getScriptSnapshot(ref.fileName);
@ -399,12 +430,12 @@ module ts.server {
};
}
openClientFile(fileName: string) {
openClientFile({ file: fileName }: protocol.OpenRequestArgs) {
var file = ts.normalizePath(fileName);
this.projectService.openClientFile(file);
}
getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody {
getQuickInfo({ line, offset, file: fileName }: protocol.FileLocationRequestArgs): protocol.QuickInfoResponseBody {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@ -430,7 +461,7 @@ module ts.server {
};
}
getFormattingEditsForRange(line: number, offset: number, endLine: number, endOffset: number, fileName: string): protocol.CodeEdit[] {
getFormattingEditsForRange({line, offset, endLine, endOffset, file: fileName}: protocol.FormatRequestArgs): protocol.CodeEdit[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@ -457,7 +488,7 @@ module ts.server {
});
}
getFormattingEditsAfterKeystroke(line: number, offset: number, key: string, fileName: string): protocol.CodeEdit[] {
getFormattingEditsAfterKeystroke({line, offset, key, file: fileName}: protocol.FormatOnKeyRequestArgs): protocol.CodeEdit[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
@ -530,7 +561,7 @@ module ts.server {
});
}
getCompletions(line: number, offset: number, prefix: string, fileName: string): protocol.CompletionEntry[] {
getCompletions({ line, offset, prefix, file: fileName}: protocol.CompletionsRequestArgs): protocol.CompletionEntry[] {
if (!prefix) {
prefix = "";
}
@ -556,8 +587,7 @@ module ts.server {
}, []).sort((a, b) => a.name.localeCompare(b.name));
}
getCompletionEntryDetails(line: number, offset: number,
entryNames: string[], fileName: string): protocol.CompletionEntryDetails[] {
getCompletionEntryDetails({ line, offset, entryNames, file: fileName}: protocol.CompletionDetailsRequestArgs): protocol.CompletionEntryDetails[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@ -576,20 +606,20 @@ module ts.server {
}, []);
}
getSignatureHelpItems(line: number, offset: number, fileName: string): protocol.SignatureHelpItems {
getSignatureHelpItems({ line, offset, file: fileName }: protocol.SignatureHelpRequestArgs): protocol.SignatureHelpItems {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
throw Errors.NoProject;
}
var compilerService = project.compilerService;
var position = compilerService.host.lineOffsetToPosition(file, line, offset);
var helpItems = compilerService.languageService.getSignatureHelpItems(file, position);
if (!helpItems) {
return undefined;
}
var span = helpItems.applicableSpan;
var result: protocol.SignatureHelpItems = {
items: helpItems.items,
@ -601,11 +631,11 @@ module ts.server {
argumentIndex: helpItems.argumentIndex,
argumentCount: helpItems.argumentCount,
}
return result;
}
getDiagnostics(delay: number, fileNames: string[]) {
getDiagnostics({ delay, files: fileNames }: protocol.GeterrRequestArgs): void {
var checkList = fileNames.reduce((accum: PendingErrorCheck[], fileName: string) => {
fileName = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(fileName);
@ -616,11 +646,11 @@ module ts.server {
}, []);
if (checkList.length > 0) {
this.updateErrorCheck(checkList, this.changeSeq,(n) => n == this.changeSeq, delay)
this.updateErrorCheck(checkList, this.changeSeq, (n) => n == this.changeSeq, delay)
}
}
change(line: number, offset: number, endLine: number, endOffset: number, insertString: string, fileName: string) {
change({ line, offset, endLine, endOffset, insertString, file: fileName }: protocol.ChangeRequestArgs): void {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (project) {
@ -635,7 +665,7 @@ module ts.server {
}
}
reload(fileName: string, tempFileName: string, reqSeq = 0) {
reload({ file: fileName, tmpfile: tempFileName }: protocol.ReloadRequestArgs, reqSeq = 0): void {
var file = ts.normalizePath(fileName);
var tmpfile = ts.normalizePath(tempFileName);
var project = this.projectService.getProjectForFile(file);
@ -648,7 +678,7 @@ module ts.server {
}
}
saveToTmp(fileName: string, tempFileName: string) {
saveToTmp({ file: fileName, tmpfile: tempFileName }: protocol.SavetoRequestArgs): void {
var file = ts.normalizePath(fileName);
var tmpfile = ts.normalizePath(tempFileName);
@ -658,7 +688,7 @@ module ts.server {
}
}
closeClientFile(fileName: string) {
closeClientFile({ file: fileName }: protocol.FileRequestArgs) {
var file = ts.normalizePath(fileName);
this.projectService.closeClientFile(file);
}
@ -682,7 +712,7 @@ module ts.server {
}));
}
getNavigationBarItems(fileName: string): protocol.NavigationBarItem[] {
getNavigationBarItems({ file: fileName }: protocol.FileRequestArgs): protocol.NavigationBarItem[]{
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@ -698,7 +728,7 @@ module ts.server {
return this.decorateNavigationBarItem(project, fileName, items);
}
getNavigateToItems(searchValue: string, fileName: string, maxResultCount?: number): protocol.NavtoItem[] {
getNavigateToItems({ searchValue, file: fileName, maxResultCount }: protocol.NavtoRequestArgs): protocol.NavtoItem[]{
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@ -737,7 +767,7 @@ module ts.server {
});
}
getBraceMatching(line: number, offset: number, fileName: string): protocol.TextSpan[] {
getBraceMatching({ line, offset, file: fileName }: protocol.FileLocationRequestArgs): protocol.TextSpan[]{
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
@ -779,109 +809,91 @@ module ts.server {
break;
}
case CommandNames.Definition: {
var defArgs = <protocol.FileLocationRequestArgs>request.arguments;
response = this.getDefinition(defArgs.line, defArgs.offset, defArgs.file);
response = this.getDefinition(<protocol.FileLocationRequestArgs>request.arguments);
break;
}
case CommandNames.References: {
var refArgs = <protocol.FileLocationRequestArgs>request.arguments;
response = this.getReferences(refArgs.line, refArgs.offset, refArgs.file);
response = this.getReferences(<protocol.FileLocationRequestArgs>request.arguments);
break;
}
case CommandNames.Rename: {
var renameArgs = <protocol.RenameRequestArgs>request.arguments;
response = this.getRenameLocations(renameArgs.line, renameArgs.offset, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings);
response = this.getRenameLocations(<protocol.RenameRequestArgs>request.arguments);
break;
}
case CommandNames.Open: {
var openArgs = <protocol.OpenRequestArgs>request.arguments;
this.openClientFile(openArgs.file);
this.openClientFile(<protocol.OpenRequestArgs>request.arguments);
responseRequired = false;
break;
}
case CommandNames.Quickinfo: {
var quickinfoArgs = <protocol.FileLocationRequestArgs>request.arguments;
response = this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.offset, quickinfoArgs.file);
response = this.getQuickInfo(<protocol.FileLocationRequestArgs>request.arguments);
break;
}
case CommandNames.Format: {
var formatArgs = <protocol.FormatRequestArgs>request.arguments;
response = this.getFormattingEditsForRange(formatArgs.line, formatArgs.offset, formatArgs.endLine, formatArgs.endOffset, formatArgs.file);
response = this.getFormattingEditsForRange(<protocol.FormatRequestArgs>request.arguments);
break;
}
case CommandNames.Formatonkey: {
var formatOnKeyArgs = <protocol.FormatOnKeyRequestArgs>request.arguments;
response = this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.offset, formatOnKeyArgs.key, formatOnKeyArgs.file);
response = this.getFormattingEditsAfterKeystroke(<protocol.FormatOnKeyRequestArgs>request.arguments);
break;
}
case CommandNames.Completions: {
var completionsArgs = <protocol.CompletionsRequestArgs>request.arguments;
response = this.getCompletions(completionsArgs.line, completionsArgs.offset, completionsArgs.prefix, completionsArgs.file);
response = this.getCompletions(<protocol.CompletionsRequestArgs>request.arguments);
break;
}
case CommandNames.CompletionDetails: {
var completionDetailsArgs = <protocol.CompletionDetailsRequestArgs>request.arguments;
response =
this.getCompletionEntryDetails(completionDetailsArgs.line,completionDetailsArgs.offset,
completionDetailsArgs.entryNames,completionDetailsArgs.file);
response = this.getCompletionEntryDetails(<protocol.CompletionDetailsRequestArgs>request.arguments);
break;
}
case CommandNames.SignatureHelp: {
var signatureHelpArgs = <protocol.SignatureHelpRequestArgs>request.arguments;
response = this.getSignatureHelpItems(signatureHelpArgs.line, signatureHelpArgs.offset, signatureHelpArgs.file);
response = this.getSignatureHelpItems(<protocol.SignatureHelpRequestArgs>request.arguments);
break;
}
case CommandNames.Geterr: {
var geterrArgs = <protocol.GeterrRequestArgs>request.arguments;
response = this.getDiagnostics(geterrArgs.delay, geterrArgs.files);
this.getDiagnostics(<protocol.GeterrRequestArgs>request.arguments);
responseRequired = false;
break;
}
case CommandNames.Change: {
var changeArgs = <protocol.ChangeRequestArgs>request.arguments;
this.change(changeArgs.line, changeArgs.offset, changeArgs.endLine, changeArgs.endOffset,
changeArgs.insertString, changeArgs.file);
this.change(<protocol.ChangeRequestArgs>request.arguments);
responseRequired = false;
break;
}
case CommandNames.Configure: {
var configureArgs = <protocol.ConfigureRequestArguments>request.arguments;
this.projectService.setHostConfiguration(configureArgs);
this.projectService.setHostConfiguration(<protocol.ConfigureRequestArguments>request.arguments);
this.output(undefined, CommandNames.Configure, request.seq);
responseRequired = false;
break;
}
case CommandNames.Reload: {
var reloadArgs = <protocol.ReloadRequestArgs>request.arguments;
this.reload(reloadArgs.file, reloadArgs.tmpfile, request.seq);
this.reload(<protocol.ReloadRequestArgs>request.arguments);
responseRequired = false;
break;
}
case CommandNames.Saveto: {
var savetoArgs = <protocol.SavetoRequestArgs>request.arguments;
this.saveToTmp(savetoArgs.file, savetoArgs.tmpfile);
this.saveToTmp(<protocol.SavetoRequestArgs>request.arguments);
responseRequired = false;
break;
}
case CommandNames.Close: {
var closeArgs = <protocol.FileRequestArgs>request.arguments;
this.closeClientFile(closeArgs.file);
this.closeClientFile(<protocol.FileRequestArgs>request.arguments);
responseRequired = false;
break;
}
case CommandNames.Navto: {
var navtoArgs = <protocol.NavtoRequestArgs>request.arguments;
response = this.getNavigateToItems(navtoArgs.searchValue, navtoArgs.file, navtoArgs.maxResultCount);
response = this.getNavigateToItems(<protocol.NavtoRequestArgs>request.arguments);
break;
}
case CommandNames.Brace: {
var braceArguments = <protocol.FileLocationRequestArgs>request.arguments;
response = this.getBraceMatching(braceArguments.line, braceArguments.offset, braceArguments.file);
response = this.getBraceMatching(<protocol.FileLocationRequestArgs>request.arguments);
break;
}
case CommandNames.NavBar: {
var navBarArgs = <protocol.FileRequestArgs>request.arguments;
response = this.getNavigationBarItems(navBarArgs.file);
response = this.getNavigationBarItems(<protocol.FileRequestArgs>request.arguments);
break;
}
case CommandNames.Occurrences: {
response = this.getOccurrences(<protocol.FileLocationRequestArgs>request.arguments);
break;
}
default: {

View File

@ -328,8 +328,13 @@ module ts.formatting {
if (formattingScanner.isOnToken()) {
let startLine = sourceFile.getLineAndCharacterOfPosition(enclosingNode.getStart(sourceFile)).line;
let undecoratedStartLine = startLine;
if (enclosingNode.decorators) {
undecoratedStartLine = sourceFile.getLineAndCharacterOfPosition(getNonDecoratorTokenPosOfNode(enclosingNode, sourceFile)).line;
}
let delta = getOwnOrInheritedDelta(enclosingNode, options, sourceFile);
processNode(enclosingNode, enclosingNode, startLine, initialIndentation, delta);
processNode(enclosingNode, enclosingNode, startLine, undecoratedStartLine, initialIndentation, delta);
}
formattingScanner.close();
@ -500,7 +505,7 @@ module ts.formatting {
}
}
function processNode(node: Node, contextNode: Node, nodeStartLine: number, indentation: number, delta: number) {
function processNode(node: Node, contextNode: Node, nodeStartLine: number, undecoratedNodeStartLine: number, indentation: number, delta: number) {
if (!rangeOverlapsWithStartEnd(originalRange, node.getStart(sourceFile), node.getEnd())) {
return;
}
@ -526,7 +531,7 @@ module ts.formatting {
forEachChild(
node,
child => {
processChildNode(child, /*inheritedIndentation*/ Constants.Unknown, node, nodeDynamicIndentation, nodeStartLine, /*isListElement*/ false)
processChildNode(child, /*inheritedIndentation*/ Constants.Unknown, node, nodeDynamicIndentation, nodeStartLine, undecoratedNodeStartLine, /*isListElement*/ false)
},
(nodes: NodeArray<Node>) => {
processChildNodes(nodes, node, nodeStartLine, nodeDynamicIndentation);
@ -547,11 +552,17 @@ module ts.formatting {
parent: Node,
parentDynamicIndentation: DynamicIndentation,
parentStartLine: number,
undecoratedParentStartLine: number,
isListItem: boolean): number {
let childStartPos = child.getStart(sourceFile);
let childStart = sourceFile.getLineAndCharacterOfPosition(childStartPos);
let childStartLine = sourceFile.getLineAndCharacterOfPosition(childStartPos).line;
let undecoratedChildStartLine = childStartLine;
if (child.decorators) {
undecoratedChildStartLine = sourceFile.getLineAndCharacterOfPosition(getNonDecoratorTokenPosOfNode(child, sourceFile)).line;
}
// if child is a list item - try to get its indentation
let childIndentationAmount = Constants.Unknown;
@ -594,9 +605,10 @@ module ts.formatting {
return inheritedIndentation;
}
let childIndentation = computeIndentation(child, childStart.line, childIndentationAmount, node, parentDynamicIndentation, parentStartLine);
let effectiveParentStartLine = child.kind === SyntaxKind.Decorator ? childStartLine : undecoratedParentStartLine;
let childIndentation = computeIndentation(child, childStartLine, childIndentationAmount, node, parentDynamicIndentation, effectiveParentStartLine);
processNode(child, childContextNode, childStart.line, childIndentation.indentation, childIndentation.delta);
processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta);
childContextNode = node;
@ -640,7 +652,7 @@ module ts.formatting {
let inheritedIndentation = Constants.Unknown;
for (let child of nodes) {
inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, /*isListElement*/ true)
inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListElement*/ true)
}
if (listEndToken !== SyntaxKind.Unknown) {

View File

@ -208,6 +208,11 @@ module ts.formatting {
public SpaceAfterAnonymousFunctionKeyword: Rule;
public NoSpaceAfterAnonymousFunctionKeyword: Rule;
// Insert space after @ in decorator
public SpaceBeforeAt: Rule;
public NoSpaceAfterAt: Rule;
public SpaceAfterDecorator: Rule;
constructor() {
///
/// Common Rules
@ -344,6 +349,11 @@ module ts.formatting {
// Remove spaces in empty interface literals. e.g.: x: {}
this.NoSpaceBetweenEmptyInterfaceBraceBrackets = new Rule(RuleDescriptor.create1(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsObjectTypeContext), RuleAction.Delete));
// decorators
this.SpaceBeforeAt = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.AtToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
this.NoSpaceAfterAt = new Rule(RuleDescriptor.create3(SyntaxKind.AtToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
this.SpaceAfterDecorator = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.ExportKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.ClassKeyword, SyntaxKind.StaticKeyword, SyntaxKind.PublicKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.GetKeyword, SyntaxKind.SetKeyword, SyntaxKind.OpenBracketToken, SyntaxKind.AsteriskToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), RuleAction.Space));
// These rules are higher in priority than user-configurable rules.
this.HighPriorityCommonRules =
[
@ -381,7 +391,10 @@ module ts.formatting {
this.NoSpaceBetweenCloseParenAndAngularBracket,
this.NoSpaceAfterOpenAngularBracket,
this.NoSpaceBeforeCloseAngularBracket,
this.NoSpaceAfterCloseAngularBracket
this.NoSpaceAfterCloseAngularBracket,
this.SpaceBeforeAt,
this.NoSpaceAfterAt,
this.SpaceAfterDecorator,
];
// These rules are lower in priority than user-configurable rules.
@ -649,6 +662,20 @@ module ts.formatting {
return context.TokensAreOnSameLine();
}
static IsEndOfDecoratorContextOnSameLine(context: FormattingContext): boolean {
return context.TokensAreOnSameLine() &&
context.contextNode.decorators &&
Rules.NodeIsInDecoratorContext(context.currentTokenParent) &&
!Rules.NodeIsInDecoratorContext(context.nextTokenParent);
}
static NodeIsInDecoratorContext(node: Node): boolean {
while (isExpression(node)) {
node = node.parent;
}
return node.kind === SyntaxKind.Decorator;
}
static IsStartOfVariableDeclarationList(context: FormattingContext): boolean {
return context.currentTokenParent.kind === SyntaxKind.VariableDeclarationList &&
context.currentTokenParent.getStart(context.sourceFile) === context.currentTokenSpan.pos;

View File

@ -1,18 +1,3 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
module ts {
export module OutliningElementsCollector {
export function collectElements(sourceFile: SourceFile): OutliningSpan[] {
@ -31,6 +16,66 @@ module ts {
}
}
function addOutliningSpanComments(commentSpan: CommentRange, autoCollapse: boolean) {
if (commentSpan) {
let span: OutliningSpan = {
textSpan: createTextSpanFromBounds(commentSpan.pos, commentSpan.end),
hintSpan: createTextSpanFromBounds(commentSpan.pos, commentSpan.end),
bannerText: collapseText,
autoCollapse: autoCollapse
};
elements.push(span);
}
}
function addOutliningForLeadingCommentsForNode(n: Node) {
let comments = ts.getLeadingCommentRangesOfNode(n, sourceFile);
if (comments) {
let firstSingleLineCommentStart = -1;
let lastSingleLineCommentEnd = -1;
let isFirstSingleLineComment = true;
let singleLineCommentCount = 0;
for (let currentComment of comments) {
// For single line comments, combine consecutive ones (2 or more) into
// a single span from the start of the first till the end of the last
if (currentComment.kind === SyntaxKind.SingleLineCommentTrivia) {
if (isFirstSingleLineComment) {
firstSingleLineCommentStart = currentComment.pos;
}
isFirstSingleLineComment = false;
lastSingleLineCommentEnd = currentComment.end;
singleLineCommentCount++;
}
else if (currentComment.kind === SyntaxKind.MultiLineCommentTrivia) {
combineAndAddMultipleSingleLineComments(singleLineCommentCount, firstSingleLineCommentStart, lastSingleLineCommentEnd);
addOutliningSpanComments(currentComment, /*autoCollapse*/ false);
singleLineCommentCount = 0;
lastSingleLineCommentEnd = -1;
isFirstSingleLineComment = true;
}
}
combineAndAddMultipleSingleLineComments(singleLineCommentCount, firstSingleLineCommentStart, lastSingleLineCommentEnd);
}
}
function combineAndAddMultipleSingleLineComments(count: number, start: number, end: number) {
// Only outline spans of two or more consecutive single line comments
if (count > 1) {
let multipleSingleLineComments = {
pos: start,
end: end,
kind: SyntaxKind.SingleLineCommentTrivia
}
addOutliningSpanComments(multipleSingleLineComments, /*autoCollapse*/ false);
}
}
function autoCollapse(node: Node) {
return isFunctionBlock(node) && node.parent.kind !== SyntaxKind.ArrowFunction;
}
@ -41,6 +86,11 @@ module ts {
if (depth > maxDepth) {
return;
}
if (isDeclaration(n)) {
addOutliningForLeadingCommentsForNode(n);
}
switch (n.kind) {
case SyntaxKind.Block:
if (!isFunctionBlock(n)) {
@ -93,7 +143,7 @@ module ts {
});
break;
}
// Fallthrough.
// Fallthrough.
case SyntaxKind.ModuleBlock: {
let openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);

File diff suppressed because it is too large Load Diff

View File

@ -135,11 +135,21 @@ module ts {
findReferences(fileName: string, position: number): string;
/**
* @deprecated
* Returns a JSON-encoded value of the type:
* { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[]
*/
getOccurrencesAtPosition(fileName: string, position: number): string;
/**
* Returns a JSON-encoded value of the type:
* { fileName: string; highlights: { start: number; length: number, isDefinition: boolean }[] }[]
*
* @param fileToSearch A JSON encoded string[] containing the file names that should be
* considered when searching.
*/
getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string;
/**
* Returns a JSON-encoded value of the type:
* { name: string; kind: string; kindModifiers: string; containerName: string; containerKind: string; matchKind: string; fileName: string; textSpan: { start: number; length: number}; } [] = [];
@ -590,6 +600,14 @@ module ts {
});
}
public getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string {
return this.forwardJSONCall(
"getDocumentHighlights('" + fileName + "', " + position + ")",
() => {
return this.languageService.getDocumentHighlights(fileName, position, JSON.parse(filesToSearch));
});
}
/// COMPLETION LISTS
/**

View File

@ -1,12 +1,18 @@
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,6): error TS2461: Type 'string | number' is not an array type.
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,7): error TS2322: Type 'number' is not assignable to type 'string'.
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,14): error TS2322: Type 'string' is not assignable to type 'number'.
==== tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts (1 errors) ====
==== tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts (3 errors) ====
var a: string, b: number;
var tuple: [number, string] = [2, "3"];
for ([a = 1, b = ""] of tuple) {
~~~~~~~~~~~~~~~
!!! error TS2461: Type 'string | number' is not an array type.
~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
a;
b;
}

View File

@ -9,44 +9,55 @@ function f0() {
var a1 = [...a];
>a1 : number[]
>[...a] : number[]
>...a : number
>a : number[]
var a2 = [1, ...a];
>a2 : number[]
>[1, ...a] : number[]
>...a : number
>a : number[]
var a3 = [1, 2, ...a];
>a3 : number[]
>[1, 2, ...a] : number[]
>...a : number
>a : number[]
var a4 = [...a, 1];
>a4 : number[]
>[...a, 1] : number[]
>...a : number
>a : number[]
var a5 = [...a, 1, 2];
>a5 : number[]
>[...a, 1, 2] : number[]
>...a : number
>a : number[]
var a6 = [1, 2, ...a, 1, 2];
>a6 : number[]
>[1, 2, ...a, 1, 2] : number[]
>...a : number
>a : number[]
var a7 = [1, ...a, 2, ...a];
>a7 : number[]
>[1, ...a, 2, ...a] : number[]
>...a : number
>a : number[]
>...a : number
>a : number[]
var a8 = [...a, ...a, ...a];
>a8 : number[]
>[...a, ...a, ...a] : number[]
>...a : number
>a : number[]
>...a : number
>a : number[]
>...a : number
>a : number[]
}
@ -60,6 +71,7 @@ function f1() {
var b = ["hello", ...a, true];
>b : (string | number | boolean)[]
>["hello", ...a, true] : (string | number | boolean)[]
>...a : number
>a : number[]
var b: (string | number | boolean)[];
@ -72,19 +84,29 @@ function f2() {
var a = [...[...[...[...[...[]]]]]];
>a : any[]
>[...[...[...[...[...[]]]]]] : undefined[]
>...[...[...[...[...[]]]]] : undefined
>[...[...[...[...[]]]]] : undefined[]
>...[...[...[...[]]]] : undefined
>[...[...[...[]]]] : undefined[]
>...[...[...[]]] : undefined
>[...[...[]]] : undefined[]
>...[...[]] : undefined
>[...[]] : undefined[]
>...[] : undefined
>[] : undefined[]
var b = [...[...[...[...[...[5]]]]]];
>b : number[]
>[...[...[...[...[...[5]]]]]] : number[]
>...[...[...[...[...[5]]]]] : number
>[...[...[...[...[5]]]]] : number[]
>...[...[...[...[5]]]] : number
>[...[...[...[5]]]] : number[]
>...[...[...[5]]] : number
>[...[...[5]]] : number[]
>...[...[5]] : number
>[...[5]] : number[]
>...[5] : number
>[5] : number[]
}

View File

@ -38,11 +38,13 @@ foo(1, 2, "abc");
foo(1, 2, ...a);
>foo(1, 2, ...a) : void
>foo : (x: number, y: number, ...z: string[]) => void
>...a : string
>a : string[]
foo(1, 2, ...a, "abc");
>foo(1, 2, ...a, "abc") : void
>foo : (x: number, y: number, ...z: string[]) => void
>...a : string
>a : string[]
obj.foo(1, 2, "abc");
@ -56,6 +58,7 @@ obj.foo(1, 2, ...a);
>obj.foo : (x: number, y: number, ...z: string[]) => any
>obj : X
>foo : (x: number, y: number, ...z: string[]) => any
>...a : string
>a : string[]
obj.foo(1, 2, ...a, "abc");
@ -63,6 +66,7 @@ obj.foo(1, 2, ...a, "abc");
>obj.foo : (x: number, y: number, ...z: string[]) => any
>obj : X
>foo : (x: number, y: number, ...z: string[]) => any
>...a : string
>a : string[]
(obj.foo)(1, 2, "abc");
@ -78,6 +82,7 @@ obj.foo(1, 2, ...a, "abc");
>obj.foo : (x: number, y: number, ...z: string[]) => any
>obj : X
>foo : (x: number, y: number, ...z: string[]) => any
>...a : string
>a : string[]
(obj.foo)(1, 2, ...a, "abc");
@ -86,6 +91,7 @@ obj.foo(1, 2, ...a, "abc");
>obj.foo : (x: number, y: number, ...z: string[]) => any
>obj : X
>foo : (x: number, y: number, ...z: string[]) => any
>...a : string
>a : string[]
xa[1].foo(1, 2, "abc");
@ -101,6 +107,7 @@ xa[1].foo(1, 2, ...a);
>xa[1] : X
>xa : X[]
>foo : (x: number, y: number, ...z: string[]) => any
>...a : string
>a : string[]
xa[1].foo(1, 2, ...a, "abc");
@ -109,6 +116,7 @@ xa[1].foo(1, 2, ...a, "abc");
>xa[1] : X
>xa : X[]
>foo : (x: number, y: number, ...z: string[]) => any
>...a : string
>a : string[]
(<Function>xa[1].foo)(...[1, 2, "abc"]);
@ -120,6 +128,7 @@ xa[1].foo(1, 2, ...a, "abc");
>xa[1] : X
>xa : X[]
>foo : (x: number, y: number, ...z: string[]) => any
>...[1, 2, "abc"] : string | number
>[1, 2, "abc"] : (string | number)[]
class C {
@ -145,6 +154,7 @@ class C {
>foo : (x: number, y: number, ...z: string[]) => void
>x : number
>y : number
>...z : string
>z : string[]
}
foo(x: number, y: number, ...z: string[]) {
@ -167,6 +177,7 @@ class D extends C {
super(1, 2, ...a);
>super(1, 2, ...a) : void
>super : typeof C
>...a : string
>a : string[]
}
foo() {
@ -183,6 +194,7 @@ class D extends C {
>super.foo : (x: number, y: number, ...z: string[]) => void
>super : C
>foo : (x: number, y: number, ...z: string[]) => void
>...a : string
>a : string[]
}
}
@ -192,5 +204,6 @@ var c = new C(1, 2, ...a);
>c : C
>new C(1, 2, ...a) : C
>C : typeof C
>...a : string
>a : string[]

View File

@ -23,7 +23,6 @@ class Base {
}
class C extends Base {
foo() {
var _this = this;
(() => {
var obj = {
[super.bar()]() { } // needs capture

View File

@ -7,7 +7,7 @@ declare function dec<T>(target: T): T;
>T : T
@dec
>dec : unknown
>dec : <T>(target: T) => T
class C {
>C : C

View File

@ -7,7 +7,7 @@ declare function dec<T>(target: T): T;
>T : T
@dec
>dec : unknown
>dec : <T>(target: T) => T
export class C {
>C : C

View File

@ -14,6 +14,6 @@ class C {
>C : C
@dec get accessor() { return 1; }
>dec : unknown
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>accessor : number
}

View File

@ -14,6 +14,6 @@ class C {
>C : C
@dec public get accessor() { return 1; }
>dec : unknown
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>accessor : number
}

View File

@ -14,7 +14,7 @@ class C {
>C : C
@dec set accessor(value: number) { }
>dec : unknown
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>accessor : number
>value : number
}

View File

@ -14,7 +14,7 @@ class C {
>C : C
@dec public set accessor(value: number) { }
>dec : unknown
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>accessor : number
>value : number
}

View File

@ -10,6 +10,6 @@ class C {
>C : C
constructor(@dec p: number) {}
>dec : unknown
>dec : (target: Function, propertyKey: string | symbol, parameterIndex: number) => void
>p : number
}

View File

@ -14,6 +14,6 @@ class C {
>C : C
@dec method() {}
>dec : unknown
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>method : () => void
}

View File

@ -1,11 +1,11 @@
//// [decoratorOnClassMethod11.ts]
module M {
class C {
decorator(target: Object, key: string): void { }
@this.decorator
method() { }
}
module M {
class C {
decorator(target: Object, key: string): void { }
@this.decorator
method() { }
}
}
//// [decoratorOnClassMethod11.js]

View File

@ -14,8 +14,8 @@ class C {
>C : C
@dec ["1"]() { }
>dec : unknown
>dec : () => <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
@dec ["b"]() { }
>dec : unknown
>dec : () => <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
}

View File

@ -14,6 +14,6 @@ class C {
>C : C
@dec public method() {}
>dec : unknown
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>method : () => void
}

View File

@ -14,5 +14,5 @@ class C {
>C : C
@dec ["method"]() {}
>dec : unknown
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
}

View File

@ -14,5 +14,5 @@ class C {
>C : C
@dec ["method"]() {}
>dec : unknown
>dec : () => <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
}

View File

@ -14,5 +14,5 @@ class C {
>C : C
@dec public ["method"]() {}
>dec : unknown
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
}

View File

@ -10,6 +10,6 @@ class C {
>C : C
@dec method() {}
>dec : unknown
>dec : <T>(target: T) => T
>method : () => void
}

View File

@ -11,6 +11,6 @@ class C {
method(@dec p: number) {}
>method : (p: number) => void
>dec : unknown
>dec : (target: Function, propertyKey: string | symbol, parameterIndex: number) => void
>p : number
}

View File

@ -8,6 +8,6 @@ class C {
>C : C
@dec prop;
>dec : unknown
>dec : (target: any, propertyKey: string) => void
>prop : any
}

View File

@ -9,6 +9,6 @@ class C {
>C : C
@dec prop;
>dec : unknown
>dec : () => <T>(target: any, propertyKey: string) => void
>prop : any
}

View File

@ -8,6 +8,6 @@ class C {
>C : C
@dec public prop;
>dec : unknown
>dec : (target: any, propertyKey: string) => void
>prop : any
}

View File

@ -8,6 +8,6 @@ class C {
>C : C
@dec prop;
>dec : unknown
>dec : (target: Function) => void
>prop : any
}

View File

@ -0,0 +1,23 @@
//// [emitClassDeclarationWithSuperMethodCall01.ts]
class Parent {
foo() {
}
}
class Foo extends Parent {
foo() {
var x = () => super.foo();
}
}
//// [emitClassDeclarationWithSuperMethodCall01.js]
class Parent {
foo() {
}
}
class Foo extends Parent {
foo() {
var x = () => super.foo();
}
}

View File

@ -0,0 +1,26 @@
=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01.ts ===
class Parent {
>Parent : Parent
foo() {
>foo : () => void
}
}
class Foo extends Parent {
>Foo : Foo
>Parent : Parent
foo() {
>foo : () => void
var x = () => super.foo();
>x : () => void
>() => super.foo() : () => void
>super.foo() : void
>super.foo : () => void
>super : Parent
>foo : () => void
}
}

View File

@ -1,11 +1,11 @@
tests/cases/conformance/es6/for-ofStatements/for-of14.ts(2,11): error TS2488: The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator.
tests/cases/conformance/es6/for-ofStatements/for-of14.ts(2,11): error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.
==== tests/cases/conformance/es6/for-ofStatements/for-of14.ts (1 errors) ====
var v: string;
for (v of new StringIterator) { } // Should fail because the iterator is not iterable
~~~~~~~~~~~~~~~~~~
!!! error TS2488: The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator.
!!! error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.
class StringIterator {
next() {

View File

@ -1,11 +1,11 @@
tests/cases/conformance/es6/for-ofStatements/for-of16.ts(2,11): error TS2489: The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method.
tests/cases/conformance/es6/for-ofStatements/for-of16.ts(2,11): error TS2489: An iterator must have a 'next()' method.
==== tests/cases/conformance/es6/for-ofStatements/for-of16.ts (1 errors) ====
var v: string;
for (v of new StringIterator) { } // Should fail
~~~~~~~~~~~~~~~~~~
!!! error TS2489: The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method.
!!! error TS2489: An iterator must have a 'next()' method.
class StringIterator {
[Symbol.iterator]() {

View File

@ -0,0 +1,7 @@
//// [for-of57.ts]
var iter: Iterable<number>;
for (let num of iter) { }
//// [for-of57.js]
var iter;
for (let num of iter) { }

View File

@ -0,0 +1,9 @@
=== tests/cases/conformance/es6/for-ofStatements/for-of57.ts ===
var iter: Iterable<number>;
>iter : Iterable<number>
>Iterable : Iterable<T>
for (let num of iter) { }
>num : number
>iter : Iterable<number>

View File

@ -0,0 +1,28 @@
//// [iterableArrayPattern1.ts]
var [a, b] = new SymbolIterator;
class SymbolIterator {
next() {
return {
value: Symbol(),
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern1.js]
var [a, b] = new SymbolIterator;
class SymbolIterator {
next() {
return {
value: Symbol(),
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,36 @@
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern1.ts ===
var [a, b] = new SymbolIterator;
>a : symbol
>b : symbol
>new SymbolIterator : SymbolIterator
>SymbolIterator : typeof SymbolIterator
class SymbolIterator {
>SymbolIterator : SymbolIterator
next() {
>next : () => { value: symbol; done: boolean; }
return {
>{ value: Symbol(), done: false } : { value: symbol; done: boolean; }
value: Symbol(),
>value : symbol
>Symbol() : symbol
>Symbol : SymbolConstructor
done: false
>done : boolean
};
}
[Symbol.iterator]() {
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
return this;
>this : SymbolIterator
}
}

View File

@ -0,0 +1,24 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern10.ts(2,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[any, any]'.
Property '0' is missing in type 'FooIterator'.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern10.ts (1 errors) ====
function fun([a, b]) { }
fun(new FooIterator);
~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[any, any]'.
!!! error TS2345: Property '0' is missing in type 'FooIterator'.
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern10.ts]
function fun([a, b]) { }
fun(new FooIterator);
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern10.js]
function fun([a, b]) { }
fun(new FooIterator);
class Bar {
}
class Foo extends Bar {
}
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern11.ts]
function fun([a, b] = new FooIterator) { }
fun(new FooIterator);
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern11.js]
function fun([a, b] = new FooIterator) { }
fun(new FooIterator);
class Bar {
}
class Foo extends Bar {
}
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,52 @@
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern11.ts ===
function fun([a, b] = new FooIterator) { }
>fun : ([a, b]?: FooIterator) => void
>a : Foo
>b : Foo
>new FooIterator : FooIterator
>FooIterator : typeof FooIterator
fun(new FooIterator);
>fun(new FooIterator) : void
>fun : ([a, b]?: FooIterator) => void
>new FooIterator : FooIterator
>FooIterator : typeof FooIterator
class Bar { x }
>Bar : Bar
>x : any
class Foo extends Bar { y }
>Foo : Foo
>Bar : Bar
>y : any
class FooIterator {
>FooIterator : FooIterator
next() {
>next : () => { value: Foo; done: boolean; }
return {
>{ value: new Foo, done: false } : { value: Foo; done: boolean; }
value: new Foo,
>value : Foo
>new Foo : Foo
>Foo : typeof Foo
done: false
>done : boolean
};
}
[Symbol.iterator]() {
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
return this;
>this : FooIterator
}
}

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern12.ts]
function fun([a, ...b] = new FooIterator) { }
fun(new FooIterator);
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern12.js]
function fun([a, ...b] = new FooIterator) { }
fun(new FooIterator);
class Bar {
}
class Foo extends Bar {
}
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,52 @@
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern12.ts ===
function fun([a, ...b] = new FooIterator) { }
>fun : ([a, ...b]?: FooIterator) => void
>a : Foo
>b : Foo[]
>new FooIterator : FooIterator
>FooIterator : typeof FooIterator
fun(new FooIterator);
>fun(new FooIterator) : void
>fun : ([a, ...b]?: FooIterator) => void
>new FooIterator : FooIterator
>FooIterator : typeof FooIterator
class Bar { x }
>Bar : Bar
>x : any
class Foo extends Bar { y }
>Foo : Foo
>Bar : Bar
>y : any
class FooIterator {
>FooIterator : FooIterator
next() {
>next : () => { value: Foo; done: boolean; }
return {
>{ value: new Foo, done: false } : { value: Foo; done: boolean; }
value: new Foo,
>value : Foo
>new Foo : Foo
>Foo : typeof Foo
done: false
>done : boolean
};
}
[Symbol.iterator]() {
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
return this;
>this : FooIterator
}
}

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern13.ts]
function fun([a, ...b]) { }
fun(new FooIterator);
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern13.js]
function fun([a, ...b]) { }
fun(new FooIterator);
class Bar {
}
class Foo extends Bar {
}
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,50 @@
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern13.ts ===
function fun([a, ...b]) { }
>fun : ([a, ...b]: Iterable<any>) => void
>a : any
>b : any[]
fun(new FooIterator);
>fun(new FooIterator) : void
>fun : ([a, ...b]: Iterable<any>) => void
>new FooIterator : FooIterator
>FooIterator : typeof FooIterator
class Bar { x }
>Bar : Bar
>x : any
class Foo extends Bar { y }
>Foo : Foo
>Bar : Bar
>y : any
class FooIterator {
>FooIterator : FooIterator
next() {
>next : () => { value: Foo; done: boolean; }
return {
>{ value: new Foo, done: false } : { value: Foo; done: boolean; }
value: new Foo,
>value : Foo
>new Foo : Foo
>Foo : typeof Foo
done: false
>done : boolean
};
}
[Symbol.iterator]() {
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
return this;
>this : FooIterator
}
}

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern14.ts]
function fun(...[a, ...b]) { }
fun(new FooIterator);
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern14.js]
function fun(...[a, ...b]) { }
fun(new FooIterator);
class Bar {
}
class Foo extends Bar {
}
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,50 @@
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern14.ts ===
function fun(...[a, ...b]) { }
>fun : (...[a, ...b]: any[]) => void
>a : any
>b : any[]
fun(new FooIterator);
>fun(new FooIterator) : void
>fun : (...[a, ...b]: any[]) => void
>new FooIterator : FooIterator
>FooIterator : typeof FooIterator
class Bar { x }
>Bar : Bar
>x : any
class Foo extends Bar { y }
>Foo : Foo
>Bar : Bar
>y : any
class FooIterator {
>FooIterator : FooIterator
next() {
>next : () => { value: Foo; done: boolean; }
return {
>{ value: new Foo, done: false } : { value: Foo; done: boolean; }
value: new Foo,
>value : Foo
>new Foo : Foo
>Foo : typeof Foo
done: false
>done : boolean
};
}
[Symbol.iterator]() {
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
return this;
>this : FooIterator
}
}

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern15.ts]
function fun(...[a, b]: Bar[]) { }
fun(...new FooIterator);
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern15.js]
function fun(...[a, b]) { }
fun(...new FooIterator);
class Bar {
}
class Foo extends Bar {
}
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,52 @@
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern15.ts ===
function fun(...[a, b]: Bar[]) { }
>fun : (...[a, b]: Bar[]) => void
>a : Bar
>b : Bar
>Bar : Bar
fun(...new FooIterator);
>fun(...new FooIterator) : void
>fun : (...[a, b]: Bar[]) => void
>...new FooIterator : Foo
>new FooIterator : FooIterator
>FooIterator : typeof FooIterator
class Bar { x }
>Bar : Bar
>x : any
class Foo extends Bar { y }
>Foo : Foo
>Bar : Bar
>y : any
class FooIterator {
>FooIterator : FooIterator
next() {
>next : () => { value: Foo; done: boolean; }
return {
>{ value: new Foo, done: false } : { value: Foo; done: boolean; }
value: new Foo,
>value : Foo
>new Foo : Foo
>Foo : typeof Foo
done: false
>done : boolean
};
}
[Symbol.iterator]() {
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
return this;
>this : FooIterator
}
}

View File

@ -0,0 +1,37 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts(2,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[Bar, Bar]'.
Property '0' is missing in type 'FooIterator'.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts (1 errors) ====
function fun(...[a, b]: [Bar, Bar][]) { }
fun(...new FooIteratorIterator);
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[Bar, Bar]'.
!!! error TS2345: Property '0' is missing in type 'FooIterator'.
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
class FooIteratorIterator {
next() {
return {
value: new FooIterator,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,60 @@
//// [iterableArrayPattern16.ts]
function fun(...[a, b]: [Bar, Bar][]) { }
fun(...new FooIteratorIterator);
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
class FooIteratorIterator {
next() {
return {
value: new FooIterator,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern16.js]
function fun(...[a, b]) { }
fun(...new FooIteratorIterator);
class Bar {
}
class Foo extends Bar {
}
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
class FooIteratorIterator {
next() {
return {
value: new FooIterator,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,24 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts(2,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type 'Bar'.
Property 'x' is missing in type 'FooIterator'.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts (1 errors) ====
function fun(...[a, b]: Bar[]) { }
fun(new FooIterator);
~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type 'Bar'.
!!! error TS2345: Property 'x' is missing in type 'FooIterator'.
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern17.ts]
function fun(...[a, b]: Bar[]) { }
fun(new FooIterator);
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern17.js]
function fun(...[a, b]) { }
fun(new FooIterator);
class Bar {
}
class Foo extends Bar {
}
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,24 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern18.ts(2,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type 'Bar[]'.
Property 'length' is missing in type 'FooIterator'.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern18.ts (1 errors) ====
function fun([a, b]: Bar[]) { }
fun(new FooIterator);
~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type 'Bar[]'.
!!! error TS2345: Property 'length' is missing in type 'FooIterator'.
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern18.ts]
function fun([a, b]: Bar[]) { }
fun(new FooIterator);
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern18.js]
function fun([a, b]) { }
fun(new FooIterator);
class Bar {
}
class Foo extends Bar {
}
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,24 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern19.ts(2,5): error TS2345: Argument of type 'FooArrayIterator' is not assignable to parameter of type 'Bar[][]'.
Property 'length' is missing in type 'FooArrayIterator'.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern19.ts (1 errors) ====
function fun([[a], b]: Bar[][]) { }
fun(new FooArrayIterator);
~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type 'FooArrayIterator' is not assignable to parameter of type 'Bar[][]'.
!!! error TS2345: Property 'length' is missing in type 'FooArrayIterator'.
class Bar { x }
class Foo extends Bar { y }
class FooArrayIterator {
next() {
return {
value: [new Foo],
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern19.ts]
function fun([[a], b]: Bar[][]) { }
fun(new FooArrayIterator);
class Bar { x }
class Foo extends Bar { y }
class FooArrayIterator {
next() {
return {
value: [new Foo],
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern19.js]
function fun([[a], b]) { }
fun(new FooArrayIterator);
class Bar {
}
class Foo extends Bar {
}
class FooArrayIterator {
next() {
return {
value: [new Foo],
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,28 @@
//// [iterableArrayPattern2.ts]
var [a, ...b] = new SymbolIterator;
class SymbolIterator {
next() {
return {
value: Symbol(),
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern2.js]
var [a, ...b] = new SymbolIterator;
class SymbolIterator {
next() {
return {
value: Symbol(),
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,36 @@
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern2.ts ===
var [a, ...b] = new SymbolIterator;
>a : symbol
>b : symbol[]
>new SymbolIterator : SymbolIterator
>SymbolIterator : typeof SymbolIterator
class SymbolIterator {
>SymbolIterator : SymbolIterator
next() {
>next : () => { value: symbol; done: boolean; }
return {
>{ value: Symbol(), done: false } : { value: symbol; done: boolean; }
value: Symbol(),
>value : symbol
>Symbol() : symbol
>Symbol : SymbolConstructor
done: false
>done : boolean
};
}
[Symbol.iterator]() {
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
return this;
>this : SymbolIterator
}
}

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern20.ts]
function fun(...[[a = new Foo], b = [new Foo]]: Bar[][]) { }
fun(...new FooArrayIterator);
class Bar { x }
class Foo extends Bar { y }
class FooArrayIterator {
next() {
return {
value: [new Foo],
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern20.js]
function fun(...[[a = new Foo], b = [new Foo]]) { }
fun(...new FooArrayIterator);
class Bar {
}
class Foo extends Bar {
}
class FooArrayIterator {
next() {
return {
value: [new Foo],
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,58 @@
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern20.ts ===
function fun(...[[a = new Foo], b = [new Foo]]: Bar[][]) { }
>fun : (...[[a = new Foo], b = [new Foo]]: Bar[][]) => void
>a : Bar
>new Foo : Foo
>Foo : typeof Foo
>b : Bar[]
>[new Foo] : Foo[]
>new Foo : Foo
>Foo : typeof Foo
>Bar : Bar
fun(...new FooArrayIterator);
>fun(...new FooArrayIterator) : void
>fun : (...[[a = new Foo], b = [new Foo]]: Bar[][]) => void
>...new FooArrayIterator : Foo[]
>new FooArrayIterator : FooArrayIterator
>FooArrayIterator : typeof FooArrayIterator
class Bar { x }
>Bar : Bar
>x : any
class Foo extends Bar { y }
>Foo : Foo
>Bar : Bar
>y : any
class FooArrayIterator {
>FooArrayIterator : FooArrayIterator
next() {
>next : () => { value: Foo[]; done: boolean; }
return {
>{ value: [new Foo], done: false } : { value: Foo[]; done: boolean; }
value: [new Foo],
>value : Foo[]
>[new Foo] : Foo[]
>new Foo : Foo
>Foo : typeof Foo
done: false
>done : boolean
};
}
[Symbol.iterator]() {
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
return this;
>this : FooArrayIterator
}
}

View File

@ -0,0 +1,7 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern21.ts(1,5): error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern21.ts (1 errors) ====
var [a, b] = { 0: "", 1: true };
~~~~~~
!!! error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.

View File

@ -0,0 +1,5 @@
//// [iterableArrayPattern21.ts]
var [a, b] = { 0: "", 1: true };
//// [iterableArrayPattern21.js]
var [a, b] = { 0: "", 1: true };

View File

@ -0,0 +1,7 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern22.ts(1,5): error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern22.ts (1 errors) ====
var [...a] = { 0: "", 1: true };
~~~~~~
!!! error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.

View File

@ -0,0 +1,5 @@
//// [iterableArrayPattern22.ts]
var [...a] = { 0: "", 1: true };
//// [iterableArrayPattern22.js]
var [...a] = { 0: "", 1: true };

View File

@ -0,0 +1,8 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern23.ts(2,1): error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern23.ts (1 errors) ====
var a: string, b: boolean;
[a, b] = { 0: "", 1: true };
~~~~~~
!!! error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.

View File

@ -0,0 +1,7 @@
//// [iterableArrayPattern23.ts]
var a: string, b: boolean;
[a, b] = { 0: "", 1: true };
//// [iterableArrayPattern23.js]
var a, b;
[a, b] = { 0: "", 1: true };

View File

@ -0,0 +1,8 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern24.ts(2,1): error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern24.ts (1 errors) ====
var a: string, b: boolean[];
[a, ...b] = { 0: "", 1: true };
~~~~~~~~~
!!! error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator.

View File

@ -0,0 +1,7 @@
//// [iterableArrayPattern24.ts]
var a: string, b: boolean[];
[a, ...b] = { 0: "", 1: true };
//// [iterableArrayPattern24.js]
var a, b;
[a, ...b] = { 0: "", 1: true };

View File

@ -0,0 +1,8 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts(1,30): error TS2370: A rest parameter must be of an array type.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts (1 errors) ====
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { }
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2370: A rest parameter must be of an array type.
takeFirstTwoEntries(new Map([["", 0], ["hello", 1]]));

View File

@ -0,0 +1,7 @@
//// [iterableArrayPattern25.ts]
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { }
takeFirstTwoEntries(new Map([["", 0], ["hello", 1]]));
//// [iterableArrayPattern25.js]
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { }
takeFirstTwoEntries(new Map([["", 0], ["hello", 1]]));

View File

@ -0,0 +1,10 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts(2,21): error TS2345: Argument of type 'Map<string, number>' is not assignable to parameter of type '[string, number]'.
Property '0' is missing in type 'Map<string, number>'.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts (1 errors) ====
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
takeFirstTwoEntries(new Map([["", 0], ["hello", 1]]));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type 'Map<string, number>' is not assignable to parameter of type '[string, number]'.
!!! error TS2345: Property '0' is missing in type 'Map<string, number>'.

View File

@ -0,0 +1,7 @@
//// [iterableArrayPattern26.ts]
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
takeFirstTwoEntries(new Map([["", 0], ["hello", 1]]));
//// [iterableArrayPattern26.js]
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { }
takeFirstTwoEntries(new Map([["", 0], ["hello", 1]]));

View File

@ -0,0 +1,7 @@
//// [iterableArrayPattern27.ts]
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
takeFirstTwoEntries(...new Map([["", 0], ["hello", 1]]));
//// [iterableArrayPattern27.js]
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { }
takeFirstTwoEntries(...new Map([["", 0], ["hello", 1]]));

View File

@ -0,0 +1,18 @@
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern27.ts ===
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
>takeFirstTwoEntries : (...[[k1, v1], [k2, v2]]: [string, number][]) => void
>k1 : string
>v1 : number
>k2 : string
>v2 : number
takeFirstTwoEntries(...new Map([["", 0], ["hello", 1]]));
>takeFirstTwoEntries(...new Map([["", 0], ["hello", 1]])) : void
>takeFirstTwoEntries : (...[[k1, v1], [k2, v2]]: [string, number][]) => void
>...new Map([["", 0], ["hello", 1]]) : [string, number]
>new Map([["", 0], ["hello", 1]]) : Map<string, number>
>Map : MapConstructor
>[["", 0], ["hello", 1]] : [string, number][]
>["", 0] : [string, number]
>["hello", 1] : [string, number]

View File

@ -0,0 +1,10 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(2,28): error TS2453: The type argument for type parameter 'V' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'boolean'.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts (1 errors) ====
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
takeFirstTwoEntries(...new Map([["", 0], ["hello", true]]));
~~~
!!! error TS2453: The type argument for type parameter 'V' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'boolean'.

View File

@ -0,0 +1,7 @@
//// [iterableArrayPattern28.ts]
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
takeFirstTwoEntries(...new Map([["", 0], ["hello", true]]));
//// [iterableArrayPattern28.js]
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { }
takeFirstTwoEntries(...new Map([["", 0], ["hello", true]]));

View File

@ -0,0 +1,12 @@
tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts(2,21): error TS2345: Argument of type '[string, boolean]' is not assignable to parameter of type '[string, number]'.
Types of property '1' are incompatible.
Type 'boolean' is not assignable to type 'number'.
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts (1 errors) ====
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
takeFirstTwoEntries(...new Map([["", true], ["hello", true]]));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[string, boolean]' is not assignable to parameter of type '[string, number]'.
!!! error TS2345: Types of property '1' are incompatible.
!!! error TS2345: Type 'boolean' is not assignable to type 'number'.

View File

@ -0,0 +1,7 @@
//// [iterableArrayPattern29.ts]
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
takeFirstTwoEntries(...new Map([["", true], ["hello", true]]));
//// [iterableArrayPattern29.js]
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { }
takeFirstTwoEntries(...new Map([["", true], ["hello", true]]));

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern3.ts]
var a: Bar, b: Bar;
[a, b] = new FooIterator;
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern3.js]
var a, b;
[a, b] = new FooIterator;
class Bar {
}
class Foo extends Bar {
}
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,53 @@
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern3.ts ===
var a: Bar, b: Bar;
>a : Bar
>Bar : Bar
>b : Bar
>Bar : Bar
[a, b] = new FooIterator;
>[a, b] = new FooIterator : FooIterator
>[a, b] : [Bar, Bar]
>a : Bar
>b : Bar
>new FooIterator : FooIterator
>FooIterator : typeof FooIterator
class Bar { x }
>Bar : Bar
>x : any
class Foo extends Bar { y }
>Foo : Foo
>Bar : Bar
>y : any
class FooIterator {
>FooIterator : FooIterator
next() {
>next : () => { value: Foo; done: boolean; }
return {
>{ value: new Foo, done: false } : { value: Foo; done: boolean; }
value: new Foo,
>value : Foo
>new Foo : Foo
>Foo : typeof Foo
done: false
>done : boolean
};
}
[Symbol.iterator]() {
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
return this;
>this : FooIterator
}
}

View File

@ -0,0 +1,5 @@
//// [iterableArrayPattern30.ts]
const [[k1, v1], [k2, v2]] = new Map([["", true], ["hello", true]])
//// [iterableArrayPattern30.js]
const [[k1, v1], [k2, v2]] = new Map([["", true], ["hello", true]]);

View File

@ -0,0 +1,12 @@
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern30.ts ===
const [[k1, v1], [k2, v2]] = new Map([["", true], ["hello", true]])
>k1 : string
>v1 : boolean
>k2 : string
>v2 : boolean
>new Map([["", true], ["hello", true]]) : Map<string, boolean>
>Map : MapConstructor
>[["", true], ["hello", true]] : [string, boolean][]
>["", true] : [string, boolean]
>["hello", true] : [string, boolean]

View File

@ -0,0 +1,36 @@
//// [iterableArrayPattern4.ts]
var a: Bar, b: Bar[];
[a, ...b] = new FooIterator;
class Bar { x }
class Foo extends Bar { y }
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}
//// [iterableArrayPattern4.js]
var a, b;
[a, ...b] = new FooIterator;
class Bar {
}
class Foo extends Bar {
}
class FooIterator {
next() {
return {
value: new Foo,
done: false
};
}
[Symbol.iterator]() {
return this;
}
}

Some files were not shown because too many files have changed in this diff Show More