Skip to content

Commit

Permalink
Merge pull request #502 from NullVoxPopuli/ensure-that-transform-clas…
Browse files Browse the repository at this point in the history
…s-static-block-is-provided

Ensure that plugin-transform-class-static-block is provided
  • Loading branch information
ef4 authored Sep 26, 2023
2 parents af8224b + 2794a87 commit 9ae9c9c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/ember-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ function _getModuleResolutionPlugins(config) {
function _getProposalDecoratorsAndClassPlugins(config) {
if (!config.shouldIgnoreDecoratorAndClassPlugins) {
return [
/**
* Required for apps to use `@ember/template-compliation`
* for transforming templates from babel-plugin-ember-template-compilation
* which shipped in ember-cli-htmlbars 6.2
*
* Normally this plugin wouldn't be required because the feature has shipped
* in all browsers, but because we have legacy decorators, and
* legacy decorators do not support parsing the static block syntax,
* we need to compile it away.
*/
["@babel/plugin-transform-class-static-block"],
["@babel/plugin-proposal-decorators", { legacy: true }],
["@babel/plugin-proposal-class-properties"],
];
Expand Down
26 changes: 26 additions & 0 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,32 @@ describe('ember-cli-babel', function() {
});
}));

describe('static class blocks', function() {
it('can compile static blocks', co.wrap(function*(){
input.write({
'foo.js': stripIndent`
let Second = class Second extends Component {
static {
// Set Foo.bar = 1;
this.bar = 1;
}
}
`
});

subject = this.addon.transpileTree(input.path());
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
"foo.js": "function _typeof(o) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o; }, _typeof(o); }\ndefine(\"foo\", [], function () {\n \"use strict\";\n\n var _class;\n 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, _toPropertyKey(descriptor.key), descriptor); } }\n function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\n function _toPropertyKey(arg) { var key = _toPrimitive(arg, \"string\"); return _typeof(key) === \"symbol\" ? key : String(key); }\n function _toPrimitive(input, hint) { if (_typeof(input) !== \"object\" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || \"default\"); if (_typeof(res) !== \"object\") return res; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (hint === \"string\" ? String : Number)(input); }\n function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n 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 } }); Object.defineProperty(subClass, \"prototype\", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }\n function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n 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); }; }\n function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } else if (call !== void 0) { throw new TypeError(\"Derived constructors may only return object or undefined\"); } return _assertThisInitialized(self); }\n function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n function _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }\n function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n var Second = (_class = /*#__PURE__*/function (_Component) {\n _inherits(Second, _Component);\n var _super = _createSuper(Second);\n function Second() {\n _classCallCheck(this, Second);\n return _super.apply(this, arguments);\n }\n return _createClass(Second);\n }(Component), _class.bar = 1, _class);\n});"
});
}));
});

describe('decorators and class fields', function() {
it(
"can compile decorators",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@babel/helper-compilation-targets": "^7.20.7",
"@babel/plugin-proposal-class-properties": "^7.16.5",
"@babel/plugin-proposal-decorators": "^7.20.13",
"@babel/plugin-transform-class-static-block": "^7.22.11",
"@babel/plugin-proposal-private-methods": "^7.16.5",
"@babel/plugin-proposal-private-property-in-object": "^7.20.5",
"@babel/plugin-transform-modules-amd": "^7.20.11",
Expand Down

0 comments on commit 9ae9c9c

Please sign in to comment.