update
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
Copyright (C) 2012-2017 by Ingvar Stepanyan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _classApplyDescriptorSet;
|
||||
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
||||
if (descriptor.set) {
|
||||
descriptor.set.call(receiver, value);
|
||||
} else {
|
||||
if (!descriptor.writable) {
|
||||
throw new TypeError("attempted to set read only private field");
|
||||
}
|
||||
descriptor.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=classApplyDescriptorSet.js.map
|
||||
@@ -0,0 +1,10 @@
|
||||
export interface ChunkMetadata {
|
||||
importedAssets: Set<string>
|
||||
importedCss: Set<string>
|
||||
}
|
||||
|
||||
declare module 'rollup' {
|
||||
export interface RenderedChunk {
|
||||
viteMetadata?: ChunkMetadata
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var name = process.argv[2] || '.';
|
||||
var property = process.argv[3] || 'version';
|
||||
if (name != '.') name = 'node_modules/' + name;
|
||||
var json = JSON.parse(fs.readFileSync(name + '/package.json', 'utf8'));
|
||||
console.log(json[property]);
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @fileoverview Define the cursor which ignores specified tokens.
|
||||
* @author Toru Nagashima
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const DecorativeCursor = require("./decorative-cursor");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exports
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The decorative cursor which ignores specified tokens.
|
||||
*/
|
||||
module.exports = class FilterCursor extends DecorativeCursor {
|
||||
/**
|
||||
* Initializes this cursor.
|
||||
* @param {Cursor} cursor The cursor to be decorated.
|
||||
* @param {Function} predicate The predicate function to decide tokens this cursor iterates.
|
||||
*/
|
||||
constructor(cursor, predicate) {
|
||||
super(cursor);
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
moveNext() {
|
||||
const predicate = this.predicate;
|
||||
|
||||
while (super.moveNext()) {
|
||||
if (predicate(this.current)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* @fileoverview require default case in switch statements
|
||||
* @author Aliaksei Shytkin
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const DEFAULT_COMMENT_PATTERN = /^no default$/iu;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
defaultOptions: [{}],
|
||||
|
||||
docs: {
|
||||
description: "Require `default` cases in `switch` statements",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/default-case",
|
||||
},
|
||||
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
commentPattern: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
|
||||
messages: {
|
||||
missingDefaultCase: "Expected a default case.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const [options] = context.options;
|
||||
const commentPattern = options.commentPattern
|
||||
? new RegExp(options.commentPattern, "u")
|
||||
: DEFAULT_COMMENT_PATTERN;
|
||||
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Shortcut to get last element of array
|
||||
* @param {*[]} collection Array
|
||||
* @returns {any} Last element
|
||||
*/
|
||||
function last(collection) {
|
||||
return collection.at(-1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
SwitchStatement(node) {
|
||||
if (!node.cases.length) {
|
||||
/*
|
||||
* skip check of empty switch because there is no easy way
|
||||
* to extract comments inside it now
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
const hasDefault = node.cases.some(v => v.test === null);
|
||||
|
||||
if (!hasDefault) {
|
||||
let comment;
|
||||
|
||||
const lastCase = last(node.cases);
|
||||
const comments = sourceCode.getCommentsAfter(lastCase);
|
||||
|
||||
if (comments.length) {
|
||||
comment = last(comments);
|
||||
}
|
||||
|
||||
if (
|
||||
!comment ||
|
||||
!commentPattern.test(comment.value.trim())
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "missingDefaultCase",
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* @fileoverview Main Espree file that converts Acorn into Esprima output.
|
||||
*
|
||||
* This file contains code from the following MIT-licensed projects:
|
||||
* 1. Acorn
|
||||
* 2. Babylon
|
||||
* 3. Babel-ESLint
|
||||
*
|
||||
* This file also contains code from Esprima, which is BSD licensed.
|
||||
*
|
||||
* Acorn is Copyright 2012-2015 Acorn Contributors (https://github.com/marijnh/acorn/blob/master/AUTHORS)
|
||||
* Babylon is Copyright 2014-2015 various contributors (https://github.com/babel/babel/blob/master/packages/babylon/AUTHORS)
|
||||
* Babel-ESLint is Copyright 2014-2015 Sebastian McKenzie <sebmck@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Esprima is Copyright (c) jQuery Foundation, Inc. and Contributors, All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
import * as acorn from "acorn";
|
||||
import jsx from "acorn-jsx";
|
||||
import espree from "./lib/espree.js";
|
||||
import espreeVersion from "./lib/version.js";
|
||||
import * as visitorKeys from "eslint-visitor-keys";
|
||||
import { getLatestEcmaVersion, getSupportedEcmaVersions } from "./lib/options.js";
|
||||
|
||||
|
||||
// To initialize lazily.
|
||||
const parsers = {
|
||||
_regular: null,
|
||||
_jsx: null,
|
||||
|
||||
get regular() {
|
||||
if (this._regular === null) {
|
||||
this._regular = acorn.Parser.extend(espree());
|
||||
}
|
||||
return this._regular;
|
||||
},
|
||||
|
||||
get jsx() {
|
||||
if (this._jsx === null) {
|
||||
this._jsx = acorn.Parser.extend(jsx(), espree());
|
||||
}
|
||||
return this._jsx;
|
||||
},
|
||||
|
||||
get(options) {
|
||||
const useJsx = Boolean(
|
||||
options &&
|
||||
options.ecmaFeatures &&
|
||||
options.ecmaFeatures.jsx
|
||||
);
|
||||
|
||||
return useJsx ? this.jsx : this.regular;
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tokenizer
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Tokenizes the given code.
|
||||
* @param {string} code The code to tokenize.
|
||||
* @param {Object} options Options defining how to tokenize.
|
||||
* @returns {Token[]} An array of tokens.
|
||||
* @throws {SyntaxError} If the input code is invalid.
|
||||
* @private
|
||||
*/
|
||||
export function tokenize(code, options) {
|
||||
const Parser = parsers.get(options);
|
||||
|
||||
// Ensure to collect tokens.
|
||||
if (!options || options.tokens !== true) {
|
||||
options = Object.assign({}, options, { tokens: true }); // eslint-disable-line no-param-reassign -- stylistic choice
|
||||
}
|
||||
|
||||
return new Parser(options, code).tokenize();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Parser
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parses the given code.
|
||||
* @param {string} code The code to tokenize.
|
||||
* @param {Object} options Options defining how to tokenize.
|
||||
* @returns {ASTNode} The "Program" AST node.
|
||||
* @throws {SyntaxError} If the input code is invalid.
|
||||
*/
|
||||
export function parse(code, options) {
|
||||
const Parser = parsers.get(options);
|
||||
|
||||
return new Parser(options, code).parse();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
export const version = espreeVersion;
|
||||
export const name = "espree";
|
||||
|
||||
/* istanbul ignore next */
|
||||
export const VisitorKeys = (function() {
|
||||
return visitorKeys.KEYS;
|
||||
}());
|
||||
|
||||
// Derive node types from VisitorKeys
|
||||
/* istanbul ignore next */
|
||||
export const Syntax = (function() {
|
||||
let key,
|
||||
types = {};
|
||||
|
||||
if (typeof Object.create === "function") {
|
||||
types = Object.create(null);
|
||||
}
|
||||
|
||||
for (key in VisitorKeys) {
|
||||
if (Object.hasOwn(VisitorKeys, key)) {
|
||||
types[key] = key;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof Object.freeze === "function") {
|
||||
Object.freeze(types);
|
||||
}
|
||||
|
||||
return types;
|
||||
}());
|
||||
|
||||
export const latestEcmaVersion = getLatestEcmaVersion();
|
||||
|
||||
export const supportedEcmaVersions = getSupportedEcmaVersions();
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* @version 1.4.0
|
||||
* @date 2015-10-26
|
||||
* @stability 3 - Stable
|
||||
* @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
|
||||
var naturalCompare = function(a, b) {
|
||||
var i, codeA
|
||||
, codeB = 1
|
||||
, posA = 0
|
||||
, posB = 0
|
||||
, alphabet = String.alphabet
|
||||
|
||||
function getCode(str, pos, code) {
|
||||
if (code) {
|
||||
for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
|
||||
return +str.slice(pos - 1, i)
|
||||
}
|
||||
code = alphabet && alphabet.indexOf(str.charAt(pos))
|
||||
return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
|
||||
: code < 46 ? 65 // -
|
||||
: code < 48 ? code - 1
|
||||
: code < 58 ? code + 18 // 0-9
|
||||
: code < 65 ? code - 11
|
||||
: code < 91 ? code + 11 // A-Z
|
||||
: code < 97 ? code - 37
|
||||
: code < 123 ? code + 5 // a-z
|
||||
: code - 63
|
||||
}
|
||||
|
||||
|
||||
if ((a+="") != (b+="")) for (;codeB;) {
|
||||
codeA = getCode(a, posA++)
|
||||
codeB = getCode(b, posB++)
|
||||
|
||||
if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
|
||||
codeA = getCode(a, posA, posA)
|
||||
codeB = getCode(b, posB, posA = i)
|
||||
posB = i
|
||||
}
|
||||
|
||||
if (codeA != codeB) return (codeA < codeB) ? -1 : 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
try {
|
||||
module.exports = naturalCompare;
|
||||
} catch (e) {
|
||||
String.naturalCompare = naturalCompare;
|
||||
}
|
||||
@@ -0,0 +1,622 @@
|
||||
/**
|
||||
* @fileoverview Rule to disallow use of the `RegExp` constructor in favor of regular expression literals
|
||||
* @author Milos Djermanovic
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
const {
|
||||
CALL,
|
||||
CONSTRUCT,
|
||||
ReferenceTracker,
|
||||
findVariable,
|
||||
} = require("@eslint-community/eslint-utils");
|
||||
const {
|
||||
RegExpValidator,
|
||||
visitRegExpAST,
|
||||
RegExpParser,
|
||||
} = require("@eslint-community/regexpp");
|
||||
const { canTokensBeAdjacent } = require("./utils/ast-utils");
|
||||
const { REGEXPP_LATEST_ECMA_VERSION } = require("./utils/regular-expressions");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determines whether the given node is a string literal.
|
||||
* @param {ASTNode} node Node to check.
|
||||
* @returns {boolean} True if the node is a string literal.
|
||||
*/
|
||||
function isStringLiteral(node) {
|
||||
return node.type === "Literal" && typeof node.value === "string";
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given node is a regex literal.
|
||||
* @param {ASTNode} node Node to check.
|
||||
* @returns {boolean} True if the node is a regex literal.
|
||||
*/
|
||||
function isRegexLiteral(node) {
|
||||
return node.type === "Literal" && Object.hasOwn(node, "regex");
|
||||
}
|
||||
|
||||
const validPrecedingTokens = new Set([
|
||||
"(",
|
||||
";",
|
||||
"[",
|
||||
",",
|
||||
"=",
|
||||
"+",
|
||||
"*",
|
||||
"-",
|
||||
"?",
|
||||
"~",
|
||||
"%",
|
||||
"**",
|
||||
"!",
|
||||
"typeof",
|
||||
"instanceof",
|
||||
"&&",
|
||||
"||",
|
||||
"??",
|
||||
"return",
|
||||
"...",
|
||||
"delete",
|
||||
"void",
|
||||
"in",
|
||||
"<",
|
||||
">",
|
||||
"<=",
|
||||
">=",
|
||||
"==",
|
||||
"===",
|
||||
"!=",
|
||||
"!==",
|
||||
"<<",
|
||||
">>",
|
||||
">>>",
|
||||
"&",
|
||||
"|",
|
||||
"^",
|
||||
":",
|
||||
"{",
|
||||
"=>",
|
||||
"*=",
|
||||
"<<=",
|
||||
">>=",
|
||||
">>>=",
|
||||
"^=",
|
||||
"|=",
|
||||
"&=",
|
||||
"??=",
|
||||
"||=",
|
||||
"&&=",
|
||||
"**=",
|
||||
"+=",
|
||||
"-=",
|
||||
"/=",
|
||||
"%=",
|
||||
"/",
|
||||
"do",
|
||||
"break",
|
||||
"continue",
|
||||
"debugger",
|
||||
"case",
|
||||
"throw",
|
||||
]);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
defaultOptions: [
|
||||
{
|
||||
disallowRedundantWrapping: false,
|
||||
},
|
||||
],
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Disallow use of the `RegExp` constructor in favor of regular expression literals",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/prefer-regex-literals",
|
||||
},
|
||||
|
||||
hasSuggestions: true,
|
||||
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
disallowRedundantWrapping: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
|
||||
messages: {
|
||||
unexpectedRegExp:
|
||||
"Use a regular expression literal instead of the 'RegExp' constructor.",
|
||||
replaceWithLiteral:
|
||||
"Replace with an equivalent regular expression literal.",
|
||||
replaceWithLiteralAndFlags:
|
||||
"Replace with an equivalent regular expression literal with flags '{{ flags }}'.",
|
||||
replaceWithIntendedLiteralAndFlags:
|
||||
"Replace with a regular expression literal with flags '{{ flags }}'.",
|
||||
unexpectedRedundantRegExp:
|
||||
"Regular expression literal is unnecessarily wrapped within a 'RegExp' constructor.",
|
||||
unexpectedRedundantRegExpWithFlags:
|
||||
"Use regular expression literal with flags instead of the 'RegExp' constructor.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const [{ disallowRedundantWrapping }] = context.options;
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
/**
|
||||
* Determines whether the given identifier node is a reference to a global variable.
|
||||
* @param {ASTNode} node `Identifier` node to check.
|
||||
* @returns {boolean} True if the identifier is a reference to a global variable.
|
||||
*/
|
||||
function isGlobalReference(node) {
|
||||
const scope = sourceCode.getScope(node);
|
||||
const variable = findVariable(scope, node);
|
||||
|
||||
return (
|
||||
variable !== null &&
|
||||
variable.scope.type === "global" &&
|
||||
variable.defs.length === 0
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given node is a String.raw`` tagged template expression
|
||||
* with a static template literal.
|
||||
* @param {ASTNode} node Node to check.
|
||||
* @returns {boolean} True if the node is String.raw`` with a static template.
|
||||
*/
|
||||
function isStringRawTaggedStaticTemplateLiteral(node) {
|
||||
return (
|
||||
node.type === "TaggedTemplateExpression" &&
|
||||
astUtils.isSpecificMemberAccess(node.tag, "String", "raw") &&
|
||||
isGlobalReference(
|
||||
astUtils.skipChainExpression(node.tag).object,
|
||||
) &&
|
||||
astUtils.isStaticTemplateLiteral(node.quasi)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of a string
|
||||
* @param {ASTNode} node The node to get the string of.
|
||||
* @returns {string|null} The value of the node.
|
||||
*/
|
||||
function getStringValue(node) {
|
||||
if (isStringLiteral(node)) {
|
||||
return node.value;
|
||||
}
|
||||
|
||||
if (astUtils.isStaticTemplateLiteral(node)) {
|
||||
return node.quasis[0].value.cooked;
|
||||
}
|
||||
|
||||
if (isStringRawTaggedStaticTemplateLiteral(node)) {
|
||||
return node.quasi.quasis[0].value.raw;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given node is considered to be a static string by the logic of this rule.
|
||||
* @param {ASTNode} node Node to check.
|
||||
* @returns {boolean} True if the node is a static string.
|
||||
*/
|
||||
function isStaticString(node) {
|
||||
return (
|
||||
isStringLiteral(node) ||
|
||||
astUtils.isStaticTemplateLiteral(node) ||
|
||||
isStringRawTaggedStaticTemplateLiteral(node)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the relevant arguments of the given are all static string literals.
|
||||
* @param {ASTNode} node Node to check.
|
||||
* @returns {boolean} True if all arguments are static strings.
|
||||
*/
|
||||
function hasOnlyStaticStringArguments(node) {
|
||||
const args = node.arguments;
|
||||
|
||||
if (
|
||||
(args.length === 1 || args.length === 2) &&
|
||||
args.every(isStaticString)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the arguments of the given node indicate that a regex literal is unnecessarily wrapped.
|
||||
* @param {ASTNode} node Node to check.
|
||||
* @returns {boolean} True if the node already contains a regex literal argument.
|
||||
*/
|
||||
function isUnnecessarilyWrappedRegexLiteral(node) {
|
||||
const args = node.arguments;
|
||||
|
||||
if (args.length === 1 && isRegexLiteral(args[0])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
args.length === 2 &&
|
||||
isRegexLiteral(args[0]) &&
|
||||
isStaticString(args[1])
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ecmaVersion compatible for regexpp.
|
||||
* @param {number} ecmaVersion The ecmaVersion to convert.
|
||||
* @returns {import("@eslint-community/regexpp/ecma-versions").EcmaVersion} The resulting ecmaVersion compatible for regexpp.
|
||||
*/
|
||||
function getRegexppEcmaVersion(ecmaVersion) {
|
||||
if (ecmaVersion <= 5) {
|
||||
return 5;
|
||||
}
|
||||
return Math.min(ecmaVersion, REGEXPP_LATEST_ECMA_VERSION);
|
||||
}
|
||||
|
||||
const regexppEcmaVersion = getRegexppEcmaVersion(
|
||||
context.languageOptions.ecmaVersion,
|
||||
);
|
||||
|
||||
/**
|
||||
* Makes a character escaped or else returns null.
|
||||
* @param {string} character The character to escape.
|
||||
* @returns {string} The resulting escaped character.
|
||||
*/
|
||||
function resolveEscapes(character) {
|
||||
switch (character) {
|
||||
case "\n":
|
||||
case "\\\n":
|
||||
return "\\n";
|
||||
|
||||
case "\r":
|
||||
case "\\\r":
|
||||
return "\\r";
|
||||
|
||||
case "\t":
|
||||
case "\\\t":
|
||||
return "\\t";
|
||||
|
||||
case "\v":
|
||||
case "\\\v":
|
||||
return "\\v";
|
||||
|
||||
case "\f":
|
||||
case "\\\f":
|
||||
return "\\f";
|
||||
|
||||
case "/":
|
||||
return "\\/";
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given regex and flags are valid for the ecma version or not.
|
||||
* @param {string} pattern The regex pattern to check.
|
||||
* @param {string | undefined} flags The regex flags to check.
|
||||
* @returns {boolean} True if the given regex pattern and flags are valid for the ecma version.
|
||||
*/
|
||||
function isValidRegexForEcmaVersion(pattern, flags) {
|
||||
const validator = new RegExpValidator({
|
||||
ecmaVersion: regexppEcmaVersion,
|
||||
});
|
||||
|
||||
try {
|
||||
validator.validatePattern(pattern, 0, pattern.length, {
|
||||
unicode: flags ? flags.includes("u") : false,
|
||||
unicodeSets: flags ? flags.includes("v") : false,
|
||||
});
|
||||
if (flags) {
|
||||
validator.validateFlags(flags);
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether two given regex flags contain the same flags or not.
|
||||
* @param {string} flagsA The regex flags.
|
||||
* @param {string} flagsB The regex flags.
|
||||
* @returns {boolean} True if two regex flags contain same flags.
|
||||
*/
|
||||
function areFlagsEqual(flagsA, flagsB) {
|
||||
return [...flagsA].sort().join("") === [...flagsB].sort().join("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges two regex flags.
|
||||
* @param {string} flagsA The regex flags.
|
||||
* @param {string} flagsB The regex flags.
|
||||
* @returns {string} The merged regex flags.
|
||||
*/
|
||||
function mergeRegexFlags(flagsA, flagsB) {
|
||||
const flagsSet = new Set([...flagsA, ...flagsB]);
|
||||
|
||||
return [...flagsSet].join("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a give node can be fixed to the given regex pattern and flags.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @param {string} pattern The regex pattern to check.
|
||||
* @param {string} flags The regex flags
|
||||
* @returns {boolean} True if a node can be fixed to the given regex pattern and flags.
|
||||
*/
|
||||
function canFixTo(node, pattern, flags) {
|
||||
const tokenBefore = sourceCode.getTokenBefore(node);
|
||||
|
||||
return (
|
||||
sourceCode.getCommentsInside(node).length === 0 &&
|
||||
(!tokenBefore || validPrecedingTokens.has(tokenBefore.value)) &&
|
||||
isValidRegexForEcmaVersion(pattern, flags)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a safe output code considering the before and after tokens.
|
||||
* @param {ASTNode} node The regex node.
|
||||
* @param {string} newRegExpValue The new regex expression value.
|
||||
* @returns {string} The output code.
|
||||
*/
|
||||
function getSafeOutput(node, newRegExpValue) {
|
||||
const tokenBefore = sourceCode.getTokenBefore(node);
|
||||
const tokenAfter = sourceCode.getTokenAfter(node);
|
||||
|
||||
return (
|
||||
(tokenBefore &&
|
||||
!canTokensBeAdjacent(tokenBefore, newRegExpValue) &&
|
||||
tokenBefore.range[1] === node.range[0]
|
||||
? " "
|
||||
: "") +
|
||||
newRegExpValue +
|
||||
(tokenAfter &&
|
||||
!canTokensBeAdjacent(newRegExpValue, tokenAfter) &&
|
||||
node.range[1] === tokenAfter.range[0]
|
||||
? " "
|
||||
: "")
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
Program(node) {
|
||||
const scope = sourceCode.getScope(node);
|
||||
const tracker = new ReferenceTracker(scope);
|
||||
const traceMap = {
|
||||
RegExp: {
|
||||
[CALL]: true,
|
||||
[CONSTRUCT]: true,
|
||||
},
|
||||
};
|
||||
|
||||
for (const { node: refNode } of tracker.iterateGlobalReferences(
|
||||
traceMap,
|
||||
)) {
|
||||
if (
|
||||
disallowRedundantWrapping &&
|
||||
isUnnecessarilyWrappedRegexLiteral(refNode)
|
||||
) {
|
||||
const regexNode = refNode.arguments[0];
|
||||
|
||||
if (refNode.arguments.length === 2) {
|
||||
const suggests = [];
|
||||
|
||||
const argFlags =
|
||||
getStringValue(refNode.arguments[1]) || "";
|
||||
|
||||
if (
|
||||
canFixTo(
|
||||
refNode,
|
||||
regexNode.regex.pattern,
|
||||
argFlags,
|
||||
)
|
||||
) {
|
||||
suggests.push({
|
||||
messageId: "replaceWithLiteralAndFlags",
|
||||
pattern: regexNode.regex.pattern,
|
||||
flags: argFlags,
|
||||
});
|
||||
}
|
||||
|
||||
const literalFlags = regexNode.regex.flags || "";
|
||||
const mergedFlags = mergeRegexFlags(
|
||||
literalFlags,
|
||||
argFlags,
|
||||
);
|
||||
|
||||
if (
|
||||
!areFlagsEqual(mergedFlags, argFlags) &&
|
||||
canFixTo(
|
||||
refNode,
|
||||
regexNode.regex.pattern,
|
||||
mergedFlags,
|
||||
)
|
||||
) {
|
||||
suggests.push({
|
||||
messageId:
|
||||
"replaceWithIntendedLiteralAndFlags",
|
||||
pattern: regexNode.regex.pattern,
|
||||
flags: mergedFlags,
|
||||
});
|
||||
}
|
||||
|
||||
context.report({
|
||||
node: refNode,
|
||||
messageId: "unexpectedRedundantRegExpWithFlags",
|
||||
suggest: suggests.map(
|
||||
({ flags, pattern, messageId }) => ({
|
||||
messageId,
|
||||
data: {
|
||||
flags,
|
||||
},
|
||||
fix(fixer) {
|
||||
return fixer.replaceText(
|
||||
refNode,
|
||||
getSafeOutput(
|
||||
refNode,
|
||||
`/${pattern}/${flags}`,
|
||||
),
|
||||
);
|
||||
},
|
||||
}),
|
||||
),
|
||||
});
|
||||
} else {
|
||||
const outputs = [];
|
||||
|
||||
if (
|
||||
canFixTo(
|
||||
refNode,
|
||||
regexNode.regex.pattern,
|
||||
regexNode.regex.flags,
|
||||
)
|
||||
) {
|
||||
outputs.push(sourceCode.getText(regexNode));
|
||||
}
|
||||
|
||||
context.report({
|
||||
node: refNode,
|
||||
messageId: "unexpectedRedundantRegExp",
|
||||
suggest: outputs.map(output => ({
|
||||
messageId: "replaceWithLiteral",
|
||||
fix(fixer) {
|
||||
return fixer.replaceText(
|
||||
refNode,
|
||||
getSafeOutput(refNode, output),
|
||||
);
|
||||
},
|
||||
})),
|
||||
});
|
||||
}
|
||||
} else if (hasOnlyStaticStringArguments(refNode)) {
|
||||
let regexContent = getStringValue(refNode.arguments[0]);
|
||||
let noFix = false;
|
||||
let flags;
|
||||
|
||||
if (refNode.arguments[1]) {
|
||||
flags = getStringValue(refNode.arguments[1]);
|
||||
}
|
||||
|
||||
if (!canFixTo(refNode, regexContent, flags)) {
|
||||
noFix = true;
|
||||
}
|
||||
|
||||
if (
|
||||
!/^[-a-zA-Z0-9\\[\](){} \t\r\n\v\f!@#$%^&*+^_=/~`.><?,'"|:;]*$/u.test(
|
||||
regexContent,
|
||||
)
|
||||
) {
|
||||
noFix = true;
|
||||
}
|
||||
|
||||
if (regexContent && !noFix) {
|
||||
let charIncrease = 0;
|
||||
|
||||
const ast = new RegExpParser({
|
||||
ecmaVersion: regexppEcmaVersion,
|
||||
}).parsePattern(
|
||||
regexContent,
|
||||
0,
|
||||
regexContent.length,
|
||||
{
|
||||
unicode: flags
|
||||
? flags.includes("u")
|
||||
: false,
|
||||
unicodeSets: flags
|
||||
? flags.includes("v")
|
||||
: false,
|
||||
},
|
||||
);
|
||||
|
||||
visitRegExpAST(ast, {
|
||||
onCharacterEnter(characterNode) {
|
||||
const escaped = resolveEscapes(
|
||||
characterNode.raw,
|
||||
);
|
||||
|
||||
if (escaped) {
|
||||
regexContent =
|
||||
regexContent.slice(
|
||||
0,
|
||||
characterNode.start +
|
||||
charIncrease,
|
||||
) +
|
||||
escaped +
|
||||
regexContent.slice(
|
||||
characterNode.end +
|
||||
charIncrease,
|
||||
);
|
||||
|
||||
if (characterNode.raw.length === 1) {
|
||||
charIncrease += 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const newRegExpValue = `/${regexContent || "(?:)"}/${flags || ""}`;
|
||||
|
||||
context.report({
|
||||
node: refNode,
|
||||
messageId: "unexpectedRegExp",
|
||||
suggest: noFix
|
||||
? []
|
||||
: [
|
||||
{
|
||||
messageId: "replaceWithLiteral",
|
||||
fix(fixer) {
|
||||
return fixer.replaceText(
|
||||
refNode,
|
||||
getSafeOutput(
|
||||
refNode,
|
||||
newRegExpValue,
|
||||
),
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
var stringify = require('../');
|
||||
var obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
|
||||
console.log(stringify(obj));
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "backend/Backend.h"
|
||||
#include <napi.h>
|
||||
|
||||
class Backends : public Napi::ObjectWrap<Backends> {
|
||||
public:
|
||||
static void Initialize(Napi::Env env, Napi::Object exports);
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
# esbuild
|
||||
|
||||
This is the Linux ARM 64-bit binary for esbuild, a JavaScript bundler and minifier. See https://github.com/evanw/esbuild for details.
|
||||
@@ -0,0 +1,83 @@
|
||||
# json-schema-traverse
|
||||
Traverse JSON Schema passing each schema object to callback
|
||||
|
||||
[](https://travis-ci.org/epoberezkin/json-schema-traverse)
|
||||
[](https://www.npmjs.com/package/json-schema-traverse)
|
||||
[](https://coveralls.io/github/epoberezkin/json-schema-traverse?branch=master)
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm install json-schema-traverse
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
const traverse = require('json-schema-traverse');
|
||||
const schema = {
|
||||
properties: {
|
||||
foo: {type: 'string'},
|
||||
bar: {type: 'integer'}
|
||||
}
|
||||
};
|
||||
|
||||
traverse(schema, {cb});
|
||||
// cb is called 3 times with:
|
||||
// 1. root schema
|
||||
// 2. {type: 'string'}
|
||||
// 3. {type: 'integer'}
|
||||
|
||||
// Or:
|
||||
|
||||
traverse(schema, {cb: {pre, post}});
|
||||
// pre is called 3 times with:
|
||||
// 1. root schema
|
||||
// 2. {type: 'string'}
|
||||
// 3. {type: 'integer'}
|
||||
//
|
||||
// post is called 3 times with:
|
||||
// 1. {type: 'string'}
|
||||
// 2. {type: 'integer'}
|
||||
// 3. root schema
|
||||
|
||||
```
|
||||
|
||||
Callback function `cb` is called for each schema object (not including draft-06 boolean schemas), including the root schema, in pre-order traversal. Schema references ($ref) are not resolved, they are passed as is. Alternatively, you can pass a `{pre, post}` object as `cb`, and then `pre` will be called before traversing child elements, and `post` will be called after all child elements have been traversed.
|
||||
|
||||
Callback is passed these parameters:
|
||||
|
||||
- _schema_: the current schema object
|
||||
- _JSON pointer_: from the root schema to the current schema object
|
||||
- _root schema_: the schema passed to `traverse` object
|
||||
- _parent JSON pointer_: from the root schema to the parent schema object (see below)
|
||||
- _parent keyword_: the keyword inside which this schema appears (e.g. `properties`, `anyOf`, etc.)
|
||||
- _parent schema_: not necessarily parent object/array; in the example above the parent schema for `{type: 'string'}` is the root schema
|
||||
- _index/property_: index or property name in the array/object containing multiple schemas; in the example above for `{type: 'string'}` the property name is `'foo'`
|
||||
|
||||
|
||||
## Traverse objects in all unknown keywords
|
||||
|
||||
```javascript
|
||||
const traverse = require('json-schema-traverse');
|
||||
const schema = {
|
||||
mySchema: {
|
||||
minimum: 1,
|
||||
maximum: 2
|
||||
}
|
||||
};
|
||||
|
||||
traverse(schema, {allKeys: true, cb});
|
||||
// cb is called 2 times with:
|
||||
// 1. root schema
|
||||
// 2. mySchema
|
||||
```
|
||||
|
||||
Without option `allKeys: true` callback will be called only with root schema.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/epoberezkin/json-schema-traverse/blob/master/LICENSE)
|
||||
@@ -0,0 +1,60 @@
|
||||
# `react-dom`
|
||||
|
||||
This package serves as the entry point to the DOM and server renderers for React. It is intended to be paired with the generic React package, which is shipped as `react` to npm.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install react react-dom
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### In the browser
|
||||
|
||||
```js
|
||||
import { createRoot } from 'react-dom/client';
|
||||
|
||||
function App() {
|
||||
return <div>Hello World</div>;
|
||||
}
|
||||
|
||||
const root = createRoot(document.getElementById('root'));
|
||||
root.render(<App />);
|
||||
```
|
||||
|
||||
### On the server
|
||||
|
||||
```js
|
||||
import { renderToPipeableStream } from 'react-dom/server';
|
||||
|
||||
function App() {
|
||||
return <div>Hello World</div>;
|
||||
}
|
||||
|
||||
function handleRequest(res) {
|
||||
// ... in your server handler ...
|
||||
const stream = renderToPipeableStream(<App />, {
|
||||
onShellReady() {
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-type', 'text/html');
|
||||
stream.pipe(res);
|
||||
},
|
||||
// ...
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `react-dom`
|
||||
|
||||
See https://react.dev/reference/react-dom
|
||||
|
||||
### `react-dom/client`
|
||||
|
||||
See https://react.dev/reference/react-dom/client
|
||||
|
||||
### `react-dom/server`
|
||||
|
||||
See https://react.dev/reference/react-dom/server
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Parses a JSON5 string, constructing the JavaScript value or object described
|
||||
* by the string.
|
||||
* @template T The type of the return value.
|
||||
* @param text The string to parse as JSON5.
|
||||
* @param reviver A function that prescribes how the value originally produced
|
||||
* by parsing is transformed before being returned.
|
||||
* @returns The JavaScript value converted from the JSON5 string.
|
||||
*/
|
||||
declare function parse<T = any>(
|
||||
text: string,
|
||||
reviver?: ((this: any, key: string, value: any) => any) | null,
|
||||
): T
|
||||
|
||||
export = parse
|
||||
@@ -0,0 +1,54 @@
|
||||
# end-of-stream
|
||||
|
||||
A node module that calls a callback when a readable/writable/duplex stream has completed or failed.
|
||||
|
||||
npm install end-of-stream
|
||||
|
||||
[](https://travis-ci.org/mafintosh/end-of-stream)
|
||||
|
||||
## Usage
|
||||
|
||||
Simply pass a stream and a callback to the `eos`.
|
||||
Both legacy streams, streams2 and stream3 are supported.
|
||||
|
||||
``` js
|
||||
var eos = require('end-of-stream');
|
||||
|
||||
eos(readableStream, function(err) {
|
||||
// this will be set to the stream instance
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has ended', this === readableStream);
|
||||
});
|
||||
|
||||
eos(writableStream, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has finished', this === writableStream);
|
||||
});
|
||||
|
||||
eos(duplexStream, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has ended and finished', this === duplexStream);
|
||||
});
|
||||
|
||||
eos(duplexStream, {readable:false}, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has finished but might still be readable');
|
||||
});
|
||||
|
||||
eos(duplexStream, {writable:false}, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has ended but might still be writable');
|
||||
});
|
||||
|
||||
eos(readableStream, {error:false}, function(err) {
|
||||
// do not treat emit('error', err) as a end-of-stream
|
||||
});
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Related
|
||||
|
||||
`end-of-stream` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
|
||||
Reference in New Issue
Block a user