Skip to content

Commit 346a865

Browse files
author
Andy Hanson
committed
Merge branch 'master' into map5
2 parents 145f0b2 + b82fe52 commit 346a865

File tree

86 files changed

+1097
-1099
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1097
-1099
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17278,7 +17278,7 @@ namespace ts {
1727817278
}
1727917279

1728017280
if (node.kind === SyntaxKind.BindingElement) {
17281-
if (node.parent.kind === SyntaxKind.ObjectBindingPattern && languageVersion < ScriptTarget.ESNext) {
17281+
if (node.parent.kind === SyntaxKind.ObjectBindingPattern && languageVersion < ScriptTarget.ESNext && !isInAmbientContext(node)) {
1728217282
checkExternalEmitHelpers(node, ExternalEmitHelpers.Rest);
1728317283
}
1728417284
// check computed properties inside property names of binding elements

src/compiler/diagnosticMessages.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,7 +2757,7 @@
27572757
"category": "Message",
27582758
"code": 6094
27592759
},
2760-
"Loading module as file / folder, candidate module location '{0}'.": {
2760+
"Loading module as file / folder, candidate module location '{0}', target file type '{1}'.": {
27612761
"category": "Message",
27622762
"code": 6095
27632763
},
@@ -2769,7 +2769,7 @@
27692769
"category": "Message",
27702770
"code": 6097
27712771
},
2772-
"Loading module '{0}' from 'node_modules' folder.": {
2772+
"Loading module '{0}' from 'node_modules' folder, target file type '{1}'.": {
27732773
"category": "Message",
27742774
"code": 6098
27752775
},
@@ -2965,10 +2965,14 @@
29652965
"category": "Message",
29662966
"code": 6146
29672967
},
2968-
"Resolution for module '{0}' was found in cache": {
2968+
"Resolution for module '{0}' was found in cache.": {
29692969
"category": "Message",
29702970
"code": 6147
29712971
},
2972+
"Directory '{0}' does not exist, skipping all lookups in it.": {
2973+
"category": "Message",
2974+
"code": 6148
2975+
},
29722976
"Variable '{0}' implicitly has an '{1}' type.": {
29732977
"category": "Error",
29742978
"code": 7005

src/compiler/emitter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,6 @@ namespace ts {
670670
// Transformation nodes
671671
case SyntaxKind.PartiallyEmittedExpression:
672672
return emitPartiallyEmittedExpression(<PartiallyEmittedExpression>node);
673-
case SyntaxKind.RawExpression:
674-
return writeLines((<RawExpression>node).text);
675673
}
676674
}
677675

src/compiler/factory.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,19 +1530,6 @@ namespace ts {
15301530
return node;
15311531
}
15321532

1533-
/**
1534-
* Creates a node that emits a string of raw text in an expression position. Raw text is never
1535-
* transformed, should be ES3 compliant, and should have the same precedence as
1536-
* PrimaryExpression.
1537-
*
1538-
* @param text The raw text of the node.
1539-
*/
1540-
export function createRawExpression(text: string) {
1541-
const node = <RawExpression>createNode(SyntaxKind.RawExpression);
1542-
node.text = text;
1543-
return node;
1544-
}
1545-
15461533
// Compound nodes
15471534

15481535
export function createComma(left: Expression, right: Expression) {

src/compiler/moduleNameResolver.ts

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace ts {
3232
* Kinds of file that we are currently looking for.
3333
* Typically there is one pass with Extensions.TypeScript, then a second pass with Extensions.JavaScript.
3434
*/
35-
const enum Extensions {
35+
enum Extensions {
3636
TypeScript, /** '.ts', '.tsx', or '.d.ts' */
3737
JavaScript, /** '.js' or '.jsx' */
3838
DtsOnly /** Only '.d.ts' */
@@ -217,9 +217,13 @@ namespace ts {
217217
return forEach(typeRoots, typeRoot => {
218218
const candidate = combinePaths(typeRoot, typeReferenceDirectiveName);
219219
const candidateDirectory = getDirectoryPath(candidate);
220+
const directoryExists = directoryProbablyExists(candidateDirectory, host);
221+
if (!directoryExists && traceEnabled) {
222+
trace(host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, candidateDirectory);
223+
}
220224
return resolvedTypeScriptOnly(
221225
loadNodeModuleFromDirectory(Extensions.DtsOnly, candidate, failedLookupLocations,
222-
!directoryProbablyExists(candidateDirectory, host), moduleResolutionState));
226+
!directoryExists, moduleResolutionState));
223227
});
224228
}
225229
else {
@@ -701,7 +705,7 @@ namespace ts {
701705

702706
if (moduleHasNonRelativeName(moduleName)) {
703707
if (traceEnabled) {
704-
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName);
708+
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);
705709
}
706710
const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state, cache);
707711
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.
@@ -729,11 +733,33 @@ namespace ts {
729733

730734
function nodeLoadModuleByRelativeName(extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
731735
if (state.traceEnabled) {
732-
trace(state.host, Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0, candidate);
736+
trace(state.host, Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0_target_file_type_1, candidate, Extensions[extensions]);
733737
}
734-
735-
const resolvedFromFile = !pathEndsWithDirectorySeparator(candidate) && loadModuleFromFile(extensions, candidate, failedLookupLocations, onlyRecordFailures, state);
736-
return resolvedFromFile || loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, onlyRecordFailures, state);
738+
if (!pathEndsWithDirectorySeparator(candidate)) {
739+
if (!onlyRecordFailures) {
740+
const parentOfCandidate = getDirectoryPath(candidate);
741+
if (!directoryProbablyExists(parentOfCandidate, state.host)) {
742+
if (state.traceEnabled) {
743+
trace(state.host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, parentOfCandidate);
744+
}
745+
onlyRecordFailures = true;
746+
}
747+
}
748+
const resolvedFromFile = loadModuleFromFile(extensions, candidate, failedLookupLocations, onlyRecordFailures, state);
749+
if (resolvedFromFile) {
750+
return resolvedFromFile;
751+
}
752+
}
753+
if (!onlyRecordFailures) {
754+
const candidateExists = directoryProbablyExists(candidate, state.host);
755+
if (!candidateExists) {
756+
if (state.traceEnabled) {
757+
trace(state.host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, candidate);
758+
}
759+
onlyRecordFailures = true;
760+
}
761+
}
762+
return loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, onlyRecordFailures, state);
737763
}
738764

739765
/* @internal */
@@ -792,19 +818,21 @@ namespace ts {
792818

793819
/** Return the file if it exists. */
794820
function tryFile(fileName: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined {
795-
if (!onlyRecordFailures && state.host.fileExists(fileName)) {
796-
if (state.traceEnabled) {
797-
trace(state.host, Diagnostics.File_0_exist_use_it_as_a_name_resolution_result, fileName);
821+
if (!onlyRecordFailures) {
822+
if (state.host.fileExists(fileName)) {
823+
if (state.traceEnabled) {
824+
trace(state.host, Diagnostics.File_0_exist_use_it_as_a_name_resolution_result, fileName);
825+
}
826+
return fileName;
798827
}
799-
return fileName;
800-
}
801-
else {
802-
if (state.traceEnabled) {
803-
trace(state.host, Diagnostics.File_0_does_not_exist, fileName);
828+
else {
829+
if (state.traceEnabled) {
830+
trace(state.host, Diagnostics.File_0_does_not_exist, fileName);
831+
}
804832
}
805-
failedLookupLocations.push(fileName);
806-
return undefined;
807833
}
834+
failedLookupLocations.push(fileName);
835+
return undefined;
808836
}
809837

810838
function loadNodeModuleFromDirectory(extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
@@ -841,7 +869,7 @@ namespace ts {
841869
}
842870
}
843871
else {
844-
if (state.traceEnabled) {
872+
if (directoryExists && state.traceEnabled) {
845873
trace(state.host, Diagnostics.File_0_does_not_exist, packageJsonPath);
846874
}
847875
// record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results
@@ -873,9 +901,7 @@ namespace ts {
873901
return combinePaths(directory, "package.json");
874902
}
875903

876-
function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
877-
const nodeModulesFolder = combinePaths(directory, "node_modules");
878-
const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host);
904+
function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, nodeModulesFolder: string, nodeModulesFolderExists: boolean, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
879905
const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName));
880906

881907
return loadModuleFromFile(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state) ||
@@ -905,12 +931,26 @@ namespace ts {
905931

906932
/** Load a module from a single node_modules directory, but not from any ancestors' node_modules directories. */
907933
function loadModuleFromNodeModulesOneLevel(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState, typesOnly = false): Resolved | undefined {
908-
const packageResult = typesOnly ? undefined : loadModuleFromNodeModulesFolder(extensions, moduleName, directory, failedLookupLocations, state);
934+
const nodeModulesFolder = combinePaths(directory, "node_modules");
935+
const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host);
936+
if (!nodeModulesFolderExists && state.traceEnabled) {
937+
trace(state.host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, nodeModulesFolder);
938+
}
939+
940+
const packageResult = typesOnly ? undefined : loadModuleFromNodeModulesFolder(extensions, moduleName, nodeModulesFolder, nodeModulesFolderExists, failedLookupLocations, state);
909941
if (packageResult) {
910942
return packageResult;
911943
}
912944
if (extensions !== Extensions.JavaScript) {
913-
return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, combinePaths("@types", moduleName), directory, failedLookupLocations, state);
945+
const nodeModulesAtTypes = combinePaths(nodeModulesFolder, "@types");
946+
let nodeModulesAtTypesExists = nodeModulesFolderExists;
947+
if (nodeModulesFolderExists && !directoryProbablyExists(nodeModulesAtTypes, state.host)) {
948+
if (state.traceEnabled) {
949+
trace(state.host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, nodeModulesAtTypes);
950+
}
951+
nodeModulesAtTypesExists = false;
952+
}
953+
return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, moduleName, nodeModulesAtTypes, nodeModulesAtTypesExists, failedLookupLocations, state);
914954
}
915955
}
916956

0 commit comments

Comments
 (0)