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

Fix ts.transpileDeclaration having empty sourceMapText when declarationMap is true #59314

Conversation

MichaelMitchell-at
Copy link

Fixes #59313

Copy link
Author

@MichaelMitchell-at MichaelMitchell-at left a comment

Choose a reason for hiding this comment

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

I've verified this fixes the issue for my use case, but I'm not sure how to write a test for this. I didn't find any existing tests that I could use as a reference.

cc @weswigham

@@ -468,7 +468,6 @@ export const commonOptionsWithBuild: CommandLineOption[] = [
affectsBuildInfo: true,
showInSimplifiedHelpView: true,
category: Diagnostics.Emit,
transpileOptionValue: undefined,
Copy link
Author

@MichaelMitchell-at MichaelMitchell-at Jul 17, 2024

Choose a reason for hiding this comment

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

This being set to undefined caused declarationMap to be set to undefined in options

for (const option of transpileOptionValueCompilerOptions) {
// Do not set redundant config options if `verbatimModuleSyntax` was supplied.
if (options.verbatimModuleSyntax && optionsRedundantWithVerbatimModuleSyntax.has(option.name)) {
continue;
}
options[option.name] = option.transpileOptionValue;
}

@@ -205,7 +205,7 @@ function transpileWorker(input: string, transpileOptions: TranspileOptions, decl
addRange(/*to*/ diagnostics, /*from*/ program.getOptionsDiagnostics());
}
// Emit
const result = program.emit(/*targetSourceFile*/ undefined, /*writeFile*/ undefined, /*cancellationToken*/ undefined, /*emitOnlyDtsFiles*/ declaration, transpileOptions.transformers, /*forceDtsEmit*/ declaration);
const result = program.emit(/*targetSourceFile*/ undefined, /*writeFile*/ undefined, /*cancellationToken*/ undefined, /*emitOnly*/ undefined, transpileOptions.transformers, /*forceDtsEmit*/ undefined);
Copy link
Author

@MichaelMitchell-at MichaelMitchell-at Jul 17, 2024

Choose a reason for hiding this comment

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

Before we were passing true to forceDtsEmit, which caused this to evaluate to false:

sourceMap: !forceDtsEmit && compilerOptions.declarationMap,

though I'm not sure if this is actually the correct fix. Perhaps it would be to just remove !forceDtsEmit && from emitter.ts.

Changing emitOnlyDtsFiles to undefined actually doesn't seem to matter, at least with the configuration I tested with, which seems kind of surprising.

Copy link
Author

Choose a reason for hiding this comment

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

Well, no permutation of what I said results in all the tests passing, so clearly not as easy of a fix as I hoped.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jul 17, 2024
@sheetalkamat
Copy link
Member

Closing in favor of #59337

@MichaelMitchell-at MichaelMitchell-at deleted the fix_transpile_declaration_source_map branch July 18, 2024 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[transpileDeclaration API] ts.transpileDeclaration always returns empty sourceMapText
3 participants