Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Foo = function (_Bar) {
var Foo =
/*#__PURE__*/
function (_Bar) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not important... but is there a reason why this is on 3 lines instead of 1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its just how babel-generator spits out code from the AST, looks weird to me too, but 🙄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably just because we removed some logic with newlines using tokens/comments so it's like that now

babelHelpers.inherits(Foo, _Bar);

function Foo(options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ function _asyncToGenerator(fn) { return function () { var _this = this, _argumen

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Foo = function () {
var Foo =
/*#__PURE__*/
function () {
function Foo() {
_classCallCheck(this, Foo);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Test = function () {
var Test =
/*#__PURE__*/
function () {
function Test() {
babelHelpers.classCallCheck(this, Test);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"column": 10
},
"generated": {
"line": 9,
"line": 11,
"column": 15
}
}]
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Foo = function (_Bar) {
var Foo =
/*#__PURE__*/
function (_Bar) {
babelHelpers.inherits(Foo, _Bar);

function Foo(...args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";

var Child = function (_Parent) {
var Child =
/*#__PURE__*/
function (_Parent) {
babelHelpers.inherits(Child, _Parent);

function Child() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export default (param => {
var _class, _temp;

return _temp = _class = function () {
return _temp = _class =
/*#__PURE__*/
function () {
function App() {
babelHelpers.classCallCheck(this, App);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function withContext(ComposedComponent) {
var _class, _temp;

return _temp = _class = function (_Component) {
return _temp = _class =
/*#__PURE__*/
function (_Component) {
babelHelpers.inherits(WithContext, _Component);

function WithContext() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var A = function () {
var A =
/*#__PURE__*/
function () {
function A() {
babelHelpers.classCallCheck(this, A);
}
Expand All @@ -12,7 +14,9 @@ var A = function () {
return A;
}();

var B = function (_A) {
var B =
/*#__PURE__*/
function (_A) {
babelHelpers.inherits(B, _A);

function B(...args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Foo = function (_Bar) {
var Foo =
/*#__PURE__*/
function (_Bar) {
babelHelpers.inherits(Foo, _Bar);

function Foo() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Foo = function (_Bar) {
var Foo =
/*#__PURE__*/
function (_Bar) {
babelHelpers.inherits(Foo, _Bar);

function Foo() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Foo = function (_Bar) {
var Foo =
/*#__PURE__*/
function (_Bar) {
babelHelpers.inherits(Foo, _Bar);

function Foo(...args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";

var Child = function (_Parent) {
var Child =
/*#__PURE__*/
function (_Parent) {
babelHelpers.inherits(Child, _Parent);

function Child() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export default (param => {
var _class, _temp;

return _temp = _class = function () {
return _temp = _class =
/*#__PURE__*/
function () {
function App() {
babelHelpers.classCallCheck(this, App);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Foo = function (_Bar) {
var Foo =
/*#__PURE__*/
function (_Bar) {
babelHelpers.inherits(Foo, _Bar);

function Foo() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Foo = function (_Bar) {
var Foo =
/*#__PURE__*/
function (_Bar) {
babelHelpers.inherits(Foo, _Bar);

function Foo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ var Test = function Test() {

_classCallCheck(this, Test);

var Other = function (_Test) {
var Other =
/*#__PURE__*/
function (_Test) {
_inherits(Other, _Test);

function Other() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function withContext(ComposedComponent) {
var _class, _temp;

return _temp = _class = function (_Component) {
return _temp = _class =
/*#__PURE__*/
function (_Component) {
babelHelpers.inherits(WithContext, _Component);

function WithContext() {
Expand Down
12 changes: 7 additions & 5 deletions packages/babel-plugin-transform-es2015-classes/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import LooseTransformer from "./loose";
import VanillaTransformer from "./vanilla";
import nameFunction from "babel-helper-function-name";

const PURE_ANNOTATION = "#__PURE__";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use this across multiple plugins? We might want to add it in a helper.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xtuc sure thing, whats the best place to add such?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too late but I had something like babel-help-emit-pure-annotation in mind but I'm not sure it will be used apart from here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just make it when we need/get to it. It's not a breaking change to swap it out either


export default function({ types: t }) {
// todo: investigate traversal requeueing
const VISITED = Symbol();
Expand Down Expand Up @@ -51,11 +53,11 @@ export default function({ types: t }) {

path.replaceWith(new Constructor(path, state.file).run());

if (
path.isCallExpression() &&
path.get("callee").isArrowFunctionExpression()
) {
path.get("callee").arrowFunctionToExpression();
if (path.isCallExpression()) {
path.addComment("leading", PURE_ANNOTATION);
if (path.get("callee").isArrowFunctionExpression()) {
path.get("callee").arrowFunctionToExpression();
}
}
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ let A = function A() {
console.log('a');
};

let B = function () {
let B =
/*#__PURE__*/
function () {
function B() {}

var _proto = B.prototype;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.crea

let B = function B() {};

let A = function (_B) {
let A =
/*#__PURE__*/
function (_B) {
_inheritsLoose(A, _B);

function A(track) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Test = function (_Foo) {
var Test =
/*#__PURE__*/
function (_Foo) {
babelHelpers.inheritsLoose(Test, _Foo);

function Test() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Test = function (_Foo) {
var Test =
/*#__PURE__*/
function (_Foo) {
babelHelpers.inheritsLoose(Test, _Foo);

function Test() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Test = function (_Foo) {
var Test =
/*#__PURE__*/
function (_Foo) {
babelHelpers.inheritsLoose(Test, _Foo);

function Test() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var x = function () {
var x =
/*#__PURE__*/
function () {
var _proto = x.prototype;

_proto.f = function f() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Child = function (_Base) {
var Child =
/*#__PURE__*/
function (_Base) {
babelHelpers.inheritsLoose(Child, _Base);

function Child() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Child = function (_Base) {
var Child =
/*#__PURE__*/
function (_Base) {
babelHelpers.inheritsLoose(Child, _Base);

function Child() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var Foo = function () {
var Foo =
/*#__PURE__*/
function () {
function Foo() {}

var _proto = Foo.prototype;

_proto["bar"] = function bar() {};

return Foo;
}();
}();
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @flow
var C = function () {
var C =
/*#__PURE__*/
function () {
function C() {}

var _proto = C.prototype;
Expand All @@ -9,4 +11,4 @@ var C = function () {
};

return C;
}();
}();
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Test = function () {
var Test =
/*#__PURE__*/
function () {
function Test() {}

var _proto = Test.prototype;
Expand All @@ -10,4 +12,4 @@ var Test = function () {
_proto.c = function c() {};

return Test;
}();
}();
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var BaseController = function (_Chaplin$Controller) {
var BaseController =
/*#__PURE__*/
function (_Chaplin$Controller) {
babelHelpers.inheritsLoose(BaseController, _Chaplin$Controller);

function BaseController() {
Expand All @@ -8,7 +10,9 @@ var BaseController = function (_Chaplin$Controller) {
return BaseController;
}(Chaplin.Controller);

var BaseController2 = function (_Chaplin$Controller$A) {
var BaseController2 =
/*#__PURE__*/
function (_Chaplin$Controller$A) {
babelHelpers.inheritsLoose(BaseController2, _Chaplin$Controller$A);

function BaseController2() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Test = function (_Foo) {
var Test =
/*#__PURE__*/
function (_Foo) {
babelHelpers.inheritsLoose(Test, _Foo);

function Test() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ var _binarySerializer = require("./helpers/binary-serializer");
var _binarySerializer2 = babelHelpers.interopRequireDefault(_binarySerializer);

// import ...
var Connection = function (_EventEmitter) {
var Connection =
/*#__PURE__*/
function (_EventEmitter) {
babelHelpers.inherits(Connection, _EventEmitter);

function Connection(endpoint, joinKey, joinData, roomId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ var _BaseFoo2 = require("./BaseFoo");

var _BaseFoo3 = babelHelpers.interopRequireDefault(_BaseFoo2);

var SubFoo = function (_BaseFoo) {
var SubFoo =
/*#__PURE__*/
function (_BaseFoo) {
babelHelpers.inherits(SubFoo, _BaseFoo);

function SubFoo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ var _react = require("react");

var _react2 = babelHelpers.interopRequireDefault(_react);

var RandomComponent = function (_Component) {
var RandomComponent =
/*#__PURE__*/
function (_Component) {
babelHelpers.inherits(RandomComponent, _Component);

function RandomComponent() {
Expand Down
Loading