merge with origin/master, add trace message with type of 'typings' field is not 'string'
This commit is contained in:
commit
2dbf621e97
|
@ -6148,14 +6148,25 @@ namespace ts {
|
||||||
function inferFromTypes(source: Type, target: Type) {
|
function inferFromTypes(source: Type, target: Type) {
|
||||||
if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union ||
|
if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union ||
|
||||||
source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) {
|
source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) {
|
||||||
// Source and target are both unions or both intersections. To improve the quality of
|
// Source and target are both unions or both intersections. First, find each
|
||||||
// inferences we first reduce the types by removing constituents that are identically
|
// target constituent type that has an identically matching source constituent
|
||||||
// matched by a constituent in the other type. For example, when inferring from
|
// type, and for each such target constituent type infer from the type to itself.
|
||||||
// 'string | string[]' to 'string | T', we reduce the types to 'string[]' and 'T'.
|
// When inferring from a type to itself we effectively find all type parameter
|
||||||
const reducedSource = reduceUnionOrIntersectionType(<UnionOrIntersectionType>source, <UnionOrIntersectionType>target);
|
// occurrences within that type and infer themselves as their type arguments.
|
||||||
const reducedTarget = reduceUnionOrIntersectionType(<UnionOrIntersectionType>target, <UnionOrIntersectionType>source);
|
let matchingTypes: Type[];
|
||||||
source = reducedSource;
|
for (const t of (<UnionOrIntersectionType>target).types) {
|
||||||
target = reducedTarget;
|
if (typeIdenticalToSomeType(t, (<UnionOrIntersectionType>source).types)) {
|
||||||
|
(matchingTypes || (matchingTypes = [])).push(t);
|
||||||
|
inferFromTypes(t, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Next, to improve the quality of inferences, reduce the source and target types by
|
||||||
|
// removing the identically matched constituents. For example, when inferring from
|
||||||
|
// 'string | string[]' to 'string | T' we reduce the types to 'string[]' and 'T'.
|
||||||
|
if (matchingTypes) {
|
||||||
|
source = removeTypesFromUnionOrIntersection(<UnionOrIntersectionType>source, matchingTypes);
|
||||||
|
target = removeTypesFromUnionOrIntersection(<UnionOrIntersectionType>target, matchingTypes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (target.flags & TypeFlags.TypeParameter) {
|
if (target.flags & TypeFlags.TypeParameter) {
|
||||||
// If target is a type parameter, make an inference, unless the source type contains
|
// If target is a type parameter, make an inference, unless the source type contains
|
||||||
|
@ -6317,9 +6328,9 @@ namespace ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function typeIdenticalToSomeType(source: Type, target: UnionOrIntersectionType): boolean {
|
function typeIdenticalToSomeType(type: Type, types: Type[]): boolean {
|
||||||
for (const t of target.types) {
|
for (const t of types) {
|
||||||
if (isTypeIdenticalTo(source, t)) {
|
if (isTypeIdenticalTo(t, type)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6327,29 +6338,17 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the reduced form of the source type. This type is computed by by removing all source
|
* Return a new union or intersection type computed by removing a given set of types
|
||||||
* constituents that have an identical match in the target type.
|
* from a given union or intersection type.
|
||||||
*/
|
*/
|
||||||
function reduceUnionOrIntersectionType(source: UnionOrIntersectionType, target: UnionOrIntersectionType) {
|
function removeTypesFromUnionOrIntersection(type: UnionOrIntersectionType, typesToRemove: Type[]) {
|
||||||
let sourceTypes = source.types;
|
const reducedTypes: Type[] = [];
|
||||||
let sourceIndex = 0;
|
for (const t of type.types) {
|
||||||
let modified = false;
|
if (!typeIdenticalToSomeType(t, typesToRemove)) {
|
||||||
while (sourceIndex < sourceTypes.length) {
|
reducedTypes.push(t);
|
||||||
if (typeIdenticalToSomeType(sourceTypes[sourceIndex], target)) {
|
|
||||||
if (!modified) {
|
|
||||||
sourceTypes = sourceTypes.slice(0);
|
|
||||||
modified = true;
|
|
||||||
}
|
|
||||||
sourceTypes.splice(sourceIndex, 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sourceIndex++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (modified) {
|
return type.flags & TypeFlags.Union ? getUnionType(reducedTypes, /*noSubtypeReduction*/ true) : getIntersectionType(reducedTypes);
|
||||||
return source.flags & TypeFlags.Union ? getUnionType(sourceTypes, /*noSubtypeReduction*/ true) : getIntersectionType(sourceTypes);
|
|
||||||
}
|
|
||||||
return source;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInferenceCandidates(context: InferenceContext, index: number): Type[] {
|
function getInferenceCandidates(context: InferenceContext, index: number): Type[] {
|
||||||
|
@ -15493,6 +15492,11 @@ namespace ts {
|
||||||
let flags = 0;
|
let flags = 0;
|
||||||
for (const modifier of node.modifiers) {
|
for (const modifier of node.modifiers) {
|
||||||
switch (modifier.kind) {
|
switch (modifier.kind) {
|
||||||
|
case SyntaxKind.ConstKeyword:
|
||||||
|
if (node.kind !== SyntaxKind.EnumDeclaration && node.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||||
|
return grammarErrorOnNode(node, Diagnostics.A_class_member_cannot_have_the_0_keyword, tokenToString(SyntaxKind.ConstKeyword));
|
||||||
|
}
|
||||||
|
break;
|
||||||
case SyntaxKind.PublicKeyword:
|
case SyntaxKind.PublicKeyword:
|
||||||
case SyntaxKind.ProtectedKeyword:
|
case SyntaxKind.ProtectedKeyword:
|
||||||
case SyntaxKind.PrivateKeyword:
|
case SyntaxKind.PrivateKeyword:
|
||||||
|
|
|
@ -791,7 +791,10 @@
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 1247
|
"code": 1247
|
||||||
},
|
},
|
||||||
|
"A class member cannot have the '{0}' keyword.": {
|
||||||
|
"category": "Error",
|
||||||
|
"code": 1248
|
||||||
|
},
|
||||||
"'with' statements are not allowed in an async function block.": {
|
"'with' statements are not allowed in an async function block.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 1300
|
"code": 1300
|
||||||
|
@ -2507,6 +2510,10 @@
|
||||||
"Checking if '{0}' is the longest matching prefix for '{1}' - '{2}'.": {
|
"Checking if '{0}' is the longest matching prefix for '{1}' - '{2}'.": {
|
||||||
"category": "Message",
|
"category": "Message",
|
||||||
"code": 6112
|
"code": 6112
|
||||||
|
},
|
||||||
|
"Expected type of 'typings' field in 'package.json' to be 'string', got '{0}'.": {
|
||||||
|
"category": "Message",
|
||||||
|
"code": 6113
|
||||||
},
|
},
|
||||||
"Variable '{0}' implicitly has an '{1}' type.": {
|
"Variable '{0}' implicitly has an '{1}' type.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
|
|
|
@ -1134,6 +1134,14 @@ namespace ts {
|
||||||
return token === t && tryParse(nextTokenCanFollowModifier);
|
return token === t && tryParse(nextTokenCanFollowModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nextTokenIsOnSameLineAndCanFollowModifier() {
|
||||||
|
nextToken();
|
||||||
|
if (scanner.hasPrecedingLineBreak()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return canFollowModifier();
|
||||||
|
}
|
||||||
|
|
||||||
function nextTokenCanFollowModifier() {
|
function nextTokenCanFollowModifier() {
|
||||||
if (token === SyntaxKind.ConstKeyword) {
|
if (token === SyntaxKind.ConstKeyword) {
|
||||||
// 'const' is only a modifier if followed by 'enum'.
|
// 'const' is only a modifier if followed by 'enum'.
|
||||||
|
@ -1154,11 +1162,7 @@ namespace ts {
|
||||||
return canFollowModifier();
|
return canFollowModifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
nextToken();
|
return nextTokenIsOnSameLineAndCanFollowModifier();
|
||||||
if (scanner.hasPrecedingLineBreak()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return canFollowModifier();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseAnyContextualModifier(): boolean {
|
function parseAnyContextualModifier(): boolean {
|
||||||
|
@ -4923,15 +4927,31 @@ namespace ts {
|
||||||
return decorators;
|
return decorators;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseModifiers(): ModifiersArray {
|
/*
|
||||||
|
* There are situations in which a modifier like 'const' will appear unexpectedly, such as on a class member.
|
||||||
|
* In those situations, if we are entirely sure that 'const' is not valid on its own (such as when ASI takes effect
|
||||||
|
* and turns it into a standalone declaration), then it is better to parse it and report an error later.
|
||||||
|
*
|
||||||
|
* In such situations, 'permitInvalidConstAsModifier' should be set to true.
|
||||||
|
*/
|
||||||
|
function parseModifiers(permitInvalidConstAsModifier?: boolean): ModifiersArray {
|
||||||
let flags = 0;
|
let flags = 0;
|
||||||
let modifiers: ModifiersArray;
|
let modifiers: ModifiersArray;
|
||||||
while (true) {
|
while (true) {
|
||||||
const modifierStart = scanner.getStartPos();
|
const modifierStart = scanner.getStartPos();
|
||||||
const modifierKind = token;
|
const modifierKind = token;
|
||||||
|
|
||||||
if (!parseAnyContextualModifier()) {
|
if (token === SyntaxKind.ConstKeyword && permitInvalidConstAsModifier) {
|
||||||
break;
|
// We need to ensure that any subsequent modifiers appear on the same line
|
||||||
|
// so that when 'const' is a standalone declaration, we don't issue an error.
|
||||||
|
if (!tryParse(nextTokenIsOnSameLineAndCanFollowModifier)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!parseAnyContextualModifier()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!modifiers) {
|
if (!modifiers) {
|
||||||
|
@ -4976,7 +4996,7 @@ namespace ts {
|
||||||
|
|
||||||
const fullStart = getNodePos();
|
const fullStart = getNodePos();
|
||||||
const decorators = parseDecorators();
|
const decorators = parseDecorators();
|
||||||
const modifiers = parseModifiers();
|
const modifiers = parseModifiers(/*permitInvalidConstAsModifier*/ true);
|
||||||
|
|
||||||
const accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers);
|
const accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers);
|
||||||
if (accessor) {
|
if (accessor) {
|
||||||
|
|
|
@ -429,13 +429,18 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jsonContent.typings) {
|
if (jsonContent.typings) {
|
||||||
const typingsFile = normalizePath(combinePaths(candidate, jsonContent.typings));
|
if (typeof jsonContent.typings === "string") {
|
||||||
if (traceEnabled) {
|
const typingsFile = normalizePath(combinePaths(candidate, jsonContent.typings));
|
||||||
trace(host, Diagnostics.package_json_has_typings_field_0_that_references_1, jsonContent.typings, typingsFile);
|
if (traceEnabled) {
|
||||||
|
trace(host, Diagnostics.package_json_has_typings_field_0_that_references_1, jsonContent.typings, typingsFile);
|
||||||
|
}
|
||||||
|
const result = loadModuleFromFile(extensions, typingsFile, failedLookupLocation, host, traceEnabled);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const result = loadModuleFromFile(extensions, typingsFile , failedLookupLocation, host, traceEnabled);
|
else if (traceEnabled) {
|
||||||
if (result) {
|
trace(host, Diagnostics.Expected_type_of_typings_field_in_package_json_to_be_string_got_0, typeof jsonContent.typings);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -446,7 +451,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (traceEnabled) {
|
if (traceEnabled) {
|
||||||
trace(host, Diagnostics.package_json_does_not_have_typings_field);
|
trace(host, Diagnostics.File_0_does_not_exist, packageJsonPath);
|
||||||
}
|
}
|
||||||
// record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results
|
// record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results
|
||||||
failedLookupLocation.push(packageJsonPath);
|
failedLookupLocation.push(packageJsonPath);
|
||||||
|
|
13
src/lib/es6.d.ts
vendored
13
src/lib/es6.d.ts
vendored
|
@ -1224,7 +1224,7 @@ declare namespace Reflect {
|
||||||
function isExtensible(target: any): boolean;
|
function isExtensible(target: any): boolean;
|
||||||
function ownKeys(target: any): Array<PropertyKey>;
|
function ownKeys(target: any): Array<PropertyKey>;
|
||||||
function preventExtensions(target: any): boolean;
|
function preventExtensions(target: any): boolean;
|
||||||
function set(target: any, propertyKey: PropertyKey, value: any, receiver? :any): boolean;
|
function set(target: any, propertyKey: PropertyKey, value: any, receiver?: any): boolean;
|
||||||
function setPrototypeOf(target: any, proto: any): boolean;
|
function setPrototypeOf(target: any, proto: any): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1272,7 +1272,16 @@ interface PromiseConstructor {
|
||||||
* @param values An array of Promises.
|
* @param values An array of Promises.
|
||||||
* @returns A new Promise.
|
* @returns A new Promise.
|
||||||
*/
|
*/
|
||||||
all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>;
|
all<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
|
||||||
|
all<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
|
||||||
|
all<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>]): Promise<[T1, T2, T3, T4]>;
|
||||||
|
all<T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>;
|
||||||
|
all<T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>;
|
||||||
|
all<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>;
|
||||||
|
all<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
|
||||||
|
all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
|
||||||
|
all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
|
||||||
|
all<TAll>(values: Iterable<TAll | PromiseLike<TAll>>): Promise<TAll[]>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
|
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
|
||||||
|
|
|
@ -461,6 +461,7 @@ namespace ts.formatting {
|
||||||
case SyntaxKind.ParenthesizedType:
|
case SyntaxKind.ParenthesizedType:
|
||||||
case SyntaxKind.TaggedTemplateExpression:
|
case SyntaxKind.TaggedTemplateExpression:
|
||||||
case SyntaxKind.AwaitExpression:
|
case SyntaxKind.AwaitExpression:
|
||||||
|
case SyntaxKind.NamedImports:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
23
tests/baselines/reference/ClassDeclaration26.errors.txt
Normal file
23
tests/baselines/reference/ClassDeclaration26.errors.txt
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
tests/cases/compiler/ClassDeclaration26.ts(2,22): error TS1005: ';' expected.
|
||||||
|
tests/cases/compiler/ClassDeclaration26.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
|
||||||
|
tests/cases/compiler/ClassDeclaration26.ts(4,20): error TS1005: '=' expected.
|
||||||
|
tests/cases/compiler/ClassDeclaration26.ts(4,23): error TS1005: '=>' expected.
|
||||||
|
tests/cases/compiler/ClassDeclaration26.ts(5,1): error TS1128: Declaration or statement expected.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/compiler/ClassDeclaration26.ts (5 errors) ====
|
||||||
|
class C {
|
||||||
|
public const var export foo = 10;
|
||||||
|
~~~~~~
|
||||||
|
!!! error TS1005: ';' expected.
|
||||||
|
|
||||||
|
var constructor() { }
|
||||||
|
~~~
|
||||||
|
!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
|
||||||
|
~
|
||||||
|
!!! error TS1005: '=' expected.
|
||||||
|
~
|
||||||
|
!!! error TS1005: '=>' expected.
|
||||||
|
}
|
||||||
|
~
|
||||||
|
!!! error TS1128: Declaration or statement expected.
|
15
tests/baselines/reference/ClassDeclaration26.js
Normal file
15
tests/baselines/reference/ClassDeclaration26.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
//// [ClassDeclaration26.ts]
|
||||||
|
class C {
|
||||||
|
public const var export foo = 10;
|
||||||
|
|
||||||
|
var constructor() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
//// [ClassDeclaration26.js]
|
||||||
|
var C = (function () {
|
||||||
|
function C() {
|
||||||
|
this.foo = 10;
|
||||||
|
}
|
||||||
|
return C;
|
||||||
|
})();
|
||||||
|
var constructor = function () { };
|
|
@ -0,0 +1,9 @@
|
||||||
|
tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration.ts(2,3): error TS1248: A class member cannot have the 'const' keyword.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration.ts (1 errors) ====
|
||||||
|
class AtomicNumbers {
|
||||||
|
static const H = 1;
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
!!! error TS1248: A class member cannot have the 'const' keyword.
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
//// [ClassDeclarationWithInvalidConstOnPropertyDeclaration.ts]
|
||||||
|
class AtomicNumbers {
|
||||||
|
static const H = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//// [ClassDeclarationWithInvalidConstOnPropertyDeclaration.js]
|
||||||
|
var AtomicNumbers = (function () {
|
||||||
|
function AtomicNumbers() {
|
||||||
|
}
|
||||||
|
AtomicNumbers.H = 1;
|
||||||
|
return AtomicNumbers;
|
||||||
|
})();
|
|
@ -0,0 +1,13 @@
|
||||||
|
//// [ClassDeclarationWithInvalidConstOnPropertyDeclaration2.ts]
|
||||||
|
class C {
|
||||||
|
const
|
||||||
|
x = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
//// [ClassDeclarationWithInvalidConstOnPropertyDeclaration2.js]
|
||||||
|
var C = (function () {
|
||||||
|
function C() {
|
||||||
|
this.x = 10;
|
||||||
|
}
|
||||||
|
return C;
|
||||||
|
})();
|
|
@ -0,0 +1,10 @@
|
||||||
|
=== tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration2.ts ===
|
||||||
|
class C {
|
||||||
|
>C : Symbol(C, Decl(ClassDeclarationWithInvalidConstOnPropertyDeclaration2.ts, 0, 0))
|
||||||
|
|
||||||
|
const
|
||||||
|
>const : Symbol(const, Decl(ClassDeclarationWithInvalidConstOnPropertyDeclaration2.ts, 0, 9))
|
||||||
|
|
||||||
|
x = 10;
|
||||||
|
>x : Symbol(x, Decl(ClassDeclarationWithInvalidConstOnPropertyDeclaration2.ts, 1, 9))
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
=== tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration2.ts ===
|
||||||
|
class C {
|
||||||
|
>C : C
|
||||||
|
|
||||||
|
const
|
||||||
|
>const : any
|
||||||
|
|
||||||
|
x = 10;
|
||||||
|
>x : number
|
||||||
|
>10 : number
|
||||||
|
}
|
14
tests/baselines/reference/recursiveUnionTypeInference.js
Normal file
14
tests/baselines/reference/recursiveUnionTypeInference.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
//// [recursiveUnionTypeInference.ts]
|
||||||
|
interface Foo<T> {
|
||||||
|
x: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bar<T>(x: Foo<T> | string): T {
|
||||||
|
return bar(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//// [recursiveUnionTypeInference.js]
|
||||||
|
function bar(x) {
|
||||||
|
return bar(x);
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
=== tests/cases/compiler/recursiveUnionTypeInference.ts ===
|
||||||
|
interface Foo<T> {
|
||||||
|
>Foo : Symbol(Foo, Decl(recursiveUnionTypeInference.ts, 0, 0))
|
||||||
|
>T : Symbol(T, Decl(recursiveUnionTypeInference.ts, 0, 14))
|
||||||
|
|
||||||
|
x: T;
|
||||||
|
>x : Symbol(x, Decl(recursiveUnionTypeInference.ts, 0, 18))
|
||||||
|
>T : Symbol(T, Decl(recursiveUnionTypeInference.ts, 0, 14))
|
||||||
|
}
|
||||||
|
|
||||||
|
function bar<T>(x: Foo<T> | string): T {
|
||||||
|
>bar : Symbol(bar, Decl(recursiveUnionTypeInference.ts, 2, 1))
|
||||||
|
>T : Symbol(T, Decl(recursiveUnionTypeInference.ts, 4, 13))
|
||||||
|
>x : Symbol(x, Decl(recursiveUnionTypeInference.ts, 4, 16))
|
||||||
|
>Foo : Symbol(Foo, Decl(recursiveUnionTypeInference.ts, 0, 0))
|
||||||
|
>T : Symbol(T, Decl(recursiveUnionTypeInference.ts, 4, 13))
|
||||||
|
>T : Symbol(T, Decl(recursiveUnionTypeInference.ts, 4, 13))
|
||||||
|
|
||||||
|
return bar(x);
|
||||||
|
>bar : Symbol(bar, Decl(recursiveUnionTypeInference.ts, 2, 1))
|
||||||
|
>x : Symbol(x, Decl(recursiveUnionTypeInference.ts, 4, 16))
|
||||||
|
}
|
||||||
|
|
24
tests/baselines/reference/recursiveUnionTypeInference.types
Normal file
24
tests/baselines/reference/recursiveUnionTypeInference.types
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
=== tests/cases/compiler/recursiveUnionTypeInference.ts ===
|
||||||
|
interface Foo<T> {
|
||||||
|
>Foo : Foo<T>
|
||||||
|
>T : T
|
||||||
|
|
||||||
|
x: T;
|
||||||
|
>x : T
|
||||||
|
>T : T
|
||||||
|
}
|
||||||
|
|
||||||
|
function bar<T>(x: Foo<T> | string): T {
|
||||||
|
>bar : <T>(x: Foo<T> | string) => T
|
||||||
|
>T : T
|
||||||
|
>x : Foo<T> | string
|
||||||
|
>Foo : Foo<T>
|
||||||
|
>T : T
|
||||||
|
>T : T
|
||||||
|
|
||||||
|
return bar(x);
|
||||||
|
>bar(x) : T
|
||||||
|
>bar : <T>(x: Foo<T> | string) => T
|
||||||
|
>x : Foo<T> | string
|
||||||
|
}
|
||||||
|
|
5
tests/cases/compiler/ClassDeclaration26.ts
Normal file
5
tests/cases/compiler/ClassDeclaration26.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class C {
|
||||||
|
public const var export foo = 10;
|
||||||
|
|
||||||
|
var constructor() { }
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
class AtomicNumbers {
|
||||||
|
static const H = 1;
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
class C {
|
||||||
|
const
|
||||||
|
x = 10;
|
||||||
|
}
|
7
tests/cases/compiler/recursiveUnionTypeInference.ts
Normal file
7
tests/cases/compiler/recursiveUnionTypeInference.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
interface Foo<T> {
|
||||||
|
x: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bar<T>(x: Foo<T> | string): T {
|
||||||
|
return bar(x);
|
||||||
|
}
|
|
@ -1,12 +1,14 @@
|
||||||
/// <reference path='fourslash.ts' />
|
/// <reference path='fourslash.ts' />
|
||||||
|
|
||||||
////export const class C {
|
////export const class C {
|
||||||
//// private static c/*1*/onst foo;
|
//// private static c/*1*/onst f/*2*/oo;
|
||||||
//// constructor(public con/*2*/st foo) {
|
//// constructor(public con/*3*/st foo) {
|
||||||
//// }
|
//// }
|
||||||
////}
|
////}
|
||||||
|
|
||||||
goTo.marker("1");
|
goTo.marker("1");
|
||||||
verify.occurrencesAtPositionCount(1);
|
verify.occurrencesAtPositionCount(0);
|
||||||
goTo.marker("2");
|
goTo.marker("2");
|
||||||
|
verify.occurrencesAtPositionCount(1);
|
||||||
|
goTo.marker("3");
|
||||||
verify.occurrencesAtPositionCount(0);
|
verify.occurrencesAtPositionCount(0);
|
12
tests/cases/fourslash/smartIndentNamedImport.ts
Normal file
12
tests/cases/fourslash/smartIndentNamedImport.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/// <reference path='fourslash.ts' />
|
||||||
|
|
||||||
|
////import {/*0*/
|
||||||
|
//// numbers as bn,/*1*/
|
||||||
|
//// list/*2*/
|
||||||
|
////} from '@bykov/basics';/*3*/
|
||||||
|
|
||||||
|
format.document();
|
||||||
|
goTo.marker("0"); verify.currentLineContentIs("import {");
|
||||||
|
goTo.marker("1"); verify.currentLineContentIs(" numbers as bn,");
|
||||||
|
goTo.marker("2"); verify.currentLineContentIs(" list");
|
||||||
|
goTo.marker("3"); verify.currentLineContentIs("} from '@bykov/basics';");
|
|
@ -99,13 +99,34 @@ module ts {
|
||||||
assert.equal(resolution.failedLookupLocations.length, supportedTypeScriptExtensions.length);
|
assert.equal(resolution.failedLookupLocations.length, supportedTypeScriptExtensions.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
it("module name as directory - load from typings", () => {
|
it("module name as directory - load from 'typings'", () => {
|
||||||
testLoadingFromPackageJson("/a/b/c/d.ts", "/a/b/c/bar/package.json", "c/d/e.d.ts", "/a/b/c/bar/c/d/e.d.ts", "./bar");
|
testLoadingFromPackageJson("/a/b/c/d.ts", "/a/b/c/bar/package.json", "c/d/e.d.ts", "/a/b/c/bar/c/d/e.d.ts", "./bar");
|
||||||
testLoadingFromPackageJson("/a/b/c/d.ts", "/a/bar/package.json", "e.d.ts", "/a/bar/e.d.ts", "../../bar");
|
testLoadingFromPackageJson("/a/b/c/d.ts", "/a/bar/package.json", "e.d.ts", "/a/bar/e.d.ts", "../../bar");
|
||||||
testLoadingFromPackageJson("/a/b/c/d.ts", "/bar/package.json", "e.d.ts", "/bar/e.d.ts", "/bar");
|
testLoadingFromPackageJson("/a/b/c/d.ts", "/bar/package.json", "e.d.ts", "/bar/e.d.ts", "/bar");
|
||||||
testLoadingFromPackageJson("c:/a/b/c/d.ts", "c:/bar/package.json", "e.d.ts", "c:/bar/e.d.ts", "c:/bar");
|
testLoadingFromPackageJson("c:/a/b/c/d.ts", "c:/bar/package.json", "e.d.ts", "c:/bar/e.d.ts", "c:/bar");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function testTypingsIgnored(typings: any): void {
|
||||||
|
let containingFile = { name: "/a/b.ts" };
|
||||||
|
let packageJson = { name: "/node_modules/b/package.json", content: JSON.stringify({ "typings": typings }) };
|
||||||
|
let moduleFile = { name: "/a/b.d.ts" };
|
||||||
|
|
||||||
|
let indexPath = "/node_modules/b/index.d.ts";
|
||||||
|
let indexFile = { name: indexPath }
|
||||||
|
|
||||||
|
let resolution = nodeModuleNameResolver("b", containingFile.name, {}, createModuleResolutionHost(containingFile, packageJson, moduleFile, indexFile));
|
||||||
|
|
||||||
|
assert.equal(resolution.resolvedModule.resolvedFileName, indexPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
it("module name as directory - handle invalid 'typings'", () => {
|
||||||
|
testTypingsIgnored(["a", "b"]);
|
||||||
|
testTypingsIgnored({ "a": "b" });
|
||||||
|
testTypingsIgnored(true);
|
||||||
|
testTypingsIgnored(null);
|
||||||
|
testTypingsIgnored(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
it("module name as directory - load index.d.ts", () => {
|
it("module name as directory - load index.d.ts", () => {
|
||||||
let containingFile = { name: "/a/b/c.ts" };
|
let containingFile = { name: "/a/b/c.ts" };
|
||||||
let packageJson = { name: "/a/b/foo/package.json", content: JSON.stringify({ main: "/c/d" }) };
|
let packageJson = { name: "/a/b/foo/package.json", content: JSON.stringify({ main: "/c/d" }) };
|
||||||
|
|
Loading…
Reference in a new issue