Skip to content

Commit a9ed42f

Browse files
author
Gabriela Britto
committed
Merge branch 'master' into qualified-name-param-tag-error
2 parents dd0a612 + 52b8256 commit a9ed42f

File tree

40 files changed

+708
-113
lines changed

40 files changed

+708
-113
lines changed

completionAtDottedNamespace.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////namespace wwer./**/w
4+
5+
verify.completions({ marker: "", exact: [], isNewIdentifierLocation: true });

scripts/build/baselineAccept.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function baselineAccept(subfolder = "") {
1212
}
1313

1414
function baselineCopy(subfolder = "") {
15-
return gulp.src([`${localBaseline}${subfolder ? `${subfolder}/` : ``}**`, `!${localBaseline}${subfolder}/**/*.delete`], { base: localBaseline, read: false })
15+
return gulp.src([`${localBaseline}${subfolder ? `${subfolder}/` : ``}**`, `!${localBaseline}${subfolder}/**/*.delete`], { base: localBaseline })
1616
.pipe(gulp.dest(refBaseline));
1717
}
1818

@@ -21,4 +21,4 @@ function baselineDelete(subfolder = "") {
2121
.pipe(rm())
2222
.pipe(rename({ extname: "" }))
2323
.pipe(rm(refBaseline));
24-
}
24+
}

src/compiler/checker.ts

Lines changed: 82 additions & 73 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@
17761776
"category": "Error",
17771777
"code": 2496
17781778
},
1779-
"Module '{0}' resolves to a non-module entity and cannot be imported using this construct.": {
1779+
"This module can only be referenced with ECMAScript imports/exports by turning on the '{0}' flag and referencing its default export.": {
17801780
"category": "Error",
17811781
"code": 2497
17821782
},

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,7 @@ namespace ts {
18981898
case SyntaxKind.StringLiteral:
18991899
return createIdentifier("String");
19001900

1901+
case SyntaxKind.PrefixUnaryExpression:
19011902
case SyntaxKind.NumericLiteral:
19021903
return createIdentifier("Number");
19031904

src/compiler/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3916,7 +3916,9 @@ namespace ts {
39163916
aliasTypeArguments?: ReadonlyArray<Type>; // Alias type arguments (if any)
39173917
/* @internal */ aliasTypeArgumentsContainsMarker?: boolean; // Alias type arguments (if any)
39183918
/* @internal */
3919-
wildcardInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type
3919+
permissiveInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type
3920+
/* @internal */
3921+
restrictiveInstantiation?: Type; // Instantiation with type parameters mapped to unconstrained form
39203922
/* @internal */
39213923
immediateBaseConstraint?: Type; // Immediate base constraint cache
39223924
}

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@ namespace ts.server {
20082008
const path = toNormalizedPath(uncheckedFileName);
20092009
const info = this.getScriptInfoForNormalizedPath(path);
20102010
if (info) return info;
2011-
const configProject = this.configuredProjects.get(uncheckedFileName);
2011+
const configProject = this.configuredProjects.get(this.toPath(uncheckedFileName));
20122012
return configProject && configProject.getCompilerOptions().configFile;
20132013
}
20142014

src/services/completions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ namespace ts.Completions {
104104
getJSCompletionEntries(sourceFile, location!.pos, uniqueNames, compilerOptions.target!, entries); // TODO: GH#18217
105105
}
106106
else {
107-
if ((!symbols || symbols.length === 0) && keywordFilters === KeywordCompletionFilters.None) {
107+
if (!isNewIdentifierLocation && (!symbols || symbols.length === 0) && keywordFilters === KeywordCompletionFilters.None) {
108108
return undefined;
109109
}
110110

src/services/getEditsForFileRename.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ namespace ts {
151151
const toImport = oldFromNew !== undefined
152152
// If we're at the new location (file was already renamed), need to redo module resolution starting from the old location.
153153
// TODO:GH#18217
154-
? getSourceFileToImportFromResolved(resolveModuleName(importLiteral.text, oldImportFromPath, program.getCompilerOptions(), host as ModuleResolutionHost), oldToNew, host)
154+
? getSourceFileToImportFromResolved(resolveModuleName(importLiteral.text, oldImportFromPath, program.getCompilerOptions(), host as ModuleResolutionHost), oldToNew)
155155
: getSourceFileToImport(importedModuleSymbol, importLiteral, sourceFile, program, host, oldToNew);
156156

157157
// Need an update if the imported file moved, or the importing file moved and was using a relative path.
@@ -192,28 +192,35 @@ namespace ts {
192192
const resolved = host.resolveModuleNames
193193
? host.getResolvedModuleWithFailedLookupLocationsFromCache && host.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName)
194194
: program.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName);
195-
return getSourceFileToImportFromResolved(resolved, oldToNew, host);
195+
return getSourceFileToImportFromResolved(resolved, oldToNew);
196196
}
197197
}
198198

199-
function getSourceFileToImportFromResolved(resolved: ResolvedModuleWithFailedLookupLocations | undefined, oldToNew: PathUpdater, host: LanguageServiceHost): ToImport | undefined {
199+
function getSourceFileToImportFromResolved(resolved: ResolvedModuleWithFailedLookupLocations | undefined, oldToNew: PathUpdater): ToImport | undefined {
200200
// Search through all locations looking for a moved file, and only then test already existing files.
201201
// This is because if `a.ts` is compiled to `a.js` and `a.ts` is moved, we don't want to resolve anything to `a.js`, but to `a.ts`'s new location.
202-
return tryEach(tryGetNewFile) || tryEach(tryGetOldFile);
202+
if (!resolved) return undefined;
203203

204-
function tryEach(cb: (oldFileName: string) => ToImport | undefined): ToImport | undefined {
205-
return resolved && (
206-
(resolved.resolvedModule && cb(resolved.resolvedModule.resolvedFileName)) || firstDefined(resolved.failedLookupLocations, cb));
204+
// First try resolved module
205+
if (resolved.resolvedModule) {
206+
const result = tryChange(resolved.resolvedModule.resolvedFileName);
207+
if (result) return result;
207208
}
208209

209-
function tryGetNewFile(oldFileName: string): ToImport | undefined {
210-
const newFileName = oldToNew(oldFileName);
211-
return newFileName !== undefined && host.fileExists!(newFileName) ? { newFileName, updated: true } : undefined; // TODO: GH#18217
210+
// Then failed lookups except package.json since we dont want to touch them (only included ts/js files)
211+
const result = forEach(resolved.failedLookupLocations, tryChangeWithIgnoringPackageJson);
212+
if (result) return result;
213+
214+
// If nothing changed, then result is resolved module file thats not updated
215+
return resolved.resolvedModule && { newFileName: resolved.resolvedModule.resolvedFileName, updated: false };
216+
217+
function tryChangeWithIgnoringPackageJson(oldFileName: string) {
218+
return !endsWith(oldFileName, "/package.json") ? tryChange(oldFileName) : undefined;
212219
}
213220

214-
function tryGetOldFile(oldFileName: string): ToImport | undefined {
221+
function tryChange(oldFileName: string) {
215222
const newFileName = oldToNew(oldFileName);
216-
return host.fileExists!(oldFileName) ? newFileName !== undefined ? { newFileName, updated: true } : { newFileName: oldFileName, updated: false } : undefined; // TODO: GH#18217
223+
return newFileName && { newFileName, updated: true };
217224
}
218225
}
219226

src/testRunner/unittests/tsserver/refactors.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,40 @@ namespace ts.projectSystem {
116116
renameLocation: undefined,
117117
});
118118
});
119+
120+
it("handles canonicalization of tsconfig path", () => {
121+
const aTs: File = { path: "/Foo/a.ts", content: "const x = 0;" };
122+
const tsconfig: File = { path: "/Foo/tsconfig.json", content: '{ "files": ["./a.ts"] }' };
123+
const session = createSession(createServerHost([aTs, tsconfig]));
124+
openFilesForSession([aTs], session);
125+
126+
const result = executeSessionRequest<protocol.GetEditsForRefactorRequest, protocol.GetEditsForRefactorResponse>(session, protocol.CommandTypes.GetEditsForRefactor, {
127+
file: aTs.path,
128+
startLine: 1,
129+
startOffset: 1,
130+
endLine: 2,
131+
endOffset: aTs.content.length,
132+
refactor: "Move to a new file",
133+
action: "Move to a new file",
134+
});
135+
assert.deepEqual<protocol.RefactorEditInfo | undefined>(result, {
136+
edits: [
137+
{
138+
fileName: aTs.path,
139+
textChanges: [{ start: { line: 1, offset: 1 }, end: { line: 1, offset: aTs.content.length + 1 }, newText: "" }],
140+
},
141+
{
142+
fileName: tsconfig.path,
143+
textChanges: [{ start: { line: 1, offset: 21 }, end: { line: 1, offset: 21 }, newText: ', "./x.ts"' }],
144+
},
145+
{
146+
fileName: "/Foo/x.ts",
147+
textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: "const x = 0;\n" }],
148+
},
149+
],
150+
renameFilename: undefined,
151+
renameLocation: undefined,
152+
});
153+
});
119154
});
120155
}

0 commit comments

Comments
 (0)