Add Path#isInStrictMode (#7712)
* Add Path#isInStrictMode * Fix undefined directives * Explicitly return for arrow expressions
This commit is contained in:
@@ -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")));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user