[Pkg-javascript-commits] [node-acorn-object-spread] 03/05: New upstream version 1.0.0

Julien Puydt julien.puydt at laposte.net
Mon Sep 18 20:06:33 UTC 2017


This is an automated email from the git hooks/post-receive script.

jpuydt-guest pushed a commit to branch master
in repository node-acorn-object-spread.

commit 40b75118f011d567a769aeba4299d95f9e622145
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Mon Sep 18 21:44:36 2017 +0200

    New upstream version 1.0.0
---
 .editorconfig               |   7 +
 .gitattributes              |   1 +
 .gitignore                  |   1 +
 .npmignore                  |   2 +
 .travis.yml                 |   2 +
 README.md                   |  33 +++
 test/driver.js              | 108 ++++++++++
 test/run.js                 |  70 ++++++
 test/tests-object-spread.js | 513 ++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 737 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..c14d5c6
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,7 @@
+root = true
+
+[*]
+indent_style = space
+indent_size = 2
+end_of_line = lf
+insert_final_newline = true
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..fcadb2c
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text eol=lf
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..07e6e47
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/node_modules
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..2c630f1
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,2 @@
+test
+.*
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..ffb9f71
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,2 @@
+language: node_js
+node_js: '0.10'
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..2044a39
--- /dev/null
+++ b/README.md
@@ -0,0 +1,33 @@
+# ObjectSpread support in acorn
+
+[![Build Status](https://travis-ci.org/UXtemple/acorn-object-spread.svg?branch=master)](https://travis-ci.org/UXtemple/acorn-object-spread)
+[![NPM version](https://img.shields.io/npm/v/acorn-object-spread.svg)](https://www.npmjs.org/package/acorn-object-spread)
+
+This is plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript.
+
+## Usage
+
+You can use this module directly in order to get Acorn instance with plugin installed:
+
+```javascript
+var acorn = require('acorn-object-spread');
+```
+
+Or you can use `inject.js` for injecting plugin into your own version of Acorn like this:
+
+```javascript
+var acorn = require('acorn-object-spread/inject')(require('./custom-acorn'));
+```
+
+Then, use the `plugins` option whenever you need to support objectSpread while parsing:
+
+```javascript
+var ast = acorn.parse(code, {
+  plugins: { objectSpread: true }
+});
+```
+## License
+
+This plugin is issued under the [MIT license](./LICENSE).
+
+With <3 by UXtemple.
diff --git a/test/driver.js b/test/driver.js
new file mode 100644
index 0000000..921d739
--- /dev/null
+++ b/test/driver.js
@@ -0,0 +1,108 @@
+var tests = [];
+
+exports.test = function(code, ast, options) {
+  tests.push({code: code, ast: ast, options: options});
+};
+exports.testFail = function(code, message, options) {
+  tests.push({code: code, error: message, options: options});
+};
+exports.testAssert = function(code, assert, options) {
+  tests.push({code: code, assert: assert, options: options});
+};
+
+exports.runTests = function(config, callback) {
+  var parse = config.parse;
+
+  for (var i = 0; i < tests.length; ++i) {
+    var test = tests[i];
+    if (config.filter && !config.filter(test)) continue;
+    try {
+      var testOpts = test.options || {locations: true};
+      var expected = {};
+      if (expected.onComment = testOpts.onComment) {
+        testOpts.onComment = []
+      }
+      if (expected.onToken = testOpts.onToken) {
+        testOpts.onToken = [];
+      }
+      testOpts.plugins = testOpts.plugins || { objectSpread: true };
+      var ast = parse(test.code, testOpts);
+
+      if (test.error) {
+        if (config.loose) {
+          callback("ok", test.code);
+        } else {
+          callback("fail", test.code, "Expected error message: " + test.error + "\nBut parsing succeeded.");
+        }
+      }
+      else if (test.assert) {
+        var error = test.assert(ast);
+        if (error) callback("fail", test.code,
+                               "\n  Assertion failed:\n " + error);
+        else callback("ok", test.code);
+      } else {
+        var mis = misMatch(test.ast, ast);
+        for (var name in expected) {
+          if (mis) break;
+          if (expected[name]) {
+            mis = misMatch(expected[name], testOpts[name]);
+            testOpts[name] = expected[name];
+          }
+        }
+        if (mis) callback("fail", test.code, mis);
+        else callback("ok", test.code);
+      }
+    } catch(e) {
+      if (!(e instanceof SyntaxError)) {
+        throw e;
+      }
+      if (test.error) {
+        if (e.message == test.error) callback("ok", test.code);
+        else callback("fail", test.code,
+                      "Expected error message: " + test.error + "\nGot error message: " + e.message);
+      } else {
+        callback("error", test.code, e.stack || e.toString());
+      }
+    }
+  }
+};
+
+function ppJSON(v) { return v instanceof RegExp ? v.toString() : JSON.stringify(v, null, 2); }
+function addPath(str, pt) {
+  if (str.charAt(str.length-1) == ")")
+    return str.slice(0, str.length-1) + "/" + pt + ")";
+  return str + " (" + pt + ")";
+}
+
+var misMatch = exports.misMatch = function(exp, act) {
+  if (!exp || !act || (typeof exp != "object") || (typeof act != "object")) {
+    if (exp !== act) return ppJSON(exp) + " !== " + ppJSON(act);
+  } else if (exp instanceof RegExp || act instanceof RegExp) {
+    var left = ppJSON(exp), right = ppJSON(act);
+    if (left !== right) return left + " !== " + right;
+  } else if (exp.splice) {
+    if (!act.slice) return ppJSON(exp) + " != " + ppJSON(act);
+    if (act.length != exp.length) return "array length mismatch " + exp.length + " != " + act.length;
+    for (var i = 0; i < act.length; ++i) {
+      var mis = misMatch(exp[i], act[i]);
+      if (mis) return addPath(mis, i);
+    }
+  } else {
+    for (var prop in exp) {
+      var mis = misMatch(exp[prop], act[prop]);
+      if (mis) return addPath(mis, prop);
+    }
+  }
+};
+
+function mangle(ast) {
+  if (typeof ast != "object" || !ast) return;
+  if (ast.slice) {
+    for (var i = 0; i < ast.length; ++i) mangle(ast[i]);
+  } else {
+    var loc = ast.start && ast.end && {start: ast.start, end: ast.end};
+    if (loc) { delete ast.start; delete ast.end; }
+    for (var name in ast) if (ast.hasOwnProperty(name)) mangle(ast[name]);
+    if (loc) ast.loc = loc;
+  }
+}
diff --git a/test/run.js b/test/run.js
new file mode 100644
index 0000000..cf1151f
--- /dev/null
+++ b/test/run.js
@@ -0,0 +1,70 @@
+var driver = require("./driver.js");
+require("./tests-object-spread.js");
+
+function group(name) {
+  if (typeof console === "object" && console.group) {
+    console.group(name);
+  }
+}
+
+function groupEnd() {
+  if (typeof console === "object" && console.groupEnd) {
+    console.groupEnd(name);
+  }
+}
+
+function log(title, message) {
+  if (typeof console === "object") console.log(title, message);
+}
+
+var stats, modes = {
+  Normal: {
+    config: {
+      parse: require("..").parse
+    }
+  }
+};
+
+function report(state, code, message) {
+  if (state != "ok") {++stats.failed; log(code, message);}
+  ++stats.testsRun;
+}
+
+group("Errors");
+
+for (var name in modes) {
+  group(name);
+  var mode = modes[name];
+  stats = mode.stats = {testsRun: 0, failed: 0};
+  var t0 = +new Date;
+  driver.runTests(mode.config, report);
+  mode.stats.duration = +new Date - t0;
+  groupEnd();
+}
+
+groupEnd();
+
+function outputStats(name, stats) {
+  log(name + ":", stats.testsRun + " tests run in " + stats.duration + "ms; " +
+    (stats.failed ? stats.failed + " failures." : "all passed."));
+}
+
+var total = {testsRun: 0, failed: 0, duration: 0};
+
+group("Stats");
+
+for (var name in modes) {
+  var stats = modes[name].stats;
+  outputStats(name + " parser", stats);
+  for (var key in stats) total[key] += stats[key];
+}
+
+outputStats("Total", total);
+
+groupEnd();
+
+if (total.failed && typeof process === "object") {
+  process.stdout.write("", function() {
+    process.exit(1);
+  });
+}
diff --git a/test/tests-object-spread.js b/test/tests-object-spread.js
new file mode 100644
index 0000000..541cf13
--- /dev/null
+++ b/test/tests-object-spread.js
@@ -0,0 +1,513 @@
+// ObjectSpread tests
+
+var fbTestFixture = {
+  // Taken and adapted from babylon's tests.
+  'ObjectSpread': {
+    'let z = {...x}': {
+      "type": "VariableDeclaration",
+      "start": 0,
+      "end": 14,
+      "loc": {
+        "start": {
+          "line": 1,
+          "column": 0
+        },
+        "end": {
+          "line": 1,
+          "column": 14
+        }
+      },
+      "declarations": [
+        {
+          "type": "VariableDeclarator",
+          "start": 4,
+          "end": 14,
+          "loc": {
+            "start": {
+              "line": 1,
+              "column": 4
+            },
+            "end": {
+              "line": 1,
+              "column": 14
+            }
+          },
+          "id": {
+            "type": "Identifier",
+            "start": 4,
+            "end": 5,
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 4
+              },
+              "end": {
+                "line": 1,
+                "column": 5
+              }
+            },
+            "name": "z"
+          },
+          "init": {
+            "type": "ObjectExpression",
+            "start": 8,
+            "end": 14,
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 8
+              },
+              "end": {
+                "line": 1,
+                "column": 14
+              }
+            },
+            "properties": [
+              {
+                "type": "SpreadProperty",
+                "start": 9,
+                "end": 13,
+                "loc": {
+                  "start": {
+                    "line": 1,
+                    "column": 9
+                  },
+                  "end": {
+                    "line": 1,
+                    "column": 13
+                  }
+                },
+                "argument": {
+                  "type": "Identifier",
+                  "start": 12,
+                  "end": 13,
+                  "loc": {
+                    "start": {
+                      "line": 1,
+                      "column": 12
+                    },
+                    "end": {
+                      "line": 1,
+                      "column": 13
+                    }
+                  },
+                  "name": "x"
+                }
+              }
+            ]
+          }
+        }
+      ],
+      "kind": "let"
+    },
+    'z = {x, ...y}': {
+      "type": "ExpressionStatement",
+      "start": 0,
+      "end": 13,
+      "loc": {
+        "start": {
+          "line": 1,
+          "column": 0
+        },
+        "end": {
+          "line": 1,
+          "column": 13
+        }
+      },
+      "expression": {
+        "type": "AssignmentExpression",
+        "start": 0,
+        "end": 13,
+        "loc": {
+          "start": {
+            "line": 1,
+            "column": 0
+          },
+          "end": {
+            "line": 1,
+            "column": 13
+          }
+        },
+        "operator": "=",
+        "left": {
+          "type": "Identifier",
+          "start": 0,
+          "end": 1,
+          "loc": {
+            "start": {
+              "line": 1,
+              "column": 0
+            },
+            "end": {
+              "line": 1,
+              "column": 1
+            }
+          },
+          "name": "z"
+        },
+        "right": {
+          "type": "ObjectExpression",
+          "start": 4,
+          "end": 13,
+          "loc": {
+            "start": {
+              "line": 1,
+              "column": 4
+            },
+            "end": {
+              "line": 1,
+              "column": 13
+            }
+          },
+          "properties": [
+            {
+              "type": "Property",
+              "start": 5,
+              "end": 6,
+              "loc": {
+                "start": {
+                  "line": 1,
+                  "column": 5
+                },
+                "end": {
+                  "line": 1,
+                  "column": 6
+                }
+              },
+              "method": false,
+              "shorthand": true,
+              "computed": false,
+              "key": {
+                "type": "Identifier",
+                "start": 5,
+                "end": 6,
+                "loc": {
+                  "start": {
+                    "line": 1,
+                    "column": 5
+                  },
+                  "end": {
+                    "line": 1,
+                    "column": 6
+                  }
+                },
+                "name": "x"
+              },
+              "value": {
+                "type": "Identifier",
+                "start": 5,
+                "end": 6,
+                "loc": {
+                  "start": {
+                    "line": 1,
+                    "column": 5
+                  },
+                  "end": {
+                    "line": 1,
+                    "column": 6
+                  }
+                },
+                "name": "x"
+              }
+            },
+            {
+              "type": "SpreadProperty",
+              "start": 8,
+              "end": 12,
+              "loc": {
+                "start": {
+                  "line": 1,
+                  "column": 8
+                },
+                "end": {
+                  "line": 1,
+                  "column": 12
+                }
+              },
+              "argument": {
+                "type": "Identifier",
+                "start": 11,
+                "end": 12,
+                "loc": {
+                  "start": {
+                    "line": 1,
+                    "column": 11
+                  },
+                  "end": {
+                    "line": 1,
+                    "column": 12
+                  }
+                },
+                "name": "y"
+              }
+            }
+          ]
+        }
+      }
+    },
+    '({x, ...y, a, ...b, c})': {
+      "type": "ExpressionStatement",
+      "start": 0,
+      "end": 23,
+      "loc": {
+        "start": {
+          "line": 1,
+          "column": 0
+        },
+        "end": {
+          "line": 1,
+          "column": 23
+        }
+      },
+      "expression": {
+        "type": "ObjectExpression",
+        "start": 1,
+        "end": 22,
+        "loc": {
+          "start": {
+            "line": 1,
+            "column": 1
+          },
+          "end": {
+            "line": 1,
+            "column": 22
+          }
+        },
+        "properties": [
+          {
+            "type": "Property",
+            "start": 2,
+            "end": 3,
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 2
+              },
+              "end": {
+                "line": 1,
+                "column": 3
+              }
+            },
+            "method": false,
+            "shorthand": true,
+            "computed": false,
+            "key": {
+              "type": "Identifier",
+              "start": 2,
+              "end": 3,
+              "loc": {
+                "start": {
+                  "line": 1,
+                  "column": 2
+                },
+                "end": {
+                  "line": 1,
+                  "column": 3
+                }
+              },
+              "name": "x"
+            },
+            "value": {
+              "type": "Identifier",
+              "start": 2,
+              "end": 3,
+              "loc": {
+                "start": {
+                  "line": 1,
+                  "column": 2
+                },
+                "end": {
+                  "line": 1,
+                  "column": 3
+                }
+              },
+              "name": "x"
+            }
+          },
+          {
+            "type": "SpreadProperty",
+            "start": 5,
+            "end": 9,
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 5
+              },
+              "end": {
+                "line": 1,
+                "column": 9
+              }
+            },
+            "argument": {
+              "type": "Identifier",
+              "start": 8,
+              "end": 9,
+              "loc": {
+                "start": {
+                  "line": 1,
+                  "column": 8
+                },
+                "end": {
+                  "line": 1,
+                  "column": 9
+                }
+              },
+              "name": "y"
+            }
+          },
+          {
+            "type": "Property",
+            "start": 11,
+            "end": 12,
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 11
+              },
+              "end": {
+                "line": 1,
+                "column": 12
+              }
+            },
+            "method": false,
+            "shorthand": true,
+            "computed": false,
+            "key": {
+              "type": "Identifier",
+              "start": 11,
+              "end": 12,
+              "loc": {
+                "start": {
+                  "line": 1,
+                  "column": 11
+                },
+                "end": {
+                  "line": 1,
+                  "column": 12
+                }
+              },
+              "name": "a"
+            },
+            "value": {
+              "type": "Identifier",
+              "start": 11,
+              "end": 12,
+              "loc": {
+                "start": {
+                  "line": 1,
+                  "column": 11
+                },
+                "end": {
+                  "line": 1,
+                  "column": 12
+                }
+              },
+              "name": "a"
+            }
+          },
+          {
+            "type": "SpreadProperty",
+            "start": 14,
+            "end": 18,
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 14
+              },
+              "end": {
+                "line": 1,
+                "column": 18
+              }
+            },
+            "argument": {
+              "type": "Identifier",
+              "start": 17,
+              "end": 18,
+              "loc": {
+                "start": {
+                  "line": 1,
+                  "column": 17
+                },
+                "end": {
+                  "line": 1,
+                  "column": 18
+                }
+              },
+              "name": "b"
+            }
+          },
+          {
+            "type": "Property",
+            "start": 20,
+            "end": 21,
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 20
+              },
+              "end": {
+                "line": 1,
+                "column": 21
+              }
+            },
+            "method": false,
+            "shorthand": true,
+            "computed": false,
+            "key": {
+              "type": "Identifier",
+              "start": 20,
+              "end": 21,
+              "loc": {
+                "start": {
+                  "line": 1,
+                  "column": 20
+                },
+                "end": {
+                  "line": 1,
+                  "column": 21
+                }
+              },
+              "name": "c"
+            },
+            "value": {
+              "type": "Identifier",
+              "start": 20,
+              "end": 21,
+              "loc": {
+                "start": {
+                  "line": 1,
+                  "column": 20
+                },
+                "end": {
+                  "line": 1,
+                  "column": 21
+                }
+              },
+              "name": "c"
+            }
+          }
+        ]
+      }
+    }
+  }
+};
+
+if (typeof exports !== "undefined") {
+  var test = require("./driver.js").test;
+  var testFail = require("./driver.js").testFail;
+  var tokTypes = require("../").tokTypes;
+}
+
+for (var ns in fbTestFixture) {
+  ns = fbTestFixture[ns];
+  for (var code in ns) {
+    test(code, {
+      type: 'Program',
+      body: [ns[code]]
+    }, {
+      ecmaVersion: 7,
+      locations: true,
+      ranges: true
+    });
+  }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-object-spread.git



More information about the Pkg-javascript-commits mailing list