Merge pull request #1127 from Microsoft/shorthandProperty

Shorthand property
This commit is contained in:
Yui 2014-11-17 13:09:49 -08:00
commit acc2550a7f
53 changed files with 1230 additions and 37 deletions

View file

@ -380,6 +380,7 @@ module ts {
break;
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.EnumMember:

View file

@ -93,6 +93,7 @@ module ts {
getReturnTypeOfSignature: getReturnTypeOfSignature,
getSymbolsInScope: getSymbolsInScope,
getSymbolInfo: getSymbolInfo,
getShorthandAssignmentValueSymbol: getShorthandAssignmentValueSymbol,
getTypeOfNode: getTypeOfNode,
typeToString: typeToString,
getSymbolDisplayBuilder: getSymbolDisplayBuilder,
@ -109,6 +110,7 @@ module ts {
getAliasedSymbol: resolveImport,
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
hasEarlyErrors: hasEarlyErrors,
isEmitBlocked: isEmitBlocked
};
@ -1665,6 +1667,13 @@ module ts {
}
return type;
}
// If it is a short-hand property assignment; Use the type of the identifier
if (declaration.kind === SyntaxKind.ShorthandPropertyAssignment) {
var type = checkIdentifier(<Identifier>declaration.name);
return type
}
// Rest parameters default to type any[], other parameters default to type any
var type = declaration.flags & NodeFlags.Rest ? createArrayType(anyType) : anyType;
checkImplicitAny(type);
@ -2399,7 +2408,7 @@ module ts {
}
// Return the symbol for the property with the given name in the given type. Creates synthetic union properties when
// necessary, maps primtive types and type parameters are to their apparent types, and augments with properties from
// necessary, maps primitive types and type parameters are to their apparent types, and augments with properties from
// Object and Function as appropriate.
function getPropertyOfType(type: Type, name: string): Symbol {
if (type.flags & TypeFlags.Union) {
@ -2434,7 +2443,7 @@ module ts {
}
// Return the signatures of the given kind in the given type. Creates synthetic union signatures when necessary and
// maps primtive types and type parameters are to their apparent types.
// maps primitive types and type parameters are to their apparent types.
function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] {
return getSignaturesOfObjectOrUnionType(getApparentType(type), kind);
}
@ -2447,7 +2456,7 @@ module ts {
}
// Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and
// maps primtive types and type parameters are to their apparent types.
// maps primitive types and type parameters are to their apparent types.
function getIndexTypeOfType(type: Type, kind: IndexKind): Type {
return getIndexTypeOfObjectOrUnionType(getApparentType(type), kind);
}
@ -5000,7 +5009,15 @@ module ts {
if (hasProperty(members, id)) {
var member = members[id];
if (member.flags & SymbolFlags.Property) {
var type = checkExpression((<PropertyDeclaration>member.declarations[0]).initializer, contextualMapper);
var memberDecl = <PropertyDeclaration>member.declarations[0];
var type: Type;
if (memberDecl.kind === SyntaxKind.PropertyAssignment) {
type = checkExpression(memberDecl.initializer, contextualMapper);
}
else {
Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment);
type = checkExpression(memberDecl.name, contextualMapper);
}
var prop = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name);
prop.declarations = member.declarations;
prop.parent = member.parent;
@ -8816,6 +8833,16 @@ module ts {
return undefined;
}
function getShorthandAssignmentValueSymbol(location: Node): Symbol {
// The function returns a value symbol of an identifier in the short-hand property assignment.
// This is necessary as an identifier in short-hand property assignment can contains two meaning:
// property name and property value.
if (location && location.kind === SyntaxKind.ShorthandPropertyAssignment) {
return resolveEntityName(location, (<ShortHandPropertyDeclaration>location).name, SymbolFlags.Value);
}
return undefined;
}
function getTypeOfNode(node: Node): Type {
if (isInsideWithStatementBody(node)) {
// We cannot answer semantic questions within a with block, do not proceed any further

View file

@ -122,6 +122,7 @@ module ts {
let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." },
Invalid_template_literal_expected: { code: 1158, category: DiagnosticCategory.Error, key: "Invalid template literal; expected '}'" },
Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: DiagnosticCategory.Error, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." },
A_object_member_cannot_be_declared_optional: { code: 1160, category: DiagnosticCategory.Error, key: "A object member cannot be declared optional." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

View file

@ -480,6 +480,11 @@
"code": 1159
},
"A object member cannot be declared optional.": {
"category": "Error",
"code": 1160
},
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300

View file

@ -927,13 +927,14 @@ module ts {
}
}
function isNonExpressionIdentifier(node: Identifier) {
function isNotExpressionIdentifier(node: Identifier) {
var parent = node.parent;
switch (parent.kind) {
case SyntaxKind.Parameter:
case SyntaxKind.VariableDeclaration:
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
case SyntaxKind.EnumMember:
case SyntaxKind.Method:
case SyntaxKind.FunctionDeclaration:
@ -957,17 +958,24 @@ module ts {
}
}
function emitIdentifier(node: Identifier) {
if (!isNonExpressionIdentifier(node)) {
var prefix = resolver.getExpressionNamePrefix(node);
if (prefix) {
write(prefix);
write(".");
}
function emitExpressionIdentifier(node: Identifier) {
var prefix = resolver.getExpressionNamePrefix(node);
if (prefix) {
write(prefix);
write(".");
}
write(getSourceTextOfLocalNode(node));
}
function emitIdentifier(node: Identifier) {
if (!isNotExpressionIdentifier(node)) {
emitExpressionIdentifier(node);
}
else {
write(getSourceTextOfLocalNode(node));
}
}
function emitThis(node: Node) {
if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.LexicalThis) {
write("_this");
@ -1033,6 +1041,36 @@ module ts {
emitTrailingComments(node);
}
function emitShortHandPropertyAssignment(node: ShortHandPropertyDeclaration) {
function emitAsNormalPropertyAssignment() {
emitLeadingComments(node);
// Emit identifier as an identifier
emit(node.name);
write(": ");
// Even though this is stored as identified because it is in short-hand property assignment,
// treated it as expression
emitExpressionIdentifier(node.name);
emitTrailingComments(node);
}
if (compilerOptions.target < ScriptTarget.ES6) {
emitAsNormalPropertyAssignment();
}
else if (compilerOptions.target >= ScriptTarget.ES6) {
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment
var prefix = resolver.getExpressionNamePrefix(node.name);
if (prefix) {
emitAsNormalPropertyAssignment();
}
// If short-hand property has no prefix, emit it as short-hand.
else {
emitLeadingComments(node);
emit(node.name);
emitTrailingComments(node);
}
}
}
function tryEmitConstantValue(node: PropertyAccess | IndexedAccess): boolean {
var constantValue = resolver.getConstantValue(node);
if (constantValue !== undefined) {
@ -2250,6 +2288,8 @@ module ts {
return emitObjectLiteral(<ObjectLiteral>node);
case SyntaxKind.PropertyAssignment:
return emitPropertyAssignment(<PropertyDeclaration>node);
case SyntaxKind.ShorthandPropertyAssignment:
return emitShortHandPropertyAssignment(<ShortHandPropertyDeclaration>node);
case SyntaxKind.PropertyAccess:
return emitPropertyAccess(<PropertyAccess>node);
case SyntaxKind.IndexedAccess:

View file

@ -202,6 +202,7 @@ module ts {
child((<ParameterDeclaration>node).initializer);
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
return child((<PropertyDeclaration>node).name) ||
child((<PropertyDeclaration>node).type) ||
child((<PropertyDeclaration>node).initializer);
@ -580,6 +581,7 @@ module ts {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
case SyntaxKind.EnumMember:
case SyntaxKind.Method:
case SyntaxKind.FunctionDeclaration:
@ -2729,10 +2731,14 @@ module ts {
return finishNode(node);
}
function parsePropertyAssignment(): PropertyDeclaration {
var node = <PropertyDeclaration>createNode(SyntaxKind.PropertyAssignment);
node.name = parsePropertyName();
function parsePropertyAssignment(): Declaration {
var nodePos = scanner.getStartPos();
var nameToken = token;
var propertyName = parsePropertyName();
var node: Declaration;
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
node = <PropertyDeclaration>createNode(SyntaxKind.PropertyAssignment, nodePos);
node.name = propertyName;
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false);
var body = parseBody(/* ignoreMissingOpenBrace */ false);
// do not propagate property name as name for function expression
@ -2740,11 +2746,26 @@ module ts {
// var x = 1;
// var y = { x() { } }
// otherwise this will bring y.x into the scope of x which is incorrect
node.initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, undefined, sig, body);
(<PropertyDeclaration>node).initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, undefined, sig, body);
return finishNode(node);
}
// Disallow optional property assignment
if (token === SyntaxKind.QuestionToken) {
var questionStart = scanner.getTokenPos();
grammarErrorAtPos(questionStart, scanner.getStartPos() - questionStart, Diagnostics.A_object_member_cannot_be_declared_optional);
nextToken();
}
// Parse to check if it is short-hand property assignment or normal property assignment
if (token !== SyntaxKind.ColonToken && nameToken === SyntaxKind.Identifier) {
node = <ShortHandPropertyDeclaration>createNode(SyntaxKind.ShorthandPropertyAssignment, nodePos);
node.name = propertyName;
}
else {
node = <PropertyDeclaration>createNode(SyntaxKind.PropertyAssignment, nodePos);
node.name = propertyName;
parseExpected(SyntaxKind.ColonToken);
node.initializer = parseAssignmentExpression(false);
(<PropertyDeclaration>node).initializer = parseAssignmentExpression(false);
}
return finishNode(node);
}
@ -2794,6 +2815,9 @@ module ts {
if (p.kind === SyntaxKind.PropertyAssignment) {
currentKind = Property;
}
else if (p.kind === SyntaxKind.ShorthandPropertyAssignment) {
currentKind = Property;
}
else if (p.kind === SyntaxKind.GetAccessor) {
currentKind = GetAccessor;
}

View file

@ -167,6 +167,7 @@ module ts {
ArrayLiteral,
ObjectLiteral,
PropertyAssignment,
ShorthandPropertyAssignment,
PropertyAccess,
IndexedAccess,
CallExpression,
@ -335,6 +336,10 @@ module ts {
initializer?: Expression;
}
export interface ShortHandPropertyDeclaration extends Declaration {
name: Identifier;
}
export interface ParameterDeclaration extends VariableDeclaration { }
/**
@ -719,6 +724,7 @@ module ts {
getReturnTypeOfSignature(signature: Signature): Type;
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
getSymbolInfo(node: Node): Symbol;
getShorthandAssignmentValueSymbol(location: Node): Symbol;
getTypeOfNode(node: Node): Type;
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string;

View file

@ -2051,7 +2051,7 @@ module ts {
/** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */
function isNameOfPropertyAssignment(node: Node): boolean {
return (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) &&
node.parent.kind === SyntaxKind.PropertyAssignment && (<PropertyDeclaration>node.parent).name === node;
(node.parent.kind === SyntaxKind.PropertyAssignment || node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) && (<PropertyDeclaration>node.parent).name === node;
}
function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean {
@ -2745,7 +2745,7 @@ module ts {
var existingMemberNames: Map<boolean> = {};
forEach(existingMembers, m => {
if (m.kind !== SyntaxKind.PropertyAssignment) {
if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment) {
// Ignore omitted expressions for missing members in the object literal
return;
}
@ -4165,8 +4165,21 @@ module ts {
}
var referenceSymbol = typeInfoResolver.getSymbolInfo(referenceLocation);
if (referenceSymbol && isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation)) {
result.push(getReferenceEntryFromNode(referenceLocation));
if (referenceSymbol) {
var referenceSymbolDeclaration = referenceSymbol.valueDeclaration;
var shorthandValueSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration);
if (isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation)) {
result.push(getReferenceEntryFromNode(referenceLocation));
}
/* Because in short-hand property assignment, an identifier which stored as name of the short-hand property assignment
* has two meaning : property name and property value. Therefore when we do findAllReference at the position where
* an identifier is declared, the language service should return the position of the variable declaration as well as
* the position in short-hand property assignment excluding property accessing. However, if we do findAllReference at the
* position of property accessing, the referenceEntry of such position will be handled in the first case.
*/
else if (!(referenceSymbol.flags & SymbolFlags.Transient) && searchSymbols.indexOf(shorthandValueSymbol) >= 0) {
result.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name));
}
}
});
}
@ -4334,6 +4347,22 @@ module ts {
forEach(getPropertySymbolsFromContextualType(location), contextualSymbol => {
result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol));
});
/* Because in short-hand property assignment, location has two meaning : property name and as value of the property
* When we do findAllReference at the position of the short-hand property assignment, we would want to have references to position of
* property name and variable declaration of the identifier.
* Like in below example, when querying for all references for an identifier 'name', of the property assignment, the language service
* should show both 'name' in 'obj' and 'name' in variable declaration
* var name = "Foo";
* var obj = { name };
* In order to do that, we will populate the search set with the value symbol of the identifier as a value of the property assignment
* so that when matching with potential reference symbol, both symbols from property declaration and variable declaration
* will be included correctly.
*/
var shorthandValueSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(location.parent);
if (shorthandValueSymbol) {
result.push(shorthandValueSymbol);
}
}
// If this is a union property, add all the symbols from all its source symbols in all unioned types.
@ -4674,6 +4703,7 @@ module ts {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
case SyntaxKind.EnumMember:
case SyntaxKind.Method:
case SyntaxKind.Constructor:

View file

@ -1,11 +1,14 @@
tests/cases/compiler/incompleteObjectLiteral1.ts(1,14): error TS1005: ':' expected.
tests/cases/compiler/incompleteObjectLiteral1.ts(1,14): error TS1005: ',' expected.
tests/cases/compiler/incompleteObjectLiteral1.ts(1,16): error TS1128: Declaration or statement expected.
tests/cases/compiler/incompleteObjectLiteral1.ts(1,12): error TS2304: Cannot find name 'aa'.
==== tests/cases/compiler/incompleteObjectLiteral1.ts (2 errors) ====
==== tests/cases/compiler/incompleteObjectLiteral1.ts (3 errors) ====
var tt = { aa; }
~
!!! error TS1005: ':' expected.
!!! error TS1005: ',' expected.
~
!!! error TS1128: Declaration or statement expected.
~~
!!! error TS2304: Cannot find name 'aa'.
var x = tt;

View file

@ -0,0 +1,39 @@
//// [objectLiteralShorthandProperties.ts]
var a, b, c;
var x1 = {
a
};
var x2 = {
a,
}
var x3 = {
a: 0,
b,
c,
d() { },
x3,
parent: x3
};
//// [objectLiteralShorthandProperties.js]
var a, b, c;
var x1 = {
a: a
};
var x2 = {
a: a,
};
var x3 = {
a: 0,
b: b,
c: c,
d: function () {
},
x3: x3,
parent: x3
};

View file

@ -0,0 +1,50 @@
=== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandProperties.ts ===
var a, b, c;
>a : any
>b : any
>c : any
var x1 = {
>x1 : { a: any; }
>{ a} : { a: any; }
a
>a : any
};
var x2 = {
>x2 : { a: any; }
>{ a,} : { a: any; }
a,
>a : any
}
var x3 = {
>x3 : any
>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d: () => void; x3: any; parent: any; }
a: 0,
>a : number
b,
>b : any
c,
>c : any
d() { },
>d : () => void
>d() { } : () => void
x3,
>x3 : any
parent: x3
>parent : any
>x3 : any
};

View file

@ -0,0 +1,36 @@
//// [objectLiteralShorthandPropertiesAssignment.ts]
var id: number = 10000;
var name: string = "my name";
var person: { name: string; id: number } = { name, id };
function foo( obj:{ name: string }): void { };
function bar(name: string, id: number) { return { name, id }; }
function bar1(name: string, id: number) { return { name }; }
function baz(name: string, id: number): { name: string; id: number } { return { name, id }; }
foo(person);
var person1 = bar("Hello", 5);
var person2: { name: string } = bar("Hello", 5);
var person3: { name: string; id:number } = bar("Hello", 5);
//// [objectLiteralShorthandPropertiesAssignment.js]
var id = 10000;
var name = "my name";
var person = { name: name, id: id };
function foo(obj) {
}
;
function bar(name, id) {
return { name: name, id: id };
}
function bar1(name, id) {
return { name: name };
}
function baz(name, id) {
return { name: name, id: id };
}
foo(person);
var person1 = bar("Hello", 5);
var person2 = bar("Hello", 5);
var person3 = bar("Hello", 5);

View file

@ -0,0 +1,68 @@
=== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignment.ts ===
var id: number = 10000;
>id : number
var name: string = "my name";
>name : string
var person: { name: string; id: number } = { name, id };
>person : { name: string; id: number; }
>name : string
>id : number
>{ name, id } : { name: string; id: number; }
>name : string
>id : number
function foo( obj:{ name: string }): void { };
>foo : (obj: { name: string; }) => void
>obj : { name: string; }
>name : string
function bar(name: string, id: number) { return { name, id }; }
>bar : (name: string, id: number) => { name: string; id: number; }
>name : string
>id : number
>{ name, id } : { name: string; id: number; }
>name : string
>id : number
function bar1(name: string, id: number) { return { name }; }
>bar1 : (name: string, id: number) => { name: string; }
>name : string
>id : number
>{ name } : { name: string; }
>name : string
function baz(name: string, id: number): { name: string; id: number } { return { name, id }; }
>baz : (name: string, id: number) => { name: string; id: number; }
>name : string
>id : number
>name : string
>id : number
>{ name, id } : { name: string; id: number; }
>name : string
>id : number
foo(person);
>foo(person) : void
>foo : (obj: { name: string; }) => void
>person : { name: string; id: number; }
var person1 = bar("Hello", 5);
>person1 : { name: string; id: number; }
>bar("Hello", 5) : { name: string; id: number; }
>bar : (name: string, id: number) => { name: string; id: number; }
var person2: { name: string } = bar("Hello", 5);
>person2 : { name: string; }
>name : string
>bar("Hello", 5) : { name: string; id: number; }
>bar : (name: string, id: number) => { name: string; id: number; }
var person3: { name: string; id:number } = bar("Hello", 5);
>person3 : { name: string; id: number; }
>name : string
>id : number
>bar("Hello", 5) : { name: string; id: number; }
>bar : (name: string, id: number) => { name: string; id: number; }

View file

@ -0,0 +1,36 @@
//// [objectLiteralShorthandPropertiesAssignmentES6.ts]
var id: number = 10000;
var name: string = "my name";
var person: { name: string; id: number } = { name, id };
function foo(obj: { name: string }): void { };
function bar(name: string, id: number) { return { name, id }; }
function bar1(name: string, id: number) { return { name }; }
function baz(name: string, id: number): { name: string; id: number } { return { name, id }; }
foo(person);
var person1 = bar("Hello", 5);
var person2: { name: string } = bar("Hello", 5);
var person3: { name: string; id: number } = bar("Hello", 5);
//// [objectLiteralShorthandPropertiesAssignmentES6.js]
var id = 10000;
var name = "my name";
var person = { name, id };
function foo(obj) {
}
;
function bar(name, id) {
return { name, id };
}
function bar1(name, id) {
return { name };
}
function baz(name, id) {
return { name, id };
}
foo(person);
var person1 = bar("Hello", 5);
var person2 = bar("Hello", 5);
var person3 = bar("Hello", 5);

View file

@ -0,0 +1,68 @@
=== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentES6.ts ===
var id: number = 10000;
>id : number
var name: string = "my name";
>name : string
var person: { name: string; id: number } = { name, id };
>person : { name: string; id: number; }
>name : string
>id : number
>{ name, id } : { name: string; id: number; }
>name : string
>id : number
function foo(obj: { name: string }): void { };
>foo : (obj: { name: string; }) => void
>obj : { name: string; }
>name : string
function bar(name: string, id: number) { return { name, id }; }
>bar : (name: string, id: number) => { name: string; id: number; }
>name : string
>id : number
>{ name, id } : { name: string; id: number; }
>name : string
>id : number
function bar1(name: string, id: number) { return { name }; }
>bar1 : (name: string, id: number) => { name: string; }
>name : string
>id : number
>{ name } : { name: string; }
>name : string
function baz(name: string, id: number): { name: string; id: number } { return { name, id }; }
>baz : (name: string, id: number) => { name: string; id: number; }
>name : string
>id : number
>name : string
>id : number
>{ name, id } : { name: string; id: number; }
>name : string
>id : number
foo(person);
>foo(person) : void
>foo : (obj: { name: string; }) => void
>person : { name: string; id: number; }
var person1 = bar("Hello", 5);
>person1 : { name: string; id: number; }
>bar("Hello", 5) : { name: string; id: number; }
>bar : (name: string, id: number) => { name: string; id: number; }
var person2: { name: string } = bar("Hello", 5);
>person2 : { name: string; }
>name : string
>bar("Hello", 5) : { name: string; id: number; }
>bar : (name: string, id: number) => { name: string; id: number; }
var person3: { name: string; id: number } = bar("Hello", 5);
>person3 : { name: string; id: number; }
>name : string
>id : number
>bar("Hello", 5) : { name: string; id: number; }
>bar : (name: string, id: number) => { name: string; id: number; }

View file

@ -0,0 +1,44 @@
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,16): error TS1131: Property or signature expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,25): error TS1128: Declaration or statement expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(6,53): error TS1005: ';' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(4,5): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'.
Property 'b' is missing in type '{ name: string; id: number; }'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(6,79): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ id: string; name: number; }'.
Types of property 'id' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(8,5): error TS2345: Argument of type '{ name: string; id: number; }' is not assignable to parameter of type '{ name: string; id: boolean; }'.
Types of property 'id' are incompatible.
Type 'number' is not assignable to type 'boolean'.
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts (7 errors) ====
var id: number = 10000;
var name: string = "my name";
var person: { b: string; id: number } = { name, id }; // error
~~~~~~
!!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'.
!!! error TS2322: Property 'b' is missing in type '{ name: string; id: number; }'.
var person1: { name, id }; // error: can't use short-hand property assignment in type position
~~~~
!!! error TS1131: Property or signature expected.
~
!!! error TS1128: Declaration or statement expected.
~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error
~
!!! error TS1005: ';' expected.
~~~~~~~~~~~~
!!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ id: string; name: number; }'.
!!! error TS2322: Types of property 'id' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
function bar(obj: { name: string; id: boolean }) { }
bar({ name, id }); // error
~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ name: string; id: number; }' is not assignable to parameter of type '{ name: string; id: boolean; }'.
!!! error TS2345: Types of property 'id' are incompatible.
!!! error TS2345: Type 'number' is not assignable to type 'boolean'.

View file

@ -0,0 +1,48 @@
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(5,55): error TS1005: ';' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(6,55): error TS1005: ';' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,16): error TS1131: Property or signature expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,25): error TS1128: Declaration or statement expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(8,28): error TS1005: ';' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(4,5): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'.
Property 'b' is missing in type '{ name: string; id: number; }'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(5,79): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ name: number; id: string; }'.
Types of property 'name' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(8,5): error TS2322: Type '{ name: number; id: string; }' is not assignable to type '{ name: string; id: number; }'.
Types of property 'name' are incompatible.
Type 'number' is not assignable to type 'string'.
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts (9 errors) ====
var id: number = 10000;
var name: string = "my name";
var person: { b: string; id: number } = { name, id }; // error
~~~~~~
!!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'.
!!! error TS2322: Property 'b' is missing in type '{ name: string; id: number; }'.
function bar(name: string, id: number): { name: number, id: string } { return { name, id }; } // error
~
!!! error TS1005: ';' expected.
~~~~~~~~~~~~
!!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ name: number; id: string; }'.
!!! error TS2322: Types of property 'name' are incompatible.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
function foo(name: string, id: number): { name: string, id: number } { return { name, id }; } // error
~
!!! error TS1005: ';' expected.
var person1: { name, id }; // error : Can't use shorthand in the type position
~~~~
!!! error TS1131: Property or signature expected.
~
!!! error TS1128: Declaration or statement expected.
~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
var person2: { name: string, id: number } = bar("hello", 5);
~
!!! error TS1005: ';' expected.
~~~~~~~
!!! error TS2322: Type '{ name: number; id: string; }' is not assignable to type '{ name: string; id: number; }'.
!!! error TS2322: Types of property 'name' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type 'string'.

View file

@ -0,0 +1,39 @@
//// [objectLiteralShorthandPropertiesES6.ts]
var a, b, c;
var x1 = {
a
};
var x2 = {
a,
}
var x3 = {
a: 0,
b,
c,
d() { },
x3,
parent: x3
};
//// [objectLiteralShorthandPropertiesES6.js]
var a, b, c;
var x1 = {
a
};
var x2 = {
a,
};
var x3 = {
a: 0,
b,
c,
d: function () {
},
x3,
parent: x3
};

View file

@ -0,0 +1,50 @@
=== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesES6.ts ===
var a, b, c;
>a : any
>b : any
>c : any
var x1 = {
>x1 : { a: any; }
>{ a} : { a: any; }
a
>a : any
};
var x2 = {
>x2 : { a: any; }
>{ a,} : { a: any; }
a,
>a : any
}
var x3 = {
>x3 : any
>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d: () => void; x3: any; parent: any; }
a: 0,
>a : number
b,
>b : any
c,
>c : any
d() { },
>d : () => void
>d() { } : () => void
x3,
>x3 : any
parent: x3
>parent : any
>x3 : any
};

View file

@ -0,0 +1,11 @@
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNoneExistingIdentifier.ts(3,5): error TS2304: Cannot find name 'undefinedVariable'.
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNoneExistingIdentifier.ts (1 errors) ====
var x = {
x, // OK
undefinedVariable // Error
~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'undefinedVariable'.
}

View file

@ -0,0 +1,12 @@
//// [objectLiteralShorthandPropertiesErrorFromNoneExistingIdentifier.ts]
var x = {
x, // OK
undefinedVariable // Error
}
//// [objectLiteralShorthandPropertiesErrorFromNoneExistingIdentifier.js]
var x = {
x: x,
undefinedVariable: undefinedVariable // Error
};

View file

@ -0,0 +1,77 @@
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(3,20): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(4,7): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(5,10): error TS1005: '(' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(6,10): error TS1005: '(' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(7,9): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(8,10): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(9,8): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(10,10): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(12,1): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,6): error TS1005: ',' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,6): error TS1005: ',' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,6): error TS1005: '=' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(18,1): error TS1128: Declaration or statement expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(20,17): error TS1005: ':' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,5): error TS2300: Duplicate identifier 'a'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,7): error TS2304: Cannot find name 'b'.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,5): error TS2300: Duplicate identifier 'a'.
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts (18 errors) ====
// errors
var y = {
"stringLiteral",
~
!!! error TS1005: ':' expected.
42,
~
!!! error TS1005: ':' expected.
get e,
~
!!! error TS1005: '(' expected.
~
!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
set f,
~
!!! error TS1005: '(' expected.
this,
~
!!! error TS1005: ':' expected.
super,
~
!!! error TS1005: ':' expected.
var,
~
!!! error TS1005: ':' expected.
class,
~
!!! error TS1005: ':' expected.
typeof
};
~
!!! error TS1005: ':' expected.
var x = {
a.b,
~
!!! error TS1005: ',' expected.
~
!!! error TS2300: Duplicate identifier 'a'.
~
!!! error TS2304: Cannot find name 'b'.
a["ss"],
~
!!! error TS1005: ',' expected.
~
!!! error TS2300: Duplicate identifier 'a'.
a[1],
~
!!! error TS1005: '=' expected.
};
~
!!! error TS1128: Declaration or statement expected.
var v = { class }; // error
~
!!! error TS1005: ':' expected.

View file

@ -0,0 +1,24 @@
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorWithModule.ts(10,10): error TS1005: ',' expected.
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorWithModule.ts(14,3): error TS2339: Property 'y' does not exist on type 'typeof m'.
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorWithModule.ts (2 errors) ====
// module export
var x = "Foo";
module m {
export var x;
}
module n {
var z = 10000;
export var y = {
m.x // error
~
!!! error TS1005: ',' expected.
};
}
m.y.x;
~
!!! error TS2339: Property 'y' does not exist on type 'typeof m'.

View file

@ -0,0 +1,20 @@
//// [objectLiteralShorthandPropertiesFunctionArgument.ts]
var id: number = 10000;
var name: string = "my name";
var person = { name, id };
function foo(p: { name: string; id: number }) { }
foo(person);
var obj = { name: name, id: id };
//// [objectLiteralShorthandPropertiesFunctionArgument.js]
var id = 10000;
var name = "my name";
var person = { name: name, id: id };
function foo(p) {
}
foo(person);
var obj = { name: name, id: id };

View file

@ -0,0 +1,33 @@
=== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesFunctionArgument.ts ===
var id: number = 10000;
>id : number
var name: string = "my name";
>name : string
var person = { name, id };
>person : { name: string; id: number; }
>{ name, id } : { name: string; id: number; }
>name : string
>id : number
function foo(p: { name: string; id: number }) { }
>foo : (p: { name: string; id: number; }) => void
>p : { name: string; id: number; }
>name : string
>id : number
foo(person);
>foo(person) : void
>foo : (p: { name: string; id: number; }) => void
>person : { name: string; id: number; }
var obj = { name: name, id: id };
>obj : { name: string; id: number; }
>{ name: name, id: id } : { name: string; id: number; }
>name : string
>name : string
>id : number
>id : number

View file

@ -0,0 +1,14 @@
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesFunctionArgument2.ts(7,5): error TS2345: Argument of type '{ name: string; id: number; }' is not assignable to parameter of type '{ a: string; id: number; }'.
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesFunctionArgument2.ts (1 errors) ====
var id: number = 10000;
var name: string = "my name";
var person = { name, id };
function foo(p: { a: string; id: number }) { }
foo(person); // error
~~~~~~
!!! error TS2345: Argument of type '{ name: string; id: number; }' is not assignable to parameter of type '{ a: string; id: number; }'.

View file

@ -0,0 +1,17 @@
//// [objectLiteralShorthandPropertiesFunctionArgument2.ts]
var id: number = 10000;
var name: string = "my name";
var person = { name, id };
function foo(p: { a: string; id: number }) { }
foo(person); // error
//// [objectLiteralShorthandPropertiesFunctionArgument2.js]
var id = 10000;
var name = "my name";
var person = { name: name, id: id };
function foo(p) {
}
foo(person); // error

View file

@ -0,0 +1,30 @@
//// [objectLiteralShorthandPropertiesWithModule.ts]
// module export
module m {
export var x;
}
module m {
var z = x;
var y = {
a: x,
x
};
}
//// [objectLiteralShorthandPropertiesWithModule.js]
// module export
var m;
(function (m) {
m.x;
})(m || (m = {}));
var m;
(function (m) {
var z = m.x;
var y = {
a: m.x,
x: m.x
};
})(m || (m = {}));

View file

@ -0,0 +1,31 @@
=== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesWithModule.ts ===
// module export
module m {
>m : typeof m
export var x;
>x : any
}
module m {
>m : typeof m
var z = x;
>z : any
>x : any
var y = {
>y : { a: any; x: any; }
>{ a: x, x } : { a: any; x: any; }
a: x,
>a : any
>x : any
x
>x : any
};
}

View file

@ -0,0 +1,28 @@
//// [objectLiteralShorthandPropertiesWithModuleES6.ts]
module m {
export var x;
}
module m {
var z = x;
var y = {
a: x,
x
};
}
//// [objectLiteralShorthandPropertiesWithModuleES6.js]
var m;
(function (m) {
m.x;
})(m || (m = {}));
var m;
(function (m) {
var z = m.x;
var y = {
a: m.x,
x: m.x
};
})(m || (m = {}));

View file

@ -0,0 +1,30 @@
=== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesWithModuleES6.ts ===
module m {
>m : typeof m
export var x;
>x : any
}
module m {
>m : typeof m
var z = x;
>z : any
>x : any
var y = {
>y : { a: any; x: any; }
>{ a: x, x } : { a: any; x: any; }
a: x,
>a : any
>x : any
x
>x : any
};
}

View file

@ -1,10 +1,9 @@
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(12,6): error TS1112: A class member cannot be declared optional.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(20,6): error TS1112: A class member cannot be declared optional.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1005: ':' expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,7): error TS1109: Expression expected.
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1160: A object member cannot be declared optional.
==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts (4 errors) ====
==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts (3 errors) ====
// Basic uses of optional properties
var a: {
@ -33,8 +32,6 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith
var b = {
x?: 1 // error
~
!!! error TS1005: ':' expected.
~
!!! error TS1109: Expression expected.
!!! error TS1160: A object member cannot be declared optional.
}

View file

@ -1,13 +1,16 @@
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,14): error TS1005: ':' expected.
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,14): error TS1005: ',' expected.
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,16): error TS1128: Declaration or statement expected.
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts(1,12): error TS2304: Cannot find name 'aa'.
==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts (2 errors) ====
==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser512097.ts (3 errors) ====
var tt = { aa; } // After this point, no useful parsing occurs in the entire file
~
!!! error TS1005: ':' expected.
!!! error TS1005: ',' expected.
~
!!! error TS1128: Declaration or statement expected.
~~
!!! error TS2304: Cannot find name 'aa'.
if (true) {
}

View file

@ -1,11 +1,14 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(2,1): error TS1005: ':' expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(2,1): error TS1005: ',' expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(2,7): error TS1005: ':' expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts(1,11): error TS2304: Cannot find name 'a'.
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts (2 errors) ====
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ObjectLiterals/parserErrorRecovery_ObjectLiteral2.ts (3 errors) ====
var v = { a
~
!!! error TS2304: Cannot find name 'a'.
return;
~~~~~~
!!! error TS1005: ':' expected.
!!! error TS1005: ',' expected.
~
!!! error TS1005: ':' expected.

View file

@ -0,0 +1,20 @@
// @target: es5
var a, b, c;
var x1 = {
a
};
var x2 = {
a,
}
var x3 = {
a: 0,
b,
c,
d() { },
x3,
parent: x3
};

View file

@ -0,0 +1,13 @@
var id: number = 10000;
var name: string = "my name";
var person: { name: string; id: number } = { name, id };
function foo( obj:{ name: string }): void { };
function bar(name: string, id: number) { return { name, id }; }
function bar1(name: string, id: number) { return { name }; }
function baz(name: string, id: number): { name: string; id: number } { return { name, id }; }
foo(person);
var person1 = bar("Hello", 5);
var person2: { name: string } = bar("Hello", 5);
var person3: { name: string; id:number } = bar("Hello", 5);

View file

@ -0,0 +1,14 @@
// @target: es6
var id: number = 10000;
var name: string = "my name";
var person: { name: string; id: number } = { name, id };
function foo(obj: { name: string }): void { };
function bar(name: string, id: number) { return { name, id }; }
function bar1(name: string, id: number) { return { name }; }
function baz(name: string, id: number): { name: string; id: number } { return { name, id }; }
foo(person);
var person1 = bar("Hello", 5);
var person2: { name: string } = bar("Hello", 5);
var person3: { name: string; id: number } = bar("Hello", 5);

View file

@ -0,0 +1,9 @@
var id: number = 10000;
var name: string = "my name";
var person: { b: string; id: number } = { name, id }; // error
var person1: { name, id }; // error: can't use short-hand property assignment in type position
function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error
function bar(obj: { name: string; id: boolean }) { }
bar({ name, id }); // error

View file

@ -0,0 +1,8 @@
var id: number = 10000;
var name: string = "my name";
var person: { b: string; id: number } = { name, id }; // error
function bar(name: string, id: number): { name: number, id: string } { return { name, id }; } // error
function foo(name: string, id: number): { name: string, id: number } { return { name, id }; } // error
var person1: { name, id }; // error : Can't use shorthand in the type position
var person2: { name: string, id: number } = bar("hello", 5);

View file

@ -0,0 +1,20 @@
// @target: es6
var a, b, c;
var x1 = {
a
};
var x2 = {
a,
}
var x3 = {
a: 0,
b,
c,
d() { },
x3,
parent: x3
};

View file

@ -0,0 +1,4 @@
var x = {
x, // OK
undefinedVariable // Error
}

View file

@ -0,0 +1,20 @@
// errors
var y = {
"stringLiteral",
42,
get e,
set f,
this,
super,
var,
class,
typeof
};
var x = {
a.b,
a["ss"],
a[1],
};
var v = { class }; // error

View file

@ -0,0 +1,14 @@
// module export
var x = "Foo";
module m {
export var x;
}
module n {
var z = 10000;
export var y = {
m.x // error
};
}
m.y.x;

View file

@ -0,0 +1,10 @@
var id: number = 10000;
var name: string = "my name";
var person = { name, id };
function foo(p: { name: string; id: number }) { }
foo(person);
var obj = { name: name, id: id };

View file

@ -0,0 +1,7 @@
var id: number = 10000;
var name: string = "my name";
var person = { name, id };
function foo(p: { a: string; id: number }) { }
foo(person); // error

View file

@ -0,0 +1,13 @@
// module export
module m {
export var x;
}
module m {
var z = x;
var y = {
a: x,
x
};
}

View file

@ -0,0 +1,13 @@
// @target: es6
module m {
export var x;
}
module m {
var z = x;
var y = {
a: x,
x
};
}

View file

@ -0,0 +1,6 @@
///<reference path="fourslash.ts" />
//// var person: {name:string; id:number} = {n/**/
goTo.marker();
verify.completionListContains("name", /*text*/ undefined, /*documentation*/ undefined, "property");

View file

@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />
//// var person: {name:string; id: number} = { n/**/
goTo.marker();
verify.memberListContains('name');
verify.memberListContains('id');

View file

@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />
//// var person: {name:string; id: number} = { n/**/
goTo.marker();
verify.memberListContains('name');
verify.memberListContains('id');

View file

@ -0,0 +1,19 @@
/// <reference path='fourslash.ts'/>
//// var /*1*/name = "Foo";
////
//// var obj = { /*2*/name };
//// var obj1 = { /*3*/name:name };
//// obj./*4*/name;
goTo.marker('1');
verify.referencesCountIs(3);
goTo.marker('2');
verify.referencesCountIs(4);
goTo.marker('3');
verify.referencesCountIs(1);
goTo.marker('4');
verify.referencesCountIs(2);

View file

@ -0,0 +1,23 @@
/// <reference path='fourslash.ts'/>
//// var /*1*/dx = "Foo";
////
//// module M { export var /*2*/dx; }
//// module M {
//// var z = 100;
//// export var y = { /*3*/dx, z };
//// }
//// M.y./*4*/dx;
goTo.marker('1');
debugger;
verify.referencesCountIs(1);
goTo.marker('2');
verify.referencesCountIs(2);
goTo.marker('3');
verify.referencesCountIs(3);
goTo.marker('4');
verify.referencesCountIs(2);

View file

@ -0,0 +1,21 @@
/// <reference path='fourslash.ts' />
//// var name1 = undefined, id1 = undefined;
//// var /*obj1*/obj1 = {/*name1*/name1, /*id1*/id1};
//// var name2 = "Hello";
//// var id2 = 10000;
//// var /*obj2*/obj2 = {/*name2*/name2, /*id2*/id2};
goTo.marker("obj1");
verify.quickInfoIs("(var) obj1: {\n name1: any;\n id1: any;\n}");
goTo.marker("name1");
verify.quickInfoIs("(property) name1: any");
goTo.marker("id1");
verify.quickInfoIs("(property) id1: any");
goTo.marker("obj2");
verify.quickInfoIs("(var) obj2: {\n name2: string;\n id2: number;\n}");
goTo.marker("name2");
verify.quickInfoIs("(property) name2: string");
goTo.marker("id2");
verify.quickInfoIs("(property) id2: number");