Emit tests for computed properties

This commit is contained in:
Jason Freeman 2014-11-17 16:36:30 -08:00
parent 17a09d1d36
commit 0e864143de
16 changed files with 238 additions and 0 deletions

View file

@ -0,0 +1,14 @@
//// [computedPropertyNames1.ts]
var v = {
get [0 + 1]() { return 0 },
set [0 + 1](v) { }
}
//// [computedPropertyNames1.js]
var v = {
get [0 + 1]() {
return 0;
},
set [0 + 1](v) {
}
};

View file

@ -0,0 +1,19 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(6,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(8,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts (2 errors) ====
var methodName = "method";
var accessorName = "accessor";
class C {
[methodName]() { }
static [methodName]() { }
get [accessorName]() { }
~~~~~~~~~~~~~~
!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
set [accessorName](v) { }
static get [accessorName]() { }
~~~~~~~~~~~~~~
!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
static set [accessorName](v) { }
}

View file

@ -0,0 +1,48 @@
//// [computedPropertyNames2.ts]
var methodName = "method";
var accessorName = "accessor";
class C {
[methodName]() { }
static [methodName]() { }
get [accessorName]() { }
set [accessorName](v) { }
static get [accessorName]() { }
static set [accessorName](v) { }
}
//// [computedPropertyNames2.js]
var methodName = "method";
var accessorName = "accessor";
var C = (function () {
function C() {
}
C.prototype[methodName] = function () {
};
C[methodName] = function () {
};
Object.defineProperty(C.prototype, accessorName, {
get: function () {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, accessorName, {
set: function (v) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C, accessorName, {
get: function () {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C, accessorName, {
set: function (v) {
},
enumerable: true,
configurable: true
});
return C;
})();

View file

@ -0,0 +1,18 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts (2 errors) ====
var id;
class C {
[0 + 1]() { }
static [() => { }]() { }
get [delete id]() { }
~~~~~~~~~~~
!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
set [[0, 1]](v) { }
static get [<String>""]() { }
~~~~~~~~~~~~
!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
static set [id.toString()](v) { }
}

View file

@ -0,0 +1,47 @@
//// [computedPropertyNames3.ts]
var id;
class C {
[0 + 1]() { }
static [() => { }]() { }
get [delete id]() { }
set [[0, 1]](v) { }
static get [<String>""]() { }
static set [id.toString()](v) { }
}
//// [computedPropertyNames3.js]
var id;
var C = (function () {
function C() {
}
C.prototype[0 + 1] = function () {
};
C[function () {
}] = function () {
};
Object.defineProperty(C.prototype, delete id, {
get: function () {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, [0, 1], {
set: function (v) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C, "", {
get: function () {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C, id.toString(), {
set: function (v) {
},
enumerable: true,
configurable: true
});
return C;
})();

View file

@ -0,0 +1,13 @@
//// [parserComputedPropertyName12.ts]
class C {
[e]() { }
}
//// [parserComputedPropertyName12.js]
var C = (function () {
function C() {
}
C.prototype[e] = function () {
};
return C;
})();

View file

@ -0,0 +1,6 @@
//// [parserComputedPropertyName17.ts]
var v = { set [e](v) { } }
//// [parserComputedPropertyName17.js]
var v = { set [e](v) {
} };

View file

@ -0,0 +1,5 @@
//// [parserComputedPropertyName2.ts]
var v = { [e]: 1 };
//// [parserComputedPropertyName2.js]
var v = { [e]: 1 };

View file

@ -0,0 +1,17 @@
//// [parserComputedPropertyName24.ts]
class C {
set [e](v) { }
}
//// [parserComputedPropertyName24.js]
var C = (function () {
function C() {
}
Object.defineProperty(C.prototype, e, {
set: function (v) {
},
enumerable: true,
configurable: true
});
return C;
})();

View file

@ -0,0 +1,6 @@
//// [parserComputedPropertyName3.ts]
var v = { [e]() { } };
//// [parserComputedPropertyName3.js]
var v = { [e]: function () {
} };

View file

@ -0,0 +1,6 @@
//// [parserComputedPropertyName4.ts]
var v = { get [e]() { } };
//// [parserComputedPropertyName4.js]
var v = { get [e]() {
} };

View file

@ -0,0 +1,5 @@
//// [parserComputedPropertyName6.ts]
var v = { [e]: 1, [e + e]: 2 };
//// [parserComputedPropertyName6.js]
var v = { [e]: 1, [e + e]: 2 };

View file

@ -0,0 +1,5 @@
// @target: es6
var v = {
get [0 + 1]() { return 0 },
set [0 + 1](v) { }
}

View file

@ -0,0 +1,11 @@
// @target: es6
var methodName = "method";
var accessorName = "accessor";
class C {
[methodName]() { }
static [methodName]() { }
get [accessorName]() { }
set [accessorName](v) { }
static get [accessorName]() { }
static set [accessorName](v) { }
}

View file

@ -0,0 +1,10 @@
// @target: es6
var id;
class C {
[0 + 1]() { }
static [() => { }]() { }
get [delete id]() { }
set [[0, 1]](v) { }
static get [<String>""]() { }
static set [id.toString()](v) { }
}

View file

@ -0,0 +1,8 @@
// @target: es6
var methodName = "method";
var accessorName = "accessor";
class C {
[methodName](v: string);
[methodName]();
[methodName](v?: string) { }
}