From 9e5baacd26b3399a12b7570398a15d3bc631bd7b Mon Sep 17 00:00:00 2001 From: Dan Freeman Date: Thu, 12 Dec 2019 18:31:57 +0100 Subject: [PATCH 01/23] Include decorator and class field plugins after TypeScript, if present --- index.js | 6 +++--- node-tests/addon-test.js | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6010ab74..68e05ab5 100644 --- a/index.js +++ b/index.js @@ -340,7 +340,8 @@ module.exports = { plugins, [require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }], { - before: ['@babel/plugin-proposal-class-properties', '@babel/plugin-transform-typescript'] + before: ['@babel/plugin-proposal-class-properties'], + after: ['@babel/plugin-transform-typescript'] } ); } @@ -357,8 +358,7 @@ module.exports = { plugins, [require.resolve('@babel/plugin-proposal-class-properties'), { loose: options.loose || false }], { - after: ['@babel/plugin-proposal-decorators'], - before: ['@babel/plugin-transform-typescript'] + after: ['@babel/plugin-proposal-decorators', '@babel/plugin-transform-typescript'] } ); } diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index b4429b48..8265e81b 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -792,6 +792,12 @@ describe('ember-cli-babel', function() { expect(loosePlugins[1][1].loose).to.equal(true, 'loose setting added correctly'); }); + + it('should include class fields and decorators after typescript if detected', function() { + let plugins = this.addon._addDecoratorPlugins(['@babel/plugin-transform-typescript'], {}); + expect(plugins[0]).to.equal('@babel/plugin-transform-typescript', 'typescript still first'); + expect(plugins.length).to.equal(3, 'class fields and decorators added'); + }); }); describe('_shouldIncludeHelpers()', function() { From f602be43632f20dffb36ac4972481bd73adb173e Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Thu, 19 Dec 2019 03:26:42 -0500 Subject: [PATCH 02/23] feat: add TypeScript tranform when e-c-ts >= 4.0.0-alpha --- index.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 3 ++ yarn.lock | 41 ++++++++++++++++++++++++- 3 files changed, 127 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 68e05ab5..e1a3962e 100644 --- a/index.js +++ b/index.js @@ -254,14 +254,20 @@ module.exports = { }, _getExtensions(config) { + let shouldIncludeTypeScriptPlugins = this._shouldIncludeTypeScriptPlugins(); let emberCLIBabelConfig = config['ember-cli-babel'] || {}; - return emberCLIBabelConfig.extensions || ['js']; + let extensions = emberCLIBabelConfig.extensions || ['js']; + if (shouldIncludeTypeScriptPlugins && !extensions.includes('ts')) { + extensions.push('ts'); + } + return extensions; }, _getBabelOptions(config) { let addonProvidedConfig = this._getAddonProvidedConfig(config); let shouldCompileModules = this._shouldCompileModules(config); let shouldIncludeHelpers = this._shouldIncludeHelpers(config); + let shouldIncludeTypeScriptPlugins = this._shouldIncludeTypeScriptPlugins(); let shouldIncludeDecoratorPlugins = this._shouldIncludeDecoratorPlugins(config); let emberCLIBabelConfig = config['ember-cli-babel']; @@ -292,6 +298,10 @@ module.exports = { let userPlugins = addonProvidedConfig.plugins; let userPostTransformPlugins = addonProvidedConfig.postTransformPlugins; + if (shouldIncludeTypeScriptPlugins) { + userPlugins = this._addTypeScriptPlugins(userPlugins.slice(), addonProvidedConfig.options); + } + if (shouldIncludeDecoratorPlugins) { userPlugins = this._addDecoratorPlugins(userPlugins.slice(), addonProvidedConfig.options); } @@ -320,6 +330,79 @@ module.exports = { return options; }, + _shouldIncludeTypeScriptPlugins() { + let checker = new VersionChecker(this.parent).for('ember-cli-typescript', 'npm'); + + return checker.gte('4.0.0-alpha'); + }, + + _shouldIncludeOptionalChainingNullishCoalescingPlugins() { + let checker = new VersionChecker(this.parent).for('typescript', 'npm'); + + return checker.gte('3.7.0'); + }, + + _addTypeScriptPlugins(plugins) { + const { hasPlugin, addPlugin } = require('ember-cli-babel-plugin-helpers'); + const shouldIncludeOptionalChainingNullishCoalescingPlugins = this._shouldIncludeOptionalChainingNullishCoalescingPlugins(); + + if (shouldIncludeOptionalChainingNullishCoalescingPlugins) { + 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(`${ + this._parentName() + } has added the TypeScript transform plugin to its build, but ember-cli-babel provides this by default now when ember-cli-typescript >= 4.0 is installed! You can remove the transform, or the addon that provided it.`); + } + } else { + addPlugin( + plugins, + [ + require.resolve('@babel/plugin-transform-typescript'), + { allowDeclareFields: true }, + ], + { + before: [ + '@babel/plugin-proposal-class-properties', + '@babel/plugin-proposal-private-methods', + '@babel/plugin-proposal-decorators', + ] + } + ); + } + return plugins; + }, + _shouldIncludeDecoratorPlugins(config) { let customOptions = config['ember-cli-babel'] || {}; diff --git a/package.json b/package.json index 296a007d..253abf4e 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,11 @@ "@babel/core": "^7.7.0", "@babel/plugin-proposal-class-properties": "^7.7.0", "@babel/plugin-proposal-decorators": "^7.7.0", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.7.4", + "@babel/plugin-proposal-optional-chaining": "^7.7.5", "@babel/plugin-transform-modules-amd": "^7.5.0", "@babel/plugin-transform-runtime": "^7.6.0", + "@babel/plugin-transform-typescript": "^7.7.4", "@babel/polyfill": "^7.7.0", "@babel/preset-env": "^7.7.0", "@babel/runtime": "^7.7.0", diff --git a/yarn.lock b/yarn.lock index eff7b3e8..086dea7d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -477,6 +477,14 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-syntax-json-strings" "^7.2.0" +"@babel/plugin-proposal-nullish-coalescing-operator@^7.7.4": + version "7.7.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.7.4.tgz#7db302c83bc30caa89e38fee935635ef6bd11c28" + integrity sha512-TbYHmr1Gl1UC7Vo2HVuj/Naci5BEGNZ0AJhzqD2Vpr6QPFWpUmBRLrIDjedzx7/CShq0bRDS2gI4FIs77VHLVQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-nullish-coalescing-operator" "^7.7.4" + "@babel/plugin-proposal-object-rest-spread@^7.6.2": version "7.6.2" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.6.2.tgz#8ffccc8f3a6545e9f78988b6bf4fe881b88e8096" @@ -493,6 +501,14 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-syntax-optional-catch-binding" "^7.2.0" +"@babel/plugin-proposal-optional-chaining@^7.7.5": + version "7.7.5" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.7.5.tgz#f0835f044cef85b31071a924010a2a390add11d4" + integrity sha512-sOwFqT8JSchtJeDD+CjmWCaiFoLxY4Ps7NjvwHC/U7l4e9i5pTRNt8nDMIFSOUL+ncFbYSwruHM8WknYItWdXw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-optional-chaining" "^7.7.4" + "@babel/plugin-proposal-unicode-property-regex@^7.7.0": version "7.7.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.7.0.tgz#549fe1717a1bd0a2a7e63163841cb37e78179d5d" @@ -529,6 +545,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-syntax-nullish-coalescing-operator@^7.7.4": + version "7.7.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.7.4.tgz#e53b751d0c3061b1ba3089242524b65a7a9da12b" + integrity sha512-XKh/yIRPiQTOeBg0QJjEus5qiSKucKAiApNtO1psqG7D17xmE+X2i5ZqBEuSvo0HRuyPaKaSN/Gy+Ha9KFQolw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-object-rest-spread@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.2.0.tgz#3b7a3e733510c57e820b9142a6579ac8b0dfad2e" @@ -543,6 +566,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-syntax-optional-chaining@^7.7.4": + version "7.7.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.7.4.tgz#c91fdde6de85d2eb8906daea7b21944c3610c901" + integrity sha512-2MqYD5WjZSbJdUagnJvIdSfkb/ucOC9/1fRJxm7GAxY6YQLWlUvkfxoNbUPcPLHJyetKUDQ4+yyuUyAoc0HriA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-top-level-await@^7.7.0": version "7.7.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.7.0.tgz#f5699549f50bbe8d12b1843a4e82f0a37bb65f4d" @@ -550,7 +580,7 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" -"@babel/plugin-syntax-typescript@^7.2.0": +"@babel/plugin-syntax-typescript@^7.2.0", "@babel/plugin-syntax-typescript@^7.7.4": version "7.7.4" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.7.4.tgz#5d037ffa10f3b25a16f32570ebbe7a8c2efa304b" integrity sha512-77blgY18Hud4NM1ggTA8xVT/dBENQf17OpiToSa2jSmEY3fWXD2jwrdVlO4kq5yzUTeF15WSQ6b4fByNvJcjpQ== @@ -803,6 +833,15 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-transform-typescript@^7.7.4": + version "7.7.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.7.4.tgz#2974fd05f4e85c695acaf497f432342de9fc0636" + integrity sha512-X8e3tcPEKnwwPVG+vP/vSqEShkwODOEeyQGod82qrIuidwIrfnsGn11qPM1jBLF4MqguTXXYzm58d0dY+/wdpg== + dependencies: + "@babel/helper-create-class-features-plugin" "^7.7.4" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-typescript" "^7.7.4" + "@babel/plugin-transform-typescript@~7.4.0": version "7.4.5" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.4.5.tgz#ab3351ba35307b79981993536c93ff8be050ba28" From e2680b1e9af6585fe196805632bc2d81600c8798 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Thu, 19 Dec 2019 04:34:25 -0500 Subject: [PATCH 03/23] tests: add tests for _addTypeScriptPlugins() --- node-tests/addon-test.js | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index 8265e81b..8521515e 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -746,6 +746,58 @@ describe('ember-cli-babel', function() { }); }); + describe('_addTypeScriptPlugins', function() { + it('should add only the TypeScript plugin by default', function() { + expect(this.addon._addTypeScriptPlugins([], {}).length).to.equal(1, 'plugin added correctly'); + }); + + it('should warn and not add the TypeScript plugin if already added', function() { + this.addon.project.ui = { + writeWarnLine(message) { + expect(message).to.match(/has added the TypeScript transform plugin to its build/); + } + }; + + expect( + this.addon._addTypeScriptPlugins([ + ['@babel/plugin-transform-typescript'] + ], + {} + ).length).to.equal(1, 'plugin was not added'); + }); + + it('should add optional chaining and nullish coalescing operator when told to', function() { + this.addon._shouldIncludeOptionalChainingNullishCoalescingPlugins = function() { return true; } + expect(this.addon._addTypeScriptPlugins([], {}).length).to.equal(3, 'plugins added correctly'); + }); + + it('should warn and not add optional chaining if already added', function() { + this.addon._shouldIncludeOptionalChainingNullishCoalescingPlugins = function() { return true; } + 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._shouldIncludeOptionalChainingNullishCoalescingPlugins = function() { return true; } + 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'); + }); + }); + describe('_addDecoratorPlugins', function() { it('should include babel transforms by default', function() { expect(this.addon._addDecoratorPlugins([], {}).length).to.equal(2, 'plugins added correctly'); From 55ac0b29cf8cb5d66a0a4495b768a2b01c7c2b03 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Thu, 19 Dec 2019 05:26:27 -0500 Subject: [PATCH 04/23] tests: add (failing) test for _getExtensions --- node-tests/addon-test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index 8521515e..1864c618 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -1031,6 +1031,23 @@ describe('ember-cli-babel', function() { }); }); + describe('_getExtensions', function() { + it('defaults to js only', function() { + expect(this.addon._getExtensions({})).to.have.members(['js']); + }); + it('adds ts automatically', function() { + this.addon._shouldIncludeTypeScriptPlugins = function() { return true; } + expect(this.addon._getExtensions({})).to.have.members(['js', 'ts']); + }); + it('respects user-configured extensions', function() { + expect(this.addon._getExtensions({ 'ember-cli-babel': { extensions: ['coffee'] } })).to.have.members(['coffee']); + }); + it('respects user-configured extensions even when adding TS plugin', function() { + this.addon._shouldIncludeTypeScriptPlugins = function() { return true; } + expect(this.addon._getExtensions({ 'ember-cli-babel': { extensions: ['coffee'] } })).to.have.members(['coffee']); + }); + }); + describe('buildBabelOptions', function() { this.timeout(0); From 7f81c4768d98e539727c0e3937e17a48bc8ad039 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Thu, 19 Dec 2019 05:27:11 -0500 Subject: [PATCH 05/23] fix: don't add ts to user-configured extensions --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e1a3962e..fd1a26cd 100644 --- a/index.js +++ b/index.js @@ -256,11 +256,11 @@ module.exports = { _getExtensions(config) { let shouldIncludeTypeScriptPlugins = this._shouldIncludeTypeScriptPlugins(); let emberCLIBabelConfig = config['ember-cli-babel'] || {}; - let extensions = emberCLIBabelConfig.extensions || ['js']; - if (shouldIncludeTypeScriptPlugins && !extensions.includes('ts')) { - extensions.push('ts'); + let defaultExtensions = ['js']; + if (shouldIncludeTypeScriptPlugins) { + defaultExtensions.push('ts'); } - return extensions; + return emberCLIBabelConfig.extensions || defaultExtensions; }, _getBabelOptions(config) { From 5a1f5a89039083af6620c7c7fd2856cffa93a5b8 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Thu, 19 Dec 2019 11:13:47 -0500 Subject: [PATCH 06/23] refactor: simplify extension determination --- index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/index.js b/index.js index fd1a26cd..28c25b05 100644 --- a/index.js +++ b/index.js @@ -256,11 +256,7 @@ module.exports = { _getExtensions(config) { let shouldIncludeTypeScriptPlugins = this._shouldIncludeTypeScriptPlugins(); let emberCLIBabelConfig = config['ember-cli-babel'] || {}; - let defaultExtensions = ['js']; - if (shouldIncludeTypeScriptPlugins) { - defaultExtensions.push('ts'); - } - return emberCLIBabelConfig.extensions || defaultExtensions; + return emberCLIBabelConfig.extensions || (shouldIncludeTypeScriptPlugins ? ['js', 'ts'] : ['js']); }, _getBabelOptions(config) { From e88eeb9e1c04b3edd390f09751ff36b0906ef8fe Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Thu, 19 Dec 2019 11:23:47 -0500 Subject: [PATCH 07/23] feat: added caching of ember-cli-typescript version check also s/_shouldIncludeTypeScriptPlugins/_shouldHandleTypeScript/ Co-authored-by: Dan Freeman --- index.js | 20 +++++++++++++------- node-tests/addon-test.js | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 28c25b05..9eb2e064 100644 --- a/index.js +++ b/index.js @@ -254,16 +254,16 @@ module.exports = { }, _getExtensions(config) { - let shouldIncludeTypeScriptPlugins = this._shouldIncludeTypeScriptPlugins(); + let shouldHandleTypeScript = this._shouldHandleTypeScript(); let emberCLIBabelConfig = config['ember-cli-babel'] || {}; - return emberCLIBabelConfig.extensions || (shouldIncludeTypeScriptPlugins ? ['js', 'ts'] : ['js']); + return emberCLIBabelConfig.extensions || (shouldHandleTypeScript ? ['js', 'ts'] : ['js']); }, _getBabelOptions(config) { let addonProvidedConfig = this._getAddonProvidedConfig(config); let shouldCompileModules = this._shouldCompileModules(config); let shouldIncludeHelpers = this._shouldIncludeHelpers(config); - let shouldIncludeTypeScriptPlugins = this._shouldIncludeTypeScriptPlugins(); + let shouldHandleTypeScript = this._shouldHandleTypeScript(); let shouldIncludeDecoratorPlugins = this._shouldIncludeDecoratorPlugins(config); let emberCLIBabelConfig = config['ember-cli-babel']; @@ -294,7 +294,7 @@ module.exports = { let userPlugins = addonProvidedConfig.plugins; let userPostTransformPlugins = addonProvidedConfig.postTransformPlugins; - if (shouldIncludeTypeScriptPlugins) { + if (shouldHandleTypeScript) { userPlugins = this._addTypeScriptPlugins(userPlugins.slice(), addonProvidedConfig.options); } @@ -326,10 +326,16 @@ module.exports = { return options; }, - _shouldIncludeTypeScriptPlugins() { - let checker = new VersionChecker(this.parent).for('ember-cli-typescript', 'npm'); + _shouldHandleTypeScript() { + if (this._cachedShouldHandleTypescript === undefined) { + // TODO: this doesn't account for things like in-repo addons and other + // weird inclusion structures + let checker = new VersionChecker(this.parent).for('ember-cli-typescript', 'npm'); - return checker.gte('4.0.0-alpha'); + this._cachedShouldHandleTypescript = checker.gte('4.0.0-alpha.0'); + } + + return this._cachedShouldHandleTypescript; }, _shouldIncludeOptionalChainingNullishCoalescingPlugins() { diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index 1864c618..b1cb8029 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -1036,14 +1036,14 @@ describe('ember-cli-babel', function() { expect(this.addon._getExtensions({})).to.have.members(['js']); }); it('adds ts automatically', function() { - this.addon._shouldIncludeTypeScriptPlugins = function() { return true; } + this.addon._shouldHandleTypeScript = function() { return true; } expect(this.addon._getExtensions({})).to.have.members(['js', 'ts']); }); it('respects user-configured extensions', function() { expect(this.addon._getExtensions({ 'ember-cli-babel': { extensions: ['coffee'] } })).to.have.members(['coffee']); }); it('respects user-configured extensions even when adding TS plugin', function() { - this.addon._shouldIncludeTypeScriptPlugins = function() { return true; } + this.addon._shouldHandleTypeScript = function() { return true; } expect(this.addon._getExtensions({ 'ember-cli-babel': { extensions: ['coffee'] } })).to.have.members(['coffee']); }); }); From b05c974ae0d970a61359c1e90edb2697fe4d6757 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Thu, 19 Dec 2019 16:37:44 -0500 Subject: [PATCH 08/23] fix: conditionally apply class feature ordering restrictions Co-authored-by: Dan Freeman --- index.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 9eb2e064..8388e845 100644 --- a/index.js +++ b/index.js @@ -344,6 +344,23 @@ module.exports = { return checker.gte('3.7.0'); }, + _buildClassFeaturePluginConstraints(constraints) { + // With older versions of ember-cli-typescript, class feature plugins like + // @babel/plugin-proposal-class-properties were run before the TS transform. + // With more recent language features like `declare` field modifiers, Babel + // now has assertions requiring that the TS transform runs first, so if we + // know we're responsible for setting that transform up, we follow those rules. + if (this._shouldHandleTypeScript()) { + constraints.after = constraints.after || []; + constraints.after.push('@babel/plugin-transform-typescript'); + } else { + constraints.before = constraints.before || []; + constraints.before.push('@babel/plugin-transform-typescript'); + } + + return constraints; + }, + _addTypeScriptPlugins(plugins) { const { hasPlugin, addPlugin } = require('ember-cli-babel-plugin-helpers'); const shouldIncludeOptionalChainingNullishCoalescingPlugins = this._shouldIncludeOptionalChainingNullishCoalescingPlugins(); @@ -424,10 +441,9 @@ module.exports = { addPlugin( plugins, [require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }], - { - before: ['@babel/plugin-proposal-class-properties'], - after: ['@babel/plugin-transform-typescript'] - } + this._buildClassFeaturePluginConstraints({ + before: ['@babel/plugin-proposal-class-properties'] + }) ); } @@ -442,9 +458,9 @@ module.exports = { addPlugin( plugins, [require.resolve('@babel/plugin-proposal-class-properties'), { loose: options.loose || false }], - { - after: ['@babel/plugin-proposal-decorators', '@babel/plugin-transform-typescript'] - } + this._buildClassFeaturePluginConstraints({ + after: ['@babel/plugin-proposal-decorators'] + }) ); } From 134b0a4aa6589299b88a5f7f7e0cb82f3d0641f0 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Thu, 19 Dec 2019 16:50:33 -0500 Subject: [PATCH 09/23] tests: test conditional class feature ordering restrictions --- node-tests/addon-test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index b1cb8029..8c61b15e 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -845,11 +845,19 @@ describe('ember-cli-babel', function() { expect(loosePlugins[1][1].loose).to.equal(true, 'loose setting added correctly'); }); - it('should include class fields and decorators after typescript if detected', function() { + it('should include class fields and decorators after typescript if handling typescript', function() { + this.addon._shouldHandleTypeScript = function() { return true; } let plugins = this.addon._addDecoratorPlugins(['@babel/plugin-transform-typescript'], {}); expect(plugins[0]).to.equal('@babel/plugin-transform-typescript', 'typescript still first'); expect(plugins.length).to.equal(3, 'class fields and decorators added'); }); + + it('should include class fields and decorators before typescript if not handling typescript', function() { + this.addon._shouldHandleTypeScript = function() { return false; } + let plugins = this.addon._addDecoratorPlugins(['@babel/plugin-transform-typescript'], {}); + expect(plugins.length).to.equal(3, 'class fields and decorators added'); + expect(plugins[2]).to.equal('@babel/plugin-transform-typescript', 'typescript is now last'); + }); }); describe('_shouldIncludeHelpers()', function() { From 2e79c2f876f356b9b6eabdcdfe7dfc3e3903f032 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Thu, 19 Dec 2019 16:58:29 -0500 Subject: [PATCH 10/23] fix: don't conditionally add optional chaining and nullish coalescing --- index.js | 61 +++++++++++++++++----------------------- node-tests/addon-test.js | 13 ++------- 2 files changed, 29 insertions(+), 45 deletions(-) diff --git a/index.js b/index.js index 8388e845..adfddd91 100644 --- a/index.js +++ b/index.js @@ -338,12 +338,6 @@ module.exports = { return this._cachedShouldHandleTypescript; }, - _shouldIncludeOptionalChainingNullishCoalescingPlugins() { - let checker = new VersionChecker(this.parent).for('typescript', 'npm'); - - return checker.gte('3.7.0'); - }, - _buildClassFeaturePluginConstraints(constraints) { // With older versions of ember-cli-typescript, class feature plugins like // @babel/plugin-proposal-class-properties were run before the TS transform. @@ -363,38 +357,35 @@ module.exports = { _addTypeScriptPlugins(plugins) { const { hasPlugin, addPlugin } = require('ember-cli-babel-plugin-helpers'); - const shouldIncludeOptionalChainingNullishCoalescingPlugins = this._shouldIncludeOptionalChainingNullishCoalescingPlugins(); - - if (shouldIncludeOptionalChainingNullishCoalescingPlugins) { - 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-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-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')) { diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index 8c61b15e..427f32f9 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -747,8 +747,8 @@ describe('ember-cli-babel', function() { }); describe('_addTypeScriptPlugins', function() { - it('should add only the TypeScript plugin by default', function() { - expect(this.addon._addTypeScriptPlugins([], {}).length).to.equal(1, 'plugin added correctly'); + it('should add TypeScript, optional chaining, and nullish coalescing operator plugins', function() { + expect(this.addon._addTypeScriptPlugins([], {}).length).to.equal(3, 'plugins added correctly'); }); it('should warn and not add the TypeScript plugin if already added', function() { @@ -763,16 +763,10 @@ describe('ember-cli-babel', function() { ['@babel/plugin-transform-typescript'] ], {} - ).length).to.equal(1, 'plugin was not added'); - }); - - it('should add optional chaining and nullish coalescing operator when told to', function() { - this.addon._shouldIncludeOptionalChainingNullishCoalescingPlugins = function() { return true; } - expect(this.addon._addTypeScriptPlugins([], {}).length).to.equal(3, 'plugins added correctly'); + ).length).to.equal(3, 'plugin was not added'); }); it('should warn and not add optional chaining if already added', function() { - this.addon._shouldIncludeOptionalChainingNullishCoalescingPlugins = function() { return true; } this.addon.project.ui = { writeWarnLine(message) { expect(message).to.match(/has added the optional chaining plugin to its build/); @@ -785,7 +779,6 @@ describe('ember-cli-babel', function() { }); it('should warn and not add nullish coalescing operator if already added', function() { - this.addon._shouldIncludeOptionalChainingNullishCoalescingPlugins = function() { return true; } this.addon.project.ui = { writeWarnLine(message) { expect(message).to.match(/has added the nullish coalescing operator plugin to its build/); From 14e75901c68fe491c3f072674509f285b99121fd Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Fri, 20 Dec 2019 13:07:59 -0500 Subject: [PATCH 11/23] refactor: get e-c-ts version from parent.addons --- index.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index adfddd91..0c2437b2 100644 --- a/index.js +++ b/index.js @@ -327,15 +327,9 @@ module.exports = { }, _shouldHandleTypeScript() { - if (this._cachedShouldHandleTypescript === undefined) { - // TODO: this doesn't account for things like in-repo addons and other - // weird inclusion structures - let checker = new VersionChecker(this.parent).for('ember-cli-typescript', 'npm'); - - this._cachedShouldHandleTypescript = checker.gte('4.0.0-alpha.0'); - } - - return this._cachedShouldHandleTypescript; + let typeScriptAddon = this.parent.addons.find(a => a.name === 'ember-cli-typescript'); + return typeof typeScriptAddon !== 'undefined' + && semver.gte(typeScriptAddon.pkg.version, '4.0.0-alpha.0'); }, _buildClassFeaturePluginConstraints(constraints) { From 24b8d09c07a23b0c89505d294e9060290e37eb5a Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Fri, 20 Dec 2019 13:41:53 -0500 Subject: [PATCH 12/23] tests: add test for _shouldHandleTypeScript --- node-tests/addon-test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index 427f32f9..b0068370 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -746,6 +746,30 @@ describe('ember-cli-babel', function() { }); }); + describe('_shouldHandleTypeScript', function() { + it('should return false by default', function() { + expect(this.addon._shouldHandleTypeScript({})).to.be.false; + }); + it('should return true when ember-cli-typescript >= 4.0.0-alpha.0 is installed', function() { + this.addon.parent.addons.push({ + name: 'ember-cli-typescript', + pkg: { + version: '4.0.0-alpha.0', + }, + }); + expect(this.addon._shouldHandleTypeScript({})).to.be.true; + }); + it('should return false when ember-cli-typescript < 4.0.0-alpha.0 is installed', function() { + this.addon.parent.addons.push({ + name: 'ember-cli-typescript', + pkg: { + version: '3.0.0', + }, + }); + expect(this.addon._shouldHandleTypeScript({})).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'); From 7c6db1500b9fdd875aab8f915201dab5262e86e6 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Fri, 20 Dec 2019 14:17:48 -0500 Subject: [PATCH 13/23] feat: add flag for manual override --- index.js | 25 +++++++++++++++---------- node-tests/addon-test.js | 27 ++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 0c2437b2..0fe359f7 100644 --- a/index.js +++ b/index.js @@ -254,7 +254,7 @@ module.exports = { }, _getExtensions(config) { - let shouldHandleTypeScript = this._shouldHandleTypeScript(); + let shouldHandleTypeScript = this._shouldHandleTypeScript(config); let emberCLIBabelConfig = config['ember-cli-babel'] || {}; return emberCLIBabelConfig.extensions || (shouldHandleTypeScript ? ['js', 'ts'] : ['js']); }, @@ -263,7 +263,7 @@ module.exports = { let addonProvidedConfig = this._getAddonProvidedConfig(config); let shouldCompileModules = this._shouldCompileModules(config); let shouldIncludeHelpers = this._shouldIncludeHelpers(config); - let shouldHandleTypeScript = this._shouldHandleTypeScript(); + let shouldHandleTypeScript = this._shouldHandleTypeScript(config); let shouldIncludeDecoratorPlugins = this._shouldIncludeDecoratorPlugins(config); let emberCLIBabelConfig = config['ember-cli-babel']; @@ -299,7 +299,7 @@ module.exports = { } if (shouldIncludeDecoratorPlugins) { - userPlugins = this._addDecoratorPlugins(userPlugins.slice(), addonProvidedConfig.options); + userPlugins = this._addDecoratorPlugins(userPlugins.slice(), addonProvidedConfig.options, config); } options.plugins = [].concat( @@ -326,19 +326,24 @@ module.exports = { return options; }, - _shouldHandleTypeScript() { - let typeScriptAddon = this.parent.addons.find(a => a.name === 'ember-cli-typescript'); + _shouldHandleTypeScript(config) { + let emberCLIBabelConfig = config['ember-cli-babel'] || {}; + if (typeof emberCLIBabelConfig.enableTypeScriptTransforms === 'boolean') { + return emberCLIBabelConfig.enableTypeScriptTransforms; + } + let typeScriptAddon = this.parent.addons + && this.parent.addons.find(a => a.name === 'ember-cli-typescript'); return typeof typeScriptAddon !== 'undefined' && semver.gte(typeScriptAddon.pkg.version, '4.0.0-alpha.0'); }, - _buildClassFeaturePluginConstraints(constraints) { + _buildClassFeaturePluginConstraints(constraints, config) { // With older versions of ember-cli-typescript, class feature plugins like // @babel/plugin-proposal-class-properties were run before the TS transform. // With more recent language features like `declare` field modifiers, Babel // now has assertions requiring that the TS transform runs first, so if we // know we're responsible for setting that transform up, we follow those rules. - if (this._shouldHandleTypeScript()) { + if (this._shouldHandleTypeScript(config)) { constraints.after = constraints.after || []; constraints.after.push('@babel/plugin-transform-typescript'); } else { @@ -413,7 +418,7 @@ module.exports = { return customOptions.disableDecoratorTransforms !== true; }, - _addDecoratorPlugins(plugins, options) { + _addDecoratorPlugins(plugins, options, config) { const { hasPlugin, addPlugin } = require('ember-cli-babel-plugin-helpers'); if (hasPlugin(plugins, '@babel/plugin-proposal-decorators')) { @@ -428,7 +433,7 @@ module.exports = { [require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }], this._buildClassFeaturePluginConstraints({ before: ['@babel/plugin-proposal-class-properties'] - }) + }, config) ); } @@ -445,7 +450,7 @@ module.exports = { [require.resolve('@babel/plugin-proposal-class-properties'), { loose: options.loose || false }], this._buildClassFeaturePluginConstraints({ after: ['@babel/plugin-proposal-decorators'] - }) + }, config) ); } diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index b0068370..b69e7516 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -768,6 +768,21 @@ 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; + }); + it('should return false when TypeScript transforms are manually disabled', function() { + expect(this.addon._shouldHandleTypeScript({ 'ember-cli-babel': { enableTypeScriptTransforms: false } })).to.be.false; + }); + it('should return false when TypeScript transforms are manually disabled, even when ember-cli-typescript >= 4.0.0-alpha.0 is installed', function() { + this.addon.parent.addons.push({ + name: 'ember-cli-typescript', + pkg: { + version: '4.0.0-alpha.0', + }, + }); + expect(this.addon._shouldHandleTypeScript({ 'ember-cli-babel': { enableTypeScriptTransforms: false } })).to.be.false; + }); }); describe('_addTypeScriptPlugins', function() { @@ -817,7 +832,7 @@ describe('ember-cli-babel', function() { describe('_addDecoratorPlugins', function() { it('should include babel transforms by default', function() { - expect(this.addon._addDecoratorPlugins([], {}).length).to.equal(2, 'plugins added correctly'); + expect(this.addon._addDecoratorPlugins([], {}, {}).length).to.equal(2, 'plugins added correctly'); }); it('should include only fields if it detects decorators plugin', function() { @@ -831,6 +846,7 @@ describe('ember-cli-babel', function() { this.addon._addDecoratorPlugins([ ['@babel/plugin-proposal-decorators'] ], + {}, {} ).length).to.equal(2, 'plugins were not added'); }); @@ -847,31 +863,32 @@ describe('ember-cli-babel', function() { [ ['@babel/plugin-proposal-class-properties'] ], + {}, {} ).length ).to.equal(2, 'plugins were not added'); }); it('should use babel options loose mode for class properties', function() { - let strictPlugins = this.addon._addDecoratorPlugins([], {}); + let strictPlugins = this.addon._addDecoratorPlugins([], {}, {}); expect(strictPlugins[1][1].loose).to.equal(false, 'loose is false if no option is provided'); - let loosePlugins = this.addon._addDecoratorPlugins([], { loose: true }); + let loosePlugins = this.addon._addDecoratorPlugins([], { loose: true }, {}); expect(loosePlugins[1][1].loose).to.equal(true, 'loose setting added correctly'); }); it('should include class fields and decorators after typescript if handling typescript', function() { this.addon._shouldHandleTypeScript = function() { return true; } - let plugins = this.addon._addDecoratorPlugins(['@babel/plugin-transform-typescript'], {}); + let plugins = this.addon._addDecoratorPlugins(['@babel/plugin-transform-typescript'], {}, {}); expect(plugins[0]).to.equal('@babel/plugin-transform-typescript', 'typescript still first'); expect(plugins.length).to.equal(3, 'class fields and decorators added'); }); it('should include class fields and decorators before typescript if not handling typescript', function() { this.addon._shouldHandleTypeScript = function() { return false; } - let plugins = this.addon._addDecoratorPlugins(['@babel/plugin-transform-typescript'], {}); + let plugins = this.addon._addDecoratorPlugins(['@babel/plugin-transform-typescript'], {}, {}); expect(plugins.length).to.equal(3, 'class fields and decorators added'); expect(plugins[2]).to.equal('@babel/plugin-transform-typescript', 'typescript is now last'); }); From ac58290139e2d0b78542a1c6d9984c5cc866e0da Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Mon, 30 Dec 2019 15:33:24 -0500 Subject: [PATCH 14/23] refactor: only enforce TS transform else case --- index.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/index.js b/index.js index 0fe359f7..de278d15 100644 --- a/index.js +++ b/index.js @@ -340,13 +340,7 @@ module.exports = { _buildClassFeaturePluginConstraints(constraints, config) { // With older versions of ember-cli-typescript, class feature plugins like // @babel/plugin-proposal-class-properties were run before the TS transform. - // With more recent language features like `declare` field modifiers, Babel - // now has assertions requiring that the TS transform runs first, so if we - // know we're responsible for setting that transform up, we follow those rules. - if (this._shouldHandleTypeScript(config)) { - constraints.after = constraints.after || []; - constraints.after.push('@babel/plugin-transform-typescript'); - } else { + if (!this._shouldHandleTypeScript(config)) { constraints.before = constraints.before || []; constraints.before.push('@babel/plugin-transform-typescript'); } From 21de7961f3916b801d0a8f0eed11cafab79c7a38 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Mon, 30 Dec 2019 15:39:50 -0500 Subject: [PATCH 15/23] feat: handle ts (in addition to js) by default --- index.js | 3 +-- node-tests/addon-test.js | 10 +--------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index de278d15..6bb81023 100644 --- a/index.js +++ b/index.js @@ -254,9 +254,8 @@ module.exports = { }, _getExtensions(config) { - let shouldHandleTypeScript = this._shouldHandleTypeScript(config); let emberCLIBabelConfig = config['ember-cli-babel'] || {}; - return emberCLIBabelConfig.extensions || (shouldHandleTypeScript ? ['js', 'ts'] : ['js']); + return emberCLIBabelConfig.extensions || ['js', 'ts']; }, _getBabelOptions(config) { diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index 1d73fc72..223462d8 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -1074,20 +1074,12 @@ describe('ember-cli-babel', function() { }); describe('_getExtensions', function() { - it('defaults to js only', function() { - expect(this.addon._getExtensions({})).to.have.members(['js']); - }); - it('adds ts automatically', function() { - this.addon._shouldHandleTypeScript = function() { return true; } + it('defaults to js and ts', function() { expect(this.addon._getExtensions({})).to.have.members(['js', 'ts']); }); it('respects user-configured extensions', function() { expect(this.addon._getExtensions({ 'ember-cli-babel': { extensions: ['coffee'] } })).to.have.members(['coffee']); }); - it('respects user-configured extensions even when adding TS plugin', function() { - this.addon._shouldHandleTypeScript = function() { return true; } - expect(this.addon._getExtensions({ 'ember-cli-babel': { extensions: ['coffee'] } })).to.have.members(['coffee']); - }); }); describe('buildBabelOptions', function() { From 802323f8fa0379de04b92f04b934f7e7dcbc72fb Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Wed, 8 Jan 2020 07:01:43 -0500 Subject: [PATCH 16/23] chore: s/\t/ / --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 6bb81023..131bec85 100644 --- a/index.js +++ b/index.js @@ -336,7 +336,7 @@ module.exports = { && semver.gte(typeScriptAddon.pkg.version, '4.0.0-alpha.0'); }, - _buildClassFeaturePluginConstraints(constraints, config) { + _buildClassFeaturePluginConstraints(constraints, config) { // With older versions of ember-cli-typescript, class feature plugins like // @babel/plugin-proposal-class-properties were run before the TS transform. if (!this._shouldHandleTypeScript(config)) { From 5d7a817b2effa5c90ca86970f34b59662fea7892 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Wed, 8 Jan 2020 07:04:57 -0500 Subject: [PATCH 17/23] chore: add ember-cli-typescript version to comment --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 131bec85..04939403 100644 --- a/index.js +++ b/index.js @@ -337,7 +337,7 @@ module.exports = { }, _buildClassFeaturePluginConstraints(constraints, config) { - // With older versions of ember-cli-typescript, class feature plugins like + // With versions of ember-cli-typescript < 4.0, class feature plugins like // @babel/plugin-proposal-class-properties were run before the TS transform. if (!this._shouldHandleTypeScript(config)) { constraints.before = constraints.before || []; From 5fb2aa02a0272dcf7a7722e4431dd83697c56ad3 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Wed, 8 Jan 2020 07:42:18 -0500 Subject: [PATCH 18/23] docs: document enableTypeScriptTransforms --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index 189c6a6b..54625547 100755 --- a/README.md +++ b/README.md @@ -19,6 +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) * [Addon usage](#addon-usage) + [Adding Custom Plugins](#adding-custom-plugins) + [Additional Trees](#additional-trees) @@ -121,6 +122,7 @@ interface EmberCLIBabelConfig { disablePresetEnv?: boolean; disableEmberModulesAPIPolyfill?: boolean; disableDecoratorTransforms?: boolean; + enableTypeScriptTransforms?: boolean; extensions?: string[]; }; } @@ -259,6 +261,40 @@ module.exports = function(defaults) { } ``` +#### Enabling TypeScript Transforms + +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. + +You can enable the TypeScript Babel transforms manually *without* +`ember-cli-typescript` by setting the `enableTypeScriptTransforms`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. + +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: + +```js +// ember-cli-build.js +module.exports = function(defaults) { + let app = new EmberApp(defaults, { + 'ember-cli-babel': { + enableTypeScriptTransforms: true + } + }); + + return app.toTree(); +} +``` + ### Addon usage #### Adding Custom Plugins From 63932609ee71abd1441ce43553dd46e0019dca86 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Thu, 9 Jan 2020 20:19:14 -0500 Subject: [PATCH 19/23] Revert "feat: handle ts (in addition to js) by default" This reverts commit 21de7961f3916b801d0a8f0eed11cafab79c7a38. --- index.js | 3 ++- node-tests/addon-test.js | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 04939403..8d2fe42e 100644 --- a/index.js +++ b/index.js @@ -254,8 +254,9 @@ module.exports = { }, _getExtensions(config) { + let shouldHandleTypeScript = this._shouldHandleTypeScript(config); let emberCLIBabelConfig = config['ember-cli-babel'] || {}; - return emberCLIBabelConfig.extensions || ['js', 'ts']; + return emberCLIBabelConfig.extensions || (shouldHandleTypeScript ? ['js', 'ts'] : ['js']); }, _getBabelOptions(config) { diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index 223462d8..1d73fc72 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -1074,12 +1074,20 @@ describe('ember-cli-babel', function() { }); describe('_getExtensions', function() { - it('defaults to js and ts', function() { + it('defaults to js only', function() { + expect(this.addon._getExtensions({})).to.have.members(['js']); + }); + it('adds ts automatically', function() { + this.addon._shouldHandleTypeScript = function() { return true; } expect(this.addon._getExtensions({})).to.have.members(['js', 'ts']); }); it('respects user-configured extensions', function() { expect(this.addon._getExtensions({ 'ember-cli-babel': { extensions: ['coffee'] } })).to.have.members(['coffee']); }); + it('respects user-configured extensions even when adding TS plugin', function() { + this.addon._shouldHandleTypeScript = function() { return true; } + expect(this.addon._getExtensions({ 'ember-cli-babel': { extensions: ['coffee'] } })).to.have.members(['coffee']); + }); }); describe('buildBabelOptions', function() { From 9bf6424154f1f1ec1004ebb5ae9821c50b2841ef Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Sat, 18 Jan 2020 10:22:54 -0500 Subject: [PATCH 20/23] fix: e-c-ts was released as 4.0.0-alpha.1 --- index.js | 2 +- node-tests/addon-test.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 8d2fe42e..cc904887 100644 --- a/index.js +++ b/index.js @@ -334,7 +334,7 @@ module.exports = { let typeScriptAddon = this.parent.addons && this.parent.addons.find(a => a.name === 'ember-cli-typescript'); return typeof typeScriptAddon !== 'undefined' - && semver.gte(typeScriptAddon.pkg.version, '4.0.0-alpha.0'); + && semver.gte(typeScriptAddon.pkg.version, '4.0.0-alpha.1'); }, _buildClassFeaturePluginConstraints(constraints, config) { diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index 1d73fc72..dbfe2108 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -750,16 +750,16 @@ describe('ember-cli-babel', function() { it('should return false by default', function() { expect(this.addon._shouldHandleTypeScript({})).to.be.false; }); - it('should return true when ember-cli-typescript >= 4.0.0-alpha.0 is installed', function() { + it('should return true when ember-cli-typescript >= 4.0.0-alpha.1 is installed', function() { this.addon.parent.addons.push({ name: 'ember-cli-typescript', pkg: { - version: '4.0.0-alpha.0', + version: '4.0.0-alpha.1', }, }); expect(this.addon._shouldHandleTypeScript({})).to.be.true; }); - it('should return false when ember-cli-typescript < 4.0.0-alpha.0 is installed', function() { + it('should return false when ember-cli-typescript < 4.0.0-alpha.1 is installed', function() { this.addon.parent.addons.push({ name: 'ember-cli-typescript', pkg: { @@ -774,11 +774,11 @@ describe('ember-cli-babel', function() { it('should return false when TypeScript transforms are manually disabled', function() { expect(this.addon._shouldHandleTypeScript({ 'ember-cli-babel': { enableTypeScriptTransforms: false } })).to.be.false; }); - it('should return false when TypeScript transforms are manually disabled, even when ember-cli-typescript >= 4.0.0-alpha.0 is installed', function() { + 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({ name: 'ember-cli-typescript', pkg: { - version: '4.0.0-alpha.0', + version: '4.0.0-alpha.1', }, }); expect(this.addon._shouldHandleTypeScript({ 'ember-cli-babel': { enableTypeScriptTransforms: false } })).to.be.false; From f6adfe19b9aa02fe0d97f09f86cf517fe2175a1d Mon Sep 17 00:00:00 2001 From: Dan Freeman Date: Mon, 20 Jan 2020 11:02:41 -0500 Subject: [PATCH 21/23] fix: don't emit modules for .d.ts files --- index.js | 13 +++++++++++-- node-tests/addon-test.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) 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* () { From d0db857cf75745f4f256059259eff4ca6727861c Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Mon, 27 Jan 2020 16:15:31 -0500 Subject: [PATCH 22/23] chore: upgrade to latest @babel packages --- package.json | 6 +++--- yarn.lock | 55 +++++++++------------------------------------------- 2 files changed, 12 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 29ba5bc5..f945314a 100644 --- a/package.json +++ b/package.json @@ -43,11 +43,11 @@ "@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.7.4", - "@babel/plugin-proposal-optional-chaining": "^7.7.5", + "@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.7.4", + "@babel/plugin-transform-typescript": "^7.8.3", "@babel/polyfill": "^7.8.3", "@babel/preset-env": "^7.8.3", "@babel/runtime": "^7.8.3", diff --git a/yarn.lock b/yarn.lock index 9ddbd675..a4445663 100644 --- a/yarn.lock +++ b/yarn.lock @@ -84,7 +84,7 @@ levenary "^1.1.0" semver "^5.5.0" -"@babel/helper-create-class-features-plugin@^7.7.4", "@babel/helper-create-class-features-plugin@^7.8.3": +"@babel/helper-create-class-features-plugin@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.8.3.tgz#5b94be88c255f140fd2c10dd151e7f98f4bff397" integrity sha512-qmp4pD7zeTxsv0JNecSBsEmG1ei2MqwJq4YQcK3ZWm/0t07QstWfvuV/vm3Qt5xNMFETn2SZqpMx2MQzbtq+KA== @@ -300,14 +300,6 @@ "@babel/helper-plugin-utils" "^7.8.3" "@babel/plugin-syntax-json-strings" "^7.8.0" -"@babel/plugin-proposal-nullish-coalescing-operator@^7.7.4": - version "7.7.4" - resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.7.4.tgz#7db302c83bc30caa89e38fee935635ef6bd11c28" - integrity sha512-TbYHmr1Gl1UC7Vo2HVuj/Naci5BEGNZ0AJhzqD2Vpr6QPFWpUmBRLrIDjedzx7/CShq0bRDS2gI4FIs77VHLVQ== - dependencies: - "@babel/helper-plugin-utils" "^7.0.0" - "@babel/plugin-syntax-nullish-coalescing-operator" "^7.7.4" - "@babel/plugin-proposal-nullish-coalescing-operator@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.8.3.tgz#e4572253fdeed65cddeecfdab3f928afeb2fd5d2" @@ -332,14 +324,6 @@ "@babel/helper-plugin-utils" "^7.8.3" "@babel/plugin-syntax-optional-catch-binding" "^7.8.0" -"@babel/plugin-proposal-optional-chaining@^7.7.5": - version "7.7.5" - resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.7.5.tgz#f0835f044cef85b31071a924010a2a390add11d4" - integrity sha512-sOwFqT8JSchtJeDD+CjmWCaiFoLxY4Ps7NjvwHC/U7l4e9i5pTRNt8nDMIFSOUL+ncFbYSwruHM8WknYItWdXw== - dependencies: - "@babel/helper-plugin-utils" "^7.0.0" - "@babel/plugin-syntax-optional-chaining" "^7.7.4" - "@babel/plugin-proposal-optional-chaining@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.8.3.tgz#ae10b3214cb25f7adb1f3bc87ba42ca10b7e2543" @@ -384,13 +368,6 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.0" -"@babel/plugin-syntax-nullish-coalescing-operator@^7.7.4": - version "7.7.4" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.7.4.tgz#e53b751d0c3061b1ba3089242524b65a7a9da12b" - integrity sha512-XKh/yIRPiQTOeBg0QJjEus5qiSKucKAiApNtO1psqG7D17xmE+X2i5ZqBEuSvo0HRuyPaKaSN/Gy+Ha9KFQolw== - dependencies: - "@babel/helper-plugin-utils" "^7.0.0" - "@babel/plugin-syntax-nullish-coalescing-operator@^7.8.0": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.8.3.tgz#167ed70368886081f74b5c36c65a88c03b66d1a9" @@ -412,13 +389,6 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.0" -"@babel/plugin-syntax-optional-chaining@^7.7.4": - version "7.7.4" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.7.4.tgz#c91fdde6de85d2eb8906daea7b21944c3610c901" - integrity sha512-2MqYD5WjZSbJdUagnJvIdSfkb/ucOC9/1fRJxm7GAxY6YQLWlUvkfxoNbUPcPLHJyetKUDQ4+yyuUyAoc0HriA== - dependencies: - "@babel/helper-plugin-utils" "^7.0.0" - "@babel/plugin-syntax-optional-chaining@^7.8.0": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.8.3.tgz#4f69c2ab95167e0180cd5336613f8c5788f7d48a" @@ -433,20 +403,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.3" -"@babel/plugin-syntax-typescript@^7.2.0": +"@babel/plugin-syntax-typescript@^7.2.0", "@babel/plugin-syntax-typescript@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.8.3.tgz#c1f659dda97711a569cef75275f7e15dcaa6cabc" integrity sha512-GO1MQ/SGGGoiEXY0e0bSpHimJvxqB7lktLLIq2pv8xG7WZ8IMEle74jIe1FhprHBWjwjZtXHkycDLZXIWM5Wfg== dependencies: "@babel/helper-plugin-utils" "^7.8.3" -"@babel/plugin-syntax-typescript@^7.7.4": - version "7.7.4" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.7.4.tgz#5d037ffa10f3b25a16f32570ebbe7a8c2efa304b" - integrity sha512-77blgY18Hud4NM1ggTA8xVT/dBENQf17OpiToSa2jSmEY3fWXD2jwrdVlO4kq5yzUTeF15WSQ6b4fByNvJcjpQ== - dependencies: - "@babel/helper-plugin-utils" "^7.0.0" - "@babel/plugin-transform-arrow-functions@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.8.3.tgz#82776c2ed0cd9e1a49956daeb896024c9473b8b6" @@ -694,14 +657,14 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.3" -"@babel/plugin-transform-typescript@^7.7.4": - version "7.7.4" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.7.4.tgz#2974fd05f4e85c695acaf497f432342de9fc0636" - integrity sha512-X8e3tcPEKnwwPVG+vP/vSqEShkwODOEeyQGod82qrIuidwIrfnsGn11qPM1jBLF4MqguTXXYzm58d0dY+/wdpg== +"@babel/plugin-transform-typescript@^7.8.3": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.8.3.tgz#be6f01a7ef423be68e65ace1f04fc407e6d88917" + integrity sha512-Ebj230AxcrKGZPKIp4g4TdQLrqX95TobLUWKd/CwG7X1XHUH1ZpkpFvXuXqWbtGRWb7uuEWNlrl681wsOArAdQ== dependencies: - "@babel/helper-create-class-features-plugin" "^7.7.4" - "@babel/helper-plugin-utils" "^7.0.0" - "@babel/plugin-syntax-typescript" "^7.7.4" + "@babel/helper-create-class-features-plugin" "^7.8.3" + "@babel/helper-plugin-utils" "^7.8.3" + "@babel/plugin-syntax-typescript" "^7.8.3" "@babel/plugin-transform-typescript@~7.4.0": version "7.4.5" From 4ab55d1f44776f3579e22d655953a59f207bbacf Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Mon, 27 Jan 2020 16:38:26 -0500 Subject: [PATCH 23/23] refactor: don't explicitly add optional-chaining/nullish coalescing As of 7.8.0, @babel/preset-env enables optional-chaining and nullish-coalescing by default. --- README.md | 22 +++++++++---------- index.js | 38 ++++----------------------------- node-tests/addon-test.js | 46 ++++++++-------------------------------- package.json | 2 -- 4 files changed, 23 insertions(+), 85 deletions(-) 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..0cf54828 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -804,28 +804,24 @@ 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; + it('should return true when the TypeScript transform is manually enabled', function() { + 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; + it('should return false when the TypeScript transforms is manually disabled', function() { + 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() { + it('should return false when the TypeScript transform is manually disabled, even when ember-cli-typescript >= 4.0.0-alpha.1 is installed', function() { this.addon.parent.addons.push({ name: 'ember-cli-typescript', pkg: { 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",