UI for Zipcoin Blue

pluginutils.es.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. import { extname, resolve, sep } from 'path';
  2. import { walk } from 'estree-walker';
  3. import mm from 'micromatch';
  4. function addExtension ( filename, ext ) {
  5. if ( ext === void 0 ) ext = '.js';
  6. if ( !extname( filename ) ) { filename += ext; }
  7. return filename;
  8. }
  9. var blockDeclarations = {
  10. 'const': true,
  11. 'let': true
  12. };
  13. var extractors = {
  14. Literal: function Literal ( names, param ) {
  15. names.push( param.value );
  16. },
  17. Identifier: function Identifier ( names, param ) {
  18. names.push( param.name );
  19. },
  20. ObjectPattern: function ObjectPattern ( names, param ) {
  21. param.properties.forEach( function (prop) {
  22. extractors[ (prop.value || prop.key).type ]( names, prop.value || prop.key );
  23. });
  24. },
  25. ArrayPattern: function ArrayPattern ( names, param ) {
  26. param.elements.forEach( function (element) {
  27. if ( element ) { extractors[ element.type ]( names, element ); }
  28. });
  29. },
  30. RestElement: function RestElement ( names, param ) {
  31. extractors[ param.argument.type ]( names, param.argument );
  32. },
  33. AssignmentPattern: function AssignmentPattern ( names, param ) {
  34. return extractors[ param.left.type ]( names, param.left );
  35. }
  36. };
  37. function extractNames ( param ) {
  38. var names = [];
  39. extractors[ param.type ]( names, param );
  40. return names;
  41. }
  42. var Scope = function Scope ( options ) {
  43. var this$1 = this;
  44. options = options || {};
  45. this.parent = options.parent;
  46. this.isBlockScope = !!options.block;
  47. this.declarations = Object.create( null );
  48. if ( options.params ) {
  49. options.params.forEach( function (param) {
  50. extractNames( param ).forEach( function (name) {
  51. this$1.declarations[ name ] = true;
  52. });
  53. });
  54. }
  55. };
  56. Scope.prototype.addDeclaration = function addDeclaration ( node, isBlockDeclaration, isVar ) {
  57. var this$1 = this;
  58. if ( !isBlockDeclaration && this.isBlockScope ) {
  59. // it's a `var` or function node, and this
  60. // is a block scope, so we need to go up
  61. this.parent.addDeclaration( node, isBlockDeclaration, isVar );
  62. } else if ( node.id ) {
  63. extractNames( node.id ).forEach( function (name) {
  64. this$1.declarations[ name ] = true;
  65. });
  66. }
  67. };
  68. Scope.prototype.contains = function contains ( name ) {
  69. return this.declarations[ name ] ||
  70. ( this.parent ? this.parent.contains( name ) : false );
  71. };
  72. function attachScopes ( ast, propertyName ) {
  73. if ( propertyName === void 0 ) propertyName = 'scope';
  74. var scope = new Scope();
  75. walk( ast, {
  76. enter: function enter ( node, parent ) {
  77. // function foo () {...}
  78. // class Foo {...}
  79. if ( /(Function|Class)Declaration/.test( node.type ) ) {
  80. scope.addDeclaration( node, false, false );
  81. }
  82. // var foo = 1
  83. if ( node.type === 'VariableDeclaration' ) {
  84. var isBlockDeclaration = blockDeclarations[ node.kind ];
  85. node.declarations.forEach( function (declaration) {
  86. scope.addDeclaration( declaration, isBlockDeclaration, true );
  87. });
  88. }
  89. var newScope;
  90. // create new function scope
  91. if ( /Function/.test( node.type ) ) {
  92. newScope = new Scope({
  93. parent: scope,
  94. block: false,
  95. params: node.params
  96. });
  97. // named function expressions - the name is considered
  98. // part of the function's scope
  99. if ( node.type === 'FunctionExpression' && node.id ) {
  100. newScope.addDeclaration( node, false, false );
  101. }
  102. }
  103. // create new block scope
  104. if ( node.type === 'BlockStatement' && !/Function/.test( parent.type ) ) {
  105. newScope = new Scope({
  106. parent: scope,
  107. block: true
  108. });
  109. }
  110. // catch clause has its own block scope
  111. if ( node.type === 'CatchClause' ) {
  112. newScope = new Scope({
  113. parent: scope,
  114. params: [ node.param ],
  115. block: true
  116. });
  117. }
  118. if ( newScope ) {
  119. Object.defineProperty( node, propertyName, {
  120. value: newScope,
  121. configurable: true
  122. });
  123. scope = newScope;
  124. }
  125. },
  126. leave: function leave ( node ) {
  127. if ( node[ propertyName ] ) { scope = scope.parent; }
  128. }
  129. });
  130. return scope;
  131. }
  132. function ensureArray ( thing ) {
  133. if ( Array.isArray( thing ) ) { return thing; }
  134. if ( thing == undefined ) { return []; }
  135. return [ thing ];
  136. }
  137. function createFilter ( include, exclude ) {
  138. var getMatcher = function (id) { return ( isRegexp( id ) ? id : { test: mm.matcher( resolve( id ) ) } ); };
  139. include = ensureArray( include ).map( getMatcher );
  140. exclude = ensureArray( exclude ).map( getMatcher );
  141. return function ( id ) {
  142. if ( typeof id !== 'string' ) { return false; }
  143. if ( /\0/.test( id ) ) { return false; }
  144. id = id.split( sep ).join( '/' );
  145. for ( var i = 0; i < exclude.length; ++i ) {
  146. var matcher = exclude[i];
  147. if ( matcher.test( id ) ) { return false; }
  148. }
  149. for ( var i$1 = 0; i$1 < include.length; ++i$1 ) {
  150. var matcher$1 = include[i$1];
  151. if ( matcher$1.test( id ) ) { return true; }
  152. }
  153. return !include.length;
  154. };
  155. }
  156. function isRegexp ( val ) {
  157. return val instanceof RegExp;
  158. }
  159. var reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split( ' ' );
  160. var builtins = 'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split( ' ' );
  161. var blacklisted = Object.create( null );
  162. reservedWords.concat( builtins ).forEach( function (word) { return blacklisted[ word ] = true; } );
  163. function makeLegalIdentifier ( str ) {
  164. str = str
  165. .replace( /-(\w)/g, function ( _, letter ) { return letter.toUpperCase(); } )
  166. .replace( /[^$_a-zA-Z0-9]/g, '_' );
  167. if ( /\d/.test( str[0] ) || blacklisted[ str ] ) { str = "_" + str; }
  168. return str;
  169. }
  170. function serializeArray (arr, indent, baseIndent) {
  171. var output = '[';
  172. var separator = indent ? '\n' + baseIndent + indent : '';
  173. for (var i = 0; i < arr.length; i++) {
  174. var key = arr[i];
  175. output += "" + (i > 0 ? ',' : '') + separator + (serialize(key, indent, baseIndent + indent));
  176. }
  177. return output + (indent ? '\n' + baseIndent : '') + "]";
  178. }
  179. function serializeObject (obj, indent, baseIndent) {
  180. var output = '{';
  181. var separator = indent ? '\n' + baseIndent + indent : '';
  182. var keys = Object.keys(obj);
  183. for (var i = 0; i < keys.length; i++) {
  184. var key = keys[i];
  185. var stringKey = makeLegalIdentifier(key) === key ? key : JSON.stringify(key);
  186. output += "" + (i > 0 ? ',' : '') + separator + stringKey + ":" + (indent ? ' ' : '') + (serialize(obj[key], indent, baseIndent + indent));
  187. }
  188. return output + (indent ? '\n' + baseIndent : '') + "}";
  189. }
  190. function serialize (obj, indent, baseIndent) {
  191. if (obj === Infinity)
  192. { return 'Infinity'; }
  193. if (obj instanceof Date)
  194. { return 'new Date(' + obj.getTime() + ')'; }
  195. if (obj instanceof RegExp)
  196. { return obj.toString(); }
  197. if (typeof obj === 'number' && isNaN(obj))
  198. { return 'NaN'; }
  199. if (Array.isArray(obj))
  200. { return serializeArray(obj, indent, baseIndent); }
  201. if (obj === null)
  202. { return 'null'; }
  203. if (typeof obj === 'object')
  204. { return serializeObject(obj, indent, baseIndent); }
  205. return JSON.stringify(obj);
  206. }
  207. // convert data object into separate named exports (and default)
  208. function dataToNamedExports (data, options) {
  209. if ( options === void 0 ) options = {};
  210. var t = options.compact ? '' : 'indent' in options ? options.indent : '\t';
  211. var _ = options.compact ? '' : ' ';
  212. var n = options.compact ? '' : '\n';
  213. var declarationType = options.preferConst ? 'const' : 'var';
  214. if (options.namedExports === false || typeof data !== 'object' || Array.isArray(data) || data === null)
  215. { return ("export default" + _ + (serialize( data, options.compact ? null : t, '' )) + ";"); }
  216. var namedExportCode = '';
  217. var defaultExportRows = [];
  218. var dataKeys = Object.keys(data);
  219. for (var i = 0; i < dataKeys.length; i++) {
  220. var key = dataKeys[i];
  221. if (key === makeLegalIdentifier(key)) {
  222. if (options.objectShorthand)
  223. { defaultExportRows.push(key); }
  224. else
  225. { defaultExportRows.push((key + ":" + _ + key)); }
  226. namedExportCode += "export " + declarationType + " " + key + _ + "=" + _ + (serialize(data[key], options.compact ? null : t, '')) + ";" + n;
  227. } else {
  228. defaultExportRows.push(((JSON.stringify(key)) + ": " + (serialize(data[key], options.compact ? null : t, ''))));
  229. }
  230. }
  231. return namedExportCode + "export default" + _ + "{" + n + t + (defaultExportRows.join(("," + n + t))) + n + "};" + n;
  232. }
  233. export { addExtension, attachScopes, createFilter, makeLegalIdentifier, dataToNamedExports as dataToEsm };