Merge branch 'loadJsFromModules' into loadJsFromModules-2.0

This commit is contained in:
Bill Ticehurst
2016-06-27 17:15:55 -07:00
80 changed files with 721 additions and 62 deletions

1
.gitignore vendored
View File

@@ -49,3 +49,4 @@ internal/
**/.vscode
!**/.vscode/tasks.json
!tests/cases/projects/projectOption/**/node_modules
!tests/cases/projects/NodeModulesSearch/**/*

View File

@@ -374,6 +374,11 @@ namespace ts {
type: "boolean",
description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output
},
{
name: "maxNodeModuleJsDepth",
type: "number",
description: Diagnostics.The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files
},
{
name: "listEmittedFiles",
type: "boolean"

View File

@@ -2804,7 +2804,14 @@
"category": "Message",
"code": 6135
},
"The maximum dependency depth to search under node_modules and load JavaScript files": {
"category": "Message",
"code": 6136
},
"No types specified in 'package.json' but 'allowJs' is set, so returning 'main' value of '{0}'": {
"category": "Message",
"code": 6137
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005

View File

@@ -130,10 +130,10 @@ namespace ts {
}
function tryReadTypesSection(packageJsonPath: string, baseDirectory: string, state: ModuleResolutionState): string {
let jsonContent: { typings?: string, types?: string };
let jsonContent: { typings?: string, types?: string, main?: string };
try {
const jsonText = state.host.readFile(packageJsonPath);
jsonContent = jsonText ? <{ typings?: string, types?: string }>JSON.parse(jsonText) : {};
jsonContent = jsonText ? <{ typings?: string, types?: string, main?: string }>JSON.parse(jsonText) : {};
}
catch (e) {
// gracefully handle if readFile fails or returns not JSON
@@ -173,6 +173,14 @@ namespace ts {
}
return typesFilePath;
}
// Use the main module for inferring types if no types package specified and the allowJs is set
if (state.compilerOptions.allowJs && jsonContent.main && typeof jsonContent.main === "string") {
if (state.traceEnabled) {
trace(state.host, Diagnostics.No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0, jsonContent.main);
}
const mainFilePath = normalizePath(combinePaths(baseDirectory, jsonContent.main));
return mainFilePath;
}
return undefined;
}
@@ -610,7 +618,7 @@ namespace ts {
failedLookupLocations, supportedExtensions, state);
let isExternalLibraryImport = false;
if (!resolvedFileName) {
if (!resolvedFileName) {
if (moduleHasNonRelativeName(moduleName)) {
if (traceEnabled) {
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName);
@@ -740,12 +748,13 @@ namespace ts {
const nodeModulesFolder = combinePaths(directory, "node_modules");
const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host);
const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName));
// Load only typescript files irrespective of allowJs option if loading from node modules
let result = loadModuleFromFile(candidate, supportedTypeScriptExtensions, failedLookupLocations, !nodeModulesFolderExists, state);
const supportedExtensions = getSupportedExtensions(state.compilerOptions);
let result = loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, !nodeModulesFolderExists, state);
if (result) {
return result;
}
result = loadNodeModuleFromDirectory(supportedTypeScriptExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state);
result = loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state);
if (result) {
return result;
}
@@ -1057,6 +1066,23 @@ namespace ts {
let resolvedTypeReferenceDirectives: Map<ResolvedTypeReferenceDirective> = {};
let fileProcessingDiagnostics = createDiagnosticCollection();
// The below settings are to track if a .js file should be add to the program if loaded via searching under node_modules.
// This works as imported modules are discovered recursively in a depth first manner, specifically:
// - For each root file, findSourceFile is called.
// - This calls processImportedModules for each module imported in the source file.
// - This calls resolveModuleNames, and then calls findSourceFile for each resolved module.
// As all these operations happen - and are nested - within the createProgram call, they close over the below variables.
// The current resolution depth is tracked by incrementing/decrementing as the depth first search progresses.
const maxNodeModulesJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 2;
let currentNodeModulesJsDepth = 0;
// If a module has some of its imports skipped due to being at the depth limit under node_modules, then track
// this, as it may be imported at a shallower depth later, and then it will need its skipped imports processed.
const modulesWithElidedImports: Map<boolean> = {};
// Track source files that are JavaScript files found by searching under node_modules, as these shouldn't be compiled.
const jsFilesFoundSearchingNodeModules: Map<boolean> = {};
const start = new Date().getTime();
host = host || createCompilerHost(options);
@@ -1211,6 +1237,7 @@ namespace ts {
(oldOptions.rootDir !== options.rootDir) ||
(oldOptions.configFilePath !== options.configFilePath) ||
(oldOptions.baseUrl !== options.baseUrl) ||
(oldOptions.maxNodeModuleJsDepth !== options.maxNodeModuleJsDepth) ||
!arrayIsEqualTo(oldOptions.typeRoots, oldOptions.typeRoots) ||
!arrayIsEqualTo(oldOptions.rootDirs, options.rootDirs) ||
!mapIsEqualTo(oldOptions.paths, options.paths)) {
@@ -1335,6 +1362,7 @@ namespace ts {
getSourceFile: program.getSourceFile,
getSourceFileByPath: program.getSourceFileByPath,
getSourceFiles: program.getSourceFiles,
getFilesFromNodeModules: () => jsFilesFoundSearchingNodeModules,
writeFile: writeFileCallback || (
(fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)),
isEmitBlocked,
@@ -1869,6 +1897,14 @@ namespace ts {
reportFileNamesDifferOnlyInCasingError(fileName, file.fileName, refFile, refPos, refEnd);
}
// See if we need to reprocess the imports due to prior skipped imports
if (file && lookUp(modulesWithElidedImports, file.path)) {
if (currentNodeModulesJsDepth < maxNodeModulesJsDepth) {
modulesWithElidedImports[file.path] = false;
processImportedModules(file, getDirectoryPath(fileName));
}
}
return file;
}
@@ -2007,16 +2043,38 @@ namespace ts {
for (let i = 0; i < moduleNames.length; i++) {
const resolution = resolutions[i];
setResolvedModule(file, moduleNames[i], resolution);
const resolvedPath = resolution ? toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName) : undefined;
// add file to program only if:
// - resolution was successful
// - noResolve is falsy
// - module name comes from the list of imports
const shouldAddFile = resolution &&
!options.noResolve &&
i < file.imports.length;
// - it's not a top level JavaScript module that exceeded the search max
const isJsFileUnderNodeModules = resolution && resolution.isExternalLibraryImport &&
hasJavaScriptFileExtension(resolution.resolvedFileName);
if (shouldAddFile) {
findSourceFile(resolution.resolvedFileName, toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, /*isReference*/ false, file, skipTrivia(file.text, file.imports[i].pos), file.imports[i].end);
if (isJsFileUnderNodeModules) {
jsFilesFoundSearchingNodeModules[resolvedPath] = true;
currentNodeModulesJsDepth++;
}
const elideImport = isJsFileUnderNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth;
const shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport;
if (elideImport) {
modulesWithElidedImports[file.path] = true;
}
else if (shouldAddFile) {
findSourceFile(resolution.resolvedFileName,
resolvedPath,
/*isDefaultLib*/ false, /*isReference*/ false,
file,
skipTrivia(file.text, file.imports[i].pos),
file.imports[i].end);
}
if (isJsFileUnderNodeModules) {
currentNodeModulesJsDepth--;
}
}
}

View File

@@ -2533,6 +2533,7 @@ namespace ts {
declaration?: boolean;
declarationDir?: string;
/* @internal */ diagnostics?: boolean;
disableSizeLimit?: boolean;
emitBOM?: boolean;
emitDecoratorMetadata?: boolean;
experimentalDecorators?: boolean;
@@ -2548,6 +2549,7 @@ namespace ts {
/*@internal*/listFiles?: boolean;
locale?: string;
mapRoot?: string;
maxNodeModuleJsDepth?: number;
module?: ModuleKind;
moduleResolution?: ModuleResolutionKind;
newLine?: NewLineKind;
@@ -2586,7 +2588,6 @@ namespace ts {
/* @internal */ suppressOutputPathCheck?: boolean;
target?: ScriptTarget;
traceResolution?: boolean;
disableSizeLimit?: boolean;
types?: string[];
/** Paths used to used to compute primary types search locations */
typeRoots?: string[];

View File

@@ -35,6 +35,9 @@ namespace ts {
export interface EmitHost extends ScriptReferenceHost {
getSourceFiles(): SourceFile[];
/* @internal */
getFilesFromNodeModules(): Map<boolean>;
getCommonSourceDirectory(): string;
getCanonicalFileName(fileName: string): string;
getNewLine(): string;
@@ -2274,8 +2277,10 @@ namespace ts {
}
else {
const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile];
const nodeModulesFiles = host.getFilesFromNodeModules();
for (const sourceFile of sourceFiles) {
if (!isDeclarationFile(sourceFile)) {
// Don't emit if source file is a declaration file, or was located under node_modules
if (!isDeclarationFile(sourceFile) && !lookUp(nodeModulesFiles, sourceFile.path)) {
onSingleFileEmit(host, sourceFile);
}
}
@@ -2307,11 +2312,14 @@ namespace ts {
}
function onBundledEmit(host: EmitHost) {
// Can emit only sources that are not declaration file and are either non module code or module with --module or --target es6 specified
const bundledSources = filter(host.getSourceFiles(), sourceFile =>
!isDeclarationFile(sourceFile) // Not a declaration file
&& (!isExternalModule(sourceFile) || !!getEmitModuleKind(options))); // and not a module, unless module emit enabled
// Can emit only sources that are not declaration file and are either non module code or module with
// --module or --target es6 specified. Files included by searching under node_modules are also not emitted.
const nodeModulesFiles = host.getFilesFromNodeModules();
const bundledSources = filter(host.getSourceFiles(),
sourceFile => !isDeclarationFile(sourceFile) &&
!lookUp(nodeModulesFiles, sourceFile.path) &&
(!isExternalModule(sourceFile) ||
!!getEmitModuleKind(options)));
if (bundledSources.length) {
const jsFilePath = options.outFile || options.out;
const emitFileNames: EmitFileNames = {

View File

@@ -31,18 +31,12 @@ abstract class RunnerBase {
/** Replaces instances of full paths with fileNames only */
static removeFullPaths(path: string) {
let fixedPath = path;
// full paths either start with a drive letter or / for *nix, shouldn't have \ in the path at this point
const fullPath = /(\w+:|\/)?([\w+\-\.]|\/)*\.tsx?/g;
const fullPathList = fixedPath.match(fullPath);
if (fullPathList) {
fullPathList.forEach((match: string) => fixedPath = fixedPath.replace(match, Harness.Path.getFileName(match)));
}
// If its a full path (starts with "C:" or "/") replace with just the filename
let fixedPath = /^(\w:|\/)/.test(path) ? Harness.Path.getFileName(path) : path;
// when running in the browser the 'full path' is the host name, shows up in error baselines
const localHost = /http:\/localhost:\d+/g;
fixedPath = fixedPath.replace(localHost, "");
return fixedPath;
}
}
}

View File

@@ -4,5 +4,5 @@ tests/cases/compiler/declarationEmit_invalidReference2.ts(1,1): error TS6053: Fi
==== tests/cases/compiler/declarationEmit_invalidReference2.ts (1 errors) ====
/// <reference path="invalid.ts" />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'invalid.ts' not found.
!!! error TS6053: File 'tests/cases/compiler/invalid.ts' not found.
var x = 0;

View File

@@ -1,7 +1,7 @@
error TS5055: Cannot write file 'tests/cases/compiler/a.d.ts' because it would overwrite input file.
!!! error TS5055: Cannot write file 'a.d.ts' because it would overwrite input file.
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.d.ts' because it would overwrite input file.
==== tests/cases/compiler/a.d.ts (0 errors) ====
declare class c {

View File

@@ -1,7 +1,7 @@
error TS5055: Cannot write file 'tests/cases/compiler/out.d.ts' because it would overwrite input file.
!!! error TS5055: Cannot write file 'out.d.ts' because it would overwrite input file.
!!! error TS5055: Cannot write file 'tests/cases/compiler/out.d.ts' because it would overwrite input file.
==== tests/cases/compiler/out.d.ts (0 errors) ====
declare class c {

View File

@@ -14,7 +14,7 @@ tests/cases/compiler/exportStarFromEmptyModule_module4.ts(4,5): error TS2339: Pr
==== tests/cases/compiler/exportStarFromEmptyModule_module3.ts (1 errors) ====
export * from "./exportStarFromEmptyModule_module2";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2306: File 'exportStarFromEmptyModule_module2.ts' is not a module.
!!! error TS2306: File 'tests/cases/compiler/exportStarFromEmptyModule_module2.ts' is not a module.
export * from "./exportStarFromEmptyModule_module1";
export class A {

View File

@@ -4,7 +4,7 @@ tests/cases/conformance/externalModules/foo_1.ts(1,22): error TS2306: File 'test
==== tests/cases/conformance/externalModules/foo_1.ts (1 errors) ====
import foo = require("./foo_0");
~~~~~~~~~
!!! error TS2306: File 'foo_0.ts' is not a module.
!!! error TS2306: File 'tests/cases/conformance/externalModules/foo_0.ts' is not a module.
// Import should fail. foo_0 not an external module
if(foo.answer === 42){

View File

@@ -5,10 +5,10 @@ tests/cases/compiler/invalidTripleSlashReference.ts(2,1): error TS6053: File 'te
==== tests/cases/compiler/invalidTripleSlashReference.ts (2 errors) ====
/// <reference path='filedoesnotexist.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'filedoesnotexist.ts' not found.
!!! error TS6053: File 'tests/cases/compiler/filedoesnotexist.ts' not found.
/// <reference path='otherdoesnotexist.d.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'otherdoesnotexist.d.ts' not found.
!!! error TS6053: File 'tests/cases/compiler/otherdoesnotexist.d.ts' not found.
// this test doesn't actually give the errors you want due to the way the compiler reports errors
var x = 1;

View File

@@ -1,7 +1,7 @@
error TS5055: Cannot write file 'tests/cases/compiler/a.d.ts' because it would overwrite input file.
!!! error TS5055: Cannot write file 'a.d.ts' because it would overwrite input file.
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.d.ts' because it would overwrite input file.
==== tests/cases/compiler/a.ts (0 errors) ====
class c {
}

View File

@@ -1,7 +1,7 @@
error TS5055: Cannot write file 'tests/cases/compiler/b.d.ts' because it would overwrite input file.
!!! error TS5055: Cannot write file 'b.d.ts' because it would overwrite input file.
!!! error TS5055: Cannot write file 'tests/cases/compiler/b.d.ts' because it would overwrite input file.
==== tests/cases/compiler/a.ts (0 errors) ====
class c {
}

View File

@@ -18,7 +18,7 @@
==== /node_modules/bar/index.d.ts (1 errors) ====
/// <reference types="alpha" />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! message TS4090: Conflicting library definitions for 'alpha' found at 'index.d.ts' and 'index.d.ts'. Copy the correct file to the 'typings' folder to resolve this conflict.
!!! message TS4090: Conflicting library definitions for 'alpha' found at '/node_modules/bar/node_modules/alpha/index.d.ts' and '/node_modules/foo/node_modules/alpha/index.d.ts'. Copy the correct file to the 'typings' folder to resolve this conflict.
declare var bar: any;
==== /node_modules/bar/node_modules/alpha/index.d.ts (0 errors) ====

View File

@@ -7,7 +7,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource1.ts(4,1): error TS60
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {
export module CompilerDiagnostics {

View File

@@ -348,7 +348,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(449,40): error
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {
export enum TokenID {

View File

@@ -523,7 +523,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {
export class ASTSpan {

View File

@@ -215,7 +215,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource12.ts(524,30): error
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {
export interface IAstWalker {

View File

@@ -122,7 +122,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource13.ts(135,36): error
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript.AstWalkerWithDetailCallback {
export interface AstWalkerDetailCallback {

View File

@@ -166,7 +166,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource14.ts(572,20): error
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {
export function lastOf(items: any[]): any {

View File

@@ -7,7 +7,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource2.ts(4,1): error TS60
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {

View File

@@ -7,7 +7,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource3.ts(4,1): error TS60
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {
// Note: Any addition to the NodeType should also be supported with addition to AstWalkerDetailCallback

View File

@@ -8,7 +8,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource4.ts(195,37): error T
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {

View File

@@ -16,7 +16,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource5.ts(61,65): error TS
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {
// TODO: refactor indent logic for use in emit

View File

@@ -67,7 +67,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource6.ts(215,20): error T
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {
export class TypeCollectionContext {

View File

@@ -309,7 +309,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(828,13): error T
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {
export class Continuation {

View File

@@ -140,7 +140,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource8.ts(454,35): error T
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {

View File

@@ -39,7 +39,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(200,48): error T
///<reference path='typescript.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
module TypeScript {
export class Binder {

View File

@@ -128,16 +128,16 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32):
///<reference path='..\compiler\io.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'io.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/compiler/io.ts' not found.
///<reference path='..\compiler\typescript.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescript.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/compiler/typescript.ts' not found.
///<reference path='..\services\typescriptServices.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'typescriptServices.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/services/typescriptServices.ts' not found.
///<reference path='diff.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'diff.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/RealWorld/diff.ts' not found.
declare var assert: Harness.Assert;
~~~~~~

View File

@@ -146,7 +146,7 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserindenter.ts(736,38):
///<reference path='formatting.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'formatting.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/parser/ecmascript5/RealWorld/formatting.ts' not found.
module Formatting {

View File

@@ -0,0 +1,6 @@
define(["require", "exports", "m1"], function (require, exports, m1) {
"use strict";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number (if direct import of m2 made the m3 module visible).
});

View File

@@ -0,0 +1,40 @@
importHigher/root.ts(6,1): error TS2322: Type 'string' is not assignable to type 'number'.
==== entry.js (0 errors) ====
var m3 = require("m3");
module.exports = {
"a": 42,
"b": "hello, world",
"person": m3.person
};
==== index.js (0 errors) ====
var m2 = require('m2');
/**
* @param {string} p1 The first param
*/
exports.f1 = function(p1) {
return 42;
};
exports.f2 = m2;
==== index.js (0 errors) ====
exports.person = {
"name": "John Doe",
"age": 42
}
==== importHigher/root.ts (1 errors) ====
import * as m1 from "m1";
import * as m2 from "m2";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number (if direct import of m2 made the m3 module visible).
~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.

View File

@@ -0,0 +1,18 @@
{
"scenario": "Verify that a higher import loads a module that was previously skipped",
"projectRoot": "tests/cases/projects/NodeModulesSearch",
"baselineCheck": true,
"declaration": false,
"moduleResolution": "node",
"project": "importHigher",
"resolvedInputFiles": [
"lib.d.ts",
"importHigher/node_modules/m2/entry.js",
"importHigher/node_modules/m1/index.js",
"importHigher/node_modules/m2/node_modules/m3/index.js",
"importHigher/root.ts"
],
"emittedFiles": [
"importHigher/root.js"
]
}

View File

@@ -0,0 +1,5 @@
"use strict";
var m1 = require("m1");
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number (if direct import of m2 made the m3 module visible).

View File

@@ -0,0 +1,40 @@
importHigher/root.ts(6,1): error TS2322: Type 'string' is not assignable to type 'number'.
==== entry.js (0 errors) ====
var m3 = require("m3");
module.exports = {
"a": 42,
"b": "hello, world",
"person": m3.person
};
==== index.js (0 errors) ====
var m2 = require('m2');
/**
* @param {string} p1 The first param
*/
exports.f1 = function(p1) {
return 42;
};
exports.f2 = m2;
==== index.js (0 errors) ====
exports.person = {
"name": "John Doe",
"age": 42
}
==== importHigher/root.ts (1 errors) ====
import * as m1 from "m1";
import * as m2 from "m2";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number (if direct import of m2 made the m3 module visible).
~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.

View File

@@ -0,0 +1,18 @@
{
"scenario": "Verify that a higher import loads a module that was previously skipped",
"projectRoot": "tests/cases/projects/NodeModulesSearch",
"baselineCheck": true,
"declaration": false,
"moduleResolution": "node",
"project": "importHigher",
"resolvedInputFiles": [
"lib.d.ts",
"importHigher/node_modules/m2/entry.js",
"importHigher/node_modules/m1/index.js",
"importHigher/node_modules/m2/node_modules/m3/index.js",
"importHigher/root.ts"
],
"emittedFiles": [
"importHigher/root.js"
]
}

View File

@@ -0,0 +1,6 @@
define(["require", "exports", "m1"], function (require, exports, m1) {
"use strict";
m1.f1("test");
m1.f2.a = "10"; // Error: Should be number
m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any".
});

View File

@@ -0,0 +1,32 @@
maxDepthExceeded/root.ts(3,1): error TS2322: Type 'string' is not assignable to type 'number'.
==== entry.js (0 errors) ====
var m3 = require("m3");
module.exports = {
"a": 42,
"b": "hello, world",
"person": m3.person
};
==== index.js (0 errors) ====
var m2 = require('m2');
/**
* @param {string} p1 The first param
*/
exports.f1 = function(p1) {
return 42;
};
exports.f2 = m2;
==== maxDepthExceeded/root.ts (1 errors) ====
import * as m1 from "m1";
m1.f1("test");
m1.f2.a = "10"; // Error: Should be number
~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any".

View File

@@ -0,0 +1,17 @@
{
"scenario": "Verify that JavaScript modules are not resolved if too many hops",
"projectRoot": "tests/cases/projects/NodeModulesSearch",
"baselineCheck": true,
"declaration": false,
"moduleResolution": "node",
"project": "maxDepthExceeded",
"resolvedInputFiles": [
"lib.d.ts",
"maxDepthExceeded/node_modules/m2/entry.js",
"maxDepthExceeded/node_modules/m1/index.js",
"maxDepthExceeded/root.ts"
],
"emittedFiles": [
"maxDepthExceeded/root.js"
]
}

View File

@@ -0,0 +1,5 @@
"use strict";
var m1 = require("m1");
m1.f1("test");
m1.f2.a = "10"; // Error: Should be number
m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any".

View File

@@ -0,0 +1,32 @@
maxDepthExceeded/root.ts(3,1): error TS2322: Type 'string' is not assignable to type 'number'.
==== entry.js (0 errors) ====
var m3 = require("m3");
module.exports = {
"a": 42,
"b": "hello, world",
"person": m3.person
};
==== index.js (0 errors) ====
var m2 = require('m2');
/**
* @param {string} p1 The first param
*/
exports.f1 = function(p1) {
return 42;
};
exports.f2 = m2;
==== maxDepthExceeded/root.ts (1 errors) ====
import * as m1 from "m1";
m1.f1("test");
m1.f2.a = "10"; // Error: Should be number
~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any".

View File

@@ -0,0 +1,17 @@
{
"scenario": "Verify that JavaScript modules are not resolved if too many hops",
"projectRoot": "tests/cases/projects/NodeModulesSearch",
"baselineCheck": true,
"declaration": false,
"moduleResolution": "node",
"project": "maxDepthExceeded",
"resolvedInputFiles": [
"lib.d.ts",
"maxDepthExceeded/node_modules/m2/entry.js",
"maxDepthExceeded/node_modules/m1/index.js",
"maxDepthExceeded/root.ts"
],
"emittedFiles": [
"maxDepthExceeded/root.js"
]
}

View File

@@ -0,0 +1,6 @@
define(["require", "exports", "m1"], function (require, exports, m1) {
"use strict";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number
});

View File

@@ -0,0 +1,38 @@
maxDepthIncreased/root.ts(4,1): error TS2322: Type 'string' is not assignable to type 'number'.
==== index.js (0 errors) ====
exports.person = {
"name": "John Doe",
"age": 42
}
==== entry.js (0 errors) ====
var m3 = require("m3");
module.exports = {
"a": 42,
"b": "hello, world",
"person": m3.person
};
==== index.js (0 errors) ====
var m2 = require('m2');
/**
* @param {string} p1 The first param
*/
exports.f1 = function(p1) {
return 42;
};
exports.f2 = m2;
==== maxDepthIncreased/root.ts (1 errors) ====
import * as m1 from "m1";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number
~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.

View File

@@ -0,0 +1,18 @@
{
"scenario": "Verify that the setting to search node_modules deeper takes effect",
"projectRoot": "tests/cases/projects/NodeModulesSearch",
"baselineCheck": true,
"declaration": false,
"moduleResolution": "node",
"project": "maxDepthIncreased",
"resolvedInputFiles": [
"lib.d.ts",
"maxDepthIncreased/node_modules/m2/node_modules/m3/index.js",
"maxDepthIncreased/node_modules/m2/entry.js",
"maxDepthIncreased/node_modules/m1/index.js",
"maxDepthIncreased/root.ts"
],
"emittedFiles": [
"maxDepthIncreased/root.js"
]
}

View File

@@ -0,0 +1,5 @@
"use strict";
var m1 = require("m1");
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number

View File

@@ -0,0 +1,38 @@
maxDepthIncreased/root.ts(4,1): error TS2322: Type 'string' is not assignable to type 'number'.
==== index.js (0 errors) ====
exports.person = {
"name": "John Doe",
"age": 42
}
==== entry.js (0 errors) ====
var m3 = require("m3");
module.exports = {
"a": 42,
"b": "hello, world",
"person": m3.person
};
==== index.js (0 errors) ====
var m2 = require('m2');
/**
* @param {string} p1 The first param
*/
exports.f1 = function(p1) {
return 42;
};
exports.f2 = m2;
==== maxDepthIncreased/root.ts (1 errors) ====
import * as m1 from "m1";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number
~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.

View File

@@ -0,0 +1,18 @@
{
"scenario": "Verify that the setting to search node_modules deeper takes effect",
"projectRoot": "tests/cases/projects/NodeModulesSearch",
"baselineCheck": true,
"declaration": false,
"moduleResolution": "node",
"project": "maxDepthIncreased",
"resolvedInputFiles": [
"lib.d.ts",
"maxDepthIncreased/node_modules/m2/node_modules/m3/index.js",
"maxDepthIncreased/node_modules/m2/entry.js",
"maxDepthIncreased/node_modules/m1/index.js",
"maxDepthIncreased/root.ts"
],
"emittedFiles": [
"maxDepthIncreased/root.js"
]
}

View File

@@ -1,7 +1,7 @@
error TS6059: File 'FolderA/FolderB/fileB.ts' is not under 'rootDir' 'FolderA/FolderB/FolderC'. 'rootDir' is expected to contain all source files.
!!! error TS6059: File 'fileB.ts' is not under 'rootDir' 'FolderA/FolderB/FolderC'. 'rootDir' is expected to contain all source files.
!!! error TS6059: File 'FolderA/FolderB/fileB.ts' is not under 'rootDir' 'FolderA/FolderB/FolderC'. 'rootDir' is expected to contain all source files.
==== FolderA/FolderB/FolderC/fileC.ts (0 errors) ====
class C {
}

View File

@@ -1,7 +1,7 @@
error TS6059: File 'FolderA/FolderB/fileB.ts' is not under 'rootDir' 'FolderA/FolderB/FolderC'. 'rootDir' is expected to contain all source files.
!!! error TS6059: File 'fileB.ts' is not under 'rootDir' 'FolderA/FolderB/FolderC'. 'rootDir' is expected to contain all source files.
!!! error TS6059: File 'FolderA/FolderB/fileB.ts' is not under 'rootDir' 'FolderA/FolderB/FolderC'. 'rootDir' is expected to contain all source files.
==== FolderA/FolderB/FolderC/fileC.ts (0 errors) ====
class C {
}

View File

@@ -6,7 +6,7 @@ tests/cases/compiler/requireOfAnEmptyFile1_a.ts(3,21): error TS2306: File 'tests
import fs = require('./requireOfAnEmptyFile1_b');
~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2306: File 'requireOfAnEmptyFile1_b.ts' is not a module.
!!! error TS2306: File 'tests/cases/compiler/requireOfAnEmptyFile1_b.ts' is not a module.
==== tests/cases/compiler/requireOfAnEmptyFile1_b.ts (0 errors) ====

View File

@@ -19,7 +19,7 @@ tests/cases/conformance/scanner/ecmascript5/scannertest1.ts(20,23): error TS2304
==== tests/cases/conformance/scanner/ecmascript5/scannertest1.ts (16 errors) ====
///<reference path='References.ts' />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'References.ts' not found.
!!! error TS6053: File 'tests/cases/conformance/scanner/ecmascript5/References.ts' not found.
class CharacterInfo {
public static isDecimalDigit(c: number): boolean {

View File

@@ -4,7 +4,7 @@ tests/cases/compiler/selfReferencingFile2.ts(1,1): error TS6053: File 'tests/cas
==== tests/cases/compiler/selfReferencingFile2.ts (1 errors) ====
///<reference path='../selfReferencingFile2.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'selfReferencingFile2.ts' not found.
!!! error TS6053: File 'tests/cases/selfReferencingFile2.ts' not found.
class selfReferencingFile2 {

View File

@@ -0,0 +1,18 @@
///<reference path="fourslash.ts" />
// @allowJs: true
// @Filename: node_modules/myMod/index.js
//// module.exports = { n: 3, s: 'foo', b: true };
// @Filename: consumer.js
//// var x = require('myMod');
//// x/**/;
goTo.file('consumer.js');
goTo.marker();
edit.insert('.');
verify.completionListContains("n", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
verify.completionListContains("s", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
verify.completionListContains("b", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
edit.insert('n.');
verify.completionListContains("toFixed", /*displayText:*/ undefined, /*documentation*/ undefined, "method");

View File

@@ -0,0 +1,23 @@
///<reference path="fourslash.ts" />
// @allowJs: true
// @Filename: node_modules/myMod/package.json
//// {"main": "entry.js"}
// @Filename: node_modules/myMod/entry.js
//// module.exports = { n: 3, s: 'foo', b: true };
// @Filename: consumer.js
//// var x = require('myMod');
//// x/**/;
goTo.file('consumer.js');
goTo.marker();
edit.insert('.');
verify.completionListContains("n", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
verify.completionListContains("s", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
verify.completionListContains("b", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
edit.insert('n.');
verify.completionListContains("toFixed", /*displayText:*/ undefined, /*documentation*/ undefined, "method");

View File

@@ -0,0 +1,38 @@
///<reference path="fourslash.ts" />
// @allowJs: true
// @Filename: node_modules/myMod/index.js
//// exports.n = 3;
//// exports.s = 'foo';
//// exports.b = true;
// @Filename: node_modules/anotherMod/index.js
//// exports.x = 3;
//// exports.y = 'foo';
//// /**
//// * @param {(number | boolean)} a The first param
//// * @param {Array<string>} b The second param
//// */
//// exports.z = function(a,b){ return "test"; };
// @Filename: consumer.js
//// import * as x from 'myMod';
//// import {y,z} from 'anotherMod';
//// x/**/;
goTo.file('consumer.js');
goTo.marker();
edit.insert('.');
verify.completionListContains("n", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
verify.completionListContains("s", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
verify.completionListContains("b", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
edit.insert('n.');
verify.completionListContains("toFixed", /*displayText:*/ undefined, /*documentation*/ undefined, "method");
edit.backspace(4);
edit.insert('y.');
verify.completionListContains("toUpperCase", /*displayText:*/ undefined, /*documentation*/ undefined, "method");
edit.backspace(2);
edit.insert('z(');
verify.currentSignatureHelpIs("z(a: number | boolean, b: string[]): string");

View File

@@ -0,0 +1,19 @@
///<reference path="fourslash.ts" />
// @allowJs: true
// @Filename: node_modules/myMod/index.js
//// module.exports = { n: 3, s: 'foo', b: true };
// @Filename: consumer.js
//// import * as x from 'myMod';
//// x/**/;
goTo.file('consumer.js');
goTo.marker();
edit.insert('.');
verify.completionListContains("n", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
verify.completionListContains("s", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
verify.completionListContains("b", /*displayText:*/ undefined, /*documentation*/ undefined, "property");
edit.insert('n.');
verify.completionListContains("toFixed", /*displayText:*/ undefined, /*documentation*/ undefined, "method");

View File

@@ -0,0 +1,8 @@
{
"scenario": "Verify that a higher import loads a module that was previously skipped",
"projectRoot": "tests/cases/projects/NodeModulesSearch",
"baselineCheck": true,
"declaration": false,
"moduleResolution": "node",
"project": "importHigher"
}

View File

@@ -0,0 +1,8 @@
{
"scenario": "Verify that JavaScript modules are not resolved if too many hops",
"projectRoot": "tests/cases/projects/NodeModulesSearch",
"baselineCheck": true,
"declaration": false,
"moduleResolution": "node",
"project": "maxDepthExceeded"
}

View File

@@ -0,0 +1,8 @@
{
"scenario": "Verify that the setting to search node_modules deeper takes effect",
"projectRoot": "tests/cases/projects/NodeModulesSearch",
"baselineCheck": true,
"declaration": false,
"moduleResolution": "node",
"project": "maxDepthIncreased"
}

View File

@@ -0,0 +1,10 @@
var m2 = require('m2');
/**
* @param {string} p1 The first param
*/
exports.f1 = function(p1) {
return 42;
};
exports.f2 = m2;

View File

@@ -0,0 +1,7 @@
var m3 = require("m3");
module.exports = {
"a": 42,
"b": "hello, world",
"person": m3.person
};

View File

@@ -0,0 +1,4 @@
exports.person = {
"name": "John Doe",
"age": 42
}

View File

@@ -0,0 +1,3 @@
{
"main": "entry.js"
}

View File

@@ -0,0 +1,6 @@
import * as m1 from "m1";
import * as m2 from "m2";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number (if direct import of m2 made the m3 module visible).

View File

@@ -0,0 +1,7 @@
{
"compilerOptions": {
"allowJs": true,
"declaration": false,
"moduleResolution": "node"
}
}

View File

@@ -0,0 +1,10 @@
var m2 = require('m2');
/**
* @param {string} p1 The first param
*/
exports.f1 = function(p1) {
return 42;
};
exports.f2 = m2;

View File

@@ -0,0 +1,7 @@
var m3 = require("m3");
module.exports = {
"a": 42,
"b": "hello, world",
"person": m3.person
};

View File

@@ -0,0 +1,4 @@
exports.person = {
"name": "John Doe",
"age": 42
}

View File

@@ -0,0 +1,3 @@
{
"main": "entry.js"
}

View File

@@ -0,0 +1,4 @@
import * as m1 from "m1";
m1.f1("test");
m1.f2.a = "10"; // Error: Should be number
m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any".

View File

@@ -0,0 +1,5 @@
{
"compilerOptions": {
"allowJs": true
}
}

View File

@@ -0,0 +1,10 @@
var m2 = require('m2');
/**
* @param {string} p1 The first param
*/
exports.f1 = function(p1) {
return 42;
};
exports.f2 = m2;

View File

@@ -0,0 +1,7 @@
var m3 = require("m3");
module.exports = {
"a": 42,
"b": "hello, world",
"person": m3.person
};

View File

@@ -0,0 +1,4 @@
exports.person = {
"name": "John Doe",
"age": 42
}

View File

@@ -0,0 +1,3 @@
{
"main": "entry.js"
}

View File

@@ -0,0 +1,4 @@
import * as m1 from "m1";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number

View File

@@ -0,0 +1,6 @@
{
"compilerOptions": {
"allowJs": true,
"maxNodeModuleJsDepth": 3
}
}