diff --git a/lib/babel/visitor.js b/lib/babel/visitor.js index a628e71a..a5842eac 100644 --- a/lib/babel/visitor.js +++ b/lib/babel/visitor.js @@ -822,27 +822,25 @@ function serializeFunctionAst(fnNode, parentIsStrict) { /** * Remove unnecessary 'use strict' directives from function body. - * Also make all directives render with double quotes. * @param {Object} bodyNode - Function body block AST node * @param {boolean} isStrict - `true` if function already in strict mode * @returns {Array|undefined} - Altered directive nodes array, * or `undefined` if no changes need to be made */ function amendDirectives(bodyNode, isStrict) { - const {directives} = bodyNode; - if (directives.length === 0) return undefined; + const {directives} = bodyNode, + numDirectives = directives.length; + if (numDirectives === 0) return undefined; - return directives.filter(({value: valueNode}) => { - if (valueNode.value === 'use strict') { + const amendedDirectives = directives.filter((directiveNode) => { + if (directiveNode.value.value === 'use strict') { if (isStrict) return false; isStrict = true; } - - // Ensure directive renders with double quotes - // TODO Remove this once fixed in Babel https://github.com/babel/babel/pull/14094 - valueNode.extra = undefined; return true; }); + if (amendedDirectives.length === numDirectives) return undefined; + return amendedDirectives; } /**