update
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { deepEqual } from "./utils.js";
|
||||
function retainSearchParams(keys) {
|
||||
return ({ search, next }) => {
|
||||
const result = next(search);
|
||||
if (keys === true) {
|
||||
return { ...search, ...result };
|
||||
}
|
||||
keys.forEach((key) => {
|
||||
if (!(key in result)) {
|
||||
result[key] = search[key];
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
}
|
||||
function stripSearchParams(input) {
|
||||
return ({ search, next }) => {
|
||||
if (input === true) {
|
||||
return {};
|
||||
}
|
||||
const result = next(search);
|
||||
if (Array.isArray(input)) {
|
||||
input.forEach((key) => {
|
||||
delete result[key];
|
||||
});
|
||||
} else {
|
||||
Object.entries(input).forEach(
|
||||
([key, value]) => {
|
||||
if (deepEqual(result[key], value)) {
|
||||
delete result[key];
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
export {
|
||||
retainSearchParams,
|
||||
stripSearchParams
|
||||
};
|
||||
//# sourceMappingURL=searchMiddleware.js.map
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"1":"0 9 Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I","2":"C L M G N O P"},C:{"1":"0 9 SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","2":"1 2 3 4 5 6 7 8 nC LC J PB K D E F A B C L M G N O P QB RB qC rC"},D:{"1":"0 9 mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC","2":"1 2 3 4 5 6 7 8 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB","194":"kB lB"},E:{"1":"G yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","2":"J PB K D E F A B C sC SC tC uC vC wC TC FC","322":"L M GC xC"},F:{"1":"0 ZB 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 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z","2":"1 2 3 4 5 6 7 8 F B C G N O P QB RB SB TB UB VB WB 4C 5C 6C 7C FC kC 8C GC","194":"XB YB"},G:{"1":"RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC","2":"E SC 9C lC AD BD CD DD ED FD GD HD ID JD","578":"KD LD MD ND OD PD QD"},H:{"2":"WD"},I:{"2":"LC J I XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"1":"H","2":"A B C FC kC GC"},L:{"1":"I"},M:{"2":"EC"},N:{"2":"A B"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD","2":"J"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"qD rD"}},B:5,C:"MediaRecorder API",D:true};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E mC","132":"F A B"},B:{"1":"0 9 C L M G N O P Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I"},C:{"1":"0 1 2 3 4 5 6 7 8 9 B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","2":"nC LC J PB qC rC","132":"K D E F A"},D:{"1":"0 1 2 3 4 5 6 7 8 9 G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC","2":"J","16":"PB K D E L M","388":"F A B C"},E:{"1":"D E F A B C L M G uC vC wC TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","2":"J sC SC","16":"PB K","388":"tC"},F:{"1":"0 1 2 3 4 5 6 7 8 C G N O P QB RB SB TB UB VB WB XB YB ZB 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 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 8C GC","2":"F 4C 5C 6C 7C","132":"B FC kC"},G:{"1":"E BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC","2":"9C","16":"SC lC","388":"AD"},H:{"1":"WD"},I:{"1":"I bD cD","2":"XD YD ZD","388":"LC J aD lC"},J:{"1":"A","388":"D"},K:{"1":"C H GC","2":"A","132":"B FC kC"},L:{"1":"I"},M:{"1":"EC"},N:{"132":"A B"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 J dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"qD rD"}},B:1,C:"CustomEvent",D:true};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"48":0.00456,"52":0.02736,"56":0.00456,"78":0.00456,"91":0.00456,"99":0.01368,"102":0.00456,"105":0.00456,"113":0.00456,"115":0.53352,"118":0.00456,"122":0.00456,"123":0.00456,"124":0.00456,"125":0.07752,"127":0.01824,"128":0.10488,"129":0.00912,"130":0.00456,"131":0.00456,"132":0.01824,"133":0.0228,"134":0.03648,"135":1.06248,"136":4.19976,"137":0.00456,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 49 50 51 53 54 55 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 79 80 81 82 83 84 85 86 87 88 89 90 92 93 94 95 96 97 98 100 101 103 104 106 107 108 109 110 111 112 114 116 117 119 120 121 126 138 139 140 3.5 3.6"},D:{"34":0.00456,"38":0.00456,"41":0.00456,"49":0.00912,"53":0.00456,"71":0.00456,"79":0.10032,"80":0.00456,"81":0.00912,"86":0.00456,"87":0.05472,"88":0.00456,"89":0.00456,"90":0.00456,"91":0.00456,"94":0.01824,"100":0.01368,"102":0.0228,"103":0.03192,"104":0.03648,"105":0.00456,"106":0.01824,"107":0.01824,"108":0.03192,"109":1.37256,"110":0.00912,"111":0.01824,"112":0.00912,"113":0.01824,"114":0.0228,"115":0.00456,"116":0.05016,"118":0.00456,"119":0.0228,"120":0.03192,"121":0.01824,"122":0.22344,"123":0.02736,"124":0.10944,"125":0.07296,"126":0.03192,"127":0.0228,"128":0.0684,"129":0.04104,"130":0.0684,"131":0.28728,"132":0.44688,"133":7.50576,"134":15.02064,"135":0.01368,"136":0.00456,_:"4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 35 36 37 39 40 42 43 44 45 46 47 48 50 51 52 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 72 73 74 75 76 77 78 83 84 85 92 93 95 96 97 98 99 101 117 137 138"},F:{"36":0.00456,"46":0.02736,"85":0.00456,"86":0.00456,"87":0.03192,"88":0.01368,"89":0.00456,"95":0.1824,"114":0.00456,"115":0.00456,"116":0.40584,"117":2.17512,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 37 38 39 40 41 42 43 44 45 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 90 91 92 93 94 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"92":0.00456,"106":0.00456,"108":0.00456,"109":0.0456,"110":0.00456,"112":0.00456,"114":0.00456,"120":0.00456,"122":0.00912,"124":0.00456,"126":0.00456,"127":0.02736,"128":0.00456,"129":0.00456,"130":0.00912,"131":0.07752,"132":0.20976,"133":1.95168,"134":3.65256,_:"12 13 14 15 16 17 18 79 80 81 83 84 85 86 87 88 89 90 91 93 94 95 96 97 98 99 100 101 102 103 104 105 107 111 113 115 116 117 118 119 121 123 125"},E:{"8":0.00456,"14":0.00456,_:"0 4 5 6 7 9 10 11 12 13 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1 15.2-15.3","12.1":0.00456,"13.1":0.01368,"14.1":0.03648,"15.1":0.00456,"15.4":0.00456,"15.5":0.00912,"15.6":0.13224,"16.0":0.00912,"16.1":0.01824,"16.2":0.00912,"16.3":0.02736,"16.4":0.01368,"16.5":0.00912,"16.6":0.12312,"17.0":0.01368,"17.1":0.07296,"17.2":0.05016,"17.3":0.01368,"17.4":0.02736,"17.5":0.05472,"17.6":0.2052,"18.0":0.06384,"18.1":0.0912,"18.2":0.05016,"18.3":1.09896,"18.4":0.03648},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.0022,"5.0-5.1":0,"6.0-6.1":0.00661,"7.0-7.1":0.00441,"8.1-8.4":0,"9.0-9.2":0.0033,"9.3":0.01542,"10.0-10.2":0.0011,"10.3":0.02533,"11.0-11.2":0.11675,"11.3-11.4":0.00771,"12.0-12.1":0.00441,"12.2-12.5":0.10904,"13.0-13.1":0.0022,"13.2":0.0033,"13.3":0.00441,"13.4-13.7":0.01542,"14.0-14.4":0.03855,"14.5-14.8":0.04626,"15.0-15.1":0.02533,"15.2-15.3":0.02533,"15.4":0.03084,"15.5":0.03524,"15.6-15.8":0.43395,"16.0":0.06168,"16.1":0.12666,"16.2":0.06608,"16.3":0.11455,"16.4":0.02533,"16.5":0.04736,"16.6-16.7":0.51435,"17.0":0.03084,"17.1":0.05507,"17.2":0.04185,"17.3":0.05837,"17.4":0.11675,"17.5":0.25993,"17.6-17.7":0.75446,"18.0":0.21147,"18.1":0.69168,"18.2":0.30949,"18.3":6.46851,"18.4":0.09582},P:{"4":0.17423,"21":0.01025,"22":0.0205,"23":0.0205,"24":0.0205,"25":0.0205,"26":0.05124,"27":2.33674,_:"20 8.2 9.2 10.1 11.1-11.2 12.0 14.0 15.0 16.0 17.0 18.0 19.0","5.0-5.4":0.0205,"6.2-6.4":0.0205,"7.2-7.4":0.03075,"13.0":0.01025},I:{"0":0.06513,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00002,"4.4":0,"4.4.3-4.4.4":0.00007},K:{"0":0.60373,_:"10 11 12 11.1 11.5 12.1"},A:{"11":0.01368,_:"6 7 8 9 10 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.33178},Q:{_:"14.9"},O:{"0":0.03807},H:{"0":0},L:{"0":40.54611}};
|
||||
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _nonIterableRest;
|
||||
function _nonIterableRest() {
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
||||
}
|
||||
|
||||
//# sourceMappingURL=nonIterableRest.js.map
|
||||
@@ -0,0 +1,24 @@
|
||||
const SemVer = require('../classes/semver')
|
||||
const Range = require('../classes/range')
|
||||
const minSatisfying = (versions, range, options) => {
|
||||
let min = null
|
||||
let minSV = null
|
||||
let rangeObj = null
|
||||
try {
|
||||
rangeObj = new Range(range, options)
|
||||
} catch (er) {
|
||||
return null
|
||||
}
|
||||
versions.forEach((v) => {
|
||||
if (rangeObj.test(v)) {
|
||||
// satisfies(v, range, options)
|
||||
if (!min || minSV.compare(v) === 1) {
|
||||
// compare(min, v, true)
|
||||
min = v
|
||||
minSV = new SemVer(min, options)
|
||||
}
|
||||
}
|
||||
})
|
||||
return min
|
||||
}
|
||||
module.exports = minSatisfying
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"1":"F A B","2":"mC","8":"K D E"},B:{"1":"0 9 C L M G N O P Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I"},C:{"1":"0 1 2 3 4 5 6 7 8 9 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC rC","132":"nC LC qC"},D:{"1":"0 1 2 3 4 5 6 7 8 9 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC"},E:{"1":"J PB K D E F A B C L M G tC uC vC wC TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","132":"sC SC"},F:{"1":"0 1 2 3 4 5 6 7 8 F B C G N O P QB RB SB TB UB VB WB XB YB ZB 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 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 4C 5C 6C 7C FC kC 8C GC"},G:{"1":"E SC 9C lC AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC"},H:{"260":"WD"},I:{"1":"LC J I aD lC bD cD","132":"XD YD ZD"},J:{"1":"D A"},K:{"1":"A B C H FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"1":"A B"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 J dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"qD rD"}},B:1,C:"Canvas (basic support)",D:true};
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Program uses a modified version of the `qss` package:
|
||||
* Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License
|
||||
* https://github.com/lukeed/qss/blob/master/license.md
|
||||
*/
|
||||
/**
|
||||
* Encodes an object into a query string.
|
||||
* @param obj - The object to encode into a query string.
|
||||
* @param [pfx] - An optional prefix to add before the query string.
|
||||
* @returns The encoded query string.
|
||||
* @example
|
||||
* ```
|
||||
* // Example input: encode({ token: 'foo', key: 'value' })
|
||||
* // Expected output: "token=foo&key=value"
|
||||
* ```
|
||||
*/
|
||||
export declare function encode(obj: any, pfx?: string): string;
|
||||
/**
|
||||
* Decodes a query string into an object.
|
||||
* @param str - The query string to decode.
|
||||
* @param [pfx] - An optional prefix to filter out from the query string.
|
||||
* @returns The decoded key-value pairs in an object format.
|
||||
* @example
|
||||
* // Example input: decode("token=foo&key=value")
|
||||
* // Expected output: { "token": "foo", "key": "value" }
|
||||
*/
|
||||
export declare function decode(str: any, pfx?: string): any;
|
||||
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.statements = exports.statement = exports.smart = exports.program = exports.expression = exports.default = void 0;
|
||||
var formatters = require("./formatters.js");
|
||||
var _builder = require("./builder.js");
|
||||
const smart = exports.smart = (0, _builder.default)(formatters.smart);
|
||||
const statement = exports.statement = (0, _builder.default)(formatters.statement);
|
||||
const statements = exports.statements = (0, _builder.default)(formatters.statements);
|
||||
const expression = exports.expression = (0, _builder.default)(formatters.expression);
|
||||
const program = exports.program = (0, _builder.default)(formatters.program);
|
||||
var _default = exports.default = Object.assign(smart.bind(undefined), {
|
||||
smart,
|
||||
statement,
|
||||
statements,
|
||||
expression,
|
||||
program,
|
||||
ast: smart.ast
|
||||
});
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -0,0 +1,183 @@
|
||||
# enhanced-resolve
|
||||
|
||||
[![npm][npm]][npm-url]
|
||||
[![Build Status][build-status]][build-status-url]
|
||||
[![codecov][codecov-badge]][codecov-url]
|
||||
[![Install Size][size]][size-url]
|
||||
[![GitHub Discussions][discussion]][discussion-url]
|
||||
|
||||
Offers an async require.resolve function. It's highly configurable.
|
||||
|
||||
## Features
|
||||
|
||||
- plugin system
|
||||
- provide a custom filesystem
|
||||
- sync and async node.js filesystems included
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Install
|
||||
|
||||
```sh
|
||||
# npm
|
||||
npm install enhanced-resolve
|
||||
# or Yarn
|
||||
yarn add enhanced-resolve
|
||||
```
|
||||
|
||||
### Resolve
|
||||
|
||||
There is a Node.js API which allows to resolve requests according to the Node.js resolving rules.
|
||||
Sync and async APIs are offered. A `create` method allows to create a custom resolve function.
|
||||
|
||||
```js
|
||||
const resolve = require("enhanced-resolve");
|
||||
|
||||
resolve("/some/path/to/folder", "module/dir", (err, result) => {
|
||||
result; // === "/some/path/node_modules/module/dir/index.js"
|
||||
});
|
||||
|
||||
resolve.sync("/some/path/to/folder", "../../dir");
|
||||
// === "/some/path/dir/index.js"
|
||||
|
||||
const myResolve = resolve.create({
|
||||
// or resolve.create.sync
|
||||
extensions: [".ts", ".js"]
|
||||
// see more options below
|
||||
});
|
||||
|
||||
myResolve("/some/path/to/folder", "ts-module", (err, result) => {
|
||||
result; // === "/some/node_modules/ts-module/index.ts"
|
||||
});
|
||||
```
|
||||
|
||||
### Creating a Resolver
|
||||
|
||||
The easiest way to create a resolver is to use the `createResolver` function on `ResolveFactory`, along with one of the supplied File System implementations.
|
||||
|
||||
```js
|
||||
const fs = require("fs");
|
||||
const { CachedInputFileSystem, ResolverFactory } = require("enhanced-resolve");
|
||||
|
||||
// create a resolver
|
||||
const myResolver = ResolverFactory.createResolver({
|
||||
// Typical usage will consume the `fs` + `CachedInputFileSystem`, which wraps Node.js `fs` to add caching.
|
||||
fileSystem: new CachedInputFileSystem(fs, 4000),
|
||||
extensions: [".js", ".json"]
|
||||
/* any other resolver options here. Options/defaults can be seen below */
|
||||
});
|
||||
|
||||
// resolve a file with the new resolver
|
||||
const context = {};
|
||||
const lookupStartPath = "/Users/webpack/some/root/dir";
|
||||
const request = "./path/to-look-up.js";
|
||||
const resolveContext = {};
|
||||
myResolver.resolve(context, lookupStartPath, request, resolveContext, (
|
||||
err /*Error*/,
|
||||
filepath /*string*/
|
||||
) => {
|
||||
// Do something with the path
|
||||
});
|
||||
```
|
||||
|
||||
#### Resolver Options
|
||||
|
||||
| Field | Default | Description |
|
||||
|------------------|-----------------------------| --------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| alias | [] | A list of module alias configurations or an object which maps key to value |
|
||||
| aliasFields | [] | A list of alias fields in description files |
|
||||
| extensionAlias | {} | An object which maps extension to extension aliases |
|
||||
| cachePredicate | function() { return true }; | A function which decides whether a request should be cached or not. An object is passed to the function with `path` and `request` properties. |
|
||||
| cacheWithContext | true | If unsafe cache is enabled, includes `request.context` in the cache key |
|
||||
| conditionNames | [] | A list of exports field condition names |
|
||||
| descriptionFiles | ["package.json"] | A list of description files to read from |
|
||||
| enforceExtension | false | Enforce that a extension from extensions must be used |
|
||||
| exportsFields | ["exports"] | A list of exports fields in description files |
|
||||
| extensions | [".js", ".json", ".node"] | A list of extensions which should be tried for files |
|
||||
| fallback | [] | Same as `alias`, but only used if default resolving fails |
|
||||
| fileSystem | | The file system which should be used |
|
||||
| fullySpecified | false | Request passed to resolve is already fully specified and extensions or main files are not resolved for it (they are still resolved for internal requests) |
|
||||
| mainFields | ["main"] | A list of main fields in description files |
|
||||
| mainFiles | ["index"] | A list of main files in directories |
|
||||
| modules | ["node_modules"] | A list of directories to resolve modules from, can be absolute path or folder name |
|
||||
| plugins | [] | A list of additional resolve plugins which should be applied |
|
||||
| resolver | undefined | A prepared Resolver to which the plugins are attached |
|
||||
| resolveToContext | false | Resolve to a context instead of a file |
|
||||
| preferRelative | false | Prefer to resolve module requests as relative request and fallback to resolving as module |
|
||||
| preferAbsolute | false | Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots |
|
||||
| restrictions | [] | A list of resolve restrictions |
|
||||
| roots | [] | A list of root paths |
|
||||
| symlinks | true | Whether to resolve symlinks to their symlinked location |
|
||||
| unsafeCache | false | Use this cache object to unsafely cache the successful requests |
|
||||
|
||||
## Plugins
|
||||
|
||||
Similar to `webpack`, the core of `enhanced-resolve` functionality is implemented as individual plugins that are executed using [`tapable`](https://github.com/webpack/tapable).
|
||||
These plugins can extend the functionality of the library, adding other ways for files/contexts to be resolved.
|
||||
|
||||
A plugin should be a `class` (or its ES5 equivalent) with an `apply` method. The `apply` method will receive a `resolver` instance, that can be used to hook in to the event system.
|
||||
|
||||
### Plugin Boilerplate
|
||||
|
||||
```js
|
||||
class MyResolverPlugin {
|
||||
constructor(source, target) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
apply(resolver) {
|
||||
const target = resolver.ensureHook(this.target);
|
||||
resolver
|
||||
.getHook(this.source)
|
||||
.tapAsync("MyResolverPlugin", (request, resolveContext, callback) => {
|
||||
// Any logic you need to create a new `request` can go here
|
||||
resolver.doResolve(target, request, null, resolveContext, callback);
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Plugins are executed in a pipeline, and register which event they should be executed before/after. In the example above, `source` is the name of the event that starts the pipeline, and `target` is what event this plugin should fire, which is what continues the execution of the pipeline. For an example of how these different plugin events create a chain, see `lib/ResolverFactory.js`, in the `//// pipeline ////` section.
|
||||
|
||||
## Escaping
|
||||
|
||||
It's allowed to escape `#` as `\0#` to avoid parsing it as fragment.
|
||||
|
||||
enhanced-resolve will try to resolve requests containing `#` as path and as fragment, so it will automatically figure out if `./some#thing` means `.../some.js#thing` or `.../some#thing.js`. When a `#` is resolved as path it will be escaped in the result. Here: `.../some\0#thing.js`.
|
||||
|
||||
## Tests
|
||||
|
||||
```javascript
|
||||
yarn test
|
||||
```
|
||||
|
||||
## Passing options from webpack
|
||||
|
||||
If you are using `webpack`, and you want to pass custom options to `enhanced-resolve`, the options are passed from the `resolve` key of your webpack configuration e.g.:
|
||||
|
||||
```
|
||||
resolve: {
|
||||
extensions: ['.js', '.jsx'],
|
||||
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
|
||||
plugins: [new DirectoryNamedWebpackPlugin()]
|
||||
...
|
||||
},
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) 2012-2019 JS Foundation and other contributors
|
||||
|
||||
MIT (http://www.opensource.org/licenses/mit-license.php)
|
||||
|
||||
[npm]: https://img.shields.io/npm/v/enhanced-resolve.svg
|
||||
[npm-url]: https://www.npmjs.com/package/enhanced-resolve
|
||||
[build-status]: https://github.com/webpack/enhanced-resolve/actions/workflows/test.yml/badge.svg
|
||||
[build-status-url]: https://github.com/webpack/enhanced-resolve/actions
|
||||
[codecov-badge]: https://codecov.io/gh/webpack/enhanced-resolve/branch/main/graph/badge.svg?token=6B6NxtsZc3
|
||||
[codecov-url]: https://codecov.io/gh/webpack/enhanced-resolve
|
||||
[size]: https://packagephobia.com/badge?p=enhanced-resolve
|
||||
[size-url]: https://packagephobia.com/result?p=enhanced-resolve
|
||||
[discussion]: https://img.shields.io/github/discussions/webpack/webpack
|
||||
[discussion-url]: https://github.com/webpack/webpack/discussions
|
||||
@@ -0,0 +1,123 @@
|
||||
export type ObjectDefinition = import("./types.cts").ObjectDefinition;
|
||||
export type PropertyDefinition = import("./types.cts").PropertyDefinition;
|
||||
/**
|
||||
* @fileoverview Merge Strategy
|
||||
*/
|
||||
/**
|
||||
* Container class for several different merge strategies.
|
||||
*/
|
||||
export class MergeStrategy {
|
||||
/**
|
||||
* Merges two keys by overwriting the first with the second.
|
||||
* @param {*} value1 The value from the first object key.
|
||||
* @param {*} value2 The value from the second object key.
|
||||
* @returns {*} The second value.
|
||||
*/
|
||||
static overwrite(value1: any, value2: any): any;
|
||||
/**
|
||||
* Merges two keys by replacing the first with the second only if the
|
||||
* second is defined.
|
||||
* @param {*} value1 The value from the first object key.
|
||||
* @param {*} value2 The value from the second object key.
|
||||
* @returns {*} The second value if it is defined.
|
||||
*/
|
||||
static replace(value1: any, value2: any): any;
|
||||
/**
|
||||
* Merges two properties by assigning properties from the second to the first.
|
||||
* @param {*} value1 The value from the first object key.
|
||||
* @param {*} value2 The value from the second object key.
|
||||
* @returns {*} A new object containing properties from both value1 and
|
||||
* value2.
|
||||
*/
|
||||
static assign(value1: any, value2: any): any;
|
||||
}
|
||||
/**
|
||||
* Represents an object validation/merging schema.
|
||||
*/
|
||||
export class ObjectSchema {
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* @param {ObjectDefinition} definitions The schema definitions.
|
||||
*/
|
||||
constructor(definitions: ObjectDefinition);
|
||||
/**
|
||||
* Determines if a strategy has been registered for the given object key.
|
||||
* @param {string} key The object key to find a strategy for.
|
||||
* @returns {boolean} True if the key has a strategy registered, false if not.
|
||||
*/
|
||||
hasKey(key: string): boolean;
|
||||
/**
|
||||
* Merges objects together to create a new object comprised of the keys
|
||||
* of the all objects. Keys are merged based on the each key's merge
|
||||
* strategy.
|
||||
* @param {...Object} objects The objects to merge.
|
||||
* @returns {Object} A new object with a mix of all objects' keys.
|
||||
* @throws {Error} If any object is invalid.
|
||||
*/
|
||||
merge(...objects: any[]): any;
|
||||
/**
|
||||
* Validates an object's keys based on the validate strategy for each key.
|
||||
* @param {Object} object The object to validate.
|
||||
* @returns {void}
|
||||
* @throws {Error} When the object is invalid.
|
||||
*/
|
||||
validate(object: any): void;
|
||||
#private;
|
||||
}
|
||||
/**
|
||||
* @fileoverview Validation Strategy
|
||||
*/
|
||||
/**
|
||||
* Container class for several different validation strategies.
|
||||
*/
|
||||
export class ValidationStrategy {
|
||||
/**
|
||||
* Validates that a value is an array.
|
||||
* @param {*} value The value to validate.
|
||||
* @returns {void}
|
||||
* @throws {TypeError} If the value is invalid.
|
||||
*/
|
||||
static array(value: any): void;
|
||||
/**
|
||||
* Validates that a value is a boolean.
|
||||
* @param {*} value The value to validate.
|
||||
* @returns {void}
|
||||
* @throws {TypeError} If the value is invalid.
|
||||
*/
|
||||
static boolean(value: any): void;
|
||||
/**
|
||||
* Validates that a value is a number.
|
||||
* @param {*} value The value to validate.
|
||||
* @returns {void}
|
||||
* @throws {TypeError} If the value is invalid.
|
||||
*/
|
||||
static number(value: any): void;
|
||||
/**
|
||||
* Validates that a value is a object.
|
||||
* @param {*} value The value to validate.
|
||||
* @returns {void}
|
||||
* @throws {TypeError} If the value is invalid.
|
||||
*/
|
||||
static object(value: any): void;
|
||||
/**
|
||||
* Validates that a value is a object or null.
|
||||
* @param {*} value The value to validate.
|
||||
* @returns {void}
|
||||
* @throws {TypeError} If the value is invalid.
|
||||
*/
|
||||
static "object?"(value: any): void;
|
||||
/**
|
||||
* Validates that a value is a string.
|
||||
* @param {*} value The value to validate.
|
||||
* @returns {void}
|
||||
* @throws {TypeError} If the value is invalid.
|
||||
*/
|
||||
static string(value: any): void;
|
||||
/**
|
||||
* Validates that a value is a non-empty string.
|
||||
* @param {*} value The value to validate.
|
||||
* @returns {void}
|
||||
* @throws {TypeError} If the value is invalid.
|
||||
*/
|
||||
static "string!"(value: any): void;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const parse = require('./parse')
|
||||
const prerelease = (version, options) => {
|
||||
const parsed = parse(version, options)
|
||||
return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
|
||||
}
|
||||
module.exports = prerelease
|
||||
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"name": "@eslint-community/eslint-utils",
|
||||
"version": "4.5.1",
|
||||
"description": "Utilities for ESLint plugins.",
|
||||
"keywords": [
|
||||
"eslint"
|
||||
],
|
||||
"homepage": "https://github.com/eslint-community/eslint-utils#readme",
|
||||
"bugs": {
|
||||
"url": "https://github.com/eslint-community/eslint-utils/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/eslint-community/eslint-utils"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "Toru Nagashima",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./index.mjs",
|
||||
"require": "./index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"main": "index",
|
||||
"module": "index.mjs",
|
||||
"files": [
|
||||
"index.*"
|
||||
],
|
||||
"scripts": {
|
||||
"prebuild": "npm run -s clean",
|
||||
"build": "rollup -c",
|
||||
"clean": "rimraf .nyc_output coverage index.*",
|
||||
"coverage": "opener ./coverage/lcov-report/index.html",
|
||||
"docs:build": "vitepress build docs",
|
||||
"docs:watch": "vitepress dev docs",
|
||||
"format": "npm run -s format:prettier -- --write",
|
||||
"format:prettier": "prettier .",
|
||||
"format:check": "npm run -s format:prettier -- --check",
|
||||
"lint:eslint": "eslint .",
|
||||
"lint:format": "npm run -s format:check",
|
||||
"lint:installed-check": "installed-check -v -i installed-check -i npm-run-all2 -i knip",
|
||||
"lint:knip": "knip",
|
||||
"lint": "run-p lint:*",
|
||||
"test": "c8 mocha --reporter dot \"test/*.mjs\"",
|
||||
"preversion": "npm test && npm run -s build",
|
||||
"postversion": "git push && git push --tags",
|
||||
"prewatch": "npm run -s clean",
|
||||
"watch": "warun \"{src,test}/**/*.mjs\" -- npm run -s test:mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"eslint-visitor-keys": "^3.4.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint-community/eslint-plugin-mysticatea": "^15.6.1",
|
||||
"c8": "^8.0.1",
|
||||
"dot-prop": "^7.2.0",
|
||||
"eslint": "^8.57.1",
|
||||
"installed-check": "^8.0.1",
|
||||
"knip": "^5.33.3",
|
||||
"mocha": "^9.2.2",
|
||||
"npm-run-all2": "^6.2.3",
|
||||
"opener": "^1.5.2",
|
||||
"prettier": "2.8.8",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "^2.79.2",
|
||||
"rollup-plugin-sourcemaps": "^0.6.3",
|
||||
"semver": "^7.6.3",
|
||||
"vitepress": "^1.4.1",
|
||||
"warun": "^1.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^6.0.0 || ^7.0.0 || >=8.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
},
|
||||
"funding": "https://opencollective.com/eslint"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (it) {
|
||||
const { pluginName } = it;
|
||||
|
||||
return `
|
||||
ESLint couldn't find the plugin "${pluginName}". because there is whitespace in the name. Please check your configuration and remove all whitespace from the plugin name.
|
||||
|
||||
If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
|
||||
`.trimStart();
|
||||
};
|
||||
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
// We define these manually to ensure they're always copied
|
||||
// even if they would move up the prototype chain
|
||||
// https://nodejs.org/api/http.html#http_class_http_incomingmessage
|
||||
const knownProperties = [
|
||||
'aborted',
|
||||
'complete',
|
||||
'headers',
|
||||
'httpVersion',
|
||||
'httpVersionMinor',
|
||||
'httpVersionMajor',
|
||||
'method',
|
||||
'rawHeaders',
|
||||
'rawTrailers',
|
||||
'setTimeout',
|
||||
'socket',
|
||||
'statusCode',
|
||||
'statusMessage',
|
||||
'trailers',
|
||||
'url'
|
||||
];
|
||||
|
||||
module.exports = (fromStream, toStream) => {
|
||||
if (toStream._readableState.autoDestroy) {
|
||||
throw new Error('The second stream must have the `autoDestroy` option set to `false`');
|
||||
}
|
||||
|
||||
const fromProperties = new Set(Object.keys(fromStream).concat(knownProperties));
|
||||
|
||||
const properties = {};
|
||||
|
||||
for (const property of fromProperties) {
|
||||
// Don't overwrite existing properties.
|
||||
if (property in toStream) {
|
||||
continue;
|
||||
}
|
||||
|
||||
properties[property] = {
|
||||
get() {
|
||||
const value = fromStream[property];
|
||||
const isFunction = typeof value === 'function';
|
||||
|
||||
return isFunction ? value.bind(fromStream) : value;
|
||||
},
|
||||
set(value) {
|
||||
fromStream[property] = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: false
|
||||
};
|
||||
}
|
||||
|
||||
Object.defineProperties(toStream, properties);
|
||||
|
||||
fromStream.once('aborted', () => {
|
||||
toStream.destroy();
|
||||
|
||||
toStream.emit('aborted');
|
||||
});
|
||||
|
||||
fromStream.once('close', () => {
|
||||
if (fromStream.complete) {
|
||||
if (toStream.readable) {
|
||||
toStream.once('end', () => {
|
||||
toStream.emit('close');
|
||||
});
|
||||
} else {
|
||||
toStream.emit('close');
|
||||
}
|
||||
} else {
|
||||
toStream.emit('close');
|
||||
}
|
||||
});
|
||||
|
||||
return toStream;
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
||||
"name": "chownr",
|
||||
"description": "like `chown -R`",
|
||||
"version": "1.1.4",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/isaacs/chownr.git"
|
||||
},
|
||||
"main": "chownr.js",
|
||||
"files": [
|
||||
"chownr.js"
|
||||
],
|
||||
"devDependencies": {
|
||||
"mkdirp": "0.3",
|
||||
"rimraf": "^2.7.1",
|
||||
"tap": "^14.10.6"
|
||||
},
|
||||
"tap": {
|
||||
"check-coverage": true
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap",
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"prepublishOnly": "git push origin --follow-tags"
|
||||
},
|
||||
"license": "ISC"
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
/**
|
||||
* @fileoverview Rule to control spacing within function calls
|
||||
* @author Matt DuVall <http://www.mattduvall.com>
|
||||
* @deprecated in ESLint v8.53.0
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
deprecated: {
|
||||
message: "Formatting rules are being moved out of ESLint core.",
|
||||
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
||||
deprecatedSince: "8.53.0",
|
||||
availableUntil: "10.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
||||
url: "https://eslint.style/guide/migration",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin-js",
|
||||
url: "https://eslint.style/packages/js",
|
||||
},
|
||||
rule: {
|
||||
name: "function-call-spacing",
|
||||
url: "https://eslint.style/rules/js/function-call-spacing",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Require or disallow spacing between function identifiers and their invocations",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/func-call-spacing",
|
||||
},
|
||||
|
||||
fixable: "whitespace",
|
||||
|
||||
schema: {
|
||||
anyOf: [
|
||||
{
|
||||
type: "array",
|
||||
items: [
|
||||
{
|
||||
enum: ["never"],
|
||||
},
|
||||
],
|
||||
minItems: 0,
|
||||
maxItems: 1,
|
||||
},
|
||||
{
|
||||
type: "array",
|
||||
items: [
|
||||
{
|
||||
enum: ["always"],
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
allowNewlines: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
minItems: 0,
|
||||
maxItems: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
messages: {
|
||||
unexpectedWhitespace:
|
||||
"Unexpected whitespace between function name and paren.",
|
||||
unexpectedNewline:
|
||||
"Unexpected newline between function name and paren.",
|
||||
missing: "Missing space between function name and paren.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const never = context.options[0] !== "always";
|
||||
const allowNewlines =
|
||||
!never && context.options[1] && context.options[1].allowNewlines;
|
||||
const sourceCode = context.sourceCode;
|
||||
const text = sourceCode.getText();
|
||||
|
||||
/**
|
||||
* Check if open space is present in a function name
|
||||
* @param {ASTNode} node node to evaluate
|
||||
* @param {Token} leftToken The last token of the callee. This may be the closing parenthesis that encloses the callee.
|
||||
* @param {Token} rightToken Tha first token of the arguments. this is the opening parenthesis that encloses the arguments.
|
||||
* @returns {void}
|
||||
* @private
|
||||
*/
|
||||
function checkSpacing(node, leftToken, rightToken) {
|
||||
const textBetweenTokens = text
|
||||
.slice(leftToken.range[1], rightToken.range[0])
|
||||
.replace(/\/\*.*?\*\//gu, "");
|
||||
const hasWhitespace = /\s/u.test(textBetweenTokens);
|
||||
const hasNewline =
|
||||
hasWhitespace &&
|
||||
astUtils.LINEBREAK_MATCHER.test(textBetweenTokens);
|
||||
|
||||
/*
|
||||
* never allowNewlines hasWhitespace hasNewline message
|
||||
* F F F F Missing space between function name and paren.
|
||||
* F F F T (Invalid `!hasWhitespace && hasNewline`)
|
||||
* F F T T Unexpected newline between function name and paren.
|
||||
* F F T F (OK)
|
||||
* F T T F (OK)
|
||||
* F T T T (OK)
|
||||
* F T F T (Invalid `!hasWhitespace && hasNewline`)
|
||||
* F T F F Missing space between function name and paren.
|
||||
* T T F F (Invalid `never && allowNewlines`)
|
||||
* T T F T (Invalid `!hasWhitespace && hasNewline`)
|
||||
* T T T T (Invalid `never && allowNewlines`)
|
||||
* T T T F (Invalid `never && allowNewlines`)
|
||||
* T F T F Unexpected space between function name and paren.
|
||||
* T F T T Unexpected space between function name and paren.
|
||||
* T F F T (Invalid `!hasWhitespace && hasNewline`)
|
||||
* T F F F (OK)
|
||||
*
|
||||
* T T Unexpected space between function name and paren.
|
||||
* F F Missing space between function name and paren.
|
||||
* F F T Unexpected newline between function name and paren.
|
||||
*/
|
||||
|
||||
if (never && hasWhitespace) {
|
||||
context.report({
|
||||
node,
|
||||
loc: {
|
||||
start: leftToken.loc.end,
|
||||
end: {
|
||||
line: rightToken.loc.start.line,
|
||||
column: rightToken.loc.start.column - 1,
|
||||
},
|
||||
},
|
||||
messageId: "unexpectedWhitespace",
|
||||
fix(fixer) {
|
||||
// Don't remove comments.
|
||||
if (
|
||||
sourceCode.commentsExistBetween(
|
||||
leftToken,
|
||||
rightToken,
|
||||
)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If `?.` exists, it doesn't hide no-unexpected-multiline errors
|
||||
if (node.optional) {
|
||||
return fixer.replaceTextRange(
|
||||
[leftToken.range[1], rightToken.range[0]],
|
||||
"?.",
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Only autofix if there is no newline
|
||||
* https://github.com/eslint/eslint/issues/7787
|
||||
*/
|
||||
if (hasNewline) {
|
||||
return null;
|
||||
}
|
||||
return fixer.removeRange([
|
||||
leftToken.range[1],
|
||||
rightToken.range[0],
|
||||
]);
|
||||
},
|
||||
});
|
||||
} else if (!never && !hasWhitespace) {
|
||||
context.report({
|
||||
node,
|
||||
loc: {
|
||||
start: {
|
||||
line: leftToken.loc.end.line,
|
||||
column: leftToken.loc.end.column - 1,
|
||||
},
|
||||
end: rightToken.loc.start,
|
||||
},
|
||||
messageId: "missing",
|
||||
fix(fixer) {
|
||||
if (node.optional) {
|
||||
return null; // Not sure if inserting a space to either before/after `?.` token.
|
||||
}
|
||||
return fixer.insertTextBefore(rightToken, " ");
|
||||
},
|
||||
});
|
||||
} else if (!never && !allowNewlines && hasNewline) {
|
||||
context.report({
|
||||
node,
|
||||
loc: {
|
||||
start: leftToken.loc.end,
|
||||
end: rightToken.loc.start,
|
||||
},
|
||||
messageId: "unexpectedNewline",
|
||||
fix(fixer) {
|
||||
/*
|
||||
* Only autofix if there is no newline
|
||||
* https://github.com/eslint/eslint/issues/7787
|
||||
* But if `?.` exists, it doesn't hide no-unexpected-multiline errors
|
||||
*/
|
||||
if (!node.optional) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Don't remove comments.
|
||||
if (
|
||||
sourceCode.commentsExistBetween(
|
||||
leftToken,
|
||||
rightToken,
|
||||
)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const range = [leftToken.range[1], rightToken.range[0]];
|
||||
const qdToken = sourceCode.getTokenAfter(leftToken);
|
||||
|
||||
if (qdToken.range[0] === leftToken.range[1]) {
|
||||
return fixer.replaceTextRange(range, "?. ");
|
||||
}
|
||||
if (qdToken.range[1] === rightToken.range[0]) {
|
||||
return fixer.replaceTextRange(range, " ?.");
|
||||
}
|
||||
return fixer.replaceTextRange(range, " ?. ");
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
"CallExpression, NewExpression"(node) {
|
||||
const lastToken = sourceCode.getLastToken(node);
|
||||
const lastCalleeToken = sourceCode.getLastToken(node.callee);
|
||||
const parenToken = sourceCode.getFirstTokenBetween(
|
||||
lastCalleeToken,
|
||||
lastToken,
|
||||
astUtils.isOpeningParenToken,
|
||||
);
|
||||
const prevToken =
|
||||
parenToken &&
|
||||
sourceCode.getTokenBefore(
|
||||
parenToken,
|
||||
astUtils.isNotQuestionDotToken,
|
||||
);
|
||||
|
||||
// Parens in NewExpression are optional
|
||||
if (!(parenToken && parenToken.range[1] < node.range[1])) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkSpacing(node, prevToken, parenToken);
|
||||
},
|
||||
|
||||
ImportExpression(node) {
|
||||
const leftToken = sourceCode.getFirstToken(node);
|
||||
const rightToken = sourceCode.getTokenAfter(leftToken);
|
||||
|
||||
checkSpacing(node, leftToken, rightToken);
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,775 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _buffer = require("./buffer.js");
|
||||
var n = require("./node/index.js");
|
||||
var _t = require("@babel/types");
|
||||
var _tokenMap = require("./token-map.js");
|
||||
var generatorFunctions = require("./generators/index.js");
|
||||
var _deprecated = require("./generators/deprecated.js");
|
||||
const {
|
||||
isExpression,
|
||||
isFunction,
|
||||
isStatement,
|
||||
isClassBody,
|
||||
isTSInterfaceBody,
|
||||
isTSEnumMember
|
||||
} = _t;
|
||||
const SCIENTIFIC_NOTATION = /e/i;
|
||||
const ZERO_DECIMAL_INTEGER = /\.0+$/;
|
||||
const HAS_NEWLINE = /[\n\r\u2028\u2029]/;
|
||||
const HAS_NEWLINE_OR_BlOCK_COMMENT_END = /[\n\r\u2028\u2029]|\*\//;
|
||||
function commentIsNewline(c) {
|
||||
return c.type === "CommentLine" || HAS_NEWLINE.test(c.value);
|
||||
}
|
||||
const {
|
||||
needsParens
|
||||
} = n;
|
||||
class Printer {
|
||||
constructor(format, map, tokens, originalCode) {
|
||||
this.inForStatementInit = false;
|
||||
this.tokenContext = 0;
|
||||
this._tokens = null;
|
||||
this._originalCode = null;
|
||||
this._currentNode = null;
|
||||
this._indent = 0;
|
||||
this._indentRepeat = 0;
|
||||
this._insideAux = false;
|
||||
this._noLineTerminator = false;
|
||||
this._noLineTerminatorAfterNode = null;
|
||||
this._printAuxAfterOnNextUserNode = false;
|
||||
this._printedComments = new Set();
|
||||
this._endsWithInteger = false;
|
||||
this._endsWithWord = false;
|
||||
this._endsWithDiv = false;
|
||||
this._lastCommentLine = 0;
|
||||
this._endsWithInnerRaw = false;
|
||||
this._indentInnerComments = true;
|
||||
this.tokenMap = null;
|
||||
this._boundGetRawIdentifier = this._getRawIdentifier.bind(this);
|
||||
this._printSemicolonBeforeNextNode = -1;
|
||||
this._printSemicolonBeforeNextToken = -1;
|
||||
this.format = format;
|
||||
this._tokens = tokens;
|
||||
this._originalCode = originalCode;
|
||||
this._indentRepeat = format.indent.style.length;
|
||||
this._inputMap = map == null ? void 0 : map._inputMap;
|
||||
this._buf = new _buffer.default(map, format.indent.style[0]);
|
||||
}
|
||||
enterForStatementInit() {
|
||||
if (this.inForStatementInit) return () => {};
|
||||
this.inForStatementInit = true;
|
||||
return () => {
|
||||
this.inForStatementInit = false;
|
||||
};
|
||||
}
|
||||
enterDelimited() {
|
||||
const oldInForStatementInit = this.inForStatementInit;
|
||||
const oldNoLineTerminatorAfterNode = this._noLineTerminatorAfterNode;
|
||||
if (oldInForStatementInit === false && oldNoLineTerminatorAfterNode === null) {
|
||||
return () => {};
|
||||
}
|
||||
this.inForStatementInit = false;
|
||||
this._noLineTerminatorAfterNode = null;
|
||||
return () => {
|
||||
this.inForStatementInit = oldInForStatementInit;
|
||||
this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
||||
};
|
||||
}
|
||||
generate(ast) {
|
||||
if (this.format.preserveFormat) {
|
||||
this.tokenMap = new _tokenMap.TokenMap(ast, this._tokens, this._originalCode);
|
||||
}
|
||||
this.print(ast);
|
||||
this._maybeAddAuxComment();
|
||||
return this._buf.get();
|
||||
}
|
||||
indent() {
|
||||
const {
|
||||
format
|
||||
} = this;
|
||||
if (format.preserveFormat || format.compact || format.concise) {
|
||||
return;
|
||||
}
|
||||
this._indent++;
|
||||
}
|
||||
dedent() {
|
||||
const {
|
||||
format
|
||||
} = this;
|
||||
if (format.preserveFormat || format.compact || format.concise) {
|
||||
return;
|
||||
}
|
||||
this._indent--;
|
||||
}
|
||||
semicolon(force = false) {
|
||||
this._maybeAddAuxComment();
|
||||
if (force) {
|
||||
this._appendChar(59);
|
||||
this._noLineTerminator = false;
|
||||
return;
|
||||
}
|
||||
if (this.tokenMap) {
|
||||
const node = this._currentNode;
|
||||
if (node.start != null && node.end != null) {
|
||||
if (!this.tokenMap.endMatches(node, ";")) {
|
||||
this._printSemicolonBeforeNextNode = this._buf.getCurrentLine();
|
||||
return;
|
||||
}
|
||||
const indexes = this.tokenMap.getIndexes(this._currentNode);
|
||||
this._catchUpTo(this._tokens[indexes[indexes.length - 1]].loc.start);
|
||||
}
|
||||
}
|
||||
this._queue(59);
|
||||
this._noLineTerminator = false;
|
||||
}
|
||||
rightBrace(node) {
|
||||
if (this.format.minified) {
|
||||
this._buf.removeLastSemicolon();
|
||||
}
|
||||
this.sourceWithOffset("end", node.loc, -1);
|
||||
this.tokenChar(125);
|
||||
}
|
||||
rightParens(node) {
|
||||
this.sourceWithOffset("end", node.loc, -1);
|
||||
this.tokenChar(41);
|
||||
}
|
||||
space(force = false) {
|
||||
const {
|
||||
format
|
||||
} = this;
|
||||
if (format.compact || format.preserveFormat) return;
|
||||
if (force) {
|
||||
this._space();
|
||||
} else if (this._buf.hasContent()) {
|
||||
const lastCp = this.getLastChar();
|
||||
if (lastCp !== 32 && lastCp !== 10) {
|
||||
this._space();
|
||||
}
|
||||
}
|
||||
}
|
||||
word(str, noLineTerminatorAfter = false) {
|
||||
this.tokenContext = 0;
|
||||
this._maybePrintInnerComments(str);
|
||||
this._maybeAddAuxComment();
|
||||
if (this.tokenMap) this._catchUpToCurrentToken(str);
|
||||
if (this._endsWithWord || this._endsWithDiv && str.charCodeAt(0) === 47) {
|
||||
this._space();
|
||||
}
|
||||
this._append(str, false);
|
||||
this._endsWithWord = true;
|
||||
this._noLineTerminator = noLineTerminatorAfter;
|
||||
}
|
||||
number(str, number) {
|
||||
function isNonDecimalLiteral(str) {
|
||||
if (str.length > 2 && str.charCodeAt(0) === 48) {
|
||||
const secondChar = str.charCodeAt(1);
|
||||
return secondChar === 98 || secondChar === 111 || secondChar === 120;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
this.word(str);
|
||||
this._endsWithInteger = Number.isInteger(number) && !isNonDecimalLiteral(str) && !SCIENTIFIC_NOTATION.test(str) && !ZERO_DECIMAL_INTEGER.test(str) && str.charCodeAt(str.length - 1) !== 46;
|
||||
}
|
||||
token(str, maybeNewline = false, occurrenceCount = 0) {
|
||||
this.tokenContext = 0;
|
||||
this._maybePrintInnerComments(str, occurrenceCount);
|
||||
this._maybeAddAuxComment();
|
||||
if (this.tokenMap) this._catchUpToCurrentToken(str, occurrenceCount);
|
||||
const lastChar = this.getLastChar();
|
||||
const strFirst = str.charCodeAt(0);
|
||||
if (lastChar === 33 && (str === "--" || strFirst === 61) || strFirst === 43 && lastChar === 43 || strFirst === 45 && lastChar === 45 || strFirst === 46 && this._endsWithInteger) {
|
||||
this._space();
|
||||
}
|
||||
this._append(str, maybeNewline);
|
||||
this._noLineTerminator = false;
|
||||
}
|
||||
tokenChar(char) {
|
||||
this.tokenContext = 0;
|
||||
const str = String.fromCharCode(char);
|
||||
this._maybePrintInnerComments(str);
|
||||
this._maybeAddAuxComment();
|
||||
if (this.tokenMap) this._catchUpToCurrentToken(str);
|
||||
const lastChar = this.getLastChar();
|
||||
if (char === 43 && lastChar === 43 || char === 45 && lastChar === 45 || char === 46 && this._endsWithInteger) {
|
||||
this._space();
|
||||
}
|
||||
this._appendChar(char);
|
||||
this._noLineTerminator = false;
|
||||
}
|
||||
newline(i = 1, force) {
|
||||
if (i <= 0) return;
|
||||
if (!force) {
|
||||
if (this.format.retainLines || this.format.compact) return;
|
||||
if (this.format.concise) {
|
||||
this.space();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (i > 2) i = 2;
|
||||
i -= this._buf.getNewlineCount();
|
||||
for (let j = 0; j < i; j++) {
|
||||
this._newline();
|
||||
}
|
||||
return;
|
||||
}
|
||||
endsWith(char) {
|
||||
return this.getLastChar() === char;
|
||||
}
|
||||
getLastChar() {
|
||||
return this._buf.getLastChar();
|
||||
}
|
||||
endsWithCharAndNewline() {
|
||||
return this._buf.endsWithCharAndNewline();
|
||||
}
|
||||
removeTrailingNewline() {
|
||||
this._buf.removeTrailingNewline();
|
||||
}
|
||||
exactSource(loc, cb) {
|
||||
if (!loc) {
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
this._catchUp("start", loc);
|
||||
this._buf.exactSource(loc, cb);
|
||||
}
|
||||
source(prop, loc) {
|
||||
if (!loc) return;
|
||||
this._catchUp(prop, loc);
|
||||
this._buf.source(prop, loc);
|
||||
}
|
||||
sourceWithOffset(prop, loc, columnOffset) {
|
||||
if (!loc || this.format.preserveFormat) return;
|
||||
this._catchUp(prop, loc);
|
||||
this._buf.sourceWithOffset(prop, loc, columnOffset);
|
||||
}
|
||||
sourceIdentifierName(identifierName, pos) {
|
||||
if (!this._buf._canMarkIdName) return;
|
||||
const sourcePosition = this._buf._sourcePosition;
|
||||
sourcePosition.identifierNamePos = pos;
|
||||
sourcePosition.identifierName = identifierName;
|
||||
}
|
||||
_space() {
|
||||
this._queue(32);
|
||||
}
|
||||
_newline() {
|
||||
this._queue(10);
|
||||
}
|
||||
_catchUpToCurrentToken(str, occurrenceCount = 0) {
|
||||
const token = this.tokenMap.findMatching(this._currentNode, str, occurrenceCount);
|
||||
if (token) this._catchUpTo(token.loc.start);
|
||||
if (this._printSemicolonBeforeNextToken !== -1 && this._printSemicolonBeforeNextToken === this._buf.getCurrentLine()) {
|
||||
this._buf.appendChar(59);
|
||||
this._endsWithWord = false;
|
||||
this._endsWithInteger = false;
|
||||
this._endsWithDiv = false;
|
||||
}
|
||||
this._printSemicolonBeforeNextToken = -1;
|
||||
this._printSemicolonBeforeNextNode = -1;
|
||||
}
|
||||
_append(str, maybeNewline) {
|
||||
this._maybeIndent(str.charCodeAt(0));
|
||||
this._buf.append(str, maybeNewline);
|
||||
this._endsWithWord = false;
|
||||
this._endsWithInteger = false;
|
||||
this._endsWithDiv = false;
|
||||
}
|
||||
_appendChar(char) {
|
||||
this._maybeIndent(char);
|
||||
this._buf.appendChar(char);
|
||||
this._endsWithWord = false;
|
||||
this._endsWithInteger = false;
|
||||
this._endsWithDiv = false;
|
||||
}
|
||||
_queue(char) {
|
||||
this._maybeIndent(char);
|
||||
this._buf.queue(char);
|
||||
this._endsWithWord = false;
|
||||
this._endsWithInteger = false;
|
||||
}
|
||||
_maybeIndent(firstChar) {
|
||||
if (this._indent && firstChar !== 10 && this.endsWith(10)) {
|
||||
this._buf.queueIndentation(this._getIndent());
|
||||
}
|
||||
}
|
||||
_shouldIndent(firstChar) {
|
||||
if (this._indent && firstChar !== 10 && this.endsWith(10)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catchUp(line) {
|
||||
if (!this.format.retainLines) return;
|
||||
const count = line - this._buf.getCurrentLine();
|
||||
for (let i = 0; i < count; i++) {
|
||||
this._newline();
|
||||
}
|
||||
}
|
||||
_catchUp(prop, loc) {
|
||||
const {
|
||||
format
|
||||
} = this;
|
||||
if (!format.preserveFormat) {
|
||||
if (format.retainLines && loc != null && loc[prop]) {
|
||||
this.catchUp(loc[prop].line);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const pos = loc == null ? void 0 : loc[prop];
|
||||
if (pos != null) this._catchUpTo(pos);
|
||||
}
|
||||
_catchUpTo({
|
||||
line,
|
||||
column,
|
||||
index
|
||||
}) {
|
||||
const count = line - this._buf.getCurrentLine();
|
||||
if (count > 0 && this._noLineTerminator) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < count; i++) {
|
||||
this._newline();
|
||||
}
|
||||
const spacesCount = count > 0 ? column : column - this._buf.getCurrentColumn();
|
||||
if (spacesCount > 0) {
|
||||
const spaces = this._originalCode ? this._originalCode.slice(index - spacesCount, index).replace(/[^\t\x0B\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]/gu, " ") : " ".repeat(spacesCount);
|
||||
this._append(spaces, false);
|
||||
}
|
||||
}
|
||||
_getIndent() {
|
||||
return this._indentRepeat * this._indent;
|
||||
}
|
||||
printTerminatorless(node) {
|
||||
this._noLineTerminator = true;
|
||||
this.print(node);
|
||||
}
|
||||
print(node, noLineTerminatorAfter, trailingCommentsLineOffset) {
|
||||
var _node$extra, _node$leadingComments, _node$leadingComments2;
|
||||
if (!node) return;
|
||||
this._endsWithInnerRaw = false;
|
||||
const nodeType = node.type;
|
||||
const format = this.format;
|
||||
const oldConcise = format.concise;
|
||||
if (node._compact) {
|
||||
format.concise = true;
|
||||
}
|
||||
const printMethod = this[nodeType];
|
||||
if (printMethod === undefined) {
|
||||
throw new ReferenceError(`unknown node of type ${JSON.stringify(nodeType)} with constructor ${JSON.stringify(node.constructor.name)}`);
|
||||
}
|
||||
const parent = this._currentNode;
|
||||
this._currentNode = node;
|
||||
if (this.tokenMap) {
|
||||
this._printSemicolonBeforeNextToken = this._printSemicolonBeforeNextNode;
|
||||
}
|
||||
const oldInAux = this._insideAux;
|
||||
this._insideAux = node.loc == null;
|
||||
this._maybeAddAuxComment(this._insideAux && !oldInAux);
|
||||
const parenthesized = (_node$extra = node.extra) == null ? void 0 : _node$extra.parenthesized;
|
||||
let shouldPrintParens = parenthesized && format.preserveFormat || parenthesized && format.retainFunctionParens && nodeType === "FunctionExpression" || needsParens(node, parent, this.tokenContext, this.inForStatementInit, format.preserveFormat ? this._boundGetRawIdentifier : undefined);
|
||||
if (!shouldPrintParens && parenthesized && (_node$leadingComments = node.leadingComments) != null && _node$leadingComments.length && node.leadingComments[0].type === "CommentBlock") {
|
||||
const parentType = parent == null ? void 0 : parent.type;
|
||||
switch (parentType) {
|
||||
case "ExpressionStatement":
|
||||
case "VariableDeclarator":
|
||||
case "AssignmentExpression":
|
||||
case "ReturnStatement":
|
||||
break;
|
||||
case "CallExpression":
|
||||
case "OptionalCallExpression":
|
||||
case "NewExpression":
|
||||
if (parent.callee !== node) break;
|
||||
default:
|
||||
shouldPrintParens = true;
|
||||
}
|
||||
}
|
||||
let indentParenthesized = false;
|
||||
if (!shouldPrintParens && this._noLineTerminator && ((_node$leadingComments2 = node.leadingComments) != null && _node$leadingComments2.some(commentIsNewline) || this.format.retainLines && node.loc && node.loc.start.line > this._buf.getCurrentLine())) {
|
||||
shouldPrintParens = true;
|
||||
indentParenthesized = true;
|
||||
}
|
||||
let oldNoLineTerminatorAfterNode;
|
||||
let oldInForStatementInitWasTrue;
|
||||
if (!shouldPrintParens) {
|
||||
noLineTerminatorAfter || (noLineTerminatorAfter = parent && this._noLineTerminatorAfterNode === parent && n.isLastChild(parent, node));
|
||||
if (noLineTerminatorAfter) {
|
||||
var _node$trailingComment;
|
||||
if ((_node$trailingComment = node.trailingComments) != null && _node$trailingComment.some(commentIsNewline)) {
|
||||
if (isExpression(node)) shouldPrintParens = true;
|
||||
} else {
|
||||
oldNoLineTerminatorAfterNode = this._noLineTerminatorAfterNode;
|
||||
this._noLineTerminatorAfterNode = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (shouldPrintParens) {
|
||||
this.tokenChar(40);
|
||||
if (indentParenthesized) this.indent();
|
||||
this._endsWithInnerRaw = false;
|
||||
if (this.inForStatementInit) {
|
||||
oldInForStatementInitWasTrue = true;
|
||||
this.inForStatementInit = false;
|
||||
}
|
||||
oldNoLineTerminatorAfterNode = this._noLineTerminatorAfterNode;
|
||||
this._noLineTerminatorAfterNode = null;
|
||||
}
|
||||
this._lastCommentLine = 0;
|
||||
this._printLeadingComments(node, parent);
|
||||
const loc = nodeType === "Program" || nodeType === "File" ? null : node.loc;
|
||||
this.exactSource(loc, printMethod.bind(this, node, parent));
|
||||
if (shouldPrintParens) {
|
||||
this._printTrailingComments(node, parent);
|
||||
if (indentParenthesized) {
|
||||
this.dedent();
|
||||
this.newline();
|
||||
}
|
||||
this.tokenChar(41);
|
||||
this._noLineTerminator = noLineTerminatorAfter;
|
||||
if (oldInForStatementInitWasTrue) this.inForStatementInit = true;
|
||||
} else if (noLineTerminatorAfter && !this._noLineTerminator) {
|
||||
this._noLineTerminator = true;
|
||||
this._printTrailingComments(node, parent);
|
||||
} else {
|
||||
this._printTrailingComments(node, parent, trailingCommentsLineOffset);
|
||||
}
|
||||
this._currentNode = parent;
|
||||
format.concise = oldConcise;
|
||||
this._insideAux = oldInAux;
|
||||
if (oldNoLineTerminatorAfterNode !== undefined) {
|
||||
this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
||||
}
|
||||
this._endsWithInnerRaw = false;
|
||||
}
|
||||
_maybeAddAuxComment(enteredPositionlessNode) {
|
||||
if (enteredPositionlessNode) this._printAuxBeforeComment();
|
||||
if (!this._insideAux) this._printAuxAfterComment();
|
||||
}
|
||||
_printAuxBeforeComment() {
|
||||
if (this._printAuxAfterOnNextUserNode) return;
|
||||
this._printAuxAfterOnNextUserNode = true;
|
||||
const comment = this.format.auxiliaryCommentBefore;
|
||||
if (comment) {
|
||||
this._printComment({
|
||||
type: "CommentBlock",
|
||||
value: comment
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
_printAuxAfterComment() {
|
||||
if (!this._printAuxAfterOnNextUserNode) return;
|
||||
this._printAuxAfterOnNextUserNode = false;
|
||||
const comment = this.format.auxiliaryCommentAfter;
|
||||
if (comment) {
|
||||
this._printComment({
|
||||
type: "CommentBlock",
|
||||
value: comment
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
getPossibleRaw(node) {
|
||||
const extra = node.extra;
|
||||
if ((extra == null ? void 0 : extra.raw) != null && extra.rawValue != null && node.value === extra.rawValue) {
|
||||
return extra.raw;
|
||||
}
|
||||
}
|
||||
printJoin(nodes, statement, indent, separator, printTrailingSeparator, addNewlines, iterator, trailingCommentsLineOffset) {
|
||||
if (!(nodes != null && nodes.length)) return;
|
||||
if (indent == null && this.format.retainLines) {
|
||||
var _nodes$0$loc;
|
||||
const startLine = (_nodes$0$loc = nodes[0].loc) == null ? void 0 : _nodes$0$loc.start.line;
|
||||
if (startLine != null && startLine !== this._buf.getCurrentLine()) {
|
||||
indent = true;
|
||||
}
|
||||
}
|
||||
if (indent) this.indent();
|
||||
const newlineOpts = {
|
||||
addNewlines: addNewlines,
|
||||
nextNodeStartLine: 0
|
||||
};
|
||||
const boundSeparator = separator == null ? void 0 : separator.bind(this);
|
||||
const len = nodes.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const node = nodes[i];
|
||||
if (!node) continue;
|
||||
if (statement) this._printNewline(i === 0, newlineOpts);
|
||||
this.print(node, undefined, trailingCommentsLineOffset || 0);
|
||||
iterator == null || iterator(node, i);
|
||||
if (boundSeparator != null) {
|
||||
if (i < len - 1) boundSeparator(i, false);else if (printTrailingSeparator) boundSeparator(i, true);
|
||||
}
|
||||
if (statement) {
|
||||
var _node$trailingComment2;
|
||||
if (!((_node$trailingComment2 = node.trailingComments) != null && _node$trailingComment2.length)) {
|
||||
this._lastCommentLine = 0;
|
||||
}
|
||||
if (i + 1 === len) {
|
||||
this.newline(1);
|
||||
} else {
|
||||
var _nextNode$loc;
|
||||
const nextNode = nodes[i + 1];
|
||||
newlineOpts.nextNodeStartLine = ((_nextNode$loc = nextNode.loc) == null ? void 0 : _nextNode$loc.start.line) || 0;
|
||||
this._printNewline(true, newlineOpts);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (indent) this.dedent();
|
||||
}
|
||||
printAndIndentOnComments(node) {
|
||||
const indent = node.leadingComments && node.leadingComments.length > 0;
|
||||
if (indent) this.indent();
|
||||
this.print(node);
|
||||
if (indent) this.dedent();
|
||||
}
|
||||
printBlock(parent) {
|
||||
const node = parent.body;
|
||||
if (node.type !== "EmptyStatement") {
|
||||
this.space();
|
||||
}
|
||||
this.print(node);
|
||||
}
|
||||
_printTrailingComments(node, parent, lineOffset) {
|
||||
const {
|
||||
innerComments,
|
||||
trailingComments
|
||||
} = node;
|
||||
if (innerComments != null && innerComments.length) {
|
||||
this._printComments(2, innerComments, node, parent, lineOffset);
|
||||
}
|
||||
if (trailingComments != null && trailingComments.length) {
|
||||
this._printComments(2, trailingComments, node, parent, lineOffset);
|
||||
}
|
||||
}
|
||||
_printLeadingComments(node, parent) {
|
||||
const comments = node.leadingComments;
|
||||
if (!(comments != null && comments.length)) return;
|
||||
this._printComments(0, comments, node, parent);
|
||||
}
|
||||
_maybePrintInnerComments(nextTokenStr, nextTokenOccurrenceCount) {
|
||||
if (this._endsWithInnerRaw) {
|
||||
var _this$tokenMap;
|
||||
this.printInnerComments((_this$tokenMap = this.tokenMap) == null ? void 0 : _this$tokenMap.findMatching(this._currentNode, nextTokenStr, nextTokenOccurrenceCount));
|
||||
}
|
||||
this._endsWithInnerRaw = true;
|
||||
this._indentInnerComments = true;
|
||||
}
|
||||
printInnerComments(nextToken) {
|
||||
const node = this._currentNode;
|
||||
const comments = node.innerComments;
|
||||
if (!(comments != null && comments.length)) return;
|
||||
const hasSpace = this.endsWith(32);
|
||||
const indent = this._indentInnerComments;
|
||||
const printedCommentsCount = this._printedComments.size;
|
||||
if (indent) this.indent();
|
||||
this._printComments(1, comments, node, undefined, undefined, nextToken);
|
||||
if (hasSpace && printedCommentsCount !== this._printedComments.size) {
|
||||
this.space();
|
||||
}
|
||||
if (indent) this.dedent();
|
||||
}
|
||||
noIndentInnerCommentsHere() {
|
||||
this._indentInnerComments = false;
|
||||
}
|
||||
printSequence(nodes, indent, trailingCommentsLineOffset, addNewlines) {
|
||||
this.printJoin(nodes, true, indent != null ? indent : false, undefined, undefined, addNewlines, undefined, trailingCommentsLineOffset);
|
||||
}
|
||||
printList(items, printTrailingSeparator, statement, indent, separator, iterator) {
|
||||
this.printJoin(items, statement, indent, separator != null ? separator : commaSeparator, printTrailingSeparator, undefined, iterator);
|
||||
}
|
||||
shouldPrintTrailingComma(listEnd) {
|
||||
if (!this.tokenMap) return null;
|
||||
const listEndIndex = this.tokenMap.findLastIndex(this._currentNode, token => this.tokenMap.matchesOriginal(token, listEnd));
|
||||
if (listEndIndex <= 0) return null;
|
||||
return this.tokenMap.matchesOriginal(this._tokens[listEndIndex - 1], ",");
|
||||
}
|
||||
_printNewline(newLine, opts) {
|
||||
const format = this.format;
|
||||
if (format.retainLines || format.compact) return;
|
||||
if (format.concise) {
|
||||
this.space();
|
||||
return;
|
||||
}
|
||||
if (!newLine) {
|
||||
return;
|
||||
}
|
||||
const startLine = opts.nextNodeStartLine;
|
||||
const lastCommentLine = this._lastCommentLine;
|
||||
if (startLine > 0 && lastCommentLine > 0) {
|
||||
const offset = startLine - lastCommentLine;
|
||||
if (offset >= 0) {
|
||||
this.newline(offset || 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this._buf.hasContent()) {
|
||||
this.newline(1);
|
||||
}
|
||||
}
|
||||
_shouldPrintComment(comment, nextToken) {
|
||||
if (comment.ignore) return 0;
|
||||
if (this._printedComments.has(comment)) return 0;
|
||||
if (this._noLineTerminator && HAS_NEWLINE_OR_BlOCK_COMMENT_END.test(comment.value)) {
|
||||
return 2;
|
||||
}
|
||||
if (nextToken && this.tokenMap) {
|
||||
const commentTok = this.tokenMap.find(this._currentNode, token => token.value === comment.value);
|
||||
if (commentTok && commentTok.start > nextToken.start) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
this._printedComments.add(comment);
|
||||
if (!this.format.shouldPrintComment(comment.value)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
_printComment(comment, skipNewLines) {
|
||||
const noLineTerminator = this._noLineTerminator;
|
||||
const isBlockComment = comment.type === "CommentBlock";
|
||||
const printNewLines = isBlockComment && skipNewLines !== 1 && !this._noLineTerminator;
|
||||
if (printNewLines && this._buf.hasContent() && skipNewLines !== 2) {
|
||||
this.newline(1);
|
||||
}
|
||||
const lastCharCode = this.getLastChar();
|
||||
if (lastCharCode !== 91 && lastCharCode !== 123 && lastCharCode !== 40) {
|
||||
this.space();
|
||||
}
|
||||
let val;
|
||||
if (isBlockComment) {
|
||||
val = `/*${comment.value}*/`;
|
||||
if (this.format.indent.adjustMultilineComment) {
|
||||
var _comment$loc;
|
||||
const offset = (_comment$loc = comment.loc) == null ? void 0 : _comment$loc.start.column;
|
||||
if (offset) {
|
||||
const newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
||||
val = val.replace(newlineRegex, "\n");
|
||||
}
|
||||
if (this.format.concise) {
|
||||
val = val.replace(/\n(?!$)/g, `\n`);
|
||||
} else {
|
||||
let indentSize = this.format.retainLines ? 0 : this._buf.getCurrentColumn();
|
||||
if (this._shouldIndent(47) || this.format.retainLines) {
|
||||
indentSize += this._getIndent();
|
||||
}
|
||||
val = val.replace(/\n(?!$)/g, `\n${" ".repeat(indentSize)}`);
|
||||
}
|
||||
}
|
||||
} else if (!noLineTerminator) {
|
||||
val = `//${comment.value}`;
|
||||
} else {
|
||||
val = `/*${comment.value}*/`;
|
||||
}
|
||||
if (this._endsWithDiv) this._space();
|
||||
if (this.tokenMap) {
|
||||
const {
|
||||
_printSemicolonBeforeNextToken,
|
||||
_printSemicolonBeforeNextNode
|
||||
} = this;
|
||||
this._printSemicolonBeforeNextToken = -1;
|
||||
this._printSemicolonBeforeNextNode = -1;
|
||||
this.source("start", comment.loc);
|
||||
this._append(val, isBlockComment);
|
||||
this._printSemicolonBeforeNextNode = _printSemicolonBeforeNextNode;
|
||||
this._printSemicolonBeforeNextToken = _printSemicolonBeforeNextToken;
|
||||
} else {
|
||||
this.source("start", comment.loc);
|
||||
this._append(val, isBlockComment);
|
||||
}
|
||||
if (!isBlockComment && !noLineTerminator) {
|
||||
this.newline(1, true);
|
||||
}
|
||||
if (printNewLines && skipNewLines !== 3) {
|
||||
this.newline(1);
|
||||
}
|
||||
}
|
||||
_printComments(type, comments, node, parent, lineOffset = 0, nextToken) {
|
||||
const nodeLoc = node.loc;
|
||||
const len = comments.length;
|
||||
let hasLoc = !!nodeLoc;
|
||||
const nodeStartLine = hasLoc ? nodeLoc.start.line : 0;
|
||||
const nodeEndLine = hasLoc ? nodeLoc.end.line : 0;
|
||||
let lastLine = 0;
|
||||
let leadingCommentNewline = 0;
|
||||
const maybeNewline = this._noLineTerminator ? function () {} : this.newline.bind(this);
|
||||
for (let i = 0; i < len; i++) {
|
||||
const comment = comments[i];
|
||||
const shouldPrint = this._shouldPrintComment(comment, nextToken);
|
||||
if (shouldPrint === 2) {
|
||||
hasLoc = false;
|
||||
break;
|
||||
}
|
||||
if (hasLoc && comment.loc && shouldPrint === 1) {
|
||||
const commentStartLine = comment.loc.start.line;
|
||||
const commentEndLine = comment.loc.end.line;
|
||||
if (type === 0) {
|
||||
let offset = 0;
|
||||
if (i === 0) {
|
||||
if (this._buf.hasContent() && (comment.type === "CommentLine" || commentStartLine !== commentEndLine)) {
|
||||
offset = leadingCommentNewline = 1;
|
||||
}
|
||||
} else {
|
||||
offset = commentStartLine - lastLine;
|
||||
}
|
||||
lastLine = commentEndLine;
|
||||
maybeNewline(offset);
|
||||
this._printComment(comment, 1);
|
||||
if (i + 1 === len) {
|
||||
maybeNewline(Math.max(nodeStartLine - lastLine, leadingCommentNewline));
|
||||
lastLine = nodeStartLine;
|
||||
}
|
||||
} else if (type === 1) {
|
||||
const offset = commentStartLine - (i === 0 ? nodeStartLine : lastLine);
|
||||
lastLine = commentEndLine;
|
||||
maybeNewline(offset);
|
||||
this._printComment(comment, 1);
|
||||
if (i + 1 === len) {
|
||||
maybeNewline(Math.min(1, nodeEndLine - lastLine));
|
||||
lastLine = nodeEndLine;
|
||||
}
|
||||
} else {
|
||||
const offset = commentStartLine - (i === 0 ? nodeEndLine - lineOffset : lastLine);
|
||||
lastLine = commentEndLine;
|
||||
maybeNewline(offset);
|
||||
this._printComment(comment, 1);
|
||||
}
|
||||
} else {
|
||||
hasLoc = false;
|
||||
if (shouldPrint !== 1) {
|
||||
continue;
|
||||
}
|
||||
if (len === 1) {
|
||||
const singleLine = comment.loc ? comment.loc.start.line === comment.loc.end.line : !HAS_NEWLINE.test(comment.value);
|
||||
const shouldSkipNewline = singleLine && !isStatement(node) && !isClassBody(parent) && !isTSInterfaceBody(parent) && !isTSEnumMember(node);
|
||||
if (type === 0) {
|
||||
this._printComment(comment, shouldSkipNewline && node.type !== "ObjectExpression" || singleLine && isFunction(parent, {
|
||||
body: node
|
||||
}) ? 1 : 0);
|
||||
} else if (shouldSkipNewline && type === 2) {
|
||||
this._printComment(comment, 1);
|
||||
} else {
|
||||
this._printComment(comment, 0);
|
||||
}
|
||||
} else if (type === 1 && !(node.type === "ObjectExpression" && node.properties.length > 1) && node.type !== "ClassBody" && node.type !== "TSInterfaceBody") {
|
||||
this._printComment(comment, i === 0 ? 2 : i === len - 1 ? 3 : 0);
|
||||
} else {
|
||||
this._printComment(comment, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type === 2 && hasLoc && lastLine) {
|
||||
this._lastCommentLine = lastLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
Object.assign(Printer.prototype, generatorFunctions);
|
||||
{
|
||||
(0, _deprecated.addDeprecatedGenerators)(Printer);
|
||||
}
|
||||
var _default = exports.default = Printer;
|
||||
function commaSeparator(occurrenceCount, last) {
|
||||
this.token(",", false, occurrenceCount);
|
||||
if (!last) this.space();
|
||||
}
|
||||
|
||||
//# sourceMappingURL=printer.js.map
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,524 @@
|
||||
// src/parse-path.ts
|
||||
var ARG_LENGTH = {
|
||||
a: 7,
|
||||
c: 6,
|
||||
h: 1,
|
||||
l: 2,
|
||||
m: 2,
|
||||
q: 4,
|
||||
s: 4,
|
||||
t: 2,
|
||||
v: 1,
|
||||
z: 0
|
||||
};
|
||||
var SEGMENT_PATTERN = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
|
||||
var NUMBER = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
|
||||
function parseValues(args) {
|
||||
const numbers = args.match(NUMBER);
|
||||
return numbers ? numbers.map(Number) : [];
|
||||
}
|
||||
function parsePath(path) {
|
||||
const data = [];
|
||||
const p = String(path).trim();
|
||||
if (p[0] !== "M" && p[0] !== "m") {
|
||||
return data;
|
||||
}
|
||||
p.replace(SEGMENT_PATTERN, (_, command, args) => {
|
||||
const theArgs = parseValues(args);
|
||||
let type = command.toLowerCase();
|
||||
let theCommand = command;
|
||||
if (type === "m" && theArgs.length > 2) {
|
||||
data.push([theCommand, ...theArgs.splice(0, 2)]);
|
||||
type = "l";
|
||||
theCommand = theCommand === "m" ? "l" : "L";
|
||||
}
|
||||
if (theArgs.length < ARG_LENGTH[type]) {
|
||||
return "";
|
||||
}
|
||||
data.push([theCommand, ...theArgs.splice(0, ARG_LENGTH[type])]);
|
||||
while (theArgs.length >= ARG_LENGTH[type] && theArgs.length && ARG_LENGTH[type]) {
|
||||
data.push([theCommand, ...theArgs.splice(0, ARG_LENGTH[type])]);
|
||||
}
|
||||
return "";
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
// src/path2d.ts
|
||||
function rotatePoint(point, angle) {
|
||||
const nx = point.x * Math.cos(angle) - point.y * Math.sin(angle);
|
||||
const ny = point.y * Math.cos(angle) + point.x * Math.sin(angle);
|
||||
point.x = nx;
|
||||
point.y = ny;
|
||||
}
|
||||
function translatePoint(point, dx, dy) {
|
||||
point.x += dx;
|
||||
point.y += dy;
|
||||
}
|
||||
function scalePoint(point, s) {
|
||||
point.x *= s;
|
||||
point.y *= s;
|
||||
}
|
||||
var Path2D = class _Path2D {
|
||||
constructor(path) {
|
||||
this.commands = [];
|
||||
if (path && path instanceof _Path2D) {
|
||||
this.commands.push(...path.commands);
|
||||
} else if (path) {
|
||||
this.commands = parsePath(path);
|
||||
}
|
||||
}
|
||||
addPath(path) {
|
||||
if (path && path instanceof _Path2D) {
|
||||
this.commands.push(...path.commands);
|
||||
}
|
||||
}
|
||||
moveTo(x, y) {
|
||||
this.commands.push(["M", x, y]);
|
||||
}
|
||||
lineTo(x, y) {
|
||||
this.commands.push(["L", x, y]);
|
||||
}
|
||||
arc(x, y, r, start, end, ccw) {
|
||||
this.commands.push(["AC", x, y, r, start, end, !!ccw]);
|
||||
}
|
||||
arcTo(x1, y1, x2, y2, r) {
|
||||
this.commands.push(["AT", x1, y1, x2, y2, r]);
|
||||
}
|
||||
ellipse(x, y, rx, ry, angle, start, end, ccw) {
|
||||
this.commands.push(["E", x, y, rx, ry, angle, start, end, !!ccw]);
|
||||
}
|
||||
closePath() {
|
||||
this.commands.push(["Z"]);
|
||||
}
|
||||
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
||||
this.commands.push(["C", cp1x, cp1y, cp2x, cp2y, x, y]);
|
||||
}
|
||||
quadraticCurveTo(cpx, cpy, x, y) {
|
||||
this.commands.push(["Q", cpx, cpy, x, y]);
|
||||
}
|
||||
rect(x, y, width, height) {
|
||||
this.commands.push(["R", x, y, width, height]);
|
||||
}
|
||||
roundRect(x, y, width, height, radii) {
|
||||
if (typeof radii === "undefined") {
|
||||
this.commands.push(["RR", x, y, width, height, 0]);
|
||||
} else {
|
||||
this.commands.push(["RR", x, y, width, height, radii]);
|
||||
}
|
||||
}
|
||||
};
|
||||
function buildPath(ctx, commands) {
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
let endAngle;
|
||||
let startAngle;
|
||||
let largeArcFlag;
|
||||
let sweepFlag;
|
||||
let endPoint;
|
||||
let midPoint;
|
||||
let angle;
|
||||
let lambda;
|
||||
let t1;
|
||||
let t2;
|
||||
let x1;
|
||||
let y1;
|
||||
let r;
|
||||
let rx;
|
||||
let ry;
|
||||
let w;
|
||||
let h;
|
||||
let pathType;
|
||||
let centerPoint;
|
||||
let ccw;
|
||||
let radii;
|
||||
let cpx = null;
|
||||
let cpy = null;
|
||||
let qcpx = null;
|
||||
let qcpy = null;
|
||||
let startPoint = null;
|
||||
let currentPoint = null;
|
||||
ctx.beginPath();
|
||||
for (let i = 0; i < commands.length; ++i) {
|
||||
pathType = commands[i][0];
|
||||
if (pathType !== "S" && pathType !== "s" && pathType !== "C" && pathType !== "c") {
|
||||
cpx = null;
|
||||
cpy = null;
|
||||
}
|
||||
if (pathType !== "T" && pathType !== "t" && pathType !== "Q" && pathType !== "q") {
|
||||
qcpx = null;
|
||||
qcpy = null;
|
||||
}
|
||||
let c;
|
||||
switch (pathType) {
|
||||
case "m":
|
||||
case "M":
|
||||
c = commands[i];
|
||||
if (pathType === "m") {
|
||||
x += c[1];
|
||||
y += c[2];
|
||||
} else {
|
||||
x = c[1];
|
||||
y = c[2];
|
||||
}
|
||||
if (pathType === "M" || !startPoint) {
|
||||
startPoint = { x, y };
|
||||
}
|
||||
ctx.moveTo(x, y);
|
||||
break;
|
||||
case "l":
|
||||
c = commands[i];
|
||||
x += c[1];
|
||||
y += c[2];
|
||||
ctx.lineTo(x, y);
|
||||
break;
|
||||
case "L":
|
||||
c = commands[i];
|
||||
x = c[1];
|
||||
y = c[2];
|
||||
ctx.lineTo(x, y);
|
||||
break;
|
||||
case "H":
|
||||
c = commands[i];
|
||||
x = c[1];
|
||||
ctx.lineTo(x, y);
|
||||
break;
|
||||
case "h":
|
||||
c = commands[i];
|
||||
x += c[1];
|
||||
ctx.lineTo(x, y);
|
||||
break;
|
||||
case "V":
|
||||
c = commands[i];
|
||||
y = c[1];
|
||||
ctx.lineTo(x, y);
|
||||
break;
|
||||
case "v":
|
||||
c = commands[i];
|
||||
y += c[1];
|
||||
ctx.lineTo(x, y);
|
||||
break;
|
||||
case "a":
|
||||
case "A":
|
||||
c = commands[i];
|
||||
if (currentPoint === null) {
|
||||
throw new Error("This should never happen");
|
||||
}
|
||||
if (pathType === "a") {
|
||||
x += c[6];
|
||||
y += c[7];
|
||||
} else {
|
||||
x = c[6];
|
||||
y = c[7];
|
||||
}
|
||||
rx = c[1];
|
||||
ry = c[2];
|
||||
angle = c[3] * Math.PI / 180;
|
||||
largeArcFlag = !!c[4];
|
||||
sweepFlag = !!c[5];
|
||||
endPoint = { x, y };
|
||||
midPoint = {
|
||||
x: (currentPoint.x - endPoint.x) / 2,
|
||||
y: (currentPoint.y - endPoint.y) / 2
|
||||
};
|
||||
rotatePoint(midPoint, -angle);
|
||||
lambda = midPoint.x * midPoint.x / (rx * rx) + midPoint.y * midPoint.y / (ry * ry);
|
||||
if (lambda > 1) {
|
||||
lambda = Math.sqrt(lambda);
|
||||
rx *= lambda;
|
||||
ry *= lambda;
|
||||
}
|
||||
centerPoint = {
|
||||
x: rx * midPoint.y / ry,
|
||||
y: -(ry * midPoint.x) / rx
|
||||
};
|
||||
t1 = rx * rx * ry * ry;
|
||||
t2 = rx * rx * midPoint.y * midPoint.y + ry * ry * midPoint.x * midPoint.x;
|
||||
if (sweepFlag !== largeArcFlag) {
|
||||
scalePoint(centerPoint, Math.sqrt((t1 - t2) / t2) || 0);
|
||||
} else {
|
||||
scalePoint(centerPoint, -Math.sqrt((t1 - t2) / t2) || 0);
|
||||
}
|
||||
startAngle = Math.atan2((midPoint.y - centerPoint.y) / ry, (midPoint.x - centerPoint.x) / rx);
|
||||
endAngle = Math.atan2(-(midPoint.y + centerPoint.y) / ry, -(midPoint.x + centerPoint.x) / rx);
|
||||
rotatePoint(centerPoint, angle);
|
||||
translatePoint(centerPoint, (endPoint.x + currentPoint.x) / 2, (endPoint.y + currentPoint.y) / 2);
|
||||
ctx.save();
|
||||
ctx.translate(centerPoint.x, centerPoint.y);
|
||||
ctx.rotate(angle);
|
||||
ctx.scale(rx, ry);
|
||||
ctx.arc(0, 0, 1, startAngle, endAngle, !sweepFlag);
|
||||
ctx.restore();
|
||||
break;
|
||||
case "C":
|
||||
c = commands[i];
|
||||
cpx = c[3];
|
||||
cpy = c[4];
|
||||
x = c[5];
|
||||
y = c[6];
|
||||
ctx.bezierCurveTo(c[1], c[2], cpx, cpy, x, y);
|
||||
break;
|
||||
case "c":
|
||||
c = commands[i];
|
||||
ctx.bezierCurveTo(c[1] + x, c[2] + y, c[3] + x, c[4] + y, c[5] + x, c[6] + y);
|
||||
cpx = c[3] + x;
|
||||
cpy = c[4] + y;
|
||||
x += c[5];
|
||||
y += c[6];
|
||||
break;
|
||||
case "S":
|
||||
c = commands[i];
|
||||
if (cpx === null || cpy === null) {
|
||||
cpx = x;
|
||||
cpy = y;
|
||||
}
|
||||
ctx.bezierCurveTo(2 * x - cpx, 2 * y - cpy, c[1], c[2], c[3], c[4]);
|
||||
cpx = c[1];
|
||||
cpy = c[2];
|
||||
x = c[3];
|
||||
y = c[4];
|
||||
break;
|
||||
case "s":
|
||||
c = commands[i];
|
||||
if (cpx === null || cpy === null) {
|
||||
cpx = x;
|
||||
cpy = y;
|
||||
}
|
||||
ctx.bezierCurveTo(2 * x - cpx, 2 * y - cpy, c[1] + x, c[2] + y, c[3] + x, c[4] + y);
|
||||
cpx = c[1] + x;
|
||||
cpy = c[2] + y;
|
||||
x += c[3];
|
||||
y += c[4];
|
||||
break;
|
||||
case "Q":
|
||||
c = commands[i];
|
||||
qcpx = c[1];
|
||||
qcpy = c[2];
|
||||
x = c[3];
|
||||
y = c[4];
|
||||
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
|
||||
break;
|
||||
case "q":
|
||||
c = commands[i];
|
||||
qcpx = c[1] + x;
|
||||
qcpy = c[2] + y;
|
||||
x += c[3];
|
||||
y += c[4];
|
||||
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
|
||||
break;
|
||||
case "T":
|
||||
c = commands[i];
|
||||
if (qcpx === null || qcpy === null) {
|
||||
qcpx = x;
|
||||
qcpy = y;
|
||||
}
|
||||
qcpx = 2 * x - qcpx;
|
||||
qcpy = 2 * y - qcpy;
|
||||
x = c[1];
|
||||
y = c[2];
|
||||
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
|
||||
break;
|
||||
case "t":
|
||||
c = commands[i];
|
||||
if (qcpx === null || qcpy === null) {
|
||||
qcpx = x;
|
||||
qcpy = y;
|
||||
}
|
||||
qcpx = 2 * x - qcpx;
|
||||
qcpy = 2 * y - qcpy;
|
||||
x += c[1];
|
||||
y += c[2];
|
||||
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
|
||||
break;
|
||||
case "z":
|
||||
case "Z":
|
||||
if (startPoint) {
|
||||
x = startPoint.x;
|
||||
y = startPoint.y;
|
||||
}
|
||||
startPoint = null;
|
||||
ctx.closePath();
|
||||
break;
|
||||
case "AC":
|
||||
c = commands[i];
|
||||
x = c[1];
|
||||
y = c[2];
|
||||
r = c[3];
|
||||
startAngle = c[4];
|
||||
endAngle = c[5];
|
||||
ccw = c[6];
|
||||
ctx.arc(x, y, r, startAngle, endAngle, ccw);
|
||||
break;
|
||||
case "AT":
|
||||
c = commands[i];
|
||||
x1 = c[1];
|
||||
y1 = c[2];
|
||||
x = c[3];
|
||||
y = c[4];
|
||||
r = c[5];
|
||||
ctx.arcTo(x1, y1, x, y, r);
|
||||
break;
|
||||
case "E":
|
||||
c = commands[i];
|
||||
x = c[1];
|
||||
y = c[2];
|
||||
rx = c[3];
|
||||
ry = c[4];
|
||||
angle = c[5];
|
||||
startAngle = c[6];
|
||||
endAngle = c[7];
|
||||
ccw = c[8];
|
||||
ctx.save();
|
||||
ctx.translate(x, y);
|
||||
ctx.rotate(angle);
|
||||
ctx.scale(rx, ry);
|
||||
ctx.arc(0, 0, 1, startAngle, endAngle, ccw);
|
||||
ctx.restore();
|
||||
break;
|
||||
case "R":
|
||||
c = commands[i];
|
||||
x = c[1];
|
||||
y = c[2];
|
||||
w = c[3];
|
||||
h = c[4];
|
||||
startPoint = { x, y };
|
||||
ctx.rect(x, y, w, h);
|
||||
break;
|
||||
case "RR":
|
||||
c = commands[i];
|
||||
x = c[1];
|
||||
y = c[2];
|
||||
w = c[3];
|
||||
h = c[4];
|
||||
radii = c[5];
|
||||
startPoint = { x, y };
|
||||
ctx.roundRect(x, y, w, h, radii);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Invalid path command: ${pathType}`);
|
||||
}
|
||||
if (!currentPoint) {
|
||||
currentPoint = { x, y };
|
||||
} else {
|
||||
currentPoint.x = x;
|
||||
currentPoint.y = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// src/round-rect.ts
|
||||
function roundRect(x, y, width, height, radii = 0) {
|
||||
if (typeof radii === "number") {
|
||||
radii = [radii];
|
||||
}
|
||||
if (Array.isArray(radii)) {
|
||||
if (radii.length === 0 || radii.length > 4) {
|
||||
throw new RangeError(
|
||||
`Failed to execute 'roundRect' on '${this.constructor.name}': ${radii.length} radii provided. Between one and four radii are necessary.`
|
||||
);
|
||||
}
|
||||
radii.forEach((v) => {
|
||||
if (v < 0) {
|
||||
throw new RangeError(
|
||||
`Failed to execute 'roundRect' on '${this.constructor.name}': Radius value ${v} is negative.`
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (radii.length === 1 && radii[0] === 0) {
|
||||
this.rect(x, y, width, height);
|
||||
return;
|
||||
}
|
||||
const minRadius = Math.min(width, height) / 2;
|
||||
const tl = Math.min(minRadius, radii[0]);
|
||||
let tr = tl;
|
||||
let br = tl;
|
||||
let bl = tl;
|
||||
if (radii.length === 2) {
|
||||
tr = Math.min(minRadius, radii[1]);
|
||||
bl = tr;
|
||||
}
|
||||
if (radii.length === 3) {
|
||||
tr = Math.min(minRadius, radii[1]);
|
||||
bl = tr;
|
||||
br = Math.min(minRadius, radii[2]);
|
||||
}
|
||||
if (radii.length === 4) {
|
||||
tr = Math.min(minRadius, radii[1]);
|
||||
br = Math.min(minRadius, radii[2]);
|
||||
bl = Math.min(minRadius, radii[3]);
|
||||
}
|
||||
this.moveTo(x, y + height - bl);
|
||||
this.arcTo(x, y, x + tl, y, tl);
|
||||
this.arcTo(x + width, y, x + width, y + tr, tr);
|
||||
this.arcTo(x + width, y + height, x + width - br, y + height, br);
|
||||
this.arcTo(x, y + height, x, y + height - bl, bl);
|
||||
this.closePath();
|
||||
}
|
||||
|
||||
// src/apply.ts
|
||||
function applyPath2DToCanvasRenderingContext(CanvasRenderingContext2D) {
|
||||
if (!CanvasRenderingContext2D) return;
|
||||
const cClip = CanvasRenderingContext2D.prototype.clip;
|
||||
const cFill = CanvasRenderingContext2D.prototype.fill;
|
||||
const cStroke = CanvasRenderingContext2D.prototype.stroke;
|
||||
const cIsPointInPath = CanvasRenderingContext2D.prototype.isPointInPath;
|
||||
CanvasRenderingContext2D.prototype.clip = function clip(...args) {
|
||||
if (args[0] instanceof Path2D) {
|
||||
const path = args[0];
|
||||
const fillRule2 = args[1] || "nonzero";
|
||||
buildPath(this, path.commands);
|
||||
return cClip.apply(this, [fillRule2]);
|
||||
}
|
||||
const fillRule = args[0] || "nonzero";
|
||||
return cClip.apply(this, [fillRule]);
|
||||
};
|
||||
CanvasRenderingContext2D.prototype.fill = function fill(...args) {
|
||||
if (args[0] instanceof Path2D) {
|
||||
const path = args[0];
|
||||
const fillRule2 = args[1] || "nonzero";
|
||||
buildPath(this, path.commands);
|
||||
return cFill.apply(this, [fillRule2]);
|
||||
}
|
||||
const fillRule = args[0] || "nonzero";
|
||||
return cFill.apply(this, [fillRule]);
|
||||
};
|
||||
CanvasRenderingContext2D.prototype.stroke = function stroke(path) {
|
||||
if (path) {
|
||||
buildPath(this, path.commands);
|
||||
}
|
||||
cStroke.apply(this);
|
||||
};
|
||||
CanvasRenderingContext2D.prototype.isPointInPath = function isPointInPath(...args) {
|
||||
if (args[0] instanceof Path2D) {
|
||||
const path = args[0];
|
||||
const x = args[1];
|
||||
const y = args[2];
|
||||
const fillRule = args[3] || "nonzero";
|
||||
buildPath(this, path.commands);
|
||||
return cIsPointInPath.apply(this, [x, y, fillRule]);
|
||||
}
|
||||
return cIsPointInPath.apply(this, args);
|
||||
};
|
||||
}
|
||||
function applyRoundRectToCanvasRenderingContext2D(CanvasRenderingContext2D) {
|
||||
if (CanvasRenderingContext2D && !CanvasRenderingContext2D.prototype.roundRect) {
|
||||
CanvasRenderingContext2D.prototype.roundRect = roundRect;
|
||||
}
|
||||
}
|
||||
function applyRoundRectToPath2D(P2D) {
|
||||
if (P2D && !P2D.prototype.roundRect) {
|
||||
P2D.prototype.roundRect = roundRect;
|
||||
}
|
||||
}
|
||||
export {
|
||||
Path2D,
|
||||
applyPath2DToCanvasRenderingContext,
|
||||
applyRoundRectToCanvasRenderingContext2D,
|
||||
applyRoundRectToPath2D,
|
||||
buildPath,
|
||||
parsePath,
|
||||
roundRect
|
||||
};
|
||||
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
||||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
||||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
||||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
||||
var ERR_INVALID_ARG_TYPE = require('../../../errors').codes.ERR_INVALID_ARG_TYPE;
|
||||
function from(Readable, iterable, opts) {
|
||||
var iterator;
|
||||
if (iterable && typeof iterable.next === 'function') {
|
||||
iterator = iterable;
|
||||
} else if (iterable && iterable[Symbol.asyncIterator]) iterator = iterable[Symbol.asyncIterator]();else if (iterable && iterable[Symbol.iterator]) iterator = iterable[Symbol.iterator]();else throw new ERR_INVALID_ARG_TYPE('iterable', ['Iterable'], iterable);
|
||||
var readable = new Readable(_objectSpread({
|
||||
objectMode: true
|
||||
}, opts));
|
||||
// Reading boolean to protect against _read
|
||||
// being called before last iteration completion.
|
||||
var reading = false;
|
||||
readable._read = function () {
|
||||
if (!reading) {
|
||||
reading = true;
|
||||
next();
|
||||
}
|
||||
};
|
||||
function next() {
|
||||
return _next2.apply(this, arguments);
|
||||
}
|
||||
function _next2() {
|
||||
_next2 = _asyncToGenerator(function* () {
|
||||
try {
|
||||
var _yield$iterator$next = yield iterator.next(),
|
||||
value = _yield$iterator$next.value,
|
||||
done = _yield$iterator$next.done;
|
||||
if (done) {
|
||||
readable.push(null);
|
||||
} else if (readable.push(yield value)) {
|
||||
next();
|
||||
} else {
|
||||
reading = false;
|
||||
}
|
||||
} catch (err) {
|
||||
readable.destroy(err);
|
||||
}
|
||||
});
|
||||
return _next2.apply(this, arguments);
|
||||
}
|
||||
return readable;
|
||||
}
|
||||
module.exports = from;
|
||||
@@ -0,0 +1,32 @@
|
||||
export interface StartSerializer {
|
||||
stringify: (obj: unknown) => string
|
||||
parse: (str: string) => unknown
|
||||
encode: <T>(value: T) => T
|
||||
decode: <T>(value: T) => T
|
||||
}
|
||||
|
||||
export type SerializerStringifyBy<T, TSerializable> = T extends TSerializable
|
||||
? T
|
||||
: T extends (...args: Array<any>) => any
|
||||
? 'Function is not serializable'
|
||||
: { [K in keyof T]: SerializerStringifyBy<T[K], TSerializable> }
|
||||
|
||||
export type SerializerParseBy<T, TSerializable> = T extends TSerializable
|
||||
? T
|
||||
: unknown extends SerializerExtensions['ReadableStream']
|
||||
? { [K in keyof T]: SerializerParseBy<T[K], TSerializable> }
|
||||
: T extends SerializerExtensions['ReadableStream']
|
||||
? ReadableStream
|
||||
: { [K in keyof T]: SerializerParseBy<T[K], TSerializable> }
|
||||
|
||||
export interface DefaultSerializerExtensions {
|
||||
ReadableStream: unknown
|
||||
}
|
||||
|
||||
export interface SerializerExtensions extends DefaultSerializerExtensions {}
|
||||
|
||||
export type Serializable = Date | undefined | Error | FormData | bigint
|
||||
|
||||
export type SerializerStringify<T> = SerializerStringifyBy<T, Serializable>
|
||||
|
||||
export type SerializerParse<T> = SerializerParseBy<T, Serializable>
|
||||
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.addDeprecatedGenerators = addDeprecatedGenerators;
|
||||
function addDeprecatedGenerators(PrinterClass) {
|
||||
{
|
||||
const deprecatedBabel7Generators = {
|
||||
Noop() {},
|
||||
TSExpressionWithTypeArguments(node) {
|
||||
this.print(node.expression);
|
||||
this.print(node.typeParameters);
|
||||
},
|
||||
DecimalLiteral(node) {
|
||||
const raw = this.getPossibleRaw(node);
|
||||
if (!this.format.minified && raw !== undefined) {
|
||||
this.word(raw);
|
||||
return;
|
||||
}
|
||||
this.word(node.value + "m");
|
||||
}
|
||||
};
|
||||
Object.assign(PrinterClass.prototype, deprecatedBabel7Generators);
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=deprecated.js.map
|
||||
Reference in New Issue
Block a user