Merge pull request #5535 from Microsoft/computedPropertiesInDestructuringPR
allow computed properties in destructuring, treat computed properties…
This commit is contained in:
commit
072e93898d
|
@ -189,6 +189,11 @@ namespace ts {
|
|||
}
|
||||
if (node.name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
const nameExpression = (<ComputedPropertyName>node.name).expression;
|
||||
// treat computed property names where expression is string/numeric literal as just string/numeric literal
|
||||
if (isStringOrNumericLiteral(nameExpression.kind)) {
|
||||
return (<LiteralExpression>nameExpression).text;
|
||||
}
|
||||
|
||||
Debug.assert(isWellKnownSymbolSyntactically(nameExpression));
|
||||
return getPropertyNameForKnownSymbolName((<PropertyAccessExpression>nameExpression).name.text);
|
||||
}
|
||||
|
|
|
@ -2342,6 +2342,26 @@ namespace ts {
|
|||
return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node);
|
||||
}
|
||||
|
||||
function getTextOfPropertyName(name: PropertyName): string {
|
||||
switch (name.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
return (<Identifier>name).text;
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
return (<LiteralExpression>name).text;
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
if (isStringOrNumericLiteral((<ComputedPropertyName>name).expression.kind)) {
|
||||
return (<LiteralExpression>(<ComputedPropertyName>name).expression).text;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isComputedNonLiteralName(name: PropertyName): boolean {
|
||||
return name.kind === SyntaxKind.ComputedPropertyName && !isStringOrNumericLiteral((<ComputedPropertyName>name).expression.kind);
|
||||
}
|
||||
|
||||
// Return the inferred type for a binding element
|
||||
function getTypeForBindingElement(declaration: BindingElement): Type {
|
||||
const pattern = <BindingPattern>declaration.parent;
|
||||
|
@ -2364,10 +2384,17 @@ namespace ts {
|
|||
if (pattern.kind === SyntaxKind.ObjectBindingPattern) {
|
||||
// Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form)
|
||||
const name = declaration.propertyName || <Identifier>declaration.name;
|
||||
if (isComputedNonLiteralName(name)) {
|
||||
// computed properties with non-literal names are treated as 'any'
|
||||
return anyType;
|
||||
}
|
||||
|
||||
// Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature,
|
||||
// or otherwise the type of the string index signature.
|
||||
type = getTypeOfPropertyOfType(parentType, name.text) ||
|
||||
isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, IndexKind.Number) ||
|
||||
const text = getTextOfPropertyName(name);
|
||||
|
||||
type = getTypeOfPropertyOfType(parentType, text) ||
|
||||
isNumericLiteralName(text) && getIndexTypeOfType(parentType, IndexKind.Number) ||
|
||||
getIndexTypeOfType(parentType, IndexKind.String);
|
||||
if (!type) {
|
||||
error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name));
|
||||
|
@ -2478,10 +2505,18 @@ namespace ts {
|
|||
// Return the type implied by an object binding pattern
|
||||
function getTypeFromObjectBindingPattern(pattern: BindingPattern, includePatternInType: boolean): Type {
|
||||
const members: SymbolTable = {};
|
||||
let hasComputedProperties = false;
|
||||
forEach(pattern.elements, e => {
|
||||
const flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : 0);
|
||||
const name = e.propertyName || <Identifier>e.name;
|
||||
const symbol = <TransientSymbol>createSymbol(flags, name.text);
|
||||
if (isComputedNonLiteralName(name)) {
|
||||
// do not include computed properties in the implied type
|
||||
hasComputedProperties = true;
|
||||
return;
|
||||
}
|
||||
|
||||
const text = getTextOfPropertyName(name);
|
||||
const flags = SymbolFlags.Property | SymbolFlags.Transient | (e.initializer ? SymbolFlags.Optional : 0);
|
||||
const symbol = <TransientSymbol>createSymbol(flags, text);
|
||||
symbol.type = getTypeFromBindingElement(e, includePatternInType);
|
||||
symbol.bindingElement = e;
|
||||
members[symbol.name] = symbol;
|
||||
|
@ -2490,6 +2525,9 @@ namespace ts {
|
|||
if (includePatternInType) {
|
||||
result.pattern = pattern;
|
||||
}
|
||||
if (hasComputedProperties) {
|
||||
result.flags |= TypeFlags.ObjectLiteralPatternWithComputedProperties;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -5013,7 +5051,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean {
|
||||
if (someConstituentTypeHasKind(target, TypeFlags.ObjectType)) {
|
||||
if (!(target.flags & TypeFlags.ObjectLiteralPatternWithComputedProperties) && someConstituentTypeHasKind(target, TypeFlags.ObjectType)) {
|
||||
for (const prop of getPropertiesOfObjectType(source)) {
|
||||
if (!isKnownProperty(target, prop.name)) {
|
||||
if (reportErrors) {
|
||||
|
@ -7467,6 +7505,7 @@ namespace ts {
|
|||
(contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern || contextualType.pattern.kind === SyntaxKind.ObjectLiteralExpression);
|
||||
let typeFlags: TypeFlags = 0;
|
||||
|
||||
let patternWithComputedProperties = false;
|
||||
for (const memberDecl of node.properties) {
|
||||
let member = memberDecl.symbol;
|
||||
if (memberDecl.kind === SyntaxKind.PropertyAssignment ||
|
||||
|
@ -7494,8 +7533,11 @@ namespace ts {
|
|||
if (isOptional) {
|
||||
prop.flags |= SymbolFlags.Optional;
|
||||
}
|
||||
if (hasDynamicName(memberDecl)) {
|
||||
patternWithComputedProperties = true;
|
||||
}
|
||||
}
|
||||
else if (contextualTypeHasPattern) {
|
||||
else if (contextualTypeHasPattern && !(contextualType.flags & TypeFlags.ObjectLiteralPatternWithComputedProperties)) {
|
||||
// If object literal is contextually typed by the implied type of a binding pattern, and if the
|
||||
// binding pattern specifies a default value for the property, make the property optional.
|
||||
const impliedProp = getPropertyOfType(contextualType, member.name);
|
||||
|
@ -7552,7 +7594,7 @@ namespace ts {
|
|||
const numberIndexType = getIndexType(IndexKind.Number);
|
||||
const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType);
|
||||
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshObjectLiteral;
|
||||
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags);
|
||||
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags) | (patternWithComputedProperties ? TypeFlags.ObjectLiteralPatternWithComputedProperties : 0);
|
||||
if (inDestructuringPattern) {
|
||||
result.pattern = node;
|
||||
}
|
||||
|
@ -10082,19 +10124,27 @@ namespace ts {
|
|||
const properties = node.properties;
|
||||
for (const p of properties) {
|
||||
if (p.kind === SyntaxKind.PropertyAssignment || p.kind === SyntaxKind.ShorthandPropertyAssignment) {
|
||||
// TODO(andersh): Computed property support
|
||||
const name = <Identifier>(<PropertyAssignment>p).name;
|
||||
const name = <PropertyName>(<PropertyAssignment>p).name;
|
||||
if (name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
checkComputedPropertyName(<ComputedPropertyName>name);
|
||||
}
|
||||
if (isComputedNonLiteralName(name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const text = getTextOfPropertyName(name);
|
||||
const type = isTypeAny(sourceType)
|
||||
? sourceType
|
||||
: getTypeOfPropertyOfType(sourceType, name.text) ||
|
||||
isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, IndexKind.Number) ||
|
||||
: getTypeOfPropertyOfType(sourceType, text) ||
|
||||
isNumericLiteralName(text) && getIndexTypeOfType(sourceType, IndexKind.Number) ||
|
||||
getIndexTypeOfType(sourceType, IndexKind.String);
|
||||
if (type) {
|
||||
if (p.kind === SyntaxKind.ShorthandPropertyAssignment) {
|
||||
checkDestructuringAssignment(<ShorthandPropertyAssignment>p, type);
|
||||
}
|
||||
else {
|
||||
checkDestructuringAssignment((<PropertyAssignment>p).initializer || name, type);
|
||||
// non-shorthand property assignments should always have initializers
|
||||
checkDestructuringAssignment((<PropertyAssignment>p).initializer, type);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -12227,6 +12277,14 @@ namespace ts {
|
|||
checkExpressionCached(node.initializer);
|
||||
}
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.BindingElement) {
|
||||
// check computed properties inside property names of binding elements
|
||||
if (node.propertyName && node.propertyName.kind === SyntaxKind.ComputedPropertyName) {
|
||||
checkComputedPropertyName(<ComputedPropertyName>node.propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
// For a binding pattern, check contained binding elements
|
||||
if (isBindingPattern(node.name)) {
|
||||
forEach((<BindingPattern>node.name).elements, checkSourceElement);
|
||||
|
@ -13338,11 +13396,14 @@ namespace ts {
|
|||
const enumIsConst = isConst(node);
|
||||
|
||||
for (const member of node.members) {
|
||||
if (member.name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
if (isComputedNonLiteralName(<PropertyName>member.name)) {
|
||||
error(member.name, Diagnostics.Computed_property_names_are_not_allowed_in_enums);
|
||||
}
|
||||
else if (isNumericLiteralName((<Identifier>member.name).text)) {
|
||||
error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name);
|
||||
else {
|
||||
const text = getTextOfPropertyName(<PropertyName>member.name);
|
||||
if (isNumericLiteralName(text)) {
|
||||
error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name);
|
||||
}
|
||||
}
|
||||
|
||||
const previousEnumMemberIsNonConstant = autoValue === undefined;
|
||||
|
@ -15800,7 +15861,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
function checkGrammarForNonSymbolComputedProperty(node: DeclarationName, message: DiagnosticMessage) {
|
||||
if (node.kind === SyntaxKind.ComputedPropertyName && !isWellKnownSymbolSyntactically((<ComputedPropertyName>node).expression)) {
|
||||
if (isDynamicName(node)) {
|
||||
return grammarErrorOnNode(node, message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4244,15 +4244,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
|||
return node;
|
||||
}
|
||||
|
||||
function createPropertyAccessForDestructuringProperty(object: Expression, propName: Identifier | LiteralExpression): Expression {
|
||||
// We create a synthetic copy of the identifier in order to avoid the rewriting that might
|
||||
// otherwise occur when the identifier is emitted.
|
||||
const syntheticName = <Identifier | LiteralExpression>createSynthesizedNode(propName.kind);
|
||||
syntheticName.text = propName.text;
|
||||
if (syntheticName.kind !== SyntaxKind.Identifier) {
|
||||
return createElementAccessExpression(object, syntheticName);
|
||||
function createPropertyAccessForDestructuringProperty(object: Expression, propName: PropertyName): Expression {
|
||||
let index: Expression;
|
||||
const nameIsComputed = propName.kind === SyntaxKind.ComputedPropertyName;
|
||||
if (nameIsComputed) {
|
||||
index = ensureIdentifier((<ComputedPropertyName>propName).expression, /* reuseIdentifierExpression */ false);
|
||||
}
|
||||
return createPropertyAccessExpression(object, syntheticName);
|
||||
else {
|
||||
// We create a synthetic copy of the identifier in order to avoid the rewriting that might
|
||||
// otherwise occur when the identifier is emitted.
|
||||
index = <Identifier | LiteralExpression>createSynthesizedNode(propName.kind);
|
||||
(<Identifier | LiteralExpression>index).text = (<Identifier | LiteralExpression>propName).text;
|
||||
}
|
||||
|
||||
return !nameIsComputed && index.kind === SyntaxKind.Identifier
|
||||
? createPropertyAccessExpression(object, <Identifier>index)
|
||||
: createElementAccessExpression(object, index);
|
||||
}
|
||||
|
||||
function createSliceCall(value: Expression, sliceIndex: number): CallExpression {
|
||||
|
|
|
@ -1087,7 +1087,7 @@ namespace ts {
|
|||
token === SyntaxKind.NumericLiteral;
|
||||
}
|
||||
|
||||
function parsePropertyNameWorker(allowComputedPropertyNames: boolean): DeclarationName {
|
||||
function parsePropertyNameWorker(allowComputedPropertyNames: boolean): PropertyName {
|
||||
if (token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral) {
|
||||
return parseLiteralNode(/*internName*/ true);
|
||||
}
|
||||
|
@ -1097,7 +1097,7 @@ namespace ts {
|
|||
return parseIdentifierName();
|
||||
}
|
||||
|
||||
function parsePropertyName(): DeclarationName {
|
||||
function parsePropertyName(): PropertyName {
|
||||
return parsePropertyNameWorker(/*allowComputedPropertyNames:*/ true);
|
||||
}
|
||||
|
||||
|
@ -1207,7 +1207,7 @@ namespace ts {
|
|||
case ParsingContext.ObjectLiteralMembers:
|
||||
return token === SyntaxKind.OpenBracketToken || token === SyntaxKind.AsteriskToken || isLiteralPropertyName();
|
||||
case ParsingContext.ObjectBindingElements:
|
||||
return isLiteralPropertyName();
|
||||
return token === SyntaxKind.OpenBracketToken || isLiteralPropertyName();
|
||||
case ParsingContext.HeritageClauseElement:
|
||||
// If we see { } then only consume it as an expression if it is followed by , or {
|
||||
// That way we won't consume the body of a class in its heritage clause.
|
||||
|
@ -4587,7 +4587,6 @@ namespace ts {
|
|||
|
||||
function parseObjectBindingElement(): BindingElement {
|
||||
const node = <BindingElement>createNode(SyntaxKind.BindingElement);
|
||||
// TODO(andersh): Handle computed properties
|
||||
const tokenIsIdentifier = isIdentifier();
|
||||
const propertyName = parsePropertyName();
|
||||
if (tokenIsIdentifier && token !== SyntaxKind.ColonToken) {
|
||||
|
@ -4595,7 +4594,7 @@ namespace ts {
|
|||
}
|
||||
else {
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
node.propertyName = <Identifier>propertyName;
|
||||
node.propertyName = propertyName;
|
||||
node.name = parseIdentifierOrPattern();
|
||||
}
|
||||
node.initializer = parseBindingElementInitializer(/*inParameter*/ false);
|
||||
|
|
|
@ -491,6 +491,7 @@ namespace ts {
|
|||
|
||||
export type EntityName = Identifier | QualifiedName;
|
||||
|
||||
export type PropertyName = Identifier | LiteralExpression | ComputedPropertyName;
|
||||
export type DeclarationName = Identifier | LiteralExpression | ComputedPropertyName | BindingPattern;
|
||||
|
||||
export interface Declaration extends Node {
|
||||
|
@ -543,7 +544,7 @@ namespace ts {
|
|||
|
||||
// SyntaxKind.BindingElement
|
||||
export interface BindingElement extends Declaration {
|
||||
propertyName?: Identifier; // Binding property name (in object binding pattern)
|
||||
propertyName?: PropertyName; // Binding property name (in object binding pattern)
|
||||
dotDotDotToken?: Node; // Present on rest binding element
|
||||
name: Identifier | BindingPattern; // Declared binding element name
|
||||
initializer?: Expression; // Optional initializer
|
||||
|
@ -587,7 +588,7 @@ namespace ts {
|
|||
// SyntaxKind.ShorthandPropertyAssignment
|
||||
// SyntaxKind.EnumMember
|
||||
export interface VariableLikeDeclaration extends Declaration {
|
||||
propertyName?: Identifier;
|
||||
propertyName?: PropertyName;
|
||||
dotDotDotToken?: Node;
|
||||
name: DeclarationName;
|
||||
questionToken?: Node;
|
||||
|
@ -1824,6 +1825,7 @@ namespace ts {
|
|||
ContainsAnyFunctionType = 0x00800000, // Type is or contains object literal type
|
||||
ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6
|
||||
ThisType = 0x02000000, // This type
|
||||
ObjectLiteralPatternWithComputedProperties = 0x04000000, // Object literal type implied by binding pattern has computed properties
|
||||
|
||||
/* @internal */
|
||||
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null,
|
||||
|
|
|
@ -1489,6 +1489,10 @@ namespace ts {
|
|||
return isFunctionLike(node) && (node.flags & NodeFlags.Async) !== 0 && !isAccessor(node);
|
||||
}
|
||||
|
||||
export function isStringOrNumericLiteral(kind: SyntaxKind): boolean {
|
||||
return kind === SyntaxKind.StringLiteral || kind === SyntaxKind.NumericLiteral;
|
||||
}
|
||||
|
||||
/**
|
||||
* A declaration has a dynamic name if both of the following are true:
|
||||
* 1. The declaration has a computed property name
|
||||
|
@ -1497,9 +1501,13 @@ namespace ts {
|
|||
* Symbol.
|
||||
*/
|
||||
export function hasDynamicName(declaration: Declaration): boolean {
|
||||
return declaration.name &&
|
||||
declaration.name.kind === SyntaxKind.ComputedPropertyName &&
|
||||
!isWellKnownSymbolSyntactically((<ComputedPropertyName>declaration.name).expression);
|
||||
return declaration.name && isDynamicName(declaration.name);
|
||||
}
|
||||
|
||||
export function isDynamicName(name: DeclarationName): boolean {
|
||||
return name.kind === SyntaxKind.ComputedPropertyName &&
|
||||
!isStringOrNumericLiteral((<ComputedPropertyName>name).expression.kind) &&
|
||||
!isWellKnownSymbolSyntactically((<ComputedPropertyName>name).expression);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3916,7 +3916,10 @@ namespace ts {
|
|||
let existingName: string;
|
||||
|
||||
if (m.kind === SyntaxKind.BindingElement && (<BindingElement>m).propertyName) {
|
||||
existingName = (<BindingElement>m).propertyName.text;
|
||||
// include only identifiers in completion list
|
||||
if ((<BindingElement>m).propertyName.kind === SyntaxKind.Identifier) {
|
||||
existingName = (<Identifier>(<BindingElement>m).propertyName).text
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO(jfreeman): Account for computed property name
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(20,8): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(21,12): error TS2339: Property 'toExponential' does not exist on type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(33,4): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(34,5): error TS2365: Operator '+' cannot be applied to types 'number' and '{}'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/computedPropertiesInDestructuring1.ts (4 errors) ====
|
||||
// destructuring in variable declarations
|
||||
let foo = "bar";
|
||||
let {[foo]: bar} = {bar: "bar"};
|
||||
|
||||
let {["bar"]: bar2} = {bar: "bar"};
|
||||
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {bar: "bar"};
|
||||
|
||||
let [{[foo]: bar4}] = [{bar: "bar"}];
|
||||
let [{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
function f1({["bar"]: x}: { bar: number }) {}
|
||||
function f2({[foo]: x}: { bar: number }) {}
|
||||
function f3({[foo2()]: x}: { bar: number }) {}
|
||||
function f4([{[foo]: x}]: [{ bar: number }]) {}
|
||||
function f5([{[foo2()]: x}]: [{ bar: number }]) {}
|
||||
|
||||
// report errors on type errors in computed properties used in destructuring
|
||||
let [{[foo()]: bar6}] = [{bar: "bar"}];
|
||||
~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
let [{[foo.toExponential()]: bar7}] = [{bar: "bar"}];
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2339: Property 'toExponential' does not exist on type 'string'.
|
||||
|
||||
// destructuring assignment
|
||||
({[foo]: bar} = {bar: "bar"});
|
||||
|
||||
({["bar"]: bar2} = {bar: "bar"});
|
||||
|
||||
({[foo2()]: bar3} = {bar: "bar"});
|
||||
|
||||
[{[foo]: bar4}] = [{bar: "bar"}];
|
||||
[{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
[{[foo()]: bar4}] = [{bar: "bar"}];
|
||||
~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
[{[(1 + {})]: bar4}] = [{bar: "bar"}];
|
||||
~~~~~~
|
||||
!!! error TS2365: Operator '+' cannot be applied to types 'number' and '{}'.
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
//// [computedPropertiesInDestructuring1.ts]
|
||||
// destructuring in variable declarations
|
||||
let foo = "bar";
|
||||
let {[foo]: bar} = {bar: "bar"};
|
||||
|
||||
let {["bar"]: bar2} = {bar: "bar"};
|
||||
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {bar: "bar"};
|
||||
|
||||
let [{[foo]: bar4}] = [{bar: "bar"}];
|
||||
let [{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
function f1({["bar"]: x}: { bar: number }) {}
|
||||
function f2({[foo]: x}: { bar: number }) {}
|
||||
function f3({[foo2()]: x}: { bar: number }) {}
|
||||
function f4([{[foo]: x}]: [{ bar: number }]) {}
|
||||
function f5([{[foo2()]: x}]: [{ bar: number }]) {}
|
||||
|
||||
// report errors on type errors in computed properties used in destructuring
|
||||
let [{[foo()]: bar6}] = [{bar: "bar"}];
|
||||
let [{[foo.toExponential()]: bar7}] = [{bar: "bar"}];
|
||||
|
||||
// destructuring assignment
|
||||
({[foo]: bar} = {bar: "bar"});
|
||||
|
||||
({["bar"]: bar2} = {bar: "bar"});
|
||||
|
||||
({[foo2()]: bar3} = {bar: "bar"});
|
||||
|
||||
[{[foo]: bar4}] = [{bar: "bar"}];
|
||||
[{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
[{[foo()]: bar4}] = [{bar: "bar"}];
|
||||
[{[(1 + {})]: bar4}] = [{bar: "bar"}];
|
||||
|
||||
|
||||
|
||||
|
||||
//// [computedPropertiesInDestructuring1.js]
|
||||
// destructuring in variable declarations
|
||||
var foo = "bar";
|
||||
var _a = foo, bar = { bar: "bar" }[_a];
|
||||
var _b = "bar", bar2 = { bar: "bar" }[_b];
|
||||
var foo2 = function () { return "bar"; };
|
||||
var _c = foo2(), bar3 = { bar: "bar" }[_c];
|
||||
var _d = foo, bar4 = [{ bar: "bar" }][0][_d];
|
||||
var _e = foo2(), bar5 = [{ bar: "bar" }][0][_e];
|
||||
function f1(_a) {
|
||||
var _b = "bar", x = _a[_b];
|
||||
}
|
||||
function f2(_a) {
|
||||
var _b = foo, x = _a[_b];
|
||||
}
|
||||
function f3(_a) {
|
||||
var _b = foo2(), x = _a[_b];
|
||||
}
|
||||
function f4(_a) {
|
||||
var _b = foo, x = _a[0][_b];
|
||||
}
|
||||
function f5(_a) {
|
||||
var _b = foo2(), x = _a[0][_b];
|
||||
}
|
||||
// report errors on type errors in computed properties used in destructuring
|
||||
var _f = foo(), bar6 = [{ bar: "bar" }][0][_f];
|
||||
var _g = foo.toExponential(), bar7 = [{ bar: "bar" }][0][_g];
|
||||
// destructuring assignment
|
||||
(_h = { bar: "bar" }, _j = foo, bar = _h[_j], _h);
|
||||
(_k = { bar: "bar" }, _l = "bar", bar2 = _k[_l], _k);
|
||||
(_m = { bar: "bar" }, _o = foo2(), bar3 = _m[_o], _m);
|
||||
_p = foo, bar4 = [{ bar: "bar" }][0][_p];
|
||||
_q = foo2(), bar5 = [{ bar: "bar" }][0][_q];
|
||||
_r = foo(), bar4 = [{ bar: "bar" }][0][_r];
|
||||
_s = (1 + {}), bar4 = [{ bar: "bar" }][0][_s];
|
||||
var _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
@ -0,0 +1,51 @@
|
|||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(21,8): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(22,12): error TS2339: Property 'toExponential' does not exist on type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(34,4): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(35,5): error TS2365: Operator '+' cannot be applied to types 'number' and '{}'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts (4 errors) ====
|
||||
// destructuring in variable declarations
|
||||
let foo = "bar";
|
||||
let {[foo]: bar} = {bar: "bar"};
|
||||
|
||||
let {["bar"]: bar2} = {bar: "bar"};
|
||||
let {[11]: bar2_1} = {11: "bar"};
|
||||
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {bar: "bar"};
|
||||
|
||||
let [{[foo]: bar4}] = [{bar: "bar"}];
|
||||
let [{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
function f1({["bar"]: x}: { bar: number }) {}
|
||||
function f2({[foo]: x}: { bar: number }) {}
|
||||
function f3({[foo2()]: x}: { bar: number }) {}
|
||||
function f4([{[foo]: x}]: [{ bar: number }]) {}
|
||||
function f5([{[foo2()]: x}]: [{ bar: number }]) {}
|
||||
|
||||
// report errors on type errors in computed properties used in destructuring
|
||||
let [{[foo()]: bar6}] = [{bar: "bar"}];
|
||||
~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
let [{[foo.toExponential()]: bar7}] = [{bar: "bar"}];
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2339: Property 'toExponential' does not exist on type 'string'.
|
||||
|
||||
// destructuring assignment
|
||||
({[foo]: bar} = {bar: "bar"});
|
||||
|
||||
({["bar"]: bar2} = {bar: "bar"});
|
||||
|
||||
({[foo2()]: bar3} = {bar: "bar"});
|
||||
|
||||
[{[foo]: bar4}] = [{bar: "bar"}];
|
||||
[{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
[{[foo()]: bar4}] = [{bar: "bar"}];
|
||||
~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
[{[(1 + {})]: bar4}] = [{bar: "bar"}];
|
||||
~~~~~~
|
||||
!!! error TS2365: Operator '+' cannot be applied to types 'number' and '{}'.
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
//// [computedPropertiesInDestructuring1_ES6.ts]
|
||||
// destructuring in variable declarations
|
||||
let foo = "bar";
|
||||
let {[foo]: bar} = {bar: "bar"};
|
||||
|
||||
let {["bar"]: bar2} = {bar: "bar"};
|
||||
let {[11]: bar2_1} = {11: "bar"};
|
||||
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {bar: "bar"};
|
||||
|
||||
let [{[foo]: bar4}] = [{bar: "bar"}];
|
||||
let [{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
function f1({["bar"]: x}: { bar: number }) {}
|
||||
function f2({[foo]: x}: { bar: number }) {}
|
||||
function f3({[foo2()]: x}: { bar: number }) {}
|
||||
function f4([{[foo]: x}]: [{ bar: number }]) {}
|
||||
function f5([{[foo2()]: x}]: [{ bar: number }]) {}
|
||||
|
||||
// report errors on type errors in computed properties used in destructuring
|
||||
let [{[foo()]: bar6}] = [{bar: "bar"}];
|
||||
let [{[foo.toExponential()]: bar7}] = [{bar: "bar"}];
|
||||
|
||||
// destructuring assignment
|
||||
({[foo]: bar} = {bar: "bar"});
|
||||
|
||||
({["bar"]: bar2} = {bar: "bar"});
|
||||
|
||||
({[foo2()]: bar3} = {bar: "bar"});
|
||||
|
||||
[{[foo]: bar4}] = [{bar: "bar"}];
|
||||
[{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
[{[foo()]: bar4}] = [{bar: "bar"}];
|
||||
[{[(1 + {})]: bar4}] = [{bar: "bar"}];
|
||||
|
||||
|
||||
//// [computedPropertiesInDestructuring1_ES6.js]
|
||||
// destructuring in variable declarations
|
||||
let foo = "bar";
|
||||
let { [foo]: bar } = { bar: "bar" };
|
||||
let { ["bar"]: bar2 } = { bar: "bar" };
|
||||
let { [11]: bar2_1 } = { 11: "bar" };
|
||||
let foo2 = () => "bar";
|
||||
let { [foo2()]: bar3 } = { bar: "bar" };
|
||||
let [{ [foo]: bar4 }] = [{ bar: "bar" }];
|
||||
let [{ [foo2()]: bar5 }] = [{ bar: "bar" }];
|
||||
function f1({ ["bar"]: x }) { }
|
||||
function f2({ [foo]: x }) { }
|
||||
function f3({ [foo2()]: x }) { }
|
||||
function f4([{ [foo]: x }]) { }
|
||||
function f5([{ [foo2()]: x }]) { }
|
||||
// report errors on type errors in computed properties used in destructuring
|
||||
let [{ [foo()]: bar6 }] = [{ bar: "bar" }];
|
||||
let [{ [foo.toExponential()]: bar7 }] = [{ bar: "bar" }];
|
||||
// destructuring assignment
|
||||
({ [foo]: bar } = { bar: "bar" });
|
||||
({ ["bar"]: bar2 } = { bar: "bar" });
|
||||
({ [foo2()]: bar3 } = { bar: "bar" });
|
||||
[{ [foo]: bar4 }] = [{ bar: "bar" }];
|
||||
[{ [foo2()]: bar5 }] = [{ bar: "bar" }];
|
||||
[{ [foo()]: bar4 }] = [{ bar: "bar" }];
|
||||
[{ [(1 + {})]: bar4 }] = [{ bar: "bar" }];
|
|
@ -0,0 +1,7 @@
|
|||
//// [computedPropertiesInDestructuring2.ts]
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {};
|
||||
|
||||
//// [computedPropertiesInDestructuring2.js]
|
||||
var foo2 = function () { return "bar"; };
|
||||
var _a = foo2(), bar3 = {}[_a];
|
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/computedPropertiesInDestructuring2.ts ===
|
||||
let foo2 = () => "bar";
|
||||
>foo2 : Symbol(foo2, Decl(computedPropertiesInDestructuring2.ts, 0, 3))
|
||||
|
||||
let {[foo2()]: bar3} = {};
|
||||
>foo2 : Symbol(foo2, Decl(computedPropertiesInDestructuring2.ts, 0, 3))
|
||||
>bar3 : Symbol(bar3, Decl(computedPropertiesInDestructuring2.ts, 1, 5))
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
=== tests/cases/compiler/computedPropertiesInDestructuring2.ts ===
|
||||
let foo2 = () => "bar";
|
||||
>foo2 : () => string
|
||||
>() => "bar" : () => string
|
||||
>"bar" : string
|
||||
|
||||
let {[foo2()]: bar3} = {};
|
||||
>foo2() : string
|
||||
>foo2 : () => string
|
||||
>bar3 : any
|
||||
>{} : {}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
//// [computedPropertiesInDestructuring2_ES6.ts]
|
||||
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {};
|
||||
|
||||
//// [computedPropertiesInDestructuring2_ES6.js]
|
||||
let foo2 = () => "bar";
|
||||
let { [foo2()]: bar3 } = {};
|
|
@ -0,0 +1,9 @@
|
|||
=== tests/cases/compiler/computedPropertiesInDestructuring2_ES6.ts ===
|
||||
|
||||
let foo2 = () => "bar";
|
||||
>foo2 : Symbol(foo2, Decl(computedPropertiesInDestructuring2_ES6.ts, 1, 3))
|
||||
|
||||
let {[foo2()]: bar3} = {};
|
||||
>foo2 : Symbol(foo2, Decl(computedPropertiesInDestructuring2_ES6.ts, 1, 3))
|
||||
>bar3 : Symbol(bar3, Decl(computedPropertiesInDestructuring2_ES6.ts, 2, 5))
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
=== tests/cases/compiler/computedPropertiesInDestructuring2_ES6.ts ===
|
||||
|
||||
let foo2 = () => "bar";
|
||||
>foo2 : () => string
|
||||
>() => "bar" : () => string
|
||||
>"bar" : string
|
||||
|
||||
let {[foo2()]: bar3} = {};
|
||||
>foo2() : string
|
||||
>foo2 : () => string
|
||||
>bar3 : any
|
||||
>{} : {}
|
||||
|
|
@ -9,8 +9,8 @@ var a: any;
|
|||
>a : any
|
||||
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [<any>true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : {}
|
||||
>v : { [0](): void; [""](): void; }
|
||||
>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [<any>true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [0](): void; [""](): void; }
|
||||
|
||||
[s]() { },
|
||||
>s : string
|
||||
|
|
|
@ -9,8 +9,8 @@ var a: any;
|
|||
>a : any
|
||||
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [<any>true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : {}
|
||||
>v : { [0](): void; [""](): void; }
|
||||
>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [<any>true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [0](): void; [""](): void; }
|
||||
|
||||
[s]() { },
|
||||
>s : string
|
||||
|
|
|
@ -46,16 +46,8 @@ var v = (_a = {},
|
|||
enumerable: true,
|
||||
configurable: true
|
||||
}),
|
||||
Object.defineProperty(_a, "", {
|
||||
set: function (v) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
}),
|
||||
Object.defineProperty(_a, 0, {
|
||||
get: function () { return 0; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
}),
|
||||
,
|
||||
,
|
||||
Object.defineProperty(_a, a, {
|
||||
set: function (v) { },
|
||||
enumerable: true,
|
||||
|
|
|
@ -9,8 +9,8 @@ var a: any;
|
|||
>a : any
|
||||
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : {}
|
||||
>v : { [0]: number; [""]: any; }
|
||||
>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [0]: number; [""]: any; }
|
||||
|
||||
get [s]() { return 0; },
|
||||
>s : string
|
||||
|
|
|
@ -9,8 +9,8 @@ var a: any;
|
|||
>a : any
|
||||
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : {}
|
||||
>v : { [0]: number; [""]: any; }
|
||||
>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [0]: number; [""]: any; }
|
||||
|
||||
get [s]() { return 0; },
|
||||
>s : string
|
||||
|
|
|
@ -3,15 +3,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts(6,
|
|||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts(7,12): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts(8,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts(9,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts(10,12): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts(11,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts(12,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts(13,12): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts(14,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts(15,12): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts (11 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts (9 errors) ====
|
||||
var s: string;
|
||||
var n: number;
|
||||
var a: any;
|
||||
|
@ -32,11 +30,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES5.ts(15
|
|||
~~~~
|
||||
!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
static [""]: number;
|
||||
~~~~
|
||||
!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
[0]: number;
|
||||
~~~
|
||||
!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
[a]: number;
|
||||
~~~
|
||||
!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
|
|
|
@ -3,15 +3,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts(6,
|
|||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts(7,12): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts(8,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts(9,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts(10,12): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts(11,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts(12,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts(13,12): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts(14,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts(15,12): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts (11 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts (9 errors) ====
|
||||
var s: string;
|
||||
var n: number;
|
||||
var a: any;
|
||||
|
@ -32,11 +30,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames12_ES6.ts(15
|
|||
~~~~
|
||||
!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
static [""]: number;
|
||||
~~~~
|
||||
!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
[0]: number;
|
||||
~~~
|
||||
!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
[a]: number;
|
||||
~~~
|
||||
!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
|
|
|
@ -48,16 +48,6 @@ var C = (function () {
|
|||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, "", {
|
||||
set: function (v) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, 0, {
|
||||
get: function () { return 0; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, a, {
|
||||
set: function (v) { },
|
||||
enumerable: true,
|
||||
|
|
|
@ -27,10 +27,6 @@ var C = (function () {
|
|||
Object.defineProperty(C.prototype, "get1", {
|
||||
// Computed properties
|
||||
get: function () { return new Foo; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, "set1", {
|
||||
set: function (p) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
|
|
|
@ -27,10 +27,6 @@ var C = (function () {
|
|||
Object.defineProperty(C.prototype, "get1", {
|
||||
// Computed properties
|
||||
get: function () { return new Foo; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, "set1", {
|
||||
set: function (p) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES5.ts(8,5): error TS2393: Duplicate function implementation.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES5.ts(8,5): error TS2411: Property '[""]' of type '() => Foo' is not assignable to string index type '() => Foo2'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES5.ts(9,5): error TS2393: Duplicate function implementation.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES5.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES5.ts (3 errors) ====
|
||||
class Foo { x }
|
||||
class Foo2 { x; y }
|
||||
|
||||
|
@ -10,7 +12,11 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES5.ts(8,
|
|||
|
||||
// Computed properties
|
||||
[""]() { return new Foo }
|
||||
~~~~
|
||||
!!! error TS2393: Duplicate function implementation.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2411: Property '[""]' of type '() => Foo' is not assignable to string index type '() => Foo2'.
|
||||
[""]() { return new Foo2 }
|
||||
~~~~
|
||||
!!! error TS2393: Duplicate function implementation.
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES6.ts(8,5): error TS2393: Duplicate function implementation.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES6.ts(8,5): error TS2411: Property '[""]' of type '() => Foo' is not assignable to string index type '() => Foo2'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES6.ts(9,5): error TS2393: Duplicate function implementation.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES6.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES6.ts (3 errors) ====
|
||||
class Foo { x }
|
||||
class Foo2 { x; y }
|
||||
|
||||
|
@ -10,7 +12,11 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES6.ts(8,
|
|||
|
||||
// Computed properties
|
||||
[""]() { return new Foo }
|
||||
~~~~
|
||||
!!! error TS2393: Duplicate function implementation.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2411: Property '[""]' of type '() => Foo' is not assignable to string index type '() => Foo2'.
|
||||
[""]() { return new Foo2 }
|
||||
~~~~
|
||||
!!! error TS2393: Duplicate function implementation.
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES5.ts(8,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES5.ts(8,5): error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES5.ts (2 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES5.ts (1 errors) ====
|
||||
class Foo { x }
|
||||
class Foo2 { x; y }
|
||||
|
||||
|
@ -11,8 +10,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES5.ts(8,
|
|||
|
||||
// Computed properties
|
||||
[""]: Foo;
|
||||
~~~~
|
||||
!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
~~~~~~~~~~
|
||||
!!! error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES6.ts(8,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES6.ts(8,5): error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES6.ts (2 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES6.ts (1 errors) ====
|
||||
class Foo { x }
|
||||
class Foo2 { x; y }
|
||||
|
||||
|
@ -11,8 +10,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES6.ts(8,
|
|||
|
||||
// Computed properties
|
||||
[""]: Foo;
|
||||
~~~~
|
||||
!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol.
|
||||
~~~~~~~~~~
|
||||
!!! error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
}
|
|
@ -41,10 +41,6 @@ var D = (function (_super) {
|
|||
Object.defineProperty(D.prototype, "get1", {
|
||||
// Computed properties
|
||||
get: function () { return new Foo; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(D.prototype, "set1", {
|
||||
set: function (p) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(5,5): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(11,5): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts (2 errors) ====
|
||||
class Foo { x }
|
||||
class Foo2 { x; y }
|
||||
|
||||
class C {
|
||||
get ["get1"]() { return new Foo }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
}
|
||||
|
||||
class D extends C {
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(5,5): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(11,5): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts (2 errors) ====
|
||||
class Foo { x }
|
||||
class Foo2 { x; y }
|
||||
|
||||
class C {
|
||||
get ["get1"]() { return new Foo }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
}
|
||||
|
||||
class D extends C {
|
||||
|
|
|
@ -9,8 +9,8 @@ var a: any;
|
|||
>a : any
|
||||
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [<any>true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : {}
|
||||
>v : { [0]: number; [""]: number; }
|
||||
>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [<any>true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [0]: number; [""]: number; }
|
||||
|
||||
[s]: 0,
|
||||
>s : string
|
||||
|
|
|
@ -9,8 +9,8 @@ var a: any;
|
|||
>a : any
|
||||
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [<any>true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : {}
|
||||
>v : { [0]: number; [""]: number; }
|
||||
>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [<any>true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [0]: number; [""]: number; }
|
||||
|
||||
[s]: 0,
|
||||
>s : string
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2_ES5.ts ===
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ ["hello"]() { debugger; }} : {}
|
||||
>v : { ["hello"](): void; }
|
||||
>{ ["hello"]() { debugger; }} : { ["hello"](): void; }
|
||||
|
||||
["hello"]() {
|
||||
>"hello" : string
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2_ES6.ts ===
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ ["hello"]() { debugger; }} : {}
|
||||
>v : { ["hello"](): void; }
|
||||
>{ ["hello"]() { debugger; }} : { ["hello"](): void; }
|
||||
|
||||
["hello"]() {
|
||||
>"hello" : string
|
||||
|
|
|
@ -10,16 +10,16 @@ class C {
|
|||
static get ["computedname"]() {
|
||||
return "";
|
||||
}
|
||||
get ["computedname"]() {
|
||||
get ["computedname1"]() {
|
||||
return "";
|
||||
}
|
||||
get ["computedname"]() {
|
||||
get ["computedname2"]() {
|
||||
return "";
|
||||
}
|
||||
|
||||
set ["computedname"](x: any) {
|
||||
set ["computedname3"](x: any) {
|
||||
}
|
||||
set ["computedname"](y: string) {
|
||||
set ["computedname4"](y: string) {
|
||||
}
|
||||
|
||||
set foo(a: string) { }
|
||||
|
@ -38,15 +38,15 @@ class C {
|
|||
static get ["computedname"]() {
|
||||
return "";
|
||||
}
|
||||
get ["computedname"]() {
|
||||
get ["computedname1"]() {
|
||||
return "";
|
||||
}
|
||||
get ["computedname"]() {
|
||||
get ["computedname2"]() {
|
||||
return "";
|
||||
}
|
||||
set ["computedname"](x) {
|
||||
set ["computedname3"](x) {
|
||||
}
|
||||
set ["computedname"](y) {
|
||||
set ["computedname4"](y) {
|
||||
}
|
||||
set foo(a) { }
|
||||
static set bar(b) { }
|
||||
|
|
|
@ -21,18 +21,18 @@ class C {
|
|||
static get ["computedname"]() {
|
||||
return "";
|
||||
}
|
||||
get ["computedname"]() {
|
||||
get ["computedname1"]() {
|
||||
return "";
|
||||
}
|
||||
get ["computedname"]() {
|
||||
get ["computedname2"]() {
|
||||
return "";
|
||||
}
|
||||
|
||||
set ["computedname"](x: any) {
|
||||
>x : Symbol(x, Decl(emitClassDeclarationWithGetterSetterInES6.ts, 18, 25))
|
||||
set ["computedname3"](x: any) {
|
||||
>x : Symbol(x, Decl(emitClassDeclarationWithGetterSetterInES6.ts, 18, 26))
|
||||
}
|
||||
set ["computedname"](y: string) {
|
||||
>y : Symbol(y, Decl(emitClassDeclarationWithGetterSetterInES6.ts, 20, 25))
|
||||
set ["computedname4"](y: string) {
|
||||
>y : Symbol(y, Decl(emitClassDeclarationWithGetterSetterInES6.ts, 20, 26))
|
||||
}
|
||||
|
||||
set foo(a: string) { }
|
||||
|
|
|
@ -25,25 +25,25 @@ class C {
|
|||
return "";
|
||||
>"" : string
|
||||
}
|
||||
get ["computedname"]() {
|
||||
>"computedname" : string
|
||||
get ["computedname1"]() {
|
||||
>"computedname1" : string
|
||||
|
||||
return "";
|
||||
>"" : string
|
||||
}
|
||||
get ["computedname"]() {
|
||||
>"computedname" : string
|
||||
get ["computedname2"]() {
|
||||
>"computedname2" : string
|
||||
|
||||
return "";
|
||||
>"" : string
|
||||
}
|
||||
|
||||
set ["computedname"](x: any) {
|
||||
>"computedname" : string
|
||||
set ["computedname3"](x: any) {
|
||||
>"computedname3" : string
|
||||
>x : any
|
||||
}
|
||||
set ["computedname"](y: string) {
|
||||
>"computedname" : string
|
||||
set ["computedname4"](y: string) {
|
||||
>"computedname4" : string
|
||||
>y : string
|
||||
}
|
||||
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
class D {
|
||||
_bar: string;
|
||||
foo() { }
|
||||
["computedName"]() { }
|
||||
["computedName"](a: string) { }
|
||||
["computedName"](a: string): number { return 1; }
|
||||
["computedName1"]() { }
|
||||
["computedName2"](a: string) { }
|
||||
["computedName3"](a: string): number { return 1; }
|
||||
bar(): string {
|
||||
return this._bar;
|
||||
}
|
||||
baz(a: any, x: string): string {
|
||||
return "HELLO";
|
||||
}
|
||||
static ["computedname"]() { }
|
||||
static ["computedname"](a: string) { }
|
||||
static ["computedname"](a: string): boolean { return true; }
|
||||
static ["computedname4"]() { }
|
||||
static ["computedname5"](a: string) { }
|
||||
static ["computedname6"](a: string): boolean { return true; }
|
||||
static staticMethod() {
|
||||
var x = 1 + 2;
|
||||
return x
|
||||
|
@ -25,18 +25,18 @@ class D {
|
|||
//// [emitClassDeclarationWithMethodInES6.js]
|
||||
class D {
|
||||
foo() { }
|
||||
["computedName"]() { }
|
||||
["computedName"](a) { }
|
||||
["computedName"](a) { return 1; }
|
||||
["computedName1"]() { }
|
||||
["computedName2"](a) { }
|
||||
["computedName3"](a) { return 1; }
|
||||
bar() {
|
||||
return this._bar;
|
||||
}
|
||||
baz(a, x) {
|
||||
return "HELLO";
|
||||
}
|
||||
static ["computedname"]() { }
|
||||
static ["computedname"](a) { }
|
||||
static ["computedname"](a) { return true; }
|
||||
static ["computedname4"]() { }
|
||||
static ["computedname5"](a) { }
|
||||
static ["computedname6"](a) { return true; }
|
||||
static staticMethod() {
|
||||
var x = 1 + 2;
|
||||
return x;
|
||||
|
|
|
@ -8,15 +8,15 @@ class D {
|
|||
foo() { }
|
||||
>foo : Symbol(foo, Decl(emitClassDeclarationWithMethodInES6.ts, 1, 17))
|
||||
|
||||
["computedName"]() { }
|
||||
["computedName"](a: string) { }
|
||||
>a : Symbol(a, Decl(emitClassDeclarationWithMethodInES6.ts, 4, 21))
|
||||
["computedName1"]() { }
|
||||
["computedName2"](a: string) { }
|
||||
>a : Symbol(a, Decl(emitClassDeclarationWithMethodInES6.ts, 4, 22))
|
||||
|
||||
["computedName"](a: string): number { return 1; }
|
||||
>a : Symbol(a, Decl(emitClassDeclarationWithMethodInES6.ts, 5, 21))
|
||||
["computedName3"](a: string): number { return 1; }
|
||||
>a : Symbol(a, Decl(emitClassDeclarationWithMethodInES6.ts, 5, 22))
|
||||
|
||||
bar(): string {
|
||||
>bar : Symbol(bar, Decl(emitClassDeclarationWithMethodInES6.ts, 5, 53))
|
||||
>bar : Symbol(bar, Decl(emitClassDeclarationWithMethodInES6.ts, 5, 54))
|
||||
|
||||
return this._bar;
|
||||
>this._bar : Symbol(_bar, Decl(emitClassDeclarationWithMethodInES6.ts, 0, 9))
|
||||
|
@ -30,15 +30,15 @@ class D {
|
|||
|
||||
return "HELLO";
|
||||
}
|
||||
static ["computedname"]() { }
|
||||
static ["computedname"](a: string) { }
|
||||
>a : Symbol(a, Decl(emitClassDeclarationWithMethodInES6.ts, 13, 28))
|
||||
static ["computedname4"]() { }
|
||||
static ["computedname5"](a: string) { }
|
||||
>a : Symbol(a, Decl(emitClassDeclarationWithMethodInES6.ts, 13, 29))
|
||||
|
||||
static ["computedname"](a: string): boolean { return true; }
|
||||
>a : Symbol(a, Decl(emitClassDeclarationWithMethodInES6.ts, 14, 28))
|
||||
static ["computedname6"](a: string): boolean { return true; }
|
||||
>a : Symbol(a, Decl(emitClassDeclarationWithMethodInES6.ts, 14, 29))
|
||||
|
||||
static staticMethod() {
|
||||
>staticMethod : Symbol(D.staticMethod, Decl(emitClassDeclarationWithMethodInES6.ts, 14, 64))
|
||||
>staticMethod : Symbol(D.staticMethod, Decl(emitClassDeclarationWithMethodInES6.ts, 14, 65))
|
||||
|
||||
var x = 1 + 2;
|
||||
>x : Symbol(x, Decl(emitClassDeclarationWithMethodInES6.ts, 16, 11))
|
||||
|
|
|
@ -8,15 +8,15 @@ class D {
|
|||
foo() { }
|
||||
>foo : () => void
|
||||
|
||||
["computedName"]() { }
|
||||
>"computedName" : string
|
||||
["computedName1"]() { }
|
||||
>"computedName1" : string
|
||||
|
||||
["computedName"](a: string) { }
|
||||
>"computedName" : string
|
||||
["computedName2"](a: string) { }
|
||||
>"computedName2" : string
|
||||
>a : string
|
||||
|
||||
["computedName"](a: string): number { return 1; }
|
||||
>"computedName" : string
|
||||
["computedName3"](a: string): number { return 1; }
|
||||
>"computedName3" : string
|
||||
>a : string
|
||||
>1 : number
|
||||
|
||||
|
@ -36,15 +36,15 @@ class D {
|
|||
return "HELLO";
|
||||
>"HELLO" : string
|
||||
}
|
||||
static ["computedname"]() { }
|
||||
>"computedname" : string
|
||||
static ["computedname4"]() { }
|
||||
>"computedname4" : string
|
||||
|
||||
static ["computedname"](a: string) { }
|
||||
>"computedname" : string
|
||||
static ["computedname5"](a: string) { }
|
||||
>"computedname5" : string
|
||||
>a : string
|
||||
|
||||
static ["computedname"](a: string): boolean { return true; }
|
||||
>"computedname" : string
|
||||
static ["computedname6"](a: string): boolean { return true; }
|
||||
>"computedname6" : string
|
||||
>a : string
|
||||
>true : boolean
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
tests/cases/compiler/literalsInComputedProperties1.ts(40,5): error TS2452: An enum member cannot have a numeric name.
|
||||
tests/cases/compiler/literalsInComputedProperties1.ts(41,5): error TS2452: An enum member cannot have a numeric name.
|
||||
tests/cases/compiler/literalsInComputedProperties1.ts(42,5): error TS2452: An enum member cannot have a numeric name.
|
||||
tests/cases/compiler/literalsInComputedProperties1.ts(43,5): error TS2452: An enum member cannot have a numeric name.
|
||||
|
||||
|
||||
==== tests/cases/compiler/literalsInComputedProperties1.ts (4 errors) ====
|
||||
|
||||
let x = {
|
||||
1:1,
|
||||
[2]:1,
|
||||
"3":1,
|
||||
["4"]:1
|
||||
}
|
||||
x[1].toExponential();
|
||||
x[2].toExponential();
|
||||
x[3].toExponential();
|
||||
x[4].toExponential();
|
||||
|
||||
interface A {
|
||||
1:number;
|
||||
[2]:number;
|
||||
"3":number;
|
||||
["4"]:number;
|
||||
}
|
||||
|
||||
let y:A;
|
||||
y[1].toExponential();
|
||||
y[2].toExponential();
|
||||
y[3].toExponential();
|
||||
y[4].toExponential();
|
||||
|
||||
class C {
|
||||
1:number;
|
||||
[2]:number;
|
||||
"3":number;
|
||||
["4"]:number;
|
||||
}
|
||||
|
||||
let z:C;
|
||||
z[1].toExponential();
|
||||
z[2].toExponential();
|
||||
z[3].toExponential();
|
||||
z[4].toExponential();
|
||||
|
||||
enum X {
|
||||
1 = 1,
|
||||
~
|
||||
!!! error TS2452: An enum member cannot have a numeric name.
|
||||
[2] = 2,
|
||||
~~~
|
||||
!!! error TS2452: An enum member cannot have a numeric name.
|
||||
"3" = 3,
|
||||
~~~
|
||||
!!! error TS2452: An enum member cannot have a numeric name.
|
||||
["4"] = 4,
|
||||
~~~~~
|
||||
!!! error TS2452: An enum member cannot have a numeric name.
|
||||
"foo" = 5,
|
||||
["bar"] = 6
|
||||
}
|
||||
|
||||
let a = X["foo"];
|
||||
let a0 = X["bar"];
|
||||
|
||||
// TODO: make sure that enum still disallow template literals as member names
|
94
tests/baselines/reference/literalsInComputedProperties1.js
Normal file
94
tests/baselines/reference/literalsInComputedProperties1.js
Normal file
|
@ -0,0 +1,94 @@
|
|||
//// [literalsInComputedProperties1.ts]
|
||||
|
||||
let x = {
|
||||
1:1,
|
||||
[2]:1,
|
||||
"3":1,
|
||||
["4"]:1
|
||||
}
|
||||
x[1].toExponential();
|
||||
x[2].toExponential();
|
||||
x[3].toExponential();
|
||||
x[4].toExponential();
|
||||
|
||||
interface A {
|
||||
1:number;
|
||||
[2]:number;
|
||||
"3":number;
|
||||
["4"]:number;
|
||||
}
|
||||
|
||||
let y:A;
|
||||
y[1].toExponential();
|
||||
y[2].toExponential();
|
||||
y[3].toExponential();
|
||||
y[4].toExponential();
|
||||
|
||||
class C {
|
||||
1:number;
|
||||
[2]:number;
|
||||
"3":number;
|
||||
["4"]:number;
|
||||
}
|
||||
|
||||
let z:C;
|
||||
z[1].toExponential();
|
||||
z[2].toExponential();
|
||||
z[3].toExponential();
|
||||
z[4].toExponential();
|
||||
|
||||
enum X {
|
||||
1 = 1,
|
||||
[2] = 2,
|
||||
"3" = 3,
|
||||
["4"] = 4,
|
||||
"foo" = 5,
|
||||
["bar"] = 6
|
||||
}
|
||||
|
||||
let a = X["foo"];
|
||||
let a0 = X["bar"];
|
||||
|
||||
// TODO: make sure that enum still disallow template literals as member names
|
||||
|
||||
//// [literalsInComputedProperties1.js]
|
||||
var x = (_a = {
|
||||
1: 1
|
||||
},
|
||||
_a[2] = 1,
|
||||
_a["3"] = 1,
|
||||
_a["4"] = 1,
|
||||
_a
|
||||
);
|
||||
x[1].toExponential();
|
||||
x[2].toExponential();
|
||||
x[3].toExponential();
|
||||
x[4].toExponential();
|
||||
var y;
|
||||
y[1].toExponential();
|
||||
y[2].toExponential();
|
||||
y[3].toExponential();
|
||||
y[4].toExponential();
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
})();
|
||||
var z;
|
||||
z[1].toExponential();
|
||||
z[2].toExponential();
|
||||
z[3].toExponential();
|
||||
z[4].toExponential();
|
||||
var X;
|
||||
(function (X) {
|
||||
X[X["1"] = 1] = "1";
|
||||
X[X[2] = 2] = 2;
|
||||
X[X["3"] = 3] = "3";
|
||||
X[X["4"] = 4] = "4";
|
||||
X[X["foo"] = 5] = "foo";
|
||||
X[X["bar"] = 6] = "bar";
|
||||
})(X || (X = {}));
|
||||
var a = X["foo"];
|
||||
var a0 = X["bar"];
|
||||
var _a;
|
||||
// TODO: make sure that enum still disallow template literals as member names
|
36
tests/cases/compiler/computedPropertiesInDestructuring1.ts
Normal file
36
tests/cases/compiler/computedPropertiesInDestructuring1.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
// destructuring in variable declarations
|
||||
let foo = "bar";
|
||||
let {[foo]: bar} = {bar: "bar"};
|
||||
|
||||
let {["bar"]: bar2} = {bar: "bar"};
|
||||
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {bar: "bar"};
|
||||
|
||||
let [{[foo]: bar4}] = [{bar: "bar"}];
|
||||
let [{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
function f1({["bar"]: x}: { bar: number }) {}
|
||||
function f2({[foo]: x}: { bar: number }) {}
|
||||
function f3({[foo2()]: x}: { bar: number }) {}
|
||||
function f4([{[foo]: x}]: [{ bar: number }]) {}
|
||||
function f5([{[foo2()]: x}]: [{ bar: number }]) {}
|
||||
|
||||
// report errors on type errors in computed properties used in destructuring
|
||||
let [{[foo()]: bar6}] = [{bar: "bar"}];
|
||||
let [{[foo.toExponential()]: bar7}] = [{bar: "bar"}];
|
||||
|
||||
// destructuring assignment
|
||||
({[foo]: bar} = {bar: "bar"});
|
||||
|
||||
({["bar"]: bar2} = {bar: "bar"});
|
||||
|
||||
({[foo2()]: bar3} = {bar: "bar"});
|
||||
|
||||
[{[foo]: bar4}] = [{bar: "bar"}];
|
||||
[{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
[{[foo()]: bar4}] = [{bar: "bar"}];
|
||||
[{[(1 + {})]: bar4}] = [{bar: "bar"}];
|
||||
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
// @target: ES6
|
||||
// destructuring in variable declarations
|
||||
let foo = "bar";
|
||||
let {[foo]: bar} = {bar: "bar"};
|
||||
|
||||
let {["bar"]: bar2} = {bar: "bar"};
|
||||
let {[11]: bar2_1} = {11: "bar"};
|
||||
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {bar: "bar"};
|
||||
|
||||
let [{[foo]: bar4}] = [{bar: "bar"}];
|
||||
let [{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
function f1({["bar"]: x}: { bar: number }) {}
|
||||
function f2({[foo]: x}: { bar: number }) {}
|
||||
function f3({[foo2()]: x}: { bar: number }) {}
|
||||
function f4([{[foo]: x}]: [{ bar: number }]) {}
|
||||
function f5([{[foo2()]: x}]: [{ bar: number }]) {}
|
||||
|
||||
// report errors on type errors in computed properties used in destructuring
|
||||
let [{[foo()]: bar6}] = [{bar: "bar"}];
|
||||
let [{[foo.toExponential()]: bar7}] = [{bar: "bar"}];
|
||||
|
||||
// destructuring assignment
|
||||
({[foo]: bar} = {bar: "bar"});
|
||||
|
||||
({["bar"]: bar2} = {bar: "bar"});
|
||||
|
||||
({[foo2()]: bar3} = {bar: "bar"});
|
||||
|
||||
[{[foo]: bar4}] = [{bar: "bar"}];
|
||||
[{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
|
||||
[{[foo()]: bar4}] = [{bar: "bar"}];
|
||||
[{[(1 + {})]: bar4}] = [{bar: "bar"}];
|
|
@ -0,0 +1,2 @@
|
|||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {};
|
|
@ -0,0 +1,4 @@
|
|||
// @target: ES6
|
||||
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {};
|
52
tests/cases/compiler/literalsInComputedProperties1.ts
Normal file
52
tests/cases/compiler/literalsInComputedProperties1.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
// @noImplicitAny: true
|
||||
|
||||
let x = {
|
||||
1:1,
|
||||
[2]:1,
|
||||
"3":1,
|
||||
["4"]:1
|
||||
}
|
||||
x[1].toExponential();
|
||||
x[2].toExponential();
|
||||
x[3].toExponential();
|
||||
x[4].toExponential();
|
||||
|
||||
interface A {
|
||||
1:number;
|
||||
[2]:number;
|
||||
"3":number;
|
||||
["4"]:number;
|
||||
}
|
||||
|
||||
let y:A;
|
||||
y[1].toExponential();
|
||||
y[2].toExponential();
|
||||
y[3].toExponential();
|
||||
y[4].toExponential();
|
||||
|
||||
class C {
|
||||
1:number;
|
||||
[2]:number;
|
||||
"3":number;
|
||||
["4"]:number;
|
||||
}
|
||||
|
||||
let z:C;
|
||||
z[1].toExponential();
|
||||
z[2].toExponential();
|
||||
z[3].toExponential();
|
||||
z[4].toExponential();
|
||||
|
||||
enum X {
|
||||
1 = 1,
|
||||
[2] = 2,
|
||||
"3" = 3,
|
||||
["4"] = 4,
|
||||
"foo" = 5,
|
||||
["bar"] = 6
|
||||
}
|
||||
|
||||
let a = X["foo"];
|
||||
let a0 = X["bar"];
|
||||
|
||||
// TODO: make sure that enum still disallow template literals as member names
|
|
@ -10,16 +10,16 @@ class C {
|
|||
static get ["computedname"]() {
|
||||
return "";
|
||||
}
|
||||
get ["computedname"]() {
|
||||
get ["computedname1"]() {
|
||||
return "";
|
||||
}
|
||||
get ["computedname"]() {
|
||||
get ["computedname2"]() {
|
||||
return "";
|
||||
}
|
||||
|
||||
set ["computedname"](x: any) {
|
||||
set ["computedname3"](x: any) {
|
||||
}
|
||||
set ["computedname"](y: string) {
|
||||
set ["computedname4"](y: string) {
|
||||
}
|
||||
|
||||
set foo(a: string) { }
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
class D {
|
||||
_bar: string;
|
||||
foo() { }
|
||||
["computedName"]() { }
|
||||
["computedName"](a: string) { }
|
||||
["computedName"](a: string): number { return 1; }
|
||||
["computedName1"]() { }
|
||||
["computedName2"](a: string) { }
|
||||
["computedName3"](a: string): number { return 1; }
|
||||
bar(): string {
|
||||
return this._bar;
|
||||
}
|
||||
baz(a: any, x: string): string {
|
||||
return "HELLO";
|
||||
}
|
||||
static ["computedname"]() { }
|
||||
static ["computedname"](a: string) { }
|
||||
static ["computedname"](a: string): boolean { return true; }
|
||||
static ["computedname4"]() { }
|
||||
static ["computedname5"](a: string) { }
|
||||
static ["computedname6"](a: string): boolean { return true; }
|
||||
static staticMethod() {
|
||||
var x = 1 + 2;
|
||||
return x
|
||||
|
|
Loading…
Reference in a new issue