From 29c37d5d2df25353eefe6ca814219ada2ea37bee Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Fri, 30 Sep 2016 22:33:32 -0700 Subject: [PATCH] CoffeeScript compiler: strip exported variables *before* running through the Babel compiler, to avoid Babel turning a one-line `var` statement into a multiline `var` statement and breaking the parsing logic in `stripExportedVars` --- packages/coffeescript/plugin/compile-coffeescript.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/coffeescript/plugin/compile-coffeescript.js b/packages/coffeescript/plugin/compile-coffeescript.js index 68c6bc1363..0de7fbadc0 100644 --- a/packages/coffeescript/plugin/compile-coffeescript.js +++ b/packages/coffeescript/plugin/compile-coffeescript.js @@ -83,6 +83,11 @@ export class CoffeeCompiler extends CachingCompiler { let sourceMap = JSON.parse(output.v3SourceMap); + output.js = stripExportedVars( + output.js, + inputFile.getDeclaredExports().map(e => e.name) + ); + if (source.indexOf('`') !== -1) { // If source contains backticks, pass the coffee output through babel-compiler const doubleRoastedCoffee = @@ -108,10 +113,7 @@ export class CoffeeCompiler extends CachingCompiler { } } - return addSharedHeader(stripExportedVars( - output.js, - inputFile.getDeclaredExports().map(e => e.name) - ), sourceMap); + return addSharedHeader(output.js, sourceMap); } addCompileResult(inputFile, sourceWithMap) {