From faf2ac5f9eec1d2436c71a4fc266a74b11a97042 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Fri, 2 Jun 2017 08:12:03 -0700 Subject: [PATCH] Hack to get export default work (#1866) Fixes #1854 --- src/printer.js | 10 +++++++++- .../compiler/__snapshots__/jsfmt.spec.js.snap | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/printer.js b/src/printer.js index 7c7a70eb8..b526894d8 100644 --- a/src/printer.js +++ b/src/printer.js @@ -2414,7 +2414,15 @@ function genericPrintNoParens(path, options, print, args) { return concat(parts); case "TSNamespaceExportDeclaration": if (n.declaration) { - parts.push("export ", path.call(print, "declaration")); + // Temporary fix until https://github.com/eslint/typescript-eslint-parser/issues/263 + const isDefault = options.originalText + .slice(util.locStart(n), util.locStart(n.declaration)) + .match(/\bdefault\b/); + parts.push( + "export ", + isDefault ? "default " : "", + path.call(print, "declaration") + ); } else { parts.push("export as namespace ", path.call(print, "name")); diff --git a/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap index c7de3c9c7..51d9ab59b 100644 --- a/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap @@ -381,7 +381,7 @@ declare module "foo" { declare module "foo" { export var before: C; - export class C { + export default class C { method(): C; }