From 28d0ff02910e8e68dc3a2def74166aece71a4ba0 Mon Sep 17 00:00:00 2001 From: ZHAO Jinxiang Date: Fri, 18 Mar 2022 20:37:57 +0800 Subject: [PATCH] Fix export default expression comment --- src/compiler/transformers/declarations.ts | 3 +++ .../exportDefaultExpressionComments.js | 22 +++++++++++++++++++ .../exportDefaultExpressionComments.symbols | 7 ++++++ .../exportDefaultExpressionComments.types | 7 ++++++ .../exportDefaultExpressionComments.ts | 6 +++++ 5 files changed, 45 insertions(+) create mode 100644 tests/baselines/reference/exportDefaultExpressionComments.js create mode 100644 tests/baselines/reference/exportDefaultExpressionComments.symbols create mode 100644 tests/baselines/reference/exportDefaultExpressionComments.types create mode 100644 tests/cases/conformance/declarationEmit/exportDefaultExpressionComments.ts diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index eae56dbaf1ae8..37814d4e3f2e0 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -1140,6 +1140,9 @@ namespace ts { const varDecl = factory.createVariableDeclaration(newId, /*exclamationToken*/ undefined, resolver.createTypeOfExpression(input.expression, input, declarationEmitNodeBuilderFlags, symbolTracker), /*initializer*/ undefined); errorFallbackNode = undefined; const statement = factory.createVariableStatement(needsDeclare ? [factory.createModifier(SyntaxKind.DeclareKeyword)] : [], factory.createVariableDeclarationList([varDecl], NodeFlags.Const)); + + preserveJsDoc(statement, input); + removeAllComments(input); return [statement, factory.updateExportAssignment(input, input.decorators, input.modifiers, newId)]; } } diff --git a/tests/baselines/reference/exportDefaultExpressionComments.js b/tests/baselines/reference/exportDefaultExpressionComments.js new file mode 100644 index 0000000000000..c3a9bb61da611 --- /dev/null +++ b/tests/baselines/reference/exportDefaultExpressionComments.js @@ -0,0 +1,22 @@ +//// [exportDefaultExpressionComments.ts] +/** + * JSDoc Comments + */ +export default null + + +//// [exportDefaultExpressionComments.js] +"use strict"; +exports.__esModule = true; +/** + * JSDoc Comments + */ +exports["default"] = null; + + +//// [exportDefaultExpressionComments.d.ts] +/** + * JSDoc Comments + */ +declare const _default: any; +export default _default; diff --git a/tests/baselines/reference/exportDefaultExpressionComments.symbols b/tests/baselines/reference/exportDefaultExpressionComments.symbols new file mode 100644 index 0000000000000..a3a94331a56cd --- /dev/null +++ b/tests/baselines/reference/exportDefaultExpressionComments.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/declarationEmit/exportDefaultExpressionComments.ts === +/** +No type information for this code. * JSDoc Comments +No type information for this code. */ +No type information for this code.export default null +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultExpressionComments.types b/tests/baselines/reference/exportDefaultExpressionComments.types new file mode 100644 index 0000000000000..012b8d32555ff --- /dev/null +++ b/tests/baselines/reference/exportDefaultExpressionComments.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/declarationEmit/exportDefaultExpressionComments.ts === +/** + * JSDoc Comments + */ +export default null +>null : null + diff --git a/tests/cases/conformance/declarationEmit/exportDefaultExpressionComments.ts b/tests/cases/conformance/declarationEmit/exportDefaultExpressionComments.ts new file mode 100644 index 0000000000000..a7477cc7557ab --- /dev/null +++ b/tests/cases/conformance/declarationEmit/exportDefaultExpressionComments.ts @@ -0,0 +1,6 @@ +// @declaration: true + +/** + * JSDoc Comments + */ +export default null