diff --git a/tests/baselines/reference/importsImplicitlyReadonly.errors.txt b/tests/baselines/reference/importsImplicitlyReadonly.errors.txt new file mode 100644 index 00000000000..cc6e1918020 --- /dev/null +++ b/tests/baselines/reference/importsImplicitlyReadonly.errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/externalModules/b.ts(6,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/externalModules/b.ts(7,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/externalModules/b.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/externalModules/b.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + +==== tests/cases/conformance/externalModules/b.ts (4 errors) ==== + import { x, y } from "./a"; + import * as a1 from "./a"; + import a2 = require("./a"); + const a3 = a1; + + x = 1; // Error + ~ +!!! error TS2364: Invalid left-hand side of assignment expression. + y = 1; // Error + ~ +!!! error TS2364: Invalid left-hand side of assignment expression. + a1.x = 1; // Error + ~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + a1.y = 1; // Error + ~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + a2.x = 1; + a2.y = 1; + a3.x = 1; + a3.y = 1; +==== tests/cases/conformance/externalModules/a.ts (0 errors) ==== + + export var x = 1; + var y = 1; + export { y }; + \ No newline at end of file diff --git a/tests/baselines/reference/importsImplicitlyReadonly.js b/tests/baselines/reference/importsImplicitlyReadonly.js new file mode 100644 index 00000000000..4630de598cc --- /dev/null +++ b/tests/baselines/reference/importsImplicitlyReadonly.js @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/externalModules/importsImplicitlyReadonly.ts] //// + +//// [a.ts] + +export var x = 1; +var y = 1; +export { y }; + +//// [b.ts] +import { x, y } from "./a"; +import * as a1 from "./a"; +import a2 = require("./a"); +const a3 = a1; + +x = 1; // Error +y = 1; // Error +a1.x = 1; // Error +a1.y = 1; // Error +a2.x = 1; +a2.y = 1; +a3.x = 1; +a3.y = 1; + +//// [a.js] +"use strict"; +exports.x = 1; +var y = 1; +exports.y = y; +//// [b.js] +"use strict"; +var a_1 = require("./a"); +var a1 = require("./a"); +var a2 = require("./a"); +var a3 = a1; +a_1.x = 1; // Error +a_1.y = 1; // Error +a1.x = 1; // Error +a1.y = 1; // Error +a2.x = 1; +a2.y = 1; +a3.x = 1; +a3.y = 1; diff --git a/tests/baselines/reference/readonlyMembers.errors.txt b/tests/baselines/reference/readonlyMembers.errors.txt new file mode 100644 index 00000000000..7bc10aa3746 --- /dev/null +++ b/tests/baselines/reference/readonlyMembers.errors.txt @@ -0,0 +1,114 @@ +tests/cases/compiler/readonlyMembers.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(17,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(19,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(20,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(21,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(25,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(26,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(27,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(36,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(40,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(49,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(56,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(62,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + +==== tests/cases/compiler/readonlyMembers.ts (15 errors) ==== + + interface X { + readonly a: number; + readonly b?: number; + } + var x: X = { a: 0 }; + x.a = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + x.b = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + class C { + readonly a: number; + readonly b = 1; + get c() { return 1 } + constructor() { + this.a = 1; // Ok + this.b = 1; // Ok + this.c = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + const f = () => { + this.a = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + this.b = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + this.c = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + } + } + foo() { + this.a = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + this.b = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + this.c = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + } + } + + var o = { + get a() { return 1 }, + get b() { return 1 }, + set b(value) { } + }; + o.a = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + o.b = 1; + + var p: { readonly a: number, b: number } = { a: 1, b: 1 }; + p.a = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + p.b = 1; + var q: { a: number, b: number } = p; + q.a = 1; + q.b = 1; + + enum E { + A, B, C + } + E.A = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + namespace N { + export const a = 1; + export let b = 1; + export var c = 1; + } + N.a = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + N.b = 1; + N.c = 1; + + let xx: { readonly [x: string]: string }; + let s = xx["foo"]; + xx["foo"] = "abc"; // Error + ~~~~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + let yy: { readonly [x: number]: string, [x: string]: string }; + yy[1] = "abc"; // Error + ~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + yy["foo"] = "abc"; \ No newline at end of file diff --git a/tests/baselines/reference/readonlyMembers.js b/tests/baselines/reference/readonlyMembers.js new file mode 100644 index 00000000000..899c52d8626 --- /dev/null +++ b/tests/baselines/reference/readonlyMembers.js @@ -0,0 +1,132 @@ +//// [readonlyMembers.ts] + +interface X { + readonly a: number; + readonly b?: number; +} +var x: X = { a: 0 }; +x.a = 1; // Error +x.b = 1; // Error + +class C { + readonly a: number; + readonly b = 1; + get c() { return 1 } + constructor() { + this.a = 1; // Ok + this.b = 1; // Ok + this.c = 1; // Error + const f = () => { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + } + } + foo() { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + } +} + +var o = { + get a() { return 1 }, + get b() { return 1 }, + set b(value) { } +}; +o.a = 1; // Error +o.b = 1; + +var p: { readonly a: number, b: number } = { a: 1, b: 1 }; +p.a = 1; // Error +p.b = 1; +var q: { a: number, b: number } = p; +q.a = 1; +q.b = 1; + +enum E { + A, B, C +} +E.A = 1; // Error + +namespace N { + export const a = 1; + export let b = 1; + export var c = 1; +} +N.a = 1; // Error +N.b = 1; +N.c = 1; + +let xx: { readonly [x: string]: string }; +let s = xx["foo"]; +xx["foo"] = "abc"; // Error + +let yy: { readonly [x: number]: string, [x: string]: string }; +yy[1] = "abc"; // Error +yy["foo"] = "abc"; + +//// [readonlyMembers.js] +var x = { a: 0 }; +x.a = 1; // Error +x.b = 1; // Error +var C = (function () { + function C() { + var _this = this; + this.b = 1; + this.a = 1; // Ok + this.b = 1; // Ok + this.c = 1; // Error + var f = function () { + _this.a = 1; // Error + _this.b = 1; // Error + _this.c = 1; // Error + }; + } + Object.defineProperty(C.prototype, "c", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + C.prototype.foo = function () { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + }; + return C; +}()); +var o = { + get a() { return 1; }, + get b() { return 1; }, + set b(value) { } +}; +o.a = 1; // Error +o.b = 1; +var p = { a: 1, b: 1 }; +p.a = 1; // Error +p.b = 1; +var q = p; +q.a = 1; +q.b = 1; +var E; +(function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; +})(E || (E = {})); +E.A = 1; // Error +var N; +(function (N) { + N.a = 1; + N.b = 1; + N.c = 1; +})(N || (N = {})); +N.a = 1; // Error +N.b = 1; +N.c = 1; +var xx; +var s = xx["foo"]; +xx["foo"] = "abc"; // Error +var yy; +yy[1] = "abc"; // Error +yy["foo"] = "abc";