diff --git a/broccoli/to-es5.js b/broccoli/to-es5.js index ae56fdb28c8..ba9f6fa7e9a 100644 --- a/broccoli/to-es5.js +++ b/broccoli/to-es5.js @@ -9,6 +9,8 @@ module.exports = function toES6(tree, _options) { options.sourceMaps = true; options.plugins = [ injectBabelHelpers, + ['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true, legacy: false }], + ['@babel/plugin-proposal-class-properties'], ['@babel/transform-template-literals', { loose: true }], ['@babel/transform-literals'], ['@babel/transform-arrow-functions'], diff --git a/package.json b/package.json index 424c2e672b7..7667946090c 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,21 @@ "resolve": "^1.6.0" }, "devDependencies": { + "@babel/helper-module-imports": "^7.0.0", + "@babel/plugin-proposal-class-properties": "^7.2.1", + "@babel/plugin-proposal-decorators": "^7.2.0", + "@babel/plugin-transform-arrow-functions": "^7.2.0", + "@babel/plugin-transform-block-scoping": "^7.2.0", + "@babel/plugin-transform-classes": "^7.2.0", + "@babel/plugin-transform-computed-properties": "^7.2.0", + "@babel/plugin-transform-destructuring": "^7.2.0", + "@babel/plugin-transform-literals": "^7.2.0", + "@babel/plugin-transform-modules-amd": "^7.2.0", + "@babel/plugin-transform-object-assign": "^7.2.0", + "@babel/plugin-transform-parameters": "^7.2.0", + "@babel/plugin-transform-shorthand-properties": "^7.2.0", + "@babel/plugin-transform-spread": "^7.2.0", + "@babel/plugin-transform-template-literals": "^7.2.0", "@glimmer/compiler": "^0.36.4", "@glimmer/env": "^0.1.7", "@glimmer/interfaces": "^0.36.4", @@ -92,19 +107,6 @@ "babel-plugin-debug-macros": "^0.2.0", "babel-plugin-filter-imports": "^2.0.4", "babel-plugin-module-resolver": "^3.1.1", - "@babel/helper-module-imports": "^7.0.0", - "@babel/plugin-transform-arrow-functions": "^7.2.0", - "@babel/plugin-transform-block-scoping": "^7.2.0", - "@babel/plugin-transform-classes": "^7.2.0", - "@babel/plugin-transform-computed-properties": "^7.2.0", - "@babel/plugin-transform-destructuring": "^7.2.0", - "@babel/plugin-transform-literals": "^7.2.0", - "@babel/plugin-transform-modules-amd": "^7.2.0", - "@babel/plugin-transform-parameters": "^7.2.0", - "@babel/plugin-transform-shorthand-properties": "^7.2.0", - "@babel/plugin-transform-spread": "^7.2.0", - "@babel/plugin-transform-template-literals": "^7.2.0", - "@babel/plugin-transform-object-assign": "^7.2.0", "babel-template": "^6.26.0", "backburner.js": "^2.4.2", "broccoli-babel-transpiler": "^7.1.1", diff --git a/packages/@ember/-internals/metal/tests/computed_test.js b/packages/@ember/-internals/metal/tests/computed_test.js index 77a3483ab3e..f119c53d565 100644 --- a/packages/@ember/-internals/metal/tests/computed_test.js +++ b/packages/@ember/-internals/metal/tests/computed_test.js @@ -989,39 +989,27 @@ moduleFor( } ); -function addComputedTo(klass, descriptor, dependents) { - let proto = klass.prototype; - - Object.defineProperty(proto, name, descriptor); - - let propertyDescriptor = Object.getOwnPropertyDescriptor(proto, name); - - if (dependents) { - return computed(dependents)(proto, name, propertyDescriptor); - } - - return computed(proto, name, propertyDescriptor); -} - moduleFor( 'computed - decorator - cacheable', class extends AbstractTestCase { beforeEach() { - class TestObj {} + + count = 0; let func = function() { count++; return 'bar ' + count; }; - addComputedTo(TestObj, { - key: 'foo', - descriptor: { - configurable: false, - enumerable: true, - get: func, - set: func, - }, - }); + + class TestObj { + @computed() + get foo() { + return func(); + } + set foo() { + return func(); + } + } obj = new TestObj(); } @@ -1119,59 +1107,39 @@ moduleFor( 'computed - decorator', class extends AbstractTestCase { ['@test computed property asserts the presence of a getter'](assert) { - class TestObj {} - assert.throws(() => { - addComputedTo(TestObj, { - key: 'nonGetter', - descriptor: { - configurable: false, - enumerable: true, - writeable: true, - value: () => true, // method + class TestObj { + @computed() + nonGetter() { + return true; } - }); + } + + new TestObj(); }, /not a native accessor/); } ['@test computed property works with a getter'](assert) { - class TestObj {} - - addComputedTo(TestObj, { - key: 'someGetter', - descriptor: { - configurable: false, - get: () => true, + class TestObj { + @computed() + get someGetter() { + return true; } - }); + } let instance = new TestObj(); assert.ok(instance.someGetter); } ['@test computed property with dependent key and getter'](assert) { - class TestObj {} + class TestObj { + @computed() other = true; - addComputedTo(TestObj, { - key: 'other', - descriptor: { - value: true, - writable: true, + @computed('other') + get someGetter() { + return `${this.other}`; } - }); - addComputedTo( - TestObj, - { - key: 'someGetter', - descriptor: { - configurable: false, - get: function() { - return `${this.other}`; - }, - } - }, - 'other' - ); + } let instance = new TestObj(); assert.equal(instance.someGetter, 'true'); diff --git a/yarn.lock b/yarn.lock index fdd7e8ab24b..36f1f32cc35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -64,6 +64,17 @@ "@babel/traverse" "^7.1.0" "@babel/types" "^7.0.0" +"@babel/helper-create-class-features-plugin@^7.2.1": + version "7.2.1" + resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.2.1.tgz#f6e8027291669ef64433220dc8327531233f1161" + integrity sha512-EsEP7XLFmcJHjcuFYBxYD1FkP0irC8C9fsrt2tX/jrAi/eTnFI6DOPgVFb+WREeg1GboF+Ib+nCHbGBodyAXSg== + dependencies: + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-member-expression-to-functions" "^7.0.0" + "@babel/helper-optimise-call-expression" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-replace-supers" "^7.1.0" + "@babel/helper-define-map@^7.1.0": version "7.1.0" resolved "https://registry.yarnpkg.com/@babel/helper-define-map/-/helper-define-map-7.1.0.tgz#3b74caec329b3c80c116290887c0dd9ae468c20c" @@ -227,6 +238,24 @@ "@babel/helper-remap-async-to-generator" "^7.1.0" "@babel/plugin-syntax-async-generators" "^7.2.0" +"@babel/plugin-proposal-class-properties@^7.2.1": + version "7.2.1" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.2.1.tgz#c734a53e0a1ec40fe5c22ee5069d26da3b187d05" + integrity sha512-/4FKFChkQ2Jgb8lBDsvFX496YTi7UWTetVgS8oJUpX1e/DlaoeEK57At27ug8Hu2zI2g8bzkJ+8k9qrHZRPGPA== + dependencies: + "@babel/helper-create-class-features-plugin" "^7.2.1" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-proposal-decorators@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-decorators/-/plugin-proposal-decorators-7.2.0.tgz#6b4278282a6f5dd08b5d89b94f21aa1671fea071" + integrity sha512-yrDmvCsOMvNPpjCC6HMseiac2rUuQdeNqUyPU+3QbW7gLg/APX0c/7l9i/aulSICJQOkP6/4EHxkcB4d4DqZhg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-replace-supers" "^7.1.0" + "@babel/helper-split-export-declaration" "^7.0.0" + "@babel/plugin-syntax-decorators" "^7.2.0" + "@babel/plugin-proposal-json-strings@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-json-strings/-/plugin-proposal-json-strings-7.2.0.tgz#568ecc446c6148ae6b267f02551130891e29f317" @@ -267,6 +296,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-syntax-decorators@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-decorators/-/plugin-syntax-decorators-7.2.0.tgz#c50b1b957dcc69e4b1127b65e1c33eef61570c1b" + integrity sha512-38QdqVoXdHUQfTpZo3rQwqQdWtCn5tMv4uV6r2RMfTqNBuv4ZBhz79SfaQWKTVmxHjeFv/DnXVC/+agHCklYWA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-json-strings@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.2.0.tgz#72bd13f6ffe1d25938129d2a186b11fd62951470" @@ -1362,11 +1398,6 @@ babel-plugin-syntax-async-functions@^6.8.0: resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95" integrity sha1-ytnK0RkbWtY0vzCuCHI5HgZHvpU= -babel-plugin-syntax-decorators@^6.1.18: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-decorators/-/babel-plugin-syntax-decorators-6.13.0.tgz#312563b4dbde3cc806cee3e416cceeaddd11ac0b" - integrity sha1-MSVjtNvePMgGzuPkFszurd0RrAs= - babel-plugin-syntax-exponentiation-operator@^6.8.0: version "6.13.0" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de" @@ -1386,15 +1417,6 @@ babel-plugin-transform-async-to-generator@^6.22.0: babel-plugin-syntax-async-functions "^6.8.0" babel-runtime "^6.22.0" -babel-plugin-transform-decorators-legacy@^1.3.5: - version "1.3.5" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-decorators-legacy/-/babel-plugin-transform-decorators-legacy-1.3.5.tgz#0e492dffa0edd70529072887f8aa86d4dd8b40a1" - integrity sha512-jYHwjzRXRelYQ1uGm353zNzf3QmtdCfvJbuYTZ4gKveK7M9H1fs3a5AKdY1JUDl0z97E30ukORW1dzhWvsabtA== - dependencies: - babel-plugin-syntax-decorators "^6.1.18" - babel-runtime "^6.2.0" - babel-template "^6.3.0" - babel-plugin-transform-es2015-arrow-functions@^6.22.0: version "6.22.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221" @@ -1667,7 +1689,7 @@ babel-register@^6.26.0: mkdirp "^0.5.1" source-map-support "^0.4.15" -babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0: +babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" integrity sha1-llxwWGaOgrVde/4E/yM3vItWR/4= @@ -1675,7 +1697,7 @@ babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtime@^6.22.0, babel-runtim core-js "^2.4.0" regenerator-runtime "^0.11.0" -babel-template@^6.24.1, babel-template@^6.26.0, babel-template@^6.3.0: +babel-template@^6.24.1, babel-template@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02" integrity sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI=