mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2024-11-13 06:36:17 +00:00
10859 lines
364 KiB
JavaScript
10859 lines
364 KiB
JavaScript
|
/**
|
|||
|
* Modules in this bundle
|
|||
|
* @license
|
|||
|
*
|
|||
|
* power-assert-formatter:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* contributors: James Talmage
|
|||
|
* homepage: https://github.com/power-assert-js/power-assert-formatter
|
|||
|
* version: 1.4.1
|
|||
|
*
|
|||
|
* acorn:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* maintainers: marijn <marijnh@gmail.com>, rreverser <me@rreverser.com>
|
|||
|
* contributors: -e List of Acorn contributors. Updated before every release., Adrian Rakovsky, Alistair Braidwood, Andres Suarez, Angelo, Aparajita Fishman, Arian Stolwijk, Artem Govorov, Brandon Mills, Charles Hughes, Conrad Irwin, David Bonnet, Domenico Matteo, ForbesLindesay, Forbes Lindesay, Gilad Peleg, impinball, Ingvar Stepanyan, Jackson Ray Hamilton, Jesse McCarthy, Jiaxing Wang, Joel Kemp, Johannes Herr, Jordan Klassen, Jürg Lehni, keeyipchan, Keheliya Gallaba, Kevin Kwok, krator, Marijn Haverbeke, Martin Carlberg, Mathias Bynens, Mathieu 'p01' Henri, Matthew Bastien, Max Schaefer, Max Zerzouri, Mihai Bazon, Mike Rennie, Nicholas C. Zakas, Nick Fitzgerald, Olivier Thomann, Oskar Schöldström, Paul Harper, Peter Rust, PlNG, Prayag Verma, ReadmeCritic, r-e-d, Richard Gibson, Rich Harris, Sebastian McKenzie, Timothy Gu, Toru Nagashima, zsjforcn
|
|||
|
* homepage: https://github.com/ternjs/acorn
|
|||
|
* version: 3.2.0
|
|||
|
*
|
|||
|
* acorn-es7-plugin:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: matatbread
|
|||
|
* maintainers: matatbread <npm@mailed.me.uk>
|
|||
|
* homepage: https://github.com/MatAtBread/acorn-es7-plugin#readme
|
|||
|
* version: 1.0.15
|
|||
|
*
|
|||
|
* core-js:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* maintainers: zloirock <zloirock@zloirock.ru>
|
|||
|
* homepage: https://github.com/zloirock/core-js#readme
|
|||
|
* version: 2.4.0
|
|||
|
*
|
|||
|
* diff-match-patch:
|
|||
|
* license: http://www.apache.org/licenses/LICENSE-2.0
|
|||
|
* maintainers: forbeslindesay <forbes@lindeay.co.uk>
|
|||
|
* homepage: https://github.com/ForbesLindesay/diff-match-patch#readme
|
|||
|
* version: 1.0.0
|
|||
|
*
|
|||
|
* eastasianwidth:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Masaki Komagata
|
|||
|
* maintainers: komagata <komagata@gmail.com>
|
|||
|
* homepage: https://github.com/komagata/eastasianwidth#readme
|
|||
|
* version: 0.1.1
|
|||
|
*
|
|||
|
* espurify:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* maintainers: twada <takuto.wada@gmail.com>
|
|||
|
* homepage: https://github.com/estools/espurify
|
|||
|
* version: 1.6.0
|
|||
|
*
|
|||
|
* estraverse:
|
|||
|
* license: BSD-2-Clause (http://opensource.org/licenses/BSD-2-Clause)
|
|||
|
* maintainers: constellation <utatane.tea@gmail.com>, michaelficarra <npm@michael.ficarra.me>, nzakas <nicholas@nczconsulting.com>
|
|||
|
* homepage: https://github.com/estools/estraverse
|
|||
|
* version: 4.2.0
|
|||
|
*
|
|||
|
* events:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Irakli Gozalishvili <rfobic@gmail.com>
|
|||
|
* maintainers: gozala <rfobic@gmail.com>, defunctzombie <shtylman@gmail.com>
|
|||
|
* homepage: https://github.com/Gozala/events#readme
|
|||
|
* version: 1.1.1
|
|||
|
*
|
|||
|
* inherits:
|
|||
|
* license: ISC (http://opensource.org/licenses/ISC)
|
|||
|
* maintainers: isaacs <i@izs.me>
|
|||
|
* homepage: https://github.com/isaacs/inherits#readme
|
|||
|
* version: 2.0.1
|
|||
|
*
|
|||
|
* power-assert-context-formatter:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* maintainers: twada <takuto.wada@gmail.com>
|
|||
|
* homepage: https://github.com/twada/power-assert-runtime
|
|||
|
* version: 1.0.7
|
|||
|
*
|
|||
|
* power-assert-context-reducer-ast:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* maintainers: twada <takuto.wada@gmail.com>
|
|||
|
* homepage: https://github.com/twada/power-assert-runtime
|
|||
|
* version: 1.0.7
|
|||
|
*
|
|||
|
* power-assert-context-traversal:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* maintainers: twada <takuto.wada@gmail.com>
|
|||
|
* homepage: https://github.com/twada/power-assert-runtime
|
|||
|
* version: 1.0.7
|
|||
|
*
|
|||
|
* power-assert-renderer-assertion:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* maintainers: twada <takuto.wada@gmail.com>
|
|||
|
* homepage: https://github.com/twada/power-assert-runtime
|
|||
|
* version: 1.0.7
|
|||
|
*
|
|||
|
* power-assert-renderer-base:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* maintainers: twada <takuto.wada@gmail.com>
|
|||
|
* homepage: https://github.com/twada/power-assert-runtime
|
|||
|
* version: 1.0.7
|
|||
|
*
|
|||
|
* power-assert-renderer-comparison:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* maintainers: twada <takuto.wada@gmail.com>
|
|||
|
* homepage: https://github.com/twada/power-assert-runtime
|
|||
|
* version: 1.0.7
|
|||
|
*
|
|||
|
* power-assert-renderer-diagram:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* maintainers: twada <takuto.wada@gmail.com>
|
|||
|
* homepage: https://github.com/twada/power-assert-runtime
|
|||
|
* version: 1.0.7
|
|||
|
*
|
|||
|
* power-assert-renderer-file:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* maintainers: twada <takuto.wada@gmail.com>
|
|||
|
* homepage: https://github.com/twada/power-assert-runtime
|
|||
|
* version: 1.0.7
|
|||
|
*
|
|||
|
* process:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Roman Shtylman <shtylman@gmail.com>
|
|||
|
* maintainers: coolaj86 <coolaj86@gmail.com>, cwmma <calvin.metcalf@gmail.com>, defunctzombie <shtylman@gmail.com>
|
|||
|
* homepage: https://github.com/shtylman/node-process#readme
|
|||
|
* version: 0.11.5
|
|||
|
*
|
|||
|
* stringifier:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* maintainers: twada <takuto.wada@gmail.com>
|
|||
|
* homepage: https://github.com/twada/stringifier
|
|||
|
* version: 1.3.0
|
|||
|
*
|
|||
|
* traverse:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: James Halliday <mail@substack.net>
|
|||
|
* maintainers: substack <mail@substack.net>
|
|||
|
* homepage: https://github.com/substack/js-traverse
|
|||
|
* version: 0.6.6
|
|||
|
*
|
|||
|
* type-name:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Takuto Wada <takuto.wada@gmail.com>
|
|||
|
* maintainers: twada <takuto.wada@gmail.com>
|
|||
|
* contributors: azu, Yosuke Furukawa
|
|||
|
* homepage: https://github.com/twada/type-name
|
|||
|
* version: 2.0.1
|
|||
|
*
|
|||
|
* util:
|
|||
|
* license: MIT (http://opensource.org/licenses/MIT)
|
|||
|
* author: Joyent
|
|||
|
* maintainers: shtylman <shtylman@gmail.com>
|
|||
|
* homepage: https://github.com/defunctzombie/node-util
|
|||
|
* version: 0.10.3
|
|||
|
*
|
|||
|
* This header is generated by licensify (https://github.com/twada/licensify)
|
|||
|
*/
|
|||
|
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.powerAssertFormatter = f()}})(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){
|
|||
|
/**
|
|||
|
* power-assert-formatter.js - Power Assert output formatter
|
|||
|
*
|
|||
|
* https://github.com/power-assert-js/power-assert-formatter
|
|||
|
*
|
|||
|
* Copyright (c) 2013-2016 Takuto Wada
|
|||
|
* Licensed under the MIT license.
|
|||
|
* https://github.com/power-assert-js/power-assert-formatter/blob/master/MIT-LICENSE.txt
|
|||
|
*/
|
|||
|
'use strict';
|
|||
|
|
|||
|
module.exports = _dereq_('./lib/create');
|
|||
|
|
|||
|
},{"./lib/create":2}],2:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var createFormatter = _dereq_('power-assert-context-formatter');
|
|||
|
var appendAst = _dereq_('power-assert-context-reducer-ast');
|
|||
|
var FileRenderer = _dereq_('power-assert-renderer-file');
|
|||
|
var AssertionRenderer = _dereq_('power-assert-renderer-assertion');
|
|||
|
var DiagramRenderer = _dereq_('power-assert-renderer-diagram');
|
|||
|
var ComparisonRenderer = _dereq_('power-assert-renderer-comparison');
|
|||
|
var defaultOptions = _dereq_('./default-options');
|
|||
|
var assign = _dereq_('core-js/library/fn/object/assign');
|
|||
|
var map = _dereq_('core-js/library/fn/array/map');
|
|||
|
|
|||
|
// "Browserify can only analyze static requires. It is not in the scope of browserify to handle dynamic requires."
|
|||
|
// https://github.com/substack/node-browserify/issues/377
|
|||
|
var defaultRendererClasses = {
|
|||
|
'./built-in/file': FileRenderer,
|
|||
|
'./built-in/assertion': AssertionRenderer,
|
|||
|
'./built-in/diagram': DiagramRenderer,
|
|||
|
'./built-in/binary-expression': ComparisonRenderer
|
|||
|
};
|
|||
|
|
|||
|
function toRendererClass (rendererName) {
|
|||
|
var RendererClass;
|
|||
|
if (typeof rendererName === 'function') {
|
|||
|
RendererClass = rendererName;
|
|||
|
} else if (typeof rendererName === 'string') {
|
|||
|
if (defaultRendererClasses[rendererName]) {
|
|||
|
RendererClass = defaultRendererClasses[rendererName];
|
|||
|
} else {
|
|||
|
RendererClass = _dereq_(rendererName);
|
|||
|
}
|
|||
|
}
|
|||
|
return RendererClass;
|
|||
|
}
|
|||
|
|
|||
|
function create (options) {
|
|||
|
var config = assign(defaultOptions(), options);
|
|||
|
var rendererClasses = map(config.renderers, toRendererClass);
|
|||
|
var renderers = map(rendererClasses, function (clazz) {
|
|||
|
return { ctor: clazz, options: config };
|
|||
|
});
|
|||
|
return createFormatter(assign({}, config, {
|
|||
|
reducers: [
|
|||
|
appendAst
|
|||
|
],
|
|||
|
renderers: renderers,
|
|||
|
legacy: true
|
|||
|
}));
|
|||
|
}
|
|||
|
|
|||
|
create.renderers = {
|
|||
|
AssertionRenderer: AssertionRenderer,
|
|||
|
FileRenderer: FileRenderer,
|
|||
|
DiagramRenderer: DiagramRenderer,
|
|||
|
BinaryExpressionRenderer: ComparisonRenderer
|
|||
|
};
|
|||
|
create.defaultOptions = defaultOptions;
|
|||
|
module.exports = create;
|
|||
|
|
|||
|
},{"./default-options":3,"core-js/library/fn/array/map":10,"core-js/library/fn/object/assign":13,"power-assert-context-formatter":76,"power-assert-context-reducer-ast":81,"power-assert-renderer-assertion":85,"power-assert-renderer-comparison":87,"power-assert-renderer-diagram":90,"power-assert-renderer-file":93}],3:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
module.exports = function defaultOptions () {
|
|||
|
return {
|
|||
|
lineDiffThreshold: 5,
|
|||
|
maxDepth: 1,
|
|||
|
outputOffset: 2,
|
|||
|
anonymous: 'Object',
|
|||
|
circular: '#@Circular#',
|
|||
|
lineSeparator: '\n',
|
|||
|
ambiguousEastAsianCharWidth: 2,
|
|||
|
renderers: [
|
|||
|
'./built-in/file',
|
|||
|
'./built-in/assertion',
|
|||
|
'./built-in/diagram',
|
|||
|
'./built-in/binary-expression'
|
|||
|
]
|
|||
|
};
|
|||
|
};
|
|||
|
|
|||
|
},{}],4:[function(_dereq_,module,exports){
|
|||
|
var NotAsync = {} ;
|
|||
|
var asyncExit = /^async[\t ]+(return|throw)/ ;
|
|||
|
var asyncFunction = /^async[\t ]+function/ ;
|
|||
|
var atomOrPropertyOrLabel = /^\s*[):;]/ ;
|
|||
|
var removeComments = /([^\n])\/\*(\*(?!\/)|[^\n*])*\*\/([^\n])/g ;
|
|||
|
|
|||
|
function hasLineTerminatorBeforeNext(st, since) {
|
|||
|
return st.lineStart >= since;
|
|||
|
}
|
|||
|
|
|||
|
function test(regex,st,noComment) {
|
|||
|
var src = st.input.slice(st.start) ;
|
|||
|
if (noComment) {
|
|||
|
src = src.replace(removeComments,"$1 $3") ;
|
|||
|
}
|
|||
|
return regex.test(src);
|
|||
|
}
|
|||
|
|
|||
|
/* Return the object holding the parser's 'State'. This is different between acorn ('this')
|
|||
|
* and babylon ('this.state') */
|
|||
|
function state(p) {
|
|||
|
if (('state' in p) && p.state.constructor && p.state.constructor.name==='State')
|
|||
|
return p.state ; // Probably babylon
|
|||
|
return p ; // Probably acorn
|
|||
|
}
|
|||
|
|
|||
|
/* Create a new parser derived from the specified parser, so that in the
|
|||
|
* event of an error we can back out and try again */
|
|||
|
function subParse(parser, pos, extensions) {
|
|||
|
// NB: The Babylon constructor does NOT expect 'pos' as an argument, and so
|
|||
|
// the input needs truncation at the start position, however at present
|
|||
|
// this doesn't work nicely as all the node location/start/end values
|
|||
|
// are therefore offset. Consequently, this plug-in is NOT currently working
|
|||
|
// with the (undocumented) Babylon plug-in interface.
|
|||
|
var p = new parser.constructor(parser.options, parser.input, pos);
|
|||
|
if (extensions)
|
|||
|
for (var k in extensions)
|
|||
|
p[k] = extensions[k] ;
|
|||
|
|
|||
|
var src = state(parser) ;
|
|||
|
var dest = state(p) ;
|
|||
|
['inFunction','inAsyncFunction','inAsync','inGenerator','inModule'].forEach(function(k){
|
|||
|
if (k in src)
|
|||
|
dest[k] = src[k] ;
|
|||
|
}) ;
|
|||
|
p.nextToken();
|
|||
|
return p;
|
|||
|
}
|
|||
|
|
|||
|
function asyncAwaitPlugin (parser,options){
|
|||
|
var es7check = function(){} ;
|
|||
|
|
|||
|
parser.extend("initialContext",function(base){
|
|||
|
return function(){
|
|||
|
if (this.options.ecmaVersion < 7) {
|
|||
|
es7check = function(node) {
|
|||
|
parser.raise(node.start,"async/await keywords only available when ecmaVersion>=7") ;
|
|||
|
} ;
|
|||
|
}
|
|||
|
this.reservedWords = new RegExp(this.reservedWords.toString().replace(/await|async/g,"").replace("|/","/").replace("/|","/").replace("||","|")) ;
|
|||
|
this.reservedWordsStrict = new RegExp(this.reservedWordsStrict.toString().replace(/await|async/g,"").replace("|/","/").replace("/|","/").replace("||","|")) ;
|
|||
|
this.reservedWordsStrictBind = new RegExp(this.reservedWordsStrictBind.toString().replace(/await|async/g,"").replace("|/","/").replace("/|","/").replace("||","|")) ;
|
|||
|
this.inAsyncFunction = options.inAsyncFunction ;
|
|||
|
if (options.awaitAnywhere && options.inAsyncFunction)
|
|||
|
parser.raise(node.start,"The options awaitAnywhere and inAsyncFunction are mutually exclusive") ;
|
|||
|
|
|||
|
return base.apply(this,arguments);
|
|||
|
}
|
|||
|
}) ;
|
|||
|
|
|||
|
parser.extend("shouldParseExportStatement",function(base){
|
|||
|
return function(){
|
|||
|
if (this.type.label==='name' && this.value==='async' && test(asyncFunction,state(this))) {
|
|||
|
return true ;
|
|||
|
}
|
|||
|
return base.apply(this,arguments) ;
|
|||
|
}
|
|||
|
}) ;
|
|||
|
|
|||
|
parser.extend("parseStatement",function(base){
|
|||
|
return function (declaration, topLevel) {
|
|||
|
var st = state(this) ;
|
|||
|
var start = st.start;
|
|||
|
var startLoc = st.startLoc;
|
|||
|
if (st.type.label==='name') {
|
|||
|
if (test(asyncFunction,st,true)) {
|
|||
|
var wasAsync = st.inAsyncFunction ;
|
|||
|
try {
|
|||
|
st.inAsyncFunction = true ;
|
|||
|
this.next() ;
|
|||
|
var r = this.parseStatement(declaration, topLevel) ;
|
|||
|
r.async = true ;
|
|||
|
r.start = start;
|
|||
|
r.loc && (r.loc.start = startLoc);
|
|||
|
return r ;
|
|||
|
} finally {
|
|||
|
st.inAsyncFunction = wasAsync ;
|
|||
|
}
|
|||
|
} else if ((typeof options==="object" && options.asyncExits) && test(asyncExit,st)) {
|
|||
|
// NON-STANDARD EXTENSION iff. options.asyncExits is set, the
|
|||
|
// extensions 'async return <expr>?' and 'async throw <expr>?'
|
|||
|
// are enabled. In each case they are the standard ESTree nodes
|
|||
|
// with the flag 'async:true'
|
|||
|
this.next() ;
|
|||
|
var r = this.parseStatement(declaration, topLevel) ;
|
|||
|
r.async = true ;
|
|||
|
r.start = start;
|
|||
|
r.loc && (r.loc.start = startLoc);
|
|||
|
return r ;
|
|||
|
}
|
|||
|
}
|
|||
|
return base.apply(this,arguments);
|
|||
|
}
|
|||
|
}) ;
|
|||
|
|
|||
|
parser.extend("parseIdent",function(base){
|
|||
|
return function(liberal){
|
|||
|
var id = base.apply(this,arguments);
|
|||
|
var st = state(this) ;
|
|||
|
if (st.inAsyncFunction && id.name==='await') {
|
|||
|
if (arguments.length===0) {
|
|||
|
this.raise(id.start,"'await' is reserved within async functions") ;
|
|||
|
}
|
|||
|
}
|
|||
|
return id ;
|
|||
|
}
|
|||
|
}) ;
|
|||
|
|
|||
|
parser.extend("parseExprAtom",function(base){
|
|||
|
return function(refShorthandDefaultPos){
|
|||
|
var st = state(this) ;
|
|||
|
var start = st.start ;
|
|||
|
var startLoc = st.startLoc;
|
|||
|
var rhs,r = base.apply(this,arguments);
|
|||
|
if (r.type==='Identifier') {
|
|||
|
if (r.name==='async' && !hasLineTerminatorBeforeNext(st, r.end)) {
|
|||
|
// Is this really an async function?
|
|||
|
var isAsync = st.inAsyncFunction ;
|
|||
|
try {
|
|||
|
st.inAsyncFunction = true ;
|
|||
|
var pp = this ;
|
|||
|
var inBody = false ;
|
|||
|
|
|||
|
var parseHooks = {
|
|||
|
parseFunctionBody:function(node,isArrowFunction){
|
|||
|
try {
|
|||
|
var wasInBody = inBody ;
|
|||
|
inBody = true ;
|
|||
|
return pp.parseFunctionBody.apply(this,arguments) ;
|
|||
|
} finally {
|
|||
|
inBody = wasInBody ;
|
|||
|
}
|
|||
|
},
|
|||
|
raise:function(){
|
|||
|
try {
|
|||
|
return pp.raise.apply(this,arguments) ;
|
|||
|
} catch(ex) {
|
|||
|
throw inBody?ex:NotAsync ;
|
|||
|
}
|
|||
|
}
|
|||
|
} ;
|
|||
|
|
|||
|
rhs = subParse(this,st.start,parseHooks).parseExpression() ;
|
|||
|
if (rhs.type==='SequenceExpression')
|
|||
|
rhs = rhs.expressions[0] ;
|
|||
|
if (rhs.type==='FunctionExpression' || rhs.type==='FunctionDeclaration' || rhs.type==='ArrowFunctionExpression') {
|
|||
|
rhs.async = true ;
|
|||
|
rhs.start = start;
|
|||
|
rhs.loc && (rhs.loc.start = startLoc);
|
|||
|
st.pos = rhs.end;
|
|||
|
this.next();
|
|||
|
es7check(rhs) ;
|
|||
|
return rhs ;
|
|||
|
}
|
|||
|
} catch (ex) {
|
|||
|
if (ex!==NotAsync)
|
|||
|
throw ex ;
|
|||
|
}
|
|||
|
finally {
|
|||
|
st.inAsyncFunction = isAsync ;
|
|||
|
}
|
|||
|
}
|
|||
|
else if (r.name==='await') {
|
|||
|
var n = this.startNodeAt(r.start, r.loc && r.loc.start);
|
|||
|
if (st.inAsyncFunction) {
|
|||
|
rhs = this.parseExprSubscripts() ;
|
|||
|
n.operator = 'await' ;
|
|||
|
n.argument = rhs ;
|
|||
|
n = this.finishNodeAt(n,'AwaitExpression', rhs.end, rhs.loc && rhs.loc.end) ;
|
|||
|
es7check(n) ;
|
|||
|
return n ;
|
|||
|
} else
|
|||
|
// NON-STANDARD EXTENSION iff. options.awaitAnywhere is true,
|
|||
|
// an 'AwaitExpression' is allowed anywhere the token 'await'
|
|||
|
// could not be an identifier with the name 'await'.
|
|||
|
|
|||
|
// Look-ahead to see if this is really a property or label called async or await
|
|||
|
if (st.input.slice(r.end).match(atomOrPropertyOrLabel))
|
|||
|
return r ; // This is a valid property name or label
|
|||
|
|
|||
|
if (typeof options==="object" && options.awaitAnywhere) {
|
|||
|
start = st.start ;
|
|||
|
rhs = subParse(this,start-4).parseExprSubscripts() ;
|
|||
|
if (rhs.end<=start) {
|
|||
|
rhs = subParse(this,start).parseExprSubscripts() ;
|
|||
|
n.operator = 'await' ;
|
|||
|
n.argument = rhs ;
|
|||
|
n = this.finishNodeAt(n,'AwaitExpression', rhs.end, rhs.loc && rhs.loc.end) ;
|
|||
|
st.pos = rhs.end;
|
|||
|
this.next();
|
|||
|
es7check(n) ;
|
|||
|
return n ;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return r ;
|
|||
|
}
|
|||
|
}) ;
|
|||
|
|
|||
|
parser.extend('finishNodeAt',function(base){
|
|||
|
return function(node,type,pos,loc) {
|
|||
|
if (node.__asyncValue) {
|
|||
|
delete node.__asyncValue ;
|
|||
|
node.value.async = true ;
|
|||
|
}
|
|||
|
return base.apply(this,arguments) ;
|
|||
|
}
|
|||
|
}) ;
|
|||
|
|
|||
|
parser.extend('finishNode',function(base){
|
|||
|
return function(node,type) {
|
|||
|
if (node.__asyncValue) {
|
|||
|
delete node.__asyncValue ;
|
|||
|
node.value.async = true ;
|
|||
|
}
|
|||
|
return base.apply(this,arguments) ;
|
|||
|
}
|
|||
|
}) ;
|
|||
|
|
|||
|
parser.extend("parsePropertyName",function(base){
|
|||
|
return function (prop) {
|
|||
|
var st = state(this) ;
|
|||
|
var key = base.apply(this,arguments) ;
|
|||
|
if (key.type === "Identifier" && key.name === "async" && !hasLineTerminatorBeforeNext(st, key.end)) {
|
|||
|
// Look-ahead to see if this is really a property or label called async or await
|
|||
|
if (!st.input.slice(key.end).match(atomOrPropertyOrLabel)){
|
|||
|
es7check(prop) ;
|
|||
|
key = base.apply(this,arguments) ;
|
|||
|
if (key.type==='Identifier') {
|
|||
|
if (key.name==='constructor')
|
|||
|
this.raise(key.start,"'constructor()' cannot be be async") ;
|
|||
|
else if (key.name==='set')
|
|||
|
this.raise(key.start,"'set <member>(value)' cannot be be async") ;
|
|||
|
}
|
|||
|
prop.__asyncValue = true ;
|
|||
|
}
|
|||
|
}
|
|||
|
return key;
|
|||
|
};
|
|||
|
}) ;
|
|||
|
|
|||
|
parser.extend("parseClassMethod",function(base){
|
|||
|
return function (classBody, method, isGenerator) {
|
|||
|
var st, wasAsync ;
|
|||
|
if (method.__asyncValue) {
|
|||
|
st = state(this) ;
|
|||
|
wasAsync = st.inAsyncFunction ;
|
|||
|
st.inAsyncFunction = true ;
|
|||
|
}
|
|||
|
var r = base.apply(this,arguments) ;
|
|||
|
if (st) {
|
|||
|
st.inAsyncFunction = wasAsync ;
|
|||
|
}
|
|||
|
return r ;
|
|||
|
}
|
|||
|
}) ;
|
|||
|
|
|||
|
parser.extend("parsePropertyValue",function(base){
|
|||
|
return function (prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors) {
|
|||
|
var st, wasAsync ;
|
|||
|
if (prop.__asyncValue) {
|
|||
|
st = state(this) ;
|
|||
|
wasAsync = st.inAsyncFunction ;
|
|||
|
st.inAsyncFunction = true ;
|
|||
|
}
|
|||
|
var r = base.apply(this,arguments) ;
|
|||
|
if (st) {
|
|||
|
st.inAsyncFunction = wasAsync ;
|
|||
|
}
|
|||
|
return r ;
|
|||
|
}
|
|||
|
}) ;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = function(acorn) {
|
|||
|
acorn.plugins.asyncawait = asyncAwaitPlugin ;
|
|||
|
return acorn
|
|||
|
}
|
|||
|
|
|||
|
},{}],5:[function(_dereq_,module,exports){
|
|||
|
(function (global){
|
|||
|
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.acorn = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;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 _dereq_=="function"&&_dereq_;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
|
|||
|
// A recursive descent parser operates by defining functions for all
|
|||
|
// syntactic elements, and recursively calling those, each function
|
|||
|
// advancing the input stream and returning an AST node. Precedence
|
|||
|
// of constructs (for example, the fact that `!x[1]` means `!(x[1])`
|
|||
|
// instead of `(!x)[1]` is handled by the fact that the parser
|
|||
|
// function that parses unary prefix operators is called first, and
|
|||
|
// in turn calls the function that parses `[]` subscripts — that
|
|||
|
// way, it'll receive the node for `x[1]` already parsed, and wraps
|
|||
|
// *that* in the unary operator node.
|
|||
|
//
|
|||
|
// Acorn uses an [operator precedence parser][opp] to handle binary
|
|||
|
// operator precedence, because it is much more compact than using
|
|||
|
// the technique outlined above, which uses different, nesting
|
|||
|
// functions to specify precedence, for all of the ten binary
|
|||
|
// precedence levels that JavaScript defines.
|
|||
|
//
|
|||
|
// [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
|
|||
|
|
|||
|
"use strict";
|
|||
|
|
|||
|
var _tokentype = _dereq_("./tokentype");
|
|||
|
|
|||
|
var _state = _dereq_("./state");
|
|||
|
|
|||
|
var _parseutil = _dereq_("./parseutil");
|
|||
|
|
|||
|
var pp = _state.Parser.prototype;
|
|||
|
|
|||
|
// Check if property name clashes with already added.
|
|||
|
// Object/class getters and setters are not allowed to clash —
|
|||
|
// either with each other or with an init property — and in
|
|||
|
// strict mode, init properties are also not allowed to be repeated.
|
|||
|
|
|||
|
pp.checkPropClash = function (prop, propHash) {
|
|||
|
if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand)) return;
|
|||
|
var key = prop.key;var name = undefined;
|
|||
|
switch (key.type) {
|
|||
|
case "Identifier":
|
|||
|
name = key.name;break;
|
|||
|
case "Literal":
|
|||
|
name = String(key.value);break;
|
|||
|
default:
|
|||
|
return;
|
|||
|
}
|
|||
|
var kind = prop.kind;
|
|||
|
|
|||
|
if (this.options.ecmaVersion >= 6) {
|
|||
|
if (name === "__proto__" && kind === "init") {
|
|||
|
if (propHash.proto) this.raiseRecoverable(key.start, "Redefinition of __proto__ property");
|
|||
|
propHash.proto = true;
|
|||
|
}
|
|||
|
return;
|
|||
|
}
|
|||
|
name = "$" + name;
|
|||
|
var other = propHash[name];
|
|||
|
if (other) {
|
|||
|
var isGetSet = kind !== "init";
|
|||
|
if ((this.strict || isGetSet) && other[kind] || !(isGetSet ^ other.init)) this.raiseRecoverable(key.start, "Redefinition of property");
|
|||
|
} else {
|
|||
|
other = propHash[name] = {
|
|||
|
init: false,
|
|||
|
get: false,
|
|||
|
set: false
|
|||
|
};
|
|||
|
}
|
|||
|
other[kind] = true;
|
|||
|
};
|
|||
|
|
|||
|
// ### Expression parsing
|
|||
|
|
|||
|
// These nest, from the most general expression type at the top to
|
|||
|
// 'atomic', nondivisible expression types at the bottom. Most of
|
|||
|
// the functions will simply let the function(s) below them parse,
|
|||
|
// and, *if* the syntactic construct they handle is present, wrap
|
|||
|
// the AST node that the inner parser gave them in another node.
|
|||
|
|
|||
|
// Parse a full expression. The optional arguments are used to
|
|||
|
// forbid the `in` operator (in for loops initalization expressions)
|
|||
|
// and provide reference for storing '=' operator inside shorthand
|
|||
|
// property assignment in contexts where both object expression
|
|||
|
// and object pattern might appear (so it's possible to raise
|
|||
|
// delayed syntax error at correct position).
|
|||
|
|
|||
|
pp.parseExpression = function (noIn, refDestructuringErrors) {
|
|||
|
var startPos = this.start,
|
|||
|
startLoc = this.startLoc;
|
|||
|
var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
|
|||
|
if (this.type === _tokentype.types.comma) {
|
|||
|
var node = this.startNodeAt(startPos, startLoc);
|
|||
|
node.expressions = [expr];
|
|||
|
while (this.eat(_tokentype.types.comma)) node.expressions.push(this.parseMaybeAssign(noIn, refDestructuringErrors));
|
|||
|
return this.finishNode(node, "SequenceExpression");
|
|||
|
}
|
|||
|
return expr;
|
|||
|
};
|
|||
|
|
|||
|
// Parse an assignment expression. This includes applications of
|
|||
|
// operators like `+=`.
|
|||
|
|
|||
|
pp.parseMaybeAssign = function (noIn, refDestructuringErrors, afterLeftParse) {
|
|||
|
if (this.inGenerator && this.isContextual("yield")) return this.parseYield();
|
|||
|
|
|||
|
var ownDestructuringErrors = false;
|
|||
|
if (!refDestructuringErrors) {
|
|||
|
refDestructuringErrors = new _parseutil.DestructuringErrors();
|
|||
|
ownDestructuringErrors = true;
|
|||
|
}
|
|||
|
var startPos = this.start,
|
|||
|
startLoc = this.startLoc;
|
|||
|
if (this.type == _tokentype.types.parenL || this.type == _tokentype.types.name) this.potentialArrowAt = this.start;
|
|||
|
var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
|
|||
|
if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc);
|
|||
|
if (this.type.isAssign) {
|
|||
|
this.checkPatternErrors(refDestructuringErrors, true);
|
|||
|
if (!ownDestructuringErrors) _parseutil.DestructuringErrors.call(refDestructuringErrors);
|
|||
|
var node = this.startNodeAt(startPos, startLoc);
|
|||
|
node.operator = this.value;
|
|||
|
node.left = this.type === _tokentype.types.eq ? this.toAssignable(left) : left;
|
|||
|
refDestructuringErrors.shorthandAssign = 0; // reset because shorthand default was used correctly
|
|||
|
this.checkLVal(left);
|
|||
|
this.next();
|
|||
|
node.right = this.parseMaybeAssign(noIn);
|
|||
|
return this.finishNode(node, "AssignmentExpression");
|
|||
|
} else {
|
|||
|
if (ownDestructuringErrors) this.checkExpressionErrors(refDestructuringErrors, true);
|
|||
|
}
|
|||
|
return left;
|
|||
|
};
|
|||
|
|
|||
|
// Parse a ternary conditional (`?:`) operator.
|
|||
|
|
|||
|
pp.parseMaybeConditional = function (noIn, refDestructuringErrors) {
|
|||
|
var startPos = this.start,
|
|||
|
startLoc = this.startLoc;
|
|||
|
var expr = this.parseExprOps(noIn, refDestructuringErrors);
|
|||
|
if (this.checkExpressionErrors(refDestructuringErrors)) return expr;
|
|||
|
if (this.eat(_tokentype.types.question)) {
|
|||
|
var node = this.startNodeAt(startPos, startLoc);
|
|||
|
node.test = expr;
|
|||
|
node.consequent = this.parseMaybeAssign();
|
|||
|
this.expect(_tokentype.types.colon);
|
|||
|
node.alternate = this.parseMaybeAssign(noIn);
|
|||
|
return this.finishNode(node, "ConditionalExpression");
|
|||
|
}
|
|||
|
return expr;
|
|||
|
};
|
|||
|
|
|||
|
// Start the precedence parser.
|
|||
|
|
|||
|
pp.parseExprOps = function (noIn, refDestructuringErrors) {
|
|||
|
var startPos = this.start,
|
|||
|
startLoc = this.startLoc;
|
|||
|
var expr = this.parseMaybeUnary(refDestructuringErrors, false);
|
|||
|
if (this.checkExpressionErrors(refDestructuringErrors)) return expr;
|
|||
|
return this.parseExprOp(expr, startPos, startLoc, -1, noIn);
|
|||
|
};
|
|||
|
|
|||
|
// Parse binary operators with the operator precedence parsing
|
|||
|
// algorithm. `left` is the left-hand side of the operator.
|
|||
|
// `minPrec` provides context that allows the function to stop and
|
|||
|
// defer further parser to one of its callers when it encounters an
|
|||
|
// operator that has a lower precedence than the set it is parsing.
|
|||
|
|
|||
|
pp.parseExprOp = function (left, leftStartPos, leftStartLoc, minPrec, noIn) {
|
|||
|
var prec = this.type.binop;
|
|||
|
if (prec != null && (!noIn || this.type !== _tokentype.types._in)) {
|
|||
|
if (prec > minPrec) {
|
|||
|
var logical = this.type === _tokentype.types.logicalOR || this.type === _tokentype.types.logicalAND;
|
|||
|
var op = this.value;
|
|||
|
this.next();
|
|||
|
var startPos = this.start,
|
|||
|
startLoc = this.startLoc;
|
|||
|
var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
|
|||
|
var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
|
|||
|
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn);
|
|||
|
}
|
|||
|
}
|
|||
|
return left;
|
|||
|
};
|
|||
|
|
|||
|
pp.buildBinary = function (startPos, startLoc, left, right, op, logical) {
|
|||
|
var node = this.startNodeAt(startPos, startLoc);
|
|||
|
node.left = left;
|
|||
|
node.operator = op;
|
|||
|
node.right = right;
|
|||
|
return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression");
|
|||
|
};
|
|||
|
|
|||
|
// Parse unary operators, both prefix and postfix.
|
|||
|
|
|||
|
pp.parseMaybeUnary = function (refDestructuringErrors, sawUnary) {
|
|||
|
var startPos = this.start,
|
|||
|
startLoc = this.startLoc,
|
|||
|
expr = undefined;
|
|||
|
if (this.type.prefix) {
|
|||
|
var node = this.startNode(),
|
|||
|
update = this.type === _tokentype.types.incDec;
|
|||
|
node.operator = this.value;
|
|||
|
node.prefix = true;
|
|||
|
this.next();
|
|||
|
node.argument = this.parseMaybeUnary(null, true);
|
|||
|
this.checkExpressionErrors(refDestructuringErrors, true);
|
|||
|
if (update) this.checkLVal(node.argument);else if (this.strict && node.operator === "delete" && node.argument.type === "Identifier") this.raiseRecoverable(node.start, "Deleting local variable in strict mode");else sawUnary = true;
|
|||
|
expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
|
|||
|
} else {
|
|||
|
expr = this.parseExprSubscripts(refDestructuringErrors);
|
|||
|
if (this.checkExpressionErrors(refDestructuringErrors)) return expr;
|
|||
|
while (this.type.postfix && !this.canInsertSemicolon()) {
|
|||
|
var node = this.startNodeAt(startPos, startLoc);
|
|||
|
node.operator = this.value;
|
|||
|
node.prefix = false;
|
|||
|
node.argument = expr;
|
|||
|
this.checkLVal(expr);
|
|||
|
this.next();
|
|||
|
expr = this.finishNode(node, "UpdateExpression");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (!sawUnary && this.eat(_tokentype.types.starstar)) return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false);else return expr;
|
|||
|
};
|
|||
|
|
|||
|
// Parse call, dot, and `[]`-subscript expressions.
|
|||
|
|
|||
|
pp.parseExprSubscripts = function (refDestructuringErrors) {
|
|||
|
var startPos = this.start,
|
|||
|
startLoc = this.startLoc;
|
|||
|
var expr = this.parseExprAtom(refDestructuringErrors);
|
|||
|
var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
|
|||
|
if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) return expr;
|
|||
|
return this.parseSubscripts(expr, startPos, startLoc);
|
|||
|
};
|
|||
|
|
|||
|
pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {
|
|||
|
for (;;) {
|
|||
|
if (this.eat(_tokentype.types.dot)) {
|
|||
|
var node = this.startNodeAt(startPos, startLoc);
|
|||
|
node.object = base;
|
|||
|
node.property = this.parseIdent(true);
|
|||
|
node.computed = false;
|
|||
|
base = this.finishNode(node, "MemberExpression");
|
|||
|
} else if (this.eat(_tokentype.types.bracketL)) {
|
|||
|
var node = this.startNodeAt(startPos, startLoc);
|
|||
|
node.object = base;
|
|||
|
node.property = this.parseExpression();
|
|||
|
node.computed = true;
|
|||
|
this.expect(_tokentype.types.bracketR);
|
|||
|
base = this.finishNode(node, "MemberExpression");
|
|||
|
} else if (!noCalls && this.eat(_tokentype.types.parenL)) {
|
|||
|
var node = this.startNodeAt(startPos, startLoc);
|
|||
|
node.callee = base;
|
|||
|
node.arguments = this.parseExprList(_tokentype.types.parenR, false);
|
|||
|
base = this.finishNode(node, "CallExpression");
|
|||
|
} else if (this.type === _tokentype.types.backQuote) {
|
|||
|
var node = this.startNodeAt(startPos, startLoc);
|
|||
|
node.tag = base;
|
|||
|
node.quasi = this.parseTemplate();
|
|||
|
base = this.finishNode(node, "TaggedTemplateExpression");
|
|||
|
} else {
|
|||
|
return base;
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Parse an atomic expression — either a single token that is an
|
|||
|
// expression, an expression started by a keyword like `function` or
|
|||
|
// `new`, or an expression wrapped in punctuation like `()`, `[]`,
|
|||
|
// or `{}`.
|
|||
|
|
|||
|
pp.parseExprAtom = function (refDestructuringErrors) {
|
|||
|
var node = undefined,
|
|||
|
canBeArrow = this.potentialArrowAt == this.start;
|
|||
|
switch (this.type) {
|
|||
|
case _tokentype.types._super:
|
|||
|
if (!this.inFunction) this.raise(this.start, "'super' outside of function or class");
|
|||
|
|
|||
|
case _tokentype.types._this:
|
|||
|
var type = this.type === _tokentype.types._this ? "ThisExpression" : "Super";
|
|||
|
node = this.startNode();
|
|||
|
this.next();
|
|||
|
return this.finishNode(node, type);
|
|||
|
|
|||
|
case _tokentype.types.name:
|
|||
|
var startPos = this.start,
|
|||
|
startLoc = this.startLoc;
|
|||
|
var id = this.parseIdent(this.type !== _tokentype.types.name);
|
|||
|
if (canBeArrow && !this.canInsertSemicolon() && this.eat(_tokentype.types.arrow)) return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id]);
|
|||
|
return id;
|
|||
|
|
|||
|
case _tokentype.types.regexp:
|
|||
|
var value = this.value;
|
|||
|
node = this.parseLiteral(value.value);
|
|||
|
node.regex = { pattern: value.pattern, flags: value.flags };
|
|||
|
return node;
|
|||
|
|
|||
|
case _tokentype.types.num:case _tokentype.types.string:
|
|||
|
return this.parseLiteral(this.value);
|
|||
|
|
|||
|
case _tokentype.types._null:case _tokentype.types._true:case _tokentype.types._false:
|
|||
|
node = this.startNode();
|
|||
|
node.value = this.type === _tokentype.types._null ? null : this.type === _tokentype.types._true;
|
|||
|
node.raw = this.type.keyword;
|
|||
|
this.next();
|
|||
|
return this.finishNode(node, "Literal");
|
|||
|
|
|||
|
case _tokentype.types.parenL:
|
|||
|
return this.parseParenAndDistinguishExpression(canBeArrow);
|
|||
|
|
|||
|
case _tokentype.types.bracketL:
|
|||
|
node = this.startNode();
|
|||
|
this.next();
|
|||
|
node.elements = this.parseExprList(_tokentype.types.bracketR, true, true, refDestructuringErrors);
|
|||
|
return this.finishNode(node, "ArrayExpression");
|
|||
|
|
|||
|
case _tokentype.types.braceL:
|
|||
|
return this.parseObj(false, refDestructuringErrors);
|
|||
|
|
|||
|
case _tokentype.types._function:
|
|||
|
node = this.startNode();
|
|||
|
this.next();
|
|||
|
return this.parseFunction(node, false);
|
|||
|
|
|||
|
case _tokentype.types._class:
|
|||
|
return this.parseClass(this.startNode(), false);
|
|||
|
|
|||
|
case _tokentype.types._new:
|
|||
|
return this.parseNew();
|
|||
|
|
|||
|
case _tokentype.types.backQuote:
|
|||
|
return this.parseTemplate();
|
|||
|
|
|||
|
default:
|
|||
|
this.unexpected();
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
pp.parseLiteral = function (value) {
|
|||
|
var node = this.startNode();
|
|||
|
node.value = value;
|
|||
|
node.raw = this.input.slice(this.start, this.end);
|
|||
|
this.next();
|
|||
|
return this.finishNode(node, "Literal");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseParenExpression = function () {
|
|||
|
this.expect(_tokentype.types.parenL);
|
|||
|
var val = this.parseExpression();
|
|||
|
this.expect(_tokentype.types.parenR);
|
|||
|
return val;
|
|||
|
};
|
|||
|
|
|||
|
pp.parseParenAndDistinguishExpression = function (canBeArrow) {
|
|||
|
var startPos = this.start,
|
|||
|
startLoc = this.startLoc,
|
|||
|
val = undefined;
|
|||
|
if (this.options.ecmaVersion >= 6) {
|
|||
|
this.next();
|
|||
|
|
|||
|
var innerStartPos = this.start,
|
|||
|
innerStartLoc = this.startLoc;
|
|||
|
var exprList = [],
|
|||
|
first = true;
|
|||
|
var refDestructuringErrors = new _parseutil.DestructuringErrors(),
|
|||
|
spreadStart = undefined,
|
|||
|
innerParenStart = undefined;
|
|||
|
while (this.type !== _tokentype.types.parenR) {
|
|||
|
first ? first = false : this.expect(_tokentype.types.comma);
|
|||
|
if (this.type === _tokentype.types.ellipsis) {
|
|||
|
spreadStart = this.start;
|
|||
|
exprList.push(this.parseParenItem(this.parseRest()));
|
|||
|
break;
|
|||
|
} else {
|
|||
|
if (this.type === _tokentype.types.parenL && !innerParenStart) {
|
|||
|
innerParenStart = this.start;
|
|||
|
}
|
|||
|
exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
|
|||
|
}
|
|||
|
}
|
|||
|
var innerEndPos = this.start,
|
|||
|
innerEndLoc = this.startLoc;
|
|||
|
this.expect(_tokentype.types.parenR);
|
|||
|
|
|||
|
if (canBeArrow && !this.canInsertSemicolon() && this.eat(_tokentype.types.arrow)) {
|
|||
|
this.checkPatternErrors(refDestructuringErrors, true);
|
|||
|
if (innerParenStart) this.unexpected(innerParenStart);
|
|||
|
return this.parseParenArrowList(startPos, startLoc, exprList);
|
|||
|
}
|
|||
|
|
|||
|
if (!exprList.length) this.unexpected(this.lastTokStart);
|
|||
|
if (spreadStart) this.unexpected(spreadStart);
|
|||
|
this.checkExpressionErrors(refDestructuringErrors, true);
|
|||
|
|
|||
|
if (exprList.length > 1) {
|
|||
|
val = this.startNodeAt(innerStartPos, innerStartLoc);
|
|||
|
val.expressions = exprList;
|
|||
|
this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
|
|||
|
} else {
|
|||
|
val = exprList[0];
|
|||
|
}
|
|||
|
} else {
|
|||
|
val = this.parseParenExpression();
|
|||
|
}
|
|||
|
|
|||
|
if (this.options.preserveParens) {
|
|||
|
var par = this.startNodeAt(startPos, startLoc);
|
|||
|
par.expression = val;
|
|||
|
return this.finishNode(par, "ParenthesizedExpression");
|
|||
|
} else {
|
|||
|
return val;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
pp.parseParenItem = function (item) {
|
|||
|
return item;
|
|||
|
};
|
|||
|
|
|||
|
pp.parseParenArrowList = function (startPos, startLoc, exprList) {
|
|||
|
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList);
|
|||
|
};
|
|||
|
|
|||
|
// New's precedence is slightly tricky. It must allow its argument to
|
|||
|
// be a `[]` or dot subscript expression, but not a call — at least,
|
|||
|
// not without wrapping it in parentheses. Thus, it uses the noCalls
|
|||
|
// argument to parseSubscripts to prevent it from consuming the
|
|||
|
// argument list.
|
|||
|
|
|||
|
var empty = [];
|
|||
|
|
|||
|
pp.parseNew = function () {
|
|||
|
var node = this.startNode();
|
|||
|
var meta = this.parseIdent(true);
|
|||
|
if (this.options.ecmaVersion >= 6 && this.eat(_tokentype.types.dot)) {
|
|||
|
node.meta = meta;
|
|||
|
node.property = this.parseIdent(true);
|
|||
|
if (node.property.name !== "target") this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target");
|
|||
|
if (!this.inFunction) this.raiseRecoverable(node.start, "new.target can only be used in functions");
|
|||
|
return this.finishNode(node, "MetaProperty");
|
|||
|
}
|
|||
|
var startPos = this.start,
|
|||
|
startLoc = this.startLoc;
|
|||
|
node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
|
|||
|
if (this.eat(_tokentype.types.parenL)) node.arguments = this.parseExprList(_tokentype.types.parenR, false);else node.arguments = empty;
|
|||
|
return this.finishNode(node, "NewExpression");
|
|||
|
};
|
|||
|
|
|||
|
// Parse template expression.
|
|||
|
|
|||
|
pp.parseTemplateElement = function () {
|
|||
|
var elem = this.startNode();
|
|||
|
elem.value = {
|
|||
|
raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, '\n'),
|
|||
|
cooked: this.value
|
|||
|
};
|
|||
|
this.next();
|
|||
|
elem.tail = this.type === _tokentype.types.backQuote;
|
|||
|
return this.finishNode(elem, "TemplateElement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseTemplate = function () {
|
|||
|
var node = this.startNode();
|
|||
|
this.next();
|
|||
|
node.expressions = [];
|
|||
|
var curElt = this.parseTemplateElement();
|
|||
|
node.quasis = [curElt];
|
|||
|
while (!curElt.tail) {
|
|||
|
this.expect(_tokentype.types.dollarBraceL);
|
|||
|
node.expressions.push(this.parseExpression());
|
|||
|
this.expect(_tokentype.types.braceR);
|
|||
|
node.quasis.push(curElt = this.parseTemplateElement());
|
|||
|
}
|
|||
|
this.next();
|
|||
|
return this.finishNode(node, "TemplateLiteral");
|
|||
|
};
|
|||
|
|
|||
|
// Parse an object literal or binding pattern.
|
|||
|
|
|||
|
pp.parseObj = function (isPattern, refDestructuringErrors) {
|
|||
|
var node = this.startNode(),
|
|||
|
first = true,
|
|||
|
propHash = {};
|
|||
|
node.properties = [];
|
|||
|
this.next();
|
|||
|
while (!this.eat(_tokentype.types.braceR)) {
|
|||
|
if (!first) {
|
|||
|
this.expect(_tokentype.types.comma);
|
|||
|
if (this.afterTrailingComma(_tokentype.types.braceR)) break;
|
|||
|
} else first = false;
|
|||
|
|
|||
|
var prop = this.startNode(),
|
|||
|
isGenerator = undefined,
|
|||
|
startPos = undefined,
|
|||
|
startLoc = undefined;
|
|||
|
if (this.options.ecmaVersion >= 6) {
|
|||
|
prop.method = false;
|
|||
|
prop.shorthand = false;
|
|||
|
if (isPattern || refDestructuringErrors) {
|
|||
|
startPos = this.start;
|
|||
|
startLoc = this.startLoc;
|
|||
|
}
|
|||
|
if (!isPattern) isGenerator = this.eat(_tokentype.types.star);
|
|||
|
}
|
|||
|
this.parsePropertyName(prop);
|
|||
|
this.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors);
|
|||
|
this.checkPropClash(prop, propHash);
|
|||
|
node.properties.push(this.finishNode(prop, "Property"));
|
|||
|
}
|
|||
|
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression");
|
|||
|
};
|
|||
|
|
|||
|
pp.parsePropertyValue = function (prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors) {
|
|||
|
if (this.eat(_tokentype.types.colon)) {
|
|||
|
prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
|
|||
|
prop.kind = "init";
|
|||
|
} else if (this.options.ecmaVersion >= 6 && this.type === _tokentype.types.parenL) {
|
|||
|
if (isPattern) this.unexpected();
|
|||
|
prop.kind = "init";
|
|||
|
prop.method = true;
|
|||
|
prop.value = this.parseMethod(isGenerator);
|
|||
|
} else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && this.type != _tokentype.types.comma && this.type != _tokentype.types.braceR) {
|
|||
|
if (isGenerator || isPattern) this.unexpected();
|
|||
|
prop.kind = prop.key.name;
|
|||
|
this.parsePropertyName(prop);
|
|||
|
prop.value = this.parseMethod(false);
|
|||
|
var paramCount = prop.kind === "get" ? 0 : 1;
|
|||
|
if (prop.value.params.length !== paramCount) {
|
|||
|
var start = prop.value.start;
|
|||
|
if (prop.kind === "get") this.raiseRecoverable(start, "getter should have no params");else this.raiseRecoverable(start, "setter should have exactly one param");
|
|||
|
}
|
|||
|
if (prop.kind === "set" && prop.value.params[0].type === "RestElement") this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params");
|
|||
|
} else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
|
|||
|
if (this.keywords.test(prop.key.name) || (this.strict ? this.reservedWordsStrictBind : this.reservedWords).test(prop.key.name) || this.inGenerator && prop.key.name == "yield") this.raiseRecoverable(prop.key.start, "'" + prop.key.name + "' can not be used as shorthand property");
|
|||
|
prop.kind = "init";
|
|||
|
if (isPattern) {
|
|||
|
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
|
|||
|
} else if (this.type === _tokentype.types.eq && refDestructuringErrors) {
|
|||
|
if (!refDestructuringErrors.shorthandAssign) refDestructuringErrors.shorthandAssign = this.start;
|
|||
|
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
|
|||
|
} else {
|
|||
|
prop.value = prop.key;
|
|||
|
}
|
|||
|
prop.shorthand = true;
|
|||
|
} else this.unexpected();
|
|||
|
};
|
|||
|
|
|||
|
pp.parsePropertyName = function (prop) {
|
|||
|
if (this.options.ecmaVersion >= 6) {
|
|||
|
if (this.eat(_tokentype.types.bracketL)) {
|
|||
|
prop.computed = true;
|
|||
|
prop.key = this.parseMaybeAssign();
|
|||
|
this.expect(_tokentype.types.bracketR);
|
|||
|
return prop.key;
|
|||
|
} else {
|
|||
|
prop.computed = false;
|
|||
|
}
|
|||
|
}
|
|||
|
return prop.key = this.type === _tokentype.types.num || this.type === _tokentype.types.string ? this.parseExprAtom() : this.parseIdent(true);
|
|||
|
};
|
|||
|
|
|||
|
// Initialize empty function node.
|
|||
|
|
|||
|
pp.initFunction = function (node) {
|
|||
|
node.id = null;
|
|||
|
if (this.options.ecmaVersion >= 6) {
|
|||
|
node.generator = false;
|
|||
|
node.expression = false;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Parse object or class method.
|
|||
|
|
|||
|
pp.parseMethod = function (isGenerator) {
|
|||
|
var node = this.startNode(),
|
|||
|
oldInGen = this.inGenerator;
|
|||
|
this.inGenerator = isGenerator;
|
|||
|
this.initFunction(node);
|
|||
|
this.expect(_tokentype.types.parenL);
|
|||
|
node.params = this.parseBindingList(_tokentype.types.parenR, false, false);
|
|||
|
if (this.options.ecmaVersion >= 6) node.generator = isGenerator;
|
|||
|
this.parseFunctionBody(node, false);
|
|||
|
this.inGenerator = oldInGen;
|
|||
|
return this.finishNode(node, "FunctionExpression");
|
|||
|
};
|
|||
|
|
|||
|
// Parse arrow function expression with given parameters.
|
|||
|
|
|||
|
pp.parseArrowExpression = function (node, params) {
|
|||
|
var oldInGen = this.inGenerator;
|
|||
|
this.inGenerator = false;
|
|||
|
this.initFunction(node);
|
|||
|
node.params = this.toAssignableList(params, true);
|
|||
|
this.parseFunctionBody(node, true);
|
|||
|
this.inGenerator = oldInGen;
|
|||
|
return this.finishNode(node, "ArrowFunctionExpression");
|
|||
|
};
|
|||
|
|
|||
|
// Parse function body and check parameters.
|
|||
|
|
|||
|
pp.parseFunctionBody = function (node, isArrowFunction) {
|
|||
|
var isExpression = isArrowFunction && this.type !== _tokentype.types.braceL;
|
|||
|
|
|||
|
if (isExpression) {
|
|||
|
node.body = this.parseMaybeAssign();
|
|||
|
node.expression = true;
|
|||
|
} else {
|
|||
|
// Start a new scope with regard to labels and the `inFunction`
|
|||
|
// flag (restore them to their old value afterwards).
|
|||
|
var oldInFunc = this.inFunction,
|
|||
|
oldLabels = this.labels;
|
|||
|
this.inFunction = true;this.labels = [];
|
|||
|
node.body = this.parseBlock(true);
|
|||
|
node.expression = false;
|
|||
|
this.inFunction = oldInFunc;this.labels = oldLabels;
|
|||
|
}
|
|||
|
|
|||
|
// If this is a strict mode function, verify that argument names
|
|||
|
// are not repeated, and it does not try to bind the words `eval`
|
|||
|
// or `arguments`.
|
|||
|
if (this.strict || !isExpression && node.body.body.length && this.isUseStrict(node.body.body[0])) {
|
|||
|
var oldStrict = this.strict;
|
|||
|
this.strict = true;
|
|||
|
if (node.id) this.checkLVal(node.id, true);
|
|||
|
this.checkParams(node);
|
|||
|
this.strict = oldStrict;
|
|||
|
} else if (isArrowFunction) {
|
|||
|
this.checkParams(node);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Checks function params for various disallowed patterns such as using "eval"
|
|||
|
// or "arguments" and duplicate parameters.
|
|||
|
|
|||
|
pp.checkParams = function (node) {
|
|||
|
var nameHash = {};
|
|||
|
for (var i = 0; i < node.params.length; i++) {
|
|||
|
this.checkLVal(node.params[i], true, nameHash);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Parses a comma-separated list of expressions, and returns them as
|
|||
|
// an array. `close` is the token type that ends the list, and
|
|||
|
// `allowEmpty` can be turned on to allow subsequent commas with
|
|||
|
// nothing in between them to be parsed as `null` (which is needed
|
|||
|
// for array literals).
|
|||
|
|
|||
|
pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
|
|||
|
var elts = [],
|
|||
|
first = true;
|
|||
|
while (!this.eat(close)) {
|
|||
|
if (!first) {
|
|||
|
this.expect(_tokentype.types.comma);
|
|||
|
if (allowTrailingComma && this.afterTrailingComma(close)) break;
|
|||
|
} else first = false;
|
|||
|
|
|||
|
var elt = undefined;
|
|||
|
if (allowEmpty && this.type === _tokentype.types.comma) elt = null;else if (this.type === _tokentype.types.ellipsis) {
|
|||
|
elt = this.parseSpread(refDestructuringErrors);
|
|||
|
if (this.type === _tokentype.types.comma && refDestructuringErrors && !refDestructuringErrors.trailingComma) {
|
|||
|
refDestructuringErrors.trailingComma = this.lastTokStart;
|
|||
|
}
|
|||
|
} else elt = this.parseMaybeAssign(false, refDestructuringErrors);
|
|||
|
elts.push(elt);
|
|||
|
}
|
|||
|
return elts;
|
|||
|
};
|
|||
|
|
|||
|
// Parse the next token as an identifier. If `liberal` is true (used
|
|||
|
// when parsing properties), it will also convert keywords into
|
|||
|
// identifiers.
|
|||
|
|
|||
|
pp.parseIdent = function (liberal) {
|
|||
|
var node = this.startNode();
|
|||
|
if (liberal && this.options.allowReserved == "never") liberal = false;
|
|||
|
if (this.type === _tokentype.types.name) {
|
|||
|
if (!liberal && (this.strict ? this.reservedWordsStrict : this.reservedWords).test(this.value) && (this.options.ecmaVersion >= 6 || this.input.slice(this.start, this.end).indexOf("\\") == -1)) this.raiseRecoverable(this.start, "The keyword '" + this.value + "' is reserved");
|
|||
|
if (!liberal && this.inGenerator && this.value === "yield") this.raiseRecoverable(this.start, "Can not use 'yield' as identifier inside a generator");
|
|||
|
node.name = this.value;
|
|||
|
} else if (liberal && this.type.keyword) {
|
|||
|
node.name = this.type.keyword;
|
|||
|
} else {
|
|||
|
this.unexpected();
|
|||
|
}
|
|||
|
this.next();
|
|||
|
return this.finishNode(node, "Identifier");
|
|||
|
};
|
|||
|
|
|||
|
// Parses yield expression inside generator.
|
|||
|
|
|||
|
pp.parseYield = function () {
|
|||
|
var node = this.startNode();
|
|||
|
this.next();
|
|||
|
if (this.type == _tokentype.types.semi || this.canInsertSemicolon() || this.type != _tokentype.types.star && !this.type.startsExpr) {
|
|||
|
node.delegate = false;
|
|||
|
node.argument = null;
|
|||
|
} else {
|
|||
|
node.delegate = this.eat(_tokentype.types.star);
|
|||
|
node.argument = this.parseMaybeAssign();
|
|||
|
}
|
|||
|
return this.finishNode(node, "YieldExpression");
|
|||
|
};
|
|||
|
|
|||
|
},{"./parseutil":9,"./state":10,"./tokentype":14}],2:[function(_dereq_,module,exports){
|
|||
|
// Reserved word lists for various dialects of the language
|
|||
|
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
exports.isIdentifierStart = isIdentifierStart;
|
|||
|
exports.isIdentifierChar = isIdentifierChar;
|
|||
|
var reservedWords = {
|
|||
|
3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
|
|||
|
5: "class enum extends super const export import",
|
|||
|
6: "enum",
|
|||
|
7: "enum",
|
|||
|
strict: "implements interface let package private protected public static yield",
|
|||
|
strictBind: "eval arguments"
|
|||
|
};
|
|||
|
|
|||
|
exports.reservedWords = reservedWords;
|
|||
|
// And the keywords
|
|||
|
|
|||
|
var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
|
|||
|
|
|||
|
var keywords = {
|
|||
|
5: ecma5AndLessKeywords,
|
|||
|
6: ecma5AndLessKeywords + " const class extends export import super"
|
|||
|
};
|
|||
|
|
|||
|
exports.keywords = keywords;
|
|||
|
// ## Character categories
|
|||
|
|
|||
|
// Big ugly regular expressions that match characters in the
|
|||
|
// whitespace, identifier, and identifier-start categories. These
|
|||
|
// are only applied when a character is found to actually have a
|
|||
|
// code point above 128.
|
|||
|
// Generated by `bin/generate-identifier-regex.js`.
|
|||
|
|
|||
|
var nonASCIIidentifierStartChars = "ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠ-ࢴऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡૹଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘ-ౚౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൟ-ൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿕ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞭꞰ-ꞷꟷ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꣽꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭥꭰ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ";
|
|||
|
var nonASCIIidentifierChars = "·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛ࣣ-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఃా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ഁ-ഃാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ංඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ູົຼ່-ໍ໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠐-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭ᳲ-᳴᳸᳹᷀-᷵᷼-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-꣄꣐-꣙꣠-꣱꤀-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍-﹏0-9_";
|
|||
|
|
|||
|
var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
|
|||
|
var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
|
|||
|
|
|||
|
nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
|
|||
|
|
|||
|
// These are a run-length and offset encoded representation of the
|
|||
|
// >0xffff code points that are a valid part of identifiers. The
|
|||
|
// offset starts at 0x10000, and each pair of numbers represents an
|
|||
|
// offset to the next range, and then a size of the range. They were
|
|||
|
// generated by bin/generate-identifier-regex.js
|
|||
|
var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 17, 26, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 99, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 26, 45, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 785, 52, 76, 44, 33, 24, 27, 35, 42, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 287, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 86, 25, 391, 63, 32, 0, 449, 56, 1288, 921, 103, 110, 18, 195, 2749, 1070, 4050, 582, 8634, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 881, 68, 12, 0, 67, 12, 16481, 1, 3071, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 4149, 196, 1340, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42710, 42, 4148, 12, 221, 3, 5761, 10591, 541];
|
|||
|
var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 1306, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 52, 0, 13, 2, 49, 13, 10, 2, 4, 9, 83, 11, 168, 11, 6, 9, 7, 3, 57, 0, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 316, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 423, 9, 20855, 9, 135, 4, 60, 6, 26, 9, 1016, 45, 17, 3, 19723, 1, 5319, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 3617, 6, 792618, 239];
|
|||
|
|
|||
|
// This has a complexity linear to the value of the code. The
|
|||
|
// assumption is that looking up astral identifier characters is
|
|||
|
// rare.
|
|||
|
function isInAstralSet(code, set) {
|
|||
|
var pos = 0x10000;
|
|||
|
for (var i = 0; i < set.length; i += 2) {
|
|||
|
pos += set[i];
|
|||
|
if (pos > code) return false;
|
|||
|
pos += set[i + 1];
|
|||
|
if (pos >= code) return true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Test whether a given character code starts an identifier.
|
|||
|
|
|||
|
function isIdentifierStart(code, astral) {
|
|||
|
if (code < 65) return code === 36;
|
|||
|
if (code < 91) return true;
|
|||
|
if (code < 97) return code === 95;
|
|||
|
if (code < 123) return true;
|
|||
|
if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
|
|||
|
if (astral === false) return false;
|
|||
|
return isInAstralSet(code, astralIdentifierStartCodes);
|
|||
|
}
|
|||
|
|
|||
|
// Test whether a given character is part of an identifier.
|
|||
|
|
|||
|
function isIdentifierChar(code, astral) {
|
|||
|
if (code < 48) return code === 36;
|
|||
|
if (code < 58) return true;
|
|||
|
if (code < 65) return false;
|
|||
|
if (code < 91) return true;
|
|||
|
if (code < 97) return code === 95;
|
|||
|
if (code < 123) return true;
|
|||
|
if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
|
|||
|
if (astral === false) return false;
|
|||
|
return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
|
|||
|
}
|
|||
|
|
|||
|
},{}],3:[function(_dereq_,module,exports){
|
|||
|
// Acorn is a tiny, fast JavaScript parser written in JavaScript.
|
|||
|
//
|
|||
|
// Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
|
|||
|
// various contributors and released under an MIT license.
|
|||
|
//
|
|||
|
// Git repositories for Acorn are available at
|
|||
|
//
|
|||
|
// http://marijnhaverbeke.nl/git/acorn
|
|||
|
// https://github.com/ternjs/acorn.git
|
|||
|
//
|
|||
|
// Please use the [github bug tracker][ghbt] to report issues.
|
|||
|
//
|
|||
|
// [ghbt]: https://github.com/ternjs/acorn/issues
|
|||
|
//
|
|||
|
// This file defines the main parser interface. The library also comes
|
|||
|
// with a [error-tolerant parser][dammit] and an
|
|||
|
// [abstract syntax tree walker][walk], defined in other files.
|
|||
|
//
|
|||
|
// [dammit]: acorn_loose.js
|
|||
|
// [walk]: util/walk.js
|
|||
|
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
exports.parse = parse;
|
|||
|
exports.parseExpressionAt = parseExpressionAt;
|
|||
|
exports.tokenizer = tokenizer;
|
|||
|
|
|||
|
var _state = _dereq_("./state");
|
|||
|
|
|||
|
_dereq_("./parseutil");
|
|||
|
|
|||
|
_dereq_("./statement");
|
|||
|
|
|||
|
_dereq_("./lval");
|
|||
|
|
|||
|
_dereq_("./expression");
|
|||
|
|
|||
|
_dereq_("./location");
|
|||
|
|
|||
|
exports.Parser = _state.Parser;
|
|||
|
exports.plugins = _state.plugins;
|
|||
|
|
|||
|
var _options = _dereq_("./options");
|
|||
|
|
|||
|
exports.defaultOptions = _options.defaultOptions;
|
|||
|
|
|||
|
var _locutil = _dereq_("./locutil");
|
|||
|
|
|||
|
exports.Position = _locutil.Position;
|
|||
|
exports.SourceLocation = _locutil.SourceLocation;
|
|||
|
exports.getLineInfo = _locutil.getLineInfo;
|
|||
|
|
|||
|
var _node = _dereq_("./node");
|
|||
|
|
|||
|
exports.Node = _node.Node;
|
|||
|
|
|||
|
var _tokentype = _dereq_("./tokentype");
|
|||
|
|
|||
|
exports.TokenType = _tokentype.TokenType;
|
|||
|
exports.tokTypes = _tokentype.types;
|
|||
|
|
|||
|
var _tokencontext = _dereq_("./tokencontext");
|
|||
|
|
|||
|
exports.TokContext = _tokencontext.TokContext;
|
|||
|
exports.tokContexts = _tokencontext.types;
|
|||
|
|
|||
|
var _identifier = _dereq_("./identifier");
|
|||
|
|
|||
|
exports.isIdentifierChar = _identifier.isIdentifierChar;
|
|||
|
exports.isIdentifierStart = _identifier.isIdentifierStart;
|
|||
|
|
|||
|
var _tokenize = _dereq_("./tokenize");
|
|||
|
|
|||
|
exports.Token = _tokenize.Token;
|
|||
|
|
|||
|
var _whitespace = _dereq_("./whitespace");
|
|||
|
|
|||
|
exports.isNewLine = _whitespace.isNewLine;
|
|||
|
exports.lineBreak = _whitespace.lineBreak;
|
|||
|
exports.lineBreakG = _whitespace.lineBreakG;
|
|||
|
var version = "3.1.0";
|
|||
|
|
|||
|
exports.version = version;
|
|||
|
// The main exported interface (under `self.acorn` when in the
|
|||
|
// browser) is a `parse` function that takes a code string and
|
|||
|
// returns an abstract syntax tree as specified by [Mozilla parser
|
|||
|
// API][api].
|
|||
|
//
|
|||
|
// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
|
|||
|
|
|||
|
function parse(input, options) {
|
|||
|
return new _state.Parser(options, input).parse();
|
|||
|
}
|
|||
|
|
|||
|
// This function tries to parse a single expression at a given
|
|||
|
// offset in a string. Useful for parsing mixed-language formats
|
|||
|
// that embed JavaScript expressions.
|
|||
|
|
|||
|
function parseExpressionAt(input, pos, options) {
|
|||
|
var p = new _state.Parser(options, input, pos);
|
|||
|
p.nextToken();
|
|||
|
return p.parseExpression();
|
|||
|
}
|
|||
|
|
|||
|
// Acorn is organized as a tokenizer and a recursive-descent parser.
|
|||
|
// The `tokenizer` export provides an interface to the tokenizer.
|
|||
|
|
|||
|
function tokenizer(input, options) {
|
|||
|
return new _state.Parser(options, input);
|
|||
|
}
|
|||
|
|
|||
|
},{"./expression":1,"./identifier":2,"./location":4,"./locutil":5,"./lval":6,"./node":7,"./options":8,"./parseutil":9,"./state":10,"./statement":11,"./tokencontext":12,"./tokenize":13,"./tokentype":14,"./whitespace":16}],4:[function(_dereq_,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var _state = _dereq_("./state");
|
|||
|
|
|||
|
var _locutil = _dereq_("./locutil");
|
|||
|
|
|||
|
var pp = _state.Parser.prototype;
|
|||
|
|
|||
|
// This function is used to raise exceptions on parse errors. It
|
|||
|
// takes an offset integer (into the current `input`) to indicate
|
|||
|
// the location of the error, attaches the position to the end
|
|||
|
// of the error message, and then raises a `SyntaxError` with that
|
|||
|
// message.
|
|||
|
|
|||
|
pp.raise = function (pos, message) {
|
|||
|
var loc = _locutil.getLineInfo(this.input, pos);
|
|||
|
message += " (" + loc.line + ":" + loc.column + ")";
|
|||
|
var err = new SyntaxError(message);
|
|||
|
err.pos = pos;err.loc = loc;err.raisedAt = this.pos;
|
|||
|
throw err;
|
|||
|
};
|
|||
|
|
|||
|
pp.raiseRecoverable = pp.raise;
|
|||
|
|
|||
|
pp.curPosition = function () {
|
|||
|
if (this.options.locations) {
|
|||
|
return new _locutil.Position(this.curLine, this.pos - this.lineStart);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
},{"./locutil":5,"./state":10}],5:[function(_dereq_,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
exports.getLineInfo = getLineInfo;
|
|||
|
|
|||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|||
|
|
|||
|
var _whitespace = _dereq_("./whitespace");
|
|||
|
|
|||
|
// These are used when `options.locations` is on, for the
|
|||
|
// `startLoc` and `endLoc` properties.
|
|||
|
|
|||
|
var Position = (function () {
|
|||
|
function Position(line, col) {
|
|||
|
_classCallCheck(this, Position);
|
|||
|
|
|||
|
this.line = line;
|
|||
|
this.column = col;
|
|||
|
}
|
|||
|
|
|||
|
Position.prototype.offset = function offset(n) {
|
|||
|
return new Position(this.line, this.column + n);
|
|||
|
};
|
|||
|
|
|||
|
return Position;
|
|||
|
})();
|
|||
|
|
|||
|
exports.Position = Position;
|
|||
|
|
|||
|
var SourceLocation = function SourceLocation(p, start, end) {
|
|||
|
_classCallCheck(this, SourceLocation);
|
|||
|
|
|||
|
this.start = start;
|
|||
|
this.end = end;
|
|||
|
if (p.sourceFile !== null) this.source = p.sourceFile;
|
|||
|
}
|
|||
|
|
|||
|
// The `getLineInfo` function is mostly useful when the
|
|||
|
// `locations` option is off (for performance reasons) and you
|
|||
|
// want to find the line/column position for a given character
|
|||
|
// offset. `input` should be the code string that the offset refers
|
|||
|
// into.
|
|||
|
|
|||
|
;
|
|||
|
|
|||
|
exports.SourceLocation = SourceLocation;
|
|||
|
|
|||
|
function getLineInfo(input, offset) {
|
|||
|
for (var line = 1, cur = 0;;) {
|
|||
|
_whitespace.lineBreakG.lastIndex = cur;
|
|||
|
var match = _whitespace.lineBreakG.exec(input);
|
|||
|
if (match && match.index < offset) {
|
|||
|
++line;
|
|||
|
cur = match.index + match[0].length;
|
|||
|
} else {
|
|||
|
return new Position(line, offset - cur);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
},{"./whitespace":16}],6:[function(_dereq_,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var _tokentype = _dereq_("./tokentype");
|
|||
|
|
|||
|
var _state = _dereq_("./state");
|
|||
|
|
|||
|
var _util = _dereq_("./util");
|
|||
|
|
|||
|
var pp = _state.Parser.prototype;
|
|||
|
|
|||
|
// Convert existing expression atom to assignable pattern
|
|||
|
// if possible.
|
|||
|
|
|||
|
pp.toAssignable = function (node, isBinding) {
|
|||
|
if (this.options.ecmaVersion >= 6 && node) {
|
|||
|
switch (node.type) {
|
|||
|
case "Identifier":
|
|||
|
case "ObjectPattern":
|
|||
|
case "ArrayPattern":
|
|||
|
break;
|
|||
|
|
|||
|
case "ObjectExpression":
|
|||
|
node.type = "ObjectPattern";
|
|||
|
for (var i = 0; i < node.properties.length; i++) {
|
|||
|
var prop = node.properties[i];
|
|||
|
if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter");
|
|||
|
this.toAssignable(prop.value, isBinding);
|
|||
|
}
|
|||
|
break;
|
|||
|
|
|||
|
case "ArrayExpression":
|
|||
|
node.type = "ArrayPattern";
|
|||
|
this.toAssignableList(node.elements, isBinding);
|
|||
|
break;
|
|||
|
|
|||
|
case "AssignmentExpression":
|
|||
|
if (node.operator === "=") {
|
|||
|
node.type = "AssignmentPattern";
|
|||
|
delete node.operator;
|
|||
|
// falls through to AssignmentPattern
|
|||
|
} else {
|
|||
|
this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
case "AssignmentPattern":
|
|||
|
if (node.right.type === "YieldExpression") this.raise(node.right.start, "Yield expression cannot be a default value");
|
|||
|
break;
|
|||
|
|
|||
|
case "ParenthesizedExpression":
|
|||
|
node.expression = this.toAssignable(node.expression, isBinding);
|
|||
|
break;
|
|||
|
|
|||
|
case "MemberExpression":
|
|||
|
if (!isBinding) break;
|
|||
|
|
|||
|
default:
|
|||
|
this.raise(node.start, "Assigning to rvalue");
|
|||
|
}
|
|||
|
}
|
|||
|
return node;
|
|||
|
};
|
|||
|
|
|||
|
// Convert list of expression atoms to binding list.
|
|||
|
|
|||
|
pp.toAssignableList = function (exprList, isBinding) {
|
|||
|
var end = exprList.length;
|
|||
|
if (end) {
|
|||
|
var last = exprList[end - 1];
|
|||
|
if (last && last.type == "RestElement") {
|
|||
|
--end;
|
|||
|
} else if (last && last.type == "SpreadElement") {
|
|||
|
last.type = "RestElement";
|
|||
|
var arg = last.argument;
|
|||
|
this.toAssignable(arg, isBinding);
|
|||
|
if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") this.unexpected(arg.start);
|
|||
|
--end;
|
|||
|
}
|
|||
|
|
|||
|
if (isBinding && last.type === "RestElement" && last.argument.type !== "Identifier") this.unexpected(last.argument.start);
|
|||
|
}
|
|||
|
for (var i = 0; i < end; i++) {
|
|||
|
var elt = exprList[i];
|
|||
|
if (elt) this.toAssignable(elt, isBinding);
|
|||
|
}
|
|||
|
return exprList;
|
|||
|
};
|
|||
|
|
|||
|
// Parses spread element.
|
|||
|
|
|||
|
pp.parseSpread = function (refDestructuringErrors) {
|
|||
|
var node = this.startNode();
|
|||
|
this.next();
|
|||
|
node.argument = this.parseMaybeAssign(refDestructuringErrors);
|
|||
|
return this.finishNode(node, "SpreadElement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseRest = function (allowNonIdent) {
|
|||
|
var node = this.startNode();
|
|||
|
this.next();
|
|||
|
|
|||
|
// RestElement inside of a function parameter must be an identifier
|
|||
|
if (allowNonIdent) node.argument = this.type === _tokentype.types.name ? this.parseIdent() : this.unexpected();else node.argument = this.type === _tokentype.types.name || this.type === _tokentype.types.bracketL ? this.parseBindingAtom() : this.unexpected();
|
|||
|
|
|||
|
return this.finishNode(node, "RestElement");
|
|||
|
};
|
|||
|
|
|||
|
// Parses lvalue (assignable) atom.
|
|||
|
|
|||
|
pp.parseBindingAtom = function () {
|
|||
|
if (this.options.ecmaVersion < 6) return this.parseIdent();
|
|||
|
switch (this.type) {
|
|||
|
case _tokentype.types.name:
|
|||
|
return this.parseIdent();
|
|||
|
|
|||
|
case _tokentype.types.bracketL:
|
|||
|
var node = this.startNode();
|
|||
|
this.next();
|
|||
|
node.elements = this.parseBindingList(_tokentype.types.bracketR, true, true);
|
|||
|
return this.finishNode(node, "ArrayPattern");
|
|||
|
|
|||
|
case _tokentype.types.braceL:
|
|||
|
return this.parseObj(true);
|
|||
|
|
|||
|
default:
|
|||
|
this.unexpected();
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
pp.parseBindingList = function (close, allowEmpty, allowTrailingComma, allowNonIdent) {
|
|||
|
var elts = [],
|
|||
|
first = true;
|
|||
|
while (!this.eat(close)) {
|
|||
|
if (first) first = false;else this.expect(_tokentype.types.comma);
|
|||
|
if (allowEmpty && this.type === _tokentype.types.comma) {
|
|||
|
elts.push(null);
|
|||
|
} else if (allowTrailingComma && this.afterTrailingComma(close)) {
|
|||
|
break;
|
|||
|
} else if (this.type === _tokentype.types.ellipsis) {
|
|||
|
var rest = this.parseRest(allowNonIdent);
|
|||
|
this.parseBindingListItem(rest);
|
|||
|
elts.push(rest);
|
|||
|
if (this.type === _tokentype.types.comma) this.raise(this.start, "Comma is not permitted after the rest element");
|
|||
|
this.expect(close);
|
|||
|
break;
|
|||
|
} else {
|
|||
|
var elem = this.parseMaybeDefault(this.start, this.startLoc);
|
|||
|
this.parseBindingListItem(elem);
|
|||
|
elts.push(elem);
|
|||
|
}
|
|||
|
}
|
|||
|
return elts;
|
|||
|
};
|
|||
|
|
|||
|
pp.parseBindingListItem = function (param) {
|
|||
|
return param;
|
|||
|
};
|
|||
|
|
|||
|
// Parses assignment pattern around given atom if possible.
|
|||
|
|
|||
|
pp.parseMaybeDefault = function (startPos, startLoc, left) {
|
|||
|
left = left || this.parseBindingAtom();
|
|||
|
if (this.options.ecmaVersion < 6 || !this.eat(_tokentype.types.eq)) return left;
|
|||
|
var node = this.startNodeAt(startPos, startLoc);
|
|||
|
node.left = left;
|
|||
|
node.right = this.parseMaybeAssign();
|
|||
|
return this.finishNode(node, "AssignmentPattern");
|
|||
|
};
|
|||
|
|
|||
|
// Verify that a node is an lval — something that can be assigned
|
|||
|
// to.
|
|||
|
|
|||
|
pp.checkLVal = function (expr, isBinding, checkClashes) {
|
|||
|
switch (expr.type) {
|
|||
|
case "Identifier":
|
|||
|
if (this.strict && this.reservedWordsStrictBind.test(expr.name)) this.raiseRecoverable(expr.start, (isBinding ? "Binding " : "Assigning to ") + expr.name + " in strict mode");
|
|||
|
if (checkClashes) {
|
|||
|
if (_util.has(checkClashes, expr.name)) this.raiseRecoverable(expr.start, "Argument name clash");
|
|||
|
checkClashes[expr.name] = true;
|
|||
|
}
|
|||
|
break;
|
|||
|
|
|||
|
case "MemberExpression":
|
|||
|
if (isBinding) this.raiseRecoverable(expr.start, (isBinding ? "Binding" : "Assigning to") + " member expression");
|
|||
|
break;
|
|||
|
|
|||
|
case "ObjectPattern":
|
|||
|
for (var i = 0; i < expr.properties.length; i++) {
|
|||
|
this.checkLVal(expr.properties[i].value, isBinding, checkClashes);
|
|||
|
}break;
|
|||
|
|
|||
|
case "ArrayPattern":
|
|||
|
for (var i = 0; i < expr.elements.length; i++) {
|
|||
|
var elem = expr.elements[i];
|
|||
|
if (elem) this.checkLVal(elem, isBinding, checkClashes);
|
|||
|
}
|
|||
|
break;
|
|||
|
|
|||
|
case "AssignmentPattern":
|
|||
|
this.checkLVal(expr.left, isBinding, checkClashes);
|
|||
|
break;
|
|||
|
|
|||
|
case "RestElement":
|
|||
|
this.checkLVal(expr.argument, isBinding, checkClashes);
|
|||
|
break;
|
|||
|
|
|||
|
case "ParenthesizedExpression":
|
|||
|
this.checkLVal(expr.expression, isBinding, checkClashes);
|
|||
|
break;
|
|||
|
|
|||
|
default:
|
|||
|
this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue");
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
},{"./state":10,"./tokentype":14,"./util":15}],7:[function(_dereq_,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
|
|||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|||
|
|
|||
|
var _state = _dereq_("./state");
|
|||
|
|
|||
|
var _locutil = _dereq_("./locutil");
|
|||
|
|
|||
|
var Node = function Node(parser, pos, loc) {
|
|||
|
_classCallCheck(this, Node);
|
|||
|
|
|||
|
this.type = "";
|
|||
|
this.start = pos;
|
|||
|
this.end = 0;
|
|||
|
if (parser.options.locations) this.loc = new _locutil.SourceLocation(parser, loc);
|
|||
|
if (parser.options.directSourceFile) this.sourceFile = parser.options.directSourceFile;
|
|||
|
if (parser.options.ranges) this.range = [pos, 0];
|
|||
|
}
|
|||
|
|
|||
|
// Start an AST node, attaching a start offset.
|
|||
|
|
|||
|
;
|
|||
|
|
|||
|
exports.Node = Node;
|
|||
|
var pp = _state.Parser.prototype;
|
|||
|
|
|||
|
pp.startNode = function () {
|
|||
|
return new Node(this, this.start, this.startLoc);
|
|||
|
};
|
|||
|
|
|||
|
pp.startNodeAt = function (pos, loc) {
|
|||
|
return new Node(this, pos, loc);
|
|||
|
};
|
|||
|
|
|||
|
// Finish an AST node, adding `type` and `end` properties.
|
|||
|
|
|||
|
function finishNodeAt(node, type, pos, loc) {
|
|||
|
node.type = type;
|
|||
|
node.end = pos;
|
|||
|
if (this.options.locations) node.loc.end = loc;
|
|||
|
if (this.options.ranges) node.range[1] = pos;
|
|||
|
return node;
|
|||
|
}
|
|||
|
|
|||
|
pp.finishNode = function (node, type) {
|
|||
|
return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc);
|
|||
|
};
|
|||
|
|
|||
|
// Finish node at given position
|
|||
|
|
|||
|
pp.finishNodeAt = function (node, type, pos, loc) {
|
|||
|
return finishNodeAt.call(this, node, type, pos, loc);
|
|||
|
};
|
|||
|
|
|||
|
},{"./locutil":5,"./state":10}],8:[function(_dereq_,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
exports.getOptions = getOptions;
|
|||
|
|
|||
|
var _util = _dereq_("./util");
|
|||
|
|
|||
|
var _locutil = _dereq_("./locutil");
|
|||
|
|
|||
|
// A second optional argument can be given to further configure
|
|||
|
// the parser process. These options are recognized:
|
|||
|
|
|||
|
var defaultOptions = {
|
|||
|
// `ecmaVersion` indicates the ECMAScript version to parse. Must
|
|||
|
// be either 3, or 5, or 6. This influences support for strict
|
|||
|
// mode, the set of reserved words, support for getters and
|
|||
|
// setters and other features. The default is 6.
|
|||
|
ecmaVersion: 6,
|
|||
|
// Source type ("script" or "module") for different semantics
|
|||
|
sourceType: "script",
|
|||
|
// `onInsertedSemicolon` can be a callback that will be called
|
|||
|
// when a semicolon is automatically inserted. It will be passed
|
|||
|
// th position of the comma as an offset, and if `locations` is
|
|||
|
// enabled, it is given the location as a `{line, column}` object
|
|||
|
// as second argument.
|
|||
|
onInsertedSemicolon: null,
|
|||
|
// `onTrailingComma` is similar to `onInsertedSemicolon`, but for
|
|||
|
// trailing commas.
|
|||
|
onTrailingComma: null,
|
|||
|
// By default, reserved words are only enforced if ecmaVersion >= 5.
|
|||
|
// Set `allowReserved` to a boolean value to explicitly turn this on
|
|||
|
// an off. When this option has the value "never", reserved words
|
|||
|
// and keywords can also not be used as property names.
|
|||
|
allowReserved: null,
|
|||
|
// When enabled, a return at the top level is not considered an
|
|||
|
// error.
|
|||
|
allowReturnOutsideFunction: false,
|
|||
|
// When enabled, import/export statements are not constrained to
|
|||
|
// appearing at the top of the program.
|
|||
|
allowImportExportEverywhere: false,
|
|||
|
// When enabled, hashbang directive in the beginning of file
|
|||
|
// is allowed and treated as a line comment.
|
|||
|
allowHashBang: false,
|
|||
|
// When `locations` is on, `loc` properties holding objects with
|
|||
|
// `start` and `end` properties in `{line, column}` form (with
|
|||
|
// line being 1-based and column 0-based) will be attached to the
|
|||
|
// nodes.
|
|||
|
locations: false,
|
|||
|
// A function can be passed as `onToken` option, which will
|
|||
|
// cause Acorn to call that function with object in the same
|
|||
|
// format as tokens returned from `tokenizer().getToken()`. Note
|
|||
|
// that you are not allowed to call the parser from the
|
|||
|
// callback—that will corrupt its internal state.
|
|||
|
onToken: null,
|
|||
|
// A function can be passed as `onComment` option, which will
|
|||
|
// cause Acorn to call that function with `(block, text, start,
|
|||
|
// end)` parameters whenever a comment is skipped. `block` is a
|
|||
|
// boolean indicating whether this is a block (`/* */`) comment,
|
|||
|
// `text` is the content of the comment, and `start` and `end` are
|
|||
|
// character offsets that denote the start and end of the comment.
|
|||
|
// When the `locations` option is on, two more parameters are
|
|||
|
// passed, the full `{line, column}` locations of the start and
|
|||
|
// end of the comments. Note that you are not allowed to call the
|
|||
|
// parser from the callback—that will corrupt its internal state.
|
|||
|
onComment: null,
|
|||
|
// Nodes have their start and end characters offsets recorded in
|
|||
|
// `start` and `end` properties (directly on the node, rather than
|
|||
|
// the `loc` object, which holds line/column data. To also add a
|
|||
|
// [semi-standardized][range] `range` property holding a `[start,
|
|||
|
// end]` array with the same numbers, set the `ranges` option to
|
|||
|
// `true`.
|
|||
|
//
|
|||
|
// [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
|
|||
|
ranges: false,
|
|||
|
// It is possible to parse multiple files into a single AST by
|
|||
|
// passing the tree produced by parsing the first file as
|
|||
|
// `program` option in subsequent parses. This will add the
|
|||
|
// toplevel forms of the parsed file to the `Program` (top) node
|
|||
|
// of an existing parse tree.
|
|||
|
program: null,
|
|||
|
// When `locations` is on, you can pass this to record the source
|
|||
|
// file in every node's `loc` object.
|
|||
|
sourceFile: null,
|
|||
|
// This value, if given, is stored in every node, whether
|
|||
|
// `locations` is on or off.
|
|||
|
directSourceFile: null,
|
|||
|
// When enabled, parenthesized expressions are represented by
|
|||
|
// (non-standard) ParenthesizedExpression nodes
|
|||
|
preserveParens: false,
|
|||
|
plugins: {}
|
|||
|
};
|
|||
|
|
|||
|
exports.defaultOptions = defaultOptions;
|
|||
|
// Interpret and default an options object
|
|||
|
|
|||
|
function getOptions(opts) {
|
|||
|
var options = {};
|
|||
|
for (var opt in defaultOptions) {
|
|||
|
options[opt] = opts && _util.has(opts, opt) ? opts[opt] : defaultOptions[opt];
|
|||
|
}if (options.allowReserved == null) options.allowReserved = options.ecmaVersion < 5;
|
|||
|
|
|||
|
if (_util.isArray(options.onToken)) {
|
|||
|
(function () {
|
|||
|
var tokens = options.onToken;
|
|||
|
options.onToken = function (token) {
|
|||
|
return tokens.push(token);
|
|||
|
};
|
|||
|
})();
|
|||
|
}
|
|||
|
if (_util.isArray(options.onComment)) options.onComment = pushComment(options, options.onComment);
|
|||
|
|
|||
|
return options;
|
|||
|
}
|
|||
|
|
|||
|
function pushComment(options, array) {
|
|||
|
return function (block, text, start, end, startLoc, endLoc) {
|
|||
|
var comment = {
|
|||
|
type: block ? 'Block' : 'Line',
|
|||
|
value: text,
|
|||
|
start: start,
|
|||
|
end: end
|
|||
|
};
|
|||
|
if (options.locations) comment.loc = new _locutil.SourceLocation(this, startLoc, endLoc);
|
|||
|
if (options.ranges) comment.range = [start, end];
|
|||
|
array.push(comment);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
},{"./locutil":5,"./util":15}],9:[function(_dereq_,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
|
|||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|||
|
|
|||
|
var _tokentype = _dereq_("./tokentype");
|
|||
|
|
|||
|
var _state = _dereq_("./state");
|
|||
|
|
|||
|
var _whitespace = _dereq_("./whitespace");
|
|||
|
|
|||
|
var pp = _state.Parser.prototype;
|
|||
|
|
|||
|
// ## Parser utilities
|
|||
|
|
|||
|
// Test whether a statement node is the string literal `"use strict"`.
|
|||
|
|
|||
|
pp.isUseStrict = function (stmt) {
|
|||
|
return this.options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && stmt.expression.raw.slice(1, -1) === "use strict";
|
|||
|
};
|
|||
|
|
|||
|
// Predicate that tests whether the next token is of the given
|
|||
|
// type, and if yes, consumes it as a side effect.
|
|||
|
|
|||
|
pp.eat = function (type) {
|
|||
|
if (this.type === type) {
|
|||
|
this.next();
|
|||
|
return true;
|
|||
|
} else {
|
|||
|
return false;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Tests whether parsed token is a contextual keyword.
|
|||
|
|
|||
|
pp.isContextual = function (name) {
|
|||
|
return this.type === _tokentype.types.name && this.value === name;
|
|||
|
};
|
|||
|
|
|||
|
// Consumes contextual keyword if possible.
|
|||
|
|
|||
|
pp.eatContextual = function (name) {
|
|||
|
return this.value === name && this.eat(_tokentype.types.name);
|
|||
|
};
|
|||
|
|
|||
|
// Asserts that following token is given contextual keyword.
|
|||
|
|
|||
|
pp.expectContextual = function (name) {
|
|||
|
if (!this.eatContextual(name)) this.unexpected();
|
|||
|
};
|
|||
|
|
|||
|
// Test whether a semicolon can be inserted at the current position.
|
|||
|
|
|||
|
pp.canInsertSemicolon = function () {
|
|||
|
return this.type === _tokentype.types.eof || this.type === _tokentype.types.braceR || _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start));
|
|||
|
};
|
|||
|
|
|||
|
pp.insertSemicolon = function () {
|
|||
|
if (this.canInsertSemicolon()) {
|
|||
|
if (this.options.onInsertedSemicolon) this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc);
|
|||
|
return true;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Consume a semicolon, or, failing that, see if we are allowed to
|
|||
|
// pretend that there is a semicolon at this position.
|
|||
|
|
|||
|
pp.semicolon = function () {
|
|||
|
if (!this.eat(_tokentype.types.semi) && !this.insertSemicolon()) this.unexpected();
|
|||
|
};
|
|||
|
|
|||
|
pp.afterTrailingComma = function (tokType) {
|
|||
|
if (this.type == tokType) {
|
|||
|
if (this.options.onTrailingComma) this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc);
|
|||
|
this.next();
|
|||
|
return true;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Expect a token of a given type. If found, consume it, otherwise,
|
|||
|
// raise an unexpected token error.
|
|||
|
|
|||
|
pp.expect = function (type) {
|
|||
|
this.eat(type) || this.unexpected();
|
|||
|
};
|
|||
|
|
|||
|
// Raise an unexpected token error.
|
|||
|
|
|||
|
pp.unexpected = function (pos) {
|
|||
|
this.raise(pos != null ? pos : this.start, "Unexpected token");
|
|||
|
};
|
|||
|
|
|||
|
var DestructuringErrors = function DestructuringErrors() {
|
|||
|
_classCallCheck(this, DestructuringErrors);
|
|||
|
|
|||
|
this.shorthandAssign = 0;
|
|||
|
this.trailingComma = 0;
|
|||
|
};
|
|||
|
|
|||
|
exports.DestructuringErrors = DestructuringErrors;
|
|||
|
|
|||
|
pp.checkPatternErrors = function (refDestructuringErrors, andThrow) {
|
|||
|
var trailing = refDestructuringErrors && refDestructuringErrors.trailingComma;
|
|||
|
if (!andThrow) return !!trailing;
|
|||
|
if (trailing) this.raise(trailing, "Comma is not permitted after the rest element");
|
|||
|
};
|
|||
|
|
|||
|
pp.checkExpressionErrors = function (refDestructuringErrors, andThrow) {
|
|||
|
var pos = refDestructuringErrors && refDestructuringErrors.shorthandAssign;
|
|||
|
if (!andThrow) return !!pos;
|
|||
|
if (pos) this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns");
|
|||
|
};
|
|||
|
|
|||
|
},{"./state":10,"./tokentype":14,"./whitespace":16}],10:[function(_dereq_,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
|
|||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|||
|
|
|||
|
var _identifier = _dereq_("./identifier");
|
|||
|
|
|||
|
var _tokentype = _dereq_("./tokentype");
|
|||
|
|
|||
|
var _whitespace = _dereq_("./whitespace");
|
|||
|
|
|||
|
var _options = _dereq_("./options");
|
|||
|
|
|||
|
// Registered plugins
|
|||
|
var plugins = {};
|
|||
|
|
|||
|
exports.plugins = plugins;
|
|||
|
function keywordRegexp(words) {
|
|||
|
return new RegExp("^(" + words.replace(/ /g, "|") + ")$");
|
|||
|
}
|
|||
|
|
|||
|
var Parser = (function () {
|
|||
|
function Parser(options, input, startPos) {
|
|||
|
_classCallCheck(this, Parser);
|
|||
|
|
|||
|
this.options = options = _options.getOptions(options);
|
|||
|
this.sourceFile = options.sourceFile;
|
|||
|
this.keywords = keywordRegexp(_identifier.keywords[options.ecmaVersion >= 6 ? 6 : 5]);
|
|||
|
var reserved = options.allowReserved ? "" : _identifier.reservedWords[options.ecmaVersion] + (options.sourceType == "module" ? " await" : "");
|
|||
|
this.reservedWords = keywordRegexp(reserved);
|
|||
|
var reservedStrict = (reserved ? reserved + " " : "") + _identifier.reservedWords.strict;
|
|||
|
this.reservedWordsStrict = keywordRegexp(reservedStrict);
|
|||
|
this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + _identifier.reservedWords.strictBind);
|
|||
|
this.input = String(input);
|
|||
|
|
|||
|
// Used to signal to callers of `readWord1` whether the word
|
|||
|
// contained any escape sequences. This is needed because words with
|
|||
|
// escape sequences must not be interpreted as keywords.
|
|||
|
this.containsEsc = false;
|
|||
|
|
|||
|
// Load plugins
|
|||
|
this.loadPlugins(options.plugins);
|
|||
|
|
|||
|
// Set up token state
|
|||
|
|
|||
|
// The current position of the tokenizer in the input.
|
|||
|
if (startPos) {
|
|||
|
this.pos = startPos;
|
|||
|
this.lineStart = Math.max(0, this.input.lastIndexOf("\n", startPos));
|
|||
|
this.curLine = this.input.slice(0, this.lineStart).split(_whitespace.lineBreak).length;
|
|||
|
} else {
|
|||
|
this.pos = this.lineStart = 0;
|
|||
|
this.curLine = 1;
|
|||
|
}
|
|||
|
|
|||
|
// Properties of the current token:
|
|||
|
// Its type
|
|||
|
this.type = _tokentype.types.eof;
|
|||
|
// For tokens that include more information than their type, the value
|
|||
|
this.value = null;
|
|||
|
// Its start and end offset
|
|||
|
this.start = this.end = this.pos;
|
|||
|
// And, if locations are used, the {line, column} object
|
|||
|
// corresponding to those offsets
|
|||
|
this.startLoc = this.endLoc = this.curPosition();
|
|||
|
|
|||
|
// Position information for the previous token
|
|||
|
this.lastTokEndLoc = this.lastTokStartLoc = null;
|
|||
|
this.lastTokStart = this.lastTokEnd = this.pos;
|
|||
|
|
|||
|
// The context stack is used to superficially track syntactic
|
|||
|
// context to predict whether a regular expression is allowed in a
|
|||
|
// given position.
|
|||
|
this.context = this.initialContext();
|
|||
|
this.exprAllowed = true;
|
|||
|
|
|||
|
// Figure out if it's a module code.
|
|||
|
this.strict = this.inModule = options.sourceType === "module";
|
|||
|
|
|||
|
// Used to signify the start of a potential arrow function
|
|||
|
this.potentialArrowAt = -1;
|
|||
|
|
|||
|
// Flags to track whether we are in a function, a generator.
|
|||
|
this.inFunction = this.inGenerator = false;
|
|||
|
// Labels in scope.
|
|||
|
this.labels = [];
|
|||
|
|
|||
|
// If enabled, skip leading hashbang line.
|
|||
|
if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === '#!') this.skipLineComment(2);
|
|||
|
}
|
|||
|
|
|||
|
// DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
|
|||
|
|
|||
|
Parser.prototype.isKeyword = function isKeyword(word) {
|
|||
|
return this.keywords.test(word);
|
|||
|
};
|
|||
|
|
|||
|
Parser.prototype.isReservedWord = function isReservedWord(word) {
|
|||
|
return this.reservedWords.test(word);
|
|||
|
};
|
|||
|
|
|||
|
Parser.prototype.extend = function extend(name, f) {
|
|||
|
this[name] = f(this[name]);
|
|||
|
};
|
|||
|
|
|||
|
Parser.prototype.loadPlugins = function loadPlugins(pluginConfigs) {
|
|||
|
for (var _name in pluginConfigs) {
|
|||
|
var plugin = plugins[_name];
|
|||
|
if (!plugin) throw new Error("Plugin '" + _name + "' not found");
|
|||
|
plugin(this, pluginConfigs[_name]);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
Parser.prototype.parse = function parse() {
|
|||
|
var node = this.options.program || this.startNode();
|
|||
|
this.nextToken();
|
|||
|
return this.parseTopLevel(node);
|
|||
|
};
|
|||
|
|
|||
|
return Parser;
|
|||
|
})();
|
|||
|
|
|||
|
exports.Parser = Parser;
|
|||
|
|
|||
|
},{"./identifier":2,"./options":8,"./tokentype":14,"./whitespace":16}],11:[function(_dereq_,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var _tokentype = _dereq_("./tokentype");
|
|||
|
|
|||
|
var _state = _dereq_("./state");
|
|||
|
|
|||
|
var _whitespace = _dereq_("./whitespace");
|
|||
|
|
|||
|
var _identifier = _dereq_("./identifier");
|
|||
|
|
|||
|
var _parseutil = _dereq_("./parseutil");
|
|||
|
|
|||
|
var pp = _state.Parser.prototype;
|
|||
|
|
|||
|
// ### Statement parsing
|
|||
|
|
|||
|
// Parse a program. Initializes the parser, reads any number of
|
|||
|
// statements, and wraps them in a Program node. Optionally takes a
|
|||
|
// `program` argument. If present, the statements will be appended
|
|||
|
// to its body instead of creating a new node.
|
|||
|
|
|||
|
pp.parseTopLevel = function (node) {
|
|||
|
var first = true;
|
|||
|
if (!node.body) node.body = [];
|
|||
|
while (this.type !== _tokentype.types.eof) {
|
|||
|
var stmt = this.parseStatement(true, true);
|
|||
|
node.body.push(stmt);
|
|||
|
if (first) {
|
|||
|
if (this.isUseStrict(stmt)) this.setStrict(true);
|
|||
|
first = false;
|
|||
|
}
|
|||
|
}
|
|||
|
this.next();
|
|||
|
if (this.options.ecmaVersion >= 6) {
|
|||
|
node.sourceType = this.options.sourceType;
|
|||
|
}
|
|||
|
return this.finishNode(node, "Program");
|
|||
|
};
|
|||
|
|
|||
|
var loopLabel = { kind: "loop" },
|
|||
|
switchLabel = { kind: "switch" };
|
|||
|
|
|||
|
pp.isLet = function () {
|
|||
|
if (this.type !== _tokentype.types.name || this.options.ecmaVersion < 6 || this.value != "let") return false;
|
|||
|
_whitespace.skipWhiteSpace.lastIndex = this.pos;
|
|||
|
var skip = _whitespace.skipWhiteSpace.exec(this.input);
|
|||
|
var next = this.pos + skip[0].length,
|
|||
|
nextCh = this.input.charCodeAt(next);
|
|||
|
if (nextCh === 91 || nextCh == 123) return true; // '{' and '['
|
|||
|
if (_identifier.isIdentifierStart(nextCh, true)) {
|
|||
|
for (var pos = next + 1; _identifier.isIdentifierChar(this.input.charCodeAt(pos, true)); ++pos) {}
|
|||
|
var ident = this.input.slice(next, pos);
|
|||
|
if (!this.isKeyword(ident)) return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
};
|
|||
|
|
|||
|
// Parse a single statement.
|
|||
|
//
|
|||
|
// If expecting a statement and finding a slash operator, parse a
|
|||
|
// regular expression literal. This is to handle cases like
|
|||
|
// `if (foo) /blah/.exec(foo)`, where looking at the previous token
|
|||
|
// does not help.
|
|||
|
|
|||
|
pp.parseStatement = function (declaration, topLevel) {
|
|||
|
var starttype = this.type,
|
|||
|
node = this.startNode(),
|
|||
|
kind = undefined;
|
|||
|
|
|||
|
if (this.isLet()) {
|
|||
|
starttype = _tokentype.types._var;
|
|||
|
kind = "let";
|
|||
|
}
|
|||
|
|
|||
|
// Most types of statements are recognized by the keyword they
|
|||
|
// start with. Many are trivial to parse, some require a bit of
|
|||
|
// complexity.
|
|||
|
|
|||
|
switch (starttype) {
|
|||
|
case _tokentype.types._break:case _tokentype.types._continue:
|
|||
|
return this.parseBreakContinueStatement(node, starttype.keyword);
|
|||
|
case _tokentype.types._debugger:
|
|||
|
return this.parseDebuggerStatement(node);
|
|||
|
case _tokentype.types._do:
|
|||
|
return this.parseDoStatement(node);
|
|||
|
case _tokentype.types._for:
|
|||
|
return this.parseForStatement(node);
|
|||
|
case _tokentype.types._function:
|
|||
|
if (!declaration && this.options.ecmaVersion >= 6) this.unexpected();
|
|||
|
return this.parseFunctionStatement(node);
|
|||
|
case _tokentype.types._class:
|
|||
|
if (!declaration) this.unexpected();
|
|||
|
return this.parseClass(node, true);
|
|||
|
case _tokentype.types._if:
|
|||
|
return this.parseIfStatement(node);
|
|||
|
case _tokentype.types._return:
|
|||
|
return this.parseReturnStatement(node);
|
|||
|
case _tokentype.types._switch:
|
|||
|
return this.parseSwitchStatement(node);
|
|||
|
case _tokentype.types._throw:
|
|||
|
return this.parseThrowStatement(node);
|
|||
|
case _tokentype.types._try:
|
|||
|
return this.parseTryStatement(node);
|
|||
|
case _tokentype.types._const:case _tokentype.types._var:
|
|||
|
kind = kind || this.value;
|
|||
|
if (!declaration && kind != "var") this.unexpected();
|
|||
|
return this.parseVarStatement(node, kind);
|
|||
|
case _tokentype.types._while:
|
|||
|
return this.parseWhileStatement(node);
|
|||
|
case _tokentype.types._with:
|
|||
|
return this.parseWithStatement(node);
|
|||
|
case _tokentype.types.braceL:
|
|||
|
return this.parseBlock();
|
|||
|
case _tokentype.types.semi:
|
|||
|
return this.parseEmptyStatement(node);
|
|||
|
case _tokentype.types._export:
|
|||
|
case _tokentype.types._import:
|
|||
|
if (!this.options.allowImportExportEverywhere) {
|
|||
|
if (!topLevel) this.raise(this.start, "'import' and 'export' may only appear at the top level");
|
|||
|
if (!this.inModule) this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'");
|
|||
|
}
|
|||
|
return starttype === _tokentype.types._import ? this.parseImport(node) : this.parseExport(node);
|
|||
|
|
|||
|
// If the statement does not start with a statement keyword or a
|
|||
|
// brace, it's an ExpressionStatement or LabeledStatement. We
|
|||
|
// simply start parsing an expression, and afterwards, if the
|
|||
|
// next token is a colon and the expression was a simple
|
|||
|
// Identifier node, we switch to interpreting it as a label.
|
|||
|
default:
|
|||
|
var maybeName = this.value,
|
|||
|
expr = this.parseExpression();
|
|||
|
if (starttype === _tokentype.types.name && expr.type === "Identifier" && this.eat(_tokentype.types.colon)) return this.parseLabeledStatement(node, maybeName, expr);else return this.parseExpressionStatement(node, expr);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
pp.parseBreakContinueStatement = function (node, keyword) {
|
|||
|
var isBreak = keyword == "break";
|
|||
|
this.next();
|
|||
|
if (this.eat(_tokentype.types.semi) || this.insertSemicolon()) node.label = null;else if (this.type !== _tokentype.types.name) this.unexpected();else {
|
|||
|
node.label = this.parseIdent();
|
|||
|
this.semicolon();
|
|||
|
}
|
|||
|
|
|||
|
// Verify that there is an actual destination to break or
|
|||
|
// continue to.
|
|||
|
for (var i = 0; i < this.labels.length; ++i) {
|
|||
|
var lab = this.labels[i];
|
|||
|
if (node.label == null || lab.name === node.label.name) {
|
|||
|
if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
|
|||
|
if (node.label && isBreak) break;
|
|||
|
}
|
|||
|
}
|
|||
|
if (i === this.labels.length) this.raise(node.start, "Unsyntactic " + keyword);
|
|||
|
return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseDebuggerStatement = function (node) {
|
|||
|
this.next();
|
|||
|
this.semicolon();
|
|||
|
return this.finishNode(node, "DebuggerStatement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseDoStatement = function (node) {
|
|||
|
this.next();
|
|||
|
this.labels.push(loopLabel);
|
|||
|
node.body = this.parseStatement(false);
|
|||
|
this.labels.pop();
|
|||
|
this.expect(_tokentype.types._while);
|
|||
|
node.test = this.parseParenExpression();
|
|||
|
if (this.options.ecmaVersion >= 6) this.eat(_tokentype.types.semi);else this.semicolon();
|
|||
|
return this.finishNode(node, "DoWhileStatement");
|
|||
|
};
|
|||
|
|
|||
|
// Disambiguating between a `for` and a `for`/`in` or `for`/`of`
|
|||
|
// loop is non-trivial. Basically, we have to parse the init `var`
|
|||
|
// statement or expression, disallowing the `in` operator (see
|
|||
|
// the second parameter to `parseExpression`), and then check
|
|||
|
// whether the next token is `in` or `of`. When there is no init
|
|||
|
// part (semicolon immediately after the opening parenthesis), it
|
|||
|
// is a regular `for` loop.
|
|||
|
|
|||
|
pp.parseForStatement = function (node) {
|
|||
|
this.next();
|
|||
|
this.labels.push(loopLabel);
|
|||
|
this.expect(_tokentype.types.parenL);
|
|||
|
if (this.type === _tokentype.types.semi) return this.parseFor(node, null);
|
|||
|
var isLet = this.isLet();
|
|||
|
if (this.type === _tokentype.types._var || this.type === _tokentype.types._const || isLet) {
|
|||
|
var _init = this.startNode(),
|
|||
|
kind = isLet ? "let" : this.value;
|
|||
|
this.next();
|
|||
|
this.parseVar(_init, true, kind);
|
|||
|
this.finishNode(_init, "VariableDeclaration");
|
|||
|
if ((this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) && _init.declarations.length === 1 && !(kind !== "var" && _init.declarations[0].init)) return this.parseForIn(node, _init);
|
|||
|
return this.parseFor(node, _init);
|
|||
|
}
|
|||
|
var refDestructuringErrors = new _parseutil.DestructuringErrors();
|
|||
|
var init = this.parseExpression(true, refDestructuringErrors);
|
|||
|
if (this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) {
|
|||
|
this.checkPatternErrors(refDestructuringErrors, true);
|
|||
|
this.toAssignable(init);
|
|||
|
this.checkLVal(init);
|
|||
|
return this.parseForIn(node, init);
|
|||
|
} else {
|
|||
|
this.checkExpressionErrors(refDestructuringErrors, true);
|
|||
|
}
|
|||
|
return this.parseFor(node, init);
|
|||
|
};
|
|||
|
|
|||
|
pp.parseFunctionStatement = function (node) {
|
|||
|
this.next();
|
|||
|
return this.parseFunction(node, true);
|
|||
|
};
|
|||
|
|
|||
|
pp.parseIfStatement = function (node) {
|
|||
|
this.next();
|
|||
|
node.test = this.parseParenExpression();
|
|||
|
node.consequent = this.parseStatement(false);
|
|||
|
node.alternate = this.eat(_tokentype.types._else) ? this.parseStatement(false) : null;
|
|||
|
return this.finishNode(node, "IfStatement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseReturnStatement = function (node) {
|
|||
|
if (!this.inFunction && !this.options.allowReturnOutsideFunction) this.raise(this.start, "'return' outside of function");
|
|||
|
this.next();
|
|||
|
|
|||
|
// In `return` (and `break`/`continue`), the keywords with
|
|||
|
// optional arguments, we eagerly look for a semicolon or the
|
|||
|
// possibility to insert one.
|
|||
|
|
|||
|
if (this.eat(_tokentype.types.semi) || this.insertSemicolon()) node.argument = null;else {
|
|||
|
node.argument = this.parseExpression();this.semicolon();
|
|||
|
}
|
|||
|
return this.finishNode(node, "ReturnStatement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseSwitchStatement = function (node) {
|
|||
|
this.next();
|
|||
|
node.discriminant = this.parseParenExpression();
|
|||
|
node.cases = [];
|
|||
|
this.expect(_tokentype.types.braceL);
|
|||
|
this.labels.push(switchLabel);
|
|||
|
|
|||
|
// Statements under must be grouped (by label) in SwitchCase
|
|||
|
// nodes. `cur` is used to keep the node that we are currently
|
|||
|
// adding statements to.
|
|||
|
|
|||
|
for (var cur, sawDefault = false; this.type != _tokentype.types.braceR;) {
|
|||
|
if (this.type === _tokentype.types._case || this.type === _tokentype.types._default) {
|
|||
|
var isCase = this.type === _tokentype.types._case;
|
|||
|
if (cur) this.finishNode(cur, "SwitchCase");
|
|||
|
node.cases.push(cur = this.startNode());
|
|||
|
cur.consequent = [];
|
|||
|
this.next();
|
|||
|
if (isCase) {
|
|||
|
cur.test = this.parseExpression();
|
|||
|
} else {
|
|||
|
if (sawDefault) this.raiseRecoverable(this.lastTokStart, "Multiple default clauses");
|
|||
|
sawDefault = true;
|
|||
|
cur.test = null;
|
|||
|
}
|
|||
|
this.expect(_tokentype.types.colon);
|
|||
|
} else {
|
|||
|
if (!cur) this.unexpected();
|
|||
|
cur.consequent.push(this.parseStatement(true));
|
|||
|
}
|
|||
|
}
|
|||
|
if (cur) this.finishNode(cur, "SwitchCase");
|
|||
|
this.next(); // Closing brace
|
|||
|
this.labels.pop();
|
|||
|
return this.finishNode(node, "SwitchStatement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseThrowStatement = function (node) {
|
|||
|
this.next();
|
|||
|
if (_whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) this.raise(this.lastTokEnd, "Illegal newline after throw");
|
|||
|
node.argument = this.parseExpression();
|
|||
|
this.semicolon();
|
|||
|
return this.finishNode(node, "ThrowStatement");
|
|||
|
};
|
|||
|
|
|||
|
// Reused empty array added for node fields that are always empty.
|
|||
|
|
|||
|
var empty = [];
|
|||
|
|
|||
|
pp.parseTryStatement = function (node) {
|
|||
|
this.next();
|
|||
|
node.block = this.parseBlock();
|
|||
|
node.handler = null;
|
|||
|
if (this.type === _tokentype.types._catch) {
|
|||
|
var clause = this.startNode();
|
|||
|
this.next();
|
|||
|
this.expect(_tokentype.types.parenL);
|
|||
|
clause.param = this.parseBindingAtom();
|
|||
|
this.checkLVal(clause.param, true);
|
|||
|
this.expect(_tokentype.types.parenR);
|
|||
|
clause.body = this.parseBlock();
|
|||
|
node.handler = this.finishNode(clause, "CatchClause");
|
|||
|
}
|
|||
|
node.finalizer = this.eat(_tokentype.types._finally) ? this.parseBlock() : null;
|
|||
|
if (!node.handler && !node.finalizer) this.raise(node.start, "Missing catch or finally clause");
|
|||
|
return this.finishNode(node, "TryStatement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseVarStatement = function (node, kind) {
|
|||
|
this.next();
|
|||
|
this.parseVar(node, false, kind);
|
|||
|
this.semicolon();
|
|||
|
return this.finishNode(node, "VariableDeclaration");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseWhileStatement = function (node) {
|
|||
|
this.next();
|
|||
|
node.test = this.parseParenExpression();
|
|||
|
this.labels.push(loopLabel);
|
|||
|
node.body = this.parseStatement(false);
|
|||
|
this.labels.pop();
|
|||
|
return this.finishNode(node, "WhileStatement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseWithStatement = function (node) {
|
|||
|
if (this.strict) this.raise(this.start, "'with' in strict mode");
|
|||
|
this.next();
|
|||
|
node.object = this.parseParenExpression();
|
|||
|
node.body = this.parseStatement(false);
|
|||
|
return this.finishNode(node, "WithStatement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseEmptyStatement = function (node) {
|
|||
|
this.next();
|
|||
|
return this.finishNode(node, "EmptyStatement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseLabeledStatement = function (node, maybeName, expr) {
|
|||
|
for (var i = 0; i < this.labels.length; ++i) {
|
|||
|
if (this.labels[i].name === maybeName) this.raise(expr.start, "Label '" + maybeName + "' is already declared");
|
|||
|
}var kind = this.type.isLoop ? "loop" : this.type === _tokentype.types._switch ? "switch" : null;
|
|||
|
for (var i = this.labels.length - 1; i >= 0; i--) {
|
|||
|
var label = this.labels[i];
|
|||
|
if (label.statementStart == node.start) {
|
|||
|
label.statementStart = this.start;
|
|||
|
label.kind = kind;
|
|||
|
} else break;
|
|||
|
}
|
|||
|
this.labels.push({ name: maybeName, kind: kind, statementStart: this.start });
|
|||
|
node.body = this.parseStatement(true);
|
|||
|
this.labels.pop();
|
|||
|
node.label = expr;
|
|||
|
return this.finishNode(node, "LabeledStatement");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseExpressionStatement = function (node, expr) {
|
|||
|
node.expression = expr;
|
|||
|
this.semicolon();
|
|||
|
return this.finishNode(node, "ExpressionStatement");
|
|||
|
};
|
|||
|
|
|||
|
// Parse a semicolon-enclosed block of statements, handling `"use
|
|||
|
// strict"` declarations when `allowStrict` is true (used for
|
|||
|
// function bodies).
|
|||
|
|
|||
|
pp.parseBlock = function (allowStrict) {
|
|||
|
var node = this.startNode(),
|
|||
|
first = true,
|
|||
|
oldStrict = undefined;
|
|||
|
node.body = [];
|
|||
|
this.expect(_tokentype.types.braceL);
|
|||
|
while (!this.eat(_tokentype.types.braceR)) {
|
|||
|
var stmt = this.parseStatement(true);
|
|||
|
node.body.push(stmt);
|
|||
|
if (first && allowStrict && this.isUseStrict(stmt)) {
|
|||
|
oldStrict = this.strict;
|
|||
|
this.setStrict(this.strict = true);
|
|||
|
}
|
|||
|
first = false;
|
|||
|
}
|
|||
|
if (oldStrict === false) this.setStrict(false);
|
|||
|
return this.finishNode(node, "BlockStatement");
|
|||
|
};
|
|||
|
|
|||
|
// Parse a regular `for` loop. The disambiguation code in
|
|||
|
// `parseStatement` will already have parsed the init statement or
|
|||
|
// expression.
|
|||
|
|
|||
|
pp.parseFor = function (node, init) {
|
|||
|
node.init = init;
|
|||
|
this.expect(_tokentype.types.semi);
|
|||
|
node.test = this.type === _tokentype.types.semi ? null : this.parseExpression();
|
|||
|
this.expect(_tokentype.types.semi);
|
|||
|
node.update = this.type === _tokentype.types.parenR ? null : this.parseExpression();
|
|||
|
this.expect(_tokentype.types.parenR);
|
|||
|
node.body = this.parseStatement(false);
|
|||
|
this.labels.pop();
|
|||
|
return this.finishNode(node, "ForStatement");
|
|||
|
};
|
|||
|
|
|||
|
// Parse a `for`/`in` and `for`/`of` loop, which are almost
|
|||
|
// same from parser's perspective.
|
|||
|
|
|||
|
pp.parseForIn = function (node, init) {
|
|||
|
var type = this.type === _tokentype.types._in ? "ForInStatement" : "ForOfStatement";
|
|||
|
this.next();
|
|||
|
node.left = init;
|
|||
|
node.right = this.parseExpression();
|
|||
|
this.expect(_tokentype.types.parenR);
|
|||
|
node.body = this.parseStatement(false);
|
|||
|
this.labels.pop();
|
|||
|
return this.finishNode(node, type);
|
|||
|
};
|
|||
|
|
|||
|
// Parse a list of variable declarations.
|
|||
|
|
|||
|
pp.parseVar = function (node, isFor, kind) {
|
|||
|
node.declarations = [];
|
|||
|
node.kind = kind;
|
|||
|
for (;;) {
|
|||
|
var decl = this.startNode();
|
|||
|
this.parseVarId(decl);
|
|||
|
if (this.eat(_tokentype.types.eq)) {
|
|||
|
decl.init = this.parseMaybeAssign(isFor);
|
|||
|
} else if (kind === "const" && !(this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
|
|||
|
this.unexpected();
|
|||
|
} else if (decl.id.type != "Identifier" && !(isFor && (this.type === _tokentype.types._in || this.isContextual("of")))) {
|
|||
|
this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
|
|||
|
} else {
|
|||
|
decl.init = null;
|
|||
|
}
|
|||
|
node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
|
|||
|
if (!this.eat(_tokentype.types.comma)) break;
|
|||
|
}
|
|||
|
return node;
|
|||
|
};
|
|||
|
|
|||
|
pp.parseVarId = function (decl) {
|
|||
|
decl.id = this.parseBindingAtom();
|
|||
|
this.checkLVal(decl.id, true);
|
|||
|
};
|
|||
|
|
|||
|
// Parse a function declaration or literal (depending on the
|
|||
|
// `isStatement` parameter).
|
|||
|
|
|||
|
pp.parseFunction = function (node, isStatement, allowExpressionBody) {
|
|||
|
this.initFunction(node);
|
|||
|
if (this.options.ecmaVersion >= 6) node.generator = this.eat(_tokentype.types.star);
|
|||
|
var oldInGen = this.inGenerator;
|
|||
|
this.inGenerator = node.generator;
|
|||
|
if (isStatement || this.type === _tokentype.types.name) node.id = this.parseIdent();
|
|||
|
this.parseFunctionParams(node);
|
|||
|
this.parseFunctionBody(node, allowExpressionBody);
|
|||
|
this.inGenerator = oldInGen;
|
|||
|
return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseFunctionParams = function (node) {
|
|||
|
this.expect(_tokentype.types.parenL);
|
|||
|
node.params = this.parseBindingList(_tokentype.types.parenR, false, false, true);
|
|||
|
};
|
|||
|
|
|||
|
// Parse a class declaration or literal (depending on the
|
|||
|
// `isStatement` parameter).
|
|||
|
|
|||
|
pp.parseClass = function (node, isStatement) {
|
|||
|
this.next();
|
|||
|
this.parseClassId(node, isStatement);
|
|||
|
this.parseClassSuper(node);
|
|||
|
var classBody = this.startNode();
|
|||
|
var hadConstructor = false;
|
|||
|
classBody.body = [];
|
|||
|
this.expect(_tokentype.types.braceL);
|
|||
|
while (!this.eat(_tokentype.types.braceR)) {
|
|||
|
if (this.eat(_tokentype.types.semi)) continue;
|
|||
|
var method = this.startNode();
|
|||
|
var isGenerator = this.eat(_tokentype.types.star);
|
|||
|
var isMaybeStatic = this.type === _tokentype.types.name && this.value === "static";
|
|||
|
this.parsePropertyName(method);
|
|||
|
method["static"] = isMaybeStatic && this.type !== _tokentype.types.parenL;
|
|||
|
if (method["static"]) {
|
|||
|
if (isGenerator) this.unexpected();
|
|||
|
isGenerator = this.eat(_tokentype.types.star);
|
|||
|
this.parsePropertyName(method);
|
|||
|
}
|
|||
|
method.kind = "method";
|
|||
|
var isGetSet = false;
|
|||
|
if (!method.computed) {
|
|||
|
var key = method.key;
|
|||
|
|
|||
|
if (!isGenerator && key.type === "Identifier" && this.type !== _tokentype.types.parenL && (key.name === "get" || key.name === "set")) {
|
|||
|
isGetSet = true;
|
|||
|
method.kind = key.name;
|
|||
|
key = this.parsePropertyName(method);
|
|||
|
}
|
|||
|
if (!method["static"] && (key.type === "Identifier" && key.name === "constructor" || key.type === "Literal" && key.value === "constructor")) {
|
|||
|
if (hadConstructor) this.raise(key.start, "Duplicate constructor in the same class");
|
|||
|
if (isGetSet) this.raise(key.start, "Constructor can't have get/set modifier");
|
|||
|
if (isGenerator) this.raise(key.start, "Constructor can't be a generator");
|
|||
|
method.kind = "constructor";
|
|||
|
hadConstructor = true;
|
|||
|
}
|
|||
|
}
|
|||
|
this.parseClassMethod(classBody, method, isGenerator);
|
|||
|
if (isGetSet) {
|
|||
|
var paramCount = method.kind === "get" ? 0 : 1;
|
|||
|
if (method.value.params.length !== paramCount) {
|
|||
|
var start = method.value.start;
|
|||
|
if (method.kind === "get") this.raiseRecoverable(start, "getter should have no params");else this.raiseRecoverable(start, "setter should have exactly one param");
|
|||
|
}
|
|||
|
if (method.kind === "set" && method.value.params[0].type === "RestElement") this.raise(method.value.params[0].start, "Setter cannot use rest params");
|
|||
|
}
|
|||
|
}
|
|||
|
node.body = this.finishNode(classBody, "ClassBody");
|
|||
|
return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
|
|||
|
};
|
|||
|
|
|||
|
pp.parseClassMethod = function (classBody, method, isGenerator) {
|
|||
|
method.value = this.parseMethod(isGenerator);
|
|||
|
classBody.body.push(this.finishNode(method, "MethodDefinition"));
|
|||
|
};
|
|||
|
|
|||
|
pp.parseClassId = function (node, isStatement) {
|
|||
|
node.id = this.type === _tokentype.types.name ? this.parseIdent() : isStatement ? this.unexpected() : null;
|
|||
|
};
|
|||
|
|
|||
|
pp.parseClassSuper = function (node) {
|
|||
|
node.superClass = this.eat(_tokentype.types._extends) ? this.parseExprSubscripts() : null;
|
|||
|
};
|
|||
|
|
|||
|
// Parses module export declaration.
|
|||
|
|
|||
|
pp.parseExport = function (node) {
|
|||
|
this.next();
|
|||
|
// export * from '...'
|
|||
|
if (this.eat(_tokentype.types.star)) {
|
|||
|
this.expectContextual("from");
|
|||
|
node.source = this.type === _tokentype.types.string ? this.parseExprAtom() : this.unexpected();
|
|||
|
this.semicolon();
|
|||
|
return this.finishNode(node, "ExportAllDeclaration");
|
|||
|
}
|
|||
|
if (this.eat(_tokentype.types._default)) {
|
|||
|
// export default ...
|
|||
|
var parens = this.type == _tokentype.types.parenL;
|
|||
|
var expr = this.parseMaybeAssign();
|
|||
|
var needsSemi = true;
|
|||
|
if (!parens && (expr.type == "FunctionExpression" || expr.type == "ClassExpression")) {
|
|||
|
needsSemi = false;
|
|||
|
if (expr.id) {
|
|||
|
expr.type = expr.type == "FunctionExpression" ? "FunctionDeclaration" : "ClassDeclaration";
|
|||
|
}
|
|||
|
}
|
|||
|
node.declaration = expr;
|
|||
|
if (needsSemi) this.semicolon();
|
|||
|
return this.finishNode(node, "ExportDefaultDeclaration");
|
|||
|
}
|
|||
|
// export var|const|let|function|class ...
|
|||
|
if (this.shouldParseExportStatement()) {
|
|||
|
node.declaration = this.parseStatement(true);
|
|||
|
node.specifiers = [];
|
|||
|
node.source = null;
|
|||
|
} else {
|
|||
|
// export { x, y as z } [from '...']
|
|||
|
node.declaration = null;
|
|||
|
node.specifiers = this.parseExportSpecifiers();
|
|||
|
if (this.eatContextual("from")) {
|
|||
|
node.source = this.type === _tokentype.types.string ? this.parseExprAtom() : this.unexpected();
|
|||
|
} else {
|
|||
|
// check for keywords used as local names
|
|||
|
for (var i = 0; i < node.specifiers.length; i++) {
|
|||
|
if (this.keywords.test(node.specifiers[i].local.name) || this.reservedWords.test(node.specifiers[i].local.name)) {
|
|||
|
this.unexpected(node.specifiers[i].local.start);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
node.source = null;
|
|||
|
}
|
|||
|
this.semicolon();
|
|||
|
}
|
|||
|
return this.finishNode(node, "ExportNamedDeclaration");
|
|||
|
};
|
|||
|
|
|||
|
pp.shouldParseExportStatement = function () {
|
|||
|
return this.type.keyword || this.isLet();
|
|||
|
};
|
|||
|
|
|||
|
// Parses a comma-separated list of module exports.
|
|||
|
|
|||
|
pp.parseExportSpecifiers = function () {
|
|||
|
var nodes = [],
|
|||
|
first = true;
|
|||
|
// export { x, y as z } [from '...']
|
|||
|
this.expect(_tokentype.types.braceL);
|
|||
|
while (!this.eat(_tokentype.types.braceR)) {
|
|||
|
if (!first) {
|
|||
|
this.expect(_tokentype.types.comma);
|
|||
|
if (this.afterTrailingComma(_tokentype.types.braceR)) break;
|
|||
|
} else first = false;
|
|||
|
|
|||
|
var node = this.startNode();
|
|||
|
node.local = this.parseIdent(this.type === _tokentype.types._default);
|
|||
|
node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
|
|||
|
nodes.push(this.finishNode(node, "ExportSpecifier"));
|
|||
|
}
|
|||
|
return nodes;
|
|||
|
};
|
|||
|
|
|||
|
// Parses import declaration.
|
|||
|
|
|||
|
pp.parseImport = function (node) {
|
|||
|
this.next();
|
|||
|
// import '...'
|
|||
|
if (this.type === _tokentype.types.string) {
|
|||
|
node.specifiers = empty;
|
|||
|
node.source = this.parseExprAtom();
|
|||
|
} else {
|
|||
|
node.specifiers = this.parseImportSpecifiers();
|
|||
|
this.expectContextual("from");
|
|||
|
node.source = this.type === _tokentype.types.string ? this.parseExprAtom() : this.unexpected();
|
|||
|
}
|
|||
|
this.semicolon();
|
|||
|
return this.finishNode(node, "ImportDeclaration");
|
|||
|
};
|
|||
|
|
|||
|
// Parses a comma-separated list of module imports.
|
|||
|
|
|||
|
pp.parseImportSpecifiers = function () {
|
|||
|
var nodes = [],
|
|||
|
first = true;
|
|||
|
if (this.type === _tokentype.types.name) {
|
|||
|
// import defaultObj, { x, y as z } from '...'
|
|||
|
var node = this.startNode();
|
|||
|
node.local = this.parseIdent();
|
|||
|
this.checkLVal(node.local, true);
|
|||
|
nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
|
|||
|
if (!this.eat(_tokentype.types.comma)) return nodes;
|
|||
|
}
|
|||
|
if (this.type === _tokentype.types.star) {
|
|||
|
var node = this.startNode();
|
|||
|
this.next();
|
|||
|
this.expectContextual("as");
|
|||
|
node.local = this.parseIdent();
|
|||
|
this.checkLVal(node.local, true);
|
|||
|
nodes.push(this.finishNode(node, "ImportNamespaceSpecifier"));
|
|||
|
return nodes;
|
|||
|
}
|
|||
|
this.expect(_tokentype.types.braceL);
|
|||
|
while (!this.eat(_tokentype.types.braceR)) {
|
|||
|
if (!first) {
|
|||
|
this.expect(_tokentype.types.comma);
|
|||
|
if (this.afterTrailingComma(_tokentype.types.braceR)) break;
|
|||
|
} else first = false;
|
|||
|
|
|||
|
var node = this.startNode();
|
|||
|
node.imported = this.parseIdent(true);
|
|||
|
if (this.eatContextual("as")) {
|
|||
|
node.local = this.parseIdent();
|
|||
|
} else {
|
|||
|
node.local = node.imported;
|
|||
|
if (this.isKeyword(node.local.name)) this.unexpected(node.local.start);
|
|||
|
if (this.reservedWordsStrict.test(node.local.name)) this.raise(node.local.start, "The keyword '" + node.local.name + "' is reserved");
|
|||
|
}
|
|||
|
this.checkLVal(node.local, true);
|
|||
|
nodes.push(this.finishNode(node, "ImportSpecifier"));
|
|||
|
}
|
|||
|
return nodes;
|
|||
|
};
|
|||
|
|
|||
|
},{"./identifier":2,"./parseutil":9,"./state":10,"./tokentype":14,"./whitespace":16}],12:[function(_dereq_,module,exports){
|
|||
|
// The algorithm used to determine whether a regexp can appear at a
|
|||
|
// given point in the program is loosely based on sweet.js' approach.
|
|||
|
// See https://github.com/mozilla/sweet.js/wiki/design
|
|||
|
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
|
|||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|||
|
|
|||
|
var _state = _dereq_("./state");
|
|||
|
|
|||
|
var _tokentype = _dereq_("./tokentype");
|
|||
|
|
|||
|
var _whitespace = _dereq_("./whitespace");
|
|||
|
|
|||
|
var TokContext = function TokContext(token, isExpr, preserveSpace, override) {
|
|||
|
_classCallCheck(this, TokContext);
|
|||
|
|
|||
|
this.token = token;
|
|||
|
this.isExpr = !!isExpr;
|
|||
|
this.preserveSpace = !!preserveSpace;
|
|||
|
this.override = override;
|
|||
|
};
|
|||
|
|
|||
|
exports.TokContext = TokContext;
|
|||
|
var types = {
|
|||
|
b_stat: new TokContext("{", false),
|
|||
|
b_expr: new TokContext("{", true),
|
|||
|
b_tmpl: new TokContext("${", true),
|
|||
|
p_stat: new TokContext("(", false),
|
|||
|
p_expr: new TokContext("(", true),
|
|||
|
q_tmpl: new TokContext("`", true, true, function (p) {
|
|||
|
return p.readTmplToken();
|
|||
|
}),
|
|||
|
f_expr: new TokContext("function", true)
|
|||
|
};
|
|||
|
|
|||
|
exports.types = types;
|
|||
|
var pp = _state.Parser.prototype;
|
|||
|
|
|||
|
pp.initialContext = function () {
|
|||
|
return [types.b_stat];
|
|||
|
};
|
|||
|
|
|||
|
pp.braceIsBlock = function (prevType) {
|
|||
|
if (prevType === _tokentype.types.colon) {
|
|||
|
var _parent = this.curContext();
|
|||
|
if (_parent === types.b_stat || _parent === types.b_expr) return !_parent.isExpr;
|
|||
|
}
|
|||
|
if (prevType === _tokentype.types._return) return _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start));
|
|||
|
if (prevType === _tokentype.types._else || prevType === _tokentype.types.semi || prevType === _tokentype.types.eof || prevType === _tokentype.types.parenR) return true;
|
|||
|
if (prevType == _tokentype.types.braceL) return this.curContext() === types.b_stat;
|
|||
|
return !this.exprAllowed;
|
|||
|
};
|
|||
|
|
|||
|
pp.updateContext = function (prevType) {
|
|||
|
var update = undefined,
|
|||
|
type = this.type;
|
|||
|
if (type.keyword && prevType == _tokentype.types.dot) this.exprAllowed = false;else if (update = type.updateContext) update.call(this, prevType);else this.exprAllowed = type.beforeExpr;
|
|||
|
};
|
|||
|
|
|||
|
// Token-specific context update code
|
|||
|
|
|||
|
_tokentype.types.parenR.updateContext = _tokentype.types.braceR.updateContext = function () {
|
|||
|
if (this.context.length == 1) {
|
|||
|
this.exprAllowed = true;
|
|||
|
return;
|
|||
|
}
|
|||
|
var out = this.context.pop();
|
|||
|
if (out === types.b_stat && this.curContext() === types.f_expr) {
|
|||
|
this.context.pop();
|
|||
|
this.exprAllowed = false;
|
|||
|
} else if (out === types.b_tmpl) {
|
|||
|
this.exprAllowed = true;
|
|||
|
} else {
|
|||
|
this.exprAllowed = !out.isExpr;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
_tokentype.types.braceL.updateContext = function (prevType) {
|
|||
|
this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
|
|||
|
this.exprAllowed = true;
|
|||
|
};
|
|||
|
|
|||
|
_tokentype.types.dollarBraceL.updateContext = function () {
|
|||
|
this.context.push(types.b_tmpl);
|
|||
|
this.exprAllowed = true;
|
|||
|
};
|
|||
|
|
|||
|
_tokentype.types.parenL.updateContext = function (prevType) {
|
|||
|
var statementParens = prevType === _tokentype.types._if || prevType === _tokentype.types._for || prevType === _tokentype.types._with || prevType === _tokentype.types._while;
|
|||
|
this.context.push(statementParens ? types.p_stat : types.p_expr);
|
|||
|
this.exprAllowed = true;
|
|||
|
};
|
|||
|
|
|||
|
_tokentype.types.incDec.updateContext = function () {
|
|||
|
// tokExprAllowed stays unchanged
|
|||
|
};
|
|||
|
|
|||
|
_tokentype.types._function.updateContext = function (prevType) {
|
|||
|
if (prevType.beforeExpr && prevType !== _tokentype.types.semi && prevType !== _tokentype.types._else && (prevType !== _tokentype.types.colon || this.curContext() !== types.b_stat)) this.context.push(types.f_expr);
|
|||
|
this.exprAllowed = false;
|
|||
|
};
|
|||
|
|
|||
|
_tokentype.types.backQuote.updateContext = function () {
|
|||
|
if (this.curContext() === types.q_tmpl) this.context.pop();else this.context.push(types.q_tmpl);
|
|||
|
this.exprAllowed = false;
|
|||
|
};
|
|||
|
|
|||
|
},{"./state":10,"./tokentype":14,"./whitespace":16}],13:[function(_dereq_,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
|
|||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|||
|
|
|||
|
var _identifier = _dereq_("./identifier");
|
|||
|
|
|||
|
var _tokentype = _dereq_("./tokentype");
|
|||
|
|
|||
|
var _state = _dereq_("./state");
|
|||
|
|
|||
|
var _locutil = _dereq_("./locutil");
|
|||
|
|
|||
|
var _whitespace = _dereq_("./whitespace");
|
|||
|
|
|||
|
// Object type used to represent tokens. Note that normally, tokens
|
|||
|
// simply exist as properties on the parser object. This is only
|
|||
|
// used for the onToken callback and the external tokenizer.
|
|||
|
|
|||
|
var Token = function Token(p) {
|
|||
|
_classCallCheck(this, Token);
|
|||
|
|
|||
|
this.type = p.type;
|
|||
|
this.value = p.value;
|
|||
|
this.start = p.start;
|
|||
|
this.end = p.end;
|
|||
|
if (p.options.locations) this.loc = new _locutil.SourceLocation(p, p.startLoc, p.endLoc);
|
|||
|
if (p.options.ranges) this.range = [p.start, p.end];
|
|||
|
}
|
|||
|
|
|||
|
// ## Tokenizer
|
|||
|
|
|||
|
;
|
|||
|
|
|||
|
exports.Token = Token;
|
|||
|
var pp = _state.Parser.prototype;
|
|||
|
|
|||
|
// Are we running under Rhino?
|
|||
|
var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
|
|||
|
|
|||
|
// Move to the next token
|
|||
|
|
|||
|
pp.next = function () {
|
|||
|
if (this.options.onToken) this.options.onToken(new Token(this));
|
|||
|
|
|||
|
this.lastTokEnd = this.end;
|
|||
|
this.lastTokStart = this.start;
|
|||
|
this.lastTokEndLoc = this.endLoc;
|
|||
|
this.lastTokStartLoc = this.startLoc;
|
|||
|
this.nextToken();
|
|||
|
};
|
|||
|
|
|||
|
pp.getToken = function () {
|
|||
|
this.next();
|
|||
|
return new Token(this);
|
|||
|
};
|
|||
|
|
|||
|
// If we're in an ES6 environment, make parsers iterable
|
|||
|
if (typeof Symbol !== "undefined") pp[Symbol.iterator] = function () {
|
|||
|
var self = this;
|
|||
|
return { next: function next() {
|
|||
|
var token = self.getToken();
|
|||
|
return {
|
|||
|
done: token.type === _tokentype.types.eof,
|
|||
|
value: token
|
|||
|
};
|
|||
|
} };
|
|||
|
};
|
|||
|
|
|||
|
// Toggle strict mode. Re-reads the next number or string to please
|
|||
|
// pedantic tests (`"use strict"; 010;` should fail).
|
|||
|
|
|||
|
pp.setStrict = function (strict) {
|
|||
|
this.strict = strict;
|
|||
|
if (this.type !== _tokentype.types.num && this.type !== _tokentype.types.string) return;
|
|||
|
this.pos = this.start;
|
|||
|
if (this.options.locations) {
|
|||
|
while (this.pos < this.lineStart) {
|
|||
|
this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;
|
|||
|
--this.curLine;
|
|||
|
}
|
|||
|
}
|
|||
|
this.nextToken();
|
|||
|
};
|
|||
|
|
|||
|
pp.curContext = function () {
|
|||
|
return this.context[this.context.length - 1];
|
|||
|
};
|
|||
|
|
|||
|
// Read a single token, updating the parser object's token-related
|
|||
|
// properties.
|
|||
|
|
|||
|
pp.nextToken = function () {
|
|||
|
var curContext = this.curContext();
|
|||
|
if (!curContext || !curContext.preserveSpace) this.skipSpace();
|
|||
|
|
|||
|
this.start = this.pos;
|
|||
|
if (this.options.locations) this.startLoc = this.curPosition();
|
|||
|
if (this.pos >= this.input.length) return this.finishToken(_tokentype.types.eof);
|
|||
|
|
|||
|
if (curContext.override) return curContext.override(this);else this.readToken(this.fullCharCodeAtPos());
|
|||
|
};
|
|||
|
|
|||
|
pp.readToken = function (code) {
|
|||
|
// Identifier or keyword. '\uXXXX' sequences are allowed in
|
|||
|
// identifiers, so '\' also dispatches to that.
|
|||
|
if (_identifier.isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */) return this.readWord();
|
|||
|
|
|||
|
return this.getTokenFromCode(code);
|
|||
|
};
|
|||
|
|
|||
|
pp.fullCharCodeAtPos = function () {
|
|||
|
var code = this.input.charCodeAt(this.pos);
|
|||
|
if (code <= 0xd7ff || code >= 0xe000) return code;
|
|||
|
var next = this.input.charCodeAt(this.pos + 1);
|
|||
|
return (code << 10) + next - 0x35fdc00;
|
|||
|
};
|
|||
|
|
|||
|
pp.skipBlockComment = function () {
|
|||
|
var startLoc = this.options.onComment && this.curPosition();
|
|||
|
var start = this.pos,
|
|||
|
end = this.input.indexOf("*/", this.pos += 2);
|
|||
|
if (end === -1) this.raise(this.pos - 2, "Unterminated comment");
|
|||
|
this.pos = end + 2;
|
|||
|
if (this.options.locations) {
|
|||
|
_whitespace.lineBreakG.lastIndex = start;
|
|||
|
var match = undefined;
|
|||
|
while ((match = _whitespace.lineBreakG.exec(this.input)) && match.index < this.pos) {
|
|||
|
++this.curLine;
|
|||
|
this.lineStart = match.index + match[0].length;
|
|||
|
}
|
|||
|
}
|
|||
|
if (this.options.onComment) this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos, startLoc, this.curPosition());
|
|||
|
};
|
|||
|
|
|||
|
pp.skipLineComment = function (startSkip) {
|
|||
|
var start = this.pos;
|
|||
|
var startLoc = this.options.onComment && this.curPosition();
|
|||
|
var ch = this.input.charCodeAt(this.pos += startSkip);
|
|||
|
while (this.pos < this.input.length && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) {
|
|||
|
++this.pos;
|
|||
|
ch = this.input.charCodeAt(this.pos);
|
|||
|
}
|
|||
|
if (this.options.onComment) this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos, startLoc, this.curPosition());
|
|||
|
};
|
|||
|
|
|||
|
// Called at the start of the parse and after every token. Skips
|
|||
|
// whitespace and comments, and.
|
|||
|
|
|||
|
pp.skipSpace = function () {
|
|||
|
loop: while (this.pos < this.input.length) {
|
|||
|
var ch = this.input.charCodeAt(this.pos);
|
|||
|
switch (ch) {
|
|||
|
case 32:case 160:
|
|||
|
// ' '
|
|||
|
++this.pos;
|
|||
|
break;
|
|||
|
case 13:
|
|||
|
if (this.input.charCodeAt(this.pos + 1) === 10) {
|
|||
|
++this.pos;
|
|||
|
}
|
|||
|
case 10:case 8232:case 8233:
|
|||
|
++this.pos;
|
|||
|
if (this.options.locations) {
|
|||
|
++this.curLine;
|
|||
|
this.lineStart = this.pos;
|
|||
|
}
|
|||
|
break;
|
|||
|
case 47:
|
|||
|
// '/'
|
|||
|
switch (this.input.charCodeAt(this.pos + 1)) {
|
|||
|
case 42:
|
|||
|
// '*'
|
|||
|
this.skipBlockComment();
|
|||
|
break;
|
|||
|
case 47:
|
|||
|
this.skipLineComment(2);
|
|||
|
break;
|
|||
|
default:
|
|||
|
break loop;
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
if (ch > 8 && ch < 14 || ch >= 5760 && _whitespace.nonASCIIwhitespace.test(String.fromCharCode(ch))) {
|
|||
|
++this.pos;
|
|||
|
} else {
|
|||
|
break loop;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Called at the end of every token. Sets `end`, `val`, and
|
|||
|
// maintains `context` and `exprAllowed`, and skips the space after
|
|||
|
// the token, so that the next one's `start` will point at the
|
|||
|
// right position.
|
|||
|
|
|||
|
pp.finishToken = function (type, val) {
|
|||
|
this.end = this.pos;
|
|||
|
if (this.options.locations) this.endLoc = this.curPosition();
|
|||
|
var prevType = this.type;
|
|||
|
this.type = type;
|
|||
|
this.value = val;
|
|||
|
|
|||
|
this.updateContext(prevType);
|
|||
|
};
|
|||
|
|
|||
|
// ### Token reading
|
|||
|
|
|||
|
// This is the function that is called to fetch the next token. It
|
|||
|
// is somewhat obscure, because it works in character codes rather
|
|||
|
// than characters, and because operator parsing has been inlined
|
|||
|
// into it.
|
|||
|
//
|
|||
|
// All in the name of speed.
|
|||
|
//
|
|||
|
pp.readToken_dot = function () {
|
|||
|
var next = this.input.charCodeAt(this.pos + 1);
|
|||
|
if (next >= 48 && next <= 57) return this.readNumber(true);
|
|||
|
var next2 = this.input.charCodeAt(this.pos + 2);
|
|||
|
if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) {
|
|||
|
// 46 = dot '.'
|
|||
|
this.pos += 3;
|
|||
|
return this.finishToken(_tokentype.types.ellipsis);
|
|||
|
} else {
|
|||
|
++this.pos;
|
|||
|
return this.finishToken(_tokentype.types.dot);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
pp.readToken_slash = function () {
|
|||
|
// '/'
|
|||
|
var next = this.input.charCodeAt(this.pos + 1);
|
|||
|
if (this.exprAllowed) {
|
|||
|
++this.pos;return this.readRegexp();
|
|||
|
}
|
|||
|
if (next === 61) return this.finishOp(_tokentype.types.assign, 2);
|
|||
|
return this.finishOp(_tokentype.types.slash, 1);
|
|||
|
};
|
|||
|
|
|||
|
pp.readToken_mult_modulo_exp = function (code) {
|
|||
|
// '%*'
|
|||
|
var next = this.input.charCodeAt(this.pos + 1);
|
|||
|
var size = 1;
|
|||
|
var tokentype = code === 42 ? _tokentype.types.star : _tokentype.types.modulo;
|
|||
|
|
|||
|
// exponentiation operator ** and **=
|
|||
|
if (this.options.ecmaVersion >= 7 && next === 42) {
|
|||
|
++size;
|
|||
|
tokentype = _tokentype.types.starstar;
|
|||
|
next = this.input.charCodeAt(this.pos + 2);
|
|||
|
}
|
|||
|
|
|||
|
if (next === 61) return this.finishOp(_tokentype.types.assign, size + 1);
|
|||
|
return this.finishOp(tokentype, size);
|
|||
|
};
|
|||
|
|
|||
|
pp.readToken_pipe_amp = function (code) {
|
|||
|
// '|&'
|
|||
|
var next = this.input.charCodeAt(this.pos + 1);
|
|||
|
if (next === code) return this.finishOp(code === 124 ? _tokentype.types.logicalOR : _tokentype.types.logicalAND, 2);
|
|||
|
if (next === 61) return this.finishOp(_tokentype.types.assign, 2);
|
|||
|
return this.finishOp(code === 124 ? _tokentype.types.bitwiseOR : _tokentype.types.bitwiseAND, 1);
|
|||
|
};
|
|||
|
|
|||
|
pp.readToken_caret = function () {
|
|||
|
// '^'
|
|||
|
var next = this.input.charCodeAt(this.pos + 1);
|
|||
|
if (next === 61) return this.finishOp(_tokentype.types.assign, 2);
|
|||
|
return this.finishOp(_tokentype.types.bitwiseXOR, 1);
|
|||
|
};
|
|||
|
|
|||
|
pp.readToken_plus_min = function (code) {
|
|||
|
// '+-'
|
|||
|
var next = this.input.charCodeAt(this.pos + 1);
|
|||
|
if (next === code) {
|
|||
|
if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 && _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.pos))) {
|
|||
|
// A `-->` line comment
|
|||
|
this.skipLineComment(3);
|
|||
|
this.skipSpace();
|
|||
|
return this.nextToken();
|
|||
|
}
|
|||
|
return this.finishOp(_tokentype.types.incDec, 2);
|
|||
|
}
|
|||
|
if (next === 61) return this.finishOp(_tokentype.types.assign, 2);
|
|||
|
return this.finishOp(_tokentype.types.plusMin, 1);
|
|||
|
};
|
|||
|
|
|||
|
pp.readToken_lt_gt = function (code) {
|
|||
|
// '<>'
|
|||
|
var next = this.input.charCodeAt(this.pos + 1);
|
|||
|
var size = 1;
|
|||
|
if (next === code) {
|
|||
|
size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
|
|||
|
if (this.input.charCodeAt(this.pos + size) === 61) return this.finishOp(_tokentype.types.assign, size + 1);
|
|||
|
return this.finishOp(_tokentype.types.bitShift, size);
|
|||
|
}
|
|||
|
if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 && this.input.charCodeAt(this.pos + 3) == 45) {
|
|||
|
if (this.inModule) this.unexpected();
|
|||
|
// `<!--`, an XML-style comment that should be interpreted as a line comment
|
|||
|
this.skipLineComment(4);
|
|||
|
this.skipSpace();
|
|||
|
return this.nextToken();
|
|||
|
}
|
|||
|
if (next === 61) size = 2;
|
|||
|
return this.finishOp(_tokentype.types.relational, size);
|
|||
|
};
|
|||
|
|
|||
|
pp.readToken_eq_excl = function (code) {
|
|||
|
// '=!'
|
|||
|
var next = this.input.charCodeAt(this.pos + 1);
|
|||
|
if (next === 61) return this.finishOp(_tokentype.types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2);
|
|||
|
if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) {
|
|||
|
// '=>'
|
|||
|
this.pos += 2;
|
|||
|
return this.finishToken(_tokentype.types.arrow);
|
|||
|
}
|
|||
|
return this.finishOp(code === 61 ? _tokentype.types.eq : _tokentype.types.prefix, 1);
|
|||
|
};
|
|||
|
|
|||
|
pp.getTokenFromCode = function (code) {
|
|||
|
switch (code) {
|
|||
|
// The interpretation of a dot depends on whether it is followed
|
|||
|
// by a digit or another two dots.
|
|||
|
case 46:
|
|||
|
// '.'
|
|||
|
return this.readToken_dot();
|
|||
|
|
|||
|
// Punctuation tokens.
|
|||
|
case 40:
|
|||
|
++this.pos;return this.finishToken(_tokentype.types.parenL);
|
|||
|
case 41:
|
|||
|
++this.pos;return this.finishToken(_tokentype.types.parenR);
|
|||
|
case 59:
|
|||
|
++this.pos;return this.finishToken(_tokentype.types.semi);
|
|||
|
case 44:
|
|||
|
++this.pos;return this.finishToken(_tokentype.types.comma);
|
|||
|
case 91:
|
|||
|
++this.pos;return this.finishToken(_tokentype.types.bracketL);
|
|||
|
case 93:
|
|||
|
++this.pos;return this.finishToken(_tokentype.types.bracketR);
|
|||
|
case 123:
|
|||
|
++this.pos;return this.finishToken(_tokentype.types.braceL);
|
|||
|
case 125:
|
|||
|
++this.pos;return this.finishToken(_tokentype.types.braceR);
|
|||
|
case 58:
|
|||
|
++this.pos;return this.finishToken(_tokentype.types.colon);
|
|||
|
case 63:
|
|||
|
++this.pos;return this.finishToken(_tokentype.types.question);
|
|||
|
|
|||
|
case 96:
|
|||
|
// '`'
|
|||
|
if (this.options.ecmaVersion < 6) break;
|
|||
|
++this.pos;
|
|||
|
return this.finishToken(_tokentype.types.backQuote);
|
|||
|
|
|||
|
case 48:
|
|||
|
// '0'
|
|||
|
var next = this.input.charCodeAt(this.pos + 1);
|
|||
|
if (next === 120 || next === 88) return this.readRadixNumber(16); // '0x', '0X' - hex number
|
|||
|
if (this.options.ecmaVersion >= 6) {
|
|||
|
if (next === 111 || next === 79) return this.readRadixNumber(8); // '0o', '0O' - octal number
|
|||
|
if (next === 98 || next === 66) return this.readRadixNumber(2); // '0b', '0B' - binary number
|
|||
|
}
|
|||
|
// Anything else beginning with a digit is an integer, octal
|
|||
|
// number, or float.
|
|||
|
case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:
|
|||
|
// 1-9
|
|||
|
return this.readNumber(false);
|
|||
|
|
|||
|
// Quotes produce strings.
|
|||
|
case 34:case 39:
|
|||
|
// '"', "'"
|
|||
|
return this.readString(code);
|
|||
|
|
|||
|
// Operators are parsed inline in tiny state machines. '=' (61) is
|
|||
|
// often referred to. `finishOp` simply skips the amount of
|
|||
|
// characters it is given as second argument, and returns a token
|
|||
|
// of the type given by its first argument.
|
|||
|
|
|||
|
case 47:
|
|||
|
// '/'
|
|||
|
return this.readToken_slash();
|
|||
|
|
|||
|
case 37:case 42:
|
|||
|
// '%*'
|
|||
|
return this.readToken_mult_modulo_exp(code);
|
|||
|
|
|||
|
case 124:case 38:
|
|||
|
// '|&'
|
|||
|
return this.readToken_pipe_amp(code);
|
|||
|
|
|||
|
case 94:
|
|||
|
// '^'
|
|||
|
return this.readToken_caret();
|
|||
|
|
|||
|
case 43:case 45:
|
|||
|
// '+-'
|
|||
|
return this.readToken_plus_min(code);
|
|||
|
|
|||
|
case 60:case 62:
|
|||
|
// '<>'
|
|||
|
return this.readToken_lt_gt(code);
|
|||
|
|
|||
|
case 61:case 33:
|
|||
|
// '=!'
|
|||
|
return this.readToken_eq_excl(code);
|
|||
|
|
|||
|
case 126:
|
|||
|
// '~'
|
|||
|
return this.finishOp(_tokentype.types.prefix, 1);
|
|||
|
}
|
|||
|
|
|||
|
this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
|
|||
|
};
|
|||
|
|
|||
|
pp.finishOp = function (type, size) {
|
|||
|
var str = this.input.slice(this.pos, this.pos + size);
|
|||
|
this.pos += size;
|
|||
|
return this.finishToken(type, str);
|
|||
|
};
|
|||
|
|
|||
|
// Parse a regular expression. Some context-awareness is necessary,
|
|||
|
// since a '/' inside a '[]' set does not end the expression.
|
|||
|
|
|||
|
function tryCreateRegexp(src, flags, throwErrorAt, parser) {
|
|||
|
try {
|
|||
|
return new RegExp(src, flags);
|
|||
|
} catch (e) {
|
|||
|
if (throwErrorAt !== undefined) {
|
|||
|
if (e instanceof SyntaxError) parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message);
|
|||
|
throw e;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var regexpUnicodeSupport = !!tryCreateRegexp("", "u");
|
|||
|
|
|||
|
pp.readRegexp = function () {
|
|||
|
var _this = this;
|
|||
|
|
|||
|
var escaped = undefined,
|
|||
|
inClass = undefined,
|
|||
|
start = this.pos;
|
|||
|
for (;;) {
|
|||
|
if (this.pos >= this.input.length) this.raise(start, "Unterminated regular expression");
|
|||
|
var ch = this.input.charAt(this.pos);
|
|||
|
if (_whitespace.lineBreak.test(ch)) this.raise(start, "Unterminated regular expression");
|
|||
|
if (!escaped) {
|
|||
|
if (ch === "[") inClass = true;else if (ch === "]" && inClass) inClass = false;else if (ch === "/" && !inClass) break;
|
|||
|
escaped = ch === "\\";
|
|||
|
} else escaped = false;
|
|||
|
++this.pos;
|
|||
|
}
|
|||
|
var content = this.input.slice(start, this.pos);
|
|||
|
++this.pos;
|
|||
|
// Need to use `readWord1` because '\uXXXX' sequences are allowed
|
|||
|
// here (don't ask).
|
|||
|
var mods = this.readWord1();
|
|||
|
var tmp = content,
|
|||
|
tmpFlags = "";
|
|||
|
if (mods) {
|
|||
|
var validFlags = /^[gim]*$/;
|
|||
|
if (this.options.ecmaVersion >= 6) validFlags = /^[gimuy]*$/;
|
|||
|
if (!validFlags.test(mods)) this.raise(start, "Invalid regular expression flag");
|
|||
|
if (mods.indexOf("u") >= 0) {
|
|||
|
if (regexpUnicodeSupport) {
|
|||
|
tmpFlags = "u";
|
|||
|
} else {
|
|||
|
// Replace each astral symbol and every Unicode escape sequence that
|
|||
|
// possibly represents an astral symbol or a paired surrogate with a
|
|||
|
// single ASCII symbol to avoid throwing on regular expressions that
|
|||
|
// are only valid in combination with the `/u` flag.
|
|||
|
// Note: replacing with the ASCII symbol `x` might cause false
|
|||
|
// negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
|
|||
|
// perfectly valid pattern that is equivalent to `[a-b]`, but it would
|
|||
|
// be replaced by `[x-b]` which throws an error.
|
|||
|
tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
|
|||
|
code = Number("0x" + code);
|
|||
|
if (code > 0x10FFFF) _this.raise(start + offset + 3, "Code point out of bounds");
|
|||
|
return "x";
|
|||
|
});
|
|||
|
tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
|
|||
|
tmpFlags = tmpFlags.replace("u", "");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
// Detect invalid regular expressions.
|
|||
|
var value = null;
|
|||
|
// Rhino's regular expression parser is flaky and throws uncatchable exceptions,
|
|||
|
// so don't do detection if we are running under Rhino
|
|||
|
if (!isRhino) {
|
|||
|
tryCreateRegexp(tmp, tmpFlags, start, this);
|
|||
|
// Get a regular expression object for this pattern-flag pair, or `null` in
|
|||
|
// case the current environment doesn't support the flags it uses.
|
|||
|
value = tryCreateRegexp(content, mods);
|
|||
|
}
|
|||
|
return this.finishToken(_tokentype.types.regexp, { pattern: content, flags: mods, value: value });
|
|||
|
};
|
|||
|
|
|||
|
// Read an integer in the given radix. Return null if zero digits
|
|||
|
// were read, the integer value otherwise. When `len` is given, this
|
|||
|
// will return `null` unless the integer has exactly `len` digits.
|
|||
|
|
|||
|
pp.readInt = function (radix, len) {
|
|||
|
var start = this.pos,
|
|||
|
total = 0;
|
|||
|
for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
|
|||
|
var code = this.input.charCodeAt(this.pos),
|
|||
|
val = undefined;
|
|||
|
if (code >= 97) val = code - 97 + 10; // a
|
|||
|
else if (code >= 65) val = code - 65 + 10; // A
|
|||
|
else if (code >= 48 && code <= 57) val = code - 48; // 0-9
|
|||
|
else val = Infinity;
|
|||
|
if (val >= radix) break;
|
|||
|
++this.pos;
|
|||
|
total = total * radix + val;
|
|||
|
}
|
|||
|
if (this.pos === start || len != null && this.pos - start !== len) return null;
|
|||
|
|
|||
|
return total;
|
|||
|
};
|
|||
|
|
|||
|
pp.readRadixNumber = function (radix) {
|
|||
|
this.pos += 2; // 0x
|
|||
|
var val = this.readInt(radix);
|
|||
|
if (val == null) this.raise(this.start + 2, "Expected number in radix " + radix);
|
|||
|
if (_identifier.isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
|
|||
|
return this.finishToken(_tokentype.types.num, val);
|
|||
|
};
|
|||
|
|
|||
|
// Read an integer, octal integer, or floating-point number.
|
|||
|
|
|||
|
pp.readNumber = function (startsWithDot) {
|
|||
|
var start = this.pos,
|
|||
|
isFloat = false,
|
|||
|
octal = this.input.charCodeAt(this.pos) === 48;
|
|||
|
if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number");
|
|||
|
var next = this.input.charCodeAt(this.pos);
|
|||
|
if (next === 46) {
|
|||
|
// '.'
|
|||
|
++this.pos;
|
|||
|
this.readInt(10);
|
|||
|
isFloat = true;
|
|||
|
next = this.input.charCodeAt(this.pos);
|
|||
|
}
|
|||
|
if (next === 69 || next === 101) {
|
|||
|
// 'eE'
|
|||
|
next = this.input.charCodeAt(++this.pos);
|
|||
|
if (next === 43 || next === 45) ++this.pos; // '+-'
|
|||
|
if (this.readInt(10) === null) this.raise(start, "Invalid number");
|
|||
|
isFloat = true;
|
|||
|
}
|
|||
|
if (_identifier.isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
|
|||
|
|
|||
|
var str = this.input.slice(start, this.pos),
|
|||
|
val = undefined;
|
|||
|
if (isFloat) val = parseFloat(str);else if (!octal || str.length === 1) val = parseInt(str, 10);else if (/[89]/.test(str) || this.strict) this.raise(start, "Invalid number");else val = parseInt(str, 8);
|
|||
|
return this.finishToken(_tokentype.types.num, val);
|
|||
|
};
|
|||
|
|
|||
|
// Read a string value, interpreting backslash-escapes.
|
|||
|
|
|||
|
pp.readCodePoint = function () {
|
|||
|
var ch = this.input.charCodeAt(this.pos),
|
|||
|
code = undefined;
|
|||
|
|
|||
|
if (ch === 123) {
|
|||
|
if (this.options.ecmaVersion < 6) this.unexpected();
|
|||
|
var codePos = ++this.pos;
|
|||
|
code = this.readHexChar(this.input.indexOf('}', this.pos) - this.pos);
|
|||
|
++this.pos;
|
|||
|
if (code > 0x10FFFF) this.raise(codePos, "Code point out of bounds");
|
|||
|
} else {
|
|||
|
code = this.readHexChar(4);
|
|||
|
}
|
|||
|
return code;
|
|||
|
};
|
|||
|
|
|||
|
function codePointToString(code) {
|
|||
|
// UTF-16 Decoding
|
|||
|
if (code <= 0xFFFF) return String.fromCharCode(code);
|
|||
|
code -= 0x10000;
|
|||
|
return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00);
|
|||
|
}
|
|||
|
|
|||
|
pp.readString = function (quote) {
|
|||
|
var out = "",
|
|||
|
chunkStart = ++this.pos;
|
|||
|
for (;;) {
|
|||
|
if (this.pos >= this.input.length) this.raise(this.start, "Unterminated string constant");
|
|||
|
var ch = this.input.charCodeAt(this.pos);
|
|||
|
if (ch === quote) break;
|
|||
|
if (ch === 92) {
|
|||
|
// '\'
|
|||
|
out += this.input.slice(chunkStart, this.pos);
|
|||
|
out += this.readEscapedChar(false);
|
|||
|
chunkStart = this.pos;
|
|||
|
} else {
|
|||
|
if (_whitespace.isNewLine(ch)) this.raise(this.start, "Unterminated string constant");
|
|||
|
++this.pos;
|
|||
|
}
|
|||
|
}
|
|||
|
out += this.input.slice(chunkStart, this.pos++);
|
|||
|
return this.finishToken(_tokentype.types.string, out);
|
|||
|
};
|
|||
|
|
|||
|
// Reads template string tokens.
|
|||
|
|
|||
|
pp.readTmplToken = function () {
|
|||
|
var out = "",
|
|||
|
chunkStart = this.pos;
|
|||
|
for (;;) {
|
|||
|
if (this.pos >= this.input.length) this.raise(this.start, "Unterminated template");
|
|||
|
var ch = this.input.charCodeAt(this.pos);
|
|||
|
if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) {
|
|||
|
// '`', '${'
|
|||
|
if (this.pos === this.start && this.type === _tokentype.types.template) {
|
|||
|
if (ch === 36) {
|
|||
|
this.pos += 2;
|
|||
|
return this.finishToken(_tokentype.types.dollarBraceL);
|
|||
|
} else {
|
|||
|
++this.pos;
|
|||
|
return this.finishToken(_tokentype.types.backQuote);
|
|||
|
}
|
|||
|
}
|
|||
|
out += this.input.slice(chunkStart, this.pos);
|
|||
|
return this.finishToken(_tokentype.types.template, out);
|
|||
|
}
|
|||
|
if (ch === 92) {
|
|||
|
// '\'
|
|||
|
out += this.input.slice(chunkStart, this.pos);
|
|||
|
out += this.readEscapedChar(true);
|
|||
|
chunkStart = this.pos;
|
|||
|
} else if (_whitespace.isNewLine(ch)) {
|
|||
|
out += this.input.slice(chunkStart, this.pos);
|
|||
|
++this.pos;
|
|||
|
switch (ch) {
|
|||
|
case 13:
|
|||
|
if (this.input.charCodeAt(this.pos) === 10) ++this.pos;
|
|||
|
case 10:
|
|||
|
out += "\n";
|
|||
|
break;
|
|||
|
default:
|
|||
|
out += String.fromCharCode(ch);
|
|||
|
break;
|
|||
|
}
|
|||
|
if (this.options.locations) {
|
|||
|
++this.curLine;
|
|||
|
this.lineStart = this.pos;
|
|||
|
}
|
|||
|
chunkStart = this.pos;
|
|||
|
} else {
|
|||
|
++this.pos;
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Used to read escaped characters
|
|||
|
|
|||
|
pp.readEscapedChar = function (inTemplate) {
|
|||
|
var ch = this.input.charCodeAt(++this.pos);
|
|||
|
++this.pos;
|
|||
|
switch (ch) {
|
|||
|
case 110:
|
|||
|
return "\n"; // 'n' -> '\n'
|
|||
|
case 114:
|
|||
|
return "\r"; // 'r' -> '\r'
|
|||
|
case 120:
|
|||
|
return String.fromCharCode(this.readHexChar(2)); // 'x'
|
|||
|
case 117:
|
|||
|
return codePointToString(this.readCodePoint()); // 'u'
|
|||
|
case 116:
|
|||
|
return "\t"; // 't' -> '\t'
|
|||
|
case 98:
|
|||
|
return "\b"; // 'b' -> '\b'
|
|||
|
case 118:
|
|||
|
return "\u000b"; // 'v' -> '\u000b'
|
|||
|
case 102:
|
|||
|
return "\f"; // 'f' -> '\f'
|
|||
|
case 13:
|
|||
|
if (this.input.charCodeAt(this.pos) === 10) ++this.pos; // '\r\n'
|
|||
|
case 10:
|
|||
|
// ' \n'
|
|||
|
if (this.options.locations) {
|
|||
|
this.lineStart = this.pos;++this.curLine;
|
|||
|
}
|
|||
|
return "";
|
|||
|
default:
|
|||
|
if (ch >= 48 && ch <= 55) {
|
|||
|
var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
|
|||
|
var octal = parseInt(octalStr, 8);
|
|||
|
if (octal > 255) {
|
|||
|
octalStr = octalStr.slice(0, -1);
|
|||
|
octal = parseInt(octalStr, 8);
|
|||
|
}
|
|||
|
if (octalStr !== "0" && (this.strict || inTemplate)) {
|
|||
|
this.raise(this.pos - 2, "Octal literal in strict mode");
|
|||
|
}
|
|||
|
this.pos += octalStr.length - 1;
|
|||
|
return String.fromCharCode(octal);
|
|||
|
}
|
|||
|
return String.fromCharCode(ch);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Used to read character escape sequences ('\x', '\u', '\U').
|
|||
|
|
|||
|
pp.readHexChar = function (len) {
|
|||
|
var codePos = this.pos;
|
|||
|
var n = this.readInt(16, len);
|
|||
|
if (n === null) this.raise(codePos, "Bad character escape sequence");
|
|||
|
return n;
|
|||
|
};
|
|||
|
|
|||
|
// Read an identifier, and return it as a string. Sets `this.containsEsc`
|
|||
|
// to whether the word contained a '\u' escape.
|
|||
|
//
|
|||
|
// Incrementally adds only escaped chars, adding other chunks as-is
|
|||
|
// as a micro-optimization.
|
|||
|
|
|||
|
pp.readWord1 = function () {
|
|||
|
this.containsEsc = false;
|
|||
|
var word = "",
|
|||
|
first = true,
|
|||
|
chunkStart = this.pos;
|
|||
|
var astral = this.options.ecmaVersion >= 6;
|
|||
|
while (this.pos < this.input.length) {
|
|||
|
var ch = this.fullCharCodeAtPos();
|
|||
|
if (_identifier.isIdentifierChar(ch, astral)) {
|
|||
|
this.pos += ch <= 0xffff ? 1 : 2;
|
|||
|
} else if (ch === 92) {
|
|||
|
// "\"
|
|||
|
this.containsEsc = true;
|
|||
|
word += this.input.slice(chunkStart, this.pos);
|
|||
|
var escStart = this.pos;
|
|||
|
if (this.input.charCodeAt(++this.pos) != 117) // "u"
|
|||
|
this.raise(this.pos, "Expecting Unicode escape sequence \\uXXXX");
|
|||
|
++this.pos;
|
|||
|
var esc = this.readCodePoint();
|
|||
|
if (!(first ? _identifier.isIdentifierStart : _identifier.isIdentifierChar)(esc, astral)) this.raise(escStart, "Invalid Unicode escape");
|
|||
|
word += codePointToString(esc);
|
|||
|
chunkStart = this.pos;
|
|||
|
} else {
|
|||
|
break;
|
|||
|
}
|
|||
|
first = false;
|
|||
|
}
|
|||
|
return word + this.input.slice(chunkStart, this.pos);
|
|||
|
};
|
|||
|
|
|||
|
// Read an identifier or keyword token. Will check for reserved
|
|||
|
// words when necessary.
|
|||
|
|
|||
|
pp.readWord = function () {
|
|||
|
var word = this.readWord1();
|
|||
|
var type = _tokentype.types.name;
|
|||
|
if ((this.options.ecmaVersion >= 6 || !this.containsEsc) && this.keywords.test(word)) type = _tokentype.keywords[word];
|
|||
|
return this.finishToken(type, word);
|
|||
|
};
|
|||
|
|
|||
|
},{"./identifier":2,"./locutil":5,"./state":10,"./tokentype":14,"./whitespace":16}],14:[function(_dereq_,module,exports){
|
|||
|
// ## Token types
|
|||
|
|
|||
|
// The assignment of fine-grained, information-carrying type objects
|
|||
|
// allows the tokenizer to store the information it has about a
|
|||
|
// token in a way that is very cheap for the parser to look up.
|
|||
|
|
|||
|
// All token type variables start with an underscore, to make them
|
|||
|
// easy to recognize.
|
|||
|
|
|||
|
// The `beforeExpr` property is used to disambiguate between regular
|
|||
|
// expressions and divisions. It is set on all token types that can
|
|||
|
// be followed by an expression (thus, a slash after them would be a
|
|||
|
// regular expression).
|
|||
|
//
|
|||
|
// The `startsExpr` property is used to check if the token ends a
|
|||
|
// `yield` expression. It is set on all token types that either can
|
|||
|
// directly start an expression (like a quotation mark) or can
|
|||
|
// continue an expression (like the body of a string).
|
|||
|
//
|
|||
|
// `isLoop` marks a keyword as starting a loop, which is important
|
|||
|
// to know when parsing a label, in order to allow or disallow
|
|||
|
// continue jumps to that label.
|
|||
|
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
|
|||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|||
|
|
|||
|
var TokenType = function TokenType(label) {
|
|||
|
var conf = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
|||
|
|
|||
|
_classCallCheck(this, TokenType);
|
|||
|
|
|||
|
this.label = label;
|
|||
|
this.keyword = conf.keyword;
|
|||
|
this.beforeExpr = !!conf.beforeExpr;
|
|||
|
this.startsExpr = !!conf.startsExpr;
|
|||
|
this.isLoop = !!conf.isLoop;
|
|||
|
this.isAssign = !!conf.isAssign;
|
|||
|
this.prefix = !!conf.prefix;
|
|||
|
this.postfix = !!conf.postfix;
|
|||
|
this.binop = conf.binop || null;
|
|||
|
this.updateContext = null;
|
|||
|
};
|
|||
|
|
|||
|
exports.TokenType = TokenType;
|
|||
|
|
|||
|
function binop(name, prec) {
|
|||
|
return new TokenType(name, { beforeExpr: true, binop: prec });
|
|||
|
}
|
|||
|
var beforeExpr = { beforeExpr: true },
|
|||
|
startsExpr = { startsExpr: true };
|
|||
|
|
|||
|
var types = {
|
|||
|
num: new TokenType("num", startsExpr),
|
|||
|
regexp: new TokenType("regexp", startsExpr),
|
|||
|
string: new TokenType("string", startsExpr),
|
|||
|
name: new TokenType("name", startsExpr),
|
|||
|
eof: new TokenType("eof"),
|
|||
|
|
|||
|
// Punctuation token types.
|
|||
|
bracketL: new TokenType("[", { beforeExpr: true, startsExpr: true }),
|
|||
|
bracketR: new TokenType("]"),
|
|||
|
braceL: new TokenType("{", { beforeExpr: true, startsExpr: true }),
|
|||
|
braceR: new TokenType("}"),
|
|||
|
parenL: new TokenType("(", { beforeExpr: true, startsExpr: true }),
|
|||
|
parenR: new TokenType(")"),
|
|||
|
comma: new TokenType(",", beforeExpr),
|
|||
|
semi: new TokenType(";", beforeExpr),
|
|||
|
colon: new TokenType(":", beforeExpr),
|
|||
|
dot: new TokenType("."),
|
|||
|
question: new TokenType("?", beforeExpr),
|
|||
|
arrow: new TokenType("=>", beforeExpr),
|
|||
|
template: new TokenType("template"),
|
|||
|
ellipsis: new TokenType("...", beforeExpr),
|
|||
|
backQuote: new TokenType("`", startsExpr),
|
|||
|
dollarBraceL: new TokenType("${", { beforeExpr: true, startsExpr: true }),
|
|||
|
|
|||
|
// Operators. These carry several kinds of properties to help the
|
|||
|
// parser use them properly (the presence of these properties is
|
|||
|
// what categorizes them as operators).
|
|||
|
//
|
|||
|
// `binop`, when present, specifies that this operator is a binary
|
|||
|
// operator, and will refer to its precedence.
|
|||
|
//
|
|||
|
// `prefix` and `postfix` mark the operator as a prefix or postfix
|
|||
|
// unary operator.
|
|||
|
//
|
|||
|
// `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
|
|||
|
// binary operators with a very low precedence, that should result
|
|||
|
// in AssignmentExpression nodes.
|
|||
|
|
|||
|
eq: new TokenType("=", { beforeExpr: true, isAssign: true }),
|
|||
|
assign: new TokenType("_=", { beforeExpr: true, isAssign: true }),
|
|||
|
incDec: new TokenType("++/--", { prefix: true, postfix: true, startsExpr: true }),
|
|||
|
prefix: new TokenType("prefix", { beforeExpr: true, prefix: true, startsExpr: true }),
|
|||
|
logicalOR: binop("||", 1),
|
|||
|
logicalAND: binop("&&", 2),
|
|||
|
bitwiseOR: binop("|", 3),
|
|||
|
bitwiseXOR: binop("^", 4),
|
|||
|
bitwiseAND: binop("&", 5),
|
|||
|
equality: binop("==/!=", 6),
|
|||
|
relational: binop("</>", 7),
|
|||
|
bitShift: binop("<</>>", 8),
|
|||
|
plusMin: new TokenType("+/-", { beforeExpr: true, binop: 9, prefix: true, startsExpr: true }),
|
|||
|
modulo: binop("%", 10),
|
|||
|
star: binop("*", 10),
|
|||
|
slash: binop("/", 10),
|
|||
|
starstar: new TokenType("**", { beforeExpr: true })
|
|||
|
};
|
|||
|
|
|||
|
exports.types = types;
|
|||
|
// Map keyword names to token types.
|
|||
|
|
|||
|
var keywords = {};
|
|||
|
|
|||
|
exports.keywords = keywords;
|
|||
|
// Succinct definitions of keyword token types
|
|||
|
function kw(name) {
|
|||
|
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
|||
|
|
|||
|
options.keyword = name;
|
|||
|
keywords[name] = types["_" + name] = new TokenType(name, options);
|
|||
|
}
|
|||
|
|
|||
|
kw("break");
|
|||
|
kw("case", beforeExpr);
|
|||
|
kw("catch");
|
|||
|
kw("continue");
|
|||
|
kw("debugger");
|
|||
|
kw("default", beforeExpr);
|
|||
|
kw("do", { isLoop: true, beforeExpr: true });
|
|||
|
kw("else", beforeExpr);
|
|||
|
kw("finally");
|
|||
|
kw("for", { isLoop: true });
|
|||
|
kw("function", startsExpr);
|
|||
|
kw("if");
|
|||
|
kw("return", beforeExpr);
|
|||
|
kw("switch");
|
|||
|
kw("throw", beforeExpr);
|
|||
|
kw("try");
|
|||
|
kw("var");
|
|||
|
kw("const");
|
|||
|
kw("while", { isLoop: true });
|
|||
|
kw("with");
|
|||
|
kw("new", { beforeExpr: true, startsExpr: true });
|
|||
|
kw("this", startsExpr);
|
|||
|
kw("super", startsExpr);
|
|||
|
kw("class");
|
|||
|
kw("extends", beforeExpr);
|
|||
|
kw("export");
|
|||
|
kw("import");
|
|||
|
kw("null", startsExpr);
|
|||
|
kw("true", startsExpr);
|
|||
|
kw("false", startsExpr);
|
|||
|
kw("in", { beforeExpr: true, binop: 7 });
|
|||
|
kw("instanceof", { beforeExpr: true, binop: 7 });
|
|||
|
kw("typeof", { beforeExpr: true, prefix: true, startsExpr: true });
|
|||
|
kw("void", { beforeExpr: true, prefix: true, startsExpr: true });
|
|||
|
kw("delete", { beforeExpr: true, prefix: true, startsExpr: true });
|
|||
|
|
|||
|
},{}],15:[function(_dereq_,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
exports.isArray = isArray;
|
|||
|
exports.has = has;
|
|||
|
|
|||
|
function isArray(obj) {
|
|||
|
return Object.prototype.toString.call(obj) === "[object Array]";
|
|||
|
}
|
|||
|
|
|||
|
// Checks if an object has a property.
|
|||
|
|
|||
|
function has(obj, propName) {
|
|||
|
return Object.prototype.hasOwnProperty.call(obj, propName);
|
|||
|
}
|
|||
|
|
|||
|
},{}],16:[function(_dereq_,module,exports){
|
|||
|
// Matches a whole line break (where CRLF is considered a single
|
|||
|
// line break). Used to count lines.
|
|||
|
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
exports.isNewLine = isNewLine;
|
|||
|
var lineBreak = /\r\n?|\n|\u2028|\u2029/;
|
|||
|
exports.lineBreak = lineBreak;
|
|||
|
var lineBreakG = new RegExp(lineBreak.source, "g");
|
|||
|
|
|||
|
exports.lineBreakG = lineBreakG;
|
|||
|
|
|||
|
function isNewLine(code) {
|
|||
|
return code === 10 || code === 13 || code === 0x2028 || code == 0x2029;
|
|||
|
}
|
|||
|
|
|||
|
var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
|
|||
|
|
|||
|
exports.nonASCIIwhitespace = nonASCIIwhitespace;
|
|||
|
var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
|
|||
|
exports.skipWhiteSpace = skipWhiteSpace;
|
|||
|
|
|||
|
},{}]},{},[3])(3)
|
|||
|
});
|
|||
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|||
|
},{}],6:[function(_dereq_,module,exports){
|
|||
|
_dereq_('../../modules/es6.array.filter');
|
|||
|
module.exports = _dereq_('../../modules/_core').Array.filter;
|
|||
|
},{"../../modules/_core":23,"../../modules/es6.array.filter":57}],7:[function(_dereq_,module,exports){
|
|||
|
_dereq_('../../modules/es6.array.for-each');
|
|||
|
module.exports = _dereq_('../../modules/_core').Array.forEach;
|
|||
|
},{"../../modules/_core":23,"../../modules/es6.array.for-each":58}],8:[function(_dereq_,module,exports){
|
|||
|
_dereq_('../../modules/es6.array.index-of');
|
|||
|
module.exports = _dereq_('../../modules/_core').Array.indexOf;
|
|||
|
},{"../../modules/_core":23,"../../modules/es6.array.index-of":59}],9:[function(_dereq_,module,exports){
|
|||
|
_dereq_('../../modules/es6.array.is-array');
|
|||
|
module.exports = _dereq_('../../modules/_core').Array.isArray;
|
|||
|
},{"../../modules/_core":23,"../../modules/es6.array.is-array":60}],10:[function(_dereq_,module,exports){
|
|||
|
_dereq_('../../modules/es6.array.map');
|
|||
|
module.exports = _dereq_('../../modules/_core').Array.map;
|
|||
|
},{"../../modules/_core":23,"../../modules/es6.array.map":61}],11:[function(_dereq_,module,exports){
|
|||
|
_dereq_('../../modules/es6.array.reduce-right');
|
|||
|
module.exports = _dereq_('../../modules/_core').Array.reduceRight;
|
|||
|
},{"../../modules/_core":23,"../../modules/es6.array.reduce-right":62}],12:[function(_dereq_,module,exports){
|
|||
|
_dereq_('../../modules/es6.array.reduce');
|
|||
|
module.exports = _dereq_('../../modules/_core').Array.reduce;
|
|||
|
},{"../../modules/_core":23,"../../modules/es6.array.reduce":63}],13:[function(_dereq_,module,exports){
|
|||
|
_dereq_('../../modules/es6.object.assign');
|
|||
|
module.exports = _dereq_('../../modules/_core').Object.assign;
|
|||
|
},{"../../modules/_core":23,"../../modules/es6.object.assign":64}],14:[function(_dereq_,module,exports){
|
|||
|
_dereq_('../../modules/es6.object.keys');
|
|||
|
module.exports = _dereq_('../../modules/_core').Object.keys;
|
|||
|
},{"../../modules/_core":23,"../../modules/es6.object.keys":65}],15:[function(_dereq_,module,exports){
|
|||
|
module.exports = function(it){
|
|||
|
if(typeof it != 'function')throw TypeError(it + ' is not a function!');
|
|||
|
return it;
|
|||
|
};
|
|||
|
},{}],16:[function(_dereq_,module,exports){
|
|||
|
var isObject = _dereq_('./_is-object');
|
|||
|
module.exports = function(it){
|
|||
|
if(!isObject(it))throw TypeError(it + ' is not an object!');
|
|||
|
return it;
|
|||
|
};
|
|||
|
},{"./_is-object":37}],17:[function(_dereq_,module,exports){
|
|||
|
// false -> Array#indexOf
|
|||
|
// true -> Array#includes
|
|||
|
var toIObject = _dereq_('./_to-iobject')
|
|||
|
, toLength = _dereq_('./_to-length')
|
|||
|
, toIndex = _dereq_('./_to-index');
|
|||
|
module.exports = function(IS_INCLUDES){
|
|||
|
return function($this, el, fromIndex){
|
|||
|
var O = toIObject($this)
|
|||
|
, length = toLength(O.length)
|
|||
|
, index = toIndex(fromIndex, length)
|
|||
|
, value;
|
|||
|
// Array#includes uses SameValueZero equality algorithm
|
|||
|
if(IS_INCLUDES && el != el)while(length > index){
|
|||
|
value = O[index++];
|
|||
|
if(value != value)return true;
|
|||
|
// Array#toIndex ignores holes, Array#includes - not
|
|||
|
} else for(;length > index; index++)if(IS_INCLUDES || index in O){
|
|||
|
if(O[index] === el)return IS_INCLUDES || index || 0;
|
|||
|
} return !IS_INCLUDES && -1;
|
|||
|
};
|
|||
|
};
|
|||
|
},{"./_to-index":49,"./_to-iobject":51,"./_to-length":52}],18:[function(_dereq_,module,exports){
|
|||
|
// 0 -> Array#forEach
|
|||
|
// 1 -> Array#map
|
|||
|
// 2 -> Array#filter
|
|||
|
// 3 -> Array#some
|
|||
|
// 4 -> Array#every
|
|||
|
// 5 -> Array#find
|
|||
|
// 6 -> Array#findIndex
|
|||
|
var ctx = _dereq_('./_ctx')
|
|||
|
, IObject = _dereq_('./_iobject')
|
|||
|
, toObject = _dereq_('./_to-object')
|
|||
|
, toLength = _dereq_('./_to-length')
|
|||
|
, asc = _dereq_('./_array-species-create');
|
|||
|
module.exports = function(TYPE, $create){
|
|||
|
var IS_MAP = TYPE == 1
|
|||
|
, IS_FILTER = TYPE == 2
|
|||
|
, IS_SOME = TYPE == 3
|
|||
|
, IS_EVERY = TYPE == 4
|
|||
|
, IS_FIND_INDEX = TYPE == 6
|
|||
|
, NO_HOLES = TYPE == 5 || IS_FIND_INDEX
|
|||
|
, create = $create || asc;
|
|||
|
return function($this, callbackfn, that){
|
|||
|
var O = toObject($this)
|
|||
|
, self = IObject(O)
|
|||
|
, f = ctx(callbackfn, that, 3)
|
|||
|
, length = toLength(self.length)
|
|||
|
, index = 0
|
|||
|
, result = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined
|
|||
|
, val, res;
|
|||
|
for(;length > index; index++)if(NO_HOLES || index in self){
|
|||
|
val = self[index];
|
|||
|
res = f(val, index, O);
|
|||
|
if(TYPE){
|
|||
|
if(IS_MAP)result[index] = res; // map
|
|||
|
else if(res)switch(TYPE){
|
|||
|
case 3: return true; // some
|
|||
|
case 5: return val; // find
|
|||
|
case 6: return index; // findIndex
|
|||
|
case 2: result.push(val); // filter
|
|||
|
} else if(IS_EVERY)return false; // every
|
|||
|
}
|
|||
|
}
|
|||
|
return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result;
|
|||
|
};
|
|||
|
};
|
|||
|
},{"./_array-species-create":21,"./_ctx":24,"./_iobject":35,"./_to-length":52,"./_to-object":53}],19:[function(_dereq_,module,exports){
|
|||
|
var aFunction = _dereq_('./_a-function')
|
|||
|
, toObject = _dereq_('./_to-object')
|
|||
|
, IObject = _dereq_('./_iobject')
|
|||
|
, toLength = _dereq_('./_to-length');
|
|||
|
|
|||
|
module.exports = function(that, callbackfn, aLen, memo, isRight){
|
|||
|
aFunction(callbackfn);
|
|||
|
var O = toObject(that)
|
|||
|
, self = IObject(O)
|
|||
|
, length = toLength(O.length)
|
|||
|
, index = isRight ? length - 1 : 0
|
|||
|
, i = isRight ? -1 : 1;
|
|||
|
if(aLen < 2)for(;;){
|
|||
|
if(index in self){
|
|||
|
memo = self[index];
|
|||
|
index += i;
|
|||
|
break;
|
|||
|
}
|
|||
|
index += i;
|
|||
|
if(isRight ? index < 0 : length <= index){
|
|||
|
throw TypeError('Reduce of empty array with no initial value');
|
|||
|
}
|
|||
|
}
|
|||
|
for(;isRight ? index >= 0 : length > index; index += i)if(index in self){
|
|||
|
memo = callbackfn(memo, self[index], index, O);
|
|||
|
}
|
|||
|
return memo;
|
|||
|
};
|
|||
|
},{"./_a-function":15,"./_iobject":35,"./_to-length":52,"./_to-object":53}],20:[function(_dereq_,module,exports){
|
|||
|
var isObject = _dereq_('./_is-object')
|
|||
|
, isArray = _dereq_('./_is-array')
|
|||
|
, SPECIES = _dereq_('./_wks')('species');
|
|||
|
|
|||
|
module.exports = function(original){
|
|||
|
var C;
|
|||
|
if(isArray(original)){
|
|||
|
C = original.constructor;
|
|||
|
// cross-realm fallback
|
|||
|
if(typeof C == 'function' && (C === Array || isArray(C.prototype)))C = undefined;
|
|||
|
if(isObject(C)){
|
|||
|
C = C[SPECIES];
|
|||
|
if(C === null)C = undefined;
|
|||
|
}
|
|||
|
} return C === undefined ? Array : C;
|
|||
|
};
|
|||
|
},{"./_is-array":36,"./_is-object":37,"./_wks":56}],21:[function(_dereq_,module,exports){
|
|||
|
// 9.4.2.3 ArraySpeciesCreate(originalArray, length)
|
|||
|
var speciesConstructor = _dereq_('./_array-species-constructor');
|
|||
|
|
|||
|
module.exports = function(original, length){
|
|||
|
return new (speciesConstructor(original))(length);
|
|||
|
};
|
|||
|
},{"./_array-species-constructor":20}],22:[function(_dereq_,module,exports){
|
|||
|
var toString = {}.toString;
|
|||
|
|
|||
|
module.exports = function(it){
|
|||
|
return toString.call(it).slice(8, -1);
|
|||
|
};
|
|||
|
},{}],23:[function(_dereq_,module,exports){
|
|||
|
var core = module.exports = {version: '2.4.0'};
|
|||
|
if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef
|
|||
|
},{}],24:[function(_dereq_,module,exports){
|
|||
|
// optional / simple context binding
|
|||
|
var aFunction = _dereq_('./_a-function');
|
|||
|
module.exports = function(fn, that, length){
|
|||
|
aFunction(fn);
|
|||
|
if(that === undefined)return fn;
|
|||
|
switch(length){
|
|||
|
case 1: return function(a){
|
|||
|
return fn.call(that, a);
|
|||
|
};
|
|||
|
case 2: return function(a, b){
|
|||
|
return fn.call(that, a, b);
|
|||
|
};
|
|||
|
case 3: return function(a, b, c){
|
|||
|
return fn.call(that, a, b, c);
|
|||
|
};
|
|||
|
}
|
|||
|
return function(/* ...args */){
|
|||
|
return fn.apply(that, arguments);
|
|||
|
};
|
|||
|
};
|
|||
|
},{"./_a-function":15}],25:[function(_dereq_,module,exports){
|
|||
|
// 7.2.1 RequireObjectCoercible(argument)
|
|||
|
module.exports = function(it){
|
|||
|
if(it == undefined)throw TypeError("Can't call method on " + it);
|
|||
|
return it;
|
|||
|
};
|
|||
|
},{}],26:[function(_dereq_,module,exports){
|
|||
|
// Thank's IE8 for his funny defineProperty
|
|||
|
module.exports = !_dereq_('./_fails')(function(){
|
|||
|
return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7;
|
|||
|
});
|
|||
|
},{"./_fails":30}],27:[function(_dereq_,module,exports){
|
|||
|
var isObject = _dereq_('./_is-object')
|
|||
|
, document = _dereq_('./_global').document
|
|||
|
// in old IE typeof document.createElement is 'object'
|
|||
|
, is = isObject(document) && isObject(document.createElement);
|
|||
|
module.exports = function(it){
|
|||
|
return is ? document.createElement(it) : {};
|
|||
|
};
|
|||
|
},{"./_global":31,"./_is-object":37}],28:[function(_dereq_,module,exports){
|
|||
|
// IE 8- don't enum bug keys
|
|||
|
module.exports = (
|
|||
|
'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'
|
|||
|
).split(',');
|
|||
|
},{}],29:[function(_dereq_,module,exports){
|
|||
|
var global = _dereq_('./_global')
|
|||
|
, core = _dereq_('./_core')
|
|||
|
, ctx = _dereq_('./_ctx')
|
|||
|
, hide = _dereq_('./_hide')
|
|||
|
, PROTOTYPE = 'prototype';
|
|||
|
|
|||
|
var $export = function(type, name, source){
|
|||
|
var IS_FORCED = type & $export.F
|
|||
|
, IS_GLOBAL = type & $export.G
|
|||
|
, IS_STATIC = type & $export.S
|
|||
|
, IS_PROTO = type & $export.P
|
|||
|
, IS_BIND = type & $export.B
|
|||
|
, IS_WRAP = type & $export.W
|
|||
|
, exports = IS_GLOBAL ? core : core[name] || (core[name] = {})
|
|||
|
, expProto = exports[PROTOTYPE]
|
|||
|
, target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE]
|
|||
|
, key, own, out;
|
|||
|
if(IS_GLOBAL)source = name;
|
|||
|
for(key in source){
|
|||
|
// contains in native
|
|||
|
own = !IS_FORCED && target && target[key] !== undefined;
|
|||
|
if(own && key in exports)continue;
|
|||
|
// export native or passed
|
|||
|
out = own ? target[key] : source[key];
|
|||
|
// prevent global pollution for namespaces
|
|||
|
exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key]
|
|||
|
// bind timers to global for call from export context
|
|||
|
: IS_BIND && own ? ctx(out, global)
|
|||
|
// wrap global constructors for prevent change them in library
|
|||
|
: IS_WRAP && target[key] == out ? (function(C){
|
|||
|
var F = function(a, b, c){
|
|||
|
if(this instanceof C){
|
|||
|
switch(arguments.length){
|
|||
|
case 0: return new C;
|
|||
|
case 1: return new C(a);
|
|||
|
case 2: return new C(a, b);
|
|||
|
} return new C(a, b, c);
|
|||
|
} return C.apply(this, arguments);
|
|||
|
};
|
|||
|
F[PROTOTYPE] = C[PROTOTYPE];
|
|||
|
return F;
|
|||
|
// make static versions for prototype methods
|
|||
|
})(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
|
|||
|
// export proto methods to core.%CONSTRUCTOR%.methods.%NAME%
|
|||
|
if(IS_PROTO){
|
|||
|
(exports.virtual || (exports.virtual = {}))[key] = out;
|
|||
|
// export proto methods to core.%CONSTRUCTOR%.prototype.%NAME%
|
|||
|
if(type & $export.R && expProto && !expProto[key])hide(expProto, key, out);
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
// type bitmap
|
|||
|
$export.F = 1; // forced
|
|||
|
$export.G = 2; // global
|
|||
|
$export.S = 4; // static
|
|||
|
$export.P = 8; // proto
|
|||
|
$export.B = 16; // bind
|
|||
|
$export.W = 32; // wrap
|
|||
|
$export.U = 64; // safe
|
|||
|
$export.R = 128; // real proto method for `library`
|
|||
|
module.exports = $export;
|
|||
|
},{"./_core":23,"./_ctx":24,"./_global":31,"./_hide":33}],30:[function(_dereq_,module,exports){
|
|||
|
module.exports = function(exec){
|
|||
|
try {
|
|||
|
return !!exec();
|
|||
|
} catch(e){
|
|||
|
return true;
|
|||
|
}
|
|||
|
};
|
|||
|
},{}],31:[function(_dereq_,module,exports){
|
|||
|
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
|||
|
var global = module.exports = typeof window != 'undefined' && window.Math == Math
|
|||
|
? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
|
|||
|
if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef
|
|||
|
},{}],32:[function(_dereq_,module,exports){
|
|||
|
var hasOwnProperty = {}.hasOwnProperty;
|
|||
|
module.exports = function(it, key){
|
|||
|
return hasOwnProperty.call(it, key);
|
|||
|
};
|
|||
|
},{}],33:[function(_dereq_,module,exports){
|
|||
|
var dP = _dereq_('./_object-dp')
|
|||
|
, createDesc = _dereq_('./_property-desc');
|
|||
|
module.exports = _dereq_('./_descriptors') ? function(object, key, value){
|
|||
|
return dP.f(object, key, createDesc(1, value));
|
|||
|
} : function(object, key, value){
|
|||
|
object[key] = value;
|
|||
|
return object;
|
|||
|
};
|
|||
|
},{"./_descriptors":26,"./_object-dp":39,"./_property-desc":45}],34:[function(_dereq_,module,exports){
|
|||
|
module.exports = !_dereq_('./_descriptors') && !_dereq_('./_fails')(function(){
|
|||
|
return Object.defineProperty(_dereq_('./_dom-create')('div'), 'a', {get: function(){ return 7; }}).a != 7;
|
|||
|
});
|
|||
|
},{"./_descriptors":26,"./_dom-create":27,"./_fails":30}],35:[function(_dereq_,module,exports){
|
|||
|
// fallback for non-array-like ES3 and non-enumerable old V8 strings
|
|||
|
var cof = _dereq_('./_cof');
|
|||
|
module.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){
|
|||
|
return cof(it) == 'String' ? it.split('') : Object(it);
|
|||
|
};
|
|||
|
},{"./_cof":22}],36:[function(_dereq_,module,exports){
|
|||
|
// 7.2.2 IsArray(argument)
|
|||
|
var cof = _dereq_('./_cof');
|
|||
|
module.exports = Array.isArray || function isArray(arg){
|
|||
|
return cof(arg) == 'Array';
|
|||
|
};
|
|||
|
},{"./_cof":22}],37:[function(_dereq_,module,exports){
|
|||
|
module.exports = function(it){
|
|||
|
return typeof it === 'object' ? it !== null : typeof it === 'function';
|
|||
|
};
|
|||
|
},{}],38:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
// 19.1.2.1 Object.assign(target, source, ...)
|
|||
|
var getKeys = _dereq_('./_object-keys')
|
|||
|
, gOPS = _dereq_('./_object-gops')
|
|||
|
, pIE = _dereq_('./_object-pie')
|
|||
|
, toObject = _dereq_('./_to-object')
|
|||
|
, IObject = _dereq_('./_iobject')
|
|||
|
, $assign = Object.assign;
|
|||
|
|
|||
|
// should work with symbols and should have deterministic property order (V8 bug)
|
|||
|
module.exports = !$assign || _dereq_('./_fails')(function(){
|
|||
|
var A = {}
|
|||
|
, B = {}
|
|||
|
, S = Symbol()
|
|||
|
, K = 'abcdefghijklmnopqrst';
|
|||
|
A[S] = 7;
|
|||
|
K.split('').forEach(function(k){ B[k] = k; });
|
|||
|
return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K;
|
|||
|
}) ? function assign(target, source){ // eslint-disable-line no-unused-vars
|
|||
|
var T = toObject(target)
|
|||
|
, aLen = arguments.length
|
|||
|
, index = 1
|
|||
|
, getSymbols = gOPS.f
|
|||
|
, isEnum = pIE.f;
|
|||
|
while(aLen > index){
|
|||
|
var S = IObject(arguments[index++])
|
|||
|
, keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S)
|
|||
|
, length = keys.length
|
|||
|
, j = 0
|
|||
|
, key;
|
|||
|
while(length > j)if(isEnum.call(S, key = keys[j++]))T[key] = S[key];
|
|||
|
} return T;
|
|||
|
} : $assign;
|
|||
|
},{"./_fails":30,"./_iobject":35,"./_object-gops":40,"./_object-keys":42,"./_object-pie":43,"./_to-object":53}],39:[function(_dereq_,module,exports){
|
|||
|
var anObject = _dereq_('./_an-object')
|
|||
|
, IE8_DOM_DEFINE = _dereq_('./_ie8-dom-define')
|
|||
|
, toPrimitive = _dereq_('./_to-primitive')
|
|||
|
, dP = Object.defineProperty;
|
|||
|
|
|||
|
exports.f = _dereq_('./_descriptors') ? Object.defineProperty : function defineProperty(O, P, Attributes){
|
|||
|
anObject(O);
|
|||
|
P = toPrimitive(P, true);
|
|||
|
anObject(Attributes);
|
|||
|
if(IE8_DOM_DEFINE)try {
|
|||
|
return dP(O, P, Attributes);
|
|||
|
} catch(e){ /* empty */ }
|
|||
|
if('get' in Attributes || 'set' in Attributes)throw TypeError('Accessors not supported!');
|
|||
|
if('value' in Attributes)O[P] = Attributes.value;
|
|||
|
return O;
|
|||
|
};
|
|||
|
},{"./_an-object":16,"./_descriptors":26,"./_ie8-dom-define":34,"./_to-primitive":54}],40:[function(_dereq_,module,exports){
|
|||
|
exports.f = Object.getOwnPropertySymbols;
|
|||
|
},{}],41:[function(_dereq_,module,exports){
|
|||
|
var has = _dereq_('./_has')
|
|||
|
, toIObject = _dereq_('./_to-iobject')
|
|||
|
, arrayIndexOf = _dereq_('./_array-includes')(false)
|
|||
|
, IE_PROTO = _dereq_('./_shared-key')('IE_PROTO');
|
|||
|
|
|||
|
module.exports = function(object, names){
|
|||
|
var O = toIObject(object)
|
|||
|
, i = 0
|
|||
|
, result = []
|
|||
|
, key;
|
|||
|
for(key in O)if(key != IE_PROTO)has(O, key) && result.push(key);
|
|||
|
// Don't enum bug & hidden keys
|
|||
|
while(names.length > i)if(has(O, key = names[i++])){
|
|||
|
~arrayIndexOf(result, key) || result.push(key);
|
|||
|
}
|
|||
|
return result;
|
|||
|
};
|
|||
|
},{"./_array-includes":17,"./_has":32,"./_shared-key":46,"./_to-iobject":51}],42:[function(_dereq_,module,exports){
|
|||
|
// 19.1.2.14 / 15.2.3.14 Object.keys(O)
|
|||
|
var $keys = _dereq_('./_object-keys-internal')
|
|||
|
, enumBugKeys = _dereq_('./_enum-bug-keys');
|
|||
|
|
|||
|
module.exports = Object.keys || function keys(O){
|
|||
|
return $keys(O, enumBugKeys);
|
|||
|
};
|
|||
|
},{"./_enum-bug-keys":28,"./_object-keys-internal":41}],43:[function(_dereq_,module,exports){
|
|||
|
exports.f = {}.propertyIsEnumerable;
|
|||
|
},{}],44:[function(_dereq_,module,exports){
|
|||
|
// most Object methods by ES6 should accept primitives
|
|||
|
var $export = _dereq_('./_export')
|
|||
|
, core = _dereq_('./_core')
|
|||
|
, fails = _dereq_('./_fails');
|
|||
|
module.exports = function(KEY, exec){
|
|||
|
var fn = (core.Object || {})[KEY] || Object[KEY]
|
|||
|
, exp = {};
|
|||
|
exp[KEY] = exec(fn);
|
|||
|
$export($export.S + $export.F * fails(function(){ fn(1); }), 'Object', exp);
|
|||
|
};
|
|||
|
},{"./_core":23,"./_export":29,"./_fails":30}],45:[function(_dereq_,module,exports){
|
|||
|
module.exports = function(bitmap, value){
|
|||
|
return {
|
|||
|
enumerable : !(bitmap & 1),
|
|||
|
configurable: !(bitmap & 2),
|
|||
|
writable : !(bitmap & 4),
|
|||
|
value : value
|
|||
|
};
|
|||
|
};
|
|||
|
},{}],46:[function(_dereq_,module,exports){
|
|||
|
var shared = _dereq_('./_shared')('keys')
|
|||
|
, uid = _dereq_('./_uid');
|
|||
|
module.exports = function(key){
|
|||
|
return shared[key] || (shared[key] = uid(key));
|
|||
|
};
|
|||
|
},{"./_shared":47,"./_uid":55}],47:[function(_dereq_,module,exports){
|
|||
|
var global = _dereq_('./_global')
|
|||
|
, SHARED = '__core-js_shared__'
|
|||
|
, store = global[SHARED] || (global[SHARED] = {});
|
|||
|
module.exports = function(key){
|
|||
|
return store[key] || (store[key] = {});
|
|||
|
};
|
|||
|
},{"./_global":31}],48:[function(_dereq_,module,exports){
|
|||
|
var fails = _dereq_('./_fails');
|
|||
|
|
|||
|
module.exports = function(method, arg){
|
|||
|
return !!method && fails(function(){
|
|||
|
arg ? method.call(null, function(){}, 1) : method.call(null);
|
|||
|
});
|
|||
|
};
|
|||
|
},{"./_fails":30}],49:[function(_dereq_,module,exports){
|
|||
|
var toInteger = _dereq_('./_to-integer')
|
|||
|
, max = Math.max
|
|||
|
, min = Math.min;
|
|||
|
module.exports = function(index, length){
|
|||
|
index = toInteger(index);
|
|||
|
return index < 0 ? max(index + length, 0) : min(index, length);
|
|||
|
};
|
|||
|
},{"./_to-integer":50}],50:[function(_dereq_,module,exports){
|
|||
|
// 7.1.4 ToInteger
|
|||
|
var ceil = Math.ceil
|
|||
|
, floor = Math.floor;
|
|||
|
module.exports = function(it){
|
|||
|
return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
|
|||
|
};
|
|||
|
},{}],51:[function(_dereq_,module,exports){
|
|||
|
// to indexed object, toObject with fallback for non-array-like ES3 strings
|
|||
|
var IObject = _dereq_('./_iobject')
|
|||
|
, defined = _dereq_('./_defined');
|
|||
|
module.exports = function(it){
|
|||
|
return IObject(defined(it));
|
|||
|
};
|
|||
|
},{"./_defined":25,"./_iobject":35}],52:[function(_dereq_,module,exports){
|
|||
|
// 7.1.15 ToLength
|
|||
|
var toInteger = _dereq_('./_to-integer')
|
|||
|
, min = Math.min;
|
|||
|
module.exports = function(it){
|
|||
|
return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
|
|||
|
};
|
|||
|
},{"./_to-integer":50}],53:[function(_dereq_,module,exports){
|
|||
|
// 7.1.13 ToObject(argument)
|
|||
|
var defined = _dereq_('./_defined');
|
|||
|
module.exports = function(it){
|
|||
|
return Object(defined(it));
|
|||
|
};
|
|||
|
},{"./_defined":25}],54:[function(_dereq_,module,exports){
|
|||
|
// 7.1.1 ToPrimitive(input [, PreferredType])
|
|||
|
var isObject = _dereq_('./_is-object');
|
|||
|
// instead of the ES6 spec version, we didn't implement @@toPrimitive case
|
|||
|
// and the second argument - flag - preferred type is a string
|
|||
|
module.exports = function(it, S){
|
|||
|
if(!isObject(it))return it;
|
|||
|
var fn, val;
|
|||
|
if(S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val;
|
|||
|
if(typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it)))return val;
|
|||
|
if(!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val;
|
|||
|
throw TypeError("Can't convert object to primitive value");
|
|||
|
};
|
|||
|
},{"./_is-object":37}],55:[function(_dereq_,module,exports){
|
|||
|
var id = 0
|
|||
|
, px = Math.random();
|
|||
|
module.exports = function(key){
|
|||
|
return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
|
|||
|
};
|
|||
|
},{}],56:[function(_dereq_,module,exports){
|
|||
|
var store = _dereq_('./_shared')('wks')
|
|||
|
, uid = _dereq_('./_uid')
|
|||
|
, Symbol = _dereq_('./_global').Symbol
|
|||
|
, USE_SYMBOL = typeof Symbol == 'function';
|
|||
|
|
|||
|
var $exports = module.exports = function(name){
|
|||
|
return store[name] || (store[name] =
|
|||
|
USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : uid)('Symbol.' + name));
|
|||
|
};
|
|||
|
|
|||
|
$exports.store = store;
|
|||
|
},{"./_global":31,"./_shared":47,"./_uid":55}],57:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
var $export = _dereq_('./_export')
|
|||
|
, $filter = _dereq_('./_array-methods')(2);
|
|||
|
|
|||
|
$export($export.P + $export.F * !_dereq_('./_strict-method')([].filter, true), 'Array', {
|
|||
|
// 22.1.3.7 / 15.4.4.20 Array.prototype.filter(callbackfn [, thisArg])
|
|||
|
filter: function filter(callbackfn /* , thisArg */){
|
|||
|
return $filter(this, callbackfn, arguments[1]);
|
|||
|
}
|
|||
|
});
|
|||
|
},{"./_array-methods":18,"./_export":29,"./_strict-method":48}],58:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
var $export = _dereq_('./_export')
|
|||
|
, $forEach = _dereq_('./_array-methods')(0)
|
|||
|
, STRICT = _dereq_('./_strict-method')([].forEach, true);
|
|||
|
|
|||
|
$export($export.P + $export.F * !STRICT, 'Array', {
|
|||
|
// 22.1.3.10 / 15.4.4.18 Array.prototype.forEach(callbackfn [, thisArg])
|
|||
|
forEach: function forEach(callbackfn /* , thisArg */){
|
|||
|
return $forEach(this, callbackfn, arguments[1]);
|
|||
|
}
|
|||
|
});
|
|||
|
},{"./_array-methods":18,"./_export":29,"./_strict-method":48}],59:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
var $export = _dereq_('./_export')
|
|||
|
, $indexOf = _dereq_('./_array-includes')(false)
|
|||
|
, $native = [].indexOf
|
|||
|
, NEGATIVE_ZERO = !!$native && 1 / [1].indexOf(1, -0) < 0;
|
|||
|
|
|||
|
$export($export.P + $export.F * (NEGATIVE_ZERO || !_dereq_('./_strict-method')($native)), 'Array', {
|
|||
|
// 22.1.3.11 / 15.4.4.14 Array.prototype.indexOf(searchElement [, fromIndex])
|
|||
|
indexOf: function indexOf(searchElement /*, fromIndex = 0 */){
|
|||
|
return NEGATIVE_ZERO
|
|||
|
// convert -0 to +0
|
|||
|
? $native.apply(this, arguments) || 0
|
|||
|
: $indexOf(this, searchElement, arguments[1]);
|
|||
|
}
|
|||
|
});
|
|||
|
},{"./_array-includes":17,"./_export":29,"./_strict-method":48}],60:[function(_dereq_,module,exports){
|
|||
|
// 22.1.2.2 / 15.4.3.2 Array.isArray(arg)
|
|||
|
var $export = _dereq_('./_export');
|
|||
|
|
|||
|
$export($export.S, 'Array', {isArray: _dereq_('./_is-array')});
|
|||
|
},{"./_export":29,"./_is-array":36}],61:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
var $export = _dereq_('./_export')
|
|||
|
, $map = _dereq_('./_array-methods')(1);
|
|||
|
|
|||
|
$export($export.P + $export.F * !_dereq_('./_strict-method')([].map, true), 'Array', {
|
|||
|
// 22.1.3.15 / 15.4.4.19 Array.prototype.map(callbackfn [, thisArg])
|
|||
|
map: function map(callbackfn /* , thisArg */){
|
|||
|
return $map(this, callbackfn, arguments[1]);
|
|||
|
}
|
|||
|
});
|
|||
|
},{"./_array-methods":18,"./_export":29,"./_strict-method":48}],62:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
var $export = _dereq_('./_export')
|
|||
|
, $reduce = _dereq_('./_array-reduce');
|
|||
|
|
|||
|
$export($export.P + $export.F * !_dereq_('./_strict-method')([].reduceRight, true), 'Array', {
|
|||
|
// 22.1.3.19 / 15.4.4.22 Array.prototype.reduceRight(callbackfn [, initialValue])
|
|||
|
reduceRight: function reduceRight(callbackfn /* , initialValue */){
|
|||
|
return $reduce(this, callbackfn, arguments.length, arguments[1], true);
|
|||
|
}
|
|||
|
});
|
|||
|
},{"./_array-reduce":19,"./_export":29,"./_strict-method":48}],63:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
var $export = _dereq_('./_export')
|
|||
|
, $reduce = _dereq_('./_array-reduce');
|
|||
|
|
|||
|
$export($export.P + $export.F * !_dereq_('./_strict-method')([].reduce, true), 'Array', {
|
|||
|
// 22.1.3.18 / 15.4.4.21 Array.prototype.reduce(callbackfn [, initialValue])
|
|||
|
reduce: function reduce(callbackfn /* , initialValue */){
|
|||
|
return $reduce(this, callbackfn, arguments.length, arguments[1], false);
|
|||
|
}
|
|||
|
});
|
|||
|
},{"./_array-reduce":19,"./_export":29,"./_strict-method":48}],64:[function(_dereq_,module,exports){
|
|||
|
// 19.1.3.1 Object.assign(target, source)
|
|||
|
var $export = _dereq_('./_export');
|
|||
|
|
|||
|
$export($export.S + $export.F, 'Object', {assign: _dereq_('./_object-assign')});
|
|||
|
},{"./_export":29,"./_object-assign":38}],65:[function(_dereq_,module,exports){
|
|||
|
// 19.1.2.14 Object.keys(O)
|
|||
|
var toObject = _dereq_('./_to-object')
|
|||
|
, $keys = _dereq_('./_object-keys');
|
|||
|
|
|||
|
_dereq_('./_object-sap')('keys', function(){
|
|||
|
return function keys(it){
|
|||
|
return $keys(toObject(it));
|
|||
|
};
|
|||
|
});
|
|||
|
},{"./_object-keys":42,"./_object-sap":44,"./_to-object":53}],66:[function(_dereq_,module,exports){
|
|||
|
'use strict'
|
|||
|
|
|||
|
/**
|
|||
|
* Diff Match and Patch
|
|||
|
*
|
|||
|
* Copyright 2006 Google Inc.
|
|||
|
* http://code.google.com/p/google-diff-match-patch/
|
|||
|
*
|
|||
|
* 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.
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* @fileoverview Computes the difference between two texts to create a patch.
|
|||
|
* Applies the patch onto another text, allowing for errors.
|
|||
|
* @author fraser@google.com (Neil Fraser)
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* Class containing the diff, match and patch methods.
|
|||
|
* @constructor
|
|||
|
*/
|
|||
|
function diff_match_patch() {
|
|||
|
|
|||
|
// Defaults.
|
|||
|
// Redefine these in your program to override the defaults.
|
|||
|
|
|||
|
// Number of seconds to map a diff before giving up (0 for infinity).
|
|||
|
this.Diff_Timeout = 1.0;
|
|||
|
// Cost of an empty edit operation in terms of edit characters.
|
|||
|
this.Diff_EditCost = 4;
|
|||
|
// At what point is no match declared (0.0 = perfection, 1.0 = very loose).
|
|||
|
this.Match_Threshold = 0.5;
|
|||
|
// How far to search for a match (0 = exact location, 1000+ = broad match).
|
|||
|
// A match this many characters away from the expected location will add
|
|||
|
// 1.0 to the score (0.0 is a perfect match).
|
|||
|
this.Match_Distance = 1000;
|
|||
|
// When deleting a large block of text (over ~64 characters), how close do
|
|||
|
// the contents have to be to match the expected contents. (0.0 = perfection,
|
|||
|
// 1.0 = very loose). Note that Match_Threshold controls how closely the
|
|||
|
// end points of a delete need to match.
|
|||
|
this.Patch_DeleteThreshold = 0.5;
|
|||
|
// Chunk size for context length.
|
|||
|
this.Patch_Margin = 4;
|
|||
|
|
|||
|
// The number of bits in an int.
|
|||
|
this.Match_MaxBits = 32;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// DIFF FUNCTIONS
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* The data structure representing a diff is an array of tuples:
|
|||
|
* [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
|
|||
|
* which means: delete 'Hello', add 'Goodbye' and keep ' world.'
|
|||
|
*/
|
|||
|
var DIFF_DELETE = -1;
|
|||
|
var DIFF_INSERT = 1;
|
|||
|
var DIFF_EQUAL = 0;
|
|||
|
|
|||
|
/** @typedef {{0: number, 1: string}} */
|
|||
|
diff_match_patch.Diff;
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Find the differences between two texts. Simplifies the problem by stripping
|
|||
|
* any common prefix or suffix off the texts before diffing.
|
|||
|
* @param {string} text1 Old string to be diffed.
|
|||
|
* @param {string} text2 New string to be diffed.
|
|||
|
* @param {boolean=} opt_checklines Optional speedup flag. If present and false,
|
|||
|
* then don't run a line-level diff first to identify the changed areas.
|
|||
|
* Defaults to true, which does a faster, slightly less optimal diff.
|
|||
|
* @param {number} opt_deadline Optional time when the diff should be complete
|
|||
|
* by. Used internally for recursive calls. Users should set DiffTimeout
|
|||
|
* instead.
|
|||
|
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_main = function(text1, text2, opt_checklines,
|
|||
|
opt_deadline) {
|
|||
|
// Set a deadline by which time the diff must be complete.
|
|||
|
if (typeof opt_deadline == 'undefined') {
|
|||
|
if (this.Diff_Timeout <= 0) {
|
|||
|
opt_deadline = Number.MAX_VALUE;
|
|||
|
} else {
|
|||
|
opt_deadline = (new Date).getTime() + this.Diff_Timeout * 1000;
|
|||
|
}
|
|||
|
}
|
|||
|
var deadline = opt_deadline;
|
|||
|
|
|||
|
// Check for null inputs.
|
|||
|
if (text1 == null || text2 == null) {
|
|||
|
throw new Error('Null input. (diff_main)');
|
|||
|
}
|
|||
|
|
|||
|
// Check for equality (speedup).
|
|||
|
if (text1 == text2) {
|
|||
|
if (text1) {
|
|||
|
return [[DIFF_EQUAL, text1]];
|
|||
|
}
|
|||
|
return [];
|
|||
|
}
|
|||
|
|
|||
|
if (typeof opt_checklines == 'undefined') {
|
|||
|
opt_checklines = true;
|
|||
|
}
|
|||
|
var checklines = opt_checklines;
|
|||
|
|
|||
|
// Trim off common prefix (speedup).
|
|||
|
var commonlength = this.diff_commonPrefix(text1, text2);
|
|||
|
var commonprefix = text1.substring(0, commonlength);
|
|||
|
text1 = text1.substring(commonlength);
|
|||
|
text2 = text2.substring(commonlength);
|
|||
|
|
|||
|
// Trim off common suffix (speedup).
|
|||
|
commonlength = this.diff_commonSuffix(text1, text2);
|
|||
|
var commonsuffix = text1.substring(text1.length - commonlength);
|
|||
|
text1 = text1.substring(0, text1.length - commonlength);
|
|||
|
text2 = text2.substring(0, text2.length - commonlength);
|
|||
|
|
|||
|
// Compute the diff on the middle block.
|
|||
|
var diffs = this.diff_compute_(text1, text2, checklines, deadline);
|
|||
|
|
|||
|
// Restore the prefix and suffix.
|
|||
|
if (commonprefix) {
|
|||
|
diffs.unshift([DIFF_EQUAL, commonprefix]);
|
|||
|
}
|
|||
|
if (commonsuffix) {
|
|||
|
diffs.push([DIFF_EQUAL, commonsuffix]);
|
|||
|
}
|
|||
|
this.diff_cleanupMerge(diffs);
|
|||
|
return diffs;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Find the differences between two texts. Assumes that the texts do not
|
|||
|
* have any common prefix or suffix.
|
|||
|
* @param {string} text1 Old string to be diffed.
|
|||
|
* @param {string} text2 New string to be diffed.
|
|||
|
* @param {boolean} checklines Speedup flag. If false, then don't run a
|
|||
|
* line-level diff first to identify the changed areas.
|
|||
|
* If true, then run a faster, slightly less optimal diff.
|
|||
|
* @param {number} deadline Time when the diff should be complete by.
|
|||
|
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines,
|
|||
|
deadline) {
|
|||
|
var diffs;
|
|||
|
|
|||
|
if (!text1) {
|
|||
|
// Just add some text (speedup).
|
|||
|
return [[DIFF_INSERT, text2]];
|
|||
|
}
|
|||
|
|
|||
|
if (!text2) {
|
|||
|
// Just delete some text (speedup).
|
|||
|
return [[DIFF_DELETE, text1]];
|
|||
|
}
|
|||
|
|
|||
|
var longtext = text1.length > text2.length ? text1 : text2;
|
|||
|
var shorttext = text1.length > text2.length ? text2 : text1;
|
|||
|
var i = longtext.indexOf(shorttext);
|
|||
|
if (i != -1) {
|
|||
|
// Shorter text is inside the longer text (speedup).
|
|||
|
diffs = [[DIFF_INSERT, longtext.substring(0, i)],
|
|||
|
[DIFF_EQUAL, shorttext],
|
|||
|
[DIFF_INSERT, longtext.substring(i + shorttext.length)]];
|
|||
|
// Swap insertions for deletions if diff is reversed.
|
|||
|
if (text1.length > text2.length) {
|
|||
|
diffs[0][0] = diffs[2][0] = DIFF_DELETE;
|
|||
|
}
|
|||
|
return diffs;
|
|||
|
}
|
|||
|
|
|||
|
if (shorttext.length == 1) {
|
|||
|
// Single character string.
|
|||
|
// After the previous speedup, the character can't be an equality.
|
|||
|
return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
|
|||
|
}
|
|||
|
|
|||
|
// Check to see if the problem can be split in two.
|
|||
|
var hm = this.diff_halfMatch_(text1, text2);
|
|||
|
if (hm) {
|
|||
|
// A half-match was found, sort out the return data.
|
|||
|
var text1_a = hm[0];
|
|||
|
var text1_b = hm[1];
|
|||
|
var text2_a = hm[2];
|
|||
|
var text2_b = hm[3];
|
|||
|
var mid_common = hm[4];
|
|||
|
// Send both pairs off for separate processing.
|
|||
|
var diffs_a = this.diff_main(text1_a, text2_a, checklines, deadline);
|
|||
|
var diffs_b = this.diff_main(text1_b, text2_b, checklines, deadline);
|
|||
|
// Merge the results.
|
|||
|
return diffs_a.concat([[DIFF_EQUAL, mid_common]], diffs_b);
|
|||
|
}
|
|||
|
|
|||
|
if (checklines && text1.length > 100 && text2.length > 100) {
|
|||
|
return this.diff_lineMode_(text1, text2, deadline);
|
|||
|
}
|
|||
|
|
|||
|
return this.diff_bisect_(text1, text2, deadline);
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Do a quick line-level diff on both strings, then rediff the parts for
|
|||
|
* greater accuracy.
|
|||
|
* This speedup can produce non-minimal diffs.
|
|||
|
* @param {string} text1 Old string to be diffed.
|
|||
|
* @param {string} text2 New string to be diffed.
|
|||
|
* @param {number} deadline Time when the diff should be complete by.
|
|||
|
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_lineMode_ = function(text1, text2, deadline) {
|
|||
|
// Scan the text on a line-by-line basis first.
|
|||
|
var a = this.diff_linesToChars_(text1, text2);
|
|||
|
text1 = a.chars1;
|
|||
|
text2 = a.chars2;
|
|||
|
var linearray = a.lineArray;
|
|||
|
|
|||
|
var diffs = this.diff_main(text1, text2, false, deadline);
|
|||
|
|
|||
|
// Convert the diff back to original text.
|
|||
|
this.diff_charsToLines_(diffs, linearray);
|
|||
|
// Eliminate freak matches (e.g. blank lines)
|
|||
|
this.diff_cleanupSemantic(diffs);
|
|||
|
|
|||
|
// Rediff any replacement blocks, this time character-by-character.
|
|||
|
// Add a dummy entry at the end.
|
|||
|
diffs.push([DIFF_EQUAL, '']);
|
|||
|
var pointer = 0;
|
|||
|
var count_delete = 0;
|
|||
|
var count_insert = 0;
|
|||
|
var text_delete = '';
|
|||
|
var text_insert = '';
|
|||
|
while (pointer < diffs.length) {
|
|||
|
switch (diffs[pointer][0]) {
|
|||
|
case DIFF_INSERT:
|
|||
|
count_insert++;
|
|||
|
text_insert += diffs[pointer][1];
|
|||
|
break;
|
|||
|
case DIFF_DELETE:
|
|||
|
count_delete++;
|
|||
|
text_delete += diffs[pointer][1];
|
|||
|
break;
|
|||
|
case DIFF_EQUAL:
|
|||
|
// Upon reaching an equality, check for prior redundancies.
|
|||
|
if (count_delete >= 1 && count_insert >= 1) {
|
|||
|
// Delete the offending records and add the merged ones.
|
|||
|
diffs.splice(pointer - count_delete - count_insert,
|
|||
|
count_delete + count_insert);
|
|||
|
pointer = pointer - count_delete - count_insert;
|
|||
|
var a = this.diff_main(text_delete, text_insert, false, deadline);
|
|||
|
for (var j = a.length - 1; j >= 0; j--) {
|
|||
|
diffs.splice(pointer, 0, a[j]);
|
|||
|
}
|
|||
|
pointer = pointer + a.length;
|
|||
|
}
|
|||
|
count_insert = 0;
|
|||
|
count_delete = 0;
|
|||
|
text_delete = '';
|
|||
|
text_insert = '';
|
|||
|
break;
|
|||
|
}
|
|||
|
pointer++;
|
|||
|
}
|
|||
|
diffs.pop(); // Remove the dummy entry at the end.
|
|||
|
|
|||
|
return diffs;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Find the 'middle snake' of a diff, split the problem in two
|
|||
|
* and return the recursively constructed diff.
|
|||
|
* See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
|
|||
|
* @param {string} text1 Old string to be diffed.
|
|||
|
* @param {string} text2 New string to be diffed.
|
|||
|
* @param {number} deadline Time at which to bail if not yet complete.
|
|||
|
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) {
|
|||
|
// Cache the text lengths to prevent multiple calls.
|
|||
|
var text1_length = text1.length;
|
|||
|
var text2_length = text2.length;
|
|||
|
var max_d = Math.ceil((text1_length + text2_length) / 2);
|
|||
|
var v_offset = max_d;
|
|||
|
var v_length = 2 * max_d;
|
|||
|
var v1 = new Array(v_length);
|
|||
|
var v2 = new Array(v_length);
|
|||
|
// Setting all elements to -1 is faster in Chrome & Firefox than mixing
|
|||
|
// integers and undefined.
|
|||
|
for (var x = 0; x < v_length; x++) {
|
|||
|
v1[x] = -1;
|
|||
|
v2[x] = -1;
|
|||
|
}
|
|||
|
v1[v_offset + 1] = 0;
|
|||
|
v2[v_offset + 1] = 0;
|
|||
|
var delta = text1_length - text2_length;
|
|||
|
// If the total number of characters is odd, then the front path will collide
|
|||
|
// with the reverse path.
|
|||
|
var front = (delta % 2 != 0);
|
|||
|
// Offsets for start and end of k loop.
|
|||
|
// Prevents mapping of space beyond the grid.
|
|||
|
var k1start = 0;
|
|||
|
var k1end = 0;
|
|||
|
var k2start = 0;
|
|||
|
var k2end = 0;
|
|||
|
for (var d = 0; d < max_d; d++) {
|
|||
|
// Bail out if deadline is reached.
|
|||
|
if ((new Date()).getTime() > deadline) {
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
// Walk the front path one step.
|
|||
|
for (var k1 = -d + k1start; k1 <= d - k1end; k1 += 2) {
|
|||
|
var k1_offset = v_offset + k1;
|
|||
|
var x1;
|
|||
|
if (k1 == -d || (k1 != d && v1[k1_offset - 1] < v1[k1_offset + 1])) {
|
|||
|
x1 = v1[k1_offset + 1];
|
|||
|
} else {
|
|||
|
x1 = v1[k1_offset - 1] + 1;
|
|||
|
}
|
|||
|
var y1 = x1 - k1;
|
|||
|
while (x1 < text1_length && y1 < text2_length &&
|
|||
|
text1.charAt(x1) == text2.charAt(y1)) {
|
|||
|
x1++;
|
|||
|
y1++;
|
|||
|
}
|
|||
|
v1[k1_offset] = x1;
|
|||
|
if (x1 > text1_length) {
|
|||
|
// Ran off the right of the graph.
|
|||
|
k1end += 2;
|
|||
|
} else if (y1 > text2_length) {
|
|||
|
// Ran off the bottom of the graph.
|
|||
|
k1start += 2;
|
|||
|
} else if (front) {
|
|||
|
var k2_offset = v_offset + delta - k1;
|
|||
|
if (k2_offset >= 0 && k2_offset < v_length && v2[k2_offset] != -1) {
|
|||
|
// Mirror x2 onto top-left coordinate system.
|
|||
|
var x2 = text1_length - v2[k2_offset];
|
|||
|
if (x1 >= x2) {
|
|||
|
// Overlap detected.
|
|||
|
return this.diff_bisectSplit_(text1, text2, x1, y1, deadline);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Walk the reverse path one step.
|
|||
|
for (var k2 = -d + k2start; k2 <= d - k2end; k2 += 2) {
|
|||
|
var k2_offset = v_offset + k2;
|
|||
|
var x2;
|
|||
|
if (k2 == -d || (k2 != d && v2[k2_offset - 1] < v2[k2_offset + 1])) {
|
|||
|
x2 = v2[k2_offset + 1];
|
|||
|
} else {
|
|||
|
x2 = v2[k2_offset - 1] + 1;
|
|||
|
}
|
|||
|
var y2 = x2 - k2;
|
|||
|
while (x2 < text1_length && y2 < text2_length &&
|
|||
|
text1.charAt(text1_length - x2 - 1) ==
|
|||
|
text2.charAt(text2_length - y2 - 1)) {
|
|||
|
x2++;
|
|||
|
y2++;
|
|||
|
}
|
|||
|
v2[k2_offset] = x2;
|
|||
|
if (x2 > text1_length) {
|
|||
|
// Ran off the left of the graph.
|
|||
|
k2end += 2;
|
|||
|
} else if (y2 > text2_length) {
|
|||
|
// Ran off the top of the graph.
|
|||
|
k2start += 2;
|
|||
|
} else if (!front) {
|
|||
|
var k1_offset = v_offset + delta - k2;
|
|||
|
if (k1_offset >= 0 && k1_offset < v_length && v1[k1_offset] != -1) {
|
|||
|
var x1 = v1[k1_offset];
|
|||
|
var y1 = v_offset + x1 - k1_offset;
|
|||
|
// Mirror x2 onto top-left coordinate system.
|
|||
|
x2 = text1_length - x2;
|
|||
|
if (x1 >= x2) {
|
|||
|
// Overlap detected.
|
|||
|
return this.diff_bisectSplit_(text1, text2, x1, y1, deadline);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
// Diff took too long and hit the deadline or
|
|||
|
// number of diffs equals number of characters, no commonality at all.
|
|||
|
return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Given the location of the 'middle snake', split the diff in two parts
|
|||
|
* and recurse.
|
|||
|
* @param {string} text1 Old string to be diffed.
|
|||
|
* @param {string} text2 New string to be diffed.
|
|||
|
* @param {number} x Index of split point in text1.
|
|||
|
* @param {number} y Index of split point in text2.
|
|||
|
* @param {number} deadline Time at which to bail if not yet complete.
|
|||
|
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_bisectSplit_ = function(text1, text2, x, y,
|
|||
|
deadline) {
|
|||
|
var text1a = text1.substring(0, x);
|
|||
|
var text2a = text2.substring(0, y);
|
|||
|
var text1b = text1.substring(x);
|
|||
|
var text2b = text2.substring(y);
|
|||
|
|
|||
|
// Compute both diffs serially.
|
|||
|
var diffs = this.diff_main(text1a, text2a, false, deadline);
|
|||
|
var diffsb = this.diff_main(text1b, text2b, false, deadline);
|
|||
|
|
|||
|
return diffs.concat(diffsb);
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Split two texts into an array of strings. Reduce the texts to a string of
|
|||
|
* hashes where each Unicode character represents one line.
|
|||
|
* @param {string} text1 First string.
|
|||
|
* @param {string} text2 Second string.
|
|||
|
* @return {{chars1: string, chars2: string, lineArray: !Array.<string>}}
|
|||
|
* An object containing the encoded text1, the encoded text2 and
|
|||
|
* the array of unique strings.
|
|||
|
* The zeroth element of the array of unique strings is intentionally blank.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) {
|
|||
|
var lineArray = []; // e.g. lineArray[4] == 'Hello\n'
|
|||
|
var lineHash = {}; // e.g. lineHash['Hello\n'] == 4
|
|||
|
|
|||
|
// '\x00' is a valid character, but various debuggers don't like it.
|
|||
|
// So we'll insert a junk entry to avoid generating a null character.
|
|||
|
lineArray[0] = '';
|
|||
|
|
|||
|
/**
|
|||
|
* Split a text into an array of strings. Reduce the texts to a string of
|
|||
|
* hashes where each Unicode character represents one line.
|
|||
|
* Modifies linearray and linehash through being a closure.
|
|||
|
* @param {string} text String to encode.
|
|||
|
* @return {string} Encoded string.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
function diff_linesToCharsMunge_(text) {
|
|||
|
var chars = '';
|
|||
|
// Walk the text, pulling out a substring for each line.
|
|||
|
// text.split('\n') would would temporarily double our memory footprint.
|
|||
|
// Modifying text would create many large strings to garbage collect.
|
|||
|
var lineStart = 0;
|
|||
|
var lineEnd = -1;
|
|||
|
// Keeping our own length variable is faster than looking it up.
|
|||
|
var lineArrayLength = lineArray.length;
|
|||
|
while (lineEnd < text.length - 1) {
|
|||
|
lineEnd = text.indexOf('\n', lineStart);
|
|||
|
if (lineEnd == -1) {
|
|||
|
lineEnd = text.length - 1;
|
|||
|
}
|
|||
|
var line = text.substring(lineStart, lineEnd + 1);
|
|||
|
lineStart = lineEnd + 1;
|
|||
|
|
|||
|
if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) :
|
|||
|
(lineHash[line] !== undefined)) {
|
|||
|
chars += String.fromCharCode(lineHash[line]);
|
|||
|
} else {
|
|||
|
chars += String.fromCharCode(lineArrayLength);
|
|||
|
lineHash[line] = lineArrayLength;
|
|||
|
lineArray[lineArrayLength++] = line;
|
|||
|
}
|
|||
|
}
|
|||
|
return chars;
|
|||
|
}
|
|||
|
|
|||
|
var chars1 = diff_linesToCharsMunge_(text1);
|
|||
|
var chars2 = diff_linesToCharsMunge_(text2);
|
|||
|
return {chars1: chars1, chars2: chars2, lineArray: lineArray};
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Rehydrate the text in a diff from a string of line hashes to real lines of
|
|||
|
* text.
|
|||
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|||
|
* @param {!Array.<string>} lineArray Array of unique strings.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_charsToLines_ = function(diffs, lineArray) {
|
|||
|
for (var x = 0; x < diffs.length; x++) {
|
|||
|
var chars = diffs[x][1];
|
|||
|
var text = [];
|
|||
|
for (var y = 0; y < chars.length; y++) {
|
|||
|
text[y] = lineArray[chars.charCodeAt(y)];
|
|||
|
}
|
|||
|
diffs[x][1] = text.join('');
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Determine the common prefix of two strings.
|
|||
|
* @param {string} text1 First string.
|
|||
|
* @param {string} text2 Second string.
|
|||
|
* @return {number} The number of characters common to the start of each
|
|||
|
* string.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_commonPrefix = function(text1, text2) {
|
|||
|
// Quick check for common null cases.
|
|||
|
if (!text1 || !text2 || text1.charAt(0) != text2.charAt(0)) {
|
|||
|
return 0;
|
|||
|
}
|
|||
|
// Binary search.
|
|||
|
// Performance analysis: http://neil.fraser.name/news/2007/10/09/
|
|||
|
var pointermin = 0;
|
|||
|
var pointermax = Math.min(text1.length, text2.length);
|
|||
|
var pointermid = pointermax;
|
|||
|
var pointerstart = 0;
|
|||
|
while (pointermin < pointermid) {
|
|||
|
if (text1.substring(pointerstart, pointermid) ==
|
|||
|
text2.substring(pointerstart, pointermid)) {
|
|||
|
pointermin = pointermid;
|
|||
|
pointerstart = pointermin;
|
|||
|
} else {
|
|||
|
pointermax = pointermid;
|
|||
|
}
|
|||
|
pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
|
|||
|
}
|
|||
|
return pointermid;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Determine the common suffix of two strings.
|
|||
|
* @param {string} text1 First string.
|
|||
|
* @param {string} text2 Second string.
|
|||
|
* @return {number} The number of characters common to the end of each string.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_commonSuffix = function(text1, text2) {
|
|||
|
// Quick check for common null cases.
|
|||
|
if (!text1 || !text2 ||
|
|||
|
text1.charAt(text1.length - 1) != text2.charAt(text2.length - 1)) {
|
|||
|
return 0;
|
|||
|
}
|
|||
|
// Binary search.
|
|||
|
// Performance analysis: http://neil.fraser.name/news/2007/10/09/
|
|||
|
var pointermin = 0;
|
|||
|
var pointermax = Math.min(text1.length, text2.length);
|
|||
|
var pointermid = pointermax;
|
|||
|
var pointerend = 0;
|
|||
|
while (pointermin < pointermid) {
|
|||
|
if (text1.substring(text1.length - pointermid, text1.length - pointerend) ==
|
|||
|
text2.substring(text2.length - pointermid, text2.length - pointerend)) {
|
|||
|
pointermin = pointermid;
|
|||
|
pointerend = pointermin;
|
|||
|
} else {
|
|||
|
pointermax = pointermid;
|
|||
|
}
|
|||
|
pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
|
|||
|
}
|
|||
|
return pointermid;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Determine if the suffix of one string is the prefix of another.
|
|||
|
* @param {string} text1 First string.
|
|||
|
* @param {string} text2 Second string.
|
|||
|
* @return {number} The number of characters common to the end of the first
|
|||
|
* string and the start of the second string.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_commonOverlap_ = function(text1, text2) {
|
|||
|
// Cache the text lengths to prevent multiple calls.
|
|||
|
var text1_length = text1.length;
|
|||
|
var text2_length = text2.length;
|
|||
|
// Eliminate the null case.
|
|||
|
if (text1_length == 0 || text2_length == 0) {
|
|||
|
return 0;
|
|||
|
}
|
|||
|
// Truncate the longer string.
|
|||
|
if (text1_length > text2_length) {
|
|||
|
text1 = text1.substring(text1_length - text2_length);
|
|||
|
} else if (text1_length < text2_length) {
|
|||
|
text2 = text2.substring(0, text1_length);
|
|||
|
}
|
|||
|
var text_length = Math.min(text1_length, text2_length);
|
|||
|
// Quick check for the worst case.
|
|||
|
if (text1 == text2) {
|
|||
|
return text_length;
|
|||
|
}
|
|||
|
|
|||
|
// Start by looking for a single character match
|
|||
|
// and increase length until no match is found.
|
|||
|
// Performance analysis: http://neil.fraser.name/news/2010/11/04/
|
|||
|
var best = 0;
|
|||
|
var length = 1;
|
|||
|
while (true) {
|
|||
|
var pattern = text1.substring(text_length - length);
|
|||
|
var found = text2.indexOf(pattern);
|
|||
|
if (found == -1) {
|
|||
|
return best;
|
|||
|
}
|
|||
|
length += found;
|
|||
|
if (found == 0 || text1.substring(text_length - length) ==
|
|||
|
text2.substring(0, length)) {
|
|||
|
best = length;
|
|||
|
length++;
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Do the two texts share a substring which is at least half the length of the
|
|||
|
* longer text?
|
|||
|
* This speedup can produce non-minimal diffs.
|
|||
|
* @param {string} text1 First string.
|
|||
|
* @param {string} text2 Second string.
|
|||
|
* @return {Array.<string>} Five element Array, containing the prefix of
|
|||
|
* text1, the suffix of text1, the prefix of text2, the suffix of
|
|||
|
* text2 and the common middle. Or null if there was no match.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) {
|
|||
|
if (this.Diff_Timeout <= 0) {
|
|||
|
// Don't risk returning a non-optimal diff if we have unlimited time.
|
|||
|
return null;
|
|||
|
}
|
|||
|
var longtext = text1.length > text2.length ? text1 : text2;
|
|||
|
var shorttext = text1.length > text2.length ? text2 : text1;
|
|||
|
if (longtext.length < 4 || shorttext.length * 2 < longtext.length) {
|
|||
|
return null; // Pointless.
|
|||
|
}
|
|||
|
var dmp = this; // 'this' becomes 'window' in a closure.
|
|||
|
|
|||
|
/**
|
|||
|
* Does a substring of shorttext exist within longtext such that the substring
|
|||
|
* is at least half the length of longtext?
|
|||
|
* Closure, but does not reference any external variables.
|
|||
|
* @param {string} longtext Longer string.
|
|||
|
* @param {string} shorttext Shorter string.
|
|||
|
* @param {number} i Start index of quarter length substring within longtext.
|
|||
|
* @return {Array.<string>} Five element Array, containing the prefix of
|
|||
|
* longtext, the suffix of longtext, the prefix of shorttext, the suffix
|
|||
|
* of shorttext and the common middle. Or null if there was no match.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
function diff_halfMatchI_(longtext, shorttext, i) {
|
|||
|
// Start with a 1/4 length substring at position i as a seed.
|
|||
|
var seed = longtext.substring(i, i + Math.floor(longtext.length / 4));
|
|||
|
var j = -1;
|
|||
|
var best_common = '';
|
|||
|
var best_longtext_a, best_longtext_b, best_shorttext_a, best_shorttext_b;
|
|||
|
while ((j = shorttext.indexOf(seed, j + 1)) != -1) {
|
|||
|
var prefixLength = dmp.diff_commonPrefix(longtext.substring(i),
|
|||
|
shorttext.substring(j));
|
|||
|
var suffixLength = dmp.diff_commonSuffix(longtext.substring(0, i),
|
|||
|
shorttext.substring(0, j));
|
|||
|
if (best_common.length < suffixLength + prefixLength) {
|
|||
|
best_common = shorttext.substring(j - suffixLength, j) +
|
|||
|
shorttext.substring(j, j + prefixLength);
|
|||
|
best_longtext_a = longtext.substring(0, i - suffixLength);
|
|||
|
best_longtext_b = longtext.substring(i + prefixLength);
|
|||
|
best_shorttext_a = shorttext.substring(0, j - suffixLength);
|
|||
|
best_shorttext_b = shorttext.substring(j + prefixLength);
|
|||
|
}
|
|||
|
}
|
|||
|
if (best_common.length * 2 >= longtext.length) {
|
|||
|
return [best_longtext_a, best_longtext_b,
|
|||
|
best_shorttext_a, best_shorttext_b, best_common];
|
|||
|
} else {
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// First check if the second quarter is the seed for a half-match.
|
|||
|
var hm1 = diff_halfMatchI_(longtext, shorttext,
|
|||
|
Math.ceil(longtext.length / 4));
|
|||
|
// Check again based on the third quarter.
|
|||
|
var hm2 = diff_halfMatchI_(longtext, shorttext,
|
|||
|
Math.ceil(longtext.length / 2));
|
|||
|
var hm;
|
|||
|
if (!hm1 && !hm2) {
|
|||
|
return null;
|
|||
|
} else if (!hm2) {
|
|||
|
hm = hm1;
|
|||
|
} else if (!hm1) {
|
|||
|
hm = hm2;
|
|||
|
} else {
|
|||
|
// Both matched. Select the longest.
|
|||
|
hm = hm1[4].length > hm2[4].length ? hm1 : hm2;
|
|||
|
}
|
|||
|
|
|||
|
// A half-match was found, sort out the return data.
|
|||
|
var text1_a, text1_b, text2_a, text2_b;
|
|||
|
if (text1.length > text2.length) {
|
|||
|
text1_a = hm[0];
|
|||
|
text1_b = hm[1];
|
|||
|
text2_a = hm[2];
|
|||
|
text2_b = hm[3];
|
|||
|
} else {
|
|||
|
text2_a = hm[0];
|
|||
|
text2_b = hm[1];
|
|||
|
text1_a = hm[2];
|
|||
|
text1_b = hm[3];
|
|||
|
}
|
|||
|
var mid_common = hm[4];
|
|||
|
return [text1_a, text1_b, text2_a, text2_b, mid_common];
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Reduce the number of edits by eliminating semantically trivial equalities.
|
|||
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) {
|
|||
|
var changes = false;
|
|||
|
var equalities = []; // Stack of indices where equalities are found.
|
|||
|
var equalitiesLength = 0; // Keeping our own length var is faster in JS.
|
|||
|
/** @type {?string} */
|
|||
|
var lastequality = null;
|
|||
|
// Always equal to diffs[equalities[equalitiesLength - 1]][1]
|
|||
|
var pointer = 0; // Index of current position.
|
|||
|
// Number of characters that changed prior to the equality.
|
|||
|
var length_insertions1 = 0;
|
|||
|
var length_deletions1 = 0;
|
|||
|
// Number of characters that changed after the equality.
|
|||
|
var length_insertions2 = 0;
|
|||
|
var length_deletions2 = 0;
|
|||
|
while (pointer < diffs.length) {
|
|||
|
if (diffs[pointer][0] == DIFF_EQUAL) { // Equality found.
|
|||
|
equalities[equalitiesLength++] = pointer;
|
|||
|
length_insertions1 = length_insertions2;
|
|||
|
length_deletions1 = length_deletions2;
|
|||
|
length_insertions2 = 0;
|
|||
|
length_deletions2 = 0;
|
|||
|
lastequality = diffs[pointer][1];
|
|||
|
} else { // An insertion or deletion.
|
|||
|
if (diffs[pointer][0] == DIFF_INSERT) {
|
|||
|
length_insertions2 += diffs[pointer][1].length;
|
|||
|
} else {
|
|||
|
length_deletions2 += diffs[pointer][1].length;
|
|||
|
}
|
|||
|
// Eliminate an equality that is smaller or equal to the edits on both
|
|||
|
// sides of it.
|
|||
|
if (lastequality && (lastequality.length <=
|
|||
|
Math.max(length_insertions1, length_deletions1)) &&
|
|||
|
(lastequality.length <= Math.max(length_insertions2,
|
|||
|
length_deletions2))) {
|
|||
|
// Duplicate record.
|
|||
|
diffs.splice(equalities[equalitiesLength - 1], 0,
|
|||
|
[DIFF_DELETE, lastequality]);
|
|||
|
// Change second copy to insert.
|
|||
|
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
|
|||
|
// Throw away the equality we just deleted.
|
|||
|
equalitiesLength--;
|
|||
|
// Throw away the previous equality (it needs to be reevaluated).
|
|||
|
equalitiesLength--;
|
|||
|
pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
|
|||
|
length_insertions1 = 0; // Reset the counters.
|
|||
|
length_deletions1 = 0;
|
|||
|
length_insertions2 = 0;
|
|||
|
length_deletions2 = 0;
|
|||
|
lastequality = null;
|
|||
|
changes = true;
|
|||
|
}
|
|||
|
}
|
|||
|
pointer++;
|
|||
|
}
|
|||
|
|
|||
|
// Normalize the diff.
|
|||
|
if (changes) {
|
|||
|
this.diff_cleanupMerge(diffs);
|
|||
|
}
|
|||
|
this.diff_cleanupSemanticLossless(diffs);
|
|||
|
|
|||
|
// Find any overlaps between deletions and insertions.
|
|||
|
// e.g: <del>abcxxx</del><ins>xxxdef</ins>
|
|||
|
// -> <del>abc</del>xxx<ins>def</ins>
|
|||
|
// e.g: <del>xxxabc</del><ins>defxxx</ins>
|
|||
|
// -> <ins>def</ins>xxx<del>abc</del>
|
|||
|
// Only extract an overlap if it is as big as the edit ahead or behind it.
|
|||
|
pointer = 1;
|
|||
|
while (pointer < diffs.length) {
|
|||
|
if (diffs[pointer - 1][0] == DIFF_DELETE &&
|
|||
|
diffs[pointer][0] == DIFF_INSERT) {
|
|||
|
var deletion = diffs[pointer - 1][1];
|
|||
|
var insertion = diffs[pointer][1];
|
|||
|
var overlap_length1 = this.diff_commonOverlap_(deletion, insertion);
|
|||
|
var overlap_length2 = this.diff_commonOverlap_(insertion, deletion);
|
|||
|
if (overlap_length1 >= overlap_length2) {
|
|||
|
if (overlap_length1 >= deletion.length / 2 ||
|
|||
|
overlap_length1 >= insertion.length / 2) {
|
|||
|
// Overlap found. Insert an equality and trim the surrounding edits.
|
|||
|
diffs.splice(pointer, 0,
|
|||
|
[DIFF_EQUAL, insertion.substring(0, overlap_length1)]);
|
|||
|
diffs[pointer - 1][1] =
|
|||
|
deletion.substring(0, deletion.length - overlap_length1);
|
|||
|
diffs[pointer + 1][1] = insertion.substring(overlap_length1);
|
|||
|
pointer++;
|
|||
|
}
|
|||
|
} else {
|
|||
|
if (overlap_length2 >= deletion.length / 2 ||
|
|||
|
overlap_length2 >= insertion.length / 2) {
|
|||
|
// Reverse overlap found.
|
|||
|
// Insert an equality and swap and trim the surrounding edits.
|
|||
|
diffs.splice(pointer, 0,
|
|||
|
[DIFF_EQUAL, deletion.substring(0, overlap_length2)]);
|
|||
|
diffs[pointer - 1][0] = DIFF_INSERT;
|
|||
|
diffs[pointer - 1][1] =
|
|||
|
insertion.substring(0, insertion.length - overlap_length2);
|
|||
|
diffs[pointer + 1][0] = DIFF_DELETE;
|
|||
|
diffs[pointer + 1][1] =
|
|||
|
deletion.substring(overlap_length2);
|
|||
|
pointer++;
|
|||
|
}
|
|||
|
}
|
|||
|
pointer++;
|
|||
|
}
|
|||
|
pointer++;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Look for single edits surrounded on both sides by equalities
|
|||
|
* which can be shifted sideways to align the edit to a word boundary.
|
|||
|
* e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
|
|||
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_cleanupSemanticLossless = function(diffs) {
|
|||
|
/**
|
|||
|
* Given two strings, compute a score representing whether the internal
|
|||
|
* boundary falls on logical boundaries.
|
|||
|
* Scores range from 6 (best) to 0 (worst).
|
|||
|
* Closure, but does not reference any external variables.
|
|||
|
* @param {string} one First string.
|
|||
|
* @param {string} two Second string.
|
|||
|
* @return {number} The score.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
function diff_cleanupSemanticScore_(one, two) {
|
|||
|
if (!one || !two) {
|
|||
|
// Edges are the best.
|
|||
|
return 6;
|
|||
|
}
|
|||
|
|
|||
|
// Each port of this function behaves slightly differently due to
|
|||
|
// subtle differences in each language's definition of things like
|
|||
|
// 'whitespace'. Since this function's purpose is largely cosmetic,
|
|||
|
// the choice has been made to use each language's native features
|
|||
|
// rather than force total conformity.
|
|||
|
var char1 = one.charAt(one.length - 1);
|
|||
|
var char2 = two.charAt(0);
|
|||
|
var nonAlphaNumeric1 = char1.match(diff_match_patch.nonAlphaNumericRegex_);
|
|||
|
var nonAlphaNumeric2 = char2.match(diff_match_patch.nonAlphaNumericRegex_);
|
|||
|
var whitespace1 = nonAlphaNumeric1 &&
|
|||
|
char1.match(diff_match_patch.whitespaceRegex_);
|
|||
|
var whitespace2 = nonAlphaNumeric2 &&
|
|||
|
char2.match(diff_match_patch.whitespaceRegex_);
|
|||
|
var lineBreak1 = whitespace1 &&
|
|||
|
char1.match(diff_match_patch.linebreakRegex_);
|
|||
|
var lineBreak2 = whitespace2 &&
|
|||
|
char2.match(diff_match_patch.linebreakRegex_);
|
|||
|
var blankLine1 = lineBreak1 &&
|
|||
|
one.match(diff_match_patch.blanklineEndRegex_);
|
|||
|
var blankLine2 = lineBreak2 &&
|
|||
|
two.match(diff_match_patch.blanklineStartRegex_);
|
|||
|
|
|||
|
if (blankLine1 || blankLine2) {
|
|||
|
// Five points for blank lines.
|
|||
|
return 5;
|
|||
|
} else if (lineBreak1 || lineBreak2) {
|
|||
|
// Four points for line breaks.
|
|||
|
return 4;
|
|||
|
} else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) {
|
|||
|
// Three points for end of sentences.
|
|||
|
return 3;
|
|||
|
} else if (whitespace1 || whitespace2) {
|
|||
|
// Two points for whitespace.
|
|||
|
return 2;
|
|||
|
} else if (nonAlphaNumeric1 || nonAlphaNumeric2) {
|
|||
|
// One point for non-alphanumeric.
|
|||
|
return 1;
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
var pointer = 1;
|
|||
|
// Intentionally ignore the first and last element (don't need checking).
|
|||
|
while (pointer < diffs.length - 1) {
|
|||
|
if (diffs[pointer - 1][0] == DIFF_EQUAL &&
|
|||
|
diffs[pointer + 1][0] == DIFF_EQUAL) {
|
|||
|
// This is a single edit surrounded by equalities.
|
|||
|
var equality1 = diffs[pointer - 1][1];
|
|||
|
var edit = diffs[pointer][1];
|
|||
|
var equality2 = diffs[pointer + 1][1];
|
|||
|
|
|||
|
// First, shift the edit as far left as possible.
|
|||
|
var commonOffset = this.diff_commonSuffix(equality1, edit);
|
|||
|
if (commonOffset) {
|
|||
|
var commonString = edit.substring(edit.length - commonOffset);
|
|||
|
equality1 = equality1.substring(0, equality1.length - commonOffset);
|
|||
|
edit = commonString + edit.substring(0, edit.length - commonOffset);
|
|||
|
equality2 = commonString + equality2;
|
|||
|
}
|
|||
|
|
|||
|
// Second, step character by character right, looking for the best fit.
|
|||
|
var bestEquality1 = equality1;
|
|||
|
var bestEdit = edit;
|
|||
|
var bestEquality2 = equality2;
|
|||
|
var bestScore = diff_cleanupSemanticScore_(equality1, edit) +
|
|||
|
diff_cleanupSemanticScore_(edit, equality2);
|
|||
|
while (edit.charAt(0) === equality2.charAt(0)) {
|
|||
|
equality1 += edit.charAt(0);
|
|||
|
edit = edit.substring(1) + equality2.charAt(0);
|
|||
|
equality2 = equality2.substring(1);
|
|||
|
var score = diff_cleanupSemanticScore_(equality1, edit) +
|
|||
|
diff_cleanupSemanticScore_(edit, equality2);
|
|||
|
// The >= encourages trailing rather than leading whitespace on edits.
|
|||
|
if (score >= bestScore) {
|
|||
|
bestScore = score;
|
|||
|
bestEquality1 = equality1;
|
|||
|
bestEdit = edit;
|
|||
|
bestEquality2 = equality2;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (diffs[pointer - 1][1] != bestEquality1) {
|
|||
|
// We have an improvement, save it back to the diff.
|
|||
|
if (bestEquality1) {
|
|||
|
diffs[pointer - 1][1] = bestEquality1;
|
|||
|
} else {
|
|||
|
diffs.splice(pointer - 1, 1);
|
|||
|
pointer--;
|
|||
|
}
|
|||
|
diffs[pointer][1] = bestEdit;
|
|||
|
if (bestEquality2) {
|
|||
|
diffs[pointer + 1][1] = bestEquality2;
|
|||
|
} else {
|
|||
|
diffs.splice(pointer + 1, 1);
|
|||
|
pointer--;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
pointer++;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Define some regex patterns for matching boundaries.
|
|||
|
diff_match_patch.nonAlphaNumericRegex_ = /[^a-zA-Z0-9]/;
|
|||
|
diff_match_patch.whitespaceRegex_ = /\s/;
|
|||
|
diff_match_patch.linebreakRegex_ = /[\r\n]/;
|
|||
|
diff_match_patch.blanklineEndRegex_ = /\n\r?\n$/;
|
|||
|
diff_match_patch.blanklineStartRegex_ = /^\r?\n\r?\n/;
|
|||
|
|
|||
|
/**
|
|||
|
* Reduce the number of edits by eliminating operationally trivial equalities.
|
|||
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) {
|
|||
|
var changes = false;
|
|||
|
var equalities = []; // Stack of indices where equalities are found.
|
|||
|
var equalitiesLength = 0; // Keeping our own length var is faster in JS.
|
|||
|
/** @type {?string} */
|
|||
|
var lastequality = null;
|
|||
|
// Always equal to diffs[equalities[equalitiesLength - 1]][1]
|
|||
|
var pointer = 0; // Index of current position.
|
|||
|
// Is there an insertion operation before the last equality.
|
|||
|
var pre_ins = false;
|
|||
|
// Is there a deletion operation before the last equality.
|
|||
|
var pre_del = false;
|
|||
|
// Is there an insertion operation after the last equality.
|
|||
|
var post_ins = false;
|
|||
|
// Is there a deletion operation after the last equality.
|
|||
|
var post_del = false;
|
|||
|
while (pointer < diffs.length) {
|
|||
|
if (diffs[pointer][0] == DIFF_EQUAL) { // Equality found.
|
|||
|
if (diffs[pointer][1].length < this.Diff_EditCost &&
|
|||
|
(post_ins || post_del)) {
|
|||
|
// Candidate found.
|
|||
|
equalities[equalitiesLength++] = pointer;
|
|||
|
pre_ins = post_ins;
|
|||
|
pre_del = post_del;
|
|||
|
lastequality = diffs[pointer][1];
|
|||
|
} else {
|
|||
|
// Not a candidate, and can never become one.
|
|||
|
equalitiesLength = 0;
|
|||
|
lastequality = null;
|
|||
|
}
|
|||
|
post_ins = post_del = false;
|
|||
|
} else { // An insertion or deletion.
|
|||
|
if (diffs[pointer][0] == DIFF_DELETE) {
|
|||
|
post_del = true;
|
|||
|
} else {
|
|||
|
post_ins = true;
|
|||
|
}
|
|||
|
/*
|
|||
|
* Five types to be split:
|
|||
|
* <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del>
|
|||
|
* <ins>A</ins>X<ins>C</ins><del>D</del>
|
|||
|
* <ins>A</ins><del>B</del>X<ins>C</ins>
|
|||
|
* <ins>A</del>X<ins>C</ins><del>D</del>
|
|||
|
* <ins>A</ins><del>B</del>X<del>C</del>
|
|||
|
*/
|
|||
|
if (lastequality && ((pre_ins && pre_del && post_ins && post_del) ||
|
|||
|
((lastequality.length < this.Diff_EditCost / 2) &&
|
|||
|
(pre_ins + pre_del + post_ins + post_del) == 3))) {
|
|||
|
// Duplicate record.
|
|||
|
diffs.splice(equalities[equalitiesLength - 1], 0,
|
|||
|
[DIFF_DELETE, lastequality]);
|
|||
|
// Change second copy to insert.
|
|||
|
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
|
|||
|
equalitiesLength--; // Throw away the equality we just deleted;
|
|||
|
lastequality = null;
|
|||
|
if (pre_ins && pre_del) {
|
|||
|
// No changes made which could affect previous entry, keep going.
|
|||
|
post_ins = post_del = true;
|
|||
|
equalitiesLength = 0;
|
|||
|
} else {
|
|||
|
equalitiesLength--; // Throw away the previous equality.
|
|||
|
pointer = equalitiesLength > 0 ?
|
|||
|
equalities[equalitiesLength - 1] : -1;
|
|||
|
post_ins = post_del = false;
|
|||
|
}
|
|||
|
changes = true;
|
|||
|
}
|
|||
|
}
|
|||
|
pointer++;
|
|||
|
}
|
|||
|
|
|||
|
if (changes) {
|
|||
|
this.diff_cleanupMerge(diffs);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Reorder and merge like edit sections. Merge equalities.
|
|||
|
* Any edit section can move as long as it doesn't cross an equality.
|
|||
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_cleanupMerge = function(diffs) {
|
|||
|
diffs.push([DIFF_EQUAL, '']); // Add a dummy entry at the end.
|
|||
|
var pointer = 0;
|
|||
|
var count_delete = 0;
|
|||
|
var count_insert = 0;
|
|||
|
var text_delete = '';
|
|||
|
var text_insert = '';
|
|||
|
var commonlength;
|
|||
|
while (pointer < diffs.length) {
|
|||
|
switch (diffs[pointer][0]) {
|
|||
|
case DIFF_INSERT:
|
|||
|
count_insert++;
|
|||
|
text_insert += diffs[pointer][1];
|
|||
|
pointer++;
|
|||
|
break;
|
|||
|
case DIFF_DELETE:
|
|||
|
count_delete++;
|
|||
|
text_delete += diffs[pointer][1];
|
|||
|
pointer++;
|
|||
|
break;
|
|||
|
case DIFF_EQUAL:
|
|||
|
// Upon reaching an equality, check for prior redundancies.
|
|||
|
if (count_delete + count_insert > 1) {
|
|||
|
if (count_delete !== 0 && count_insert !== 0) {
|
|||
|
// Factor out any common prefixies.
|
|||
|
commonlength = this.diff_commonPrefix(text_insert, text_delete);
|
|||
|
if (commonlength !== 0) {
|
|||
|
if ((pointer - count_delete - count_insert) > 0 &&
|
|||
|
diffs[pointer - count_delete - count_insert - 1][0] ==
|
|||
|
DIFF_EQUAL) {
|
|||
|
diffs[pointer - count_delete - count_insert - 1][1] +=
|
|||
|
text_insert.substring(0, commonlength);
|
|||
|
} else {
|
|||
|
diffs.splice(0, 0, [DIFF_EQUAL,
|
|||
|
text_insert.substring(0, commonlength)]);
|
|||
|
pointer++;
|
|||
|
}
|
|||
|
text_insert = text_insert.substring(commonlength);
|
|||
|
text_delete = text_delete.substring(commonlength);
|
|||
|
}
|
|||
|
// Factor out any common suffixies.
|
|||
|
commonlength = this.diff_commonSuffix(text_insert, text_delete);
|
|||
|
if (commonlength !== 0) {
|
|||
|
diffs[pointer][1] = text_insert.substring(text_insert.length -
|
|||
|
commonlength) + diffs[pointer][1];
|
|||
|
text_insert = text_insert.substring(0, text_insert.length -
|
|||
|
commonlength);
|
|||
|
text_delete = text_delete.substring(0, text_delete.length -
|
|||
|
commonlength);
|
|||
|
}
|
|||
|
}
|
|||
|
// Delete the offending records and add the merged ones.
|
|||
|
if (count_delete === 0) {
|
|||
|
diffs.splice(pointer - count_insert,
|
|||
|
count_delete + count_insert, [DIFF_INSERT, text_insert]);
|
|||
|
} else if (count_insert === 0) {
|
|||
|
diffs.splice(pointer - count_delete,
|
|||
|
count_delete + count_insert, [DIFF_DELETE, text_delete]);
|
|||
|
} else {
|
|||
|
diffs.splice(pointer - count_delete - count_insert,
|
|||
|
count_delete + count_insert, [DIFF_DELETE, text_delete],
|
|||
|
[DIFF_INSERT, text_insert]);
|
|||
|
}
|
|||
|
pointer = pointer - count_delete - count_insert +
|
|||
|
(count_delete ? 1 : 0) + (count_insert ? 1 : 0) + 1;
|
|||
|
} else if (pointer !== 0 && diffs[pointer - 1][0] == DIFF_EQUAL) {
|
|||
|
// Merge this equality with the previous one.
|
|||
|
diffs[pointer - 1][1] += diffs[pointer][1];
|
|||
|
diffs.splice(pointer, 1);
|
|||
|
} else {
|
|||
|
pointer++;
|
|||
|
}
|
|||
|
count_insert = 0;
|
|||
|
count_delete = 0;
|
|||
|
text_delete = '';
|
|||
|
text_insert = '';
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
if (diffs[diffs.length - 1][1] === '') {
|
|||
|
diffs.pop(); // Remove the dummy entry at the end.
|
|||
|
}
|
|||
|
|
|||
|
// Second pass: look for single edits surrounded on both sides by equalities
|
|||
|
// which can be shifted sideways to eliminate an equality.
|
|||
|
// e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC
|
|||
|
var changes = false;
|
|||
|
pointer = 1;
|
|||
|
// Intentionally ignore the first and last element (don't need checking).
|
|||
|
while (pointer < diffs.length - 1) {
|
|||
|
if (diffs[pointer - 1][0] == DIFF_EQUAL &&
|
|||
|
diffs[pointer + 1][0] == DIFF_EQUAL) {
|
|||
|
// This is a single edit surrounded by equalities.
|
|||
|
if (diffs[pointer][1].substring(diffs[pointer][1].length -
|
|||
|
diffs[pointer - 1][1].length) == diffs[pointer - 1][1]) {
|
|||
|
// Shift the edit over the previous equality.
|
|||
|
diffs[pointer][1] = diffs[pointer - 1][1] +
|
|||
|
diffs[pointer][1].substring(0, diffs[pointer][1].length -
|
|||
|
diffs[pointer - 1][1].length);
|
|||
|
diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
|
|||
|
diffs.splice(pointer - 1, 1);
|
|||
|
changes = true;
|
|||
|
} else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) ==
|
|||
|
diffs[pointer + 1][1]) {
|
|||
|
// Shift the edit over the next equality.
|
|||
|
diffs[pointer - 1][1] += diffs[pointer + 1][1];
|
|||
|
diffs[pointer][1] =
|
|||
|
diffs[pointer][1].substring(diffs[pointer + 1][1].length) +
|
|||
|
diffs[pointer + 1][1];
|
|||
|
diffs.splice(pointer + 1, 1);
|
|||
|
changes = true;
|
|||
|
}
|
|||
|
}
|
|||
|
pointer++;
|
|||
|
}
|
|||
|
// If shifts were made, the diff needs reordering and another shift sweep.
|
|||
|
if (changes) {
|
|||
|
this.diff_cleanupMerge(diffs);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* loc is a location in text1, compute and return the equivalent location in
|
|||
|
* text2.
|
|||
|
* e.g. 'The cat' vs 'The big cat', 1->1, 5->8
|
|||
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|||
|
* @param {number} loc Location within text1.
|
|||
|
* @return {number} Location within text2.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_xIndex = function(diffs, loc) {
|
|||
|
var chars1 = 0;
|
|||
|
var chars2 = 0;
|
|||
|
var last_chars1 = 0;
|
|||
|
var last_chars2 = 0;
|
|||
|
var x;
|
|||
|
for (x = 0; x < diffs.length; x++) {
|
|||
|
if (diffs[x][0] !== DIFF_INSERT) { // Equality or deletion.
|
|||
|
chars1 += diffs[x][1].length;
|
|||
|
}
|
|||
|
if (diffs[x][0] !== DIFF_DELETE) { // Equality or insertion.
|
|||
|
chars2 += diffs[x][1].length;
|
|||
|
}
|
|||
|
if (chars1 > loc) { // Overshot the location.
|
|||
|
break;
|
|||
|
}
|
|||
|
last_chars1 = chars1;
|
|||
|
last_chars2 = chars2;
|
|||
|
}
|
|||
|
// Was the location was deleted?
|
|||
|
if (diffs.length != x && diffs[x][0] === DIFF_DELETE) {
|
|||
|
return last_chars2;
|
|||
|
}
|
|||
|
// Add the remaining character length.
|
|||
|
return last_chars2 + (loc - last_chars1);
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Convert a diff array into a pretty HTML report.
|
|||
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|||
|
* @return {string} HTML representation.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_prettyHtml = function(diffs) {
|
|||
|
var html = [];
|
|||
|
var pattern_amp = /&/g;
|
|||
|
var pattern_lt = /</g;
|
|||
|
var pattern_gt = />/g;
|
|||
|
var pattern_para = /\n/g;
|
|||
|
for (var x = 0; x < diffs.length; x++) {
|
|||
|
var op = diffs[x][0]; // Operation (insert, delete, equal)
|
|||
|
var data = diffs[x][1]; // Text of change.
|
|||
|
var text = data.replace(pattern_amp, '&').replace(pattern_lt, '<')
|
|||
|
.replace(pattern_gt, '>').replace(pattern_para, '¶<br>');
|
|||
|
switch (op) {
|
|||
|
case DIFF_INSERT:
|
|||
|
html[x] = '<ins style="background:#e6ffe6;">' + text + '</ins>';
|
|||
|
break;
|
|||
|
case DIFF_DELETE:
|
|||
|
html[x] = '<del style="background:#ffe6e6;">' + text + '</del>';
|
|||
|
break;
|
|||
|
case DIFF_EQUAL:
|
|||
|
html[x] = '<span>' + text + '</span>';
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
return html.join('');
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Compute and return the source text (all equalities and deletions).
|
|||
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|||
|
* @return {string} Source text.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_text1 = function(diffs) {
|
|||
|
var text = [];
|
|||
|
for (var x = 0; x < diffs.length; x++) {
|
|||
|
if (diffs[x][0] !== DIFF_INSERT) {
|
|||
|
text[x] = diffs[x][1];
|
|||
|
}
|
|||
|
}
|
|||
|
return text.join('');
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Compute and return the destination text (all equalities and insertions).
|
|||
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|||
|
* @return {string} Destination text.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_text2 = function(diffs) {
|
|||
|
var text = [];
|
|||
|
for (var x = 0; x < diffs.length; x++) {
|
|||
|
if (diffs[x][0] !== DIFF_DELETE) {
|
|||
|
text[x] = diffs[x][1];
|
|||
|
}
|
|||
|
}
|
|||
|
return text.join('');
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Compute the Levenshtein distance; the number of inserted, deleted or
|
|||
|
* substituted characters.
|
|||
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|||
|
* @return {number} Number of changes.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_levenshtein = function(diffs) {
|
|||
|
var levenshtein = 0;
|
|||
|
var insertions = 0;
|
|||
|
var deletions = 0;
|
|||
|
for (var x = 0; x < diffs.length; x++) {
|
|||
|
var op = diffs[x][0];
|
|||
|
var data = diffs[x][1];
|
|||
|
switch (op) {
|
|||
|
case DIFF_INSERT:
|
|||
|
insertions += data.length;
|
|||
|
break;
|
|||
|
case DIFF_DELETE:
|
|||
|
deletions += data.length;
|
|||
|
break;
|
|||
|
case DIFF_EQUAL:
|
|||
|
// A deletion and an insertion is one substitution.
|
|||
|
levenshtein += Math.max(insertions, deletions);
|
|||
|
insertions = 0;
|
|||
|
deletions = 0;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
levenshtein += Math.max(insertions, deletions);
|
|||
|
return levenshtein;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Crush the diff into an encoded string which describes the operations
|
|||
|
* required to transform text1 into text2.
|
|||
|
* E.g. =3\t-2\t+ing -> Keep 3 chars, delete 2 chars, insert 'ing'.
|
|||
|
* Operations are tab-separated. Inserted text is escaped using %xx notation.
|
|||
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|||
|
* @return {string} Delta text.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_toDelta = function(diffs) {
|
|||
|
var text = [];
|
|||
|
for (var x = 0; x < diffs.length; x++) {
|
|||
|
switch (diffs[x][0]) {
|
|||
|
case DIFF_INSERT:
|
|||
|
text[x] = '+' + encodeURI(diffs[x][1]);
|
|||
|
break;
|
|||
|
case DIFF_DELETE:
|
|||
|
text[x] = '-' + diffs[x][1].length;
|
|||
|
break;
|
|||
|
case DIFF_EQUAL:
|
|||
|
text[x] = '=' + diffs[x][1].length;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
return text.join('\t').replace(/%20/g, ' ');
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Given the original text1, and an encoded string which describes the
|
|||
|
* operations required to transform text1 into text2, compute the full diff.
|
|||
|
* @param {string} text1 Source string for the diff.
|
|||
|
* @param {string} delta Delta text.
|
|||
|
* @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
|
|||
|
* @throws {!Error} If invalid input.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.diff_fromDelta = function(text1, delta) {
|
|||
|
var diffs = [];
|
|||
|
var diffsLength = 0; // Keeping our own length var is faster in JS.
|
|||
|
var pointer = 0; // Cursor in text1
|
|||
|
var tokens = delta.split(/\t/g);
|
|||
|
for (var x = 0; x < tokens.length; x++) {
|
|||
|
// Each token begins with a one character parameter which specifies the
|
|||
|
// operation of this token (delete, insert, equality).
|
|||
|
var param = tokens[x].substring(1);
|
|||
|
switch (tokens[x].charAt(0)) {
|
|||
|
case '+':
|
|||
|
try {
|
|||
|
diffs[diffsLength++] = [DIFF_INSERT, decodeURI(param)];
|
|||
|
} catch (ex) {
|
|||
|
// Malformed URI sequence.
|
|||
|
throw new Error('Illegal escape in diff_fromDelta: ' + param);
|
|||
|
}
|
|||
|
break;
|
|||
|
case '-':
|
|||
|
// Fall through.
|
|||
|
case '=':
|
|||
|
var n = parseInt(param, 10);
|
|||
|
if (isNaN(n) || n < 0) {
|
|||
|
throw new Error('Invalid number in diff_fromDelta: ' + param);
|
|||
|
}
|
|||
|
var text = text1.substring(pointer, pointer += n);
|
|||
|
if (tokens[x].charAt(0) == '=') {
|
|||
|
diffs[diffsLength++] = [DIFF_EQUAL, text];
|
|||
|
} else {
|
|||
|
diffs[diffsLength++] = [DIFF_DELETE, text];
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
// Blank tokens are ok (from a trailing \t).
|
|||
|
// Anything else is an error.
|
|||
|
if (tokens[x]) {
|
|||
|
throw new Error('Invalid diff operation in diff_fromDelta: ' +
|
|||
|
tokens[x]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if (pointer != text1.length) {
|
|||
|
throw new Error('Delta length (' + pointer +
|
|||
|
') does not equal source text length (' + text1.length + ').');
|
|||
|
}
|
|||
|
return diffs;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
// MATCH FUNCTIONS
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Locate the best instance of 'pattern' in 'text' near 'loc'.
|
|||
|
* @param {string} text The text to search.
|
|||
|
* @param {string} pattern The pattern to search for.
|
|||
|
* @param {number} loc The location to search around.
|
|||
|
* @return {number} Best match index or -1.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.match_main = function(text, pattern, loc) {
|
|||
|
// Check for null inputs.
|
|||
|
if (text == null || pattern == null || loc == null) {
|
|||
|
throw new Error('Null input. (match_main)');
|
|||
|
}
|
|||
|
|
|||
|
loc = Math.max(0, Math.min(loc, text.length));
|
|||
|
if (text == pattern) {
|
|||
|
// Shortcut (potentially not guaranteed by the algorithm)
|
|||
|
return 0;
|
|||
|
} else if (!text.length) {
|
|||
|
// Nothing to match.
|
|||
|
return -1;
|
|||
|
} else if (text.substring(loc, loc + pattern.length) == pattern) {
|
|||
|
// Perfect match at the perfect spot! (Includes case of null pattern)
|
|||
|
return loc;
|
|||
|
} else {
|
|||
|
// Do a fuzzy compare.
|
|||
|
return this.match_bitap_(text, pattern, loc);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Locate the best instance of 'pattern' in 'text' near 'loc' using the
|
|||
|
* Bitap algorithm.
|
|||
|
* @param {string} text The text to search.
|
|||
|
* @param {string} pattern The pattern to search for.
|
|||
|
* @param {number} loc The location to search around.
|
|||
|
* @return {number} Best match index or -1.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.match_bitap_ = function(text, pattern, loc) {
|
|||
|
if (pattern.length > this.Match_MaxBits) {
|
|||
|
throw new Error('Pattern too long for this browser.');
|
|||
|
}
|
|||
|
|
|||
|
// Initialise the alphabet.
|
|||
|
var s = this.match_alphabet_(pattern);
|
|||
|
|
|||
|
var dmp = this; // 'this' becomes 'window' in a closure.
|
|||
|
|
|||
|
/**
|
|||
|
* Compute and return the score for a match with e errors and x location.
|
|||
|
* Accesses loc and pattern through being a closure.
|
|||
|
* @param {number} e Number of errors in match.
|
|||
|
* @param {number} x Location of match.
|
|||
|
* @return {number} Overall score for match (0.0 = good, 1.0 = bad).
|
|||
|
* @private
|
|||
|
*/
|
|||
|
function match_bitapScore_(e, x) {
|
|||
|
var accuracy = e / pattern.length;
|
|||
|
var proximity = Math.abs(loc - x);
|
|||
|
if (!dmp.Match_Distance) {
|
|||
|
// Dodge divide by zero error.
|
|||
|
return proximity ? 1.0 : accuracy;
|
|||
|
}
|
|||
|
return accuracy + (proximity / dmp.Match_Distance);
|
|||
|
}
|
|||
|
|
|||
|
// Highest score beyond which we give up.
|
|||
|
var score_threshold = this.Match_Threshold;
|
|||
|
// Is there a nearby exact match? (speedup)
|
|||
|
var best_loc = text.indexOf(pattern, loc);
|
|||
|
if (best_loc != -1) {
|
|||
|
score_threshold = Math.min(match_bitapScore_(0, best_loc), score_threshold);
|
|||
|
// What about in the other direction? (speedup)
|
|||
|
best_loc = text.lastIndexOf(pattern, loc + pattern.length);
|
|||
|
if (best_loc != -1) {
|
|||
|
score_threshold =
|
|||
|
Math.min(match_bitapScore_(0, best_loc), score_threshold);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Initialise the bit arrays.
|
|||
|
var matchmask = 1 << (pattern.length - 1);
|
|||
|
best_loc = -1;
|
|||
|
|
|||
|
var bin_min, bin_mid;
|
|||
|
var bin_max = pattern.length + text.length;
|
|||
|
var last_rd;
|
|||
|
for (var d = 0; d < pattern.length; d++) {
|
|||
|
// Scan for the best match; each iteration allows for one more error.
|
|||
|
// Run a binary search to determine how far from 'loc' we can stray at this
|
|||
|
// error level.
|
|||
|
bin_min = 0;
|
|||
|
bin_mid = bin_max;
|
|||
|
while (bin_min < bin_mid) {
|
|||
|
if (match_bitapScore_(d, loc + bin_mid) <= score_threshold) {
|
|||
|
bin_min = bin_mid;
|
|||
|
} else {
|
|||
|
bin_max = bin_mid;
|
|||
|
}
|
|||
|
bin_mid = Math.floor((bin_max - bin_min) / 2 + bin_min);
|
|||
|
}
|
|||
|
// Use the result from this iteration as the maximum for the next.
|
|||
|
bin_max = bin_mid;
|
|||
|
var start = Math.max(1, loc - bin_mid + 1);
|
|||
|
var finish = Math.min(loc + bin_mid, text.length) + pattern.length;
|
|||
|
|
|||
|
var rd = Array(finish + 2);
|
|||
|
rd[finish + 1] = (1 << d) - 1;
|
|||
|
for (var j = finish; j >= start; j--) {
|
|||
|
// The alphabet (s) is a sparse hash, so the following line generates
|
|||
|
// warnings.
|
|||
|
var charMatch = s[text.charAt(j - 1)];
|
|||
|
if (d === 0) { // First pass: exact match.
|
|||
|
rd[j] = ((rd[j + 1] << 1) | 1) & charMatch;
|
|||
|
} else { // Subsequent passes: fuzzy match.
|
|||
|
rd[j] = (((rd[j + 1] << 1) | 1) & charMatch) |
|
|||
|
(((last_rd[j + 1] | last_rd[j]) << 1) | 1) |
|
|||
|
last_rd[j + 1];
|
|||
|
}
|
|||
|
if (rd[j] & matchmask) {
|
|||
|
var score = match_bitapScore_(d, j - 1);
|
|||
|
// This match will almost certainly be better than any existing match.
|
|||
|
// But check anyway.
|
|||
|
if (score <= score_threshold) {
|
|||
|
// Told you so.
|
|||
|
score_threshold = score;
|
|||
|
best_loc = j - 1;
|
|||
|
if (best_loc > loc) {
|
|||
|
// When passing loc, don't exceed our current distance from loc.
|
|||
|
start = Math.max(1, 2 * loc - best_loc);
|
|||
|
} else {
|
|||
|
// Already passed loc, downhill from here on in.
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
// No hope for a (better) match at greater error levels.
|
|||
|
if (match_bitapScore_(d + 1, loc) > score_threshold) {
|
|||
|
break;
|
|||
|
}
|
|||
|
last_rd = rd;
|
|||
|
}
|
|||
|
return best_loc;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Initialise the alphabet for the Bitap algorithm.
|
|||
|
* @param {string} pattern The text to encode.
|
|||
|
* @return {!Object} Hash of character locations.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.match_alphabet_ = function(pattern) {
|
|||
|
var s = {};
|
|||
|
for (var i = 0; i < pattern.length; i++) {
|
|||
|
s[pattern.charAt(i)] = 0;
|
|||
|
}
|
|||
|
for (var i = 0; i < pattern.length; i++) {
|
|||
|
s[pattern.charAt(i)] |= 1 << (pattern.length - i - 1);
|
|||
|
}
|
|||
|
return s;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
// PATCH FUNCTIONS
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Increase the context until it is unique,
|
|||
|
* but don't let the pattern expand beyond Match_MaxBits.
|
|||
|
* @param {!diff_match_patch.patch_obj} patch The patch to grow.
|
|||
|
* @param {string} text Source text.
|
|||
|
* @private
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.patch_addContext_ = function(patch, text) {
|
|||
|
if (text.length == 0) {
|
|||
|
return;
|
|||
|
}
|
|||
|
var pattern = text.substring(patch.start2, patch.start2 + patch.length1);
|
|||
|
var padding = 0;
|
|||
|
|
|||
|
// Look for the first and last matches of pattern in text. If two different
|
|||
|
// matches are found, increase the pattern length.
|
|||
|
while (text.indexOf(pattern) != text.lastIndexOf(pattern) &&
|
|||
|
pattern.length < this.Match_MaxBits - this.Patch_Margin -
|
|||
|
this.Patch_Margin) {
|
|||
|
padding += this.Patch_Margin;
|
|||
|
pattern = text.substring(patch.start2 - padding,
|
|||
|
patch.start2 + patch.length1 + padding);
|
|||
|
}
|
|||
|
// Add one chunk for good luck.
|
|||
|
padding += this.Patch_Margin;
|
|||
|
|
|||
|
// Add the prefix.
|
|||
|
var prefix = text.substring(patch.start2 - padding, patch.start2);
|
|||
|
if (prefix) {
|
|||
|
patch.diffs.unshift([DIFF_EQUAL, prefix]);
|
|||
|
}
|
|||
|
// Add the suffix.
|
|||
|
var suffix = text.substring(patch.start2 + patch.length1,
|
|||
|
patch.start2 + patch.length1 + padding);
|
|||
|
if (suffix) {
|
|||
|
patch.diffs.push([DIFF_EQUAL, suffix]);
|
|||
|
}
|
|||
|
|
|||
|
// Roll back the start points.
|
|||
|
patch.start1 -= prefix.length;
|
|||
|
patch.start2 -= prefix.length;
|
|||
|
// Extend the lengths.
|
|||
|
patch.length1 += prefix.length + suffix.length;
|
|||
|
patch.length2 += prefix.length + suffix.length;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Compute a list of patches to turn text1 into text2.
|
|||
|
* Use diffs if provided, otherwise compute it ourselves.
|
|||
|
* There are four ways to call this function, depending on what data is
|
|||
|
* available to the caller:
|
|||
|
* Method 1:
|
|||
|
* a = text1, b = text2
|
|||
|
* Method 2:
|
|||
|
* a = diffs
|
|||
|
* Method 3 (optimal):
|
|||
|
* a = text1, b = diffs
|
|||
|
* Method 4 (deprecated, use method 3):
|
|||
|
* a = text1, b = text2, c = diffs
|
|||
|
*
|
|||
|
* @param {string|!Array.<!diff_match_patch.Diff>} a text1 (methods 1,3,4) or
|
|||
|
* Array of diff tuples for text1 to text2 (method 2).
|
|||
|
* @param {string|!Array.<!diff_match_patch.Diff>} opt_b text2 (methods 1,4) or
|
|||
|
* Array of diff tuples for text1 to text2 (method 3) or undefined (method 2).
|
|||
|
* @param {string|!Array.<!diff_match_patch.Diff>} opt_c Array of diff tuples
|
|||
|
* for text1 to text2 (method 4) or undefined (methods 1,2,3).
|
|||
|
* @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.patch_make = function(a, opt_b, opt_c) {
|
|||
|
var text1, diffs;
|
|||
|
if (typeof a == 'string' && typeof opt_b == 'string' &&
|
|||
|
typeof opt_c == 'undefined') {
|
|||
|
// Method 1: text1, text2
|
|||
|
// Compute diffs from text1 and text2.
|
|||
|
text1 = /** @type {string} */(a);
|
|||
|
diffs = this.diff_main(text1, /** @type {string} */(opt_b), true);
|
|||
|
if (diffs.length > 2) {
|
|||
|
this.diff_cleanupSemantic(diffs);
|
|||
|
this.diff_cleanupEfficiency(diffs);
|
|||
|
}
|
|||
|
} else if (a && typeof a == 'object' && typeof opt_b == 'undefined' &&
|
|||
|
typeof opt_c == 'undefined') {
|
|||
|
// Method 2: diffs
|
|||
|
// Compute text1 from diffs.
|
|||
|
diffs = /** @type {!Array.<!diff_match_patch.Diff>} */(a);
|
|||
|
text1 = this.diff_text1(diffs);
|
|||
|
} else if (typeof a == 'string' && opt_b && typeof opt_b == 'object' &&
|
|||
|
typeof opt_c == 'undefined') {
|
|||
|
// Method 3: text1, diffs
|
|||
|
text1 = /** @type {string} */(a);
|
|||
|
diffs = /** @type {!Array.<!diff_match_patch.Diff>} */(opt_b);
|
|||
|
} else if (typeof a == 'string' && typeof opt_b == 'string' &&
|
|||
|
opt_c && typeof opt_c == 'object') {
|
|||
|
// Method 4: text1, text2, diffs
|
|||
|
// text2 is not used.
|
|||
|
text1 = /** @type {string} */(a);
|
|||
|
diffs = /** @type {!Array.<!diff_match_patch.Diff>} */(opt_c);
|
|||
|
} else {
|
|||
|
throw new Error('Unknown call format to patch_make.');
|
|||
|
}
|
|||
|
|
|||
|
if (diffs.length === 0) {
|
|||
|
return []; // Get rid of the null case.
|
|||
|
}
|
|||
|
var patches = [];
|
|||
|
var patch = new diff_match_patch.patch_obj();
|
|||
|
var patchDiffLength = 0; // Keeping our own length var is faster in JS.
|
|||
|
var char_count1 = 0; // Number of characters into the text1 string.
|
|||
|
var char_count2 = 0; // Number of characters into the text2 string.
|
|||
|
// Start with text1 (prepatch_text) and apply the diffs until we arrive at
|
|||
|
// text2 (postpatch_text). We recreate the patches one by one to determine
|
|||
|
// context info.
|
|||
|
var prepatch_text = text1;
|
|||
|
var postpatch_text = text1;
|
|||
|
for (var x = 0; x < diffs.length; x++) {
|
|||
|
var diff_type = diffs[x][0];
|
|||
|
var diff_text = diffs[x][1];
|
|||
|
|
|||
|
if (!patchDiffLength && diff_type !== DIFF_EQUAL) {
|
|||
|
// A new patch starts here.
|
|||
|
patch.start1 = char_count1;
|
|||
|
patch.start2 = char_count2;
|
|||
|
}
|
|||
|
|
|||
|
switch (diff_type) {
|
|||
|
case DIFF_INSERT:
|
|||
|
patch.diffs[patchDiffLength++] = diffs[x];
|
|||
|
patch.length2 += diff_text.length;
|
|||
|
postpatch_text = postpatch_text.substring(0, char_count2) + diff_text +
|
|||
|
postpatch_text.substring(char_count2);
|
|||
|
break;
|
|||
|
case DIFF_DELETE:
|
|||
|
patch.length1 += diff_text.length;
|
|||
|
patch.diffs[patchDiffLength++] = diffs[x];
|
|||
|
postpatch_text = postpatch_text.substring(0, char_count2) +
|
|||
|
postpatch_text.substring(char_count2 +
|
|||
|
diff_text.length);
|
|||
|
break;
|
|||
|
case DIFF_EQUAL:
|
|||
|
if (diff_text.length <= 2 * this.Patch_Margin &&
|
|||
|
patchDiffLength && diffs.length != x + 1) {
|
|||
|
// Small equality inside a patch.
|
|||
|
patch.diffs[patchDiffLength++] = diffs[x];
|
|||
|
patch.length1 += diff_text.length;
|
|||
|
patch.length2 += diff_text.length;
|
|||
|
} else if (diff_text.length >= 2 * this.Patch_Margin) {
|
|||
|
// Time for a new patch.
|
|||
|
if (patchDiffLength) {
|
|||
|
this.patch_addContext_(patch, prepatch_text);
|
|||
|
patches.push(patch);
|
|||
|
patch = new diff_match_patch.patch_obj();
|
|||
|
patchDiffLength = 0;
|
|||
|
// Unlike Unidiff, our patch lists have a rolling context.
|
|||
|
// http://code.google.com/p/google-diff-match-patch/wiki/Unidiff
|
|||
|
// Update prepatch text & pos to reflect the application of the
|
|||
|
// just completed patch.
|
|||
|
prepatch_text = postpatch_text;
|
|||
|
char_count1 = char_count2;
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
// Update the current character count.
|
|||
|
if (diff_type !== DIFF_INSERT) {
|
|||
|
char_count1 += diff_text.length;
|
|||
|
}
|
|||
|
if (diff_type !== DIFF_DELETE) {
|
|||
|
char_count2 += diff_text.length;
|
|||
|
}
|
|||
|
}
|
|||
|
// Pick up the leftover patch if not empty.
|
|||
|
if (patchDiffLength) {
|
|||
|
this.patch_addContext_(patch, prepatch_text);
|
|||
|
patches.push(patch);
|
|||
|
}
|
|||
|
|
|||
|
return patches;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Given an array of patches, return another array that is identical.
|
|||
|
* @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
|
|||
|
* @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.patch_deepCopy = function(patches) {
|
|||
|
// Making deep copies is hard in JavaScript.
|
|||
|
var patchesCopy = [];
|
|||
|
for (var x = 0; x < patches.length; x++) {
|
|||
|
var patch = patches[x];
|
|||
|
var patchCopy = new diff_match_patch.patch_obj();
|
|||
|
patchCopy.diffs = [];
|
|||
|
for (var y = 0; y < patch.diffs.length; y++) {
|
|||
|
patchCopy.diffs[y] = patch.diffs[y].slice();
|
|||
|
}
|
|||
|
patchCopy.start1 = patch.start1;
|
|||
|
patchCopy.start2 = patch.start2;
|
|||
|
patchCopy.length1 = patch.length1;
|
|||
|
patchCopy.length2 = patch.length2;
|
|||
|
patchesCopy[x] = patchCopy;
|
|||
|
}
|
|||
|
return patchesCopy;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Merge a set of patches onto the text. Return a patched text, as well
|
|||
|
* as a list of true/false values indicating which patches were applied.
|
|||
|
* @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
|
|||
|
* @param {string} text Old text.
|
|||
|
* @return {!Array.<string|!Array.<boolean>>} Two element Array, containing the
|
|||
|
* new text and an array of boolean values.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.patch_apply = function(patches, text) {
|
|||
|
if (patches.length == 0) {
|
|||
|
return [text, []];
|
|||
|
}
|
|||
|
|
|||
|
// Deep copy the patches so that no changes are made to originals.
|
|||
|
patches = this.patch_deepCopy(patches);
|
|||
|
|
|||
|
var nullPadding = this.patch_addPadding(patches);
|
|||
|
text = nullPadding + text + nullPadding;
|
|||
|
|
|||
|
this.patch_splitMax(patches);
|
|||
|
// delta keeps track of the offset between the expected and actual location
|
|||
|
// of the previous patch. If there are patches expected at positions 10 and
|
|||
|
// 20, but the first patch was found at 12, delta is 2 and the second patch
|
|||
|
// has an effective expected position of 22.
|
|||
|
var delta = 0;
|
|||
|
var results = [];
|
|||
|
for (var x = 0; x < patches.length; x++) {
|
|||
|
var expected_loc = patches[x].start2 + delta;
|
|||
|
var text1 = this.diff_text1(patches[x].diffs);
|
|||
|
var start_loc;
|
|||
|
var end_loc = -1;
|
|||
|
if (text1.length > this.Match_MaxBits) {
|
|||
|
// patch_splitMax will only provide an oversized pattern in the case of
|
|||
|
// a monster delete.
|
|||
|
start_loc = this.match_main(text, text1.substring(0, this.Match_MaxBits),
|
|||
|
expected_loc);
|
|||
|
if (start_loc != -1) {
|
|||
|
end_loc = this.match_main(text,
|
|||
|
text1.substring(text1.length - this.Match_MaxBits),
|
|||
|
expected_loc + text1.length - this.Match_MaxBits);
|
|||
|
if (end_loc == -1 || start_loc >= end_loc) {
|
|||
|
// Can't find valid trailing context. Drop this patch.
|
|||
|
start_loc = -1;
|
|||
|
}
|
|||
|
}
|
|||
|
} else {
|
|||
|
start_loc = this.match_main(text, text1, expected_loc);
|
|||
|
}
|
|||
|
if (start_loc == -1) {
|
|||
|
// No match found. :(
|
|||
|
results[x] = false;
|
|||
|
// Subtract the delta for this failed patch from subsequent patches.
|
|||
|
delta -= patches[x].length2 - patches[x].length1;
|
|||
|
} else {
|
|||
|
// Found a match. :)
|
|||
|
results[x] = true;
|
|||
|
delta = start_loc - expected_loc;
|
|||
|
var text2;
|
|||
|
if (end_loc == -1) {
|
|||
|
text2 = text.substring(start_loc, start_loc + text1.length);
|
|||
|
} else {
|
|||
|
text2 = text.substring(start_loc, end_loc + this.Match_MaxBits);
|
|||
|
}
|
|||
|
if (text1 == text2) {
|
|||
|
// Perfect match, just shove the replacement text in.
|
|||
|
text = text.substring(0, start_loc) +
|
|||
|
this.diff_text2(patches[x].diffs) +
|
|||
|
text.substring(start_loc + text1.length);
|
|||
|
} else {
|
|||
|
// Imperfect match. Run a diff to get a framework of equivalent
|
|||
|
// indices.
|
|||
|
var diffs = this.diff_main(text1, text2, false);
|
|||
|
if (text1.length > this.Match_MaxBits &&
|
|||
|
this.diff_levenshtein(diffs) / text1.length >
|
|||
|
this.Patch_DeleteThreshold) {
|
|||
|
// The end points match, but the content is unacceptably bad.
|
|||
|
results[x] = false;
|
|||
|
} else {
|
|||
|
this.diff_cleanupSemanticLossless(diffs);
|
|||
|
var index1 = 0;
|
|||
|
var index2;
|
|||
|
for (var y = 0; y < patches[x].diffs.length; y++) {
|
|||
|
var mod = patches[x].diffs[y];
|
|||
|
if (mod[0] !== DIFF_EQUAL) {
|
|||
|
index2 = this.diff_xIndex(diffs, index1);
|
|||
|
}
|
|||
|
if (mod[0] === DIFF_INSERT) { // Insertion
|
|||
|
text = text.substring(0, start_loc + index2) + mod[1] +
|
|||
|
text.substring(start_loc + index2);
|
|||
|
} else if (mod[0] === DIFF_DELETE) { // Deletion
|
|||
|
text = text.substring(0, start_loc + index2) +
|
|||
|
text.substring(start_loc + this.diff_xIndex(diffs,
|
|||
|
index1 + mod[1].length));
|
|||
|
}
|
|||
|
if (mod[0] !== DIFF_DELETE) {
|
|||
|
index1 += mod[1].length;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
// Strip the padding off.
|
|||
|
text = text.substring(nullPadding.length, text.length - nullPadding.length);
|
|||
|
return [text, results];
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Add some padding on text start and end so that edges can match something.
|
|||
|
* Intended to be called only from within patch_apply.
|
|||
|
* @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
|
|||
|
* @return {string} The padding string added to each side.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.patch_addPadding = function(patches) {
|
|||
|
var paddingLength = this.Patch_Margin;
|
|||
|
var nullPadding = '';
|
|||
|
for (var x = 1; x <= paddingLength; x++) {
|
|||
|
nullPadding += String.fromCharCode(x);
|
|||
|
}
|
|||
|
|
|||
|
// Bump all the patches forward.
|
|||
|
for (var x = 0; x < patches.length; x++) {
|
|||
|
patches[x].start1 += paddingLength;
|
|||
|
patches[x].start2 += paddingLength;
|
|||
|
}
|
|||
|
|
|||
|
// Add some padding on start of first diff.
|
|||
|
var patch = patches[0];
|
|||
|
var diffs = patch.diffs;
|
|||
|
if (diffs.length == 0 || diffs[0][0] != DIFF_EQUAL) {
|
|||
|
// Add nullPadding equality.
|
|||
|
diffs.unshift([DIFF_EQUAL, nullPadding]);
|
|||
|
patch.start1 -= paddingLength; // Should be 0.
|
|||
|
patch.start2 -= paddingLength; // Should be 0.
|
|||
|
patch.length1 += paddingLength;
|
|||
|
patch.length2 += paddingLength;
|
|||
|
} else if (paddingLength > diffs[0][1].length) {
|
|||
|
// Grow first equality.
|
|||
|
var extraLength = paddingLength - diffs[0][1].length;
|
|||
|
diffs[0][1] = nullPadding.substring(diffs[0][1].length) + diffs[0][1];
|
|||
|
patch.start1 -= extraLength;
|
|||
|
patch.start2 -= extraLength;
|
|||
|
patch.length1 += extraLength;
|
|||
|
patch.length2 += extraLength;
|
|||
|
}
|
|||
|
|
|||
|
// Add some padding on end of last diff.
|
|||
|
patch = patches[patches.length - 1];
|
|||
|
diffs = patch.diffs;
|
|||
|
if (diffs.length == 0 || diffs[diffs.length - 1][0] != DIFF_EQUAL) {
|
|||
|
// Add nullPadding equality.
|
|||
|
diffs.push([DIFF_EQUAL, nullPadding]);
|
|||
|
patch.length1 += paddingLength;
|
|||
|
patch.length2 += paddingLength;
|
|||
|
} else if (paddingLength > diffs[diffs.length - 1][1].length) {
|
|||
|
// Grow last equality.
|
|||
|
var extraLength = paddingLength - diffs[diffs.length - 1][1].length;
|
|||
|
diffs[diffs.length - 1][1] += nullPadding.substring(0, extraLength);
|
|||
|
patch.length1 += extraLength;
|
|||
|
patch.length2 += extraLength;
|
|||
|
}
|
|||
|
|
|||
|
return nullPadding;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Look through the patches and break up any which are longer than the maximum
|
|||
|
* limit of the match algorithm.
|
|||
|
* Intended to be called only from within patch_apply.
|
|||
|
* @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.patch_splitMax = function(patches) {
|
|||
|
var patch_size = this.Match_MaxBits;
|
|||
|
for (var x = 0; x < patches.length; x++) {
|
|||
|
if (patches[x].length1 <= patch_size) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
var bigpatch = patches[x];
|
|||
|
// Remove the big old patch.
|
|||
|
patches.splice(x--, 1);
|
|||
|
var start1 = bigpatch.start1;
|
|||
|
var start2 = bigpatch.start2;
|
|||
|
var precontext = '';
|
|||
|
while (bigpatch.diffs.length !== 0) {
|
|||
|
// Create one of several smaller patches.
|
|||
|
var patch = new diff_match_patch.patch_obj();
|
|||
|
var empty = true;
|
|||
|
patch.start1 = start1 - precontext.length;
|
|||
|
patch.start2 = start2 - precontext.length;
|
|||
|
if (precontext !== '') {
|
|||
|
patch.length1 = patch.length2 = precontext.length;
|
|||
|
patch.diffs.push([DIFF_EQUAL, precontext]);
|
|||
|
}
|
|||
|
while (bigpatch.diffs.length !== 0 &&
|
|||
|
patch.length1 < patch_size - this.Patch_Margin) {
|
|||
|
var diff_type = bigpatch.diffs[0][0];
|
|||
|
var diff_text = bigpatch.diffs[0][1];
|
|||
|
if (diff_type === DIFF_INSERT) {
|
|||
|
// Insertions are harmless.
|
|||
|
patch.length2 += diff_text.length;
|
|||
|
start2 += diff_text.length;
|
|||
|
patch.diffs.push(bigpatch.diffs.shift());
|
|||
|
empty = false;
|
|||
|
} else if (diff_type === DIFF_DELETE && patch.diffs.length == 1 &&
|
|||
|
patch.diffs[0][0] == DIFF_EQUAL &&
|
|||
|
diff_text.length > 2 * patch_size) {
|
|||
|
// This is a large deletion. Let it pass in one chunk.
|
|||
|
patch.length1 += diff_text.length;
|
|||
|
start1 += diff_text.length;
|
|||
|
empty = false;
|
|||
|
patch.diffs.push([diff_type, diff_text]);
|
|||
|
bigpatch.diffs.shift();
|
|||
|
} else {
|
|||
|
// Deletion or equality. Only take as much as we can stomach.
|
|||
|
diff_text = diff_text.substring(0,
|
|||
|
patch_size - patch.length1 - this.Patch_Margin);
|
|||
|
patch.length1 += diff_text.length;
|
|||
|
start1 += diff_text.length;
|
|||
|
if (diff_type === DIFF_EQUAL) {
|
|||
|
patch.length2 += diff_text.length;
|
|||
|
start2 += diff_text.length;
|
|||
|
} else {
|
|||
|
empty = false;
|
|||
|
}
|
|||
|
patch.diffs.push([diff_type, diff_text]);
|
|||
|
if (diff_text == bigpatch.diffs[0][1]) {
|
|||
|
bigpatch.diffs.shift();
|
|||
|
} else {
|
|||
|
bigpatch.diffs[0][1] =
|
|||
|
bigpatch.diffs[0][1].substring(diff_text.length);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
// Compute the head context for the next patch.
|
|||
|
precontext = this.diff_text2(patch.diffs);
|
|||
|
precontext =
|
|||
|
precontext.substring(precontext.length - this.Patch_Margin);
|
|||
|
// Append the end context for this patch.
|
|||
|
var postcontext = this.diff_text1(bigpatch.diffs)
|
|||
|
.substring(0, this.Patch_Margin);
|
|||
|
if (postcontext !== '') {
|
|||
|
patch.length1 += postcontext.length;
|
|||
|
patch.length2 += postcontext.length;
|
|||
|
if (patch.diffs.length !== 0 &&
|
|||
|
patch.diffs[patch.diffs.length - 1][0] === DIFF_EQUAL) {
|
|||
|
patch.diffs[patch.diffs.length - 1][1] += postcontext;
|
|||
|
} else {
|
|||
|
patch.diffs.push([DIFF_EQUAL, postcontext]);
|
|||
|
}
|
|||
|
}
|
|||
|
if (!empty) {
|
|||
|
patches.splice(++x, 0, patch);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Take a list of patches and return a textual representation.
|
|||
|
* @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
|
|||
|
* @return {string} Text representation of patches.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.patch_toText = function(patches) {
|
|||
|
var text = [];
|
|||
|
for (var x = 0; x < patches.length; x++) {
|
|||
|
text[x] = patches[x];
|
|||
|
}
|
|||
|
return text.join('');
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Parse a textual representation of patches and return a list of Patch objects.
|
|||
|
* @param {string} textline Text representation of patches.
|
|||
|
* @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
|
|||
|
* @throws {!Error} If invalid input.
|
|||
|
*/
|
|||
|
diff_match_patch.prototype.patch_fromText = function(textline) {
|
|||
|
var patches = [];
|
|||
|
if (!textline) {
|
|||
|
return patches;
|
|||
|
}
|
|||
|
var text = textline.split('\n');
|
|||
|
var textPointer = 0;
|
|||
|
var patchHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;
|
|||
|
while (textPointer < text.length) {
|
|||
|
var m = text[textPointer].match(patchHeader);
|
|||
|
if (!m) {
|
|||
|
throw new Error('Invalid patch string: ' + text[textPointer]);
|
|||
|
}
|
|||
|
var patch = new diff_match_patch.patch_obj();
|
|||
|
patches.push(patch);
|
|||
|
patch.start1 = parseInt(m[1], 10);
|
|||
|
if (m[2] === '') {
|
|||
|
patch.start1--;
|
|||
|
patch.length1 = 1;
|
|||
|
} else if (m[2] == '0') {
|
|||
|
patch.length1 = 0;
|
|||
|
} else {
|
|||
|
patch.start1--;
|
|||
|
patch.length1 = parseInt(m[2], 10);
|
|||
|
}
|
|||
|
|
|||
|
patch.start2 = parseInt(m[3], 10);
|
|||
|
if (m[4] === '') {
|
|||
|
patch.start2--;
|
|||
|
patch.length2 = 1;
|
|||
|
} else if (m[4] == '0') {
|
|||
|
patch.length2 = 0;
|
|||
|
} else {
|
|||
|
patch.start2--;
|
|||
|
patch.length2 = parseInt(m[4], 10);
|
|||
|
}
|
|||
|
textPointer++;
|
|||
|
|
|||
|
while (textPointer < text.length) {
|
|||
|
var sign = text[textPointer].charAt(0);
|
|||
|
try {
|
|||
|
var line = decodeURI(text[textPointer].substring(1));
|
|||
|
} catch (ex) {
|
|||
|
// Malformed URI sequence.
|
|||
|
throw new Error('Illegal escape in patch_fromText: ' + line);
|
|||
|
}
|
|||
|
if (sign == '-') {
|
|||
|
// Deletion.
|
|||
|
patch.diffs.push([DIFF_DELETE, line]);
|
|||
|
} else if (sign == '+') {
|
|||
|
// Insertion.
|
|||
|
patch.diffs.push([DIFF_INSERT, line]);
|
|||
|
} else if (sign == ' ') {
|
|||
|
// Minor equality.
|
|||
|
patch.diffs.push([DIFF_EQUAL, line]);
|
|||
|
} else if (sign == '@') {
|
|||
|
// Start of next patch.
|
|||
|
break;
|
|||
|
} else if (sign === '') {
|
|||
|
// Blank line? Whatever.
|
|||
|
} else {
|
|||
|
// WTF?
|
|||
|
throw new Error('Invalid patch mode "' + sign + '" in: ' + line);
|
|||
|
}
|
|||
|
textPointer++;
|
|||
|
}
|
|||
|
}
|
|||
|
return patches;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Class representing one patch operation.
|
|||
|
* @constructor
|
|||
|
*/
|
|||
|
diff_match_patch.patch_obj = function() {
|
|||
|
/** @type {!Array.<!diff_match_patch.Diff>} */
|
|||
|
this.diffs = [];
|
|||
|
/** @type {?number} */
|
|||
|
this.start1 = null;
|
|||
|
/** @type {?number} */
|
|||
|
this.start2 = null;
|
|||
|
/** @type {number} */
|
|||
|
this.length1 = 0;
|
|||
|
/** @type {number} */
|
|||
|
this.length2 = 0;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Emmulate GNU diff's format.
|
|||
|
* Header: @@ -382,8 +481,9 @@
|
|||
|
* Indicies are printed as 1-based, not 0-based.
|
|||
|
* @return {string} The GNU diff string.
|
|||
|
*/
|
|||
|
diff_match_patch.patch_obj.prototype.toString = function() {
|
|||
|
var coords1, coords2;
|
|||
|
if (this.length1 === 0) {
|
|||
|
coords1 = this.start1 + ',0';
|
|||
|
} else if (this.length1 == 1) {
|
|||
|
coords1 = this.start1 + 1;
|
|||
|
} else {
|
|||
|
coords1 = (this.start1 + 1) + ',' + this.length1;
|
|||
|
}
|
|||
|
if (this.length2 === 0) {
|
|||
|
coords2 = this.start2 + ',0';
|
|||
|
} else if (this.length2 == 1) {
|
|||
|
coords2 = this.start2 + 1;
|
|||
|
} else {
|
|||
|
coords2 = (this.start2 + 1) + ',' + this.length2;
|
|||
|
}
|
|||
|
var text = ['@@ -' + coords1 + ' +' + coords2 + ' @@\n'];
|
|||
|
var op;
|
|||
|
// Escape the body of the patch with %xx notation.
|
|||
|
for (var x = 0; x < this.diffs.length; x++) {
|
|||
|
switch (this.diffs[x][0]) {
|
|||
|
case DIFF_INSERT:
|
|||
|
op = '+';
|
|||
|
break;
|
|||
|
case DIFF_DELETE:
|
|||
|
op = '-';
|
|||
|
break;
|
|||
|
case DIFF_EQUAL:
|
|||
|
op = ' ';
|
|||
|
break;
|
|||
|
}
|
|||
|
text[x + 1] = op + encodeURI(this.diffs[x][1]) + '\n';
|
|||
|
}
|
|||
|
return text.join('').replace(/%20/g, ' ');
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
// The following export code was added by @ForbesLindesay
|
|||
|
module.exports = diff_match_patch;
|
|||
|
module.exports['diff_match_patch'] = diff_match_patch;
|
|||
|
module.exports['DIFF_DELETE'] = DIFF_DELETE;
|
|||
|
module.exports['DIFF_INSERT'] = DIFF_INSERT;
|
|||
|
module.exports['DIFF_EQUAL'] = DIFF_EQUAL;
|
|||
|
|
|||
|
},{}],67:[function(_dereq_,module,exports){
|
|||
|
var eaw = {};
|
|||
|
|
|||
|
if ('undefined' == typeof module) {
|
|||
|
window.eastasianwidth = eaw;
|
|||
|
} else {
|
|||
|
module.exports = eaw;
|
|||
|
}
|
|||
|
|
|||
|
eaw.eastAsianWidth = function(character) {
|
|||
|
var x = character.charCodeAt(0);
|
|||
|
var y = (character.length == 2) ? character.charCodeAt(1) : 0;
|
|||
|
var codePoint = x;
|
|||
|
if ((0xD800 <= x && x <= 0xDBFF) && (0xDC00 <= y && y <= 0xDFFF)) {
|
|||
|
x &= 0x3FF;
|
|||
|
y &= 0x3FF;
|
|||
|
codePoint = (x << 10) | y;
|
|||
|
codePoint += 0x10000;
|
|||
|
}
|
|||
|
|
|||
|
if ((0x3000 == codePoint) ||
|
|||
|
(0xFF01 <= codePoint && codePoint <= 0xFF60) ||
|
|||
|
(0xFFE0 <= codePoint && codePoint <= 0xFFE6)) {
|
|||
|
return 'F';
|
|||
|
}
|
|||
|
if ((0x20A9 == codePoint) ||
|
|||
|
(0xFF61 <= codePoint && codePoint <= 0xFFBE) ||
|
|||
|
(0xFFC2 <= codePoint && codePoint <= 0xFFC7) ||
|
|||
|
(0xFFCA <= codePoint && codePoint <= 0xFFCF) ||
|
|||
|
(0xFFD2 <= codePoint && codePoint <= 0xFFD7) ||
|
|||
|
(0xFFDA <= codePoint && codePoint <= 0xFFDC) ||
|
|||
|
(0xFFE8 <= codePoint && codePoint <= 0xFFEE)) {
|
|||
|
return 'H';
|
|||
|
}
|
|||
|
if ((0x1100 <= codePoint && codePoint <= 0x115F) ||
|
|||
|
(0x11A3 <= codePoint && codePoint <= 0x11A7) ||
|
|||
|
(0x11FA <= codePoint && codePoint <= 0x11FF) ||
|
|||
|
(0x2329 <= codePoint && codePoint <= 0x232A) ||
|
|||
|
(0x2E80 <= codePoint && codePoint <= 0x2E99) ||
|
|||
|
(0x2E9B <= codePoint && codePoint <= 0x2EF3) ||
|
|||
|
(0x2F00 <= codePoint && codePoint <= 0x2FD5) ||
|
|||
|
(0x2FF0 <= codePoint && codePoint <= 0x2FFB) ||
|
|||
|
(0x3001 <= codePoint && codePoint <= 0x303E) ||
|
|||
|
(0x3041 <= codePoint && codePoint <= 0x3096) ||
|
|||
|
(0x3099 <= codePoint && codePoint <= 0x30FF) ||
|
|||
|
(0x3105 <= codePoint && codePoint <= 0x312D) ||
|
|||
|
(0x3131 <= codePoint && codePoint <= 0x318E) ||
|
|||
|
(0x3190 <= codePoint && codePoint <= 0x31BA) ||
|
|||
|
(0x31C0 <= codePoint && codePoint <= 0x31E3) ||
|
|||
|
(0x31F0 <= codePoint && codePoint <= 0x321E) ||
|
|||
|
(0x3220 <= codePoint && codePoint <= 0x3247) ||
|
|||
|
(0x3250 <= codePoint && codePoint <= 0x32FE) ||
|
|||
|
(0x3300 <= codePoint && codePoint <= 0x4DBF) ||
|
|||
|
(0x4E00 <= codePoint && codePoint <= 0xA48C) ||
|
|||
|
(0xA490 <= codePoint && codePoint <= 0xA4C6) ||
|
|||
|
(0xA960 <= codePoint && codePoint <= 0xA97C) ||
|
|||
|
(0xAC00 <= codePoint && codePoint <= 0xD7A3) ||
|
|||
|
(0xD7B0 <= codePoint && codePoint <= 0xD7C6) ||
|
|||
|
(0xD7CB <= codePoint && codePoint <= 0xD7FB) ||
|
|||
|
(0xF900 <= codePoint && codePoint <= 0xFAFF) ||
|
|||
|
(0xFE10 <= codePoint && codePoint <= 0xFE19) ||
|
|||
|
(0xFE30 <= codePoint && codePoint <= 0xFE52) ||
|
|||
|
(0xFE54 <= codePoint && codePoint <= 0xFE66) ||
|
|||
|
(0xFE68 <= codePoint && codePoint <= 0xFE6B) ||
|
|||
|
(0x1B000 <= codePoint && codePoint <= 0x1B001) ||
|
|||
|
(0x1F200 <= codePoint && codePoint <= 0x1F202) ||
|
|||
|
(0x1F210 <= codePoint && codePoint <= 0x1F23A) ||
|
|||
|
(0x1F240 <= codePoint && codePoint <= 0x1F248) ||
|
|||
|
(0x1F250 <= codePoint && codePoint <= 0x1F251) ||
|
|||
|
(0x20000 <= codePoint && codePoint <= 0x2F73F) ||
|
|||
|
(0x2B740 <= codePoint && codePoint <= 0x2FFFD) ||
|
|||
|
(0x30000 <= codePoint && codePoint <= 0x3FFFD)) {
|
|||
|
return 'W';
|
|||
|
}
|
|||
|
if ((0x0020 <= codePoint && codePoint <= 0x007E) ||
|
|||
|
(0x00A2 <= codePoint && codePoint <= 0x00A3) ||
|
|||
|
(0x00A5 <= codePoint && codePoint <= 0x00A6) ||
|
|||
|
(0x00AC == codePoint) ||
|
|||
|
(0x00AF == codePoint) ||
|
|||
|
(0x27E6 <= codePoint && codePoint <= 0x27ED) ||
|
|||
|
(0x2985 <= codePoint && codePoint <= 0x2986)) {
|
|||
|
return 'Na';
|
|||
|
}
|
|||
|
if ((0x00A1 == codePoint) ||
|
|||
|
(0x00A4 == codePoint) ||
|
|||
|
(0x00A7 <= codePoint && codePoint <= 0x00A8) ||
|
|||
|
(0x00AA == codePoint) ||
|
|||
|
(0x00AD <= codePoint && codePoint <= 0x00AE) ||
|
|||
|
(0x00B0 <= codePoint && codePoint <= 0x00B4) ||
|
|||
|
(0x00B6 <= codePoint && codePoint <= 0x00BA) ||
|
|||
|
(0x00BC <= codePoint && codePoint <= 0x00BF) ||
|
|||
|
(0x00C6 == codePoint) ||
|
|||
|
(0x00D0 == codePoint) ||
|
|||
|
(0x00D7 <= codePoint && codePoint <= 0x00D8) ||
|
|||
|
(0x00DE <= codePoint && codePoint <= 0x00E1) ||
|
|||
|
(0x00E6 == codePoint) ||
|
|||
|
(0x00E8 <= codePoint && codePoint <= 0x00EA) ||
|
|||
|
(0x00EC <= codePoint && codePoint <= 0x00ED) ||
|
|||
|
(0x00F0 == codePoint) ||
|
|||
|
(0x00F2 <= codePoint && codePoint <= 0x00F3) ||
|
|||
|
(0x00F7 <= codePoint && codePoint <= 0x00FA) ||
|
|||
|
(0x00FC == codePoint) ||
|
|||
|
(0x00FE == codePoint) ||
|
|||
|
(0x0101 == codePoint) ||
|
|||
|
(0x0111 == codePoint) ||
|
|||
|
(0x0113 == codePoint) ||
|
|||
|
(0x011B == codePoint) ||
|
|||
|
(0x0126 <= codePoint && codePoint <= 0x0127) ||
|
|||
|
(0x012B == codePoint) ||
|
|||
|
(0x0131 <= codePoint && codePoint <= 0x0133) ||
|
|||
|
(0x0138 == codePoint) ||
|
|||
|
(0x013F <= codePoint && codePoint <= 0x0142) ||
|
|||
|
(0x0144 == codePoint) ||
|
|||
|
(0x0148 <= codePoint && codePoint <= 0x014B) ||
|
|||
|
(0x014D == codePoint) ||
|
|||
|
(0x0152 <= codePoint && codePoint <= 0x0153) ||
|
|||
|
(0x0166 <= codePoint && codePoint <= 0x0167) ||
|
|||
|
(0x016B == codePoint) ||
|
|||
|
(0x01CE == codePoint) ||
|
|||
|
(0x01D0 == codePoint) ||
|
|||
|
(0x01D2 == codePoint) ||
|
|||
|
(0x01D4 == codePoint) ||
|
|||
|
(0x01D6 == codePoint) ||
|
|||
|
(0x01D8 == codePoint) ||
|
|||
|
(0x01DA == codePoint) ||
|
|||
|
(0x01DC == codePoint) ||
|
|||
|
(0x0251 == codePoint) ||
|
|||
|
(0x0261 == codePoint) ||
|
|||
|
(0x02C4 == codePoint) ||
|
|||
|
(0x02C7 == codePoint) ||
|
|||
|
(0x02C9 <= codePoint && codePoint <= 0x02CB) ||
|
|||
|
(0x02CD == codePoint) ||
|
|||
|
(0x02D0 == codePoint) ||
|
|||
|
(0x02D8 <= codePoint && codePoint <= 0x02DB) ||
|
|||
|
(0x02DD == codePoint) ||
|
|||
|
(0x02DF == codePoint) ||
|
|||
|
(0x0300 <= codePoint && codePoint <= 0x036F) ||
|
|||
|
(0x0391 <= codePoint && codePoint <= 0x03A1) ||
|
|||
|
(0x03A3 <= codePoint && codePoint <= 0x03A9) ||
|
|||
|
(0x03B1 <= codePoint && codePoint <= 0x03C1) ||
|
|||
|
(0x03C3 <= codePoint && codePoint <= 0x03C9) ||
|
|||
|
(0x0401 == codePoint) ||
|
|||
|
(0x0410 <= codePoint && codePoint <= 0x044F) ||
|
|||
|
(0x0451 == codePoint) ||
|
|||
|
(0x2010 == codePoint) ||
|
|||
|
(0x2013 <= codePoint && codePoint <= 0x2016) ||
|
|||
|
(0x2018 <= codePoint && codePoint <= 0x2019) ||
|
|||
|
(0x201C <= codePoint && codePoint <= 0x201D) ||
|
|||
|
(0x2020 <= codePoint && codePoint <= 0x2022) ||
|
|||
|
(0x2024 <= codePoint && codePoint <= 0x2027) ||
|
|||
|
(0x2030 == codePoint) ||
|
|||
|
(0x2032 <= codePoint && codePoint <= 0x2033) ||
|
|||
|
(0x2035 == codePoint) ||
|
|||
|
(0x203B == codePoint) ||
|
|||
|
(0x203E == codePoint) ||
|
|||
|
(0x2074 == codePoint) ||
|
|||
|
(0x207F == codePoint) ||
|
|||
|
(0x2081 <= codePoint && codePoint <= 0x2084) ||
|
|||
|
(0x20AC == codePoint) ||
|
|||
|
(0x2103 == codePoint) ||
|
|||
|
(0x2105 == codePoint) ||
|
|||
|
(0x2109 == codePoint) ||
|
|||
|
(0x2113 == codePoint) ||
|
|||
|
(0x2116 == codePoint) ||
|
|||
|
(0x2121 <= codePoint && codePoint <= 0x2122) ||
|
|||
|
(0x2126 == codePoint) ||
|
|||
|
(0x212B == codePoint) ||
|
|||
|
(0x2153 <= codePoint && codePoint <= 0x2154) ||
|
|||
|
(0x215B <= codePoint && codePoint <= 0x215E) ||
|
|||
|
(0x2160 <= codePoint && codePoint <= 0x216B) ||
|
|||
|
(0x2170 <= codePoint && codePoint <= 0x2179) ||
|
|||
|
(0x2189 == codePoint) ||
|
|||
|
(0x2190 <= codePoint && codePoint <= 0x2199) ||
|
|||
|
(0x21B8 <= codePoint && codePoint <= 0x21B9) ||
|
|||
|
(0x21D2 == codePoint) ||
|
|||
|
(0x21D4 == codePoint) ||
|
|||
|
(0x21E7 == codePoint) ||
|
|||
|
(0x2200 == codePoint) ||
|
|||
|
(0x2202 <= codePoint && codePoint <= 0x2203) ||
|
|||
|
(0x2207 <= codePoint && codePoint <= 0x2208) ||
|
|||
|
(0x220B == codePoint) ||
|
|||
|
(0x220F == codePoint) ||
|
|||
|
(0x2211 == codePoint) ||
|
|||
|
(0x2215 == codePoint) ||
|
|||
|
(0x221A == codePoint) ||
|
|||
|
(0x221D <= codePoint && codePoint <= 0x2220) ||
|
|||
|
(0x2223 == codePoint) ||
|
|||
|
(0x2225 == codePoint) ||
|
|||
|
(0x2227 <= codePoint && codePoint <= 0x222C) ||
|
|||
|
(0x222E == codePoint) ||
|
|||
|
(0x2234 <= codePoint && codePoint <= 0x2237) ||
|
|||
|
(0x223C <= codePoint && codePoint <= 0x223D) ||
|
|||
|
(0x2248 == codePoint) ||
|
|||
|
(0x224C == codePoint) ||
|
|||
|
(0x2252 == codePoint) ||
|
|||
|
(0x2260 <= codePoint && codePoint <= 0x2261) ||
|
|||
|
(0x2264 <= codePoint && codePoint <= 0x2267) ||
|
|||
|
(0x226A <= codePoint && codePoint <= 0x226B) ||
|
|||
|
(0x226E <= codePoint && codePoint <= 0x226F) ||
|
|||
|
(0x2282 <= codePoint && codePoint <= 0x2283) ||
|
|||
|
(0x2286 <= codePoint && codePoint <= 0x2287) ||
|
|||
|
(0x2295 == codePoint) ||
|
|||
|
(0x2299 == codePoint) ||
|
|||
|
(0x22A5 == codePoint) ||
|
|||
|
(0x22BF == codePoint) ||
|
|||
|
(0x2312 == codePoint) ||
|
|||
|
(0x2460 <= codePoint && codePoint <= 0x24E9) ||
|
|||
|
(0x24EB <= codePoint && codePoint <= 0x254B) ||
|
|||
|
(0x2550 <= codePoint && codePoint <= 0x2573) ||
|
|||
|
(0x2580 <= codePoint && codePoint <= 0x258F) ||
|
|||
|
(0x2592 <= codePoint && codePoint <= 0x2595) ||
|
|||
|
(0x25A0 <= codePoint && codePoint <= 0x25A1) ||
|
|||
|
(0x25A3 <= codePoint && codePoint <= 0x25A9) ||
|
|||
|
(0x25B2 <= codePoint && codePoint <= 0x25B3) ||
|
|||
|
(0x25B6 <= codePoint && codePoint <= 0x25B7) ||
|
|||
|
(0x25BC <= codePoint && codePoint <= 0x25BD) ||
|
|||
|
(0x25C0 <= codePoint && codePoint <= 0x25C1) ||
|
|||
|
(0x25C6 <= codePoint && codePoint <= 0x25C8) ||
|
|||
|
(0x25CB == codePoint) ||
|
|||
|
(0x25CE <= codePoint && codePoint <= 0x25D1) ||
|
|||
|
(0x25E2 <= codePoint && codePoint <= 0x25E5) ||
|
|||
|
(0x25EF == codePoint) ||
|
|||
|
(0x2605 <= codePoint && codePoint <= 0x2606) ||
|
|||
|
(0x2609 == codePoint) ||
|
|||
|
(0x260E <= codePoint && codePoint <= 0x260F) ||
|
|||
|
(0x2614 <= codePoint && codePoint <= 0x2615) ||
|
|||
|
(0x261C == codePoint) ||
|
|||
|
(0x261E == codePoint) ||
|
|||
|
(0x2640 == codePoint) ||
|
|||
|
(0x2642 == codePoint) ||
|
|||
|
(0x2660 <= codePoint && codePoint <= 0x2661) ||
|
|||
|
(0x2663 <= codePoint && codePoint <= 0x2665) ||
|
|||
|
(0x2667 <= codePoint && codePoint <= 0x266A) ||
|
|||
|
(0x266C <= codePoint && codePoint <= 0x266D) ||
|
|||
|
(0x266F == codePoint) ||
|
|||
|
(0x269E <= codePoint && codePoint <= 0x269F) ||
|
|||
|
(0x26BE <= codePoint && codePoint <= 0x26BF) ||
|
|||
|
(0x26C4 <= codePoint && codePoint <= 0x26CD) ||
|
|||
|
(0x26CF <= codePoint && codePoint <= 0x26E1) ||
|
|||
|
(0x26E3 == codePoint) ||
|
|||
|
(0x26E8 <= codePoint && codePoint <= 0x26FF) ||
|
|||
|
(0x273D == codePoint) ||
|
|||
|
(0x2757 == codePoint) ||
|
|||
|
(0x2776 <= codePoint && codePoint <= 0x277F) ||
|
|||
|
(0x2B55 <= codePoint && codePoint <= 0x2B59) ||
|
|||
|
(0x3248 <= codePoint && codePoint <= 0x324F) ||
|
|||
|
(0xE000 <= codePoint && codePoint <= 0xF8FF) ||
|
|||
|
(0xFE00 <= codePoint && codePoint <= 0xFE0F) ||
|
|||
|
(0xFFFD == codePoint) ||
|
|||
|
(0x1F100 <= codePoint && codePoint <= 0x1F10A) ||
|
|||
|
(0x1F110 <= codePoint && codePoint <= 0x1F12D) ||
|
|||
|
(0x1F130 <= codePoint && codePoint <= 0x1F169) ||
|
|||
|
(0x1F170 <= codePoint && codePoint <= 0x1F19A) ||
|
|||
|
(0xE0100 <= codePoint && codePoint <= 0xE01EF) ||
|
|||
|
(0xF0000 <= codePoint && codePoint <= 0xFFFFD) ||
|
|||
|
(0x100000 <= codePoint && codePoint <= 0x10FFFD)) {
|
|||
|
return 'A';
|
|||
|
}
|
|||
|
|
|||
|
return 'N';
|
|||
|
};
|
|||
|
|
|||
|
eaw.characterLength = function(character) {
|
|||
|
var code = this.eastAsianWidth(character);
|
|||
|
if (code == 'F' || code == 'W' || code == 'A') {
|
|||
|
return 2;
|
|||
|
} else {
|
|||
|
return 1;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
eaw.length = function(string) {
|
|||
|
var len = 0;
|
|||
|
for (var i = 0; i < string.length; i++) {
|
|||
|
len = len + this.characterLength(string.charAt(i));
|
|||
|
}
|
|||
|
return len;
|
|||
|
};
|
|||
|
|
|||
|
eaw.slice = function(text, start, end) {
|
|||
|
start = start ? start : 0;
|
|||
|
end = end ? end : 1;
|
|||
|
var result = '';
|
|||
|
for (var i = 0; i < text.length; i++) {
|
|||
|
var char = text.charAt(i);
|
|||
|
var eawLen = eaw.length(result + char);
|
|||
|
if (eawLen >= 1 + start && eawLen < 1 + end) {
|
|||
|
result += char
|
|||
|
}
|
|||
|
}
|
|||
|
return result;
|
|||
|
};
|
|||
|
|
|||
|
},{}],68:[function(_dereq_,module,exports){
|
|||
|
/**
|
|||
|
* espurify - Clone new AST without extra properties
|
|||
|
*
|
|||
|
* https://github.com/estools/espurify
|
|||
|
*
|
|||
|
* Copyright (c) 2014-2016 Takuto Wada
|
|||
|
* Licensed under the MIT license.
|
|||
|
* https://github.com/estools/espurify/blob/master/MIT-LICENSE.txt
|
|||
|
*/
|
|||
|
'use strict';
|
|||
|
|
|||
|
var createWhitelist = _dereq_('./lib/create-whitelist');
|
|||
|
var cloneWithWhitelist = _dereq_('./lib/clone-ast');
|
|||
|
|
|||
|
function createCloneFunction (options) {
|
|||
|
return cloneWithWhitelist(createWhitelist(options));
|
|||
|
}
|
|||
|
|
|||
|
var espurify = createCloneFunction();
|
|||
|
espurify.customize = createCloneFunction;
|
|||
|
espurify.cloneWithWhitelist = cloneWithWhitelist;
|
|||
|
module.exports = espurify;
|
|||
|
|
|||
|
},{"./lib/clone-ast":70,"./lib/create-whitelist":71}],69:[function(_dereq_,module,exports){
|
|||
|
module.exports = {
|
|||
|
ArrayExpression: ['type', 'elements'],
|
|||
|
ArrayPattern: ['type', 'elements'],
|
|||
|
ArrowFunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'expression'],
|
|||
|
AssignmentExpression: ['type', 'operator', 'left', 'right'],
|
|||
|
AssignmentPattern: ['type', 'left', 'right'],
|
|||
|
BinaryExpression: ['type', 'operator', 'left', 'right'],
|
|||
|
BlockStatement: ['type', 'body'],
|
|||
|
BreakStatement: ['type', 'label'],
|
|||
|
CallExpression: ['type', 'callee', 'arguments'],
|
|||
|
CatchClause: ['type', 'param', 'guard', 'body'],
|
|||
|
ClassBody: ['type', 'body'],
|
|||
|
ClassDeclaration: ['type', 'id', 'superClass', 'body'],
|
|||
|
ClassExpression: ['type', 'id', 'superClass', 'body'],
|
|||
|
ConditionalExpression: ['type', 'test', 'alternate', 'consequent'],
|
|||
|
ContinueStatement: ['type', 'label'],
|
|||
|
DebuggerStatement: ['type'],
|
|||
|
DoWhileStatement: ['type', 'body', 'test'],
|
|||
|
EmptyStatement: ['type'],
|
|||
|
ExportAllDeclaration: ['type', 'source'],
|
|||
|
ExportDefaultDeclaration: ['type', 'declaration'],
|
|||
|
ExportNamedDeclaration: ['type', 'declaration', 'specifiers', 'source'],
|
|||
|
ExportSpecifier: ['type', 'exported', 'local'],
|
|||
|
ExpressionStatement: ['type', 'expression'],
|
|||
|
ForInStatement: ['type', 'left', 'right', 'body'],
|
|||
|
ForOfStatement: ['type', 'left', 'right', 'body'],
|
|||
|
ForStatement: ['type', 'init', 'test', 'update', 'body'],
|
|||
|
FunctionDeclaration: ['type', 'id', 'params', 'body', 'generator'],
|
|||
|
FunctionExpression: ['type', 'id', 'params', 'body', 'generator'],
|
|||
|
Identifier: ['type', 'name'],
|
|||
|
IfStatement: ['type', 'test', 'consequent', 'alternate'],
|
|||
|
ImportDeclaration: ['type', 'specifiers', 'source'],
|
|||
|
ImportDefaultSpecifier: ['type', 'local'],
|
|||
|
ImportNamespaceSpecifier: ['type', 'local'],
|
|||
|
ImportSpecifier: ['type', 'imported', 'local'],
|
|||
|
LabeledStatement: ['type', 'label', 'body'],
|
|||
|
Literal: ['type', 'value', 'regex'],
|
|||
|
LogicalExpression: ['type', 'operator', 'left', 'right'],
|
|||
|
MemberExpression: ['type', 'object', 'property', 'computed'],
|
|||
|
MetaProperty: ['type', 'meta', 'property'],
|
|||
|
MethodDefinition: ['type', 'key', 'value', 'kind', 'computed', 'static'],
|
|||
|
NewExpression: ['type', 'callee', 'arguments'],
|
|||
|
ObjectExpression: ['type', 'properties'],
|
|||
|
ObjectPattern: ['type', 'properties'],
|
|||
|
Program: ['type', 'body', 'sourceType'],
|
|||
|
Property: ['type', 'key', 'value', 'kind', 'method', 'shorthand', 'computed'],
|
|||
|
RestElement: ['type', 'argument'],
|
|||
|
ReturnStatement: ['type', 'argument'],
|
|||
|
SequenceExpression: ['type', 'expressions'],
|
|||
|
SpreadElement: ['type', 'argument'],
|
|||
|
Super: ['type'],
|
|||
|
SwitchCase: ['type', 'test', 'consequent'],
|
|||
|
SwitchStatement: ['type', 'discriminant', 'cases', 'lexical'],
|
|||
|
TaggedTemplateExpression: ['type', 'tag', 'quasi'],
|
|||
|
TemplateElement: ['type', 'tail', 'value'],
|
|||
|
TemplateLiteral: ['type', 'quasis', 'expressions'],
|
|||
|
ThisExpression: ['type'],
|
|||
|
ThrowStatement: ['type', 'argument'],
|
|||
|
TryStatement: ['type', 'block', 'handler', 'finalizer'],
|
|||
|
UnaryExpression: ['type', 'operator', 'prefix', 'argument'],
|
|||
|
UpdateExpression: ['type', 'operator', 'argument', 'prefix'],
|
|||
|
VariableDeclaration: ['type', 'declarations', 'kind'],
|
|||
|
VariableDeclarator: ['type', 'id', 'init'],
|
|||
|
WhileStatement: ['type', 'test', 'body'],
|
|||
|
WithStatement: ['type', 'object', 'body'],
|
|||
|
YieldExpression: ['type', 'argument', 'delegate']
|
|||
|
};
|
|||
|
|
|||
|
},{}],70:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var isArray = _dereq_('core-js/library/fn/array/is-array');
|
|||
|
var objectKeys = _dereq_('core-js/library/fn/object/keys');
|
|||
|
var indexOf = _dereq_('core-js/library/fn/array/index-of');
|
|||
|
var reduce = _dereq_('core-js/library/fn/array/reduce');
|
|||
|
|
|||
|
module.exports = function cloneWithWhitelist (astWhiteList) {
|
|||
|
var whitelist = reduce(objectKeys(astWhiteList), function (props, key) {
|
|||
|
var propNames = astWhiteList[key];
|
|||
|
var prepend = (indexOf(propNames, 'type') === -1) ? ['type'] : [];
|
|||
|
props[key] = prepend.concat(propNames);
|
|||
|
return props;
|
|||
|
}, {});
|
|||
|
|
|||
|
function cloneNodeOrObject (obj) {
|
|||
|
var props = obj.type ? whitelist[obj.type] : null;
|
|||
|
if (props) {
|
|||
|
return cloneNode(obj, props);
|
|||
|
} else {
|
|||
|
return cloneObject(obj);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function cloneArray (ary) {
|
|||
|
var i = ary.length, clone = [];
|
|||
|
while (i--) {
|
|||
|
clone[i] = cloneOf(ary[i]);
|
|||
|
}
|
|||
|
return clone;
|
|||
|
}
|
|||
|
|
|||
|
function cloneNode (node, props) {
|
|||
|
var i, len, key, clone = {};
|
|||
|
for (i = 0, len = props.length; i < len; i += 1) {
|
|||
|
key = props[i];
|
|||
|
if (node.hasOwnProperty(key)) {
|
|||
|
clone[key] = cloneOf(node[key]);
|
|||
|
}
|
|||
|
}
|
|||
|
return clone;
|
|||
|
}
|
|||
|
|
|||
|
function cloneObject (obj) {
|
|||
|
var props = objectKeys(obj);
|
|||
|
var i, len, key, clone = {};
|
|||
|
for (i = 0, len = props.length; i < len; i += 1) {
|
|||
|
key = props[i];
|
|||
|
clone[key] = cloneOf(obj[key]);
|
|||
|
}
|
|||
|
return clone;
|
|||
|
}
|
|||
|
|
|||
|
function cloneOf (val) {
|
|||
|
if (typeof val === 'object' && val !== null) {
|
|||
|
if (val instanceof RegExp) {
|
|||
|
return new RegExp(val);
|
|||
|
} else if (isArray(val)) {
|
|||
|
return cloneArray(val);
|
|||
|
} else {
|
|||
|
return cloneNodeOrObject(val);
|
|||
|
}
|
|||
|
} else {
|
|||
|
return val;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return cloneNodeOrObject;
|
|||
|
};
|
|||
|
|
|||
|
},{"core-js/library/fn/array/index-of":8,"core-js/library/fn/array/is-array":9,"core-js/library/fn/array/reduce":12,"core-js/library/fn/object/keys":14}],71:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var defaultProps = _dereq_('./ast-properties');
|
|||
|
var objectKeys = _dereq_('core-js/library/fn/object/keys');
|
|||
|
var assign = _dereq_('core-js/library/fn/object/assign');
|
|||
|
|
|||
|
module.exports = function createWhitelist (options) {
|
|||
|
var opts = assign({}, options);
|
|||
|
var typeName, i, len;
|
|||
|
var keys = objectKeys(defaultProps);
|
|||
|
var result = {};
|
|||
|
for (i = 0, len = keys.length; i < len; i += 1) {
|
|||
|
typeName = keys[i];
|
|||
|
result[typeName] = defaultProps[typeName].concat(opts.extra);
|
|||
|
}
|
|||
|
return result;
|
|||
|
};
|
|||
|
|
|||
|
},{"./ast-properties":69,"core-js/library/fn/object/assign":13,"core-js/library/fn/object/keys":14}],72:[function(_dereq_,module,exports){
|
|||
|
/*
|
|||
|
Copyright (C) 2012-2013 Yusuke Suzuki <utatane.tea@gmail.com>
|
|||
|
Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
|
|||
|
|
|||
|
Redistribution and use in source and binary forms, with or without
|
|||
|
modification, are permitted provided that the following conditions are met:
|
|||
|
|
|||
|
* Redistributions of source code must retain the above copyright
|
|||
|
notice, this list of conditions and the following disclaimer.
|
|||
|
* Redistributions in binary form must reproduce the above copyright
|
|||
|
notice, this list of conditions and the following disclaimer in the
|
|||
|
documentation and/or other materials provided with the distribution.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|||
|
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|||
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
*/
|
|||
|
/*jslint vars:false, bitwise:true*/
|
|||
|
/*jshint indent:4*/
|
|||
|
/*global exports:true*/
|
|||
|
(function clone(exports) {
|
|||
|
'use strict';
|
|||
|
|
|||
|
var Syntax,
|
|||
|
isArray,
|
|||
|
VisitorOption,
|
|||
|
VisitorKeys,
|
|||
|
objectCreate,
|
|||
|
objectKeys,
|
|||
|
BREAK,
|
|||
|
SKIP,
|
|||
|
REMOVE;
|
|||
|
|
|||
|
function ignoreJSHintError() { }
|
|||
|
|
|||
|
isArray = Array.isArray;
|
|||
|
if (!isArray) {
|
|||
|
isArray = function isArray(array) {
|
|||
|
return Object.prototype.toString.call(array) === '[object Array]';
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function deepCopy(obj) {
|
|||
|
var ret = {}, key, val;
|
|||
|
for (key in obj) {
|
|||
|
if (obj.hasOwnProperty(key)) {
|
|||
|
val = obj[key];
|
|||
|
if (typeof val === 'object' && val !== null) {
|
|||
|
ret[key] = deepCopy(val);
|
|||
|
} else {
|
|||
|
ret[key] = val;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
function shallowCopy(obj) {
|
|||
|
var ret = {}, key;
|
|||
|
for (key in obj) {
|
|||
|
if (obj.hasOwnProperty(key)) {
|
|||
|
ret[key] = obj[key];
|
|||
|
}
|
|||
|
}
|
|||
|
return ret;
|
|||
|
}
|
|||
|
ignoreJSHintError(shallowCopy);
|
|||
|
|
|||
|
// based on LLVM libc++ upper_bound / lower_bound
|
|||
|
// MIT License
|
|||
|
|
|||
|
function upperBound(array, func) {
|
|||
|
var diff, len, i, current;
|
|||
|
|
|||
|
len = array.length;
|
|||
|
i = 0;
|
|||
|
|
|||
|
while (len) {
|
|||
|
diff = len >>> 1;
|
|||
|
current = i + diff;
|
|||
|
if (func(array[current])) {
|
|||
|
len = diff;
|
|||
|
} else {
|
|||
|
i = current + 1;
|
|||
|
len -= diff + 1;
|
|||
|
}
|
|||
|
}
|
|||
|
return i;
|
|||
|
}
|
|||
|
|
|||
|
function lowerBound(array, func) {
|
|||
|
var diff, len, i, current;
|
|||
|
|
|||
|
len = array.length;
|
|||
|
i = 0;
|
|||
|
|
|||
|
while (len) {
|
|||
|
diff = len >>> 1;
|
|||
|
current = i + diff;
|
|||
|
if (func(array[current])) {
|
|||
|
i = current + 1;
|
|||
|
len -= diff + 1;
|
|||
|
} else {
|
|||
|
len = diff;
|
|||
|
}
|
|||
|
}
|
|||
|
return i;
|
|||
|
}
|
|||
|
ignoreJSHintError(lowerBound);
|
|||
|
|
|||
|
objectCreate = Object.create || (function () {
|
|||
|
function F() { }
|
|||
|
|
|||
|
return function (o) {
|
|||
|
F.prototype = o;
|
|||
|
return new F();
|
|||
|
};
|
|||
|
})();
|
|||
|
|
|||
|
objectKeys = Object.keys || function (o) {
|
|||
|
var keys = [], key;
|
|||
|
for (key in o) {
|
|||
|
keys.push(key);
|
|||
|
}
|
|||
|
return keys;
|
|||
|
};
|
|||
|
|
|||
|
function extend(to, from) {
|
|||
|
var keys = objectKeys(from), key, i, len;
|
|||
|
for (i = 0, len = keys.length; i < len; i += 1) {
|
|||
|
key = keys[i];
|
|||
|
to[key] = from[key];
|
|||
|
}
|
|||
|
return to;
|
|||
|
}
|
|||
|
|
|||
|
Syntax = {
|
|||
|
AssignmentExpression: 'AssignmentExpression',
|
|||
|
AssignmentPattern: 'AssignmentPattern',
|
|||
|
ArrayExpression: 'ArrayExpression',
|
|||
|
ArrayPattern: 'ArrayPattern',
|
|||
|
ArrowFunctionExpression: 'ArrowFunctionExpression',
|
|||
|
AwaitExpression: 'AwaitExpression', // CAUTION: It's deferred to ES7.
|
|||
|
BlockStatement: 'BlockStatement',
|
|||
|
BinaryExpression: 'BinaryExpression',
|
|||
|
BreakStatement: 'BreakStatement',
|
|||
|
CallExpression: 'CallExpression',
|
|||
|
CatchClause: 'CatchClause',
|
|||
|
ClassBody: 'ClassBody',
|
|||
|
ClassDeclaration: 'ClassDeclaration',
|
|||
|
ClassExpression: 'ClassExpression',
|
|||
|
ComprehensionBlock: 'ComprehensionBlock', // CAUTION: It's deferred to ES7.
|
|||
|
ComprehensionExpression: 'ComprehensionExpression', // CAUTION: It's deferred to ES7.
|
|||
|
ConditionalExpression: 'ConditionalExpression',
|
|||
|
ContinueStatement: 'ContinueStatement',
|
|||
|
DebuggerStatement: 'DebuggerStatement',
|
|||
|
DirectiveStatement: 'DirectiveStatement',
|
|||
|
DoWhileStatement: 'DoWhileStatement',
|
|||
|
EmptyStatement: 'EmptyStatement',
|
|||
|
ExportAllDeclaration: 'ExportAllDeclaration',
|
|||
|
ExportDefaultDeclaration: 'ExportDefaultDeclaration',
|
|||
|
ExportNamedDeclaration: 'ExportNamedDeclaration',
|
|||
|
ExportSpecifier: 'ExportSpecifier',
|
|||
|
ExpressionStatement: 'ExpressionStatement',
|
|||
|
ForStatement: 'ForStatement',
|
|||
|
ForInStatement: 'ForInStatement',
|
|||
|
ForOfStatement: 'ForOfStatement',
|
|||
|
FunctionDeclaration: 'FunctionDeclaration',
|
|||
|
FunctionExpression: 'FunctionExpression',
|
|||
|
GeneratorExpression: 'GeneratorExpression', // CAUTION: It's deferred to ES7.
|
|||
|
Identifier: 'Identifier',
|
|||
|
IfStatement: 'IfStatement',
|
|||
|
ImportDeclaration: 'ImportDeclaration',
|
|||
|
ImportDefaultSpecifier: 'ImportDefaultSpecifier',
|
|||
|
ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
|
|||
|
ImportSpecifier: 'ImportSpecifier',
|
|||
|
Literal: 'Literal',
|
|||
|
LabeledStatement: 'LabeledStatement',
|
|||
|
LogicalExpression: 'LogicalExpression',
|
|||
|
MemberExpression: 'MemberExpression',
|
|||
|
MetaProperty: 'MetaProperty',
|
|||
|
MethodDefinition: 'MethodDefinition',
|
|||
|
ModuleSpecifier: 'ModuleSpecifier',
|
|||
|
NewExpression: 'NewExpression',
|
|||
|
ObjectExpression: 'ObjectExpression',
|
|||
|
ObjectPattern: 'ObjectPattern',
|
|||
|
Program: 'Program',
|
|||
|
Property: 'Property',
|
|||
|
RestElement: 'RestElement',
|
|||
|
ReturnStatement: 'ReturnStatement',
|
|||
|
SequenceExpression: 'SequenceExpression',
|
|||
|
SpreadElement: 'SpreadElement',
|
|||
|
Super: 'Super',
|
|||
|
SwitchStatement: 'SwitchStatement',
|
|||
|
SwitchCase: 'SwitchCase',
|
|||
|
TaggedTemplateExpression: 'TaggedTemplateExpression',
|
|||
|
TemplateElement: 'TemplateElement',
|
|||
|
TemplateLiteral: 'TemplateLiteral',
|
|||
|
ThisExpression: 'ThisExpression',
|
|||
|
ThrowStatement: 'ThrowStatement',
|
|||
|
TryStatement: 'TryStatement',
|
|||
|
UnaryExpression: 'UnaryExpression',
|
|||
|
UpdateExpression: 'UpdateExpression',
|
|||
|
VariableDeclaration: 'VariableDeclaration',
|
|||
|
VariableDeclarator: 'VariableDeclarator',
|
|||
|
WhileStatement: 'WhileStatement',
|
|||
|
WithStatement: 'WithStatement',
|
|||
|
YieldExpression: 'YieldExpression'
|
|||
|
};
|
|||
|
|
|||
|
VisitorKeys = {
|
|||
|
AssignmentExpression: ['left', 'right'],
|
|||
|
AssignmentPattern: ['left', 'right'],
|
|||
|
ArrayExpression: ['elements'],
|
|||
|
ArrayPattern: ['elements'],
|
|||
|
ArrowFunctionExpression: ['params', 'body'],
|
|||
|
AwaitExpression: ['argument'], // CAUTION: It's deferred to ES7.
|
|||
|
BlockStatement: ['body'],
|
|||
|
BinaryExpression: ['left', 'right'],
|
|||
|
BreakStatement: ['label'],
|
|||
|
CallExpression: ['callee', 'arguments'],
|
|||
|
CatchClause: ['param', 'body'],
|
|||
|
ClassBody: ['body'],
|
|||
|
ClassDeclaration: ['id', 'superClass', 'body'],
|
|||
|
ClassExpression: ['id', 'superClass', 'body'],
|
|||
|
ComprehensionBlock: ['left', 'right'], // CAUTION: It's deferred to ES7.
|
|||
|
ComprehensionExpression: ['blocks', 'filter', 'body'], // CAUTION: It's deferred to ES7.
|
|||
|
ConditionalExpression: ['test', 'consequent', 'alternate'],
|
|||
|
ContinueStatement: ['label'],
|
|||
|
DebuggerStatement: [],
|
|||
|
DirectiveStatement: [],
|
|||
|
DoWhileStatement: ['body', 'test'],
|
|||
|
EmptyStatement: [],
|
|||
|
ExportAllDeclaration: ['source'],
|
|||
|
ExportDefaultDeclaration: ['declaration'],
|
|||
|
ExportNamedDeclaration: ['declaration', 'specifiers', 'source'],
|
|||
|
ExportSpecifier: ['exported', 'local'],
|
|||
|
ExpressionStatement: ['expression'],
|
|||
|
ForStatement: ['init', 'test', 'update', 'body'],
|
|||
|
ForInStatement: ['left', 'right', 'body'],
|
|||
|
ForOfStatement: ['left', 'right', 'body'],
|
|||
|
FunctionDeclaration: ['id', 'params', 'body'],
|
|||
|
FunctionExpression: ['id', 'params', 'body'],
|
|||
|
GeneratorExpression: ['blocks', 'filter', 'body'], // CAUTION: It's deferred to ES7.
|
|||
|
Identifier: [],
|
|||
|
IfStatement: ['test', 'consequent', 'alternate'],
|
|||
|
ImportDeclaration: ['specifiers', 'source'],
|
|||
|
ImportDefaultSpecifier: ['local'],
|
|||
|
ImportNamespaceSpecifier: ['local'],
|
|||
|
ImportSpecifier: ['imported', 'local'],
|
|||
|
Literal: [],
|
|||
|
LabeledStatement: ['label', 'body'],
|
|||
|
LogicalExpression: ['left', 'right'],
|
|||
|
MemberExpression: ['object', 'property'],
|
|||
|
MetaProperty: ['meta', 'property'],
|
|||
|
MethodDefinition: ['key', 'value'],
|
|||
|
ModuleSpecifier: [],
|
|||
|
NewExpression: ['callee', 'arguments'],
|
|||
|
ObjectExpression: ['properties'],
|
|||
|
ObjectPattern: ['properties'],
|
|||
|
Program: ['body'],
|
|||
|
Property: ['key', 'value'],
|
|||
|
RestElement: [ 'argument' ],
|
|||
|
ReturnStatement: ['argument'],
|
|||
|
SequenceExpression: ['expressions'],
|
|||
|
SpreadElement: ['argument'],
|
|||
|
Super: [],
|
|||
|
SwitchStatement: ['discriminant', 'cases'],
|
|||
|
SwitchCase: ['test', 'consequent'],
|
|||
|
TaggedTemplateExpression: ['tag', 'quasi'],
|
|||
|
TemplateElement: [],
|
|||
|
TemplateLiteral: ['quasis', 'expressions'],
|
|||
|
ThisExpression: [],
|
|||
|
ThrowStatement: ['argument'],
|
|||
|
TryStatement: ['block', 'handler', 'finalizer'],
|
|||
|
UnaryExpression: ['argument'],
|
|||
|
UpdateExpression: ['argument'],
|
|||
|
VariableDeclaration: ['declarations'],
|
|||
|
VariableDeclarator: ['id', 'init'],
|
|||
|
WhileStatement: ['test', 'body'],
|
|||
|
WithStatement: ['object', 'body'],
|
|||
|
YieldExpression: ['argument']
|
|||
|
};
|
|||
|
|
|||
|
// unique id
|
|||
|
BREAK = {};
|
|||
|
SKIP = {};
|
|||
|
REMOVE = {};
|
|||
|
|
|||
|
VisitorOption = {
|
|||
|
Break: BREAK,
|
|||
|
Skip: SKIP,
|
|||
|
Remove: REMOVE
|
|||
|
};
|
|||
|
|
|||
|
function Reference(parent, key) {
|
|||
|
this.parent = parent;
|
|||
|
this.key = key;
|
|||
|
}
|
|||
|
|
|||
|
Reference.prototype.replace = function replace(node) {
|
|||
|
this.parent[this.key] = node;
|
|||
|
};
|
|||
|
|
|||
|
Reference.prototype.remove = function remove() {
|
|||
|
if (isArray(this.parent)) {
|
|||
|
this.parent.splice(this.key, 1);
|
|||
|
return true;
|
|||
|
} else {
|
|||
|
this.replace(null);
|
|||
|
return false;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
function Element(node, path, wrap, ref) {
|
|||
|
this.node = node;
|
|||
|
this.path = path;
|
|||
|
this.wrap = wrap;
|
|||
|
this.ref = ref;
|
|||
|
}
|
|||
|
|
|||
|
function Controller() { }
|
|||
|
|
|||
|
// API:
|
|||
|
// return property path array from root to current node
|
|||
|
Controller.prototype.path = function path() {
|
|||
|
var i, iz, j, jz, result, element;
|
|||
|
|
|||
|
function addToPath(result, path) {
|
|||
|
if (isArray(path)) {
|
|||
|
for (j = 0, jz = path.length; j < jz; ++j) {
|
|||
|
result.push(path[j]);
|
|||
|
}
|
|||
|
} else {
|
|||
|
result.push(path);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// root node
|
|||
|
if (!this.__current.path) {
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// first node is sentinel, second node is root element
|
|||
|
result = [];
|
|||
|
for (i = 2, iz = this.__leavelist.length; i < iz; ++i) {
|
|||
|
element = this.__leavelist[i];
|
|||
|
addToPath(result, element.path);
|
|||
|
}
|
|||
|
addToPath(result, this.__current.path);
|
|||
|
return result;
|
|||
|
};
|
|||
|
|
|||
|
// API:
|
|||
|
// return type of current node
|
|||
|
Controller.prototype.type = function () {
|
|||
|
var node = this.current();
|
|||
|
return node.type || this.__current.wrap;
|
|||
|
};
|
|||
|
|
|||
|
// API:
|
|||
|
// return array of parent elements
|
|||
|
Controller.prototype.parents = function parents() {
|
|||
|
var i, iz, result;
|
|||
|
|
|||
|
// first node is sentinel
|
|||
|
result = [];
|
|||
|
for (i = 1, iz = this.__leavelist.length; i < iz; ++i) {
|
|||
|
result.push(this.__leavelist[i].node);
|
|||
|
}
|
|||
|
|
|||
|
return result;
|
|||
|
};
|
|||
|
|
|||
|
// API:
|
|||
|
// return current node
|
|||
|
Controller.prototype.current = function current() {
|
|||
|
return this.__current.node;
|
|||
|
};
|
|||
|
|
|||
|
Controller.prototype.__execute = function __execute(callback, element) {
|
|||
|
var previous, result;
|
|||
|
|
|||
|
result = undefined;
|
|||
|
|
|||
|
previous = this.__current;
|
|||
|
this.__current = element;
|
|||
|
this.__state = null;
|
|||
|
if (callback) {
|
|||
|
result = callback.call(this, element.node, this.__leavelist[this.__leavelist.length - 1].node);
|
|||
|
}
|
|||
|
this.__current = previous;
|
|||
|
|
|||
|
return result;
|
|||
|
};
|
|||
|
|
|||
|
// API:
|
|||
|
// notify control skip / break
|
|||
|
Controller.prototype.notify = function notify(flag) {
|
|||
|
this.__state = flag;
|
|||
|
};
|
|||
|
|
|||
|
// API:
|
|||
|
// skip child nodes of current node
|
|||
|
Controller.prototype.skip = function () {
|
|||
|
this.notify(SKIP);
|
|||
|
};
|
|||
|
|
|||
|
// API:
|
|||
|
// break traversals
|
|||
|
Controller.prototype['break'] = function () {
|
|||
|
this.notify(BREAK);
|
|||
|
};
|
|||
|
|
|||
|
// API:
|
|||
|
// remove node
|
|||
|
Controller.prototype.remove = function () {
|
|||
|
this.notify(REMOVE);
|
|||
|
};
|
|||
|
|
|||
|
Controller.prototype.__initialize = function(root, visitor) {
|
|||
|
this.visitor = visitor;
|
|||
|
this.root = root;
|
|||
|
this.__worklist = [];
|
|||
|
this.__leavelist = [];
|
|||
|
this.__current = null;
|
|||
|
this.__state = null;
|
|||
|
this.__fallback = null;
|
|||
|
if (visitor.fallback === 'iteration') {
|
|||
|
this.__fallback = objectKeys;
|
|||
|
} else if (typeof visitor.fallback === 'function') {
|
|||
|
this.__fallback = visitor.fallback;
|
|||
|
}
|
|||
|
|
|||
|
this.__keys = VisitorKeys;
|
|||
|
if (visitor.keys) {
|
|||
|
this.__keys = extend(objectCreate(this.__keys), visitor.keys);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
function isNode(node) {
|
|||
|
if (node == null) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
return typeof node === 'object' && typeof node.type === 'string';
|
|||
|
}
|
|||
|
|
|||
|
function isProperty(nodeType, key) {
|
|||
|
return (nodeType === Syntax.ObjectExpression || nodeType === Syntax.ObjectPattern) && 'properties' === key;
|
|||
|
}
|
|||
|
|
|||
|
Controller.prototype.traverse = function traverse(root, visitor) {
|
|||
|
var worklist,
|
|||
|
leavelist,
|
|||
|
element,
|
|||
|
node,
|
|||
|
nodeType,
|
|||
|
ret,
|
|||
|
key,
|
|||
|
current,
|
|||
|
current2,
|
|||
|
candidates,
|
|||
|
candidate,
|
|||
|
sentinel;
|
|||
|
|
|||
|
this.__initialize(root, visitor);
|
|||
|
|
|||
|
sentinel = {};
|
|||
|
|
|||
|
// reference
|
|||
|
worklist = this.__worklist;
|
|||
|
leavelist = this.__leavelist;
|
|||
|
|
|||
|
// initialize
|
|||
|
worklist.push(new Element(root, null, null, null));
|
|||
|
leavelist.push(new Element(null, null, null, null));
|
|||
|
|
|||
|
while (worklist.length) {
|
|||
|
element = worklist.pop();
|
|||
|
|
|||
|
if (element === sentinel) {
|
|||
|
element = leavelist.pop();
|
|||
|
|
|||
|
ret = this.__execute(visitor.leave, element);
|
|||
|
|
|||
|
if (this.__state === BREAK || ret === BREAK) {
|
|||
|
return;
|
|||
|
}
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
if (element.node) {
|
|||
|
|
|||
|
ret = this.__execute(visitor.enter, element);
|
|||
|
|
|||
|
if (this.__state === BREAK || ret === BREAK) {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
worklist.push(sentinel);
|
|||
|
leavelist.push(element);
|
|||
|
|
|||
|
if (this.__state === SKIP || ret === SKIP) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
node = element.node;
|
|||
|
nodeType = node.type || element.wrap;
|
|||
|
candidates = this.__keys[nodeType];
|
|||
|
if (!candidates) {
|
|||
|
if (this.__fallback) {
|
|||
|
candidates = this.__fallback(node);
|
|||
|
} else {
|
|||
|
throw new Error('Unknown node type ' + nodeType + '.');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
current = candidates.length;
|
|||
|
while ((current -= 1) >= 0) {
|
|||
|
key = candidates[current];
|
|||
|
candidate = node[key];
|
|||
|
if (!candidate) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
if (isArray(candidate)) {
|
|||
|
current2 = candidate.length;
|
|||
|
while ((current2 -= 1) >= 0) {
|
|||
|
if (!candidate[current2]) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
if (isProperty(nodeType, candidates[current])) {
|
|||
|
element = new Element(candidate[current2], [key, current2], 'Property', null);
|
|||
|
} else if (isNode(candidate[current2])) {
|
|||
|
element = new Element(candidate[current2], [key, current2], null, null);
|
|||
|
} else {
|
|||
|
continue;
|
|||
|
}
|
|||
|
worklist.push(element);
|
|||
|
}
|
|||
|
} else if (isNode(candidate)) {
|
|||
|
worklist.push(new Element(candidate, key, null, null));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
Controller.prototype.replace = function replace(root, visitor) {
|
|||
|
var worklist,
|
|||
|
leavelist,
|
|||
|
node,
|
|||
|
nodeType,
|
|||
|
target,
|
|||
|
element,
|
|||
|
current,
|
|||
|
current2,
|
|||
|
candidates,
|
|||
|
candidate,
|
|||
|
sentinel,
|
|||
|
outer,
|
|||
|
key;
|
|||
|
|
|||
|
function removeElem(element) {
|
|||
|
var i,
|
|||
|
key,
|
|||
|
nextElem,
|
|||
|
parent;
|
|||
|
|
|||
|
if (element.ref.remove()) {
|
|||
|
// When the reference is an element of an array.
|
|||
|
key = element.ref.key;
|
|||
|
parent = element.ref.parent;
|
|||
|
|
|||
|
// If removed from array, then decrease following items' keys.
|
|||
|
i = worklist.length;
|
|||
|
while (i--) {
|
|||
|
nextElem = worklist[i];
|
|||
|
if (nextElem.ref && nextElem.ref.parent === parent) {
|
|||
|
if (nextElem.ref.key < key) {
|
|||
|
break;
|
|||
|
}
|
|||
|
--nextElem.ref.key;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
this.__initialize(root, visitor);
|
|||
|
|
|||
|
sentinel = {};
|
|||
|
|
|||
|
// reference
|
|||
|
worklist = this.__worklist;
|
|||
|
leavelist = this.__leavelist;
|
|||
|
|
|||
|
// initialize
|
|||
|
outer = {
|
|||
|
root: root
|
|||
|
};
|
|||
|
element = new Element(root, null, null, new Reference(outer, 'root'));
|
|||
|
worklist.push(element);
|
|||
|
leavelist.push(element);
|
|||
|
|
|||
|
while (worklist.length) {
|
|||
|
element = worklist.pop();
|
|||
|
|
|||
|
if (element === sentinel) {
|
|||
|
element = leavelist.pop();
|
|||
|
|
|||
|
target = this.__execute(visitor.leave, element);
|
|||
|
|
|||
|
// node may be replaced with null,
|
|||
|
// so distinguish between undefined and null in this place
|
|||
|
if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
|
|||
|
// replace
|
|||
|
element.ref.replace(target);
|
|||
|
}
|
|||
|
|
|||
|
if (this.__state === REMOVE || target === REMOVE) {
|
|||
|
removeElem(element);
|
|||
|
}
|
|||
|
|
|||
|
if (this.__state === BREAK || target === BREAK) {
|
|||
|
return outer.root;
|
|||
|
}
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
target = this.__execute(visitor.enter, element);
|
|||
|
|
|||
|
// node may be replaced with null,
|
|||
|
// so distinguish between undefined and null in this place
|
|||
|
if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
|
|||
|
// replace
|
|||
|
element.ref.replace(target);
|
|||
|
element.node = target;
|
|||
|
}
|
|||
|
|
|||
|
if (this.__state === REMOVE || target === REMOVE) {
|
|||
|
removeElem(element);
|
|||
|
element.node = null;
|
|||
|
}
|
|||
|
|
|||
|
if (this.__state === BREAK || target === BREAK) {
|
|||
|
return outer.root;
|
|||
|
}
|
|||
|
|
|||
|
// node may be null
|
|||
|
node = element.node;
|
|||
|
if (!node) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
worklist.push(sentinel);
|
|||
|
leavelist.push(element);
|
|||
|
|
|||
|
if (this.__state === SKIP || target === SKIP) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
nodeType = node.type || element.wrap;
|
|||
|
candidates = this.__keys[nodeType];
|
|||
|
if (!candidates) {
|
|||
|
if (this.__fallback) {
|
|||
|
candidates = this.__fallback(node);
|
|||
|
} else {
|
|||
|
throw new Error('Unknown node type ' + nodeType + '.');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
current = candidates.length;
|
|||
|
while ((current -= 1) >= 0) {
|
|||
|
key = candidates[current];
|
|||
|
candidate = node[key];
|
|||
|
if (!candidate) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
if (isArray(candidate)) {
|
|||
|
current2 = candidate.length;
|
|||
|
while ((current2 -= 1) >= 0) {
|
|||
|
if (!candidate[current2]) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
if (isProperty(nodeType, candidates[current])) {
|
|||
|
element = new Element(candidate[current2], [key, current2], 'Property', new Reference(candidate, current2));
|
|||
|
} else if (isNode(candidate[current2])) {
|
|||
|
element = new Element(candidate[current2], [key, current2], null, new Reference(candidate, current2));
|
|||
|
} else {
|
|||
|
continue;
|
|||
|
}
|
|||
|
worklist.push(element);
|
|||
|
}
|
|||
|
} else if (isNode(candidate)) {
|
|||
|
worklist.push(new Element(candidate, key, null, new Reference(node, key)));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return outer.root;
|
|||
|
};
|
|||
|
|
|||
|
function traverse(root, visitor) {
|
|||
|
var controller = new Controller();
|
|||
|
return controller.traverse(root, visitor);
|
|||
|
}
|
|||
|
|
|||
|
function replace(root, visitor) {
|
|||
|
var controller = new Controller();
|
|||
|
return controller.replace(root, visitor);
|
|||
|
}
|
|||
|
|
|||
|
function extendCommentRange(comment, tokens) {
|
|||
|
var target;
|
|||
|
|
|||
|
target = upperBound(tokens, function search(token) {
|
|||
|
return token.range[0] > comment.range[0];
|
|||
|
});
|
|||
|
|
|||
|
comment.extendedRange = [comment.range[0], comment.range[1]];
|
|||
|
|
|||
|
if (target !== tokens.length) {
|
|||
|
comment.extendedRange[1] = tokens[target].range[0];
|
|||
|
}
|
|||
|
|
|||
|
target -= 1;
|
|||
|
if (target >= 0) {
|
|||
|
comment.extendedRange[0] = tokens[target].range[1];
|
|||
|
}
|
|||
|
|
|||
|
return comment;
|
|||
|
}
|
|||
|
|
|||
|
function attachComments(tree, providedComments, tokens) {
|
|||
|
// At first, we should calculate extended comment ranges.
|
|||
|
var comments = [], comment, len, i, cursor;
|
|||
|
|
|||
|
if (!tree.range) {
|
|||
|
throw new Error('attachComments needs range information');
|
|||
|
}
|
|||
|
|
|||
|
// tokens array is empty, we attach comments to tree as 'leadingComments'
|
|||
|
if (!tokens.length) {
|
|||
|
if (providedComments.length) {
|
|||
|
for (i = 0, len = providedComments.length; i < len; i += 1) {
|
|||
|
comment = deepCopy(providedComments[i]);
|
|||
|
comment.extendedRange = [0, tree.range[0]];
|
|||
|
comments.push(comment);
|
|||
|
}
|
|||
|
tree.leadingComments = comments;
|
|||
|
}
|
|||
|
return tree;
|
|||
|
}
|
|||
|
|
|||
|
for (i = 0, len = providedComments.length; i < len; i += 1) {
|
|||
|
comments.push(extendCommentRange(deepCopy(providedComments[i]), tokens));
|
|||
|
}
|
|||
|
|
|||
|
// This is based on John Freeman's implementation.
|
|||
|
cursor = 0;
|
|||
|
traverse(tree, {
|
|||
|
enter: function (node) {
|
|||
|
var comment;
|
|||
|
|
|||
|
while (cursor < comments.length) {
|
|||
|
comment = comments[cursor];
|
|||
|
if (comment.extendedRange[1] > node.range[0]) {
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if (comment.extendedRange[1] === node.range[0]) {
|
|||
|
if (!node.leadingComments) {
|
|||
|
node.leadingComments = [];
|
|||
|
}
|
|||
|
node.leadingComments.push(comment);
|
|||
|
comments.splice(cursor, 1);
|
|||
|
} else {
|
|||
|
cursor += 1;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// already out of owned node
|
|||
|
if (cursor === comments.length) {
|
|||
|
return VisitorOption.Break;
|
|||
|
}
|
|||
|
|
|||
|
if (comments[cursor].extendedRange[0] > node.range[1]) {
|
|||
|
return VisitorOption.Skip;
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
cursor = 0;
|
|||
|
traverse(tree, {
|
|||
|
leave: function (node) {
|
|||
|
var comment;
|
|||
|
|
|||
|
while (cursor < comments.length) {
|
|||
|
comment = comments[cursor];
|
|||
|
if (node.range[1] < comment.extendedRange[0]) {
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if (node.range[1] === comment.extendedRange[0]) {
|
|||
|
if (!node.trailingComments) {
|
|||
|
node.trailingComments = [];
|
|||
|
}
|
|||
|
node.trailingComments.push(comment);
|
|||
|
comments.splice(cursor, 1);
|
|||
|
} else {
|
|||
|
cursor += 1;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// already out of owned node
|
|||
|
if (cursor === comments.length) {
|
|||
|
return VisitorOption.Break;
|
|||
|
}
|
|||
|
|
|||
|
if (comments[cursor].extendedRange[0] > node.range[1]) {
|
|||
|
return VisitorOption.Skip;
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
return tree;
|
|||
|
}
|
|||
|
|
|||
|
exports.version = _dereq_('./package.json').version;
|
|||
|
exports.Syntax = Syntax;
|
|||
|
exports.traverse = traverse;
|
|||
|
exports.replace = replace;
|
|||
|
exports.attachComments = attachComments;
|
|||
|
exports.VisitorKeys = VisitorKeys;
|
|||
|
exports.VisitorOption = VisitorOption;
|
|||
|
exports.Controller = Controller;
|
|||
|
exports.cloneEnvironment = function () { return clone({}); };
|
|||
|
|
|||
|
return exports;
|
|||
|
}(exports));
|
|||
|
/* vim: set sw=4 ts=4 et tw=80 : */
|
|||
|
|
|||
|
},{"./package.json":73}],73:[function(_dereq_,module,exports){
|
|||
|
module.exports={"version":"4.2.0"}
|
|||
|
},{}],74:[function(_dereq_,module,exports){
|
|||
|
// 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
|
|||
|
// persons to whom the Software is furnished to do so, subject to the
|
|||
|
// following conditions:
|
|||
|
//
|
|||
|
// The above copyright notice and this permission notice shall be included
|
|||
|
// in all copies or substantial portions of the Software.
|
|||
|
//
|
|||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|||
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|||
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|||
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
|
|||
|
function EventEmitter() {
|
|||
|
this._events = this._events || {};
|
|||
|
this._maxListeners = this._maxListeners || undefined;
|
|||
|
}
|
|||
|
module.exports = EventEmitter;
|
|||
|
|
|||
|
// Backwards-compat with node 0.10.x
|
|||
|
EventEmitter.EventEmitter = EventEmitter;
|
|||
|
|
|||
|
EventEmitter.prototype._events = undefined;
|
|||
|
EventEmitter.prototype._maxListeners = undefined;
|
|||
|
|
|||
|
// By default EventEmitters will print a warning if more than 10 listeners are
|
|||
|
// added to it. This is a useful default which helps finding memory leaks.
|
|||
|
EventEmitter.defaultMaxListeners = 10;
|
|||
|
|
|||
|
// Obviously not all Emitters should be limited to 10. This function allows
|
|||
|
// that to be increased. Set to zero for unlimited.
|
|||
|
EventEmitter.prototype.setMaxListeners = function(n) {
|
|||
|
if (!isNumber(n) || n < 0 || isNaN(n))
|
|||
|
throw TypeError('n must be a positive number');
|
|||
|
this._maxListeners = n;
|
|||
|
return this;
|
|||
|
};
|
|||
|
|
|||
|
EventEmitter.prototype.emit = function(type) {
|
|||
|
var er, handler, len, args, i, listeners;
|
|||
|
|
|||
|
if (!this._events)
|
|||
|
this._events = {};
|
|||
|
|
|||
|
// If there is no 'error' event listener then throw.
|
|||
|
if (type === 'error') {
|
|||
|
if (!this._events.error ||
|
|||
|
(isObject(this._events.error) && !this._events.error.length)) {
|
|||
|
er = arguments[1];
|
|||
|
if (er instanceof Error) {
|
|||
|
throw er; // Unhandled 'error' event
|
|||
|
} else {
|
|||
|
// At least give some kind of context to the user
|
|||
|
var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
|
|||
|
err.context = er;
|
|||
|
throw err;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
handler = this._events[type];
|
|||
|
|
|||
|
if (isUndefined(handler))
|
|||
|
return false;
|
|||
|
|
|||
|
if (isFunction(handler)) {
|
|||
|
switch (arguments.length) {
|
|||
|
// fast cases
|
|||
|
case 1:
|
|||
|
handler.call(this);
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
handler.call(this, arguments[1]);
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
handler.call(this, arguments[1], arguments[2]);
|
|||
|
break;
|
|||
|
// slower
|
|||
|
default:
|
|||
|
args = Array.prototype.slice.call(arguments, 1);
|
|||
|
handler.apply(this, args);
|
|||
|
}
|
|||
|
} else if (isObject(handler)) {
|
|||
|
args = Array.prototype.slice.call(arguments, 1);
|
|||
|
listeners = handler.slice();
|
|||
|
len = listeners.length;
|
|||
|
for (i = 0; i < len; i++)
|
|||
|
listeners[i].apply(this, args);
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
};
|
|||
|
|
|||
|
EventEmitter.prototype.addListener = function(type, listener) {
|
|||
|
var m;
|
|||
|
|
|||
|
if (!isFunction(listener))
|
|||
|
throw TypeError('listener must be a function');
|
|||
|
|
|||
|
if (!this._events)
|
|||
|
this._events = {};
|
|||
|
|
|||
|
// To avoid recursion in the case that type === "newListener"! Before
|
|||
|
// adding it to the listeners, first emit "newListener".
|
|||
|
if (this._events.newListener)
|
|||
|
this.emit('newListener', type,
|
|||
|
isFunction(listener.listener) ?
|
|||
|
listener.listener : listener);
|
|||
|
|
|||
|
if (!this._events[type])
|
|||
|
// Optimize the case of one listener. Don't need the extra array object.
|
|||
|
this._events[type] = listener;
|
|||
|
else if (isObject(this._events[type]))
|
|||
|
// If we've already got an array, just append.
|
|||
|
this._events[type].push(listener);
|
|||
|
else
|
|||
|
// Adding the second element, need to change to array.
|
|||
|
this._events[type] = [this._events[type], listener];
|
|||
|
|
|||
|
// Check for listener leak
|
|||
|
if (isObject(this._events[type]) && !this._events[type].warned) {
|
|||
|
if (!isUndefined(this._maxListeners)) {
|
|||
|
m = this._maxListeners;
|
|||
|
} else {
|
|||
|
m = EventEmitter.defaultMaxListeners;
|
|||
|
}
|
|||
|
|
|||
|
if (m && m > 0 && this._events[type].length > m) {
|
|||
|
this._events[type].warned = true;
|
|||
|
console.error('(node) warning: possible EventEmitter memory ' +
|
|||
|
'leak detected. %d listeners added. ' +
|
|||
|
'Use emitter.setMaxListeners() to increase limit.',
|
|||
|
this._events[type].length);
|
|||
|
if (typeof console.trace === 'function') {
|
|||
|
// not supported in IE 10
|
|||
|
console.trace();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return this;
|
|||
|
};
|
|||
|
|
|||
|
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|||
|
|
|||
|
EventEmitter.prototype.once = function(type, listener) {
|
|||
|
if (!isFunction(listener))
|
|||
|
throw TypeError('listener must be a function');
|
|||
|
|
|||
|
var fired = false;
|
|||
|
|
|||
|
function g() {
|
|||
|
this.removeListener(type, g);
|
|||
|
|
|||
|
if (!fired) {
|
|||
|
fired = true;
|
|||
|
listener.apply(this, arguments);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
g.listener = listener;
|
|||
|
this.on(type, g);
|
|||
|
|
|||
|
return this;
|
|||
|
};
|
|||
|
|
|||
|
// emits a 'removeListener' event iff the listener was removed
|
|||
|
EventEmitter.prototype.removeListener = function(type, listener) {
|
|||
|
var list, position, length, i;
|
|||
|
|
|||
|
if (!isFunction(listener))
|
|||
|
throw TypeError('listener must be a function');
|
|||
|
|
|||
|
if (!this._events || !this._events[type])
|
|||
|
return this;
|
|||
|
|
|||
|
list = this._events[type];
|
|||
|
length = list.length;
|
|||
|
position = -1;
|
|||
|
|
|||
|
if (list === listener ||
|
|||
|
(isFunction(list.listener) && list.listener === listener)) {
|
|||
|
delete this._events[type];
|
|||
|
if (this._events.removeListener)
|
|||
|
this.emit('removeListener', type, listener);
|
|||
|
|
|||
|
} else if (isObject(list)) {
|
|||
|
for (i = length; i-- > 0;) {
|
|||
|
if (list[i] === listener ||
|
|||
|
(list[i].listener && list[i].listener === listener)) {
|
|||
|
position = i;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (position < 0)
|
|||
|
return this;
|
|||
|
|
|||
|
if (list.length === 1) {
|
|||
|
list.length = 0;
|
|||
|
delete this._events[type];
|
|||
|
} else {
|
|||
|
list.splice(position, 1);
|
|||
|
}
|
|||
|
|
|||
|
if (this._events.removeListener)
|
|||
|
this.emit('removeListener', type, listener);
|
|||
|
}
|
|||
|
|
|||
|
return this;
|
|||
|
};
|
|||
|
|
|||
|
EventEmitter.prototype.removeAllListeners = function(type) {
|
|||
|
var key, listeners;
|
|||
|
|
|||
|
if (!this._events)
|
|||
|
return this;
|
|||
|
|
|||
|
// not listening for removeListener, no need to emit
|
|||
|
if (!this._events.removeListener) {
|
|||
|
if (arguments.length === 0)
|
|||
|
this._events = {};
|
|||
|
else if (this._events[type])
|
|||
|
delete this._events[type];
|
|||
|
return this;
|
|||
|
}
|
|||
|
|
|||
|
// emit removeListener for all listeners on all events
|
|||
|
if (arguments.length === 0) {
|
|||
|
for (key in this._events) {
|
|||
|
if (key === 'removeListener') continue;
|
|||
|
this.removeAllListeners(key);
|
|||
|
}
|
|||
|
this.removeAllListeners('removeListener');
|
|||
|
this._events = {};
|
|||
|
return this;
|
|||
|
}
|
|||
|
|
|||
|
listeners = this._events[type];
|
|||
|
|
|||
|
if (isFunction(listeners)) {
|
|||
|
this.removeListener(type, listeners);
|
|||
|
} else if (listeners) {
|
|||
|
// LIFO order
|
|||
|
while (listeners.length)
|
|||
|
this.removeListener(type, listeners[listeners.length - 1]);
|
|||
|
}
|
|||
|
delete this._events[type];
|
|||
|
|
|||
|
return this;
|
|||
|
};
|
|||
|
|
|||
|
EventEmitter.prototype.listeners = function(type) {
|
|||
|
var ret;
|
|||
|
if (!this._events || !this._events[type])
|
|||
|
ret = [];
|
|||
|
else if (isFunction(this._events[type]))
|
|||
|
ret = [this._events[type]];
|
|||
|
else
|
|||
|
ret = this._events[type].slice();
|
|||
|
return ret;
|
|||
|
};
|
|||
|
|
|||
|
EventEmitter.prototype.listenerCount = function(type) {
|
|||
|
if (this._events) {
|
|||
|
var evlistener = this._events[type];
|
|||
|
|
|||
|
if (isFunction(evlistener))
|
|||
|
return 1;
|
|||
|
else if (evlistener)
|
|||
|
return evlistener.length;
|
|||
|
}
|
|||
|
return 0;
|
|||
|
};
|
|||
|
|
|||
|
EventEmitter.listenerCount = function(emitter, type) {
|
|||
|
return emitter.listenerCount(type);
|
|||
|
};
|
|||
|
|
|||
|
function isFunction(arg) {
|
|||
|
return typeof arg === 'function';
|
|||
|
}
|
|||
|
|
|||
|
function isNumber(arg) {
|
|||
|
return typeof arg === 'number';
|
|||
|
}
|
|||
|
|
|||
|
function isObject(arg) {
|
|||
|
return typeof arg === 'object' && arg !== null;
|
|||
|
}
|
|||
|
|
|||
|
function isUndefined(arg) {
|
|||
|
return arg === void 0;
|
|||
|
}
|
|||
|
|
|||
|
},{}],75:[function(_dereq_,module,exports){
|
|||
|
if (typeof Object.create === 'function') {
|
|||
|
// implementation from standard node.js 'util' module
|
|||
|
module.exports = function inherits(ctor, superCtor) {
|
|||
|
ctor.super_ = superCtor
|
|||
|
ctor.prototype = Object.create(superCtor.prototype, {
|
|||
|
constructor: {
|
|||
|
value: ctor,
|
|||
|
enumerable: false,
|
|||
|
writable: true,
|
|||
|
configurable: true
|
|||
|
}
|
|||
|
});
|
|||
|
};
|
|||
|
} else {
|
|||
|
// old school shim for old browsers
|
|||
|
module.exports = function inherits(ctor, superCtor) {
|
|||
|
ctor.super_ = superCtor
|
|||
|
var TempCtor = function () {}
|
|||
|
TempCtor.prototype = superCtor.prototype
|
|||
|
ctor.prototype = new TempCtor()
|
|||
|
ctor.prototype.constructor = ctor
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
},{}],76:[function(_dereq_,module,exports){
|
|||
|
module.exports = _dereq_('./lib/create-formatter');
|
|||
|
|
|||
|
},{"./lib/create-formatter":77}],77:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var assign = _dereq_('core-js/library/fn/object/assign');
|
|||
|
var ContextTraversal = _dereq_('power-assert-context-traversal');
|
|||
|
var LegacyContextTraversal = _dereq_('./legacy-context-traversal');
|
|||
|
var StringWriter = _dereq_('./string-writer');
|
|||
|
var defaultOptions = _dereq_('./default-options');
|
|||
|
var reduce = _dereq_('core-js/library/fn/array/reduce');
|
|||
|
|
|||
|
/**
|
|||
|
* options.reducers [array]
|
|||
|
* options.renderers [array]
|
|||
|
* options.outputOffset [number]
|
|||
|
* options.lineSeparator [string]
|
|||
|
* options.legacy [boolean]
|
|||
|
*/
|
|||
|
function createFormatter (options) {
|
|||
|
var formatterConfig = assign({}, defaultOptions(), options);
|
|||
|
var reducers = formatterConfig.reducers || [];
|
|||
|
var rendererConfigs = formatterConfig.renderers;
|
|||
|
var len = rendererConfigs.length;
|
|||
|
|
|||
|
return function (powerAssertContext) {
|
|||
|
var context = reduce(reducers, function (prevContext, reducer) {
|
|||
|
return reducer(prevContext);
|
|||
|
}, powerAssertContext);
|
|||
|
var writer = new StringWriter(formatterConfig);
|
|||
|
var traversal;
|
|||
|
if (formatterConfig.legacy) {
|
|||
|
traversal = new LegacyContextTraversal(context);
|
|||
|
traversal.setWritable(writer);
|
|||
|
} else {
|
|||
|
traversal = new ContextTraversal(context);
|
|||
|
}
|
|||
|
for (var i = 0; i < len; i += 1) {
|
|||
|
var RendererClass;
|
|||
|
var renderer;
|
|||
|
var config = rendererConfigs[i];
|
|||
|
if (typeof config === 'object') {
|
|||
|
RendererClass = config.ctor;
|
|||
|
renderer = new RendererClass(config.options);
|
|||
|
} else if (typeof config === 'function') {
|
|||
|
RendererClass = config;
|
|||
|
renderer = new RendererClass();
|
|||
|
}
|
|||
|
renderer.init(traversal);
|
|||
|
if (typeof renderer.setWritable === 'function') {
|
|||
|
renderer.setWritable(writer);
|
|||
|
}
|
|||
|
}
|
|||
|
traversal.traverse();
|
|||
|
writer.write('');
|
|||
|
return writer.toString();
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
createFormatter.StringWriter = StringWriter;
|
|||
|
module.exports = createFormatter;
|
|||
|
|
|||
|
},{"./default-options":78,"./legacy-context-traversal":79,"./string-writer":80,"core-js/library/fn/array/reduce":12,"core-js/library/fn/object/assign":13,"power-assert-context-traversal":82}],78:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
module.exports = function defaultOptions () {
|
|||
|
return {
|
|||
|
reducers: [
|
|||
|
],
|
|||
|
legacy: false,
|
|||
|
outputOffset: 2,
|
|||
|
lineSeparator: '\n'
|
|||
|
};
|
|||
|
};
|
|||
|
|
|||
|
},{}],79:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var ContextTraversal = _dereq_('power-assert-context-traversal');
|
|||
|
var inherits = _dereq_('util').inherits;
|
|||
|
var slice = Array.prototype.slice;
|
|||
|
|
|||
|
function LegacyContextTraversal (powerAssertContext) {
|
|||
|
ContextTraversal.call(this, powerAssertContext);
|
|||
|
}
|
|||
|
inherits(LegacyContextTraversal, ContextTraversal);
|
|||
|
|
|||
|
LegacyContextTraversal.prototype.setWritable = function (writer) {
|
|||
|
this.writer = writer;
|
|||
|
};
|
|||
|
|
|||
|
LegacyContextTraversal.prototype.on = function () {
|
|||
|
var args = slice.apply(arguments);
|
|||
|
if (args[0] === 'render') {
|
|||
|
args[0] = 'end';
|
|||
|
}
|
|||
|
ContextTraversal.prototype.on.apply(this, args);
|
|||
|
};
|
|||
|
|
|||
|
LegacyContextTraversal.prototype.emit = function () {
|
|||
|
var args = slice.apply(arguments);
|
|||
|
if (args[0] === 'end') {
|
|||
|
args[1] = this.writer;
|
|||
|
}
|
|||
|
ContextTraversal.prototype.emit.apply(this, args);
|
|||
|
};
|
|||
|
|
|||
|
module.exports = LegacyContextTraversal;
|
|||
|
|
|||
|
},{"power-assert-context-traversal":82,"util":100}],80:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
function spacerStr (len) {
|
|||
|
var str = '';
|
|||
|
for(var i = 0; i < len; i += 1) {
|
|||
|
str += ' ';
|
|||
|
}
|
|||
|
return str;
|
|||
|
}
|
|||
|
|
|||
|
function StringWriter (config) {
|
|||
|
this.lines = [];
|
|||
|
this.lineSeparator = config.lineSeparator;
|
|||
|
this.regex = new RegExp(this.lineSeparator, 'g');
|
|||
|
this.spacer = spacerStr(config.outputOffset);
|
|||
|
}
|
|||
|
|
|||
|
StringWriter.prototype.write = function (str) {
|
|||
|
this.lines.push(this.spacer + str.replace(this.regex, this.lineSeparator + this.spacer));
|
|||
|
};
|
|||
|
|
|||
|
StringWriter.prototype.toString = function () {
|
|||
|
var str = this.lines.join(this.lineSeparator);
|
|||
|
this.lines.length = 0;
|
|||
|
return str;
|
|||
|
};
|
|||
|
|
|||
|
module.exports = StringWriter;
|
|||
|
|
|||
|
},{}],81:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var parser = _dereq_('acorn');
|
|||
|
_dereq_('acorn-es7-plugin')(parser);
|
|||
|
var estraverse = _dereq_('estraverse');
|
|||
|
var purifyAst = _dereq_('espurify').customize({extra: ['range']});
|
|||
|
var assign = _dereq_('core-js/library/fn/object/assign');
|
|||
|
|
|||
|
module.exports = function (powerAssertContext) {
|
|||
|
var source = powerAssertContext.source;
|
|||
|
if (source.ast && source.tokens && source.visitorKeys) {
|
|||
|
return powerAssertContext;
|
|||
|
}
|
|||
|
var astAndTokens = parse(source);
|
|||
|
var newSource = assign({}, source, {
|
|||
|
ast: purifyAst(astAndTokens.expression),
|
|||
|
tokens: astAndTokens.tokens,
|
|||
|
visitorKeys: estraverse.VisitorKeys
|
|||
|
});
|
|||
|
return assign({}, powerAssertContext, { source: newSource });
|
|||
|
};
|
|||
|
|
|||
|
function parserOptions(tokens) {
|
|||
|
return {
|
|||
|
sourceType: 'module',
|
|||
|
ecmaVersion: 7,
|
|||
|
locations: true,
|
|||
|
ranges: false,
|
|||
|
onToken: tokens,
|
|||
|
plugins: {asyncawait: true}
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function parse (source) {
|
|||
|
var code = source.content;
|
|||
|
var ast, tokens;
|
|||
|
|
|||
|
function doParse(wrapper) {
|
|||
|
var content = wrapper ? wrapper(code) : code;
|
|||
|
var tokenBag = [];
|
|||
|
ast = parser.parse(content, parserOptions(tokenBag));
|
|||
|
if (wrapper) {
|
|||
|
ast = ast.body[0].body;
|
|||
|
tokens = tokenBag.slice(6, -2);
|
|||
|
} else {
|
|||
|
tokens = tokenBag.slice(0, -1);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (source.async) {
|
|||
|
doParse(wrappedInAsync);
|
|||
|
} else if (source.generator) {
|
|||
|
doParse(wrappedInGenerator);
|
|||
|
} else {
|
|||
|
doParse();
|
|||
|
}
|
|||
|
|
|||
|
var exp = ast.body[0].expression;
|
|||
|
var columnOffset = exp.loc.start.column;
|
|||
|
var offsetTree = estraverse.replace(exp, {
|
|||
|
keys: estraverse.VisitorKeys,
|
|||
|
enter: function (eachNode) {
|
|||
|
if (!eachNode.loc && eachNode.range) {
|
|||
|
// skip already visited node
|
|||
|
return eachNode;
|
|||
|
}
|
|||
|
eachNode.range = [
|
|||
|
eachNode.loc.start.column - columnOffset,
|
|||
|
eachNode.loc.end.column - columnOffset
|
|||
|
];
|
|||
|
delete eachNode.loc;
|
|||
|
return eachNode;
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
return {
|
|||
|
tokens: offsetAndSlimDownTokens(tokens),
|
|||
|
expression: offsetTree
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function wrappedInGenerator (jsCode) {
|
|||
|
return 'function *wrapper() { ' + jsCode + ' }';
|
|||
|
}
|
|||
|
|
|||
|
function wrappedInAsync (jsCode) {
|
|||
|
return 'async function wrapper() { ' + jsCode + ' }';
|
|||
|
}
|
|||
|
|
|||
|
function offsetAndSlimDownTokens (tokens) {
|
|||
|
var i, token, newToken, result = [];
|
|||
|
var columnOffset;
|
|||
|
for(i = 0; i < tokens.length; i += 1) {
|
|||
|
token = tokens[i];
|
|||
|
if (i === 0) {
|
|||
|
columnOffset = token.loc.start.column;
|
|||
|
}
|
|||
|
newToken = {
|
|||
|
type: {
|
|||
|
label: token.type.label
|
|||
|
}
|
|||
|
};
|
|||
|
if (typeof token.value !== 'undefined') {
|
|||
|
newToken.value = token.value;
|
|||
|
}
|
|||
|
newToken.range = [
|
|||
|
token.loc.start.column - columnOffset,
|
|||
|
token.loc.end.column - columnOffset
|
|||
|
];
|
|||
|
result.push(newToken);
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
},{"acorn":5,"acorn-es7-plugin":4,"core-js/library/fn/object/assign":13,"espurify":68,"estraverse":72}],82:[function(_dereq_,module,exports){
|
|||
|
module.exports = _dereq_('./lib/context-traversal');
|
|||
|
|
|||
|
},{"./lib/context-traversal":83}],83:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var EventEmitter = _dereq_('events').EventEmitter;
|
|||
|
var inherits = _dereq_('util').inherits;
|
|||
|
var estraverse = _dereq_('estraverse');
|
|||
|
var forEach = _dereq_('core-js/library/fn/array/for-each');
|
|||
|
var reduce = _dereq_('core-js/library/fn/array/reduce');
|
|||
|
var locationOf = _dereq_('./location');
|
|||
|
var literalPattern = /^(?:String|Numeric|Null|Boolean|RegExp)?Literal$/;
|
|||
|
var assign = _dereq_('core-js/library/fn/object/assign');
|
|||
|
|
|||
|
function ContextTraversal (powerAssertContext) {
|
|||
|
this.powerAssertContext = powerAssertContext;
|
|||
|
EventEmitter.call(this);
|
|||
|
}
|
|||
|
inherits(ContextTraversal, EventEmitter);
|
|||
|
|
|||
|
ContextTraversal.prototype.traverse = function () {
|
|||
|
var _this = this;
|
|||
|
var source = _this.powerAssertContext.source;
|
|||
|
parseIfJson(source, 'ast');
|
|||
|
parseIfJson(source, 'tokens');
|
|||
|
parseIfJson(source, 'visitorKeys');
|
|||
|
_this.emit('start', this.powerAssertContext);
|
|||
|
forEach(this.powerAssertContext.args, function (capturedArgument) {
|
|||
|
onEachEsNode(capturedArgument, source, function (esNode) {
|
|||
|
_this.emit('data', esNode);
|
|||
|
});
|
|||
|
});
|
|||
|
_this.emit('end');
|
|||
|
};
|
|||
|
|
|||
|
function parseIfJson (source, propName) {
|
|||
|
if (typeof source[propName] === 'string') {
|
|||
|
source[propName] = JSON.parse(source[propName]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function onEachEsNode(capturedArgument, source, callback) {
|
|||
|
var espathToValue = reduce(capturedArgument.events, function (accum, ev) {
|
|||
|
accum[ev.espath] = ev.value;
|
|||
|
return accum;
|
|||
|
}, {});
|
|||
|
var nodeStack = [];
|
|||
|
estraverse.traverse(source.ast, {
|
|||
|
keys: source.visitorKeys,
|
|||
|
enter: function (currentNode, parentNode) {
|
|||
|
var parentEsNode = (0 < nodeStack.length) ? nodeStack[nodeStack.length - 1] : null;
|
|||
|
var esNode = createEsNode(this.path(), currentNode, espathToValue, source.content, source.tokens, parentEsNode);
|
|||
|
nodeStack.push(esNode);
|
|||
|
callback(esNode);
|
|||
|
},
|
|||
|
leave: function (currentNode, parentNode) {
|
|||
|
nodeStack.pop();
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
function isLiteral (node) {
|
|||
|
return literalPattern.test(node.type);
|
|||
|
}
|
|||
|
|
|||
|
function createEsNode (path, currentNode, espathToValue, jsCode, tokens, parent) {
|
|||
|
var espath = path ? path.join('/') : '';
|
|||
|
return {
|
|||
|
espath: espath,
|
|||
|
parent: parent,
|
|||
|
key: path ? path[path.length - 1] : null,
|
|||
|
node: currentNode,
|
|||
|
code: jsCode.slice(currentNode.range[0], currentNode.range[1]),
|
|||
|
value: isLiteral(currentNode) ? currentNode.value : espathToValue[espath],
|
|||
|
isCaptured: espathToValue.hasOwnProperty(espath),
|
|||
|
range: locationOf(currentNode, tokens)
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
module.exports = ContextTraversal;
|
|||
|
|
|||
|
},{"./location":84,"core-js/library/fn/array/for-each":7,"core-js/library/fn/array/reduce":12,"core-js/library/fn/object/assign":13,"estraverse":72,"events":74,"util":100}],84:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var syntax = _dereq_('estraverse').Syntax;
|
|||
|
|
|||
|
function locationOf(currentNode, tokens) {
|
|||
|
switch(currentNode.type) {
|
|||
|
case syntax.MemberExpression:
|
|||
|
return propertyLocationOf(currentNode, tokens);
|
|||
|
case syntax.CallExpression:
|
|||
|
if (currentNode.callee.type === syntax.MemberExpression) {
|
|||
|
return propertyLocationOf(currentNode.callee, tokens);
|
|||
|
}
|
|||
|
break;
|
|||
|
case syntax.BinaryExpression:
|
|||
|
case syntax.LogicalExpression:
|
|||
|
case syntax.AssignmentExpression:
|
|||
|
return infixOperatorLocationOf(currentNode, tokens);
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
return currentNode.range;
|
|||
|
}
|
|||
|
|
|||
|
function propertyLocationOf(memberExpression, tokens) {
|
|||
|
var prop = memberExpression.property;
|
|||
|
var token;
|
|||
|
if (!memberExpression.computed) {
|
|||
|
return prop.range;
|
|||
|
}
|
|||
|
token = findLeftBracketTokenOf(memberExpression, tokens);
|
|||
|
return token ? token.range : prop.range;
|
|||
|
}
|
|||
|
|
|||
|
// calculate location of infix operator for BinaryExpression, AssignmentExpression and LogicalExpression.
|
|||
|
function infixOperatorLocationOf (expression, tokens) {
|
|||
|
var token = findOperatorTokenOf(expression, tokens);
|
|||
|
return token ? token.range : expression.left.range;
|
|||
|
}
|
|||
|
|
|||
|
function findLeftBracketTokenOf(expression, tokens) {
|
|||
|
var fromColumn = expression.property.range[0];
|
|||
|
return searchToken(tokens, function (token, index) {
|
|||
|
var prevToken;
|
|||
|
if (token.range[0] === fromColumn) {
|
|||
|
prevToken = tokens[index - 1];
|
|||
|
// if (prevToken.type === 'Punctuator' && prevToken.value === '[') { // esprima
|
|||
|
if (prevToken.type.label === '[') { // acorn
|
|||
|
return prevToken;
|
|||
|
}
|
|||
|
}
|
|||
|
return undefined;
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
function findOperatorTokenOf(expression, tokens) {
|
|||
|
var fromColumn = expression.left.range[1];
|
|||
|
var toColumn = expression.right.range[0];
|
|||
|
return searchToken(tokens, function (token, index) {
|
|||
|
if (fromColumn < token.range[0] &&
|
|||
|
token.range[1] < toColumn &&
|
|||
|
token.value === expression.operator) {
|
|||
|
return token;
|
|||
|
}
|
|||
|
return undefined;
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
function searchToken(tokens, predicate) {
|
|||
|
var i, token, found;
|
|||
|
for(i = 0; i < tokens.length; i += 1) {
|
|||
|
token = tokens[i];
|
|||
|
found = predicate(token, i);
|
|||
|
if (found) {
|
|||
|
return found;
|
|||
|
}
|
|||
|
}
|
|||
|
return undefined;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = locationOf;
|
|||
|
|
|||
|
},{"estraverse":72}],85:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var BaseRenderer = _dereq_('power-assert-renderer-base');
|
|||
|
var inherits = _dereq_('util').inherits;
|
|||
|
|
|||
|
function AssertionRenderer () {
|
|||
|
BaseRenderer.call(this);
|
|||
|
}
|
|||
|
inherits(AssertionRenderer, BaseRenderer);
|
|||
|
|
|||
|
AssertionRenderer.prototype.onStart = function (context) {
|
|||
|
this.assertionLine = context.source.content;
|
|||
|
};
|
|||
|
|
|||
|
AssertionRenderer.prototype.onEnd = function () {
|
|||
|
this.write('');
|
|||
|
this.write(this.assertionLine);
|
|||
|
};
|
|||
|
|
|||
|
module.exports = AssertionRenderer;
|
|||
|
|
|||
|
},{"power-assert-renderer-base":86,"util":100}],86:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
function BaseRenderer () {
|
|||
|
}
|
|||
|
|
|||
|
BaseRenderer.prototype.init = function (traversal) {
|
|||
|
var _this = this;
|
|||
|
traversal.on('start', function (context) {
|
|||
|
_this.onStart(context);
|
|||
|
});
|
|||
|
traversal.on('data', function (esNode) {
|
|||
|
_this.onData(esNode);
|
|||
|
});
|
|||
|
traversal.on('end', function () {
|
|||
|
_this.onEnd();
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
BaseRenderer.prototype.setWritable = function (writable) {
|
|||
|
this.writable = writable;
|
|||
|
};
|
|||
|
|
|||
|
// API
|
|||
|
BaseRenderer.prototype.onStart = function (context) {
|
|||
|
};
|
|||
|
|
|||
|
// API
|
|||
|
BaseRenderer.prototype.onData = function (esNode) {
|
|||
|
};
|
|||
|
|
|||
|
// API
|
|||
|
BaseRenderer.prototype.onEnd = function () {
|
|||
|
};
|
|||
|
|
|||
|
// API
|
|||
|
BaseRenderer.prototype.write = function (str) {
|
|||
|
this.writable.write(str);
|
|||
|
};
|
|||
|
|
|||
|
module.exports = BaseRenderer;
|
|||
|
|
|||
|
},{}],87:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var BaseRenderer = _dereq_('power-assert-renderer-base');
|
|||
|
var inherits = _dereq_('util').inherits;
|
|||
|
var typeName = _dereq_('type-name');
|
|||
|
var keys = _dereq_('core-js/library/fn/object/keys');
|
|||
|
var forEach = _dereq_('core-js/library/fn/array/for-each');
|
|||
|
var udiff = _dereq_('./lib/udiff');
|
|||
|
var stringifier = _dereq_('stringifier');
|
|||
|
var assign = _dereq_('core-js/library/fn/object/assign');
|
|||
|
var defaultOptions = _dereq_('./lib/default-options');
|
|||
|
var literalPattern = /^(?:String|Numeric|Null|Boolean|RegExp)?Literal$/;
|
|||
|
|
|||
|
function isLiteral (node) {
|
|||
|
return literalPattern.test(node.type);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* options.stringify [function]
|
|||
|
* options.maxDepth [number]
|
|||
|
* options.lineSeparator [string]
|
|||
|
* options.anonymous [string]
|
|||
|
* options.circular [string]
|
|||
|
*
|
|||
|
* options.diff [function]
|
|||
|
* options.lineDiffThreshold [number]
|
|||
|
*/
|
|||
|
function ComparisonRenderer (config) {
|
|||
|
BaseRenderer.call(this);
|
|||
|
this.config = assign({}, defaultOptions(), config);
|
|||
|
if (typeof this.config.stringify === 'function') {
|
|||
|
this.stringify = this.config.stringify;
|
|||
|
} else {
|
|||
|
this.stringify = stringifier(this.config);
|
|||
|
}
|
|||
|
if (typeof this.config.diff === 'function') {
|
|||
|
this.diff = this.config.diff;
|
|||
|
} else {
|
|||
|
this.diff = udiff(this.config);
|
|||
|
}
|
|||
|
this.espathToPair = {};
|
|||
|
}
|
|||
|
inherits(ComparisonRenderer, BaseRenderer);
|
|||
|
|
|||
|
ComparisonRenderer.prototype.onData = function (esNode) {
|
|||
|
var pair;
|
|||
|
if (!esNode.isCaptured) {
|
|||
|
if (isTargetBinaryExpression(esNode.parent) && isLiteral(esNode.node)) {
|
|||
|
this.espathToPair[esNode.parent.espath][esNode.key] = {code: esNode.code, value: esNode.value};
|
|||
|
}
|
|||
|
return;
|
|||
|
}
|
|||
|
if (isTargetBinaryExpression(esNode.parent)) {
|
|||
|
this.espathToPair[esNode.parent.espath][esNode.key] = {code: esNode.code, value: esNode.value};
|
|||
|
}
|
|||
|
if (isTargetBinaryExpression(esNode)) {
|
|||
|
pair = {
|
|||
|
operator: esNode.node.operator,
|
|||
|
value: esNode.value
|
|||
|
};
|
|||
|
this.espathToPair[esNode.espath] = pair;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
ComparisonRenderer.prototype.onEnd = function () {
|
|||
|
var _this = this;
|
|||
|
var pairs = [];
|
|||
|
forEach(keys(this.espathToPair), function (espath) {
|
|||
|
var pair = _this.espathToPair[espath];
|
|||
|
if (pair.left && pair.right) {
|
|||
|
pairs.push(pair);
|
|||
|
}
|
|||
|
});
|
|||
|
forEach(pairs, function (pair) {
|
|||
|
_this.compare(pair);
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
ComparisonRenderer.prototype.compare = function (pair) {
|
|||
|
if (isStringDiffTarget(pair)) {
|
|||
|
this.showStringDiff(pair);
|
|||
|
} else {
|
|||
|
this.showExpectedAndActual(pair);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
ComparisonRenderer.prototype.showExpectedAndActual = function (pair) {
|
|||
|
this.write('');
|
|||
|
this.write('[' + typeName(pair.right.value) + '] ' + pair.right.code);
|
|||
|
this.write('=> ' + this.stringify(pair.right.value));
|
|||
|
this.write('[' + typeName(pair.left.value) + '] ' + pair.left.code);
|
|||
|
this.write('=> ' + this.stringify(pair.left.value));
|
|||
|
};
|
|||
|
|
|||
|
ComparisonRenderer.prototype.showStringDiff = function (pair) {
|
|||
|
this.write('');
|
|||
|
this.write('--- [string] ' + pair.right.code);
|
|||
|
this.write('+++ [string] ' + pair.left.code);
|
|||
|
this.write(this.diff(pair.right.value, pair.left.value, this.config));
|
|||
|
};
|
|||
|
|
|||
|
function isTargetBinaryExpression (esNode) {
|
|||
|
return esNode &&
|
|||
|
esNode.node.type === 'BinaryExpression' &&
|
|||
|
(esNode.node.operator === '===' || esNode.node.operator === '==') &&
|
|||
|
esNode.isCaptured &&
|
|||
|
!(esNode.value);
|
|||
|
}
|
|||
|
|
|||
|
function isStringDiffTarget(pair) {
|
|||
|
return typeof pair.left.value === 'string' && typeof pair.right.value === 'string';
|
|||
|
}
|
|||
|
|
|||
|
ComparisonRenderer.udiff = udiff;
|
|||
|
module.exports = ComparisonRenderer;
|
|||
|
|
|||
|
},{"./lib/default-options":88,"./lib/udiff":89,"core-js/library/fn/array/for-each":7,"core-js/library/fn/object/assign":13,"core-js/library/fn/object/keys":14,"power-assert-renderer-base":86,"stringifier":95,"type-name":98,"util":100}],88:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
module.exports = function defaultOptions () {
|
|||
|
return {
|
|||
|
lineDiffThreshold: 5,
|
|||
|
maxDepth: 2,
|
|||
|
indent: null,
|
|||
|
outputOffset: 2,
|
|||
|
anonymous: 'Object',
|
|||
|
circular: '#@Circular#',
|
|||
|
lineSeparator: '\n'
|
|||
|
};
|
|||
|
};
|
|||
|
|
|||
|
},{}],89:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var DiffMatchPatch = _dereq_('diff-match-patch');
|
|||
|
var dmp = new DiffMatchPatch();
|
|||
|
|
|||
|
function udiff (config) {
|
|||
|
return function diff (text1, text2) {
|
|||
|
var patch;
|
|||
|
if (config && shouldUseLineLevelDiff(text1, config)) {
|
|||
|
patch = udiffLines(text1, text2);
|
|||
|
} else {
|
|||
|
patch = udiffChars(text1, text2);
|
|||
|
}
|
|||
|
return decodeURIComponent(patch);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function shouldUseLineLevelDiff (text, config) {
|
|||
|
return config.lineDiffThreshold < text.split(/\r\n|\r|\n/).length;
|
|||
|
}
|
|||
|
|
|||
|
function udiffLines(text1, text2) {
|
|||
|
/*jshint camelcase: false */
|
|||
|
var a = dmp.diff_linesToChars_(text1, text2);
|
|||
|
var diffs = dmp.diff_main(a.chars1, a.chars2, false);
|
|||
|
dmp.diff_charsToLines_(diffs, a.lineArray);
|
|||
|
dmp.diff_cleanupSemantic(diffs);
|
|||
|
return dmp.patch_toText(dmp.patch_make(text1, diffs));
|
|||
|
}
|
|||
|
|
|||
|
function udiffChars (text1, text2) {
|
|||
|
/*jshint camelcase: false */
|
|||
|
var diffs = dmp.diff_main(text1, text2, false);
|
|||
|
dmp.diff_cleanupSemantic(diffs);
|
|||
|
return dmp.patch_toText(dmp.patch_make(text1, diffs));
|
|||
|
}
|
|||
|
|
|||
|
module.exports = udiff;
|
|||
|
|
|||
|
},{"diff-match-patch":66}],90:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var BaseRenderer = _dereq_('power-assert-renderer-base');
|
|||
|
var inherits = _dereq_('util').inherits;
|
|||
|
var forEach = _dereq_('core-js/library/fn/array/for-each');
|
|||
|
var stringifier = _dereq_('stringifier');
|
|||
|
var stringWidth = _dereq_('./lib/string-width');
|
|||
|
var assign = _dereq_('core-js/library/fn/object/assign');
|
|||
|
var defaultOptions = _dereq_('./lib/default-options');
|
|||
|
|
|||
|
/**
|
|||
|
* options.stringify [function]
|
|||
|
* options.maxDepth [number]
|
|||
|
* options.lineSeparator [string]
|
|||
|
* options.anonymous [string]
|
|||
|
* options.circular [string]
|
|||
|
*
|
|||
|
* options.widthOf [function]
|
|||
|
* options.ambiguousEastAsianCharWidth [number]
|
|||
|
*/
|
|||
|
function DiagramRenderer (config) {
|
|||
|
BaseRenderer.call(this);
|
|||
|
this.config = assign({}, defaultOptions(), config);
|
|||
|
this.events = [];
|
|||
|
if (typeof this.config.stringify === 'function') {
|
|||
|
this.stringify = this.config.stringify;
|
|||
|
} else {
|
|||
|
this.stringify = stringifier(this.config);
|
|||
|
}
|
|||
|
if (typeof this.config.widthOf === 'function') {
|
|||
|
this.widthOf = this.config.widthOf;
|
|||
|
} else {
|
|||
|
this.widthOf = stringWidth(this.config);
|
|||
|
}
|
|||
|
this.initialVertivalBarLength = 1;
|
|||
|
}
|
|||
|
inherits(DiagramRenderer, BaseRenderer);
|
|||
|
|
|||
|
DiagramRenderer.prototype.onStart = function (context) {
|
|||
|
this.assertionLine = context.source.content;
|
|||
|
this.initializeRows();
|
|||
|
};
|
|||
|
|
|||
|
DiagramRenderer.prototype.onData = function (esNode) {
|
|||
|
if (!esNode.isCaptured) {
|
|||
|
return;
|
|||
|
}
|
|||
|
this.events.push({value: esNode.value, leftIndex: esNode.range[0]});
|
|||
|
};
|
|||
|
|
|||
|
DiagramRenderer.prototype.onEnd = function () {
|
|||
|
this.events.sort(rightToLeft);
|
|||
|
this.constructRows(this.events);
|
|||
|
var _this = this;
|
|||
|
forEach(this.rows, function (columns) {
|
|||
|
_this.write(columns.join(''));
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
DiagramRenderer.prototype.initializeRows = function () {
|
|||
|
this.rows = [];
|
|||
|
for (var i = 0; i <= this.initialVertivalBarLength; i += 1) {
|
|||
|
this.addOneMoreRow();
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
DiagramRenderer.prototype.newRowFor = function (assertionLine) {
|
|||
|
return createRow(this.widthOf(assertionLine), ' ');
|
|||
|
};
|
|||
|
|
|||
|
DiagramRenderer.prototype.addOneMoreRow = function () {
|
|||
|
this.rows.push(this.newRowFor(this.assertionLine));
|
|||
|
};
|
|||
|
|
|||
|
DiagramRenderer.prototype.lastRow = function () {
|
|||
|
return this.rows[this.rows.length - 1];
|
|||
|
};
|
|||
|
|
|||
|
DiagramRenderer.prototype.renderVerticalBarAt = function (columnIndex) {
|
|||
|
var i, lastRowIndex = this.rows.length - 1;
|
|||
|
for (i = 0; i < lastRowIndex; i += 1) {
|
|||
|
this.rows[i].splice(columnIndex, 1, '|');
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
DiagramRenderer.prototype.renderValueAt = function (columnIndex, dumpedValue) {
|
|||
|
var i, width = this.widthOf(dumpedValue);
|
|||
|
for (i = 0; i < width; i += 1) {
|
|||
|
this.lastRow().splice(columnIndex + i, 1, dumpedValue.charAt(i));
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
DiagramRenderer.prototype.isOverlapped = function (prevCapturing, nextCaputuring, dumpedValue) {
|
|||
|
return (typeof prevCapturing !== 'undefined') && this.startColumnFor(prevCapturing) <= (this.startColumnFor(nextCaputuring) + this.widthOf(dumpedValue));
|
|||
|
};
|
|||
|
|
|||
|
DiagramRenderer.prototype.constructRows = function (capturedEvents) {
|
|||
|
var that = this;
|
|||
|
var prevCaptured;
|
|||
|
forEach(capturedEvents, function (captured) {
|
|||
|
var dumpedValue = that.stringify(captured.value);
|
|||
|
if (that.isOverlapped(prevCaptured, captured, dumpedValue)) {
|
|||
|
that.addOneMoreRow();
|
|||
|
}
|
|||
|
that.renderVerticalBarAt(that.startColumnFor(captured));
|
|||
|
that.renderValueAt(that.startColumnFor(captured), dumpedValue);
|
|||
|
prevCaptured = captured;
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
DiagramRenderer.prototype.startColumnFor = function (captured) {
|
|||
|
return this.widthOf(this.assertionLine.slice(0, captured.leftIndex));
|
|||
|
};
|
|||
|
|
|||
|
function createRow (numCols, initial) {
|
|||
|
var row = [], i;
|
|||
|
for(i = 0; i < numCols; i += 1) {
|
|||
|
row[i] = initial;
|
|||
|
}
|
|||
|
return row;
|
|||
|
}
|
|||
|
|
|||
|
function rightToLeft (a, b) {
|
|||
|
return b.leftIndex - a.leftIndex;
|
|||
|
}
|
|||
|
|
|||
|
DiagramRenderer.stringWidth = stringWidth;
|
|||
|
module.exports = DiagramRenderer;
|
|||
|
|
|||
|
},{"./lib/default-options":91,"./lib/string-width":92,"core-js/library/fn/array/for-each":7,"core-js/library/fn/object/assign":13,"power-assert-renderer-base":86,"stringifier":95,"util":100}],91:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
module.exports = function defaultOptions () {
|
|||
|
return {
|
|||
|
ambiguousEastAsianCharWidth: 2,
|
|||
|
maxDepth: 2,
|
|||
|
indent: null,
|
|||
|
outputOffset: 2,
|
|||
|
anonymous: 'Object',
|
|||
|
circular: '#@Circular#',
|
|||
|
lineSeparator: '\n'
|
|||
|
};
|
|||
|
};
|
|||
|
|
|||
|
},{}],92:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var eaw = _dereq_('eastasianwidth');
|
|||
|
|
|||
|
function stringWidth (config) {
|
|||
|
var ambiguousCharWidth = (config && config.ambiguousEastAsianCharWidth) || 1;
|
|||
|
return function widthOf (str) {
|
|||
|
var i, code, width = 0;
|
|||
|
for(i = 0; i < str.length; i+=1) {
|
|||
|
code = eaw.eastAsianWidth(str.charAt(i));
|
|||
|
switch(code) {
|
|||
|
case 'F':
|
|||
|
case 'W':
|
|||
|
width += 2;
|
|||
|
break;
|
|||
|
case 'H':
|
|||
|
case 'Na':
|
|||
|
case 'N':
|
|||
|
width += 1;
|
|||
|
break;
|
|||
|
case 'A':
|
|||
|
width += ambiguousCharWidth;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
return width;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
module.exports = stringWidth;
|
|||
|
|
|||
|
},{"eastasianwidth":67}],93:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var BaseRenderer = _dereq_('power-assert-renderer-base');
|
|||
|
var inherits = _dereq_('util').inherits;
|
|||
|
|
|||
|
function FileRenderer () {
|
|||
|
BaseRenderer.call(this);
|
|||
|
}
|
|||
|
inherits(FileRenderer, BaseRenderer);
|
|||
|
|
|||
|
FileRenderer.prototype.onStart = function (context) {
|
|||
|
this.filepath = context.source.filepath;
|
|||
|
this.lineNumber = context.source.line;
|
|||
|
};
|
|||
|
|
|||
|
FileRenderer.prototype.onEnd = function () {
|
|||
|
if (this.filepath) {
|
|||
|
this.write('# ' + [this.filepath, this.lineNumber].join(':'));
|
|||
|
} else {
|
|||
|
this.write('# at line: ' + this.lineNumber);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
module.exports = FileRenderer;
|
|||
|
|
|||
|
},{"power-assert-renderer-base":86,"util":100}],94:[function(_dereq_,module,exports){
|
|||
|
// shim for using process in browser
|
|||
|
|
|||
|
var process = module.exports = {};
|
|||
|
|
|||
|
// cached from whatever global is present so that test runners that stub it
|
|||
|
// don't break things. But we need to wrap it in a try catch in case it is
|
|||
|
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
|||
|
// function because try/catches deoptimize in certain engines.
|
|||
|
|
|||
|
var cachedSetTimeout;
|
|||
|
var cachedClearTimeout;
|
|||
|
|
|||
|
(function () {
|
|||
|
try {
|
|||
|
cachedSetTimeout = setTimeout;
|
|||
|
} catch (e) {
|
|||
|
cachedSetTimeout = function () {
|
|||
|
throw new Error('setTimeout is not defined');
|
|||
|
}
|
|||
|
}
|
|||
|
try {
|
|||
|
cachedClearTimeout = clearTimeout;
|
|||
|
} catch (e) {
|
|||
|
cachedClearTimeout = function () {
|
|||
|
throw new Error('clearTimeout is not defined');
|
|||
|
}
|
|||
|
}
|
|||
|
} ())
|
|||
|
var queue = [];
|
|||
|
var draining = false;
|
|||
|
var currentQueue;
|
|||
|
var queueIndex = -1;
|
|||
|
|
|||
|
function cleanUpNextTick() {
|
|||
|
if (!draining || !currentQueue) {
|
|||
|
return;
|
|||
|
}
|
|||
|
draining = false;
|
|||
|
if (currentQueue.length) {
|
|||
|
queue = currentQueue.concat(queue);
|
|||
|
} else {
|
|||
|
queueIndex = -1;
|
|||
|
}
|
|||
|
if (queue.length) {
|
|||
|
drainQueue();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function drainQueue() {
|
|||
|
if (draining) {
|
|||
|
return;
|
|||
|
}
|
|||
|
var timeout = cachedSetTimeout(cleanUpNextTick);
|
|||
|
draining = true;
|
|||
|
|
|||
|
var len = queue.length;
|
|||
|
while(len) {
|
|||
|
currentQueue = queue;
|
|||
|
queue = [];
|
|||
|
while (++queueIndex < len) {
|
|||
|
if (currentQueue) {
|
|||
|
currentQueue[queueIndex].run();
|
|||
|
}
|
|||
|
}
|
|||
|
queueIndex = -1;
|
|||
|
len = queue.length;
|
|||
|
}
|
|||
|
currentQueue = null;
|
|||
|
draining = false;
|
|||
|
cachedClearTimeout(timeout);
|
|||
|
}
|
|||
|
|
|||
|
process.nextTick = function (fun) {
|
|||
|
var args = new Array(arguments.length - 1);
|
|||
|
if (arguments.length > 1) {
|
|||
|
for (var i = 1; i < arguments.length; i++) {
|
|||
|
args[i - 1] = arguments[i];
|
|||
|
}
|
|||
|
}
|
|||
|
queue.push(new Item(fun, args));
|
|||
|
if (queue.length === 1 && !draining) {
|
|||
|
cachedSetTimeout(drainQueue, 0);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// v8 likes predictible objects
|
|||
|
function Item(fun, array) {
|
|||
|
this.fun = fun;
|
|||
|
this.array = array;
|
|||
|
}
|
|||
|
Item.prototype.run = function () {
|
|||
|
this.fun.apply(null, this.array);
|
|||
|
};
|
|||
|
process.title = 'browser';
|
|||
|
process.browser = true;
|
|||
|
process.env = {};
|
|||
|
process.argv = [];
|
|||
|
process.version = ''; // empty string to avoid regexp issues
|
|||
|
process.versions = {};
|
|||
|
|
|||
|
function noop() {}
|
|||
|
|
|||
|
process.on = noop;
|
|||
|
process.addListener = noop;
|
|||
|
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');
|
|||
|
};
|
|||
|
|
|||
|
process.cwd = function () { return '/' };
|
|||
|
process.chdir = function (dir) {
|
|||
|
throw new Error('process.chdir is not supported');
|
|||
|
};
|
|||
|
process.umask = function() { return 0; };
|
|||
|
|
|||
|
},{}],95:[function(_dereq_,module,exports){
|
|||
|
/**
|
|||
|
* stringifier
|
|||
|
*
|
|||
|
* https://github.com/twada/stringifier
|
|||
|
*
|
|||
|
* Copyright (c) 2014-2015 Takuto Wada
|
|||
|
* Licensed under the MIT license.
|
|||
|
* http://twada.mit-license.org/2014-2015
|
|||
|
*/
|
|||
|
'use strict';
|
|||
|
|
|||
|
var traverse = _dereq_('traverse');
|
|||
|
var typeName = _dereq_('type-name');
|
|||
|
var assign = _dereq_('core-js/library/fn/object/assign');
|
|||
|
var s = _dereq_('./strategies');
|
|||
|
|
|||
|
function defaultHandlers () {
|
|||
|
return {
|
|||
|
'null': s.always('null'),
|
|||
|
'undefined': s.always('undefined'),
|
|||
|
'function': s.prune(),
|
|||
|
'string': s.json(),
|
|||
|
'boolean': s.json(),
|
|||
|
'number': s.number(),
|
|||
|
'symbol': s.toStr(),
|
|||
|
'RegExp': s.toStr(),
|
|||
|
'String': s.newLike(),
|
|||
|
'Boolean': s.newLike(),
|
|||
|
'Number': s.newLike(),
|
|||
|
'Date': s.newLike(),
|
|||
|
'Array': s.array(),
|
|||
|
'Object': s.object(),
|
|||
|
'@default': s.object()
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function defaultOptions () {
|
|||
|
return {
|
|||
|
maxDepth: null,
|
|||
|
indent: null,
|
|||
|
anonymous: '@Anonymous',
|
|||
|
circular: '#@Circular#',
|
|||
|
snip: '..(snip)',
|
|||
|
lineSeparator: '\n',
|
|||
|
typeFun: typeName
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function createStringifier (customOptions) {
|
|||
|
var options = assign({}, defaultOptions(), customOptions);
|
|||
|
var handlers = assign({}, defaultHandlers(), options.handlers);
|
|||
|
return function stringifyAny (push, x) {
|
|||
|
var context = this;
|
|||
|
var handler = handlerFor(context.node, options, handlers);
|
|||
|
var currentPath = '/' + context.path.join('/');
|
|||
|
var customization = handlers[currentPath];
|
|||
|
var acc = {
|
|||
|
context: context,
|
|||
|
options: options,
|
|||
|
handlers: handlers,
|
|||
|
push: push
|
|||
|
};
|
|||
|
if (typeName(customization) === 'function') {
|
|||
|
handler = customization;
|
|||
|
} else if (typeName(customization) === 'number') {
|
|||
|
handler = s.flow.compose(s.filters.truncate(customization),handler);
|
|||
|
} else if (context.parent && typeName(context.parent.node) === 'Array' && !(context.key in context.parent.node)) {
|
|||
|
// sparse arrays
|
|||
|
handler = s.always('');
|
|||
|
}
|
|||
|
handler(acc, x);
|
|||
|
return push;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function handlerFor (val, options, handlers) {
|
|||
|
var tname = options.typeFun(val);
|
|||
|
if (typeName(handlers[tname]) === 'function') {
|
|||
|
return handlers[tname];
|
|||
|
}
|
|||
|
return handlers['@default'];
|
|||
|
}
|
|||
|
|
|||
|
function walk (val, reducer) {
|
|||
|
var buffer = [];
|
|||
|
var push = function (str) {
|
|||
|
buffer.push(str);
|
|||
|
};
|
|||
|
traverse(val).reduce(reducer, push);
|
|||
|
return buffer.join('');
|
|||
|
}
|
|||
|
|
|||
|
function stringify (val, options) {
|
|||
|
return walk(val, createStringifier(options));
|
|||
|
}
|
|||
|
|
|||
|
function stringifier (options) {
|
|||
|
return function (val) {
|
|||
|
return walk(val, createStringifier(options));
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
stringifier.stringify = stringify;
|
|||
|
stringifier.strategies = s;
|
|||
|
stringifier.defaultOptions = defaultOptions;
|
|||
|
stringifier.defaultHandlers = defaultHandlers;
|
|||
|
module.exports = stringifier;
|
|||
|
|
|||
|
},{"./strategies":96,"core-js/library/fn/object/assign":13,"traverse":97,"type-name":98}],96:[function(_dereq_,module,exports){
|
|||
|
'use strict';
|
|||
|
|
|||
|
var typeName = _dereq_('type-name');
|
|||
|
var forEach = _dereq_('core-js/library/fn/array/for-each');
|
|||
|
var arrayFilter = _dereq_('core-js/library/fn/array/filter');
|
|||
|
var reduceRight = _dereq_('core-js/library/fn/array/reduce-right');
|
|||
|
var indexOf = _dereq_('core-js/library/fn/array/index-of');
|
|||
|
var slice = Array.prototype.slice;
|
|||
|
var END = {};
|
|||
|
var ITERATE = {};
|
|||
|
|
|||
|
// arguments should end with end or iterate
|
|||
|
function compose () {
|
|||
|
var filters = slice.apply(arguments);
|
|||
|
return reduceRight(filters, function(right, left) {
|
|||
|
return left(right);
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
// skip children
|
|||
|
function end () {
|
|||
|
return function (acc, x) {
|
|||
|
acc.context.keys = [];
|
|||
|
return END;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// iterate children
|
|||
|
function iterate () {
|
|||
|
return function (acc, x) {
|
|||
|
return ITERATE;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function filter (predicate) {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
var toBeIterated;
|
|||
|
var isIteratingArray = (typeName(x) === 'Array');
|
|||
|
if (typeName(predicate) === 'function') {
|
|||
|
toBeIterated = [];
|
|||
|
forEach(acc.context.keys, function (key) {
|
|||
|
var indexOrKey = isIteratingArray ? parseInt(key, 10) : key;
|
|||
|
var kvp = {
|
|||
|
key: indexOrKey,
|
|||
|
value: x[key]
|
|||
|
};
|
|||
|
var decision = predicate(kvp);
|
|||
|
if (decision) {
|
|||
|
toBeIterated.push(key);
|
|||
|
}
|
|||
|
if (typeName(decision) === 'number') {
|
|||
|
truncateByKey(decision, key, acc);
|
|||
|
}
|
|||
|
if (typeName(decision) === 'function') {
|
|||
|
customizeStrategyForKey(decision, key, acc);
|
|||
|
}
|
|||
|
});
|
|||
|
acc.context.keys = toBeIterated;
|
|||
|
}
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function customizeStrategyForKey (strategy, key, acc) {
|
|||
|
acc.handlers[currentPath(key, acc)] = strategy;
|
|||
|
}
|
|||
|
|
|||
|
function truncateByKey (size, key, acc) {
|
|||
|
acc.handlers[currentPath(key, acc)] = size;
|
|||
|
}
|
|||
|
|
|||
|
function currentPath (key, acc) {
|
|||
|
var pathToCurrentNode = [''].concat(acc.context.path);
|
|||
|
if (typeName(key) !== 'undefined') {
|
|||
|
pathToCurrentNode.push(key);
|
|||
|
}
|
|||
|
return pathToCurrentNode.join('/');
|
|||
|
}
|
|||
|
|
|||
|
function allowedKeys (orderedWhiteList) {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
var isIteratingArray = (typeName(x) === 'Array');
|
|||
|
if (!isIteratingArray && typeName(orderedWhiteList) === 'Array') {
|
|||
|
acc.context.keys = arrayFilter(orderedWhiteList, function (propKey) {
|
|||
|
return indexOf(acc.context.keys, propKey) !== -1;
|
|||
|
});
|
|||
|
}
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function safeKeys () {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
if (typeName(x) !== 'Array') {
|
|||
|
acc.context.keys = arrayFilter(acc.context.keys, function (propKey) {
|
|||
|
// Error handling for unsafe property access.
|
|||
|
// For example, on PhantomJS,
|
|||
|
// accessing HTMLInputElement.selectionEnd causes TypeError
|
|||
|
try {
|
|||
|
var val = x[propKey];
|
|||
|
return true;
|
|||
|
} catch (e) {
|
|||
|
// skip unsafe key
|
|||
|
return false;
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function arrayIndicesToKeys () {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
if (typeName(x) === 'Array' && 0 < x.length) {
|
|||
|
var indices = Array(x.length);
|
|||
|
for(var i = 0; i < x.length; i += 1) {
|
|||
|
indices[i] = String(i); // traverse uses strings as keys
|
|||
|
}
|
|||
|
acc.context.keys = indices;
|
|||
|
}
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function when (guard, then) {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
var kvp = {
|
|||
|
key: acc.context.key,
|
|||
|
value: x
|
|||
|
};
|
|||
|
if (guard(kvp, acc)) {
|
|||
|
return then(acc, x);
|
|||
|
}
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function truncate (size) {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
var orig = acc.push;
|
|||
|
var ret;
|
|||
|
acc.push = function (str) {
|
|||
|
var savings = str.length - size;
|
|||
|
var truncated;
|
|||
|
if (savings <= size) {
|
|||
|
orig.call(acc, str);
|
|||
|
} else {
|
|||
|
truncated = str.substring(0, size);
|
|||
|
orig.call(acc, truncated + acc.options.snip);
|
|||
|
}
|
|||
|
};
|
|||
|
ret = next(acc, x);
|
|||
|
acc.push = orig;
|
|||
|
return ret;
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function constructorName () {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
var name = acc.options.typeFun(x);
|
|||
|
if (name === '') {
|
|||
|
name = acc.options.anonymous;
|
|||
|
}
|
|||
|
acc.push(name);
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function always (str) {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
acc.push(str);
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function optionValue (key) {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
acc.push(acc.options[key]);
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function json (replacer) {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
acc.push(JSON.stringify(x, replacer));
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function toStr () {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
acc.push(x.toString());
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function decorateArray () {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
acc.context.before(function (node) {
|
|||
|
acc.push('[');
|
|||
|
});
|
|||
|
acc.context.after(function (node) {
|
|||
|
afterAllChildren(this, acc.push, acc.options);
|
|||
|
acc.push(']');
|
|||
|
});
|
|||
|
acc.context.pre(function (val, key) {
|
|||
|
beforeEachChild(this, acc.push, acc.options);
|
|||
|
});
|
|||
|
acc.context.post(function (childContext) {
|
|||
|
afterEachChild(childContext, acc.push);
|
|||
|
});
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function decorateObject () {
|
|||
|
return function (next) {
|
|||
|
return function (acc, x) {
|
|||
|
acc.context.before(function (node) {
|
|||
|
acc.push('{');
|
|||
|
});
|
|||
|
acc.context.after(function (node) {
|
|||
|
afterAllChildren(this, acc.push, acc.options);
|
|||
|
acc.push('}');
|
|||
|
});
|
|||
|
acc.context.pre(function (val, key) {
|
|||
|
beforeEachChild(this, acc.push, acc.options);
|
|||
|
acc.push(sanitizeKey(key) + (acc.options.indent ? ': ' : ':'));
|
|||
|
});
|
|||
|
acc.context.post(function (childContext) {
|
|||
|
afterEachChild(childContext, acc.push);
|
|||
|
});
|
|||
|
return next(acc, x);
|
|||
|
};
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function sanitizeKey (key) {
|
|||
|
return /^[A-Za-z_]+$/.test(key) ? key : JSON.stringify(key);
|
|||
|
}
|
|||
|
|
|||
|
function afterAllChildren (context, push, options) {
|
|||
|
if (options.indent && 0 < context.keys.length) {
|
|||
|
push(options.lineSeparator);
|
|||
|
for(var i = 0; i < context.level; i += 1) { // indent level - 1
|
|||
|
push(options.indent);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function beforeEachChild (context, push, options) {
|
|||
|
if (options.indent) {
|
|||
|
push(options.lineSeparator);
|
|||
|
for(var i = 0; i <= context.level; i += 1) {
|
|||
|
push(options.indent);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function afterEachChild (childContext, push) {
|
|||
|
if (!childContext.isLast) {
|
|||
|
push(',');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function nan (kvp, acc) {
|
|||
|
return kvp.value !== kvp.value;
|
|||
|
}
|
|||
|
|
|||
|
function positiveInfinity (kvp, acc) {
|
|||
|
return !isFinite(kvp.value) && kvp.value === Infinity;
|
|||
|
}
|
|||
|
|
|||
|
function negativeInfinity (kvp, acc) {
|
|||
|
return !isFinite(kvp.value) && kvp.value !== Infinity;
|
|||
|
}
|
|||
|
|
|||
|
function circular (kvp, acc) {
|
|||
|
return acc.context.circular;
|
|||
|
}
|
|||
|
|
|||
|
function maxDepth (kvp, acc) {
|
|||
|
return (acc.options.maxDepth && acc.options.maxDepth <= acc.context.level);
|
|||
|
}
|
|||
|
|
|||
|
var prune = compose(
|
|||
|
always('#'),
|
|||
|
constructorName(),
|
|||
|
always('#'),
|
|||
|
end()
|
|||
|
);
|
|||
|
var omitNaN = when(nan, compose(
|
|||
|
always('NaN'),
|
|||
|
end()
|
|||
|
));
|
|||
|
var omitPositiveInfinity = when(positiveInfinity, compose(
|
|||
|
always('Infinity'),
|
|||
|
end()
|
|||
|
));
|
|||
|
var omitNegativeInfinity = when(negativeInfinity, compose(
|
|||
|
always('-Infinity'),
|
|||
|
end()
|
|||
|
));
|
|||
|
var omitCircular = when(circular, compose(
|
|||
|
optionValue('circular'),
|
|||
|
end()
|
|||
|
));
|
|||
|
var omitMaxDepth = when(maxDepth, prune);
|
|||
|
|
|||
|
module.exports = {
|
|||
|
filters: {
|
|||
|
always: always,
|
|||
|
optionValue: optionValue,
|
|||
|
constructorName: constructorName,
|
|||
|
json: json,
|
|||
|
toStr: toStr,
|
|||
|
prune: prune,
|
|||
|
truncate: truncate,
|
|||
|
decorateArray: decorateArray,
|
|||
|
decorateObject: decorateObject
|
|||
|
},
|
|||
|
flow: {
|
|||
|
compose: compose,
|
|||
|
when: when,
|
|||
|
allowedKeys: allowedKeys,
|
|||
|
safeKeys: safeKeys,
|
|||
|
arrayIndicesToKeys: arrayIndicesToKeys,
|
|||
|
filter: filter,
|
|||
|
iterate: iterate,
|
|||
|
end: end
|
|||
|
},
|
|||
|
symbols: {
|
|||
|
END: END,
|
|||
|
ITERATE: ITERATE
|
|||
|
},
|
|||
|
always: function (str) {
|
|||
|
return compose(always(str), end());
|
|||
|
},
|
|||
|
json: function () {
|
|||
|
return compose(json(), end());
|
|||
|
},
|
|||
|
toStr: function () {
|
|||
|
return compose(toStr(), end());
|
|||
|
},
|
|||
|
prune: function () {
|
|||
|
return prune;
|
|||
|
},
|
|||
|
number: function () {
|
|||
|
return compose(
|
|||
|
omitNaN,
|
|||
|
omitPositiveInfinity,
|
|||
|
omitNegativeInfinity,
|
|||
|
json(),
|
|||
|
end()
|
|||
|
);
|
|||
|
},
|
|||
|
newLike: function () {
|
|||
|
return compose(
|
|||
|
always('new '),
|
|||
|
constructorName(),
|
|||
|
always('('),
|
|||
|
json(),
|
|||
|
always(')'),
|
|||
|
end()
|
|||
|
);
|
|||
|
},
|
|||
|
array: function (predicate) {
|
|||
|
return compose(
|
|||
|
omitCircular,
|
|||
|
omitMaxDepth,
|
|||
|
decorateArray(),
|
|||
|
arrayIndicesToKeys(),
|
|||
|
filter(predicate),
|
|||
|
iterate()
|
|||
|
);
|
|||
|
},
|
|||
|
object: function (predicate, orderedWhiteList) {
|
|||
|
return compose(
|
|||
|
omitCircular,
|
|||
|
omitMaxDepth,
|
|||
|
constructorName(),
|
|||
|
decorateObject(),
|
|||
|
allowedKeys(orderedWhiteList),
|
|||
|
safeKeys(),
|
|||
|
filter(predicate),
|
|||
|
iterate()
|
|||
|
);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
},{"core-js/library/fn/array/filter":6,"core-js/library/fn/array/for-each":7,"core-js/library/fn/array/index-of":8,"core-js/library/fn/array/reduce-right":11,"type-name":98}],97:[function(_dereq_,module,exports){
|
|||
|
var traverse = module.exports = function (obj) {
|
|||
|
return new Traverse(obj);
|
|||
|
};
|
|||
|
|
|||
|
function Traverse (obj) {
|
|||
|
this.value = obj;
|
|||
|
}
|
|||
|
|
|||
|
Traverse.prototype.get = function (ps) {
|
|||
|
var node = this.value;
|
|||
|
for (var i = 0; i < ps.length; i ++) {
|
|||
|
var key = ps[i];
|
|||
|
if (!node || !hasOwnProperty.call(node, key)) {
|
|||
|
node = undefined;
|
|||
|
break;
|
|||
|
}
|
|||
|
node = node[key];
|
|||
|
}
|
|||
|
return node;
|
|||
|
};
|
|||
|
|
|||
|
Traverse.prototype.has = function (ps) {
|
|||
|
var node = this.value;
|
|||
|
for (var i = 0; i < ps.length; i ++) {
|
|||
|
var key = ps[i];
|
|||
|
if (!node || !hasOwnProperty.call(node, key)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
node = node[key];
|
|||
|
}
|
|||
|
return true;
|
|||
|
};
|
|||
|
|
|||
|
Traverse.prototype.set = function (ps, value) {
|
|||
|
var node = this.value;
|
|||
|
for (var i = 0; i < ps.length - 1; i ++) {
|
|||
|
var key = ps[i];
|
|||
|
if (!hasOwnProperty.call(node, key)) node[key] = {};
|
|||
|
node = node[key];
|
|||
|
}
|
|||
|
node[ps[i]] = value;
|
|||
|
return value;
|
|||
|
};
|
|||
|
|
|||
|
Traverse.prototype.map = function (cb) {
|
|||
|
return walk(this.value, cb, true);
|
|||
|
};
|
|||
|
|
|||
|
Traverse.prototype.forEach = function (cb) {
|
|||
|
this.value = walk(this.value, cb, false);
|
|||
|
return this.value;
|
|||
|
};
|
|||
|
|
|||
|
Traverse.prototype.reduce = function (cb, init) {
|
|||
|
var skip = arguments.length === 1;
|
|||
|
var acc = skip ? this.value : init;
|
|||
|
this.forEach(function (x) {
|
|||
|
if (!this.isRoot || !skip) {
|
|||
|
acc = cb.call(this, acc, x);
|
|||
|
}
|
|||
|
});
|
|||
|
return acc;
|
|||
|
};
|
|||
|
|
|||
|
Traverse.prototype.paths = function () {
|
|||
|
var acc = [];
|
|||
|
this.forEach(function (x) {
|
|||
|
acc.push(this.path);
|
|||
|
});
|
|||
|
return acc;
|
|||
|
};
|
|||
|
|
|||
|
Traverse.prototype.nodes = function () {
|
|||
|
var acc = [];
|
|||
|
this.forEach(function (x) {
|
|||
|
acc.push(this.node);
|
|||
|
});
|
|||
|
return acc;
|
|||
|
};
|
|||
|
|
|||
|
Traverse.prototype.clone = function () {
|
|||
|
var parents = [], nodes = [];
|
|||
|
|
|||
|
return (function clone (src) {
|
|||
|
for (var i = 0; i < parents.length; i++) {
|
|||
|
if (parents[i] === src) {
|
|||
|
return nodes[i];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (typeof src === 'object' && src !== null) {
|
|||
|
var dst = copy(src);
|
|||
|
|
|||
|
parents.push(src);
|
|||
|
nodes.push(dst);
|
|||
|
|
|||
|
forEach(objectKeys(src), function (key) {
|
|||
|
dst[key] = clone(src[key]);
|
|||
|
});
|
|||
|
|
|||
|
parents.pop();
|
|||
|
nodes.pop();
|
|||
|
return dst;
|
|||
|
}
|
|||
|
else {
|
|||
|
return src;
|
|||
|
}
|
|||
|
})(this.value);
|
|||
|
};
|
|||
|
|
|||
|
function walk (root, cb, immutable) {
|
|||
|
var path = [];
|
|||
|
var parents = [];
|
|||
|
var alive = true;
|
|||
|
|
|||
|
return (function walker (node_) {
|
|||
|
var node = immutable ? copy(node_) : node_;
|
|||
|
var modifiers = {};
|
|||
|
|
|||
|
var keepGoing = true;
|
|||
|
|
|||
|
var state = {
|
|||
|
node : node,
|
|||
|
node_ : node_,
|
|||
|
path : [].concat(path),
|
|||
|
parent : parents[parents.length - 1],
|
|||
|
parents : parents,
|
|||
|
key : path.slice(-1)[0],
|
|||
|
isRoot : path.length === 0,
|
|||
|
level : path.length,
|
|||
|
circular : null,
|
|||
|
update : function (x, stopHere) {
|
|||
|
if (!state.isRoot) {
|
|||
|
state.parent.node[state.key] = x;
|
|||
|
}
|
|||
|
state.node = x;
|
|||
|
if (stopHere) keepGoing = false;
|
|||
|
},
|
|||
|
'delete' : function (stopHere) {
|
|||
|
delete state.parent.node[state.key];
|
|||
|
if (stopHere) keepGoing = false;
|
|||
|
},
|
|||
|
remove : function (stopHere) {
|
|||
|
if (isArray(state.parent.node)) {
|
|||
|
state.parent.node.splice(state.key, 1);
|
|||
|
}
|
|||
|
else {
|
|||
|
delete state.parent.node[state.key];
|
|||
|
}
|
|||
|
if (stopHere) keepGoing = false;
|
|||
|
},
|
|||
|
keys : null,
|
|||
|
before : function (f) { modifiers.before = f },
|
|||
|
after : function (f) { modifiers.after = f },
|
|||
|
pre : function (f) { modifiers.pre = f },
|
|||
|
post : function (f) { modifiers.post = f },
|
|||
|
stop : function () { alive = false },
|
|||
|
block : function () { keepGoing = false }
|
|||
|
};
|
|||
|
|
|||
|
if (!alive) return state;
|
|||
|
|
|||
|
function updateState() {
|
|||
|
if (typeof state.node === 'object' && state.node !== null) {
|
|||
|
if (!state.keys || state.node_ !== state.node) {
|
|||
|
state.keys = objectKeys(state.node)
|
|||
|
}
|
|||
|
|
|||
|
state.isLeaf = state.keys.length == 0;
|
|||
|
|
|||
|
for (var i = 0; i < parents.length; i++) {
|
|||
|
if (parents[i].node_ === node_) {
|
|||
|
state.circular = parents[i];
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else {
|
|||
|
state.isLeaf = true;
|
|||
|
state.keys = null;
|
|||
|
}
|
|||
|
|
|||
|
state.notLeaf = !state.isLeaf;
|
|||
|
state.notRoot = !state.isRoot;
|
|||
|
}
|
|||
|
|
|||
|
updateState();
|
|||
|
|
|||
|
// use return values to update if defined
|
|||
|
var ret = cb.call(state, state.node);
|
|||
|
if (ret !== undefined && state.update) state.update(ret);
|
|||
|
|
|||
|
if (modifiers.before) modifiers.before.call(state, state.node);
|
|||
|
|
|||
|
if (!keepGoing) return state;
|
|||
|
|
|||
|
if (typeof state.node == 'object'
|
|||
|
&& state.node !== null && !state.circular) {
|
|||
|
parents.push(state);
|
|||
|
|
|||
|
updateState();
|
|||
|
|
|||
|
forEach(state.keys, function (key, i) {
|
|||
|
path.push(key);
|
|||
|
|
|||
|
if (modifiers.pre) modifiers.pre.call(state, state.node[key], key);
|
|||
|
|
|||
|
var child = walker(state.node[key]);
|
|||
|
if (immutable && hasOwnProperty.call(state.node, key)) {
|
|||
|
state.node[key] = child.node;
|
|||
|
}
|
|||
|
|
|||
|
child.isLast = i == state.keys.length - 1;
|
|||
|
child.isFirst = i == 0;
|
|||
|
|
|||
|
if (modifiers.post) modifiers.post.call(state, child);
|
|||
|
|
|||
|
path.pop();
|
|||
|
});
|
|||
|
parents.pop();
|
|||
|
}
|
|||
|
|
|||
|
if (modifiers.after) modifiers.after.call(state, state.node);
|
|||
|
|
|||
|
return state;
|
|||
|
})(root).node;
|
|||
|
}
|
|||
|
|
|||
|
function copy (src) {
|
|||
|
if (typeof src === 'object' && src !== null) {
|
|||
|
var dst;
|
|||
|
|
|||
|
if (isArray(src)) {
|
|||
|
dst = [];
|
|||
|
}
|
|||
|
else if (isDate(src)) {
|
|||
|
dst = new Date(src.getTime ? src.getTime() : src);
|
|||
|
}
|
|||
|
else if (isRegExp(src)) {
|
|||
|
dst = new RegExp(src);
|
|||
|
}
|
|||
|
else if (isError(src)) {
|
|||
|
dst = { message: src.message };
|
|||
|
}
|
|||
|
else if (isBoolean(src)) {
|
|||
|
dst = new Boolean(src);
|
|||
|
}
|
|||
|
else if (isNumber(src)) {
|
|||
|
dst = new Number(src);
|
|||
|
}
|
|||
|
else if (isString(src)) {
|
|||
|
dst = new String(src);
|
|||
|
}
|
|||
|
else if (Object.create && Object.getPrototypeOf) {
|
|||
|
dst = Object.create(Object.getPrototypeOf(src));
|
|||
|
}
|
|||
|
else if (src.constructor === Object) {
|
|||
|
dst = {};
|
|||
|
}
|
|||
|
else {
|
|||
|
var proto =
|
|||
|
(src.constructor && src.constructor.prototype)
|
|||
|
|| src.__proto__
|
|||
|
|| {}
|
|||
|
;
|
|||
|
var T = function () {};
|
|||
|
T.prototype = proto;
|
|||
|
dst = new T;
|
|||
|
}
|
|||
|
|
|||
|
forEach(objectKeys(src), function (key) {
|
|||
|
dst[key] = src[key];
|
|||
|
});
|
|||
|
return dst;
|
|||
|
}
|
|||
|
else return src;
|
|||
|
}
|
|||
|
|
|||
|
var objectKeys = Object.keys || function keys (obj) {
|
|||
|
var res = [];
|
|||
|
for (var key in obj) res.push(key)
|
|||
|
return res;
|
|||
|
};
|
|||
|
|
|||
|
function toS (obj) { return Object.prototype.toString.call(obj) }
|
|||
|
function isDate (obj) { return toS(obj) === '[object Date]' }
|
|||
|
function isRegExp (obj) { return toS(obj) === '[object RegExp]' }
|
|||
|
function isError (obj) { return toS(obj) === '[object Error]' }
|
|||
|
function isBoolean (obj) { return toS(obj) === '[object Boolean]' }
|
|||
|
function isNumber (obj) { return toS(obj) === '[object Number]' }
|
|||
|
function isString (obj) { return toS(obj) === '[object String]' }
|
|||
|
|
|||
|
var isArray = Array.isArray || function isArray (xs) {
|
|||
|
return Object.prototype.toString.call(xs) === '[object Array]';
|
|||
|
};
|
|||
|
|
|||
|
var forEach = function (xs, fn) {
|
|||
|
if (xs.forEach) return xs.forEach(fn)
|
|||
|
else for (var i = 0; i < xs.length; i++) {
|
|||
|
fn(xs[i], i, xs);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
forEach(objectKeys(Traverse.prototype), function (key) {
|
|||
|
traverse[key] = function (obj) {
|
|||
|
var args = [].slice.call(arguments, 1);
|
|||
|
var t = new Traverse(obj);
|
|||
|
return t[key].apply(t, args);
|
|||
|
};
|
|||
|
});
|
|||
|
|
|||
|
var hasOwnProperty = Object.hasOwnProperty || function (obj, key) {
|
|||
|
return key in obj;
|
|||
|
};
|
|||
|
|
|||
|
},{}],98:[function(_dereq_,module,exports){
|
|||
|
/**
|
|||
|
* type-name - Just a reasonable typeof
|
|||
|
*
|
|||
|
* https://github.com/twada/type-name
|
|||
|
*
|
|||
|
* Copyright (c) 2014-2016 Takuto Wada
|
|||
|
* Licensed under the MIT license.
|
|||
|
* http://twada.mit-license.org/2014-2016
|
|||
|
*/
|
|||
|
'use strict';
|
|||
|
|
|||
|
var toStr = Object.prototype.toString;
|
|||
|
|
|||
|
function funcName (f) {
|
|||
|
return f.name ? f.name : /^\s*function\s*([^\(]*)/im.exec(f.toString())[1];
|
|||
|
}
|
|||
|
|
|||
|
function ctorName (obj) {
|
|||
|
var strName = toStr.call(obj).slice(8, -1);
|
|||
|
if ((strName === 'Object' || strName === 'Error') && obj.constructor) {
|
|||
|
return funcName(obj.constructor);
|
|||
|
}
|
|||
|
return strName;
|
|||
|
}
|
|||
|
|
|||
|
function typeName (val) {
|
|||
|
var type;
|
|||
|
if (val === null) {
|
|||
|
return 'null';
|
|||
|
}
|
|||
|
type = typeof(val);
|
|||
|
if (type === 'object') {
|
|||
|
return ctorName(val);
|
|||
|
}
|
|||
|
return type;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = typeName;
|
|||
|
|
|||
|
},{}],99:[function(_dereq_,module,exports){
|
|||
|
module.exports = function isBuffer(arg) {
|
|||
|
return arg && typeof arg === 'object'
|
|||
|
&& typeof arg.copy === 'function'
|
|||
|
&& typeof arg.fill === 'function'
|
|||
|
&& typeof arg.readUInt8 === 'function';
|
|||
|
}
|
|||
|
},{}],100:[function(_dereq_,module,exports){
|
|||
|
(function (process,global){
|
|||
|
// 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
|
|||
|
// persons to whom the Software is furnished to do so, subject to the
|
|||
|
// following conditions:
|
|||
|
//
|
|||
|
// The above copyright notice and this permission notice shall be included
|
|||
|
// in all copies or substantial portions of the Software.
|
|||
|
//
|
|||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|||
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|||
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|||
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
|
|||
|
var formatRegExp = /%[sdj%]/g;
|
|||
|
exports.format = function(f) {
|
|||
|
if (!isString(f)) {
|
|||
|
var objects = [];
|
|||
|
for (var i = 0; i < arguments.length; i++) {
|
|||
|
objects.push(inspect(arguments[i]));
|
|||
|
}
|
|||
|
return objects.join(' ');
|
|||
|
}
|
|||
|
|
|||
|
var i = 1;
|
|||
|
var args = arguments;
|
|||
|
var len = args.length;
|
|||
|
var str = String(f).replace(formatRegExp, function(x) {
|
|||
|
if (x === '%%') return '%';
|
|||
|
if (i >= len) return x;
|
|||
|
switch (x) {
|
|||
|
case '%s': return String(args[i++]);
|
|||
|
case '%d': return Number(args[i++]);
|
|||
|
case '%j':
|
|||
|
try {
|
|||
|
return JSON.stringify(args[i++]);
|
|||
|
} catch (_) {
|
|||
|
return '[Circular]';
|
|||
|
}
|
|||
|
default:
|
|||
|
return x;
|
|||
|
}
|
|||
|
});
|
|||
|
for (var x = args[i]; i < len; x = args[++i]) {
|
|||
|
if (isNull(x) || !isObject(x)) {
|
|||
|
str += ' ' + x;
|
|||
|
} else {
|
|||
|
str += ' ' + inspect(x);
|
|||
|
}
|
|||
|
}
|
|||
|
return str;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
// Mark that a method should not be used.
|
|||
|
// Returns a modified function which warns once by default.
|
|||
|
// If --no-deprecation is set, then it is a no-op.
|
|||
|
exports.deprecate = function(fn, msg) {
|
|||
|
// Allow for deprecating things in the process of starting up.
|
|||
|
if (isUndefined(global.process)) {
|
|||
|
return function() {
|
|||
|
return exports.deprecate(fn, msg).apply(this, arguments);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
if (process.noDeprecation === true) {
|
|||
|
return fn;
|
|||
|
}
|
|||
|
|
|||
|
var warned = false;
|
|||
|
function deprecated() {
|
|||
|
if (!warned) {
|
|||
|
if (process.throwDeprecation) {
|
|||
|
throw new Error(msg);
|
|||
|
} else if (process.traceDeprecation) {
|
|||
|
console.trace(msg);
|
|||
|
} else {
|
|||
|
console.error(msg);
|
|||
|
}
|
|||
|
warned = true;
|
|||
|
}
|
|||
|
return fn.apply(this, arguments);
|
|||
|
}
|
|||
|
|
|||
|
return deprecated;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
var debugs = {};
|
|||
|
var debugEnviron;
|
|||
|
exports.debuglog = function(set) {
|
|||
|
if (isUndefined(debugEnviron))
|
|||
|
debugEnviron = process.env.NODE_DEBUG || '';
|
|||
|
set = set.toUpperCase();
|
|||
|
if (!debugs[set]) {
|
|||
|
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
|
|||
|
var pid = process.pid;
|
|||
|
debugs[set] = function() {
|
|||
|
var msg = exports.format.apply(exports, arguments);
|
|||
|
console.error('%s %d: %s', set, pid, msg);
|
|||
|
};
|
|||
|
} else {
|
|||
|
debugs[set] = function() {};
|
|||
|
}
|
|||
|
}
|
|||
|
return debugs[set];
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Echos the value of a value. Trys to print the value out
|
|||
|
* in the best way possible given the different types.
|
|||
|
*
|
|||
|
* @param {Object} obj The object to print out.
|
|||
|
* @param {Object} opts Optional options object that alters the output.
|
|||
|
*/
|
|||
|
/* legacy: obj, showHidden, depth, colors*/
|
|||
|
function inspect(obj, opts) {
|
|||
|
// default options
|
|||
|
var ctx = {
|
|||
|
seen: [],
|
|||
|
stylize: stylizeNoColor
|
|||
|
};
|
|||
|
// legacy...
|
|||
|
if (arguments.length >= 3) ctx.depth = arguments[2];
|
|||
|
if (arguments.length >= 4) ctx.colors = arguments[3];
|
|||
|
if (isBoolean(opts)) {
|
|||
|
// legacy...
|
|||
|
ctx.showHidden = opts;
|
|||
|
} else if (opts) {
|
|||
|
// got an "options" object
|
|||
|
exports._extend(ctx, opts);
|
|||
|
}
|
|||
|
// set default options
|
|||
|
if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
|
|||
|
if (isUndefined(ctx.depth)) ctx.depth = 2;
|
|||
|
if (isUndefined(ctx.colors)) ctx.colors = false;
|
|||
|
if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
|
|||
|
if (ctx.colors) ctx.stylize = stylizeWithColor;
|
|||
|
return formatValue(ctx, obj, ctx.depth);
|
|||
|
}
|
|||
|
exports.inspect = inspect;
|
|||
|
|
|||
|
|
|||
|
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
|||
|
inspect.colors = {
|
|||
|
'bold' : [1, 22],
|
|||
|
'italic' : [3, 23],
|
|||
|
'underline' : [4, 24],
|
|||
|
'inverse' : [7, 27],
|
|||
|
'white' : [37, 39],
|
|||
|
'grey' : [90, 39],
|
|||
|
'black' : [30, 39],
|
|||
|
'blue' : [34, 39],
|
|||
|
'cyan' : [36, 39],
|
|||
|
'green' : [32, 39],
|
|||
|
'magenta' : [35, 39],
|
|||
|
'red' : [31, 39],
|
|||
|
'yellow' : [33, 39]
|
|||
|
};
|
|||
|
|
|||
|
// Don't use 'blue' not visible on cmd.exe
|
|||
|
inspect.styles = {
|
|||
|
'special': 'cyan',
|
|||
|
'number': 'yellow',
|
|||
|
'boolean': 'yellow',
|
|||
|
'undefined': 'grey',
|
|||
|
'null': 'bold',
|
|||
|
'string': 'green',
|
|||
|
'date': 'magenta',
|
|||
|
// "name": intentionally not styling
|
|||
|
'regexp': 'red'
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
function stylizeWithColor(str, styleType) {
|
|||
|
var style = inspect.styles[styleType];
|
|||
|
|
|||
|
if (style) {
|
|||
|
return '\u001b[' + inspect.colors[style][0] + 'm' + str +
|
|||
|
'\u001b[' + inspect.colors[style][1] + 'm';
|
|||
|
} else {
|
|||
|
return str;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function stylizeNoColor(str, styleType) {
|
|||
|
return str;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function arrayToHash(array) {
|
|||
|
var hash = {};
|
|||
|
|
|||
|
array.forEach(function(val, idx) {
|
|||
|
hash[val] = true;
|
|||
|
});
|
|||
|
|
|||
|
return hash;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function formatValue(ctx, value, recurseTimes) {
|
|||
|
// Provide a hook for user-specified inspect functions.
|
|||
|
// Check that value is an object with an inspect function on it
|
|||
|
if (ctx.customInspect &&
|
|||
|
value &&
|
|||
|
isFunction(value.inspect) &&
|
|||
|
// Filter out the util module, it's inspect function is special
|
|||
|
value.inspect !== exports.inspect &&
|
|||
|
// Also filter out any prototype objects using the circular check.
|
|||
|
!(value.constructor && value.constructor.prototype === value)) {
|
|||
|
var ret = value.inspect(recurseTimes, ctx);
|
|||
|
if (!isString(ret)) {
|
|||
|
ret = formatValue(ctx, ret, recurseTimes);
|
|||
|
}
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
// Primitive types cannot have properties
|
|||
|
var primitive = formatPrimitive(ctx, value);
|
|||
|
if (primitive) {
|
|||
|
return primitive;
|
|||
|
}
|
|||
|
|
|||
|
// Look up the keys of the object.
|
|||
|
var keys = Object.keys(value);
|
|||
|
var visibleKeys = arrayToHash(keys);
|
|||
|
|
|||
|
if (ctx.showHidden) {
|
|||
|
keys = Object.getOwnPropertyNames(value);
|
|||
|
}
|
|||
|
|
|||
|
// IE doesn't make error fields non-enumerable
|
|||
|
// http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
|
|||
|
if (isError(value)
|
|||
|
&& (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
|
|||
|
return formatError(value);
|
|||
|
}
|
|||
|
|
|||
|
// Some type of object without properties can be shortcutted.
|
|||
|
if (keys.length === 0) {
|
|||
|
if (isFunction(value)) {
|
|||
|
var name = value.name ? ': ' + value.name : '';
|
|||
|
return ctx.stylize('[Function' + name + ']', 'special');
|
|||
|
}
|
|||
|
if (isRegExp(value)) {
|
|||
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|||
|
}
|
|||
|
if (isDate(value)) {
|
|||
|
return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
|||
|
}
|
|||
|
if (isError(value)) {
|
|||
|
return formatError(value);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var base = '', array = false, braces = ['{', '}'];
|
|||
|
|
|||
|
// Make Array say that they are Array
|
|||
|
if (isArray(value)) {
|
|||
|
array = true;
|
|||
|
braces = ['[', ']'];
|
|||
|
}
|
|||
|
|
|||
|
// Make functions say that they are functions
|
|||
|
if (isFunction(value)) {
|
|||
|
var n = value.name ? ': ' + value.name : '';
|
|||
|
base = ' [Function' + n + ']';
|
|||
|
}
|
|||
|
|
|||
|
// Make RegExps say that they are RegExps
|
|||
|
if (isRegExp(value)) {
|
|||
|
base = ' ' + RegExp.prototype.toString.call(value);
|
|||
|
}
|
|||
|
|
|||
|
// Make dates with properties first say the date
|
|||
|
if (isDate(value)) {
|
|||
|
base = ' ' + Date.prototype.toUTCString.call(value);
|
|||
|
}
|
|||
|
|
|||
|
// Make error with message first say the error
|
|||
|
if (isError(value)) {
|
|||
|
base = ' ' + formatError(value);
|
|||
|
}
|
|||
|
|
|||
|
if (keys.length === 0 && (!array || value.length == 0)) {
|
|||
|
return braces[0] + base + braces[1];
|
|||
|
}
|
|||
|
|
|||
|
if (recurseTimes < 0) {
|
|||
|
if (isRegExp(value)) {
|
|||
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|||
|
} else {
|
|||
|
return ctx.stylize('[Object]', 'special');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
ctx.seen.push(value);
|
|||
|
|
|||
|
var output;
|
|||
|
if (array) {
|
|||
|
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
|||
|
} else {
|
|||
|
output = keys.map(function(key) {
|
|||
|
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
ctx.seen.pop();
|
|||
|
|
|||
|
return reduceToSingleString(output, base, braces);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function formatPrimitive(ctx, value) {
|
|||
|
if (isUndefined(value))
|
|||
|
return ctx.stylize('undefined', 'undefined');
|
|||
|
if (isString(value)) {
|
|||
|
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
|||
|
.replace(/'/g, "\\'")
|
|||
|
.replace(/\\"/g, '"') + '\'';
|
|||
|
return ctx.stylize(simple, 'string');
|
|||
|
}
|
|||
|
if (isNumber(value))
|
|||
|
return ctx.stylize('' + value, 'number');
|
|||
|
if (isBoolean(value))
|
|||
|
return ctx.stylize('' + value, 'boolean');
|
|||
|
// For some reason typeof null is "object", so special case here.
|
|||
|
if (isNull(value))
|
|||
|
return ctx.stylize('null', 'null');
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function formatError(value) {
|
|||
|
return '[' + Error.prototype.toString.call(value) + ']';
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
|||
|
var output = [];
|
|||
|
for (var i = 0, l = value.length; i < l; ++i) {
|
|||
|
if (hasOwnProperty(value, String(i))) {
|
|||
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|||
|
String(i), true));
|
|||
|
} else {
|
|||
|
output.push('');
|
|||
|
}
|
|||
|
}
|
|||
|
keys.forEach(function(key) {
|
|||
|
if (!key.match(/^\d+$/)) {
|
|||
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|||
|
key, true));
|
|||
|
}
|
|||
|
});
|
|||
|
return output;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
|||
|
var name, str, desc;
|
|||
|
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
|||
|
if (desc.get) {
|
|||
|
if (desc.set) {
|
|||
|
str = ctx.stylize('[Getter/Setter]', 'special');
|
|||
|
} else {
|
|||
|
str = ctx.stylize('[Getter]', 'special');
|
|||
|
}
|
|||
|
} else {
|
|||
|
if (desc.set) {
|
|||
|
str = ctx.stylize('[Setter]', 'special');
|
|||
|
}
|
|||
|
}
|
|||
|
if (!hasOwnProperty(visibleKeys, key)) {
|
|||
|
name = '[' + key + ']';
|
|||
|
}
|
|||
|
if (!str) {
|
|||
|
if (ctx.seen.indexOf(desc.value) < 0) {
|
|||
|
if (isNull(recurseTimes)) {
|
|||
|
str = formatValue(ctx, desc.value, null);
|
|||
|
} else {
|
|||
|
str = formatValue(ctx, desc.value, recurseTimes - 1);
|
|||
|
}
|
|||
|
if (str.indexOf('\n') > -1) {
|
|||
|
if (array) {
|
|||
|
str = str.split('\n').map(function(line) {
|
|||
|
return ' ' + line;
|
|||
|
}).join('\n').substr(2);
|
|||
|
} else {
|
|||
|
str = '\n' + str.split('\n').map(function(line) {
|
|||
|
return ' ' + line;
|
|||
|
}).join('\n');
|
|||
|
}
|
|||
|
}
|
|||
|
} else {
|
|||
|
str = ctx.stylize('[Circular]', 'special');
|
|||
|
}
|
|||
|
}
|
|||
|
if (isUndefined(name)) {
|
|||
|
if (array && key.match(/^\d+$/)) {
|
|||
|
return str;
|
|||
|
}
|
|||
|
name = JSON.stringify('' + key);
|
|||
|
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
|||
|
name = name.substr(1, name.length - 2);
|
|||
|
name = ctx.stylize(name, 'name');
|
|||
|
} else {
|
|||
|
name = name.replace(/'/g, "\\'")
|
|||
|
.replace(/\\"/g, '"')
|
|||
|
.replace(/(^"|"$)/g, "'");
|
|||
|
name = ctx.stylize(name, 'string');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return name + ': ' + str;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function reduceToSingleString(output, base, braces) {
|
|||
|
var numLinesEst = 0;
|
|||
|
var length = output.reduce(function(prev, cur) {
|
|||
|
numLinesEst++;
|
|||
|
if (cur.indexOf('\n') >= 0) numLinesEst++;
|
|||
|
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
|
|||
|
}, 0);
|
|||
|
|
|||
|
if (length > 60) {
|
|||
|
return braces[0] +
|
|||
|
(base === '' ? '' : base + '\n ') +
|
|||
|
' ' +
|
|||
|
output.join(',\n ') +
|
|||
|
' ' +
|
|||
|
braces[1];
|
|||
|
}
|
|||
|
|
|||
|
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// NOTE: These type checking functions intentionally don't use `instanceof`
|
|||
|
// because it is fragile and can be easily faked with `Object.create()`.
|
|||
|
function isArray(ar) {
|
|||
|
return Array.isArray(ar);
|
|||
|
}
|
|||
|
exports.isArray = isArray;
|
|||
|
|
|||
|
function isBoolean(arg) {
|
|||
|
return typeof arg === 'boolean';
|
|||
|
}
|
|||
|
exports.isBoolean = isBoolean;
|
|||
|
|
|||
|
function isNull(arg) {
|
|||
|
return arg === null;
|
|||
|
}
|
|||
|
exports.isNull = isNull;
|
|||
|
|
|||
|
function isNullOrUndefined(arg) {
|
|||
|
return arg == null;
|
|||
|
}
|
|||
|
exports.isNullOrUndefined = isNullOrUndefined;
|
|||
|
|
|||
|
function isNumber(arg) {
|
|||
|
return typeof arg === 'number';
|
|||
|
}
|
|||
|
exports.isNumber = isNumber;
|
|||
|
|
|||
|
function isString(arg) {
|
|||
|
return typeof arg === 'string';
|
|||
|
}
|
|||
|
exports.isString = isString;
|
|||
|
|
|||
|
function isSymbol(arg) {
|
|||
|
return typeof arg === 'symbol';
|
|||
|
}
|
|||
|
exports.isSymbol = isSymbol;
|
|||
|
|
|||
|
function isUndefined(arg) {
|
|||
|
return arg === void 0;
|
|||
|
}
|
|||
|
exports.isUndefined = isUndefined;
|
|||
|
|
|||
|
function isRegExp(re) {
|
|||
|
return isObject(re) && objectToString(re) === '[object RegExp]';
|
|||
|
}
|
|||
|
exports.isRegExp = isRegExp;
|
|||
|
|
|||
|
function isObject(arg) {
|
|||
|
return typeof arg === 'object' && arg !== null;
|
|||
|
}
|
|||
|
exports.isObject = isObject;
|
|||
|
|
|||
|
function isDate(d) {
|
|||
|
return isObject(d) && objectToString(d) === '[object Date]';
|
|||
|
}
|
|||
|
exports.isDate = isDate;
|
|||
|
|
|||
|
function isError(e) {
|
|||
|
return isObject(e) &&
|
|||
|
(objectToString(e) === '[object Error]' || e instanceof Error);
|
|||
|
}
|
|||
|
exports.isError = isError;
|
|||
|
|
|||
|
function isFunction(arg) {
|
|||
|
return typeof arg === 'function';
|
|||
|
}
|
|||
|
exports.isFunction = isFunction;
|
|||
|
|
|||
|
function isPrimitive(arg) {
|
|||
|
return arg === null ||
|
|||
|
typeof arg === 'boolean' ||
|
|||
|
typeof arg === 'number' ||
|
|||
|
typeof arg === 'string' ||
|
|||
|
typeof arg === 'symbol' || // ES6 symbol
|
|||
|
typeof arg === 'undefined';
|
|||
|
}
|
|||
|
exports.isPrimitive = isPrimitive;
|
|||
|
|
|||
|
exports.isBuffer = _dereq_('./support/isBuffer');
|
|||
|
|
|||
|
function objectToString(o) {
|
|||
|
return Object.prototype.toString.call(o);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function pad(n) {
|
|||
|
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
|||
|
'Oct', 'Nov', 'Dec'];
|
|||
|
|
|||
|
// 26 Feb 16:19:34
|
|||
|
function timestamp() {
|
|||
|
var d = new Date();
|
|||
|
var time = [pad(d.getHours()),
|
|||
|
pad(d.getMinutes()),
|
|||
|
pad(d.getSeconds())].join(':');
|
|||
|
return [d.getDate(), months[d.getMonth()], time].join(' ');
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// log is just a thin wrapper to console.log that prepends a timestamp
|
|||
|
exports.log = function() {
|
|||
|
console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Inherit the prototype methods from one constructor into another.
|
|||
|
*
|
|||
|
* The Function.prototype.inherits from lang.js rewritten as a standalone
|
|||
|
* function (not on Function.prototype). NOTE: If this file is to be loaded
|
|||
|
* during bootstrapping this function needs to be rewritten using some native
|
|||
|
* functions as prototype setup using normal JavaScript does not work as
|
|||
|
* expected during bootstrapping (see mirror.js in r114903).
|
|||
|
*
|
|||
|
* @param {function} ctor Constructor function which needs to inherit the
|
|||
|
* prototype.
|
|||
|
* @param {function} superCtor Constructor function to inherit prototype from.
|
|||
|
*/
|
|||
|
exports.inherits = _dereq_('inherits');
|
|||
|
|
|||
|
exports._extend = function(origin, add) {
|
|||
|
// Don't do anything if add isn't an object
|
|||
|
if (!add || !isObject(add)) return origin;
|
|||
|
|
|||
|
var keys = Object.keys(add);
|
|||
|
var i = keys.length;
|
|||
|
while (i--) {
|
|||
|
origin[keys[i]] = add[keys[i]];
|
|||
|
}
|
|||
|
return origin;
|
|||
|
};
|
|||
|
|
|||
|
function hasOwnProperty(obj, prop) {
|
|||
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|||
|
}
|
|||
|
|
|||
|
}).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|||
|
},{"./support/isBuffer":99,"_process":94,"inherits":75}]},{},[1])(1)
|
|||
|
});
|