diff --git a/README.md b/README.md index 54625547..ead52c7a 100755 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ allow you to use latest Javascript in your Ember CLI project. + [Enabling Source Maps](#enabling-source-maps) + [Modules](#modules) + [Disabling Debug Tooling Support](#disabling-debug-tooling-support) - + [Enabling TypeScript Transforms](#enabling-typescript-transforms) + + [Enabling TypeScript Transpilation](#enabling-typescript-transpilation) * [Addon usage](#addon-usage) + [Adding Custom Plugins](#adding-custom-plugins) + [Additional Trees](#additional-trees) @@ -122,7 +122,7 @@ interface EmberCLIBabelConfig { disablePresetEnv?: boolean; disableEmberModulesAPIPolyfill?: boolean; disableDecoratorTransforms?: boolean; - enableTypeScriptTransforms?: boolean; + enableTypeScriptTransform?: boolean; extensions?: string[]; }; } @@ -261,33 +261,31 @@ module.exports = function(defaults) { } ``` -#### Enabling TypeScript Transforms +#### Enabling TypeScript Transpilation -The transform plugins required for Babel to transpile TypeScript (including -transforms required for all valid TypeScript features such as optional -chaining and nullish coalescing) will automatically be enabled when -`ember-cli-typescript` >= 4.0 is installed. +The transform plugin required for Babel to transpile TypeScript will +automatically be enabled when `ember-cli-typescript` >= 4.0 is installed. -You can enable the TypeScript Babel transforms manually *without* -`ember-cli-typescript` by setting the `enableTypeScriptTransforms`to `true`. +You can enable the TypeScript Babel transform manually *without* +`ember-cli-typescript` by setting the `enableTypeScriptTransform` to `true`. NOTE: Setting this option to `true` is not compatible with `ember-cli-typescript` < 4.0 because of conflicting Babel plugin ordering constraints and is unnecessary because `ember-cli-typescript` < 4.0 adds the -TypeScript Babel transforms itself. +TypeScript Babel transform itself. NOTE: Setting this option to `true` does *not* enable type-checking. For integrated type-checking, you will need [`ember-cli-typescript`](https://ember-cli-typescript.com). -In an app, manually enabling the TypeScript transforms would look like: +In an app, manually enabling the TypeScript transform would look like: ```js // ember-cli-build.js module.exports = function(defaults) { let app = new EmberApp(defaults, { 'ember-cli-babel': { - enableTypeScriptTransforms: true + enableTypeScriptTransform: true } }); diff --git a/index.js b/index.js index 9d78a9b1..2b01723f 100644 --- a/index.js +++ b/index.js @@ -304,7 +304,7 @@ module.exports = { let userPostTransformPlugins = addonProvidedConfig.postTransformPlugins; if (shouldHandleTypeScript) { - userPlugins = this._addTypeScriptPlugins(userPlugins.slice(), addonProvidedConfig.options); + userPlugins = this._addTypeScriptPlugin(userPlugins.slice(), addonProvidedConfig.options); } if (shouldIncludeDecoratorPlugins) { @@ -337,8 +337,8 @@ module.exports = { _shouldHandleTypeScript(config) { let emberCLIBabelConfig = config['ember-cli-babel'] || {}; - if (typeof emberCLIBabelConfig.enableTypeScriptTransforms === 'boolean') { - return emberCLIBabelConfig.enableTypeScriptTransforms; + if (typeof emberCLIBabelConfig.enableTypeScriptTransform === 'boolean') { + return emberCLIBabelConfig.enableTypeScriptTransform; } let typeScriptAddon = this.parent.addons && this.parent.addons.find(a => a.name === 'ember-cli-typescript'); @@ -357,39 +357,9 @@ module.exports = { return constraints; }, - _addTypeScriptPlugins(plugins) { + _addTypeScriptPlugin(plugins) { const { hasPlugin, addPlugin } = require('ember-cli-babel-plugin-helpers'); - if (hasPlugin(plugins, '@babel/plugin-proposal-optional-chaining')) { - if (this.parent === this.project) { - this.project.ui.writeWarnLine(`${ - this._parentName() - } has added the optional chaining plugin to its build, but ember-cli-babel provides this by default now when ember-cli-typescript >= 4.0 and typescript >= 3.7 are installed! You can remove the transform, or the addon that provided it.`); - } - } else { - addPlugin( - plugins, - [ - require.resolve('@babel/plugin-proposal-optional-chaining'), - ] - ); - } - - if (hasPlugin(plugins, '@babel/plugin-proposal-nullish-coalescing-operator')) { - if (this.parent === this.project) { - this.project.ui.writeWarnLine(`${ - this._parentName() - } has added the nullish coalescing operator plugin to its build, but ember-cli-babel provides this by default now when ember-cli-typescript >= 4.0 and typescript >= 3.7 are installed! You can remove the transform, or the addon that provided it.`); - } - } else { - addPlugin( - plugins, - [ - require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'), - ] - ); - } - if (hasPlugin(plugins, '@babel/plugin-transform-typescript')) { if (this.parent === this.project) { this.project.ui.writeWarnLine(`${ diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index 61c0014e..904109bd 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -805,10 +805,10 @@ describe('ember-cli-babel', function() { expect(this.addon._shouldHandleTypeScript({})).to.be.false; }); it('should return true when TypeScript transforms are manually enabled', function() { - expect(this.addon._shouldHandleTypeScript({ 'ember-cli-babel': { enableTypeScriptTransforms: true } })).to.be.true; + expect(this.addon._shouldHandleTypeScript({ 'ember-cli-babel': { enableTypeScriptTransform: true } })).to.be.true; }); it('should return false when TypeScript transforms are manually disabled', function() { - expect(this.addon._shouldHandleTypeScript({ 'ember-cli-babel': { enableTypeScriptTransforms: false } })).to.be.false; + expect(this.addon._shouldHandleTypeScript({ 'ember-cli-babel': { enableTypeScriptTransform: false } })).to.be.false; }); it('should return false when TypeScript transforms are manually disabled, even when ember-cli-typescript >= 4.0.0-alpha.1 is installed', function() { this.addon.parent.addons.push({ @@ -817,15 +817,11 @@ describe('ember-cli-babel', function() { version: '4.0.0-alpha.1', }, }); - expect(this.addon._shouldHandleTypeScript({ 'ember-cli-babel': { enableTypeScriptTransforms: false } })).to.be.false; + expect(this.addon._shouldHandleTypeScript({ 'ember-cli-babel': { enableTypeScriptTransform: false } })).to.be.false; }); }); - describe('_addTypeScriptPlugins', function() { - it('should add TypeScript, optional chaining, and nullish coalescing operator plugins', function() { - expect(this.addon._addTypeScriptPlugins([], {}).length).to.equal(3, 'plugins added correctly'); - }); - + describe('_addTypeScriptPlugin', function() { it('should warn and not add the TypeScript plugin if already added', function() { this.addon.project.ui = { writeWarnLine(message) { @@ -834,35 +830,11 @@ describe('ember-cli-babel', function() { }; expect( - this.addon._addTypeScriptPlugins([ + this.addon._addTypeScriptPlugin([ ['@babel/plugin-transform-typescript'] ], {} - ).length).to.equal(3, 'plugin was not added'); - }); - - it('should warn and not add optional chaining if already added', function() { - this.addon.project.ui = { - writeWarnLine(message) { - expect(message).to.match(/has added the optional chaining plugin to its build/); - } - }; - - expect(this.addon._addTypeScriptPlugins([ - ['@babel/plugin-proposal-optional-chaining'] - ], {}).length).to.equal(3, 'plugin was not added'); - }); - - it('should warn and not add nullish coalescing operator if already added', function() { - this.addon.project.ui = { - writeWarnLine(message) { - expect(message).to.match(/has added the nullish coalescing operator plugin to its build/); - } - }; - - expect(this.addon._addTypeScriptPlugins([ - ['@babel/plugin-proposal-nullish-coalescing-operator'] - ], {}).length).to.equal(3, 'plugin was not added'); + ).length).to.equal(1, 'plugin was not added'); }); }); diff --git a/package.json b/package.json index f945314a..896bcd28 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,6 @@ "@babel/core": "^7.8.3", "@babel/plugin-proposal-class-properties": "^7.8.3", "@babel/plugin-proposal-decorators": "^7.8.3", - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3", - "@babel/plugin-proposal-optional-chaining": "^7.8.3", "@babel/plugin-transform-modules-amd": "^7.8.3", "@babel/plugin-transform-runtime": "^7.8.3", "@babel/plugin-transform-typescript": "^7.8.3",