Files
add-and-commit/node_modules/babel-plugin-minify-dead-code-elimination/lib/remove-use-strict.js
Federico Grandi f118062594 Update with working working version (#12)
* Fix workflow

* Trigger

* [auto] Update compiled version

* [auto] Commit modules

* Push Windows changes

* Fix

* [auto] Update compiled version

* Try removing cwd

* [auto] Update compiled version

* Try with path module

* [auto] Update compiled version

* Fix path

* [auto] Update compiled version

* Use raw path

* [auto] Update compiled version

* Other path

* [auto] Update compiled version

* Avoid @action/exec

* [auto] Update compiled version

* test

* [auto] Update compiled version

* test

* [auto] Update compiled version

* test

* [auto] Update compiled version

* test

* [auto] Update compiled version

* Try with shelljs

* [auto] Update compiled version

* Fix my stupidity

* Copy scripts to local dir

* [auto] Update compiled version

* Still use path

* [auto] Update compiled version

* Delete entrypoint.sh

* [auto] Update compiled version

* Make file executable

* [auto] Update compiled version

* Try using bash

* [auto] Update compiled version
2019-12-14 21:47:13 +01:00

48 lines
1.2 KiB
JavaScript

"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;
}) : [];
}