WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const util_1 = require("../util");
|
||||
const analyzeChain_1 = require("./prefer-optional-chain-utils/analyzeChain");
|
||||
const checkNullishAndReport_1 = require("./prefer-optional-chain-utils/checkNullishAndReport");
|
||||
const gatherLogicalOperands_1 = require("./prefer-optional-chain-utils/gatherLogicalOperands");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'prefer-optional-chain',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Enforce using concise optional chain expressions instead of chained logical ands, negated logical ors, or empty objects',
|
||||
recommended: 'stylistic',
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
fixable: 'code',
|
||||
hasSuggestions: true,
|
||||
messages: {
|
||||
optionalChainSuggest: 'Change to an optional chain.',
|
||||
preferOptionalChain: "Prefer using an optional chain expression instead, as it's more concise and easier to read.",
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing: {
|
||||
type: 'boolean',
|
||||
description: 'Allow autofixers that will change the return type of the expression. This option is considered unsafe as it may break the build.',
|
||||
},
|
||||
checkAny: {
|
||||
type: 'boolean',
|
||||
description: 'Check operands that are typed as `any` when inspecting "loose boolean" operands.',
|
||||
},
|
||||
checkBigInt: {
|
||||
type: 'boolean',
|
||||
description: 'Check operands that are typed as `bigint` when inspecting "loose boolean" operands.',
|
||||
},
|
||||
checkBoolean: {
|
||||
type: 'boolean',
|
||||
description: 'Check operands that are typed as `boolean` when inspecting "loose boolean" operands.',
|
||||
},
|
||||
checkNumber: {
|
||||
type: 'boolean',
|
||||
description: 'Check operands that are typed as `number` when inspecting "loose boolean" operands.',
|
||||
},
|
||||
checkString: {
|
||||
type: 'boolean',
|
||||
description: 'Check operands that are typed as `string` when inspecting "loose boolean" operands.',
|
||||
},
|
||||
checkUnknown: {
|
||||
type: 'boolean',
|
||||
description: 'Check operands that are typed as `unknown` when inspecting "loose boolean" operands.',
|
||||
},
|
||||
requireNullish: {
|
||||
type: 'boolean',
|
||||
description: 'Skip operands that are not typed with `null` and/or `undefined` when inspecting "loose boolean" operands.',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing: false,
|
||||
checkAny: true,
|
||||
checkBigInt: true,
|
||||
checkBoolean: true,
|
||||
checkNumber: true,
|
||||
checkString: true,
|
||||
checkUnknown: true,
|
||||
requireNullish: false,
|
||||
},
|
||||
],
|
||||
create(context, [options]) {
|
||||
const parserServices = (0, util_1.getParserServices)(context);
|
||||
const seenLogicals = new Set();
|
||||
return {
|
||||
'LogicalExpression[operator!="??"]'(node) {
|
||||
if (seenLogicals.has(node)) {
|
||||
return;
|
||||
}
|
||||
const { newlySeenLogicals, operands } = (0, gatherLogicalOperands_1.gatherLogicalOperands)(node, parserServices, context.sourceCode, options);
|
||||
for (const logical of newlySeenLogicals) {
|
||||
seenLogicals.add(logical);
|
||||
}
|
||||
let currentChain = [];
|
||||
for (const operand of operands) {
|
||||
if (operand.type === gatherLogicalOperands_1.OperandValidity.Invalid) {
|
||||
(0, analyzeChain_1.analyzeChain)(context, parserServices, options, node, node.operator, currentChain);
|
||||
currentChain = [];
|
||||
}
|
||||
else if (operand.type === gatherLogicalOperands_1.OperandValidity.Last) {
|
||||
(0, analyzeChain_1.analyzeChain)(context, parserServices, options, node, node.operator, currentChain, operand);
|
||||
currentChain = [];
|
||||
}
|
||||
else {
|
||||
currentChain.push(operand);
|
||||
}
|
||||
}
|
||||
// make sure to check whatever's left
|
||||
if (currentChain.length > 0) {
|
||||
(0, analyzeChain_1.analyzeChain)(context, parserServices, options, node, node.operator, currentChain);
|
||||
}
|
||||
},
|
||||
// specific handling for `(foo ?? {}).bar` / `(foo || {}).bar`
|
||||
'LogicalExpression[operator="||"], LogicalExpression[operator="??"]'(node) {
|
||||
const leftNode = node.left;
|
||||
const rightNode = node.right;
|
||||
const parentNode = node.parent;
|
||||
const isRightNodeAnEmptyObjectLiteral = rightNode.type === utils_1.AST_NODE_TYPES.ObjectExpression &&
|
||||
rightNode.properties.length === 0;
|
||||
if (!isRightNodeAnEmptyObjectLiteral ||
|
||||
parentNode.type !== utils_1.AST_NODE_TYPES.MemberExpression ||
|
||||
parentNode.optional) {
|
||||
return;
|
||||
}
|
||||
seenLogicals.add(node);
|
||||
function isLeftSideLowerPrecedence() {
|
||||
const logicalTsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
|
||||
const leftTsNode = parserServices.esTreeNodeToTSNodeMap.get(leftNode);
|
||||
const leftPrecedence = (0, util_1.getOperatorPrecedence)(leftTsNode.kind, logicalTsNode.operatorToken.kind);
|
||||
return leftPrecedence < util_1.OperatorPrecedence.LeftHandSide;
|
||||
}
|
||||
(0, checkNullishAndReport_1.checkNullishAndReport)(context, parserServices, options, [leftNode], {
|
||||
node: parentNode,
|
||||
messageId: 'preferOptionalChain',
|
||||
suggest: [
|
||||
{
|
||||
messageId: 'optionalChainSuggest',
|
||||
fix: (fixer) => {
|
||||
const leftNodeText = context.sourceCode.getText(leftNode);
|
||||
// Any node that is made of an operator with higher or equal precedence,
|
||||
const maybeWrappedLeftNode = isLeftSideLowerPrecedence()
|
||||
? `(${leftNodeText})`
|
||||
: leftNodeText;
|
||||
const propertyToBeOptionalText = context.sourceCode.getText(parentNode.property);
|
||||
const maybeWrappedProperty = parentNode.computed
|
||||
? `[${propertyToBeOptionalText}]`
|
||||
: propertyToBeOptionalText;
|
||||
return fixer.replaceTextRange(parentNode.range, `${maybeWrappedLeftNode}?.${maybeWrappedProperty}`);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';
|
||||
export default _default;
|
||||
/**
|
||||
* A version of `stylistic` that only contains type-checked rules and disables of any corresponding core ESLint rules.
|
||||
* @see {@link https://typescript-eslint.io/users/configs#stylistic-type-checked-only}
|
||||
*/
|
||||
declare function _default(plugin: FlatConfig.Plugin, parser: FlatConfig.Parser): FlatConfig.ConfigArray;
|
||||
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
function _new_arrow_check(innerThis, boundThis) {
|
||||
if (innerThis !== boundThis) throw new TypeError("Cannot instantiate an arrow function");
|
||||
}
|
||||
exports._ = _new_arrow_check;
|
||||
@@ -0,0 +1 @@
|
||||
export { _ as default } from "../esm/_class_check_private_static_access.js";
|
||||
@@ -0,0 +1,28 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
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
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
/// <reference lib="es2020.intl" />
|
||||
|
||||
interface Number {
|
||||
/**
|
||||
* Converts a number to a string by using the current or specified locale.
|
||||
* @param locales A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
|
||||
* @param options An object that contains one or more properties that specify comparison options.
|
||||
*/
|
||||
toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions): string;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
getpino.io
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,308 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ScopeBase = void 0;
|
||||
const types_1 = require("@typescript-eslint/types");
|
||||
const assert_1 = require("../assert");
|
||||
const ID_1 = require("../ID");
|
||||
const Reference_1 = require("../referencer/Reference");
|
||||
const variable_1 = require("../variable");
|
||||
const ScopeType_1 = require("./ScopeType");
|
||||
/**
|
||||
* Test if scope is strict
|
||||
*/
|
||||
function isStrictScope(scope, block, isMethodDefinition) {
|
||||
let body;
|
||||
// When upper scope is exists and strict, inner scope is also strict.
|
||||
if (scope.upper?.isStrict) {
|
||||
return true;
|
||||
}
|
||||
if (isMethodDefinition) {
|
||||
return true;
|
||||
}
|
||||
if (scope.type === ScopeType_1.ScopeType.class ||
|
||||
scope.type === ScopeType_1.ScopeType.conditionalType ||
|
||||
scope.type === ScopeType_1.ScopeType.functionType ||
|
||||
scope.type === ScopeType_1.ScopeType.mappedType ||
|
||||
scope.type === ScopeType_1.ScopeType.module ||
|
||||
scope.type === ScopeType_1.ScopeType.tsEnum ||
|
||||
scope.type === ScopeType_1.ScopeType.tsModule ||
|
||||
scope.type === ScopeType_1.ScopeType.type) {
|
||||
return true;
|
||||
}
|
||||
if (scope.type === ScopeType_1.ScopeType.block || scope.type === ScopeType_1.ScopeType.switch) {
|
||||
return false;
|
||||
}
|
||||
if (scope.type === ScopeType_1.ScopeType.function) {
|
||||
const functionBody = block;
|
||||
switch (functionBody.type) {
|
||||
case types_1.AST_NODE_TYPES.ArrowFunctionExpression:
|
||||
if (functionBody.body.type !== types_1.AST_NODE_TYPES.BlockStatement) {
|
||||
return false;
|
||||
}
|
||||
body = functionBody.body;
|
||||
break;
|
||||
case types_1.AST_NODE_TYPES.Program:
|
||||
body = functionBody;
|
||||
break;
|
||||
default:
|
||||
body = functionBody.body;
|
||||
}
|
||||
if (!body) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (scope.type === ScopeType_1.ScopeType.global) {
|
||||
body = block;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
// Search 'use strict' directive.
|
||||
for (const stmt of body.body) {
|
||||
if (stmt.type !== types_1.AST_NODE_TYPES.ExpressionStatement ||
|
||||
stmt.directive == null) {
|
||||
break;
|
||||
}
|
||||
if (stmt.directive === 'use strict') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function registerScope(scopeManager, scope) {
|
||||
scopeManager.scopes.push(scope);
|
||||
const scopes = scopeManager.nodeToScope.get(scope.block);
|
||||
if (scopes) {
|
||||
scopes.push(scope);
|
||||
}
|
||||
else {
|
||||
scopeManager.nodeToScope.set(scope.block, [scope]);
|
||||
}
|
||||
}
|
||||
const generator = (0, ID_1.createIdGenerator)();
|
||||
const VARIABLE_SCOPE_TYPES = new Set([
|
||||
ScopeType_1.ScopeType.classFieldInitializer,
|
||||
ScopeType_1.ScopeType.classStaticBlock,
|
||||
ScopeType_1.ScopeType.function,
|
||||
ScopeType_1.ScopeType.global,
|
||||
ScopeType_1.ScopeType.module,
|
||||
ScopeType_1.ScopeType.tsModule,
|
||||
]);
|
||||
class ScopeBase {
|
||||
/**
|
||||
* A unique ID for this instance - primarily used to help debugging and testing
|
||||
*/
|
||||
$id = generator();
|
||||
/**
|
||||
* The AST node which created this scope.
|
||||
* @public
|
||||
*/
|
||||
block;
|
||||
/**
|
||||
* The array of child scopes. This does not include grandchild scopes.
|
||||
* @public
|
||||
*/
|
||||
childScopes = [];
|
||||
/**
|
||||
* A map of the variables for each node in this scope.
|
||||
* This is map is a pointer to the one in the parent ScopeManager instance
|
||||
*/
|
||||
#declaredVariables;
|
||||
/**
|
||||
* Generally, through the lexical scoping of JS you can always know which variable an identifier in the source code
|
||||
* refers to. There are a few exceptions to this rule. With `global` and `with` scopes you can only decide at runtime
|
||||
* which variable a reference refers to.
|
||||
* All those scopes are considered "dynamic".
|
||||
*/
|
||||
#dynamic;
|
||||
/**
|
||||
* Whether this scope is created by a FunctionExpression.
|
||||
* @public
|
||||
*/
|
||||
functionExpressionScope = false;
|
||||
/**
|
||||
* Whether 'use strict' is in effect in this scope.
|
||||
* @public
|
||||
*/
|
||||
isStrict;
|
||||
/**
|
||||
* List of {@link Reference}s that are left to be resolved (i.e. which
|
||||
* need to be linked to the variable they refer to).
|
||||
*/
|
||||
leftToResolve = [];
|
||||
/**
|
||||
* Any variable {@link Reference} found in this scope.
|
||||
* This includes occurrences of local variables as well as variables from parent scopes (including the global scope).
|
||||
* For local variables this also includes defining occurrences (like in a 'var' statement).
|
||||
* In a 'function' scope this does not include the occurrences of the formal parameter in the parameter list.
|
||||
* @public
|
||||
*/
|
||||
references = [];
|
||||
/**
|
||||
* The map from variable names to variable objects.
|
||||
* @public
|
||||
*/
|
||||
set = new Map();
|
||||
/**
|
||||
* The {@link Reference}s that are not resolved with this scope.
|
||||
* @public
|
||||
*/
|
||||
through = [];
|
||||
type;
|
||||
/**
|
||||
* Reference to the parent {@link Scope}.
|
||||
* @public
|
||||
*/
|
||||
upper;
|
||||
/**
|
||||
* The scoped {@link Variable}s of this scope.
|
||||
* In the case of a 'function' scope this includes the automatic argument `arguments` as its first element, as well
|
||||
* as all further formal arguments.
|
||||
* This does not include variables which are defined in child scopes.
|
||||
* @public
|
||||
*/
|
||||
variables = [];
|
||||
/**
|
||||
* For scopes that can contain variable declarations, this is a self-reference.
|
||||
* For other scope types this is the *variableScope* value of the parent scope.
|
||||
* @public
|
||||
*/
|
||||
#dynamicCloseRef = (ref) => {
|
||||
// notify all names are through to global
|
||||
let current = this;
|
||||
do {
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
current.through.push(ref);
|
||||
current = current.upper;
|
||||
/* eslint-enable @typescript-eslint/no-non-null-assertion */
|
||||
} while (current);
|
||||
};
|
||||
#staticCloseRef = (ref) => {
|
||||
const resolve = () => {
|
||||
const name = ref.identifier.name;
|
||||
const variable = this.set.get(name);
|
||||
if (!variable) {
|
||||
return false;
|
||||
}
|
||||
if (!this.isValidResolution(ref, variable)) {
|
||||
return false;
|
||||
}
|
||||
// make sure we don't match a type reference to a value variable
|
||||
const isValidTypeReference = ref.isTypeReference && variable.isTypeVariable;
|
||||
const isValidValueReference = ref.isValueReference && variable.isValueVariable;
|
||||
if (!isValidTypeReference && !isValidValueReference) {
|
||||
return false;
|
||||
}
|
||||
variable.references.push(ref);
|
||||
ref.resolved = variable;
|
||||
return true;
|
||||
};
|
||||
if (!resolve()) {
|
||||
this.delegateToUpperScope(ref);
|
||||
}
|
||||
};
|
||||
variableScope;
|
||||
constructor(scopeManager, type, upperScope, block, isMethodDefinition) {
|
||||
const upperScopeAsScopeBase = upperScope;
|
||||
this.type = type;
|
||||
this.#dynamic =
|
||||
this.type === ScopeType_1.ScopeType.global || this.type === ScopeType_1.ScopeType.with;
|
||||
this.block = block;
|
||||
this.variableScope = this.isVariableScope()
|
||||
? this
|
||||
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
upperScopeAsScopeBase.variableScope;
|
||||
this.upper = upperScope;
|
||||
/**
|
||||
* Whether 'use strict' is in effect in this scope.
|
||||
* @member {boolean} Scope#isStrict
|
||||
*/
|
||||
this.isStrict = isStrictScope(this, block, isMethodDefinition);
|
||||
// this is guaranteed to be correct at runtime
|
||||
upperScopeAsScopeBase?.childScopes.push(this);
|
||||
this.#declaredVariables = scopeManager.declaredVariables;
|
||||
registerScope(scopeManager, this);
|
||||
}
|
||||
isVariableScope() {
|
||||
return VARIABLE_SCOPE_TYPES.has(this.type);
|
||||
}
|
||||
close(_scopeManager) {
|
||||
const closeRef = this.shouldStaticallyClose()
|
||||
? this.#staticCloseRef
|
||||
: this.#dynamicCloseRef;
|
||||
// Try Resolving all references in this scope.
|
||||
(0, assert_1.assert)(this.leftToResolve);
|
||||
this.leftToResolve.forEach(ref => closeRef(ref));
|
||||
this.leftToResolve = null;
|
||||
return this.upper;
|
||||
}
|
||||
shouldStaticallyClose() {
|
||||
return !this.#dynamic || this.type === 'global';
|
||||
}
|
||||
/**
|
||||
* To override by function scopes.
|
||||
* References in default parameters isn't resolved to variables which are in their function body.
|
||||
*/
|
||||
defineVariable(nameOrVariable, set, variables, node, def) {
|
||||
const name = typeof nameOrVariable === 'string' ? nameOrVariable : nameOrVariable.name;
|
||||
let variable = set.get(name);
|
||||
if (!variable) {
|
||||
variable =
|
||||
typeof nameOrVariable === 'string'
|
||||
? new variable_1.Variable(name, this)
|
||||
: nameOrVariable;
|
||||
set.set(name, variable);
|
||||
variables.push(variable);
|
||||
}
|
||||
if (def) {
|
||||
variable.defs.push(def);
|
||||
this.addDeclaredVariablesOfNode(variable, def.node);
|
||||
this.addDeclaredVariablesOfNode(variable, def.parent);
|
||||
}
|
||||
if (node) {
|
||||
variable.identifiers.push(node);
|
||||
}
|
||||
}
|
||||
delegateToUpperScope(ref) {
|
||||
this.upper?.leftToResolve?.push(ref);
|
||||
this.through.push(ref);
|
||||
}
|
||||
isValidResolution(_ref, _variable) {
|
||||
return true;
|
||||
}
|
||||
addDeclaredVariablesOfNode(variable, node) {
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
let variables = this.#declaredVariables.get(node);
|
||||
if (variables == null) {
|
||||
variables = [];
|
||||
this.#declaredVariables.set(node, variables);
|
||||
}
|
||||
if (!variables.includes(variable)) {
|
||||
variables.push(variable);
|
||||
}
|
||||
}
|
||||
defineIdentifier(node, def) {
|
||||
this.defineVariable(node.name, this.set, this.variables, node, def);
|
||||
}
|
||||
defineLiteralIdentifier(node, def) {
|
||||
this.defineVariable(node.value, this.set, this.variables, null, def);
|
||||
}
|
||||
referenceDualValueType(node) {
|
||||
const ref = new Reference_1.Reference(node, this, Reference_1.ReferenceFlag.Read, null, null, false, Reference_1.ReferenceTypeFlag.Type | Reference_1.ReferenceTypeFlag.Value);
|
||||
this.references.push(ref);
|
||||
this.leftToResolve?.push(ref);
|
||||
}
|
||||
referenceType(node) {
|
||||
const ref = new Reference_1.Reference(node, this, Reference_1.ReferenceFlag.Read, null, null, false, Reference_1.ReferenceTypeFlag.Type);
|
||||
this.references.push(ref);
|
||||
this.leftToResolve?.push(ref);
|
||||
}
|
||||
referenceValue(node, assign = Reference_1.ReferenceFlag.Read, writeExpr, maybeImplicitGlobal, init = false) {
|
||||
const ref = new Reference_1.Reference(node, this, assign, writeExpr, maybeImplicitGlobal, init, Reference_1.ReferenceTypeFlag.Value);
|
||||
this.references.push(ref);
|
||||
this.leftToResolve?.push(ref);
|
||||
}
|
||||
}
|
||||
exports.ScopeBase = ScopeBase;
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../../src/api/node/encoder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGR,IAAI,EAEJ,UAAU,EAEb,MAAM,oBAAoB,CAAC;AAyL5B;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAEnE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU,CAuKjD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAE3D"}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
const { pipeline, PassThrough } = require('stream')
|
||||
|
||||
module.exports = async function ({ targets }) {
|
||||
const streams = await Promise.all(targets.map(async (t) => {
|
||||
const fn = require(t.target)
|
||||
const stream = await fn(t.options)
|
||||
return stream
|
||||
}))
|
||||
|
||||
const stream = new PassThrough()
|
||||
pipeline(stream, ...streams, () => {})
|
||||
return stream
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
{
|
||||
"id": "http://json-schema.org/draft-04/schema#",
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "Core schema meta-schema",
|
||||
"definitions": {
|
||||
"schemaArray": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": { "$ref": "#" }
|
||||
},
|
||||
"positiveInteger": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"positiveIntegerDefault0": {
|
||||
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
|
||||
},
|
||||
"simpleTypes": {
|
||||
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
|
||||
},
|
||||
"stringArray": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" },
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"$schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": {},
|
||||
"multipleOf": {
|
||||
"type": "number",
|
||||
"minimum": 0,
|
||||
"exclusiveMinimum": true
|
||||
},
|
||||
"maximum": {
|
||||
"type": "number"
|
||||
},
|
||||
"exclusiveMaximum": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"minimum": {
|
||||
"type": "number"
|
||||
},
|
||||
"exclusiveMinimum": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"maxLength": { "$ref": "#/definitions/positiveInteger" },
|
||||
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
||||
"pattern": {
|
||||
"type": "string",
|
||||
"format": "regex"
|
||||
},
|
||||
"additionalItems": {
|
||||
"anyOf": [
|
||||
{ "type": "boolean" },
|
||||
{ "$ref": "#" }
|
||||
],
|
||||
"default": {}
|
||||
},
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#" },
|
||||
{ "$ref": "#/definitions/schemaArray" }
|
||||
],
|
||||
"default": {}
|
||||
},
|
||||
"maxItems": { "$ref": "#/definitions/positiveInteger" },
|
||||
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
||||
"uniqueItems": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
|
||||
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
||||
"required": { "$ref": "#/definitions/stringArray" },
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{ "type": "boolean" },
|
||||
{ "$ref": "#" }
|
||||
],
|
||||
"default": {}
|
||||
},
|
||||
"definitions": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"properties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"patternProperties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"dependencies": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#" },
|
||||
{ "$ref": "#/definitions/stringArray" }
|
||||
]
|
||||
}
|
||||
},
|
||||
"enum": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"type": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#/definitions/simpleTypes" },
|
||||
{
|
||||
"type": "array",
|
||||
"items": { "$ref": "#/definitions/simpleTypes" },
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"format": { "type": "string" },
|
||||
"allOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"anyOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"oneOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"not": { "$ref": "#" }
|
||||
},
|
||||
"dependencies": {
|
||||
"exclusiveMaximum": [ "maximum" ],
|
||||
"exclusiveMinimum": [ "minimum" ]
|
||||
},
|
||||
"default": {}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
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
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
/// <reference lib="es2022" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="webworker.importscripts" />
|
||||
/// <reference lib="scripthost" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
@@ -0,0 +1,219 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const util_1 = require("../util");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'class-methods-use-this',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Enforce that class methods utilize `this`',
|
||||
extendsBaseRule: true,
|
||||
requiresTypeChecking: false,
|
||||
},
|
||||
messages: {
|
||||
missingThis: "Expected 'this' to be used by class {{name}}.",
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
enforceForClassFields: {
|
||||
type: 'boolean',
|
||||
description: 'Enforces that functions used as instance field initializers utilize `this`.',
|
||||
},
|
||||
exceptMethods: {
|
||||
type: 'array',
|
||||
description: 'Allows specified method names to be ignored with this rule.',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
ignoreClassesThatImplementAnInterface: {
|
||||
description: 'Whether to ignore class members that are defined within a class that `implements` a type.',
|
||||
oneOf: [
|
||||
{
|
||||
type: 'boolean',
|
||||
description: 'Ignore all classes that implement an interface',
|
||||
},
|
||||
{
|
||||
type: 'string',
|
||||
description: 'Ignore only the public fields of classes that implement an interface',
|
||||
enum: ['public-fields'],
|
||||
},
|
||||
],
|
||||
},
|
||||
ignoreOverrideMethods: {
|
||||
type: 'boolean',
|
||||
description: 'Whether to ignore members marked with the `override` modifier.',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
enforceForClassFields: true,
|
||||
exceptMethods: [],
|
||||
ignoreClassesThatImplementAnInterface: false,
|
||||
ignoreOverrideMethods: false,
|
||||
},
|
||||
],
|
||||
create(context, [{ enforceForClassFields, exceptMethods: exceptMethodsRaw, ignoreClassesThatImplementAnInterface, ignoreOverrideMethods, },]) {
|
||||
const exceptMethods = new Set(exceptMethodsRaw);
|
||||
let stack;
|
||||
function pushContext(member) {
|
||||
if (member?.parent.type === utils_1.AST_NODE_TYPES.ClassBody) {
|
||||
stack = {
|
||||
class: member.parent.parent,
|
||||
member,
|
||||
parent: stack,
|
||||
usesThis: false,
|
||||
};
|
||||
}
|
||||
else {
|
||||
stack = {
|
||||
class: null,
|
||||
member: null,
|
||||
parent: stack,
|
||||
usesThis: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
function enterFunction(node) {
|
||||
if (node.parent.type === utils_1.AST_NODE_TYPES.MethodDefinition ||
|
||||
node.parent.type === utils_1.AST_NODE_TYPES.PropertyDefinition ||
|
||||
node.parent.type === utils_1.AST_NODE_TYPES.AccessorProperty) {
|
||||
pushContext(node.parent);
|
||||
}
|
||||
else {
|
||||
pushContext();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Pop `this` used flag from the stack.
|
||||
*/
|
||||
function popContext() {
|
||||
const oldStack = stack;
|
||||
stack = stack?.parent;
|
||||
return oldStack;
|
||||
}
|
||||
function isPublicField(accessibility) {
|
||||
if (!accessibility || accessibility === 'public') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Check if the node is an instance method not excluded by config
|
||||
*/
|
||||
function isIncludedInstanceMethod(node) {
|
||||
if (node.static ||
|
||||
(node.type === utils_1.AST_NODE_TYPES.MethodDefinition &&
|
||||
node.kind === 'constructor') ||
|
||||
((node.type === utils_1.AST_NODE_TYPES.PropertyDefinition ||
|
||||
node.type === utils_1.AST_NODE_TYPES.AccessorProperty) &&
|
||||
!enforceForClassFields)) {
|
||||
return false;
|
||||
}
|
||||
if (node.computed || exceptMethods.size === 0) {
|
||||
return true;
|
||||
}
|
||||
const hashIfNeeded = node.key.type === utils_1.AST_NODE_TYPES.PrivateIdentifier ? '#' : '';
|
||||
const name = (0, util_1.getStaticMemberAccessValue)(node, context);
|
||||
return (typeof name !== 'string' || !exceptMethods.has(hashIfNeeded + name));
|
||||
}
|
||||
/**
|
||||
* Checks if we are leaving a function that is a method, and reports if 'this' has not been used.
|
||||
* Static methods and the constructor are exempt.
|
||||
* Then pops the context off the stack.
|
||||
*/
|
||||
function exitFunction(node) {
|
||||
const stackContext = popContext();
|
||||
if (stackContext?.member == null ||
|
||||
stackContext.usesThis ||
|
||||
(ignoreOverrideMethods && stackContext.member.override) ||
|
||||
(ignoreClassesThatImplementAnInterface === true &&
|
||||
stackContext.class.implements.length > 0) ||
|
||||
(ignoreClassesThatImplementAnInterface === 'public-fields' &&
|
||||
stackContext.class.implements.length > 0 &&
|
||||
isPublicField(stackContext.member.accessibility))) {
|
||||
return;
|
||||
}
|
||||
if (isIncludedInstanceMethod(stackContext.member)) {
|
||||
context.report({
|
||||
loc: (0, util_1.getFunctionHeadLoc)(node, context.sourceCode),
|
||||
node,
|
||||
messageId: 'missingThis',
|
||||
data: {
|
||||
name: (0, util_1.getFunctionNameWithKind)(node),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
// function declarations have their own `this` context
|
||||
FunctionDeclaration() {
|
||||
pushContext();
|
||||
},
|
||||
'FunctionDeclaration:exit'() {
|
||||
popContext();
|
||||
},
|
||||
FunctionExpression(node) {
|
||||
enterFunction(node);
|
||||
},
|
||||
'FunctionExpression:exit'(node) {
|
||||
exitFunction(node);
|
||||
},
|
||||
...(enforceForClassFields
|
||||
? {
|
||||
'AccessorProperty > ArrowFunctionExpression.value'(node) {
|
||||
enterFunction(node);
|
||||
},
|
||||
'AccessorProperty > ArrowFunctionExpression.value:exit'(node) {
|
||||
exitFunction(node);
|
||||
},
|
||||
'PropertyDefinition > ArrowFunctionExpression.value'(node) {
|
||||
enterFunction(node);
|
||||
},
|
||||
'PropertyDefinition > ArrowFunctionExpression.value:exit'(node) {
|
||||
exitFunction(node);
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
/*
|
||||
* Class field value are implicit functions.
|
||||
*/
|
||||
'AccessorProperty:exit'() {
|
||||
popContext();
|
||||
},
|
||||
'AccessorProperty > *.key:exit'() {
|
||||
pushContext();
|
||||
},
|
||||
'PropertyDefinition:exit'() {
|
||||
popContext();
|
||||
},
|
||||
'PropertyDefinition > *.key:exit'() {
|
||||
pushContext();
|
||||
},
|
||||
/*
|
||||
* Class static blocks are implicit functions. They aren't required to use `this`,
|
||||
* but we have to push context so that it captures any use of `this` in the static block
|
||||
* separately from enclosing contexts, because static blocks have their own `this` and it
|
||||
* shouldn't count as used `this` in enclosing contexts.
|
||||
*/
|
||||
StaticBlock() {
|
||||
pushContext();
|
||||
},
|
||||
'StaticBlock:exit'() {
|
||||
popContext();
|
||||
},
|
||||
'ThisExpression, Super'() {
|
||||
if (stack) {
|
||||
stack.usesThis = true;
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,137 @@
|
||||
import { t as rolldown } from "./rolldown-DiYVDns9.mjs";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { readdir } from "node:fs/promises";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { cwd } from "node:process";
|
||||
//#region src/utils/load-config.ts
|
||||
async function bundleTsConfig(configFile, isEsm) {
|
||||
const dirnameVarName = "injected_original_dirname";
|
||||
const filenameVarName = "injected_original_filename";
|
||||
const importMetaUrlVarName = "injected_original_import_meta_url";
|
||||
const bundle = await rolldown({
|
||||
input: configFile,
|
||||
platform: "node",
|
||||
resolve: { mainFields: ["main"] },
|
||||
transform: { define: {
|
||||
__dirname: dirnameVarName,
|
||||
__filename: filenameVarName,
|
||||
"import.meta.url": importMetaUrlVarName,
|
||||
"import.meta.dirname": dirnameVarName,
|
||||
"import.meta.filename": filenameVarName
|
||||
} },
|
||||
treeshake: false,
|
||||
external: [/^[\w@][^:]/],
|
||||
plugins: [{
|
||||
name: "inject-file-scope-variables",
|
||||
transform: {
|
||||
filter: { id: /\.[cm]?[jt]s$/ },
|
||||
async handler(code, id) {
|
||||
return {
|
||||
code: `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};` + code,
|
||||
map: null
|
||||
};
|
||||
}
|
||||
}
|
||||
}]
|
||||
});
|
||||
const outputDir = path.dirname(configFile);
|
||||
const fileName = (await bundle.write({
|
||||
dir: outputDir,
|
||||
format: isEsm ? "esm" : "cjs",
|
||||
sourcemap: "inline",
|
||||
entryFileNames: `rolldown.config.[hash]${path.extname(configFile).replace("ts", "js")}`
|
||||
})).output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
|
||||
return path.join(outputDir, fileName);
|
||||
}
|
||||
const SUPPORTED_JS_CONFIG_FORMATS = [
|
||||
".js",
|
||||
".mjs",
|
||||
".cjs"
|
||||
];
|
||||
const SUPPORTED_TS_CONFIG_FORMATS = [
|
||||
".ts",
|
||||
".mts",
|
||||
".cts"
|
||||
];
|
||||
const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
|
||||
const DEFAULT_CONFIG_BASE = "rolldown.config";
|
||||
async function findConfigFileNameInCwd() {
|
||||
const filesInWorkingDirectory = new Set(await readdir(cwd()));
|
||||
for (const extension of SUPPORTED_CONFIG_FORMATS) {
|
||||
const fileName = `${DEFAULT_CONFIG_BASE}${extension}`;
|
||||
if (filesInWorkingDirectory.has(fileName)) return fileName;
|
||||
}
|
||||
throw new Error("No `rolldown.config` configuration file found.");
|
||||
}
|
||||
async function loadTsConfig(configFile) {
|
||||
const file = await bundleTsConfig(configFile, isFilePathESM(configFile));
|
||||
try {
|
||||
return (await import(pathToFileURL(file).href)).default;
|
||||
} finally {
|
||||
fs.unlink(file, () => {});
|
||||
}
|
||||
}
|
||||
function isFilePathESM(filePath) {
|
||||
if (/\.m[jt]s$/.test(filePath)) return true;
|
||||
else if (/\.c[jt]s$/.test(filePath)) return false;
|
||||
else {
|
||||
const pkg = findNearestPackageData(path.dirname(filePath));
|
||||
if (pkg) return pkg.type === "module";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function findNearestPackageData(basedir) {
|
||||
while (basedir) {
|
||||
const pkgPath = path.join(basedir, "package.json");
|
||||
if (tryStatSync(pkgPath)?.isFile()) try {
|
||||
return JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
||||
} catch {}
|
||||
const nextBasedir = path.dirname(basedir);
|
||||
if (nextBasedir === basedir) break;
|
||||
basedir = nextBasedir;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function tryStatSync(file) {
|
||||
try {
|
||||
return fs.statSync(file, { throwIfNoEntry: false });
|
||||
} catch {}
|
||||
}
|
||||
async function loadNativeConfig(resolvedPath) {
|
||||
const url = pathToFileURL(resolvedPath).href;
|
||||
const { freshImport } = await import("./dist-DKbukT1H.mjs");
|
||||
const freshImported = freshImport(url);
|
||||
if (freshImported) {
|
||||
const { result } = await freshImported;
|
||||
return result.default;
|
||||
}
|
||||
return (await import(url + "?t=" + Date.now())).default;
|
||||
}
|
||||
/**
|
||||
* Load config from a file in a way that Rolldown does.
|
||||
*
|
||||
* @param configPath The path to the config file. If empty, it will look for `rolldown.config` with supported extensions in the current working directory.
|
||||
* @param options Loading options. `configLoader` selects `'bundle'` (default) or `'native'`.
|
||||
* @returns The loaded config export
|
||||
*
|
||||
* @category Config
|
||||
*/
|
||||
async function loadConfig(configPath, options = {}) {
|
||||
const configLoader = options.configLoader ?? "bundle";
|
||||
const ext = path.extname(configPath = configPath || await findConfigFileNameInCwd());
|
||||
try {
|
||||
if (configLoader === "native") return await loadNativeConfig(path.resolve(configPath));
|
||||
if (SUPPORTED_JS_CONFIG_FORMATS.includes(ext) || process.env.NODE_OPTIONS?.includes("--import=tsx") && SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return (await import(pathToFileURL(configPath).href)).default;
|
||||
else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return await loadTsConfig(path.resolve(configPath));
|
||||
else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
|
||||
} catch (err) {
|
||||
if (configLoader === "native") {
|
||||
const tsHint = SUPPORTED_TS_CONFIG_FORMATS.includes(ext) && !process.features.typescript ? " This runtime does not natively support TypeScript config files." : "";
|
||||
throw new Error(`Failed to load the config file "${configPath}" using the "native" config loader.${tsHint} Try "--configLoader bundle", or register a loader such as "--import tsx".`, { cause: err });
|
||||
}
|
||||
throw new Error("Error happened while loading config.", { cause: err });
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
export { loadConfig as t };
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"instruction-error.d.ts","sourceRoot":"","sources":["../../src/instruction-error.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA+DtC,wBAAgB,kCAAkC;AAC9C;;GAEG;AACH,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,gBAAgB,EAAE,MAAM,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,GACtD,WAAW,CA8Bb"}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Code generated by Herebyfile.mjs generate:enums from internal/core/compileroptions.go. DO NOT EDIT.
|
||||
export var ModuleResolutionKind;
|
||||
(function (ModuleResolutionKind) {
|
||||
ModuleResolutionKind[ModuleResolutionKind["Unknown"] = 0] = "Unknown";
|
||||
ModuleResolutionKind[ModuleResolutionKind["Classic"] = 1] = "Classic";
|
||||
ModuleResolutionKind[ModuleResolutionKind["Node10"] = 2] = "Node10";
|
||||
ModuleResolutionKind[ModuleResolutionKind["Node16"] = 3] = "Node16";
|
||||
ModuleResolutionKind[ModuleResolutionKind["NodeNext"] = 99] = "NodeNext";
|
||||
ModuleResolutionKind[ModuleResolutionKind["Bundler"] = 100] = "Bundler";
|
||||
})(ModuleResolutionKind || (ModuleResolutionKind = {}));
|
||||
//# sourceMappingURL=moduleResolutionKind.js.map
|
||||
@@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
var ruleModules = require('../dotjs')
|
||||
, toHash = require('./util').toHash;
|
||||
|
||||
module.exports = function rules() {
|
||||
var RULES = [
|
||||
{ type: 'number',
|
||||
rules: [ { 'maximum': ['exclusiveMaximum'] },
|
||||
{ 'minimum': ['exclusiveMinimum'] }, 'multipleOf', 'format'] },
|
||||
{ type: 'string',
|
||||
rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
|
||||
{ type: 'array',
|
||||
rules: [ 'maxItems', 'minItems', 'items', 'contains', 'uniqueItems' ] },
|
||||
{ type: 'object',
|
||||
rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames',
|
||||
{ 'properties': ['additionalProperties', 'patternProperties'] } ] },
|
||||
{ rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf', 'if' ] }
|
||||
];
|
||||
|
||||
var ALL = [ 'type', '$comment' ];
|
||||
var KEYWORDS = [
|
||||
'$schema', '$id', 'id', '$data', '$async', 'title',
|
||||
'description', 'default', 'definitions',
|
||||
'examples', 'readOnly', 'writeOnly',
|
||||
'contentMediaType', 'contentEncoding',
|
||||
'additionalItems', 'then', 'else'
|
||||
];
|
||||
var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
|
||||
RULES.all = toHash(ALL);
|
||||
RULES.types = toHash(TYPES);
|
||||
|
||||
RULES.forEach(function (group) {
|
||||
group.rules = group.rules.map(function (keyword) {
|
||||
var implKeywords;
|
||||
if (typeof keyword == 'object') {
|
||||
var key = Object.keys(keyword)[0];
|
||||
implKeywords = keyword[key];
|
||||
keyword = key;
|
||||
implKeywords.forEach(function (k) {
|
||||
ALL.push(k);
|
||||
RULES.all[k] = true;
|
||||
});
|
||||
}
|
||||
ALL.push(keyword);
|
||||
var rule = RULES.all[keyword] = {
|
||||
keyword: keyword,
|
||||
code: ruleModules[keyword],
|
||||
implements: implKeywords
|
||||
};
|
||||
return rule;
|
||||
});
|
||||
|
||||
RULES.all.$comment = {
|
||||
keyword: '$comment',
|
||||
code: ruleModules.$comment
|
||||
};
|
||||
|
||||
if (group.type) RULES.types[group.type] = group;
|
||||
});
|
||||
|
||||
RULES.keywords = toHash(ALL.concat(KEYWORDS));
|
||||
RULES.custom = {};
|
||||
|
||||
return RULES;
|
||||
};
|
||||
Binary file not shown.
@@ -0,0 +1,411 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ComparisonType = exports.NullishComparisonType = exports.OperandValidity = exports.Yoda = void 0;
|
||||
exports.gatherLogicalOperands = gatherLogicalOperands;
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const ts_api_utils_1 = require("ts-api-utils");
|
||||
const ts = __importStar(require("typescript"));
|
||||
const util_1 = require("../../util");
|
||||
var Yoda;
|
||||
(function (Yoda) {
|
||||
Yoda[Yoda["Yes"] = 0] = "Yes";
|
||||
Yoda[Yoda["No"] = 1] = "No";
|
||||
Yoda[Yoda["Unknown"] = 2] = "Unknown";
|
||||
})(Yoda || (exports.Yoda = Yoda = {}));
|
||||
var ComparisonValueType;
|
||||
(function (ComparisonValueType) {
|
||||
ComparisonValueType["Null"] = "Null";
|
||||
ComparisonValueType["Undefined"] = "Undefined";
|
||||
ComparisonValueType["UndefinedStringLiteral"] = "UndefinedStringLiteral";
|
||||
})(ComparisonValueType || (ComparisonValueType = {}));
|
||||
var OperandValidity;
|
||||
(function (OperandValidity) {
|
||||
OperandValidity["Valid"] = "Valid";
|
||||
OperandValidity["Last"] = "Last";
|
||||
OperandValidity["Invalid"] = "Invalid";
|
||||
})(OperandValidity || (exports.OperandValidity = OperandValidity = {}));
|
||||
var NullishComparisonType;
|
||||
(function (NullishComparisonType) {
|
||||
/** `x != null`, `x != undefined` */
|
||||
NullishComparisonType["NotEqualNullOrUndefined"] = "NotEqualNullOrUndefined";
|
||||
/** `x == null`, `x == undefined` */
|
||||
NullishComparisonType["EqualNullOrUndefined"] = "EqualNullOrUndefined";
|
||||
/** `x !== null` */
|
||||
NullishComparisonType["NotStrictEqualNull"] = "NotStrictEqualNull";
|
||||
/** `x === null` */
|
||||
NullishComparisonType["StrictEqualNull"] = "StrictEqualNull";
|
||||
/** `x !== undefined`, `typeof x !== 'undefined'` */
|
||||
NullishComparisonType["NotStrictEqualUndefined"] = "NotStrictEqualUndefined";
|
||||
/** `x === undefined`, `typeof x === 'undefined'` */
|
||||
NullishComparisonType["StrictEqualUndefined"] = "StrictEqualUndefined";
|
||||
/** `!x` */
|
||||
NullishComparisonType["NotBoolean"] = "NotBoolean";
|
||||
/** `x` */
|
||||
NullishComparisonType["Boolean"] = "Boolean";
|
||||
})(NullishComparisonType || (exports.NullishComparisonType = NullishComparisonType = {}));
|
||||
var ComparisonType;
|
||||
(function (ComparisonType) {
|
||||
ComparisonType["NotEqual"] = "NotEqual";
|
||||
ComparisonType["Equal"] = "Equal";
|
||||
ComparisonType["NotStrictEqual"] = "NotStrictEqual";
|
||||
ComparisonType["StrictEqual"] = "StrictEqual";
|
||||
})(ComparisonType || (exports.ComparisonType = ComparisonType = {}));
|
||||
const NULLISH_FLAGS = ts.TypeFlags.Null | ts.TypeFlags.Undefined;
|
||||
function isValidFalseBooleanCheckType(node, disallowFalseyLiteral, parserServices, options) {
|
||||
const type = parserServices.getTypeAtLocation(node);
|
||||
const types = (0, ts_api_utils_1.unionConstituents)(type);
|
||||
const primitiveAndObjectParts = types.flatMap(type => (0, ts_api_utils_1.intersectionConstituents)(type));
|
||||
if (disallowFalseyLiteral &&
|
||||
/*
|
||||
```
|
||||
declare const x: false | {a: string};
|
||||
x && x.a;
|
||||
!x || x.a;
|
||||
```
|
||||
|
||||
We don't want to consider these two cases because the boolean expression
|
||||
narrows out the non-nullish falsy cases - so converting the chain to `x?.a`
|
||||
would introduce a build error
|
||||
*/ (primitiveAndObjectParts.some(t => (0, ts_api_utils_1.isBooleanLiteralType)(t) && t.intrinsicName === 'false') ||
|
||||
primitiveAndObjectParts.some(t => (0, ts_api_utils_1.isStringLiteralType)(t) && t.value === '') ||
|
||||
primitiveAndObjectParts.some(t => (0, ts_api_utils_1.isNumberLiteralType)(t) && t.value === 0) ||
|
||||
primitiveAndObjectParts.some(t => (0, ts_api_utils_1.isBigIntLiteralType)(t) && t.value.base10Value === '0'))) {
|
||||
return false;
|
||||
}
|
||||
let allowedFlags = NULLISH_FLAGS | ts.TypeFlags.Object;
|
||||
if (options.checkAny === true) {
|
||||
allowedFlags |= ts.TypeFlags.Any;
|
||||
}
|
||||
if (options.checkUnknown === true) {
|
||||
allowedFlags |= ts.TypeFlags.Unknown;
|
||||
}
|
||||
if (options.checkString === true) {
|
||||
allowedFlags |= ts.TypeFlags.StringLike;
|
||||
}
|
||||
if (options.checkNumber === true) {
|
||||
allowedFlags |= ts.TypeFlags.NumberLike;
|
||||
}
|
||||
if (options.checkBoolean === true) {
|
||||
allowedFlags |= ts.TypeFlags.BooleanLike;
|
||||
}
|
||||
if (options.checkBigInt === true) {
|
||||
allowedFlags |= ts.TypeFlags.BigIntLike;
|
||||
}
|
||||
return primitiveAndObjectParts.every(t => (0, util_1.isTypeFlagSet)(t, allowedFlags));
|
||||
}
|
||||
function gatherLogicalOperands(node, parserServices, sourceCode, options) {
|
||||
const result = [];
|
||||
const { newlySeenLogicals, operands } = flattenLogicalOperands(node);
|
||||
for (const operand of operands) {
|
||||
const areMoreOperands = operand !== operands.at(-1);
|
||||
switch (operand.type) {
|
||||
case utils_1.AST_NODE_TYPES.BinaryExpression: {
|
||||
// check for "yoda" style logical: null != x
|
||||
const { comparedExpression, comparedValue, isYoda } = (() => {
|
||||
// non-yoda checks are by far the most common, so check for them first
|
||||
const comparedValueRight = getComparisonValueType(operand.right);
|
||||
if (comparedValueRight) {
|
||||
return {
|
||||
comparedExpression: operand.left,
|
||||
comparedValue: comparedValueRight,
|
||||
isYoda: false,
|
||||
};
|
||||
}
|
||||
return {
|
||||
comparedExpression: operand.right,
|
||||
comparedValue: getComparisonValueType(operand.left),
|
||||
isYoda: true,
|
||||
};
|
||||
})();
|
||||
if (comparedValue === ComparisonValueType.UndefinedStringLiteral) {
|
||||
if (comparedExpression.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
|
||||
comparedExpression.operator === 'typeof') {
|
||||
const argument = comparedExpression.argument;
|
||||
if (argument.type === utils_1.AST_NODE_TYPES.Identifier &&
|
||||
// typeof window === 'undefined'
|
||||
(0, util_1.isReferenceToGlobalFunction)(argument.name, argument, sourceCode)) {
|
||||
result.push({ type: OperandValidity.Invalid });
|
||||
continue;
|
||||
}
|
||||
// typeof x.y === 'undefined'
|
||||
result.push({
|
||||
comparedName: comparedExpression.argument,
|
||||
comparisonType: operand.operator.startsWith('!')
|
||||
? NullishComparisonType.NotStrictEqualUndefined
|
||||
: NullishComparisonType.StrictEqualUndefined,
|
||||
isYoda,
|
||||
node: operand,
|
||||
type: OperandValidity.Valid,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
// y === 'undefined'
|
||||
result.push({ type: OperandValidity.Invalid });
|
||||
continue;
|
||||
}
|
||||
if (operand.operator.startsWith('!') !== (node.operator === '||')) {
|
||||
switch (operand.operator) {
|
||||
case '!=':
|
||||
case '==':
|
||||
if (comparedValue === ComparisonValueType.Null ||
|
||||
comparedValue === ComparisonValueType.Undefined) {
|
||||
// x == null, x == undefined
|
||||
result.push({
|
||||
comparedName: comparedExpression,
|
||||
comparisonType: operand.operator.startsWith('!')
|
||||
? NullishComparisonType.NotEqualNullOrUndefined
|
||||
: NullishComparisonType.EqualNullOrUndefined,
|
||||
isYoda,
|
||||
node: operand,
|
||||
type: OperandValidity.Valid,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case '!==':
|
||||
case '===': {
|
||||
const comparedName = comparedExpression;
|
||||
switch (comparedValue) {
|
||||
case ComparisonValueType.Null:
|
||||
result.push({
|
||||
comparedName,
|
||||
comparisonType: operand.operator.startsWith('!')
|
||||
? NullishComparisonType.NotStrictEqualNull
|
||||
: NullishComparisonType.StrictEqualNull,
|
||||
isYoda,
|
||||
node: operand,
|
||||
type: OperandValidity.Valid,
|
||||
});
|
||||
continue;
|
||||
case ComparisonValueType.Undefined:
|
||||
result.push({
|
||||
comparedName,
|
||||
comparisonType: operand.operator.startsWith('!')
|
||||
? NullishComparisonType.NotStrictEqualUndefined
|
||||
: NullishComparisonType.StrictEqualUndefined,
|
||||
isYoda,
|
||||
node: operand,
|
||||
type: OperandValidity.Valid,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// x == something :(
|
||||
// x === something :(
|
||||
// x != something :(
|
||||
// x !== something :(
|
||||
const binaryComparisonChain = getBinaryComparisonChain(operand);
|
||||
if (binaryComparisonChain) {
|
||||
const { comparedName, comparedValue, yoda } = binaryComparisonChain;
|
||||
switch (operand.operator) {
|
||||
case '==':
|
||||
case '===': {
|
||||
const comparisonType = operand.operator === '=='
|
||||
? ComparisonType.Equal
|
||||
: ComparisonType.StrictEqual;
|
||||
result.push({
|
||||
comparedName,
|
||||
comparisonType,
|
||||
comparisonValue: comparedValue,
|
||||
node: operand,
|
||||
type: OperandValidity.Last,
|
||||
yoda,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
case '!=':
|
||||
case '!==': {
|
||||
const comparisonType = operand.operator === '!='
|
||||
? ComparisonType.NotEqual
|
||||
: ComparisonType.NotStrictEqual;
|
||||
result.push({
|
||||
comparedName,
|
||||
comparisonType,
|
||||
comparisonValue: comparedValue,
|
||||
node: operand,
|
||||
type: OperandValidity.Last,
|
||||
yoda,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
result.push({ type: OperandValidity.Invalid });
|
||||
continue;
|
||||
}
|
||||
case utils_1.AST_NODE_TYPES.UnaryExpression:
|
||||
if (operand.operator === '!' &&
|
||||
(!areMoreOperands ||
|
||||
isValidFalseBooleanCheckType(operand.argument, node.operator === '||', parserServices, options))) {
|
||||
result.push({
|
||||
comparedName: operand.argument,
|
||||
comparisonType: NullishComparisonType.NotBoolean,
|
||||
isYoda: false,
|
||||
node: operand,
|
||||
type: OperandValidity.Valid,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
result.push({ type: OperandValidity.Invalid });
|
||||
continue;
|
||||
case utils_1.AST_NODE_TYPES.LogicalExpression:
|
||||
// explicitly ignore the mixed logical expression cases
|
||||
result.push({ type: OperandValidity.Invalid });
|
||||
continue;
|
||||
default:
|
||||
if (!areMoreOperands ||
|
||||
isValidFalseBooleanCheckType(operand, node.operator === '&&', parserServices, options)) {
|
||||
result.push({
|
||||
comparedName: operand,
|
||||
comparisonType: NullishComparisonType.Boolean,
|
||||
isYoda: false,
|
||||
node: operand,
|
||||
type: OperandValidity.Valid,
|
||||
});
|
||||
}
|
||||
else {
|
||||
result.push({ type: OperandValidity.Invalid });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return {
|
||||
newlySeenLogicals,
|
||||
operands: result,
|
||||
};
|
||||
/*
|
||||
The AST is always constructed such the first element is always the deepest element.
|
||||
I.e. for this code: `foo && foo.bar && foo.bar.baz && foo.bar.baz.buzz`
|
||||
The AST will look like this:
|
||||
{
|
||||
left: {
|
||||
left: {
|
||||
left: foo
|
||||
right: foo.bar
|
||||
}
|
||||
right: foo.bar.baz
|
||||
}
|
||||
right: foo.bar.baz.buzz
|
||||
}
|
||||
|
||||
So given any logical expression, we can perform a depth-first traversal to get
|
||||
the operands in order.
|
||||
|
||||
Note that this function purposely does not inspect mixed logical expressions
|
||||
like `foo || foo.bar && foo.bar.baz` - separate selector
|
||||
*/
|
||||
function flattenLogicalOperands(node) {
|
||||
const operands = [];
|
||||
const newlySeenLogicals = new Set([node]);
|
||||
const stack = [node.right, node.left];
|
||||
let current;
|
||||
while ((current = stack.pop())) {
|
||||
if (current.type === utils_1.AST_NODE_TYPES.LogicalExpression &&
|
||||
current.operator === node.operator) {
|
||||
newlySeenLogicals.add(current);
|
||||
stack.push(current.right);
|
||||
stack.push(current.left);
|
||||
}
|
||||
else {
|
||||
operands.push(current);
|
||||
}
|
||||
}
|
||||
return {
|
||||
newlySeenLogicals,
|
||||
operands,
|
||||
};
|
||||
}
|
||||
function getComparisonValueType(node) {
|
||||
switch (node.type) {
|
||||
case utils_1.AST_NODE_TYPES.Literal:
|
||||
// eslint-disable-next-line eqeqeq, @typescript-eslint/internal/eqeq-nullish -- intentional exact comparison against null
|
||||
if (node.value === null && node.raw === 'null') {
|
||||
return ComparisonValueType.Null;
|
||||
}
|
||||
if (node.value === 'undefined') {
|
||||
return ComparisonValueType.UndefinedStringLiteral;
|
||||
}
|
||||
return null;
|
||||
case utils_1.AST_NODE_TYPES.Identifier:
|
||||
if (node.name === 'undefined') {
|
||||
return ComparisonValueType.Undefined;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function isMemberBasedExpression(node) {
|
||||
if (node.type === utils_1.AST_NODE_TYPES.MemberExpression) {
|
||||
return true;
|
||||
}
|
||||
if (node.type === utils_1.AST_NODE_TYPES.CallExpression &&
|
||||
node.callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function getBinaryComparisonChain(node) {
|
||||
const { left, right } = node;
|
||||
const isLeftMemberExpression = isMemberBasedExpression(left);
|
||||
const isRightMemberExpression = isMemberBasedExpression(right);
|
||||
if (isLeftMemberExpression && !isRightMemberExpression) {
|
||||
const [comparedName, comparedValue] = [left, right];
|
||||
return {
|
||||
comparedName,
|
||||
comparedValue,
|
||||
yoda: Yoda.No,
|
||||
};
|
||||
}
|
||||
if (!isLeftMemberExpression && isRightMemberExpression) {
|
||||
const [comparedName, comparedValue] = [right, left];
|
||||
return {
|
||||
comparedName,
|
||||
comparedValue,
|
||||
yoda: Yoda.Yes,
|
||||
};
|
||||
}
|
||||
if (isLeftMemberExpression && isRightMemberExpression) {
|
||||
return {
|
||||
comparedName: left,
|
||||
comparedValue: right,
|
||||
yoda: Yoda.Unknown,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
# ES6-Promise (subset of [rsvp.js](https://github.com/tildeio/rsvp.js)) [](https://travis-ci.org/stefanpenner/es6-promise)
|
||||
|
||||
This is a polyfill of the [ES6 Promise](http://www.ecma-international.org/ecma-262/6.0/#sec-promise-constructor). The implementation is a subset of [rsvp.js](https://github.com/tildeio/rsvp.js) extracted by @jakearchibald, if you're wanting extra features and more debugging options, check out the [full library](https://github.com/tildeio/rsvp.js).
|
||||
|
||||
For API details and how to use promises, see the <a href="http://www.html5rocks.com/en/tutorials/es6/promises/">JavaScript Promises HTML5Rocks article</a>.
|
||||
|
||||
## Downloads
|
||||
|
||||
* [es6-promise 27.86 KB (7.33 KB gzipped)](https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.js)
|
||||
* [es6-promise-auto 27.78 KB (7.3 KB gzipped)](https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.auto.js) - Automatically provides/replaces `Promise` if missing or broken.
|
||||
* [es6-promise-min 6.17 KB (2.4 KB gzipped)](https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.min.js)
|
||||
* [es6-promise-auto-min 6.19 KB (2.4 KB gzipped)](https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.auto.min.js) - Minified version of `es6-promise-auto` above.
|
||||
|
||||
## CDN
|
||||
|
||||
To use via a CDN include this in your html:
|
||||
|
||||
```html
|
||||
<!-- Automatically provides/replaces `Promise` if missing or broken. -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script>
|
||||
|
||||
<!-- Minified version of `es6-promise-auto` below. -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script>
|
||||
|
||||
```
|
||||
|
||||
## Node.js
|
||||
|
||||
To install:
|
||||
|
||||
```sh
|
||||
yarn add es6-promise
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
npm install es6-promise
|
||||
```
|
||||
|
||||
To use:
|
||||
|
||||
```js
|
||||
var Promise = require('es6-promise').Promise;
|
||||
```
|
||||
|
||||
|
||||
## Usage in IE<9
|
||||
|
||||
`catch` and `finally` are reserved keywords in IE<9, meaning
|
||||
`promise.catch(func)` or `promise.finally(func)` throw a syntax error. To work
|
||||
around this, you can use a string to access the property as shown in the
|
||||
following example.
|
||||
|
||||
However most minifiers will automatically fix this for you, making the
|
||||
resulting code safe for old browsers and production:
|
||||
|
||||
```js
|
||||
promise['catch'](function(err) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
promise['finally'](function() {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
## Auto-polyfill
|
||||
|
||||
To polyfill the global environment (either in Node or in the browser via CommonJS) use the following code snippet:
|
||||
|
||||
```js
|
||||
require('es6-promise').polyfill();
|
||||
```
|
||||
|
||||
Alternatively
|
||||
|
||||
```js
|
||||
require('es6-promise/auto');
|
||||
```
|
||||
|
||||
Notice that we don't assign the result of `polyfill()` to any variable. The `polyfill()` method will patch the global environment (in this case to the `Promise` name) when called.
|
||||
|
||||
## Building & Testing
|
||||
|
||||
You will need to have PhantomJS installed globally in order to run the tests.
|
||||
|
||||
`npm install -g phantomjs`
|
||||
|
||||
* `npm run build` to build
|
||||
* `npm test` to run tests
|
||||
* `npm start` to run a build watcher, and webserver to test
|
||||
* `npm run test:server` for a testem test runner and watching builder
|
||||
@@ -0,0 +1,8 @@
|
||||
function _class_private_field_loose_base(receiver, privateKey) {
|
||||
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
|
||||
throw new TypeError("attempted to use private field on non-instance");
|
||||
}
|
||||
|
||||
return receiver;
|
||||
}
|
||||
export { _class_private_field_loose_base as _ };
|
||||
Reference in New Issue
Block a user