diff --git a/config/codemod-const.js b/config/codemod-const.js deleted file mode 100644 index 37eee5b769..0000000000 --- a/config/codemod-const.js +++ /dev/null @@ -1,43 +0,0 @@ -/* eslint no-console:0 */ - -/** Find constants (identified by ALL_CAPS_DECLARATIONS), and inline them globally. - * This is safe because Preact *only* uses global constants. - */ -export default (file, api) => { - let j = api.jscodeshift, - code = j(file.source), - constants = {}, - found = 0; - - code - .find(j.VariableDeclaration) - .filter(decl => { - for (let i = decl.value.declarations.length; i--; ) { - let node = decl.value.declarations[i], - name = node.id && node.id.name, - init = node.init; - if (name && init && name.match(/^[A-Z0-9_$]+$/g) && !init.regex) { - if (init.type === 'Literal') { - // console.log(`Inlining constant: ${name}=${init.raw}`); - found++; - constants[name] = init; - // remove declaration - decl.value.declarations.splice(i, 1); - // if it's the last, we'll remove the whole statement - return !decl.value.declarations.length; - } - } - } - return false; - }) - .remove(); - - code - .find(j.Identifier) - .filter( - path => path.value.name && constants.hasOwnProperty(path.value.name) - ) - .replaceWith(path => (found++, constants[path.value.name])); - - return found ? code.toSource({ quote: 'single' }) : null; -}; diff --git a/config/codemod-let-name.js b/config/codemod-let-name.js deleted file mode 100644 index 5f69411ed4..0000000000 --- a/config/codemod-let-name.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Restores var names transformed by babel's let block scoping - */ -export default (file, api) => { - let j = api.jscodeshift; - let code = j(file.source); - - // @TODO unsafe, but without it we gain 20b gzipped: https://www.diffchecker.com/bVrOJWTO - code - .findVariableDeclarators() - .filter(d => /^_i/.test(d.value.id.name)) - .renameTo('i'); - code.findVariableDeclarators('_key').renameTo('key'); - - return code.toSource({ quote: 'single' }); -}; diff --git a/config/codemod-strip-tdz.js b/config/codemod-strip-tdz.js deleted file mode 100644 index 469c9c32a5..0000000000 --- a/config/codemod-strip-tdz.js +++ /dev/null @@ -1,60 +0,0 @@ -/* eslint no-console:0 */ - -// parent node types that we don't want to remove pointless initializations from (because it breaks hoisting) -const BLOCKED = ['ForStatement', 'WhileStatement']; // 'IfStatement', 'SwitchStatement' - -/** Removes var initialization to `void 0`, which Babel adds for TDZ strictness. */ -export default (file, api) => { - let { jscodeshift } = api, - found = 0; - - let code = jscodeshift(file.source) - .find(jscodeshift.VariableDeclaration) - .forEach(handleDeclaration); - - function handleDeclaration(decl) { - let p = decl, - remove = true; - - while ((p = p.parentPath)) { - if (~BLOCKED.indexOf(p.value.type)) { - remove = false; - break; - } - } - - decl.value.declarations.filter(isPointless).forEach(node => { - if (remove === false) { - console.log( - `> Skipping removal of undefined init for "${node.id.name}": within ${p.value.type}` - ); - } else { - removeNodeInitialization(node); - } - }); - } - - function removeNodeInitialization(node) { - node.init = null; - found++; - } - - function isPointless(node) { - let { init } = node; - if (init) { - if ( - init.type === 'UnaryExpression' && - init.operator === 'void' && - init.argument.value == 0 - ) { - return true; - } - if (init.type === 'Identifier' && init.name === 'undefined') { - return true; - } - } - return false; - } - - return found ? code.toSource({ quote: 'single' }) : null; -};