Skip to content

Commit 4925940

Browse files
authored
Merge pull request #365 from typed-ember/class-field-ordering
[v2] Ensure consistency with `tsc` re: class property initialization order
2 parents 8302e53 + 356e434 commit 4925940

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

tests/unit/build-test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,16 @@ module('Unit | Build', function() {
2727
assert.ok(fromTs);
2828
assert.equal(fromTs, 'From test-support');
2929
});
30+
31+
test('property initialization occurs in the right order', function(assert) {
32+
class TestClass {
33+
// we shouldn't encourage folks to write code like this, but tsc ensures
34+
// that constructor param fields are set before field initializers run
35+
field = this.constructorParam;
36+
constructor(private constructorParam: string) {}
37+
}
38+
39+
let instance = new TestClass('hello');
40+
assert.equal(instance.field, 'hello');
41+
});
3042
});

ts/addon.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export default addon({
6767
// preprocessor registry, so we need to beat it to the punch.
6868
this._registerBabelExtension();
6969

70-
this._addPluginIfMissing('@babel/plugin-transform-typescript');
7170
this._addPluginIfMissing(
7271
'@babel/plugin-proposal-class-properties',
7372
{ loose: true },
@@ -76,6 +75,10 @@ export default addon({
7675
after: ['@babel/plugin-proposal-decorators'],
7776
}
7877
);
78+
79+
// Needs to come after the class properties plugin (see tests/unit/build-test.ts -
80+
// "property initialization occurs in the right order")
81+
this._addPluginIfMissing('@babel/plugin-transform-typescript');
7982
},
8083

8184
shouldIncludeChildAddon(addon) {

0 commit comments

Comments
 (0)