From 4191d01877533d7935df3843ae41fee40f35459a Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Sun, 3 Apr 2016 14:43:11 -0700 Subject: [PATCH] If CoffeeScript source contains backticks, pass the coffee output through the ecmascript package (closes #6000) --- packages/coffeescript/package.js | 4 +++- packages/coffeescript/plugin/compile-coffeescript.js | 8 ++++++++ packages/coffeescript/tests/coffeescript_tests.coffee | 10 ++++++++++ packages/coffeescript/tests/es2015_module.js | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 packages/coffeescript/tests/es2015_module.js diff --git a/packages/coffeescript/package.js b/packages/coffeescript/package.js index 2b1ba86237..d5ac16eaf2 100644 --- a/packages/coffeescript/package.js +++ b/packages/coffeescript/package.js @@ -15,17 +15,19 @@ Package.registerBuildPlugin({ Package.onUse(function (api) { api.use('isobuild:compiler-plugin@1.0.0'); + api.use('ecmascript'); }); Package.onTest(function (api) { api.use(['coffeescript', 'tinytest']); - api.use(['coffeescript-test-helper'], ['client', 'server']); + api.use(['coffeescript-test-helper', 'ecmascript'], ['client', 'server']); api.addFiles('bare_test_setup.coffee', ['client'], {bare: true}); api.addFiles('bare_tests.js', ['client']); api.addFiles([ 'coffeescript_test_setup.js', 'tests/coffeescript_tests.coffee', 'tests/coffeescript_strict_tests.coffee', + 'tests/es2015_module.js', 'tests/litcoffeescript_tests.litcoffee', 'tests/litcoffeescript_tests.coffee.md', 'coffeescript_tests.js' diff --git a/packages/coffeescript/plugin/compile-coffeescript.js b/packages/coffeescript/plugin/compile-coffeescript.js index ee302f4488..097a91baf9 100644 --- a/packages/coffeescript/plugin/compile-coffeescript.js +++ b/packages/coffeescript/plugin/compile-coffeescript.js @@ -1,5 +1,6 @@ import sourcemap from "source-map"; import coffee from "coffee-script"; +import { ECMAScript } from "meteor/ecmascript"; // The coffee-script compiler overrides Error.prepareStackTrace, mostly for the // use of coffee.run which we don't use. This conflicts with the tool's use of @@ -67,6 +68,13 @@ export class CoffeeCompiler extends CachingCompiler { return null; } + if (source.indexOf('`') !== -1) { + // If source contains backticks, pass the coffee output through ecmascript + try { + output.js = ECMAScript.compileForShell(output.js); + } catch (e) {} + } + const stripped = stripExportedVars( output.js, inputFile.getDeclaredExports().map(e => e.name)); diff --git a/packages/coffeescript/tests/coffeescript_tests.coffee b/packages/coffeescript/tests/coffeescript_tests.coffee index 32ffd7a9d9..5268f8e459 100644 --- a/packages/coffeescript/tests/coffeescript_tests.coffee +++ b/packages/coffeescript/tests/coffeescript_tests.coffee @@ -4,3 +4,13 @@ Meteor.__COFFEESCRIPT_PRESENT = true share.coffeeShared = 789 Tinytest.add "coffeescript - compile", (test) -> test.isTrue true + + +# import/export statements must be top-level +`import { Meteor as testingForImportedSymbol123456789 } from "meteor/meteor";` +Tinytest.add "coffeescript - import external package via backticks", (test) -> + test.isTrue testingForImportedSymbol123456789? + +`import { testingForImportedModule987654321 } from "./es2015_module.js";` +Tinytest.add "coffeescript - import local module via backticks", (test) -> + test.isTrue testingForImportedModule987654321? diff --git a/packages/coffeescript/tests/es2015_module.js b/packages/coffeescript/tests/es2015_module.js new file mode 100644 index 0000000000..9eb8c9f8c1 --- /dev/null +++ b/packages/coffeescript/tests/es2015_module.js @@ -0,0 +1 @@ +export const testingForImportedModule987654321 = true;