mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
tools: update eslint to 8.21.0
PR-URL: https://github.com/nodejs/node/pull/44162 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Feng Yu <F3n67u@outlook.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
1 parent
fecec4d3ba
commit
873941a43e
1074 files changed
+18527
-3105
No files matched your search
+16
-7
@@ -15,7 +15,6 @@ const Rules = require("../rules");
|
||||
// Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
exports.defaultConfig = [
|
||||
{
|
||||
plugins: {
|
||||
@@ -41,21 +40,31 @@ exports.defaultConfig = [
|
||||
})
|
||||
}
|
||||
},
|
||||
ignores: [
|
||||
"**/node_modules/**",
|
||||
".git/**"
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
ecmaVersion: "latest",
|
||||
parser: "@/espree",
|
||||
parserOptions: {}
|
||||
}
|
||||
},
|
||||
|
||||
// default ignores are listed here
|
||||
{
|
||||
ignores: [
|
||||
"**/node_modules/**",
|
||||
".git/**"
|
||||
]
|
||||
},
|
||||
|
||||
// intentionally empty config to ensure these files are globbed by default
|
||||
{
|
||||
files: ["**/*.js", "**/*.mjs"]
|
||||
},
|
||||
{
|
||||
files: ["**/*.cjs"],
|
||||
languageOptions: {
|
||||
sourceType: "commonjs"
|
||||
sourceType: "commonjs",
|
||||
ecmaVersion: "latest"
|
||||
}
|
||||
}
|
||||
];
|
||||
+41
-2
@@ -36,6 +36,8 @@ function splitPluginIdentifier(identifier) {
|
||||
};
|
||||
}
|
||||
|
||||
const originalBaseConfig = Symbol("originalBaseConfig");
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -48,10 +50,14 @@ class FlatConfigArray extends ConfigArray {
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* @param {*[]} configs An array of configuration information.
|
||||
* @param {{basePath: string, baseConfig: FlatConfig}} options The options
|
||||
* @param {{basePath: string, shouldIgnore: boolean, baseConfig: FlatConfig}} options The options
|
||||
* to use for the config array instance.
|
||||
*/
|
||||
constructor(configs, { basePath, baseConfig = defaultConfig } = {}) {
|
||||
constructor(configs, {
|
||||
basePath,
|
||||
shouldIgnore = true,
|
||||
baseConfig = defaultConfig
|
||||
} = {}) {
|
||||
super(configs, {
|
||||
basePath,
|
||||
schema: flatConfigSchema
|
||||
@@ -62,6 +68,22 @@ class FlatConfigArray extends ConfigArray {
|
||||
} else {
|
||||
this.unshift(baseConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* The baes config used to build the config array.
|
||||
* @type {Array<FlatConfig>}
|
||||
*/
|
||||
this[originalBaseConfig] = baseConfig;
|
||||
Object.defineProperty(this, originalBaseConfig, { writable: false });
|
||||
|
||||
/**
|
||||
* Determines if `ignores` fields should be honored.
|
||||
* If true, then all `ignores` fields are honored.
|
||||
* if false, then only `ignores` fields in the baseConfig are honored.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.shouldIgnore = shouldIgnore;
|
||||
Object.defineProperty(this, "shouldIgnore", { writable: false });
|
||||
}
|
||||
|
||||
/* eslint-disable class-methods-use-this -- Desired as instance method */
|
||||
@@ -87,6 +109,23 @@ class FlatConfigArray extends ConfigArray {
|
||||
return require("../../conf/eslint-all");
|
||||
}
|
||||
|
||||
/*
|
||||
* If `shouldIgnore` is false, we remove any ignore patterns specified
|
||||
* in the config so long as it's not a default config and it doesn't
|
||||
* have a `files` entry.
|
||||
*/
|
||||
if (
|
||||
!this.shouldIgnore &&
|
||||
!this[originalBaseConfig].includes(config) &&
|
||||
config.ignores &&
|
||||
!config.files
|
||||
) {
|
||||
/* eslint-disable-next-line no-unused-vars -- need to strip off other keys */
|
||||
const { ignores, ...otherKeys } = config;
|
||||
|
||||
return otherKeys;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
+9
-1
@@ -20,7 +20,14 @@ function parseRuleId(ruleId) {
|
||||
|
||||
// distinguish between core rules and plugin rules
|
||||
if (ruleId.includes("/")) {
|
||||
pluginName = ruleId.slice(0, ruleId.lastIndexOf("/"));
|
||||
|
||||
// mimic scoped npm packages
|
||||
if (ruleId.startsWith("@")) {
|
||||
pluginName = ruleId.slice(0, ruleId.lastIndexOf("/"));
|
||||
} else {
|
||||
pluginName = ruleId.slice(0, ruleId.indexOf("/"));
|
||||
}
|
||||
|
||||
ruleName = ruleId.slice(pluginName.length + 1);
|
||||
} else {
|
||||
pluginName = "@";
|
||||
@@ -47,6 +54,7 @@ function getRuleFromConfig(ruleId, config) {
|
||||
const plugin = config.plugins && config.plugins[pluginName];
|
||||
let rule = plugin && plugin.rules && plugin.rules[ruleName];
|
||||
|
||||
|
||||
// normalize function rules into objects
|
||||
if (rule && typeof rule === "function") {
|
||||
rule = {
|
||||
|
||||
+621
@@ -0,0 +1,621 @@
|
||||
/**
|
||||
* @fileoverview Helper functions for ESLint class
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const fsp = fs.promises;
|
||||
const isGlob = require("is-glob");
|
||||
const globby = require("globby");
|
||||
const hash = require("../cli-engine/hash");
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Errors
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The error type when no files match a glob.
|
||||
*/
|
||||
class NoFilesFoundError extends Error {
|
||||
|
||||
/**
|
||||
* @param {string} pattern The glob pattern which was not found.
|
||||
* @param {boolean} globEnabled If `false` then the pattern was a glob pattern, but glob was disabled.
|
||||
*/
|
||||
constructor(pattern, globEnabled) {
|
||||
super(`No files matching '${pattern}' were found${!globEnabled ? " (glob was disabled)" : ""}.`);
|
||||
this.messageTemplate = "file-not-found";
|
||||
this.messageData = { pattern, globDisabled: !globEnabled };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The error type when there are files matched by a glob, but all of them have been ignored.
|
||||
*/
|
||||
class AllFilesIgnoredError extends Error {
|
||||
|
||||
/**
|
||||
* @param {string} pattern The glob pattern which was not found.
|
||||
*/
|
||||
constructor(pattern) {
|
||||
super(`All files matched by '${pattern}' are ignored.`);
|
||||
this.messageTemplate = "all-files-ignored";
|
||||
this.messageData = { pattern };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// General Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Check if a given value is a non-empty string or not.
|
||||
* @param {any} x The value to check.
|
||||
* @returns {boolean} `true` if `x` is a non-empty string.
|
||||
*/
|
||||
function isNonEmptyString(x) {
|
||||
return typeof x === "string" && x.trim() !== "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given value is an array of non-empty stringss or not.
|
||||
* @param {any} x The value to check.
|
||||
* @returns {boolean} `true` if `x` is an array of non-empty stringss.
|
||||
*/
|
||||
function isArrayOfNonEmptyString(x) {
|
||||
return Array.isArray(x) && x.every(isNonEmptyString);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// File-related Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Normalizes slashes in a file pattern to posix-style.
|
||||
* @param {string} pattern The pattern to replace slashes in.
|
||||
* @returns {string} The pattern with slashes normalized.
|
||||
*/
|
||||
function normalizeToPosix(pattern) {
|
||||
return pattern.replace(/\\/gu, "/");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is a glob pattern or not.
|
||||
* @param {string} pattern A glob pattern.
|
||||
* @returns {boolean} `true` if the string is a glob pattern.
|
||||
*/
|
||||
function isGlobPattern(pattern) {
|
||||
return isGlob(path.sep === "\\" ? normalizeToPosix(pattern) : pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all files matching the options specified.
|
||||
* @param {Object} args The arguments objects.
|
||||
* @param {Array<string>} args.patterns An array of glob patterns.
|
||||
* @param {boolean} args.globInputPaths true to interpret glob patterns,
|
||||
* false to not interpret glob patterns.
|
||||
* @param {string} args.cwd The current working directory to find from.
|
||||
* @param {FlatConfigArray} args.configs The configs for the current run.
|
||||
* @returns {Promise<Array<string>>} The fully resolved file paths.
|
||||
* @throws {AllFilesIgnoredError} If there are no results due to an ignore pattern.
|
||||
* @throws {NoFilesFoundError} If no files matched the given patterns.
|
||||
*/
|
||||
async function findFiles({
|
||||
patterns,
|
||||
globInputPaths,
|
||||
cwd,
|
||||
configs
|
||||
}) {
|
||||
|
||||
const results = [];
|
||||
const globbyPatterns = [];
|
||||
const missingPatterns = [];
|
||||
|
||||
// check to see if we have explicit files and directories
|
||||
const filePaths = patterns.map(filePath => path.resolve(cwd, filePath));
|
||||
const stats = await Promise.all(
|
||||
filePaths.map(
|
||||
filePath => fsp.stat(filePath).catch(() => {})
|
||||
)
|
||||
);
|
||||
|
||||
stats.forEach((stat, index) => {
|
||||
|
||||
const filePath = filePaths[index];
|
||||
const pattern = patterns[index];
|
||||
|
||||
if (stat) {
|
||||
|
||||
// files are added directly to the list
|
||||
if (stat.isFile()) {
|
||||
results.push({
|
||||
filePath,
|
||||
ignored: configs.isIgnored(filePath)
|
||||
});
|
||||
}
|
||||
|
||||
// directories need extensions attached
|
||||
if (stat.isDirectory()) {
|
||||
|
||||
// filePatterns are all relative to cwd
|
||||
const filePatterns = configs.files
|
||||
.filter(filePattern => {
|
||||
|
||||
// can only do this for strings, not functions
|
||||
if (typeof filePattern !== "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// patterns ending with * are not used for file search
|
||||
if (filePattern.endsWith("*")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// not sure how to handle negated patterns yet
|
||||
if (filePattern.startsWith("!")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if the pattern would be inside the cwd or not
|
||||
const fullFilePattern = path.join(cwd, filePattern);
|
||||
const relativeFilePattern = path.relative(configs.basePath, fullFilePattern);
|
||||
|
||||
return !relativeFilePattern.startsWith("..");
|
||||
})
|
||||
.map(filePattern => {
|
||||
if (filePattern.startsWith("**")) {
|
||||
return path.join(pattern, filePattern);
|
||||
}
|
||||
|
||||
// adjust the path to be relative to the cwd
|
||||
return path.relative(
|
||||
cwd,
|
||||
path.join(configs.basePath, filePattern)
|
||||
);
|
||||
})
|
||||
.map(normalizeToPosix);
|
||||
|
||||
if (filePatterns.length) {
|
||||
globbyPatterns.push(...filePatterns);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// save patterns for later use based on whether globs are enabled
|
||||
if (globInputPaths && isGlobPattern(filePath)) {
|
||||
globbyPatterns.push(pattern);
|
||||
} else {
|
||||
missingPatterns.push(pattern);
|
||||
}
|
||||
});
|
||||
|
||||
// note: globbyPatterns can be an empty array
|
||||
const globbyResults = (await globby(globbyPatterns, {
|
||||
cwd,
|
||||
absolute: true,
|
||||
ignore: configs.ignores.filter(matcher => typeof matcher === "string")
|
||||
}));
|
||||
|
||||
// if there are no results, tell the user why
|
||||
if (!results.length && !globbyResults.length) {
|
||||
|
||||
// try globby without ignoring anything
|
||||
/* eslint-disable no-unreachable-loop -- We want to exit early. */
|
||||
for (const globbyPattern of globbyPatterns) {
|
||||
|
||||
/* eslint-disable-next-line no-unused-vars -- Want to exit early. */
|
||||
for await (const filePath of globby.stream(globbyPattern, { cwd, absolute: true })) {
|
||||
|
||||
// files were found but ignored
|
||||
throw new AllFilesIgnoredError(globbyPattern);
|
||||
}
|
||||
|
||||
// no files were found
|
||||
throw new NoFilesFoundError(globbyPattern, globInputPaths);
|
||||
}
|
||||
/* eslint-enable no-unreachable-loop -- Go back to normal. */
|
||||
|
||||
}
|
||||
|
||||
// there were patterns that didn't match anything, tell the user
|
||||
if (missingPatterns.length) {
|
||||
throw new NoFilesFoundError(missingPatterns[0], globInputPaths);
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
...results,
|
||||
...globbyResults.map(filePath => ({
|
||||
filePath: path.resolve(filePath),
|
||||
ignored: false
|
||||
}))
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether a file exists at the given location
|
||||
* @param {string} resolvedPath A path from the CWD
|
||||
* @throws {Error} As thrown by `fs.statSync` or `fs.isFile`.
|
||||
* @returns {boolean} `true` if a file exists
|
||||
*/
|
||||
function fileExists(resolvedPath) {
|
||||
try {
|
||||
return fs.statSync(resolvedPath).isFile();
|
||||
} catch (error) {
|
||||
if (error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a directory exists at the given location
|
||||
* @param {string} resolvedPath A path from the CWD
|
||||
* @throws {Error} As thrown by `fs.statSync` or `fs.isDirectory`.
|
||||
* @returns {boolean} `true` if a directory exists
|
||||
*/
|
||||
function directoryExists(resolvedPath) {
|
||||
try {
|
||||
return fs.statSync(resolvedPath).isDirectory();
|
||||
} catch (error) {
|
||||
if (error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Results-related Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Checks if the given message is an error message.
|
||||
* @param {LintMessage} message The message to check.
|
||||
* @returns {boolean} Whether or not the message is an error message.
|
||||
* @private
|
||||
*/
|
||||
function isErrorMessage(message) {
|
||||
return message.severity === 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns result with warning by ignore settings
|
||||
* @param {string} filePath File path of checked code
|
||||
* @param {string} baseDir Absolute path of base directory
|
||||
* @returns {LintResult} Result with single warning
|
||||
* @private
|
||||
*/
|
||||
function createIgnoreResult(filePath, baseDir) {
|
||||
let message;
|
||||
const isHidden = filePath.split(path.sep)
|
||||
.find(segment => /^\./u.test(segment));
|
||||
const isInNodeModules = baseDir && path.relative(baseDir, filePath).startsWith("node_modules");
|
||||
|
||||
if (isHidden) {
|
||||
message = "File ignored by default. Use a negated ignore pattern (like \"--ignore-pattern '!<relative/path/to/filename>'\") to override.";
|
||||
} else if (isInNodeModules) {
|
||||
message = "File ignored by default. Use \"--ignore-pattern '!node_modules/*'\" to override.";
|
||||
} else {
|
||||
message = "File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override.";
|
||||
}
|
||||
|
||||
return {
|
||||
filePath: path.resolve(filePath),
|
||||
messages: [
|
||||
{
|
||||
fatal: false,
|
||||
severity: 1,
|
||||
message
|
||||
}
|
||||
],
|
||||
errorCount: 0,
|
||||
warningCount: 1,
|
||||
fatalErrorCount: 0,
|
||||
fixableErrorCount: 0,
|
||||
fixableWarningCount: 0
|
||||
};
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Options-related Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Check if a given value is a valid fix type or not.
|
||||
* @param {any} x The value to check.
|
||||
* @returns {boolean} `true` if `x` is valid fix type.
|
||||
*/
|
||||
function isFixType(x) {
|
||||
return x === "directive" || x === "problem" || x === "suggestion" || x === "layout";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given value is an array of fix types or not.
|
||||
* @param {any} x The value to check.
|
||||
* @returns {boolean} `true` if `x` is an array of fix types.
|
||||
*/
|
||||
function isFixTypeArray(x) {
|
||||
return Array.isArray(x) && x.every(isFixType);
|
||||
}
|
||||
|
||||
/**
|
||||
* The error for invalid options.
|
||||
*/
|
||||
class ESLintInvalidOptionsError extends Error {
|
||||
constructor(messages) {
|
||||
super(`Invalid Options:\n- ${messages.join("\n- ")}`);
|
||||
this.code = "ESLINT_INVALID_OPTIONS";
|
||||
Error.captureStackTrace(this, ESLintInvalidOptionsError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and normalizes options for the wrapped CLIEngine instance.
|
||||
* @param {FlatESLintOptions} options The options to process.
|
||||
* @throws {ESLintInvalidOptionsError} If of any of a variety of type errors.
|
||||
* @returns {FlatESLintOptions} The normalized options.
|
||||
*/
|
||||
function processOptions({
|
||||
allowInlineConfig = true, // ← we cannot use `overrideConfig.noInlineConfig` instead because `allowInlineConfig` has side-effect that suppress warnings that show inline configs are ignored.
|
||||
baseConfig = null,
|
||||
cache = false,
|
||||
cacheLocation = ".eslintcache",
|
||||
cacheStrategy = "metadata",
|
||||
cwd = process.cwd(),
|
||||
errorOnUnmatchedPattern = true,
|
||||
extensions = null, // ← should be null by default because if it's an array then it suppresses RFC20 feature.
|
||||
fix = false,
|
||||
fixTypes = null, // ← should be null by default because if it's an array then it suppresses rules that don't have the `meta.type` property.
|
||||
globInputPaths = true,
|
||||
ignore = true,
|
||||
ignorePath = null, // ← should be null by default because if it's a string then it may throw ENOENT.
|
||||
ignorePatterns = null,
|
||||
overrideConfig = null,
|
||||
overrideConfigFile = null,
|
||||
plugins = {},
|
||||
reportUnusedDisableDirectives = null, // ← should be null by default because if it's a string then it overrides the 'reportUnusedDisableDirectives' setting in config files. And we cannot use `overrideConfig.reportUnusedDisableDirectives` instead because we cannot configure the `error` severity with that.
|
||||
...unknownOptions
|
||||
}) {
|
||||
const errors = [];
|
||||
const unknownOptionKeys = Object.keys(unknownOptions);
|
||||
|
||||
if (unknownOptionKeys.length >= 1) {
|
||||
errors.push(`Unknown options: ${unknownOptionKeys.join(", ")}`);
|
||||
if (unknownOptionKeys.includes("cacheFile")) {
|
||||
errors.push("'cacheFile' has been removed. Please use the 'cacheLocation' option instead.");
|
||||
}
|
||||
if (unknownOptionKeys.includes("configFile")) {
|
||||
errors.push("'configFile' has been removed. Please use the 'overrideConfigFile' option instead.");
|
||||
}
|
||||
if (unknownOptionKeys.includes("envs")) {
|
||||
errors.push("'envs' has been removed.");
|
||||
}
|
||||
if (unknownOptionKeys.includes("resolvePluginsRelativeTo")) {
|
||||
errors.push("'resolvePluginsRelativeTo' has been removed.");
|
||||
}
|
||||
if (unknownOptionKeys.includes("globals")) {
|
||||
errors.push("'globals' has been removed. Please use the 'overrideConfig.languageOptions.globals' option instead.");
|
||||
}
|
||||
if (unknownOptionKeys.includes("ignorePattern")) {
|
||||
errors.push("'ignorePattern' has been removed. Please use the 'overrideConfig.ignorePatterns' option instead.");
|
||||
}
|
||||
if (unknownOptionKeys.includes("parser")) {
|
||||
errors.push("'parser' has been removed. Please use the 'overrideConfig.languageOptions.parser' option instead.");
|
||||
}
|
||||
if (unknownOptionKeys.includes("parserOptions")) {
|
||||
errors.push("'parserOptions' has been removed. Please use the 'overrideConfig.languageOptions.parserOptions' option instead.");
|
||||
}
|
||||
if (unknownOptionKeys.includes("rules")) {
|
||||
errors.push("'rules' has been removed. Please use the 'overrideConfig.rules' option instead.");
|
||||
}
|
||||
if (unknownOptionKeys.includes("rulePaths")) {
|
||||
errors.push("'rulePaths' has been removed. Please define your rules using plugins.");
|
||||
}
|
||||
}
|
||||
if (typeof allowInlineConfig !== "boolean") {
|
||||
errors.push("'allowInlineConfig' must be a boolean.");
|
||||
}
|
||||
if (typeof baseConfig !== "object") {
|
||||
errors.push("'baseConfig' must be an object or null.");
|
||||
}
|
||||
if (typeof cache !== "boolean") {
|
||||
errors.push("'cache' must be a boolean.");
|
||||
}
|
||||
if (cache) {
|
||||
errors.push("'cache' option is not yet supported.");
|
||||
}
|
||||
if (!isNonEmptyString(cacheLocation)) {
|
||||
errors.push("'cacheLocation' must be a non-empty string.");
|
||||
}
|
||||
if (
|
||||
cacheStrategy !== "metadata" &&
|
||||
cacheStrategy !== "content"
|
||||
) {
|
||||
errors.push("'cacheStrategy' must be any of \"metadata\", \"content\".");
|
||||
}
|
||||
if (!isNonEmptyString(cwd) || !path.isAbsolute(cwd)) {
|
||||
errors.push("'cwd' must be an absolute path.");
|
||||
}
|
||||
if (typeof errorOnUnmatchedPattern !== "boolean") {
|
||||
errors.push("'errorOnUnmatchedPattern' must be a boolean.");
|
||||
}
|
||||
if (!isArrayOfNonEmptyString(extensions) && extensions !== null) {
|
||||
errors.push("'extensions' must be an array of non-empty strings or null.");
|
||||
}
|
||||
if (typeof fix !== "boolean" && typeof fix !== "function") {
|
||||
errors.push("'fix' must be a boolean or a function.");
|
||||
}
|
||||
if (fixTypes !== null && !isFixTypeArray(fixTypes)) {
|
||||
errors.push("'fixTypes' must be an array of any of \"directive\", \"problem\", \"suggestion\", and \"layout\".");
|
||||
}
|
||||
if (typeof globInputPaths !== "boolean") {
|
||||
errors.push("'globInputPaths' must be a boolean.");
|
||||
}
|
||||
if (typeof ignore !== "boolean") {
|
||||
errors.push("'ignore' must be a boolean.");
|
||||
}
|
||||
if (!isNonEmptyString(ignorePath) && ignorePath !== null) {
|
||||
errors.push("'ignorePath' must be a non-empty string or null.");
|
||||
}
|
||||
if (typeof overrideConfig !== "object") {
|
||||
errors.push("'overrideConfig' must be an object or null.");
|
||||
}
|
||||
if (!isNonEmptyString(overrideConfigFile) && overrideConfigFile !== null && overrideConfigFile !== true) {
|
||||
errors.push("'overrideConfigFile' must be a non-empty string, null, or true.");
|
||||
}
|
||||
if (typeof plugins !== "object") {
|
||||
errors.push("'plugins' must be an object or null.");
|
||||
} else if (plugins !== null && Object.keys(plugins).includes("")) {
|
||||
errors.push("'plugins' must not include an empty string.");
|
||||
}
|
||||
if (Array.isArray(plugins)) {
|
||||
errors.push("'plugins' doesn't add plugins to configuration to load. Please use the 'overrideConfig.plugins' option instead.");
|
||||
}
|
||||
if (
|
||||
reportUnusedDisableDirectives !== "error" &&
|
||||
reportUnusedDisableDirectives !== "warn" &&
|
||||
reportUnusedDisableDirectives !== "off" &&
|
||||
reportUnusedDisableDirectives !== null
|
||||
) {
|
||||
errors.push("'reportUnusedDisableDirectives' must be any of \"error\", \"warn\", \"off\", and null.");
|
||||
}
|
||||
if (errors.length > 0) {
|
||||
throw new ESLintInvalidOptionsError(errors);
|
||||
}
|
||||
|
||||
return {
|
||||
allowInlineConfig,
|
||||
baseConfig,
|
||||
cache,
|
||||
cacheLocation,
|
||||
cacheStrategy,
|
||||
|
||||
// when overrideConfigFile is true that means don't do config file lookup
|
||||
configFile: overrideConfigFile === true ? false : overrideConfigFile,
|
||||
overrideConfig,
|
||||
cwd,
|
||||
errorOnUnmatchedPattern,
|
||||
extensions,
|
||||
fix,
|
||||
fixTypes,
|
||||
globInputPaths,
|
||||
ignore,
|
||||
ignorePath,
|
||||
ignorePatterns,
|
||||
reportUnusedDisableDirectives
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Cache-related helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* return the cacheFile to be used by eslint, based on whether the provided parameter is
|
||||
* a directory or looks like a directory (ends in `path.sep`), in which case the file
|
||||
* name will be the `cacheFile/.cache_hashOfCWD`
|
||||
*
|
||||
* if cacheFile points to a file or looks like a file then in will just use that file
|
||||
* @param {string} cacheFile The name of file to be used to store the cache
|
||||
* @param {string} cwd Current working directory
|
||||
* @returns {string} the resolved path to the cache file
|
||||
*/
|
||||
function getCacheFile(cacheFile, cwd) {
|
||||
|
||||
/*
|
||||
* make sure the path separators are normalized for the environment/os
|
||||
* keeping the trailing path separator if present
|
||||
*/
|
||||
const normalizedCacheFile = path.normalize(cacheFile);
|
||||
|
||||
const resolvedCacheFile = path.resolve(cwd, normalizedCacheFile);
|
||||
const looksLikeADirectory = normalizedCacheFile.slice(-1) === path.sep;
|
||||
|
||||
/**
|
||||
* return the name for the cache file in case the provided parameter is a directory
|
||||
* @returns {string} the resolved path to the cacheFile
|
||||
*/
|
||||
function getCacheFileForDirectory() {
|
||||
return path.join(resolvedCacheFile, `.cache_${hash(cwd)}`);
|
||||
}
|
||||
|
||||
let fileStats;
|
||||
|
||||
try {
|
||||
fileStats = fs.lstatSync(resolvedCacheFile);
|
||||
} catch {
|
||||
fileStats = null;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* in case the file exists we need to verify if the provided path
|
||||
* is a directory or a file. If it is a directory we want to create a file
|
||||
* inside that directory
|
||||
*/
|
||||
if (fileStats) {
|
||||
|
||||
/*
|
||||
* is a directory or is a file, but the original file the user provided
|
||||
* looks like a directory but `path.resolve` removed the `last path.sep`
|
||||
* so we need to still treat this like a directory
|
||||
*/
|
||||
if (fileStats.isDirectory() || looksLikeADirectory) {
|
||||
return getCacheFileForDirectory();
|
||||
}
|
||||
|
||||
// is file so just use that file
|
||||
return resolvedCacheFile;
|
||||
}
|
||||
|
||||
/*
|
||||
* here we known the file or directory doesn't exist,
|
||||
* so we will try to infer if its a directory if it looks like a directory
|
||||
* for the current operating system.
|
||||
*/
|
||||
|
||||
// if the last character passed is a path separator we assume is a directory
|
||||
if (looksLikeADirectory) {
|
||||
return getCacheFileForDirectory();
|
||||
}
|
||||
|
||||
return resolvedCacheFile;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
module.exports = {
|
||||
isGlobPattern,
|
||||
directoryExists,
|
||||
fileExists,
|
||||
findFiles,
|
||||
|
||||
isNonEmptyString,
|
||||
isArrayOfNonEmptyString,
|
||||
|
||||
createIgnoreResult,
|
||||
isErrorMessage,
|
||||
|
||||
processOptions,
|
||||
|
||||
getCacheFile
|
||||
};
|
||||
+1164
File diff suppressed because it is too large.
Load diff
+3
-1
@@ -1,7 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
const { ESLint } = require("./eslint");
|
||||
const { FlatESLint } = require("./flat-eslint");
|
||||
|
||||
module.exports = {
|
||||
ESLint
|
||||
ESLint,
|
||||
FlatESLint
|
||||
};
|
||||
+18
-1
@@ -1608,6 +1608,11 @@ class Linter {
|
||||
...languageOptions.globals
|
||||
};
|
||||
|
||||
// double check that there is a parser to avoid mysterious error messages
|
||||
if (!languageOptions.parser) {
|
||||
throw new TypeError(`No parser specified for ${options.filename}`);
|
||||
}
|
||||
|
||||
// Espree expects this information to be passed in
|
||||
if (isEspree(languageOptions.parser)) {
|
||||
const parserOptions = languageOptions.parserOptions;
|
||||
@@ -1770,12 +1775,24 @@ class Linter {
|
||||
debug("With flat config: %s", options.filename);
|
||||
|
||||
// we need a filename to match configs against
|
||||
const filename = options.filename || "<input>";
|
||||
const filename = options.filename || "__placeholder__.js";
|
||||
|
||||
// Store the config array in order to get plugin envs and rules later.
|
||||
internalSlotsMap.get(this).lastConfigArray = configArray;
|
||||
const config = configArray.getConfig(filename);
|
||||
|
||||
if (!config) {
|
||||
return [
|
||||
{
|
||||
ruleId: null,
|
||||
severity: 1,
|
||||
message: `No matching configuration found for ${filename}.`,
|
||||
line: 0,
|
||||
column: 0
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
// Verify.
|
||||
if (config.processor) {
|
||||
debug("Apply the processor: %o", config.processor);
|
||||
|
||||
+39
-36
@@ -480,51 +480,54 @@ class FlatRuleTester {
|
||||
].concat(scenarioErrors).join("\n"));
|
||||
}
|
||||
|
||||
const baseConfig = {
|
||||
plugins: {
|
||||
const baseConfig = [
|
||||
{
|
||||
plugins: {
|
||||
|
||||
// copy root plugin over
|
||||
"@": {
|
||||
// copy root plugin over
|
||||
"@": {
|
||||
|
||||
/*
|
||||
* Parsers are wrapped to detect more errors, so this needs
|
||||
* to be a new object for each call to run(), otherwise the
|
||||
* parsers will be wrapped multiple times.
|
||||
*/
|
||||
parsers: {
|
||||
...defaultConfig[0].plugins["@"].parsers
|
||||
/*
|
||||
* Parsers are wrapped to detect more errors, so this needs
|
||||
* to be a new object for each call to run(), otherwise the
|
||||
* parsers will be wrapped multiple times.
|
||||
*/
|
||||
parsers: {
|
||||
...defaultConfig[0].plugins["@"].parsers
|
||||
},
|
||||
|
||||
/*
|
||||
* The rules key on the default plugin is a proxy to lazy-load
|
||||
* just the rules that are needed. So, don't create a new object
|
||||
* here, just use the default one to keep that performance
|
||||
* enhancement.
|
||||
*/
|
||||
rules: defaultConfig[0].plugins["@"].rules
|
||||
},
|
||||
"rule-to-test": {
|
||||
rules: {
|
||||
[ruleName]: Object.assign({}, rule, {
|
||||
|
||||
/*
|
||||
* The rules key on the default plugin is a proxy to lazy-load
|
||||
* just the rules that are needed. So, don't create a new object
|
||||
* here, just use the default one to keep that performance
|
||||
* enhancement.
|
||||
*/
|
||||
rules: defaultConfig[0].plugins["@"].rules
|
||||
},
|
||||
"rule-to-test": {
|
||||
rules: {
|
||||
[ruleName]: Object.assign({}, rule, {
|
||||
// Create a wrapper rule that freezes the `context` properties.
|
||||
create(context) {
|
||||
freezeDeeply(context.options);
|
||||
freezeDeeply(context.settings);
|
||||
freezeDeeply(context.parserOptions);
|
||||
|
||||
// Create a wrapper rule that freezes the `context` properties.
|
||||
create(context) {
|
||||
freezeDeeply(context.options);
|
||||
freezeDeeply(context.settings);
|
||||
freezeDeeply(context.parserOptions);
|
||||
// freezeDeeply(context.languageOptions);
|
||||
|
||||
// freezeDeeply(context.languageOptions);
|
||||
|
||||
return (typeof rule === "function" ? rule : rule.create)(context);
|
||||
}
|
||||
})
|
||||
return (typeof rule === "function" ? rule : rule.create)(context);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
languageOptions: {
|
||||
...defaultConfig[0].languageOptions
|
||||
}
|
||||
},
|
||||
languageOptions: {
|
||||
...defaultConfig[0].languageOptions
|
||||
}
|
||||
};
|
||||
...defaultConfig.slice(1)
|
||||
];
|
||||
|
||||
/**
|
||||
* Run the rule for the given item
|
||||
|
||||
+42
@@ -305,6 +305,36 @@ function getCommentsDeprecation() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit a deprecation warning if function-style format is being used.
|
||||
* @param {string} ruleName Name of the rule.
|
||||
* @returns {void}
|
||||
*/
|
||||
function emitLegacyRuleAPIWarning(ruleName) {
|
||||
if (!emitLegacyRuleAPIWarning[`warned-${ruleName}`]) {
|
||||
emitLegacyRuleAPIWarning[`warned-${ruleName}`] = true;
|
||||
process.emitWarning(
|
||||
`"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules`,
|
||||
"DeprecationWarning"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit a deprecation warning if rule has options but is missing the "meta.schema" property
|
||||
* @param {string} ruleName Name of the rule.
|
||||
* @returns {void}
|
||||
*/
|
||||
function emitMissingSchemaWarning(ruleName) {
|
||||
if (!emitMissingSchemaWarning[`warned-${ruleName}`]) {
|
||||
emitMissingSchemaWarning[`warned-${ruleName}`] = true;
|
||||
process.emitWarning(
|
||||
`"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`,
|
||||
"DeprecationWarning"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public Interface
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -521,6 +551,9 @@ class RuleTester {
|
||||
].concat(scenarioErrors).join("\n"));
|
||||
}
|
||||
|
||||
if (typeof rule === "function") {
|
||||
emitLegacyRuleAPIWarning(ruleName);
|
||||
}
|
||||
|
||||
linter.defineRule(ruleName, Object.assign({}, rule, {
|
||||
|
||||
@@ -578,6 +611,15 @@ class RuleTester {
|
||||
|
||||
if (hasOwnProperty(item, "options")) {
|
||||
assert(Array.isArray(item.options), "options must be an array");
|
||||
if (
|
||||
item.options.length > 0 &&
|
||||
typeof rule === "object" &&
|
||||
(
|
||||
!rule.meta || (rule.meta && (typeof rule.meta.schema === "undefined" || rule.meta.schema === null))
|
||||
)
|
||||
) {
|
||||
emitMissingSchemaWarning(ruleName);
|
||||
}
|
||||
config.rules[ruleName] = [1].concat(item.options);
|
||||
} else {
|
||||
config.rules[ruleName] = 1;
|
||||
|
||||
+4
-1
@@ -9,6 +9,9 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
const GraphemeSplitter = require("grapheme-splitter");
|
||||
|
||||
const splitter = new GraphemeSplitter();
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
@@ -508,7 +511,7 @@ module.exports = {
|
||||
const startToken = sourceCode.getFirstToken(property);
|
||||
const endToken = getLastTokenBeforeColon(property.key);
|
||||
|
||||
return endToken.range[1] - startToken.range[0];
|
||||
return splitter.countGraphemes(sourceCode.getText().slice(startToken.range[0], endToken.range[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+11
-4
@@ -231,9 +231,15 @@ module.exports = {
|
||||
const parent = getParentNodeOfToken(token);
|
||||
|
||||
if (parent && isParentNodeType(parent, nodeType)) {
|
||||
const parentStartNodeOrToken = parent.type === "StaticBlock"
|
||||
? sourceCode.getFirstToken(parent, { skip: 1 }) // opening brace of the static block
|
||||
: parent;
|
||||
let parentStartNodeOrToken = parent;
|
||||
|
||||
if (parent.type === "StaticBlock") {
|
||||
parentStartNodeOrToken = sourceCode.getFirstToken(parent, { skip: 1 }); // opening brace of the static block
|
||||
} else if (parent.type === "SwitchStatement") {
|
||||
parentStartNodeOrToken = sourceCode.getTokenAfter(parent.discriminant, {
|
||||
filter: astUtils.isOpeningBraceToken
|
||||
}); // opening brace of the switch statement
|
||||
}
|
||||
|
||||
return token.loc.start.line - parentStartNodeOrToken.loc.start.line === 1;
|
||||
}
|
||||
@@ -264,7 +270,8 @@ module.exports = {
|
||||
isCommentAtParentStart(token, "ClassBody") ||
|
||||
isCommentAtParentStart(token, "BlockStatement") ||
|
||||
isCommentAtParentStart(token, "StaticBlock") ||
|
||||
isCommentAtParentStart(token, "SwitchCase")
|
||||
isCommentAtParentStart(token, "SwitchCase") ||
|
||||
isCommentAtParentStart(token, "SwitchStatement")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+43
@@ -105,6 +105,10 @@ module.exports = {
|
||||
type: "integer",
|
||||
minimum: 2,
|
||||
default: 2
|
||||
},
|
||||
allowLineSeparatedGroups: {
|
||||
type: "boolean",
|
||||
default: false
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
@@ -124,17 +128,21 @@ module.exports = {
|
||||
const insensitive = options && options.caseSensitive === false;
|
||||
const natural = options && options.natural;
|
||||
const minKeys = options && options.minKeys;
|
||||
const allowLineSeparatedGroups = options && options.allowLineSeparatedGroups || false;
|
||||
const isValidOrder = isValidOrders[
|
||||
order + (insensitive ? "I" : "") + (natural ? "N" : "")
|
||||
];
|
||||
|
||||
// The stack to save the previous property's name for each object literals.
|
||||
let stack = null;
|
||||
const sourceCode = context.getSourceCode();
|
||||
|
||||
return {
|
||||
ObjectExpression(node) {
|
||||
stack = {
|
||||
upper: stack,
|
||||
prevNode: null,
|
||||
prevBlankLine: false,
|
||||
prevName: null,
|
||||
numKeys: node.properties.length
|
||||
};
|
||||
@@ -159,10 +167,45 @@ module.exports = {
|
||||
const numKeys = stack.numKeys;
|
||||
const thisName = getPropertyName(node);
|
||||
|
||||
// Get tokens between current node and previous node
|
||||
const tokens = stack.prevNode && sourceCode
|
||||
.getTokensBetween(stack.prevNode, node, { includeComments: true });
|
||||
|
||||
let isBlankLineBetweenNodes = stack.prevBlankLine;
|
||||
|
||||
if (tokens) {
|
||||
|
||||
// check blank line between tokens
|
||||
tokens.forEach((token, index) => {
|
||||
const previousToken = tokens[index - 1];
|
||||
|
||||
if (previousToken && (token.loc.start.line - previousToken.loc.end.line > 1)) {
|
||||
isBlankLineBetweenNodes = true;
|
||||
}
|
||||
});
|
||||
|
||||
// check blank line between the current node and the last token
|
||||
if (!isBlankLineBetweenNodes && (node.loc.start.line - tokens[tokens.length - 1].loc.end.line > 1)) {
|
||||
isBlankLineBetweenNodes = true;
|
||||
}
|
||||
|
||||
// check blank line between the first token and the previous node
|
||||
if (!isBlankLineBetweenNodes && (tokens[0].loc.start.line - stack.prevNode.loc.end.line > 1)) {
|
||||
isBlankLineBetweenNodes = true;
|
||||
}
|
||||
}
|
||||
|
||||
stack.prevNode = node;
|
||||
|
||||
if (thisName !== null) {
|
||||
stack.prevName = thisName;
|
||||
}
|
||||
|
||||
if (allowLineSeparatedGroups && isBlankLineBetweenNodes) {
|
||||
stack.prevBlankLine = thisName === null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (prevName === null || thisName === null || numKeys < minKeys) {
|
||||
return;
|
||||
}
|
||||
|
||||
+4
@@ -12,6 +12,8 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const { FileEnumerator } = require("./cli-engine/file-enumerator");
|
||||
const { FlatESLint } = require("./eslint/flat-eslint");
|
||||
const FlatRuleTester = require("./rule-tester/flat-rule-tester");
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
@@ -19,5 +21,7 @@ const { FileEnumerator } = require("./cli-engine/file-enumerator");
|
||||
|
||||
module.exports = {
|
||||
builtinRules: require("./rules"),
|
||||
FlatESLint,
|
||||
FlatRuleTester,
|
||||
FileEnumerator
|
||||
};
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
const babelP = import("./lib/index.js");
|
||||
|
||||
const functionNames = [
|
||||
"createConfigItem",
|
||||
"loadPartialConfig",
|
||||
"loadOptions",
|
||||
"transform",
|
||||
"transformFile",
|
||||
"transformFromAst",
|
||||
"parse",
|
||||
];
|
||||
|
||||
for (const name of functionNames) {
|
||||
exports[`${name}Sync`] = function () {
|
||||
throw new Error(
|
||||
`"${name}Sync" is not supported when loading @babel/core using require()`
|
||||
);
|
||||
};
|
||||
exports[name] = function (...args) {
|
||||
babelP.then(babel => {
|
||||
babel[name](...args);
|
||||
});
|
||||
};
|
||||
exports[`${name}Async`] = function (...args) {
|
||||
return babelP.then(babel => babel[`${name}Async`](...args));
|
||||
};
|
||||
}
|
||||
+1
-2
@@ -62,8 +62,7 @@ function makeCachedFunction(CallCache, handler) {
|
||||
let value;
|
||||
|
||||
if ((0, _util.isIterableIterator)(handlerResult)) {
|
||||
const gen = handlerResult;
|
||||
value = yield* (0, _async.onFirstPause)(gen, () => {
|
||||
value = yield* (0, _async.onFirstPause)(handlerResult, () => {
|
||||
finishLock = setupAsyncLocks(cache, futureCache, arg);
|
||||
});
|
||||
} else {
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -24,7 +24,7 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
||||
let import_;
|
||||
|
||||
try {
|
||||
import_ = require("./import").default;
|
||||
import_ = require("./import.cjs");
|
||||
} catch (_unused) {}
|
||||
|
||||
const importMetaResolveP = import_ && process.execArgv.includes("--experimental-import-meta-resolve") ? import_("data:text/javascript,export default import.meta.resolve").then(m => m.default || _importMetaResolve.resolve, () => _importMetaResolve.resolve) : Promise.resolve(_importMetaResolve.resolve);
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
module.exports = function import_(filepath) {
|
||||
return import(filepath);
|
||||
};
|
||||
|
||||
0 && 0;
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = import_;
|
||||
|
||||
function import_(filepath) {
|
||||
return import(filepath);
|
||||
}
|
||||
|
||||
0 && 0;
|
||||
Generated
Vendored
+1
-1
@@ -55,7 +55,7 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
||||
let import_;
|
||||
|
||||
try {
|
||||
import_ = require("./import").default;
|
||||
import_ = require("./import.cjs");
|
||||
} catch (_unused) {}
|
||||
|
||||
const supportsESM = _semver().satisfies(process.versions.node, "^12.17 || >=13.2");
|
||||
|
||||
+11
-5
@@ -38,13 +38,19 @@ const loadOptionsRunner = _gensync()(function* (opts) {
|
||||
|
||||
const createConfigItemRunner = _gensync()(_item.createConfigItem);
|
||||
|
||||
const maybeErrback = runner => (opts, callback) => {
|
||||
if (callback === undefined && typeof opts === "function") {
|
||||
callback = opts;
|
||||
opts = undefined;
|
||||
const maybeErrback = runner => (argOrCallback, maybeCallback) => {
|
||||
let arg;
|
||||
let callback;
|
||||
|
||||
if (maybeCallback === undefined && typeof argOrCallback === "function") {
|
||||
callback = argOrCallback;
|
||||
arg = undefined;
|
||||
} else {
|
||||
callback = maybeCallback;
|
||||
arg = argOrCallback;
|
||||
}
|
||||
|
||||
return callback ? runner.errback(opts, callback) : runner.sync(opts);
|
||||
return callback ? runner.errback(arg, callback) : runner.sync(arg);
|
||||
};
|
||||
|
||||
const loadPartialConfig = maybeErrback(_partial.loadPartialConfig);
|
||||
|
||||
+22
-4
@@ -19,7 +19,9 @@ function _gensync() {
|
||||
return data;
|
||||
}
|
||||
|
||||
const id = x => x;
|
||||
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); }); }; }
|
||||
|
||||
const runGenerator = _gensync()(function* (item) {
|
||||
return yield* item;
|
||||
@@ -49,7 +51,15 @@ function maybeAsync(fn, message) {
|
||||
|
||||
const withKind = _gensync()({
|
||||
sync: cb => cb("sync"),
|
||||
async: cb => cb("async")
|
||||
async: function () {
|
||||
var _ref = _asyncToGenerator(function* (cb) {
|
||||
return cb("async");
|
||||
});
|
||||
|
||||
return function async(_x) {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}()
|
||||
});
|
||||
|
||||
function forwardAsync(action, cb) {
|
||||
@@ -83,8 +93,16 @@ const onFirstPause = _gensync()({
|
||||
exports.onFirstPause = onFirstPause;
|
||||
|
||||
const waitFor = _gensync()({
|
||||
sync: id,
|
||||
async: id
|
||||
sync: x => x,
|
||||
async: function () {
|
||||
var _ref2 = _asyncToGenerator(function* (x) {
|
||||
return x;
|
||||
});
|
||||
|
||||
return function async(_x2) {
|
||||
return _ref2.apply(this, arguments);
|
||||
};
|
||||
}()
|
||||
});
|
||||
|
||||
exports.waitFor = waitFor;
|
||||
|
||||
+1
-1
@@ -247,7 +247,7 @@ var _transformAst = require("./transform-ast");
|
||||
|
||||
var _parse = require("./parse");
|
||||
|
||||
const version = "7.18.6";
|
||||
const version = "7.18.10";
|
||||
exports.version = version;
|
||||
const DEFAULT_EXTENSIONS = Object.freeze([".js", ".jsx", ".es6", ".es", ".mjs", ".cjs"]);
|
||||
exports.DEFAULT_EXTENSIONS = DEFAULT_EXTENSIONS;
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -131,7 +131,7 @@ function* normalizeFile(pluginPasses, options, code, ast) {
|
||||
|
||||
return new _file.default(options, {
|
||||
code,
|
||||
ast,
|
||||
ast: ast,
|
||||
inputMap
|
||||
});
|
||||
}
|
||||
|
||||
Generated
Vendored
+185
-59
@@ -93,7 +93,7 @@ var debug_1 = debug$1;
|
||||
|
||||
const createToken = (name, value, isGlobal) => {
|
||||
const index = R++;
|
||||
debug(index, value);
|
||||
debug(name, index, value);
|
||||
t[name] = index;
|
||||
src[index] = value;
|
||||
re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
|
||||
@@ -140,17 +140,17 @@ var debug_1 = debug$1;
|
||||
createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` + `\\s+-\\s+` + `(${src[t.XRANGEPLAIN]})` + `\\s*$`);
|
||||
createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` + `\\s+-\\s+` + `(${src[t.XRANGEPLAINLOOSE]})` + `\\s*$`);
|
||||
createToken('STAR', '(<|>)?=?\\s*\\*');
|
||||
createToken('GTE0', '^\\s*>=\\s*0\.0\.0\\s*$');
|
||||
createToken('GTE0PRE', '^\\s*>=\\s*0\.0\.0-0\\s*$');
|
||||
createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
|
||||
createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
|
||||
})(re$3, re$3.exports);
|
||||
|
||||
const opts = ['includePrerelease', 'loose', 'rtl'];
|
||||
|
||||
const parseOptions$2 = options => !options ? {} : typeof options !== 'object' ? {
|
||||
loose: true
|
||||
} : opts.filter(k => options[k]).reduce((options, k) => {
|
||||
options[k] = true;
|
||||
return options;
|
||||
} : opts.filter(k => options[k]).reduce((o, k) => {
|
||||
o[k] = true;
|
||||
return o;
|
||||
}, {});
|
||||
|
||||
var parseOptions_1 = parseOptions$2;
|
||||
@@ -430,7 +430,7 @@ class SemVer$c {
|
||||
}
|
||||
|
||||
if (identifier) {
|
||||
if (this.prerelease[0] === identifier) {
|
||||
if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
|
||||
if (isNaN(this.prerelease[1])) {
|
||||
this.prerelease = [identifier, 0];
|
||||
}
|
||||
@@ -517,7 +517,7 @@ const inc = (version, release, options, identifier) => {
|
||||
}
|
||||
|
||||
try {
|
||||
return new SemVer$a(version, options).inc(release, identifier).version;
|
||||
return new SemVer$a(version instanceof SemVer$a ? version.version : version, options).inc(release, identifier).version;
|
||||
} catch (er) {
|
||||
return null;
|
||||
}
|
||||
@@ -647,13 +647,25 @@ const lte$1 = lte_1;
|
||||
const cmp = (a, op, b, loose) => {
|
||||
switch (op) {
|
||||
case '===':
|
||||
if (typeof a === 'object') a = a.version;
|
||||
if (typeof b === 'object') b = b.version;
|
||||
if (typeof a === 'object') {
|
||||
a = a.version;
|
||||
}
|
||||
|
||||
if (typeof b === 'object') {
|
||||
b = b.version;
|
||||
}
|
||||
|
||||
return a === b;
|
||||
|
||||
case '!==':
|
||||
if (typeof a === 'object') a = a.version;
|
||||
if (typeof b === 'object') b = b.version;
|
||||
if (typeof a === 'object') {
|
||||
a = a.version;
|
||||
}
|
||||
|
||||
if (typeof b === 'object') {
|
||||
b = b.version;
|
||||
}
|
||||
|
||||
return a !== b;
|
||||
|
||||
case '':
|
||||
@@ -721,7 +733,10 @@ const coerce = (version, options) => {
|
||||
re[t.COERCERTL].lastIndex = -1;
|
||||
}
|
||||
|
||||
if (match === null) return null;
|
||||
if (match === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parse(`${match[2]}.${match[3] || '0'}.${match[4] || '0'}`, options);
|
||||
};
|
||||
|
||||
@@ -1567,7 +1582,7 @@ function requireRange() {
|
||||
this.loose = !!options.loose;
|
||||
this.includePrerelease = !!options.includePrerelease;
|
||||
this.raw = range;
|
||||
this.set = range.split(/\s*\|\|\s*/).map(range => this.parseRange(range.trim())).filter(c => c.length);
|
||||
this.set = range.split('||').map(r => this.parseRange(r.trim())).filter(c => c.length);
|
||||
|
||||
if (!this.set.length) {
|
||||
throw new TypeError(`Invalid SemVer Range: ${range}`);
|
||||
@@ -1576,7 +1591,10 @@ function requireRange() {
|
||||
if (this.set.length > 1) {
|
||||
const first = this.set[0];
|
||||
this.set = this.set.filter(c => !isNullSet(c[0]));
|
||||
if (this.set.length === 0) this.set = [first];else if (this.set.length > 1) {
|
||||
|
||||
if (this.set.length === 0) {
|
||||
this.set = [first];
|
||||
} else if (this.set.length > 1) {
|
||||
for (const c of this.set) {
|
||||
if (c.length === 1 && isAny(c[0])) {
|
||||
this.set = [c];
|
||||
@@ -1605,27 +1623,45 @@ function requireRange() {
|
||||
const memoOpts = Object.keys(this.options).join(',');
|
||||
const memoKey = `parseRange:${memoOpts}:${range}`;
|
||||
const cached = cache.get(memoKey);
|
||||
if (cached) return cached;
|
||||
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
const loose = this.options.loose;
|
||||
const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
|
||||
range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
|
||||
debug('hyphen replace', range);
|
||||
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
|
||||
debug('comparator trim', range, re[t.COMPARATORTRIM]);
|
||||
debug('comparator trim', range);
|
||||
range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
|
||||
range = range.replace(re[t.CARETTRIM], caretTrimReplace);
|
||||
range = range.split(/\s+/).join(' ');
|
||||
const compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
|
||||
const rangeList = range.split(' ').map(comp => parseComparator(comp, this.options)).join(' ').split(/\s+/).map(comp => replaceGTE0(comp, this.options)).filter(this.options.loose ? comp => !!comp.match(compRe) : () => true).map(comp => new Comparator(comp, this.options));
|
||||
rangeList.length;
|
||||
let rangeList = range.split(' ').map(comp => parseComparator(comp, this.options)).join(' ').split(/\s+/).map(comp => replaceGTE0(comp, this.options));
|
||||
|
||||
if (loose) {
|
||||
rangeList = rangeList.filter(comp => {
|
||||
debug('loose invalid filter', comp, this.options);
|
||||
return !!comp.match(re[t.COMPARATORLOOSE]);
|
||||
});
|
||||
}
|
||||
|
||||
debug('range list', rangeList);
|
||||
const rangeMap = new Map();
|
||||
const comparators = rangeList.map(comp => new Comparator(comp, this.options));
|
||||
|
||||
for (const comp of comparators) {
|
||||
if (isNullSet(comp)) {
|
||||
return [comp];
|
||||
}
|
||||
|
||||
for (const comp of rangeList) {
|
||||
if (isNullSet(comp)) return [comp];
|
||||
rangeMap.set(comp.value, comp);
|
||||
}
|
||||
|
||||
if (rangeMap.size > 1 && rangeMap.has('')) rangeMap.delete('');
|
||||
if (rangeMap.size > 1 && rangeMap.has('')) {
|
||||
rangeMap.delete('');
|
||||
}
|
||||
|
||||
const result = [...rangeMap.values()];
|
||||
cache.set(memoKey, result);
|
||||
return result;
|
||||
@@ -1722,8 +1758,8 @@ function requireRange() {
|
||||
|
||||
const isX = id => !id || id.toLowerCase() === 'x' || id === '*';
|
||||
|
||||
const replaceTildes = (comp, options) => comp.trim().split(/\s+/).map(comp => {
|
||||
return replaceTilde(comp, options);
|
||||
const replaceTildes = (comp, options) => comp.trim().split(/\s+/).map(c => {
|
||||
return replaceTilde(c, options);
|
||||
}).join(' ');
|
||||
|
||||
const replaceTilde = (comp, options) => {
|
||||
@@ -1750,8 +1786,8 @@ function requireRange() {
|
||||
});
|
||||
};
|
||||
|
||||
const replaceCarets = (comp, options) => comp.trim().split(/\s+/).map(comp => {
|
||||
return replaceCaret(comp, options);
|
||||
const replaceCarets = (comp, options) => comp.trim().split(/\s+/).map(c => {
|
||||
return replaceCaret(c, options);
|
||||
}).join(' ');
|
||||
|
||||
const replaceCaret = (comp, options) => {
|
||||
@@ -1805,8 +1841,8 @@ function requireRange() {
|
||||
|
||||
const replaceXRanges = (comp, options) => {
|
||||
debug('replaceXRanges', comp, options);
|
||||
return comp.split(/\s+/).map(comp => {
|
||||
return replaceXRange(comp, options);
|
||||
return comp.split(/\s+/).map(c => {
|
||||
return replaceXRange(c, options);
|
||||
}).join(' ');
|
||||
};
|
||||
|
||||
@@ -1860,7 +1896,10 @@ function requireRange() {
|
||||
}
|
||||
}
|
||||
|
||||
if (gtlt === '<') pr = '-0';
|
||||
if (gtlt === '<') {
|
||||
pr = '-0';
|
||||
}
|
||||
|
||||
ret = `${gtlt + M}.${m}.${p}${pr}`;
|
||||
} else if (xm) {
|
||||
ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
|
||||
@@ -2199,7 +2238,10 @@ const minVersion = (range, loose) => {
|
||||
throw new Error(`Unexpected operation: ${comparator.operator}`);
|
||||
}
|
||||
});
|
||||
if (setMin && (!minver || gt$1(minver, setMin))) minver = setMin;
|
||||
|
||||
if (setMin && (!minver || gt$1(minver, setMin))) {
|
||||
minver = setMin;
|
||||
}
|
||||
}
|
||||
|
||||
if (minver && range.test(minver)) {
|
||||
@@ -2321,7 +2363,7 @@ const compare$1 = compare_1;
|
||||
|
||||
var simplify = (versions, range, options) => {
|
||||
const set = [];
|
||||
let min = null;
|
||||
let first = null;
|
||||
let prev = null;
|
||||
const v = versions.sort((a, b) => compare$1(a, b, options));
|
||||
|
||||
@@ -2330,22 +2372,38 @@ var simplify = (versions, range, options) => {
|
||||
|
||||
if (included) {
|
||||
prev = version;
|
||||
if (!min) min = version;
|
||||
|
||||
if (!first) {
|
||||
first = version;
|
||||
}
|
||||
} else {
|
||||
if (prev) {
|
||||
set.push([min, prev]);
|
||||
set.push([first, prev]);
|
||||
}
|
||||
|
||||
prev = null;
|
||||
min = null;
|
||||
first = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (min) set.push([min, null]);
|
||||
if (first) {
|
||||
set.push([first, null]);
|
||||
}
|
||||
|
||||
const ranges = [];
|
||||
|
||||
for (const [min, max] of set) {
|
||||
if (min === max) ranges.push(min);else if (!max && min === v[0]) ranges.push('*');else if (!max) ranges.push(`>=${min}`);else if (min === v[0]) ranges.push(`<=${max}`);else ranges.push(`${min} - ${max}`);
|
||||
if (min === max) {
|
||||
ranges.push(min);
|
||||
} else if (!max && min === v[0]) {
|
||||
ranges.push('*');
|
||||
} else if (!max) {
|
||||
ranges.push(`>=${min}`);
|
||||
} else if (min === v[0]) {
|
||||
ranges.push(`<=${max}`);
|
||||
} else {
|
||||
ranges.push(`${min} - ${max}`);
|
||||
}
|
||||
}
|
||||
|
||||
const simplified = ranges.join(' || ');
|
||||
@@ -2362,7 +2420,10 @@ const satisfies = satisfies_1;
|
||||
const compare = compare_1;
|
||||
|
||||
const subset = (sub, dom, options = {}) => {
|
||||
if (sub === dom) return true;
|
||||
if (sub === dom) {
|
||||
return true;
|
||||
}
|
||||
|
||||
sub = new Range(sub, options);
|
||||
dom = new Range(dom, options);
|
||||
let sawNonNull = false;
|
||||
@@ -2371,47 +2432,85 @@ const subset = (sub, dom, options = {}) => {
|
||||
for (const simpleDom of dom.set) {
|
||||
const isSub = simpleSubset(simpleSub, simpleDom, options);
|
||||
sawNonNull = sawNonNull || isSub !== null;
|
||||
if (isSub) continue OUTER;
|
||||
|
||||
if (isSub) {
|
||||
continue OUTER;
|
||||
}
|
||||
}
|
||||
|
||||
if (sawNonNull) return false;
|
||||
if (sawNonNull) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const simpleSubset = (sub, dom, options) => {
|
||||
if (sub === dom) return true;
|
||||
if (sub === dom) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sub.length === 1 && sub[0].semver === ANY) {
|
||||
if (dom.length === 1 && dom[0].semver === ANY) return true;else if (options.includePrerelease) sub = [new Comparator('>=0.0.0-0')];else sub = [new Comparator('>=0.0.0')];
|
||||
if (dom.length === 1 && dom[0].semver === ANY) {
|
||||
return true;
|
||||
} else if (options.includePrerelease) {
|
||||
sub = [new Comparator('>=0.0.0-0')];
|
||||
} else {
|
||||
sub = [new Comparator('>=0.0.0')];
|
||||
}
|
||||
}
|
||||
|
||||
if (dom.length === 1 && dom[0].semver === ANY) {
|
||||
if (options.includePrerelease) return true;else dom = [new Comparator('>=0.0.0')];
|
||||
if (options.includePrerelease) {
|
||||
return true;
|
||||
} else {
|
||||
dom = [new Comparator('>=0.0.0')];
|
||||
}
|
||||
}
|
||||
|
||||
const eqSet = new Set();
|
||||
let gt, lt;
|
||||
|
||||
for (const c of sub) {
|
||||
if (c.operator === '>' || c.operator === '>=') gt = higherGT(gt, c, options);else if (c.operator === '<' || c.operator === '<=') lt = lowerLT(lt, c, options);else eqSet.add(c.semver);
|
||||
if (c.operator === '>' || c.operator === '>=') {
|
||||
gt = higherGT(gt, c, options);
|
||||
} else if (c.operator === '<' || c.operator === '<=') {
|
||||
lt = lowerLT(lt, c, options);
|
||||
} else {
|
||||
eqSet.add(c.semver);
|
||||
}
|
||||
}
|
||||
|
||||
if (eqSet.size > 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (eqSet.size > 1) return null;
|
||||
let gtltComp;
|
||||
|
||||
if (gt && lt) {
|
||||
gtltComp = compare(gt.semver, lt.semver, options);
|
||||
if (gtltComp > 0) return null;else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) return null;
|
||||
|
||||
if (gtltComp > 0) {
|
||||
return null;
|
||||
} else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
for (const eq of eqSet) {
|
||||
if (gt && !satisfies(eq, String(gt), options)) return null;
|
||||
if (lt && !satisfies(eq, String(lt), options)) return null;
|
||||
if (gt && !satisfies(eq, String(gt), options)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (lt && !satisfies(eq, String(lt), options)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (const c of dom) {
|
||||
if (!satisfies(eq, String(c), options)) return false;
|
||||
if (!satisfies(eq, String(c), options)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -2439,8 +2538,13 @@ const simpleSubset = (sub, dom, options) => {
|
||||
|
||||
if (c.operator === '>' || c.operator === '>=') {
|
||||
higher = higherGT(gt, c, options);
|
||||
if (higher === c && higher !== gt) return false;
|
||||
} else if (gt.operator === '>=' && !satisfies(gt.semver, String(c), options)) return false;
|
||||
|
||||
if (higher === c && higher !== gt) {
|
||||
return false;
|
||||
}
|
||||
} else if (gt.operator === '>=' && !satisfies(gt.semver, String(c), options)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (lt) {
|
||||
@@ -2452,27 +2556,49 @@ const simpleSubset = (sub, dom, options) => {
|
||||
|
||||
if (c.operator === '<' || c.operator === '<=') {
|
||||
lower = lowerLT(lt, c, options);
|
||||
if (lower === c && lower !== lt) return false;
|
||||
} else if (lt.operator === '<=' && !satisfies(lt.semver, String(c), options)) return false;
|
||||
|
||||
if (lower === c && lower !== lt) {
|
||||
return false;
|
||||
}
|
||||
} else if (lt.operator === '<=' && !satisfies(lt.semver, String(c), options)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!c.operator && (lt || gt) && gtltComp !== 0) return false;
|
||||
if (!c.operator && (lt || gt) && gtltComp !== 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (gt && hasDomLT && !lt && gtltComp !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lt && hasDomGT && !gt && gtltComp !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (needDomGTPre || needDomLTPre) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gt && hasDomLT && !lt && gtltComp !== 0) return false;
|
||||
if (lt && hasDomGT && !gt && gtltComp !== 0) return false;
|
||||
if (needDomGTPre || needDomLTPre) return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
const higherGT = (a, b, options) => {
|
||||
if (!a) return b;
|
||||
if (!a) {
|
||||
return b;
|
||||
}
|
||||
|
||||
const comp = compare(a.semver, b.semver, options);
|
||||
return comp > 0 ? a : comp < 0 ? b : b.operator === '>' && a.operator === '>=' ? b : a;
|
||||
};
|
||||
|
||||
const lowerLT = (a, b, options) => {
|
||||
if (!a) return b;
|
||||
if (!a) {
|
||||
return b;
|
||||
}
|
||||
|
||||
const comp = compare(a.semver, b.semver, options);
|
||||
return comp < 0 ? a : comp > 0 ? b : b.operator === '<' && a.operator === '<=' ? b : a;
|
||||
};
|
||||
|
||||
+13
-12
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/core",
|
||||
"version": "7.18.6",
|
||||
"version": "7.18.10",
|
||||
"description": "Babel compiler core.",
|
||||
"main": "./lib/index.js",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
@@ -48,14 +48,14 @@
|
||||
"dependencies": {
|
||||
"@ampproject/remapping": "^2.1.0",
|
||||
"@babel/code-frame": "^7.18.6",
|
||||
"@babel/generator": "^7.18.6",
|
||||
"@babel/helper-compilation-targets": "^7.18.6",
|
||||
"@babel/helper-module-transforms": "^7.18.6",
|
||||
"@babel/helpers": "^7.18.6",
|
||||
"@babel/parser": "^7.18.6",
|
||||
"@babel/template": "^7.18.6",
|
||||
"@babel/traverse": "^7.18.6",
|
||||
"@babel/types": "^7.18.6",
|
||||
"@babel/generator": "^7.18.10",
|
||||
"@babel/helper-compilation-targets": "^7.18.9",
|
||||
"@babel/helper-module-transforms": "^7.18.9",
|
||||
"@babel/helpers": "^7.18.9",
|
||||
"@babel/parser": "^7.18.10",
|
||||
"@babel/template": "^7.18.10",
|
||||
"@babel/traverse": "^7.18.10",
|
||||
"@babel/types": "^7.18.10",
|
||||
"convert-source-map": "^1.7.0",
|
||||
"debug": "^4.1.0",
|
||||
"gensync": "^1.0.0-beta.2",
|
||||
@@ -63,14 +63,15 @@
|
||||
"semver": "^6.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-transform-fixture-test-runner": "^7.18.6",
|
||||
"@babel/helper-transform-fixture-test-runner": "^7.18.10",
|
||||
"@babel/plugin-syntax-flow": "^7.18.6",
|
||||
"@babel/plugin-transform-flow-strip-types": "^7.18.6",
|
||||
"@babel/plugin-transform-flow-strip-types": "^7.18.9",
|
||||
"@babel/plugin-transform-modules-commonjs": "^7.18.6",
|
||||
"@babel/preset-env": "^7.18.6",
|
||||
"@babel/preset-env": "^7.18.10",
|
||||
"@jridgewell/trace-mapping": "^0.3.8",
|
||||
"@types/convert-source-map": "^1.5.1",
|
||||
"@types/debug": "^4.1.0",
|
||||
"@types/gensync": "^1.0.0",
|
||||
"@types/resolve": "^1.3.2",
|
||||
"@types/semver": "^5.4.0",
|
||||
"rimraf": "^3.0.0"
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ module.exports = function parse(code, options, client) {
|
||||
}
|
||||
|
||||
if (!isRunningMinSupportedCoreVersion) {
|
||||
throw new Error(`@babel/eslint-parser@${"7.18.2"} does not support @babel/core@${client.getVersion()}. Please upgrade to @babel/core@${minSupportedCoreVersion}.`);
|
||||
throw new Error(`@babel/eslint-parser@${"7.18.9"} does not support @babel/core@${client.getVersion()}. Please upgrade to @babel/core@${minSupportedCoreVersion}.`);
|
||||
}
|
||||
|
||||
const {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/eslint-parser",
|
||||
"version": "7.18.2",
|
||||
"version": "7.18.9",
|
||||
"description": "ESLint parser that allows for linting of experimental syntax transformed by Babel",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"license": "MIT",
|
||||
@@ -36,7 +36,7 @@
|
||||
"semver": "^6.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.18.2",
|
||||
"@babel/core": "^7.18.9",
|
||||
"dedent": "^0.7.0",
|
||||
"eslint": "^7.27.0",
|
||||
"eslint-8": "npm:eslint@^8.0.0"
|
||||
|
||||
+177
-71
@@ -14,21 +14,70 @@ function SourcePos() {
|
||||
};
|
||||
}
|
||||
|
||||
const SPACES_RE = /^[ \t]+$/;
|
||||
|
||||
class Buffer {
|
||||
constructor(map) {
|
||||
this._map = null;
|
||||
this._buf = "";
|
||||
this._str = "";
|
||||
this._appendCount = 0;
|
||||
this._last = 0;
|
||||
this._queue = [];
|
||||
this._queueCursor = 0;
|
||||
this._position = {
|
||||
line: 1,
|
||||
column: 0
|
||||
};
|
||||
this._sourcePosition = SourcePos();
|
||||
this._disallowedPop = null;
|
||||
this._disallowedPop = {
|
||||
identifierName: undefined,
|
||||
line: undefined,
|
||||
column: undefined,
|
||||
filename: undefined,
|
||||
objectReusable: true
|
||||
};
|
||||
this._map = map;
|
||||
|
||||
this._allocQueue();
|
||||
}
|
||||
|
||||
_allocQueue() {
|
||||
const queue = this._queue;
|
||||
|
||||
for (let i = 0; i < 16; i++) {
|
||||
queue.push({
|
||||
char: 0,
|
||||
repeat: 1,
|
||||
line: undefined,
|
||||
column: undefined,
|
||||
identifierName: undefined,
|
||||
filename: ""
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_pushQueue(char, repeat, line, column, identifierName, filename) {
|
||||
const cursor = this._queueCursor;
|
||||
|
||||
if (cursor === this._queue.length) {
|
||||
this._allocQueue();
|
||||
}
|
||||
|
||||
const item = this._queue[cursor];
|
||||
item.char = char;
|
||||
item.repeat = repeat;
|
||||
item.line = line;
|
||||
item.column = column;
|
||||
item.identifierName = identifierName;
|
||||
item.filename = filename;
|
||||
this._queueCursor++;
|
||||
}
|
||||
|
||||
_popQueue() {
|
||||
if (this._queueCursor === 0) {
|
||||
throw new Error("Cannot pop from empty queue");
|
||||
}
|
||||
|
||||
return this._queue[--this._queueCursor];
|
||||
}
|
||||
|
||||
get() {
|
||||
@@ -36,7 +85,7 @@ class Buffer {
|
||||
|
||||
const map = this._map;
|
||||
const result = {
|
||||
code: this._buf.trimRight(),
|
||||
code: (this._buf + this._str).trimRight(),
|
||||
decodedMap: map == null ? void 0 : map.getDecoded(),
|
||||
|
||||
get map() {
|
||||
@@ -69,51 +118,91 @@ class Buffer {
|
||||
return result;
|
||||
}
|
||||
|
||||
append(str) {
|
||||
append(str, maybeNewline) {
|
||||
this._flush();
|
||||
|
||||
const {
|
||||
line,
|
||||
column,
|
||||
filename,
|
||||
identifierName
|
||||
} = this._sourcePosition;
|
||||
|
||||
this._append(str, line, column, identifierName, filename);
|
||||
this._append(str, this._sourcePosition, maybeNewline);
|
||||
}
|
||||
|
||||
queue(str) {
|
||||
if (str === "\n") {
|
||||
while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) {
|
||||
this._queue.shift();
|
||||
appendChar(char) {
|
||||
this._flush();
|
||||
|
||||
this._appendChar(char, 1, this._sourcePosition);
|
||||
}
|
||||
|
||||
queue(char) {
|
||||
if (char === 10) {
|
||||
while (this._queueCursor !== 0) {
|
||||
const char = this._queue[this._queueCursor - 1].char;
|
||||
|
||||
if (char !== 32 && char !== 9) {
|
||||
break;
|
||||
}
|
||||
|
||||
this._queueCursor--;
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
line,
|
||||
column,
|
||||
filename,
|
||||
identifierName
|
||||
} = this._sourcePosition;
|
||||
const sourcePosition = this._sourcePosition;
|
||||
|
||||
this._queue.unshift([str, line, column, identifierName, filename]);
|
||||
this._pushQueue(char, 1, sourcePosition.line, sourcePosition.column, sourcePosition.identifierName, sourcePosition.filename);
|
||||
}
|
||||
|
||||
queueIndentation(str) {
|
||||
this._queue.unshift([str, undefined, undefined, undefined, undefined]);
|
||||
queueIndentation(char, repeat) {
|
||||
this._pushQueue(char, repeat, undefined, undefined, undefined, undefined);
|
||||
}
|
||||
|
||||
_flush() {
|
||||
let item;
|
||||
const queueCursor = this._queueCursor;
|
||||
const queue = this._queue;
|
||||
|
||||
while (item = this._queue.pop()) {
|
||||
this._append(...item);
|
||||
for (let i = 0; i < queueCursor; i++) {
|
||||
const item = queue[i];
|
||||
|
||||
this._appendChar(item.char, item.repeat, item);
|
||||
}
|
||||
|
||||
this._queueCursor = 0;
|
||||
}
|
||||
|
||||
_appendChar(char, repeat, sourcePos) {
|
||||
this._last = char;
|
||||
this._str += repeat > 1 ? String.fromCharCode(char).repeat(repeat) : String.fromCharCode(char);
|
||||
|
||||
if (char !== 10) {
|
||||
this._mark(sourcePos.line, sourcePos.column, sourcePos.identifierName, sourcePos.filename);
|
||||
|
||||
this._position.column += repeat;
|
||||
} else {
|
||||
this._position.line++;
|
||||
this._position.column = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_append(str, line, column, identifierName, filename) {
|
||||
this._buf += str;
|
||||
this._last = str.charCodeAt(str.length - 1);
|
||||
_append(str, sourcePos, maybeNewline) {
|
||||
const len = str.length;
|
||||
this._last = str.charCodeAt(len - 1);
|
||||
|
||||
if (++this._appendCount > 4096) {
|
||||
+this._str;
|
||||
this._buf += this._str;
|
||||
this._str = str;
|
||||
this._appendCount = 0;
|
||||
} else {
|
||||
this._str += str;
|
||||
}
|
||||
|
||||
if (!maybeNewline && !this._map) {
|
||||
this._position.column += len;
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
column,
|
||||
identifierName,
|
||||
filename
|
||||
} = sourcePos;
|
||||
let line = sourcePos.line;
|
||||
let i = str.indexOf("\n");
|
||||
let last = 0;
|
||||
|
||||
@@ -143,41 +232,36 @@ class Buffer {
|
||||
}
|
||||
|
||||
removeTrailingNewline() {
|
||||
if (this._queue.length > 0 && this._queue[0][0] === "\n") {
|
||||
this._queue.shift();
|
||||
const queueCursor = this._queueCursor;
|
||||
|
||||
if (queueCursor !== 0 && this._queue[queueCursor - 1].char === 10) {
|
||||
this._queueCursor--;
|
||||
}
|
||||
}
|
||||
|
||||
removeLastSemicolon() {
|
||||
if (this._queue.length > 0 && this._queue[0][0] === ";") {
|
||||
this._queue.shift();
|
||||
const queueCursor = this._queueCursor;
|
||||
|
||||
if (queueCursor !== 0 && this._queue[queueCursor - 1].char === 59) {
|
||||
this._queueCursor--;
|
||||
}
|
||||
}
|
||||
|
||||
getLastChar() {
|
||||
let last;
|
||||
|
||||
if (this._queue.length > 0) {
|
||||
const str = this._queue[0][0];
|
||||
last = str.charCodeAt(0);
|
||||
} else {
|
||||
last = this._last;
|
||||
}
|
||||
|
||||
return last;
|
||||
const queueCursor = this._queueCursor;
|
||||
return queueCursor !== 0 ? this._queue[queueCursor - 1].char : this._last;
|
||||
}
|
||||
|
||||
endsWithCharAndNewline() {
|
||||
const queue = this._queue;
|
||||
const queueCursor = this._queueCursor;
|
||||
|
||||
if (queue.length > 0) {
|
||||
const last = queue[0][0];
|
||||
const lastCp = last.charCodeAt(0);
|
||||
if (queueCursor !== 0) {
|
||||
const lastCp = queue[queueCursor - 1].char;
|
||||
if (lastCp !== 10) return;
|
||||
|
||||
if (queue.length > 1) {
|
||||
const secondLast = queue[1][0];
|
||||
return secondLast.charCodeAt(0);
|
||||
if (queueCursor > 1) {
|
||||
return queue[queueCursor - 2].char;
|
||||
} else {
|
||||
return this._last;
|
||||
}
|
||||
@@ -185,10 +269,11 @@ class Buffer {
|
||||
}
|
||||
|
||||
hasContent() {
|
||||
return this._queue.length > 0 || !!this._last;
|
||||
return this._queueCursor !== 0 || !!this._last;
|
||||
}
|
||||
|
||||
exactSource(loc, cb) {
|
||||
if (!this._map) return cb();
|
||||
this.source("start", loc);
|
||||
cb();
|
||||
this.source("end", loc);
|
||||
@@ -197,7 +282,7 @@ class Buffer {
|
||||
}
|
||||
|
||||
source(prop, loc) {
|
||||
if (prop && !loc) return;
|
||||
if (!loc) return;
|
||||
|
||||
this._normalizePosition(prop, loc, this._sourcePosition);
|
||||
}
|
||||
@@ -211,43 +296,64 @@ class Buffer {
|
||||
this.source(prop, loc);
|
||||
cb();
|
||||
|
||||
if (!this._disallowedPop || this._disallowedPop.line !== originalLine || this._disallowedPop.column !== originalColumn || this._disallowedPop.filename !== originalFilename) {
|
||||
if (this._disallowedPop.objectReusable || this._disallowedPop.line !== originalLine || this._disallowedPop.column !== originalColumn || this._disallowedPop.filename !== originalFilename) {
|
||||
this._sourcePosition.line = originalLine;
|
||||
this._sourcePosition.column = originalColumn;
|
||||
this._sourcePosition.filename = originalFilename;
|
||||
this._sourcePosition.identifierName = originalIdentifierName;
|
||||
this._disallowedPop = null;
|
||||
this._disallowedPop.objectReusable = true;
|
||||
}
|
||||
}
|
||||
|
||||
_disallowPop(prop, loc) {
|
||||
if (prop && !loc) return;
|
||||
this._disallowedPop = this._normalizePosition(prop, loc, SourcePos());
|
||||
if (!loc) return;
|
||||
const disallowedPop = this._disallowedPop;
|
||||
|
||||
this._normalizePosition(prop, loc, disallowedPop);
|
||||
|
||||
disallowedPop.objectReusable = false;
|
||||
}
|
||||
|
||||
_normalizePosition(prop, loc, targetObj) {
|
||||
const pos = loc ? loc[prop] : null;
|
||||
targetObj.identifierName = prop === "start" && (loc == null ? void 0 : loc.identifierName) || undefined;
|
||||
targetObj.line = pos == null ? void 0 : pos.line;
|
||||
targetObj.column = pos == null ? void 0 : pos.column;
|
||||
targetObj.filename = loc == null ? void 0 : loc.filename;
|
||||
return targetObj;
|
||||
const pos = loc[prop];
|
||||
targetObj.identifierName = prop === "start" && loc.identifierName || undefined;
|
||||
|
||||
if (pos) {
|
||||
targetObj.line = pos.line;
|
||||
targetObj.column = pos.column;
|
||||
targetObj.filename = loc.filename;
|
||||
} else {
|
||||
targetObj.line = null;
|
||||
targetObj.column = null;
|
||||
targetObj.filename = null;
|
||||
}
|
||||
}
|
||||
|
||||
getCurrentColumn() {
|
||||
const extra = this._queue.reduce((acc, item) => item[0] + acc, "");
|
||||
const queue = this._queue;
|
||||
let lastIndex = -1;
|
||||
let len = 0;
|
||||
|
||||
const lastIndex = extra.lastIndexOf("\n");
|
||||
return lastIndex === -1 ? this._position.column + extra.length : extra.length - 1 - lastIndex;
|
||||
for (let i = 0; i < this._queueCursor; i++) {
|
||||
const item = queue[i];
|
||||
|
||||
if (item.char === 10) {
|
||||
lastIndex = i;
|
||||
len += item.repeat;
|
||||
}
|
||||
}
|
||||
|
||||
return lastIndex === -1 ? this._position.column + len : len - 1 - lastIndex;
|
||||
}
|
||||
|
||||
getCurrentLine() {
|
||||
const extra = this._queue.reduce((acc, item) => item[0] + acc, "");
|
||||
|
||||
let count = 0;
|
||||
const queue = this._queue;
|
||||
|
||||
for (let i = 0; i < extra.length; i++) {
|
||||
if (extra[i] === "\n") count++;
|
||||
for (let i = 0; i < this._queueCursor; i++) {
|
||||
if (queue[i].char === 10) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return this._position.line + count;
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ function Program(node) {
|
||||
function BlockStatement(node) {
|
||||
var _node$directives;
|
||||
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
this.printInnerComments(node);
|
||||
const hasDirectives = (_node$directives = node.directives) == null ? void 0 : _node$directives.length;
|
||||
|
||||
@@ -48,7 +48,7 @@ function BlockStatement(node) {
|
||||
this.rightBrace();
|
||||
} else {
|
||||
this.source("end", node.loc);
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ function DirectiveLiteral(node) {
|
||||
}
|
||||
|
||||
function InterpreterDirective(node) {
|
||||
this.token(`#!${node.value}\n`);
|
||||
this.token(`#!${node.value}\n`, true);
|
||||
}
|
||||
|
||||
function Placeholder(node) {
|
||||
|
||||
Generated
Vendored
+15
-15
@@ -67,11 +67,11 @@ function ClassDeclaration(node, parent) {
|
||||
}
|
||||
|
||||
function ClassBody(node) {
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
this.printInnerComments(node);
|
||||
|
||||
if (node.body.length === 0) {
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
} else {
|
||||
this.newline();
|
||||
this.indent();
|
||||
@@ -88,9 +88,9 @@ function ClassProperty(node) {
|
||||
this.tsPrintClassMemberModifiers(node);
|
||||
|
||||
if (node.computed) {
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.print(node.key, node);
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
} else {
|
||||
this._variance(node);
|
||||
|
||||
@@ -98,18 +98,18 @@ function ClassProperty(node) {
|
||||
}
|
||||
|
||||
if (node.optional) {
|
||||
this.token("?");
|
||||
this.tokenChar(63);
|
||||
}
|
||||
|
||||
if (node.definite) {
|
||||
this.token("!");
|
||||
this.tokenChar(33);
|
||||
}
|
||||
|
||||
this.print(node.typeAnnotation, node);
|
||||
|
||||
if (node.value) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(node.value, node);
|
||||
}
|
||||
@@ -126,9 +126,9 @@ function ClassAccessorProperty(node) {
|
||||
this.space();
|
||||
|
||||
if (node.computed) {
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.print(node.key, node);
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
} else {
|
||||
this._variance(node);
|
||||
|
||||
@@ -136,18 +136,18 @@ function ClassAccessorProperty(node) {
|
||||
}
|
||||
|
||||
if (node.optional) {
|
||||
this.token("?");
|
||||
this.tokenChar(63);
|
||||
}
|
||||
|
||||
if (node.definite) {
|
||||
this.token("!");
|
||||
this.tokenChar(33);
|
||||
}
|
||||
|
||||
this.print(node.typeAnnotation, node);
|
||||
|
||||
if (node.value) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(node.value, node);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ function ClassPrivateProperty(node) {
|
||||
|
||||
if (node.value) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(node.value, node);
|
||||
}
|
||||
@@ -201,10 +201,10 @@ function _classMethodHead(node) {
|
||||
function StaticBlock(node) {
|
||||
this.word("static");
|
||||
this.space();
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
|
||||
if (node.body.length === 0) {
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
} else {
|
||||
this.newline();
|
||||
this.printSequence(node.body, node, {
|
||||
|
||||
Generated
Vendored
+29
-29
@@ -64,9 +64,9 @@ function DoExpression(node) {
|
||||
}
|
||||
|
||||
function ParenthesizedExpression(node) {
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(node.expression, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
}
|
||||
|
||||
function UpdateExpression(node) {
|
||||
@@ -82,11 +82,11 @@ function UpdateExpression(node) {
|
||||
function ConditionalExpression(node) {
|
||||
this.print(node.test, node);
|
||||
this.space();
|
||||
this.token("?");
|
||||
this.tokenChar(63);
|
||||
this.space();
|
||||
this.print(node.consequent, node);
|
||||
this.space();
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
this.print(node.alternate, node);
|
||||
}
|
||||
@@ -109,9 +109,9 @@ function NewExpression(node, parent) {
|
||||
this.token("?.");
|
||||
}
|
||||
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.printList(node.arguments, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
}
|
||||
|
||||
function SequenceExpression(node) {
|
||||
@@ -152,15 +152,15 @@ function shouldParenthesizeDecoratorExpression(node) {
|
||||
}
|
||||
|
||||
function Decorator(node) {
|
||||
this.token("@");
|
||||
this.tokenChar(64);
|
||||
const {
|
||||
expression
|
||||
} = node;
|
||||
|
||||
if (shouldParenthesizeDecoratorExpression(expression)) {
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(expression, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
} else {
|
||||
this.print(expression, node);
|
||||
}
|
||||
@@ -186,12 +186,12 @@ function OptionalMemberExpression(node) {
|
||||
}
|
||||
|
||||
if (computed) {
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.print(node.property, node);
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
} else {
|
||||
if (!node.optional) {
|
||||
this.token(".");
|
||||
this.tokenChar(46);
|
||||
}
|
||||
|
||||
this.print(node.property, node);
|
||||
@@ -207,18 +207,18 @@ function OptionalCallExpression(node) {
|
||||
this.token("?.");
|
||||
}
|
||||
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.printList(node.arguments, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
}
|
||||
|
||||
function CallExpression(node) {
|
||||
this.print(node.callee, node);
|
||||
this.print(node.typeArguments, node);
|
||||
this.print(node.typeParameters, node);
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.printList(node.arguments, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
}
|
||||
|
||||
function Import() {
|
||||
@@ -238,7 +238,7 @@ function YieldExpression(node) {
|
||||
this.word("yield");
|
||||
|
||||
if (node.delegate) {
|
||||
this.token("*");
|
||||
this.tokenChar(42);
|
||||
}
|
||||
|
||||
if (node.argument) {
|
||||
@@ -258,10 +258,10 @@ function ExpressionStatement(node) {
|
||||
|
||||
function AssignmentPattern(node) {
|
||||
this.print(node.left, node);
|
||||
if (node.left.optional) this.token("?");
|
||||
if (node.left.optional) this.tokenChar(63);
|
||||
this.print(node.left.typeAnnotation, node);
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(node.right, node);
|
||||
}
|
||||
@@ -270,7 +270,7 @@ function AssignmentExpression(node, parent) {
|
||||
const parens = this.inForStatementInitCounter && node.operator === "in" && !n.needsParens(node, parent);
|
||||
|
||||
if (parens) {
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
}
|
||||
|
||||
this.print(node.left, node);
|
||||
@@ -286,7 +286,7 @@ function AssignmentExpression(node, parent) {
|
||||
this.print(node.right, node);
|
||||
|
||||
if (parens) {
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,38 +310,38 @@ function MemberExpression(node) {
|
||||
}
|
||||
|
||||
if (computed) {
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.print(node.property, node);
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
} else {
|
||||
this.token(".");
|
||||
this.tokenChar(46);
|
||||
this.print(node.property, node);
|
||||
}
|
||||
}
|
||||
|
||||
function MetaProperty(node) {
|
||||
this.print(node.meta, node);
|
||||
this.token(".");
|
||||
this.tokenChar(46);
|
||||
this.print(node.property, node);
|
||||
}
|
||||
|
||||
function PrivateName(node) {
|
||||
this.token("#");
|
||||
this.tokenChar(35);
|
||||
this.print(node.id, node);
|
||||
}
|
||||
|
||||
function V8IntrinsicIdentifier(node) {
|
||||
this.token("%");
|
||||
this.tokenChar(37);
|
||||
this.word(node.name);
|
||||
}
|
||||
|
||||
function ModuleExpression(node) {
|
||||
this.word("module");
|
||||
this.space();
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
|
||||
if (node.body.body.length === 0) {
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
} else {
|
||||
this.newline();
|
||||
this.printSequence(node.body.body, node, {
|
||||
|
||||
+61
-61
@@ -94,9 +94,9 @@ function AnyTypeAnnotation() {
|
||||
}
|
||||
|
||||
function ArrayTypeAnnotation(node) {
|
||||
this.print(node.elementType, node);
|
||||
this.token("[");
|
||||
this.token("]");
|
||||
this.print(node.elementType, node, true);
|
||||
this.tokenChar(91);
|
||||
this.tokenChar(93);
|
||||
}
|
||||
|
||||
function BooleanTypeAnnotation() {
|
||||
@@ -143,16 +143,16 @@ function DeclareFunction(node, parent) {
|
||||
}
|
||||
|
||||
function InferredPredicate() {
|
||||
this.token("%");
|
||||
this.tokenChar(37);
|
||||
this.word("checks");
|
||||
}
|
||||
|
||||
function DeclaredPredicate(node) {
|
||||
this.token("%");
|
||||
this.tokenChar(37);
|
||||
this.word("checks");
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(node.value, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
}
|
||||
|
||||
function DeclareInterface(node) {
|
||||
@@ -175,7 +175,7 @@ function DeclareModuleExports(node) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
this.word("module");
|
||||
this.token(".");
|
||||
this.tokenChar(46);
|
||||
this.word("exports");
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
@@ -307,7 +307,7 @@ function EnumDefaultedMember(node) {
|
||||
id
|
||||
} = node;
|
||||
this.print(id, node);
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
}
|
||||
|
||||
function enumInitializedMember(context, node) {
|
||||
@@ -341,7 +341,7 @@ function FlowExportDeclaration(node) {
|
||||
this.print(declar, node);
|
||||
if (!isStatement(declar)) this.semicolon();
|
||||
} else {
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
|
||||
if (node.specifiers.length) {
|
||||
this.space();
|
||||
@@ -349,7 +349,7 @@ function FlowExportDeclaration(node) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
|
||||
if (node.source) {
|
||||
this.space();
|
||||
@@ -363,21 +363,21 @@ function FlowExportDeclaration(node) {
|
||||
}
|
||||
|
||||
function ExistsTypeAnnotation() {
|
||||
this.token("*");
|
||||
this.tokenChar(42);
|
||||
}
|
||||
|
||||
function FunctionTypeAnnotation(node, parent) {
|
||||
this.print(node.typeParameters, node);
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
|
||||
if (node.this) {
|
||||
this.word("this");
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
this.print(node.this.typeAnnotation, node);
|
||||
|
||||
if (node.params.length || node.rest) {
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
this.space();
|
||||
}
|
||||
}
|
||||
@@ -386,7 +386,7 @@ function FunctionTypeAnnotation(node, parent) {
|
||||
|
||||
if (node.rest) {
|
||||
if (node.params.length) {
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
this.space();
|
||||
}
|
||||
|
||||
@@ -394,10 +394,10 @@ function FunctionTypeAnnotation(node, parent) {
|
||||
this.print(node.rest, node);
|
||||
}
|
||||
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
|
||||
if (parent && (parent.type === "ObjectTypeCallProperty" || parent.type === "DeclareFunction" || parent.type === "ObjectTypeProperty" && parent.method)) {
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
} else {
|
||||
this.space();
|
||||
this.token("=>");
|
||||
@@ -409,10 +409,10 @@ function FunctionTypeAnnotation(node, parent) {
|
||||
|
||||
function FunctionTypeParam(node) {
|
||||
this.print(node.name, node);
|
||||
if (node.optional) this.token("?");
|
||||
if (node.optional) this.tokenChar(63);
|
||||
|
||||
if (node.name) {
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
}
|
||||
|
||||
@@ -421,7 +421,7 @@ function FunctionTypeParam(node) {
|
||||
|
||||
function InterfaceExtends(node) {
|
||||
this.print(node.id, node);
|
||||
this.print(node.typeParameters, node);
|
||||
this.print(node.typeParameters, node, true);
|
||||
}
|
||||
|
||||
function _interfaceish(node) {
|
||||
@@ -458,9 +458,9 @@ function _interfaceish(node) {
|
||||
function _variance(node) {
|
||||
if (node.variance) {
|
||||
if (node.variance.kind === "plus") {
|
||||
this.token("+");
|
||||
this.tokenChar(43);
|
||||
} else if (node.variance.kind === "minus") {
|
||||
this.token("-");
|
||||
this.tokenChar(45);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -474,7 +474,7 @@ function InterfaceDeclaration(node) {
|
||||
|
||||
function andSeparator() {
|
||||
this.space();
|
||||
this.token("&");
|
||||
this.tokenChar(38);
|
||||
this.space();
|
||||
}
|
||||
|
||||
@@ -507,7 +507,7 @@ function EmptyTypeAnnotation() {
|
||||
}
|
||||
|
||||
function NullableTypeAnnotation(node) {
|
||||
this.token("?");
|
||||
this.tokenChar(63);
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
@@ -524,9 +524,9 @@ function ThisTypeAnnotation() {
|
||||
}
|
||||
|
||||
function TupleTypeAnnotation(node) {
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.printList(node.types, node);
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
}
|
||||
|
||||
function TypeofTypeAnnotation(node) {
|
||||
@@ -541,23 +541,23 @@ function TypeAlias(node) {
|
||||
this.print(node.id, node);
|
||||
this.print(node.typeParameters, node);
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(node.right, node);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
function TypeAnnotation(node) {
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
if (node.optional) this.token("?");
|
||||
if (node.optional) this.tokenChar(63);
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
function TypeParameterInstantiation(node) {
|
||||
this.token("<");
|
||||
this.tokenChar(60);
|
||||
this.printList(node.params, node, {});
|
||||
this.token(">");
|
||||
this.tokenChar(62);
|
||||
}
|
||||
|
||||
function TypeParameter(node) {
|
||||
@@ -571,7 +571,7 @@ function TypeParameter(node) {
|
||||
|
||||
if (node.default) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(node.default, node);
|
||||
}
|
||||
@@ -586,14 +586,14 @@ function OpaqueType(node) {
|
||||
this.print(node.typeParameters, node);
|
||||
|
||||
if (node.supertype) {
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
this.print(node.supertype, node);
|
||||
}
|
||||
|
||||
if (node.impltype) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(node.impltype, node);
|
||||
}
|
||||
@@ -605,7 +605,7 @@ function ObjectTypeAnnotation(node) {
|
||||
if (node.exact) {
|
||||
this.token("{|");
|
||||
} else {
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
}
|
||||
|
||||
const props = [...node.properties, ...(node.callProperties || []), ...(node.indexers || []), ...(node.internalSlots || [])];
|
||||
@@ -621,7 +621,7 @@ function ObjectTypeAnnotation(node) {
|
||||
statement: true,
|
||||
iterator: () => {
|
||||
if (props.length !== 1 || node.inexact) {
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
this.space();
|
||||
}
|
||||
}
|
||||
@@ -643,7 +643,7 @@ function ObjectTypeAnnotation(node) {
|
||||
if (node.exact) {
|
||||
this.token("|}");
|
||||
} else {
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -653,15 +653,15 @@ function ObjectTypeInternalSlot(node) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("[");
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.tokenChar(91);
|
||||
this.print(node.id, node);
|
||||
this.token("]");
|
||||
this.token("]");
|
||||
if (node.optional) this.token("?");
|
||||
this.tokenChar(93);
|
||||
this.tokenChar(93);
|
||||
if (node.optional) this.tokenChar(63);
|
||||
|
||||
if (!node.method) {
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
}
|
||||
|
||||
@@ -685,17 +685,17 @@ function ObjectTypeIndexer(node) {
|
||||
|
||||
this._variance(node);
|
||||
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
|
||||
if (node.id) {
|
||||
this.print(node.id, node);
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.key, node);
|
||||
this.token("]");
|
||||
this.token(":");
|
||||
this.tokenChar(93);
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
this.print(node.value, node);
|
||||
}
|
||||
@@ -719,10 +719,10 @@ function ObjectTypeProperty(node) {
|
||||
this._variance(node);
|
||||
|
||||
this.print(node.key, node);
|
||||
if (node.optional) this.token("?");
|
||||
if (node.optional) this.tokenChar(63);
|
||||
|
||||
if (!node.method) {
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
}
|
||||
|
||||
@@ -736,7 +736,7 @@ function ObjectTypeSpreadProperty(node) {
|
||||
|
||||
function QualifiedTypeIdentifier(node) {
|
||||
this.print(node.qualification, node);
|
||||
this.token(".");
|
||||
this.tokenChar(46);
|
||||
this.print(node.id, node);
|
||||
}
|
||||
|
||||
@@ -746,7 +746,7 @@ function SymbolTypeAnnotation() {
|
||||
|
||||
function orSeparator() {
|
||||
this.space();
|
||||
this.token("|");
|
||||
this.tokenChar(124);
|
||||
this.space();
|
||||
}
|
||||
|
||||
@@ -757,17 +757,17 @@ function UnionTypeAnnotation(node) {
|
||||
}
|
||||
|
||||
function TypeCastExpression(node) {
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(node.expression, node);
|
||||
this.print(node.typeAnnotation, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
}
|
||||
|
||||
function Variance(node) {
|
||||
if (node.kind === "plus") {
|
||||
this.token("+");
|
||||
this.tokenChar(43);
|
||||
} else {
|
||||
this.token("-");
|
||||
this.tokenChar(45);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -776,10 +776,10 @@ function VoidTypeAnnotation() {
|
||||
}
|
||||
|
||||
function IndexedAccessType(node) {
|
||||
this.print(node.objectType, node);
|
||||
this.token("[");
|
||||
this.print(node.objectType, node, true);
|
||||
this.tokenChar(91);
|
||||
this.print(node.indexType, node);
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
}
|
||||
|
||||
function OptionalIndexedAccessType(node) {
|
||||
@@ -789,7 +789,7 @@ function OptionalIndexedAccessType(node) {
|
||||
this.token("?.");
|
||||
}
|
||||
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.print(node.indexType, node);
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
}
|
||||
+15
-15
@@ -23,7 +23,7 @@ function JSXAttribute(node) {
|
||||
this.print(node.name, node);
|
||||
|
||||
if (node.value) {
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.print(node.value, node);
|
||||
}
|
||||
}
|
||||
@@ -34,34 +34,34 @@ function JSXIdentifier(node) {
|
||||
|
||||
function JSXNamespacedName(node) {
|
||||
this.print(node.namespace, node);
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.print(node.name, node);
|
||||
}
|
||||
|
||||
function JSXMemberExpression(node) {
|
||||
this.print(node.object, node);
|
||||
this.token(".");
|
||||
this.tokenChar(46);
|
||||
this.print(node.property, node);
|
||||
}
|
||||
|
||||
function JSXSpreadAttribute(node) {
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
this.token("...");
|
||||
this.print(node.argument, node);
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
|
||||
function JSXExpressionContainer(node) {
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
this.print(node.expression, node);
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
|
||||
function JSXSpreadChild(node) {
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
this.token("...");
|
||||
this.print(node.expression, node);
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
|
||||
function JSXText(node) {
|
||||
@@ -93,7 +93,7 @@ function spaceSeparator() {
|
||||
}
|
||||
|
||||
function JSXOpeningElement(node) {
|
||||
this.token("<");
|
||||
this.tokenChar(60);
|
||||
this.print(node.name, node);
|
||||
this.print(node.typeParameters, node);
|
||||
|
||||
@@ -108,14 +108,14 @@ function JSXOpeningElement(node) {
|
||||
this.space();
|
||||
this.token("/>");
|
||||
} else {
|
||||
this.token(">");
|
||||
this.tokenChar(62);
|
||||
}
|
||||
}
|
||||
|
||||
function JSXClosingElement(node) {
|
||||
this.token("</");
|
||||
this.print(node.name, node);
|
||||
this.token(">");
|
||||
this.tokenChar(62);
|
||||
}
|
||||
|
||||
function JSXEmptyExpression(node) {
|
||||
@@ -135,11 +135,11 @@ function JSXFragment(node) {
|
||||
}
|
||||
|
||||
function JSXOpeningFragment() {
|
||||
this.token("<");
|
||||
this.token(">");
|
||||
this.tokenChar(60);
|
||||
this.tokenChar(62);
|
||||
}
|
||||
|
||||
function JSXClosingFragment() {
|
||||
this.token("</");
|
||||
this.token(">");
|
||||
this.tokenChar(62);
|
||||
}
|
||||
Generated
Vendored
+11
-11
@@ -20,12 +20,12 @@ const {
|
||||
|
||||
function _params(node) {
|
||||
this.print(node.typeParameters, node);
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
|
||||
this._parameters(node.params, node);
|
||||
|
||||
this.token(")");
|
||||
this.print(node.returnType, node);
|
||||
this.tokenChar(41);
|
||||
this.print(node.returnType, node, node.type === "ArrowFunctionExpression");
|
||||
}
|
||||
|
||||
function _parameters(parameters, parent) {
|
||||
@@ -33,7 +33,7 @@ function _parameters(parameters, parent) {
|
||||
this._param(parameters[i], parent);
|
||||
|
||||
if (i < parameters.length - 1) {
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
this.space();
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ function _param(parameter, parent) {
|
||||
this.print(parameter, parent);
|
||||
|
||||
if (parameter.optional) {
|
||||
this.token("?");
|
||||
this.tokenChar(63);
|
||||
}
|
||||
|
||||
this.print(parameter.typeAnnotation, parameter);
|
||||
@@ -68,20 +68,20 @@ function _methodHead(node) {
|
||||
|
||||
if (kind === "method" || kind === "init") {
|
||||
if (node.generator) {
|
||||
this.token("*");
|
||||
this.tokenChar(42);
|
||||
}
|
||||
}
|
||||
|
||||
if (node.computed) {
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.print(key, node);
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
} else {
|
||||
this.print(key, node);
|
||||
}
|
||||
|
||||
if (node.optional) {
|
||||
this.token("?");
|
||||
this.tokenChar(63);
|
||||
}
|
||||
|
||||
this._params(node);
|
||||
@@ -90,7 +90,7 @@ function _methodHead(node) {
|
||||
function _predicate(node) {
|
||||
if (node.predicate) {
|
||||
if (!node.returnType) {
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
}
|
||||
|
||||
this.space();
|
||||
@@ -105,7 +105,7 @@ function _functionHead(node) {
|
||||
}
|
||||
|
||||
this.word("function");
|
||||
if (node.generator) this.token("*");
|
||||
if (node.generator) this.tokenChar(42);
|
||||
this.printInnerComments(node);
|
||||
this.space();
|
||||
|
||||
|
||||
Generated
Vendored
+12
-12
@@ -67,7 +67,7 @@ function ExportSpecifier(node) {
|
||||
}
|
||||
|
||||
function ExportNamespaceSpecifier(node) {
|
||||
this.token("*");
|
||||
this.tokenChar(42);
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.space();
|
||||
@@ -83,7 +83,7 @@ function ExportAllDeclaration(node) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("*");
|
||||
this.tokenChar(42);
|
||||
this.space();
|
||||
this.word("from");
|
||||
this.space();
|
||||
@@ -122,7 +122,7 @@ function ExportNamedDeclaration(node) {
|
||||
this.print(specifiers.shift(), node);
|
||||
|
||||
if (specifiers.length) {
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
this.space();
|
||||
}
|
||||
} else {
|
||||
@@ -131,7 +131,7 @@ function ExportNamedDeclaration(node) {
|
||||
}
|
||||
|
||||
if (specifiers.length || !specifiers.length && !hasSpecial) {
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
|
||||
if (specifiers.length) {
|
||||
this.space();
|
||||
@@ -139,7 +139,7 @@ function ExportNamedDeclaration(node) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
|
||||
if (node.source) {
|
||||
@@ -189,7 +189,7 @@ function ImportDeclaration(node) {
|
||||
this.print(specifiers.shift(), node);
|
||||
|
||||
if (specifiers.length) {
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
this.space();
|
||||
}
|
||||
} else {
|
||||
@@ -198,14 +198,14 @@ function ImportDeclaration(node) {
|
||||
}
|
||||
|
||||
if (specifiers.length) {
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
this.space();
|
||||
this.printList(specifiers, node);
|
||||
this.space();
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
} else if (isTypeKind && !hasSpecifiers) {
|
||||
this.token("{");
|
||||
this.token("}");
|
||||
this.tokenChar(123);
|
||||
this.tokenChar(125);
|
||||
}
|
||||
|
||||
if (hasSpecifiers || isTypeKind) {
|
||||
@@ -231,13 +231,13 @@ function ImportDeclaration(node) {
|
||||
|
||||
function ImportAttribute(node) {
|
||||
this.print(node.key);
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
this.print(node.value);
|
||||
}
|
||||
|
||||
function ImportNamespaceSpecifier(node) {
|
||||
this.token("*");
|
||||
this.tokenChar(42);
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.space();
|
||||
|
||||
Generated
Vendored
+29
-29
@@ -34,23 +34,23 @@ const {
|
||||
function WithStatement(node) {
|
||||
this.word("with");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(node.object, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
this.printBlock(node);
|
||||
}
|
||||
|
||||
function IfStatement(node) {
|
||||
this.word("if");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(node.test, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
this.space();
|
||||
const needsBlock = node.alternate && isIfStatement(getLastStatement(node.consequent));
|
||||
|
||||
if (needsBlock) {
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
this.newline();
|
||||
this.indent();
|
||||
}
|
||||
@@ -60,7 +60,7 @@ function IfStatement(node) {
|
||||
if (needsBlock) {
|
||||
this.dedent();
|
||||
this.newline();
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
|
||||
if (node.alternate) {
|
||||
@@ -86,34 +86,34 @@ function getLastStatement(statement) {
|
||||
function ForStatement(node) {
|
||||
this.word("for");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.inForStatementInitCounter++;
|
||||
this.print(node.init, node);
|
||||
this.inForStatementInitCounter--;
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
|
||||
if (node.test) {
|
||||
this.space();
|
||||
this.print(node.test, node);
|
||||
}
|
||||
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
|
||||
if (node.update) {
|
||||
this.space();
|
||||
this.print(node.update, node);
|
||||
}
|
||||
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
this.printBlock(node);
|
||||
}
|
||||
|
||||
function WhileStatement(node) {
|
||||
this.word("while");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(node.test, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
this.printBlock(node);
|
||||
}
|
||||
|
||||
@@ -127,13 +127,13 @@ function ForXStatement(node) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(node.left, node);
|
||||
this.space();
|
||||
this.word(isForOf ? "of" : "in");
|
||||
this.space();
|
||||
this.print(node.right, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
this.printBlock(node);
|
||||
}
|
||||
|
||||
@@ -149,9 +149,9 @@ function DoWhileStatement(node) {
|
||||
this.space();
|
||||
this.word("while");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(node.test, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ function ThrowStatement(node) {
|
||||
|
||||
function LabeledStatement(node) {
|
||||
this.print(node.label, node);
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
@@ -216,10 +216,10 @@ function CatchClause(node) {
|
||||
this.space();
|
||||
|
||||
if (node.param) {
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(node.param, node);
|
||||
this.print(node.param.typeAnnotation, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
this.space();
|
||||
}
|
||||
|
||||
@@ -229,11 +229,11 @@ function CatchClause(node) {
|
||||
function SwitchStatement(node) {
|
||||
this.word("switch");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(node.discriminant, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
this.space();
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
this.printSequence(node.cases, node, {
|
||||
indent: true,
|
||||
|
||||
@@ -242,7 +242,7 @@ function SwitchStatement(node) {
|
||||
}
|
||||
|
||||
});
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
|
||||
function SwitchCase(node) {
|
||||
@@ -250,10 +250,10 @@ function SwitchCase(node) {
|
||||
this.word("case");
|
||||
this.space();
|
||||
this.print(node.test, node);
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
} else {
|
||||
this.word("default");
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
}
|
||||
|
||||
if (node.consequent.length) {
|
||||
@@ -270,7 +270,7 @@ function DebuggerStatement() {
|
||||
}
|
||||
|
||||
function variableDeclarationIndent() {
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
this.newline();
|
||||
|
||||
if (this.endsWith(10)) {
|
||||
@@ -279,7 +279,7 @@ function variableDeclarationIndent() {
|
||||
}
|
||||
|
||||
function constDeclarationIndent() {
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
this.newline();
|
||||
|
||||
if (this.endsWith(10)) {
|
||||
@@ -328,12 +328,12 @@ function VariableDeclaration(node, parent) {
|
||||
|
||||
function VariableDeclarator(node) {
|
||||
this.print(node.id, node);
|
||||
if (node.definite) this.token("!");
|
||||
if (node.definite) this.tokenChar(33);
|
||||
this.print(node.id.typeAnnotation, node);
|
||||
|
||||
if (node.init) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(node.init, node);
|
||||
}
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -17,7 +17,7 @@ function TemplateElement(node, parent) {
|
||||
const isFirst = parent.quasis[0] === node;
|
||||
const isLast = parent.quasis[parent.quasis.length - 1] === node;
|
||||
const value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${");
|
||||
this.token(value);
|
||||
this.token(value, true);
|
||||
}
|
||||
|
||||
function TemplateLiteral(node) {
|
||||
|
||||
+12
-12
@@ -40,7 +40,7 @@ function Identifier(node) {
|
||||
}
|
||||
|
||||
function ArgumentPlaceholder() {
|
||||
this.token("?");
|
||||
this.tokenChar(63);
|
||||
}
|
||||
|
||||
function RestElement(node) {
|
||||
@@ -50,7 +50,7 @@ function RestElement(node) {
|
||||
|
||||
function ObjectExpression(node) {
|
||||
const props = node.properties;
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
this.printInnerComments(node);
|
||||
|
||||
if (props.length) {
|
||||
@@ -62,7 +62,7 @@ function ObjectExpression(node) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
|
||||
function ObjectMethod(node) {
|
||||
@@ -78,9 +78,9 @@ function ObjectProperty(node) {
|
||||
this.printJoin(node.decorators, node);
|
||||
|
||||
if (node.computed) {
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.print(node.key, node);
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
} else {
|
||||
if (isAssignmentPattern(node.value) && isIdentifier(node.key) && node.key.name === node.value.left.name) {
|
||||
this.print(node.value, node);
|
||||
@@ -94,7 +94,7 @@ function ObjectProperty(node) {
|
||||
}
|
||||
}
|
||||
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
this.print(node.value, node);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ function ObjectProperty(node) {
|
||||
function ArrayExpression(node) {
|
||||
const elems = node.elements;
|
||||
const len = elems.length;
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.printInnerComments(node);
|
||||
|
||||
for (let i = 0; i < elems.length; i++) {
|
||||
@@ -111,13 +111,13 @@ function ArrayExpression(node) {
|
||||
if (elem) {
|
||||
if (i > 0) this.space();
|
||||
this.print(elem, node);
|
||||
if (i < len - 1) this.token(",");
|
||||
if (i < len - 1) this.tokenChar(44);
|
||||
} else {
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
}
|
||||
}
|
||||
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
}
|
||||
|
||||
function RecordExpression(node) {
|
||||
@@ -175,7 +175,7 @@ function TupleExpression(node) {
|
||||
if (elem) {
|
||||
if (i > 0) this.space();
|
||||
this.print(elem, node);
|
||||
if (i < len - 1) this.token(",");
|
||||
if (i < len - 1) this.tokenChar(44);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,5 +272,5 @@ function PipelineBareFunction(node) {
|
||||
}
|
||||
|
||||
function PipelinePrimaryTopicReference() {
|
||||
this.token("#");
|
||||
this.tokenChar(35);
|
||||
}
|
||||
Generated
Vendored
+62
-62
@@ -73,21 +73,21 @@ exports.tsPrintSignatureDeclarationBase = tsPrintSignatureDeclarationBase;
|
||||
exports.tsPrintTypeLiteralOrInterfaceBody = tsPrintTypeLiteralOrInterfaceBody;
|
||||
|
||||
function TSTypeAnnotation(node) {
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
if (node.optional) this.token("?");
|
||||
if (node.optional) this.tokenChar(63);
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
function TSTypeParameterInstantiation(node, parent) {
|
||||
this.token("<");
|
||||
this.tokenChar(60);
|
||||
this.printList(node.params, node, {});
|
||||
|
||||
if (parent.type === "ArrowFunctionExpression" && node.params.length === 1) {
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
}
|
||||
|
||||
this.token(">");
|
||||
this.tokenChar(62);
|
||||
}
|
||||
|
||||
function TSTypeParameter(node) {
|
||||
@@ -112,7 +112,7 @@ function TSTypeParameter(node) {
|
||||
|
||||
if (node.default) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(node.default, node);
|
||||
}
|
||||
@@ -140,31 +140,31 @@ function TSDeclareFunction(node) {
|
||||
|
||||
this._functionHead(node);
|
||||
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
}
|
||||
|
||||
function TSDeclareMethod(node) {
|
||||
this._classMethodHead(node);
|
||||
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
}
|
||||
|
||||
function TSQualifiedName(node) {
|
||||
this.print(node.left, node);
|
||||
this.token(".");
|
||||
this.tokenChar(46);
|
||||
this.print(node.right, node);
|
||||
}
|
||||
|
||||
function TSCallSignatureDeclaration(node) {
|
||||
this.tsPrintSignatureDeclarationBase(node);
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
}
|
||||
|
||||
function TSConstructSignatureDeclaration(node) {
|
||||
this.word("new");
|
||||
this.space();
|
||||
this.tsPrintSignatureDeclarationBase(node);
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
}
|
||||
|
||||
function TSPropertySignature(node) {
|
||||
@@ -183,27 +183,27 @@ function TSPropertySignature(node) {
|
||||
|
||||
if (initializer) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(initializer, node);
|
||||
}
|
||||
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
}
|
||||
|
||||
function tsPrintPropertyOrMethodName(node) {
|
||||
if (node.computed) {
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
}
|
||||
|
||||
this.print(node.key, node);
|
||||
|
||||
if (node.computed) {
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
}
|
||||
|
||||
if (node.optional) {
|
||||
this.token("?");
|
||||
this.tokenChar(63);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ function TSMethodSignature(node) {
|
||||
|
||||
this.tsPrintPropertyOrMethodName(node);
|
||||
this.tsPrintSignatureDeclarationBase(node);
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
}
|
||||
|
||||
function TSIndexSignature(node) {
|
||||
@@ -238,13 +238,13 @@ function TSIndexSignature(node) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
|
||||
this._parameters(node.parameters, node);
|
||||
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
this.print(node.typeAnnotation, node);
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
}
|
||||
|
||||
function TSAnyKeyword() {
|
||||
@@ -324,11 +324,11 @@ function tsPrintFunctionOrConstructorType(node) {
|
||||
} = node;
|
||||
const parameters = node.parameters;
|
||||
this.print(typeParameters, node);
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
|
||||
this._parameters(parameters, node);
|
||||
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
this.space();
|
||||
this.token("=>");
|
||||
this.space();
|
||||
@@ -337,8 +337,8 @@ function tsPrintFunctionOrConstructorType(node) {
|
||||
}
|
||||
|
||||
function TSTypeReference(node) {
|
||||
this.print(node.typeName, node);
|
||||
this.print(node.typeParameters, node);
|
||||
this.print(node.typeName, node, true);
|
||||
this.print(node.typeParameters, node, true);
|
||||
}
|
||||
|
||||
function TSTypePredicate(node) {
|
||||
@@ -395,19 +395,19 @@ function tsPrintBraced(printer, members, node) {
|
||||
}
|
||||
|
||||
function TSArrayType(node) {
|
||||
this.print(node.elementType, node);
|
||||
this.print(node.elementType, node, true);
|
||||
this.token("[]");
|
||||
}
|
||||
|
||||
function TSTupleType(node) {
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.printList(node.elementTypes, node);
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
}
|
||||
|
||||
function TSOptionalType(node) {
|
||||
this.print(node.typeAnnotation, node);
|
||||
this.token("?");
|
||||
this.tokenChar(63);
|
||||
}
|
||||
|
||||
function TSRestType(node) {
|
||||
@@ -417,8 +417,8 @@ function TSRestType(node) {
|
||||
|
||||
function TSNamedTupleMember(node) {
|
||||
this.print(node.label, node);
|
||||
if (node.optional) this.token("?");
|
||||
this.token(":");
|
||||
if (node.optional) this.tokenChar(63);
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
this.print(node.elementType, node);
|
||||
}
|
||||
@@ -449,11 +449,11 @@ function TSConditionalType(node) {
|
||||
this.space();
|
||||
this.print(node.extendsType);
|
||||
this.space();
|
||||
this.token("?");
|
||||
this.tokenChar(63);
|
||||
this.space();
|
||||
this.print(node.trueType);
|
||||
this.space();
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
this.print(node.falseType);
|
||||
}
|
||||
@@ -465,9 +465,9 @@ function TSInferType(node) {
|
||||
}
|
||||
|
||||
function TSParenthesizedType(node) {
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(node.typeAnnotation, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
}
|
||||
|
||||
function TSTypeOperator(node) {
|
||||
@@ -477,10 +477,10 @@ function TSTypeOperator(node) {
|
||||
}
|
||||
|
||||
function TSIndexedAccessType(node) {
|
||||
this.print(node.objectType, node);
|
||||
this.token("[");
|
||||
this.print(node.objectType, node, true);
|
||||
this.tokenChar(91);
|
||||
this.print(node.indexType, node);
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
}
|
||||
|
||||
function TSMappedType(node) {
|
||||
@@ -490,7 +490,7 @@ function TSMappedType(node) {
|
||||
readonly,
|
||||
typeParameter
|
||||
} = node;
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
this.space();
|
||||
|
||||
if (readonly) {
|
||||
@@ -499,7 +499,7 @@ function TSMappedType(node) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.token("[");
|
||||
this.tokenChar(91);
|
||||
this.word(typeParameter.name);
|
||||
this.space();
|
||||
this.word("in");
|
||||
@@ -513,18 +513,18 @@ function TSMappedType(node) {
|
||||
this.print(nameType, node);
|
||||
}
|
||||
|
||||
this.token("]");
|
||||
this.tokenChar(93);
|
||||
|
||||
if (optional) {
|
||||
tokenIfPlusMinus(this, optional);
|
||||
this.token("?");
|
||||
this.tokenChar(63);
|
||||
}
|
||||
|
||||
this.token(":");
|
||||
this.tokenChar(58);
|
||||
this.space();
|
||||
this.print(node.typeAnnotation, node);
|
||||
this.space();
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
|
||||
function tokenIfPlusMinus(self, tok) {
|
||||
@@ -594,10 +594,10 @@ function TSTypeAliasDeclaration(node) {
|
||||
this.print(id, node);
|
||||
this.print(typeParameters, node);
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(typeAnnotation, node);
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
}
|
||||
|
||||
function TSAsExpression(node) {
|
||||
@@ -617,9 +617,9 @@ function TSTypeAssertion(node) {
|
||||
typeAnnotation,
|
||||
expression
|
||||
} = node;
|
||||
this.token("<");
|
||||
this.tokenChar(60);
|
||||
this.print(typeAnnotation, node);
|
||||
this.token(">");
|
||||
this.tokenChar(62);
|
||||
this.space();
|
||||
this.print(expression, node);
|
||||
}
|
||||
@@ -663,12 +663,12 @@ function TSEnumMember(node) {
|
||||
|
||||
if (initializer) {
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(initializer, node);
|
||||
}
|
||||
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
}
|
||||
|
||||
function TSModuleDeclaration(node) {
|
||||
@@ -690,14 +690,14 @@ function TSModuleDeclaration(node) {
|
||||
this.print(id, node);
|
||||
|
||||
if (!node.body) {
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
return;
|
||||
}
|
||||
|
||||
let body = node.body;
|
||||
|
||||
while (body.type === "TSModuleDeclaration") {
|
||||
this.token(".");
|
||||
this.tokenChar(46);
|
||||
this.print(body.id, body);
|
||||
body = body.body;
|
||||
}
|
||||
@@ -717,12 +717,12 @@ function TSImportType(node) {
|
||||
typeParameters
|
||||
} = node;
|
||||
this.word("import");
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.print(argument, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
|
||||
if (qualifier) {
|
||||
this.token(".");
|
||||
this.tokenChar(46);
|
||||
this.print(qualifier, node);
|
||||
}
|
||||
|
||||
@@ -747,30 +747,30 @@ function TSImportEqualsDeclaration(node) {
|
||||
this.space();
|
||||
this.print(id, node);
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(moduleReference, node);
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
}
|
||||
|
||||
function TSExternalModuleReference(node) {
|
||||
this.token("require(");
|
||||
this.print(node.expression, node);
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
}
|
||||
|
||||
function TSNonNullExpression(node) {
|
||||
this.print(node.expression, node);
|
||||
this.token("!");
|
||||
this.tokenChar(33);
|
||||
}
|
||||
|
||||
function TSExportAssignment(node) {
|
||||
this.word("export");
|
||||
this.space();
|
||||
this.token("=");
|
||||
this.tokenChar(61);
|
||||
this.space();
|
||||
this.print(node.expression, node);
|
||||
this.token(";");
|
||||
this.tokenChar(59);
|
||||
}
|
||||
|
||||
function TSNamespaceExportDeclaration(node) {
|
||||
@@ -789,11 +789,11 @@ function tsPrintSignatureDeclarationBase(node) {
|
||||
} = node;
|
||||
const parameters = node.parameters;
|
||||
this.print(typeParameters, node);
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
|
||||
this._parameters(parameters, node);
|
||||
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
const returnType = node.typeAnnotation;
|
||||
this.print(returnType, node);
|
||||
}
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ function normalizeOptions(code, opts) {
|
||||
|
||||
format.shouldPrintComment = format.shouldPrintComment || (() => format.comments);
|
||||
} else {
|
||||
format.shouldPrintComment = format.shouldPrintComment || (value => format.comments || value.indexOf("@license") >= 0 || value.indexOf("@preserve") >= 0);
|
||||
format.shouldPrintComment = format.shouldPrintComment || (value => format.comments || value.includes("@license") || value.includes("@preserve"));
|
||||
}
|
||||
|
||||
if (format.compact === "auto") {
|
||||
|
||||
+5
-17
@@ -50,7 +50,6 @@ function expandAliases(obj) {
|
||||
|
||||
const expandedParens = expandAliases(parens);
|
||||
const expandedWhitespaceNodes = expandAliases(whitespace.nodes);
|
||||
const expandedWhitespaceList = expandAliases(whitespace.list);
|
||||
|
||||
function find(obj, node, parent, printStack) {
|
||||
const fn = obj[node.type];
|
||||
@@ -72,32 +71,21 @@ function needsWhitespace(node, parent, type) {
|
||||
node = node.expression;
|
||||
}
|
||||
|
||||
let linesInfo = find(expandedWhitespaceNodes, node, parent);
|
||||
const flag = find(expandedWhitespaceNodes, node, parent);
|
||||
|
||||
if (!linesInfo) {
|
||||
const items = find(expandedWhitespaceList, node, parent);
|
||||
|
||||
if (items) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
linesInfo = needsWhitespace(items[i], node, type);
|
||||
if (linesInfo) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof linesInfo === "object" && linesInfo !== null) {
|
||||
return linesInfo[type] || false;
|
||||
if (typeof flag === "number") {
|
||||
return (flag & type) !== 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function needsWhitespaceBefore(node, parent) {
|
||||
return needsWhitespace(node, parent, "before");
|
||||
return needsWhitespace(node, parent, 1);
|
||||
}
|
||||
|
||||
function needsWhitespaceAfter(node, parent) {
|
||||
return needsWhitespace(node, parent, "after");
|
||||
return needsWhitespace(node, parent, 2);
|
||||
}
|
||||
|
||||
function needsParens(node, parent, printStack) {
|
||||
|
||||
+16
-31
@@ -123,6 +123,7 @@ function NullableTypeAnnotation(node, parent) {
|
||||
}
|
||||
|
||||
function FunctionTypeAnnotation(node, parent, printStack) {
|
||||
if (printStack.length < 3) return;
|
||||
return isUnionTypeAnnotation(parent) || isIntersectionTypeAnnotation(parent) || isArrayTypeAnnotation(parent) || isTypeAnnotation(parent) && isArrowFunctionExpression(printStack[printStack.length - 3]);
|
||||
}
|
||||
|
||||
@@ -131,16 +132,11 @@ function UpdateExpression(node, parent) {
|
||||
}
|
||||
|
||||
function ObjectExpression(node, parent, printStack) {
|
||||
return isFirstInContext(printStack, {
|
||||
expressionStatement: true,
|
||||
arrowBody: true
|
||||
});
|
||||
return isFirstInContext(printStack, 1 | 2);
|
||||
}
|
||||
|
||||
function DoExpression(node, parent, printStack) {
|
||||
return !node.async && isFirstInContext(printStack, {
|
||||
expressionStatement: true
|
||||
});
|
||||
return !node.async && isFirstInContext(printStack, 1);
|
||||
}
|
||||
|
||||
function Binary(node, parent) {
|
||||
@@ -217,10 +213,7 @@ function YieldExpression(node, parent) {
|
||||
}
|
||||
|
||||
function ClassExpression(node, parent, printStack) {
|
||||
return isFirstInContext(printStack, {
|
||||
expressionStatement: true,
|
||||
exportDefault: true
|
||||
});
|
||||
return isFirstInContext(printStack, 1 | 4);
|
||||
}
|
||||
|
||||
function UnaryLike(node, parent) {
|
||||
@@ -231,10 +224,7 @@ function UnaryLike(node, parent) {
|
||||
}
|
||||
|
||||
function FunctionExpression(node, parent, printStack) {
|
||||
return isFirstInContext(printStack, {
|
||||
expressionStatement: true,
|
||||
exportDefault: true
|
||||
});
|
||||
return isFirstInContext(printStack, 1 | 4);
|
||||
}
|
||||
|
||||
function ArrowFunctionExpression(node, parent) {
|
||||
@@ -301,26 +291,21 @@ function Identifier(node, parent, printStack) {
|
||||
computed: true,
|
||||
optional: false
|
||||
});
|
||||
return isFirstInContext(printStack, {
|
||||
expressionStatement: isFollowedByBracket,
|
||||
forHead: isFollowedByBracket,
|
||||
forInHead: isFollowedByBracket,
|
||||
forOfHead: true
|
||||
});
|
||||
return isFirstInContext(printStack, isFollowedByBracket ? 1 | 8 | 16 | 32 : 32);
|
||||
}
|
||||
|
||||
return node.name === "async" && isForOfStatement(parent) && node === parent.left;
|
||||
}
|
||||
|
||||
function isFirstInContext(printStack, {
|
||||
expressionStatement = false,
|
||||
arrowBody = false,
|
||||
exportDefault = false,
|
||||
forHead = false,
|
||||
forInHead = false,
|
||||
forOfHead = false
|
||||
}) {
|
||||
function isFirstInContext(printStack, checkParam) {
|
||||
const expressionStatement = checkParam & 1;
|
||||
const arrowBody = checkParam & 2;
|
||||
const exportDefault = checkParam & 4;
|
||||
const forHead = checkParam & 8;
|
||||
const forInHead = checkParam & 16;
|
||||
const forOfHead = checkParam & 32;
|
||||
let i = printStack.length - 1;
|
||||
if (i <= 0) return;
|
||||
let node = printStack[i];
|
||||
i--;
|
||||
let parent = printStack[i];
|
||||
@@ -342,13 +327,13 @@ function isFirstInContext(printStack, {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasPostfixPart(node, parent) && !isNewExpression(parent) || isSequenceExpression(parent) && parent.expressions[0] === node || isUpdateExpression(parent) && !parent.prefix || isConditional(parent, {
|
||||
if (i > 0 && (hasPostfixPart(node, parent) && !isNewExpression(parent) || isSequenceExpression(parent) && parent.expressions[0] === node || isUpdateExpression(parent) && !parent.prefix || isConditional(parent, {
|
||||
test: node
|
||||
}) || isBinary(parent, {
|
||||
left: node
|
||||
}) || isAssignmentExpression(parent, {
|
||||
left: node
|
||||
})) {
|
||||
}))) {
|
||||
node = parent;
|
||||
i--;
|
||||
parent = printStack[i];
|
||||
|
||||
+37
-73
@@ -3,7 +3,7 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.nodes = exports.list = void 0;
|
||||
exports.nodes = void 0;
|
||||
|
||||
var _t = require("@babel/types");
|
||||
|
||||
@@ -24,30 +24,42 @@ const {
|
||||
isStringLiteral
|
||||
} = _t;
|
||||
|
||||
function crawl(node, state = {}) {
|
||||
function crawlInternal(node, state) {
|
||||
if (!node) return state;
|
||||
|
||||
if (isMemberExpression(node) || isOptionalMemberExpression(node)) {
|
||||
crawl(node.object, state);
|
||||
if (node.computed) crawl(node.property, state);
|
||||
crawlInternal(node.object, state);
|
||||
if (node.computed) crawlInternal(node.property, state);
|
||||
} else if (isBinary(node) || isAssignmentExpression(node)) {
|
||||
crawl(node.left, state);
|
||||
crawl(node.right, state);
|
||||
crawlInternal(node.left, state);
|
||||
crawlInternal(node.right, state);
|
||||
} else if (isCallExpression(node) || isOptionalCallExpression(node)) {
|
||||
state.hasCall = true;
|
||||
crawl(node.callee, state);
|
||||
crawlInternal(node.callee, state);
|
||||
} else if (isFunction(node)) {
|
||||
state.hasFunction = true;
|
||||
} else if (isIdentifier(node)) {
|
||||
state.hasHelper = state.hasHelper || isHelper(node.callee);
|
||||
state.hasHelper = state.hasHelper || node.callee && isHelper(node.callee);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
function crawl(node) {
|
||||
return crawlInternal(node, {
|
||||
hasCall: false,
|
||||
hasFunction: false,
|
||||
hasHelper: false
|
||||
});
|
||||
}
|
||||
|
||||
function isHelper(node) {
|
||||
if (!node) return false;
|
||||
|
||||
if (isMemberExpression(node)) {
|
||||
return isHelper(node.object) || isHelper(node.property);
|
||||
} else if (isIdentifier(node)) {
|
||||
return node.name === "require" || node.name[0] === "_";
|
||||
return node.name === "require" || node.name.charCodeAt(0) === 95;
|
||||
} else if (isCallExpression(node)) {
|
||||
return isHelper(node.callee);
|
||||
} else if (isBinary(node) || isAssignmentExpression(node)) {
|
||||
@@ -66,51 +78,35 @@ const nodes = {
|
||||
const state = crawl(node.right);
|
||||
|
||||
if (state.hasCall && state.hasHelper || state.hasFunction) {
|
||||
return {
|
||||
before: state.hasFunction,
|
||||
after: true
|
||||
};
|
||||
return state.hasFunction ? 1 | 2 : 2;
|
||||
}
|
||||
},
|
||||
|
||||
SwitchCase(node, parent) {
|
||||
return {
|
||||
before: !!node.consequent.length || parent.cases[0] === node,
|
||||
after: !node.consequent.length && parent.cases[parent.cases.length - 1] === node
|
||||
};
|
||||
return (!!node.consequent.length || parent.cases[0] === node ? 1 : 0) | (!node.consequent.length && parent.cases[parent.cases.length - 1] === node ? 2 : 0);
|
||||
},
|
||||
|
||||
LogicalExpression(node) {
|
||||
if (isFunction(node.left) || isFunction(node.right)) {
|
||||
return {
|
||||
after: true
|
||||
};
|
||||
return 2;
|
||||
}
|
||||
},
|
||||
|
||||
Literal(node) {
|
||||
if (isStringLiteral(node) && node.value === "use strict") {
|
||||
return {
|
||||
after: true
|
||||
};
|
||||
return 2;
|
||||
}
|
||||
},
|
||||
|
||||
CallExpression(node) {
|
||||
if (isFunction(node.callee) || isHelper(node)) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
return 1 | 2;
|
||||
}
|
||||
},
|
||||
|
||||
OptionalCallExpression(node) {
|
||||
if (isFunction(node.callee)) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
return 1 | 2;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -119,26 +115,20 @@ const nodes = {
|
||||
const declar = node.declarations[i];
|
||||
let enabled = isHelper(declar.id) && !isType(declar.init);
|
||||
|
||||
if (!enabled) {
|
||||
if (!enabled && declar.init) {
|
||||
const state = crawl(declar.init);
|
||||
enabled = isHelper(declar.init) && state.hasCall || state.hasFunction;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
return 1 | 2;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
IfStatement(node) {
|
||||
if (isBlockStatement(node.consequent)) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
return 1 | 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,9 +137,7 @@ exports.nodes = nodes;
|
||||
|
||||
nodes.ObjectProperty = nodes.ObjectTypeProperty = nodes.ObjectMethod = function (node, parent) {
|
||||
if (parent.properties[0] === node) {
|
||||
return {
|
||||
before: true
|
||||
};
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -157,9 +145,7 @@ nodes.ObjectTypeCallProperty = function (node, parent) {
|
||||
var _parent$properties;
|
||||
|
||||
if (parent.callProperties[0] === node && !((_parent$properties = parent.properties) != null && _parent$properties.length)) {
|
||||
return {
|
||||
before: true
|
||||
};
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -167,9 +153,7 @@ nodes.ObjectTypeIndexer = function (node, parent) {
|
||||
var _parent$properties2, _parent$callPropertie;
|
||||
|
||||
if (parent.indexers[0] === node && !((_parent$properties2 = parent.properties) != null && _parent$properties2.length) && !((_parent$callPropertie = parent.callProperties) != null && _parent$callPropertie.length)) {
|
||||
return {
|
||||
before: true
|
||||
};
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -177,34 +161,14 @@ nodes.ObjectTypeInternalSlot = function (node, parent) {
|
||||
var _parent$properties3, _parent$callPropertie2, _parent$indexers;
|
||||
|
||||
if (parent.internalSlots[0] === node && !((_parent$properties3 = parent.properties) != null && _parent$properties3.length) && !((_parent$callPropertie2 = parent.callProperties) != null && _parent$callPropertie2.length) && !((_parent$indexers = parent.indexers) != null && _parent$indexers.length)) {
|
||||
return {
|
||||
before: true
|
||||
};
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
const list = {
|
||||
VariableDeclaration(node) {
|
||||
return node.declarations.map(decl => decl.init);
|
||||
},
|
||||
|
||||
ArrayExpression(node) {
|
||||
return node.elements;
|
||||
},
|
||||
|
||||
ObjectExpression(node) {
|
||||
return node.properties;
|
||||
}
|
||||
|
||||
};
|
||||
exports.list = list;
|
||||
[["Function", true], ["Class", true], ["Loop", true], ["LabeledStatement", true], ["SwitchStatement", true], ["TryStatement", true]].forEach(function ([type, amounts]) {
|
||||
[type].concat(FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) {
|
||||
nodes[type] = function () {
|
||||
return {
|
||||
after: amounts,
|
||||
before: amounts
|
||||
};
|
||||
};
|
||||
const ret = amounts ? 1 | 2 : 0;
|
||||
|
||||
nodes[type] = () => ret;
|
||||
});
|
||||
});
|
||||
+148
-73
@@ -9,15 +9,8 @@ var _buffer = require("./buffer");
|
||||
|
||||
var n = require("./node");
|
||||
|
||||
var _t = require("@babel/types");
|
||||
|
||||
var generatorFunctions = require("./generators");
|
||||
|
||||
const {
|
||||
isProgram,
|
||||
isFile,
|
||||
isEmptyStatement
|
||||
} = _t;
|
||||
const SCIENTIFIC_NOTATION = /e/i;
|
||||
const ZERO_DECIMAL_INTEGER = /\.0+$/;
|
||||
const NON_DECIMAL_LITERAL = /^0[box]/;
|
||||
@@ -33,15 +26,19 @@ class Printer {
|
||||
this.inForStatementInitCounter = 0;
|
||||
this._printStack = [];
|
||||
this._indent = 0;
|
||||
this._indentChar = 0;
|
||||
this._indentRepeat = 0;
|
||||
this._insideAux = false;
|
||||
this._parenPushNewlineState = null;
|
||||
this._noLineTerminator = false;
|
||||
this._printAuxAfterOnNextUserNode = false;
|
||||
this._printedComments = new WeakSet();
|
||||
this._printedComments = new Set();
|
||||
this._endsWithInteger = false;
|
||||
this._endsWithWord = false;
|
||||
this.format = format;
|
||||
this._buf = new _buffer.default(map);
|
||||
this._indentChar = format.indent.style.charCodeAt(0);
|
||||
this._indentRepeat = format.indent.style.length;
|
||||
}
|
||||
|
||||
generate(ast) {
|
||||
@@ -65,7 +62,11 @@ class Printer {
|
||||
semicolon(force = false) {
|
||||
this._maybeAddAuxComment();
|
||||
|
||||
this._append(";", !force);
|
||||
if (force) {
|
||||
this._appendChar(59);
|
||||
} else {
|
||||
this._queue(59);
|
||||
}
|
||||
}
|
||||
|
||||
rightBrace() {
|
||||
@@ -73,7 +74,7 @@ class Printer {
|
||||
this._buf.removeLastSemicolon();
|
||||
}
|
||||
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
|
||||
space(force = false) {
|
||||
@@ -91,13 +92,13 @@ class Printer {
|
||||
}
|
||||
|
||||
word(str) {
|
||||
if (this._endsWithWord || this.endsWith(47) && str.charCodeAt(0) === 47) {
|
||||
if (this._endsWithWord || str.charCodeAt(0) === 47 && this.endsWith(47)) {
|
||||
this._space();
|
||||
}
|
||||
|
||||
this._maybeAddAuxComment();
|
||||
|
||||
this._append(str);
|
||||
this._append(str, false);
|
||||
|
||||
this._endsWithWord = true;
|
||||
}
|
||||
@@ -107,17 +108,29 @@ class Printer {
|
||||
this._endsWithInteger = Number.isInteger(+str) && !NON_DECIMAL_LITERAL.test(str) && !SCIENTIFIC_NOTATION.test(str) && !ZERO_DECIMAL_INTEGER.test(str) && str.charCodeAt(str.length - 1) !== 46;
|
||||
}
|
||||
|
||||
token(str) {
|
||||
token(str, maybeNewline = false) {
|
||||
const lastChar = this.getLastChar();
|
||||
const strFirst = str.charCodeAt(0);
|
||||
|
||||
if (str === "--" && lastChar === 33 || strFirst === 43 && lastChar === 43 || strFirst === 45 && lastChar === 45 || strFirst === 46 && this._endsWithInteger) {
|
||||
if (lastChar === 33 && str === "--" || strFirst === 43 && lastChar === 43 || strFirst === 45 && lastChar === 45 || strFirst === 46 && this._endsWithInteger) {
|
||||
this._space();
|
||||
}
|
||||
|
||||
this._maybeAddAuxComment();
|
||||
|
||||
this._append(str);
|
||||
this._append(str, maybeNewline);
|
||||
}
|
||||
|
||||
tokenChar(char) {
|
||||
const lastChar = this.getLastChar();
|
||||
|
||||
if (char === 43 && lastChar === 43 || char === 45 && lastChar === 45 || char === 46 && this._endsWithInteger) {
|
||||
this._space();
|
||||
}
|
||||
|
||||
this._maybeAddAuxComment();
|
||||
|
||||
this._appendChar(char);
|
||||
}
|
||||
|
||||
newline(i = 1) {
|
||||
@@ -177,61 +190,103 @@ class Printer {
|
||||
}
|
||||
|
||||
_space() {
|
||||
this._append(" ", true);
|
||||
this._queue(32);
|
||||
}
|
||||
|
||||
_newline() {
|
||||
this._append("\n", true);
|
||||
this._queue(10);
|
||||
}
|
||||
|
||||
_append(str, queue = false) {
|
||||
_append(str, maybeNewline) {
|
||||
this._maybeAddParen(str);
|
||||
|
||||
this._maybeIndent(str);
|
||||
this._maybeIndent(str.charCodeAt(0));
|
||||
|
||||
this._buf.append(str, maybeNewline);
|
||||
|
||||
if (queue) this._buf.queue(str);else this._buf.append(str);
|
||||
this._endsWithWord = false;
|
||||
this._endsWithInteger = false;
|
||||
}
|
||||
|
||||
_maybeIndent(str) {
|
||||
if (this._indent && this.endsWith(10) && str.charCodeAt(0) !== 10) {
|
||||
this._buf.queueIndentation(this._getIndent());
|
||||
_appendChar(char) {
|
||||
this._maybeAddParenChar(char);
|
||||
|
||||
this._maybeIndent(char);
|
||||
|
||||
this._buf.appendChar(char);
|
||||
|
||||
this._endsWithWord = false;
|
||||
this._endsWithInteger = false;
|
||||
}
|
||||
|
||||
_queue(char) {
|
||||
this._maybeAddParenChar(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._indentChar, this._getIndent());
|
||||
}
|
||||
}
|
||||
|
||||
_maybeAddParenChar(char) {
|
||||
const parenPushNewlineState = this._parenPushNewlineState;
|
||||
if (!parenPushNewlineState) return;
|
||||
|
||||
if (char === 32) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (char !== 10) {
|
||||
this._parenPushNewlineState = null;
|
||||
return;
|
||||
}
|
||||
|
||||
this.tokenChar(40);
|
||||
this.indent();
|
||||
parenPushNewlineState.printed = true;
|
||||
}
|
||||
|
||||
_maybeAddParen(str) {
|
||||
const parenPushNewlineState = this._parenPushNewlineState;
|
||||
if (!parenPushNewlineState) return;
|
||||
const len = str.length;
|
||||
let i;
|
||||
|
||||
for (i = 0; i < str.length && str[i] === " "; i++) continue;
|
||||
for (i = 0; i < len && str.charCodeAt(i) === 32; i++) continue;
|
||||
|
||||
if (i === str.length) {
|
||||
if (i === len) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cha = str[i];
|
||||
const cha = str.charCodeAt(i);
|
||||
|
||||
if (cha !== "\n") {
|
||||
if (cha !== "/" || i + 1 === str.length) {
|
||||
if (cha !== 10) {
|
||||
if (cha !== 47 || i + 1 === len) {
|
||||
this._parenPushNewlineState = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const chaPost = str[i + 1];
|
||||
const chaPost = str.charCodeAt(i + 1);
|
||||
|
||||
if (chaPost === "*") {
|
||||
if (PURE_ANNOTATION_RE.test(str.slice(i + 2, str.length - 2))) {
|
||||
if (chaPost === 42) {
|
||||
if (PURE_ANNOTATION_RE.test(str.slice(i + 2, len - 2))) {
|
||||
return;
|
||||
}
|
||||
} else if (chaPost !== "/") {
|
||||
} else if (chaPost !== 47) {
|
||||
this._parenPushNewlineState = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.token("(");
|
||||
this.tokenChar(40);
|
||||
this.indent();
|
||||
parenPushNewlineState.printed = true;
|
||||
}
|
||||
@@ -250,7 +305,7 @@ class Printer {
|
||||
}
|
||||
|
||||
_getIndent() {
|
||||
return this.format.indent.style.repeat(this._indent);
|
||||
return this._indentRepeat * this._indent;
|
||||
}
|
||||
|
||||
printTerminatorless(node, parent, isLabel) {
|
||||
@@ -268,54 +323,64 @@ class Printer {
|
||||
if (terminatorState.printed) {
|
||||
this.dedent();
|
||||
this.newline();
|
||||
this.token(")");
|
||||
this.tokenChar(41);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print(node, parent) {
|
||||
print(node, parent, noLineTerminator) {
|
||||
if (!node) return;
|
||||
const oldConcise = this.format.concise;
|
||||
const nodeType = node.type;
|
||||
const format = this.format;
|
||||
const oldConcise = format.concise;
|
||||
|
||||
if (node._compact) {
|
||||
this.format.concise = true;
|
||||
format.concise = true;
|
||||
}
|
||||
|
||||
const printMethod = this[node.type];
|
||||
const printMethod = this[nodeType];
|
||||
|
||||
if (!printMethod) {
|
||||
throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node == null ? void 0 : node.constructor.name)}`);
|
||||
if (printMethod === undefined) {
|
||||
throw new ReferenceError(`unknown node of type ${JSON.stringify(nodeType)} with constructor ${JSON.stringify(node.constructor.name)}`);
|
||||
}
|
||||
|
||||
this._printStack.push(node);
|
||||
|
||||
const oldInAux = this._insideAux;
|
||||
this._insideAux = !node.loc;
|
||||
this._insideAux = node.loc == undefined;
|
||||
|
||||
this._maybeAddAuxComment(this._insideAux && !oldInAux);
|
||||
|
||||
let shouldPrintParens = needsParens(node, parent, this._printStack);
|
||||
let shouldPrintParens;
|
||||
|
||||
if (this.format.retainFunctionParens && node.type === "FunctionExpression" && node.extra && node.extra.parenthesized) {
|
||||
if (format.retainFunctionParens && nodeType === "FunctionExpression" && node.extra && node.extra.parenthesized) {
|
||||
shouldPrintParens = true;
|
||||
} else {
|
||||
shouldPrintParens = needsParens(node, parent, this._printStack);
|
||||
}
|
||||
|
||||
if (shouldPrintParens) this.token("(");
|
||||
if (shouldPrintParens) this.tokenChar(40);
|
||||
|
||||
this._printLeadingComments(node);
|
||||
|
||||
const loc = isProgram(node) || isFile(node) ? null : node.loc;
|
||||
this.withSource("start", loc, () => {
|
||||
printMethod.call(this, node, parent);
|
||||
});
|
||||
const loc = nodeType === "Program" || nodeType === "File" ? null : node.loc;
|
||||
this.withSource("start", loc, printMethod.bind(this, node, parent));
|
||||
|
||||
this._printTrailingComments(node);
|
||||
if (noLineTerminator && !this._noLineTerminator) {
|
||||
this._noLineTerminator = true;
|
||||
|
||||
if (shouldPrintParens) this.token(")");
|
||||
this._printTrailingComments(node);
|
||||
|
||||
this._noLineTerminator = false;
|
||||
} else {
|
||||
this._printTrailingComments(node);
|
||||
}
|
||||
|
||||
if (shouldPrintParens) this.tokenChar(41);
|
||||
|
||||
this._printStack.pop();
|
||||
|
||||
this.format.concise = oldConcise;
|
||||
format.concise = oldConcise;
|
||||
this._insideAux = oldInAux;
|
||||
}
|
||||
|
||||
@@ -364,8 +429,9 @@ class Printer {
|
||||
const newlineOpts = {
|
||||
addNewlines: opts.addNewlines
|
||||
};
|
||||
const len = nodes.length;
|
||||
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
for (let i = 0; i < len; i++) {
|
||||
const node = nodes[i];
|
||||
if (!node) continue;
|
||||
if (opts.statement) this._printNewline(true, node, parent, newlineOpts);
|
||||
@@ -375,7 +441,7 @@ class Printer {
|
||||
opts.iterator(node, i);
|
||||
}
|
||||
|
||||
if (opts.separator && i < nodes.length - 1) {
|
||||
if (opts.separator && i < len - 1) {
|
||||
opts.separator.call(this);
|
||||
}
|
||||
|
||||
@@ -395,7 +461,7 @@ class Printer {
|
||||
printBlock(parent) {
|
||||
const node = parent.body;
|
||||
|
||||
if (!isEmptyStatement(node)) {
|
||||
if (node.type !== "EmptyStatement") {
|
||||
this.space();
|
||||
}
|
||||
|
||||
@@ -455,13 +521,13 @@ class Printer {
|
||||
}
|
||||
|
||||
_getComments(leading, node) {
|
||||
return node && (leading ? node.leadingComments : node.trailingComments) || [];
|
||||
return node && (leading ? node.leadingComments : node.trailingComments) || null;
|
||||
}
|
||||
|
||||
_printComment(comment, skipNewLines) {
|
||||
if (!this.format.shouldPrintComment(comment.value)) return;
|
||||
if (comment.ignore) return;
|
||||
if (this._printedComments.has(comment)) return;
|
||||
if (!this.format.shouldPrintComment(comment.value)) return;
|
||||
|
||||
this._printedComments.add(comment);
|
||||
|
||||
@@ -474,26 +540,35 @@ class Printer {
|
||||
this.space();
|
||||
}
|
||||
|
||||
let val = !isBlockComment && !this._noLineTerminator ? `//${comment.value}\n` : `/*${comment.value}*/`;
|
||||
let val;
|
||||
let maybeNewline = false;
|
||||
|
||||
if (isBlockComment && this.format.indent.adjustMultilineComment) {
|
||||
var _comment$loc;
|
||||
if (isBlockComment) {
|
||||
val = `/*${comment.value}*/`;
|
||||
|
||||
const offset = (_comment$loc = comment.loc) == null ? void 0 : _comment$loc.start.column;
|
||||
if (this.format.indent.adjustMultilineComment) {
|
||||
var _comment$loc;
|
||||
|
||||
if (offset) {
|
||||
const newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
||||
val = val.replace(newlineRegex, "\n");
|
||||
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");
|
||||
}
|
||||
|
||||
const indentSize = Math.max(this._getIndent(), this.format.retainLines ? 0 : this._buf.getCurrentColumn());
|
||||
val = val.replace(/\n(?!$)/g, `\n${" ".repeat(indentSize)}`);
|
||||
maybeNewline = true;
|
||||
}
|
||||
|
||||
const indentSize = Math.max(this._getIndent().length, this.format.retainLines ? 0 : this._buf.getCurrentColumn());
|
||||
val = val.replace(/\n(?!$)/g, `\n${" ".repeat(indentSize)}`);
|
||||
} else if (!this._noLineTerminator) {
|
||||
val = `//${comment.value}\n`;
|
||||
maybeNewline = true;
|
||||
} else {
|
||||
val = `/*${comment.value}*/`;
|
||||
}
|
||||
|
||||
if (this.endsWith(47)) this._space();
|
||||
this.withSource("start", comment.loc, () => {
|
||||
this._append(val);
|
||||
});
|
||||
this.withSource("start", comment.loc, this._append.bind(this, val, maybeNewline));
|
||||
if (printNewLines) this.newline(1);
|
||||
}
|
||||
|
||||
@@ -516,11 +591,11 @@ class Printer {
|
||||
this.space();
|
||||
this.word("assert");
|
||||
this.space();
|
||||
this.token("{");
|
||||
this.tokenChar(123);
|
||||
this.space();
|
||||
this.printList(node.assertions, node);
|
||||
this.space();
|
||||
this.token("}");
|
||||
this.tokenChar(125);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,6 +609,6 @@ var _default = Printer;
|
||||
exports.default = _default;
|
||||
|
||||
function commaSeparator() {
|
||||
this.token(",");
|
||||
this.tokenChar(44);
|
||||
this.space();
|
||||
}
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/generator",
|
||||
"version": "7.18.7",
|
||||
"version": "7.18.12",
|
||||
"description": "Turns an AST into code.",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"license": "MIT",
|
||||
@@ -19,13 +19,13 @@
|
||||
"lib"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.18.7",
|
||||
"@babel/types": "^7.18.10",
|
||||
"@jridgewell/gen-mapping": "^0.3.2",
|
||||
"jsesc": "^2.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-fixtures": "^7.18.6",
|
||||
"@babel/parser": "^7.18.6",
|
||||
"@babel/parser": "^7.18.11",
|
||||
"@jridgewell/trace-mapping": "^0.3.8",
|
||||
"@types/jsesc": "^2.5.0",
|
||||
"charcodes": "^0.2.0"
|
||||
|
||||
Generated
Vendored
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-compilation-targets",
|
||||
"version": "7.18.6",
|
||||
"version": "7.18.9",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"license": "MIT",
|
||||
"description": "Helper functions on Babel compilation targets",
|
||||
@@ -22,7 +22,7 @@
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/compat-data": "^7.18.6",
|
||||
"@babel/compat-data": "^7.18.8",
|
||||
"@babel/helper-validator-option": "^7.18.6",
|
||||
"browserslist": "^4.20.2",
|
||||
"semver": "^6.3.0"
|
||||
@@ -31,7 +31,7 @@
|
||||
"@babel/core": "^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.18.6",
|
||||
"@babel/core": "^7.18.9",
|
||||
"@babel/helper-plugin-test-runner": "^7.18.6",
|
||||
"@types/semver": "^5.5.0"
|
||||
},
|
||||
|
||||
Generated
Vendored
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-environment-visitor",
|
||||
"version": "7.18.6",
|
||||
"version": "7.18.9",
|
||||
"description": "Helper visitor to only visit nodes in the current 'this' context",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -18,8 +18,8 @@
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/traverse": "^7.18.6",
|
||||
"@babel/types": "^7.18.6"
|
||||
"@babel/traverse": "^7.18.9",
|
||||
"@babel/types": "^7.18.9"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-function-name",
|
||||
"version": "7.18.6",
|
||||
"version": "7.18.9",
|
||||
"description": "Helper function to change the property 'name' of every function",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -15,7 +15,7 @@
|
||||
"main": "./lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/template": "^7.18.6",
|
||||
"@babel/types": "^7.18.6"
|
||||
"@babel/types": "^7.18.9"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
|
||||
Generated
Vendored
+4
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-module-transforms",
|
||||
"version": "7.18.8",
|
||||
"version": "7.18.9",
|
||||
"description": "Babel helper functions for implementing ES6 module transformations",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-module-transforms",
|
||||
@@ -15,14 +15,14 @@
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-environment-visitor": "^7.18.6",
|
||||
"@babel/helper-environment-visitor": "^7.18.9",
|
||||
"@babel/helper-module-imports": "^7.18.6",
|
||||
"@babel/helper-simple-access": "^7.18.6",
|
||||
"@babel/helper-split-export-declaration": "^7.18.6",
|
||||
"@babel/helper-validator-identifier": "^7.18.6",
|
||||
"@babel/template": "^7.18.6",
|
||||
"@babel/traverse": "^7.18.8",
|
||||
"@babel/types": "^7.18.8"
|
||||
"@babel/traverse": "^7.18.9",
|
||||
"@babel/types": "^7.18.9"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helper-plugin-utils",
|
||||
"version": "7.18.6",
|
||||
"version": "7.18.9",
|
||||
"description": "General utilities for plugins to use",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-plugin-utils",
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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.
|
||||
+328
@@ -0,0 +1,328 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.readCodePoint = readCodePoint;
|
||||
exports.readInt = readInt;
|
||||
exports.readStringContents = readStringContents;
|
||||
|
||||
var _isDigit = function isDigit(code) {
|
||||
return code >= 48 && code <= 57;
|
||||
};
|
||||
|
||||
const forbiddenNumericSeparatorSiblings = {
|
||||
decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
|
||||
hex: new Set([46, 88, 95, 120])
|
||||
};
|
||||
const isAllowedNumericSeparatorSibling = {
|
||||
bin: ch => ch === 48 || ch === 49,
|
||||
oct: ch => ch >= 48 && ch <= 55,
|
||||
dec: ch => ch >= 48 && ch <= 57,
|
||||
hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
|
||||
};
|
||||
|
||||
function readStringContents(type, input, pos, lineStart, curLine, errors) {
|
||||
const initialPos = pos;
|
||||
const initialLineStart = lineStart;
|
||||
const initialCurLine = curLine;
|
||||
let out = "";
|
||||
let containsInvalid = false;
|
||||
let chunkStart = pos;
|
||||
const {
|
||||
length
|
||||
} = input;
|
||||
|
||||
for (;;) {
|
||||
if (pos >= length) {
|
||||
errors.unterminated(initialPos, initialLineStart, initialCurLine);
|
||||
out += input.slice(chunkStart, pos);
|
||||
break;
|
||||
}
|
||||
|
||||
const ch = input.charCodeAt(pos);
|
||||
|
||||
if (isStringEnd(type, ch, input, pos)) {
|
||||
out += input.slice(chunkStart, pos);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ch === 92) {
|
||||
out += input.slice(chunkStart, pos);
|
||||
let escaped;
|
||||
({
|
||||
ch: escaped,
|
||||
pos,
|
||||
lineStart,
|
||||
curLine
|
||||
} = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors));
|
||||
|
||||
if (escaped === null) {
|
||||
containsInvalid = true;
|
||||
} else {
|
||||
out += escaped;
|
||||
}
|
||||
|
||||
chunkStart = pos;
|
||||
} else if (ch === 8232 || ch === 8233) {
|
||||
++pos;
|
||||
++curLine;
|
||||
lineStart = pos;
|
||||
} else if (ch === 10 || ch === 13) {
|
||||
if (type === "template") {
|
||||
out += input.slice(chunkStart, pos) + "\n";
|
||||
++pos;
|
||||
|
||||
if (ch === 13 && input.charCodeAt(pos) === 10) {
|
||||
++pos;
|
||||
}
|
||||
|
||||
++curLine;
|
||||
chunkStart = lineStart = pos;
|
||||
} else {
|
||||
errors.unterminated(initialPos, initialLineStart, initialCurLine);
|
||||
}
|
||||
} else {
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
pos,
|
||||
str: out,
|
||||
containsInvalid,
|
||||
lineStart,
|
||||
curLine
|
||||
};
|
||||
}
|
||||
|
||||
function isStringEnd(type, ch, input, pos) {
|
||||
if (type === "template") {
|
||||
return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
|
||||
}
|
||||
|
||||
return ch === (type === "double" ? 34 : 39);
|
||||
}
|
||||
|
||||
function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
|
||||
const throwOnInvalid = !inTemplate;
|
||||
pos++;
|
||||
|
||||
const res = ch => ({
|
||||
pos,
|
||||
ch,
|
||||
lineStart,
|
||||
curLine
|
||||
});
|
||||
|
||||
const ch = input.charCodeAt(pos++);
|
||||
|
||||
switch (ch) {
|
||||
case 110:
|
||||
return res("\n");
|
||||
|
||||
case 114:
|
||||
return res("\r");
|
||||
|
||||
case 120:
|
||||
{
|
||||
let code;
|
||||
({
|
||||
code,
|
||||
pos
|
||||
} = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
|
||||
return res(code === null ? null : String.fromCharCode(code));
|
||||
}
|
||||
|
||||
case 117:
|
||||
{
|
||||
let code;
|
||||
({
|
||||
code,
|
||||
pos
|
||||
} = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
|
||||
return res(code === null ? null : String.fromCodePoint(code));
|
||||
}
|
||||
|
||||
case 116:
|
||||
return res("\t");
|
||||
|
||||
case 98:
|
||||
return res("\b");
|
||||
|
||||
case 118:
|
||||
return res("\u000b");
|
||||
|
||||
case 102:
|
||||
return res("\f");
|
||||
|
||||
case 13:
|
||||
if (input.charCodeAt(pos) === 10) {
|
||||
++pos;
|
||||
}
|
||||
|
||||
case 10:
|
||||
lineStart = pos;
|
||||
++curLine;
|
||||
|
||||
case 8232:
|
||||
case 8233:
|
||||
return res("");
|
||||
|
||||
case 56:
|
||||
case 57:
|
||||
if (inTemplate) {
|
||||
return res(null);
|
||||
} else {
|
||||
errors.strictNumericEscape(pos - 1, lineStart, curLine);
|
||||
}
|
||||
|
||||
default:
|
||||
if (ch >= 48 && ch <= 55) {
|
||||
const startPos = pos - 1;
|
||||
const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
|
||||
let octalStr = match[0];
|
||||
let octal = parseInt(octalStr, 8);
|
||||
|
||||
if (octal > 255) {
|
||||
octalStr = octalStr.slice(0, -1);
|
||||
octal = parseInt(octalStr, 8);
|
||||
}
|
||||
|
||||
pos += octalStr.length - 1;
|
||||
const next = input.charCodeAt(pos);
|
||||
|
||||
if (octalStr !== "0" || next === 56 || next === 57) {
|
||||
if (inTemplate) {
|
||||
return res(null);
|
||||
} else {
|
||||
errors.strictNumericEscape(startPos, lineStart, curLine);
|
||||
}
|
||||
}
|
||||
|
||||
return res(String.fromCharCode(octal));
|
||||
}
|
||||
|
||||
return res(String.fromCharCode(ch));
|
||||
}
|
||||
}
|
||||
|
||||
function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
|
||||
const initialPos = pos;
|
||||
let n;
|
||||
({
|
||||
n,
|
||||
pos
|
||||
} = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors));
|
||||
|
||||
if (n === null) {
|
||||
if (throwOnInvalid) {
|
||||
errors.invalidEscapeSequence(initialPos, lineStart, curLine);
|
||||
} else {
|
||||
pos = initialPos - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
code: n,
|
||||
pos
|
||||
};
|
||||
}
|
||||
|
||||
function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors) {
|
||||
const start = pos;
|
||||
const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
|
||||
const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
|
||||
let invalid = false;
|
||||
let total = 0;
|
||||
|
||||
for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
|
||||
const code = input.charCodeAt(pos);
|
||||
let val;
|
||||
|
||||
if (code === 95 && allowNumSeparator !== "bail") {
|
||||
const prev = input.charCodeAt(pos - 1);
|
||||
const next = input.charCodeAt(pos + 1);
|
||||
|
||||
if (!allowNumSeparator) {
|
||||
errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
|
||||
} else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
|
||||
errors.unexpectedNumericSeparator(pos, lineStart, curLine);
|
||||
}
|
||||
|
||||
++pos;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code >= 97) {
|
||||
val = code - 97 + 10;
|
||||
} else if (code >= 65) {
|
||||
val = code - 65 + 10;
|
||||
} else if (_isDigit(code)) {
|
||||
val = code - 48;
|
||||
} else {
|
||||
val = Infinity;
|
||||
}
|
||||
|
||||
if (val >= radix) {
|
||||
if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
|
||||
val = 0;
|
||||
} else if (forceLen) {
|
||||
val = 0;
|
||||
invalid = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
++pos;
|
||||
total = total * radix + val;
|
||||
}
|
||||
|
||||
if (pos === start || len != null && pos - start !== len || invalid) {
|
||||
return {
|
||||
n: null,
|
||||
pos
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
n: total,
|
||||
pos
|
||||
};
|
||||
}
|
||||
|
||||
function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
|
||||
const ch = input.charCodeAt(pos);
|
||||
let code;
|
||||
|
||||
if (ch === 123) {
|
||||
++pos;
|
||||
({
|
||||
code,
|
||||
pos
|
||||
} = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
|
||||
++pos;
|
||||
|
||||
if (code !== null && code > 0x10ffff) {
|
||||
if (throwOnInvalid) {
|
||||
errors.invalidCodePoint(pos, lineStart, curLine);
|
||||
} else {
|
||||
return {
|
||||
code: null,
|
||||
pos
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
({
|
||||
code,
|
||||
pos
|
||||
} = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
|
||||
}
|
||||
|
||||
return {
|
||||
code,
|
||||
pos
|
||||
};
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "@babel/helper-string-parser",
|
||||
"version": "7.18.10",
|
||||
"description": "A utility package to parse strings",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-helper-string-parser"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-string-parser",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"devDependencies": {
|
||||
"charcodes": "^0.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"exports": {
|
||||
".": "./lib/index.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"type": "commonjs"
|
||||
}
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helpers",
|
||||
"version": "7.18.6",
|
||||
"version": "7.18.9",
|
||||
"description": "Collection of helper functions used by Babel transforms.",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helpers",
|
||||
@@ -16,13 +16,13 @@
|
||||
"main": "./lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/template": "^7.18.6",
|
||||
"@babel/traverse": "^7.18.6",
|
||||
"@babel/types": "^7.18.6"
|
||||
"@babel/traverse": "^7.18.9",
|
||||
"@babel/types": "^7.18.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/generator": "^7.18.6",
|
||||
"@babel/generator": "^7.18.9",
|
||||
"@babel/helper-plugin-test-runner": "^7.18.6",
|
||||
"@babel/parser": "^7.18.6",
|
||||
"@babel/parser": "^7.18.9",
|
||||
"regenerator-runtime": "^0.13.9",
|
||||
"terser": "^5.9.0"
|
||||
},
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -5,7 +5,7 @@ import { createRequire } from "module";
|
||||
|
||||
const [parse, generate] = await Promise.all([
|
||||
import("@babel/parser").then(ns => ns.parse),
|
||||
import("@babel/generator").then(ns => ns.default.default),
|
||||
import("@babel/generator").then(ns => ns.default.default || ns.default),
|
||||
]).catch(error =>
|
||||
Promise.reject(
|
||||
new Error(
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
try {
|
||||
module.exports = require("./lib/index.cjs");
|
||||
} catch {
|
||||
module.exports = require("./lib/index.js");
|
||||
}
|
||||
+970
-837
File diff suppressed because it is too large.
Load diff
+4
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/parser",
|
||||
"version": "7.18.8",
|
||||
"version": "7.18.11",
|
||||
"description": "A JavaScript parser",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-parser",
|
||||
@@ -27,7 +27,8 @@
|
||||
"files": [
|
||||
"bin",
|
||||
"lib",
|
||||
"typings"
|
||||
"typings",
|
||||
"index.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
@@ -36,6 +37,7 @@
|
||||
"@babel/code-frame": "^7.18.6",
|
||||
"@babel/helper-check-duplicate-nodes": "^7.18.6",
|
||||
"@babel/helper-fixtures": "^7.18.6",
|
||||
"@babel/helper-string-parser": "^7.18.10",
|
||||
"@babel/helper-validator-identifier": "^7.18.6",
|
||||
"charcodes": "^0.2.0"
|
||||
},
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/template",
|
||||
"version": "7.18.6",
|
||||
"version": "7.18.10",
|
||||
"description": "Generate an AST from a string template.",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-template",
|
||||
@@ -17,8 +17,8 @@
|
||||
"main": "./lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.18.6",
|
||||
"@babel/parser": "^7.18.6",
|
||||
"@babel/types": "^7.18.6"
|
||||
"@babel/parser": "^7.18.10",
|
||||
"@babel/types": "^7.18.10"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
|
||||
+8
-1
@@ -119,6 +119,10 @@ function unwrapFunctionEnvironment() {
|
||||
hoistFunctionEnvironment(this);
|
||||
}
|
||||
|
||||
function setType(path, type) {
|
||||
path.node.type = type;
|
||||
}
|
||||
|
||||
function arrowFunctionToExpression({
|
||||
allowInsertArrow = true,
|
||||
specCompliant = false,
|
||||
@@ -133,7 +137,7 @@ function arrowFunctionToExpression({
|
||||
fnPath: fn
|
||||
} = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow);
|
||||
fn.ensureBlock();
|
||||
fn.node.type = "FunctionExpression";
|
||||
setType(fn, "FunctionExpression");
|
||||
|
||||
if (!noNewArrows) {
|
||||
const checkBinding = thisBinding ? null : fn.scope.generateUidIdentifier("arrowCheckId");
|
||||
@@ -147,7 +151,10 @@ function arrowFunctionToExpression({
|
||||
|
||||
fn.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
|
||||
fn.replaceWith(callExpression(memberExpression((0, _helperFunctionName.default)(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
|
||||
return fn.get("callee.object");
|
||||
}
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
const getSuperCallsVisitor = (0, _visitors.merge)([{
|
||||
|
||||
+1
-1
@@ -402,6 +402,6 @@ function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
|
||||
return ids;
|
||||
}
|
||||
|
||||
function getOuterBindingIdentifierPaths(duplicates) {
|
||||
function getOuterBindingIdentifierPaths(duplicates = false) {
|
||||
return this.getBindingIdentifierPaths(duplicates, true);
|
||||
}
|
||||
Generated
Vendored
-5
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _index = require("../index");
|
||||
Generated
Vendored
-3
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("@babel/types");
|
||||
+5
-6
@@ -43,6 +43,8 @@ var NodePath_family = require("./family");
|
||||
|
||||
var NodePath_comments = require("./comments");
|
||||
|
||||
var NodePath_virtual_types_validator = require("./lib/virtual-types-validator");
|
||||
|
||||
const {
|
||||
validate
|
||||
} = _t;
|
||||
@@ -246,14 +248,11 @@ for (const type of t.TYPES) {
|
||||
};
|
||||
}
|
||||
|
||||
Object.assign(NodePath.prototype, NodePath_virtual_types_validator);
|
||||
|
||||
for (const type of Object.keys(virtualTypes)) {
|
||||
if (type[0] === "_") continue;
|
||||
if (t.TYPES.indexOf(type) < 0) t.TYPES.push(type);
|
||||
const virtualType = virtualTypes[type];
|
||||
|
||||
NodePath.prototype[`is${type}`] = function (opts) {
|
||||
return virtualType.checkPath(this, opts);
|
||||
};
|
||||
if (!t.TYPES.includes(type)) t.TYPES.push(type);
|
||||
}
|
||||
|
||||
var _default = NodePath;
|
||||
|
||||
+9
-2
@@ -441,13 +441,20 @@ function isInStrictMode() {
|
||||
sourceType: "module"
|
||||
})) return true;
|
||||
if (path.isClass()) return true;
|
||||
if (!path.isProgram() && !path.isFunction()) return false;
|
||||
|
||||
if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const body = path.isFunction() ? path.node.body : path.node;
|
||||
let body;
|
||||
|
||||
if (path.isFunction()) {
|
||||
body = path.node.body;
|
||||
} else if (path.isProgram()) {
|
||||
body = path.node;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const directive of body.directives) {
|
||||
if (directive.value.value === "use strict") {
|
||||
|
||||
Generated
Vendored
+183
@@ -0,0 +1,183 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isBindingIdentifier = isBindingIdentifier;
|
||||
exports.isBlockScoped = isBlockScoped;
|
||||
exports.isExistentialTypeParam = isExistentialTypeParam;
|
||||
exports.isExpression = isExpression;
|
||||
exports.isFlow = isFlow;
|
||||
exports.isForAwaitStatement = isForAwaitStatement;
|
||||
exports.isGenerated = isGenerated;
|
||||
exports.isNumericLiteralTypeAnnotation = isNumericLiteralTypeAnnotation;
|
||||
exports.isPure = isPure;
|
||||
exports.isReferenced = isReferenced;
|
||||
exports.isReferencedIdentifier = isReferencedIdentifier;
|
||||
exports.isReferencedMemberExpression = isReferencedMemberExpression;
|
||||
exports.isRestProperty = isRestProperty;
|
||||
exports.isScope = isScope;
|
||||
exports.isSpreadProperty = isSpreadProperty;
|
||||
exports.isStatement = isStatement;
|
||||
exports.isUser = isUser;
|
||||
exports.isVar = isVar;
|
||||
|
||||
var _t = require("@babel/types");
|
||||
|
||||
const {
|
||||
isBinding,
|
||||
isBlockScoped: nodeIsBlockScoped,
|
||||
isExportDeclaration,
|
||||
isExpression: nodeIsExpression,
|
||||
isFlow: nodeIsFlow,
|
||||
isForStatement,
|
||||
isForXStatement,
|
||||
isIdentifier,
|
||||
isImportDeclaration,
|
||||
isImportSpecifier,
|
||||
isJSXIdentifier,
|
||||
isJSXMemberExpression,
|
||||
isMemberExpression,
|
||||
isRestElement: nodeIsRestElement,
|
||||
isReferenced: nodeIsReferenced,
|
||||
isScope: nodeIsScope,
|
||||
isStatement: nodeIsStatement,
|
||||
isVar: nodeIsVar,
|
||||
isVariableDeclaration,
|
||||
react
|
||||
} = _t;
|
||||
const {
|
||||
isCompatTag
|
||||
} = react;
|
||||
|
||||
function isReferencedIdentifier(opts) {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = this;
|
||||
|
||||
if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
|
||||
if (isJSXIdentifier(node, opts)) {
|
||||
if (isCompatTag(node.name)) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return nodeIsReferenced(node, parent, this.parentPath.parent);
|
||||
}
|
||||
|
||||
function isReferencedMemberExpression() {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = this;
|
||||
return isMemberExpression(node) && nodeIsReferenced(node, parent);
|
||||
}
|
||||
|
||||
function isBindingIdentifier() {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = this;
|
||||
const grandparent = this.parentPath.parent;
|
||||
return isIdentifier(node) && isBinding(node, parent, grandparent);
|
||||
}
|
||||
|
||||
function isStatement() {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = this;
|
||||
|
||||
if (nodeIsStatement(node)) {
|
||||
if (isVariableDeclaration(node)) {
|
||||
if (isForXStatement(parent, {
|
||||
left: node
|
||||
})) return false;
|
||||
if (isForStatement(parent, {
|
||||
init: node
|
||||
})) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isExpression() {
|
||||
if (this.isIdentifier()) {
|
||||
return this.isReferencedIdentifier();
|
||||
} else {
|
||||
return nodeIsExpression(this.node);
|
||||
}
|
||||
}
|
||||
|
||||
function isScope() {
|
||||
return nodeIsScope(this.node, this.parent);
|
||||
}
|
||||
|
||||
function isReferenced() {
|
||||
return nodeIsReferenced(this.node, this.parent);
|
||||
}
|
||||
|
||||
function isBlockScoped() {
|
||||
return nodeIsBlockScoped(this.node);
|
||||
}
|
||||
|
||||
function isVar() {
|
||||
return nodeIsVar(this.node);
|
||||
}
|
||||
|
||||
function isUser() {
|
||||
return this.node && !!this.node.loc;
|
||||
}
|
||||
|
||||
function isGenerated() {
|
||||
return !this.isUser();
|
||||
}
|
||||
|
||||
function isPure(constantsOnly) {
|
||||
return this.scope.isPure(this.node, constantsOnly);
|
||||
}
|
||||
|
||||
function isFlow() {
|
||||
const {
|
||||
node
|
||||
} = this;
|
||||
|
||||
if (nodeIsFlow(node)) {
|
||||
return true;
|
||||
} else if (isImportDeclaration(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else if (isExportDeclaration(node)) {
|
||||
return node.exportKind === "type";
|
||||
} else if (isImportSpecifier(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isRestProperty() {
|
||||
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectPattern();
|
||||
}
|
||||
|
||||
function isSpreadProperty() {
|
||||
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectExpression();
|
||||
}
|
||||
|
||||
function isForAwaitStatement() {
|
||||
return isForStatement(this.node, {
|
||||
await: true
|
||||
});
|
||||
}
|
||||
|
||||
function isExistentialTypeParam() {
|
||||
throw new Error("`path.isExistentialTypeParam` has been renamed to `path.isExistsTypeAnnotation()` in Babel 7.");
|
||||
}
|
||||
|
||||
function isNumericLiteralTypeAnnotation() {
|
||||
throw new Error("`path.isNumericLiteralTypeAnnotation()` has been renamed to `path.isNumberLiteralTypeAnnotation()` in Babel 7.");
|
||||
}
|
||||
Generated
Vendored
+18
-206
@@ -4,227 +4,39 @@ Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.Var = exports.User = exports.Statement = exports.SpreadProperty = exports.Scope = exports.RestProperty = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = exports.Referenced = exports.Pure = exports.NumericLiteralTypeAnnotation = exports.Generated = exports.ForAwaitStatement = exports.Flow = exports.Expression = exports.ExistentialTypeParam = exports.BlockScoped = exports.BindingIdentifier = void 0;
|
||||
|
||||
var _t = require("@babel/types");
|
||||
|
||||
const {
|
||||
isBinding,
|
||||
isBlockScoped,
|
||||
isExportDeclaration,
|
||||
isExpression,
|
||||
isFlow,
|
||||
isForStatement,
|
||||
isForXStatement,
|
||||
isIdentifier,
|
||||
isImportDeclaration,
|
||||
isImportSpecifier,
|
||||
isJSXIdentifier,
|
||||
isJSXMemberExpression,
|
||||
isMemberExpression,
|
||||
isReferenced,
|
||||
isScope,
|
||||
isStatement,
|
||||
isVar,
|
||||
isVariableDeclaration,
|
||||
react
|
||||
} = _t;
|
||||
const {
|
||||
isCompatTag
|
||||
} = react;
|
||||
const ReferencedIdentifier = {
|
||||
types: ["Identifier", "JSXIdentifier"],
|
||||
|
||||
checkPath(path, opts) {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = path;
|
||||
|
||||
if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
|
||||
if (isJSXIdentifier(node, opts)) {
|
||||
if (isCompatTag(node.name)) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return isReferenced(node, parent, path.parentPath.parent);
|
||||
}
|
||||
|
||||
};
|
||||
const ReferencedIdentifier = ["Identifier", "JSXIdentifier"];
|
||||
exports.ReferencedIdentifier = ReferencedIdentifier;
|
||||
const ReferencedMemberExpression = {
|
||||
types: ["MemberExpression"],
|
||||
|
||||
checkPath({
|
||||
node,
|
||||
parent
|
||||
}) {
|
||||
return isMemberExpression(node) && isReferenced(node, parent);
|
||||
}
|
||||
|
||||
};
|
||||
const ReferencedMemberExpression = ["MemberExpression"];
|
||||
exports.ReferencedMemberExpression = ReferencedMemberExpression;
|
||||
const BindingIdentifier = {
|
||||
types: ["Identifier"],
|
||||
|
||||
checkPath(path) {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = path;
|
||||
const grandparent = path.parentPath.parent;
|
||||
return isIdentifier(node) && isBinding(node, parent, grandparent);
|
||||
}
|
||||
|
||||
};
|
||||
const BindingIdentifier = ["Identifier"];
|
||||
exports.BindingIdentifier = BindingIdentifier;
|
||||
const Statement = {
|
||||
types: ["Statement"],
|
||||
|
||||
checkPath({
|
||||
node,
|
||||
parent
|
||||
}) {
|
||||
if (isStatement(node)) {
|
||||
if (isVariableDeclaration(node)) {
|
||||
if (isForXStatement(parent, {
|
||||
left: node
|
||||
})) return false;
|
||||
if (isForStatement(parent, {
|
||||
init: node
|
||||
})) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
const Statement = ["Statement"];
|
||||
exports.Statement = Statement;
|
||||
const Expression = {
|
||||
types: ["Expression"],
|
||||
|
||||
checkPath(path) {
|
||||
if (path.isIdentifier()) {
|
||||
return path.isReferencedIdentifier();
|
||||
} else {
|
||||
return isExpression(path.node);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
const Expression = ["Expression"];
|
||||
exports.Expression = Expression;
|
||||
const Scope = {
|
||||
types: ["Scopable", "Pattern"],
|
||||
|
||||
checkPath(path) {
|
||||
return isScope(path.node, path.parent);
|
||||
}
|
||||
|
||||
};
|
||||
const Scope = ["Scopable", "Pattern"];
|
||||
exports.Scope = Scope;
|
||||
const Referenced = {
|
||||
checkPath(path) {
|
||||
return isReferenced(path.node, path.parent);
|
||||
}
|
||||
|
||||
};
|
||||
const Referenced = null;
|
||||
exports.Referenced = Referenced;
|
||||
const BlockScoped = {
|
||||
checkPath(path) {
|
||||
return isBlockScoped(path.node);
|
||||
}
|
||||
|
||||
};
|
||||
const BlockScoped = null;
|
||||
exports.BlockScoped = BlockScoped;
|
||||
const Var = {
|
||||
types: ["VariableDeclaration"],
|
||||
|
||||
checkPath(path) {
|
||||
return isVar(path.node);
|
||||
}
|
||||
|
||||
};
|
||||
const Var = ["VariableDeclaration"];
|
||||
exports.Var = Var;
|
||||
const User = {
|
||||
checkPath(path) {
|
||||
return path.node && !!path.node.loc;
|
||||
}
|
||||
|
||||
};
|
||||
const User = null;
|
||||
exports.User = User;
|
||||
const Generated = {
|
||||
checkPath(path) {
|
||||
return !path.isUser();
|
||||
}
|
||||
|
||||
};
|
||||
const Generated = null;
|
||||
exports.Generated = Generated;
|
||||
const Pure = {
|
||||
checkPath(path, constantsOnly) {
|
||||
return path.scope.isPure(path.node, constantsOnly);
|
||||
}
|
||||
|
||||
};
|
||||
const Pure = null;
|
||||
exports.Pure = Pure;
|
||||
const Flow = {
|
||||
types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"],
|
||||
|
||||
checkPath({
|
||||
node
|
||||
}) {
|
||||
if (isFlow(node)) {
|
||||
return true;
|
||||
} else if (isImportDeclaration(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else if (isExportDeclaration(node)) {
|
||||
return node.exportKind === "type";
|
||||
} else if (isImportSpecifier(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
const Flow = ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"];
|
||||
exports.Flow = Flow;
|
||||
const RestProperty = {
|
||||
types: ["RestElement"],
|
||||
|
||||
checkPath(path) {
|
||||
return path.parentPath && path.parentPath.isObjectPattern();
|
||||
}
|
||||
|
||||
};
|
||||
const RestProperty = ["RestElement"];
|
||||
exports.RestProperty = RestProperty;
|
||||
const SpreadProperty = {
|
||||
types: ["RestElement"],
|
||||
|
||||
checkPath(path) {
|
||||
return path.parentPath && path.parentPath.isObjectExpression();
|
||||
}
|
||||
|
||||
};
|
||||
const SpreadProperty = ["RestElement"];
|
||||
exports.SpreadProperty = SpreadProperty;
|
||||
const ExistentialTypeParam = {
|
||||
types: ["ExistsTypeAnnotation"]
|
||||
};
|
||||
const ExistentialTypeParam = ["ExistsTypeAnnotation"];
|
||||
exports.ExistentialTypeParam = ExistentialTypeParam;
|
||||
const NumericLiteralTypeAnnotation = {
|
||||
types: ["NumberLiteralTypeAnnotation"]
|
||||
};
|
||||
const NumericLiteralTypeAnnotation = ["NumberLiteralTypeAnnotation"];
|
||||
exports.NumericLiteralTypeAnnotation = NumericLiteralTypeAnnotation;
|
||||
const ForAwaitStatement = {
|
||||
types: ["ForOfStatement"],
|
||||
|
||||
checkPath({
|
||||
node
|
||||
}) {
|
||||
return node.await === true;
|
||||
}
|
||||
|
||||
};
|
||||
const ForAwaitStatement = ["ForOfStatement"];
|
||||
exports.ForAwaitStatement = ForAwaitStatement;
|
||||
+1
-3
@@ -1,5 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
var _index = require("./index");
|
||||
|
||||
var _virtualTypes = require("./path/generated/virtual-types");
|
||||
var _index = require("./index");
|
||||
+11
-7
@@ -17,6 +17,10 @@ const {
|
||||
TYPES
|
||||
} = _t;
|
||||
|
||||
function isVirtualType(type) {
|
||||
return type in virtualTypes;
|
||||
}
|
||||
|
||||
function explode(visitor) {
|
||||
if (visitor._exploded) return visitor;
|
||||
visitor._exploded = true;
|
||||
@@ -40,18 +44,18 @@ function explode(visitor) {
|
||||
|
||||
for (const nodeType of Object.keys(visitor)) {
|
||||
if (shouldIgnoreKey(nodeType)) continue;
|
||||
const wrapper = virtualTypes[nodeType];
|
||||
if (!wrapper) continue;
|
||||
if (!isVirtualType(nodeType)) continue;
|
||||
const fns = visitor[nodeType];
|
||||
|
||||
for (const type of Object.keys(fns)) {
|
||||
fns[type] = wrapCheck(wrapper, fns[type]);
|
||||
fns[type] = wrapCheck(nodeType, fns[type]);
|
||||
}
|
||||
|
||||
delete visitor[nodeType];
|
||||
const types = virtualTypes[nodeType];
|
||||
|
||||
if (wrapper.types) {
|
||||
for (const type of wrapper.types) {
|
||||
if (types !== null) {
|
||||
for (const type of types) {
|
||||
if (visitor[type]) {
|
||||
mergePair(visitor[type], fns);
|
||||
} else {
|
||||
@@ -212,9 +216,9 @@ function ensureCallbackArrays(obj) {
|
||||
if (obj.exit && !Array.isArray(obj.exit)) obj.exit = [obj.exit];
|
||||
}
|
||||
|
||||
function wrapCheck(wrapper, fn) {
|
||||
function wrapCheck(nodeType, fn) {
|
||||
const newFn = function (path) {
|
||||
if (wrapper.checkPath(path)) {
|
||||
if (path[`is${nodeType}`]()) {
|
||||
return fn.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/traverse",
|
||||
"version": "7.18.8",
|
||||
"version": "7.18.11",
|
||||
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-traverse",
|
||||
@@ -17,13 +17,13 @@
|
||||
"main": "./lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.18.6",
|
||||
"@babel/generator": "^7.18.7",
|
||||
"@babel/helper-environment-visitor": "^7.18.6",
|
||||
"@babel/helper-function-name": "^7.18.6",
|
||||
"@babel/generator": "^7.18.10",
|
||||
"@babel/helper-environment-visitor": "^7.18.9",
|
||||
"@babel/helper-function-name": "^7.18.9",
|
||||
"@babel/helper-hoist-variables": "^7.18.6",
|
||||
"@babel/helper-split-export-declaration": "^7.18.6",
|
||||
"@babel/parser": "^7.18.8",
|
||||
"@babel/types": "^7.18.8",
|
||||
"@babel/parser": "^7.18.11",
|
||||
"@babel/types": "^7.18.10",
|
||||
"debug": "^4.1.0",
|
||||
"globals": "^11.1.0"
|
||||
},
|
||||
|
||||
Generated
Vendored
+8
-28
@@ -1,46 +1,26 @@
|
||||
import * as t from "@babel/types";
|
||||
import * as virtualTypes from "../../lib/path/lib/virtual-types.js";
|
||||
|
||||
export default function generateValidators() {
|
||||
let output = `/*
|
||||
* This file is auto-generated! Do not modify it directly.
|
||||
* To re-generate run 'make build'
|
||||
*/
|
||||
import * as t from "@babel/types";
|
||||
import NodePath from "../index";
|
||||
import type { VirtualTypeAliases } from "./virtual-types";
|
||||
import type * as t from "@babel/types";
|
||||
import type NodePath from "../index";
|
||||
import type { VirtualTypeNodePathValidators } from "../lib/virtual-types-validator";
|
||||
|
||||
export interface NodePathValidators {
|
||||
interface BaseNodePathValidators {
|
||||
`;
|
||||
|
||||
for (const type of [...t.TYPES].sort()) {
|
||||
output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
|
||||
}
|
||||
|
||||
for (const type of Object.keys(virtualTypes)) {
|
||||
// TODO: Remove this check once we stop compiling to CJS
|
||||
if (type === "default" || type === "__esModule") continue;
|
||||
|
||||
const { types } = virtualTypes[type];
|
||||
if (type[0] === "_") continue;
|
||||
if (t.NODE_FIELDS[type] || t.FLIPPED_ALIAS_KEYS[type]) {
|
||||
output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
|
||||
} else if (types /* in VirtualTypeAliases */) {
|
||||
output += `is${type}(opts?: object): this is NodePath<VirtualTypeAliases["${type}"]>;`;
|
||||
} else if (type === "Pure") {
|
||||
output += `isPure(constantsOnly?: boolean): boolean;`;
|
||||
} else {
|
||||
// if it don't have types, then VirtualTypeAliases[type] is t.Node
|
||||
// which TS marked as always true
|
||||
// eg. if (path.isBlockScope()) return;
|
||||
// path resolved to `never` here
|
||||
// so we have to return boolean instead of this is NodePath<t.Node> here
|
||||
output += `is${type}(opts?: object): boolean;`;
|
||||
}
|
||||
output += `is${type}<T extends t.Node>(this: NodePath<T>, opts?: object): this is NodePath<T & t.${type}>;`;
|
||||
}
|
||||
|
||||
output += `
|
||||
}
|
||||
|
||||
export interface NodePathValidators
|
||||
extends BaseNodePathValidators, VirtualTypeNodePathValidators {}
|
||||
`;
|
||||
|
||||
return output;
|
||||
|
||||
Generated
Vendored
-27
@@ -1,27 +0,0 @@
|
||||
import * as virtualTypes from "../../lib/path/lib/virtual-types.js";
|
||||
|
||||
export default function generateValidators() {
|
||||
let output = `/*
|
||||
* This file is auto-generated! Do not modify it directly.
|
||||
* To re-generate run 'make build'
|
||||
*/
|
||||
import * as t from "@babel/types";
|
||||
|
||||
export interface VirtualTypeAliases {
|
||||
`;
|
||||
|
||||
for (const type of Object.keys(virtualTypes)) {
|
||||
// TODO: Remove this check once we stop compiling to CJS
|
||||
if (type === "default" || type === "__esModule") continue;
|
||||
|
||||
output += ` ${type}: ${(virtualTypes[type].types || ["Node"])
|
||||
.map(t => `t.${t}`)
|
||||
.join(" | ")};`;
|
||||
}
|
||||
|
||||
output += `
|
||||
}
|
||||
`;
|
||||
|
||||
return output;
|
||||
}
|
||||
+40
-5
@@ -11,6 +11,8 @@ var _isValidIdentifier = require("../validators/isValidIdentifier");
|
||||
|
||||
var _helperValidatorIdentifier = require("@babel/helper-validator-identifier");
|
||||
|
||||
var _helperStringParser = require("@babel/helper-string-parser");
|
||||
|
||||
var _constants = require("../constants");
|
||||
|
||||
var _utils = require("./utils");
|
||||
@@ -133,7 +135,7 @@ defineType("CallExpression", {
|
||||
aliases: ["Expression"],
|
||||
fields: Object.assign({
|
||||
callee: {
|
||||
validate: (0, _utils.assertNodeType)("Expression", "V8IntrinsicIdentifier")
|
||||
validate: (0, _utils.assertNodeType)("Expression", "Super", "V8IntrinsicIdentifier")
|
||||
},
|
||||
arguments: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement", "JSXNamespacedName", "ArgumentPlaceholder")))
|
||||
@@ -530,7 +532,7 @@ defineType("MemberExpression", {
|
||||
aliases: ["Expression", "LVal"],
|
||||
fields: Object.assign({
|
||||
object: {
|
||||
validate: (0, _utils.assertNodeType)("Expression")
|
||||
validate: (0, _utils.assertNodeType)("Expression", "Super")
|
||||
},
|
||||
property: {
|
||||
validate: function () {
|
||||
@@ -938,7 +940,7 @@ defineType("ArrayPattern", {
|
||||
aliases: ["Pattern", "PatternLike", "LVal"],
|
||||
fields: Object.assign({}, patternLikeCommon(), {
|
||||
elements: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeOrValueType)("null", "PatternLike")))
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeOrValueType)("null", "PatternLike", "LVal")))
|
||||
},
|
||||
decorators: {
|
||||
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator"))),
|
||||
@@ -1086,7 +1088,7 @@ defineType("ExportDefaultDeclaration", {
|
||||
aliases: ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
fields: {
|
||||
declaration: {
|
||||
validate: (0, _utils.assertNodeType)("FunctionDeclaration", "ClassDeclaration", "Expression")
|
||||
validate: (0, _utils.assertNodeType)("TSDeclareFunction", "FunctionDeclaration", "ClassDeclaration", "Expression")
|
||||
},
|
||||
exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("value"))
|
||||
}
|
||||
@@ -1386,7 +1388,7 @@ defineType("TemplateElement", {
|
||||
builder: ["value", "tail"],
|
||||
fields: {
|
||||
value: {
|
||||
validate: (0, _utils.assertShape)({
|
||||
validate: (0, _utils.chain)((0, _utils.assertShape)({
|
||||
raw: {
|
||||
validate: (0, _utils.assertValueType)("string")
|
||||
},
|
||||
@@ -1394,6 +1396,39 @@ defineType("TemplateElement", {
|
||||
validate: (0, _utils.assertValueType)("string"),
|
||||
optional: true
|
||||
}
|
||||
}), function templateElementCookedValidator(node) {
|
||||
const raw = node.value.raw;
|
||||
let str,
|
||||
containsInvalid,
|
||||
unterminatedCalled = false;
|
||||
|
||||
try {
|
||||
const error = () => {
|
||||
throw new Error();
|
||||
};
|
||||
|
||||
({
|
||||
str,
|
||||
containsInvalid
|
||||
} = (0, _helperStringParser.readStringContents)("template", raw, 0, 0, 0, {
|
||||
unterminated() {
|
||||
unterminatedCalled = true;
|
||||
},
|
||||
|
||||
strictNumericEscape: error,
|
||||
invalidEscapeSequence: error,
|
||||
numericSeparatorInEscapeSequence: error,
|
||||
unexpectedNumericSeparator: error,
|
||||
invalidDigit: error,
|
||||
invalidCodePoint: error
|
||||
}));
|
||||
} catch (_unused) {
|
||||
unterminatedCalled = true;
|
||||
containsInvalid = true;
|
||||
}
|
||||
|
||||
if (!unterminatedCalled) throw new Error("Invalid raw");
|
||||
node.value.cooked = containsInvalid ? null : str;
|
||||
})
|
||||
},
|
||||
tail: {
|
||||
|
||||
Generated
Vendored
+2
-2
@@ -284,7 +284,7 @@ defineType("TSLiteralType", {
|
||||
validate: function () {
|
||||
const unaryExpression = (0, _utils.assertNodeType)("NumericLiteral", "BigIntLiteral");
|
||||
const unaryOperator = (0, _utils.assertOneOf)("-");
|
||||
const literal = (0, _utils.assertNodeType)("NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral");
|
||||
const literal = (0, _utils.assertNodeType)("NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral", "TemplateLiteral");
|
||||
|
||||
function validator(parent, key, node) {
|
||||
if ((0, _is.default)("UnaryExpression", node)) {
|
||||
@@ -295,7 +295,7 @@ defineType("TSLiteralType", {
|
||||
}
|
||||
}
|
||||
|
||||
validator.oneOfNodeTypes = ["NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral", "UnaryExpression"];
|
||||
validator.oneOfNodeTypes = ["NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral", "TemplateLiteral", "UnaryExpression"];
|
||||
return validator;
|
||||
}()
|
||||
}
|
||||
|
||||
+12
-12
@@ -85,7 +85,7 @@ declare class BabelNodeBreakStatement extends BabelNode {
|
||||
|
||||
declare class BabelNodeCallExpression extends BabelNode {
|
||||
type: "CallExpression";
|
||||
callee: BabelNodeExpression | BabelNodeV8IntrinsicIdentifier;
|
||||
callee: BabelNodeExpression | BabelNodeSuper | BabelNodeV8IntrinsicIdentifier;
|
||||
arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>;
|
||||
optional?: true | false;
|
||||
typeArguments?: BabelNodeTypeParameterInstantiation;
|
||||
@@ -231,7 +231,7 @@ declare class BabelNodeLogicalExpression extends BabelNode {
|
||||
|
||||
declare class BabelNodeMemberExpression extends BabelNode {
|
||||
type: "MemberExpression";
|
||||
object: BabelNodeExpression;
|
||||
object: BabelNodeExpression | BabelNodeSuper;
|
||||
property: BabelNodeExpression | BabelNodeIdentifier | BabelNodePrivateName;
|
||||
computed?: boolean;
|
||||
optional?: true | false;
|
||||
@@ -239,7 +239,7 @@ declare class BabelNodeMemberExpression extends BabelNode {
|
||||
|
||||
declare class BabelNodeNewExpression extends BabelNode {
|
||||
type: "NewExpression";
|
||||
callee: BabelNodeExpression | BabelNodeV8IntrinsicIdentifier;
|
||||
callee: BabelNodeExpression | BabelNodeSuper | BabelNodeV8IntrinsicIdentifier;
|
||||
arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>;
|
||||
optional?: true | false;
|
||||
typeArguments?: BabelNodeTypeParameterInstantiation;
|
||||
@@ -384,7 +384,7 @@ declare class BabelNodeAssignmentPattern extends BabelNode {
|
||||
|
||||
declare class BabelNodeArrayPattern extends BabelNode {
|
||||
type: "ArrayPattern";
|
||||
elements: Array<null | BabelNodePatternLike>;
|
||||
elements: Array<null | BabelNodePatternLike | BabelNodeLVal>;
|
||||
decorators?: Array<BabelNodeDecorator>;
|
||||
optional?: boolean;
|
||||
typeAnnotation?: BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | BabelNodeNoop;
|
||||
@@ -440,7 +440,7 @@ declare class BabelNodeExportAllDeclaration extends BabelNode {
|
||||
|
||||
declare class BabelNodeExportDefaultDeclaration extends BabelNode {
|
||||
type: "ExportDefaultDeclaration";
|
||||
declaration: BabelNodeFunctionDeclaration | BabelNodeClassDeclaration | BabelNodeExpression;
|
||||
declaration: BabelNodeTSDeclareFunction | BabelNodeFunctionDeclaration | BabelNodeClassDeclaration | BabelNodeExpression;
|
||||
exportKind?: "value";
|
||||
}
|
||||
|
||||
@@ -1477,7 +1477,7 @@ declare class BabelNodeTSMappedType extends BabelNode {
|
||||
|
||||
declare class BabelNodeTSLiteralType extends BabelNode {
|
||||
type: "TSLiteralType";
|
||||
literal: BabelNodeNumericLiteral | BabelNodeStringLiteral | BabelNodeBooleanLiteral | BabelNodeBigIntLiteral | BabelNodeUnaryExpression;
|
||||
literal: BabelNodeNumericLiteral | BabelNodeStringLiteral | BabelNodeBooleanLiteral | BabelNodeBigIntLiteral | BabelNodeTemplateLiteral | BabelNodeUnaryExpression;
|
||||
}
|
||||
|
||||
declare class BabelNodeTSExpressionWithTypeArguments extends BabelNode {
|
||||
@@ -1668,7 +1668,7 @@ declare module "@babel/types" {
|
||||
declare export function directiveLiteral(value: string): BabelNodeDirectiveLiteral;
|
||||
declare export function blockStatement(body: Array<BabelNodeStatement>, directives?: Array<BabelNodeDirective>): BabelNodeBlockStatement;
|
||||
declare export function breakStatement(label?: BabelNodeIdentifier): BabelNodeBreakStatement;
|
||||
declare export function callExpression(callee: BabelNodeExpression | BabelNodeV8IntrinsicIdentifier, _arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>): BabelNodeCallExpression;
|
||||
declare export function callExpression(callee: BabelNodeExpression | BabelNodeSuper | BabelNodeV8IntrinsicIdentifier, _arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>): BabelNodeCallExpression;
|
||||
declare export function catchClause(param?: BabelNodeIdentifier | BabelNodeArrayPattern | BabelNodeObjectPattern, body: BabelNodeBlockStatement): BabelNodeCatchClause;
|
||||
declare export function conditionalExpression(test: BabelNodeExpression, consequent: BabelNodeExpression, alternate: BabelNodeExpression): BabelNodeConditionalExpression;
|
||||
declare export function continueStatement(label?: BabelNodeIdentifier): BabelNodeContinueStatement;
|
||||
@@ -1690,8 +1690,8 @@ declare module "@babel/types" {
|
||||
declare export function booleanLiteral(value: boolean): BabelNodeBooleanLiteral;
|
||||
declare export function regExpLiteral(pattern: string, flags?: string): BabelNodeRegExpLiteral;
|
||||
declare export function logicalExpression(operator: "||" | "&&" | "??", left: BabelNodeExpression, right: BabelNodeExpression): BabelNodeLogicalExpression;
|
||||
declare export function memberExpression(object: BabelNodeExpression, property: BabelNodeExpression | BabelNodeIdentifier | BabelNodePrivateName, computed?: boolean, optional?: true | false): BabelNodeMemberExpression;
|
||||
declare export function newExpression(callee: BabelNodeExpression | BabelNodeV8IntrinsicIdentifier, _arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>): BabelNodeNewExpression;
|
||||
declare export function memberExpression(object: BabelNodeExpression | BabelNodeSuper, property: BabelNodeExpression | BabelNodeIdentifier | BabelNodePrivateName, computed?: boolean, optional?: true | false): BabelNodeMemberExpression;
|
||||
declare export function newExpression(callee: BabelNodeExpression | BabelNodeSuper | BabelNodeV8IntrinsicIdentifier, _arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>): BabelNodeNewExpression;
|
||||
declare export function program(body: Array<BabelNodeStatement>, directives?: Array<BabelNodeDirective>, sourceType?: "script" | "module", interpreter?: BabelNodeInterpreterDirective): BabelNodeProgram;
|
||||
declare export function objectExpression(properties: Array<BabelNodeObjectMethod | BabelNodeObjectProperty | BabelNodeSpreadElement>): BabelNodeObjectExpression;
|
||||
declare export function objectMethod(kind?: "method" | "get" | "set", key: BabelNodeExpression | BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeBigIntLiteral, params: Array<BabelNodeIdentifier | BabelNodePattern | BabelNodeRestElement>, body: BabelNodeBlockStatement, computed?: boolean, generator?: boolean, async?: boolean): BabelNodeObjectMethod;
|
||||
@@ -1712,13 +1712,13 @@ declare module "@babel/types" {
|
||||
declare export function whileStatement(test: BabelNodeExpression, body: BabelNodeStatement): BabelNodeWhileStatement;
|
||||
declare export function withStatement(object: BabelNodeExpression, body: BabelNodeStatement): BabelNodeWithStatement;
|
||||
declare export function assignmentPattern(left: BabelNodeIdentifier | BabelNodeObjectPattern | BabelNodeArrayPattern | BabelNodeMemberExpression | BabelNodeTSAsExpression | BabelNodeTSTypeAssertion | BabelNodeTSNonNullExpression, right: BabelNodeExpression): BabelNodeAssignmentPattern;
|
||||
declare export function arrayPattern(elements: Array<null | BabelNodePatternLike>): BabelNodeArrayPattern;
|
||||
declare export function arrayPattern(elements: Array<null | BabelNodePatternLike | BabelNodeLVal>): BabelNodeArrayPattern;
|
||||
declare export function arrowFunctionExpression(params: Array<BabelNodeIdentifier | BabelNodePattern | BabelNodeRestElement>, body: BabelNodeBlockStatement | BabelNodeExpression, async?: boolean): BabelNodeArrowFunctionExpression;
|
||||
declare export function classBody(body: Array<BabelNodeClassMethod | BabelNodeClassPrivateMethod | BabelNodeClassProperty | BabelNodeClassPrivateProperty | BabelNodeClassAccessorProperty | BabelNodeTSDeclareMethod | BabelNodeTSIndexSignature | BabelNodeStaticBlock>): BabelNodeClassBody;
|
||||
declare export function classExpression(id?: BabelNodeIdentifier, superClass?: BabelNodeExpression, body: BabelNodeClassBody, decorators?: Array<BabelNodeDecorator>): BabelNodeClassExpression;
|
||||
declare export function classDeclaration(id: BabelNodeIdentifier, superClass?: BabelNodeExpression, body: BabelNodeClassBody, decorators?: Array<BabelNodeDecorator>): BabelNodeClassDeclaration;
|
||||
declare export function exportAllDeclaration(source: BabelNodeStringLiteral): BabelNodeExportAllDeclaration;
|
||||
declare export function exportDefaultDeclaration(declaration: BabelNodeFunctionDeclaration | BabelNodeClassDeclaration | BabelNodeExpression): BabelNodeExportDefaultDeclaration;
|
||||
declare export function exportDefaultDeclaration(declaration: BabelNodeTSDeclareFunction | BabelNodeFunctionDeclaration | BabelNodeClassDeclaration | BabelNodeExpression): BabelNodeExportDefaultDeclaration;
|
||||
declare export function exportNamedDeclaration(declaration?: BabelNodeDeclaration, specifiers?: Array<BabelNodeExportSpecifier | BabelNodeExportDefaultSpecifier | BabelNodeExportNamespaceSpecifier>, source?: BabelNodeStringLiteral): BabelNodeExportNamedDeclaration;
|
||||
declare export function exportSpecifier(local: BabelNodeIdentifier, exported: BabelNodeIdentifier | BabelNodeStringLiteral): BabelNodeExportSpecifier;
|
||||
declare export function forOfStatement(left: BabelNodeVariableDeclaration | BabelNodeLVal, right: BabelNodeExpression, body: BabelNodeStatement, _await?: boolean): BabelNodeForOfStatement;
|
||||
@@ -1888,7 +1888,7 @@ declare module "@babel/types" {
|
||||
declare export function tsTypeOperator(typeAnnotation: BabelNodeTSType): BabelNodeTSTypeOperator;
|
||||
declare export function tsIndexedAccessType(objectType: BabelNodeTSType, indexType: BabelNodeTSType): BabelNodeTSIndexedAccessType;
|
||||
declare export function tsMappedType(typeParameter: BabelNodeTSTypeParameter, typeAnnotation?: BabelNodeTSType, nameType?: BabelNodeTSType): BabelNodeTSMappedType;
|
||||
declare export function tsLiteralType(literal: BabelNodeNumericLiteral | BabelNodeStringLiteral | BabelNodeBooleanLiteral | BabelNodeBigIntLiteral | BabelNodeUnaryExpression): BabelNodeTSLiteralType;
|
||||
declare export function tsLiteralType(literal: BabelNodeNumericLiteral | BabelNodeStringLiteral | BabelNodeBooleanLiteral | BabelNodeBigIntLiteral | BabelNodeTemplateLiteral | BabelNodeUnaryExpression): BabelNodeTSLiteralType;
|
||||
declare export function tsExpressionWithTypeArguments(expression: BabelNodeTSEntityName, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeTSExpressionWithTypeArguments;
|
||||
declare export function tsInterfaceDeclaration(id: BabelNodeIdentifier, typeParameters?: BabelNodeTSTypeParameterDeclaration, _extends?: Array<BabelNodeTSExpressionWithTypeArguments>, body: BabelNodeTSInterfaceBody): BabelNodeTSInterfaceDeclaration;
|
||||
declare export function tsInterfaceBody(body: Array<BabelNodeTSTypeElement>): BabelNodeTSInterfaceBody;
|
||||
|
||||
Generated
Vendored
+6
@@ -7,7 +7,13 @@ exports.default = prependToMemberExpression;
|
||||
|
||||
var _generated = require("../builders/generated");
|
||||
|
||||
var _ = require("..");
|
||||
|
||||
function prependToMemberExpression(member, prepend) {
|
||||
if ((0, _.isSuper)(member.object)) {
|
||||
throw new Error("Cannot prepend node to super property access (`super.foo`).");
|
||||
}
|
||||
|
||||
member.object = (0, _generated.memberExpression)(prepend, member.object);
|
||||
return member;
|
||||
}
|
||||
+5
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/types",
|
||||
"version": "7.18.8",
|
||||
"version": "7.18.10",
|
||||
"description": "Babel Types is a Lodash-esque utility library for AST nodes",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-types",
|
||||
@@ -24,14 +24,15 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/helper-string-parser": "^7.18.10",
|
||||
"@babel/helper-validator-identifier": "^7.18.6",
|
||||
"to-fast-properties": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/generator": "^7.18.7",
|
||||
"@babel/parser": "^7.18.8",
|
||||
"@babel/generator": "^7.18.10",
|
||||
"@babel/parser": "^7.18.10",
|
||||
"chalk": "^4.1.0",
|
||||
"glob": "^7.1.7"
|
||||
"glob": "^7.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
|
||||
Generated
Vendored
+51
-1
@@ -1,5 +1,38 @@
|
||||
import * as t from "../../lib/index.js";
|
||||
import stringifyValidator from "../utils/stringifyValidator.js";
|
||||
import stringifyValidator, {
|
||||
isValueType,
|
||||
} from "../utils/stringifyValidator.js";
|
||||
|
||||
const parentMaps = new Map([["File", new Set(["null"])]]);
|
||||
|
||||
function registerParentMaps(parent, nodes) {
|
||||
for (const node of nodes) {
|
||||
if (!parentMaps.has(node)) {
|
||||
parentMaps.set(node, new Set());
|
||||
}
|
||||
parentMaps.get(node).add(parent);
|
||||
}
|
||||
}
|
||||
|
||||
function getNodeTypesFromValidator(validator) {
|
||||
if (validator === undefined) return [];
|
||||
if (validator.each) {
|
||||
return getNodeTypesFromValidator(validator.each);
|
||||
}
|
||||
if (validator.chainOf) {
|
||||
return getNodeTypesFromValidator(validator.chainOf[1]);
|
||||
}
|
||||
let nodeTypes = [];
|
||||
if (validator.oneOfNodeTypes) {
|
||||
nodeTypes = validator.oneOfNodeTypes;
|
||||
}
|
||||
if (validator.oneOfNodeOrValueTypes) {
|
||||
nodeTypes = validator.oneOfNodeOrValueTypes.filter(
|
||||
type => !isValueType(type)
|
||||
);
|
||||
}
|
||||
return nodeTypes.flatMap(type => t.FLIPPED_ALIAS_KEYS[type] ?? type);
|
||||
}
|
||||
|
||||
export default function generateAstTypes() {
|
||||
let code = `// NOTE: This file is autogenerated. Do not modify.
|
||||
@@ -87,6 +120,8 @@ export type Node = ${t.TYPES.filter(k => !t.FLIPPED_ALIAS_KEYS[k])
|
||||
} else {
|
||||
struct.push(`"${fieldName}"${optional}: ${typeAnnotation};`);
|
||||
}
|
||||
|
||||
registerParentMaps(type, getNodeTypesFromValidator(field.validate));
|
||||
});
|
||||
|
||||
code += `export interface ${type} extends BaseNode {
|
||||
@@ -123,6 +158,21 @@ export interface ${deprecatedAlias[type]} extends BaseNode {
|
||||
t.DEPRECATED_KEYS
|
||||
).join(" | ")}\n\n`;
|
||||
|
||||
code += "export interface ParentMaps {\n";
|
||||
|
||||
registerParentMaps("null", [...Object.keys(t.DEPRECATED_KEYS)]);
|
||||
// todo: provide a better parent type for Placeholder, currently it acts
|
||||
// as a catch-all parent type for an abstract NodePath, s.t NodePath.parent must
|
||||
// be a Node if type has not been specified
|
||||
registerParentMaps("Node", ["Placeholder"]);
|
||||
|
||||
const parentMapsKeys = [...parentMaps.keys()].sort();
|
||||
for (const type of parentMapsKeys) {
|
||||
const deduplicated = [...parentMaps.get(type)].sort();
|
||||
code += ` ${type}: ${deduplicated.join(" | ")};\n`;
|
||||
}
|
||||
code += "}\n\n";
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
Generated
Vendored
+5
-2
@@ -8,7 +8,10 @@ export default function stringifyValidator(validator, nodePrefix) {
|
||||
}
|
||||
|
||||
if (validator.chainOf) {
|
||||
return stringifyValidator(validator.chainOf[1], nodePrefix);
|
||||
const ret = stringifyValidator(validator.chainOf[1], nodePrefix);
|
||||
return Array.isArray(ret) && ret.length === 1 && ret[0] === "any"
|
||||
? stringifyValidator(validator.chainOf[0], nodePrefix)
|
||||
: ret;
|
||||
}
|
||||
|
||||
if (validator.oneOf) {
|
||||
@@ -61,6 +64,6 @@ export default function stringifyValidator(validator, nodePrefix) {
|
||||
* Heuristic to decide whether or not the given type is a value type (eg. "null")
|
||||
* or a Node type (eg. "Expression").
|
||||
*/
|
||||
function isValueType(type) {
|
||||
export function isValueType(type) {
|
||||
return type.charAt(0).toLowerCase() === type.charAt(0);
|
||||
}
|
||||
+80
-14
@@ -106,7 +106,7 @@ const baseSchema = Object.freeze({
|
||||
const debug = createDebug('@hwc/config-array');
|
||||
|
||||
const MINIMATCH_OPTIONS = {
|
||||
matchBase: true,
|
||||
// matchBase: true,
|
||||
dot: true
|
||||
};
|
||||
|
||||
@@ -233,6 +233,11 @@ function normalizeSync(items, context, extraConfigTypes) {
|
||||
*/
|
||||
function shouldIgnoreFilePath(ignores, filePath, relativeFilePath) {
|
||||
|
||||
// all files outside of the basePath are ignored
|
||||
if (relativeFilePath.startsWith('..')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let shouldIgnore = false;
|
||||
|
||||
for (const matcher of ignores) {
|
||||
@@ -285,11 +290,6 @@ function shouldIgnoreFilePath(ignores, filePath, relativeFilePath) {
|
||||
*/
|
||||
function pathMatches(filePath, basePath, config) {
|
||||
|
||||
// a config without `files` field always match
|
||||
if (!config.files) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* For both files and ignores, functions are passed the absolute
|
||||
* file path while strings are compared against the relative
|
||||
@@ -399,8 +399,7 @@ class ConfigArray extends Array {
|
||||
* definitions to use for the ConfigArray schema.
|
||||
* @param {Array<string>} [options.configTypes] List of config types supported.
|
||||
*/
|
||||
constructor(configs,
|
||||
{
|
||||
constructor(configs, {
|
||||
basePath = '',
|
||||
normalized = false,
|
||||
schema: customSchema,
|
||||
@@ -454,7 +453,7 @@ class ConfigArray extends Array {
|
||||
this[ConfigArraySymbol.configCache] = new Map();
|
||||
|
||||
// init cache
|
||||
dataCache.set(this, {});
|
||||
dataCache.set(this, { explicitMatches: new Map() });
|
||||
|
||||
// load the configs into this array
|
||||
if (Array.isArray(configs)) {
|
||||
@@ -536,7 +535,13 @@ get ignores() {
|
||||
const result = [];
|
||||
|
||||
for (const config of this) {
|
||||
if (config.ignores && !config.files) {
|
||||
|
||||
/*
|
||||
* We only count ignores if there are no other keys in the object.
|
||||
* In this case, it acts list a globally ignored pattern. If there
|
||||
* are additional keys, then ignores act like exclusions.
|
||||
*/
|
||||
if (config.ignores && Object.keys(config).length === 1) {
|
||||
result.push(...config.ignores);
|
||||
}
|
||||
}
|
||||
@@ -588,7 +593,7 @@ normalizeSync(context = {}) {
|
||||
if (!this.isNormalized()) {
|
||||
const normalizedConfigs = normalizeSync(this, context, this.extraConfigTypes);
|
||||
this.length = 0;
|
||||
this.push(...normalizedConfigs.map(this[ConfigArraySymbol.preprocessConfig]));
|
||||
this.push(...normalizedConfigs.map(this[ConfigArraySymbol.preprocessConfig].bind(this)));
|
||||
this[ConfigArraySymbol.isNormalized] = true;
|
||||
|
||||
// prevent further changes
|
||||
@@ -621,6 +626,56 @@ normalizeSync(context = {}) {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a given file path explicitly matches a `files` entry
|
||||
* and also doesn't match an `ignores` entry. Configs that don't have
|
||||
* a `files` property are not considered an explicit match.
|
||||
* @param {string} filePath The complete path of a file to check.
|
||||
* @returns {boolean} True if the file path matches a `files` entry
|
||||
* or false if not.
|
||||
*/
|
||||
isExplicitMatch(filePath) {
|
||||
|
||||
assertNormalized(this);
|
||||
|
||||
const cache = dataCache.get(this);
|
||||
|
||||
// first check the cache to avoid duplicate work
|
||||
let result = cache.explicitMatches.get(filePath);
|
||||
|
||||
if (typeof result == 'boolean') {
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO: Maybe move elsewhere? Maybe combine with getConfig() logic?
|
||||
const relativeFilePath = path.relative(this.basePath, filePath);
|
||||
|
||||
if (shouldIgnoreFilePath(this.ignores, filePath, relativeFilePath)) {
|
||||
debug(`Ignoring ${filePath}`);
|
||||
|
||||
// cache and return result
|
||||
cache.explicitMatches.set(filePath, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// filePath isn't automatically ignored, so try to find a match
|
||||
|
||||
for (const config of this) {
|
||||
|
||||
if (!config.files) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pathMatches(filePath, this.basePath, config)) {
|
||||
debug(`Matching config found for ${filePath}`);
|
||||
cache.explicitMatches.set(filePath, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the config object for a given file path.
|
||||
* @param {string} filePath The complete path of a file to get a config for.
|
||||
@@ -641,6 +696,7 @@ getConfig(filePath) {
|
||||
const relativeFilePath = path.relative(this.basePath, filePath);
|
||||
|
||||
if (shouldIgnoreFilePath(this.ignores, filePath, relativeFilePath)) {
|
||||
debug(`Ignoring ${filePath}`);
|
||||
|
||||
// cache and return result - finalConfig is undefined at this point
|
||||
this[ConfigArraySymbol.configCache].set(filePath, finalConfig);
|
||||
@@ -650,18 +706,28 @@ getConfig(filePath) {
|
||||
// filePath isn't automatically ignored, so try to construct config
|
||||
|
||||
const matchingConfigs = [];
|
||||
let matchFound = false;
|
||||
|
||||
for (const config of this) {
|
||||
|
||||
if (!config.files) {
|
||||
debug(`Universal config found for ${filePath}`);
|
||||
matchingConfigs.push(config);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pathMatches(filePath, this.basePath, config)) {
|
||||
debug(`Matching config found for ${filePath}`);
|
||||
matchingConfigs.push(config);
|
||||
} else {
|
||||
debug(`No matching config found for ${filePath}`);
|
||||
matchFound = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// if matching both files and ignores, there will be no config to create
|
||||
if (matchingConfigs.length === 0) {
|
||||
if (!matchFound) {
|
||||
debug(`No matching configs found for ${filePath}`);
|
||||
|
||||
// cache and return result - finalConfig is undefined at this point
|
||||
this[ConfigArraySymbol.configCache].set(filePath, finalConfig);
|
||||
return finalConfig;
|
||||
|
||||
+10
-11
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@humanwhocodes/config-array",
|
||||
"version": "0.9.5",
|
||||
"version": "0.10.4",
|
||||
"description": "Glob-based configuration matching.",
|
||||
"author": "Nicholas C. Zakas",
|
||||
"main": "api.js",
|
||||
@@ -28,7 +28,6 @@
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"nitpik",
|
||||
"eslint --fix --ignore-pattern '!.eslintrc.js'"
|
||||
]
|
||||
},
|
||||
@@ -47,15 +46,15 @@
|
||||
"minimatch": "^3.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nitpik/javascript": "^0.3.3",
|
||||
"@nitpik/javascript": "0.3.3",
|
||||
"@nitpik/node": "0.0.5",
|
||||
"chai": "^4.2.0",
|
||||
"eslint": "^6.7.1",
|
||||
"esm": "^3.2.25",
|
||||
"lint-staged": "^10.2.8",
|
||||
"mocha": "^6.2.3",
|
||||
"nyc": "^14.1.1",
|
||||
"rollup": "^1.12.3",
|
||||
"yorkie": "^2.0.0"
|
||||
"chai": "4.2.0",
|
||||
"eslint": "6.7.1",
|
||||
"esm": "3.2.25",
|
||||
"lint-staged": "10.2.8",
|
||||
"mocha": "6.2.3",
|
||||
"nyc": "14.1.1",
|
||||
"rollup": "1.16.6",
|
||||
"yorkie": "2.0.0"
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
Generated
Vendored
+71
@@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
/**
|
||||
* @fileoverview Utility to convert gitignore patterns to minimatch.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
/**
|
||||
* Converts a gitignore pattern to a minimatch pattern.
|
||||
* @param {string} pattern The gitignore pattern to convert.
|
||||
* @returns {string} A minimatch pattern equivalent to `pattern`.
|
||||
*/
|
||||
function gitignoreToMinimatch(pattern) {
|
||||
|
||||
if (typeof pattern !== "string") {
|
||||
throw new TypeError("Argument must be a string.");
|
||||
}
|
||||
|
||||
// Special case: Empty string
|
||||
if (!pattern) {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
// strip off negation to make life easier
|
||||
const negated = pattern.startsWith("!");
|
||||
let patternToTest = negated ? pattern.slice(1) : pattern;
|
||||
let result = patternToTest;
|
||||
let leadingSlash = false;
|
||||
|
||||
// strip off leading slash
|
||||
if (patternToTest[0] === "/") {
|
||||
leadingSlash = true;
|
||||
result = patternToTest.slice(1);
|
||||
}
|
||||
|
||||
// For the most part, the first character determines what to do
|
||||
switch (result[0]) {
|
||||
|
||||
case "*":
|
||||
if (patternToTest[1] !== "*") {
|
||||
result = "**/" + result;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!leadingSlash && !result.includes("/") || result.endsWith("/")) {
|
||||
result = "**/" + result;
|
||||
}
|
||||
|
||||
// no further changes if the pattern ends with a wildcard
|
||||
if (result.endsWith("*") || result.endsWith("?")) {
|
||||
break;
|
||||
}
|
||||
|
||||
// differentiate between filenames and directory names
|
||||
if (!/\.[a-z\d_-]+$/.test(result)) {
|
||||
if (!result.endsWith("/")) {
|
||||
result += "/";
|
||||
}
|
||||
|
||||
result += "**";
|
||||
}
|
||||
}
|
||||
|
||||
return negated ? "!" + result : result;
|
||||
|
||||
}
|
||||
|
||||
exports.gitignoreToMinimatch = gitignoreToMinimatch;
|
||||
Generated
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* @fileoverview Utility to convert gitignore patterns to minimatch.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
/**
|
||||
* Converts a gitignore pattern to a minimatch pattern.
|
||||
* @param {string} pattern The gitignore pattern to convert.
|
||||
* @returns {string} A minimatch pattern equivalent to `pattern`.
|
||||
*/
|
||||
function gitignoreToMinimatch(pattern) {
|
||||
|
||||
if (typeof pattern !== "string") {
|
||||
throw new TypeError("Argument must be a string.");
|
||||
}
|
||||
|
||||
// Special case: Empty string
|
||||
if (!pattern) {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
// strip off negation to make life easier
|
||||
const negated = pattern.startsWith("!");
|
||||
let patternToTest = negated ? pattern.slice(1) : pattern;
|
||||
let result = patternToTest;
|
||||
let leadingSlash = false;
|
||||
|
||||
// strip off leading slash
|
||||
if (patternToTest[0] === "/") {
|
||||
leadingSlash = true;
|
||||
result = patternToTest.slice(1);
|
||||
}
|
||||
|
||||
// For the most part, the first character determines what to do
|
||||
switch (result[0]) {
|
||||
|
||||
case "*":
|
||||
if (patternToTest[1] !== "*") {
|
||||
result = "**/" + result;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!leadingSlash && !result.includes("/") || result.endsWith("/")) {
|
||||
result = "**/" + result;
|
||||
}
|
||||
|
||||
// no further changes if the pattern ends with a wildcard
|
||||
if (result.endsWith("*") || result.endsWith("?")) {
|
||||
break;
|
||||
}
|
||||
|
||||
// differentiate between filenames and directory names
|
||||
if (!/\.[a-z\d_-]+$/.test(result)) {
|
||||
if (!result.endsWith("/")) {
|
||||
result += "/";
|
||||
}
|
||||
|
||||
result += "**";
|
||||
}
|
||||
}
|
||||
|
||||
return negated ? "!" + result : result;
|
||||
|
||||
}
|
||||
|
||||
export { gitignoreToMinimatch };
|
||||
Generated
Vendored
+61
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"name": "@humanwhocodes/gitignore-to-minimatch",
|
||||
"version": "1.0.2",
|
||||
"description": "Utility to convert gitignore patterns to minimatch patterns",
|
||||
"type": "module",
|
||||
"main": "dist/gitignore-to-minimatch.cjs",
|
||||
"module": "dist/gitignore-to-minimatch.js",
|
||||
"types": "dist/gitignore-to-minimatch.d.ts",
|
||||
"exports": {
|
||||
"require": "./dist/gitignore-to-minimatch.cjs",
|
||||
"import": "./dist/gitignore-to-minimatch.js"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHooks": {
|
||||
"pre-commit": "lint-staged"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"eslint --fix"
|
||||
]
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/nzakas"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c && tsc",
|
||||
"prepare": "npm run build",
|
||||
"lint": "eslint src/ tests/",
|
||||
"lint:fix": "eslint src/ tests/",
|
||||
"pretest": "npm run build",
|
||||
"test:unit": "mocha tests/gitignore-to-minimatch.test.js",
|
||||
"test:build": "node tests/pkg.test.cjs && node tests/pkg.test.mjs",
|
||||
"test": "npm run test:unit && npm run test:build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/humanwhocodes/gitignore-to-minimatch.git"
|
||||
},
|
||||
"keywords": [
|
||||
"gitignore",
|
||||
"minimatch",
|
||||
"glob"
|
||||
],
|
||||
"author": "Nicholas C. Zaks",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"chai": "^4.3.4",
|
||||
"eslint": "^7.32.0",
|
||||
"lint-staged": "^10.4.0",
|
||||
"mocha": "^9.0.3",
|
||||
"rollup": "^1.20.3",
|
||||
"typescript": "^4.0.3",
|
||||
"yorkie": "^2.0.0"
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Denis Malinochkin
|
||||
|
||||
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.
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
|
||||
const fs = require("fs");
|
||||
exports.FILE_SYSTEM_ADAPTER = {
|
||||
lstat: fs.lstat,
|
||||
stat: fs.stat,
|
||||
lstatSync: fs.lstatSync,
|
||||
statSync: fs.statSync,
|
||||
readdir: fs.readdir,
|
||||
readdirSync: fs.readdirSync
|
||||
};
|
||||
function createFileSystemAdapter(fsMethods) {
|
||||
if (fsMethods === undefined) {
|
||||
return exports.FILE_SYSTEM_ADAPTER;
|
||||
}
|
||||
return Object.assign(Object.assign({}, exports.FILE_SYSTEM_ADAPTER), fsMethods);
|
||||
}
|
||||
exports.createFileSystemAdapter = createFileSystemAdapter;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = void 0;
|
||||
const NODE_PROCESS_VERSION_PARTS = process.versions.node.split('.');
|
||||
if (NODE_PROCESS_VERSION_PARTS[0] === undefined || NODE_PROCESS_VERSION_PARTS[1] === undefined) {
|
||||
throw new Error(`Unexpected behavior. The 'process.versions.node' variable has invalid value: ${process.versions.node}`);
|
||||
}
|
||||
const MAJOR_VERSION = Number.parseInt(NODE_PROCESS_VERSION_PARTS[0], 10);
|
||||
const MINOR_VERSION = Number.parseInt(NODE_PROCESS_VERSION_PARTS[1], 10);
|
||||
const SUPPORTED_MAJOR_VERSION = 10;
|
||||
const SUPPORTED_MINOR_VERSION = 10;
|
||||
const IS_MATCHED_BY_MAJOR = MAJOR_VERSION > SUPPORTED_MAJOR_VERSION;
|
||||
const IS_MATCHED_BY_MAJOR_AND_MINOR = MAJOR_VERSION === SUPPORTED_MAJOR_VERSION && MINOR_VERSION >= SUPPORTED_MINOR_VERSION;
|
||||
/**
|
||||
* IS `true` for Node.js 10.10 and greater.
|
||||
*/
|
||||
exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = IS_MATCHED_BY_MAJOR || IS_MATCHED_BY_MAJOR_AND_MINOR;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Settings = exports.scandirSync = exports.scandir = void 0;
|
||||
const async = require("./providers/async");
|
||||
const sync = require("./providers/sync");
|
||||
const settings_1 = require("./settings");
|
||||
exports.Settings = settings_1.default;
|
||||
function scandir(path, optionsOrSettingsOrCallback, callback) {
|
||||
if (typeof optionsOrSettingsOrCallback === 'function') {
|
||||
async.read(path, getSettings(), optionsOrSettingsOrCallback);
|
||||
return;
|
||||
}
|
||||
async.read(path, getSettings(optionsOrSettingsOrCallback), callback);
|
||||
}
|
||||
exports.scandir = scandir;
|
||||
function scandirSync(path, optionsOrSettings) {
|
||||
const settings = getSettings(optionsOrSettings);
|
||||
return sync.read(path, settings);
|
||||
}
|
||||
exports.scandirSync = scandirSync;
|
||||
function getSettings(settingsOrOptions = {}) {
|
||||
if (settingsOrOptions instanceof settings_1.default) {
|
||||
return settingsOrOptions;
|
||||
}
|
||||
return new settings_1.default(settingsOrOptions);
|
||||
}
|
||||
Generated
Vendored
+104
@@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.readdir = exports.readdirWithFileTypes = exports.read = void 0;
|
||||
const fsStat = require("@nodelib/fs.stat");
|
||||
const rpl = require("run-parallel");
|
||||
const constants_1 = require("../constants");
|
||||
const utils = require("../utils");
|
||||
const common = require("./common");
|
||||
function read(directory, settings, callback) {
|
||||
if (!settings.stats && constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
|
||||
readdirWithFileTypes(directory, settings, callback);
|
||||
return;
|
||||
}
|
||||
readdir(directory, settings, callback);
|
||||
}
|
||||
exports.read = read;
|
||||
function readdirWithFileTypes(directory, settings, callback) {
|
||||
settings.fs.readdir(directory, { withFileTypes: true }, (readdirError, dirents) => {
|
||||
if (readdirError !== null) {
|
||||
callFailureCallback(callback, readdirError);
|
||||
return;
|
||||
}
|
||||
const entries = dirents.map((dirent) => ({
|
||||
dirent,
|
||||
name: dirent.name,
|
||||
path: common.joinPathSegments(directory, dirent.name, settings.pathSegmentSeparator)
|
||||
}));
|
||||
if (!settings.followSymbolicLinks) {
|
||||
callSuccessCallback(callback, entries);
|
||||
return;
|
||||
}
|
||||
const tasks = entries.map((entry) => makeRplTaskEntry(entry, settings));
|
||||
rpl(tasks, (rplError, rplEntries) => {
|
||||
if (rplError !== null) {
|
||||
callFailureCallback(callback, rplError);
|
||||
return;
|
||||
}
|
||||
callSuccessCallback(callback, rplEntries);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.readdirWithFileTypes = readdirWithFileTypes;
|
||||
function makeRplTaskEntry(entry, settings) {
|
||||
return (done) => {
|
||||
if (!entry.dirent.isSymbolicLink()) {
|
||||
done(null, entry);
|
||||
return;
|
||||
}
|
||||
settings.fs.stat(entry.path, (statError, stats) => {
|
||||
if (statError !== null) {
|
||||
if (settings.throwErrorOnBrokenSymbolicLink) {
|
||||
done(statError);
|
||||
return;
|
||||
}
|
||||
done(null, entry);
|
||||
return;
|
||||
}
|
||||
entry.dirent = utils.fs.createDirentFromStats(entry.name, stats);
|
||||
done(null, entry);
|
||||
});
|
||||
};
|
||||
}
|
||||
function readdir(directory, settings, callback) {
|
||||
settings.fs.readdir(directory, (readdirError, names) => {
|
||||
if (readdirError !== null) {
|
||||
callFailureCallback(callback, readdirError);
|
||||
return;
|
||||
}
|
||||
const tasks = names.map((name) => {
|
||||
const path = common.joinPathSegments(directory, name, settings.pathSegmentSeparator);
|
||||
return (done) => {
|
||||
fsStat.stat(path, settings.fsStatSettings, (error, stats) => {
|
||||
if (error !== null) {
|
||||
done(error);
|
||||
return;
|
||||
}
|
||||
const entry = {
|
||||
name,
|
||||
path,
|
||||
dirent: utils.fs.createDirentFromStats(name, stats)
|
||||
};
|
||||
if (settings.stats) {
|
||||
entry.stats = stats;
|
||||
}
|
||||
done(null, entry);
|
||||
});
|
||||
};
|
||||
});
|
||||
rpl(tasks, (rplError, entries) => {
|
||||
if (rplError !== null) {
|
||||
callFailureCallback(callback, rplError);
|
||||
return;
|
||||
}
|
||||
callSuccessCallback(callback, entries);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.readdir = readdir;
|
||||
function callFailureCallback(callback, error) {
|
||||
callback(error);
|
||||
}
|
||||
function callSuccessCallback(callback, result) {
|
||||
callback(null, result);
|
||||
}
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.joinPathSegments = void 0;
|
||||
function joinPathSegments(a, b, separator) {
|
||||
/**
|
||||
* The correct handling of cases when the first segment is a root (`/`, `C:/`) or UNC path (`//?/C:/`).
|
||||
*/
|
||||
if (a.endsWith(separator)) {
|
||||
return a + b;
|
||||
}
|
||||
return a + separator + b;
|
||||
}
|
||||
exports.joinPathSegments = joinPathSegments;
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.readdir = exports.readdirWithFileTypes = exports.read = void 0;
|
||||
const fsStat = require("@nodelib/fs.stat");
|
||||
const constants_1 = require("../constants");
|
||||
const utils = require("../utils");
|
||||
const common = require("./common");
|
||||
function read(directory, settings) {
|
||||
if (!settings.stats && constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
|
||||
return readdirWithFileTypes(directory, settings);
|
||||
}
|
||||
return readdir(directory, settings);
|
||||
}
|
||||
exports.read = read;
|
||||
function readdirWithFileTypes(directory, settings) {
|
||||
const dirents = settings.fs.readdirSync(directory, { withFileTypes: true });
|
||||
return dirents.map((dirent) => {
|
||||
const entry = {
|
||||
dirent,
|
||||
name: dirent.name,
|
||||
path: common.joinPathSegments(directory, dirent.name, settings.pathSegmentSeparator)
|
||||
};
|
||||
if (entry.dirent.isSymbolicLink() && settings.followSymbolicLinks) {
|
||||
try {
|
||||
const stats = settings.fs.statSync(entry.path);
|
||||
entry.dirent = utils.fs.createDirentFromStats(entry.name, stats);
|
||||
}
|
||||
catch (error) {
|
||||
if (settings.throwErrorOnBrokenSymbolicLink) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
}
|
||||
exports.readdirWithFileTypes = readdirWithFileTypes;
|
||||
function readdir(directory, settings) {
|
||||
const names = settings.fs.readdirSync(directory);
|
||||
return names.map((name) => {
|
||||
const entryPath = common.joinPathSegments(directory, name, settings.pathSegmentSeparator);
|
||||
const stats = fsStat.statSync(entryPath, settings.fsStatSettings);
|
||||
const entry = {
|
||||
name,
|
||||
path: entryPath,
|
||||
dirent: utils.fs.createDirentFromStats(name, stats)
|
||||
};
|
||||
if (settings.stats) {
|
||||
entry.stats = stats;
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
}
|
||||
exports.readdir = readdir;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path = require("path");
|
||||
const fsStat = require("@nodelib/fs.stat");
|
||||
const fs = require("./adapters/fs");
|
||||
class Settings {
|
||||
constructor(_options = {}) {
|
||||
this._options = _options;
|
||||
this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false);
|
||||
this.fs = fs.createFileSystemAdapter(this._options.fs);
|
||||
this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path.sep);
|
||||
this.stats = this._getValue(this._options.stats, false);
|
||||
this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
|
||||
this.fsStatSettings = new fsStat.Settings({
|
||||
followSymbolicLink: this.followSymbolicLinks,
|
||||
fs: this.fs,
|
||||
throwErrorOnBrokenSymbolicLink: this.throwErrorOnBrokenSymbolicLink
|
||||
});
|
||||
}
|
||||
_getValue(option, value) {
|
||||
return option !== null && option !== void 0 ? option : value;
|
||||
}
|
||||
}
|
||||
exports.default = Settings;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createDirentFromStats = void 0;
|
||||
class DirentFromStats {
|
||||
constructor(name, stats) {
|
||||
this.name = name;
|
||||
this.isBlockDevice = stats.isBlockDevice.bind(stats);
|
||||
this.isCharacterDevice = stats.isCharacterDevice.bind(stats);
|
||||
this.isDirectory = stats.isDirectory.bind(stats);
|
||||
this.isFIFO = stats.isFIFO.bind(stats);
|
||||
this.isFile = stats.isFile.bind(stats);
|
||||
this.isSocket = stats.isSocket.bind(stats);
|
||||
this.isSymbolicLink = stats.isSymbolicLink.bind(stats);
|
||||
}
|
||||
}
|
||||
function createDirentFromStats(name, stats) {
|
||||
return new DirentFromStats(name, stats);
|
||||
}
|
||||
exports.createDirentFromStats = createDirentFromStats;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.fs = void 0;
|
||||
const fs = require("./fs");
|
||||
exports.fs = fs;
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "@nodelib/fs.scandir",
|
||||
"version": "2.1.5",
|
||||
"description": "List files and directories inside the specified directory",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/nodelib/nodelib/tree/master/packages/fs/fs.scandir",
|
||||
"keywords": [
|
||||
"NodeLib",
|
||||
"fs",
|
||||
"FileSystem",
|
||||
"file system",
|
||||
"scandir",
|
||||
"readdir",
|
||||
"dirent"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
},
|
||||
"files": [
|
||||
"out/**",
|
||||
"!out/**/*.map",
|
||||
"!out/**/*.spec.*"
|
||||
],
|
||||
"main": "out/index.js",
|
||||
"typings": "out/index.d.ts",
|
||||
"scripts": {
|
||||
"clean": "rimraf {tsconfig.tsbuildinfo,out}",
|
||||
"lint": "eslint \"src/**/*.ts\" --cache",
|
||||
"compile": "tsc -b .",
|
||||
"compile:watch": "tsc -p . --watch --sourceMap",
|
||||
"test": "mocha \"out/**/*.spec.js\" -s 0",
|
||||
"build": "npm run clean && npm run compile && npm run lint && npm test",
|
||||
"watch": "npm run clean && npm run compile:watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nodelib/fs.stat": "2.0.5",
|
||||
"run-parallel": "^1.1.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nodelib/fs.macchiato": "1.0.4",
|
||||
"@types/run-parallel": "^1.1.0"
|
||||
},
|
||||
"gitHead": "d6a7960d5281d3dd5f8e2efba49bb552d090f562"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Denis Malinochkin
|
||||
|
||||
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.
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
|
||||
const fs = require("fs");
|
||||
exports.FILE_SYSTEM_ADAPTER = {
|
||||
lstat: fs.lstat,
|
||||
stat: fs.stat,
|
||||
lstatSync: fs.lstatSync,
|
||||
statSync: fs.statSync
|
||||
};
|
||||
function createFileSystemAdapter(fsMethods) {
|
||||
if (fsMethods === undefined) {
|
||||
return exports.FILE_SYSTEM_ADAPTER;
|
||||
}
|
||||
return Object.assign(Object.assign({}, exports.FILE_SYSTEM_ADAPTER), fsMethods);
|
||||
}
|
||||
exports.createFileSystemAdapter = createFileSystemAdapter;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.statSync = exports.stat = exports.Settings = void 0;
|
||||
const async = require("./providers/async");
|
||||
const sync = require("./providers/sync");
|
||||
const settings_1 = require("./settings");
|
||||
exports.Settings = settings_1.default;
|
||||
function stat(path, optionsOrSettingsOrCallback, callback) {
|
||||
if (typeof optionsOrSettingsOrCallback === 'function') {
|
||||
async.read(path, getSettings(), optionsOrSettingsOrCallback);
|
||||
return;
|
||||
}
|
||||
async.read(path, getSettings(optionsOrSettingsOrCallback), callback);
|
||||
}
|
||||
exports.stat = stat;
|
||||
function statSync(path, optionsOrSettings) {
|
||||
const settings = getSettings(optionsOrSettings);
|
||||
return sync.read(path, settings);
|
||||
}
|
||||
exports.statSync = statSync;
|
||||
function getSettings(settingsOrOptions = {}) {
|
||||
if (settingsOrOptions instanceof settings_1.default) {
|
||||
return settingsOrOptions;
|
||||
}
|
||||
return new settings_1.default(settingsOrOptions);
|
||||
}
|
||||
Loaded 100 of 1074 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user