Created
October 15, 2014 04:55
-
-
Save zpao/e4b0f43a565a48f56baf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
--- build_old/JSXTransformer.js 2014-10-14 21:38:49.000000000 -0700 | |
+++ build/JSXTransformer.js 2014-10-14 21:49:52.000000000 -0700 | |
@@ -1,436 +1,765 @@ | |
/** | |
* JSXTransformer v0.12.0-alpha | |
*/ | |
-!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.JSXTransformer=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | |
-/*! | |
- * The buffer module from node.js, for the browser. | |
+!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.JSXTransformer=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | |
+/** | |
+ * Copyright 2013-2014, Facebook, Inc. | |
+ * All rights reserved. | |
* | |
- * @author Feross Aboukhadijeh <[email protected]> <http://feross.org> | |
- * @license MIT | |
+ * This source code is licensed under the BSD-style license found in the | |
+ * LICENSE file in the root directory of this source tree. An additional grant | |
+ * of patent rights can be found in the PATENTS file in the same directory. | |
*/ | |
+/* jshint browser: true */ | |
+/* jslint evil: true */ | |
-var base64 = _dereq_('base64-js') | |
-var ieee754 = _dereq_('ieee754') | |
-var isArray = _dereq_('is-array') | |
+'use strict'; | |
-exports.Buffer = Buffer | |
-exports.SlowBuffer = Buffer | |
-exports.INSPECT_MAX_BYTES = 50 | |
-Buffer.poolSize = 8192 // not used by this implementation | |
+var buffer = _dereq_('buffer'); | |
+var transform = _dereq_('jstransform').transform; | |
+var visitors = _dereq_('./fbtransform/visitors'); | |
-var kMaxLength = 0x3fffffff | |
+var headEl; | |
+var dummyAnchor; | |
+var inlineScriptCount = 0; | |
+ | |
+// The source-map library relies on Object.defineProperty, but IE8 doesn't | |
+// support it fully even with es5-sham. Indeed, es5-sham's defineProperty | |
+// throws when Object.prototype.__defineGetter__ is missing, so we skip building | |
+// the source map in that case. | |
+var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); | |
/** | |
- * If `Buffer.TYPED_ARRAY_SUPPORT`: | |
- * === true Use Uint8Array implementation (fastest) | |
- * === false Use Object implementation (most compatible, even IE6) | |
- * | |
- * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, | |
- * Opera 11.6+, iOS 4.2+. | |
- * | |
- * Note: | |
- * | |
- * - Implementation must support adding new properties to `Uint8Array` instances. | |
- * Firefox 4-29 lacked support, fixed in Firefox 30+. | |
- * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. | |
- * | |
- * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. | |
- * | |
- * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of | |
- * incorrect length in some situations. | |
+ * Run provided code through jstransform. | |
* | |
- * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will | |
- * get the Object implementation, which is slower but will work correctly. | |
+ * @param {string} source Original source code | |
+ * @param {object?} options Options to pass to jstransform | |
+ * @return {object} object as returned from jstransform | |
*/ | |
-Buffer.TYPED_ARRAY_SUPPORT = (function () { | |
- try { | |
- var buf = new ArrayBuffer(0) | |
- var arr = new Uint8Array(buf) | |
- arr.foo = function () { return 42 } | |
- return 42 === arr.foo() && // typed array instances can be augmented | |
- typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` | |
- new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` | |
- } catch (e) { | |
- return false | |
+function transformReact(source, options) { | |
+ // TODO: just use react-tools | |
+ options = options || {}; | |
+ var visitorList; | |
+ if (options.harmony) { | |
+ visitorList = visitors.getAllVisitors(); | |
+ } else { | |
+ visitorList = visitors.transformVisitors.react; | |
} | |
-})() | |
+ | |
+ return transform(visitorList, source, { | |
+ sourceMap: supportsAccessors && options.sourceMap | |
+ }); | |
+} | |
/** | |
- * Class: Buffer | |
- * ============= | |
- * | |
- * The Buffer constructor returns instances of `Uint8Array` that are augmented | |
- * with function properties for all the node `Buffer` API functions. We use | |
- * `Uint8Array` so that square bracket notation works as expected -- it returns | |
- * a single octet. | |
+ * Eval provided source after transforming it. | |
* | |
- * By augmenting the instances, we can avoid modifying the `Uint8Array` | |
- * prototype. | |
+ * @param {string} source Original source code | |
+ * @param {object?} options Options to pass to jstransform | |
*/ | |
-function Buffer (subject, encoding, noZero) { | |
- if (!(this instanceof Buffer)) | |
- return new Buffer(subject, encoding, noZero) | |
+function exec(source, options) { | |
+ return eval(transformReact(source, options).code); | |
+} | |
- var type = typeof subject | |
+/** | |
+ * This method returns a nicely formated line of code pointing to the exact | |
+ * location of the error `e`. The line is limited in size so big lines of code | |
+ * are also shown in a readable way. | |
+ * | |
+ * Example: | |
+ * ... x', overflow:'scroll'}} id={} onScroll={this.scroll} class=" ... | |
+ * ^ | |
+ * | |
+ * @param {string} code The full string of code | |
+ * @param {Error} e The error being thrown | |
+ * @return {string} formatted message | |
+ * @internal | |
+ */ | |
+function createSourceCodeErrorMessage(code, e) { | |
+ var sourceLines = code.split('\n'); | |
+ var erroneousLine = sourceLines[e.lineNumber - 1]; | |
- // Find the length | |
- var length | |
- if (type === 'number') | |
- length = subject > 0 ? subject >>> 0 : 0 | |
- else if (type === 'string') { | |
- if (encoding === 'base64') | |
- subject = base64clean(subject) | |
- length = Buffer.byteLength(subject, encoding) | |
- } else if (type === 'object' && subject !== null) { // assume object is array-like | |
- if (subject.type === 'Buffer' && isArray(subject.data)) | |
- subject = subject.data | |
- length = +subject.length > 0 ? Math.floor(+subject.length) : 0 | |
- } else | |
- throw new TypeError('must start with number, buffer, array or string') | |
+ // Removes any leading indenting spaces and gets the number of | |
+ // chars indenting the `erroneousLine` | |
+ var indentation = 0; | |
+ erroneousLine = erroneousLine.replace(/^\s+/, function(leadingSpaces) { | |
+ indentation = leadingSpaces.length; | |
+ return ''; | |
+ }); | |
- if (this.length > kMaxLength) | |
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' + | |
- 'size: 0x' + kMaxLength.toString(16) + ' bytes') | |
+ // Defines the number of characters that are going to show | |
+ // before and after the erroneous code | |
+ var LIMIT = 30; | |
+ var errorColumn = e.column - indentation; | |
- var buf | |
- if (Buffer.TYPED_ARRAY_SUPPORT) { | |
- // Preferred: Return an augmented `Uint8Array` instance for best performance | |
- buf = Buffer._augment(new Uint8Array(length)) | |
- } else { | |
- // Fallback: Return THIS instance of Buffer (created by `new`) | |
- buf = this | |
- buf.length = length | |
- buf._isBuffer = true | |
+ if (errorColumn > LIMIT) { | |
+ erroneousLine = '... ' + erroneousLine.slice(errorColumn - LIMIT); | |
+ errorColumn = 4 + LIMIT; | |
} | |
+ if (erroneousLine.length - errorColumn > LIMIT) { | |
+ erroneousLine = erroneousLine.slice(0, errorColumn + LIMIT) + ' ...'; | |
+ } | |
+ var message = '\n\n' + erroneousLine + '\n'; | |
+ message += new Array(errorColumn - 1).join(' ') + '^'; | |
+ return message; | |
+} | |
- var i | |
- if (Buffer.TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') { | |
- // Speed optimization -- use set if we're copying from a typed array | |
- buf._set(subject) | |
- } else if (isArrayish(subject)) { | |
- // Treat array-ish objects as a byte array | |
- if (Buffer.isBuffer(subject)) { | |
- for (i = 0; i < length; i++) | |
- buf[i] = subject.readUInt8(i) | |
+/** | |
+ * Actually transform the code. | |
+ * | |
+ * @param {string} code | |
+ * @param {string?} url | |
+ * @param {object?} options | |
+ * @return {string} The transformed code. | |
+ * @internal | |
+ */ | |
+function transformCode(code, url, options) { | |
+ try { | |
+ var transformed = transformReact(code, options); | |
+ } catch(e) { | |
+ e.message += '\n at '; | |
+ if (url) { | |
+ if ('fileName' in e) { | |
+ // We set `fileName` if it's supported by this error object and | |
+ // a `url` was provided. | |
+ // The error will correctly point to `url` in Firefox. | |
+ e.fileName = url; | |
+ } | |
+ e.message += url + ':' + e.lineNumber + ':' + e.column; | |
} else { | |
- for (i = 0; i < length; i++) | |
- buf[i] = ((subject[i] % 256) + 256) % 256 | |
+ e.message += location.href; | |
} | |
- } else if (type === 'string') { | |
- buf.write(subject, 0, encoding) | |
- } else if (type === 'number' && !Buffer.TYPED_ARRAY_SUPPORT && !noZero) { | |
- for (i = 0; i < length; i++) { | |
- buf[i] = 0 | |
+ e.message += createSourceCodeErrorMessage(code, e); | |
+ throw e; | |
+ } | |
+ | |
+ if (!transformed.sourceMap) { | |
+ return transformed.code; | |
+ } | |
+ | |
+ var map = transformed.sourceMap.toJSON(); | |
+ var source; | |
+ if (url == null) { | |
+ source = "Inline JSX script"; | |
+ inlineScriptCount++; | |
+ if (inlineScriptCount > 1) { | |
+ source += ' (' + inlineScriptCount + ')'; | |
} | |
+ } else if (dummyAnchor) { | |
+ // Firefox has problems when the sourcemap source is a proper URL with a | |
+ // protocol and hostname, so use the pathname. We could use just the | |
+ // filename, but hopefully using the full path will prevent potential | |
+ // issues where the same filename exists in multiple directories. | |
+ dummyAnchor.href = url; | |
+ source = dummyAnchor.pathname.substr(1); | |
} | |
+ map.sources = [source]; | |
+ map.sourcesContent = [code]; | |
- return buf | |
+ return ( | |
+ transformed.code + | |
+ '\n//# sourceMappingURL=data:application/json;base64,' + | |
+ buffer.Buffer(JSON.stringify(map)).toString('base64') | |
+ ); | |
} | |
-Buffer.isBuffer = function (b) { | |
- return !!(b != null && b._isBuffer) | |
-} | |
-Buffer.compare = function (a, b) { | |
- if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) | |
- throw new TypeError('Arguments must be Buffers') | |
+/** | |
+ * Appends a script element at the end of the <head> with the content of code, | |
+ * after transforming it. | |
+ * | |
+ * @param {string} code The original source code | |
+ * @param {string?} url Where the code came from. null if inline | |
+ * @param {object?} options Options to pass to jstransform | |
+ * @internal | |
+ */ | |
+function run(code, url, options) { | |
+ var scriptEl = document.createElement('script'); | |
+ scriptEl.text = transformCode(code, url, options); | |
+ headEl.appendChild(scriptEl); | |
+} | |
- var x = a.length | |
- var y = b.length | |
- for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {} | |
- if (i !== len) { | |
- x = a[i] | |
- y = b[i] | |
- } | |
- if (x < y) return -1 | |
- if (y < x) return 1 | |
- return 0 | |
-} | |
+/** | |
+ * Load script from the provided url and pass the content to the callback. | |
+ * | |
+ * @param {string} url The location of the script src | |
+ * @param {function} callback Function to call with the content of url | |
+ * @internal | |
+ */ | |
+function load(url, successCallback, errorCallback) { | |
+ var xhr; | |
+ xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') | |
+ : new XMLHttpRequest(); | |
-Buffer.isEncoding = function (encoding) { | |
- switch (String(encoding).toLowerCase()) { | |
- case 'hex': | |
- case 'utf8': | |
- case 'utf-8': | |
- case 'ascii': | |
- case 'binary': | |
- case 'base64': | |
- case 'raw': | |
- case 'ucs2': | |
- case 'ucs-2': | |
- case 'utf16le': | |
- case 'utf-16le': | |
- return true | |
- default: | |
- return false | |
+ // async, however scripts will be executed in the order they are in the | |
+ // DOM to mirror normal script loading. | |
+ xhr.open('GET', url, true); | |
+ if ('overrideMimeType' in xhr) { | |
+ xhr.overrideMimeType('text/plain'); | |
} | |
+ xhr.onreadystatechange = function() { | |
+ if (xhr.readyState === 4) { | |
+ if (xhr.status === 0 || xhr.status === 200) { | |
+ successCallback(xhr.responseText); | |
+ } else { | |
+ errorCallback(); | |
+ throw new Error("Could not load " + url); | |
+ } | |
+ } | |
+ }; | |
+ return xhr.send(null); | |
} | |
-Buffer.concat = function (list, totalLength) { | |
- if (!isArray(list)) throw new TypeError('Usage: Buffer.concat(list[, length])') | |
- | |
- if (list.length === 0) { | |
- return new Buffer(0) | |
- } else if (list.length === 1) { | |
- return list[0] | |
- } | |
+/** | |
+ * Loop over provided script tags and get the content, via innerHTML if an | |
+ * inline script, or by using XHR. Transforms are applied if needed. The scripts | |
+ * are executed in the order they are found on the page. | |
+ * | |
+ * @param {array} scripts The <script> elements to load and run. | |
+ * @internal | |
+ */ | |
+function loadScripts(scripts) { | |
+ var result = []; | |
+ var count = scripts.length; | |
- var i | |
- if (totalLength === undefined) { | |
- totalLength = 0 | |
- for (i = 0; i < list.length; i++) { | |
- totalLength += list[i].length | |
- } | |
- } | |
+ function check() { | |
+ var script, i; | |
- var buf = new Buffer(totalLength) | |
- var pos = 0 | |
- for (i = 0; i < list.length; i++) { | |
- var item = list[i] | |
- item.copy(buf, pos) | |
- pos += item.length | |
- } | |
- return buf | |
-} | |
+ for (i = 0; i < count; i++) { | |
+ script = result[i]; | |
-Buffer.byteLength = function (str, encoding) { | |
- var ret | |
- str = str + '' | |
- switch (encoding || 'utf8') { | |
- case 'ascii': | |
- case 'binary': | |
- case 'raw': | |
- ret = str.length | |
- break | |
- case 'ucs2': | |
- case 'ucs-2': | |
- case 'utf16le': | |
- case 'utf-16le': | |
- ret = str.length * 2 | |
- break | |
- case 'hex': | |
- ret = str.length >>> 1 | |
- break | |
- case 'utf8': | |
- case 'utf-8': | |
- ret = utf8ToBytes(str).length | |
- break | |
- case 'base64': | |
- ret = base64ToBytes(str).length | |
- break | |
- default: | |
- ret = str.length | |
+ if (script.loaded && !script.executed) { | |
+ script.executed = true; | |
+ run(script.content, script.url, script.options); | |
+ } else if (!script.loaded && !script.error && !script.async) { | |
+ break; | |
+ } | |
+ } | |
} | |
- return ret | |
-} | |
- | |
-// pre-set for values that may exist in the future | |
-Buffer.prototype.length = undefined | |
-Buffer.prototype.parent = undefined | |
-// toString(encoding, start=0, end=buffer.length) | |
-Buffer.prototype.toString = function (encoding, start, end) { | |
- var loweredCase = false | |
+ scripts.forEach(function(script, i) { | |
+ var options = { | |
+ sourceMap: true | |
+ }; | |
+ if (/;harmony=true(;|$)/.test(script.type)) { | |
+ options.harmony = true | |
+ } | |
- start = start >>> 0 | |
- end = end === undefined || end === Infinity ? this.length : end >>> 0 | |
+ // script.async is always true for non-javascript script tags | |
+ var async = script.hasAttribute('async'); | |
- if (!encoding) encoding = 'utf8' | |
- if (start < 0) start = 0 | |
- if (end > this.length) end = this.length | |
- if (end <= start) return '' | |
+ if (script.src) { | |
+ result[i] = { | |
+ async: async, | |
+ error: false, | |
+ executed: false, | |
+ content: null, | |
+ loaded: false, | |
+ url: script.src, | |
+ options: options | |
+ }; | |
- while (true) { | |
- switch (encoding) { | |
- case 'hex': | |
- return hexSlice(this, start, end) | |
+ load(script.src, function(content) { | |
+ result[i].loaded = true; | |
+ result[i].content = content; | |
+ check(); | |
+ }, function() { | |
+ result[i].error = true; | |
+ check(); | |
+ }); | |
+ } else { | |
+ result[i] = { | |
+ async: async, | |
+ error: false, | |
+ executed: false, | |
+ content: script.innerHTML, | |
+ loaded: true, | |
+ url: null, | |
+ options: options | |
+ }; | |
+ } | |
+ }); | |
- case 'utf8': | |
- case 'utf-8': | |
- return utf8Slice(this, start, end) | |
+ check(); | |
+} | |
- case 'ascii': | |
- return asciiSlice(this, start, end) | |
+/** | |
+ * Find and run all script tags with type="text/jsx". | |
+ * | |
+ * @internal | |
+ */ | |
+function runScripts() { | |
+ var scripts = document.getElementsByTagName('script'); | |
- case 'binary': | |
- return binarySlice(this, start, end) | |
+ // Array.prototype.slice cannot be used on NodeList on IE8 | |
+ var jsxScripts = []; | |
+ for (var i = 0; i < scripts.length; i++) { | |
+ if (/^text\/jsx(;|$)/.test(scripts.item(i).type)) { | |
+ jsxScripts.push(scripts.item(i)); | |
+ } | |
+ } | |
- case 'base64': | |
- return base64Slice(this, start, end) | |
+ if (jsxScripts.length < 1) { | |
+ return; | |
+ } | |
- case 'ucs2': | |
- case 'ucs-2': | |
- case 'utf16le': | |
- case 'utf-16le': | |
- return utf16leSlice(this, start, end) | |
+ console.warn( | |
+ 'You are using the in-browser JSX transformer. Be sure to precompile ' + | |
+ 'your JSX for production - ' + | |
+ 'http://facebook.github.io/react/docs/tooling-integration.html#jsx' | |
+ ); | |
- default: | |
- if (loweredCase) | |
- throw new TypeError('Unknown encoding: ' + encoding) | |
- encoding = (encoding + '').toLowerCase() | |
- loweredCase = true | |
- } | |
- } | |
+ loadScripts(jsxScripts); | |
} | |
-Buffer.prototype.equals = function (b) { | |
- if(!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | |
- return Buffer.compare(this, b) === 0 | |
-} | |
+// Listen for load event if we're in a browser and then kick off finding and | |
+// running of scripts. | |
+if (typeof window !== "undefined" && window !== null) { | |
+ headEl = document.getElementsByTagName('head')[0]; | |
+ dummyAnchor = document.createElement('a'); | |
-Buffer.prototype.inspect = function () { | |
- var str = '' | |
- var max = exports.INSPECT_MAX_BYTES | |
- if (this.length > 0) { | |
- str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') | |
- if (this.length > max) | |
- str += ' ... ' | |
+ if (window.addEventListener) { | |
+ window.addEventListener('DOMContentLoaded', runScripts, false); | |
+ } else { | |
+ window.attachEvent('onload', runScripts); | |
} | |
- return '<Buffer ' + str + '>' | |
} | |
-Buffer.prototype.compare = function (b) { | |
- if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | |
- return Buffer.compare(this, b) | |
-} | |
+module.exports = { | |
+ transform: transformReact, | |
+ exec: exec | |
+}; | |
-// `get` will be removed in Node 0.13+ | |
-Buffer.prototype.get = function (offset) { | |
- console.log('.get() is deprecated. Access using array indexes instead.') | |
- return this.readUInt8(offset) | |
-} | |
+},{"./fbtransform/visitors":37,"buffer":2,"jstransform":21}],2:[function(_dereq_,module,exports){ | |
+/*! | |
+ * The buffer module from node.js, for the browser. | |
+ * | |
+ * @author Feross Aboukhadijeh <[email protected]> <http://feross.org> | |
+ * @license MIT | |
+ */ | |
-// `set` will be removed in Node 0.13+ | |
-Buffer.prototype.set = function (v, offset) { | |
- console.log('.set() is deprecated. Access using array indexes instead.') | |
- return this.writeUInt8(v, offset) | |
-} | |
+var base64 = _dereq_('base64-js') | |
+var ieee754 = _dereq_('ieee754') | |
+var isArray = _dereq_('is-array') | |
-function hexWrite (buf, string, offset, length) { | |
- offset = Number(offset) || 0 | |
- var remaining = buf.length - offset | |
- if (!length) { | |
- length = remaining | |
- } else { | |
- length = Number(length) | |
- if (length > remaining) { | |
- length = remaining | |
- } | |
- } | |
+exports.Buffer = Buffer | |
+exports.SlowBuffer = Buffer | |
+exports.INSPECT_MAX_BYTES = 50 | |
+Buffer.poolSize = 8192 // not used by this implementation | |
- // must be an even number of digits | |
- var strLen = string.length | |
- if (strLen % 2 !== 0) throw new Error('Invalid hex string') | |
+var kMaxLength = 0x3fffffff | |
- if (length > strLen / 2) { | |
- length = strLen / 2 | |
- } | |
- for (var i = 0; i < length; i++) { | |
- var byte = parseInt(string.substr(i * 2, 2), 16) | |
- if (isNaN(byte)) throw new Error('Invalid hex string') | |
- buf[offset + i] = byte | |
+/** | |
+ * If `Buffer.TYPED_ARRAY_SUPPORT`: | |
+ * === true Use Uint8Array implementation (fastest) | |
+ * === false Use Object implementation (most compatible, even IE6) | |
+ * | |
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, | |
+ * Opera 11.6+, iOS 4.2+. | |
+ * | |
+ * Note: | |
+ * | |
+ * - Implementation must support adding new properties to `Uint8Array` instances. | |
+ * Firefox 4-29 lacked support, fixed in Firefox 30+. | |
+ * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. | |
+ * | |
+ * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. | |
+ * | |
+ * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of | |
+ * incorrect length in some situations. | |
+ * | |
+ * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will | |
+ * get the Object implementation, which is slower but will work correctly. | |
+ */ | |
+Buffer.TYPED_ARRAY_SUPPORT = (function () { | |
+ try { | |
+ var buf = new ArrayBuffer(0) | |
+ var arr = new Uint8Array(buf) | |
+ arr.foo = function () { return 42 } | |
+ return 42 === arr.foo() && // typed array instances can be augmented | |
+ typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` | |
+ new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` | |
+ } catch (e) { | |
+ return false | |
} | |
- return i | |
-} | |
+})() | |
-function utf8Write (buf, string, offset, length) { | |
- var charsWritten = blitBuffer(utf8ToBytes(string), buf, offset, length) | |
- return charsWritten | |
-} | |
+/** | |
+ * Class: Buffer | |
+ * ============= | |
+ * | |
+ * The Buffer constructor returns instances of `Uint8Array` that are augmented | |
+ * with function properties for all the node `Buffer` API functions. We use | |
+ * `Uint8Array` so that square bracket notation works as expected -- it returns | |
+ * a single octet. | |
+ * | |
+ * By augmenting the instances, we can avoid modifying the `Uint8Array` | |
+ * prototype. | |
+ */ | |
+function Buffer (subject, encoding, noZero) { | |
+ if (!(this instanceof Buffer)) | |
+ return new Buffer(subject, encoding, noZero) | |
-function asciiWrite (buf, string, offset, length) { | |
- var charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length) | |
- return charsWritten | |
-} | |
+ var type = typeof subject | |
-function binaryWrite (buf, string, offset, length) { | |
- return asciiWrite(buf, string, offset, length) | |
-} | |
+ // Find the length | |
+ var length | |
+ if (type === 'number') | |
+ length = subject > 0 ? subject >>> 0 : 0 | |
+ else if (type === 'string') { | |
+ if (encoding === 'base64') | |
+ subject = base64clean(subject) | |
+ length = Buffer.byteLength(subject, encoding) | |
+ } else if (type === 'object' && subject !== null) { // assume object is array-like | |
+ if (subject.type === 'Buffer' && isArray(subject.data)) | |
+ subject = subject.data | |
+ length = +subject.length > 0 ? Math.floor(+subject.length) : 0 | |
+ } else | |
+ throw new TypeError('must start with number, buffer, array or string') | |
-function base64Write (buf, string, offset, length) { | |
- var charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length) | |
- return charsWritten | |
-} | |
+ if (this.length > kMaxLength) | |
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' + | |
+ 'size: 0x' + kMaxLength.toString(16) + ' bytes') | |
-function utf16leWrite (buf, string, offset, length) { | |
- var charsWritten = blitBuffer(utf16leToBytes(string), buf, offset, length) | |
- return charsWritten | |
-} | |
+ var buf | |
+ if (Buffer.TYPED_ARRAY_SUPPORT) { | |
+ // Preferred: Return an augmented `Uint8Array` instance for best performance | |
+ buf = Buffer._augment(new Uint8Array(length)) | |
+ } else { | |
+ // Fallback: Return THIS instance of Buffer (created by `new`) | |
+ buf = this | |
+ buf.length = length | |
+ buf._isBuffer = true | |
+ } | |
-Buffer.prototype.write = function (string, offset, length, encoding) { | |
- // Support both (string, offset, length, encoding) | |
- // and the legacy (string, encoding, offset, length) | |
- if (isFinite(offset)) { | |
- if (!isFinite(length)) { | |
- encoding = length | |
- length = undefined | |
+ var i | |
+ if (Buffer.TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') { | |
+ // Speed optimization -- use set if we're copying from a typed array | |
+ buf._set(subject) | |
+ } else if (isArrayish(subject)) { | |
+ // Treat array-ish objects as a byte array | |
+ if (Buffer.isBuffer(subject)) { | |
+ for (i = 0; i < length; i++) | |
+ buf[i] = subject.readUInt8(i) | |
+ } else { | |
+ for (i = 0; i < length; i++) | |
+ buf[i] = ((subject[i] % 256) + 256) % 256 | |
+ } | |
+ } else if (type === 'string') { | |
+ buf.write(subject, 0, encoding) | |
+ } else if (type === 'number' && !Buffer.TYPED_ARRAY_SUPPORT && !noZero) { | |
+ for (i = 0; i < length; i++) { | |
+ buf[i] = 0 | |
} | |
- } else { // legacy | |
- var swap = encoding | |
- encoding = offset | |
- offset = length | |
- length = swap | |
} | |
- offset = Number(offset) || 0 | |
- var remaining = this.length - offset | |
- if (!length) { | |
- length = remaining | |
- } else { | |
- length = Number(length) | |
- if (length > remaining) { | |
- length = remaining | |
- } | |
+ return buf | |
+} | |
+ | |
+Buffer.isBuffer = function (b) { | |
+ return !!(b != null && b._isBuffer) | |
+} | |
+ | |
+Buffer.compare = function (a, b) { | |
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) | |
+ throw new TypeError('Arguments must be Buffers') | |
+ | |
+ var x = a.length | |
+ var y = b.length | |
+ for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {} | |
+ if (i !== len) { | |
+ x = a[i] | |
+ y = b[i] | |
} | |
- encoding = String(encoding || 'utf8').toLowerCase() | |
+ if (x < y) return -1 | |
+ if (y < x) return 1 | |
+ return 0 | |
+} | |
- var ret | |
- switch (encoding) { | |
+Buffer.isEncoding = function (encoding) { | |
+ switch (String(encoding).toLowerCase()) { | |
case 'hex': | |
- ret = hexWrite(this, string, offset, length) | |
- break | |
case 'utf8': | |
case 'utf-8': | |
- ret = utf8Write(this, string, offset, length) | |
- break | |
case 'ascii': | |
- ret = asciiWrite(this, string, offset, length) | |
- break | |
case 'binary': | |
- ret = binaryWrite(this, string, offset, length) | |
- break | |
case 'base64': | |
- ret = base64Write(this, string, offset, length) | |
- break | |
+ case 'raw': | |
case 'ucs2': | |
case 'ucs-2': | |
case 'utf16le': | |
case 'utf-16le': | |
- ret = utf16leWrite(this, string, offset, length) | |
- break | |
+ return true | |
default: | |
- throw new TypeError('Unknown encoding: ' + encoding) | |
+ return false | |
} | |
- return ret | |
} | |
-Buffer.prototype.toJSON = function () { | |
- return { | |
- type: 'Buffer', | |
- data: Array.prototype.slice.call(this._arr || this, 0) | |
+Buffer.concat = function (list, totalLength) { | |
+ if (!isArray(list)) throw new TypeError('Usage: Buffer.concat(list[, length])') | |
+ | |
+ if (list.length === 0) { | |
+ return new Buffer(0) | |
+ } else if (list.length === 1) { | |
+ return list[0] | |
} | |
-} | |
-function base64Slice (buf, start, end) { | |
- if (start === 0 && end === buf.length) { | |
- return base64.fromByteArray(buf) | |
- } else { | |
- return base64.fromByteArray(buf.slice(start, end)) | |
+ var i | |
+ if (totalLength === undefined) { | |
+ totalLength = 0 | |
+ for (i = 0; i < list.length; i++) { | |
+ totalLength += list[i].length | |
+ } | |
+ } | |
+ | |
+ var buf = new Buffer(totalLength) | |
+ var pos = 0 | |
+ for (i = 0; i < list.length; i++) { | |
+ var item = list[i] | |
+ item.copy(buf, pos) | |
+ pos += item.length | |
+ } | |
+ return buf | |
+} | |
+ | |
+Buffer.byteLength = function (str, encoding) { | |
+ var ret | |
+ str = str + '' | |
+ switch (encoding || 'utf8') { | |
+ case 'ascii': | |
+ case 'binary': | |
+ case 'raw': | |
+ ret = str.length | |
+ break | |
+ case 'ucs2': | |
+ case 'ucs-2': | |
+ case 'utf16le': | |
+ case 'utf-16le': | |
+ ret = str.length * 2 | |
+ break | |
+ case 'hex': | |
+ ret = str.length >>> 1 | |
+ break | |
+ case 'utf8': | |
+ case 'utf-8': | |
+ ret = utf8ToBytes(str).length | |
+ break | |
+ case 'base64': | |
+ ret = base64ToBytes(str).length | |
+ break | |
+ default: | |
+ ret = str.length | |
+ } | |
+ return ret | |
+} | |
+ | |
+// pre-set for values that may exist in the future | |
+Buffer.prototype.length = undefined | |
+Buffer.prototype.parent = undefined | |
+ | |
+// toString(encoding, start=0, end=buffer.length) | |
+Buffer.prototype.toString = function (encoding, start, end) { | |
+ var loweredCase = false | |
+ | |
+ start = start >>> 0 | |
+ end = end === undefined || end === Infinity ? this.length : end >>> 0 | |
+ | |
+ if (!encoding) encoding = 'utf8' | |
+ if (start < 0) start = 0 | |
+ if (end > this.length) end = this.length | |
+ if (end <= start) return '' | |
+ | |
+ while (true) { | |
+ switch (encoding) { | |
+ case 'hex': | |
+ return hexSlice(this, start, end) | |
+ | |
+ case 'utf8': | |
+ case 'utf-8': | |
+ return utf8Slice(this, start, end) | |
+ | |
+ case 'ascii': | |
+ return asciiSlice(this, start, end) | |
+ | |
+ case 'binary': | |
+ return binarySlice(this, start, end) | |
+ | |
+ case 'base64': | |
+ return base64Slice(this, start, end) | |
+ | |
+ case 'ucs2': | |
+ case 'ucs-2': | |
+ case 'utf16le': | |
+ case 'utf-16le': | |
+ return utf16leSlice(this, start, end) | |
+ | |
+ default: | |
+ if (loweredCase) | |
+ throw new TypeError('Unknown encoding: ' + encoding) | |
+ encoding = (encoding + '').toLowerCase() | |
+ loweredCase = true | |
+ } | |
+ } | |
+} | |
+ | |
+Buffer.prototype.equals = function (b) { | |
+ if(!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | |
+ return Buffer.compare(this, b) === 0 | |
+} | |
+ | |
+Buffer.prototype.inspect = function () { | |
+ var str = '' | |
+ var max = exports.INSPECT_MAX_BYTES | |
+ if (this.length > 0) { | |
+ str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') | |
+ if (this.length > max) | |
+ str += ' ... ' | |
+ } | |
+ return '<Buffer ' + str + '>' | |
+} | |
+ | |
+Buffer.prototype.compare = function (b) { | |
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | |
+ return Buffer.compare(this, b) | |
+} | |
+ | |
+// `get` will be removed in Node 0.13+ | |
+Buffer.prototype.get = function (offset) { | |
+ console.log('.get() is deprecated. Access using array indexes instead.') | |
+ return this.readUInt8(offset) | |
+} | |
+ | |
+// `set` will be removed in Node 0.13+ | |
+Buffer.prototype.set = function (v, offset) { | |
+ console.log('.set() is deprecated. Access using array indexes instead.') | |
+ return this.writeUInt8(v, offset) | |
+} | |
+ | |
+function hexWrite (buf, string, offset, length) { | |
+ offset = Number(offset) || 0 | |
+ var remaining = buf.length - offset | |
+ if (!length) { | |
+ length = remaining | |
+ } else { | |
+ length = Number(length) | |
+ if (length > remaining) { | |
+ length = remaining | |
+ } | |
+ } | |
+ | |
+ // must be an even number of digits | |
+ var strLen = string.length | |
+ if (strLen % 2 !== 0) throw new Error('Invalid hex string') | |
+ | |
+ if (length > strLen / 2) { | |
+ length = strLen / 2 | |
+ } | |
+ for (var i = 0; i < length; i++) { | |
+ var byte = parseInt(string.substr(i * 2, 2), 16) | |
+ if (isNaN(byte)) throw new Error('Invalid hex string') | |
+ buf[offset + i] = byte | |
+ } | |
+ return i | |
+} | |
+ | |
+function utf8Write (buf, string, offset, length) { | |
+ var charsWritten = blitBuffer(utf8ToBytes(string), buf, offset, length) | |
+ return charsWritten | |
+} | |
+ | |
+function asciiWrite (buf, string, offset, length) { | |
+ var charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length) | |
+ return charsWritten | |
+} | |
+ | |
+function binaryWrite (buf, string, offset, length) { | |
+ return asciiWrite(buf, string, offset, length) | |
+} | |
+ | |
+function base64Write (buf, string, offset, length) { | |
+ var charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length) | |
+ return charsWritten | |
+} | |
+ | |
+function utf16leWrite (buf, string, offset, length) { | |
+ var charsWritten = blitBuffer(utf16leToBytes(string), buf, offset, length) | |
+ return charsWritten | |
+} | |
+ | |
+Buffer.prototype.write = function (string, offset, length, encoding) { | |
+ // Support both (string, offset, length, encoding) | |
+ // and the legacy (string, encoding, offset, length) | |
+ if (isFinite(offset)) { | |
+ if (!isFinite(length)) { | |
+ encoding = length | |
+ length = undefined | |
+ } | |
+ } else { // legacy | |
+ var swap = encoding | |
+ encoding = offset | |
+ offset = length | |
+ length = swap | |
+ } | |
+ | |
+ offset = Number(offset) || 0 | |
+ var remaining = this.length - offset | |
+ if (!length) { | |
+ length = remaining | |
+ } else { | |
+ length = Number(length) | |
+ if (length > remaining) { | |
+ length = remaining | |
+ } | |
+ } | |
+ encoding = String(encoding || 'utf8').toLowerCase() | |
+ | |
+ var ret | |
+ switch (encoding) { | |
+ case 'hex': | |
+ ret = hexWrite(this, string, offset, length) | |
+ break | |
+ case 'utf8': | |
+ case 'utf-8': | |
+ ret = utf8Write(this, string, offset, length) | |
+ break | |
+ case 'ascii': | |
+ ret = asciiWrite(this, string, offset, length) | |
+ break | |
+ case 'binary': | |
+ ret = binaryWrite(this, string, offset, length) | |
+ break | |
+ case 'base64': | |
+ ret = base64Write(this, string, offset, length) | |
+ break | |
+ case 'ucs2': | |
+ case 'ucs-2': | |
+ case 'utf16le': | |
+ case 'utf-16le': | |
+ ret = utf16leWrite(this, string, offset, length) | |
+ break | |
+ default: | |
+ throw new TypeError('Unknown encoding: ' + encoding) | |
+ } | |
+ return ret | |
+} | |
+ | |
+Buffer.prototype.toJSON = function () { | |
+ return { | |
+ type: 'Buffer', | |
+ data: Array.prototype.slice.call(this._arr || this, 0) | |
+ } | |
+} | |
+ | |
+function base64Slice (buf, start, end) { | |
+ if (start === 0 && end === buf.length) { | |
+ return base64.fromByteArray(buf) | |
+ } else { | |
+ return base64.fromByteArray(buf.slice(start, end)) | |
} | |
} | |
function utf8Slice (buf, start, end) { | |
var res = '' | |
var tmp = '' | |
end = Math.min(buf.length, end) | |
@@ -1048,17 +1377,17 @@ | |
function decodeUtf8Char (str) { | |
try { | |
return decodeURIComponent(str) | |
} catch (err) { | |
return String.fromCharCode(0xFFFD) // UTF 8 invalid char | |
} | |
} | |
-},{"base64-js":2,"ieee754":3,"is-array":4}],2:[function(_dereq_,module,exports){ | |
+},{"base64-js":3,"ieee754":4,"is-array":5}],3:[function(_dereq_,module,exports){ | |
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | |
;(function (exports) { | |
'use strict'; | |
var Arr = (typeof Uint8Array !== 'undefined') | |
? Uint8Array | |
: Array | |
@@ -1170,17 +1499,17 @@ | |
return output | |
} | |
exports.toByteArray = b64ToByteArray | |
exports.fromByteArray = uint8ToBase64 | |
}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) | |
-},{}],3:[function(_dereq_,module,exports){ | |
+},{}],4:[function(_dereq_,module,exports){ | |
exports.read = function(buffer, offset, isLE, mLen, nBytes) { | |
var e, m, | |
eLen = nBytes * 8 - mLen - 1, | |
eMax = (1 << eLen) - 1, | |
eBias = eMax >> 1, | |
nBits = -7, | |
i = isLE ? (nBytes - 1) : 0, | |
d = isLE ? -1 : 1, | |
@@ -1256,17 +1585,17 @@ | |
e = (e << mLen) | m; | |
eLen += mLen; | |
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); | |
buffer[offset + i - d] |= s * 128; | |
}; | |
-},{}],4:[function(_dereq_,module,exports){ | |
+},{}],5:[function(_dereq_,module,exports){ | |
/** | |
* isArray | |
*/ | |
var isArray = Array.isArray; | |
/** | |
@@ -1291,17 +1620,17 @@ | |
* @param {mixed} val | |
* @return {bool} | |
*/ | |
module.exports = isArray || function (val) { | |
return !! val && '[object Array]' == str.call(val); | |
}; | |
-},{}],5:[function(_dereq_,module,exports){ | |
+},{}],6:[function(_dereq_,module,exports){ | |
(function (process){ | |
// Copyright Joyent, Inc. and other Node contributors. | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a | |
// copy of this software and associated documentation files (the | |
// "Software"), to deal in the Software without restriction, including | |
// without limitation the rights to use, copy, modify, merge, publish, | |
// distribute, sublicense, and/or sell copies of the Software, and to permit | |
@@ -1518,35 +1847,58 @@ | |
var substr = 'ab'.substr(-1) === 'b' | |
? function (str, start, len) { return str.substr(start, len) } | |
: function (str, start, len) { | |
if (start < 0) start = str.length + start; | |
return str.substr(start, len); | |
} | |
; | |
-}).call(this,_dereq_("FWaASH")) | |
-},{"FWaASH":6}],6:[function(_dereq_,module,exports){ | |
+}).call(this,_dereq_('_process')) | |
+},{"_process":7}],7:[function(_dereq_,module,exports){ | |
// shim for using process in browser | |
var process = module.exports = {}; | |
process.nextTick = (function () { | |
var canSetImmediate = typeof window !== 'undefined' | |
&& window.setImmediate; | |
+ var canMutationObserver = typeof window !== 'undefined' | |
+ && window.MutationObserver; | |
var canPost = typeof window !== 'undefined' | |
&& window.postMessage && window.addEventListener | |
; | |
if (canSetImmediate) { | |
return function (f) { return window.setImmediate(f) }; | |
} | |
+ var queue = []; | |
+ | |
+ if (canMutationObserver) { | |
+ var hiddenDiv = document.createElement("div"); | |
+ var observer = new MutationObserver(function () { | |
+ var queueList = queue.slice(); | |
+ queue.length = 0; | |
+ queueList.forEach(function (fn) { | |
+ fn(); | |
+ }); | |
+ }); | |
+ | |
+ observer.observe(hiddenDiv, { attributes: true }); | |
+ | |
+ return function nextTick(fn) { | |
+ if (!queue.length) { | |
+ hiddenDiv.setAttribute('yes', 'no'); | |
+ } | |
+ queue.push(fn); | |
+ }; | |
+ } | |
+ | |
if (canPost) { | |
- var queue = []; | |
window.addEventListener('message', function (ev) { | |
var source = ev.source; | |
if ((source === window || source === null) && ev.data === 'process-tick') { | |
ev.stopPropagation(); | |
if (queue.length > 0) { | |
var fn = queue.shift(); | |
fn(); | |
} | |
@@ -1576,25 +1928,25 @@ | |
process.once = noop; | |
process.off = noop; | |
process.removeListener = noop; | |
process.removeAllListeners = noop; | |
process.emit = noop; | |
process.binding = function (name) { | |
throw new Error('process.binding is not supported'); | |
-} | |
+}; | |
// TODO(shtylman) | |
process.cwd = function () { return '/' }; | |
process.chdir = function (dir) { | |
throw new Error('process.chdir is not supported'); | |
}; | |
-},{}],7:[function(_dereq_,module,exports){ | |
+},{}],8:[function(_dereq_,module,exports){ | |
/* | |
Copyright (C) 2013 Ariya Hidayat <[email protected]> | |
Copyright (C) 2013 Thaddee Tyl <[email protected]> | |
Copyright (C) 2012 Ariya Hidayat <[email protected]> | |
Copyright (C) 2012 Mathias Bynens <[email protected]> | |
Copyright (C) 2012 Joost-Wim Boekesteijn <[email protected]> | |
Copyright (C) 2012 Kris Kowal <[email protected]> | |
Copyright (C) 2012 Yusuke Suzuki <[email protected]> | |
@@ -3784,17 +4136,17 @@ | |
}, | |
createMethodDefinition: function (propertyType, kind, key, value) { | |
return { | |
type: Syntax.MethodDefinition, | |
key: key, | |
value: value, | |
kind: kind, | |
- 'static': propertyType === ClassPropertyType["static"] | |
+ 'static': propertyType === ClassPropertyType.static | |
}; | |
}, | |
createClassProperty: function (propertyIdentifier) { | |
return { | |
type: Syntax.ClassProperty, | |
id: propertyIdentifier | |
}; | |
@@ -6454,17 +6806,17 @@ | |
// 14 Classes | |
function parseMethodDefinition(existingPropNames) { | |
var token, key, param, propType, isValidDuplicateProp = false, | |
marker = markerCreate(), token2, parametricType, | |
parametricTypeMarker, annotationMarker; | |
if (lookahead.value === 'static') { | |
- propType = ClassPropertyType["static"]; | |
+ propType = ClassPropertyType.static; | |
lex(); | |
} else { | |
propType = ClassPropertyType.prototype; | |
} | |
if (match('*')) { | |
lex(); | |
return markerApply(marker, delegate.createMethodDefinition( | |
@@ -6591,17 +6943,17 @@ | |
} | |
return parseMethodDefinition(existingProps); | |
} | |
function parseClassBody() { | |
var classElement, classElements = [], existingProps = {}, marker = markerCreate(); | |
- existingProps[ClassPropertyType["static"]] = {}; | |
+ existingProps[ClassPropertyType.static] = {}; | |
existingProps[ClassPropertyType.prototype] = {}; | |
expect('{'); | |
while (index < length) { | |
if (match('}')) { | |
break; | |
} | |
@@ -7975,17 +8327,17 @@ | |
} | |
return types; | |
}()); | |
})); | |
/* vim: set sw=4 ts=4 et tw=80 : */ | |
-},{}],8:[function(_dereq_,module,exports){ | |
+},{}],9:[function(_dereq_,module,exports){ | |
var Base62 = (function (my) { | |
my.chars = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] | |
my.encode = function(i){ | |
if (i === 0) {return '0'} | |
var s = '' | |
while (i > 0) { | |
s = this.chars[i % 62] + s | |
@@ -8003,27 +8355,27 @@ | |
b = b * 62 + d - [, 48, 29, 87][d >> 5]; | |
return b | |
}; | |
return my; | |
}({})); | |
module.exports = Base62 | |
-},{}],9:[function(_dereq_,module,exports){ | |
+},{}],10:[function(_dereq_,module,exports){ | |
/* | |
* Copyright 2009-2011 Mozilla Foundation and contributors | |
* Licensed under the New BSD license. See LICENSE.txt or: | |
* http://opensource.org/licenses/BSD-3-Clause | |
*/ | |
exports.SourceMapGenerator = _dereq_('./source-map/source-map-generator').SourceMapGenerator; | |
exports.SourceMapConsumer = _dereq_('./source-map/source-map-consumer').SourceMapConsumer; | |
exports.SourceNode = _dereq_('./source-map/source-node').SourceNode; | |
-},{"./source-map/source-map-consumer":14,"./source-map/source-map-generator":15,"./source-map/source-node":16}],10:[function(_dereq_,module,exports){ | |
+},{"./source-map/source-map-consumer":15,"./source-map/source-map-generator":16,"./source-map/source-node":17}],11:[function(_dereq_,module,exports){ | |
/* -*- Mode: js; js-indent-level: 2; -*- */ | |
/* | |
* Copyright 2011 Mozilla Foundation and contributors | |
* Licensed under the New BSD license. See LICENSE or: | |
* http://opensource.org/licenses/BSD-3-Clause | |
*/ | |
if (typeof define !== 'function') { | |
var define = _dereq_('amdefine')(module, _dereq_); | |
@@ -8112,17 +8464,17 @@ | |
ArraySet.prototype.toArray = function ArraySet_toArray() { | |
return this._array.slice(); | |
}; | |
exports.ArraySet = ArraySet; | |
}); | |
-},{"./util":17,"amdefine":18}],11:[function(_dereq_,module,exports){ | |
+},{"./util":18,"amdefine":19}],12:[function(_dereq_,module,exports){ | |
/* -*- Mode: js; js-indent-level: 2; -*- */ | |
/* | |
* Copyright 2011 Mozilla Foundation and contributors | |
* Licensed under the New BSD license. See LICENSE or: | |
* http://opensource.org/licenses/BSD-3-Clause | |
* | |
* Based on the Base 64 VLQ implementation in Closure Compiler: | |
* https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java | |
@@ -8258,17 +8610,17 @@ | |
return { | |
value: fromVLQSigned(result), | |
rest: aStr.slice(i) | |
}; | |
}; | |
}); | |
-},{"./base64":12,"amdefine":18}],12:[function(_dereq_,module,exports){ | |
+},{"./base64":13,"amdefine":19}],13:[function(_dereq_,module,exports){ | |
/* -*- Mode: js; js-indent-level: 2; -*- */ | |
/* | |
* Copyright 2011 Mozilla Foundation and contributors | |
* Licensed under the New BSD license. See LICENSE or: | |
* http://opensource.org/licenses/BSD-3-Clause | |
*/ | |
if (typeof define !== 'function') { | |
var define = _dereq_('amdefine')(module, _dereq_); | |
@@ -8302,17 +8654,17 @@ | |
if (aChar in charToIntMap) { | |
return charToIntMap[aChar]; | |
} | |
throw new TypeError("Not a valid base 64 digit: " + aChar); | |
}; | |
}); | |
-},{"amdefine":18}],13:[function(_dereq_,module,exports){ | |
+},{"amdefine":19}],14:[function(_dereq_,module,exports){ | |
/* -*- Mode: js; js-indent-level: 2; -*- */ | |
/* | |
* Copyright 2011 Mozilla Foundation and contributors | |
* Licensed under the New BSD license. See LICENSE or: | |
* http://opensource.org/licenses/BSD-3-Clause | |
*/ | |
if (typeof define !== 'function') { | |
var define = _dereq_('amdefine')(module, _dereq_); | |
@@ -8385,17 +8737,17 @@ | |
exports.search = function search(aNeedle, aHaystack, aCompare) { | |
return aHaystack.length > 0 | |
? recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare) | |
: null; | |
}; | |
}); | |
-},{"amdefine":18}],14:[function(_dereq_,module,exports){ | |
+},{"amdefine":19}],15:[function(_dereq_,module,exports){ | |
/* -*- Mode: js; js-indent-level: 2; -*- */ | |
/* | |
* Copyright 2011 Mozilla Foundation and contributors | |
* Licensed under the New BSD license. See LICENSE or: | |
* http://opensource.org/licenses/BSD-3-Clause | |
*/ | |
if (typeof define !== 'function') { | |
var define = _dereq_('amdefine')(module, _dereq_); | |
@@ -8864,17 +9216,17 @@ | |
}; | |
}).forEach(aCallback, context); | |
}; | |
exports.SourceMapConsumer = SourceMapConsumer; | |
}); | |
-},{"./array-set":10,"./base64-vlq":11,"./binary-search":13,"./util":17,"amdefine":18}],15:[function(_dereq_,module,exports){ | |
+},{"./array-set":11,"./base64-vlq":12,"./binary-search":14,"./util":18,"amdefine":19}],16:[function(_dereq_,module,exports){ | |
/* -*- Mode: js; js-indent-level: 2; -*- */ | |
/* | |
* Copyright 2011 Mozilla Foundation and contributors | |
* Licensed under the New BSD license. See LICENSE or: | |
* http://opensource.org/licenses/BSD-3-Clause | |
*/ | |
if (typeof define !== 'function') { | |
var define = _dereq_('amdefine')(module, _dereq_); | |
@@ -9246,17 +9598,17 @@ | |
function SourceMapGenerator_toString() { | |
return JSON.stringify(this); | |
}; | |
exports.SourceMapGenerator = SourceMapGenerator; | |
}); | |
-},{"./array-set":10,"./base64-vlq":11,"./util":17,"amdefine":18}],16:[function(_dereq_,module,exports){ | |
+},{"./array-set":11,"./base64-vlq":12,"./util":18,"amdefine":19}],17:[function(_dereq_,module,exports){ | |
/* -*- Mode: js; js-indent-level: 2; -*- */ | |
/* | |
* Copyright 2011 Mozilla Foundation and contributors | |
* Licensed under the New BSD license. See LICENSE or: | |
* http://opensource.org/licenses/BSD-3-Clause | |
*/ | |
if (typeof define !== 'function') { | |
var define = _dereq_('amdefine')(module, _dereq_); | |
@@ -9619,17 +9971,17 @@ | |
return { code: generated.code, map: map }; | |
}; | |
exports.SourceNode = SourceNode; | |
}); | |
-},{"./source-map-generator":15,"./util":17,"amdefine":18}],17:[function(_dereq_,module,exports){ | |
+},{"./source-map-generator":16,"./util":18,"amdefine":19}],18:[function(_dereq_,module,exports){ | |
/* -*- Mode: js; js-indent-level: 2; -*- */ | |
/* | |
* Copyright 2011 Mozilla Foundation and contributors | |
* Licensed under the New BSD license. See LICENSE or: | |
* http://opensource.org/licenses/BSD-3-Clause | |
*/ | |
if (typeof define !== 'function') { | |
var define = _dereq_('amdefine')(module, _dereq_); | |
@@ -9826,17 +10178,17 @@ | |
} | |
return strcmp(mappingA.name, mappingB.name); | |
}; | |
exports.compareByGeneratedPositions = compareByGeneratedPositions; | |
}); | |
-},{"amdefine":18}],18:[function(_dereq_,module,exports){ | |
+},{"amdefine":19}],19:[function(_dereq_,module,exports){ | |
(function (process,__filename){ | |
/** vim: et:ts=4:sw=4:sts=4 | |
* @license amdefine 0.1.0 Copyright (c) 2011, The Dojo Foundation All Rights Reserved. | |
* Available via the MIT or new BSD license. | |
* see: http://github.com/jrburke/amdefine for details | |
*/ | |
/*jslint node: true */ | |
@@ -10128,18 +10480,18 @@ | |
define.amd = {}; | |
return define; | |
} | |
module.exports = amdefine; | |
-}).call(this,_dereq_("FWaASH"),"/../node_modules/jstransform/node_modules/source-map/node_modules/amdefine/amdefine.js") | |
-},{"FWaASH":6,"path":5}],19:[function(_dereq_,module,exports){ | |
+}).call(this,_dereq_('_process'),"/node_modules/jstransform/node_modules/source-map/node_modules/amdefine/amdefine.js") | |
+},{"_process":7,"path":6}],20:[function(_dereq_,module,exports){ | |
/** | |
* Copyright 2013 Facebook, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
@@ -10217,17 +10569,17 @@ | |
return result; | |
} | |
exports.extract = extract; | |
exports.parse = parse; | |
exports.parseAsObject = parseAsObject; | |
-},{}],20:[function(_dereq_,module,exports){ | |
+},{}],21:[function(_dereq_,module,exports){ | |
/** | |
* Copyright 2013 Facebook, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
@@ -10473,17 +10825,17 @@ | |
ret.sourceMapFilename = options.filename || 'source.js'; | |
} | |
return ret; | |
} | |
exports.transform = transform; | |
exports.Syntax = Syntax; | |
-},{"./utils":21,"esprima-fb":7,"source-map":9}],21:[function(_dereq_,module,exports){ | |
+},{"./utils":22,"esprima-fb":8,"source-map":10}],22:[function(_dereq_,module,exports){ | |
/** | |
* Copyright 2013 Facebook, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
@@ -11080,17 +11432,17 @@ | |
exports.move = move; | |
exports.scopeTypes = scopeTypes; | |
exports.updateIndent = updateIndent; | |
exports.updateState = updateState; | |
exports.analyzeAndTraverse = analyzeAndTraverse; | |
exports.getOrderedChildren = getOrderedChildren; | |
exports.getNodeSourceText = getNodeSourceText; | |
-},{"./docblock":19,"esprima-fb":7}],22:[function(_dereq_,module,exports){ | |
+},{"./docblock":20,"esprima-fb":8}],23:[function(_dereq_,module,exports){ | |
/** | |
* Copyright 2013 Facebook, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
@@ -11233,17 +11585,17 @@ | |
return node.type === Syntax.ArrowFunctionExpression; | |
}; | |
exports.visitorList = [ | |
visitArrowFunction | |
]; | |
-},{"../src/utils":21,"./es6-destructuring-visitors":24,"./es6-rest-param-visitors":27,"esprima-fb":7}],23:[function(_dereq_,module,exports){ | |
+},{"../src/utils":22,"./es6-destructuring-visitors":25,"./es6-rest-param-visitors":28,"esprima-fb":8}],24:[function(_dereq_,module,exports){ | |
/** | |
* Copyright 2013 Facebook, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
@@ -11418,17 +11770,17 @@ | |
state = utils.updateState(state, { | |
methodFuncNode: node | |
}); | |
if (methodNode.key.name === 'constructor') { | |
utils.append('function ' + state.className, state); | |
} else { | |
var methodAccessor; | |
- var prototypeOrStatic = methodNode["static"] ? '' : '.prototype'; | |
+ var prototypeOrStatic = methodNode.static ? '' : '.prototype'; | |
var objectAccessor = state.className + prototypeOrStatic; | |
if (methodNode.key.type === Syntax.Identifier) { | |
// foo() {} | |
methodAccessor = methodNode.key.name; | |
if (_shouldMungeIdentifier(methodNode.key, state)) { | |
methodAccessor = _getMungedName(methodAccessor, state); | |
} | |
@@ -11601,889 +11953,506 @@ | |
utils.append('function ' + className + '(){', state); | |
if (!state.scopeIsStrict) { | |
utils.append('"use strict";', state); | |
} | |
if (superClass.name) { | |
utils.append( | |
'if(' + superClass.name + '!==null){' + | |
superClass.name + '.apply(this,arguments);}', | |
- state | |
- ); | |
- } | |
- utils.append('}', state); | |
- } | |
- | |
- utils.move(node.body.range[0] + '{'.length, state); | |
- traverse(node.body, path, state); | |
- utils.catchupWhiteSpace(node.range[1], state); | |
-} | |
- | |
-/** | |
- * @param {function} traverse | |
- * @param {object} node | |
- * @param {array} path | |
- * @param {object} state | |
- */ | |
-function visitClassDeclaration(traverse, node, path, state) { | |
- var className = node.id.name; | |
- var superClass = _getSuperClassInfo(node, state); | |
- | |
- state = utils.updateState(state, { | |
- mungeNamespace: className, | |
- className: className, | |
- superClass: superClass | |
- }); | |
- | |
- _renderClassBody(traverse, node, path, state); | |
- | |
- return false; | |
-} | |
-visitClassDeclaration.test = function(node, path, state) { | |
- return node.type === Syntax.ClassDeclaration; | |
-}; | |
- | |
-/** | |
- * @param {function} traverse | |
- * @param {object} node | |
- * @param {array} path | |
- * @param {object} state | |
- */ | |
-function visitClassExpression(traverse, node, path, state) { | |
- var className = node.id && node.id.name || _generateAnonymousClassName(state); | |
- var superClass = _getSuperClassInfo(node, state); | |
- | |
- utils.append('(function(){', state); | |
- | |
- state = utils.updateState(state, { | |
- mungeNamespace: className, | |
- className: className, | |
- superClass: superClass | |
- }); | |
- | |
- _renderClassBody(traverse, node, path, state); | |
- | |
- utils.append('return ' + className + ';})()', state); | |
- return false; | |
-} | |
-visitClassExpression.test = function(node, path, state) { | |
- return node.type === Syntax.ClassExpression; | |
-}; | |
- | |
-/** | |
- * @param {function} traverse | |
- * @param {object} node | |
- * @param {array} path | |
- * @param {object} state | |
- */ | |
-function visitPrivateIdentifier(traverse, node, path, state) { | |
- utils.append(_getMungedName(node.name, state), state); | |
- utils.move(node.range[1], state); | |
-} | |
-visitPrivateIdentifier.test = function(node, path, state) { | |
- if (node.type === Syntax.Identifier && _shouldMungeIdentifier(node, state)) { | |
- // Always munge non-computed properties of MemberExpressions | |
- // (a la preventing access of properties of unowned objects) | |
- if (path[0].type === Syntax.MemberExpression && path[0].object !== node | |
- && path[0].computed === false) { | |
- return true; | |
- } | |
- | |
- // Always munge identifiers that were declared within the method function | |
- // scope | |
- if (utils.identWithinLexicalScope(node.name, state, state.methodFuncNode)) { | |
- return true; | |
- } | |
- | |
- // Always munge private keys on object literals defined within a method's | |
- // scope. | |
- if (path[0].type === Syntax.Property | |
- && path[1].type === Syntax.ObjectExpression) { | |
- return true; | |
- } | |
- | |
- // Always munge function parameters | |
- if (path[0].type === Syntax.FunctionExpression | |
- || path[0].type === Syntax.FunctionDeclaration | |
- || path[0].type === Syntax.ArrowFunctionExpression) { | |
- for (var i = 0; i < path[0].params.length; i++) { | |
- if (path[0].params[i] === node) { | |
- return true; | |
- } | |
- } | |
- } | |
- } | |
- return false; | |
-}; | |
- | |
-/** | |
- * @param {function} traverse | |
- * @param {object} node | |
- * @param {array} path | |
- * @param {object} state | |
- */ | |
-function visitSuperCallExpression(traverse, node, path, state) { | |
- var superClassName = state.superClass.name; | |
- | |
- if (node.callee.type === Syntax.Identifier) { | |
- if (_isConstructorMethod(state.methodNode)) { | |
- utils.append(superClassName + '.call(', state); | |
- } else { | |
- var protoProp = SUPER_PROTO_IDENT_PREFIX + superClassName; | |
- if (state.methodNode.key.type === Syntax.Identifier) { | |
- protoProp += '.' + state.methodNode.key.name; | |
- } else if (state.methodNode.key.type === Syntax.Literal) { | |
- protoProp += '[' + JSON.stringify(state.methodNode.key.value) + ']'; | |
- } | |
- utils.append(protoProp + ".call(", state); | |
- } | |
- utils.move(node.callee.range[1], state); | |
- } else if (node.callee.type === Syntax.MemberExpression) { | |
- utils.append(SUPER_PROTO_IDENT_PREFIX + superClassName, state); | |
- utils.move(node.callee.object.range[1], state); | |
- | |
- if (node.callee.computed) { | |
- // ["a" + "b"] | |
- utils.catchup(node.callee.property.range[1] + ']'.length, state); | |
- } else { | |
- // .ab | |
- utils.append('.' + node.callee.property.name, state); | |
- } | |
- | |
- utils.append('.call(', state); | |
- utils.move(node.callee.range[1], state); | |
- } | |
- | |
- utils.append('this', state); | |
- if (node.arguments.length > 0) { | |
- utils.append(',', state); | |
- utils.catchupWhiteSpace(node.arguments[0].range[0], state); | |
- traverse(node.arguments, path, state); | |
- } | |
- | |
- utils.catchupWhiteSpace(node.range[1], state); | |
- utils.append(')', state); | |
- return false; | |
-} | |
-visitSuperCallExpression.test = function(node, path, state) { | |
- if (state.superClass && node.type === Syntax.CallExpression) { | |
- var callee = node.callee; | |
- if (callee.type === Syntax.Identifier && callee.name === 'super' | |
- || callee.type == Syntax.MemberExpression | |
- && callee.object.name === 'super') { | |
- return true; | |
- } | |
- } | |
- return false; | |
-}; | |
- | |
-/** | |
- * @param {function} traverse | |
- * @param {object} node | |
- * @param {array} path | |
- * @param {object} state | |
- */ | |
-function visitSuperMemberExpression(traverse, node, path, state) { | |
- var superClassName = state.superClass.name; | |
- | |
- utils.append(SUPER_PROTO_IDENT_PREFIX + superClassName, state); | |
- utils.move(node.object.range[1], state); | |
-} | |
-visitSuperMemberExpression.test = function(node, path, state) { | |
- return state.superClass | |
- && node.type === Syntax.MemberExpression | |
- && node.object.type === Syntax.Identifier | |
- && node.object.name === 'super'; | |
-}; | |
- | |
-exports.resetSymbols = resetSymbols; | |
- | |
-exports.visitorList = [ | |
- visitClassDeclaration, | |
- visitClassExpression, | |
- visitClassFunctionExpression, | |
- visitClassMethod, | |
- visitClassMethodParam, | |
- visitPrivateIdentifier, | |
- visitSuperCallExpression, | |
- visitSuperMemberExpression | |
-]; | |
- | |
-},{"../src/utils":21,"./reserved-words-helper":31,"base62":8,"esprima-fb":7}],24:[function(_dereq_,module,exports){ | |
-/** | |
- * Copyright 2014 Facebook, Inc. | |
- * | |
- * Licensed under the Apache License, Version 2.0 (the "License"); | |
- * you may not use this file except in compliance with the License. | |
- * You may obtain a copy of the License at | |
- * | |
- * http://www.apache.org/licenses/LICENSE-2.0 | |
- * | |
- * Unless required by applicable law or agreed to in writing, software | |
- * distributed under the License is distributed on an "AS IS" BASIS, | |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
- * See the License for the specific language governing permissions and | |
- * limitations under the License. | |
- */ | |
-/*global exports:true*/ | |
- | |
-/** | |
- * Implements ES6 destructuring assignment and pattern matchng. | |
- * | |
- * function init({port, ip, coords: [x, y]}) { | |
- * return (x && y) ? {id, port} : {ip}; | |
- * }; | |
- * | |
- * function init($__0) { | |
- * var | |
- * port = $__0.port, | |
- * ip = $__0.ip, | |
- * $__1 = $__0.coords, | |
- * x = $__1[0], | |
- * y = $__1[1]; | |
- * return (x && y) ? {id, port} : {ip}; | |
- * } | |
- * | |
- * var x, {ip, port} = init({ip, port}); | |
- * | |
- * var x, $__0 = init({ip, port}), ip = $__0.ip, port = $__0.port; | |
- * | |
- */ | |
-var Syntax = _dereq_('esprima-fb').Syntax; | |
-var utils = _dereq_('../src/utils'); | |
- | |
-var reservedWordsHelper = _dereq_('./reserved-words-helper'); | |
-var restParamVisitors = _dereq_('./es6-rest-param-visitors'); | |
-var restPropertyHelpers = _dereq_('./es7-rest-property-helpers'); | |
- | |
-// ------------------------------------------------------- | |
-// 1. Structured variable declarations. | |
-// | |
-// var [a, b] = [b, a]; | |
-// var {x, y} = {y, x}; | |
-// ------------------------------------------------------- | |
- | |
-function visitStructuredVariable(traverse, node, path, state) { | |
- // Allocate new temp for the pattern. | |
- utils.append(getTmpVar(state.localScope.tempVarIndex) + '=', state); | |
- // Skip the pattern and assign the init to the temp. | |
- utils.catchupWhiteSpace(node.init.range[0], state); | |
- traverse(node.init, path, state); | |
- utils.catchup(node.init.range[1], state); | |
- // Render the destructured data. | |
- utils.append(',' + getDestructuredComponents(node.id, state), state); | |
- state.localScope.tempVarIndex++; | |
- return false; | |
-} | |
- | |
-visitStructuredVariable.test = function(node, path, state) { | |
- return node.type === Syntax.VariableDeclarator && | |
- isStructuredPattern(node.id); | |
-}; | |
- | |
-function isStructuredPattern(node) { | |
- return node.type === Syntax.ObjectPattern || | |
- node.type === Syntax.ArrayPattern; | |
-} | |
- | |
-// Main function which does actual recursive destructuring | |
-// of nested complex structures. | |
-function getDestructuredComponents(node, state) { | |
- var tmpIndex = state.localScope.tempVarIndex; | |
- var components = []; | |
- var patternItems = getPatternItems(node); | |
- | |
- for (var idx = 0; idx < patternItems.length; idx++) { | |
- var item = patternItems[idx]; | |
- if (!item) { | |
- continue; | |
- } | |
- | |
- if (item.type === Syntax.SpreadElement) { | |
- // Spread/rest of an array. | |
- // TODO(dmitrys): support spread in the middle of a pattern | |
- // and also for function param patterns: [x, ...xs, y] | |
- components.push(item.argument.name + | |
- '=Array.prototype.slice.call(' + | |
- getTmpVar(tmpIndex) + ',' + idx + ')' | |
- ); | |
- continue; | |
- } | |
- | |
- if (item.type === Syntax.SpreadProperty) { | |
- var restExpression = restPropertyHelpers.renderRestExpression( | |
- getTmpVar(tmpIndex), | |
- patternItems | |
- ); | |
- components.push(item.argument.name + '=' + restExpression); | |
- continue; | |
- } | |
- | |
- // Depending on pattern type (Array or Object), we get | |
- // corresponding pattern item parts. | |
- var accessor = getPatternItemAccessor(node, item, tmpIndex, idx); | |
- var value = getPatternItemValue(node, item); | |
- | |
- // TODO(dmitrys): implement default values: {x, y=5} | |
- if (value.type === Syntax.Identifier) { | |
- // Simple pattern item. | |
- components.push(value.name + '=' + accessor); | |
- } else { | |
- // Complex sub-structure. | |
- components.push( | |
- getInitialValue(++state.localScope.tempVarIndex, accessor) + ',' + | |
- getDestructuredComponents(value, state) | |
- ); | |
- } | |
- } | |
- | |
- return components.join(','); | |
-} | |
- | |
-function getPatternItems(node) { | |
- return node.properties || node.elements; | |
-} | |
- | |
-function getPatternItemAccessor(node, patternItem, tmpIndex, idx) { | |
- var tmpName = getTmpVar(tmpIndex); | |
- if (node.type === Syntax.ObjectPattern) { | |
- if (reservedWordsHelper.isReservedWord(patternItem.key.name)) { | |
- return tmpName + '["' + patternItem.key.name + '"]'; | |
- } else { | |
- return tmpName + '.' + patternItem.key.name; | |
+ state | |
+ ); | |
} | |
- } else { | |
- return tmpName + '[' + idx + ']'; | |
+ utils.append('}', state); | |
} | |
-} | |
- | |
-function getPatternItemValue(node, patternItem) { | |
- return node.type === Syntax.ObjectPattern | |
- ? patternItem.value | |
- : patternItem; | |
-} | |
- | |
-function getInitialValue(index, value) { | |
- return getTmpVar(index) + '=' + value; | |
-} | |
-function getTmpVar(index) { | |
- return '$__' + index; | |
+ utils.move(node.body.range[0] + '{'.length, state); | |
+ traverse(node.body, path, state); | |
+ utils.catchupWhiteSpace(node.range[1], state); | |
} | |
-// ------------------------------------------------------- | |
-// 2. Assignment expression. | |
-// | |
-// [a, b] = [b, a]; | |
-// ({x, y} = {y, x}); | |
-// ------------------------------------------------------- | |
- | |
-function visitStructuredAssignment(traverse, node, path, state) { | |
- var exprNode = node.expression; | |
- utils.append('var ' + getTmpVar(state.localScope.tempVarIndex) + '=', state); | |
+/** | |
+ * @param {function} traverse | |
+ * @param {object} node | |
+ * @param {array} path | |
+ * @param {object} state | |
+ */ | |
+function visitClassDeclaration(traverse, node, path, state) { | |
+ var className = node.id.name; | |
+ var superClass = _getSuperClassInfo(node, state); | |
- utils.catchupWhiteSpace(exprNode.right.range[0], state); | |
- traverse(exprNode.right, path, state); | |
- utils.catchup(exprNode.right.range[1], state); | |
+ state = utils.updateState(state, { | |
+ mungeNamespace: className, | |
+ className: className, | |
+ superClass: superClass | |
+ }); | |
- utils.append( | |
- ',' + getDestructuredComponents(exprNode.left, state) + ';', | |
- state | |
- ); | |
+ _renderClassBody(traverse, node, path, state); | |
- utils.catchupWhiteSpace(node.range[1], state); | |
- state.localScope.tempVarIndex++; | |
return false; | |
} | |
- | |
-visitStructuredAssignment.test = function(node, path, state) { | |
- // We consider the expression statement rather than just assignment | |
- // expression to cover case with object patters which should be | |
- // wrapped in grouping operator: ({x, y} = {y, x}); | |
- return node.type === Syntax.ExpressionStatement && | |
- node.expression.type === Syntax.AssignmentExpression && | |
- isStructuredPattern(node.expression.left); | |
+visitClassDeclaration.test = function(node, path, state) { | |
+ return node.type === Syntax.ClassDeclaration; | |
}; | |
-// ------------------------------------------------------- | |
-// 3. Structured parameter. | |
-// | |
-// function foo({x, y}) { ... } | |
-// ------------------------------------------------------- | |
+/** | |
+ * @param {function} traverse | |
+ * @param {object} node | |
+ * @param {array} path | |
+ * @param {object} state | |
+ */ | |
+function visitClassExpression(traverse, node, path, state) { | |
+ var className = node.id && node.id.name || _generateAnonymousClassName(state); | |
+ var superClass = _getSuperClassInfo(node, state); | |
-function visitStructuredParameter(traverse, node, path, state) { | |
- utils.append(getTmpVar(getParamIndex(node, path)), state); | |
- utils.catchupWhiteSpace(node.range[1], state); | |
- return true; | |
-} | |
+ utils.append('(function(){', state); | |
-function getParamIndex(paramNode, path) { | |
- var funcNode = path[0]; | |
- var tmpIndex = 0; | |
- for (var k = 0; k < funcNode.params.length; k++) { | |
- var param = funcNode.params[k]; | |
- if (param === paramNode) { | |
- break; | |
- } | |
- if (isStructuredPattern(param)) { | |
- tmpIndex++; | |
- } | |
- } | |
- return tmpIndex; | |
-} | |
+ state = utils.updateState(state, { | |
+ mungeNamespace: className, | |
+ className: className, | |
+ superClass: superClass | |
+ }); | |
-visitStructuredParameter.test = function(node, path, state) { | |
- return isStructuredPattern(node) && isFunctionNode(path[0]); | |
-}; | |
+ _renderClassBody(traverse, node, path, state); | |
-function isFunctionNode(node) { | |
- return (node.type == Syntax.FunctionDeclaration || | |
- node.type == Syntax.FunctionExpression || | |
- node.type == Syntax.MethodDefinition || | |
- node.type == Syntax.ArrowFunctionExpression); | |
+ utils.append('return ' + className + ';})()', state); | |
+ return false; | |
} | |
+visitClassExpression.test = function(node, path, state) { | |
+ return node.type === Syntax.ClassExpression; | |
+}; | |
-// ------------------------------------------------------- | |
-// 4. Function body for structured parameters. | |
-// | |
-// function foo({x, y}) { x; y; } | |
-// ------------------------------------------------------- | |
- | |
-function visitFunctionBodyForStructuredParameter(traverse, node, path, state) { | |
- var funcNode = path[0]; | |
- | |
- utils.catchup(funcNode.body.range[0] + 1, state); | |
- renderDestructuredComponents(funcNode, state); | |
- | |
- if (funcNode.rest) { | |
- utils.append( | |
- restParamVisitors.renderRestParamSetup(funcNode), | |
- state | |
- ); | |
- } | |
- | |
- return true; | |
+/** | |
+ * @param {function} traverse | |
+ * @param {object} node | |
+ * @param {array} path | |
+ * @param {object} state | |
+ */ | |
+function visitPrivateIdentifier(traverse, node, path, state) { | |
+ utils.append(_getMungedName(node.name, state), state); | |
+ utils.move(node.range[1], state); | |
} | |
+visitPrivateIdentifier.test = function(node, path, state) { | |
+ if (node.type === Syntax.Identifier && _shouldMungeIdentifier(node, state)) { | |
+ // Always munge non-computed properties of MemberExpressions | |
+ // (a la preventing access of properties of unowned objects) | |
+ if (path[0].type === Syntax.MemberExpression && path[0].object !== node | |
+ && path[0].computed === false) { | |
+ return true; | |
+ } | |
-function renderDestructuredComponents(funcNode, state) { | |
- var destructuredComponents = []; | |
+ // Always munge identifiers that were declared within the method function | |
+ // scope | |
+ if (utils.identWithinLexicalScope(node.name, state, state.methodFuncNode)) { | |
+ return true; | |
+ } | |
- for (var k = 0; k < funcNode.params.length; k++) { | |
- var param = funcNode.params[k]; | |
- if (isStructuredPattern(param)) { | |
- destructuredComponents.push( | |
- getDestructuredComponents(param, state) | |
- ); | |
- state.localScope.tempVarIndex++; | |
+ // Always munge private keys on object literals defined within a method's | |
+ // scope. | |
+ if (path[0].type === Syntax.Property | |
+ && path[1].type === Syntax.ObjectExpression) { | |
+ return true; | |
} | |
- } | |
- if (destructuredComponents.length) { | |
- utils.append('var ' + destructuredComponents.join(',') + ';', state); | |
+ // Always munge function parameters | |
+ if (path[0].type === Syntax.FunctionExpression | |
+ || path[0].type === Syntax.FunctionDeclaration | |
+ || path[0].type === Syntax.ArrowFunctionExpression) { | |
+ for (var i = 0; i < path[0].params.length; i++) { | |
+ if (path[0].params[i] === node) { | |
+ return true; | |
+ } | |
+ } | |
+ } | |
} | |
-} | |
- | |
-visitFunctionBodyForStructuredParameter.test = function(node, path, state) { | |
- return node.type === Syntax.BlockStatement && isFunctionNode(path[0]); | |
+ return false; | |
}; | |
-exports.visitorList = [ | |
- visitStructuredVariable, | |
- visitStructuredAssignment, | |
- visitStructuredParameter, | |
- visitFunctionBodyForStructuredParameter | |
-]; | |
- | |
-exports.renderDestructuredComponents = renderDestructuredComponents; | |
- | |
- | |
-},{"../src/utils":21,"./es6-rest-param-visitors":27,"./es7-rest-property-helpers":29,"./reserved-words-helper":31,"esprima-fb":7}],25:[function(_dereq_,module,exports){ | |
/** | |
- * Copyright 2013 Facebook, Inc. | |
- * | |
- * Licensed under the Apache License, Version 2.0 (the "License"); | |
- * you may not use this file except in compliance with the License. | |
- * You may obtain a copy of the License at | |
- * | |
- * http://www.apache.org/licenses/LICENSE-2.0 | |
- * | |
- * Unless required by applicable law or agreed to in writing, software | |
- * distributed under the License is distributed on an "AS IS" BASIS, | |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
- * See the License for the specific language governing permissions and | |
- * limitations under the License. | |
+ * @param {function} traverse | |
+ * @param {object} node | |
+ * @param {array} path | |
+ * @param {object} state | |
*/ | |
+function visitSuperCallExpression(traverse, node, path, state) { | |
+ var superClassName = state.superClass.name; | |
-/*jslint node:true*/ | |
- | |
-/** | |
- * Desugars concise methods of objects to function expressions. | |
- * | |
- * var foo = { | |
- * method(x, y) { ... } | |
- * }; | |
- * | |
- * var foo = { | |
- * method: function(x, y) { ... } | |
- * }; | |
- * | |
- */ | |
+ if (node.callee.type === Syntax.Identifier) { | |
+ if (_isConstructorMethod(state.methodNode)) { | |
+ utils.append(superClassName + '.call(', state); | |
+ } else { | |
+ var protoProp = SUPER_PROTO_IDENT_PREFIX + superClassName; | |
+ if (state.methodNode.key.type === Syntax.Identifier) { | |
+ protoProp += '.' + state.methodNode.key.name; | |
+ } else if (state.methodNode.key.type === Syntax.Literal) { | |
+ protoProp += '[' + JSON.stringify(state.methodNode.key.value) + ']'; | |
+ } | |
+ utils.append(protoProp + ".call(", state); | |
+ } | |
+ utils.move(node.callee.range[1], state); | |
+ } else if (node.callee.type === Syntax.MemberExpression) { | |
+ utils.append(SUPER_PROTO_IDENT_PREFIX + superClassName, state); | |
+ utils.move(node.callee.object.range[1], state); | |
-var Syntax = _dereq_('esprima-fb').Syntax; | |
-var utils = _dereq_('../src/utils'); | |
-var reservedWordsHelper = _dereq_('./reserved-words-helper'); | |
+ if (node.callee.computed) { | |
+ // ["a" + "b"] | |
+ utils.catchup(node.callee.property.range[1] + ']'.length, state); | |
+ } else { | |
+ // .ab | |
+ utils.append('.' + node.callee.property.name, state); | |
+ } | |
-function visitObjectConciseMethod(traverse, node, path, state) { | |
- var isGenerator = node.value.generator; | |
- if (isGenerator) { | |
- utils.catchupWhiteSpace(node.range[0] + 1, state); | |
+ utils.append('.call(', state); | |
+ utils.move(node.callee.range[1], state); | |
} | |
- if (node.computed) { // [<expr>]() { ...} | |
- utils.catchup(node.key.range[1] + 1, state); | |
- } else if (reservedWordsHelper.isReservedWord(node.key.name)) { | |
- utils.catchup(node.key.range[0], state); | |
- utils.append('"', state); | |
- utils.catchup(node.key.range[1], state); | |
- utils.append('"', state); | |
+ | |
+ utils.append('this', state); | |
+ if (node.arguments.length > 0) { | |
+ utils.append(',', state); | |
+ utils.catchupWhiteSpace(node.arguments[0].range[0], state); | |
+ traverse(node.arguments, path, state); | |
} | |
- utils.catchup(node.key.range[1], state); | |
- utils.append( | |
- ':function' + (isGenerator ? '*' : ''), | |
- state | |
- ); | |
- path.unshift(node); | |
- traverse(node.value, path, state); | |
- path.shift(); | |
+ utils.catchupWhiteSpace(node.range[1], state); | |
+ utils.append(')', state); | |
return false; | |
} | |
- | |
-visitObjectConciseMethod.test = function(node, path, state) { | |
- return node.type === Syntax.Property && | |
- node.value.type === Syntax.FunctionExpression && | |
- node.method === true; | |
+visitSuperCallExpression.test = function(node, path, state) { | |
+ if (state.superClass && node.type === Syntax.CallExpression) { | |
+ var callee = node.callee; | |
+ if (callee.type === Syntax.Identifier && callee.name === 'super' | |
+ || callee.type == Syntax.MemberExpression | |
+ && callee.object.name === 'super') { | |
+ return true; | |
+ } | |
+ } | |
+ return false; | |
}; | |
-exports.visitorList = [ | |
- visitObjectConciseMethod | |
-]; | |
- | |
-},{"../src/utils":21,"./reserved-words-helper":31,"esprima-fb":7}],26:[function(_dereq_,module,exports){ | |
-/** | |
- * Copyright 2013 Facebook, Inc. | |
- * | |
- * Licensed under the Apache License, Version 2.0 (the "License"); | |
- * you may not use this file except in compliance with the License. | |
- * You may obtain a copy of the License at | |
- * | |
- * http://www.apache.org/licenses/LICENSE-2.0 | |
- * | |
- * Unless required by applicable law or agreed to in writing, software | |
- * distributed under the License is distributed on an "AS IS" BASIS, | |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
- * See the License for the specific language governing permissions and | |
- * limitations under the License. | |
- */ | |
- | |
-/*jslint node: true*/ | |
- | |
/** | |
- * Desugars ES6 Object Literal short notations into ES3 full notation. | |
- * | |
- * // Easier return values. | |
- * function foo(x, y) { | |
- * return {x, y}; // {x: x, y: y} | |
- * }; | |
- * | |
- * // Destrucruting. | |
- * function init({port, ip, coords: {x, y}}) { ... } | |
- * | |
+ * @param {function} traverse | |
+ * @param {object} node | |
+ * @param {array} path | |
+ * @param {object} state | |
*/ | |
-var Syntax = _dereq_('esprima-fb').Syntax; | |
-var utils = _dereq_('../src/utils'); | |
+function visitSuperMemberExpression(traverse, node, path, state) { | |
+ var superClassName = state.superClass.name; | |
-/** | |
- * @public | |
- */ | |
-function visitObjectLiteralShortNotation(traverse, node, path, state) { | |
- utils.catchup(node.key.range[1], state); | |
- utils.append(':' + node.key.name, state); | |
- return false; | |
+ utils.append(SUPER_PROTO_IDENT_PREFIX + superClassName, state); | |
+ utils.move(node.object.range[1], state); | |
} | |
- | |
-visitObjectLiteralShortNotation.test = function(node, path, state) { | |
- return node.type === Syntax.Property && | |
- node.kind === 'init' && | |
- node.shorthand === true && | |
- path[0].type !== Syntax.ObjectPattern; | |
+visitSuperMemberExpression.test = function(node, path, state) { | |
+ return state.superClass | |
+ && node.type === Syntax.MemberExpression | |
+ && node.object.type === Syntax.Identifier | |
+ && node.object.name === 'super'; | |
}; | |
+exports.resetSymbols = resetSymbols; | |
+ | |
exports.visitorList = [ | |
- visitObjectLiteralShortNotation | |
+ visitClassDeclaration, | |
+ visitClassExpression, | |
+ visitClassFunctionExpression, | |
+ visitClassMethod, | |
+ visitClassMethodParam, | |
+ visitPrivateIdentifier, | |
+ visitSuperCallExpression, | |
+ visitSuperMemberExpression | |
]; | |
- | |
-},{"../src/utils":21,"esprima-fb":7}],27:[function(_dereq_,module,exports){ | |
+},{"../src/utils":22,"./reserved-words-helper":32,"base62":9,"esprima-fb":8}],25:[function(_dereq_,module,exports){ | |
/** | |
- * Copyright 2013 Facebook, Inc. | |
+ * Copyright 2014 Facebook, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
- | |
-/*jslint node:true*/ | |
+/*global exports:true*/ | |
/** | |
- * Desugars ES6 rest parameters into ES3 arguments slicing. | |
+ * Implements ES6 destructuring assignment and pattern matchng. | |
* | |
- * function printf(template, ...args) { | |
- * args.forEach(...); | |
+ * function init({port, ip, coords: [x, y]}) { | |
+ * return (x && y) ? {id, port} : {ip}; | |
* }; | |
* | |
- * function printf(template) { | |
- * var args = [].slice.call(arguments, 1); | |
- * args.forEach(...); | |
- * }; | |
+ * function init($__0) { | |
+ * var | |
+ * port = $__0.port, | |
+ * ip = $__0.ip, | |
+ * $__1 = $__0.coords, | |
+ * x = $__1[0], | |
+ * y = $__1[1]; | |
+ * return (x && y) ? {id, port} : {ip}; | |
+ * } | |
+ * | |
+ * var x, {ip, port} = init({ip, port}); | |
+ * | |
+ * var x, $__0 = init({ip, port}), ip = $__0.ip, port = $__0.port; | |
* | |
*/ | |
var Syntax = _dereq_('esprima-fb').Syntax; | |
var utils = _dereq_('../src/utils'); | |
+var reservedWordsHelper = _dereq_('./reserved-words-helper'); | |
+var restParamVisitors = _dereq_('./es6-rest-param-visitors'); | |
+var restPropertyHelpers = _dereq_('./es7-rest-property-helpers'); | |
+// ------------------------------------------------------- | |
+// 1. Structured variable declarations. | |
+// | |
+// var [a, b] = [b, a]; | |
+// var {x, y} = {y, x}; | |
+// ------------------------------------------------------- | |
-function _nodeIsFunctionWithRestParam(node) { | |
- return (node.type === Syntax.FunctionDeclaration | |
- || node.type === Syntax.FunctionExpression | |
- || node.type === Syntax.ArrowFunctionExpression) | |
- && node.rest; | |
+function visitStructuredVariable(traverse, node, path, state) { | |
+ // Allocate new temp for the pattern. | |
+ utils.append(getTmpVar(state.localScope.tempVarIndex) + '=', state); | |
+ // Skip the pattern and assign the init to the temp. | |
+ utils.catchupWhiteSpace(node.init.range[0], state); | |
+ traverse(node.init, path, state); | |
+ utils.catchup(node.init.range[1], state); | |
+ // Render the destructured data. | |
+ utils.append(',' + getDestructuredComponents(node.id, state), state); | |
+ state.localScope.tempVarIndex++; | |
+ return false; | |
} | |
-function visitFunctionParamsWithRestParam(traverse, node, path, state) { | |
- if (node.parametricType) { | |
- utils.catchup(node.parametricType.range[0], state); | |
- path.unshift(node); | |
- traverse(node.parametricType, path, state); | |
- path.shift(); | |
- } | |
+visitStructuredVariable.test = function(node, path, state) { | |
+ return node.type === Syntax.VariableDeclarator && | |
+ isStructuredPattern(node.id); | |
+}; | |
- // Render params. | |
- if (node.params.length) { | |
- path.unshift(node); | |
- traverse(node.params, path, state); | |
- path.shift(); | |
- } else { | |
- // -3 is for ... of the rest. | |
- utils.catchup(node.rest.range[0] - 3, state); | |
- } | |
- utils.catchupWhiteSpace(node.rest.range[1], state); | |
+function isStructuredPattern(node) { | |
+ return node.type === Syntax.ObjectPattern || | |
+ node.type === Syntax.ArrayPattern; | |
+} | |
- path.unshift(node); | |
- traverse(node.body, path, state); | |
- path.shift(); | |
+// Main function which does actual recursive destructuring | |
+// of nested complex structures. | |
+function getDestructuredComponents(node, state) { | |
+ var tmpIndex = state.localScope.tempVarIndex; | |
+ var components = []; | |
+ var patternItems = getPatternItems(node); | |
- return false; | |
-} | |
+ for (var idx = 0; idx < patternItems.length; idx++) { | |
+ var item = patternItems[idx]; | |
+ if (!item) { | |
+ continue; | |
+ } | |
-visitFunctionParamsWithRestParam.test = function(node, path, state) { | |
- return _nodeIsFunctionWithRestParam(node); | |
-}; | |
+ if (item.type === Syntax.SpreadElement) { | |
+ // Spread/rest of an array. | |
+ // TODO(dmitrys): support spread in the middle of a pattern | |
+ // and also for function param patterns: [x, ...xs, y] | |
+ components.push(item.argument.name + | |
+ '=Array.prototype.slice.call(' + | |
+ getTmpVar(tmpIndex) + ',' + idx + ')' | |
+ ); | |
+ continue; | |
+ } | |
-function renderRestParamSetup(functionNode) { | |
- return 'var ' + functionNode.rest.name + '=Array.prototype.slice.call(' + | |
- 'arguments,' + | |
- functionNode.params.length + | |
- ');'; | |
+ if (item.type === Syntax.SpreadProperty) { | |
+ var restExpression = restPropertyHelpers.renderRestExpression( | |
+ getTmpVar(tmpIndex), | |
+ patternItems | |
+ ); | |
+ components.push(item.argument.name + '=' + restExpression); | |
+ continue; | |
+ } | |
+ | |
+ // Depending on pattern type (Array or Object), we get | |
+ // corresponding pattern item parts. | |
+ var accessor = getPatternItemAccessor(node, item, tmpIndex, idx); | |
+ var value = getPatternItemValue(node, item); | |
+ | |
+ // TODO(dmitrys): implement default values: {x, y=5} | |
+ if (value.type === Syntax.Identifier) { | |
+ // Simple pattern item. | |
+ components.push(value.name + '=' + accessor); | |
+ } else { | |
+ // Complex sub-structure. | |
+ components.push( | |
+ getInitialValue(++state.localScope.tempVarIndex, accessor) + ',' + | |
+ getDestructuredComponents(value, state) | |
+ ); | |
+ } | |
+ } | |
+ | |
+ return components.join(','); | |
} | |
-function visitFunctionBodyWithRestParam(traverse, node, path, state) { | |
- utils.catchup(node.range[0] + 1, state); | |
- var parentNode = path[0]; | |
- utils.append(renderRestParamSetup(parentNode), state); | |
- return true; | |
+function getPatternItems(node) { | |
+ return node.properties || node.elements; | |
} | |
-visitFunctionBodyWithRestParam.test = function(node, path, state) { | |
- return node.type === Syntax.BlockStatement | |
- && _nodeIsFunctionWithRestParam(path[0]); | |
-}; | |
+function getPatternItemAccessor(node, patternItem, tmpIndex, idx) { | |
+ var tmpName = getTmpVar(tmpIndex); | |
+ if (node.type === Syntax.ObjectPattern) { | |
+ if (reservedWordsHelper.isReservedWord(patternItem.key.name)) { | |
+ return tmpName + '["' + patternItem.key.name + '"]'; | |
+ } else { | |
+ return tmpName + '.' + patternItem.key.name; | |
+ } | |
+ } else { | |
+ return tmpName + '[' + idx + ']'; | |
+ } | |
+} | |
-exports.renderRestParamSetup = renderRestParamSetup; | |
-exports.visitorList = [ | |
- visitFunctionParamsWithRestParam, | |
- visitFunctionBodyWithRestParam | |
-]; | |
+function getPatternItemValue(node, patternItem) { | |
+ return node.type === Syntax.ObjectPattern | |
+ ? patternItem.value | |
+ : patternItem; | |
+} | |
-},{"../src/utils":21,"esprima-fb":7}],28:[function(_dereq_,module,exports){ | |
-/** | |
- * Copyright 2013 Facebook, Inc. | |
- * | |
- * Licensed under the Apache License, Version 2.0 (the "License"); | |
- * you may not use this file except in compliance with the License. | |
- * You may obtain a copy of the License at | |
- * | |
- * http://www.apache.org/licenses/LICENSE-2.0 | |
- * | |
- * Unless required by applicable law or agreed to in writing, software | |
- * distributed under the License is distributed on an "AS IS" BASIS, | |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
- * See the License for the specific language governing permissions and | |
- * limitations under the License. | |
- */ | |
+function getInitialValue(index, value) { | |
+ return getTmpVar(index) + '=' + value; | |
+} | |
-/*jslint node:true*/ | |
+function getTmpVar(index) { | |
+ return '$__' + index; | |
+} | |
-/** | |
- * @typechecks | |
- */ | |
-'use strict'; | |
+// ------------------------------------------------------- | |
+// 2. Assignment expression. | |
+// | |
+// [a, b] = [b, a]; | |
+// ({x, y} = {y, x}); | |
+// ------------------------------------------------------- | |
-var Syntax = _dereq_('esprima-fb').Syntax; | |
-var utils = _dereq_('../src/utils'); | |
+function visitStructuredAssignment(traverse, node, path, state) { | |
+ var exprNode = node.expression; | |
+ utils.append('var ' + getTmpVar(state.localScope.tempVarIndex) + '=', state); | |
-/** | |
- * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-12.1.9 | |
- */ | |
-function visitTemplateLiteral(traverse, node, path, state) { | |
- var templateElements = node.quasis; | |
+ utils.catchupWhiteSpace(exprNode.right.range[0], state); | |
+ traverse(exprNode.right, path, state); | |
+ utils.catchup(exprNode.right.range[1], state); | |
- utils.append('(', state); | |
- for (var ii = 0; ii < templateElements.length; ii++) { | |
- var templateElement = templateElements[ii]; | |
- if (templateElement.value.raw !== '') { | |
- utils.append(getCookedValue(templateElement), state); | |
- if (!templateElement.tail) { | |
- // + between element and substitution | |
- utils.append(' + ', state); | |
- } | |
- // maintain line numbers | |
- utils.move(templateElement.range[0], state); | |
- utils.catchupNewlines(templateElement.range[1], state); | |
- } else { // templateElement.value.raw === '' | |
- // Concatenat adjacent substitutions, e.g. `${x}${y}`. Empty templates | |
- // appear before the first and after the last element - nothing to add in | |
- // those cases. | |
- if (ii > 0 && !templateElement.tail) { | |
- // + between substitution and substitution | |
- utils.append(' + ', state); | |
- } | |
- } | |
+ utils.append( | |
+ ',' + getDestructuredComponents(exprNode.left, state) + ';', | |
+ state | |
+ ); | |
- utils.move(templateElement.range[1], state); | |
- if (!templateElement.tail) { | |
- var substitution = node.expressions[ii]; | |
- if (substitution.type === Syntax.Identifier || | |
- substitution.type === Syntax.MemberExpression || | |
- substitution.type === Syntax.CallExpression) { | |
- utils.catchup(substitution.range[1], state); | |
- } else { | |
- utils.append('(', state); | |
- traverse(substitution, path, state); | |
- utils.catchup(substitution.range[1], state); | |
- utils.append(')', state); | |
- } | |
- // if next templateElement isn't empty... | |
- if (templateElements[ii + 1].value.cooked !== '') { | |
- utils.append(' + ', state); | |
- } | |
- } | |
- } | |
- utils.move(node.range[1], state); | |
- utils.append(')', state); | |
+ utils.catchupWhiteSpace(node.range[1], state); | |
+ state.localScope.tempVarIndex++; | |
return false; | |
} | |
-visitTemplateLiteral.test = function(node, path, state) { | |
- return node.type === Syntax.TemplateLiteral; | |
+visitStructuredAssignment.test = function(node, path, state) { | |
+ // We consider the expression statement rather than just assignment | |
+ // expression to cover case with object patters which should be | |
+ // wrapped in grouping operator: ({x, y} = {y, x}); | |
+ return node.type === Syntax.ExpressionStatement && | |
+ node.expression.type === Syntax.AssignmentExpression && | |
+ isStructuredPattern(node.expression.left); | |
}; | |
-/** | |
- * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-12.2.6 | |
- */ | |
-function visitTaggedTemplateExpression(traverse, node, path, state) { | |
- var template = node.quasi; | |
- var numQuasis = template.quasis.length; | |
+// ------------------------------------------------------- | |
+// 3. Structured parameter. | |
+// | |
+// function foo({x, y}) { ... } | |
+// ------------------------------------------------------- | |
- // print the tag | |
- utils.move(node.tag.range[0], state); | |
- traverse(node.tag, path, state); | |
- utils.catchup(node.tag.range[1], state); | |
+function visitStructuredParameter(traverse, node, path, state) { | |
+ utils.append(getTmpVar(getParamIndex(node, path)), state); | |
+ utils.catchupWhiteSpace(node.range[1], state); | |
+ return true; | |
+} | |
- // print array of template elements | |
- utils.append('(function() { var siteObj = [', state); | |
- for (var ii = 0; ii < numQuasis; ii++) { | |
- utils.append(getCookedValue(template.quasis[ii]), state); | |
- if (ii !== numQuasis - 1) { | |
- utils.append(', ', state); | |
+function getParamIndex(paramNode, path) { | |
+ var funcNode = path[0]; | |
+ var tmpIndex = 0; | |
+ for (var k = 0; k < funcNode.params.length; k++) { | |
+ var param = funcNode.params[k]; | |
+ if (param === paramNode) { | |
+ break; | |
} | |
- } | |
- utils.append(']; siteObj.raw = [', state); | |
- for (ii = 0; ii < numQuasis; ii++) { | |
- utils.append(getRawValue(template.quasis[ii]), state); | |
- if (ii !== numQuasis - 1) { | |
- utils.append(', ', state); | |
+ if (isStructuredPattern(param)) { | |
+ tmpIndex++; | |
} | |
} | |
- utils.append( | |
- ']; Object.freeze(siteObj.raw); Object.freeze(siteObj); return siteObj; }()', | |
- state | |
- ); | |
+ return tmpIndex; | |
+} | |
- // print substitutions | |
- if (numQuasis > 1) { | |
- for (ii = 0; ii < template.expressions.length; ii++) { | |
- var expression = template.expressions[ii]; | |
- utils.append(', ', state); | |
+visitStructuredParameter.test = function(node, path, state) { | |
+ return isStructuredPattern(node) && isFunctionNode(path[0]); | |
+}; | |
- // maintain line numbers by calling catchupWhiteSpace over the whole | |
- // previous TemplateElement | |
- utils.move(template.quasis[ii].range[0], state); | |
- utils.catchupNewlines(template.quasis[ii].range[1], state); | |
+function isFunctionNode(node) { | |
+ return (node.type == Syntax.FunctionDeclaration || | |
+ node.type == Syntax.FunctionExpression || | |
+ node.type == Syntax.MethodDefinition || | |
+ node.type == Syntax.ArrowFunctionExpression); | |
+} | |
- utils.move(expression.range[0], state); | |
- traverse(expression, path, state); | |
- utils.catchup(expression.range[1], state); | |
- } | |
- } | |
+// ------------------------------------------------------- | |
+// 4. Function body for structured parameters. | |
+// | |
+// function foo({x, y}) { x; y; } | |
+// ------------------------------------------------------- | |
- // print blank lines to push the closing ) down to account for the final | |
- // TemplateElement. | |
- utils.catchupNewlines(node.range[1], state); | |
+function visitFunctionBodyForStructuredParameter(traverse, node, path, state) { | |
+ var funcNode = path[0]; | |
- utils.append(')', state); | |
+ utils.catchup(funcNode.body.range[0] + 1, state); | |
+ renderDestructuredComponents(funcNode, state); | |
- return false; | |
+ if (funcNode.rest) { | |
+ utils.append( | |
+ restParamVisitors.renderRestParamSetup(funcNode), | |
+ state | |
+ ); | |
+ } | |
+ | |
+ return true; | |
} | |
-visitTaggedTemplateExpression.test = function(node, path, state) { | |
- return node.type === Syntax.TaggedTemplateExpression; | |
-}; | |
+function renderDestructuredComponents(funcNode, state) { | |
+ var destructuredComponents = []; | |
-function getCookedValue(templateElement) { | |
- return JSON.stringify(templateElement.value.cooked); | |
-} | |
+ for (var k = 0; k < funcNode.params.length; k++) { | |
+ var param = funcNode.params[k]; | |
+ if (isStructuredPattern(param)) { | |
+ destructuredComponents.push( | |
+ getDestructuredComponents(param, state) | |
+ ); | |
+ state.localScope.tempVarIndex++; | |
+ } | |
+ } | |
-function getRawValue(templateElement) { | |
- return JSON.stringify(templateElement.value.raw); | |
+ if (destructuredComponents.length) { | |
+ utils.append('var ' + destructuredComponents.join(',') + ';', state); | |
+ } | |
} | |
+visitFunctionBodyForStructuredParameter.test = function(node, path, state) { | |
+ return node.type === Syntax.BlockStatement && isFunctionNode(path[0]); | |
+}; | |
+ | |
exports.visitorList = [ | |
- visitTemplateLiteral, | |
- visitTaggedTemplateExpression | |
+ visitStructuredVariable, | |
+ visitStructuredAssignment, | |
+ visitStructuredParameter, | |
+ visitFunctionBodyForStructuredParameter | |
]; | |
-},{"../src/utils":21,"esprima-fb":7}],29:[function(_dereq_,module,exports){ | |
+exports.renderDestructuredComponents = renderDestructuredComponents; | |
+ | |
+ | |
+},{"../src/utils":22,"./es6-rest-param-visitors":28,"./es7-rest-property-helpers":30,"./reserved-words-helper":32,"esprima-fb":8}],26:[function(_dereq_,module,exports){ | |
/** | |
* Copyright 2013 Facebook, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
@@ -12493,637 +12462,691 @@ | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
/*jslint node:true*/ | |
/** | |
- * Desugars ES7 rest properties into ES5 object iteration. | |
+ * Desugars concise methods of objects to function expressions. | |
+ * | |
+ * var foo = { | |
+ * method(x, y) { ... } | |
+ * }; | |
+ * | |
+ * var foo = { | |
+ * method: function(x, y) { ... } | |
+ * }; | |
+ * | |
*/ | |
var Syntax = _dereq_('esprima-fb').Syntax; | |
var utils = _dereq_('../src/utils'); | |
+var reservedWordsHelper = _dereq_('./reserved-words-helper'); | |
-// TODO: This is a pretty massive helper, it should only be defined once, in the | |
-// transform's runtime environment. We don't currently have a runtime though. | |
-var restFunction = | |
- '(function(source, exclusion) {' + | |
- 'var rest = {};' + | |
- 'var hasOwn = Object.prototype.hasOwnProperty;' + | |
- 'if (source == null) {' + | |
- 'throw new TypeError();' + | |
- '}' + | |
- 'for (var key in source) {' + | |
- 'if (hasOwn.call(source, key) && !hasOwn.call(exclusion, key)) {' + | |
- 'rest[key] = source[key];' + | |
- '}' + | |
- '}' + | |
- 'return rest;' + | |
- '})'; | |
- | |
-function getPropertyNames(properties) { | |
- var names = []; | |
- for (var i = 0; i < properties.length; i++) { | |
- var property = properties[i]; | |
- if (property.type === Syntax.SpreadProperty) { | |
- continue; | |
- } | |
- if (property.type === Syntax.Identifier) { | |
- names.push(property.name); | |
- } else { | |
- names.push(property.key.name); | |
- } | |
+function visitObjectConciseMethod(traverse, node, path, state) { | |
+ var isGenerator = node.value.generator; | |
+ if (isGenerator) { | |
+ utils.catchupWhiteSpace(node.range[0] + 1, state); | |
} | |
- return names; | |
-} | |
- | |
-function getRestFunctionCall(source, exclusion) { | |
- return restFunction + '(' + source + ',' + exclusion + ')'; | |
-} | |
- | |
-function getSimpleShallowCopy(accessorExpression) { | |
- // This could be faster with 'Object.assign({}, ' + accessorExpression + ')' | |
- // but to unify code paths and avoid a ES6 dependency we use the same | |
- // helper as for the exclusion case. | |
- return getRestFunctionCall(accessorExpression, '{}'); | |
-} | |
- | |
-function renderRestExpression(accessorExpression, excludedProperties) { | |
- var excludedNames = getPropertyNames(excludedProperties); | |
- if (!excludedNames.length) { | |
- return getSimpleShallowCopy(accessorExpression); | |
+ if (node.computed) { // [<expr>]() { ...} | |
+ utils.catchup(node.key.range[1] + 1, state); | |
+ } else if (reservedWordsHelper.isReservedWord(node.key.name)) { | |
+ utils.catchup(node.key.range[0], state); | |
+ utils.append('"', state); | |
+ utils.catchup(node.key.range[1], state); | |
+ utils.append('"', state); | |
} | |
- return getRestFunctionCall( | |
- accessorExpression, | |
- '{' + excludedNames.join(':1,') + ':1}' | |
+ | |
+ utils.catchup(node.key.range[1], state); | |
+ utils.append( | |
+ ':function' + (isGenerator ? '*' : ''), | |
+ state | |
); | |
+ path.unshift(node); | |
+ traverse(node.value, path, state); | |
+ path.shift(); | |
+ return false; | |
} | |
-exports.renderRestExpression = renderRestExpression; | |
+visitObjectConciseMethod.test = function(node, path, state) { | |
+ return node.type === Syntax.Property && | |
+ node.value.type === Syntax.FunctionExpression && | |
+ node.method === true; | |
+}; | |
+ | |
+exports.visitorList = [ | |
+ visitObjectConciseMethod | |
+]; | |
-},{"../src/utils":21,"esprima-fb":7}],30:[function(_dereq_,module,exports){ | |
+},{"../src/utils":22,"./reserved-words-helper":32,"esprima-fb":8}],27:[function(_dereq_,module,exports){ | |
/** | |
- * Copyright 2004-present Facebook. All Rights Reserved. | |
+ * Copyright 2013 Facebook, Inc. | |
+ * | |
+ * Licensed under the Apache License, Version 2.0 (the "License"); | |
+ * you may not use this file except in compliance with the License. | |
+ * You may obtain a copy of the License at | |
+ * | |
+ * http://www.apache.org/licenses/LICENSE-2.0 | |
+ * | |
+ * Unless required by applicable law or agreed to in writing, software | |
+ * distributed under the License is distributed on an "AS IS" BASIS, | |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ * See the License for the specific language governing permissions and | |
+ * limitations under the License. | |
*/ | |
-/*global exports:true*/ | |
+ | |
+/*jslint node: true*/ | |
/** | |
- * Implements ES7 object spread property. | |
- * https://gist.github.com/sebmarkbage/aa849c7973cb4452c547 | |
+ * Desugars ES6 Object Literal short notations into ES3 full notation. | |
* | |
- * { ...a, x: 1 } | |
+ * // Easier return values. | |
+ * function foo(x, y) { | |
+ * return {x, y}; // {x: x, y: y} | |
+ * }; | |
* | |
- * Object.assign({}, a, {x: 1 }) | |
+ * // Destrucruting. | |
+ * function init({port, ip, coords: {x, y}}) { ... } | |
* | |
*/ | |
- | |
var Syntax = _dereq_('esprima-fb').Syntax; | |
var utils = _dereq_('../src/utils'); | |
-function visitObjectLiteralSpread(traverse, node, path, state) { | |
- utils.catchup(node.range[0], state); | |
- | |
- utils.append('Object.assign({', state); | |
- | |
- // Skip the original { | |
- utils.move(node.range[0] + 1, state); | |
- | |
- var previousWasSpread = false; | |
- | |
- for (var i = 0; i < node.properties.length; i++) { | |
- var property = node.properties[i]; | |
- if (property.type === Syntax.SpreadProperty) { | |
- | |
- // Close the previous object or initial object | |
- if (!previousWasSpread) { | |
- utils.append('}', state); | |
- } | |
- | |
- if (i === 0) { | |
- // Normally there will be a comma when we catch up, but not before | |
- // the first property. | |
- utils.append(',', state); | |
- } | |
- | |
- utils.catchup(property.range[0], state); | |
+/** | |
+ * @public | |
+ */ | |
+function visitObjectLiteralShortNotation(traverse, node, path, state) { | |
+ utils.catchup(node.key.range[1], state); | |
+ utils.append(':' + node.key.name, state); | |
+ return false; | |
+} | |
- // skip ... | |
- utils.move(property.range[0] + 3, state); | |
+visitObjectLiteralShortNotation.test = function(node, path, state) { | |
+ return node.type === Syntax.Property && | |
+ node.kind === 'init' && | |
+ node.shorthand === true && | |
+ path[0].type !== Syntax.ObjectPattern; | |
+}; | |
- traverse(property.argument, path, state); | |
+exports.visitorList = [ | |
+ visitObjectLiteralShortNotation | |
+]; | |
- utils.catchup(property.range[1], state); | |
- previousWasSpread = true; | |
+},{"../src/utils":22,"esprima-fb":8}],28:[function(_dereq_,module,exports){ | |
+/** | |
+ * Copyright 2013 Facebook, Inc. | |
+ * | |
+ * Licensed under the Apache License, Version 2.0 (the "License"); | |
+ * you may not use this file except in compliance with the License. | |
+ * You may obtain a copy of the License at | |
+ * | |
+ * http://www.apache.org/licenses/LICENSE-2.0 | |
+ * | |
+ * Unless required by applicable law or agreed to in writing, software | |
+ * distributed under the License is distributed on an "AS IS" BASIS, | |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ * See the License for the specific language governing permissions and | |
+ * limitations under the License. | |
+ */ | |
- } else { | |
+/*jslint node:true*/ | |
- utils.catchup(property.range[0], state); | |
+/** | |
+ * Desugars ES6 rest parameters into ES3 arguments slicing. | |
+ * | |
+ * function printf(template, ...args) { | |
+ * args.forEach(...); | |
+ * }; | |
+ * | |
+ * function printf(template) { | |
+ * var args = [].slice.call(arguments, 1); | |
+ * args.forEach(...); | |
+ * }; | |
+ * | |
+ */ | |
+var Syntax = _dereq_('esprima-fb').Syntax; | |
+var utils = _dereq_('../src/utils'); | |
- if (previousWasSpread) { | |
- utils.append('{', state); | |
- } | |
- traverse(property, path, state); | |
- utils.catchup(property.range[1], state); | |
+function _nodeIsFunctionWithRestParam(node) { | |
+ return (node.type === Syntax.FunctionDeclaration | |
+ || node.type === Syntax.FunctionExpression | |
+ || node.type === Syntax.ArrowFunctionExpression) | |
+ && node.rest; | |
+} | |
- previousWasSpread = false; | |
+function visitFunctionParamsWithRestParam(traverse, node, path, state) { | |
+ if (node.parametricType) { | |
+ utils.catchup(node.parametricType.range[0], state); | |
+ path.unshift(node); | |
+ traverse(node.parametricType, path, state); | |
+ path.shift(); | |
+ } | |
- } | |
+ // Render params. | |
+ if (node.params.length) { | |
+ path.unshift(node); | |
+ traverse(node.params, path, state); | |
+ path.shift(); | |
+ } else { | |
+ // -3 is for ... of the rest. | |
+ utils.catchup(node.rest.range[0] - 3, state); | |
} | |
+ utils.catchupWhiteSpace(node.rest.range[1], state); | |
- utils.catchup(node.range[1] - 1, state); | |
+ path.unshift(node); | |
+ traverse(node.body, path, state); | |
+ path.shift(); | |
- // Skip the trailing } | |
- utils.move(node.range[1], state); | |
+ return false; | |
+} | |
- if (!previousWasSpread) { | |
- utils.append('}', state); | |
- } | |
+visitFunctionParamsWithRestParam.test = function(node, path, state) { | |
+ return _nodeIsFunctionWithRestParam(node); | |
+}; | |
- utils.append(')', state); | |
- return false; | |
+function renderRestParamSetup(functionNode) { | |
+ return 'var ' + functionNode.rest.name + '=Array.prototype.slice.call(' + | |
+ 'arguments,' + | |
+ functionNode.params.length + | |
+ ');'; | |
} | |
-visitObjectLiteralSpread.test = function(node, path, state) { | |
- if (node.type !== Syntax.ObjectExpression) { | |
- return false; | |
- } | |
- // Tight loop optimization | |
- var hasAtLeastOneSpreadProperty = false; | |
- for (var i = 0; i < node.properties.length; i++) { | |
- var property = node.properties[i]; | |
- if (property.type === Syntax.SpreadProperty) { | |
- hasAtLeastOneSpreadProperty = true; | |
- } else if (property.kind !== 'init') { | |
- return false; | |
- } | |
- } | |
- return hasAtLeastOneSpreadProperty; | |
+function visitFunctionBodyWithRestParam(traverse, node, path, state) { | |
+ utils.catchup(node.range[0] + 1, state); | |
+ var parentNode = path[0]; | |
+ utils.append(renderRestParamSetup(parentNode), state); | |
+ return true; | |
+} | |
+ | |
+visitFunctionBodyWithRestParam.test = function(node, path, state) { | |
+ return node.type === Syntax.BlockStatement | |
+ && _nodeIsFunctionWithRestParam(path[0]); | |
}; | |
+exports.renderRestParamSetup = renderRestParamSetup; | |
exports.visitorList = [ | |
- visitObjectLiteralSpread | |
+ visitFunctionParamsWithRestParam, | |
+ visitFunctionBodyWithRestParam | |
]; | |
-},{"../src/utils":21,"esprima-fb":7}],31:[function(_dereq_,module,exports){ | |
+},{"../src/utils":22,"esprima-fb":8}],29:[function(_dereq_,module,exports){ | |
/** | |
- * Copyright 2014 Facebook, Inc. | |
+ * Copyright 2013 Facebook, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
-var KEYWORDS = [ | |
- 'break', 'do', 'in', 'typeof', 'case', 'else', 'instanceof', 'var', 'catch', | |
- 'export', 'new', 'void', 'class', 'extends', 'return', 'while', 'const', | |
- 'finally', 'super', 'with', 'continue', 'for', 'switch', 'yield', 'debugger', | |
- 'function', 'this', 'default', 'if', 'throw', 'delete', 'import', 'try' | |
-]; | |
- | |
-var FUTURE_RESERVED_WORDS = [ | |
- 'enum', 'await', 'implements', 'package', 'protected', 'static', 'interface', | |
- 'private', 'public' | |
-]; | |
- | |
-var LITERALS = [ | |
- 'null', | |
- 'true', | |
- 'false' | |
-]; | |
- | |
-// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-reserved-words | |
-var RESERVED_WORDS = [].concat( | |
- KEYWORDS, | |
- FUTURE_RESERVED_WORDS, | |
- LITERALS | |
-); | |
- | |
-var reservedWordsMap = {}; | |
-RESERVED_WORDS.forEach(function(k) { | |
- reservedWordsMap[k] = true; | |
-}); | |
- | |
-exports.isReservedWord = function(word) { | |
- return !!reservedWordsMap[word]; | |
-}; | |
- | |
-},{}],32:[function(_dereq_,module,exports){ | |
-var esprima = _dereq_('esprima-fb'); | |
-var utils = _dereq_('jstransform/src/utils'); | |
- | |
-var Syntax = esprima.Syntax; | |
+/*jslint node:true*/ | |
-function _isFunctionNode(node) { | |
- return node.type === Syntax.FunctionDeclaration | |
- || node.type === Syntax.FunctionExpression | |
- || node.type === Syntax.ArrowFunctionExpression; | |
-} | |
+/** | |
+ * @typechecks | |
+ */ | |
+'use strict'; | |
-function visitClassProperty(traverse, node, path, state) { | |
- utils.catchupWhiteOut(node.range[1], state); | |
- return false; | |
-} | |
-visitClassProperty.test = function(node, path, state) { | |
- return node.type === Syntax.ClassProperty; | |
-}; | |
+var Syntax = _dereq_('esprima-fb').Syntax; | |
+var utils = _dereq_('../src/utils'); | |
-function visitFunctionParametricAnnotation(traverse, node, path, state) { | |
- utils.catchupWhiteOut(node.range[1], state); | |
- return false; | |
-} | |
-visitFunctionParametricAnnotation.test = function(node, path, state) { | |
- return node.type === Syntax.ParametricTypeAnnotation | |
- && path[0] | |
- && _isFunctionNode(path[0]) | |
- && node === path[0].parametricType; | |
-}; | |
+/** | |
+ * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-12.1.9 | |
+ */ | |
+function visitTemplateLiteral(traverse, node, path, state) { | |
+ var templateElements = node.quasis; | |
-function visitFunctionReturnAnnotation(traverse, node, path, state) { | |
- utils.catchupWhiteOut(node.range[1], state); | |
- return false; | |
-} | |
-visitFunctionReturnAnnotation.test = function(node, path, state) { | |
- return path[0] && _isFunctionNode(path[0]) && node === path[0].returnType; | |
-}; | |
+ utils.append('(', state); | |
+ for (var ii = 0; ii < templateElements.length; ii++) { | |
+ var templateElement = templateElements[ii]; | |
+ if (templateElement.value.raw !== '') { | |
+ utils.append(getCookedValue(templateElement), state); | |
+ if (!templateElement.tail) { | |
+ // + between element and substitution | |
+ utils.append(' + ', state); | |
+ } | |
+ // maintain line numbers | |
+ utils.move(templateElement.range[0], state); | |
+ utils.catchupNewlines(templateElement.range[1], state); | |
+ } else { // templateElement.value.raw === '' | |
+ // Concatenat adjacent substitutions, e.g. `${x}${y}`. Empty templates | |
+ // appear before the first and after the last element - nothing to add in | |
+ // those cases. | |
+ if (ii > 0 && !templateElement.tail) { | |
+ // + between substitution and substitution | |
+ utils.append(' + ', state); | |
+ } | |
+ } | |
-function visitOptionalFunctionParameterAnnotation(traverse, node, path, state) { | |
- path.unshift(node); | |
- traverse(node.id, path, state); | |
- path.shift(); | |
- utils.catchup(node.id.range[1], state); | |
- utils.catchupWhiteOut(node.range[1], state); | |
+ utils.move(templateElement.range[1], state); | |
+ if (!templateElement.tail) { | |
+ var substitution = node.expressions[ii]; | |
+ if (substitution.type === Syntax.Identifier || | |
+ substitution.type === Syntax.MemberExpression || | |
+ substitution.type === Syntax.CallExpression) { | |
+ utils.catchup(substitution.range[1], state); | |
+ } else { | |
+ utils.append('(', state); | |
+ traverse(substitution, path, state); | |
+ utils.catchup(substitution.range[1], state); | |
+ utils.append(')', state); | |
+ } | |
+ // if next templateElement isn't empty... | |
+ if (templateElements[ii + 1].value.cooked !== '') { | |
+ utils.append(' + ', state); | |
+ } | |
+ } | |
+ } | |
+ utils.move(node.range[1], state); | |
+ utils.append(')', state); | |
return false; | |
} | |
-visitOptionalFunctionParameterAnnotation.test = function(node, path, state) { | |
- return node.type === Syntax.OptionalParameter | |
- && path[0] | |
- && _isFunctionNode(path[0]); | |
-}; | |
-function visitTypeAnnotatedIdentifier(traverse, node, path, state) { | |
- traverse(node.id, path, state); | |
- utils.catchup(node.id.range[1], state); | |
- utils.catchupWhiteOut(node.range[1], state); | |
- return false; | |
-} | |
-visitTypeAnnotatedIdentifier.test = function(node, path, state) { | |
- return node.type === Syntax.TypeAnnotatedIdentifier; | |
+visitTemplateLiteral.test = function(node, path, state) { | |
+ return node.type === Syntax.TemplateLiteral; | |
}; | |
-exports.visitorList = [ | |
- visitClassProperty, | |
- visitFunctionParametricAnnotation, | |
- visitFunctionReturnAnnotation, | |
- visitOptionalFunctionParameterAnnotation, | |
- visitTypeAnnotatedIdentifier | |
-]; | |
- | |
-},{"esprima-fb":7,"jstransform/src/utils":21}],33:[function(_dereq_,module,exports){ | |
/** | |
- * Copyright 2013-2014, Facebook, Inc. | |
- * All rights reserved. | |
- * | |
- * This source code is licensed under the BSD-style license found in the | |
- * LICENSE file in the root directory of this source tree. An additional grant | |
- * of patent rights can be found in the PATENTS file in the same directory. | |
+ * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-12.2.6 | |
*/ | |
-/* jshint browser: true */ | |
-/* jslint evil: true */ | |
- | |
-'use strict'; | |
- | |
-var buffer = _dereq_('buffer'); | |
-var transform = _dereq_('jstransform').transform; | |
-var visitors = _dereq_('./fbtransform/visitors'); | |
+function visitTaggedTemplateExpression(traverse, node, path, state) { | |
+ var template = node.quasi; | |
+ var numQuasis = template.quasis.length; | |
-var headEl; | |
-var dummyAnchor; | |
-var inlineScriptCount = 0; | |
+ // print the tag | |
+ utils.move(node.tag.range[0], state); | |
+ traverse(node.tag, path, state); | |
+ utils.catchup(node.tag.range[1], state); | |
-// The source-map library relies on Object.defineProperty, but IE8 doesn't | |
-// support it fully even with es5-sham. Indeed, es5-sham's defineProperty | |
-// throws when Object.prototype.__defineGetter__ is missing, so we skip building | |
-// the source map in that case. | |
-var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); | |
+ // print array of template elements | |
+ utils.append('(function() { var siteObj = [', state); | |
+ for (var ii = 0; ii < numQuasis; ii++) { | |
+ utils.append(getCookedValue(template.quasis[ii]), state); | |
+ if (ii !== numQuasis - 1) { | |
+ utils.append(', ', state); | |
+ } | |
+ } | |
+ utils.append(']; siteObj.raw = [', state); | |
+ for (ii = 0; ii < numQuasis; ii++) { | |
+ utils.append(getRawValue(template.quasis[ii]), state); | |
+ if (ii !== numQuasis - 1) { | |
+ utils.append(', ', state); | |
+ } | |
+ } | |
+ utils.append( | |
+ ']; Object.freeze(siteObj.raw); Object.freeze(siteObj); return siteObj; }()', | |
+ state | |
+ ); | |
-/** | |
- * Run provided code through jstransform. | |
- * | |
- * @param {string} source Original source code | |
- * @param {object?} options Options to pass to jstransform | |
- * @return {object} object as returned from jstransform | |
- */ | |
-function transformReact(source, options) { | |
- // TODO: just use react-tools | |
- options = options || {}; | |
- var visitorList; | |
- if (options.harmony) { | |
- visitorList = visitors.getAllVisitors(); | |
- } else { | |
- visitorList = visitors.transformVisitors.react; | |
+ // print substitutions | |
+ if (numQuasis > 1) { | |
+ for (ii = 0; ii < template.expressions.length; ii++) { | |
+ var expression = template.expressions[ii]; | |
+ utils.append(', ', state); | |
+ | |
+ // maintain line numbers by calling catchupWhiteSpace over the whole | |
+ // previous TemplateElement | |
+ utils.move(template.quasis[ii].range[0], state); | |
+ utils.catchupNewlines(template.quasis[ii].range[1], state); | |
+ | |
+ utils.move(expression.range[0], state); | |
+ traverse(expression, path, state); | |
+ utils.catchup(expression.range[1], state); | |
+ } | |
} | |
- return transform(visitorList, source, { | |
- sourceMap: supportsAccessors && options.sourceMap | |
- }); | |
+ // print blank lines to push the closing ) down to account for the final | |
+ // TemplateElement. | |
+ utils.catchupNewlines(node.range[1], state); | |
+ | |
+ utils.append(')', state); | |
+ | |
+ return false; | |
} | |
-/** | |
- * Eval provided source after transforming it. | |
- * | |
- * @param {string} source Original source code | |
- * @param {object?} options Options to pass to jstransform | |
- */ | |
-function exec(source, options) { | |
- return eval(transformReact(source, options).code); | |
+visitTaggedTemplateExpression.test = function(node, path, state) { | |
+ return node.type === Syntax.TaggedTemplateExpression; | |
+}; | |
+ | |
+function getCookedValue(templateElement) { | |
+ return JSON.stringify(templateElement.value.cooked); | |
+} | |
+ | |
+function getRawValue(templateElement) { | |
+ return JSON.stringify(templateElement.value.raw); | |
} | |
+exports.visitorList = [ | |
+ visitTemplateLiteral, | |
+ visitTaggedTemplateExpression | |
+]; | |
+ | |
+},{"../src/utils":22,"esprima-fb":8}],30:[function(_dereq_,module,exports){ | |
/** | |
- * This method returns a nicely formated line of code pointing to the exact | |
- * location of the error `e`. The line is limited in size so big lines of code | |
- * are also shown in a readable way. | |
+ * Copyright 2013 Facebook, Inc. | |
* | |
- * Example: | |
- * ... x', overflow:'scroll'}} id={} onScroll={this.scroll} class=" ... | |
- * ^ | |
+ * Licensed under the Apache License, Version 2.0 (the "License"); | |
+ * you may not use this file except in compliance with the License. | |
+ * You may obtain a copy of the License at | |
* | |
- * @param {string} code The full string of code | |
- * @param {Error} e The error being thrown | |
- * @return {string} formatted message | |
- * @internal | |
+ * http://www.apache.org/licenses/LICENSE-2.0 | |
+ * | |
+ * Unless required by applicable law or agreed to in writing, software | |
+ * distributed under the License is distributed on an "AS IS" BASIS, | |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ * See the License for the specific language governing permissions and | |
+ * limitations under the License. | |
*/ | |
-function createSourceCodeErrorMessage(code, e) { | |
- var sourceLines = code.split('\n'); | |
- var erroneousLine = sourceLines[e.lineNumber - 1]; | |
- | |
- // Removes any leading indenting spaces and gets the number of | |
- // chars indenting the `erroneousLine` | |
- var indentation = 0; | |
- erroneousLine = erroneousLine.replace(/^\s+/, function(leadingSpaces) { | |
- indentation = leadingSpaces.length; | |
- return ''; | |
- }); | |
- | |
- // Defines the number of characters that are going to show | |
- // before and after the erroneous code | |
- var LIMIT = 30; | |
- var errorColumn = e.column - indentation; | |
- if (errorColumn > LIMIT) { | |
- erroneousLine = '... ' + erroneousLine.slice(errorColumn - LIMIT); | |
- errorColumn = 4 + LIMIT; | |
- } | |
- if (erroneousLine.length - errorColumn > LIMIT) { | |
- erroneousLine = erroneousLine.slice(0, errorColumn + LIMIT) + ' ...'; | |
- } | |
- var message = '\n\n' + erroneousLine + '\n'; | |
- message += new Array(errorColumn - 1).join(' ') + '^'; | |
- return message; | |
-} | |
+/*jslint node:true*/ | |
/** | |
- * Actually transform the code. | |
- * | |
- * @param {string} code | |
- * @param {string?} url | |
- * @param {object?} options | |
- * @return {string} The transformed code. | |
- * @internal | |
+ * Desugars ES7 rest properties into ES5 object iteration. | |
*/ | |
-function transformCode(code, url, options) { | |
- try { | |
- var transformed = transformReact(code, options); | |
- } catch(e) { | |
- e.message += '\n at '; | |
- if (url) { | |
- if ('fileName' in e) { | |
- // We set `fileName` if it's supported by this error object and | |
- // a `url` was provided. | |
- // The error will correctly point to `url` in Firefox. | |
- e.fileName = url; | |
- } | |
- e.message += url + ':' + e.lineNumber + ':' + e.column; | |
+ | |
+var Syntax = _dereq_('esprima-fb').Syntax; | |
+var utils = _dereq_('../src/utils'); | |
+ | |
+// TODO: This is a pretty massive helper, it should only be defined once, in the | |
+// transform's runtime environment. We don't currently have a runtime though. | |
+var restFunction = | |
+ '(function(source, exclusion) {' + | |
+ 'var rest = {};' + | |
+ 'var hasOwn = Object.prototype.hasOwnProperty;' + | |
+ 'if (source == null) {' + | |
+ 'throw new TypeError();' + | |
+ '}' + | |
+ 'for (var key in source) {' + | |
+ 'if (hasOwn.call(source, key) && !hasOwn.call(exclusion, key)) {' + | |
+ 'rest[key] = source[key];' + | |
+ '}' + | |
+ '}' + | |
+ 'return rest;' + | |
+ '})'; | |
+ | |
+function getPropertyNames(properties) { | |
+ var names = []; | |
+ for (var i = 0; i < properties.length; i++) { | |
+ var property = properties[i]; | |
+ if (property.type === Syntax.SpreadProperty) { | |
+ continue; | |
+ } | |
+ if (property.type === Syntax.Identifier) { | |
+ names.push(property.name); | |
} else { | |
- e.message += location.href; | |
+ names.push(property.key.name); | |
} | |
- e.message += createSourceCodeErrorMessage(code, e); | |
- throw e; | |
} | |
+ return names; | |
+} | |
- if (!transformed.sourceMap) { | |
- return transformed.code; | |
- } | |
+function getRestFunctionCall(source, exclusion) { | |
+ return restFunction + '(' + source + ',' + exclusion + ')'; | |
+} | |
- var map = transformed.sourceMap.toJSON(); | |
- var source; | |
- if (url == null) { | |
- source = "Inline JSX script"; | |
- inlineScriptCount++; | |
- if (inlineScriptCount > 1) { | |
- source += ' (' + inlineScriptCount + ')'; | |
- } | |
- } else if (dummyAnchor) { | |
- // Firefox has problems when the sourcemap source is a proper URL with a | |
- // protocol and hostname, so use the pathname. We could use just the | |
- // filename, but hopefully using the full path will prevent potential | |
- // issues where the same filename exists in multiple directories. | |
- dummyAnchor.href = url; | |
- source = dummyAnchor.pathname.substr(1); | |
- } | |
- map.sources = [source]; | |
- map.sourcesContent = [code]; | |
+function getSimpleShallowCopy(accessorExpression) { | |
+ // This could be faster with 'Object.assign({}, ' + accessorExpression + ')' | |
+ // but to unify code paths and avoid a ES6 dependency we use the same | |
+ // helper as for the exclusion case. | |
+ return getRestFunctionCall(accessorExpression, '{}'); | |
+} | |
- return ( | |
- transformed.code + | |
- '\n//# sourceMappingURL=data:application/json;base64,' + | |
- buffer.Buffer(JSON.stringify(map)).toString('base64') | |
+function renderRestExpression(accessorExpression, excludedProperties) { | |
+ var excludedNames = getPropertyNames(excludedProperties); | |
+ if (!excludedNames.length) { | |
+ return getSimpleShallowCopy(accessorExpression); | |
+ } | |
+ return getRestFunctionCall( | |
+ accessorExpression, | |
+ '{' + excludedNames.join(':1,') + ':1}' | |
); | |
} | |
+exports.renderRestExpression = renderRestExpression; | |
+},{"../src/utils":22,"esprima-fb":8}],31:[function(_dereq_,module,exports){ | |
/** | |
- * Appends a script element at the end of the <head> with the content of code, | |
- * after transforming it. | |
- * | |
- * @param {string} code The original source code | |
- * @param {string?} url Where the code came from. null if inline | |
- * @param {object?} options Options to pass to jstransform | |
- * @internal | |
+ * Copyright 2004-present Facebook. All Rights Reserved. | |
*/ | |
-function run(code, url, options) { | |
- var scriptEl = document.createElement('script'); | |
- scriptEl.text = transformCode(code, url, options); | |
- headEl.appendChild(scriptEl); | |
-} | |
+/*global exports:true*/ | |
/** | |
- * Load script from the provided url and pass the content to the callback. | |
+ * Implements ES7 object spread property. | |
+ * https://gist.github.com/sebmarkbage/aa849c7973cb4452c547 | |
+ * | |
+ * { ...a, x: 1 } | |
+ * | |
+ * Object.assign({}, a, {x: 1 }) | |
* | |
- * @param {string} url The location of the script src | |
- * @param {function} callback Function to call with the content of url | |
- * @internal | |
*/ | |
-function load(url, successCallback, errorCallback) { | |
- var xhr; | |
- xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') | |
- : new XMLHttpRequest(); | |
- // async, however scripts will be executed in the order they are in the | |
- // DOM to mirror normal script loading. | |
- xhr.open('GET', url, true); | |
- if ('overrideMimeType' in xhr) { | |
- xhr.overrideMimeType('text/plain'); | |
- } | |
- xhr.onreadystatechange = function() { | |
- if (xhr.readyState === 4) { | |
- if (xhr.status === 0 || xhr.status === 200) { | |
- successCallback(xhr.responseText); | |
- } else { | |
- errorCallback(); | |
- throw new Error("Could not load " + url); | |
+var Syntax = _dereq_('esprima-fb').Syntax; | |
+var utils = _dereq_('../src/utils'); | |
+ | |
+function visitObjectLiteralSpread(traverse, node, path, state) { | |
+ utils.catchup(node.range[0], state); | |
+ | |
+ utils.append('Object.assign({', state); | |
+ | |
+ // Skip the original { | |
+ utils.move(node.range[0] + 1, state); | |
+ | |
+ var previousWasSpread = false; | |
+ | |
+ for (var i = 0; i < node.properties.length; i++) { | |
+ var property = node.properties[i]; | |
+ if (property.type === Syntax.SpreadProperty) { | |
+ | |
+ // Close the previous object or initial object | |
+ if (!previousWasSpread) { | |
+ utils.append('}', state); | |
+ } | |
+ | |
+ if (i === 0) { | |
+ // Normally there will be a comma when we catch up, but not before | |
+ // the first property. | |
+ utils.append(',', state); | |
} | |
- } | |
- }; | |
- return xhr.send(null); | |
-} | |
-/** | |
- * Loop over provided script tags and get the content, via innerHTML if an | |
- * inline script, or by using XHR. Transforms are applied if needed. The scripts | |
- * are executed in the order they are found on the page. | |
- * | |
- * @param {array} scripts The <script> elements to load and run. | |
- * @internal | |
- */ | |
-function loadScripts(scripts) { | |
- var result = []; | |
- var count = scripts.length; | |
+ utils.catchup(property.range[0], state); | |
- function check() { | |
- var script, i; | |
+ // skip ... | |
+ utils.move(property.range[0] + 3, state); | |
- for (i = 0; i < count; i++) { | |
- script = result[i]; | |
+ traverse(property.argument, path, state); | |
- if (script.loaded && !script.executed) { | |
- script.executed = true; | |
- run(script.content, script.url, script.options); | |
- } else if (!script.loaded && !script.error && !script.async) { | |
- break; | |
+ utils.catchup(property.range[1], state); | |
+ | |
+ previousWasSpread = true; | |
+ | |
+ } else { | |
+ | |
+ utils.catchup(property.range[0], state); | |
+ | |
+ if (previousWasSpread) { | |
+ utils.append('{', state); | |
} | |
+ | |
+ traverse(property, path, state); | |
+ | |
+ utils.catchup(property.range[1], state); | |
+ | |
+ previousWasSpread = false; | |
+ | |
} | |
} | |
- scripts.forEach(function(script, i) { | |
- var options = { | |
- sourceMap: true | |
- }; | |
- if (/;harmony=true(;|$)/.test(script.type)) { | |
- options.harmony = true | |
- } | |
+ utils.catchup(node.range[1] - 1, state); | |
- // script.async is always true for non-javascript script tags | |
- var async = script.hasAttribute('async'); | |
+ // Skip the trailing } | |
+ utils.move(node.range[1], state); | |
- if (script.src) { | |
- result[i] = { | |
- async: async, | |
- error: false, | |
- executed: false, | |
- content: null, | |
- loaded: false, | |
- url: script.src, | |
- options: options | |
- }; | |
+ if (!previousWasSpread) { | |
+ utils.append('}', state); | |
+ } | |
- load(script.src, function(content) { | |
- result[i].loaded = true; | |
- result[i].content = content; | |
- check(); | |
- }, function() { | |
- result[i].error = true; | |
- check(); | |
- }); | |
- } else { | |
- result[i] = { | |
- async: async, | |
- error: false, | |
- executed: false, | |
- content: script.innerHTML, | |
- loaded: true, | |
- url: null, | |
- options: options | |
- }; | |
+ utils.append(')', state); | |
+ return false; | |
+} | |
+ | |
+visitObjectLiteralSpread.test = function(node, path, state) { | |
+ if (node.type !== Syntax.ObjectExpression) { | |
+ return false; | |
+ } | |
+ // Tight loop optimization | |
+ var hasAtLeastOneSpreadProperty = false; | |
+ for (var i = 0; i < node.properties.length; i++) { | |
+ var property = node.properties[i]; | |
+ if (property.type === Syntax.SpreadProperty) { | |
+ hasAtLeastOneSpreadProperty = true; | |
+ } else if (property.kind !== 'init') { | |
+ return false; | |
} | |
- }); | |
+ } | |
+ return hasAtLeastOneSpreadProperty; | |
+}; | |
- check(); | |
-} | |
+exports.visitorList = [ | |
+ visitObjectLiteralSpread | |
+]; | |
+},{"../src/utils":22,"esprima-fb":8}],32:[function(_dereq_,module,exports){ | |
/** | |
- * Find and run all script tags with type="text/jsx". | |
+ * Copyright 2014 Facebook, Inc. | |
* | |
- * @internal | |
+ * Licensed under the Apache License, Version 2.0 (the "License"); | |
+ * you may not use this file except in compliance with the License. | |
+ * You may obtain a copy of the License at | |
+ * | |
+ * http://www.apache.org/licenses/LICENSE-2.0 | |
+ * | |
+ * Unless required by applicable law or agreed to in writing, software | |
+ * distributed under the License is distributed on an "AS IS" BASIS, | |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ * See the License for the specific language governing permissions and | |
+ * limitations under the License. | |
*/ | |
-function runScripts() { | |
- var scripts = document.getElementsByTagName('script'); | |
- // Array.prototype.slice cannot be used on NodeList on IE8 | |
- var jsxScripts = []; | |
- for (var i = 0; i < scripts.length; i++) { | |
- if (/^text\/jsx(;|$)/.test(scripts.item(i).type)) { | |
- jsxScripts.push(scripts.item(i)); | |
- } | |
- } | |
+var KEYWORDS = [ | |
+ 'break', 'do', 'in', 'typeof', 'case', 'else', 'instanceof', 'var', 'catch', | |
+ 'export', 'new', 'void', 'class', 'extends', 'return', 'while', 'const', | |
+ 'finally', 'super', 'with', 'continue', 'for', 'switch', 'yield', 'debugger', | |
+ 'function', 'this', 'default', 'if', 'throw', 'delete', 'import', 'try' | |
+]; | |
- if (jsxScripts.length < 1) { | |
- return; | |
- } | |
+var FUTURE_RESERVED_WORDS = [ | |
+ 'enum', 'await', 'implements', 'package', 'protected', 'static', 'interface', | |
+ 'private', 'public' | |
+]; | |
- console.warn( | |
- 'You are using the in-browser JSX transformer. Be sure to precompile ' + | |
- 'your JSX for production - ' + | |
- 'http://facebook.github.io/react/docs/tooling-integration.html#jsx' | |
- ); | |
+var LITERALS = [ | |
+ 'null', | |
+ 'true', | |
+ 'false' | |
+]; | |
- loadScripts(jsxScripts); | |
+// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-reserved-words | |
+var RESERVED_WORDS = [].concat( | |
+ KEYWORDS, | |
+ FUTURE_RESERVED_WORDS, | |
+ LITERALS | |
+); | |
+ | |
+var reservedWordsMap = {}; | |
+RESERVED_WORDS.forEach(function(k) { | |
+ reservedWordsMap[k] = true; | |
+}); | |
+ | |
+exports.isReservedWord = function(word) { | |
+ return !!reservedWordsMap[word]; | |
+}; | |
+ | |
+},{}],33:[function(_dereq_,module,exports){ | |
+var esprima = _dereq_('esprima-fb'); | |
+var utils = _dereq_('jstransform/src/utils'); | |
+ | |
+var Syntax = esprima.Syntax; | |
+ | |
+function _isFunctionNode(node) { | |
+ return node.type === Syntax.FunctionDeclaration | |
+ || node.type === Syntax.FunctionExpression | |
+ || node.type === Syntax.ArrowFunctionExpression; | |
} | |
-// Listen for load event if we're in a browser and then kick off finding and | |
-// running of scripts. | |
-if (typeof window !== "undefined" && window !== null) { | |
- headEl = document.getElementsByTagName('head')[0]; | |
- dummyAnchor = document.createElement('a'); | |
+function visitClassProperty(traverse, node, path, state) { | |
+ utils.catchupWhiteOut(node.range[1], state); | |
+ return false; | |
+} | |
+visitClassProperty.test = function(node, path, state) { | |
+ return node.type === Syntax.ClassProperty; | |
+}; | |
- if (window.addEventListener) { | |
- window.addEventListener('DOMContentLoaded', runScripts, false); | |
- } else { | |
- window.attachEvent('onload', runScripts); | |
- } | |
+function visitFunctionParametricAnnotation(traverse, node, path, state) { | |
+ utils.catchupWhiteOut(node.range[1], state); | |
+ return false; | |
} | |
+visitFunctionParametricAnnotation.test = function(node, path, state) { | |
+ return node.type === Syntax.ParametricTypeAnnotation | |
+ && path[0] | |
+ && _isFunctionNode(path[0]) | |
+ && node === path[0].parametricType; | |
+}; | |
-module.exports = { | |
- transform: transformReact, | |
- exec: exec | |
+function visitFunctionReturnAnnotation(traverse, node, path, state) { | |
+ utils.catchupWhiteOut(node.range[1], state); | |
+ return false; | |
+} | |
+visitFunctionReturnAnnotation.test = function(node, path, state) { | |
+ return path[0] && _isFunctionNode(path[0]) && node === path[0].returnType; | |
}; | |
-},{"./fbtransform/visitors":37,"buffer":1,"jstransform":20}],34:[function(_dereq_,module,exports){ | |
+function visitOptionalFunctionParameterAnnotation(traverse, node, path, state) { | |
+ path.unshift(node); | |
+ traverse(node.id, path, state); | |
+ path.shift(); | |
+ utils.catchup(node.id.range[1], state); | |
+ utils.catchupWhiteOut(node.range[1], state); | |
+ return false; | |
+} | |
+visitOptionalFunctionParameterAnnotation.test = function(node, path, state) { | |
+ return node.type === Syntax.OptionalParameter | |
+ && path[0] | |
+ && _isFunctionNode(path[0]); | |
+}; | |
+ | |
+function visitTypeAnnotatedIdentifier(traverse, node, path, state) { | |
+ traverse(node.id, path, state); | |
+ utils.catchup(node.id.range[1], state); | |
+ utils.catchupWhiteOut(node.range[1], state); | |
+ return false; | |
+} | |
+visitTypeAnnotatedIdentifier.test = function(node, path, state) { | |
+ return node.type === Syntax.TypeAnnotatedIdentifier; | |
+}; | |
+ | |
+exports.visitorList = [ | |
+ visitClassProperty, | |
+ visitFunctionParametricAnnotation, | |
+ visitFunctionReturnAnnotation, | |
+ visitOptionalFunctionParameterAnnotation, | |
+ visitTypeAnnotatedIdentifier | |
+]; | |
+ | |
+},{"esprima-fb":8,"jstransform/src/utils":22}],34:[function(_dereq_,module,exports){ | |
/** | |
* Copyright 2013-2014, Facebook, Inc. | |
* All rights reserved. | |
* | |
* This source code is licensed under the BSD-style license found in the | |
* LICENSE file in the root directory of this source tree. An additional grant | |
* of patent rights can be found in the PATENTS file in the same directory. | |
*/ | |
@@ -13368,17 +13391,17 @@ | |
visitReactTag.test = function(object, path, state) { | |
return object.type === Syntax.XJSElement; | |
}; | |
exports.visitorList = [ | |
visitReactTag | |
]; | |
-},{"./xjs":36,"esprima-fb":7,"jstransform/src/utils":21}],35:[function(_dereq_,module,exports){ | |
+},{"./xjs":36,"esprima-fb":8,"jstransform/src/utils":22}],35:[function(_dereq_,module,exports){ | |
/** | |
* Copyright 2013-2014, Facebook, Inc. | |
* All rights reserved. | |
* | |
* This source code is licensed under the BSD-style license found in the | |
* LICENSE file in the root directory of this source tree. An additional grant | |
* of patent rights can be found in the PATENTS file in the same directory. | |
*/ | |
@@ -13463,17 +13486,17 @@ | |
object.type === Syntax.VariableDeclarator | |
); | |
}; | |
exports.visitorList = [ | |
visitReactDisplayName | |
]; | |
-},{"esprima-fb":7,"jstransform/src/utils":21}],36:[function(_dereq_,module,exports){ | |
+},{"esprima-fb":8,"jstransform/src/utils":22}],36:[function(_dereq_,module,exports){ | |
/** | |
* Copyright 2013-2014, Facebook, Inc. | |
* All rights reserved. | |
* | |
* This source code is licensed under the BSD-style license found in the | |
* LICENSE file in the root directory of this source tree. An additional grant | |
* of patent rights can be found in the PATENTS file in the same directory. | |
*/ | |
@@ -13712,17 +13735,17 @@ | |
} | |
exports.knownTags = knownTags; | |
exports.renderXJSExpressionContainer = renderXJSExpressionContainer; | |
exports.renderXJSLiteral = renderXJSLiteral; | |
exports.quoteAttrName = quoteAttrName; | |
exports.trimLeft = trimLeft; | |
-},{"esprima-fb":7,"jstransform/src/utils":21}],37:[function(_dereq_,module,exports){ | |
+},{"esprima-fb":8,"jstransform/src/utils":22}],37:[function(_dereq_,module,exports){ | |
/*global exports:true*/ | |
var es6ArrowFunctions = _dereq_('jstransform/visitors/es6-arrow-function-visitors'); | |
var es6Classes = _dereq_('jstransform/visitors/es6-class-visitors'); | |
var es6Destructuring = _dereq_('jstransform/visitors/es6-destructuring-visitors'); | |
var es6ObjectConciseMethod = _dereq_('jstransform/visitors/es6-object-concise-method-visitors'); | |
var es6ObjectShortNotation = _dereq_('jstransform/visitors/es6-object-short-notation-visitors'); | |
var es6RestParameters = _dereq_('jstransform/visitors/es6-rest-param-visitors'); | |
var es6Templates = _dereq_('jstransform/visitors/es6-template-visitors'); | |
@@ -13826,11 +13849,10 @@ | |
return visitorList; | |
} | |
exports.getVisitorsBySet = getVisitorsBySet; | |
exports.getAllVisitors = getAllVisitors; | |
exports.transformVisitors = transformVisitors; | |
-},{"./transforms/react":34,"./transforms/reactDisplayName":35,"jstransform/visitors/es6-arrow-function-visitors":22,"jstransform/visitors/es6-class-visitors":23,"jstransform/visitors/es6-destructuring-visitors":24,"jstransform/visitors/es6-object-concise-method-visitors":25,"jstransform/visitors/es6-object-short-notation-visitors":26,"jstransform/visitors/es6-rest-param-visitors":27,"jstransform/visitors/es6-template-visitors":28,"jstransform/visitors/es7-spread-property-visitors":30,"jstransform/visitors/type-syntax":32}]},{},[33]) | |
-(33) | |
+},{"./transforms/react":34,"./transforms/reactDisplayName":35,"jstransform/visitors/es6-arrow-function-visitors":23,"jstransform/visitors/es6-class-visitors":24,"jstransform/visitors/es6-destructuring-visitors":25,"jstransform/visitors/es6-object-concise-method-visitors":26,"jstransform/visitors/es6-object-short-notation-visitors":27,"jstransform/visitors/es6-rest-param-visitors":28,"jstransform/visitors/es6-template-visitors":29,"jstransform/visitors/es7-spread-property-visitors":31,"jstransform/visitors/type-syntax":33}]},{},[1])(1) | |
}); | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment