avoid revisiting classes - #2694

This commit is contained in:
Sebastian McKenzie
2015-11-13 16:55:54 -08:00
parent 5cb326a7f6
commit 01356191d4
4 changed files with 50 additions and 1 deletions

View File

@@ -3,6 +3,9 @@ import VanillaTransformer from "./vanilla";
import nameFunction from "babel-helper-function-name";
export default function ({ types: t }) {
// todo: investigate traversal requeueing
let VISITED = Symbol();
return {
visitor: {
ClassDeclaration(path) {
@@ -21,8 +24,13 @@ export default function ({ types: t }) {
},
ClassExpression(path, state) {
let { node } = path;
if (node[VISITED]) return;
let inferred = nameFunction(path);
if (inferred && inferred !== path.node) return path.replaceWith(inferred);
if (inferred && inferred !== node) return path.replaceWith(inferred);
node[VISITED] = true;
let Constructor = VanillaTransformer;
if (state.opts.loose) Constructor = LooseTransformer;

View File

@@ -0,0 +1,8 @@
import BaseFoo from './BaseFoo';
export default class SubFoo extends BaseFoo {
static talk() {
super.talk();
console.log('SubFoo.talk');
}
}

View File

@@ -0,0 +1,29 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _BaseFoo2 = require('./BaseFoo');
var _BaseFoo3 = babelHelpers.interopRequireDefault(_BaseFoo2);
var SubFoo = (function (_BaseFoo) {
babelHelpers.inherits(SubFoo, _BaseFoo);
function SubFoo() {
babelHelpers.classCallCheck(this, SubFoo);
return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(SubFoo).apply(this, arguments));
}
babelHelpers.createClass(SubFoo, null, [{
key: 'talk',
value: function talk() {
babelHelpers.get(Object.getPrototypeOf(SubFoo), 'talk', this).call(this);
console.log('SubFoo.talk');
}
}]);
return SubFoo;
})(_BaseFoo3.default);
exports.default = SubFoo;

View File

@@ -0,0 +1,4 @@
{
"plugins": ["external-helpers-2"],
"presets": ["es2015"]
}