diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 228b1067bb0..7ea6d13ddba 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -169,7 +169,7 @@ namespace ts { let emitParam = false; let emitAwaiter = false; let emitGenerator = false; - + let resolutionTargets: TypeSystemEntity[] = []; let resolutionResults: boolean[] = []; let resolutionPropertyNames: TypeSystemPropertyName[] = []; @@ -2116,8 +2116,8 @@ namespace ts { case SyntaxKind.SetAccessor: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - if (node.flags & (NodeFlags.Private | NodeFlags.Protected)) { - // Private/protected properties/methods are not visible + if (node.flags & (NodeFlags.Private | NodeFlags.Protected | NodeFlags.Internal)) { + // Private/protected/internal properties/methods are not visible return false; } // Public properties/methods are visible if its parents are visible, so let it fall into next case statement @@ -5173,6 +5173,32 @@ namespace ts { } return Ternary.False; } + else if (sourcePropFlags & NodeFlags.Internal || targetPropFlags & NodeFlags.Internal) { + let sourceInDeclarationFile = isDeclarationFile(getSourceFile(sourceProp.valueDeclaration)); + let targetInDeclarationFile = isDeclarationFile(getSourceFile(targetProp.valueDeclaration)); + if (sourceInDeclarationFile || targetInDeclarationFile) { + if (targetPropFlags & NodeFlags.Internal) { + let sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & SymbolFlags.Class; + let sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(sourceProp.parent) : undefined; + let targetClass = getDeclaredTypeOfSymbol(targetProp.parent); + if (!sourceClass || !hasBaseType(sourceClass, targetClass)) { + if (reportErrors) { + reportError(Diagnostics.Property_0_is_internal_in_a_declaration_file_but_type_1_is_not_a_class_derived_from_2, + symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass)); + } + return Ternary.False; + } + } + else if (sourcePropFlags & NodeFlags.Internal) { + if (reportErrors) { + reportError(Diagnostics.Property_0_of_type_1_is_internal_in_a_declaration_file_and_is_only_accessible_within_a_declaration_file, + symbolToString(targetProp), + typeToString(source)); + } + return Ternary.False; + } + } + } let related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); if (!related) { if (reportErrors) { @@ -7943,7 +7969,16 @@ namespace ts { } // Public properties are otherwise accessible. - if (!(flags & (NodeFlags.Private | NodeFlags.Protected))) { + if (!(flags & (NodeFlags.Private | NodeFlags.Protected | NodeFlags.Internal))) { + return true; + } + + // Internal property is accessible only if declaring class comes from a non-declaration file + if (flags & NodeFlags.Internal) { + if (!isDeclarationFile(getSourceFile(node)) && (!declaringClass.symbol || isDeclarationFile(getSourceFile(declaringClass.symbol.valueDeclaration)))) { + error(node, Diagnostics.Property_0_is_internal_in_a_declaration_file_and_is_only_accessible_within_a_declaration_file, symbolToString(prop)); + return false; + } return true; } @@ -7961,7 +7996,7 @@ namespace ts { } return true; } - + // Property is known to be protected at this point // All protected properties of a supertype are accessible in a super access @@ -10814,7 +10849,7 @@ namespace ts { // or the containing class declares instance member variables with initializers. let superCallShouldBeFirst = forEach((node.parent).members, isInstancePropertyWithInitializer) || - forEach(node.parameters, p => p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)); + forEach(node.parameters, p => p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected | NodeFlags.Internal)); // Skip past any prologue directives to find the first statement // to ensure that it was a super call. @@ -11033,8 +11068,8 @@ namespace ts { else if (deviation & NodeFlags.Ambient) { error(o.name, Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient); } - else if (deviation & (NodeFlags.Private | NodeFlags.Protected)) { - error(o.name, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected); + else if (deviation & (NodeFlags.Private | NodeFlags.Protected | NodeFlags.Internal)) { + error(o.name, Diagnostics.Overload_signatures_must_all_be_public_internal_private_or_protected); } else if (deviation & NodeFlags.Abstract) { error(o.name, Diagnostics.Overload_signatures_must_all_be_abstract_or_not_abstract); @@ -11055,7 +11090,7 @@ namespace ts { } } - let flagsToCheck: NodeFlags = NodeFlags.Export | NodeFlags.Ambient | NodeFlags.Private | NodeFlags.Protected | NodeFlags.Abstract; + let flagsToCheck: NodeFlags = NodeFlags.Export | NodeFlags.Ambient | NodeFlags.Private | NodeFlags.Protected | NodeFlags.Internal | NodeFlags.Abstract; let someNodeFlags: NodeFlags = 0; let allNodeFlags = flagsToCheck; let someHaveQuestionToken = false; @@ -14967,7 +15002,7 @@ namespace ts { return; } - let lastStatic: Node, lastPrivate: Node, lastProtected: Node, lastDeclare: Node, lastAsync: Node; + let lastStatic: Node, lastPrivate: Node, lastProtected: Node, lastInternal: Node, lastDeclare: Node, lastAsync: Node; let flags = 0; for (let modifier of node.modifiers) { switch (modifier.kind) { @@ -15120,6 +15155,9 @@ namespace ts { else if (flags & NodeFlags.Protected) { return grammarErrorOnNode(lastProtected, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected"); } + else if (flags & NodeFlags.Internal) { + return grammarErrorOnNode(lastInternal, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "internal"); + } else if (flags & NodeFlags.Private) { return grammarErrorOnNode(lastPrivate, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); } diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 00085f16086..d1ff59cf0c6 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -614,6 +614,9 @@ namespace ts { else if (node.flags & NodeFlags.Protected) { write("protected "); } + else if (node.flags & NodeFlags.Internal) { + write("internal "); + } if (node.flags & NodeFlags.Static) { write("static "); @@ -1027,7 +1030,7 @@ namespace ts { if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } - else if (!(node.flags & NodeFlags.Private)) { + else if (!(node.flags & (NodeFlags.Private | NodeFlags.Internal))) { writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 22b65b58111..f1e458dd773 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1120,7 +1120,7 @@ "category": "Error", "code": 2384 }, - "Overload signatures must all be public, private or protected.": { + "Overload signatures must all be public, internal, private or protected.": { "category": "Error", "code": 2385 }, @@ -1724,6 +1724,18 @@ "category": "Error", "code": 2656 }, + "Property '{0}' is internal in a declaration file and is only accessible within a declaration file.": { + "category": "Error", + "code": 2657 + }, + "Property '{0}' of type '{1}' is internal in a declaration file and is only accessible within a declaration file.": { + "category": "Error", + "code": 2658 + }, + "Property '{0}' is internal in a declaration file, but type '{1}' is not a class derived from '{2}'.": { + "category": "Error", + "code": 2659 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index ee4dea04f09..b505b8e9322 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -82,6 +82,7 @@ namespace ts { "in": SyntaxKind.InKeyword, "instanceof": SyntaxKind.InstanceOfKeyword, "interface": SyntaxKind.InterfaceKeyword, + "internal": SyntaxKind.InternalKeyword, "is": SyntaxKind.IsKeyword, "let": SyntaxKind.LetKeyword, "module": SyntaxKind.ModuleKeyword, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 773083d49b6..b01a4d40b85 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -153,6 +153,7 @@ namespace ts { ConstructorKeyword, DeclareKeyword, GetKeyword, + InternalKeyword, IsKeyword, ModuleKeyword, NamespaceKeyword, @@ -364,22 +365,23 @@ namespace ts { Public = 0x00000010, // Property/Method Private = 0x00000020, // Property/Method Protected = 0x00000040, // Property/Method - Static = 0x00000080, // Property/Method - Abstract = 0x00000100, // Class/Method/ConstructSignature - Async = 0x00000200, // Property/Method/Function - Default = 0x00000400, // Function/Class (export default declaration) - MultiLine = 0x00000800, // Multi-line array or object literal - Synthetic = 0x00001000, // Synthetic node (for full fidelity) - DeclarationFile = 0x00002000, // Node is a .d.ts file - Let = 0x00004000, // Variable declaration - Const = 0x00008000, // Variable declaration - OctalLiteral = 0x00010000, // Octal numeric literal - Namespace = 0x00020000, // Namespace declaration - ExportContext = 0x00040000, // Export context (initialized by binding) - ContainsThis = 0x00080000, // Interface contains references to "this" + Internal = 0x00000080, // Property/Method + Static = 0x00000100, // Property/Method + Abstract = 0x00000200, // Class/Method/ConstructSignature + Async = 0x00000400, // Property/Method/Function + Default = 0x00000800, // Function/Class (export default declaration) + MultiLine = 0x00001000, // Multi-line array or object literal + Synthetic = 0x00002000, // Synthetic node (for full fidelity) + DeclarationFile = 0x00004000, // Node is a .d.ts file + Let = 0x00008000, // Variable declaration + Const = 0x00010000, // Variable declaration + OctalLiteral = 0x00020000, // Octal numeric literal + Namespace = 0x00040000, // Namespace declaration + ExportContext = 0x00080000, // Export context (initialized by binding) + ContainsThis = 0x00100000, // Interface contains references to "this" - Modifier = Export | Ambient | Public | Private | Protected | Static | Abstract | Default | Async, - AccessibilityModifier = Public | Private | Protected, + Modifier = Export | Ambient | Public | Private | Internal | Protected | Static | Abstract | Default | Async, + AccessibilityModifier = Public | Private | Internal | Protected, BlockScoped = Let | Const } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 5127b98ab3a..23280c3646a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -363,7 +363,7 @@ namespace ts { } export function isDeclarationFile(file: SourceFile): boolean { - return (file.flags & NodeFlags.DeclarationFile) !== 0; + return file && (file.flags & NodeFlags.DeclarationFile) !== 0; } export function isConstEnumDeclaration(node: Node): boolean { @@ -1453,6 +1453,7 @@ namespace ts { case SyntaxKind.ExportKeyword: case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: + case SyntaxKind.InternalKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.StaticKeyword: return true; @@ -1983,6 +1984,7 @@ namespace ts { case SyntaxKind.StaticKeyword: return NodeFlags.Static; case SyntaxKind.PublicKeyword: return NodeFlags.Public; case SyntaxKind.ProtectedKeyword: return NodeFlags.Protected; + case SyntaxKind.InternalKeyword: return NodeFlags.Internal; case SyntaxKind.PrivateKeyword: return NodeFlags.Private; case SyntaxKind.AbstractKeyword: return NodeFlags.Abstract; case SyntaxKind.ExportKeyword: return NodeFlags.Export; diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 4a467a60a84..bb8256cd1c4 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -75,26 +75,26 @@ function delint(sourceFile) { delintNode(sourceFile); function delintNode(node) { switch (node.kind) { - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 196 /* WhileStatement */: - case 195 /* DoStatement */: - if (node.statement.kind !== 190 /* Block */) { + case 198 /* ForStatement */: + case 199 /* ForInStatement */: + case 197 /* WhileStatement */: + case 196 /* DoStatement */: + if (node.statement.kind !== 191 /* Block */) { report(node, "A looping statement's contents should be wrapped in a block body."); } break; - case 194 /* IfStatement */: + case 195 /* IfStatement */: var ifStatement = node; - if (ifStatement.thenStatement.kind !== 190 /* Block */) { + if (ifStatement.thenStatement.kind !== 191 /* Block */) { report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body."); } if (ifStatement.elseStatement && - ifStatement.elseStatement.kind !== 190 /* Block */ && - ifStatement.elseStatement.kind !== 194 /* IfStatement */) { + ifStatement.elseStatement.kind !== 191 /* Block */ && + ifStatement.elseStatement.kind !== 195 /* IfStatement */) { report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body."); } break; - case 179 /* BinaryExpression */: + case 180 /* BinaryExpression */: var op = node.operatorToken.kind; if (op === 30 /* EqualsEqualsToken */ || op == 31 /* ExclamationEqualsToken */) { report(node, "Use '===' and '!=='."); diff --git a/tests/baselines/reference/classPropertyAsInternal.errors.txt b/tests/baselines/reference/classPropertyAsInternal.errors.txt new file mode 100644 index 00000000000..b93a9d9b2e1 --- /dev/null +++ b/tests/baselines/reference/classPropertyAsInternal.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/classes/members/accessibility/classPropertyAsInternal.ts(3,18): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/accessibility/classPropertyAsInternal.ts(4,18): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/accessibility/classPropertyAsInternal.ts(8,25): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/accessibility/classPropertyAsInternal.ts(9,25): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + + +==== tests/cases/conformance/classes/members/accessibility/classPropertyAsInternal.ts (4 errors) ==== + class C { + internal x: string; + internal get y() { return null; } + ~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + internal set y(x) { } + ~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + internal foo() { } + + internal static a: string; + internal static get b() { return null; } + ~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + internal static set b(x) { } + ~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + internal static foo() { } + } + + var c: C; + // all OK + c.x; + c.y; + c.y = 1; + c.foo(); + + C.a; + C.b(); + C.b = 1; + C.foo(); \ No newline at end of file diff --git a/tests/baselines/reference/classPropertyAsInternal.js b/tests/baselines/reference/classPropertyAsInternal.js new file mode 100644 index 00000000000..d4e9374e334 --- /dev/null +++ b/tests/baselines/reference/classPropertyAsInternal.js @@ -0,0 +1,55 @@ +//// [classPropertyAsInternal.ts] +class C { + internal x: string; + internal get y() { return null; } + internal set y(x) { } + internal foo() { } + + internal static a: string; + internal static get b() { return null; } + internal static set b(x) { } + internal static foo() { } +} + +var c: C; +// all OK +c.x; +c.y; +c.y = 1; +c.foo(); + +C.a; +C.b(); +C.b = 1; +C.foo(); + +//// [classPropertyAsInternal.js] +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "y", { + get: function () { return null; }, + set: function (x) { }, + enumerable: true, + configurable: true + }); + C.prototype.foo = function () { }; + Object.defineProperty(C, "b", { + get: function () { return null; }, + set: function (x) { }, + enumerable: true, + configurable: true + }); + C.foo = function () { }; + return C; +})(); +var c; +// all OK +c.x; +c.y; +c.y = 1; +c.foo(); +C.a; +C.b(); +C.b = 1; +C.foo(); diff --git a/tests/baselines/reference/functionOverloadErrors.errors.txt b/tests/baselines/reference/functionOverloadErrors.errors.txt index ae1dfeae4d1..817c69a2ba8 100644 --- a/tests/baselines/reference/functionOverloadErrors.errors.txt +++ b/tests/baselines/reference/functionOverloadErrors.errors.txt @@ -2,8 +2,8 @@ tests/cases/conformance/functions/functionOverloadErrors.ts(2,14): error TS2371: tests/cases/conformance/functions/functionOverloadErrors.ts(44,25): error TS2304: Cannot find name 'Window'. tests/cases/conformance/functions/functionOverloadErrors.ts(50,25): error TS2304: Cannot find name 'Window'. tests/cases/conformance/functions/functionOverloadErrors.ts(51,32): error TS2304: Cannot find name 'window'. -tests/cases/conformance/functions/functionOverloadErrors.ts(65,13): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/functions/functionOverloadErrors.ts(68,13): error TS2385: Overload signatures must all be public, private or protected. +tests/cases/conformance/functions/functionOverloadErrors.ts(65,13): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/functions/functionOverloadErrors.ts(68,13): error TS2385: Overload signatures must all be public, internal, private or protected. tests/cases/conformance/functions/functionOverloadErrors.ts(75,21): error TS2383: Overload signatures must all be exported or not exported. tests/cases/conformance/functions/functionOverloadErrors.ts(79,14): error TS2383: Overload signatures must all be exported or not exported. tests/cases/conformance/functions/functionOverloadErrors.ts(85,18): error TS2384: Overload signatures must all be ambient or non-ambient. @@ -89,12 +89,12 @@ tests/cases/conformance/functions/functionOverloadErrors.ts(116,19): error TS237 public f(); private f(s: string); ~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. f() { } private g(s: string); ~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. public g(); g() { } } diff --git a/tests/baselines/reference/functionOverloads5.errors.txt b/tests/baselines/reference/functionOverloads5.errors.txt index 60a74f103e0..f0d0294dc49 100644 --- a/tests/baselines/reference/functionOverloads5.errors.txt +++ b/tests/baselines/reference/functionOverloads5.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/functionOverloads5.ts(2,10): error TS2385: Overload signatures must all be public, private or protected. +tests/cases/compiler/functionOverloads5.ts(2,10): error TS2385: Overload signatures must all be public, internal, private or protected. ==== tests/cases/compiler/functionOverloads5.ts (1 errors) ==== class baz { public foo(); ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private foo(bar?:any){ } } \ No newline at end of file diff --git a/tests/baselines/reference/internalClassPropertyAccessibleWithinClass.js b/tests/baselines/reference/internalClassPropertyAccessibleWithinClass.js new file mode 100644 index 00000000000..3dee418fc22 --- /dev/null +++ b/tests/baselines/reference/internalClassPropertyAccessibleWithinClass.js @@ -0,0 +1,99 @@ +//// [internalClassPropertyAccessibleWithinClass.ts] +// no errors + +class C { + internal x: string; + internal get y() { return this.x; } + internal set y(x) { this.y = this.x; } + internal foo() { return this.foo; } + + internal static x: string; + internal static get y() { return this.x; } + internal static set y(x) { this.y = this.x; } + internal static foo() { return this.foo; } + internal static bar() { this.foo(); } +} + +// added level of function nesting +class C2 { + internal x: string; + internal get y() { () => this.x; return null; } + internal set y(x) { () => { this.y = this.x; } } + internal foo() { () => this.foo; } + + internal static x: string; + internal static get y() { () => this.x; return null; } + internal static set y(x) { + () => { this.y = this.x; } + } + internal static foo() { () => this.foo; } + internal static bar() { () => this.foo(); } +} + + +//// [internalClassPropertyAccessibleWithinClass.js] +// no errors +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "y", { + get: function () { return this.x; }, + set: function (x) { this.y = this.x; }, + enumerable: true, + configurable: true + }); + C.prototype.foo = function () { return this.foo; }; + Object.defineProperty(C, "y", { + get: function () { return this.x; }, + set: function (x) { this.y = this.x; }, + enumerable: true, + configurable: true + }); + C.foo = function () { return this.foo; }; + C.bar = function () { this.foo(); }; + return C; +})(); +// added level of function nesting +var C2 = (function () { + function C2() { + } + Object.defineProperty(C2.prototype, "y", { + get: function () { + var _this = this; + (function () { return _this.x; }); + return null; + }, + set: function (x) { + var _this = this; + (function () { _this.y = _this.x; }); + }, + enumerable: true, + configurable: true + }); + C2.prototype.foo = function () { + var _this = this; + (function () { return _this.foo; }); + }; + Object.defineProperty(C2, "y", { + get: function () { + var _this = this; + (function () { return _this.x; }); + return null; + }, + set: function (x) { + var _this = this; + (function () { _this.y = _this.x; }); + }, + enumerable: true, + configurable: true + }); + C2.foo = function () { + var _this = this; + (function () { return _this.foo; }); + }; + C2.bar = function () { + var _this = this; + (function () { return _this.foo(); }); + }; + return C2; +})(); diff --git a/tests/baselines/reference/internalClassPropertyAccessibleWithinClass.symbols b/tests/baselines/reference/internalClassPropertyAccessibleWithinClass.symbols new file mode 100644 index 00000000000..a25ddcdf51b --- /dev/null +++ b/tests/baselines/reference/internalClassPropertyAccessibleWithinClass.symbols @@ -0,0 +1,126 @@ +=== tests/cases/conformance/classes/members/accessibility/internalClassPropertyAccessibleWithinClass.ts === +// no errors + +class C { +>C : Symbol(C, Decl(internalClassPropertyAccessibleWithinClass.ts, 0, 0)) + + internal x: string; +>x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 2, 9)) + + internal get y() { return this.x; } +>y : Symbol(y, Decl(internalClassPropertyAccessibleWithinClass.ts, 3, 23), Decl(internalClassPropertyAccessibleWithinClass.ts, 4, 39)) +>this.x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 2, 9)) +>this : Symbol(C, Decl(internalClassPropertyAccessibleWithinClass.ts, 0, 0)) +>x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 2, 9)) + + internal set y(x) { this.y = this.x; } +>y : Symbol(y, Decl(internalClassPropertyAccessibleWithinClass.ts, 3, 23), Decl(internalClassPropertyAccessibleWithinClass.ts, 4, 39)) +>x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 5, 19)) +>this.y : Symbol(y, Decl(internalClassPropertyAccessibleWithinClass.ts, 3, 23), Decl(internalClassPropertyAccessibleWithinClass.ts, 4, 39)) +>this : Symbol(C, Decl(internalClassPropertyAccessibleWithinClass.ts, 0, 0)) +>y : Symbol(y, Decl(internalClassPropertyAccessibleWithinClass.ts, 3, 23), Decl(internalClassPropertyAccessibleWithinClass.ts, 4, 39)) +>this.x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 2, 9)) +>this : Symbol(C, Decl(internalClassPropertyAccessibleWithinClass.ts, 0, 0)) +>x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 2, 9)) + + internal foo() { return this.foo; } +>foo : Symbol(foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 5, 42)) +>this.foo : Symbol(foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 5, 42)) +>this : Symbol(C, Decl(internalClassPropertyAccessibleWithinClass.ts, 0, 0)) +>foo : Symbol(foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 5, 42)) + + internal static x: string; +>x : Symbol(C.x, Decl(internalClassPropertyAccessibleWithinClass.ts, 6, 39)) + + internal static get y() { return this.x; } +>y : Symbol(C.y, Decl(internalClassPropertyAccessibleWithinClass.ts, 8, 30), Decl(internalClassPropertyAccessibleWithinClass.ts, 9, 46)) +>this.x : Symbol(C.x, Decl(internalClassPropertyAccessibleWithinClass.ts, 6, 39)) +>this : Symbol(C, Decl(internalClassPropertyAccessibleWithinClass.ts, 0, 0)) +>x : Symbol(C.x, Decl(internalClassPropertyAccessibleWithinClass.ts, 6, 39)) + + internal static set y(x) { this.y = this.x; } +>y : Symbol(C.y, Decl(internalClassPropertyAccessibleWithinClass.ts, 8, 30), Decl(internalClassPropertyAccessibleWithinClass.ts, 9, 46)) +>x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 10, 26)) +>this.y : Symbol(C.y, Decl(internalClassPropertyAccessibleWithinClass.ts, 8, 30), Decl(internalClassPropertyAccessibleWithinClass.ts, 9, 46)) +>this : Symbol(C, Decl(internalClassPropertyAccessibleWithinClass.ts, 0, 0)) +>y : Symbol(C.y, Decl(internalClassPropertyAccessibleWithinClass.ts, 8, 30), Decl(internalClassPropertyAccessibleWithinClass.ts, 9, 46)) +>this.x : Symbol(C.x, Decl(internalClassPropertyAccessibleWithinClass.ts, 6, 39)) +>this : Symbol(C, Decl(internalClassPropertyAccessibleWithinClass.ts, 0, 0)) +>x : Symbol(C.x, Decl(internalClassPropertyAccessibleWithinClass.ts, 6, 39)) + + internal static foo() { return this.foo; } +>foo : Symbol(C.foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 10, 49)) +>this.foo : Symbol(C.foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 10, 49)) +>this : Symbol(C, Decl(internalClassPropertyAccessibleWithinClass.ts, 0, 0)) +>foo : Symbol(C.foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 10, 49)) + + internal static bar() { this.foo(); } +>bar : Symbol(C.bar, Decl(internalClassPropertyAccessibleWithinClass.ts, 11, 46)) +>this.foo : Symbol(C.foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 10, 49)) +>this : Symbol(C, Decl(internalClassPropertyAccessibleWithinClass.ts, 0, 0)) +>foo : Symbol(C.foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 10, 49)) +} + +// added level of function nesting +class C2 { +>C2 : Symbol(C2, Decl(internalClassPropertyAccessibleWithinClass.ts, 13, 1)) + + internal x: string; +>x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 16, 10)) + + internal get y() { () => this.x; return null; } +>y : Symbol(y, Decl(internalClassPropertyAccessibleWithinClass.ts, 17, 23), Decl(internalClassPropertyAccessibleWithinClass.ts, 18, 51)) +>this.x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 16, 10)) +>this : Symbol(C2, Decl(internalClassPropertyAccessibleWithinClass.ts, 13, 1)) +>x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 16, 10)) + + internal set y(x) { () => { this.y = this.x; } } +>y : Symbol(y, Decl(internalClassPropertyAccessibleWithinClass.ts, 17, 23), Decl(internalClassPropertyAccessibleWithinClass.ts, 18, 51)) +>x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 19, 19)) +>this.y : Symbol(y, Decl(internalClassPropertyAccessibleWithinClass.ts, 17, 23), Decl(internalClassPropertyAccessibleWithinClass.ts, 18, 51)) +>this : Symbol(C2, Decl(internalClassPropertyAccessibleWithinClass.ts, 13, 1)) +>y : Symbol(y, Decl(internalClassPropertyAccessibleWithinClass.ts, 17, 23), Decl(internalClassPropertyAccessibleWithinClass.ts, 18, 51)) +>this.x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 16, 10)) +>this : Symbol(C2, Decl(internalClassPropertyAccessibleWithinClass.ts, 13, 1)) +>x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 16, 10)) + + internal foo() { () => this.foo; } +>foo : Symbol(foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 19, 52)) +>this.foo : Symbol(foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 19, 52)) +>this : Symbol(C2, Decl(internalClassPropertyAccessibleWithinClass.ts, 13, 1)) +>foo : Symbol(foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 19, 52)) + + internal static x: string; +>x : Symbol(C2.x, Decl(internalClassPropertyAccessibleWithinClass.ts, 20, 38)) + + internal static get y() { () => this.x; return null; } +>y : Symbol(C2.y, Decl(internalClassPropertyAccessibleWithinClass.ts, 22, 30), Decl(internalClassPropertyAccessibleWithinClass.ts, 23, 58)) +>this.x : Symbol(C2.x, Decl(internalClassPropertyAccessibleWithinClass.ts, 20, 38)) +>this : Symbol(C2, Decl(internalClassPropertyAccessibleWithinClass.ts, 13, 1)) +>x : Symbol(C2.x, Decl(internalClassPropertyAccessibleWithinClass.ts, 20, 38)) + + internal static set y(x) { +>y : Symbol(C2.y, Decl(internalClassPropertyAccessibleWithinClass.ts, 22, 30), Decl(internalClassPropertyAccessibleWithinClass.ts, 23, 58)) +>x : Symbol(x, Decl(internalClassPropertyAccessibleWithinClass.ts, 24, 26)) + + () => { this.y = this.x; } +>this.y : Symbol(C2.y, Decl(internalClassPropertyAccessibleWithinClass.ts, 22, 30), Decl(internalClassPropertyAccessibleWithinClass.ts, 23, 58)) +>this : Symbol(C2, Decl(internalClassPropertyAccessibleWithinClass.ts, 13, 1)) +>y : Symbol(C2.y, Decl(internalClassPropertyAccessibleWithinClass.ts, 22, 30), Decl(internalClassPropertyAccessibleWithinClass.ts, 23, 58)) +>this.x : Symbol(C2.x, Decl(internalClassPropertyAccessibleWithinClass.ts, 20, 38)) +>this : Symbol(C2, Decl(internalClassPropertyAccessibleWithinClass.ts, 13, 1)) +>x : Symbol(C2.x, Decl(internalClassPropertyAccessibleWithinClass.ts, 20, 38)) + } + internal static foo() { () => this.foo; } +>foo : Symbol(C2.foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 26, 6)) +>this.foo : Symbol(C2.foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 26, 6)) +>this : Symbol(C2, Decl(internalClassPropertyAccessibleWithinClass.ts, 13, 1)) +>foo : Symbol(C2.foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 26, 6)) + + internal static bar() { () => this.foo(); } +>bar : Symbol(C2.bar, Decl(internalClassPropertyAccessibleWithinClass.ts, 27, 45)) +>this.foo : Symbol(C2.foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 26, 6)) +>this : Symbol(C2, Decl(internalClassPropertyAccessibleWithinClass.ts, 13, 1)) +>foo : Symbol(C2.foo, Decl(internalClassPropertyAccessibleWithinClass.ts, 26, 6)) +} + diff --git a/tests/baselines/reference/internalClassPropertyAccessibleWithinClass.types b/tests/baselines/reference/internalClassPropertyAccessibleWithinClass.types new file mode 100644 index 00000000000..166713a2767 --- /dev/null +++ b/tests/baselines/reference/internalClassPropertyAccessibleWithinClass.types @@ -0,0 +1,141 @@ +=== tests/cases/conformance/classes/members/accessibility/internalClassPropertyAccessibleWithinClass.ts === +// no errors + +class C { +>C : C + + internal x: string; +>x : string + + internal get y() { return this.x; } +>y : string +>this.x : string +>this : this +>x : string + + internal set y(x) { this.y = this.x; } +>y : string +>x : string +>this.y = this.x : string +>this.y : string +>this : this +>y : string +>this.x : string +>this : this +>x : string + + internal foo() { return this.foo; } +>foo : () => any +>this.foo : () => any +>this : this +>foo : () => any + + internal static x: string; +>x : string + + internal static get y() { return this.x; } +>y : string +>this.x : string +>this : typeof C +>x : string + + internal static set y(x) { this.y = this.x; } +>y : string +>x : string +>this.y = this.x : string +>this.y : string +>this : typeof C +>y : string +>this.x : string +>this : typeof C +>x : string + + internal static foo() { return this.foo; } +>foo : () => typeof C.foo +>this.foo : () => typeof C.foo +>this : typeof C +>foo : () => typeof C.foo + + internal static bar() { this.foo(); } +>bar : () => void +>this.foo() : () => typeof C.foo +>this.foo : () => typeof C.foo +>this : typeof C +>foo : () => typeof C.foo +} + +// added level of function nesting +class C2 { +>C2 : C2 + + internal x: string; +>x : string + + internal get y() { () => this.x; return null; } +>y : any +>() => this.x : () => string +>this.x : string +>this : this +>x : string +>null : null + + internal set y(x) { () => { this.y = this.x; } } +>y : any +>x : any +>() => { this.y = this.x; } : () => void +>this.y = this.x : string +>this.y : any +>this : this +>y : any +>this.x : string +>this : this +>x : string + + internal foo() { () => this.foo; } +>foo : () => void +>() => this.foo : () => () => void +>this.foo : () => void +>this : this +>foo : () => void + + internal static x: string; +>x : string + + internal static get y() { () => this.x; return null; } +>y : any +>() => this.x : () => string +>this.x : string +>this : typeof C2 +>x : string +>null : null + + internal static set y(x) { +>y : any +>x : any + + () => { this.y = this.x; } +>() => { this.y = this.x; } : () => void +>this.y = this.x : string +>this.y : any +>this : typeof C2 +>y : any +>this.x : string +>this : typeof C2 +>x : string + } + internal static foo() { () => this.foo; } +>foo : () => void +>() => this.foo : () => () => void +>this.foo : () => void +>this : typeof C2 +>foo : () => void + + internal static bar() { () => this.foo(); } +>bar : () => void +>() => this.foo() : () => void +>this.foo() : void +>this.foo : () => void +>this : typeof C2 +>foo : () => void +} + diff --git a/tests/baselines/reference/internalClassPropertyAssignability.errors.txt b/tests/baselines/reference/internalClassPropertyAssignability.errors.txt new file mode 100644 index 00000000000..62870df42eb --- /dev/null +++ b/tests/baselines/reference/internalClassPropertyAssignability.errors.txt @@ -0,0 +1,119 @@ +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(27,1): error TS2322: Type 'Class1' is not assignable to type 'XY'. + Property 'y' of type 'Class1' is internal in a declaration file and is only accessible within a declaration file. +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(28,1): error TS2322: Type 'Class2' is not assignable to type 'XY'. + Property 'y' of type 'Class2' is internal in a declaration file and is only accessible within a declaration file. +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(30,1): error TS2322: Type 'Class4' is not assignable to type 'XY'. + Property 'y' of type 'Class4' is internal in a declaration file and is only accessible within a declaration file. +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(32,1): error TS2322: Type 'XY' is not assignable to type 'Class1'. + Property 'y' is internal in a declaration file, but type 'XY' is not a class derived from 'Class1'. +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(36,1): error TS2322: Type 'Class5' is not assignable to type 'Class1'. + Property 'y' is internal in a declaration file, but type 'Class5' is not a class derived from 'Class1'. +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(37,1): error TS2322: Type 'XY' is not assignable to type 'Class2'. + Property 'y' is internal in a declaration file, but type 'XY' is not a class derived from 'Class2'. +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(38,1): error TS2322: Type 'Class3' is not assignable to type 'Class2'. + Property 'y' is internal in a declaration file, but type 'Class3' is not a class derived from 'Class2'. +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(39,1): error TS2322: Type 'Class4' is not assignable to type 'Class2'. + Property 'y' is internal in a declaration file, but type 'Class1' is not a class derived from 'Class2'. +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(40,1): error TS2322: Type 'Class5' is not assignable to type 'Class2'. + Property 'y' is internal in a declaration file, but type 'Class5' is not a class derived from 'Class2'. +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(42,1): error TS2322: Type 'Class4' is not assignable to type 'Class3'. + Property 'y' is internal in a declaration file, but type 'Class1' is not a class derived from 'Class3'. +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(44,1): error TS2322: Type 'XY' is not assignable to type 'Class4'. + Property 'y' is internal in a declaration file, but type 'XY' is not a class derived from 'Class1'. +tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts(45,1): error TS2322: Type 'Class5' is not assignable to type 'Class4'. + Property 'y' is internal in a declaration file, but type 'Class5' is not a class derived from 'Class1'. + + +==== tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_1.ts (12 errors) ==== + /// + interface XY { + x: number; + y: number; + } + + declare class Class3 extends Class1 { + internal y: number; // error + } + + declare class Class4 extends Class1 { + } + + + declare class Class5 { + public x: number; + internal y: number; + } + + declare var xy: XY; + declare var c1: Class1; + declare var c2: Class2; + declare var c3: Class3; + declare var c4: Class4; + declare var c5: Class5; + + xy = c1; // error + ~~ +!!! error TS2322: Type 'Class1' is not assignable to type 'XY'. +!!! error TS2322: Property 'y' of type 'Class1' is internal in a declaration file and is only accessible within a declaration file. + xy = c2; // error + ~~ +!!! error TS2322: Type 'Class2' is not assignable to type 'XY'. +!!! error TS2322: Property 'y' of type 'Class2' is internal in a declaration file and is only accessible within a declaration file. + xy = c3; // ok + xy = c4; // error + ~~ +!!! error TS2322: Type 'Class4' is not assignable to type 'XY'. +!!! error TS2322: Property 'y' of type 'Class4' is internal in a declaration file and is only accessible within a declaration file. + xy = c5; // ok + c1 = xy; // error + ~~ +!!! error TS2322: Type 'XY' is not assignable to type 'Class1'. +!!! error TS2322: Property 'y' is internal in a declaration file, but type 'XY' is not a class derived from 'Class1'. + c1 = c2; // ok + c1 = c3; // ok + c1 = c4; // ok + c1 = c5; // error + ~~ +!!! error TS2322: Type 'Class5' is not assignable to type 'Class1'. +!!! error TS2322: Property 'y' is internal in a declaration file, but type 'Class5' is not a class derived from 'Class1'. + c2 = xy; // error + ~~ +!!! error TS2322: Type 'XY' is not assignable to type 'Class2'. +!!! error TS2322: Property 'y' is internal in a declaration file, but type 'XY' is not a class derived from 'Class2'. + c2 = c3; // error + ~~ +!!! error TS2322: Type 'Class3' is not assignable to type 'Class2'. +!!! error TS2322: Property 'y' is internal in a declaration file, but type 'Class3' is not a class derived from 'Class2'. + c2 = c4; // error + ~~ +!!! error TS2322: Type 'Class4' is not assignable to type 'Class2'. +!!! error TS2322: Property 'y' is internal in a declaration file, but type 'Class1' is not a class derived from 'Class2'. + c2 = c5; // error + ~~ +!!! error TS2322: Type 'Class5' is not assignable to type 'Class2'. +!!! error TS2322: Property 'y' is internal in a declaration file, but type 'Class5' is not a class derived from 'Class2'. + c3 = xy; // ok + c3 = c4; // error + ~~ +!!! error TS2322: Type 'Class4' is not assignable to type 'Class3'. +!!! error TS2322: Property 'y' is internal in a declaration file, but type 'Class1' is not a class derived from 'Class3'. + c3 = c5; // ok + c4 = xy; // error + ~~ +!!! error TS2322: Type 'XY' is not assignable to type 'Class4'. +!!! error TS2322: Property 'y' is internal in a declaration file, but type 'XY' is not a class derived from 'Class1'. + c4 = c5; // error + ~~ +!!! error TS2322: Type 'Class5' is not assignable to type 'Class4'. +!!! error TS2322: Property 'y' is internal in a declaration file, but type 'Class5' is not a class derived from 'Class1'. + c5 = xy; // ok +==== tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability_0.d.ts (0 errors) ==== + declare class Class1 { + public x: number; + internal y: number; + } + + declare class Class2 extends Class1 { + internal y: number; // ok + } + \ No newline at end of file diff --git a/tests/baselines/reference/internalClassPropertyAssignability.js b/tests/baselines/reference/internalClassPropertyAssignability.js new file mode 100644 index 00000000000..12d484f0794 --- /dev/null +++ b/tests/baselines/reference/internalClassPropertyAssignability.js @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability.ts] //// + +//// [internalClassPropertyAssignability_0.d.ts] +declare class Class1 { + public x: number; + internal y: number; +} + +declare class Class2 extends Class1 { + internal y: number; // ok +} + +//// [internalClassPropertyAssignability_1.ts] +/// +interface XY { + x: number; + y: number; +} + +declare class Class3 extends Class1 { + internal y: number; // error +} + +declare class Class4 extends Class1 { +} + + +declare class Class5 { + public x: number; + internal y: number; +} + +declare var xy: XY; +declare var c1: Class1; +declare var c2: Class2; +declare var c3: Class3; +declare var c4: Class4; +declare var c5: Class5; + +xy = c1; // error +xy = c2; // error +xy = c3; // ok +xy = c4; // error +xy = c5; // ok +c1 = xy; // error +c1 = c2; // ok +c1 = c3; // ok +c1 = c4; // ok +c1 = c5; // error +c2 = xy; // error +c2 = c3; // error +c2 = c4; // error +c2 = c5; // error +c3 = xy; // ok +c3 = c4; // error +c3 = c5; // ok +c4 = xy; // error +c4 = c5; // error +c5 = xy; // ok + +//// [internalClassPropertyAssignability_1.js] +/// +xy = c1; // error +xy = c2; // error +xy = c3; // ok +xy = c4; // error +xy = c5; // ok +c1 = xy; // error +c1 = c2; // ok +c1 = c3; // ok +c1 = c4; // ok +c1 = c5; // error +c2 = xy; // error +c2 = c3; // error +c2 = c4; // error +c2 = c5; // error +c3 = xy; // ok +c3 = c4; // error +c3 = c5; // ok +c4 = xy; // error +c4 = c5; // error +c5 = xy; // ok diff --git a/tests/baselines/reference/internalInstanceMemberAccessibility.errors.txt b/tests/baselines/reference/internalInstanceMemberAccessibility.errors.txt new file mode 100644 index 00000000000..82f74e5815a --- /dev/null +++ b/tests/baselines/reference/internalInstanceMemberAccessibility.errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/classes/members/accessibility/internalInstanceMemberAccessibility_1.ts(4,9): error TS2657: Property 'foo' is internal in a declaration file and is only accessible within a declaration file. +tests/cases/conformance/classes/members/accessibility/internalInstanceMemberAccessibility_1.ts(6,16): error TS2657: Property 'foo' is internal in a declaration file and is only accessible within a declaration file. + + +==== tests/cases/conformance/classes/members/accessibility/internalInstanceMemberAccessibility_0.d.ts (0 errors) ==== + export declare class Base1 { + internal foo(): string; + } + +==== tests/cases/conformance/classes/members/accessibility/internalInstanceMemberAccessibility_1.ts (2 errors) ==== + import { Base1 } from "./internalInstanceMemberAccessibility_0"; + + class Derived1 extends Base1 { + x = super.foo(); // error + ~~~~~~~~~ +!!! error TS2657: Property 'foo' is internal in a declaration file and is only accessible within a declaration file. + y() { + return super.foo(); // error + ~~~~~~~~~ +!!! error TS2657: Property 'foo' is internal in a declaration file and is only accessible within a declaration file. + } + } + + declare class Base2 { + internal foo(): string; + } + + class Derived2 extends Base2 { + x = super.foo(); // ok + y() { + return super.foo(); // ok + } + } \ No newline at end of file diff --git a/tests/baselines/reference/internalInstanceMemberAccessibility.js b/tests/baselines/reference/internalInstanceMemberAccessibility.js new file mode 100644 index 00000000000..10a45e1370d --- /dev/null +++ b/tests/baselines/reference/internalInstanceMemberAccessibility.js @@ -0,0 +1,58 @@ +//// [tests/cases/conformance/classes/members/accessibility/internalInstanceMemberAccessibility.ts] //// + +//// [internalInstanceMemberAccessibility_0.d.ts] +export declare class Base1 { + internal foo(): string; +} + +//// [internalInstanceMemberAccessibility_1.ts] +import { Base1 } from "./internalInstanceMemberAccessibility_0"; + +class Derived1 extends Base1 { + x = super.foo(); // error + y() { + return super.foo(); // error + } +} + +declare class Base2 { + internal foo(): string; +} + +class Derived2 extends Base2 { + x = super.foo(); // ok + y() { + return super.foo(); // ok + } +} + +//// [internalInstanceMemberAccessibility_1.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +define(["require", "exports", "./internalInstanceMemberAccessibility_0"], function (require, exports, internalInstanceMemberAccessibility_0_1) { + var Derived1 = (function (_super) { + __extends(Derived1, _super); + function Derived1() { + _super.apply(this, arguments); + this.x = _super.prototype.foo.call(this); // error + } + Derived1.prototype.y = function () { + return _super.prototype.foo.call(this); // error + }; + return Derived1; + })(internalInstanceMemberAccessibility_0_1.Base1); + var Derived2 = (function (_super) { + __extends(Derived2, _super); + function Derived2() { + _super.apply(this, arguments); + this.x = _super.prototype.foo.call(this); // ok + } + Derived2.prototype.y = function () { + return _super.prototype.foo.call(this); // ok + }; + return Derived2; + })(Base2); +}); diff --git a/tests/baselines/reference/internalStaticMemberAccessibility.errors.txt b/tests/baselines/reference/internalStaticMemberAccessibility.errors.txt new file mode 100644 index 00000000000..88c75c824f8 --- /dev/null +++ b/tests/baselines/reference/internalStaticMemberAccessibility.errors.txt @@ -0,0 +1,28 @@ +tests/cases/conformance/classes/members/accessibility/internalStaticMemberAccessibility_1.ts(3,18): error TS2657: Property 'foo' is internal in a declaration file and is only accessible within a declaration file. +tests/cases/conformance/classes/members/accessibility/internalStaticMemberAccessibility_1.ts(4,18): error TS2657: Property 'foo' is internal in a declaration file and is only accessible within a declaration file. + + +==== tests/cases/conformance/classes/members/accessibility/internalStaticMemberAccessibility_1.ts (2 errors) ==== + /// + class Derived1 extends Base1 { + static bar = Base1.foo; // error + ~~~~~~~~~ +!!! error TS2657: Property 'foo' is internal in a declaration file and is only accessible within a declaration file. + bing = () => Base1.foo; // error + ~~~~~~~~~ +!!! error TS2657: Property 'foo' is internal in a declaration file and is only accessible within a declaration file. + } + + class Base2 { + internal static foo: string; + } + + class Derived2 extends Base2 { + static bar = Base2.foo; // ok + bing = () => Base2.foo; // ok + } +==== tests/cases/conformance/classes/members/accessibility/internalStaticMemberAccessibility_0.d.ts (0 errors) ==== + declare class Base1 { + internal static foo: string; + } + \ No newline at end of file diff --git a/tests/baselines/reference/internalStaticMemberAccessibility.js b/tests/baselines/reference/internalStaticMemberAccessibility.js new file mode 100644 index 00000000000..e83168d9a96 --- /dev/null +++ b/tests/baselines/reference/internalStaticMemberAccessibility.js @@ -0,0 +1,53 @@ +//// [tests/cases/conformance/classes/members/accessibility/internalStaticMemberAccessibility.ts] //// + +//// [internalStaticMemberAccessibility_0.d.ts] +declare class Base1 { + internal static foo: string; +} + +//// [internalStaticMemberAccessibility_1.ts] +/// +class Derived1 extends Base1 { + static bar = Base1.foo; // error + bing = () => Base1.foo; // error +} + +class Base2 { + internal static foo: string; +} + +class Derived2 extends Base2 { + static bar = Base2.foo; // ok + bing = () => Base2.foo; // ok +} + +//// [internalStaticMemberAccessibility_1.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +/// +var Derived1 = (function (_super) { + __extends(Derived1, _super); + function Derived1() { + _super.apply(this, arguments); + this.bing = function () { return Base1.foo; }; // error + } + Derived1.bar = Base1.foo; // error + return Derived1; +})(Base1); +var Base2 = (function () { + function Base2() { + } + return Base2; +})(); +var Derived2 = (function (_super) { + __extends(Derived2, _super); + function Derived2() { + _super.apply(this, arguments); + this.bing = function () { return Base2.foo; }; // ok + } + Derived2.bar = Base2.foo; // ok + return Derived2; +})(Base2); diff --git a/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt b/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt index 64d2f3d3059..dc39da0bde4 100644 --- a/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt +++ b/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt @@ -1,16 +1,16 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(3,12): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(7,12): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(12,19): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(15,15): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(16,15): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(20,19): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(25,19): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(32,12): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(36,12): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(41,15): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(45,19): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(49,19): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(53,19): error TS2385: Overload signatures must all be public, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(3,12): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(7,12): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(12,19): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(15,15): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(16,15): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(20,19): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(25,19): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(32,12): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(36,12): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(41,15): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(45,19): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(49,19): error TS2385: Overload signatures must all be public, internal, private or protected. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(53,19): error TS2385: Overload signatures must all be public, internal, private or protected. tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(59,9): error TS2341: Property 'foo' is private and only accessible within class 'C'. tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(62,10): error TS2341: Property 'foo' is private and only accessible within class 'D'. @@ -20,41 +20,41 @@ tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclara private foo(x: number); public foo(x: number, y: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private foo(x: any, y?: any) { } private bar(x: 'hi'); public bar(x: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private bar(x: number, y: string); private bar(x: any, y?: any) { } private static foo(x: number); public static foo(x: number, y: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private static foo(x: any, y?: any) { } protected baz(x: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. protected baz(x: number, y: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private baz(x: any, y?: any) { } private static bar(x: 'hi'); public static bar(x: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private static bar(x: number, y: string); private static bar(x: any, y?: any) { } protected static baz(x: 'hi'); public static baz(x: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. protected static baz(x: number, y: string); protected static baz(x: any, y?: any) { } } @@ -63,38 +63,38 @@ tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclara private foo(x: number); public foo(x: T, y: T); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private foo(x: any, y?: any) { } private bar(x: 'hi'); public bar(x: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private bar(x: T, y: T); private bar(x: any, y?: any) { } private baz(x: string); protected baz(x: number, y: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private baz(x: any, y?: any) { } private static foo(x: number); public static foo(x: number, y: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private static foo(x: any, y?: any) { } private static bar(x: 'hi'); public static bar(x: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private static bar(x: number, y: string); private static bar(x: any, y?: any) { } public static baz(x: string); // error ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. protected static baz(x: number, y: string); protected static baz(x: any, y?: any) { } } diff --git a/tests/baselines/reference/overloadModifiersMustAgree.errors.txt b/tests/baselines/reference/overloadModifiersMustAgree.errors.txt index 0efdbcdd1f6..a3a7c6fb4a3 100644 --- a/tests/baselines/reference/overloadModifiersMustAgree.errors.txt +++ b/tests/baselines/reference/overloadModifiersMustAgree.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/overloadModifiersMustAgree.ts(2,12): error TS2385: Overload signatures must all be public, private or protected. +tests/cases/compiler/overloadModifiersMustAgree.ts(2,12): error TS2385: Overload signatures must all be public, internal, private or protected. tests/cases/compiler/overloadModifiersMustAgree.ts(6,18): error TS2384: Overload signatures must all be ambient or non-ambient. tests/cases/compiler/overloadModifiersMustAgree.ts(7,17): error TS2383: Overload signatures must all be exported or not exported. tests/cases/compiler/overloadModifiersMustAgree.ts(12,5): error TS2386: Overload signatures must all be optional or required. @@ -8,7 +8,7 @@ tests/cases/compiler/overloadModifiersMustAgree.ts(12,5): error TS2386: Overload class baz { public foo(); ~~~ -!!! error TS2385: Overload signatures must all be public, private or protected. +!!! error TS2385: Overload signatures must all be public, internal, private or protected. private foo(bar?: any) { } // error - access modifiers do not agree } diff --git a/tests/cases/conformance/classes/members/accessibility/classPropertyAsInternal.ts b/tests/cases/conformance/classes/members/accessibility/classPropertyAsInternal.ts new file mode 100644 index 00000000000..19bc7b0df41 --- /dev/null +++ b/tests/cases/conformance/classes/members/accessibility/classPropertyAsInternal.ts @@ -0,0 +1,23 @@ +class C { + internal x: string; + internal get y() { return null; } + internal set y(x) { } + internal foo() { } + + internal static a: string; + internal static get b() { return null; } + internal static set b(x) { } + internal static foo() { } +} + +var c: C; +// all OK +c.x; +c.y; +c.y = 1; +c.foo(); + +C.a; +C.b(); +C.b = 1; +C.foo(); \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/accessibility/internalClassPropertyAccessibleWithinClass.ts b/tests/cases/conformance/classes/members/accessibility/internalClassPropertyAccessibleWithinClass.ts new file mode 100644 index 00000000000..4ae168c9c88 --- /dev/null +++ b/tests/cases/conformance/classes/members/accessibility/internalClassPropertyAccessibleWithinClass.ts @@ -0,0 +1,31 @@ +// @target: ES5 +// no errors + +class C { + internal x: string; + internal get y() { return this.x; } + internal set y(x) { this.y = this.x; } + internal foo() { return this.foo; } + + internal static x: string; + internal static get y() { return this.x; } + internal static set y(x) { this.y = this.x; } + internal static foo() { return this.foo; } + internal static bar() { this.foo(); } +} + +// added level of function nesting +class C2 { + internal x: string; + internal get y() { () => this.x; return null; } + internal set y(x) { () => { this.y = this.x; } } + internal foo() { () => this.foo; } + + internal static x: string; + internal static get y() { () => this.x; return null; } + internal static set y(x) { + () => { this.y = this.x; } + } + internal static foo() { () => this.foo; } + internal static bar() { () => this.foo(); } +} diff --git a/tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability.ts b/tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability.ts new file mode 100644 index 00000000000..037ac0be027 --- /dev/null +++ b/tests/cases/conformance/classes/members/accessibility/internalClassPropertyAssignability.ts @@ -0,0 +1,57 @@ +// @filename: internalClassPropertyAssignability_0.d.ts +declare class Class1 { + public x: number; + internal y: number; +} + +declare class Class2 extends Class1 { + internal y: number; // ok +} + +// @filename: internalClassPropertyAssignability_1.ts +/// +interface XY { + x: number; + y: number; +} + +declare class Class3 extends Class1 { + internal y: number; // error +} + +declare class Class4 extends Class1 { +} + + +declare class Class5 { + public x: number; + internal y: number; +} + +declare var xy: XY; +declare var c1: Class1; +declare var c2: Class2; +declare var c3: Class3; +declare var c4: Class4; +declare var c5: Class5; + +xy = c1; // error +xy = c2; // error +xy = c3; // ok +xy = c4; // error +xy = c5; // ok +c1 = xy; // error +c1 = c2; // ok +c1 = c3; // ok +c1 = c4; // ok +c1 = c5; // error +c2 = xy; // error +c2 = c3; // error +c2 = c4; // error +c2 = c5; // error +c3 = xy; // ok +c3 = c4; // error +c3 = c5; // ok +c4 = xy; // error +c4 = c5; // error +c5 = xy; // ok \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/accessibility/internalInstanceMemberAccessibility.ts b/tests/cases/conformance/classes/members/accessibility/internalInstanceMemberAccessibility.ts new file mode 100644 index 00000000000..cd7e74e77db --- /dev/null +++ b/tests/cases/conformance/classes/members/accessibility/internalInstanceMemberAccessibility.ts @@ -0,0 +1,26 @@ +// @module: amd +// @Filename: internalInstanceMemberAccessibility_0.d.ts +export declare class Base1 { + internal foo(): string; +} + +// @Filename: internalInstanceMemberAccessibility_1.ts +import { Base1 } from "./internalInstanceMemberAccessibility_0"; + +class Derived1 extends Base1 { + x = super.foo(); // error + y() { + return super.foo(); // error + } +} + +declare class Base2 { + internal foo(): string; +} + +class Derived2 extends Base2 { + x = super.foo(); // ok + y() { + return super.foo(); // ok + } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/accessibility/internalStaticMemberAccessibility.ts b/tests/cases/conformance/classes/members/accessibility/internalStaticMemberAccessibility.ts new file mode 100644 index 00000000000..1cb45db0530 --- /dev/null +++ b/tests/cases/conformance/classes/members/accessibility/internalStaticMemberAccessibility.ts @@ -0,0 +1,21 @@ +// @module: amd +// @filename: internalStaticMemberAccessibility_0.d.ts +declare class Base1 { + internal static foo: string; +} + +// @filename: internalStaticMemberAccessibility_1.ts +/// +class Derived1 extends Base1 { + static bar = Base1.foo; // error + bing = () => Base1.foo; // error +} + +class Base2 { + internal static foo: string; +} + +class Derived2 extends Base2 { + static bar = Base2.foo; // ok + bing = () => Base2.foo; // ok +} \ No newline at end of file