Merge branch 'master' of https://github.com/SaschaNaz/TypeScript into formatDestruct

This commit is contained in:
Kagami Sascha Rosylight 2016-12-22 11:04:06 +09:00
commit f65c865957
73 changed files with 1905 additions and 112 deletions

View file

@ -636,11 +636,24 @@ namespace ts {
if (declaration.pos <= usage.pos) {
// declaration is before usage
// still might be illegal if usage is in the initializer of the variable declaration
return declaration.kind !== SyntaxKind.VariableDeclaration ||
!isImmediatelyUsedInInitializerOfBlockScopedVariable(<VariableDeclaration>declaration, usage);
if (declaration.kind === SyntaxKind.BindingElement) {
// still might be illegal if declaration and usage are both binding elements (eg var [a = b, b = b] = [1, 2])
const errorBindingElement = getAncestor(usage, SyntaxKind.BindingElement) as BindingElement;
if (errorBindingElement) {
return getAncestorBindingPattern(errorBindingElement) !== getAncestorBindingPattern(declaration) ||
declaration.pos < errorBindingElement.pos;
}
// or it might be illegal if usage happens before parent variable is declared (eg var [a] = a)
return isBlockScopedNameDeclaredBeforeUse(getAncestor(declaration, SyntaxKind.VariableDeclaration) as Declaration, usage);
}
else if (declaration.kind === SyntaxKind.VariableDeclaration) {
// still might be illegal if usage is in the initializer of the variable declaration (eg var a = a)
return !isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration as VariableDeclaration, usage);
}
return true;
}
// declaration is after usage
// can be legal if usage is deferred (i.e. inside function or in initializer of instance property)
const container = getEnclosingBlockScopeContainer(declaration);
@ -697,6 +710,16 @@ namespace ts {
}
return false;
}
function getAncestorBindingPattern(node: Node): BindingPattern {
while (node) {
if (isBindingPattern(node)) {
return node;
}
node = node.parent;
}
return undefined;
}
}
// Resolve a given name for a given meaning at a given location. An error is reported if the name was not found and
@ -1063,7 +1086,7 @@ namespace ts {
Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
if (!isInAmbientContext(declaration) && !isBlockScopedNameDeclaredBeforeUse(<Declaration>getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) {
if (!isInAmbientContext(declaration) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(declaration.name));
}
}
@ -6645,7 +6668,7 @@ namespace ts {
// Starting with the parent of the symbol's declaration, check if the mapper maps any of
// the type parameters introduced by enclosing declarations. We just pick the first
// declaration since multiple declarations will all have the same parent anyway.
let node = symbol.declarations[0].parent;
let node: Node = symbol.declarations[0];
while (node) {
switch (node.kind) {
case SyntaxKind.FunctionType:
@ -6665,7 +6688,7 @@ namespace ts {
case SyntaxKind.ClassExpression:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.TypeAliasDeclaration:
const declaration = <DeclarationWithTypeParameters>node;
const declaration = node as DeclarationWithTypeParameters;
if (declaration.typeParameters) {
for (const d of declaration.typeParameters) {
if (contains(mappedTypes, getDeclaredTypeOfTypeParameter(getSymbolOfNode(d)))) {
@ -6680,6 +6703,14 @@ namespace ts {
}
}
break;
case SyntaxKind.JSDocFunctionType:
const func = node as JSDocFunctionType;
for (const p of func.parameters) {
if (contains(mappedTypes, getTypeOfNode(p))) {
return true;
}
}
break;
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.SourceFile:
return false;
@ -16891,7 +16922,7 @@ namespace ts {
if (!local.isReferenced && !local.exportSymbol) {
for (const declaration of local.declarations) {
if (!isAmbientModule(declaration)) {
error(declaration.name, Diagnostics._0_is_declared_but_never_used, local.name);
errorUnusedLocal(declaration.name, local.name);
}
}
}
@ -17149,7 +17180,8 @@ namespace ts {
// so we need to do a bit of extra work to check if reference is legal
const enclosingContainer = getEnclosingBlockScopeContainer(symbol.valueDeclaration);
if (enclosingContainer === func) {
if (symbol.valueDeclaration.kind === SyntaxKind.Parameter) {
if (symbol.valueDeclaration.kind === SyntaxKind.Parameter ||
symbol.valueDeclaration.kind === SyntaxKind.BindingElement) {
// it is ok to reference parameter in initializer if either
// - parameter is located strictly on the left of current parameter declaration
if (symbol.valueDeclaration.pos < node.pos) {
@ -21849,11 +21881,17 @@ namespace ts {
function checkGrammarNumericLiteral(node: NumericLiteral): boolean {
// Grammar checking
if (node.isOctalLiteral) {
let diagnosticMessage: DiagnosticMessage | undefined;
if (languageVersion >= ScriptTarget.ES5) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0, node.text);
diagnosticMessage = Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0;
}
if (isChildOfLiteralType(node)) {
return grammarErrorOnNode(node, Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0, node.text);
else if (isChildOfLiteralType(node)) {
diagnosticMessage = Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0;
}
if (diagnosticMessage) {
const withMinus = isPrefixUnaryExpression(node.parent) && node.parent.operator === SyntaxKind.MinusToken;
const literal = `${withMinus ? "-" : ""}0o${node.text}`;
return grammarErrorOnNode(withMinus ? node.parent : node, diagnosticMessage, literal);
}
}
}

View file

@ -227,7 +227,7 @@
"category": "Error",
"code": 1084
},
"Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o{0}'.": {
"Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '{0}'.": {
"category": "Error",
"code": 1085
},
@ -2952,7 +2952,7 @@
"Resolution for module '{0}' was found in cache": {
"category": "Message",
"code": 6147
},
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
@ -3243,7 +3243,7 @@
"category": "Message",
"code": 90015
},
"Octal literal types must use ES2015 syntax. Use the syntax '0o{0}'.": {
"Octal literal types must use ES2015 syntax. Use the syntax '{0}'.": {
"category": "Error",
"code": 8017
}

View file

@ -149,6 +149,7 @@ namespace ts {
if (host.directoryExists(atTypes)) {
(typeRoots || (typeRoots = [])).push(atTypes);
}
return undefined;
});
return typeRoots;
}
@ -237,7 +238,8 @@ namespace ts {
if (traceEnabled) {
trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup);
}
resolvedFile = resolvedTypeScriptOnly(loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState));
const result = loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState, /*cache*/ undefined);
resolvedFile = resolvedTypeScriptOnly(result && result.value);
if (!resolvedFile && traceEnabled) {
trace(host, Diagnostics.Type_reference_directive_0_was_not_resolved, typeReferenceDirectiveName);
}
@ -293,24 +295,120 @@ namespace ts {
* Cached module resolutions per containing directory.
* This assumes that any module id will have the same resolution for sibling files located in the same folder.
*/
export interface ModuleResolutionCache {
export interface ModuleResolutionCache extends NonRelativeModuleNameResolutionCache {
getOrCreateCacheForDirectory(directoryName: string): Map<ResolvedModuleWithFailedLookupLocations>;
}
export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string) {
const map = createFileMap<Map<ResolvedModuleWithFailedLookupLocations>>();
/**
* Stored map from non-relative module name to a table: directory -> result of module lookup in this directory
* We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive.
*/
export interface NonRelativeModuleNameResolutionCache {
getOrCreateCacheForModuleName(nonRelativeModuleName: string): PerModuleNameCache;
}
return { getOrCreateCacheForDirectory };
export interface PerModuleNameCache {
get(directory: string): ResolvedModuleWithFailedLookupLocations;
set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void;
}
export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): ModuleResolutionCache {
const directoryToModuleNameMap = createFileMap<Map<ResolvedModuleWithFailedLookupLocations>>();
const moduleNameToDirectoryMap = createMap<PerModuleNameCache>();
return { getOrCreateCacheForDirectory, getOrCreateCacheForModuleName };
function getOrCreateCacheForDirectory(directoryName: string) {
const path = toPath(directoryName, currentDirectory, getCanonicalFileName);
let perFolderCache = map.get(path);
let perFolderCache = directoryToModuleNameMap.get(path);
if (!perFolderCache) {
perFolderCache = createMap<ResolvedModuleWithFailedLookupLocations>();
map.set(path, perFolderCache);
directoryToModuleNameMap.set(path, perFolderCache);
}
return perFolderCache;
}
function getOrCreateCacheForModuleName(nonRelativeModuleName: string) {
if (!moduleHasNonRelativeName(nonRelativeModuleName)) {
return undefined;
}
let perModuleNameCache = moduleNameToDirectoryMap[nonRelativeModuleName];
if (!perModuleNameCache) {
moduleNameToDirectoryMap[nonRelativeModuleName] = perModuleNameCache = createPerModuleNameCache();
}
return perModuleNameCache;
}
function createPerModuleNameCache(): PerModuleNameCache {
const directoryPathMap = createFileMap<ResolvedModuleWithFailedLookupLocations>();
return { get, set };
function get(directory: string): ResolvedModuleWithFailedLookupLocations {
return directoryPathMap.get(toPath(directory, currentDirectory, getCanonicalFileName));
}
/**
* At first this function add entry directory -> module resolution result to the table.
* Then it computes the set of parent folders for 'directory' that should have the same module resolution result
* and for every parent folder in set it adds entry: parent -> module resolution. .
* Lets say we first directory name: /a/b/c/d/e and resolution result is: /a/b/bar.ts.
* Set of parent folders that should have the same result will be:
* [
* /a/b/c/d, /a/b/c, /a/b
* ]
* this means that request for module resolution from file in any of these folder will be immediately found in cache.
*/
function set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void {
const path = toPath(directory, currentDirectory, getCanonicalFileName);
// if entry is already in cache do nothing
if (directoryPathMap.contains(path)) {
return;
}
directoryPathMap.set(path, result);
const resolvedFileName = result.resolvedModule && result.resolvedModule.resolvedFileName;
// find common prefix between directory and resolved file name
// this common prefix should be the shorted path that has the same resolution
// directory: /a/b/c/d/e
// resolvedFileName: /a/b/foo.d.ts
const commonPrefix = getCommonPrefix(path, resolvedFileName);
let current = path;
while (true) {
const parent = getDirectoryPath(current);
if (parent === current || directoryPathMap.contains(parent)) {
break;
}
directoryPathMap.set(parent, result);
current = parent;
if (current == commonPrefix) {
break;
}
}
}
function getCommonPrefix(directory: Path, resolution: string) {
if (resolution === undefined) {
return undefined;
}
const resolutionDirectory = toPath(getDirectoryPath(resolution), currentDirectory, getCanonicalFileName);
// find first position where directory and resolution differs
let i = 0;
while (i < Math.min(directory.length, resolutionDirectory.length) && directory.charCodeAt(i) === resolutionDirectory.charCodeAt(i)) {
i++;
}
// find last directory separator before position i
const sep = directory.lastIndexOf(directorySeparator, i);
if (sep < 0) {
return undefined;
}
return directory.substr(0, sep);
}
}
}
export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations {
@ -318,7 +416,8 @@ namespace ts {
if (traceEnabled) {
trace(host, Diagnostics.Resolving_module_0_from_1, moduleName, containingFile);
}
const perFolderCache = cache && cache.getOrCreateCacheForDirectory(getDirectoryPath(containingFile));
const containingDirectory = getDirectoryPath(containingFile);
let perFolderCache = cache && cache.getOrCreateCacheForDirectory(containingDirectory);
let result = perFolderCache && perFolderCache[moduleName];
if (result) {
@ -342,15 +441,20 @@ namespace ts {
switch (moduleResolution) {
case ModuleResolutionKind.NodeJs:
result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host);
result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache);
break;
case ModuleResolutionKind.Classic:
result = classicNameResolver(moduleName, containingFile, compilerOptions, host);
result = classicNameResolver(moduleName, containingFile, compilerOptions, host, cache);
break;
}
if (perFolderCache) {
perFolderCache[moduleName] = result;
// put result in per-module name cache
const perModuleNameCache = cache.getOrCreateCacheForModuleName(moduleName);
if (perModuleNameCache) {
perModuleNameCache.set(containingDirectory, result);
}
}
}
@ -574,7 +678,7 @@ namespace ts {
}
}
export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations {
const containingDirectory = getDirectoryPath(containingFile);
const traceEnabled = isTraceEnabled(compilerOptions, host);
@ -582,30 +686,30 @@ namespace ts {
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
const result = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
if (result) {
const { resolved, isExternalLibraryImport } = result;
if (result && result.value) {
const { resolved, isExternalLibraryImport } = result.value;
return createResolvedModuleWithFailedLookupLocations(resolved, isExternalLibraryImport, failedLookupLocations);
}
return { resolvedModule: undefined, failedLookupLocations };
function tryResolve(extensions: Extensions): { resolved: Resolved, isExternalLibraryImport: boolean } | undefined {
function tryResolve(extensions: Extensions): SearchResult<{ resolved: Resolved, isExternalLibraryImport: boolean }> {
const resolved = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, nodeLoadModuleByRelativeName, failedLookupLocations, state);
if (resolved) {
return { resolved, isExternalLibraryImport: false };
return toSearchResult({ resolved, isExternalLibraryImport: false });
}
if (moduleHasNonRelativeName(moduleName)) {
if (traceEnabled) {
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName);
}
const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state);
const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state, cache);
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.
return resolved && { resolved: { path: realpath(resolved.path, host, traceEnabled), extension: resolved.extension }, isExternalLibraryImport: true };
return resolved && { value: resolved.value && { resolved: { path: realpath(resolved.value.path, host, traceEnabled), extension: resolved.value.extension }, isExternalLibraryImport: true } };
}
else {
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
const resolved = nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state);
return resolved && { resolved, isExternalLibraryImport: false };
return resolved && toSearchResult({ resolved, isExternalLibraryImport: false });
}
}
}
@ -775,18 +879,23 @@ namespace ts {
loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state);
}
function loadModuleFromNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
return loadModuleFromNodeModulesWorker(extensions, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ false);
function loadModuleFromNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState, cache: NonRelativeModuleNameResolutionCache): SearchResult<Resolved> {
return loadModuleFromNodeModulesWorker(extensions, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ false, cache);
}
function loadModuleFromNodeModulesAtTypes(moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
function loadModuleFromNodeModulesAtTypes(moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): SearchResult<Resolved> {
// Extensions parameter here doesn't actually matter, because typesOnly ensures we're just doing @types lookup, which is always DtsOnly.
return loadModuleFromNodeModulesWorker(Extensions.DtsOnly, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ true);
return loadModuleFromNodeModulesWorker(Extensions.DtsOnly, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ true, /*cache*/ undefined);
}
function loadModuleFromNodeModulesWorker(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState, typesOnly: boolean): Resolved | undefined {
function loadModuleFromNodeModulesWorker(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState, typesOnly: boolean, cache: NonRelativeModuleNameResolutionCache): SearchResult<Resolved> {
const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName);
return forEachAncestorDirectory(normalizeSlashes(directory), ancestorDirectory => {
if (getBaseFileName(ancestorDirectory) !== "node_modules") {
return loadModuleFromNodeModulesOneLevel(extensions, moduleName, ancestorDirectory, failedLookupLocations, state, typesOnly);
const resolutionFromCache = tryFindNonRelativeModuleNameInCache(perModuleNameCache, moduleName, ancestorDirectory, state.traceEnabled, state.host);
if (resolutionFromCache) {
return resolutionFromCache;
}
return toSearchResult(loadModuleFromNodeModulesOneLevel(extensions, moduleName, ancestorDirectory, failedLookupLocations, state, typesOnly));
}
});
}
@ -802,26 +911,41 @@ namespace ts {
}
}
export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
function tryFindNonRelativeModuleNameInCache(cache: PerModuleNameCache | undefined, moduleName: string, containingDirectory: string, traceEnabled: boolean, host: ModuleResolutionHost): SearchResult<Resolved> {
const result = cache && cache.get(containingDirectory);
if (result) {
if (traceEnabled) {
trace(host, Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName)
}
return { value: result.resolvedModule && { path: result.resolvedModule.resolvedFileName, extension: result.resolvedModule.extension } };
}
}
export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache): ResolvedModuleWithFailedLookupLocations {
const traceEnabled = isTraceEnabled(compilerOptions, host);
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
const failedLookupLocations: string[] = [];
const containingDirectory = getDirectoryPath(containingFile);
const resolved = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ false, failedLookupLocations);
return createResolvedModuleWithFailedLookupLocations(resolved && resolved.value, /*isExternalLibraryImport*/ false, failedLookupLocations);
function tryResolve(extensions: Extensions): Resolved | undefined {
function tryResolve(extensions: Extensions): SearchResult<Resolved> {
const resolvedUsingSettings = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loadModuleFromFile, failedLookupLocations, state);
if (resolvedUsingSettings) {
return resolvedUsingSettings;
return { value: resolvedUsingSettings };
}
const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName);
if (moduleHasNonRelativeName(moduleName)) {
// Climb up parent directories looking for a module.
const resolved = forEachAncestorDirectory(containingDirectory, directory => {
const resolutionFromCache = tryFindNonRelativeModuleNameInCache(perModuleNameCache, moduleName, directory, traceEnabled, host);
if (resolutionFromCache) {
return resolutionFromCache;
}
const searchName = normalizePath(combinePaths(directory, moduleName));
return loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state);
return toSearchResult(loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state));
});
if (resolved) {
return resolved;
@ -833,7 +957,7 @@ namespace ts {
}
else {
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
return loadModuleFromFile(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state);
return toSearchResult(loadModuleFromFile(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state));
}
}
}
@ -854,8 +978,28 @@ namespace ts {
return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ true, failedLookupLocations);
}
/**
* Represents result of search. Normally when searching among several alternatives we treat value `undefined` as indicator
* that search fails and we should try another option.
* However this does not allow us to represent final result that should be used instead of further searching (i.e. a final result that was found in cache).
* SearchResult is used to deal with this issue, its values represents following outcomes:
* - undefined - not found, continue searching
* - { value: undefined } - not found - stop searching
* - { value: <some-value> } - found - stop searching
*/
type SearchResult<T> = { value: T | undefined } | undefined;
/**
* Wraps value to SearchResult.
* @returns undefined if value is undefined or { value } otherwise
*/
function toSearchResult<T>(value: T | undefined): SearchResult<T> {
return value !== undefined ? { value } : undefined;
}
/** Calls `callback` on `directory` and every ancestor directory it has, returning the first defined result. */
function forEachAncestorDirectory<T>(directory: string, callback: (directory: string) => T | undefined): T | undefined {
function forEachAncestorDirectory<T>(directory: string, callback: (directory: string) => SearchResult<T>): SearchResult<T> {
while (true) {
const result = callback(directory);
if (result !== undefined) {

View file

@ -1555,12 +1555,15 @@ namespace ts {
return false;
}
type SerializedEntityNameAsExpression = Identifier | BinaryExpression | PropertyAccessExpression;
type SerializedTypeNode = SerializedEntityNameAsExpression | VoidExpression | ConditionalExpression;
/**
* Serializes the type of a node for use with decorator type metadata.
*
* @param node The node that should have its type serialized.
*/
function serializeTypeOfNode(node: Node): Expression {
function serializeTypeOfNode(node: Node): SerializedTypeNode {
switch (node.kind) {
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.Parameter:
@ -1582,7 +1585,7 @@ namespace ts {
*
* @param node The node that should have its parameter types serialized.
*/
function serializeParameterTypesOfNode(node: Node, container: ClassLikeDeclaration): Expression {
function serializeParameterTypesOfNode(node: Node, container: ClassLikeDeclaration): ArrayLiteralExpression {
const valueDeclaration =
isClassLike(node)
? getFirstConstructorWithBody(node)
@ -1590,7 +1593,7 @@ namespace ts {
? node
: undefined;
const expressions: Expression[] = [];
const expressions: SerializedTypeNode[] = [];
if (valueDeclaration) {
const parameters = getParametersOfDecoratedDeclaration(valueDeclaration, container);
const numParameters = parameters.length;
@ -1626,7 +1629,7 @@ namespace ts {
*
* @param node The node that should have its return type serialized.
*/
function serializeReturnTypeOfNode(node: Node): Expression {
function serializeReturnTypeOfNode(node: Node): SerializedTypeNode {
if (isFunctionLike(node) && node.type) {
return serializeTypeNode(node.type);
}
@ -1655,13 +1658,16 @@ namespace ts {
*
* @param node The type node to serialize.
*/
function serializeTypeNode(node: TypeNode): Expression {
function serializeTypeNode(node: TypeNode): SerializedTypeNode {
if (node === undefined) {
return createIdentifier("Object");
}
switch (node.kind) {
case SyntaxKind.VoidKeyword:
case SyntaxKind.UndefinedKeyword:
case SyntaxKind.NullKeyword:
case SyntaxKind.NeverKeyword:
return createVoidZero();
case SyntaxKind.ParenthesizedType:
@ -1713,37 +1719,8 @@ namespace ts {
case SyntaxKind.IntersectionType:
case SyntaxKind.UnionType:
{
const unionOrIntersection = <UnionOrIntersectionTypeNode>node;
let serializedUnion: Identifier;
for (const typeNode of unionOrIntersection.types) {
const serializedIndividual = serializeTypeNode(typeNode) as Identifier;
// Non identifier
if (serializedIndividual.kind !== SyntaxKind.Identifier) {
serializedUnion = undefined;
break;
}
return serializeUnionOrIntersectionType(<UnionOrIntersectionTypeNode>node);
// One of the individual is global object, return immediately
if (serializedIndividual.text === "Object") {
return serializedIndividual;
}
// Different types
if (serializedUnion && serializedUnion.text !== serializedIndividual.text) {
serializedUnion = undefined;
break;
}
serializedUnion = serializedIndividual;
}
// If we were able to find common type
if (serializedUnion) {
return serializedUnion;
}
}
// Fallthrough
case SyntaxKind.TypeQuery:
case SyntaxKind.TypeOperator:
case SyntaxKind.IndexedAccessType:
@ -1761,13 +1738,48 @@ namespace ts {
return createIdentifier("Object");
}
function serializeUnionOrIntersectionType(node: UnionOrIntersectionTypeNode): SerializedTypeNode {
let serializedUnion: SerializedTypeNode;
for (const typeNode of node.types) {
const serializedIndividual = serializeTypeNode(typeNode);
if (isVoidExpression(serializedIndividual)) {
// If we dont have any other type already set, set the initial type
if (!serializedUnion) {
serializedUnion = serializedIndividual;
}
}
else if (isIdentifier(serializedIndividual) && serializedIndividual.text === "Object") {
// One of the individual is global object, return immediately
return serializedIndividual;
}
// If there exists union that is not void 0 expression, check if the the common type is identifier.
// anything more complex and we will just default to Object
else if (serializedUnion && !isVoidExpression(serializedUnion)) {
// Different types
if (!isIdentifier(serializedUnion) ||
!isIdentifier(serializedIndividual) ||
serializedUnion.text !== serializedIndividual.text) {
return createIdentifier("Object");
}
}
else {
// Initialize the union type
serializedUnion = serializedIndividual;
}
}
// If we were able to find common type, use it
return serializedUnion;
}
/**
* Serializes a TypeReferenceNode to an appropriate JS constructor value for use with
* decorator type metadata.
*
* @param node The type reference node.
*/
function serializeTypeReferenceNode(node: TypeReferenceNode) {
function serializeTypeReferenceNode(node: TypeReferenceNode): SerializedTypeNode {
switch (resolver.getTypeReferenceSerializationKind(node.typeName, currentScope)) {
case TypeReferenceSerializationKind.Unknown:
const serialized = serializeEntityNameAsExpression(node.typeName, /*useFallback*/ true);
@ -1822,7 +1834,7 @@ namespace ts {
* @param useFallback A value indicating whether to use logical operators to test for the
* entity name at runtime.
*/
function serializeEntityNameAsExpression(node: EntityName, useFallback: boolean): Expression {
function serializeEntityNameAsExpression(node: EntityName, useFallback: boolean): SerializedEntityNameAsExpression {
switch (node.kind) {
case SyntaxKind.Identifier:
// Create a clone of the name with a new parent, and treat it as if it were
@ -1855,8 +1867,8 @@ namespace ts {
* @param useFallback A value indicating whether to use logical operators to test for the
* qualified name at runtime.
*/
function serializeQualifiedNameAsExpression(node: QualifiedName, useFallback: boolean): Expression {
let left: Expression;
function serializeQualifiedNameAsExpression(node: QualifiedName, useFallback: boolean): PropertyAccessExpression {
let left: SerializedEntityNameAsExpression;
if (node.left.kind === SyntaxKind.Identifier) {
left = serializeEntityNameAsExpression(node.left, useFallback);
}
@ -1881,7 +1893,7 @@ namespace ts {
* Gets an expression that points to the global "Symbol" constructor at runtime if it is
* available.
*/
function getGlobalSymbolNameWithFallback(): Expression {
function getGlobalSymbolNameWithFallback(): ConditionalExpression {
return createConditional(
createTypeCheck(createIdentifier("Symbol"), "function"),
createIdentifier("Symbol"),
@ -2719,7 +2731,7 @@ namespace ts {
let blockLocation: TextRange;
const body = node.body;
if (body.kind === SyntaxKind.ModuleBlock) {
addRange(statements, visitNodes((<ModuleBlock>body).statements, namespaceElementVisitor, isStatement));
saveStateAndInvoke(body, body => addRange(statements, visitNodes((<ModuleBlock>body).statements, namespaceElementVisitor, isStatement)));
statementsLocation = (<ModuleBlock>body).statements;
blockLocation = body;
}

View file

@ -742,6 +742,10 @@ namespace ts {
return false;
}
export function isPrefixUnaryExpression(node: Node): node is PrefixUnaryExpression {
return node.kind === SyntaxKind.PrefixUnaryExpression;
}
// Warning: This has the same semantics as the forEach family of functions,
// in that traversal terminates in the event that 'visitor' supplies a truthy value.
export function forEachReturnStatement<T>(body: Block, visitor: (stmt: ReturnStatement) => T): T {
@ -3591,6 +3595,10 @@ namespace ts {
return node.kind === SyntaxKind.Identifier;
}
export function isVoidExpression(node: Node): node is VoidExpression {
return node.kind === SyntaxKind.VoidExpression;
}
export function isGeneratedIdentifier(node: Node): node is GeneratedIdentifier {
// Using `>` here catches both `GeneratedIdentifierKind.None` and `undefined`.
return isIdentifier(node) && node.autoGenerateKind > GeneratedIdentifierKind.None;

View file

@ -488,18 +488,32 @@ namespace ts.formatting {
// open and close brace, 'else' and 'while' (in do statement) tokens has indentation of the parent
case SyntaxKind.OpenBraceToken:
case SyntaxKind.CloseBraceToken:
case SyntaxKind.OpenBracketToken:
case SyntaxKind.CloseBracketToken:
case SyntaxKind.OpenParenToken:
case SyntaxKind.CloseParenToken:
case SyntaxKind.ElseKeyword:
case SyntaxKind.WhileKeyword:
case SyntaxKind.AtToken:
return indentation;
default:
// if token line equals to the line of containing node (this is a first token in the node) - use node indentation
return nodeStartLine !== line ? indentation + getEffectiveDelta(delta, container) : indentation;
case SyntaxKind.SlashToken:
case SyntaxKind.GreaterThanToken: {
if (container.kind === SyntaxKind.JsxOpeningElement ||
container.kind === SyntaxKind.JsxClosingElement ||
container.kind === SyntaxKind.JsxSelfClosingElement
) {
return indentation;
}
break;
}
case SyntaxKind.OpenBracketToken:
case SyntaxKind.CloseBracketToken: {
if (container.kind !== SyntaxKind.MappedType) {
return indentation;
}
break;
}
}
// if token line equals to the line of containing node (this is a first token in the node) - use node indentation
return nodeStartLine !== line ? indentation + getEffectiveDelta(delta, container) : indentation;
},
getIndentation: () => indentation,
getDelta: child => getEffectiveDelta(delta, child),
@ -566,7 +580,7 @@ namespace ts.formatting {
if (tokenInfo.token.end > node.end) {
break;
}
consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation);
consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
}
function processChildNode(
@ -617,7 +631,7 @@ namespace ts.formatting {
break;
}
consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation);
consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation, node);
}
if (!formattingScanner.isOnToken()) {
@ -673,11 +687,11 @@ namespace ts.formatting {
computeIndentation(tokenInfo.token, startLine, Constants.Unknown, parent, parentDynamicIndentation, parentStartLine);
listDynamicIndentation = getDynamicIndentation(parent, parentStartLine, indentation.indentation, indentation.delta);
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation);
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent);
}
else {
// consume any tokens that precede the list as child elements of 'node' using its indentation scope
consumeTokenAndAdvanceScanner(tokenInfo, parent, parentDynamicIndentation);
consumeTokenAndAdvanceScanner(tokenInfo, parent, parentDynamicIndentation, parent);
}
}
}
@ -697,13 +711,13 @@ namespace ts.formatting {
// without this check close paren will be interpreted as list end token for function expression which is wrong
if (tokenInfo.token.kind === listEndToken && rangeContainsRange(parent, tokenInfo.token)) {
// consume list end token
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation);
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent);
}
}
}
}
function consumeTokenAndAdvanceScanner(currentTokenInfo: TokenInfo, parent: Node, dynamicIndentation: DynamicIndentation, container?: Node): void {
function consumeTokenAndAdvanceScanner(currentTokenInfo: TokenInfo, parent: Node, dynamicIndentation: DynamicIndentation, container: Node): void {
Debug.assert(rangeContainsRange(parent, currentTokenInfo.token));
const lastTriviaWasNewLine = formattingScanner.lastTrailingTriviaWasNewLine();

View file

@ -362,7 +362,7 @@ namespace ts.formatting {
this.NoSpaceAfterModuleImport = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.ModuleKeyword, SyntaxKind.RequireKeyword]), SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
// Add a space around certain TypeScript keywords
this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.ReadonlyKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword, SyntaxKind.TypeKeyword, SyntaxKind.FromKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.ReadonlyKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword, SyntaxKind.TypeKeyword, SyntaxKind.FromKeyword, SyntaxKind.KeyOfKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
this.SpaceBeforeCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.ExtendsKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.FromKeyword])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
// Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" {
@ -578,6 +578,8 @@ namespace ts.formatting {
return context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken;
// "in" keyword in for (let x in []) { }
case SyntaxKind.ForInStatement:
// "in" keyword in [P in keyof T]: T[P]
case SyntaxKind.TypeParameter:
return context.currentTokenSpan.kind === SyntaxKind.InKeyword || context.nextTokenSpan.kind === SyntaxKind.InKeyword;
// Technically, "of" is not a binary operator, but format it the same way as "in"
case SyntaxKind.ForOfStatement:
@ -712,11 +714,18 @@ namespace ts.formatting {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.Block:
case SyntaxKind.CatchClause:
case SyntaxKind.ModuleBlock:
case SyntaxKind.SwitchStatement:
return true;
case SyntaxKind.Block: {
const blockParent = context.currentTokenParent.parent;
if (blockParent.kind !== SyntaxKind.ArrowFunction &&
blockParent.kind !== SyntaxKind.FunctionExpression
) {
return true;
}
}
}
return false;
}
@ -836,6 +845,7 @@ namespace ts.formatting {
switch (parent.kind) {
case SyntaxKind.TypeReference:
case SyntaxKind.TypeAssertionExpression:
case SyntaxKind.TypeAliasDeclaration:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.InterfaceDeclaration:

View file

@ -438,6 +438,7 @@ namespace ts.formatting {
case SyntaxKind.ModuleBlock:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.TypeLiteral:
case SyntaxKind.MappedType:
case SyntaxKind.TupleType:
case SyntaxKind.CaseBlock:
case SyntaxKind.DefaultClause:

View file

@ -0,0 +1,16 @@
//// [tests/cases/compiler/cachedModuleResolution1.ts] ////
//// [foo.d.ts]
export declare let x: number
//// [app.ts]
import {x} from "foo";
//// [lib.ts]
import {x} from "foo";
//// [app.js]
"use strict";
//// [lib.js]
"use strict";

View file

@ -0,0 +1,13 @@
=== /a/b/node_modules/foo.d.ts ===
export declare let x: number
>x : Symbol(x, Decl(foo.d.ts, 1, 18))
=== /a/b/c/d/e/app.ts ===
import {x} from "foo";
>x : Symbol(x, Decl(app.ts, 0, 8))
=== /a/b/c/lib.ts ===
import {x} from "foo";
>x : Symbol(x, Decl(lib.ts, 0, 8))

View file

@ -0,0 +1,46 @@
[
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
"Explicitly specified module resolution kind: 'NodeJs'.",
"Loading module 'foo' from 'node_modules' folder.",
"File '/a/b/c/d/e/node_modules/foo.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/d/e/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/d/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/node_modules/foo.ts' does not exist.",
"File '/a/b/c/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/node_modules/foo.ts' does not exist.",
"File '/a/b/node_modules/foo.tsx' does not exist.",
"File '/a/b/node_modules/foo.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========",
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
"Explicitly specified module resolution kind: 'NodeJs'.",
"Loading module 'foo' from 'node_modules' folder.",
"Resolution for module 'foo' was found in cache",
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========"
]

View file

@ -0,0 +1,13 @@
=== /a/b/node_modules/foo.d.ts ===
export declare let x: number
>x : number
=== /a/b/c/d/e/app.ts ===
import {x} from "foo";
>x : number
=== /a/b/c/lib.ts ===
import {x} from "foo";
>x : number

View file

@ -0,0 +1,17 @@
//// [tests/cases/compiler/cachedModuleResolution2.ts] ////
//// [foo.d.ts]
export declare let x: number
//// [lib.ts]
import {x} from "foo";
//// [app.ts]
import {x} from "foo";
//// [lib.js]
"use strict";
//// [app.js]
"use strict";

View file

@ -0,0 +1,13 @@
=== /a/b/node_modules/foo.d.ts ===
export declare let x: number
>x : Symbol(x, Decl(foo.d.ts, 1, 18))
=== /a/b/c/lib.ts ===
import {x} from "foo";
>x : Symbol(x, Decl(lib.ts, 0, 8))
=== /a/b/c/d/e/app.ts ===
import {x} from "foo";
>x : Symbol(x, Decl(app.ts, 0, 8))

View file

@ -0,0 +1,46 @@
[
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
"Explicitly specified module resolution kind: 'NodeJs'.",
"Loading module 'foo' from 'node_modules' folder.",
"File '/a/b/c/node_modules/foo.ts' does not exist.",
"File '/a/b/c/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/node_modules/foo.ts' does not exist.",
"File '/a/b/node_modules/foo.tsx' does not exist.",
"File '/a/b/node_modules/foo.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========",
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
"Explicitly specified module resolution kind: 'NodeJs'.",
"Loading module 'foo' from 'node_modules' folder.",
"File '/a/b/c/d/e/node_modules/foo.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/d/e/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/d/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/index.d.ts' does not exist.",
"Resolution for module 'foo' was found in cache",
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========"
]

View file

@ -0,0 +1,13 @@
=== /a/b/node_modules/foo.d.ts ===
export declare let x: number
>x : number
=== /a/b/c/lib.ts ===
import {x} from "foo";
>x : number
=== /a/b/c/d/e/app.ts ===
import {x} from "foo";
>x : number

View file

@ -0,0 +1,16 @@
//// [tests/cases/compiler/cachedModuleResolution3.ts] ////
//// [foo.d.ts]
export declare let x: number
//// [app.ts]
import {x} from "foo";
//// [lib.ts]
import {x} from "foo";
//// [app.js]
"use strict";
//// [lib.js]
"use strict";

View file

@ -0,0 +1,13 @@
=== /a/b/foo.d.ts ===
export declare let x: number
>x : Symbol(x, Decl(foo.d.ts, 1, 18))
=== /a/b/c/d/e/app.ts ===
import {x} from "foo";
>x : Symbol(x, Decl(app.ts, 0, 8))
=== /a/b/c/lib.ts ===
import {x} from "foo";
>x : Symbol(x, Decl(lib.ts, 0, 8))

View file

@ -0,0 +1,21 @@
[
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
"Explicitly specified module resolution kind: 'Classic'.",
"File '/a/b/c/d/e/foo.ts' does not exist.",
"File '/a/b/c/d/e/foo.tsx' does not exist.",
"File '/a/b/c/d/e/foo.d.ts' does not exist.",
"File '/a/b/c/d/foo.ts' does not exist.",
"File '/a/b/c/d/foo.tsx' does not exist.",
"File '/a/b/c/d/foo.d.ts' does not exist.",
"File '/a/b/c/foo.ts' does not exist.",
"File '/a/b/c/foo.tsx' does not exist.",
"File '/a/b/c/foo.d.ts' does not exist.",
"File '/a/b/foo.ts' does not exist.",
"File '/a/b/foo.tsx' does not exist.",
"File '/a/b/foo.d.ts' exist - use it as a name resolution result.",
"======== Module name 'foo' was successfully resolved to '/a/b/foo.d.ts'. ========",
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
"Explicitly specified module resolution kind: 'Classic'.",
"Resolution for module 'foo' was found in cache",
"======== Module name 'foo' was successfully resolved to '/a/b/foo.d.ts'. ========"
]

View file

@ -0,0 +1,13 @@
=== /a/b/foo.d.ts ===
export declare let x: number
>x : number
=== /a/b/c/d/e/app.ts ===
import {x} from "foo";
>x : number
=== /a/b/c/lib.ts ===
import {x} from "foo";
>x : number

View file

@ -0,0 +1,17 @@
//// [tests/cases/compiler/cachedModuleResolution4.ts] ////
//// [foo.d.ts]
export declare let x: number
//// [lib.ts]
import {x} from "foo";
//// [app.ts]
import {x} from "foo";
//// [lib.js]
"use strict";
//// [app.js]
"use strict";

View file

@ -0,0 +1,13 @@
=== /a/b/foo.d.ts ===
export declare let x: number
>x : Symbol(x, Decl(foo.d.ts, 1, 18))
=== /a/b/c/lib.ts ===
import {x} from "foo";
>x : Symbol(x, Decl(lib.ts, 0, 8))
=== /a/b/c/d/e/app.ts ===
import {x} from "foo";
>x : Symbol(x, Decl(app.ts, 0, 8))

View file

@ -0,0 +1,21 @@
[
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
"Explicitly specified module resolution kind: 'Classic'.",
"File '/a/b/c/foo.ts' does not exist.",
"File '/a/b/c/foo.tsx' does not exist.",
"File '/a/b/c/foo.d.ts' does not exist.",
"File '/a/b/foo.ts' does not exist.",
"File '/a/b/foo.tsx' does not exist.",
"File '/a/b/foo.d.ts' exist - use it as a name resolution result.",
"======== Module name 'foo' was successfully resolved to '/a/b/foo.d.ts'. ========",
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
"Explicitly specified module resolution kind: 'Classic'.",
"File '/a/b/c/d/e/foo.ts' does not exist.",
"File '/a/b/c/d/e/foo.tsx' does not exist.",
"File '/a/b/c/d/e/foo.d.ts' does not exist.",
"File '/a/b/c/d/foo.ts' does not exist.",
"File '/a/b/c/d/foo.tsx' does not exist.",
"File '/a/b/c/d/foo.d.ts' does not exist.",
"Resolution for module 'foo' was found in cache",
"======== Module name 'foo' was successfully resolved to '/a/b/foo.d.ts'. ========"
]

View file

@ -0,0 +1,13 @@
=== /a/b/foo.d.ts ===
export declare let x: number
>x : number
=== /a/b/c/lib.ts ===
import {x} from "foo";
>x : number
=== /a/b/c/d/e/app.ts ===
import {x} from "foo";
>x : number

View file

@ -0,0 +1,16 @@
//// [tests/cases/compiler/cachedModuleResolution5.ts] ////
//// [foo.d.ts]
export declare let x: number
//// [app.ts]
import {x} from "foo";
//// [lib.ts]
import {x} from "foo";
//// [app.js]
"use strict";
//// [lib.js]
"use strict";

View file

@ -0,0 +1,13 @@
=== /a/b/node_modules/foo.d.ts ===
export declare let x: number
>x : Symbol(x, Decl(foo.d.ts, 1, 18))
=== /a/b/c/d/e/app.ts ===
import {x} from "foo";
>x : Symbol(x, Decl(app.ts, 0, 8))
=== /a/b/lib.ts ===
import {x} from "foo";
>x : Symbol(x, Decl(lib.ts, 0, 8))

View file

@ -0,0 +1,46 @@
[
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
"Explicitly specified module resolution kind: 'NodeJs'.",
"Loading module 'foo' from 'node_modules' folder.",
"File '/a/b/c/d/e/node_modules/foo.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/d/e/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/d/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/node_modules/foo.ts' does not exist.",
"File '/a/b/c/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/node_modules/foo.ts' does not exist.",
"File '/a/b/node_modules/foo.tsx' does not exist.",
"File '/a/b/node_modules/foo.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========",
"======== Resolving module 'foo' from '/a/b/lib.ts'. ========",
"Explicitly specified module resolution kind: 'NodeJs'.",
"Loading module 'foo' from 'node_modules' folder.",
"Resolution for module 'foo' was found in cache",
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========"
]

View file

@ -0,0 +1,13 @@
=== /a/b/node_modules/foo.d.ts ===
export declare let x: number
>x : number
=== /a/b/c/d/e/app.ts ===
import {x} from "foo";
>x : number
=== /a/b/lib.ts ===
import {x} from "foo";
>x : number

View file

@ -0,0 +1,14 @@
/a/b/c/d/e/app.ts(2,17): error TS2307: Cannot find module 'foo'.
/a/b/c/lib.ts(1,17): error TS2307: Cannot find module 'foo'.
==== /a/b/c/d/e/app.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo'.
==== /a/b/c/lib.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo'.

View file

@ -0,0 +1,13 @@
//// [tests/cases/compiler/cachedModuleResolution6.ts] ////
//// [app.ts]
import {x} from "foo";
//// [lib.ts]
import {x} from "foo";
//// [app.js]
"use strict";
//// [lib.js]
"use strict";

View file

@ -0,0 +1,102 @@
[
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
"Explicitly specified module resolution kind: 'NodeJs'.",
"Loading module 'foo' from 'node_modules' folder.",
"File '/a/b/c/d/e/node_modules/foo.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/d/e/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/d/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/node_modules/foo.ts' does not exist.",
"File '/a/b/c/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/node_modules/foo.ts' does not exist.",
"File '/a/b/node_modules/foo.tsx' does not exist.",
"File '/a/b/node_modules/foo.d.ts' does not exist.",
"File '/a/b/node_modules/foo/package.json' does not exist.",
"File '/a/b/node_modules/foo/index.ts' does not exist.",
"File '/a/b/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/node_modules/foo.ts' does not exist.",
"File '/a/node_modules/foo.tsx' does not exist.",
"File '/a/node_modules/foo.d.ts' does not exist.",
"File '/a/node_modules/foo/package.json' does not exist.",
"File '/a/node_modules/foo/index.ts' does not exist.",
"File '/a/node_modules/foo/index.tsx' does not exist.",
"File '/a/node_modules/foo/index.d.ts' does not exist.",
"File '/a/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/node_modules/@types/foo/package.json' does not exist.",
"File '/a/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/node_modules/foo.ts' does not exist.",
"File '/node_modules/foo.tsx' does not exist.",
"File '/node_modules/foo.d.ts' does not exist.",
"File '/node_modules/foo/package.json' does not exist.",
"File '/node_modules/foo/index.ts' does not exist.",
"File '/node_modules/foo/index.tsx' does not exist.",
"File '/node_modules/foo/index.d.ts' does not exist.",
"File '/node_modules/@types/foo.d.ts' does not exist.",
"File '/node_modules/@types/foo/package.json' does not exist.",
"File '/node_modules/@types/foo/index.d.ts' does not exist.",
"Loading module 'foo' from 'node_modules' folder.",
"File '/a/b/c/d/e/node_modules/foo.js' does not exist.",
"File '/a/b/c/d/e/node_modules/foo.jsx' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.js' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.jsx' does not exist.",
"File '/a/b/c/d/node_modules/foo.js' does not exist.",
"File '/a/b/c/d/node_modules/foo.jsx' does not exist.",
"File '/a/b/c/d/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.js' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.jsx' does not exist.",
"File '/a/b/c/node_modules/foo.js' does not exist.",
"File '/a/b/c/node_modules/foo.jsx' does not exist.",
"File '/a/b/c/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/foo/index.js' does not exist.",
"File '/a/b/c/node_modules/foo/index.jsx' does not exist.",
"File '/a/b/node_modules/foo.js' does not exist.",
"File '/a/b/node_modules/foo.jsx' does not exist.",
"File '/a/b/node_modules/foo/package.json' does not exist.",
"File '/a/b/node_modules/foo/index.js' does not exist.",
"File '/a/b/node_modules/foo/index.jsx' does not exist.",
"File '/a/node_modules/foo.js' does not exist.",
"File '/a/node_modules/foo.jsx' does not exist.",
"File '/a/node_modules/foo/package.json' does not exist.",
"File '/a/node_modules/foo/index.js' does not exist.",
"File '/a/node_modules/foo/index.jsx' does not exist.",
"File '/node_modules/foo.js' does not exist.",
"File '/node_modules/foo.jsx' does not exist.",
"File '/node_modules/foo/package.json' does not exist.",
"File '/node_modules/foo/index.js' does not exist.",
"File '/node_modules/foo/index.jsx' does not exist.",
"======== Module name 'foo' was not resolved. ========",
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
"Explicitly specified module resolution kind: 'NodeJs'.",
"Loading module 'foo' from 'node_modules' folder.",
"Resolution for module 'foo' was found in cache",
"======== Module name 'foo' was not resolved. ========"
]

View file

@ -0,0 +1,15 @@
/a/b/c/d/e/app.ts(1,17): error TS2307: Cannot find module 'foo'.
/a/b/c/lib.ts(2,17): error TS2307: Cannot find module 'foo'.
==== /a/b/c/lib.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo'.
==== /a/b/c/d/e/app.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo'.

View file

@ -0,0 +1,14 @@
//// [tests/cases/compiler/cachedModuleResolution7.ts] ////
//// [lib.ts]
import {x} from "foo";
//// [app.ts]
import {x} from "foo";
//// [lib.js]
"use strict";
//// [app.js]
"use strict";

View file

@ -0,0 +1,92 @@
[
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
"Explicitly specified module resolution kind: 'NodeJs'.",
"Loading module 'foo' from 'node_modules' folder.",
"File '/a/b/c/node_modules/foo.ts' does not exist.",
"File '/a/b/c/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/node_modules/foo.ts' does not exist.",
"File '/a/b/node_modules/foo.tsx' does not exist.",
"File '/a/b/node_modules/foo.d.ts' does not exist.",
"File '/a/b/node_modules/foo/package.json' does not exist.",
"File '/a/b/node_modules/foo/index.ts' does not exist.",
"File '/a/b/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/node_modules/foo.ts' does not exist.",
"File '/a/node_modules/foo.tsx' does not exist.",
"File '/a/node_modules/foo.d.ts' does not exist.",
"File '/a/node_modules/foo/package.json' does not exist.",
"File '/a/node_modules/foo/index.ts' does not exist.",
"File '/a/node_modules/foo/index.tsx' does not exist.",
"File '/a/node_modules/foo/index.d.ts' does not exist.",
"File '/a/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/node_modules/@types/foo/package.json' does not exist.",
"File '/a/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/node_modules/foo.ts' does not exist.",
"File '/node_modules/foo.tsx' does not exist.",
"File '/node_modules/foo.d.ts' does not exist.",
"File '/node_modules/foo/package.json' does not exist.",
"File '/node_modules/foo/index.ts' does not exist.",
"File '/node_modules/foo/index.tsx' does not exist.",
"File '/node_modules/foo/index.d.ts' does not exist.",
"File '/node_modules/@types/foo.d.ts' does not exist.",
"File '/node_modules/@types/foo/package.json' does not exist.",
"File '/node_modules/@types/foo/index.d.ts' does not exist.",
"Loading module 'foo' from 'node_modules' folder.",
"File '/a/b/c/node_modules/foo.js' does not exist.",
"File '/a/b/c/node_modules/foo.jsx' does not exist.",
"File '/a/b/c/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/foo/index.js' does not exist.",
"File '/a/b/c/node_modules/foo/index.jsx' does not exist.",
"File '/a/b/node_modules/foo.js' does not exist.",
"File '/a/b/node_modules/foo.jsx' does not exist.",
"File '/a/b/node_modules/foo/package.json' does not exist.",
"File '/a/b/node_modules/foo/index.js' does not exist.",
"File '/a/b/node_modules/foo/index.jsx' does not exist.",
"File '/a/node_modules/foo.js' does not exist.",
"File '/a/node_modules/foo.jsx' does not exist.",
"File '/a/node_modules/foo/package.json' does not exist.",
"File '/a/node_modules/foo/index.js' does not exist.",
"File '/a/node_modules/foo/index.jsx' does not exist.",
"File '/node_modules/foo.js' does not exist.",
"File '/node_modules/foo.jsx' does not exist.",
"File '/node_modules/foo/package.json' does not exist.",
"File '/node_modules/foo/index.js' does not exist.",
"File '/node_modules/foo/index.jsx' does not exist.",
"======== Module name 'foo' was not resolved. ========",
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
"Explicitly specified module resolution kind: 'NodeJs'.",
"Loading module 'foo' from 'node_modules' folder.",
"File '/a/b/c/d/e/node_modules/foo.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/d/e/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/d/e/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo.tsx' does not exist.",
"File '/a/b/c/d/node_modules/foo.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.ts' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.tsx' does not exist.",
"File '/a/b/c/d/node_modules/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/index.d.ts' does not exist.",
"Resolution for module 'foo' was found in cache",
"======== Module name 'foo' was not resolved. ========"
]

View file

@ -0,0 +1,14 @@
/a/b/c/d/e/app.ts(2,17): error TS2307: Cannot find module 'foo'.
/a/b/c/lib.ts(1,17): error TS2307: Cannot find module 'foo'.
==== /a/b/c/d/e/app.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo'.
==== /a/b/c/lib.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo'.

View file

@ -0,0 +1,13 @@
//// [tests/cases/compiler/cachedModuleResolution8.ts] ////
//// [app.ts]
import {x} from "foo";
//// [lib.ts]
import {x} from "foo";
//// [app.js]
"use strict";
//// [lib.js]
"use strict";

View file

@ -0,0 +1,57 @@
[
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
"Explicitly specified module resolution kind: 'Classic'.",
"File '/a/b/c/d/e/foo.ts' does not exist.",
"File '/a/b/c/d/e/foo.tsx' does not exist.",
"File '/a/b/c/d/e/foo.d.ts' does not exist.",
"File '/a/b/c/d/foo.ts' does not exist.",
"File '/a/b/c/d/foo.tsx' does not exist.",
"File '/a/b/c/d/foo.d.ts' does not exist.",
"File '/a/b/c/foo.ts' does not exist.",
"File '/a/b/c/foo.tsx' does not exist.",
"File '/a/b/c/foo.d.ts' does not exist.",
"File '/a/b/foo.ts' does not exist.",
"File '/a/b/foo.tsx' does not exist.",
"File '/a/b/foo.d.ts' does not exist.",
"File '/a/foo.ts' does not exist.",
"File '/a/foo.tsx' does not exist.",
"File '/a/foo.d.ts' does not exist.",
"File '/foo.ts' does not exist.",
"File '/foo.tsx' does not exist.",
"File '/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/e/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/d/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/node_modules/@types/foo/package.json' does not exist.",
"File '/a/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/node_modules/@types/foo.d.ts' does not exist.",
"File '/node_modules/@types/foo/package.json' does not exist.",
"File '/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/d/e/foo.js' does not exist.",
"File '/a/b/c/d/e/foo.jsx' does not exist.",
"File '/a/b/c/d/foo.js' does not exist.",
"File '/a/b/c/d/foo.jsx' does not exist.",
"File '/a/b/c/foo.js' does not exist.",
"File '/a/b/c/foo.jsx' does not exist.",
"File '/a/b/foo.js' does not exist.",
"File '/a/b/foo.jsx' does not exist.",
"File '/a/foo.js' does not exist.",
"File '/a/foo.jsx' does not exist.",
"File '/foo.js' does not exist.",
"File '/foo.jsx' does not exist.",
"======== Module name 'foo' was not resolved. ========",
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
"Explicitly specified module resolution kind: 'Classic'.",
"Resolution for module 'foo' was found in cache",
"======== Module name 'foo' was not resolved. ========"
]

View file

@ -0,0 +1,16 @@
/a/b/c/d/e/app.ts(1,17): error TS2307: Cannot find module 'foo'.
/a/b/c/lib.ts(2,17): error TS2307: Cannot find module 'foo'.
==== /a/b/c/lib.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo'.
==== /a/b/c/d/e/app.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo'.

View file

@ -0,0 +1,15 @@
//// [tests/cases/compiler/cachedModuleResolution9.ts] ////
//// [lib.ts]
import {x} from "foo";
//// [app.ts]
import {x} from "foo";
//// [lib.js]
"use strict";
//// [app.js]
"use strict";

View file

@ -0,0 +1,47 @@
[
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
"Explicitly specified module resolution kind: 'Classic'.",
"File '/a/b/c/foo.ts' does not exist.",
"File '/a/b/c/foo.tsx' does not exist.",
"File '/a/b/c/foo.d.ts' does not exist.",
"File '/a/b/foo.ts' does not exist.",
"File '/a/b/foo.tsx' does not exist.",
"File '/a/b/foo.d.ts' does not exist.",
"File '/a/foo.ts' does not exist.",
"File '/a/foo.tsx' does not exist.",
"File '/a/foo.d.ts' does not exist.",
"File '/foo.ts' does not exist.",
"File '/foo.tsx' does not exist.",
"File '/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/c/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/c/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/b/node_modules/@types/foo/package.json' does not exist.",
"File '/a/b/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/node_modules/@types/foo.d.ts' does not exist.",
"File '/a/node_modules/@types/foo/package.json' does not exist.",
"File '/a/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/node_modules/@types/foo.d.ts' does not exist.",
"File '/node_modules/@types/foo/package.json' does not exist.",
"File '/node_modules/@types/foo/index.d.ts' does not exist.",
"File '/a/b/c/foo.js' does not exist.",
"File '/a/b/c/foo.jsx' does not exist.",
"File '/a/b/foo.js' does not exist.",
"File '/a/b/foo.jsx' does not exist.",
"File '/a/foo.js' does not exist.",
"File '/a/foo.jsx' does not exist.",
"File '/foo.js' does not exist.",
"File '/foo.jsx' does not exist.",
"======== Module name 'foo' was not resolved. ========",
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
"Explicitly specified module resolution kind: 'Classic'.",
"File '/a/b/c/d/e/foo.ts' does not exist.",
"File '/a/b/c/d/e/foo.tsx' does not exist.",
"File '/a/b/c/d/e/foo.d.ts' does not exist.",
"File '/a/b/c/d/foo.ts' does not exist.",
"File '/a/b/c/d/foo.tsx' does not exist.",
"File '/a/b/c/d/foo.d.ts' does not exist.",
"Resolution for module 'foo' was found in cache",
"======== Module name 'foo' was not resolved. ========"
]

View file

@ -0,0 +1,26 @@
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(2,22): error TS2448: Block-scoped variable 'e' used before its declaration.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(3,22): error TS2448: Block-scoped variable 'i' used before its declaration.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(7,27): error TS2372: Parameter 'e' cannot be referenced in its initializer.
tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(9,27): error TS2373: Initializer of parameter 'h' cannot reference identifier 'i' declared after it.
==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts (4 errors) ====
const [a, b = a] = [1]; // ok
const [c, d = c, e = e] = [1]; // error for e = e
~
!!! error TS2448: Block-scoped variable 'e' used before its declaration.
const [f, g = f, h = i, i = f] = [1]; // error for h = i
~
!!! error TS2448: Block-scoped variable 'i' used before its declaration.
(function ([a, b = a]) { // ok
})([1]);
(function ([c, d = c, e = e]) { // error for e = e
~
!!! error TS2372: Parameter 'e' cannot be referenced in its initializer.
})([1]);
(function ([f, g = f, h = i, i = f]) { // error for h = i
~
!!! error TS2373: Initializer of parameter 'h' cannot reference identifier 'i' declared after it.
})([1])

View file

@ -0,0 +1,26 @@
//// [destructuringArrayBindingPatternAndAssignment3.ts]
const [a, b = a] = [1]; // ok
const [c, d = c, e = e] = [1]; // error for e = e
const [f, g = f, h = i, i = f] = [1]; // error for h = i
(function ([a, b = a]) { // ok
})([1]);
(function ([c, d = c, e = e]) { // error for e = e
})([1]);
(function ([f, g = f, h = i, i = f]) { // error for h = i
})([1])
//// [destructuringArrayBindingPatternAndAssignment3.js]
var _a = [1], a = _a[0], _b = _a[1], b = _b === void 0 ? a : _b; // ok
var _c = [1], c = _c[0], _d = _c[1], d = _d === void 0 ? c : _d, _e = _c[2], e = _e === void 0 ? e : _e; // error for e = e
var _f = [1], f = _f[0], _g = _f[1], g = _g === void 0 ? f : _g, _h = _f[2], h = _h === void 0 ? i : _h, _j = _f[3], i = _j === void 0 ? f : _j; // error for h = i
(function (_a) {
var a = _a[0], _b = _a[1], b = _b === void 0 ? a : _b;
})([1]);
(function (_a) {
var c = _a[0], _b = _a[1], d = _b === void 0 ? c : _b, _c = _a[2], e = _c === void 0 ? e : _c;
})([1]);
(function (_a) {
var f = _a[0], _b = _a[1], g = _b === void 0 ? f : _b, _c = _a[2], h = _c === void 0 ? i : _c, _d = _a[3], i = _d === void 0 ? f : _d;
})([1]);

View file

@ -0,0 +1,18 @@
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(6,9): error TS2448: Block-scoped variable 'f' used before its declaration.
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(7,9): error TS2448: Block-scoped variable 'f' used before its declaration.
==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts (2 errors) ====
const {
a = 1,
b = 2,
c = b, // ok
d = a, // ok
e = f, // error
~
!!! error TS2448: Block-scoped variable 'f' used before its declaration.
f = f // error
~
!!! error TS2448: Block-scoped variable 'f' used before its declaration.
} = { } as any;

View file

@ -0,0 +1,21 @@
//// [destructuringObjectBindingPatternAndAssignment4.ts]
const {
a = 1,
b = 2,
c = b, // ok
d = a, // ok
e = f, // error
f = f // error
} = { } as any;
//// [destructuringObjectBindingPatternAndAssignment4.js]
var _a = {}, _b = _a.a, a = _b === void 0 ? 1 : _b, _c = _a.b, b = _c === void 0 ? 2 : _c, _d = _a.c, c = _d === void 0 ? b : _d, // ok
_e = _a.d, // ok
d = _e === void 0 ? a : _e, // ok
_f = _a.e, // ok
e = _f === void 0 ? f : _f, // error
_g = _a.f // error
, // error
f = _g === void 0 ? f : _g // error
;

View file

@ -3,7 +3,7 @@ tests/cases/conformance/expressions/literals/literals.ts(9,17): error TS2363: Th
tests/cases/conformance/expressions/literals/literals.ts(10,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/literals/literals.ts(10,21): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/literals/literals.ts(20,9): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'.
tests/cases/conformance/expressions/literals/literals.ts(25,10): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'.
tests/cases/conformance/expressions/literals/literals.ts(25,9): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '-0o3'.
==== tests/cases/conformance/expressions/literals/literals.ts (6 errors) ====
@ -42,8 +42,8 @@ tests/cases/conformance/expressions/literals/literals.ts(25,10): error TS1085: O
var n = -1.0;
var n = -1e-4;
var n = -003; // Error in ES5
~~~
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'.
~~~~
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '-0o3'.
var n = -0x1;
var s: string;

View file

@ -0,0 +1,44 @@
//// [metadataOfClassFromModule.ts]
module MyModule {
export function inject(target: any, key: string): void { }
export class Leg { }
export class Person {
@inject leftLeg: Leg;
}
}
//// [metadataOfClassFromModule.js]
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var MyModule;
(function (MyModule) {
function inject(target, key) { }
MyModule.inject = inject;
var Leg = (function () {
function Leg() {
}
return Leg;
}());
MyModule.Leg = Leg;
var Person = (function () {
function Person() {
}
return Person;
}());
__decorate([
inject,
__metadata("design:type", Leg)
], Person.prototype, "leftLeg", void 0);
MyModule.Person = Person;
})(MyModule || (MyModule = {}));

View file

@ -0,0 +1,22 @@
=== tests/cases/compiler/metadataOfClassFromModule.ts ===
module MyModule {
>MyModule : Symbol(MyModule, Decl(metadataOfClassFromModule.ts, 0, 0))
export function inject(target: any, key: string): void { }
>inject : Symbol(inject, Decl(metadataOfClassFromModule.ts, 0, 17))
>target : Symbol(target, Decl(metadataOfClassFromModule.ts, 2, 27))
>key : Symbol(key, Decl(metadataOfClassFromModule.ts, 2, 39))
export class Leg { }
>Leg : Symbol(Leg, Decl(metadataOfClassFromModule.ts, 2, 62))
export class Person {
>Person : Symbol(Person, Decl(metadataOfClassFromModule.ts, 4, 24))
@inject leftLeg: Leg;
>inject : Symbol(inject, Decl(metadataOfClassFromModule.ts, 0, 17))
>leftLeg : Symbol(Person.leftLeg, Decl(metadataOfClassFromModule.ts, 6, 25))
>Leg : Symbol(Leg, Decl(metadataOfClassFromModule.ts, 2, 62))
}
}

View file

@ -0,0 +1,22 @@
=== tests/cases/compiler/metadataOfClassFromModule.ts ===
module MyModule {
>MyModule : typeof MyModule
export function inject(target: any, key: string): void { }
>inject : (target: any, key: string) => void
>target : any
>key : string
export class Leg { }
>Leg : Leg
export class Person {
>Person : Person
@inject leftLeg: Leg;
>inject : (target: any, key: string) => void
>leftLeg : Leg
>Leg : Leg
}
}

View file

@ -0,0 +1,113 @@
//// [metadataOfUnionWithNull.ts]
function PropDeco(target: Object, propKey: string | symbol) { }
class A {
}
class B {
@PropDeco
x: "foo" | null;
@PropDeco
y: true | never;
@PropDeco
z: "foo" | undefined;
@PropDeco
a: null;
@PropDeco
b: never;
@PropDeco
c: undefined;
@PropDeco
d: undefined | null;
@PropDeco
e: symbol | null;
@PropDeco
f: symbol | A;
@PropDeco
g: A | null;
@PropDeco
h: null | B;
@PropDeco
j: null | symbol;
}
//// [metadataOfUnionWithNull.js]
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
function PropDeco(target, propKey) { }
var A = (function () {
function A() {
}
return A;
}());
var B = (function () {
function B() {
}
return B;
}());
__decorate([
PropDeco,
__metadata("design:type", String)
], B.prototype, "x");
__decorate([
PropDeco,
__metadata("design:type", Boolean)
], B.prototype, "y");
__decorate([
PropDeco,
__metadata("design:type", String)
], B.prototype, "z");
__decorate([
PropDeco,
__metadata("design:type", void 0)
], B.prototype, "a");
__decorate([
PropDeco,
__metadata("design:type", void 0)
], B.prototype, "b");
__decorate([
PropDeco,
__metadata("design:type", void 0)
], B.prototype, "c");
__decorate([
PropDeco,
__metadata("design:type", void 0)
], B.prototype, "d");
__decorate([
PropDeco,
__metadata("design:type", typeof Symbol === "function" ? Symbol : Object)
], B.prototype, "e");
__decorate([
PropDeco,
__metadata("design:type", Object)
], B.prototype, "f");
__decorate([
PropDeco,
__metadata("design:type", A)
], B.prototype, "g");
__decorate([
PropDeco,
__metadata("design:type", B)
], B.prototype, "h");
__decorate([
PropDeco,
__metadata("design:type", typeof Symbol === "function" ? Symbol : Object)
], B.prototype, "j");

View file

@ -0,0 +1,89 @@
=== tests/cases/compiler/metadataOfUnionWithNull.ts ===
function PropDeco(target: Object, propKey: string | symbol) { }
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
>target : Symbol(target, Decl(metadataOfUnionWithNull.ts, 0, 18))
>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>propKey : Symbol(propKey, Decl(metadataOfUnionWithNull.ts, 0, 33))
class A {
>A : Symbol(A, Decl(metadataOfUnionWithNull.ts, 0, 63))
}
class B {
>B : Symbol(B, Decl(metadataOfUnionWithNull.ts, 3, 1))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
x: "foo" | null;
>x : Symbol(B.x, Decl(metadataOfUnionWithNull.ts, 5, 9))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
y: true | never;
>y : Symbol(B.y, Decl(metadataOfUnionWithNull.ts, 7, 20))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
z: "foo" | undefined;
>z : Symbol(B.z, Decl(metadataOfUnionWithNull.ts, 10, 20))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
a: null;
>a : Symbol(B.a, Decl(metadataOfUnionWithNull.ts, 13, 25))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
b: never;
>b : Symbol(B.b, Decl(metadataOfUnionWithNull.ts, 16, 12))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
c: undefined;
>c : Symbol(B.c, Decl(metadataOfUnionWithNull.ts, 19, 13))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
d: undefined | null;
>d : Symbol(B.d, Decl(metadataOfUnionWithNull.ts, 22, 17))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
e: symbol | null;
>e : Symbol(B.e, Decl(metadataOfUnionWithNull.ts, 25, 24))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
f: symbol | A;
>f : Symbol(B.f, Decl(metadataOfUnionWithNull.ts, 28, 21))
>A : Symbol(A, Decl(metadataOfUnionWithNull.ts, 0, 63))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
g: A | null;
>g : Symbol(B.g, Decl(metadataOfUnionWithNull.ts, 31, 18))
>A : Symbol(A, Decl(metadataOfUnionWithNull.ts, 0, 63))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
h: null | B;
>h : Symbol(B.h, Decl(metadataOfUnionWithNull.ts, 34, 16))
>B : Symbol(B, Decl(metadataOfUnionWithNull.ts, 3, 1))
@PropDeco
>PropDeco : Symbol(PropDeco, Decl(metadataOfUnionWithNull.ts, 0, 0))
j: null | symbol;
>j : Symbol(B.j, Decl(metadataOfUnionWithNull.ts, 37, 16))
}

View file

@ -0,0 +1,97 @@
=== tests/cases/compiler/metadataOfUnionWithNull.ts ===
function PropDeco(target: Object, propKey: string | symbol) { }
>PropDeco : (target: Object, propKey: string | symbol) => void
>target : Object
>Object : Object
>propKey : string | symbol
class A {
>A : A
}
class B {
>B : B
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
x: "foo" | null;
>x : "foo"
>null : null
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
y: true | never;
>y : true
>true : true
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
z: "foo" | undefined;
>z : "foo"
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
a: null;
>a : null
>null : null
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
b: never;
>b : never
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
c: undefined;
>c : undefined
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
d: undefined | null;
>d : null
>null : null
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
e: symbol | null;
>e : symbol
>null : null
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
f: symbol | A;
>f : symbol | A
>A : A
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
g: A | null;
>g : A
>A : A
>null : null
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
h: null | B;
>h : B
>null : null
>B : B
@PropDeco
>PropDeco : (target: Object, propKey: string | symbol) => void
j: null | symbol;
>j : symbol
>null : null
}

View file

@ -1,5 +1,5 @@
tests/cases/compiler/oldStyleOctalLiteralTypes.ts(1,8): error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o10'.
tests/cases/compiler/oldStyleOctalLiteralTypes.ts(2,9): error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o20'.
tests/cases/compiler/oldStyleOctalLiteralTypes.ts(2,8): error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '-0o20'.
==== tests/cases/compiler/oldStyleOctalLiteralTypes.ts (2 errors) ====
@ -7,6 +7,6 @@ tests/cases/compiler/oldStyleOctalLiteralTypes.ts(2,9): error TS8017: Octal lite
~~~
!!! error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o10'.
let y: -020;
~~~
!!! error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o20'.
~~~~
!!! error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '-0o20'.

View file

@ -1,7 +1,7 @@
tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts(1,2): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'.
tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts(1,1): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '-0o3'.
==== tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts (1 errors) ====
-03
~~
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'.
~~~
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '-0o3'.

View file

@ -0,0 +1,29 @@
tests/cases/compiler/unusedLocalsAndObjectSpread2.ts(6,6): error TS6133: 'rest' is declared but never used.
tests/cases/compiler/unusedLocalsAndObjectSpread2.ts(9,10): error TS6133: 'foo' is declared but never used.
tests/cases/compiler/unusedLocalsAndObjectSpread2.ts(13,8): error TS6133: 'rest' is declared but never used.
==== tests/cases/compiler/unusedLocalsAndObjectSpread2.ts (3 errors) ====
declare let props: any;
const {
children, // here!
active: _a, // here!
...rest,
~~~~
!!! error TS6133: 'rest' is declared but never used.
} = props;
function foo() {
~~~
!!! error TS6133: 'foo' is declared but never used.
const {
children,
active: _a,
...rest,
~~~~
!!! error TS6133: 'rest' is declared but never used.
} = props;
}
export const asdf = 123;

View file

@ -0,0 +1,37 @@
//// [unusedLocalsAndObjectSpread2.ts]
declare let props: any;
const {
children, // here!
active: _a, // here!
...rest,
} = props;
function foo() {
const {
children,
active: _a,
...rest,
} = props;
}
export const asdf = 123;
//// [unusedLocalsAndObjectSpread2.js]
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
var children = props.children, // here!
_a = props.active, // here!
rest = __rest(props, ["children", "active"]);
function foo() {
var children = props.children, _a = props.active, rest = __rest(props, ["children", "active"]);
}
exports.asdf = 123;

View file

@ -0,0 +1,11 @@
// @moduleResolution: node
// @traceResolution: true
// @filename: /a/b/node_modules/foo.d.ts
export declare let x: number
// @filename: /a/b/c/d/e/app.ts
import {x} from "foo";
// @filename: /a/b/c/lib.ts
import {x} from "foo";

View file

@ -0,0 +1,11 @@
// @moduleResolution: node
// @traceResolution: true
// @filename: /a/b/node_modules/foo.d.ts
export declare let x: number
// @filename: /a/b/c/lib.ts
import {x} from "foo";
// @filename: /a/b/c/d/e/app.ts
import {x} from "foo";

View file

@ -0,0 +1,11 @@
// @moduleResolution: classic
// @traceResolution: true
// @filename: /a/b/foo.d.ts
export declare let x: number
// @filename: /a/b/c/d/e/app.ts
import {x} from "foo";
// @filename: /a/b/c/lib.ts
import {x} from "foo";

View file

@ -0,0 +1,11 @@
// @moduleResolution: classic
// @traceResolution: true
// @filename: /a/b/foo.d.ts
export declare let x: number
// @filename: /a/b/c/lib.ts
import {x} from "foo";
// @filename: /a/b/c/d/e/app.ts
import {x} from "foo";

View file

@ -0,0 +1,11 @@
// @moduleResolution: node
// @traceResolution: true
// @filename: /a/b/node_modules/foo.d.ts
export declare let x: number
// @filename: /a/b/c/d/e/app.ts
import {x} from "foo";
// @filename: /a/b/lib.ts
import {x} from "foo";

View file

@ -0,0 +1,8 @@
// @moduleResolution: node
// @traceResolution: true
// @filename: /a/b/c/d/e/app.ts
import {x} from "foo";
// @filename: /a/b/c/lib.ts
import {x} from "foo";

View file

@ -0,0 +1,8 @@
// @moduleResolution: node
// @traceResolution: true
// @filename: /a/b/c/lib.ts
import {x} from "foo";
// @filename: /a/b/c/d/e/app.ts
import {x} from "foo";

View file

@ -0,0 +1,8 @@
// @moduleResolution: classic
// @traceResolution: true
// @filename: /a/b/c/d/e/app.ts
import {x} from "foo";
// @filename: /a/b/c/lib.ts
import {x} from "foo";

View file

@ -0,0 +1,9 @@
// @moduleResolution: classic
// @traceResolution: true
// @filename: /a/b/c/lib.ts
import {x} from "foo";
// @filename: /a/b/c/d/e/app.ts
import {x} from "foo";

View file

@ -0,0 +1,14 @@
// @experimentalDecorators: true
// @emitDecoratorMetadata: true
// @target: es5
module MyModule {
export function inject(target: any, key: string): void { }
export class Leg { }
export class Person {
@inject leftLeg: Leg;
}
}

View file

@ -0,0 +1,44 @@
// @experimentalDecorators: true
// @emitDecoratorMetadata: true
function PropDeco(target: Object, propKey: string | symbol) { }
class A {
}
class B {
@PropDeco
x: "foo" | null;
@PropDeco
y: true | never;
@PropDeco
z: "foo" | undefined;
@PropDeco
a: null;
@PropDeco
b: never;
@PropDeco
c: undefined;
@PropDeco
d: undefined | null;
@PropDeco
e: symbol | null;
@PropDeco
f: symbol | A;
@PropDeco
g: A | null;
@PropDeco
h: null | B;
@PropDeco
j: null | symbol;
}

View file

@ -0,0 +1,18 @@
//@noUnusedLocals:true
declare let props: any;
const {
children, // here!
active: _a, // here!
...rest,
} = props;
function foo() {
const {
children,
active: _a,
...rest,
} = props;
}
export const asdf = 123;

View file

@ -0,0 +1,10 @@
const [a, b = a] = [1]; // ok
const [c, d = c, e = e] = [1]; // error for e = e
const [f, g = f, h = i, i = f] = [1]; // error for h = i
(function ([a, b = a]) { // ok
})([1]);
(function ([c, d = c, e = e]) { // error for e = e
})([1]);
(function ([f, g = f, h = i, i = f]) { // error for h = i
})([1])

View file

@ -0,0 +1,8 @@
const {
a = 1,
b = 2,
c = b, // ok
d = a, // ok
e = f, // error
f = f // error
} = { } as any;

View file

@ -37,4 +37,4 @@ verify.currentLineContentIs(" x = 'Foo';");
goTo.marker("11");
verify.currentLineContentIs(" return fun;");
goTo.marker("12");
verify.currentLineContentIs(" } (fun1));");
verify.currentLineContentIs(" }(fun1));");

View file

@ -72,6 +72,8 @@
////<span>) </span>;/*closingParenInJsxElement2*/
////<Router routes = { 3 } / >;/*jsxExpressionSpaces*/
////<Router routes={ (3) } />;/*jsxExpressionSpaces2*/
////<Router routes={() => {}}/*jsxExpressionSpaces3*/
/////>;/*jsxDanglingSelfClosingToken*/
format.document();
goTo.marker("autoformat");
@ -120,8 +122,7 @@ goTo.marker("expressionIndent");
verify.indentationIs(12);
goTo.marker("danglingBracketAutoformat")
// TODO: verify.currentLineContentIs(" >");
verify.currentLineContentIs(" >");
verify.currentLineContentIs(" >");
goTo.marker("closingTagAutoformat");
verify.currentLineContentIs(" </div>");
@ -145,4 +146,8 @@ verify.currentLineContentIs("<span>) </span>;");
goTo.marker("jsxExpressionSpaces");
verify.currentLineContentIs("<Router routes={3} />;");
goTo.marker("jsxExpressionSpaces2");
verify.currentLineContentIs("<Router routes={(3)} />;");
verify.currentLineContentIs("<Router routes={(3)} />;");
goTo.marker("jsxExpressionSpaces3");
verify.currentLineContentIs("<Router routes={() => { }}");
goTo.marker("jsxDanglingSelfClosingToken");
verify.currentLineContentIs("/>;");

View file

@ -0,0 +1,12 @@
/// <reference path='fourslash.ts' />
/////*generic*/type t < T > = {
/////*map*/ [ P in keyof T ] : T [ P ]
////};
format.document();
goTo.marker("generic");
verify.currentLineContentIs("type t<T> = {");
goTo.marker("map");
verify.currentLineContentIs(" [P in keyof T]: T[P]");

View file

@ -0,0 +1,19 @@
///<reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: Foo.js
/////**
//// * @param {T[]} arr
//// * @param {(function(T):T)} valuator
//// * @template T
//// */
////function SortFilter(arr,valuator)
////{
//// return arr;
////}
////var a/*1*/ = SortFilter([0, 1, 2], q/*2*/ => q);
////var b/*3*/ = SortFilter([0, 1, 2], undefined);
verify.quickInfoAt('1', "var a: number[]");
verify.quickInfoAt('2', '(parameter) q: number');
verify.quickInfoAt('3', "var b: number[]");