Check that Symbol properties are proper, and support downlevel type checking

This commit is contained in:
Jason Freeman
2015-02-06 19:32:19 -08:00
parent 3834edd747
commit 4c09ccd60e
32 changed files with 457 additions and 27 deletions

View File

@@ -0,0 +1,19 @@
tests/cases/conformance/Symbols/ES5SymbolProperty1.ts(7,5): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
tests/cases/conformance/Symbols/ES5SymbolProperty1.ts(7,6): error TS2471: A computed property name of the form 'Symbol.foo' must be of type 'symbol'.
==== tests/cases/conformance/Symbols/ES5SymbolProperty1.ts (2 errors) ====
interface SymbolConstructor {
foo: string;
}
var Symbol: SymbolConstructor;
var obj = {
[Symbol.foo]: 0
~~~~~~~~~~~~
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
~~~~~~~~~~
!!! error TS2471: A computed property name of the form 'Symbol.foo' must be of type 'symbol'.
}
obj[Symbol.foo];

View File

@@ -0,0 +1,18 @@
//// [ES5SymbolProperty1.ts]
interface SymbolConstructor {
foo: string;
}
var Symbol: SymbolConstructor;
var obj = {
[Symbol.foo]: 0
}
obj[Symbol.foo];
//// [ES5SymbolProperty1.js]
var Symbol;
var obj = {
[Symbol.foo]: 0
};
obj[Symbol.foo];

View File

@@ -0,0 +1,22 @@
tests/cases/conformance/Symbols/ES5SymbolProperty2.ts(5,9): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
tests/cases/conformance/Symbols/ES5SymbolProperty2.ts(5,10): error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
tests/cases/conformance/Symbols/ES5SymbolProperty2.ts(10,11): error TS2304: Cannot find name 'Symbol'.
==== tests/cases/conformance/Symbols/ES5SymbolProperty2.ts (3 errors) ====
module M {
var Symbol;
export class C {
[Symbol.iterator]() { }
~~~~~~~~~~~~~~~~~
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
~~~~~~~~~~~~~~~
!!! error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
}
(new C)[Symbol.iterator];
}
(new M.C)[Symbol.iterator];
~~~~~~
!!! error TS2304: Cannot find name 'Symbol'.

View File

@@ -0,0 +1,27 @@
//// [ES5SymbolProperty2.ts]
module M {
var Symbol;
export class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator];
}
(new M.C)[Symbol.iterator];
//// [ES5SymbolProperty2.js]
var M;
(function (M) {
var Symbol;
var C = (function () {
function C() {
}
C.prototype[Symbol.iterator] = function () {
};
return C;
})();
M.C = C;
(new C)[Symbol.iterator];
})(M || (M = {}));
(new M.C)[Symbol.iterator];

View File

@@ -0,0 +1,16 @@
tests/cases/conformance/Symbols/ES5SymbolProperty3.ts(4,5): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
tests/cases/conformance/Symbols/ES5SymbolProperty3.ts(4,6): error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
==== tests/cases/conformance/Symbols/ES5SymbolProperty3.ts (2 errors) ====
var Symbol;
class C {
[Symbol.iterator]() { }
~~~~~~~~~~~~~~~~~
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
~~~~~~~~~~~~~~~
!!! error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
}
(new C)[Symbol.iterator]

View File

@@ -0,0 +1,19 @@
//// [ES5SymbolProperty3.ts]
var Symbol;
class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator]
//// [ES5SymbolProperty3.js]
var Symbol;
var C = (function () {
function C() {
}
C.prototype[Symbol.iterator] = function () {
};
return C;
})();
(new C)[Symbol.iterator];

View File

@@ -0,0 +1,16 @@
tests/cases/conformance/Symbols/ES5SymbolProperty4.ts(4,5): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
tests/cases/conformance/Symbols/ES5SymbolProperty4.ts(4,6): error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
==== tests/cases/conformance/Symbols/ES5SymbolProperty4.ts (2 errors) ====
var Symbol: { iterator: string };
class C {
[Symbol.iterator]() { }
~~~~~~~~~~~~~~~~~
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
~~~~~~~~~~~~~~~
!!! error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
}
(new C)[Symbol.iterator]

View File

@@ -0,0 +1,19 @@
//// [ES5SymbolProperty4.ts]
var Symbol: { iterator: string };
class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator]
//// [ES5SymbolProperty4.js]
var Symbol;
var C = (function () {
function C() {
}
C.prototype[Symbol.iterator] = function () {
};
return C;
})();
(new C)[Symbol.iterator];

View File

@@ -0,0 +1,16 @@
tests/cases/conformance/Symbols/ES5SymbolProperty5.ts(4,5): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
tests/cases/conformance/Symbols/ES5SymbolProperty5.ts(7,1): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/Symbols/ES5SymbolProperty5.ts (2 errors) ====
var Symbol: { iterator: symbol };
class C {
[Symbol.iterator]() { }
~~~~~~~~~~~~~~~~~
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
}
(new C)[Symbol.iterator](0) // Should error
~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.

View File

@@ -0,0 +1,19 @@
//// [ES5SymbolProperty5.ts]
var Symbol: { iterator: symbol };
class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator](0) // Should error
//// [ES5SymbolProperty5.js]
var Symbol;
var C = (function () {
function C() {
}
C.prototype[Symbol.iterator] = function () {
};
return C;
})();
(new C)[Symbol.iterator](0); // Should error

View File

@@ -0,0 +1,17 @@
tests/cases/conformance/Symbols/ES5SymbolProperty6.ts(2,5): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
tests/cases/conformance/Symbols/ES5SymbolProperty6.ts(2,6): error TS2304: Cannot find name 'Symbol'.
tests/cases/conformance/Symbols/ES5SymbolProperty6.ts(5,9): error TS2304: Cannot find name 'Symbol'.
==== tests/cases/conformance/Symbols/ES5SymbolProperty6.ts (3 errors) ====
class C {
[Symbol.iterator]() { }
~~~~~~~~~~~~~~~~~
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
~~~~~~
!!! error TS2304: Cannot find name 'Symbol'.
}
(new C)[Symbol.iterator]
~~~~~~
!!! error TS2304: Cannot find name 'Symbol'.

View File

@@ -0,0 +1,16 @@
//// [ES5SymbolProperty6.ts]
class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator]
//// [ES5SymbolProperty6.js]
var C = (function () {
function C() {
}
C.prototype[Symbol.iterator] = function () {
};
return C;
})();
(new C)[Symbol.iterator];

View File

@@ -0,0 +1,16 @@
tests/cases/conformance/Symbols/ES5SymbolProperty7.ts(4,5): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
tests/cases/conformance/Symbols/ES5SymbolProperty7.ts(4,6): error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
==== tests/cases/conformance/Symbols/ES5SymbolProperty7.ts (2 errors) ====
var Symbol: { iterator: any };
class C {
[Symbol.iterator]() { }
~~~~~~~~~~~~~~~~~
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
~~~~~~~~~~~~~~~
!!! error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
}
(new C)[Symbol.iterator]

View File

@@ -0,0 +1,19 @@
//// [ES5SymbolProperty7.ts]
var Symbol: { iterator: any };
class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator]
//// [ES5SymbolProperty7.js]
var Symbol;
var C = (function () {
function C() {
}
C.prototype[Symbol.iterator] = function () {
};
return C;
})();
(new C)[Symbol.iterator];

View File

@@ -0,0 +1,7 @@
//// [ES5SymbolType1.ts]
var s: symbol;
s.toString();
//// [ES5SymbolType1.js]
var s;
s.toString();

View File

@@ -0,0 +1,10 @@
=== tests/cases/conformance/Symbols/ES5SymbolType1.ts ===
var s: symbol;
>s : symbol
s.toString();
>s.toString() : string
>s.toString : () => string
>s : symbol
>toString : () => string

View File

@@ -0,0 +1,13 @@
tests/cases/conformance/es6/Symbols/symbolProperty48.ts(5,10): error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
==== tests/cases/conformance/es6/Symbols/symbolProperty48.ts (1 errors) ====
module M {
var Symbol;
class C {
[Symbol.iterator]() { }
~~~~~~~~~~~~~~~
!!! error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
}
}

View File

@@ -0,0 +1,13 @@
tests/cases/conformance/es6/Symbols/symbolProperty49.ts(5,10): error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
==== tests/cases/conformance/es6/Symbols/symbolProperty49.ts (1 errors) ====
module M {
export var Symbol;
class C {
[Symbol.iterator]() { }
~~~~~~~~~~~~~~~
!!! error TS2471: A computed property name of the form 'Symbol.iterator' must be of type 'symbol'.
}
}

View File

@@ -0,0 +1,13 @@
tests/cases/conformance/es6/Symbols/symbolProperty58.ts(6,6): error TS2471: A computed property name of the form 'Symbol.foo' must be of type 'symbol'.
==== tests/cases/conformance/es6/Symbols/symbolProperty58.ts (1 errors) ====
interface SymbolConstructor {
foo: string;
}
var obj = {
[Symbol.foo]: 0
~~~~~~~~~~
!!! error TS2471: A computed property name of the form 'Symbol.foo' must be of type 'symbol'.
}

View File

@@ -0,0 +1,13 @@
//// [symbolProperty58.ts]
interface SymbolConstructor {
foo: string;
}
var obj = {
[Symbol.foo]: 0
}
//// [symbolProperty58.js]
var obj = {
[Symbol.foo]: 0
};

View File

@@ -0,0 +1,11 @@
//@target: ES5
interface SymbolConstructor {
foo: string;
}
var Symbol: SymbolConstructor;
var obj = {
[Symbol.foo]: 0
}
obj[Symbol.foo];

View File

@@ -0,0 +1,11 @@
//@target: ES5
module M {
var Symbol;
export class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator];
}
(new M.C)[Symbol.iterator];

View File

@@ -0,0 +1,8 @@
//@target: ES5
var Symbol;
class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator]

View File

@@ -0,0 +1,8 @@
//@target: ES5
var Symbol: { iterator: string };
class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator]

View File

@@ -0,0 +1,8 @@
//@target: ES5
var Symbol: { iterator: symbol };
class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator](0) // Should error

View File

@@ -0,0 +1,6 @@
//@target: ES5
class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator]

View File

@@ -0,0 +1,8 @@
//@target: ES5
var Symbol: { iterator: any };
class C {
[Symbol.iterator]() { }
}
(new C)[Symbol.iterator]

View File

@@ -0,0 +1,3 @@
//@target: ES5
var s: symbol;
s.toString();

View File

@@ -0,0 +1,8 @@
//@target: ES6
interface SymbolConstructor {
foo: string;
}
var obj = {
[Symbol.foo]: 0
}