Skip to content

Commit 30462e1

Browse files
author
Andy Hanson
committed
Merge branch 'master' into map5
2 parents 37e18d9 + 5e6c5ef commit 30462e1

File tree

15 files changed

+206
-49
lines changed

15 files changed

+206
-49
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,9 +3135,8 @@ namespace ts {
31353135
for (const prop of getPropertiesOfType(source)) {
31363136
const inNamesToRemove = names.has(prop.name);
31373137
const isPrivate = getDeclarationModifierFlagsFromSymbol(prop) & (ModifierFlags.Private | ModifierFlags.Protected);
3138-
const isMethod = prop.flags & SymbolFlags.Method;
31393138
const isSetOnlyAccessor = prop.flags & SymbolFlags.SetAccessor && !(prop.flags & SymbolFlags.GetAccessor);
3140-
if (!inNamesToRemove && !isPrivate && !isMethod && !isSetOnlyAccessor) {
3139+
if (!inNamesToRemove && !isPrivate && !isClassMethod(prop) && !isSetOnlyAccessor) {
31413140
members.set(prop.name, prop);
31423141
}
31433142
}

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3247,7 +3247,7 @@
32473247
"category": "Message",
32483248
"code": 90003
32493249
},
3250-
"Remove unused identifiers.": {
3250+
"Remove declaration for: {0}": {
32513251
"category": "Message",
32523252
"code": 90004
32533253
},

src/harness/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ namespace FourSlash {
21412141

21422142
public verifyBraceCompletionAtPosition(negative: boolean, openingBrace: string) {
21432143

2144-
const openBraceMap = ts.createMap<ts.CharacterCodes>({
2144+
const openBraceMap = ts.createMapFromTemplate<ts.CharacterCodes>({
21452145
"(": ts.CharacterCodes.openParen,
21462146
"{": ts.CharacterCodes.openBrace,
21472147
"[": ts.CharacterCodes.openBracket,

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ namespace Harness {
909909
export const defaultLibFileName = "lib.d.ts";
910910
export const es2015DefaultLibFileName = "lib.es2015.d.ts";
911911

912-
const libFileNameSourceFileMap = ts.createMap<ts.SourceFile>({
912+
const libFileNameSourceFileMap = ts.createMapFromTemplate<ts.SourceFile>({
913913
[defaultLibFileName]: createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es5.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest)
914914
});
915915

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ namespace ts.projectSystem {
16161616
const configureHostRequest = makeSessionRequest<protocol.ConfigureRequestArguments>(CommandNames.Configure, { extraFileExtensions });
16171617
session.executeCommand(configureHostRequest).response;
16181618

1619-
// HTML file still not included in the project as it is closed
1619+
// HTML file still not included in the project as it is closed
16201620
checkNumberOfProjects(projectService, { configuredProjects: 1 });
16211621
checkProjectActualFiles(projectService.configuredProjects[0], [file1.path]);
16221622

@@ -3047,4 +3047,59 @@ namespace ts.projectSystem {
30473047
service.checkNumberOfProjects({ externalProjects: 1 });
30483048
});
30493049
});
3050+
3051+
describe("maxNodeModuleJsDepth for inferred projects", () => {
3052+
it("should be set to 2 if the project has js root files", () => {
3053+
const file1: FileOrFolder = {
3054+
path: "/a/b/file1.js",
3055+
content: `var t = require("test"); t.`
3056+
};
3057+
const moduleFile: FileOrFolder = {
3058+
path: "/a/b/node_modules/test/index.js",
3059+
content: `var v = 10; module.exports = v;`
3060+
};
3061+
3062+
const host = createServerHost([file1, moduleFile]);
3063+
const projectService = createProjectService(host);
3064+
projectService.openClientFile(file1.path);
3065+
3066+
let project = projectService.inferredProjects[0];
3067+
let options = project.getCompilerOptions();
3068+
assert.isTrue(options.maxNodeModuleJsDepth === 2);
3069+
3070+
// Assert the option sticks
3071+
projectService.setCompilerOptionsForInferredProjects({ target: ScriptTarget.ES2016 });
3072+
project = projectService.inferredProjects[0];
3073+
options = project.getCompilerOptions();
3074+
assert.isTrue(options.maxNodeModuleJsDepth === 2);
3075+
});
3076+
3077+
it("should return to normal state when all js root files are removed from project", () => {
3078+
const file1 = {
3079+
path: "/a/file1.ts",
3080+
content: "let x =1;"
3081+
};
3082+
const file2 = {
3083+
path: "/a/file2.js",
3084+
content: "let x =1;"
3085+
};
3086+
3087+
const host = createServerHost([file1, file2, libFile]);
3088+
const projectService = createProjectService(host, { useSingleInferredProject: true });
3089+
3090+
projectService.openClientFile(file1.path);
3091+
checkNumberOfInferredProjects(projectService, 1);
3092+
let project = projectService.inferredProjects[0];
3093+
assert.isUndefined(project.getCompilerOptions().maxNodeModuleJsDepth);
3094+
3095+
projectService.openClientFile(file2.path);
3096+
project = projectService.inferredProjects[0];
3097+
assert.isTrue(project.getCompilerOptions().maxNodeModuleJsDepth === 2);
3098+
3099+
projectService.closeClientFile(file2.path);
3100+
project = projectService.inferredProjects[0];
3101+
assert.isUndefined(project.getCompilerOptions().maxNodeModuleJsDepth);
3102+
});
3103+
});
3104+
30503105
}

src/harness/unittests/typingsInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ namespace ts.projectSystem {
944944
content: ""
945945
};
946946
const host = createServerHost([f, node]);
947-
const cache = createMap<string>({ "node": node.path });
947+
const cache = createMapFromTemplate<string>({ "node": node.path });
948948
const result = JsTyping.discoverTypings(host, [f.path], getDirectoryPath(<Path>f.path), /*safeListPath*/ undefined, cache, { enable: true }, ["fs", "bar"]);
949949
assert.deepEqual(result.cachedTypingPaths, [node.path]);
950950
assert.deepEqual(result.newTypingNames, ["bar"]);

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ namespace ts.server {
845845
files: parsedCommandLine.fileNames,
846846
compilerOptions: parsedCommandLine.options,
847847
configHasFilesProperty: config["files"] !== undefined,
848-
wildcardDirectories: createMap(parsedCommandLine.wildcardDirectories),
848+
wildcardDirectories: createMapFromTemplate(parsedCommandLine.wildcardDirectories),
849849
typeAcquisition: parsedCommandLine.typeAcquisition,
850850
compileOnSave: parsedCommandLine.compileOnSave
851851
};

src/server/project.ts

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,9 @@ namespace ts.server {
396396
}
397397

398398
removeFile(info: ScriptInfo, detachFromProject = true) {
399-
this.removeRootFileIfNecessary(info);
399+
if (this.isRoot(info)) {
400+
this.removeRoot(info);
401+
}
400402
this.lsHost.notifyFileRemoved(info);
401403
this.cachedUnresolvedImportsPerFile.remove(info.path);
402404

@@ -567,9 +569,6 @@ namespace ts.server {
567569

568570
setCompilerOptions(compilerOptions: CompilerOptions) {
569571
if (compilerOptions) {
570-
if (this.projectKind === ProjectKind.Inferred) {
571-
compilerOptions.allowJs = true;
572-
}
573572
compilerOptions.allowNonTsExtensions = true;
574573
if (changesAffectModuleResolution(this.compilerOptions, compilerOptions)) {
575574
// reset cached unresolved imports if changes in compiler options affected module resolution
@@ -698,11 +697,9 @@ namespace ts.server {
698697
}
699698

700699
// remove a root file from project
701-
private removeRootFileIfNecessary(info: ScriptInfo): void {
702-
if (this.isRoot(info)) {
703-
remove(this.rootFiles, info);
704-
this.rootFilesMap.remove(info.path);
705-
}
700+
protected removeRoot(info: ScriptInfo): void {
701+
remove(this.rootFiles, info);
702+
this.rootFilesMap.remove(info.path);
706703
}
707704
}
708705

@@ -717,6 +714,32 @@ namespace ts.server {
717714
}
718715
})();
719716

717+
private _isJsInferredProject = false;
718+
719+
toggleJsInferredProject(isJsInferredProject: boolean) {
720+
if (isJsInferredProject !== this._isJsInferredProject) {
721+
this._isJsInferredProject = isJsInferredProject;
722+
this.setCompilerOptions();
723+
}
724+
}
725+
726+
setCompilerOptions(options?: CompilerOptions) {
727+
// Avoid manipulating the given options directly
728+
const newOptions = options ? clone(options) : this.getCompilerOptions();
729+
if (!newOptions) {
730+
return;
731+
}
732+
733+
if (this._isJsInferredProject && typeof newOptions.maxNodeModuleJsDepth !== "number") {
734+
newOptions.maxNodeModuleJsDepth = 2;
735+
}
736+
else if (!this._isJsInferredProject) {
737+
newOptions.maxNodeModuleJsDepth = undefined;
738+
}
739+
newOptions.allowJs = true;
740+
super.setCompilerOptions(newOptions);
741+
}
742+
720743
// Used to keep track of what directories are watched for this project
721744
directoriesWatchedForTsconfig: string[] = [];
722745

@@ -731,6 +754,22 @@ namespace ts.server {
731754
/*compileOnSaveEnabled*/ false);
732755
}
733756

757+
addRoot(info: ScriptInfo) {
758+
if (!this._isJsInferredProject && info.isJavaScript()) {
759+
this.toggleJsInferredProject(/*isJsInferredProject*/ true);
760+
}
761+
super.addRoot(info);
762+
}
763+
764+
removeRoot(info: ScriptInfo) {
765+
if (this._isJsInferredProject && info.isJavaScript()) {
766+
if (filter(this.getRootScriptInfos(), info => info.isJavaScript()).length === 0) {
767+
this.toggleJsInferredProject(/*isJsInferredProject*/ false);
768+
}
769+
}
770+
super.removeRoot(info);
771+
}
772+
734773
getProjectRootPath() {
735774
// Single inferred project does not have a project root.
736775
if (this.projectService.useSingleInferredProject) {

src/server/scriptInfo.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,5 +355,9 @@ namespace ts.server {
355355
positionToLineOffset(position: number): ILineInfo {
356356
return this.textStorage.positionToLineOffset(position);
357357
}
358+
359+
public isJavaScript() {
360+
return this.scriptKind === ScriptKind.JS || this.scriptKind === ScriptKind.JSX;
361+
}
358362
}
359363
}

src/server/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ namespace ts.server {
13901390
return { response, responseRequired: true };
13911391
}
13921392

1393-
private handlers = createMap<(request: protocol.Request) => { response?: any, responseRequired?: boolean }>({
1393+
private handlers = createMapFromTemplate<(request: protocol.Request) => { response?: any, responseRequired?: boolean }>({
13941394
[CommandNames.OpenExternalProject]: (request: protocol.OpenExternalProjectRequest) => {
13951395
this.projectService.openExternalProject(request.arguments, /*suppressRefreshOfInferredProjects*/ false);
13961396
// TODO: report errors

0 commit comments

Comments
 (0)