-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Greater spec compliance for class properties (#4544)
* Desugar class properties to Object.defineProperty per spec * Define uninitialized static class properties with value=undefined * Make class-properties increased spec compliance opt-in (spec: true)
- Loading branch information
Showing
39 changed files
with
466 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...abel-plugin-transform-class-properties/test/fixtures/spec/constructor-collision/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var foo = "bar"; | ||
|
||
class Foo { | ||
bar = foo; | ||
|
||
constructor() { | ||
var foo = "foo"; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...el-plugin-transform-class-properties/test/fixtures/spec/constructor-collision/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var foo = "bar"; | ||
|
||
var Foo = function Foo() { | ||
babelHelpers.classCallCheck(this, Foo); | ||
|
||
_initialiseProps.call(this); | ||
|
||
var foo = "foo"; | ||
}; | ||
|
||
var _initialiseProps = function () { | ||
Object.defineProperty(this, "bar", { | ||
enumerable: true, | ||
writable: true, | ||
value: foo | ||
}); | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-transform-class-properties/test/fixtures/spec/derived/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo extends Bar { | ||
bar = "foo"; | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/babel-plugin-transform-class-properties/test/fixtures/spec/derived/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var Foo = function (_Bar) { | ||
babelHelpers.inherits(Foo, _Bar); | ||
|
||
function Foo(...args) { | ||
var _temp, _this, _ret; | ||
|
||
babelHelpers.classCallCheck(this, Foo); | ||
return _ret = (_temp = (_this = babelHelpers.possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).call(this, ...args)), _this), Object.defineProperty(_this, "bar", { | ||
enumerable: true, | ||
writable: true, | ||
value: "foo" | ||
}), _temp), babelHelpers.possibleConstructorReturn(_this, _ret); | ||
} | ||
|
||
return Foo; | ||
}(Bar); |
9 changes: 9 additions & 0 deletions
9
packages/babel-plugin-transform-class-properties/test/fixtures/spec/foobar/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Child extends Parent { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
scopedFunctionWithThis = () => { | ||
this.name = {}; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/babel-plugin-transform-class-properties/test/fixtures/spec/foobar/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use strict"; | ||
|
||
var Child = function (_Parent) { | ||
babelHelpers.inherits(Child, _Parent); | ||
|
||
function Child() { | ||
babelHelpers.classCallCheck(this, Child); | ||
|
||
var _this = babelHelpers.possibleConstructorReturn(this, (Child.__proto__ || Object.getPrototypeOf(Child)).call(this)); | ||
|
||
Object.defineProperty(_this, "scopedFunctionWithThis", { | ||
enumerable: true, | ||
writable: true, | ||
value: function value() { | ||
_this.name = {}; | ||
} | ||
}); | ||
return _this; | ||
} | ||
|
||
return Child; | ||
}(Parent); |
4 changes: 4 additions & 0 deletions
4
packages/babel-plugin-transform-class-properties/test/fixtures/spec/foobar/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["external-helpers", ["transform-class-properties", { "spec": true }]], | ||
"presets": ["stage-0", "es2015"] | ||
} |
3 changes: 3 additions & 0 deletions
3
...s/babel-plugin-transform-class-properties/test/fixtures/spec/instance-undefined/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo { | ||
bar; | ||
} |
3 changes: 3 additions & 0 deletions
3
...babel-plugin-transform-class-properties/test/fixtures/spec/instance-undefined/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var Foo = function Foo() { | ||
babelHelpers.classCallCheck(this, Foo); | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-transform-class-properties/test/fixtures/spec/instance/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo { | ||
bar = "foo"; | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/babel-plugin-transform-class-properties/test/fixtures/spec/instance/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var Foo = function Foo() { | ||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, "bar", { | ||
enumerable: true, | ||
writable: true, | ||
value: "foo" | ||
}); | ||
}; |
11 changes: 11 additions & 0 deletions
11
...babel-plugin-transform-class-properties/test/fixtures/spec/non-block-arrow-func/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default param => | ||
class App { | ||
static props = { | ||
prop1: 'prop1', | ||
prop2: 'prop2' | ||
} | ||
|
||
getParam() { | ||
return param; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...bel-plugin-transform-class-properties/test/fixtures/spec/non-block-arrow-func/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export default (param => { | ||
var _class, _temp; | ||
|
||
return _temp = _class = function () { | ||
function App() { | ||
babelHelpers.classCallCheck(this, App); | ||
} | ||
|
||
babelHelpers.createClass(App, [{ | ||
key: 'getParam', | ||
value: function getParam() { | ||
return param; | ||
} | ||
}]); | ||
return App; | ||
}(), Object.defineProperty(_class, 'props', { | ||
enumerable: true, | ||
writable: true, | ||
value: { | ||
prop1: 'prop1', | ||
prop2: 'prop2' | ||
} | ||
}), _temp; | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-transform-class-properties/test/fixtures/spec/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["external-helpers", ["transform-class-properties", { "spec": true }], "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"] | ||
} |
7 changes: 7 additions & 0 deletions
7
...ges/babel-plugin-transform-class-properties/test/fixtures/spec/regression-T2983/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
call(class { | ||
static test = true | ||
}); | ||
|
||
export default class { | ||
static test = true | ||
}; |
21 changes: 21 additions & 0 deletions
21
...s/babel-plugin-transform-class-properties/test/fixtures/spec/regression-T2983/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var _class, _temp; | ||
|
||
call((_temp = _class = function _class() { | ||
babelHelpers.classCallCheck(this, _class); | ||
}, Object.defineProperty(_class, "test", { | ||
enumerable: true, | ||
writable: true, | ||
value: true | ||
}), _temp)); | ||
|
||
var _class2 = function _class2() { | ||
babelHelpers.classCallCheck(this, _class2); | ||
}; | ||
|
||
Object.defineProperty(_class2, "test", { | ||
enumerable: true, | ||
writable: true, | ||
value: true | ||
}); | ||
export default _class2; | ||
; |
14 changes: 14 additions & 0 deletions
14
...ges/babel-plugin-transform-class-properties/test/fixtures/spec/regression-T6719/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function withContext(ComposedComponent) { | ||
return class WithContext extends Component { | ||
|
||
static propTypes = { | ||
context: PropTypes.shape( | ||
{ | ||
addCss: PropTypes.func, | ||
setTitle: PropTypes.func, | ||
setMeta: PropTypes.func, | ||
} | ||
), | ||
}; | ||
}; | ||
} |
24 changes: 24 additions & 0 deletions
24
...s/babel-plugin-transform-class-properties/test/fixtures/spec/regression-T6719/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function withContext(ComposedComponent) { | ||
var _class, _temp; | ||
|
||
return _temp = _class = function (_Component) { | ||
babelHelpers.inherits(WithContext, _Component); | ||
|
||
function WithContext() { | ||
babelHelpers.classCallCheck(this, WithContext); | ||
return babelHelpers.possibleConstructorReturn(this, (WithContext.__proto__ || Object.getPrototypeOf(WithContext)).apply(this, arguments)); | ||
} | ||
|
||
return WithContext; | ||
}(Component), Object.defineProperty(_class, "propTypes", { | ||
enumerable: true, | ||
writable: true, | ||
value: { | ||
context: PropTypes.shape({ | ||
addCss: PropTypes.func, | ||
setTitle: PropTypes.func, | ||
setMeta: PropTypes.func | ||
}) | ||
} | ||
}), _temp; | ||
} |
17 changes: 17 additions & 0 deletions
17
...ges/babel-plugin-transform-class-properties/test/fixtures/spec/regression-T7364/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class MyClass { | ||
myAsyncMethod = async () => { | ||
console.log(this); | ||
} | ||
} | ||
|
||
(class MyClass2 { | ||
myAsyncMethod = async () => { | ||
console.log(this); | ||
} | ||
}) | ||
|
||
export default class MyClass3 { | ||
myAsyncMethod = async () => { | ||
console.log(this); | ||
} | ||
} |
Oops, something went wrong.