Created
October 25, 2016 22:07
-
-
Save hzoo/6f393d0a24be191e25dee0bb894bb09e to your computer and use it in GitHub Desktop.
external-helpers diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /Users/hzhu/dev/babylon/lib/index.js | |
+++ (clipboard) | |
@@ -124,7 +124,229 @@ | |
return options; | |
} | |
-function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
+var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | |
+ return typeof obj; | |
+} : function (obj) { | |
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | |
+}; | |
+ | |
+ | |
+ | |
+ | |
+ | |
+var asyncGenerator = function () { | |
+ function AwaitValue(value) { | |
+ this.value = value; | |
+ } | |
+ | |
+ function AsyncGenerator(gen) { | |
+ var front, back; | |
+ | |
+ function send(key, arg) { | |
+ return new Promise(function (resolve, reject) { | |
+ var request = { | |
+ key: key, | |
+ arg: arg, | |
+ resolve: resolve, | |
+ reject: reject, | |
+ next: null | |
+ }; | |
+ | |
+ if (back) { | |
+ back = back.next = request; | |
+ } else { | |
+ front = back = request; | |
+ resume(key, arg); | |
+ } | |
+ }); | |
+ } | |
+ | |
+ function resume(key, arg) { | |
+ try { | |
+ var result = gen[key](arg); | |
+ var value = result.value; | |
+ | |
+ if (value instanceof AwaitValue) { | |
+ Promise.resolve(value.value).then(function (arg) { | |
+ resume("next", arg); | |
+ }, function (arg) { | |
+ resume("throw", arg); | |
+ }); | |
+ } else { | |
+ settle(result.done ? "return" : "normal", result.value); | |
+ } | |
+ } catch (err) { | |
+ settle("throw", err); | |
+ } | |
+ } | |
+ | |
+ function settle(type, value) { | |
+ switch (type) { | |
+ case "return": | |
+ front.resolve({ | |
+ value: value, | |
+ done: true | |
+ }); | |
+ break; | |
+ | |
+ case "throw": | |
+ front.reject(value); | |
+ break; | |
+ | |
+ default: | |
+ front.resolve({ | |
+ value: value, | |
+ done: false | |
+ }); | |
+ break; | |
+ } | |
+ | |
+ front = front.next; | |
+ | |
+ if (front) { | |
+ resume(front.key, front.arg); | |
+ } else { | |
+ back = null; | |
+ } | |
+ } | |
+ | |
+ this._invoke = send; | |
+ | |
+ if (typeof gen.return !== "function") { | |
+ this.return = undefined; | |
+ } | |
+ } | |
+ | |
+ if (typeof Symbol === "function" && Symbol.asyncIterator) { | |
+ AsyncGenerator.prototype[Symbol.asyncIterator] = function () { | |
+ return this; | |
+ }; | |
+ } | |
+ | |
+ AsyncGenerator.prototype.next = function (arg) { | |
+ return this._invoke("next", arg); | |
+ }; | |
+ | |
+ AsyncGenerator.prototype.throw = function (arg) { | |
+ return this._invoke("throw", arg); | |
+ }; | |
+ | |
+ AsyncGenerator.prototype.return = function (arg) { | |
+ return this._invoke("return", arg); | |
+ }; | |
+ | |
+ return { | |
+ wrap: function (fn) { | |
+ return function () { | |
+ return new AsyncGenerator(fn.apply(this, arguments)); | |
+ }; | |
+ }, | |
+ await: function (value) { | |
+ return new AwaitValue(value); | |
+ } | |
+ }; | |
+}(); | |
+ | |
+ | |
+ | |
+ | |
+ | |
+var classCallCheck = function (instance, Constructor) { | |
+ if (!(instance instanceof Constructor)) { | |
+ throw new TypeError("Cannot call a class as a function"); | |
+ } | |
+}; | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+var get = function get(object, property, receiver) { | |
+ if (object === null) object = Function.prototype; | |
+ var desc = Object.getOwnPropertyDescriptor(object, property); | |
+ | |
+ if (desc === undefined) { | |
+ var parent = Object.getPrototypeOf(object); | |
+ | |
+ if (parent === null) { | |
+ return undefined; | |
+ } else { | |
+ return get(parent, property, receiver); | |
+ } | |
+ } else if ("value" in desc) { | |
+ return desc.value; | |
+ } else { | |
+ var getter = desc.get; | |
+ | |
+ if (getter === undefined) { | |
+ return undefined; | |
+ } | |
+ | |
+ return getter.call(receiver); | |
+ } | |
+}; | |
+ | |
+var inherits = function (subClass, superClass) { | |
+ if (typeof superClass !== "function" && superClass !== null) { | |
+ throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | |
+ } | |
+ | |
+ subClass.prototype = Object.create(superClass && superClass.prototype, { | |
+ constructor: { | |
+ value: subClass, | |
+ enumerable: false, | |
+ writable: true, | |
+ configurable: true | |
+ } | |
+ }); | |
+ if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | |
+}; | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+ | |
+var possibleConstructorReturn = function (self, call) { | |
+ if (!self) { | |
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | |
+ } | |
+ | |
+ return call && (typeof call === "object" || typeof call === "function") ? call : self; | |
+}; | |
+ | |
+ | |
+ | |
+var set = function set(object, property, value, receiver) { | |
+ var desc = Object.getOwnPropertyDescriptor(object, property); | |
+ | |
+ if (desc === undefined) { | |
+ var parent = Object.getPrototypeOf(object); | |
+ | |
+ if (parent !== null) { | |
+ set(parent, property, value, receiver); | |
+ } | |
+ } else if ("value" in desc && desc.writable) { | |
+ desc.value = value; | |
+ } else { | |
+ var setter = desc.set; | |
+ | |
+ if (setter !== undefined) { | |
+ setter.call(receiver, value); | |
+ } | |
+ } | |
+ | |
+ return value; | |
+}; | |
// ## Token types | |
@@ -146,8 +368,7 @@ | |
var TokenType = function TokenType(label) { | |
var conf = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | |
- | |
- _classCallCheck$2(this, TokenType); | |
+ classCallCheck(this, TokenType); | |
this.label = label; | |
this.keyword = conf.keyword; | |
@@ -292,14 +513,12 @@ | |
var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/; | |
-function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
- | |
// The algorithm used to determine whether a regexp can appear at a | |
// given point in the program is loosely based on sweet.js' approach. | |
// See https://github.com/mozilla/sweet.js/wiki/design | |
var TokContext = function TokContext(token, isExpr, preserveSpace, override) { | |
- _classCallCheck$3(this, TokContext); | |
+ classCallCheck(this, TokContext); | |
this.token = token; | |
this.isExpr = !!isExpr; | |
@@ -385,20 +604,18 @@ | |
this.state.exprAllowed = false; | |
}; | |
-function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
- | |
// These are used when `options.locations` is on, for the | |
// `startLoc` and `endLoc` properties. | |
var Position = function Position(line, col) { | |
- _classCallCheck$4(this, Position); | |
+ classCallCheck(this, Position); | |
this.line = line; | |
this.column = col; | |
}; | |
var SourceLocation = function SourceLocation(start, end) { | |
- _classCallCheck$4(this, SourceLocation); | |
+ classCallCheck(this, SourceLocation); | |
this.start = start; | |
this.end = end; | |
@@ -423,11 +640,9 @@ | |
} | |
} | |
-function _classCallCheck$5(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
- | |
var State = function () { | |
function State() { | |
- _classCallCheck$5(this, State); | |
+ classCallCheck(this, State); | |
} | |
State.prototype.init = function init(options, input) { | |
@@ -558,8 +773,6 @@ | |
return State; | |
}(); | |
-function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
- | |
/* eslint indent: 0 */ | |
// Object type used to represent tokens. Note that normally, tokens | |
@@ -567,7 +780,7 @@ | |
// used for the onToken callback and the external tokenizer. | |
var Token = function Token(state) { | |
- _classCallCheck$1(this, Token); | |
+ classCallCheck(this, Token); | |
this.type = state.type; | |
this.value = state.value; | |
@@ -589,7 +802,7 @@ | |
var Tokenizer = function () { | |
function Tokenizer(options, input) { | |
- _classCallCheck$1(this, Tokenizer); | |
+ classCallCheck(this, Tokenizer); | |
this.state = new State(); | |
this.state.init(options, input); | |
@@ -1426,23 +1639,17 @@ | |
return Tokenizer; | |
}(); | |
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
- | |
-function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | |
- | |
-function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | |
- | |
var plugins = {}; | |
var Parser = function (_Tokenizer) { | |
- _inherits(Parser, _Tokenizer); | |
+ inherits(Parser, _Tokenizer); | |
function Parser(options, input) { | |
- _classCallCheck(this, Parser); | |
+ classCallCheck(this, Parser); | |
options = getOptions(options); | |
- var _this = _possibleConstructorReturn(this, _Tokenizer.call(this, options, input)); | |
+ var _this = possibleConstructorReturn(this, _Tokenizer.call(this, options, input)); | |
_this.options = options; | |
_this.inModule = _this.options.sourceType === "module"; | |
@@ -1511,8 +1718,6 @@ | |
return Parser; | |
}(Tokenizer); | |
- | |
-var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | |
var pp = Parser.prototype; | |
@@ -4140,8 +4345,6 @@ | |
return this.finishNode(node, "YieldExpression"); | |
}; | |
-function _classCallCheck$6(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
- | |
// Start an AST node, attaching a start offset. | |
var pp$4 = Parser.prototype; | |
@@ -4149,7 +4352,7 @@ | |
var Node = function () { | |
function Node(pos, loc, filename) { | |
- _classCallCheck$6(this, Node); | |
+ classCallCheck(this, Node); | |
this.type = ""; | |
this.start = pos; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment