Commit modules

This commit is contained in:
Federico Grandi
2019-12-14 23:17:51 +01:00
parent 8063b07a5a
commit a88246a48b
4243 changed files with 1074761 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
"use strict";
module.exports = removeUseStrict;
const newIssueUrl = "https://github.com/babel/minify/issues/new";
const useStrict = "use strict";
/**
* Remove redundant use strict
* If the parent has a "use strict" directive, it is not required in
* the children
*
* @param {NodePath} block BlockStatement
*/
function removeUseStrict(block) {
if (!block.isBlockStatement()) {
throw new Error(`Received ${block.type}. Expected BlockStatement. ` + `Please report at ${newIssueUrl}`);
}
const useStricts = getUseStrictDirectives(block); // early exit
if (useStricts.length < 1) return; // only keep the first use strict
if (useStricts.length > 1) {
for (let i = 1; i < useStricts.length; i++) {
useStricts[i].remove();
}
} // check if parent has an use strict
if (hasStrictParent(block)) {
useStricts[0].remove();
}
}
function hasStrictParent(path) {
return path.findParent(parent => parent.isBlockStatement() && isStrict(parent));
}
function isStrict(block) {
return getUseStrictDirectives(block).length > 0;
}
function getUseStrictDirectives(block) {
var dir = block.get("directives");
return Array.isArray(dir) ? dir.filter(function (directive) {
return directive.node.value.value === useStrict;
}) : [];
}