new license file version [CI SKIP]
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
### [3.1.3](https://github.com/medikoo/es6-symbol/compare/v3.1.2...v3.1.3) (2019-10-29)
|
||||
|
||||
### [3.1.2](https://github.com/medikoo/es6-symbol/compare/v3.1.1...v3.1.2) (2019-09-04)
|
||||
|
||||
- Access `Symbol` from a global object. Makes implementation more bulletproof, as it's safe against shadowing the `Symbol` variable e.g. in script scope, or as it's practiced by some bundlers as Webpack (thanks [@cyborgx37](https://github.com/medikoo/es6-symbol/pull/30))
|
||||
- Switch license from MIT to ISC
|
||||
- Switch linter to ESLint
|
||||
- Configure Prettier
|
||||
|
||||
## Changelog for previous versions
|
||||
|
||||
See `CHANGES` file
|
||||
@@ -0,0 +1,14 @@
|
||||
import { operate } from '../util/lift';
|
||||
import { argsOrArgArray } from '../util/argsOrArgArray';
|
||||
import { mergeAll } from './mergeAll';
|
||||
import { popNumber, popScheduler } from '../util/args';
|
||||
import { from } from '../observable/from';
|
||||
export function merge(...args) {
|
||||
const scheduler = popScheduler(args);
|
||||
const concurrent = popNumber(args, Infinity);
|
||||
args = argsOrArgArray(args);
|
||||
return operate((source, subscriber) => {
|
||||
mergeAll(concurrent)(from([source, ...args], scheduler)).subscribe(subscriber);
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=merge.js.map
|
||||
@@ -0,0 +1,5 @@
|
||||
var convert = require('./convert'),
|
||||
func = convert('iteratee', require('../iteratee'));
|
||||
|
||||
func.placeholder = require('./placeholder');
|
||||
module.exports = func;
|
||||
@@ -0,0 +1,6 @@
|
||||
const parse = require('./parse')
|
||||
const clean = (version, options) => {
|
||||
const s = parse(version.trim().replace(/^[=v]+/, ''), options)
|
||||
return s ? s.version : null
|
||||
}
|
||||
module.exports = clean
|
||||
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $TypeError = GetIntrinsic('%TypeError%');
|
||||
|
||||
var CreateNonEnumerableDataPropertyOrThrow = require('./CreateNonEnumerableDataPropertyOrThrow');
|
||||
var Get = require('./Get');
|
||||
var HasProperty = require('./HasProperty');
|
||||
var Type = require('./Type');
|
||||
|
||||
// https://262.ecma-international.org/13.0/#sec-installerrorcause
|
||||
|
||||
module.exports = function InstallErrorCause(O, options) {
|
||||
if (Type(O) !== 'Object') {
|
||||
throw new $TypeError('Assertion failed: Type(O) is not Object');
|
||||
}
|
||||
|
||||
if (Type(options) === 'Object' && HasProperty(options, 'cause')) {
|
||||
var cause = Get(options, 'cause');
|
||||
CreateNonEnumerableDataPropertyOrThrow(O, 'cause', cause);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import assertString from './util/assertString';
|
||||
import blacklist from './blacklist';
|
||||
export default function stripLow(str, keep_new_lines) {
|
||||
assertString(str);
|
||||
var chars = keep_new_lines ? '\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F' : '\\x00-\\x1F\\x7F';
|
||||
return blacklist(str, chars);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
var test = require('tape')
|
||||
var through = require('../')
|
||||
|
||||
// must emit end before close.
|
||||
|
||||
test('end before close', function (assert) {
|
||||
var ts = through()
|
||||
ts.autoDestroy = false
|
||||
var ended = false, closed = false
|
||||
|
||||
ts.on('end', function () {
|
||||
assert.ok(!closed)
|
||||
ended = true
|
||||
})
|
||||
ts.on('close', function () {
|
||||
assert.ok(ended)
|
||||
closed = true
|
||||
})
|
||||
|
||||
ts.write(1)
|
||||
ts.write(2)
|
||||
ts.write(3)
|
||||
ts.end()
|
||||
assert.ok(ended)
|
||||
assert.notOk(closed)
|
||||
ts.destroy()
|
||||
assert.ok(closed)
|
||||
assert.end()
|
||||
})
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.from = void 0;
|
||||
var scheduled_1 = require("../scheduled/scheduled");
|
||||
var innerFrom_1 = require("./innerFrom");
|
||||
function from(input, scheduler) {
|
||||
return scheduler ? scheduled_1.scheduled(input, scheduler) : innerFrom_1.innerFrom(input);
|
||||
}
|
||||
exports.from = from;
|
||||
//# sourceMappingURL=from.js.map
|
||||
@@ -0,0 +1,5 @@
|
||||
var convert = require('./convert'),
|
||||
func = convert('rearg', require('../rearg'));
|
||||
|
||||
func.placeholder = require('./placeholder');
|
||||
module.exports = func;
|
||||
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var resolveException = require("../lib/resolve-exception")
|
||||
, is = require("./is");
|
||||
|
||||
module.exports = function (value/*, options*/) {
|
||||
if (is(value)) return value;
|
||||
return resolveException(value, "%v is not a date object", arguments[1]);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"scheduleReadableStreamLike.js","sourceRoot":"","sources":["../../../../src/internal/scheduled/scheduleReadableStreamLike.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAElF,MAAM,UAAU,0BAA0B,CAAI,KAA4B,EAAE,SAAwB;IAClG,OAAO,qBAAqB,CAAC,kCAAkC,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC;AACrF,CAAC"}
|
||||
@@ -0,0 +1,54 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v1.0.2](https://github.com/inspect-js/which-boxed-primitive/compare/v1.0.1...v1.0.2) - 2020-12-14
|
||||
|
||||
### Commits
|
||||
|
||||
- [Tests] use shared travis-ci configs [`8674582`](https://github.com/inspect-js/which-boxed-primitive/commit/86745829b6a92cff2cfb0d3c0414ec9afdc2a087)
|
||||
- [Tests] migrate tests to Github Actions [`dff6643`](https://github.com/inspect-js/which-boxed-primitive/commit/dff6643405ba4d6dc6694a25904c8f72f273ece8)
|
||||
- [meta] do not publish github action workflow files [`b26112a`](https://github.com/inspect-js/which-boxed-primitive/commit/b26112a4e4ac6beec8f54c734135dbf9e9ba16f9)
|
||||
- [meta] make `auto-changelog` config consistent [`8d10175`](https://github.com/inspect-js/which-boxed-primitive/commit/8d10175171154cd6c8f8a016aa7fb71b5044acf6)
|
||||
- [readme] fix repo URLs, remove defunct badges [`ab8db24`](https://github.com/inspect-js/which-boxed-primitive/commit/ab8db247573723dbcda68469118d08c7c2692c67)
|
||||
- [Tests] run `nyc` on all tests; use `tape` runner [`7d084df`](https://github.com/inspect-js/which-boxed-primitive/commit/7d084dfc5251230e9399a81782c0b9d7ae5d1901)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `object-inspect`, `tape` [`576f6f3`](https://github.com/inspect-js/which-boxed-primitive/commit/576f6f308aed35ef1d3392bb9472def59482ed13)
|
||||
- [actions] add automatic rebasing / merge commit blocking [`97efa53`](https://github.com/inspect-js/which-boxed-primitive/commit/97efa53a307678323e63f576c07db9ff84846fd3)
|
||||
- [actions] add "Allow Edits" workflow [`fb1b4f7`](https://github.com/inspect-js/which-boxed-primitive/commit/fb1b4f7cd753fcced74ac054b20c8b2bfafe7953)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `has-symbols`, `object-inspect`, `safe-publish-latest` [`1e03c61`](https://github.com/inspect-js/which-boxed-primitive/commit/1e03c6153693d385833acc15178f675e6ce5ddd0)
|
||||
- [Deps] update `is-boolean-object`, `is-number-object`, `is-string`, `is-symbol` [`13673df`](https://github.com/inspect-js/which-boxed-primitive/commit/13673dff6e43f0a915377c3e5740ec24e86d6bb7)
|
||||
- [Dev Deps] update `auto-changelog`, `in-publish`, `tape` [`65a0e15`](https://github.com/inspect-js/which-boxed-primitive/commit/65a0e155fc46a9237692233a51ec9573621135d2)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape` [`f8a0afe`](https://github.com/inspect-js/which-boxed-primitive/commit/f8a0afea82938d64f3d2d240268afbd346d0c4da)
|
||||
- [Deps] update `is-bigint`, `is-boolean-object` [`e7a1ce2`](https://github.com/inspect-js/which-boxed-primitive/commit/e7a1ce25371c00ee726f1c0cc5b6acf10d51ec50)
|
||||
- [actions] switch Automatic Rebase workflow to `pull_request_target` event [`e46f193`](https://github.com/inspect-js/which-boxed-primitive/commit/e46f193298b158db5c8aba889803513e4ee38957)
|
||||
- [Dev Deps] update `@ljharb/eslint-config`, `tape` [`df3da14`](https://github.com/inspect-js/which-boxed-primitive/commit/df3da1424552a5d22e203a0abf1710106bfd4ae2)
|
||||
- [Dev Deps] update `auto-changelog`; add `aud` [`e2e8a12`](https://github.com/inspect-js/which-boxed-primitive/commit/e2e8a12c6fbf8c48e760ea1d1ccd5e8d2d6fbf24)
|
||||
- [meta] add `funding` field [`7df404b`](https://github.com/inspect-js/which-boxed-primitive/commit/7df404b20cd50b2b87e6645b130fefa8ee98810e)
|
||||
- [Dev Deps] update `auto-changelog` [`0d6b76d`](https://github.com/inspect-js/which-boxed-primitive/commit/0d6b76dbbe760581fa86a0c3f254988fe5d27770)
|
||||
- [Tests] only audit prod deps [`246151c`](https://github.com/inspect-js/which-boxed-primitive/commit/246151cc1407b3b1ef42014db993f62670bd82ff)
|
||||
- [meta] fix changelog [`c2d1685`](https://github.com/inspect-js/which-boxed-primitive/commit/c2d16856deffbf86e0b5029e69b65d8aa758ec3d)
|
||||
- [readme] Fix spelling error [`25fb2b5`](https://github.com/inspect-js/which-boxed-primitive/commit/25fb2b56e1f708c6364923e4bae384f818ecf57f)
|
||||
|
||||
## [v1.0.1](https://github.com/inspect-js/which-boxed-primitive/compare/v1.0.0...v1.0.1) - 2019-08-10
|
||||
|
||||
### Commits
|
||||
|
||||
- [meta] avoid running `safe-publish-latest` when not publishing [`df44b27`](https://github.com/inspect-js/which-boxed-primitive/commit/df44b27875a8f5c3c596663ecb4a063f9fc7bde3)
|
||||
|
||||
## v1.0.0 - 2019-08-10
|
||||
|
||||
### Commits
|
||||
|
||||
- [Tests] add `.travis.yml` [`764b0cf`](https://github.com/inspect-js/which-boxed-primitive/commit/764b0cf75f8d2b3a0ad2056de5f4ad85d5d1b765)
|
||||
- Initial commit [`da7d068`](https://github.com/inspect-js/which-boxed-primitive/commit/da7d068913d591294bf155db5d438f7804d71b9a)
|
||||
- readme [`1395bb2`](https://github.com/inspect-js/which-boxed-primitive/commit/1395bb27b72137ac01e48ee398a0f54e93fd87f5)
|
||||
- [Tests] add tests [`0ff580f`](https://github.com/inspect-js/which-boxed-primitive/commit/0ff580f99579cd4424af7b814bd76fcb69a2b04e)
|
||||
- implementation [`8811c32`](https://github.com/inspect-js/which-boxed-primitive/commit/8811c3262a57963634cdc83ceb5bb2c5e9ae4e7e)
|
||||
- npm init [`cffdea9`](https://github.com/inspect-js/which-boxed-primitive/commit/cffdea9755eabfa2f9ec62a6fcbce0c28f04495b)
|
||||
- [Tests] add `npm run lint` [`a8be993`](https://github.com/inspect-js/which-boxed-primitive/commit/a8be9933fec1b21267acd847df77f6438e07e3b9)
|
||||
- [meta] add FUNDING.yml [`941258c`](https://github.com/inspect-js/which-boxed-primitive/commit/941258c70c9a397466e05b614126cb8c7be77b99)
|
||||
- Only apps should have lockfiles [`6857316`](https://github.com/inspect-js/which-boxed-primitive/commit/68573165d8ce842cdf15d94af82f8cccb961b8cf)
|
||||
- [Tests] use `npx aud` in `posttest` [`ee48a91`](https://github.com/inspect-js/which-boxed-primitive/commit/ee48a9144bea23bde5cc47788a54d5aa7969d489)
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"iif.d.ts","sourceRoot":"","sources":["../../../../src/internal/observable/iif.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,OAAO,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAEtI"}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { SvelteComponentTyped } from "svelte";
|
||||
import type { DataHandler } from './core';
|
||||
declare const __propDef: {
|
||||
props: {
|
||||
handler: DataHandler;
|
||||
small?: boolean;
|
||||
};
|
||||
events: {
|
||||
[evt: string]: CustomEvent<any>;
|
||||
};
|
||||
slots: {};
|
||||
};
|
||||
export type PaginationProps = typeof __propDef.props;
|
||||
export type PaginationEvents = typeof __propDef.events;
|
||||
export type PaginationSlots = typeof __propDef.slots;
|
||||
export default class Pagination extends SvelteComponentTyped<PaginationProps, PaginationEvents, PaginationSlots> {
|
||||
}
|
||||
export {};
|
||||
@@ -0,0 +1,9 @@
|
||||
var test = require('tap').test;
|
||||
var detective = require('../');
|
||||
var fs = require('fs');
|
||||
var src = fs.readFileSync(__dirname + '/files/shebang.js');
|
||||
|
||||
test('shebang', function (t) {
|
||||
t.plan(1);
|
||||
t.deepEqual(detective(src), [ 'a', 'b', 'c' ]);
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
var setPrototypeOf = require("es5-ext/object/set-prototype-of")
|
||||
, contains = require("es5-ext/string/#/contains")
|
||||
, d = require("d")
|
||||
, Symbol = require("es6-symbol")
|
||||
, Iterator = require("./");
|
||||
|
||||
var defineProperty = Object.defineProperty, ArrayIterator;
|
||||
|
||||
ArrayIterator = module.exports = function (arr, kind) {
|
||||
if (!(this instanceof ArrayIterator)) throw new TypeError("Constructor requires 'new'");
|
||||
Iterator.call(this, arr);
|
||||
if (!kind) kind = "value";
|
||||
else if (contains.call(kind, "key+value")) kind = "key+value";
|
||||
else if (contains.call(kind, "key")) kind = "key";
|
||||
else kind = "value";
|
||||
defineProperty(this, "__kind__", d("", kind));
|
||||
};
|
||||
if (setPrototypeOf) setPrototypeOf(ArrayIterator, Iterator);
|
||||
|
||||
// Internal %ArrayIteratorPrototype% doesn't expose its constructor
|
||||
delete ArrayIterator.prototype.constructor;
|
||||
|
||||
ArrayIterator.prototype = Object.create(Iterator.prototype, {
|
||||
_resolve: d(function (i) {
|
||||
if (this.__kind__ === "value") return this.__list__[i];
|
||||
if (this.__kind__ === "key+value") return [i, this.__list__[i]];
|
||||
return i;
|
||||
})
|
||||
});
|
||||
defineProperty(ArrayIterator.prototype, Symbol.toStringTag, d("c", "Array Iterator"));
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0.019,"53":0,"54":0,"55":0.0038,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0.0038,"67":0,"68":0.0038,"69":0,"70":0,"71":0,"72":0,"73":0.019,"74":0,"75":0,"76":0,"77":0,"78":0.0038,"79":0,"80":0,"81":0,"82":0,"83":0.0038,"84":0,"85":0,"86":0.0038,"87":0,"88":0.0038,"89":0,"90":0,"91":0.0038,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0.0152,"98":0,"99":0.0038,"100":0.019,"101":0,"102":0.019,"103":0.0038,"104":0.02279,"105":0.0038,"106":0.0076,"107":0.0038,"108":0.0114,"109":0.36091,"110":0.26973,"111":0.0038,"112":0,"3.5":0,"3.6":0},D:{"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0.05319,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0.0038,"48":0,"49":0.02659,"50":0,"51":0,"52":0,"53":0.0038,"54":0,"55":0.0038,"56":0,"57":0,"58":0.0038,"59":0,"60":0,"61":0,"62":0.0076,"63":0.0038,"64":0,"65":0.0076,"66":0,"67":0,"68":0,"69":0.0038,"70":0.0038,"71":0.0038,"72":0,"73":0.0076,"74":0.0076,"75":0.0038,"76":0,"77":0.0038,"78":0.0038,"79":0.0114,"80":0.019,"81":0.0038,"83":0.0076,"84":0.0038,"85":0.0076,"86":0.15196,"87":0.0076,"88":0.0038,"89":0.0038,"90":0.0038,"91":0.0114,"92":0.0038,"93":0.0114,"94":0.0152,"95":0.0076,"96":0.02659,"97":0.0114,"98":0.0076,"99":0.0076,"100":0.02659,"101":0.02279,"102":0.0114,"103":0.05319,"104":0.0152,"105":0.019,"106":0.03799,"107":0.06838,"108":0.24314,"109":5.65291,"110":3.54067,"111":0,"112":0.0038,"113":0},F:{"9":0,"11":0,"12":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0.0038,"29":0,"30":0,"31":0,"32":0.0038,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"60":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0.0038,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0.0038,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0.0038,"92":0,"93":0.12537,"94":0.83198,"95":0.25073,"9.5-9.6":0,"10.0-10.1":0,"10.5":0,"10.6":0,"11.1":0,"11.5":0,"11.6":0,"12.1":0},B:{"12":0,"13":0,"14":0.0038,"15":0,"16":0,"17":0,"18":0,"79":0,"80":0,"81":0,"83":0,"84":0.0114,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0.0038,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0,"101":0.0038,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0.019,"108":0.019,"109":0.3989,"110":0.52046},E:{"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0.0038,"14":0.0114,"15":0.0038,_:"0","3.1":0,"3.2":0,"5.1":0,"6.1":0,"7.1":0,"9.1":0,"10.1":0,"11.1":0,"12.1":0.0038,"13.1":0.02659,"14.1":0.02659,"15.1":0.0114,"15.2-15.3":0.0038,"15.4":0.0114,"15.5":0.03039,"15.6":0.07218,"16.0":0.0076,"16.1":0.03419,"16.2":0.06458,"16.3":0.06838,"16.4":0},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0,"5.0-5.1":0.03081,"6.0-6.1":0.00147,"7.0-7.1":0.0132,"8.1-8.4":0,"9.0-9.2":0,"9.3":0.02347,"10.0-10.2":0,"10.3":0.02787,"11.0-11.2":0.0044,"11.3-11.4":0.00293,"12.0-12.1":0.0176,"12.2-12.5":0.38731,"13.0-13.1":0.00293,"13.2":0,"13.3":0.01907,"13.4-13.7":0.07922,"14.0-14.4":0.13057,"14.5-14.8":0.40491,"15.0-15.1":0.07776,"15.2-15.3":0.1115,"15.4":0.11883,"15.5":0.33009,"15.6":1.32771,"16.0":1.49055,"16.1":3.35815,"16.2":3.45498,"16.3":1.76196,"16.4":0.00587},P:{"4":0.07242,"20":0.44489,"5.0-5.4":0,"6.2-6.4":0,"7.2-7.4":0.21727,"8.2":0,"9.2":0.01035,"10.1":0,"11.1-11.2":0.02069,"12.0":0,"13.0":0.03104,"14.0":0.02069,"15.0":0.01035,"16.0":0.06208,"17.0":0.07242,"18.0":0.07242,"19.0":0.86908},I:{"0":0,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0,"4.4":0,"4.4.3-4.4.4":0.18397},K:{_:"0 10 11 12 11.1 11.5 12.1"},A:{"6":0,"7":0,"8":0,"9":0,"10":0,"11":0.02279,"5.5":0},N:{"10":0,"11":0},S:{"2.5":0,_:"3.0-3.1"},J:{"7":0,"10":0},O:{"0":0.0124},H:{"0":0.09393},L:{"0":69.63847},R:{_:"0"},M:{"0":0.30385},Q:{"13.1":0}};
|
||||
@@ -0,0 +1,104 @@
|
||||
[![Build status][nix-build-image]][nix-build-url]
|
||||
[![Windows status][win-build-image]][win-build-url]
|
||||
![Transpilation status][transpilation-image]
|
||||
[![npm version][npm-image]][npm-url]
|
||||
|
||||
# es6-symbol
|
||||
|
||||
## ECMAScript 6 Symbol polyfill
|
||||
|
||||
For more information about symbols see following links
|
||||
|
||||
- [Symbols in ECMAScript 6 by Axel Rauschmayer](http://www.2ality.com/2014/12/es6-symbols.html)
|
||||
- [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
|
||||
- [Specification](https://tc39.github.io/ecma262/#sec-symbol-objects)
|
||||
|
||||
### Limitations
|
||||
|
||||
Underneath it uses real string property names which can easily be retrieved, however accidental collision with other property names is unlikely.
|
||||
|
||||
### Usage
|
||||
|
||||
If you'd like to use native version when it exists and fallback to [ponyfill](https://ponyfill.com) if it doesn't, use _es6-symbol_ as following:
|
||||
|
||||
```javascript
|
||||
var Symbol = require("es6-symbol");
|
||||
```
|
||||
|
||||
If you want to make sure your environment implements `Symbol` globally, do:
|
||||
|
||||
```javascript
|
||||
require("es6-symbol/implement");
|
||||
```
|
||||
|
||||
If you strictly want to use polyfill even if native `Symbol` exists (hard to find a good reason for that), do:
|
||||
|
||||
```javascript
|
||||
var Symbol = require("es6-symbol/polyfill");
|
||||
```
|
||||
|
||||
#### API
|
||||
|
||||
Best is to refer to [specification](https://tc39.github.io/ecma262/#sec-symbol-objects). Still if you want quick look, follow examples:
|
||||
|
||||
```javascript
|
||||
var Symbol = require("es6-symbol");
|
||||
|
||||
var symbol = Symbol("My custom symbol");
|
||||
var x = {};
|
||||
|
||||
x[symbol] = "foo";
|
||||
console.log(x[symbol]);
|
||||
("foo");
|
||||
|
||||
// Detect iterable:
|
||||
var iterator, result;
|
||||
if (possiblyIterable[Symbol.iterator]) {
|
||||
iterator = possiblyIterable[Symbol.iterator]();
|
||||
result = iterator.next();
|
||||
while (!result.done) {
|
||||
console.log(result.value);
|
||||
result = iterator.next();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Installation
|
||||
|
||||
#### NPM
|
||||
|
||||
In your project path:
|
||||
|
||||
$ npm install es6-symbol
|
||||
|
||||
##### Browser
|
||||
|
||||
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/)
|
||||
|
||||
## Tests
|
||||
|
||||
$ npm test
|
||||
|
||||
## Security contact information
|
||||
|
||||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-es6-symbol?utm_source=npm-es6-symbol&utm_medium=referral&utm_campaign=readme">Get professional support for d with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
||||
|
||||
[nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/es6-symbol/branches/master/shields_badge.svg
|
||||
[nix-build-url]: https://semaphoreci.com/medikoo-org/es6-symbol
|
||||
[win-build-image]: https://ci.appveyor.com/api/projects/status/1s743lt3el278anj?svg=true
|
||||
[win-build-url]: https://ci.appveyor.com/project/medikoo/es6-symbol
|
||||
[transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg
|
||||
[npm-image]: https://img.shields.io/npm/v/es6-symbol.svg
|
||||
[npm-url]: https://www.npmjs.com/package/es6-symbol
|
||||
@@ -0,0 +1,51 @@
|
||||
var arrayReduce = require('./_arrayReduce'),
|
||||
baseEach = require('./_baseEach'),
|
||||
baseIteratee = require('./_baseIteratee'),
|
||||
baseReduce = require('./_baseReduce'),
|
||||
isArray = require('./isArray');
|
||||
|
||||
/**
|
||||
* Reduces `collection` to a value which is the accumulated result of running
|
||||
* each element in `collection` thru `iteratee`, where each successive
|
||||
* invocation is supplied the return value of the previous. If `accumulator`
|
||||
* is not given, the first element of `collection` is used as the initial
|
||||
* value. The iteratee is invoked with four arguments:
|
||||
* (accumulator, value, index|key, collection).
|
||||
*
|
||||
* Many lodash methods are guarded to work as iteratees for methods like
|
||||
* `_.reduce`, `_.reduceRight`, and `_.transform`.
|
||||
*
|
||||
* The guarded methods are:
|
||||
* `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
|
||||
* and `sortBy`
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 0.1.0
|
||||
* @category Collection
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||||
* @param {*} [accumulator] The initial value.
|
||||
* @returns {*} Returns the accumulated value.
|
||||
* @see _.reduceRight
|
||||
* @example
|
||||
*
|
||||
* _.reduce([1, 2], function(sum, n) {
|
||||
* return sum + n;
|
||||
* }, 0);
|
||||
* // => 3
|
||||
*
|
||||
* _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
|
||||
* (result[value] || (result[value] = [])).push(key);
|
||||
* return result;
|
||||
* }, {});
|
||||
* // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
|
||||
*/
|
||||
function reduce(collection, iteratee, accumulator) {
|
||||
var func = isArray(collection) ? arrayReduce : baseReduce,
|
||||
initAccum = arguments.length < 3;
|
||||
|
||||
return func(collection, baseIteratee(iteratee, 4), accumulator, initAccum, baseEach);
|
||||
}
|
||||
|
||||
module.exports = reduce;
|
||||
@@ -0,0 +1,103 @@
|
||||
var canReorder = require('./reorderable').canReorder;
|
||||
var canReorderSingle = require('./reorderable').canReorderSingle;
|
||||
var extractProperties = require('./extract-properties');
|
||||
var rulesOverlap = require('./rules-overlap');
|
||||
|
||||
var serializeRules = require('../../writer/one-time').rules;
|
||||
var OptimizationLevel = require('../../options/optimization-level').OptimizationLevel;
|
||||
var Token = require('../../tokenizer/token');
|
||||
|
||||
function mergeMediaQueries(tokens, context) {
|
||||
var mergeSemantically = context.options.level[OptimizationLevel.Two].mergeSemantically;
|
||||
var specificityCache = context.cache.specificity;
|
||||
var candidates = {};
|
||||
var reduced = [];
|
||||
|
||||
for (var i = tokens.length - 1; i >= 0; i--) {
|
||||
var token = tokens[i];
|
||||
if (token[0] != Token.NESTED_BLOCK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var key = serializeRules(token[1]);
|
||||
var candidate = candidates[key];
|
||||
if (!candidate) {
|
||||
candidate = [];
|
||||
candidates[key] = candidate;
|
||||
}
|
||||
|
||||
candidate.push(i);
|
||||
}
|
||||
|
||||
for (var name in candidates) {
|
||||
var positions = candidates[name];
|
||||
|
||||
positionLoop:
|
||||
for (var j = positions.length - 1; j > 0; j--) {
|
||||
var positionOne = positions[j];
|
||||
var tokenOne = tokens[positionOne];
|
||||
var positionTwo = positions[j - 1];
|
||||
var tokenTwo = tokens[positionTwo];
|
||||
|
||||
directionLoop:
|
||||
for (var direction = 1; direction >= -1; direction -= 2) {
|
||||
var topToBottom = direction == 1;
|
||||
var from = topToBottom ? positionOne + 1 : positionTwo - 1;
|
||||
var to = topToBottom ? positionTwo : positionOne;
|
||||
var delta = topToBottom ? 1 : -1;
|
||||
var source = topToBottom ? tokenOne : tokenTwo;
|
||||
var target = topToBottom ? tokenTwo : tokenOne;
|
||||
var movedProperties = extractProperties(source);
|
||||
|
||||
while (from != to) {
|
||||
var traversedProperties = extractProperties(tokens[from]);
|
||||
from += delta;
|
||||
|
||||
if (mergeSemantically && allSameRulePropertiesCanBeReordered(movedProperties, traversedProperties, specificityCache)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!canReorder(movedProperties, traversedProperties, specificityCache))
|
||||
continue directionLoop;
|
||||
}
|
||||
|
||||
target[2] = topToBottom ?
|
||||
source[2].concat(target[2]) :
|
||||
target[2].concat(source[2]);
|
||||
source[2] = [];
|
||||
|
||||
reduced.push(target);
|
||||
continue positionLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return reduced;
|
||||
}
|
||||
|
||||
function allSameRulePropertiesCanBeReordered(movedProperties, traversedProperties, specificityCache) {
|
||||
var movedProperty;
|
||||
var movedRule;
|
||||
var traversedProperty;
|
||||
var traversedRule;
|
||||
var i, l;
|
||||
var j, m;
|
||||
|
||||
for (i = 0, l = movedProperties.length; i < l; i++) {
|
||||
movedProperty = movedProperties[i];
|
||||
movedRule = movedProperty[5];
|
||||
|
||||
for (j = 0, m = traversedProperties.length; j < m; j++) {
|
||||
traversedProperty = traversedProperties[j];
|
||||
traversedRule = traversedProperty[5];
|
||||
|
||||
if (rulesOverlap(movedRule, traversedRule, true) && !canReorderSingle(movedProperty, traversedProperty, specificityCache)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = mergeMediaQueries;
|
||||
@@ -0,0 +1,48 @@
|
||||
var baseFlatten = require('./_baseFlatten'),
|
||||
baseOrderBy = require('./_baseOrderBy'),
|
||||
baseRest = require('./_baseRest'),
|
||||
isIterateeCall = require('./_isIterateeCall');
|
||||
|
||||
/**
|
||||
* Creates an array of elements, sorted in ascending order by the results of
|
||||
* running each element in a collection thru each iteratee. This method
|
||||
* performs a stable sort, that is, it preserves the original sort order of
|
||||
* equal elements. The iteratees are invoked with one argument: (value).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 0.1.0
|
||||
* @category Collection
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {...(Function|Function[])} [iteratees=[_.identity]]
|
||||
* The iteratees to sort by.
|
||||
* @returns {Array} Returns the new sorted array.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'fred', 'age': 48 },
|
||||
* { 'user': 'barney', 'age': 36 },
|
||||
* { 'user': 'fred', 'age': 30 },
|
||||
* { 'user': 'barney', 'age': 34 }
|
||||
* ];
|
||||
*
|
||||
* _.sortBy(users, [function(o) { return o.user; }]);
|
||||
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
|
||||
*
|
||||
* _.sortBy(users, ['user', 'age']);
|
||||
* // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
|
||||
*/
|
||||
var sortBy = baseRest(function(collection, iteratees) {
|
||||
if (collection == null) {
|
||||
return [];
|
||||
}
|
||||
var length = iteratees.length;
|
||||
if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
|
||||
iteratees = [];
|
||||
} else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
|
||||
iteratees = [iteratees[0]];
|
||||
}
|
||||
return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
|
||||
});
|
||||
|
||||
module.exports = sortBy;
|
||||
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint global-require: 0 */
|
||||
|
||||
// https://es5.github.io/#x9
|
||||
module.exports = {
|
||||
'Abstract Equality Comparison': require('./5/AbstractEqualityComparison'),
|
||||
'Abstract Relational Comparison': require('./5/AbstractRelationalComparison'),
|
||||
'Strict Equality Comparison': require('./5/StrictEqualityComparison'),
|
||||
abs: require('./5/abs'),
|
||||
CheckObjectCoercible: require('./5/CheckObjectCoercible'),
|
||||
DateFromTime: require('./5/DateFromTime'),
|
||||
Day: require('./5/Day'),
|
||||
DayFromYear: require('./5/DayFromYear'),
|
||||
DaysInYear: require('./5/DaysInYear'),
|
||||
DayWithinYear: require('./5/DayWithinYear'),
|
||||
floor: require('./5/floor'),
|
||||
FromPropertyDescriptor: require('./5/FromPropertyDescriptor'),
|
||||
HourFromTime: require('./5/HourFromTime'),
|
||||
InLeapYear: require('./5/InLeapYear'),
|
||||
IsAccessorDescriptor: require('./5/IsAccessorDescriptor'),
|
||||
IsCallable: require('./5/IsCallable'),
|
||||
IsDataDescriptor: require('./5/IsDataDescriptor'),
|
||||
IsGenericDescriptor: require('./5/IsGenericDescriptor'),
|
||||
IsPropertyDescriptor: require('./5/IsPropertyDescriptor'),
|
||||
MakeDate: require('./5/MakeDate'),
|
||||
MakeDay: require('./5/MakeDay'),
|
||||
MakeTime: require('./5/MakeTime'),
|
||||
MinFromTime: require('./5/MinFromTime'),
|
||||
modulo: require('./5/modulo'),
|
||||
MonthFromTime: require('./5/MonthFromTime'),
|
||||
msFromTime: require('./5/msFromTime'),
|
||||
SameValue: require('./5/SameValue'),
|
||||
SecFromTime: require('./5/SecFromTime'),
|
||||
TimeClip: require('./5/TimeClip'),
|
||||
TimeFromYear: require('./5/TimeFromYear'),
|
||||
TimeWithinDay: require('./5/TimeWithinDay'),
|
||||
ToBoolean: require('./5/ToBoolean'),
|
||||
ToInt32: require('./5/ToInt32'),
|
||||
ToInteger: require('./5/ToInteger'),
|
||||
ToNumber: require('./5/ToNumber'),
|
||||
ToObject: require('./5/ToObject'),
|
||||
ToPrimitive: require('./5/ToPrimitive'),
|
||||
ToPropertyDescriptor: require('./5/ToPropertyDescriptor'),
|
||||
ToString: require('./5/ToString'),
|
||||
ToUint16: require('./5/ToUint16'),
|
||||
ToUint32: require('./5/ToUint32'),
|
||||
Type: require('./5/Type'),
|
||||
WeekDay: require('./5/WeekDay'),
|
||||
YearFromTime: require('./5/YearFromTime')
|
||||
};
|
||||
@@ -0,0 +1,427 @@
|
||||
/* eslint-env browser */
|
||||
/**
|
||||
* The HMR proxy is a component-like object whose task is to sit in the
|
||||
* component tree in place of the proxied component, and rerender each
|
||||
* successive versions of said component.
|
||||
*/
|
||||
|
||||
import { createProxiedComponent } from './svelte-hooks.js'
|
||||
|
||||
const handledMethods = ['constructor', '$destroy']
|
||||
const forwardedMethods = ['$set', '$on']
|
||||
|
||||
const logError = (msg, err) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('[HMR][Svelte]', msg)
|
||||
if (err) {
|
||||
// NOTE avoid too much wrapping around user errors
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
const posixify = file => file.replace(/[/\\]/g, '/')
|
||||
|
||||
const getBaseName = id =>
|
||||
id
|
||||
.split('/')
|
||||
.pop()
|
||||
.split('.')
|
||||
.slice(0, -1)
|
||||
.join('.')
|
||||
|
||||
const capitalize = str => str[0].toUpperCase() + str.slice(1)
|
||||
|
||||
const getFriendlyName = id => capitalize(getBaseName(posixify(id)))
|
||||
|
||||
const getDebugName = id => `<${getFriendlyName(id)}>`
|
||||
|
||||
const relayCalls = (getTarget, names, dest = {}) => {
|
||||
for (const key of names) {
|
||||
dest[key] = function(...args) {
|
||||
const target = getTarget()
|
||||
if (!target) {
|
||||
return
|
||||
}
|
||||
return target[key] && target[key].call(this, ...args)
|
||||
}
|
||||
}
|
||||
return dest
|
||||
}
|
||||
|
||||
const isInternal = key => key !== '$$' && key.slice(0, 2) === '$$'
|
||||
|
||||
// This is intented as a somewhat generic / prospective fix to the situation
|
||||
// that arised with the introduction of $$set in Svelte 3.24.1 -- trying to
|
||||
// avoid giving full knowledge (like its name) of this implementation detail
|
||||
// to the proxy. The $$set method can be present or not on the component, and
|
||||
// its presence impacts the behaviour (but with HMR it will be tested if it is
|
||||
// present _on the proxy_). So the idea here is to expose exactly the same $$
|
||||
// props as the current version of the component and, for those that are
|
||||
// functions, proxy the calls to the current component.
|
||||
const relayInternalMethods = (proxy, cmp) => {
|
||||
// delete any previously added $$ prop
|
||||
Object.keys(proxy)
|
||||
.filter(isInternal)
|
||||
.forEach(key => {
|
||||
delete proxy[key]
|
||||
})
|
||||
// guard: no component
|
||||
if (!cmp) return
|
||||
// proxy current $$ props to the actual component
|
||||
Object.keys(cmp)
|
||||
.filter(isInternal)
|
||||
.forEach(key => {
|
||||
Object.defineProperty(proxy, key, {
|
||||
configurable: true,
|
||||
get() {
|
||||
const value = cmp[key]
|
||||
if (typeof value !== 'function') return value
|
||||
return (
|
||||
value &&
|
||||
function(...args) {
|
||||
return value.apply(this, args)
|
||||
}
|
||||
)
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// proxy custom methods
|
||||
const copyComponentProperties = (proxy, cmp, previous) => {
|
||||
if (previous) {
|
||||
previous.forEach(prop => {
|
||||
delete proxy[prop]
|
||||
})
|
||||
}
|
||||
|
||||
const props = Object.getOwnPropertyNames(Object.getPrototypeOf(cmp))
|
||||
const wrappedProps = props.filter(prop => {
|
||||
if (!handledMethods.includes(prop) && !forwardedMethods.includes(prop)) {
|
||||
Object.defineProperty(proxy, prop, {
|
||||
configurable: true,
|
||||
get() {
|
||||
return cmp[prop]
|
||||
},
|
||||
set(value) {
|
||||
// we're changing it on the real component first to see what it
|
||||
// gives... if it throws an error, we want to throw the same error in
|
||||
// order to most closely follow non-hmr behaviour.
|
||||
cmp[prop] = value
|
||||
},
|
||||
})
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
return wrappedProps
|
||||
}
|
||||
|
||||
// everything in the constructor!
|
||||
//
|
||||
// so we don't polute the component class with new members
|
||||
//
|
||||
class ProxyComponent {
|
||||
constructor(
|
||||
{
|
||||
Adapter,
|
||||
id,
|
||||
debugName,
|
||||
current, // { Component, hotOptions: { preserveLocalState, ... } }
|
||||
register,
|
||||
},
|
||||
options // { target, anchor, ... }
|
||||
) {
|
||||
let cmp
|
||||
let disposed = false
|
||||
let lastError = null
|
||||
|
||||
const setComponent = _cmp => {
|
||||
cmp = _cmp
|
||||
relayInternalMethods(this, cmp)
|
||||
}
|
||||
|
||||
const getComponent = () => cmp
|
||||
|
||||
const destroyComponent = () => {
|
||||
// destroyComponent is tolerant (don't crash on no cmp) because it
|
||||
// is possible that reload/rerender is called after a previous
|
||||
// createComponent has failed (hence we have a proxy, but no cmp)
|
||||
if (cmp) {
|
||||
cmp.$destroy()
|
||||
setComponent(null)
|
||||
}
|
||||
}
|
||||
|
||||
const refreshComponent = (target, anchor, conservativeDestroy) => {
|
||||
if (lastError) {
|
||||
lastError = null
|
||||
adapter.rerender()
|
||||
} else {
|
||||
try {
|
||||
const replaceOptions = {
|
||||
target,
|
||||
anchor,
|
||||
preserveLocalState: current.preserveLocalState,
|
||||
}
|
||||
if (conservativeDestroy) {
|
||||
replaceOptions.conservativeDestroy = true
|
||||
}
|
||||
cmp.$replace(current.Component, replaceOptions)
|
||||
} catch (err) {
|
||||
setError(err, target, anchor)
|
||||
if (
|
||||
!current.hotOptions.optimistic ||
|
||||
// non acceptable components (that is components that have to defer
|
||||
// to their parent for rerender -- e.g. accessors, named exports)
|
||||
// are most tricky, and they havent been considered when most of the
|
||||
// code has been written... as a result, they are especially tricky
|
||||
// to deal with, it's better to consider any error with them to be
|
||||
// fatal to avoid odities
|
||||
!current.canAccept ||
|
||||
(err && err.hmrFatal)
|
||||
) {
|
||||
throw err
|
||||
} else {
|
||||
// const errString = String((err && err.stack) || err)
|
||||
logError(`Error during component init: ${debugName}`, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const setError = err => {
|
||||
lastError = err
|
||||
adapter.renderError(err)
|
||||
}
|
||||
|
||||
const instance = {
|
||||
hotOptions: current.hotOptions,
|
||||
proxy: this,
|
||||
id,
|
||||
debugName,
|
||||
refreshComponent,
|
||||
}
|
||||
|
||||
const adapter = new Adapter(instance)
|
||||
|
||||
const { afterMount, rerender } = adapter
|
||||
|
||||
// $destroy is not called when a child component is disposed, so we
|
||||
// need to hook from fragment.
|
||||
const onDestroy = () => {
|
||||
// NOTE do NOT call $destroy on the cmp from here; the cmp is already
|
||||
// dead, this would not work
|
||||
if (!disposed) {
|
||||
disposed = true
|
||||
adapter.dispose()
|
||||
unregister()
|
||||
}
|
||||
}
|
||||
|
||||
// ---- register proxy instance ----
|
||||
|
||||
const unregister = register(rerender)
|
||||
|
||||
// ---- augmented methods ----
|
||||
|
||||
this.$destroy = () => {
|
||||
destroyComponent()
|
||||
onDestroy()
|
||||
}
|
||||
|
||||
// ---- forwarded methods ----
|
||||
|
||||
relayCalls(getComponent, forwardedMethods, this)
|
||||
|
||||
// ---- create & mount target component instance ---
|
||||
|
||||
try {
|
||||
let lastProperties
|
||||
createProxiedComponent(current.Component, options, {
|
||||
allowLiveBinding: current.hotOptions.allowLiveBinding,
|
||||
onDestroy,
|
||||
onMount: afterMount,
|
||||
onInstance: comp => {
|
||||
setComponent(comp)
|
||||
// WARNING the proxy MUST use the same $$ object as its component
|
||||
// instance, because a lot of wiring happens during component
|
||||
// initialisation... lots of references to $$ and $$.fragment have
|
||||
// already been distributed around when the component constructor
|
||||
// returns, before we have a chance to wrap them (and so we can't
|
||||
// wrap them no more, because existing references would become
|
||||
// invalid)
|
||||
this.$$ = comp.$$
|
||||
lastProperties = copyComponentProperties(this, comp, lastProperties)
|
||||
},
|
||||
})
|
||||
} catch (err) {
|
||||
const { target, anchor } = options
|
||||
setError(err, target, anchor)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const syncStatics = (component, proxy, previousKeys) => {
|
||||
// remove previously copied keys
|
||||
if (previousKeys) {
|
||||
for (const key of previousKeys) {
|
||||
delete proxy[key]
|
||||
}
|
||||
}
|
||||
|
||||
// forward static properties and methods
|
||||
const keys = []
|
||||
for (const key in component) {
|
||||
keys.push(key)
|
||||
proxy[key] = component[key]
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
||||
|
||||
const globalListeners = {}
|
||||
|
||||
const onGlobal = (event, fn) => {
|
||||
event = event.toLowerCase()
|
||||
if (!globalListeners[event]) globalListeners[event] = []
|
||||
globalListeners[event].push(fn)
|
||||
}
|
||||
|
||||
const fireGlobal = (event, ...args) => {
|
||||
const listeners = globalListeners[event]
|
||||
if (!listeners) return
|
||||
for (const fn of listeners) {
|
||||
fn(...args)
|
||||
}
|
||||
}
|
||||
|
||||
const fireBeforeUpdate = () => fireGlobal('beforeupdate')
|
||||
|
||||
const fireAfterUpdate = () => fireGlobal('afterupdate')
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.__SVELTE_HMR = {
|
||||
on: onGlobal,
|
||||
}
|
||||
window.dispatchEvent(new CustomEvent('svelte-hmr:ready'))
|
||||
}
|
||||
|
||||
let fatalError = false
|
||||
|
||||
export const hasFatalError = () => fatalError
|
||||
|
||||
/**
|
||||
* Creates a HMR proxy and its associated `reload` function that pushes a new
|
||||
* version to all existing instances of the component.
|
||||
*/
|
||||
export function createProxy({
|
||||
Adapter,
|
||||
id,
|
||||
Component,
|
||||
hotOptions,
|
||||
canAccept,
|
||||
preserveLocalState,
|
||||
}) {
|
||||
const debugName = getDebugName(id)
|
||||
const instances = []
|
||||
|
||||
// current object will be updated, proxy instances will keep a ref
|
||||
const current = {
|
||||
Component,
|
||||
hotOptions,
|
||||
canAccept,
|
||||
preserveLocalState,
|
||||
}
|
||||
|
||||
const name = `Proxy${debugName}`
|
||||
|
||||
// this trick gives the dynamic name Proxy<MyComponent> to the concrete
|
||||
// proxy class... unfortunately, this doesn't shows in dev tools, but
|
||||
// it stills allow to inspect cmp.constructor.name to confirm an instance
|
||||
// is a proxy
|
||||
const proxy = {
|
||||
[name]: class extends ProxyComponent {
|
||||
constructor(options) {
|
||||
try {
|
||||
super(
|
||||
{
|
||||
Adapter,
|
||||
id,
|
||||
debugName,
|
||||
current,
|
||||
register: rerender => {
|
||||
instances.push(rerender)
|
||||
const unregister = () => {
|
||||
const i = instances.indexOf(rerender)
|
||||
instances.splice(i, 1)
|
||||
}
|
||||
return unregister
|
||||
},
|
||||
},
|
||||
options
|
||||
)
|
||||
} catch (err) {
|
||||
// If we fail to create a proxy instance, any instance, that means
|
||||
// that we won't be able to fix this instance when it is updated.
|
||||
// Recovering to normal state will be impossible. HMR's dead.
|
||||
//
|
||||
// Fatal error will trigger a full reload on next update (reloading
|
||||
// right now is kinda pointless since buggy code still exists).
|
||||
//
|
||||
// NOTE Only report first error to avoid too much polution -- following
|
||||
// errors are probably caused by the first one, or they will show up
|
||||
// in turn when the first one is fixed ¯\_(ツ)_/¯
|
||||
//
|
||||
if (!fatalError) {
|
||||
fatalError = true
|
||||
logError(
|
||||
`Unrecoverable HMR error in ${debugName}: ` +
|
||||
`next update will trigger a full reload`
|
||||
)
|
||||
}
|
||||
throw err
|
||||
}
|
||||
}
|
||||
},
|
||||
}[name]
|
||||
|
||||
// initialize static members
|
||||
let previousStatics = syncStatics(current.Component, proxy)
|
||||
|
||||
const update = newState => Object.assign(current, newState)
|
||||
|
||||
// reload all existing instances of this component
|
||||
const reload = () => {
|
||||
fireBeforeUpdate()
|
||||
|
||||
// copy statics before doing anything because a static prop/method
|
||||
// could be used somewhere in the create/render call
|
||||
previousStatics = syncStatics(current.Component, proxy, previousStatics)
|
||||
|
||||
const errors = []
|
||||
|
||||
instances.forEach(rerender => {
|
||||
try {
|
||||
rerender()
|
||||
} catch (err) {
|
||||
logError(`Failed to rerender ${debugName}`, err)
|
||||
errors.push(err)
|
||||
}
|
||||
})
|
||||
|
||||
if (errors.length > 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
fireAfterUpdate()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
const hasFatalError = () => fatalError
|
||||
|
||||
return { id, proxy, update, reload, hasFatalError, current }
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
import { NodePath } from "../lib/node-path";
|
||||
import { Context } from "../lib/path-visitor";
|
||||
import { namedTypes } from "./namedTypes";
|
||||
export interface Visitor<M = {}> {
|
||||
visitPrintable?(this: Context & M, path: NodePath<namedTypes.Printable>): any;
|
||||
visitSourceLocation?(this: Context & M, path: NodePath<namedTypes.SourceLocation>): any;
|
||||
visitNode?(this: Context & M, path: NodePath<namedTypes.Node>): any;
|
||||
visitComment?(this: Context & M, path: NodePath<namedTypes.Comment>): any;
|
||||
visitPosition?(this: Context & M, path: NodePath<namedTypes.Position>): any;
|
||||
visitFile?(this: Context & M, path: NodePath<namedTypes.File>): any;
|
||||
visitProgram?(this: Context & M, path: NodePath<namedTypes.Program>): any;
|
||||
visitStatement?(this: Context & M, path: NodePath<namedTypes.Statement>): any;
|
||||
visitFunction?(this: Context & M, path: NodePath<namedTypes.Function>): any;
|
||||
visitExpression?(this: Context & M, path: NodePath<namedTypes.Expression>): any;
|
||||
visitPattern?(this: Context & M, path: NodePath<namedTypes.Pattern>): any;
|
||||
visitIdentifier?(this: Context & M, path: NodePath<namedTypes.Identifier>): any;
|
||||
visitBlockStatement?(this: Context & M, path: NodePath<namedTypes.BlockStatement>): any;
|
||||
visitEmptyStatement?(this: Context & M, path: NodePath<namedTypes.EmptyStatement>): any;
|
||||
visitExpressionStatement?(this: Context & M, path: NodePath<namedTypes.ExpressionStatement>): any;
|
||||
visitIfStatement?(this: Context & M, path: NodePath<namedTypes.IfStatement>): any;
|
||||
visitLabeledStatement?(this: Context & M, path: NodePath<namedTypes.LabeledStatement>): any;
|
||||
visitBreakStatement?(this: Context & M, path: NodePath<namedTypes.BreakStatement>): any;
|
||||
visitContinueStatement?(this: Context & M, path: NodePath<namedTypes.ContinueStatement>): any;
|
||||
visitWithStatement?(this: Context & M, path: NodePath<namedTypes.WithStatement>): any;
|
||||
visitSwitchStatement?(this: Context & M, path: NodePath<namedTypes.SwitchStatement>): any;
|
||||
visitSwitchCase?(this: Context & M, path: NodePath<namedTypes.SwitchCase>): any;
|
||||
visitReturnStatement?(this: Context & M, path: NodePath<namedTypes.ReturnStatement>): any;
|
||||
visitThrowStatement?(this: Context & M, path: NodePath<namedTypes.ThrowStatement>): any;
|
||||
visitTryStatement?(this: Context & M, path: NodePath<namedTypes.TryStatement>): any;
|
||||
visitCatchClause?(this: Context & M, path: NodePath<namedTypes.CatchClause>): any;
|
||||
visitWhileStatement?(this: Context & M, path: NodePath<namedTypes.WhileStatement>): any;
|
||||
visitDoWhileStatement?(this: Context & M, path: NodePath<namedTypes.DoWhileStatement>): any;
|
||||
visitForStatement?(this: Context & M, path: NodePath<namedTypes.ForStatement>): any;
|
||||
visitDeclaration?(this: Context & M, path: NodePath<namedTypes.Declaration>): any;
|
||||
visitVariableDeclaration?(this: Context & M, path: NodePath<namedTypes.VariableDeclaration>): any;
|
||||
visitForInStatement?(this: Context & M, path: NodePath<namedTypes.ForInStatement>): any;
|
||||
visitDebuggerStatement?(this: Context & M, path: NodePath<namedTypes.DebuggerStatement>): any;
|
||||
visitFunctionDeclaration?(this: Context & M, path: NodePath<namedTypes.FunctionDeclaration>): any;
|
||||
visitFunctionExpression?(this: Context & M, path: NodePath<namedTypes.FunctionExpression>): any;
|
||||
visitVariableDeclarator?(this: Context & M, path: NodePath<namedTypes.VariableDeclarator>): any;
|
||||
visitThisExpression?(this: Context & M, path: NodePath<namedTypes.ThisExpression>): any;
|
||||
visitArrayExpression?(this: Context & M, path: NodePath<namedTypes.ArrayExpression>): any;
|
||||
visitObjectExpression?(this: Context & M, path: NodePath<namedTypes.ObjectExpression>): any;
|
||||
visitProperty?(this: Context & M, path: NodePath<namedTypes.Property>): any;
|
||||
visitLiteral?(this: Context & M, path: NodePath<namedTypes.Literal>): any;
|
||||
visitSequenceExpression?(this: Context & M, path: NodePath<namedTypes.SequenceExpression>): any;
|
||||
visitUnaryExpression?(this: Context & M, path: NodePath<namedTypes.UnaryExpression>): any;
|
||||
visitBinaryExpression?(this: Context & M, path: NodePath<namedTypes.BinaryExpression>): any;
|
||||
visitAssignmentExpression?(this: Context & M, path: NodePath<namedTypes.AssignmentExpression>): any;
|
||||
visitMemberExpression?(this: Context & M, path: NodePath<namedTypes.MemberExpression>): any;
|
||||
visitUpdateExpression?(this: Context & M, path: NodePath<namedTypes.UpdateExpression>): any;
|
||||
visitLogicalExpression?(this: Context & M, path: NodePath<namedTypes.LogicalExpression>): any;
|
||||
visitConditionalExpression?(this: Context & M, path: NodePath<namedTypes.ConditionalExpression>): any;
|
||||
visitNewExpression?(this: Context & M, path: NodePath<namedTypes.NewExpression>): any;
|
||||
visitCallExpression?(this: Context & M, path: NodePath<namedTypes.CallExpression>): any;
|
||||
visitRestElement?(this: Context & M, path: NodePath<namedTypes.RestElement>): any;
|
||||
visitTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.TypeAnnotation>): any;
|
||||
visitTSTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.TSTypeAnnotation>): any;
|
||||
visitSpreadElementPattern?(this: Context & M, path: NodePath<namedTypes.SpreadElementPattern>): any;
|
||||
visitArrowFunctionExpression?(this: Context & M, path: NodePath<namedTypes.ArrowFunctionExpression>): any;
|
||||
visitForOfStatement?(this: Context & M, path: NodePath<namedTypes.ForOfStatement>): any;
|
||||
visitYieldExpression?(this: Context & M, path: NodePath<namedTypes.YieldExpression>): any;
|
||||
visitGeneratorExpression?(this: Context & M, path: NodePath<namedTypes.GeneratorExpression>): any;
|
||||
visitComprehensionBlock?(this: Context & M, path: NodePath<namedTypes.ComprehensionBlock>): any;
|
||||
visitComprehensionExpression?(this: Context & M, path: NodePath<namedTypes.ComprehensionExpression>): any;
|
||||
visitObjectProperty?(this: Context & M, path: NodePath<namedTypes.ObjectProperty>): any;
|
||||
visitPropertyPattern?(this: Context & M, path: NodePath<namedTypes.PropertyPattern>): any;
|
||||
visitObjectPattern?(this: Context & M, path: NodePath<namedTypes.ObjectPattern>): any;
|
||||
visitArrayPattern?(this: Context & M, path: NodePath<namedTypes.ArrayPattern>): any;
|
||||
visitMethodDefinition?(this: Context & M, path: NodePath<namedTypes.MethodDefinition>): any;
|
||||
visitSpreadElement?(this: Context & M, path: NodePath<namedTypes.SpreadElement>): any;
|
||||
visitAssignmentPattern?(this: Context & M, path: NodePath<namedTypes.AssignmentPattern>): any;
|
||||
visitClassPropertyDefinition?(this: Context & M, path: NodePath<namedTypes.ClassPropertyDefinition>): any;
|
||||
visitClassProperty?(this: Context & M, path: NodePath<namedTypes.ClassProperty>): any;
|
||||
visitClassBody?(this: Context & M, path: NodePath<namedTypes.ClassBody>): any;
|
||||
visitClassDeclaration?(this: Context & M, path: NodePath<namedTypes.ClassDeclaration>): any;
|
||||
visitClassExpression?(this: Context & M, path: NodePath<namedTypes.ClassExpression>): any;
|
||||
visitSpecifier?(this: Context & M, path: NodePath<namedTypes.Specifier>): any;
|
||||
visitModuleSpecifier?(this: Context & M, path: NodePath<namedTypes.ModuleSpecifier>): any;
|
||||
visitImportSpecifier?(this: Context & M, path: NodePath<namedTypes.ImportSpecifier>): any;
|
||||
visitImportNamespaceSpecifier?(this: Context & M, path: NodePath<namedTypes.ImportNamespaceSpecifier>): any;
|
||||
visitImportDefaultSpecifier?(this: Context & M, path: NodePath<namedTypes.ImportDefaultSpecifier>): any;
|
||||
visitImportDeclaration?(this: Context & M, path: NodePath<namedTypes.ImportDeclaration>): any;
|
||||
visitTaggedTemplateExpression?(this: Context & M, path: NodePath<namedTypes.TaggedTemplateExpression>): any;
|
||||
visitTemplateLiteral?(this: Context & M, path: NodePath<namedTypes.TemplateLiteral>): any;
|
||||
visitTemplateElement?(this: Context & M, path: NodePath<namedTypes.TemplateElement>): any;
|
||||
visitSpreadProperty?(this: Context & M, path: NodePath<namedTypes.SpreadProperty>): any;
|
||||
visitSpreadPropertyPattern?(this: Context & M, path: NodePath<namedTypes.SpreadPropertyPattern>): any;
|
||||
visitAwaitExpression?(this: Context & M, path: NodePath<namedTypes.AwaitExpression>): any;
|
||||
visitImportExpression?(this: Context & M, path: NodePath<namedTypes.ImportExpression>): any;
|
||||
visitJSXAttribute?(this: Context & M, path: NodePath<namedTypes.JSXAttribute>): any;
|
||||
visitJSXIdentifier?(this: Context & M, path: NodePath<namedTypes.JSXIdentifier>): any;
|
||||
visitJSXNamespacedName?(this: Context & M, path: NodePath<namedTypes.JSXNamespacedName>): any;
|
||||
visitJSXExpressionContainer?(this: Context & M, path: NodePath<namedTypes.JSXExpressionContainer>): any;
|
||||
visitJSXMemberExpression?(this: Context & M, path: NodePath<namedTypes.JSXMemberExpression>): any;
|
||||
visitJSXSpreadAttribute?(this: Context & M, path: NodePath<namedTypes.JSXSpreadAttribute>): any;
|
||||
visitJSXElement?(this: Context & M, path: NodePath<namedTypes.JSXElement>): any;
|
||||
visitJSXOpeningElement?(this: Context & M, path: NodePath<namedTypes.JSXOpeningElement>): any;
|
||||
visitJSXClosingElement?(this: Context & M, path: NodePath<namedTypes.JSXClosingElement>): any;
|
||||
visitJSXFragment?(this: Context & M, path: NodePath<namedTypes.JSXFragment>): any;
|
||||
visitJSXText?(this: Context & M, path: NodePath<namedTypes.JSXText>): any;
|
||||
visitJSXOpeningFragment?(this: Context & M, path: NodePath<namedTypes.JSXOpeningFragment>): any;
|
||||
visitJSXClosingFragment?(this: Context & M, path: NodePath<namedTypes.JSXClosingFragment>): any;
|
||||
visitJSXEmptyExpression?(this: Context & M, path: NodePath<namedTypes.JSXEmptyExpression>): any;
|
||||
visitJSXSpreadChild?(this: Context & M, path: NodePath<namedTypes.JSXSpreadChild>): any;
|
||||
visitTypeParameterDeclaration?(this: Context & M, path: NodePath<namedTypes.TypeParameterDeclaration>): any;
|
||||
visitTSTypeParameterDeclaration?(this: Context & M, path: NodePath<namedTypes.TSTypeParameterDeclaration>): any;
|
||||
visitTypeParameterInstantiation?(this: Context & M, path: NodePath<namedTypes.TypeParameterInstantiation>): any;
|
||||
visitTSTypeParameterInstantiation?(this: Context & M, path: NodePath<namedTypes.TSTypeParameterInstantiation>): any;
|
||||
visitClassImplements?(this: Context & M, path: NodePath<namedTypes.ClassImplements>): any;
|
||||
visitTSType?(this: Context & M, path: NodePath<namedTypes.TSType>): any;
|
||||
visitTSHasOptionalTypeParameterInstantiation?(this: Context & M, path: NodePath<namedTypes.TSHasOptionalTypeParameterInstantiation>): any;
|
||||
visitTSExpressionWithTypeArguments?(this: Context & M, path: NodePath<namedTypes.TSExpressionWithTypeArguments>): any;
|
||||
visitFlow?(this: Context & M, path: NodePath<namedTypes.Flow>): any;
|
||||
visitFlowType?(this: Context & M, path: NodePath<namedTypes.FlowType>): any;
|
||||
visitAnyTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.AnyTypeAnnotation>): any;
|
||||
visitEmptyTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.EmptyTypeAnnotation>): any;
|
||||
visitMixedTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.MixedTypeAnnotation>): any;
|
||||
visitVoidTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.VoidTypeAnnotation>): any;
|
||||
visitNumberTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.NumberTypeAnnotation>): any;
|
||||
visitNumberLiteralTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.NumberLiteralTypeAnnotation>): any;
|
||||
visitNumericLiteralTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.NumericLiteralTypeAnnotation>): any;
|
||||
visitStringTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.StringTypeAnnotation>): any;
|
||||
visitStringLiteralTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.StringLiteralTypeAnnotation>): any;
|
||||
visitBooleanTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.BooleanTypeAnnotation>): any;
|
||||
visitBooleanLiteralTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.BooleanLiteralTypeAnnotation>): any;
|
||||
visitNullableTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.NullableTypeAnnotation>): any;
|
||||
visitNullLiteralTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.NullLiteralTypeAnnotation>): any;
|
||||
visitNullTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.NullTypeAnnotation>): any;
|
||||
visitThisTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.ThisTypeAnnotation>): any;
|
||||
visitExistsTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.ExistsTypeAnnotation>): any;
|
||||
visitExistentialTypeParam?(this: Context & M, path: NodePath<namedTypes.ExistentialTypeParam>): any;
|
||||
visitFunctionTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.FunctionTypeAnnotation>): any;
|
||||
visitFunctionTypeParam?(this: Context & M, path: NodePath<namedTypes.FunctionTypeParam>): any;
|
||||
visitArrayTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.ArrayTypeAnnotation>): any;
|
||||
visitObjectTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.ObjectTypeAnnotation>): any;
|
||||
visitObjectTypeProperty?(this: Context & M, path: NodePath<namedTypes.ObjectTypeProperty>): any;
|
||||
visitObjectTypeSpreadProperty?(this: Context & M, path: NodePath<namedTypes.ObjectTypeSpreadProperty>): any;
|
||||
visitObjectTypeIndexer?(this: Context & M, path: NodePath<namedTypes.ObjectTypeIndexer>): any;
|
||||
visitObjectTypeCallProperty?(this: Context & M, path: NodePath<namedTypes.ObjectTypeCallProperty>): any;
|
||||
visitObjectTypeInternalSlot?(this: Context & M, path: NodePath<namedTypes.ObjectTypeInternalSlot>): any;
|
||||
visitVariance?(this: Context & M, path: NodePath<namedTypes.Variance>): any;
|
||||
visitQualifiedTypeIdentifier?(this: Context & M, path: NodePath<namedTypes.QualifiedTypeIdentifier>): any;
|
||||
visitGenericTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.GenericTypeAnnotation>): any;
|
||||
visitMemberTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.MemberTypeAnnotation>): any;
|
||||
visitUnionTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.UnionTypeAnnotation>): any;
|
||||
visitIntersectionTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.IntersectionTypeAnnotation>): any;
|
||||
visitTypeofTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.TypeofTypeAnnotation>): any;
|
||||
visitTypeParameter?(this: Context & M, path: NodePath<namedTypes.TypeParameter>): any;
|
||||
visitInterfaceTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.InterfaceTypeAnnotation>): any;
|
||||
visitInterfaceExtends?(this: Context & M, path: NodePath<namedTypes.InterfaceExtends>): any;
|
||||
visitInterfaceDeclaration?(this: Context & M, path: NodePath<namedTypes.InterfaceDeclaration>): any;
|
||||
visitDeclareInterface?(this: Context & M, path: NodePath<namedTypes.DeclareInterface>): any;
|
||||
visitTypeAlias?(this: Context & M, path: NodePath<namedTypes.TypeAlias>): any;
|
||||
visitOpaqueType?(this: Context & M, path: NodePath<namedTypes.OpaqueType>): any;
|
||||
visitDeclareTypeAlias?(this: Context & M, path: NodePath<namedTypes.DeclareTypeAlias>): any;
|
||||
visitDeclareOpaqueType?(this: Context & M, path: NodePath<namedTypes.DeclareOpaqueType>): any;
|
||||
visitTypeCastExpression?(this: Context & M, path: NodePath<namedTypes.TypeCastExpression>): any;
|
||||
visitTupleTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.TupleTypeAnnotation>): any;
|
||||
visitDeclareVariable?(this: Context & M, path: NodePath<namedTypes.DeclareVariable>): any;
|
||||
visitDeclareFunction?(this: Context & M, path: NodePath<namedTypes.DeclareFunction>): any;
|
||||
visitDeclareClass?(this: Context & M, path: NodePath<namedTypes.DeclareClass>): any;
|
||||
visitDeclareModule?(this: Context & M, path: NodePath<namedTypes.DeclareModule>): any;
|
||||
visitDeclareModuleExports?(this: Context & M, path: NodePath<namedTypes.DeclareModuleExports>): any;
|
||||
visitDeclareExportDeclaration?(this: Context & M, path: NodePath<namedTypes.DeclareExportDeclaration>): any;
|
||||
visitExportSpecifier?(this: Context & M, path: NodePath<namedTypes.ExportSpecifier>): any;
|
||||
visitExportBatchSpecifier?(this: Context & M, path: NodePath<namedTypes.ExportBatchSpecifier>): any;
|
||||
visitDeclareExportAllDeclaration?(this: Context & M, path: NodePath<namedTypes.DeclareExportAllDeclaration>): any;
|
||||
visitFlowPredicate?(this: Context & M, path: NodePath<namedTypes.FlowPredicate>): any;
|
||||
visitInferredPredicate?(this: Context & M, path: NodePath<namedTypes.InferredPredicate>): any;
|
||||
visitDeclaredPredicate?(this: Context & M, path: NodePath<namedTypes.DeclaredPredicate>): any;
|
||||
visitExportDeclaration?(this: Context & M, path: NodePath<namedTypes.ExportDeclaration>): any;
|
||||
visitBlock?(this: Context & M, path: NodePath<namedTypes.Block>): any;
|
||||
visitLine?(this: Context & M, path: NodePath<namedTypes.Line>): any;
|
||||
visitNoop?(this: Context & M, path: NodePath<namedTypes.Noop>): any;
|
||||
visitDoExpression?(this: Context & M, path: NodePath<namedTypes.DoExpression>): any;
|
||||
visitSuper?(this: Context & M, path: NodePath<namedTypes.Super>): any;
|
||||
visitBindExpression?(this: Context & M, path: NodePath<namedTypes.BindExpression>): any;
|
||||
visitDecorator?(this: Context & M, path: NodePath<namedTypes.Decorator>): any;
|
||||
visitMetaProperty?(this: Context & M, path: NodePath<namedTypes.MetaProperty>): any;
|
||||
visitParenthesizedExpression?(this: Context & M, path: NodePath<namedTypes.ParenthesizedExpression>): any;
|
||||
visitExportDefaultDeclaration?(this: Context & M, path: NodePath<namedTypes.ExportDefaultDeclaration>): any;
|
||||
visitExportNamedDeclaration?(this: Context & M, path: NodePath<namedTypes.ExportNamedDeclaration>): any;
|
||||
visitExportNamespaceSpecifier?(this: Context & M, path: NodePath<namedTypes.ExportNamespaceSpecifier>): any;
|
||||
visitExportDefaultSpecifier?(this: Context & M, path: NodePath<namedTypes.ExportDefaultSpecifier>): any;
|
||||
visitExportAllDeclaration?(this: Context & M, path: NodePath<namedTypes.ExportAllDeclaration>): any;
|
||||
visitCommentBlock?(this: Context & M, path: NodePath<namedTypes.CommentBlock>): any;
|
||||
visitCommentLine?(this: Context & M, path: NodePath<namedTypes.CommentLine>): any;
|
||||
visitDirective?(this: Context & M, path: NodePath<namedTypes.Directive>): any;
|
||||
visitDirectiveLiteral?(this: Context & M, path: NodePath<namedTypes.DirectiveLiteral>): any;
|
||||
visitInterpreterDirective?(this: Context & M, path: NodePath<namedTypes.InterpreterDirective>): any;
|
||||
visitStringLiteral?(this: Context & M, path: NodePath<namedTypes.StringLiteral>): any;
|
||||
visitNumericLiteral?(this: Context & M, path: NodePath<namedTypes.NumericLiteral>): any;
|
||||
visitBigIntLiteral?(this: Context & M, path: NodePath<namedTypes.BigIntLiteral>): any;
|
||||
visitNullLiteral?(this: Context & M, path: NodePath<namedTypes.NullLiteral>): any;
|
||||
visitBooleanLiteral?(this: Context & M, path: NodePath<namedTypes.BooleanLiteral>): any;
|
||||
visitRegExpLiteral?(this: Context & M, path: NodePath<namedTypes.RegExpLiteral>): any;
|
||||
visitObjectMethod?(this: Context & M, path: NodePath<namedTypes.ObjectMethod>): any;
|
||||
visitClassPrivateProperty?(this: Context & M, path: NodePath<namedTypes.ClassPrivateProperty>): any;
|
||||
visitClassMethod?(this: Context & M, path: NodePath<namedTypes.ClassMethod>): any;
|
||||
visitClassPrivateMethod?(this: Context & M, path: NodePath<namedTypes.ClassPrivateMethod>): any;
|
||||
visitPrivateName?(this: Context & M, path: NodePath<namedTypes.PrivateName>): any;
|
||||
visitRestProperty?(this: Context & M, path: NodePath<namedTypes.RestProperty>): any;
|
||||
visitForAwaitStatement?(this: Context & M, path: NodePath<namedTypes.ForAwaitStatement>): any;
|
||||
visitImport?(this: Context & M, path: NodePath<namedTypes.Import>): any;
|
||||
visitTSQualifiedName?(this: Context & M, path: NodePath<namedTypes.TSQualifiedName>): any;
|
||||
visitTSTypeReference?(this: Context & M, path: NodePath<namedTypes.TSTypeReference>): any;
|
||||
visitTSHasOptionalTypeParameters?(this: Context & M, path: NodePath<namedTypes.TSHasOptionalTypeParameters>): any;
|
||||
visitTSHasOptionalTypeAnnotation?(this: Context & M, path: NodePath<namedTypes.TSHasOptionalTypeAnnotation>): any;
|
||||
visitTSAsExpression?(this: Context & M, path: NodePath<namedTypes.TSAsExpression>): any;
|
||||
visitTSNonNullExpression?(this: Context & M, path: NodePath<namedTypes.TSNonNullExpression>): any;
|
||||
visitTSAnyKeyword?(this: Context & M, path: NodePath<namedTypes.TSAnyKeyword>): any;
|
||||
visitTSBigIntKeyword?(this: Context & M, path: NodePath<namedTypes.TSBigIntKeyword>): any;
|
||||
visitTSBooleanKeyword?(this: Context & M, path: NodePath<namedTypes.TSBooleanKeyword>): any;
|
||||
visitTSNeverKeyword?(this: Context & M, path: NodePath<namedTypes.TSNeverKeyword>): any;
|
||||
visitTSNullKeyword?(this: Context & M, path: NodePath<namedTypes.TSNullKeyword>): any;
|
||||
visitTSNumberKeyword?(this: Context & M, path: NodePath<namedTypes.TSNumberKeyword>): any;
|
||||
visitTSObjectKeyword?(this: Context & M, path: NodePath<namedTypes.TSObjectKeyword>): any;
|
||||
visitTSStringKeyword?(this: Context & M, path: NodePath<namedTypes.TSStringKeyword>): any;
|
||||
visitTSSymbolKeyword?(this: Context & M, path: NodePath<namedTypes.TSSymbolKeyword>): any;
|
||||
visitTSUndefinedKeyword?(this: Context & M, path: NodePath<namedTypes.TSUndefinedKeyword>): any;
|
||||
visitTSUnknownKeyword?(this: Context & M, path: NodePath<namedTypes.TSUnknownKeyword>): any;
|
||||
visitTSVoidKeyword?(this: Context & M, path: NodePath<namedTypes.TSVoidKeyword>): any;
|
||||
visitTSThisType?(this: Context & M, path: NodePath<namedTypes.TSThisType>): any;
|
||||
visitTSArrayType?(this: Context & M, path: NodePath<namedTypes.TSArrayType>): any;
|
||||
visitTSLiteralType?(this: Context & M, path: NodePath<namedTypes.TSLiteralType>): any;
|
||||
visitTSUnionType?(this: Context & M, path: NodePath<namedTypes.TSUnionType>): any;
|
||||
visitTSIntersectionType?(this: Context & M, path: NodePath<namedTypes.TSIntersectionType>): any;
|
||||
visitTSConditionalType?(this: Context & M, path: NodePath<namedTypes.TSConditionalType>): any;
|
||||
visitTSInferType?(this: Context & M, path: NodePath<namedTypes.TSInferType>): any;
|
||||
visitTSTypeParameter?(this: Context & M, path: NodePath<namedTypes.TSTypeParameter>): any;
|
||||
visitTSParenthesizedType?(this: Context & M, path: NodePath<namedTypes.TSParenthesizedType>): any;
|
||||
visitTSFunctionType?(this: Context & M, path: NodePath<namedTypes.TSFunctionType>): any;
|
||||
visitTSConstructorType?(this: Context & M, path: NodePath<namedTypes.TSConstructorType>): any;
|
||||
visitTSDeclareFunction?(this: Context & M, path: NodePath<namedTypes.TSDeclareFunction>): any;
|
||||
visitTSDeclareMethod?(this: Context & M, path: NodePath<namedTypes.TSDeclareMethod>): any;
|
||||
visitTSMappedType?(this: Context & M, path: NodePath<namedTypes.TSMappedType>): any;
|
||||
visitTSTupleType?(this: Context & M, path: NodePath<namedTypes.TSTupleType>): any;
|
||||
visitTSNamedTupleMember?(this: Context & M, path: NodePath<namedTypes.TSNamedTupleMember>): any;
|
||||
visitTSRestType?(this: Context & M, path: NodePath<namedTypes.TSRestType>): any;
|
||||
visitTSOptionalType?(this: Context & M, path: NodePath<namedTypes.TSOptionalType>): any;
|
||||
visitTSIndexedAccessType?(this: Context & M, path: NodePath<namedTypes.TSIndexedAccessType>): any;
|
||||
visitTSTypeOperator?(this: Context & M, path: NodePath<namedTypes.TSTypeOperator>): any;
|
||||
visitTSIndexSignature?(this: Context & M, path: NodePath<namedTypes.TSIndexSignature>): any;
|
||||
visitTSPropertySignature?(this: Context & M, path: NodePath<namedTypes.TSPropertySignature>): any;
|
||||
visitTSMethodSignature?(this: Context & M, path: NodePath<namedTypes.TSMethodSignature>): any;
|
||||
visitTSTypePredicate?(this: Context & M, path: NodePath<namedTypes.TSTypePredicate>): any;
|
||||
visitTSCallSignatureDeclaration?(this: Context & M, path: NodePath<namedTypes.TSCallSignatureDeclaration>): any;
|
||||
visitTSConstructSignatureDeclaration?(this: Context & M, path: NodePath<namedTypes.TSConstructSignatureDeclaration>): any;
|
||||
visitTSEnumMember?(this: Context & M, path: NodePath<namedTypes.TSEnumMember>): any;
|
||||
visitTSTypeQuery?(this: Context & M, path: NodePath<namedTypes.TSTypeQuery>): any;
|
||||
visitTSImportType?(this: Context & M, path: NodePath<namedTypes.TSImportType>): any;
|
||||
visitTSTypeLiteral?(this: Context & M, path: NodePath<namedTypes.TSTypeLiteral>): any;
|
||||
visitTSTypeAssertion?(this: Context & M, path: NodePath<namedTypes.TSTypeAssertion>): any;
|
||||
visitTSEnumDeclaration?(this: Context & M, path: NodePath<namedTypes.TSEnumDeclaration>): any;
|
||||
visitTSTypeAliasDeclaration?(this: Context & M, path: NodePath<namedTypes.TSTypeAliasDeclaration>): any;
|
||||
visitTSModuleBlock?(this: Context & M, path: NodePath<namedTypes.TSModuleBlock>): any;
|
||||
visitTSModuleDeclaration?(this: Context & M, path: NodePath<namedTypes.TSModuleDeclaration>): any;
|
||||
visitTSImportEqualsDeclaration?(this: Context & M, path: NodePath<namedTypes.TSImportEqualsDeclaration>): any;
|
||||
visitTSExternalModuleReference?(this: Context & M, path: NodePath<namedTypes.TSExternalModuleReference>): any;
|
||||
visitTSExportAssignment?(this: Context & M, path: NodePath<namedTypes.TSExportAssignment>): any;
|
||||
visitTSNamespaceExportDeclaration?(this: Context & M, path: NodePath<namedTypes.TSNamespaceExportDeclaration>): any;
|
||||
visitTSInterfaceBody?(this: Context & M, path: NodePath<namedTypes.TSInterfaceBody>): any;
|
||||
visitTSInterfaceDeclaration?(this: Context & M, path: NodePath<namedTypes.TSInterfaceDeclaration>): any;
|
||||
visitTSParameterProperty?(this: Context & M, path: NodePath<namedTypes.TSParameterProperty>): any;
|
||||
visitOptionalMemberExpression?(this: Context & M, path: NodePath<namedTypes.OptionalMemberExpression>): any;
|
||||
visitOptionalCallExpression?(this: Context & M, path: NodePath<namedTypes.OptionalCallExpression>): any;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
const {
|
||||
ERR_HTTP_INVALID_HEADER_VALUE,
|
||||
ERR_INVALID_CHAR
|
||||
} = require('./errors.js');
|
||||
|
||||
const isInvalidHeaderValue = /[^\t\u0020-\u007E\u0080-\u00FF]/;
|
||||
|
||||
module.exports = (name, value) => {
|
||||
if (typeof value === 'undefined') {
|
||||
throw new ERR_HTTP_INVALID_HEADER_VALUE(value, name);
|
||||
}
|
||||
|
||||
if (isInvalidHeaderValue.test(value)) {
|
||||
throw new ERR_INVALID_CHAR('header content', name);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,358 @@
|
||||
const { Rule, AtRule } = require('postcss')
|
||||
let parser = require('postcss-selector-parser')
|
||||
|
||||
/**
|
||||
* Run a selector string through postcss-selector-parser
|
||||
*/
|
||||
function parse(rawSelector, rule) {
|
||||
let nodes
|
||||
try {
|
||||
parser(parsed => {
|
||||
nodes = parsed
|
||||
}).processSync(rawSelector)
|
||||
} catch (e) {
|
||||
if (rawSelector.includes(':')) {
|
||||
throw rule ? rule.error('Missed semicolon') : e
|
||||
} else {
|
||||
throw rule ? rule.error(e.message) : e
|
||||
}
|
||||
}
|
||||
return nodes.at(0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the "&" token in a node's selector with the parent selector
|
||||
* similar to what SCSS does.
|
||||
*
|
||||
* Mutates the nodes list
|
||||
*/
|
||||
function interpolateAmpInSelector(nodes, parent) {
|
||||
let replaced = false
|
||||
nodes.each(node => {
|
||||
if (node.type === 'nesting') {
|
||||
let clonedParent = parent.clone({})
|
||||
if (node.value !== '&') {
|
||||
node.replaceWith(
|
||||
parse(node.value.replace('&', clonedParent.toString()))
|
||||
)
|
||||
} else {
|
||||
node.replaceWith(clonedParent)
|
||||
}
|
||||
replaced = true
|
||||
} else if ('nodes' in node && node.nodes) {
|
||||
if (interpolateAmpInSelector(node, parent)) {
|
||||
replaced = true
|
||||
}
|
||||
}
|
||||
})
|
||||
return replaced
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines parent and child selectors, in a SCSS-like way
|
||||
*/
|
||||
function mergeSelectors(parent, child) {
|
||||
let merged = []
|
||||
parent.selectors.forEach(sel => {
|
||||
let parentNode = parse(sel, parent)
|
||||
|
||||
child.selectors.forEach(selector => {
|
||||
if (!selector) {
|
||||
return
|
||||
}
|
||||
let node = parse(selector, child)
|
||||
let replaced = interpolateAmpInSelector(node, parentNode)
|
||||
if (!replaced) {
|
||||
node.prepend(parser.combinator({ value: ' ' }))
|
||||
node.prepend(parentNode.clone({}))
|
||||
}
|
||||
merged.push(node.toString())
|
||||
})
|
||||
})
|
||||
return merged
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a child and its preceeding comment(s) to after "after"
|
||||
*/
|
||||
function breakOut(child, after) {
|
||||
let prev = child.prev()
|
||||
after.after(child)
|
||||
while (prev && prev.type === 'comment') {
|
||||
let nextPrev = prev.prev()
|
||||
after.after(prev)
|
||||
prev = nextPrev
|
||||
}
|
||||
return child
|
||||
}
|
||||
|
||||
function createFnAtruleChilds(bubble) {
|
||||
return function atruleChilds(rule, atrule, bubbling, mergeSels = bubbling) {
|
||||
let children = []
|
||||
atrule.each(child => {
|
||||
if (child.type === 'rule' && bubbling) {
|
||||
if (mergeSels) {
|
||||
child.selectors = mergeSelectors(rule, child)
|
||||
}
|
||||
} else if (child.type === 'atrule' && child.nodes) {
|
||||
if (bubble[child.name]) {
|
||||
atruleChilds(rule, child, mergeSels)
|
||||
} else if (atrule[rootRuleMergeSel] !== false) {
|
||||
children.push(child)
|
||||
}
|
||||
} else {
|
||||
children.push(child)
|
||||
}
|
||||
})
|
||||
if (bubbling) {
|
||||
if (children.length) {
|
||||
let clone = rule.clone({ nodes: [] })
|
||||
for (let child of children) {
|
||||
clone.append(child)
|
||||
}
|
||||
atrule.prepend(clone)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pickDeclarations(selector, declarations, after) {
|
||||
let parent = new Rule({
|
||||
selector,
|
||||
nodes: []
|
||||
})
|
||||
parent.append(declarations)
|
||||
after.after(parent)
|
||||
return parent
|
||||
}
|
||||
|
||||
function atruleNames(defaults, custom) {
|
||||
let list = {}
|
||||
for (let name of defaults) {
|
||||
list[name] = true
|
||||
}
|
||||
if (custom) {
|
||||
for (let name of custom) {
|
||||
list[name.replace(/^@/, '')] = true
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
function parseRootRuleParams(params) {
|
||||
params = params.trim()
|
||||
let braceBlock = params.match(/^\((.*)\)$/)
|
||||
if (!braceBlock) {
|
||||
return { type: 'basic', selector: params }
|
||||
}
|
||||
let bits = braceBlock[1].match(/^(with(?:out)?):(.+)$/)
|
||||
if (bits) {
|
||||
let allowlist = bits[1] === 'with'
|
||||
let rules = Object.fromEntries(
|
||||
bits[2]
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.map(name => [name, true])
|
||||
)
|
||||
if (allowlist && rules.all) {
|
||||
return { type: 'noop' }
|
||||
}
|
||||
let escapes = rule => !!rules[rule]
|
||||
if (rules.all) {
|
||||
escapes = () => true
|
||||
} else if (allowlist) {
|
||||
escapes = rule => (rule === 'all' ? false : !rules[rule])
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'withrules',
|
||||
escapes
|
||||
}
|
||||
}
|
||||
// Unrecognized brace block
|
||||
return { type: 'unknown' }
|
||||
}
|
||||
|
||||
function getAncestorRules(leaf) {
|
||||
let lineage = []
|
||||
let parent = leaf.parent
|
||||
|
||||
while (parent && parent instanceof AtRule) {
|
||||
lineage.push(parent)
|
||||
parent = parent.parent
|
||||
}
|
||||
return lineage
|
||||
}
|
||||
|
||||
function unwrapRootRule(rule) {
|
||||
let escapes = rule[rootRuleEscapes]
|
||||
|
||||
if (!escapes) {
|
||||
rule.after(rule.nodes)
|
||||
} else {
|
||||
let nodes = rule.nodes
|
||||
|
||||
let topEscaped
|
||||
let topEscapedIdx = -1
|
||||
let breakoutLeaf
|
||||
let breakoutRoot
|
||||
let clone
|
||||
|
||||
let lineage = getAncestorRules(rule)
|
||||
lineage.forEach((parent, i) => {
|
||||
if (escapes(parent.name)) {
|
||||
topEscaped = parent
|
||||
topEscapedIdx = i
|
||||
breakoutRoot = clone
|
||||
} else {
|
||||
let oldClone = clone
|
||||
clone = parent.clone({ nodes: [] })
|
||||
oldClone && clone.append(oldClone)
|
||||
breakoutLeaf = breakoutLeaf || clone
|
||||
}
|
||||
})
|
||||
|
||||
if (!topEscaped) {
|
||||
rule.after(nodes)
|
||||
} else if (!breakoutRoot) {
|
||||
topEscaped.after(nodes)
|
||||
} else {
|
||||
let leaf = breakoutLeaf
|
||||
leaf.append(nodes)
|
||||
topEscaped.after(breakoutRoot)
|
||||
}
|
||||
|
||||
if (rule.next() && topEscaped) {
|
||||
let restRoot
|
||||
lineage.slice(0, topEscapedIdx + 1).forEach((parent, i, arr) => {
|
||||
let oldRoot = restRoot
|
||||
restRoot = parent.clone({ nodes: [] })
|
||||
oldRoot && restRoot.append(oldRoot)
|
||||
|
||||
let nextSibs = []
|
||||
let _child = arr[i - 1] || rule
|
||||
let next = _child.next()
|
||||
while (next) {
|
||||
nextSibs.push(next)
|
||||
next = next.next()
|
||||
}
|
||||
restRoot.append(nextSibs)
|
||||
})
|
||||
restRoot && (breakoutRoot || nodes[nodes.length - 1]).after(restRoot)
|
||||
}
|
||||
}
|
||||
|
||||
rule.remove()
|
||||
}
|
||||
|
||||
const rootRuleMergeSel = Symbol('rootRuleMergeSel')
|
||||
const rootRuleEscapes = Symbol('rootRuleEscapes')
|
||||
|
||||
function normalizeRootRule(rule) {
|
||||
let { params } = rule
|
||||
let { type, selector, escapes } = parseRootRuleParams(params)
|
||||
if (type === 'unknown') {
|
||||
throw rule.error(
|
||||
`Unknown @${rule.name} parameter ${JSON.stringify(params)}`
|
||||
)
|
||||
}
|
||||
if (type === 'basic' && selector) {
|
||||
let selectorBlock = new Rule({ selector, nodes: rule.nodes })
|
||||
rule.removeAll()
|
||||
rule.append(selectorBlock)
|
||||
}
|
||||
rule[rootRuleEscapes] = escapes
|
||||
rule[rootRuleMergeSel] = escapes ? !escapes('all') : type === 'noop'
|
||||
}
|
||||
|
||||
const hasRootRule = Symbol('hasRootRule')
|
||||
|
||||
module.exports = (opts = {}) => {
|
||||
let bubble = atruleNames(['media', 'supports', 'layer'], opts.bubble)
|
||||
let atruleChilds = createFnAtruleChilds(bubble)
|
||||
let unwrap = atruleNames(
|
||||
[
|
||||
'document',
|
||||
'font-face',
|
||||
'keyframes',
|
||||
'-webkit-keyframes',
|
||||
'-moz-keyframes'
|
||||
],
|
||||
opts.unwrap
|
||||
)
|
||||
let rootRuleName = (opts.rootRuleName || 'at-root').replace(/^@/, '')
|
||||
let preserveEmpty = opts.preserveEmpty
|
||||
|
||||
return {
|
||||
postcssPlugin: 'postcss-nested',
|
||||
|
||||
Once(root) {
|
||||
root.walkAtRules(rootRuleName, node => {
|
||||
normalizeRootRule(node)
|
||||
root[hasRootRule] = true
|
||||
})
|
||||
},
|
||||
|
||||
Rule(rule) {
|
||||
let unwrapped = false
|
||||
let after = rule
|
||||
let copyDeclarations = false
|
||||
let declarations = []
|
||||
|
||||
rule.each(child => {
|
||||
if (child.type === 'rule') {
|
||||
if (declarations.length) {
|
||||
after = pickDeclarations(rule.selector, declarations, after)
|
||||
declarations = []
|
||||
}
|
||||
|
||||
copyDeclarations = true
|
||||
unwrapped = true
|
||||
child.selectors = mergeSelectors(rule, child)
|
||||
after = breakOut(child, after)
|
||||
} else if (child.type === 'atrule') {
|
||||
if (declarations.length) {
|
||||
after = pickDeclarations(rule.selector, declarations, after)
|
||||
declarations = []
|
||||
}
|
||||
if (child.name === rootRuleName) {
|
||||
unwrapped = true
|
||||
atruleChilds(rule, child, true, child[rootRuleMergeSel])
|
||||
after = breakOut(child, after)
|
||||
} else if (bubble[child.name]) {
|
||||
copyDeclarations = true
|
||||
unwrapped = true
|
||||
atruleChilds(rule, child, true)
|
||||
after = breakOut(child, after)
|
||||
} else if (unwrap[child.name]) {
|
||||
copyDeclarations = true
|
||||
unwrapped = true
|
||||
atruleChilds(rule, child, false)
|
||||
after = breakOut(child, after)
|
||||
} else if (copyDeclarations) {
|
||||
declarations.push(child)
|
||||
}
|
||||
} else if (child.type === 'decl' && copyDeclarations) {
|
||||
declarations.push(child)
|
||||
}
|
||||
})
|
||||
|
||||
if (declarations.length) {
|
||||
after = pickDeclarations(rule.selector, declarations, after)
|
||||
}
|
||||
|
||||
if (unwrapped && preserveEmpty !== true) {
|
||||
rule.raws.semicolon = true
|
||||
if (rule.nodes.length === 0) rule.remove()
|
||||
}
|
||||
},
|
||||
|
||||
RootExit(root) {
|
||||
if (root[hasRootRule]) {
|
||||
root.walkAtRules(rootRuleName, unwrapRootRule)
|
||||
root[hasRootRule] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports.postcss = true
|
||||
@@ -0,0 +1,182 @@
|
||||
'use strict';
|
||||
|
||||
/* globals window */
|
||||
|
||||
var test = require('tape');
|
||||
var forEach = require('../');
|
||||
|
||||
test('forEach calls each iterator', function (t) {
|
||||
var count = 0;
|
||||
t.plan(4);
|
||||
forEach({ a: 1, b: 2 }, function (value, key) {
|
||||
if (count === 0) {
|
||||
t.equal(value, 1);
|
||||
t.equal(key, 'a');
|
||||
} else {
|
||||
t.equal(value, 2);
|
||||
t.equal(key, 'b');
|
||||
}
|
||||
count += 1;
|
||||
});
|
||||
});
|
||||
|
||||
test('forEach calls iterator with correct this value', function (t) {
|
||||
var thisValue = {};
|
||||
|
||||
t.plan(1);
|
||||
|
||||
forEach([0], function () {
|
||||
t.equal(this, thisValue);
|
||||
}, thisValue);
|
||||
});
|
||||
|
||||
test('second argument: iterator', function (t) {
|
||||
var arr = [];
|
||||
t['throws'](function () { forEach(arr); }, TypeError, 'undefined is not a function');
|
||||
t['throws'](function () { forEach(arr, null); }, TypeError, 'null is not a function');
|
||||
t['throws'](function () { forEach(arr, ''); }, TypeError, 'string is not a function');
|
||||
t['throws'](function () { forEach(arr, /a/); }, TypeError, 'regex is not a function');
|
||||
t['throws'](function () { forEach(arr, true); }, TypeError, 'true is not a function');
|
||||
t['throws'](function () { forEach(arr, false); }, TypeError, 'false is not a function');
|
||||
t['throws'](function () { forEach(arr, NaN); }, TypeError, 'NaN is not a function');
|
||||
t['throws'](function () { forEach(arr, 42); }, TypeError, '42 is not a function');
|
||||
t.doesNotThrow(function () { forEach(arr, function () {}); }, 'function is a function');
|
||||
t.doesNotThrow(function () { forEach(arr, setTimeout); }, 'setTimeout is a function');
|
||||
if (typeof window !== 'undefined') {
|
||||
t.doesNotThrow(function () { forEach(arr, window.alert); }, 'alert is a function');
|
||||
}
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('array', function (t) {
|
||||
var arr = [1, 2, 3];
|
||||
|
||||
t.test('iterates over every item', function (st) {
|
||||
var index = 0;
|
||||
forEach(arr, function () { index += 1; });
|
||||
st.equal(index, arr.length, 'iterates ' + arr.length + ' times');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('first iterator argument', function (st) {
|
||||
var index = 0;
|
||||
st.plan(arr.length);
|
||||
forEach(arr, function (item) {
|
||||
st.equal(arr[index], item, 'item ' + index + ' is passed as first argument');
|
||||
index += 1;
|
||||
});
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('second iterator argument', function (st) {
|
||||
var counter = 0;
|
||||
st.plan(arr.length);
|
||||
forEach(arr, function (item, index) {
|
||||
st.equal(counter, index, 'index ' + index + ' is passed as second argument');
|
||||
counter += 1;
|
||||
});
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('third iterator argument', function (st) {
|
||||
st.plan(arr.length);
|
||||
forEach(arr, function (item, index, array) {
|
||||
st.deepEqual(arr, array, 'array is passed as third argument');
|
||||
});
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('context argument', function (st) {
|
||||
var context = {};
|
||||
forEach([], function () {
|
||||
st.equal(this, context, '"this" is the passed context');
|
||||
}, context);
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('object', function (t) {
|
||||
var obj = {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3
|
||||
};
|
||||
var keys = ['a', 'b', 'c'];
|
||||
|
||||
var F = function F() {
|
||||
this.a = 1;
|
||||
this.b = 2;
|
||||
};
|
||||
F.prototype.c = 3;
|
||||
var fKeys = ['a', 'b'];
|
||||
|
||||
t.test('iterates over every object literal key', function (st) {
|
||||
var counter = 0;
|
||||
forEach(obj, function () { counter += 1; });
|
||||
st.equal(counter, keys.length, 'iterated ' + counter + ' times');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('iterates only over own keys', function (st) {
|
||||
var counter = 0;
|
||||
forEach(new F(), function () { counter += 1; });
|
||||
st.equal(counter, fKeys.length, 'iterated ' + fKeys.length + ' times');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('first iterator argument', function (st) {
|
||||
var index = 0;
|
||||
st.plan(keys.length);
|
||||
forEach(obj, function (item) {
|
||||
st.equal(obj[keys[index]], item, 'item at key ' + keys[index] + ' is passed as first argument');
|
||||
index += 1;
|
||||
});
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('second iterator argument', function (st) {
|
||||
var counter = 0;
|
||||
st.plan(keys.length);
|
||||
forEach(obj, function (item, key) {
|
||||
st.equal(keys[counter], key, 'key ' + key + ' is passed as second argument');
|
||||
counter += 1;
|
||||
});
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('third iterator argument', function (st) {
|
||||
st.plan(keys.length);
|
||||
forEach(obj, function (item, key, object) {
|
||||
st.deepEqual(obj, object, 'object is passed as third argument');
|
||||
});
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('context argument', function (st) {
|
||||
var context = {};
|
||||
forEach({}, function () {
|
||||
st.equal(this, context, '"this" is the passed context');
|
||||
}, context);
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('string', function (t) {
|
||||
var str = 'str';
|
||||
t.test('second iterator argument', function (st) {
|
||||
var counter = 0;
|
||||
st.plan((str.length * 2) + 1);
|
||||
forEach(str, function (item, index) {
|
||||
st.equal(counter, index, 'index ' + index + ' is passed as second argument');
|
||||
st.equal(str.charAt(index), item);
|
||||
counter += 1;
|
||||
});
|
||||
st.equal(counter, str.length, 'iterates ' + str.length + ' times');
|
||||
st.end();
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
|
||||
var toPosInt = require("../number/to-pos-integer");
|
||||
|
||||
var test = function (arg1, arg2) { return arg2; };
|
||||
|
||||
var desc, defineProperty, generate, mixin;
|
||||
|
||||
try {
|
||||
Object.defineProperty(test, "length", {
|
||||
configurable: true,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
value: 1
|
||||
});
|
||||
}
|
||||
catch (ignore) {}
|
||||
|
||||
if (test.length === 1) {
|
||||
// ES6
|
||||
desc = { configurable: true, writable: false, enumerable: false };
|
||||
defineProperty = Object.defineProperty;
|
||||
module.exports = function (fn, length) {
|
||||
length = toPosInt(length);
|
||||
if (fn.length === length) return fn;
|
||||
desc.value = length;
|
||||
return defineProperty(fn, "length", desc);
|
||||
};
|
||||
} else {
|
||||
mixin = require("../object/mixin");
|
||||
generate = (function () {
|
||||
var cache = [];
|
||||
return function (length) {
|
||||
var args, i = 0;
|
||||
if (cache[length]) return cache[length];
|
||||
args = [];
|
||||
while (length--) args.push("a" + (++i).toString(36));
|
||||
// eslint-disable-next-line no-new-func
|
||||
return new Function(
|
||||
"fn",
|
||||
"return function (" + args.join(", ") + ") { return fn.apply(this, arguments); };"
|
||||
);
|
||||
};
|
||||
})();
|
||||
module.exports = function (src, length) {
|
||||
var target;
|
||||
length = toPosInt(length);
|
||||
if (src.length === length) return src;
|
||||
target = generate(length)(src);
|
||||
try { mixin(target, src); }
|
||||
catch (ignore) {}
|
||||
return target;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"name":"is-typed-array","version":"1.1.10","files":{".editorconfig":{"checkedAt":1678883671533,"integrity":"sha512-gD3iQtgC7ZgFS97pyZqR0FPjMNyRAfat8dipbSL28iiJ6B1MP5dDeDYeEnP5sYMTz8whQIk3E5vltk2kcyJJEQ==","mode":420,"size":286},".nycrc":{"checkedAt":1678883669555,"integrity":"sha512-2vm1RFz8Ajl/OYrfoCWPJIm3Bpnf7Gyn5bha/lZx/cq+We3uMy9xj15XeP6x4wF3jf/pO7KMHAkU9mllm605xg==","mode":420,"size":139},".eslintrc":{"checkedAt":1678883671601,"integrity":"sha512-opsU4hyVOCWl+KD70vgmjIa3hpyg/3Wep8bJx1ymVsisTnTCAqMIAkK9W20KywP2+MT6gvW8ary69F4yqbhrYA==","mode":420,"size":148},"LICENSE":{"checkedAt":1678883671601,"integrity":"sha512-CWRd82wre8E2D9wfNTwrOCxhLsdU7obtQTc4poEGt1uTk93MEI2QW01sXILetqMRgoYp4EIKQZNHNCQrALOFjw==","mode":420,"size":1082},"index.js":{"checkedAt":1678883671601,"integrity":"sha512-cpM/+IKJRB2hLVhwfgL8TUflskOzvwrUd9euh8CAU9RkivWvJhcKKwMvaMhayufFMAzTeoRiVoWCwA0Lrkgmtg==","mode":420,"size":1770},"test/index.js":{"checkedAt":1678883671601,"integrity":"sha512-Y931f5uyGkNaZhOEW/TWGL3rVtY+VxJuuYvELmN6qLMd5Ttupteey7efyZ/N2T+O12MaYlGKkzGvD6AKi+TH3g==","mode":420,"size":3096},"package.json":{"checkedAt":1678883671601,"integrity":"sha512-WH4xL4/rKhhFU6s5EDDNNjjplZY0l8r1k3cT/+3NqCJDgFqlJ5Z27EKSCbxQ7zmCort3ENa5WCCfMFZQ1Rz9vQ==","mode":420,"size":2931},"README.md":{"checkedAt":1678883671611,"integrity":"sha512-xtsLGBqdS/IhkZNnfpcZqJWQmmXzBgY4kBPQ5l4zjWxtALv+g95Id86TZ4tyjLYL9wbnKsToPIX+O93mGhWrnw==","mode":420,"size":3121},"CHANGELOG.md":{"checkedAt":1678883671611,"integrity":"sha512-lO4TkybBGZGsA1/PhIxXBrwxhBo/k/fUpV5CPI2TCkJ2VLAkUyc93H76aQctFDa3Evam0BHGsidbhW9kNUr2ng==","mode":420,"size":5276},".github/FUNDING.yml":{"checkedAt":1678883671611,"integrity":"sha512-LNX9j+IdPy0LysKTJb0vUM5ZJKsvlL8Ng6Y+a1OQSmHCXAMCKAEFyxCw6/ucNvQadXte7n1ygzhvXO85q3su0g==","mode":420,"size":585}}}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { distinctUntilChanged } from './distinctUntilChanged';
|
||||
export function distinctUntilKeyChanged(key, compare) {
|
||||
return distinctUntilChanged((x, y) => compare ? compare(x[key], y[key]) : x[key] === y[key]);
|
||||
}
|
||||
//# sourceMappingURL=distinctUntilKeyChanged.js.map
|
||||
@@ -0,0 +1,12 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [ljharb]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: npm/es-to-primitive
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
@@ -0,0 +1,15 @@
|
||||
/** Used to detect strings that need a more robust regexp to match words. */
|
||||
var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
|
||||
|
||||
/**
|
||||
* Checks if `string` contains a word composed of Unicode symbols.
|
||||
*
|
||||
* @private
|
||||
* @param {string} string The string to inspect.
|
||||
* @returns {boolean} Returns `true` if a word is found, else `false`.
|
||||
*/
|
||||
function hasUnicodeWord(string) {
|
||||
return reHasUnicodeWord.test(string);
|
||||
}
|
||||
|
||||
module.exports = hasUnicodeWord;
|
||||
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $EvalError = GetIntrinsic('%EvalError%');
|
||||
|
||||
var DayWithinYear = require('./DayWithinYear');
|
||||
var InLeapYear = require('./InLeapYear');
|
||||
var MonthFromTime = require('./MonthFromTime');
|
||||
|
||||
// https://262.ecma-international.org/5.1/#sec-15.9.1.5
|
||||
|
||||
module.exports = function DateFromTime(t) {
|
||||
var m = MonthFromTime(t);
|
||||
var d = DayWithinYear(t);
|
||||
if (m === 0) {
|
||||
return d + 1;
|
||||
}
|
||||
if (m === 1) {
|
||||
return d - 30;
|
||||
}
|
||||
var leap = InLeapYear(t);
|
||||
if (m === 2) {
|
||||
return d - 58 - leap;
|
||||
}
|
||||
if (m === 3) {
|
||||
return d - 89 - leap;
|
||||
}
|
||||
if (m === 4) {
|
||||
return d - 119 - leap;
|
||||
}
|
||||
if (m === 5) {
|
||||
return d - 150 - leap;
|
||||
}
|
||||
if (m === 6) {
|
||||
return d - 180 - leap;
|
||||
}
|
||||
if (m === 7) {
|
||||
return d - 211 - leap;
|
||||
}
|
||||
if (m === 8) {
|
||||
return d - 242 - leap;
|
||||
}
|
||||
if (m === 9) {
|
||||
return d - 272 - leap;
|
||||
}
|
||||
if (m === 10) {
|
||||
return d - 303 - leap;
|
||||
}
|
||||
if (m === 11) {
|
||||
return d - 333 - leap;
|
||||
}
|
||||
throw new $EvalError('Assertion failed: MonthFromTime returned an impossible value: ' + m);
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
import { innerFrom } from '../observable/innerFrom';
|
||||
import { Subject } from '../Subject';
|
||||
import { operate } from '../util/lift';
|
||||
import { createOperatorSubscriber } from './OperatorSubscriber';
|
||||
export function repeatWhen(notifier) {
|
||||
return operate(function (source, subscriber) {
|
||||
var innerSub;
|
||||
var syncResub = false;
|
||||
var completions$;
|
||||
var isNotifierComplete = false;
|
||||
var isMainComplete = false;
|
||||
var checkComplete = function () { return isMainComplete && isNotifierComplete && (subscriber.complete(), true); };
|
||||
var getCompletionSubject = function () {
|
||||
if (!completions$) {
|
||||
completions$ = new Subject();
|
||||
innerFrom(notifier(completions$)).subscribe(createOperatorSubscriber(subscriber, function () {
|
||||
if (innerSub) {
|
||||
subscribeForRepeatWhen();
|
||||
}
|
||||
else {
|
||||
syncResub = true;
|
||||
}
|
||||
}, function () {
|
||||
isNotifierComplete = true;
|
||||
checkComplete();
|
||||
}));
|
||||
}
|
||||
return completions$;
|
||||
};
|
||||
var subscribeForRepeatWhen = function () {
|
||||
isMainComplete = false;
|
||||
innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, function () {
|
||||
isMainComplete = true;
|
||||
!checkComplete() && getCompletionSubject().next();
|
||||
}));
|
||||
if (syncResub) {
|
||||
innerSub.unsubscribe();
|
||||
innerSub = null;
|
||||
syncResub = false;
|
||||
subscribeForRepeatWhen();
|
||||
}
|
||||
};
|
||||
subscribeForRepeatWhen();
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=repeatWhen.js.map
|
||||
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
|
||||
var runTests = require('./builtin');
|
||||
|
||||
test('shimmed', function (t) {
|
||||
runTests(t);
|
||||
|
||||
t.end();
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"SetNumberFormatUnitOptions.d.ts","sourceRoot":"","sources":["../../../../../../packages/ecma402-abstract/NumberFormat/SetNumberFormatUnitOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAE,mBAAmB,EAAC,MAAM,iBAAiB,CAAA;AAKzE;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,IAAI,CAAC,YAAY,EACrB,OAAO,iCAA2C,EAClD,EACE,gBAAgB,GACjB,EAAE;IAAC,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,YAAY,GAAG,oBAAoB,CAAA;CAAC,QA+DnE"}
|
||||
@@ -0,0 +1,2 @@
|
||||
if(typeof cptable === 'undefined') cptable = {};
|
||||
cptable[10029] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ", D = [], e = {}; for(var i=0;i!=d.length;++i) { if(d.charCodeAt(i) !== 0xFFFD) e[d.charAt(i)] = i; D[i] = d.charAt(i); } return {"enc": e, "dec": D }; })();
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"1":"J D E F A B","2":"CC"},B:{"1":"C K L G M N O P Q R S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H"},C:{"1":"0 1 2 3 4 5 6 7 8 9 D E F A B C K L G M N O w g x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H xB yB","8":"DC tB I v J EC FC"},D:{"1":"0 1 2 3 4 5 6 7 8 9 I v J D E F A B C K L G M N O w g x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H xB yB GC"},E:{"1":"I v J D E F A B C K L G HC zB IC JC KC LC 0B qB rB 1B MC NC 2B 3B 4B 5B sB 6B 7B 8B 9B OC"},F:{"1":"0 1 2 3 4 5 6 7 8 9 B C G M N O w g x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d e qB AC TC rB","33":"F PC QC RC SC"},G:{"1":"E zB UC BC VC WC XC YC ZC aC bC cC dC eC fC gC hC iC jC kC lC mC nC 2B 3B 4B 5B sB 6B 7B 8B 9B"},H:{"1":"oC"},I:{"1":"tB I f pC qC rC sC BC tC uC"},J:{"1":"D A"},K:{"1":"h rB","33":"A B C qB AC"},L:{"1":"H"},M:{"1":"H"},N:{"1":"A B"},O:{"1":"vC"},P:{"1":"I g wC xC yC zC 0C 0B 1C 2C 3C 4C 5C sB 6C 7C 8C"},Q:{"1":"1B"},R:{"1":"9C"},S:{"1":"AD BD"}},B:2,C:"CSS3 Text-overflow"};
|
||||
@@ -0,0 +1,315 @@
|
||||
{
|
||||
"name": "csvtojson",
|
||||
"description": "A tool concentrating on converting csv data to JSON with customised parser supporting",
|
||||
"author": "Keyang Xiang <keyang.xiang@gmail.com>",
|
||||
"homepage": "https://github.com/Keyang/node-csvtojson",
|
||||
"bugs": "https://github.com/Keyang/node-csvtojson/issues",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Keyang/node-csvtojson.git"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Dane Petersen",
|
||||
"email": null,
|
||||
"url": "https://github.com/thegreatsunra",
|
||||
"contributions": 1,
|
||||
"additions": 18920,
|
||||
"deletions": 8429,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Jessica Good",
|
||||
"email": null,
|
||||
"url": "https://github.com/jessicagood",
|
||||
"contributions": 1,
|
||||
"additions": 8,
|
||||
"deletions": 5,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": null,
|
||||
"email": null,
|
||||
"url": "https://github.com/nbelakovski",
|
||||
"contributions": 2,
|
||||
"additions": 2,
|
||||
"deletions": 2,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Robert Porter",
|
||||
"email": null,
|
||||
"url": "https://github.com/colarob",
|
||||
"contributions": 1,
|
||||
"additions": 64,
|
||||
"deletions": 21,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Dimitri Kennedy",
|
||||
"email": null,
|
||||
"url": "https://github.com/roodboi",
|
||||
"contributions": 2,
|
||||
"additions": 3,
|
||||
"deletions": 3,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "José Expósito",
|
||||
"email": null,
|
||||
"url": "https://github.com/JoseExposito",
|
||||
"contributions": 1,
|
||||
"additions": 9,
|
||||
"deletions": 3,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Daniel Cohen",
|
||||
"email": null,
|
||||
"url": "https://github.com/dcohenb",
|
||||
"contributions": 1,
|
||||
"additions": 1,
|
||||
"deletions": 6,
|
||||
"hireable": true
|
||||
},
|
||||
{
|
||||
"name": "Richard Pringle",
|
||||
"email": null,
|
||||
"url": "https://github.com/richardpringle",
|
||||
"contributions": 1,
|
||||
"additions": 1,
|
||||
"deletions": 1,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Bert Verhelst",
|
||||
"email": null,
|
||||
"url": "https://github.com/bertyhell",
|
||||
"contributions": 1,
|
||||
"additions": 17,
|
||||
"deletions": 0,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": null,
|
||||
"email": null,
|
||||
"url": "https://github.com/jondayft",
|
||||
"contributions": 1,
|
||||
"additions": 18,
|
||||
"deletions": 0,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Bruce Johnson",
|
||||
"email": null,
|
||||
"url": "https://github.com/brucejo75",
|
||||
"contributions": 1,
|
||||
"additions": 36,
|
||||
"deletions": 1,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Jimi Ford",
|
||||
"email": null,
|
||||
"url": "https://github.com/JimiHFord",
|
||||
"contributions": 1,
|
||||
"additions": 5,
|
||||
"deletions": 5,
|
||||
"hireable": true
|
||||
},
|
||||
{
|
||||
"name": "Alec Fenichel",
|
||||
"email": null,
|
||||
"url": "https://github.com/fenichelar",
|
||||
"contributions": 1,
|
||||
"additions": 1,
|
||||
"deletions": 1,
|
||||
"hireable": true
|
||||
},
|
||||
{
|
||||
"name": "Hocine Moukaideche",
|
||||
"email": null,
|
||||
"url": "https://github.com/Off76",
|
||||
"contributions": 1,
|
||||
"additions": 1,
|
||||
"deletions": 1,
|
||||
"hireable": true
|
||||
},
|
||||
{
|
||||
"name": "Blake Blackshear",
|
||||
"email": null,
|
||||
"url": "https://github.com/blakeblackshear",
|
||||
"contributions": 2,
|
||||
"additions": 8,
|
||||
"deletions": 8,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Amila Welihinda",
|
||||
"email": null,
|
||||
"url": "https://github.com/amilajack",
|
||||
"contributions": 1,
|
||||
"additions": 2,
|
||||
"deletions": 1,
|
||||
"hireable": true
|
||||
},
|
||||
{
|
||||
"name": "Zsolt R. Molnar",
|
||||
"email": null,
|
||||
"url": "https://github.com/molnarzs",
|
||||
"contributions": 1,
|
||||
"additions": 40,
|
||||
"deletions": 2,
|
||||
"hireable": true
|
||||
},
|
||||
{
|
||||
"name": "Ionică Bizău (Johnny B.)",
|
||||
"email": null,
|
||||
"url": "https://github.com/IonicaBizau",
|
||||
"contributions": 1,
|
||||
"additions": 98,
|
||||
"deletions": 86,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Keita Akutsu",
|
||||
"email": null,
|
||||
"url": "https://github.com/kakts",
|
||||
"contributions": 4,
|
||||
"additions": 821,
|
||||
"deletions": 784,
|
||||
"hireable": true
|
||||
},
|
||||
{
|
||||
"name": null,
|
||||
"email": null,
|
||||
"url": "https://github.com/markwithers",
|
||||
"contributions": 1,
|
||||
"additions": 1,
|
||||
"deletions": 1,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Trang",
|
||||
"email": null,
|
||||
"url": "https://github.com/trangtungn",
|
||||
"contributions": 1,
|
||||
"additions": 6,
|
||||
"deletions": 1,
|
||||
"hireable": true
|
||||
},
|
||||
{
|
||||
"name": "Keyang Xiang",
|
||||
"email": null,
|
||||
"url": "https://github.com/Keyang",
|
||||
"contributions": 141,
|
||||
"additions": 70357,
|
||||
"deletions": 66412,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Jeff Johnson",
|
||||
"email": null,
|
||||
"url": "https://github.com/jeffcjohnson",
|
||||
"contributions": 1,
|
||||
"additions": 1,
|
||||
"deletions": 1,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Sean Lang",
|
||||
"email": null,
|
||||
"url": "https://github.com/slang800",
|
||||
"contributions": 2,
|
||||
"additions": 2,
|
||||
"deletions": 1,
|
||||
"hireable": true
|
||||
},
|
||||
{
|
||||
"name": "Matthias Lienau",
|
||||
"email": null,
|
||||
"url": "https://github.com/atufkas",
|
||||
"contributions": 9,
|
||||
"additions": 74,
|
||||
"deletions": 45,
|
||||
"hireable": null
|
||||
},
|
||||
{
|
||||
"name": "Ron Korving",
|
||||
"email": null,
|
||||
"url": "https://github.com/ronkorving",
|
||||
"contributions": 3,
|
||||
"additions": 3,
|
||||
"deletions": 3,
|
||||
"hireable": null
|
||||
}
|
||||
],
|
||||
"version": "2.0.10",
|
||||
"keywords": [
|
||||
"csv",
|
||||
"csv parser",
|
||||
"parse csv",
|
||||
"csvtojson",
|
||||
"json",
|
||||
"csv to json",
|
||||
"csv convert",
|
||||
"tojson",
|
||||
"convert csv to json",
|
||||
"csv-json"
|
||||
],
|
||||
"bin": {
|
||||
"csvtojson": "./bin/csvtojson"
|
||||
},
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bluebird": "^3.5.20",
|
||||
"@types/mocha": "^5.2.0",
|
||||
"@types/node": "^10.0.1",
|
||||
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
||||
"coveralls": "^3.0.1",
|
||||
"minimist": "^1.2.0",
|
||||
"mocha": "^5.1.1",
|
||||
"nyc": "^11.7.3",
|
||||
"sinon": "^3.2.3",
|
||||
"ts-node": "^6.0.3",
|
||||
"typescript": "^2.8.3",
|
||||
"uglifyjs-webpack-plugin": "^1.2.7",
|
||||
"webpack": "^4.16.4",
|
||||
"webpack-cli": "^3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"bluebird": "^3.5.1",
|
||||
"lodash": "^4.17.3",
|
||||
"strip-bom": "^2.0.0"
|
||||
},
|
||||
"nyc": {
|
||||
"extension": [
|
||||
".ts",
|
||||
".tsx"
|
||||
],
|
||||
"include": [
|
||||
"./src/**/*.ts"
|
||||
],
|
||||
"all": true
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "tsc -w",
|
||||
"build": "rm -Rf ./v2 && tsc && npm run build:browser && npm run build:browser:window",
|
||||
"build:browser": "webpack --config ./webpack.config.js",
|
||||
"build:browser:window": "webpack --config ./webpack.config.js --output-library-target=window --output-library=csv --output-filename=csvtojson.min.js",
|
||||
"test": "rm -Rf .ts-node && TS_NODE_CACHE_DIRECTORY=.ts-node mocha -r ts-node/register src/**/*.test.ts ./test/*.ts -R spec",
|
||||
"travis": "nyc --reporter lcov mocha -r ts-node/register src/**/*.test.ts ./test/*.ts -R spec",
|
||||
"test:debug": "mocha debug -r ts-node/register src/**/*.test.ts ./test/*.ts -R spec",
|
||||
"test:function": "mocha -r ts-node/register test/**/*.ts",
|
||||
"test-all": "mocha ./test -R spec && CSV_WORKER=3 mocha ./test -R spec ",
|
||||
"test:unit": "mocha -r ts-node/register src/**/*.ts",
|
||||
"test:all:debug": "mocha debug ./testNew -R spec",
|
||||
"coverage": "nyc --reporter html mocha -r ts-node/register src/**/*.test.ts ./test/*.ts -R spec",
|
||||
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
|
||||
},
|
||||
"browser": "./browser/browser.js",
|
||||
"main": "./v2/index.js"
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
|
||||
|
||||
let KEYWORDS = new Set(['inset', 'inherit', 'initial', 'revert', 'unset'])
|
||||
let SPACE = /\ +(?![^(]*\))/g // Similar to the one above, but with spaces instead.
|
||||
let LENGTH = /^-?(\d+|\.\d+)(.*?)$/g
|
||||
|
||||
export function parseBoxShadowValue(input) {
|
||||
let shadows = splitAtTopLevelOnly(input, ',')
|
||||
return shadows.map((shadow) => {
|
||||
let value = shadow.trim()
|
||||
let result = { raw: value }
|
||||
let parts = value.split(SPACE)
|
||||
let seen = new Set()
|
||||
|
||||
for (let part of parts) {
|
||||
// Reset index, since the regex is stateful.
|
||||
LENGTH.lastIndex = 0
|
||||
|
||||
// Keyword
|
||||
if (!seen.has('KEYWORD') && KEYWORDS.has(part)) {
|
||||
result.keyword = part
|
||||
seen.add('KEYWORD')
|
||||
}
|
||||
|
||||
// Length value
|
||||
else if (LENGTH.test(part)) {
|
||||
if (!seen.has('X')) {
|
||||
result.x = part
|
||||
seen.add('X')
|
||||
} else if (!seen.has('Y')) {
|
||||
result.y = part
|
||||
seen.add('Y')
|
||||
} else if (!seen.has('BLUR')) {
|
||||
result.blur = part
|
||||
seen.add('BLUR')
|
||||
} else if (!seen.has('SPREAD')) {
|
||||
result.spread = part
|
||||
seen.add('SPREAD')
|
||||
}
|
||||
}
|
||||
|
||||
// Color or unknown
|
||||
else {
|
||||
if (!result.color) {
|
||||
result.color = part
|
||||
} else {
|
||||
if (!result.unknown) result.unknown = []
|
||||
result.unknown.push(part)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if valid
|
||||
result.valid = result.x !== undefined && result.y !== undefined
|
||||
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
export function formatBoxShadowValue(shadows) {
|
||||
return shadows
|
||||
.map((shadow) => {
|
||||
if (!shadow.valid) {
|
||||
return shadow.raw
|
||||
}
|
||||
|
||||
return [shadow.keyword, shadow.x, shadow.y, shadow.blur, shadow.spread, shadow.color]
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
})
|
||||
.join(', ')
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Szymon Marczak
|
||||
|
||||
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.
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
declare function arg<T extends arg.Spec>(
|
||||
spec: T,
|
||||
options?: arg.Options
|
||||
): arg.Result<T>;
|
||||
|
||||
declare namespace arg {
|
||||
export const flagSymbol: unique symbol;
|
||||
|
||||
export function flag<T>(fn: T): T & { [arg.flagSymbol]: true };
|
||||
|
||||
export const COUNT: Handler<number> & { [arg.flagSymbol]: true };
|
||||
|
||||
export type Handler<T = any> = (
|
||||
value: string,
|
||||
name: string,
|
||||
previousValue?: T
|
||||
) => T;
|
||||
|
||||
export class ArgError extends Error {
|
||||
constructor(message: string, code: string);
|
||||
|
||||
code: string;
|
||||
}
|
||||
|
||||
export interface Spec {
|
||||
[key: string]: string | Handler | [Handler];
|
||||
}
|
||||
|
||||
export type Result<T extends Spec> = { _: string[] } & {
|
||||
[K in keyof T]?: T[K] extends Handler
|
||||
? ReturnType<T[K]>
|
||||
: T[K] extends [Handler]
|
||||
? Array<ReturnType<T[K][0]>>
|
||||
: never;
|
||||
};
|
||||
|
||||
export interface Options {
|
||||
argv?: string[];
|
||||
permissive?: boolean;
|
||||
stopAtPositional?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export = arg;
|
||||
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function () {
|
||||
var cosh = Math.cosh;
|
||||
if (typeof cosh !== "function") return false;
|
||||
return cosh(1) === 1.5430806348152437;
|
||||
};
|
||||
@@ -0,0 +1,276 @@
|
||||
import { isFunction } from './util/isFunction';
|
||||
import { Observer, ObservableNotification } from './types';
|
||||
import { isSubscription, Subscription } from './Subscription';
|
||||
import { config } from './config';
|
||||
import { reportUnhandledError } from './util/reportUnhandledError';
|
||||
import { noop } from './util/noop';
|
||||
import { nextNotification, errorNotification, COMPLETE_NOTIFICATION } from './NotificationFactories';
|
||||
import { timeoutProvider } from './scheduler/timeoutProvider';
|
||||
import { captureError } from './util/errorContext';
|
||||
|
||||
/**
|
||||
* Implements the {@link Observer} interface and extends the
|
||||
* {@link Subscription} class. While the {@link Observer} is the public API for
|
||||
* consuming the values of an {@link Observable}, all Observers get converted to
|
||||
* a Subscriber, in order to provide Subscription-like capabilities such as
|
||||
* `unsubscribe`. Subscriber is a common type in RxJS, and crucial for
|
||||
* implementing operators, but it is rarely used as a public API.
|
||||
*
|
||||
* @class Subscriber<T>
|
||||
*/
|
||||
export class Subscriber<T> extends Subscription implements Observer<T> {
|
||||
/**
|
||||
* A static factory for a Subscriber, given a (potentially partial) definition
|
||||
* of an Observer.
|
||||
* @param next The `next` callback of an Observer.
|
||||
* @param error The `error` callback of an
|
||||
* Observer.
|
||||
* @param complete The `complete` callback of an
|
||||
* Observer.
|
||||
* @return A Subscriber wrapping the (partially defined)
|
||||
* Observer represented by the given arguments.
|
||||
* @nocollapse
|
||||
* @deprecated Do not use. Will be removed in v8. There is no replacement for this
|
||||
* method, and there is no reason to be creating instances of `Subscriber` directly.
|
||||
* If you have a specific use case, please file an issue.
|
||||
*/
|
||||
static create<T>(next?: (x?: T) => void, error?: (e?: any) => void, complete?: () => void): Subscriber<T> {
|
||||
return new SafeSubscriber(next, error, complete);
|
||||
}
|
||||
|
||||
/** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */
|
||||
protected isStopped: boolean = false;
|
||||
/** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */
|
||||
protected destination: Subscriber<any> | Observer<any>; // this `any` is the escape hatch to erase extra type param (e.g. R)
|
||||
|
||||
/**
|
||||
* @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.
|
||||
* There is no reason to directly create an instance of Subscriber. This type is exported for typings reasons.
|
||||
*/
|
||||
constructor(destination?: Subscriber<any> | Observer<any>) {
|
||||
super();
|
||||
if (destination) {
|
||||
this.destination = destination;
|
||||
// Automatically chain subscriptions together here.
|
||||
// if destination is a Subscription, then it is a Subscriber.
|
||||
if (isSubscription(destination)) {
|
||||
destination.add(this);
|
||||
}
|
||||
} else {
|
||||
this.destination = EMPTY_OBSERVER;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link Observer} callback to receive notifications of type `next` from
|
||||
* the Observable, with a value. The Observable may call this method 0 or more
|
||||
* times.
|
||||
* @param {T} [value] The `next` value.
|
||||
* @return {void}
|
||||
*/
|
||||
next(value?: T): void {
|
||||
if (this.isStopped) {
|
||||
handleStoppedNotification(nextNotification(value), this);
|
||||
} else {
|
||||
this._next(value!);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link Observer} callback to receive notifications of type `error` from
|
||||
* the Observable, with an attached `Error`. Notifies the Observer that
|
||||
* the Observable has experienced an error condition.
|
||||
* @param {any} [err] The `error` exception.
|
||||
* @return {void}
|
||||
*/
|
||||
error(err?: any): void {
|
||||
if (this.isStopped) {
|
||||
handleStoppedNotification(errorNotification(err), this);
|
||||
} else {
|
||||
this.isStopped = true;
|
||||
this._error(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link Observer} callback to receive a valueless notification of type
|
||||
* `complete` from the Observable. Notifies the Observer that the Observable
|
||||
* has finished sending push-based notifications.
|
||||
* @return {void}
|
||||
*/
|
||||
complete(): void {
|
||||
if (this.isStopped) {
|
||||
handleStoppedNotification(COMPLETE_NOTIFICATION, this);
|
||||
} else {
|
||||
this.isStopped = true;
|
||||
this._complete();
|
||||
}
|
||||
}
|
||||
|
||||
unsubscribe(): void {
|
||||
if (!this.closed) {
|
||||
this.isStopped = true;
|
||||
super.unsubscribe();
|
||||
this.destination = null!;
|
||||
}
|
||||
}
|
||||
|
||||
protected _next(value: T): void {
|
||||
this.destination.next(value);
|
||||
}
|
||||
|
||||
protected _error(err: any): void {
|
||||
try {
|
||||
this.destination.error(err);
|
||||
} finally {
|
||||
this.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
protected _complete(): void {
|
||||
try {
|
||||
this.destination.complete();
|
||||
} finally {
|
||||
this.unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This bind is captured here because we want to be able to have
|
||||
* compatibility with monoid libraries that tend to use a method named
|
||||
* `bind`. In particular, a library called Monio requires this.
|
||||
*/
|
||||
const _bind = Function.prototype.bind;
|
||||
|
||||
function bind<Fn extends (...args: any[]) => any>(fn: Fn, thisArg: any): Fn {
|
||||
return _bind.call(fn, thisArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal optimization only, DO NOT EXPOSE.
|
||||
* @internal
|
||||
*/
|
||||
class ConsumerObserver<T> implements Observer<T> {
|
||||
constructor(private partialObserver: Partial<Observer<T>>) {}
|
||||
|
||||
next(value: T): void {
|
||||
const { partialObserver } = this;
|
||||
if (partialObserver.next) {
|
||||
try {
|
||||
partialObserver.next(value);
|
||||
} catch (error) {
|
||||
handleUnhandledError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error(err: any): void {
|
||||
const { partialObserver } = this;
|
||||
if (partialObserver.error) {
|
||||
try {
|
||||
partialObserver.error(err);
|
||||
} catch (error) {
|
||||
handleUnhandledError(error);
|
||||
}
|
||||
} else {
|
||||
handleUnhandledError(err);
|
||||
}
|
||||
}
|
||||
|
||||
complete(): void {
|
||||
const { partialObserver } = this;
|
||||
if (partialObserver.complete) {
|
||||
try {
|
||||
partialObserver.complete();
|
||||
} catch (error) {
|
||||
handleUnhandledError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class SafeSubscriber<T> extends Subscriber<T> {
|
||||
constructor(
|
||||
observerOrNext?: Partial<Observer<T>> | ((value: T) => void) | null,
|
||||
error?: ((e?: any) => void) | null,
|
||||
complete?: (() => void) | null
|
||||
) {
|
||||
super();
|
||||
|
||||
let partialObserver: Partial<Observer<T>>;
|
||||
if (isFunction(observerOrNext) || !observerOrNext) {
|
||||
// The first argument is a function, not an observer. The next
|
||||
// two arguments *could* be observers, or they could be empty.
|
||||
partialObserver = {
|
||||
next: (observerOrNext ?? undefined) as (((value: T) => void) | undefined),
|
||||
error: error ?? undefined,
|
||||
complete: complete ?? undefined,
|
||||
};
|
||||
} else {
|
||||
// The first argument is a partial observer.
|
||||
let context: any;
|
||||
if (this && config.useDeprecatedNextContext) {
|
||||
// This is a deprecated path that made `this.unsubscribe()` available in
|
||||
// next handler functions passed to subscribe. This only exists behind a flag
|
||||
// now, as it is *very* slow.
|
||||
context = Object.create(observerOrNext);
|
||||
context.unsubscribe = () => this.unsubscribe();
|
||||
partialObserver = {
|
||||
next: observerOrNext.next && bind(observerOrNext.next, context),
|
||||
error: observerOrNext.error && bind(observerOrNext.error, context),
|
||||
complete: observerOrNext.complete && bind(observerOrNext.complete, context),
|
||||
};
|
||||
} else {
|
||||
// The "normal" path. Just use the partial observer directly.
|
||||
partialObserver = observerOrNext;
|
||||
}
|
||||
}
|
||||
|
||||
// Wrap the partial observer to ensure it's a full observer, and
|
||||
// make sure proper error handling is accounted for.
|
||||
this.destination = new ConsumerObserver(partialObserver);
|
||||
}
|
||||
}
|
||||
|
||||
function handleUnhandledError(error: any) {
|
||||
if (config.useDeprecatedSynchronousErrorHandling) {
|
||||
captureError(error);
|
||||
} else {
|
||||
// Ideal path, we report this as an unhandled error,
|
||||
// which is thrown on a new call stack.
|
||||
reportUnhandledError(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An error handler used when no error handler was supplied
|
||||
* to the SafeSubscriber -- meaning no error handler was supplied
|
||||
* do the `subscribe` call on our observable.
|
||||
* @param err The error to handle
|
||||
*/
|
||||
function defaultErrorHandler(err: any) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
/**
|
||||
* A handler for notifications that cannot be sent to a stopped subscriber.
|
||||
* @param notification The notification being sent
|
||||
* @param subscriber The stopped subscriber
|
||||
*/
|
||||
function handleStoppedNotification(notification: ObservableNotification<any>, subscriber: Subscriber<any>) {
|
||||
const { onStoppedNotification } = config;
|
||||
onStoppedNotification && timeoutProvider.setTimeout(() => onStoppedNotification(notification, subscriber));
|
||||
}
|
||||
|
||||
/**
|
||||
* The observer used as a stub for subscriptions where the user did not
|
||||
* pass any arguments to `subscribe`. Comes with the default error handling
|
||||
* behavior.
|
||||
*/
|
||||
export const EMPTY_OBSERVER: Readonly<Observer<any>> & { closed: true } = {
|
||||
closed: true,
|
||||
next: noop,
|
||||
error: defaultErrorHandler,
|
||||
complete: noop,
|
||||
};
|
||||
Reference in New Issue
Block a user