diff --git a/index.js b/index.js index cc904887..9d78a9b1 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,8 @@ module.exports = { return this._cachedDebugTree.apply(null, arguments); }, - transpileTree(inputTree, config) { + transpileTree(inputTree, _config) { + let config = _config || this._getAddonOptions(); let description = `000${++count}`.slice(-3); let postDebugTree = this._debugTree(inputTree, `${description}:input`); @@ -51,7 +52,15 @@ module.exports = { output = postDebugTree; } else { let BabelTranspiler = require('broccoli-babel-transpiler'); - output = new BabelTranspiler(postDebugTree, options); + let transpilationInput = postDebugTree; + + if (this._shouldHandleTypeScript(config)) { + let Funnel = require('broccoli-funnel'); + let inputWithoutDeclarations = new Funnel(transpilationInput, { exclude: ['**/*.d.ts'] }); + transpilationInput = this._debugTree(inputWithoutDeclarations, `${description}:filtered-input`); + } + + output = new BabelTranspiler(transpilationInput, options); } return this._debugTree(output, `${description}:output`); diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index dbfe2108..61c0014e 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -635,6 +635,42 @@ describe('ember-cli-babel', function() { })); }); + describe('TypeScript transpilation', function() { + beforeEach(function() { + this.addon.parent.addons.push({ + name: 'ember-cli-typescript', + pkg: { + version: '4.0.0-alpha.1' + } + }); + }); + + it('should transpile .ts files', co.wrap(function*() { + input.write({ 'foo.ts': `let foo: string = "hi";` }); + + subject = this.addon.transpileTree(input.path()); + output = createBuilder(subject); + + yield output.build(); + + expect( + output.read() + ).to.deep.equal({ + 'foo.js': `define("foo", [], function () {\n "use strict";\n\n var foo = "hi";\n});` + }); + })); + + it('should exclude .d.ts files', co.wrap(function*() { + input.write({ 'foo.d.ts': `declare let foo: string;` }); + + subject = this.addon.transpileTree(input.path()); + output = createBuilder(subject); + + yield output.build(); + + expect(output.read()).to.deep.equal({}); + })) + }); describe('_shouldDoNothing', function() { it("will no-op if nothing to do", co.wrap(function* () {