Add Path#isInStrictMode (#7712)

* Add Path#isInStrictMode

* Fix undefined directives

* Explicitly return for arrow expressions
This commit is contained in:
Justin Ridgewell
2018-04-11 09:13:38 -04:00
committed by GitHub
parent 6597a472b3
commit 7ae724f553
3 changed files with 136 additions and 20 deletions

View File

@@ -688,26 +688,9 @@ export default function transformClass(
classState.staticPropBody.map(fn => fn(t.cloneNode(classState.classRef))),
);
const strictParent = path.findParent(path => {
if (path.isProgram() && path.node.sourceType === "module") {
return true;
}
if (path.isClassBody()) {
return true;
}
if (!path.isProgram() && !path.isBlockStatement()) {
return false;
}
return path.node.directives.some(
directive => directive.value.value === "use strict",
);
});
const isStrict = path.isInStrictMode();
let constructorOnly = classState.classId && body.length === 1;
if (constructorOnly && !strictParent) {
if (constructorOnly && !isStrict) {
for (const param of classState.construct.params) {
// It's illegal to put a use strict directive into the body of a function
// with non-simple parameters for some reason. So, we have to use a strict
@@ -720,7 +703,7 @@ export default function transformClass(
}
const directives = constructorOnly ? body[0].body.directives : [];
if (!strictParent) {
if (!isStrict) {
directives.push(t.directive(t.directiveLiteral("use strict")));
}