add illegal top level this transformer - fixes #562

This commit is contained in:
Sebastian McKenzie
2015-01-22 07:44:36 +11:00
parent b02e28f3fd
commit da6c2b8d6a
21 changed files with 41 additions and 22 deletions

View File

@@ -52,6 +52,7 @@ _.each({
"spec.noForInOfAssignment": require("./transformers/spec/no-for-in-of-assignment"),
"spec.setters": require("./transformers/spec/setters"),
"spec.blockScopedFunctions": require("./transformers/spec/block-scoped-functions"),
"spec.illegalTopLevelThis": require("./transformers/spec/illegal-top-level-this"),
"playground.malletOperator": require("./transformers/playground/mallet-operator"),
"playground.methodBinding": require("./transformers/playground/method-binding"),

View File

@@ -0,0 +1,8 @@
exports.FunctionDeclaration =
exports.FunctionExpression = function (node, parent, scope, context) {
context.skip();
};
exports.ThisExpression = function (node, parent, scope, context, file) {
throw file.errorWithNode(node, "Top level `this` is not allowed", ReferenceError);
};

View File

@@ -1 +1,3 @@
var t = x => this.x + x;
function b() {
var t = x => this.x + x;
}

View File

@@ -1,6 +1,8 @@
"use strict";
var _this = this;
var t = function (x) {
return _this.x + x;
};
function b() {
var _this = this;
var t = function (x) {
return _this.x + x;
};
}

View File

@@ -1,3 +1,3 @@
for (var [ name, before, after ] of this.test.expectation.registers) {
for (var [ name, before, after ] of test.expectation.registers) {
}

View File

@@ -16,7 +16,7 @@ var _slicedToArray = function (arr, i) {
}
};
for (var _iterator = this.test.expectation.registers[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
for (var _iterator = test.expectation.registers[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var _step$value = _slicedToArray(_step.value, 3);
var name = _step$value[0];

View File

@@ -1 +1 @@
[this.foo, this.bar] = [1, 2];
[foo.foo, foo.bar] = [1, 2];

View File

@@ -20,5 +20,5 @@ var _ref = [1, 2];
var _ref2 = _slicedToArray(_ref, 2);
this.foo = _ref2[0];
this.bar = _ref2[1];
foo.foo = _ref2[0];
foo.bar = _ref2[1];

View File

@@ -1,3 +1,3 @@
var obj = {
["x" + this.foo]: "heh"
["x" + foo.bar]: "heh"
};

View File

@@ -1,9 +1,8 @@
"use strict";
var _this = this;
var obj = (function () {
var _obj = {};
_obj["x" + _this.foo] = "heh";
_obj["x" + foo.foo] = "heh";
return _obj;
})();
})();

View File

@@ -1,3 +1,3 @@
var obj = {
["x" + this.foo]: "heh"
["x" + foo.bar]: "heh"
};

View File

@@ -9,4 +9,4 @@ var _defineProperty = function (obj, key, value) {
});
};
var obj = _defineProperty({}, "x" + this.foo, "heh");
var obj = _defineProperty({}, "x" + foo.bar, "heh");

View File

@@ -1,3 +1,3 @@
<Component
{...this.props}
{...props}
sound="moo" />

View File

@@ -1,2 +1,2 @@
React.createElement(Component, React.__spread({}, this.props, {
React.createElement(Component, React.__spread({}, props, {
sound: "moo" }));

View File

@@ -3,11 +3,11 @@ var x = <div>
</div>;
var x = <div>
{this.props.children}
{props.children}
</div>;
var x = <Composite>
{this.props.children}
{props.children}
</Composite>;
var x = <Composite>

View File

@@ -7,13 +7,13 @@ var x = React.createElement(
var x = React.createElement(
"div",
null,
this.props.children
props.children
);
var x = React.createElement(
Composite,
null,
this.props.children
props.children
);
var x = React.createElement(

View File

@@ -0,0 +1 @@
var foo = () => this;

View File

@@ -0,0 +1,3 @@
{
"throws": "Top level `this` is not allowed"
}

View File

@@ -0,0 +1 @@
this.foo();

View File

@@ -0,0 +1 @@
var self = this;

View File

@@ -0,0 +1 @@
this;