Summary: Non-final identifiers make code harder to understand. This is particularly true for JavaScript where even the *type* can change as a value gets reassigned later. This enforces to use `const` whereever possible, but doesn't "outlaw" `let`. Mixed destructuring is also still allowed. Used `eslint --fix` to change all existing cases. Reviewed By: jknoxville Differential Revision: D16131329 fbshipit-source-id: 2eceaca7c603b71b36e005be5d135e1849f2518d
34 lines
871 B
JavaScript
34 lines
871 B
JavaScript
/**
|
|
* Copyright 2018-present Facebook.
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
* @format
|
|
*/
|
|
|
|
const babylon = require('@babel/parser');
|
|
const fs = require('fs');
|
|
|
|
const electronStubs = babylon.parseExpression(
|
|
fs.readFileSync('static/electron-stubs.notjs').toString(),
|
|
);
|
|
|
|
module.exports = function(babel) {
|
|
return {
|
|
name: 'replace-electron-requires-with-stubs',
|
|
visitor: {
|
|
CallExpression(path) {
|
|
if (
|
|
path.node.type === 'CallExpression' &&
|
|
path.node.callee.type === 'Identifier' &&
|
|
path.node.callee.name === 'require' &&
|
|
path.node.arguments.length > 0
|
|
) {
|
|
if (path.node.arguments[0].value === 'electron') {
|
|
path.replaceWith(electronStubs);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
};
|
|
};
|