mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-13 09:12:52 -05:00
Merge pull request #34495 from microsoft/forceDts
Add forceDtsEmit flag to getEmitOutput
This commit is contained in:
@@ -393,7 +393,9 @@ namespace ts {
|
||||
declarationFilePath: string | undefined,
|
||||
declarationMapPath: string | undefined,
|
||||
relativeToBuildInfo: (path: string) => string) {
|
||||
if (!sourceFileOrBundle || !declarationFilePath) {
|
||||
if (!sourceFileOrBundle) return;
|
||||
if (!declarationFilePath) {
|
||||
if (emitOnlyDtsFiles || compilerOptions.emitDeclarationOnly) emitSkipped = true;
|
||||
return;
|
||||
}
|
||||
const sourceFiles = isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles;
|
||||
|
||||
@@ -1638,12 +1638,12 @@ namespace ts {
|
||||
return NavigateTo.getNavigateToItems(sourceFiles, program.getTypeChecker(), cancellationToken, searchValue, maxResultCount, excludeDtsFiles);
|
||||
}
|
||||
|
||||
function getEmitOutput(fileName: string, emitOnlyDtsFiles = false) {
|
||||
function getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean, forceDtsEmit?: boolean) {
|
||||
synchronizeHostData();
|
||||
|
||||
const sourceFile = getValidSourceFile(fileName);
|
||||
const customTransformers = host.getCustomTransformers && host.getCustomTransformers();
|
||||
return getFileEmitOutput(program, sourceFile, emitOnlyDtsFiles, cancellationToken, customTransformers);
|
||||
return getFileEmitOutput(program, sourceFile, !!emitOnlyDtsFiles, cancellationToken, customTransformers, forceDtsEmit);
|
||||
}
|
||||
|
||||
// Signature help
|
||||
|
||||
@@ -391,7 +391,7 @@ namespace ts {
|
||||
organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
|
||||
getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
|
||||
|
||||
getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput;
|
||||
getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean, forceDtsEmit?: boolean): EmitOutput;
|
||||
|
||||
getProgram(): Program | undefined;
|
||||
|
||||
|
||||
@@ -15,10 +15,9 @@ class Carousel<T> extends Vue {
|
||||
"vue-class-component.d.ts": `import Vue from "./vue";
|
||||
export function Component(x: Config): any;`
|
||||
};
|
||||
// Regression test for GH #18245 - bug in single line comment writer caused a debug assertion when attempting
|
||||
// to write an alias to a module's default export was referrenced across files and had no default export
|
||||
it("should be able to create a language service which can respond to deinition requests without throwing", () => {
|
||||
const languageService = createLanguageService({
|
||||
|
||||
function createLanguageService() {
|
||||
return ts.createLanguageService({
|
||||
getCompilationSettings() {
|
||||
return {};
|
||||
},
|
||||
@@ -39,8 +38,45 @@ export function Component(x: Config): any;`
|
||||
return getDefaultLibFilePath(options);
|
||||
},
|
||||
});
|
||||
}
|
||||
// Regression test for GH #18245 - bug in single line comment writer caused a debug assertion when attempting
|
||||
// to write an alias to a module's default export was referrenced across files and had no default export
|
||||
it("should be able to create a language service which can respond to deinition requests without throwing", () => {
|
||||
const languageService = createLanguageService();
|
||||
const definitions = languageService.getDefinitionAtPosition("foo.ts", 160); // 160 is the latter `vueTemplateHtml` position
|
||||
expect(definitions).to.exist; // eslint-disable-line no-unused-expressions
|
||||
});
|
||||
|
||||
it("getEmitOutput on language service has way to force dts emit", () => {
|
||||
const languageService = createLanguageService();
|
||||
assert.deepEqual(
|
||||
languageService.getEmitOutput(
|
||||
"foo.ts",
|
||||
/*emitOnlyDtsFiles*/ true
|
||||
),
|
||||
{
|
||||
emitSkipped: true,
|
||||
outputFiles: emptyArray,
|
||||
exportedModulesFromDeclarationEmit: undefined
|
||||
}
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
languageService.getEmitOutput(
|
||||
"foo.ts",
|
||||
/*emitOnlyDtsFiles*/ true,
|
||||
/*forceDtsEmit*/ true
|
||||
),
|
||||
{
|
||||
emitSkipped: false,
|
||||
outputFiles: [{
|
||||
name: "foo.d.ts",
|
||||
text: "export {};\r\n",
|
||||
writeByteOrderMark: false
|
||||
}],
|
||||
exportedModulesFromDeclarationEmit: undefined
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5073,7 +5073,7 @@ declare namespace ts {
|
||||
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined): RefactorEditInfo | undefined;
|
||||
organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
|
||||
getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
|
||||
getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput;
|
||||
getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean, forceDtsEmit?: boolean): EmitOutput;
|
||||
getProgram(): Program | undefined;
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
@@ -5073,7 +5073,7 @@ declare namespace ts {
|
||||
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined): RefactorEditInfo | undefined;
|
||||
organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
|
||||
getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
|
||||
getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput;
|
||||
getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean, forceDtsEmit?: boolean): EmitOutput;
|
||||
getProgram(): Program | undefined;
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user