-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
good first issuehelp wantedoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue
Milestone
Description
ES6 class scopes are automatically strict-mode. In Babel 6 the module transform pretty much just always made modules strict, but now that people are more likely to be using sourceType: "unambiguous", we'll want to make sure the class transform injects use strict if the file isn't a module and doesn't have a use strict directive in a parent scope.
Input Code
class Foo {
method(){
}
}Expected Behavior
var Foo = function () {
"use strict";
function Foo() {
_classCallCheck(this, Foo);
}
_createClass(Foo, [{
key: "method",
value: function method() {}
}]);
return Foo;
}();
Possible Solution
We likely want to walk up the parent paths, and any time a BlockStatement that is a function body is passed, we can check if path.node.directives has a use strict or not. If we get all the way to the top and didn't find one, and the root Program node doesn't have sourceType === "module", we should add a Directive node to the classes wrapper function expression.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issuehelp wantedoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue