Skip to content

Commit 2f15255

Browse files
committed
add failed test for using action as a variable name
1 parent 00933bb commit 2f15255

3 files changed

Lines changed: 88 additions & 1 deletion

File tree

__tests__/index-test.js

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ function transform7(source, _plugins) {
2525

2626
function transformWithPresetEnv(source) {
2727
let result = babel7.transformSync(source, {
28-
plugins: [[Plugin]],
28+
plugins: [
29+
[Plugin],
30+
['@babel/plugin-proposal-decorators', { legacy: true }],
31+
],
2932
presets: [['@babel/preset-env', { targets: { ie: '8' }, modules: false }]],
3033
});
3134

@@ -422,3 +425,70 @@ describe('when used with typescript', () => {
422425
expect(actual).toEqual(`Ember.addObserver();`);
423426
});
424427
});
428+
429+
describe('when used with native classes and decorators', () => {
430+
it('allows "action" to be used as a variable name', () => {
431+
let source = `
432+
import { action } from '@ember/object';
433+
import Controller from '@ember/controller';
434+
435+
export default class MyController extends Controller {
436+
@action
437+
addAction(action) {
438+
this.actions.pushObject(action);
439+
}
440+
}
441+
`;
442+
443+
let actual = transformWithPresetEnv(source);
444+
445+
expect(actual)
446+
.toEqual(`function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
447+
448+
var _dec, _class;
449+
450+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
451+
452+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
453+
454+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
455+
456+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
457+
458+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
459+
460+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
461+
462+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
463+
464+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
465+
466+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
467+
468+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
469+
470+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
471+
472+
var MyController = (_dec = Ember._action, (_class = /*#__PURE__*/function (_Ember$Controller) {
473+
_inherits(MyController, _Ember$Controller);
474+
475+
var _super = _createSuper(MyController);
476+
477+
function MyController() {
478+
_classCallCheck(this, MyController);
479+
480+
return _super.apply(this, arguments);
481+
}
482+
483+
_createClass(MyController, [{
484+
key: "addAction",
485+
value: function addAction(action) {
486+
this.actions.pushObject(action);
487+
}
488+
}]);
489+
490+
return MyController;
491+
}(Ember.Controller), (_applyDecoratedDescriptor(_class.prototype, "addAction", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "addAction"), _class.prototype)), _class));
492+
export { MyController as default };`);
493+
});
494+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"devDependencies": {
3434
"@babel/core": "^7.12.10",
35+
"@babel/plugin-proposal-decorators": "^7.12.12",
3536
"@babel/plugin-transform-typescript": "^7.12.1",
3637
"@babel/preset-env": "^7.12.11",
3738
"babel-core": "^6.25.0",

yarn.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,15 @@
312312
"@babel/helper-create-class-features-plugin" "^7.12.1"
313313
"@babel/helper-plugin-utils" "^7.10.4"
314314

315+
"@babel/plugin-proposal-decorators@^7.12.12":
316+
version "7.12.12"
317+
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-decorators/-/plugin-proposal-decorators-7.12.12.tgz#067a6d3d6ca86d54cf56bb183239199c20daeafe"
318+
integrity sha512-fhkE9lJYpw2mjHelBpM2zCbaA11aov2GJs7q4cFaXNrWx0H3bW58H9Esy2rdtYOghFBEYUDRIpvlgi+ZD+AvvQ==
319+
dependencies:
320+
"@babel/helper-create-class-features-plugin" "^7.12.1"
321+
"@babel/helper-plugin-utils" "^7.10.4"
322+
"@babel/plugin-syntax-decorators" "^7.12.1"
323+
315324
"@babel/plugin-proposal-dynamic-import@^7.12.1":
316325
version "7.12.1"
317326
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.12.1.tgz#43eb5c2a3487ecd98c5c8ea8b5fdb69a2749b2dc"
@@ -416,6 +425,13 @@
416425
dependencies:
417426
"@babel/helper-plugin-utils" "^7.10.4"
418427

428+
"@babel/plugin-syntax-decorators@^7.12.1":
429+
version "7.12.1"
430+
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-decorators/-/plugin-syntax-decorators-7.12.1.tgz#81a8b535b284476c41be6de06853a8802b98c5dd"
431+
integrity sha512-ir9YW5daRrTYiy9UJ2TzdNIJEZu8KclVzDcfSt4iEmOtwQ4llPtWInNKJyKnVXp1vE4bbVd5S31M/im3mYMO1w==
432+
dependencies:
433+
"@babel/helper-plugin-utils" "^7.10.4"
434+
419435
"@babel/plugin-syntax-dynamic-import@^7.8.0":
420436
version "7.8.3"
421437
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.8.3.tgz#62bf98b2da3cd21d626154fc96ee5b3cb68eacb3"

0 commit comments

Comments
 (0)