Skip to content

Commit

Permalink
tsickle: emit comment after missing semicolon only once
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 585982807
  • Loading branch information
lauraharker authored and copybara-github committed Nov 29, 2023
1 parent d5c2921 commit 209d420
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/jsdoc_transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,9 @@ export function jsdocTransformer(
continue;
}
}
const newDecl =
// TODO: go/ts50upgrade - Remove after upgrade.
// tslint:disable-next-line:no-unnecessary-type-assertion
ts.visitNode(decl, visitor, ts.isVariableDeclaration)!;
const newDecl = ts.setEmitFlags(
ts.visitNode(decl, visitor, ts.isVariableDeclaration)!,
ts.EmitFlags.NoComments);
const newStmt = ts.factory.createVariableStatement(
varStmt.modifiers,
ts.factory.createVariableDeclarationList([newDecl], flags));
Expand Down
1 change: 1 addition & 0 deletions src/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class FileSummary {
modName: string|undefined;
autochunk = false;
enhanceable = false;
legacyNamespace = false;
moduleType = ModuleType.UNKNOWN;

private stringify(symbol: Symbol): string {
Expand Down
3 changes: 3 additions & 0 deletions src/ts_migration_exports_shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ class Generator {
fileSummary.addStrongRequire({type: Type.CLOSURE, name: 'goog'});
fileSummary.addStrongRequire(
{type: Type.CLOSURE, name: this.srcIds.googModuleId});
if (maybeDeclareLegacyNameCall) {
fileSummary.legacyNamespace = true;
}

fileSummary.autochunk = isAutoChunk;
fileSummary.moduleType = ModuleType.GOOG_MODULE;
Expand Down
22 changes: 22 additions & 0 deletions test_files/comments/trailing_no_semicolon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
*
* @fileoverview Tests that the JSDoc comment of `other` is only emitted once.
* Without the trailing semicolon after `noExplicitSemicolon` TypeScript seems
* to duplicate the trailing comment as soon as a custom transformer modifies
* the variable statement.
*
* Generated from: test_files/comments/trailing_no_semicolon.ts
*/
goog.module('test_files.comments.trailing_no_semicolon');
var module = module || { id: 'test_files/comments/trailing_no_semicolon.ts' };
goog.require('tslib');
/** @type {number} */
const noExplicitSemicolon = 0;
/**
* This is a comment with a JSDoc tag
* JSCompiler doesn't recognize
*
* \@foobar
* @type {number}
*/
exports.other = 1;
17 changes: 17 additions & 0 deletions test_files/comments/trailing_no_semicolon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @fileoverview Tests that the JSDoc comment of `other` is only emitted once.
* Without the trailing semicolon after `noExplicitSemicolon` TypeScript seems
* to duplicate the trailing comment as soon as a custom transformer modifies
* the variable statement.
*/


const noExplicitSemicolon = 0

/**
* This is a comment with a JSDoc tag
* JSCompiler doesn't recognize
*
* @foobar
*/
export const other = 1;

0 comments on commit 209d420

Please sign in to comment.