From 5a935f156bba585b1e10e3bda7e05ec340e632df Mon Sep 17 00:00:00 2001 From: Dan Wolff Date: Mon, 5 Feb 2018 22:13:28 +0100 Subject: [PATCH] add information on testing and code style fixes #2884 --- CONTRIBUTING.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..760e26a4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,54 @@ +Contributing +============ + +## Testing + +All features and bugs should have tests that verify the fix. You can run all +tests using `npm test`. + +The most common type of test are tests that verify input and output of the +Uglify transforms. These tests exist in `test/compress`. New tests can be added +either to an existing file or in a new file `issue-xxx.js`. + +Tests that cannot be expressed as a simple AST can be found in `test/mocha`. + +## Code style + +- `LF` is always used as a line ending. +- Statements end with semicolons. +- Indentation uses 4 spaces, switch `case` 2 spaces. +- Identifiers use `snake_case`. +- Strings use double quotes (`"`). +- The Uglify code only uses ES5, even in the `harmony` branch. +- Line length should be at most 80 cols, except when it is easier to read a + longer line. +- If both sides of a comparison are of the same type, `==` and `!=` are used. +- Multiline conditions place `&&` and `||` first on the line. + +Example: + +```js +if (compressor.option("comparisons")) switch (self.operator) { + case "==": + case "!=": + // void 0 == x => null == x + if (!is_strict_comparison && is_undefined(self.left, compressor)) { + self.left = make_node(AST_Null, self.left); + } + // "undefined" == typeof x => undefined === x + else if (compressor.option("typeofs") + && self.left instanceof AST_String + && self.left.value == "undefined" + && self.right instanceof AST_UnaryPrefix + && self.right.operator == "typeof") { + var expr = self.right.expression; + if (expr instanceof AST_SymbolRef ? expr.is_declared(compressor) + : !(expr instanceof AST_PropAccess && compressor.option("ie8"))) { + self.right = expr; + self.left = make_node(AST_Undefined, self.left).optimize(compressor); + if (self.operator.length == 2) self.operator += "="; + } + } + ... +} +```