Skip to content

Commit

Permalink
Babel plugin don't convert directives to double quotes [refactor]
Browse files Browse the repository at this point in the history
No longer required after babel/babel#14094
  • Loading branch information
overlookmotel committed Jan 18, 2022
1 parent 1e797fc commit 3077d09
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions lib/babel/visitor.js
Expand Up @@ -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<Object>|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;
}

/**
Expand Down

0 comments on commit 3077d09

Please sign in to comment.