Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowJs:true + declaration:true #21455

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/declarationEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ namespace ts {
let addedGlobalFileReference = false;
let allSourcesModuleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[] = [];
forEach(sourceFiles, sourceFile => {
// Dont emit for javascript file
if (isSourceFileJavaScript(sourceFile)) {
// Dont emit for javascript file (unless allowJs is passed)
if (isSourceFileJavaScript(sourceFile) && !compilerOptions.allowJs) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace ts {
for (const sourceFile of sourceFiles) {
const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options));
const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options);
const declarationFilePath = !isSourceFileJavaScript(sourceFile) && (emitOnlyDtsFiles || options.declaration) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;
const declarationFilePath = (!isSourceFileJavaScript(sourceFile) || options.allowJs) && (emitOnlyDtsFiles || options.declaration) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;
const result = action({ jsFilePath, sourceMapFilePath, declarationFilePath }, sourceFile, emitOnlyDtsFiles);
if (result) {
return result;
Expand Down
4 changes: 0 additions & 4 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2193,10 +2193,6 @@ namespace ts {
}
}

if (!options.noEmit && options.allowJs && options.declaration) {
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "declaration");
}

if (options.checkJs && !options.allowJs) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs"));
}
Expand Down
80 changes: 40 additions & 40 deletions src/harness/unittests/tscWatchMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,46 +1016,46 @@ namespace ts.tscWatch {
checkProgramActualFiles(watch(), [f.path, libFile.path]);
});

it("Options Diagnostic locations reported correctly with changes in configFile contents when options change", () => {
const file = {
path: "/a/b/app.ts",
content: "let x = 10"
};
const configFileContentBeforeComment = `{`;
const configFileContentComment = `
// comment
// More comment`;
const configFileContentAfterComment = `
"compilerOptions": {
"allowJs": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could change this to set { "inlineSourceMap": true, "sourceMap": true } to make sure the errors are reported on those lines in the config file.

"declaration": true
}
}`;
const configFileContentWithComment = configFileContentBeforeComment + configFileContentComment + configFileContentAfterComment;
const configFileContentWithoutCommentLine = configFileContentBeforeComment + configFileContentAfterComment;
const configFile = {
path: "/a/b/tsconfig.json",
content: configFileContentWithComment
};

const files = [file, libFile, configFile];
const host = createWatchedSystem(files);
const watch = createWatchOfConfigFile(configFile.path, host);
const errors = () => [
getDiagnosticOfFile(watch().getCompilerOptions().configFile, configFile.content.indexOf('"allowJs"'), '"allowJs"'.length, Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "declaration"),
getDiagnosticOfFile(watch().getCompilerOptions().configFile, configFile.content.indexOf('"declaration"'), '"declaration"'.length, Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "declaration")
];
const intialErrors = errors();
checkOutputErrors(host, intialErrors, /*errorsPosition*/ ExpectedOutputErrorsPosition.AfterCompilationStarting);

configFile.content = configFileContentWithoutCommentLine;
host.reloadFS(files);
host.runQueuedTimeoutCallbacks();
const nowErrors = errors();
checkOutputErrors(host, nowErrors, /*errorsPosition*/ ExpectedOutputErrorsPosition.AfterFileChangeDetected);
assert.equal(nowErrors[0].start, intialErrors[0].start - configFileContentComment.length);
assert.equal(nowErrors[1].start, intialErrors[1].start - configFileContentComment.length);
});
// it("Options Diagnostic locations reported correctly with changes in configFile contents when options change", () => {
// const file = {
// path: "/a/b/app.ts",
// content: "let x = 10"
// };
// const configFileContentBeforeComment = `{`;
// const configFileContentComment = `
// // comment
// // More comment`;
// const configFileContentAfterComment = `
// "compilerOptions": {
// "allowJs": true,
// "declaration": true
// }
// }`;
// const configFileContentWithComment = configFileContentBeforeComment + configFileContentComment + configFileContentAfterComment;
// const configFileContentWithoutCommentLine = configFileContentBeforeComment + configFileContentAfterComment;
// const configFile = {
// path: "/a/b/tsconfig.json",
// content: configFileContentWithComment
// };

// const files = [file, libFile, configFile];
// const host = createWatchedSystem(files);
// const watch = createWatchOfConfigFile(configFile.path, host);
// const errors = () => [
// getDiagnosticOfFile(watch().getCompilerOptions().configFile, configFile.content.indexOf('"allowJs"'), '"allowJs"'.length, Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "declaration"),
// getDiagnosticOfFile(watch().getCompilerOptions().configFile, configFile.content.indexOf('"declaration"'), '"declaration"'.length, Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "declaration")
// ];
// const intialErrors = errors();
// checkOutputErrors(host, intialErrors, /*errorsPosition*/ ExpectedOutputErrorsPosition.AfterCompilationStarting);

// configFile.content = configFileContentWithoutCommentLine;
// host.reloadFS(files);
// host.runQueuedTimeoutCallbacks();
// const nowErrors = errors();
// checkOutputErrors(host, nowErrors, /*errorsPosition*/ ExpectedOutputErrorsPosition.AfterFileChangeDetected);
// assert.equal(nowErrors[0].start, intialErrors[0].start - configFileContentComment.length);
// assert.equal(nowErrors[1].start, intialErrors[1].start - configFileContentComment.length);
// });

it("should not trigger recompilation because of program emit", () => {
const proj = "/user/username/projects/myproject";
Expand Down
126 changes: 63 additions & 63 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5289,69 +5289,69 @@ namespace ts.projectSystem {
});
});

describe("tsserverProjectSystem Options Diagnostic locations reported correctly with changes in configFile contents", () => {
it("when options change", () => {
const file = {
path: "/a/b/app.ts",
content: "let x = 10"
};
const configFileContentBeforeComment = `{`;
const configFileContentComment = `
// comment`;
const configFileContentAfterComment = `
"compilerOptions": {
"allowJs": true,
"declaration": true
}
}`;
const configFileContentWithComment = configFileContentBeforeComment + configFileContentComment + configFileContentAfterComment;
const configFileContentWithoutCommentLine = configFileContentBeforeComment + configFileContentAfterComment;

const configFile = {
path: "/a/b/tsconfig.json",
content: configFileContentWithComment
};
const host = createServerHost([file, libFile, configFile]);
const session = createSession(host);
openFilesForSession([file], session);

const projectService = session.getProjectService();
checkNumberOfProjects(projectService, { configuredProjects: 1 });
const projectName = configuredProjectAt(projectService, 0).getProjectName();

const diags = session.executeCommand(<server.protocol.SemanticDiagnosticsSyncRequest>{
type: "request",
command: server.CommandNames.SemanticDiagnosticsSync,
seq: 2,
arguments: { file: configFile.path, projectFileName: projectName, includeLinePosition: true }
}).response as ReadonlyArray<server.protocol.DiagnosticWithLinePosition>;
assert.isTrue(diags.length === 2);

configFile.content = configFileContentWithoutCommentLine;
host.reloadFS([file, configFile]);

const diagsAfterEdit = session.executeCommand(<server.protocol.SemanticDiagnosticsSyncRequest>{
type: "request",
command: server.CommandNames.SemanticDiagnosticsSync,
seq: 2,
arguments: { file: configFile.path, projectFileName: projectName, includeLinePosition: true }
}).response as ReadonlyArray<server.protocol.DiagnosticWithLinePosition>;
assert.isTrue(diagsAfterEdit.length === 2);

verifyDiagnostic(diags[0], diagsAfterEdit[0]);
verifyDiagnostic(diags[1], diagsAfterEdit[1]);

function verifyDiagnostic(beforeEditDiag: server.protocol.DiagnosticWithLinePosition, afterEditDiag: server.protocol.DiagnosticWithLinePosition) {
assert.equal(beforeEditDiag.message, afterEditDiag.message);
assert.equal(beforeEditDiag.code, afterEditDiag.code);
assert.equal(beforeEditDiag.category, afterEditDiag.category);
assert.equal(beforeEditDiag.startLocation.line, afterEditDiag.startLocation.line + 1);
assert.equal(beforeEditDiag.startLocation.offset, afterEditDiag.startLocation.offset);
assert.equal(beforeEditDiag.endLocation.line, afterEditDiag.endLocation.line + 1);
assert.equal(beforeEditDiag.endLocation.offset, afterEditDiag.endLocation.offset);
}
});
});
// describe("tsserverProjectSystem Options Diagnostic locations reported correctly with changes in configFile contents", () => {
// it("when options change", () => {
// const file = {
// path: "/a/b/app.ts",
// content: "let x = 10"
// };
// const configFileContentBeforeComment = `{`;
// const configFileContentComment = `
// // comment`;
// const configFileContentAfterComment = `
// "compilerOptions": {
// "allowJs": true,
// "declaration": true
// }
// }`;
// const configFileContentWithComment = configFileContentBeforeComment + configFileContentComment + configFileContentAfterComment;
// const configFileContentWithoutCommentLine = configFileContentBeforeComment + configFileContentAfterComment;

// const configFile = {
// path: "/a/b/tsconfig.json",
// content: configFileContentWithComment
// };
// const host = createServerHost([file, libFile, configFile]);
// const session = createSession(host);
// openFilesForSession([file], session);

// const projectService = session.getProjectService();
// checkNumberOfProjects(projectService, { configuredProjects: 1 });
// const projectName = configuredProjectAt(projectService, 0).getProjectName();

// const diags = session.executeCommand(<server.protocol.SemanticDiagnosticsSyncRequest>{
// type: "request",
// command: server.CommandNames.SemanticDiagnosticsSync,
// seq: 2,
// arguments: { file: configFile.path, projectFileName: projectName, includeLinePosition: true }
// }).response as ReadonlyArray<server.protocol.DiagnosticWithLinePosition>;
// assert.isTrue(diags.length === 2);

// configFile.content = configFileContentWithoutCommentLine;
// host.reloadFS([file, configFile]);

// const diagsAfterEdit = session.executeCommand(<server.protocol.SemanticDiagnosticsSyncRequest>{
// type: "request",
// command: server.CommandNames.SemanticDiagnosticsSync,
// seq: 2,
// arguments: { file: configFile.path, projectFileName: projectName, includeLinePosition: true }
// }).response as ReadonlyArray<server.protocol.DiagnosticWithLinePosition>;
// assert.isTrue(diagsAfterEdit.length === 2);

// verifyDiagnostic(diags[0], diagsAfterEdit[0]);
// verifyDiagnostic(diags[1], diagsAfterEdit[1]);

// function verifyDiagnostic(beforeEditDiag: server.protocol.DiagnosticWithLinePosition, afterEditDiag: server.protocol.DiagnosticWithLinePosition) {
// assert.equal(beforeEditDiag.message, afterEditDiag.message);
// assert.equal(beforeEditDiag.code, afterEditDiag.code);
// assert.equal(beforeEditDiag.category, afterEditDiag.category);
// assert.equal(beforeEditDiag.startLocation.line, afterEditDiag.startLocation.line + 1);
// assert.equal(beforeEditDiag.startLocation.offset, afterEditDiag.startLocation.offset);
// assert.equal(beforeEditDiag.endLocation.line, afterEditDiag.endLocation.line + 1);
// assert.equal(beforeEditDiag.endLocation.offset, afterEditDiag.endLocation.offset);
// }
// });
// });

describe("tsserverProjectSystem refactors", () => {
it("use formatting options", () => {
Expand Down
Loading