Skip to content

Commit b3d901f

Browse files
author
Andy Hanson
committed
Merge branch 'master' into duplicatePackageImportFixes
2 parents ec34d03 + dd4fd8c commit b3d901f

File tree

165 files changed

+3322
-2340
lines changed

Some content is hidden

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

165 files changed

+3322
-2340
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ Jakefile.js
1919
.circleci
2020
.vscode/
2121
.parallelperf.json
22+
.mailmap
2223
test.config
2324
package-lock.json
2425
yarn.lock
2526
.github/
2627
CONTRIBUTING.md
28+
TEST-results.xml

src/compiler/binder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,10 @@ namespace ts {
20722072
if (isSpecialPropertyDeclaration(node as PropertyAccessExpression)) {
20732073
bindSpecialPropertyDeclaration(node as PropertyAccessExpression);
20742074
}
2075+
if (isInJavaScriptFile(node) && isModuleExportsPropertyAccessExpression(node as PropertyAccessExpression)) {
2076+
declareSymbol(container.locals!, /*parent*/ undefined, (node as PropertyAccessExpression).expression as Identifier,
2077+
SymbolFlags.FunctionScopedVariable | SymbolFlags.ModuleExports, SymbolFlags.FunctionScopedVariableExcludes);
2078+
}
20752079
break;
20762080
case SyntaxKind.BinaryExpression:
20772081
const specialKind = getSpecialPropertyAssignmentKind(node as BinaryExpression);

src/compiler/checker.ts

Lines changed: 189 additions & 173 deletions
Large diffs are not rendered by default.

src/compiler/comments.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ namespace ts {
7272
const savedContainerEnd = containerEnd;
7373
const savedDeclarationListContainerEnd = declarationListContainerEnd;
7474

75-
if (!skipLeadingComments) {
75+
if (!skipLeadingComments || (pos >= 0 && (emitFlags & EmitFlags.NoLeadingComments) !== 0)) {
76+
// Advance the container position of comments get emitted or if they've been disabled explicitly using NoLeadingComments.
7677
containerPos = pos;
7778
}
7879

79-
if (!skipTrailingComments) {
80+
if (!skipTrailingComments || (end >= 0 && (emitFlags & EmitFlags.NoTrailingComments) !== 0)) {
81+
// As above.
8082
containerEnd = end;
8183

8284
// To avoid invalid comment emit in a down-level binding pattern, we
@@ -426,4 +428,4 @@ namespace ts {
426428
return isRecognizedTripleSlashComment(currentText, commentPos, commentEnd);
427429
}
428430
}
429-
}
431+
}

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,6 +2417,10 @@
24172417
"category": "Error",
24182418
"code": 2729
24192419
},
2420+
"An arrow function cannot have a 'this' parameter.": {
2421+
"category": "Error",
2422+
"code": 2730
2423+
},
24202424

24212425
"Import declaration '{0}' is using private name '{1}'.": {
24222426
"category": "Error",

src/compiler/emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ namespace ts {
4949
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath };
5050
}
5151
else {
52-
const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options));
52+
const jsFilePath = getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
5353
const sourceMapFilePath = isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options);
5454
// For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error
5555
const isJs = isSourceFileJavaScript(sourceFile);
56-
const declarationFilePath = ((forceDtsPaths || getEmitDeclarations(options)) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;
56+
const declarationFilePath = ((forceDtsPaths || getEmitDeclarations(options)) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined;
5757
const declarationMapPath = getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
5858
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath: undefined };
5959
}

src/compiler/moduleSpecifiers.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,27 +166,23 @@ namespace ts.moduleSpecifiers {
166166
return result;
167167
}
168168

169-
function getAllModulePathsUsingIndirectSymlinks(files: ReadonlyArray<SourceFile>, target: string, getCanonicalFileName: (file: string) => string, host: ModuleSpecifierResolutionHost) {
169+
function getAllModulePathsUsingIndirectSymlinks(files: ReadonlyArray<SourceFile>, targets: ReadonlyArray<string>, getCanonicalFileName: (file: string) => string, host: ModuleSpecifierResolutionHost) {
170170
const links = discoverProbableSymlinks(files, getCanonicalFileName, host);
171171
const paths = arrayFrom(links.keys());
172-
let options: string[] | undefined;
172+
let options = targets.slice();
173173
const compareStrings = (!host.useCaseSensitiveFileNames || host.useCaseSensitiveFileNames()) ? compareStringsCaseSensitive : compareStringsCaseInsensitive;
174174
for (const path of paths) {
175175
const resolved = links.get(path)!;
176-
if (compareStrings(target.slice(0, resolved.length + 1), resolved + "/") === Comparison.EqualTo) {
177-
const relative = getRelativePathFromDirectory(resolved, target, getCanonicalFileName);
176+
const x = targets.find(t => compareStrings(t.slice(0, resolved.length + 1), resolved + "/") === Comparison.EqualTo); //name
177+
if (x !== undefined) {
178+
const relative = getRelativePathFromDirectory(resolved, x, getCanonicalFileName);
178179
const option = resolvePath(path, relative);
179180
if (!host.fileExists || host.fileExists(option)) {
180-
if (!options) options = [];
181181
options.push(option);
182182
}
183183
}
184184
}
185-
if (options) {
186-
options.push(target); // Since these are speculative, we also include the original resolved name as a possibility
187-
return options;
188-
}
189-
return [target];
185+
return options;
190186
}
191187

192188
/**
@@ -196,12 +192,16 @@ namespace ts.moduleSpecifiers {
196192
function getAllModulePaths(files: ReadonlyArray<SourceFile>, importedFileName: string, getCanonicalFileName: (file: string) => string, host: ModuleSpecifierResolutionHost, redirectTargetsMap: RedirectTargetsMap): ReadonlyArray<string> {
197193
const redirects = redirectTargetsMap.get(importedFileName);
198194
const importedFileNames = redirects ? [...redirects, importedFileName] : [importedFileName];
195+
const foo = importedFileNames.map(f => getNormalizedAbsolutePath(f, cwd)); //name
199196
const symlinks = mapDefined(files, sf =>
200197
sf.resolvedModules && firstDefinedIterator(sf.resolvedModules.values(), res =>
201-
res && contains(importedFileNames, res.resolvedFileName) ? res.originalPath : undefined));
202-
return symlinks.length === 0
203-
? flatMap(importedFileNames, importedFileName => getAllModulePathsUsingIndirectSymlinks(files, getNormalizedAbsolutePath(importedFileName, host.getCurrentDirectory ? host.getCurrentDirectory() : ""), getCanonicalFileName, host))
204-
: symlinks;
198+
res && res.resolvedFileName === importedFileName ? res.originalPath : undefined));
199+
const cwd = host.getCurrentDirectory ? host.getCurrentDirectory() : "";
200+
const baseOptions = getAllModulePathsUsingIndirectSymlinks(files, foo, getCanonicalFileName, host);
201+
if (symlinks.length === 0) {
202+
return baseOptions;
203+
}
204+
return deduplicate(concatenate(baseOptions, flatMap(symlinks, f => getAllModulePathsUsingIndirectSymlinks(files, [f], getCanonicalFileName, host))));//!
205205
}
206206

207207
function getRelativePathNParents(relativePath: string): number {
@@ -225,10 +225,7 @@ namespace ts.moduleSpecifiers {
225225
for (const patternText of paths[key]) {
226226
const pattern = removeFileExtension(normalizePath(patternText));
227227
const indexOfStar = pattern.indexOf("*");
228-
if (indexOfStar === 0 && pattern.length === 1) {
229-
continue;
230-
}
231-
else if (indexOfStar !== -1) {
228+
if (indexOfStar !== -1) {
232229
const prefix = pattern.substr(0, indexOfStar);
233230
const suffix = pattern.substr(indexOfStar + 1);
234231
if (relativeToBaseUrl.length >= prefix.length + suffix.length &&

src/compiler/parser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3537,8 +3537,9 @@ namespace ts {
35373537
}
35383538

35393539
// If we had "(" followed by something that's not an identifier,
3540-
// then this definitely doesn't look like a lambda.
3541-
if (!isIdentifier()) {
3540+
// then this definitely doesn't look like a lambda. "this" is not
3541+
// valid, but we want to parse it and then give a semantic error.
3542+
if (!isIdentifier() && second !== SyntaxKind.ThisKeyword) {
35423543
return Tristate.False;
35433544
}
35443545

src/compiler/program.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ namespace ts {
135135

136136
sys.writeFile(fileName, data, writeByteOrderMark);
137137

138-
const mtimeAfter = sys.getModifiedTime!(fileName); // TODO: GH#18217
138+
const mtimeAfter = sys.getModifiedTime!(fileName) || missingFileModifiedTime; // TODO: GH#18217
139139

140140
outputFingerprints.set(fileName, {
141141
hash,
@@ -2009,9 +2009,17 @@ namespace ts {
20092009
if (filesByName.has(path)) {
20102010
const file = filesByName.get(path);
20112011
// try to check if we've already seen this file but with a different casing in path
2012-
// NOTE: this only makes sense for case-insensitive file systems
2013-
if (file && options.forceConsistentCasingInFileNames && getNormalizedAbsolutePath(file.fileName, currentDirectory) !== getNormalizedAbsolutePath(fileName, currentDirectory)) {
2014-
reportFileNamesDifferOnlyInCasingError(fileName, file.fileName, refFile, refPos, refEnd);
2012+
// NOTE: this only makes sense for case-insensitive file systems, and only on files which are not redirected
2013+
if (file && options.forceConsistentCasingInFileNames) {
2014+
let inputName = fileName;
2015+
const checkedName = file.fileName;
2016+
const isRedirect = toPath(checkedName) !== toPath(inputName);
2017+
if (isRedirect) {
2018+
inputName = getProjectReferenceRedirect(fileName) || fileName;
2019+
}
2020+
if (getNormalizedAbsolutePath(checkedName, currentDirectory) !== getNormalizedAbsolutePath(inputName, currentDirectory)) {
2021+
reportFileNamesDifferOnlyInCasingError(inputName, checkedName, refFile, refPos, refEnd);
2022+
}
20152023
}
20162024

20172025
// If the file was previously found via a node_modules search, but is now being processed as a root file,

src/compiler/sourcemap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ namespace ts {
170170
if (sourceFileOrBundle.kind === SyntaxKind.SourceFile) { // emitting single module file
171171
// For modules or multiple emit files the mapRoot will have directory structure like the sources
172172
// So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map
173-
sourceMapDir = getDirectoryPath(getSourceFilePathInNewDir(sourceFileOrBundle, host, sourceMapDir));
173+
sourceMapDir = getDirectoryPath(getSourceFilePathInNewDir(sourceFileOrBundle.fileName, host, sourceMapDir));
174174
}
175175

176176
if (!isRootedDiskPath(sourceMapDir) && !isUrl(sourceMapDir)) {

src/compiler/sourcemapDecoder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace ts.sourcemaps {
6161

6262
export function decode(host: SourceMapDecodeHost, mapPath: string, map: SourceMapData, program?: Program, fallbackCache = createSourceFileLikeCache(host)): SourceMapper {
6363
const currentDirectory = getDirectoryPath(mapPath);
64-
const sourceRoot = map.sourceRoot || currentDirectory;
64+
const sourceRoot = map.sourceRoot ? getNormalizedAbsolutePath(map.sourceRoot, currentDirectory) : currentDirectory;
6565
let decodedMappings: ProcessedSourceMapPosition[];
6666
let generatedOrderedMappings: ProcessedSourceMapPosition[];
6767
let sourceOrderedMappings: ProcessedSourceMapPosition[];
@@ -98,10 +98,10 @@ namespace ts.sourcemaps {
9898

9999
function getSourceFileLike(fileName: string, location: string): SourceFileLike | undefined {
100100
// Lookup file in program, if provided
101-
const file = program && program.getSourceFile(fileName);
101+
const path = toPath(fileName, location, host.getCanonicalFileName);
102+
const file = program && program.getSourceFile(path);
102103
if (!file) {
103104
// Otherwise check the cache (which may hit disk)
104-
const path = toPath(fileName, location, host.getCanonicalFileName);
105105
return fallbackCache.get(path);
106106
}
107107
return file;

src/compiler/symbolWalker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ts {
99
getTypeOfSymbol: (sym: Symbol) => Type,
1010
getResolvedSymbol: (node: Node) => Symbol,
1111
getIndexTypeOfStructuredType: (type: Type, kind: IndexKind) => Type | undefined,
12-
getConstraintFromTypeParameter: (typeParameter: TypeParameter) => Type | undefined,
12+
getConstraintOfTypeParameter: (typeParameter: TypeParameter) => Type | undefined,
1313
getFirstIdentifier: (node: EntityNameOrEntityNameExpression) => Identifier) {
1414

1515
return getSymbolWalker;
@@ -93,7 +93,7 @@ namespace ts {
9393
}
9494

9595
function visitTypeParameter(type: TypeParameter): void {
96-
visitType(getConstraintFromTypeParameter(type));
96+
visitType(getConstraintOfTypeParameter(type));
9797
}
9898

9999
function visitUnionOrIntersectionType(type: UnionOrIntersectionType): void {

src/compiler/sys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ namespace ts {
482482
getCurrentDirectory(): string;
483483
getDirectories(path: string): string[];
484484
readDirectory(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[];
485-
getModifiedTime?(path: string): Date;
485+
getModifiedTime?(path: string): Date | undefined;
486486
setModifiedTime?(path: string, time: Date): void;
487487
deleteFile?(path: string): void;
488488
/**

src/compiler/transformers/es2015.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ namespace ts {
11211121
}
11221122

11231123
// Perform the capture.
1124-
captureThisForNode(statements, ctor, superCallExpression || createActualThis(), firstStatement);
1124+
captureThisForNode(statements, ctor, superCallExpression || createActualThis());
11251125

11261126
// If we're actually replacing the original statement, we need to signal this to the caller.
11271127
if (superCallExpression) {
@@ -1443,7 +1443,7 @@ namespace ts {
14431443
}
14441444
}
14451445

1446-
function captureThisForNode(statements: Statement[], node: Node, initializer: Expression | undefined, originalStatement?: Statement): void {
1446+
function captureThisForNode(statements: Statement[], node: Node, initializer: Expression | undefined): void {
14471447
enableSubstitutionsForCapturedThis();
14481448
const captureThisStatement = createVariableStatement(
14491449
/*modifiers*/ undefined,
@@ -1456,7 +1456,6 @@ namespace ts {
14561456
])
14571457
);
14581458
setEmitFlags(captureThisStatement, EmitFlags.NoComments | EmitFlags.CustomPrologue);
1459-
setTextRange(captureThisStatement, originalStatement);
14601459
setSourceMapRange(captureThisStatement, node);
14611460
statements.push(captureThisStatement);
14621461
}

0 commit comments

Comments
 (0)