If CoffeeScript source contains backticks, pass the coffee output through the ecmascript package (closes #6000)

This commit is contained in:
Geoffrey Booth
2016-04-03 14:43:11 -07:00
committed by Ben Newman
parent 3aa8675542
commit 4191d01877
4 changed files with 22 additions and 1 deletions

View File

@@ -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'

View File

@@ -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));

View File

@@ -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?

View File

@@ -0,0 +1 @@
export const testingForImportedModule987654321 = true;