securemark 0.262.0 → 0.262.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.262.1
4
+
5
+ - Refactoring.
6
+
3
7
  ## 0.262.0
4
8
 
5
9
  - Use :has() CSS selector.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.262.0 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.262.1 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("DOMPurify"), require("Prism"));
@@ -130,7 +130,7 @@ function push(as, bs) {
130
130
  if (bs.length === 1) return as.push(bs[0]), as;
131
131
  if (global_1.Symbol.iterator in bs && bs.length > 50) return as.push(...bs), as;
132
132
 
133
- for (let i = 0, len = bs.length; i < len; ++i) {
133
+ for (let len = bs.length, i = 0; i < len; ++i) {
134
134
  as.push(bs[i]);
135
135
  }
136
136
  } else {
@@ -772,7 +772,7 @@ function rate(window, hits1, hits2, offset) {
772
772
  let hits = 0;
773
773
  let ratio = 100;
774
774
 
775
- for (let i = 0, len = hits1.length; i < len; ++i) {
775
+ for (let len = hits1.length, i = 0; i < len; ++i) {
776
776
  const subtotal = hits1[i] + hits2[i];
777
777
  if (subtotal === 0) continue;
778
778
  offset = i + 1 === len ? 0 : offset;
@@ -1709,26 +1709,25 @@ const undefined = void 0;
1709
1709
 
1710
1710
  function memoize(f, identify = (...as) => as[0], memory) {
1711
1711
  if (typeof identify === 'object') return memoize(f, undefined, identify);
1712
- if (memory === undefined) return memoize(f, identify, new global_1.Map());
1713
- if ((0, alias_1.isArray)(memory)) return memoize(f, identify, {
1714
- has(key) {
1715
- return memory[key] !== undefined;
1716
- },
1717
-
1718
- get(key) {
1719
- return memory[key];
1720
- },
1712
+ return (0, alias_1.isArray)(memory) ? memoizeArray(f, identify, memory) : memoizeObject(f, identify, memory ?? new global_1.Map());
1713
+ }
1721
1714
 
1722
- set(key, value) {
1723
- memory[key] = value;
1724
- return this;
1725
- },
1715
+ exports.memoize = memoize;
1726
1716
 
1727
- delete() {
1728
- throw 0;
1729
- }
1717
+ function memoizeArray(f, identify, memory) {
1718
+ let nullish = false;
1719
+ return (...as) => {
1720
+ const b = identify(...as);
1721
+ let z = memory[b];
1722
+ if (z !== undefined || nullish && memory[b] !== undefined) return z;
1723
+ z = f(...as);
1724
+ nullish ||= z === undefined;
1725
+ memory[b] = z;
1726
+ return z;
1727
+ };
1728
+ }
1730
1729
 
1731
- });
1730
+ function memoizeObject(f, identify, memory) {
1732
1731
  let nullish = false;
1733
1732
  return (...as) => {
1734
1733
  const b = identify(...as);
@@ -1741,8 +1740,6 @@ function memoize(f, identify = (...as) => as[0], memory) {
1741
1740
  };
1742
1741
  }
1743
1742
 
1744
- exports.memoize = memoize;
1745
-
1746
1743
  function reduce(f, identify = (...as) => as[0]) {
1747
1744
  let key = {};
1748
1745
  let val;
@@ -2016,9 +2013,10 @@ exports.unique = exports.rndAf = exports.rndAP = exports.rnd0_ = exports.rnd0Z =
2016
2013
 
2017
2014
  const global_1 = __webpack_require__(4128);
2018
2015
 
2019
- const bases = [...Array(7)].map((_, i) => 1 << i);
2020
- const dict0_ = [...[...Array(36)].map((_, i) => i.toString(36)), ...[...Array(36)].map((_, i) => i.toString(36).toUpperCase()).slice(-26), '-', '_'];
2021
- const dictAz = [...[...Array(36)].map((_, i) => i.toString(36).toUpperCase()).slice(-26), ...[...Array(36)].map((_, i) => i.toString(36)).slice(-26)];
2016
+ const radixes = Object.freeze([...Array(7)].map((_, i) => 1 << i));
2017
+ const masks = Object.freeze(radixes.map(radix => radix - 1));
2018
+ const dict0_ = Object.freeze([...[...Array(36)].map((_, i) => i.toString(36)), ...[...Array(36)].map((_, i) => i.toString(36).toUpperCase()).slice(-26), '-', '_']);
2019
+ const dictAz = Object.freeze([...[...Array(36)].map((_, i) => i.toString(36).toUpperCase()).slice(-26), ...[...Array(36)].map((_, i) => i.toString(36)).slice(-26)]);
2022
2020
  exports.rnd16 = cons(16);
2023
2021
  exports.rnd32 = cons(32);
2024
2022
  exports.rnd62 = cons(62);
@@ -2030,38 +2028,54 @@ exports.rnd0_ = conv(exports.rnd64, dict0_);
2030
2028
  exports.rndAP = conv(exports.rnd16, dictAz);
2031
2029
  exports.rndAf = conv(exports.rnd32, dictAz);
2032
2030
 
2033
- function unique(rnd, len, mem) {
2034
- const clear = !mem;
2031
+ function unique(rnd, len = 1, mem) {
2032
+ const independence = !mem;
2035
2033
  mem ??= new global_1.Set();
2036
- let limit = 5;
2037
- return () => {
2038
- while (true) {
2034
+ const trials = 3;
2035
+ let prefixes;
2036
+ let prefix = '';
2037
+ return function random() {
2038
+ for (let i = 0; i < trials; ++i) {
2039
+ const r = rnd(len);
2040
+ if (mem.has(r)) continue;
2041
+
2039
2042
  try {
2040
- for (let i = 0; i < limit; ++i) {
2041
- const r = rnd(len);
2042
- if (mem.has(r)) continue;
2043
- mem.add(r);
2044
- return r;
2043
+ mem.add(r);
2044
+ } catch (reason) {
2045
+ // ベンチマーク程度でもSetがパンクする場合がある。
2046
+ if (!independence) throw reason;
2047
+ prefixes ??= new global_1.Set();
2048
+ prefix ||= '?';
2049
+
2050
+ for (let i = 0; i < trials; ++i) {
2051
+ prefix = rnd(prefix.length);
2052
+ if (prefixes.has(prefix)) continue;
2053
+ prefixes.add(prefix);
2054
+ mem.clear();
2055
+ return random();
2045
2056
  }
2046
- } catch {}
2047
2057
 
2048
- clear && mem.clear();
2049
- ++len;
2050
- limit = len < 3 ? limit : 3;
2058
+ prefixes = new global_1.Set();
2059
+ prefix += '?';
2060
+ return random();
2061
+ }
2062
+
2063
+ return prefix + r;
2051
2064
  }
2065
+
2066
+ ++len;
2067
+ independence && mem.clear();
2068
+ return random();
2052
2069
  };
2053
2070
  }
2054
2071
 
2055
2072
  exports.unique = unique;
2056
2073
 
2057
- function cons(radix) {
2058
- const base = bases.find(base => base >= radix);
2059
- const len = bases.indexOf(base);
2060
- return () => {
2061
- while (true) {
2062
- const r = random(len);
2063
- if (r < radix) return r;
2064
- }
2074
+ function cons(size) {
2075
+ const len = radixes.findIndex(radix => radix >= size);
2076
+ return function rnd() {
2077
+ const r = random(len);
2078
+ return r < size ? r : rnd();
2065
2079
  };
2066
2080
  }
2067
2081
 
@@ -2079,7 +2093,6 @@ function conv(rnd, dict) {
2079
2093
 
2080
2094
  const buffer = new Uint16Array(512);
2081
2095
  const digit = 16;
2082
- const masks = bases.map((_, i) => +`0b${'1'.repeat(i) || 0}`);
2083
2096
  let index = buffer.length;
2084
2097
  let offset = digit;
2085
2098
 
@@ -2342,7 +2355,7 @@ function prev(head, tail, length) {
2342
2355
  Object.defineProperty(exports, "__esModule", ({
2343
2356
  value: true
2344
2357
  }));
2345
- exports.isPrimitive = exports.isType = exports.type = void 0;
2358
+ exports.isPrimitive = exports.is = exports.type = void 0;
2346
2359
 
2347
2360
  const global_1 = __webpack_require__(4128);
2348
2361
 
@@ -2352,35 +2365,64 @@ const ObjectPrototype = Object.prototype;
2352
2365
  const ArrayPrototype = Array.prototype;
2353
2366
 
2354
2367
  function type(value) {
2355
- if (value === void 0) return 'undefined';
2356
- if (value === null) return 'null';
2357
2368
  const type = typeof value;
2358
2369
 
2359
- if (type === 'object') {
2360
- if (value[global_1.Symbol.toStringTag]) return value[global_1.Symbol.toStringTag];
2361
- const proto = (0, alias_1.ObjectGetPrototypeOf)(value);
2362
- if (proto === ObjectPrototype) return 'Object';
2363
- if (proto === ArrayPrototype) return 'Array';
2364
- return (0, alias_1.toString)(value).slice(8, -1);
2365
- }
2370
+ switch (type) {
2371
+ case 'function':
2372
+ return 'Function';
2366
2373
 
2367
- if (type === 'function') return 'Function';
2368
- return type;
2374
+ case 'object':
2375
+ if (value === null) return 'null';
2376
+ const tag = value[global_1.Symbol.toStringTag];
2377
+ if (tag) return tag;
2378
+
2379
+ switch ((0, alias_1.ObjectGetPrototypeOf)(value)) {
2380
+ case ArrayPrototype:
2381
+ return 'Array';
2382
+
2383
+ case ObjectPrototype:
2384
+ return 'Object';
2385
+
2386
+ default:
2387
+ return (0, alias_1.toString)(value).slice(8, -1);
2388
+ }
2389
+
2390
+ default:
2391
+ return type;
2392
+ }
2369
2393
  }
2370
2394
 
2371
2395
  exports.type = type;
2372
2396
 
2373
- function isType(value, name) {
2374
- if (name === 'object') return value !== null && typeof value === name;
2375
- if (name === 'function') return typeof value === name;
2376
- return type(value) === name;
2397
+ function is(type, value) {
2398
+ switch (type) {
2399
+ case 'null':
2400
+ return value === null;
2401
+
2402
+ case 'array':
2403
+ return (0, alias_1.isArray)(value);
2404
+
2405
+ case 'object':
2406
+ return value !== null && typeof value === type;
2407
+
2408
+ default:
2409
+ return typeof value === type;
2410
+ }
2377
2411
  }
2378
2412
 
2379
- exports.isType = isType;
2413
+ exports.is = is;
2380
2414
 
2381
2415
  function isPrimitive(value) {
2382
- const type = typeof value;
2383
- return type === 'object' || type === 'function' ? value === null : true;
2416
+ switch (typeof value) {
2417
+ case 'function':
2418
+ return false;
2419
+
2420
+ case 'object':
2421
+ return value === null;
2422
+
2423
+ default:
2424
+ return true;
2425
+ }
2384
2426
  }
2385
2427
 
2386
2428
  exports.isPrimitive = isPrimitive;
@@ -2805,7 +2847,7 @@ const parser_1 = __webpack_require__(6728);
2805
2847
  function validate(patterns, has, parser) {
2806
2848
  if (typeof has === 'function') return validate(patterns, '', has);
2807
2849
  if (!(0, alias_1.isArray)(patterns)) return validate([patterns], has, parser);
2808
- const match = (0, global_1.Function)(['"use strict";', 'return source =>', '0', ...patterns.map(pattern => typeof pattern === 'string' ? `|| source.slice(0, ${pattern.length}) === '${pattern}'` : `|| /${pattern.source}/${pattern.flags}.test(source)`)].join(''))();
2850
+ const match = global_1.global.eval(['source =>', patterns.map(pattern => typeof pattern === 'string' ? `|| source.slice(0, ${pattern.length}) === '${pattern}'` : `|| /${pattern.source}/${pattern.flags}.test(source)`).join('').slice(2)].join(''));
2809
2851
  return ({
2810
2852
  source,
2811
2853
  context
@@ -4112,8 +4154,20 @@ function union(parsers) {
4112
4154
  case 1:
4113
4155
  return parsers[0];
4114
4156
 
4157
+ case 2:
4158
+ return input => parsers[0](input) ?? parsers[1](input);
4159
+
4160
+ case 3:
4161
+ return input => parsers[0](input) ?? parsers[1](input) ?? parsers[2](input);
4162
+
4115
4163
  default:
4116
- return (0, global_1.Function)('parsers', ['"use strict";', 'return (input, context) =>', '0', ...parsers.map((_, i) => `|| parsers[${i}](input, context)`)].join('\n'))(parsers);
4164
+ return input => {
4165
+ for (let i = 0; i < parsers.length; ++i) {
4166
+ const parser = parsers[i];
4167
+ const result = parser(input);
4168
+ if (result) return result;
4169
+ }
4170
+ };
4117
4171
  }
4118
4172
  }
4119
4173
 
@@ -10053,7 +10107,7 @@ function unlink(h) {
10053
10107
  /***/ 3252:
10054
10108
  /***/ (function(module) {
10055
10109
 
10056
- /*! typed-dom v0.0.305 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
10110
+ /*! typed-dom v0.0.307 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
10057
10111
  (function webpackUniversalModuleDefinition(root, factory) {
10058
10112
  if(true)
10059
10113
  module.exports = factory();
@@ -10145,45 +10199,44 @@ const alias_1 = __nested_webpack_require_3232__(406);
10145
10199
 
10146
10200
  const compare_1 = __nested_webpack_require_3232__(529);
10147
10201
 
10148
- function memoize(f, identify = (...as) => as[0], memory) {
10149
- if (typeof identify === 'object') return memoize(f, void 0, identify);
10150
- if (memory === void 0) return memoize(f, identify, new global_1.Map());
10151
- if ((0, alias_1.isArray)(memory)) return memoize(f, identify, {
10152
- has(key) {
10153
- return memory[key] !== void 0;
10154
- },
10202
+ const undefined = void 0;
10155
10203
 
10156
- get(key) {
10157
- return memory[key];
10158
- },
10204
+ function memoize(f, identify = (...as) => as[0], memory) {
10205
+ if (typeof identify === 'object') return memoize(f, undefined, identify);
10206
+ return (0, alias_1.isArray)(memory) ? memoizeArray(f, identify, memory) : memoizeObject(f, identify, memory ?? new global_1.Map());
10207
+ }
10159
10208
 
10160
- set(key, value) {
10161
- memory[key] = value;
10162
- return this;
10163
- },
10209
+ exports.memoize = memoize;
10164
10210
 
10165
- delete() {
10166
- throw 0;
10167
- }
10211
+ function memoizeArray(f, identify, memory) {
10212
+ let nullish = false;
10213
+ return (...as) => {
10214
+ const b = identify(...as);
10215
+ let z = memory[b];
10216
+ if (z !== undefined || nullish && memory[b] !== undefined) return z;
10217
+ z = f(...as);
10218
+ nullish ||= z === undefined;
10219
+ memory[b] = z;
10220
+ return z;
10221
+ };
10222
+ }
10168
10223
 
10169
- });
10224
+ function memoizeObject(f, identify, memory) {
10170
10225
  let nullish = false;
10171
10226
  return (...as) => {
10172
10227
  const b = identify(...as);
10173
10228
  let z = memory.get(b);
10174
- if (z !== void 0 || nullish && memory.has(b)) return z;
10229
+ if (z !== undefined || nullish && memory.has(b)) return z;
10175
10230
  z = f(...as);
10176
- nullish ||= z === void 0;
10231
+ nullish ||= z === undefined;
10177
10232
  memory.set(b, z);
10178
10233
  return z;
10179
10234
  };
10180
10235
  }
10181
10236
 
10182
- exports.memoize = memoize;
10183
-
10184
10237
  function reduce(f, identify = (...as) => as[0]) {
10185
- let key = [];
10186
- let val = [];
10238
+ let key = {};
10239
+ let val;
10187
10240
  return (...as) => {
10188
10241
  const b = identify(...as);
10189
10242
 
@@ -10201,7 +10254,7 @@ exports.reduce = reduce;
10201
10254
  /***/ }),
10202
10255
 
10203
10256
  /***/ 521:
10204
- /***/ ((__unused_webpack_module, exports, __nested_webpack_require_4622__) => {
10257
+ /***/ ((__unused_webpack_module, exports, __nested_webpack_require_4777__) => {
10205
10258
 
10206
10259
 
10207
10260
 
@@ -10210,11 +10263,11 @@ Object.defineProperty(exports, "__esModule", ({
10210
10263
  }));
10211
10264
  exports.defrag = exports.prepend = exports.append = exports.isChildren = exports.define = exports.element = exports.text = exports.svg = exports.html = exports.frag = exports.shadow = void 0;
10212
10265
 
10213
- const global_1 = __nested_webpack_require_4622__(128);
10266
+ const global_1 = __nested_webpack_require_4777__(128);
10214
10267
 
10215
- const alias_1 = __nested_webpack_require_4622__(406);
10268
+ const alias_1 = __nested_webpack_require_4777__(406);
10216
10269
 
10217
- const memoize_1 = __nested_webpack_require_4622__(808);
10270
+ const memoize_1 = __nested_webpack_require_4777__(808);
10218
10271
 
10219
10272
  var caches;
10220
10273
 
@@ -10449,7 +10502,7 @@ exports.defrag = defrag;
10449
10502
  /******/ var __webpack_module_cache__ = {};
10450
10503
  /******/
10451
10504
  /******/ // The require function
10452
- /******/ function __nested_webpack_require_11575__(moduleId) {
10505
+ /******/ function __nested_webpack_require_11730__(moduleId) {
10453
10506
  /******/ // Check if module is in cache
10454
10507
  /******/ var cachedModule = __webpack_module_cache__[moduleId];
10455
10508
  /******/ if (cachedModule !== undefined) {
@@ -10463,7 +10516,7 @@ exports.defrag = defrag;
10463
10516
  /******/ };
10464
10517
  /******/
10465
10518
  /******/ // Execute the module function
10466
- /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_11575__);
10519
+ /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_11730__);
10467
10520
  /******/
10468
10521
  /******/ // Return the exports of the module
10469
10522
  /******/ return module.exports;
@@ -10474,7 +10527,7 @@ exports.defrag = defrag;
10474
10527
  /******/ // startup
10475
10528
  /******/ // Load entry module and return exports
10476
10529
  /******/ // This entry module is referenced by other modules so it can't be inlined
10477
- /******/ var __webpack_exports__ = __nested_webpack_require_11575__(521);
10530
+ /******/ var __webpack_exports__ = __nested_webpack_require_11730__(521);
10478
10531
  /******/
10479
10532
  /******/ return __webpack_exports__;
10480
10533
  /******/ })()
@@ -10486,7 +10539,7 @@ exports.defrag = defrag;
10486
10539
  /***/ 6120:
10487
10540
  /***/ (function(module) {
10488
10541
 
10489
- /*! typed-dom v0.0.305 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
10542
+ /*! typed-dom v0.0.307 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
10490
10543
  (function webpackUniversalModuleDefinition(root, factory) {
10491
10544
  if(true)
10492
10545
  module.exports = factory();
@@ -10504,7 +10557,7 @@ return /******/ (() => { // webpackBootstrap
10504
10557
  Object.defineProperty(exports, "__esModule", ({
10505
10558
  value: true
10506
10559
  }));
10507
- exports.duffReduce = exports.duffEach = exports.duffbk = exports.duff = void 0;
10560
+ exports.duffReduce = exports.duffEach = exports.duffbk = exports.duff = void 0; // 100,000以上でforより大幅に低速となり実用不可
10508
10561
 
10509
10562
  function duff(count, proc) {
10510
10563
  if (count > 0) {
@@ -10548,7 +10601,7 @@ function duff(count, proc) {
10548
10601
  }
10549
10602
  }
10550
10603
 
10551
- exports.duff = duff;
10604
+ exports.duff = duff; // 100,000以上でforより大幅に低速となり実用不可
10552
10605
 
10553
10606
  function duffbk(count, proc) {
10554
10607
  if (count > 0) {
@@ -10622,7 +10675,7 @@ function duffEach(array, proc) {
10622
10675
  }
10623
10676
  }
10624
10677
 
10625
- exports.duffEach = duffEach; // ベンチマークの10,000以上で急激な速度低下が見られるがNodeListなどでの
10678
+ exports.duffEach = duffEach; // ベンチマークの10,000以上で急激な速度低下が見られる場合があるがNodeListなどでの
10626
10679
  // 実際の使用では速度低下は見られない
10627
10680
 
10628
10681
  function duffReduce(array, proc, initial) {
@@ -10655,11 +10708,11 @@ exports.duffReduce = duffReduce;
10655
10708
  /***/ }),
10656
10709
 
10657
10710
  /***/ 128:
10658
- /***/ ((module, __unused_webpack_exports, __nested_webpack_require_3560__) => {
10711
+ /***/ ((module, __unused_webpack_exports, __nested_webpack_require_3627__) => {
10659
10712
 
10660
10713
 
10661
10714
 
10662
- __nested_webpack_require_3560__(921);
10715
+ __nested_webpack_require_3627__(921);
10663
10716
 
10664
10717
  const global = void 0 || typeof globalThis !== 'undefined' && globalThis // @ts-ignore
10665
10718
  || typeof self !== 'undefined' && self || Function('return this')();
@@ -10685,7 +10738,7 @@ var global = (/* unused pure expression or super */ null && (0));
10685
10738
  /******/ var __webpack_module_cache__ = {};
10686
10739
  /******/
10687
10740
  /******/ // The require function
10688
- /******/ function __nested_webpack_require_4212__(moduleId) {
10741
+ /******/ function __nested_webpack_require_4279__(moduleId) {
10689
10742
  /******/ // Check if module is in cache
10690
10743
  /******/ var cachedModule = __webpack_module_cache__[moduleId];
10691
10744
  /******/ if (cachedModule !== undefined) {
@@ -10699,7 +10752,7 @@ var global = (/* unused pure expression or super */ null && (0));
10699
10752
  /******/ };
10700
10753
  /******/
10701
10754
  /******/ // Execute the module function
10702
- /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_4212__);
10755
+ /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_4279__);
10703
10756
  /******/
10704
10757
  /******/ // Return the exports of the module
10705
10758
  /******/ return module.exports;
@@ -10717,9 +10770,9 @@ Object.defineProperty(exports, "__esModule", ({
10717
10770
  }));
10718
10771
  exports.querySelectorAll = exports.querySelectorAllWith = exports.querySelectorWith = void 0;
10719
10772
 
10720
- const global_1 = __nested_webpack_require_4212__(128);
10773
+ const global_1 = __nested_webpack_require_4279__(128);
10721
10774
 
10722
- const duff_1 = __nested_webpack_require_4212__(99);
10775
+ const duff_1 = __nested_webpack_require_4279__(99);
10723
10776
 
10724
10777
  function querySelectorWith(node, selector) {
10725
10778
  return 'matches' in node && node.matches(selector) ? node : node.querySelector(selector);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.262.0",
3
+ "version": "0.262.1",
4
4
  "description": "Secure markdown renderer working on browsers for user input data.",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/falsandtru/securemark",
@@ -34,11 +34,11 @@
34
34
  "@types/mocha": "9.1.1",
35
35
  "@types/power-assert": "1.5.8",
36
36
  "@types/prismjs": "1.26.0",
37
- "@typescript-eslint/parser": "^5.36.2",
37
+ "@typescript-eslint/parser": "^5.37.0",
38
38
  "babel-loader": "^8.2.5",
39
39
  "babel-plugin-unassert": "^3.2.0",
40
40
  "concurrently": "^7.4.0",
41
- "eslint": "^8.23.0",
41
+ "eslint": "^8.23.1",
42
42
  "eslint-plugin-redos": "^4.4.1",
43
43
  "eslint-webpack-plugin": "^3.2.0",
44
44
  "glob": "^8.0.3",
@@ -49,11 +49,11 @@
49
49
  "karma-mocha": "^2.0.1",
50
50
  "karma-power-assert": "^1.0.0",
51
51
  "mocha": "^10.0.0",
52
- "npm-check-updates": "^16.1.1",
52
+ "npm-check-updates": "^16.1.2",
53
53
  "semver": "^7.3.7",
54
- "spica": "0.0.622",
54
+ "spica": "0.0.624",
55
55
  "ts-loader": "^9.3.1",
56
- "typed-dom": "^0.0.305",
56
+ "typed-dom": "^0.0.307",
57
57
  "typescript": "4.8.3",
58
58
  "webpack": "^5.74.0",
59
59
  "webpack-cli": "^4.10.0",
@@ -1,4 +1,4 @@
1
- import { undefined, Function } from 'spica/global';
1
+ import { global, undefined } from 'spica/global';
2
2
  import { isArray } from 'spica/alias';
3
3
  import { Parser, Ctx, Tree, Context, eval, exec, check } from '../../data/parser';
4
4
 
@@ -15,15 +15,13 @@ export function validate<T>(patterns: string | RegExp | (string | RegExp)[], has
15
15
  assert(patterns.length > 0);
16
16
  assert(patterns.every(pattern => pattern instanceof RegExp ? !pattern.flags.match(/[gmy]/) && pattern.source.startsWith('^') : true));
17
17
  assert(parser);
18
- const match: (source: string) => boolean = Function([
19
- '"use strict";',
20
- 'return source =>',
21
- '0',
22
- ...patterns.map(pattern =>
18
+ const match: (source: string) => boolean = global.eval([
19
+ 'source =>',
20
+ patterns.map(pattern =>
23
21
  typeof pattern === 'string'
24
22
  ? `|| source.slice(0, ${pattern.length}) === '${pattern}'`
25
- : `|| /${pattern.source}/${pattern.flags}.test(source)`),
26
- ].join(''))();
23
+ : `|| /${pattern.source}/${pattern.flags}.test(source)`).join('').slice(2),
24
+ ].join(''));
27
25
  return ({ source, context }) => {
28
26
  if (source === '') return;
29
27
  if (!match(source)) return;
@@ -1,4 +1,4 @@
1
- import { undefined, Function } from 'spica/global';
1
+ import { undefined } from 'spica/global';
2
2
  import { Parser, Ctx, Tree, Context, SubParsers, SubTree } from '../parser';
3
3
 
4
4
  export function union<P extends Parser<unknown>>(parsers: SubParsers<P>): SubTree<P> extends Tree<P> ? P : Parser<SubTree<P>, Context<P>, SubParsers<P>>;
@@ -9,12 +9,17 @@ export function union<T, D extends Parser<T>[]>(parsers: D): Parser<T, Ctx, D> {
9
9
  return () => undefined;
10
10
  case 1:
11
11
  return parsers[0];
12
+ case 2:
13
+ return input => parsers[0](input) ?? parsers[1](input);
14
+ case 3:
15
+ return input => parsers[0](input) ?? parsers[1](input) ?? parsers[2](input);
12
16
  default:
13
- return Function('parsers', [
14
- '"use strict";',
15
- 'return (input, context) =>',
16
- '0',
17
- ...parsers.map((_, i) => `|| parsers[${i}](input, context)`),
18
- ].join('\n'))(parsers);
17
+ return input => {
18
+ for (let i = 0; i < parsers.length; ++i) {
19
+ const parser = parsers[i];
20
+ const result = parser(input);
21
+ if (result) return result;
22
+ }
23
+ };
19
24
  }
20
25
  }