This commit is contained in:
tatianamac
2019-11-26 14:50:43 -08:00
parent 8a55660ed0
commit 6d5445ecc5
13894 changed files with 2233957 additions and 0 deletions

22
node_modules/constantinople/.gitattributes generated vendored Normal file
View File

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

5
node_modules/constantinople/.prettierrc generated vendored Normal file
View File

@ -0,0 +1,5 @@
{
"bracketSpacing": false,
"singleQuote": true,
"trailingComma": "all"
}

5
node_modules/constantinople/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,5 @@
language: node_js
node_js:
- "4"
- "6"
- "8"

19
node_modules/constantinople/LICENSE generated vendored Normal file
View File

@ -0,0 +1,19 @@
Copyright (c) 2013 Forbes Lindesay
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.

46
node_modules/constantinople/README.md generated vendored Normal file
View File

@ -0,0 +1,46 @@
# constantinople
Determine whether a JavaScript expression evaluates to a constant (using Babylon). Here it is assumed to be safe to underestimate how constant something is.
[![Build Status](https://img.shields.io/travis/pugjs/constantinople/master.svg)](https://travis-ci.org/pugjs/constantinople)
[![Dependency Status](https://img.shields.io/david/pugjs/constantinople.svg)](https://david-dm.org/pugjs/constantinople)
[![NPM version](https://img.shields.io/npm/v/constantinople.svg)](https://www.npmjs.org/package/constantinople)
## Installation
npm install constantinople
## Usage
```js
var isConstant = require('constantinople')
if (isConstant('"foo" + 5')) {
console.dir(isConstant.toConstant('"foo" + 5'))
}
if (isConstant('Math.floor(10.5)', {Math: Math})) {
console.dir(isConstant.toConstant('Math.floor(10.5)', {Math: Math}))
}
```
## API
### isConstant(src, [constants, [options]])
Returns `true` if `src` evaluates to a constant, `false` otherwise. It will also return `false` if there is a syntax error, which makes it safe to use on potentially ES6 code.
Constants is an object mapping strings to values, where those values should be treated as constants. Note that this makes it a pretty bad idea to have `Math` in there if the user might make use of `Math.random` and a pretty bad idea to have `Date` in there.
Options are directly passed-through to [Babylon](https://github.com/babel/babylon#options).
### toConstant(src, [constants, [options]])
Returns the value resulting from evaluating `src`. This method throws an error if the expression is not constant. e.g. `toConstant("Math.random()")` would throw an error.
Constants is an object mapping strings to values, where those values should be treated as constants. Note that this makes it a pretty bad idea to have `Math` in there if the user might make use of `Math.random` and a pretty bad idea to have `Date` in there.
Options are directly passed-through to [Babylon](https://github.com/babel/babylon#options).
## License
MIT

2
node_modules/constantinople/lib/binaryOperation.d.ts generated vendored Normal file
View File

@ -0,0 +1,2 @@
export declare type Operator = '+' | '-' | '/' | '%' | '*' | '**' | '&' | '|' | '>>' | '>>>' | '<<' | '^' | '==' | '===' | '!=' | '!==' | 'in' | 'instanceof' | '>' | '<' | '>=' | '<=';
export default function binaryOperation(operator: Operator, left: any, right: any): any;

51
node_modules/constantinople/lib/binaryOperation.js generated vendored Normal file
View File

@ -0,0 +1,51 @@
"use strict";
exports.__esModule = true;
function binaryOperation(operator, left, right) {
switch (operator) {
case '+':
return left + right;
case '-':
return left - right;
case '/':
return left / right;
case '%':
return left % right;
case '*':
return left * right;
case '**':
return Math.pow(left, right);
case '&':
return left & right;
case '|':
return left | right;
case '>>':
return left >> right;
case '>>>':
return left >>> right;
case '<<':
return left << right;
case '^':
return left ^ right;
case '==':
return left == right;
case '===':
return left === right;
case '!=':
return left != right;
case '!==':
return left !== right;
case 'in':
return left in right;
case 'instanceof':
return left instanceof right;
case '>':
return left > right;
case '<':
return left < right;
case '>=':
return left >= right;
case '<=':
return left <= right;
}
}
exports["default"] = binaryOperation;

19
node_modules/constantinople/lib/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,19 @@
import { BabylonOptions } from 'babylon';
import * as b from 'babel-types';
export { BabylonOptions };
export interface ExpressionToConstantOptions {
constants?: any;
}
export interface Options extends ExpressionToConstantOptions {
babylon?: BabylonOptions;
}
export declare function expressionToConstant(expression: b.Expression, options?: ExpressionToConstantOptions): {
constant: true;
result: any;
} | {
constant: false;
result?: void;
};
export declare function isConstant(src: string, constants?: any, options?: BabylonOptions): boolean;
export declare function toConstant(src: string, constants?: any, options?: BabylonOptions): any;
export default isConstant;

353
node_modules/constantinople/lib/index.js generated vendored Normal file
View File

@ -0,0 +1,353 @@
"use strict";
exports.__esModule = true;
var babylon_1 = require("babylon");
var b = require("babel-types");
var binaryOperation_1 = require("./binaryOperation");
function expressionToConstant(expression, options) {
if (options === void 0) { options = {}; }
var constant = true;
function toConstant(expression) {
if (!constant)
return;
if (b.isArrayExpression(expression)) {
var result_1 = [];
for (var i = 0; constant && i < expression.elements.length; i++) {
var element = expression.elements[i];
if (b.isSpreadElement(element)) {
var spread = toConstant(element.argument);
if (!(isSpreadable(spread) && constant)) {
constant = false;
}
else {
result_1.push.apply(result_1, spread);
}
}
else {
result_1.push(toConstant(element));
}
}
return result_1;
}
if (b.isBinaryExpression(expression)) {
var left = toConstant(expression.left);
var right = toConstant(expression.right);
return constant && binaryOperation_1["default"](expression.operator, left, right);
}
if (b.isBooleanLiteral(expression)) {
return expression.value;
}
if (b.isCallExpression(expression)) {
var args = [];
for (var i = 0; constant && i < expression.arguments.length; i++) {
var arg = expression.arguments[i];
if (b.isSpreadElement(arg)) {
var spread = toConstant(arg.argument);
if (!(isSpreadable(spread) && constant)) {
constant = false;
}
else {
args.push.apply(args, spread);
}
}
else {
args.push(toConstant(arg));
}
}
if (!constant)
return;
if (b.isMemberExpression(expression.callee)) {
var object = toConstant(expression.callee.object);
if (!object || !constant) {
constant = false;
return;
}
var member = expression.callee.computed
? toConstant(expression.callee.property)
: b.isIdentifier(expression.callee.property)
? expression.callee.property.name
: undefined;
if (member === undefined && !expression.callee.computed) {
constant = false;
}
if (!constant)
return;
if (canCallMethod(object, '' + member)) {
return object[member].apply(object, args);
}
}
else {
var callee = toConstant(expression.callee);
if (!constant)
return;
return callee.apply(null, args);
}
}
if (b.isConditionalExpression(expression)) {
var test = toConstant(expression.test);
return test
? toConstant(expression.consequent)
: toConstant(expression.alternate);
}
if (b.isIdentifier(expression)) {
if (options.constants &&
{}.hasOwnProperty.call(options.constants, expression.name)) {
return options.constants[expression.name];
}
}
if (b.isLogicalExpression(expression)) {
var left = toConstant(expression.left);
var right = toConstant(expression.right);
if (constant && expression.operator === '&&') {
return left && right;
}
if (constant && expression.operator === '||') {
return left || right;
}
}
if (b.isMemberExpression(expression)) {
var object = toConstant(expression.object);
if (!object || !constant) {
constant = false;
return;
}
var member = expression.computed
? toConstant(expression.property)
: b.isIdentifier(expression.property)
? expression.property.name
: undefined;
if (member === undefined && !expression.computed) {
constant = false;
}
if (!constant)
return;
if ({}.hasOwnProperty.call(object, '' + member) && member[0] !== '_') {
return object[member];
}
}
if (b.isNullLiteral(expression)) {
return null;
}
if (b.isNumericLiteral(expression)) {
return expression.value;
}
if (b.isObjectExpression(expression)) {
var result_2 = {};
for (var i = 0; constant && i < expression.properties.length; i++) {
var property = expression.properties[i];
if (b.isObjectProperty(property)) {
if (property.shorthand) {
constant = false;
return;
}
var key = property.computed
? toConstant(property.key)
: b.isIdentifier(property.key)
? property.key.name
: b.isStringLiteral(property.key)
? property.key.value
: undefined;
if (!key || key[0] === '_') {
constant = false;
}
if (!constant)
return;
var value = toConstant(property.value);
if (!constant)
return;
result_2[key] = value;
}
else if (b.isObjectMethod(property)) {
constant = false;
}
else if (b.isSpreadProperty(property)) {
var argument = toConstant(property.argument);
if (!argument)
constant = false;
if (!constant)
return;
Object.assign(result_2, argument);
}
}
return result_2;
}
if (b.isParenthesizedExpression(expression)) {
return toConstant(expression.expression);
}
if (b.isRegExpLiteral(expression)) {
return new RegExp(expression.pattern, expression.flags);
}
if (b.isSequenceExpression(expression)) {
for (var i = 0; i < expression.expressions.length - 1 && constant; i++) {
toConstant(expression.expressions[i]);
}
return toConstant(expression.expressions[expression.expressions.length - 1]);
}
if (b.isStringLiteral(expression)) {
return expression.value;
}
// TODO: TaggedTemplateExpression
if (b.isTemplateLiteral(expression)) {
var result_3 = '';
for (var i = 0; i < expression.quasis.length; i++) {
var quasi = expression.quasis[i];
result_3 += quasi.value.cooked;
if (i < expression.expressions.length) {
result_3 += '' + toConstant(expression.expressions[i]);
}
}
return result_3;
}
if (b.isUnaryExpression(expression)) {
var argument = toConstant(expression.argument);
if (!constant) {
return;
}
switch (expression.operator) {
case '-':
return -argument;
case '+':
return +argument;
case '!':
return !argument;
case '~':
return ~argument;
case 'typeof':
return typeof argument;
case 'void':
return void argument;
}
}
constant = false;
}
var result = toConstant(expression);
return constant ? { constant: true, result: result } : { constant: false };
}
exports.expressionToConstant = expressionToConstant;
function isSpreadable(value) {
return (typeof value === 'string' ||
Array.isArray(value) ||
(typeof Set !== 'undefined' && value instanceof Set) ||
(typeof Map !== 'undefined' && value instanceof Map));
}
function shallowEqual(a, b) {
if (a === b)
return true;
if (a && b && typeof a === 'object' && typeof b === 'object') {
for (var key in a) {
if (a[key] !== b[key]) {
return false;
}
}
for (var key in b) {
if (a[key] !== b[key]) {
return false;
}
}
return true;
}
return false;
}
function canCallMethod(object, member) {
switch (typeof object) {
case 'boolean':
switch (member) {
case 'toString':
return true;
default:
return false;
}
case 'number':
switch (member) {
case 'toExponential':
case 'toFixed':
case 'toPrecision':
case 'toString':
return true;
default:
return false;
}
case 'string':
switch (member) {
case 'charAt':
case 'charCodeAt':
case 'codePointAt':
case 'concat':
case 'endsWith':
case 'includes':
case 'indexOf':
case 'lastIndexOf':
case 'match':
case 'normalize':
case 'padEnd':
case 'padStart':
case 'repeat':
case 'replace':
case 'search':
case 'slice':
case 'split':
case 'startsWith':
case 'substr':
case 'substring':
case 'toLowerCase':
case 'toUpperCase':
case 'trim':
return true;
default:
return false;
}
default:
if (object instanceof RegExp) {
switch (member) {
case 'test':
case 'exec':
return true;
default:
return false;
}
}
return {}.hasOwnProperty.call(object, member) && member[0] !== '_';
}
}
var EMPTY_OBJECT = {};
var lastSrc = '';
var lastConstants = EMPTY_OBJECT;
var lastOptions = EMPTY_OBJECT;
var lastResult = null;
var lastWasConstant = false;
function isConstant(src, constants, options) {
if (constants === void 0) { constants = EMPTY_OBJECT; }
if (options === void 0) { options = EMPTY_OBJECT; }
if (lastSrc === src &&
shallowEqual(lastConstants, constants) &&
shallowEqual(lastOptions, options)) {
return lastWasConstant;
}
lastSrc = src;
lastConstants = constants;
var ast;
try {
ast = babylon_1.parseExpression(src, options);
}
catch (ex) {
return (lastWasConstant = false);
}
var _a = expressionToConstant(ast, { constants: constants }), result = _a.result, constant = _a.constant;
lastResult = result;
return (lastWasConstant = constant);
}
exports.isConstant = isConstant;
function toConstant(src, constants, options) {
if (constants === void 0) { constants = EMPTY_OBJECT; }
if (options === void 0) { options = EMPTY_OBJECT; }
if (!isConstant(src, constants, options)) {
throw new Error(JSON.stringify(src) + ' is not constant.');
}
return lastResult;
}
exports.toConstant = toConstant;
exports["default"] = isConstant;
module.exports = isConstant;
module.exports["default"] = isConstant;
module.exports.expressionToConstant = expressionToConstant;
module.exports.isConstant = isConstant;
module.exports.toConstant = toConstant;

71
node_modules/constantinople/package.json generated vendored Normal file
View File

@ -0,0 +1,71 @@
{
"_args": [
[
"constantinople@3.1.2",
"/Users/tatiana/selfdefined"
]
],
"_from": "constantinople@3.1.2",
"_id": "constantinople@3.1.2",
"_inBundle": false,
"_integrity": "sha512-yePcBqEFhLOqSBtwYOGGS1exHo/s1xjekXiinh4itpNQGCu4KA1euPh1fg07N2wMITZXQkBz75Ntdt1ctGZouw==",
"_location": "/constantinople",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "constantinople@3.1.2",
"name": "constantinople",
"escapedName": "constantinople",
"rawSpec": "3.1.2",
"saveSpec": null,
"fetchSpec": "3.1.2"
},
"_requiredBy": [
"/pug-attrs",
"/pug-code-gen",
"/pug-filters"
],
"_resolved": "https://registry.npmjs.org/constantinople/-/constantinople-3.1.2.tgz",
"_spec": "3.1.2",
"_where": "/Users/tatiana/selfdefined",
"author": {
"name": "ForbesLindesay"
},
"bugs": {
"url": "https://github.com/ForbesLindesay/constantinople/issues"
},
"dependencies": {
"@types/babel-types": "^7.0.0",
"@types/babylon": "^6.16.2",
"babel-types": "^6.26.0",
"babylon": "^6.18.0"
},
"description": "Determine whether a JavaScript expression evaluates to a constant (using acorn)",
"devDependencies": {
"@types/node": "^9.4.4",
"mocha": "*",
"typescript": "^2.7.1"
},
"homepage": "https://github.com/ForbesLindesay/constantinople#readme",
"keywords": [
"acorn",
"ast",
"tooling"
],
"license": "MIT",
"main": "lib/index.js",
"name": "constantinople",
"repository": {
"type": "git",
"url": "git+https://github.com/ForbesLindesay/constantinople.git"
},
"scripts": {
"build": "tsc",
"prepublish": "npm run build",
"pretest": "npm run build",
"test": "mocha -R spec"
},
"types": "lib/index.d.ts",
"version": "3.1.2"
}

76
node_modules/constantinople/src/binaryOperation.ts generated vendored Normal file
View File

@ -0,0 +1,76 @@
export type Operator =
| '+'
| '-'
| '/'
| '%'
| '*'
| '**'
| '&'
| '|'
| '>>'
| '>>>'
| '<<'
| '^'
| '=='
| '==='
| '!='
| '!=='
| 'in'
| 'instanceof'
| '>'
| '<'
| '>='
| '<=';
export default function binaryOperation(
operator: Operator,
left: any,
right: any,
): any {
switch (operator) {
case '+':
return left + right;
case '-':
return left - right;
case '/':
return left / right;
case '%':
return left % right;
case '*':
return left * right;
case '**':
return left ** right;
case '&':
return left & right;
case '|':
return left | right;
case '>>':
return left >> right;
case '>>>':
return left >>> right;
case '<<':
return left << right;
case '^':
return left ^ right;
case '==':
return left == right;
case '===':
return left === right;
case '!=':
return left != right;
case '!==':
return left !== right;
case 'in':
return left in right;
case 'instanceof':
return left instanceof right;
case '>':
return left > right;
case '<':
return left < right;
case '>=':
return left >= right;
case '<=':
return left <= right;
}
}

357
node_modules/constantinople/src/index.ts generated vendored Normal file
View File

@ -0,0 +1,357 @@
import {parseExpression, BabylonOptions} from 'babylon';
import * as b from 'babel-types';
import binaryOperation from './binaryOperation';
export {BabylonOptions};
export interface ExpressionToConstantOptions {
constants?: any;
}
export interface Options extends ExpressionToConstantOptions {
babylon?: BabylonOptions;
}
export function expressionToConstant(
expression: b.Expression,
options: ExpressionToConstantOptions = {},
): {constant: true; result: any} | {constant: false; result?: void} {
let constant = true;
function toConstant(expression: b.Expression): any {
if (!constant) return;
if (b.isArrayExpression(expression)) {
const result = [];
for (let i = 0; constant && i < expression.elements.length; i++) {
const element = expression.elements[i];
if (b.isSpreadElement(element)) {
const spread = toConstant(element.argument);
if (!(isSpreadable(spread) && constant)) {
constant = false;
} else {
result.push(...spread);
}
} else {
result.push(toConstant(element));
}
}
return result;
}
if (b.isBinaryExpression(expression)) {
const left = toConstant(expression.left);
const right = toConstant(expression.right);
return constant && binaryOperation(expression.operator, left, right);
}
if (b.isBooleanLiteral(expression)) {
return expression.value;
}
if (b.isCallExpression(expression)) {
const args = [];
for (let i = 0; constant && i < expression.arguments.length; i++) {
const arg = expression.arguments[i];
if (b.isSpreadElement(arg)) {
const spread = toConstant(arg.argument);
if (!(isSpreadable(spread) && constant)) {
constant = false;
} else {
args.push(...spread);
}
} else {
args.push(toConstant(arg));
}
}
if (!constant) return;
if (b.isMemberExpression(expression.callee)) {
const object = toConstant(expression.callee.object);
if (!object || !constant) {
constant = false;
return;
}
const member = expression.callee.computed
? toConstant(expression.callee.property)
: b.isIdentifier(expression.callee.property)
? expression.callee.property.name
: undefined;
if (member === undefined && !expression.callee.computed) {
constant = false;
}
if (!constant) return;
if (canCallMethod(object, '' + member)) {
return object[member].apply(object, args);
}
} else {
const callee = toConstant(expression.callee);
if (!constant) return;
return callee.apply(null, args);
}
}
if (b.isConditionalExpression(expression)) {
const test = toConstant(expression.test);
return test
? toConstant(expression.consequent)
: toConstant(expression.alternate);
}
if (b.isIdentifier(expression)) {
if (
options.constants &&
{}.hasOwnProperty.call(options.constants, expression.name)
) {
return options.constants[expression.name];
}
}
if (b.isLogicalExpression(expression)) {
const left = toConstant(expression.left);
const right = toConstant(expression.right);
if (constant && expression.operator === '&&') {
return left && right;
}
if (constant && expression.operator === '||') {
return left || right;
}
}
if (b.isMemberExpression(expression)) {
const object = toConstant(expression.object);
if (!object || !constant) {
constant = false;
return;
}
const member = expression.computed
? toConstant(expression.property)
: b.isIdentifier(expression.property)
? expression.property.name
: undefined;
if (member === undefined && !expression.computed) {
constant = false;
}
if (!constant) return;
if ({}.hasOwnProperty.call(object, '' + member) && member[0] !== '_') {
return object[member];
}
}
if (b.isNullLiteral(expression)) {
return null;
}
if (b.isNumericLiteral(expression)) {
return expression.value;
}
if (b.isObjectExpression(expression)) {
const result: any = {};
for (let i = 0; constant && i < expression.properties.length; i++) {
const property = expression.properties[i];
if (b.isObjectProperty(property)) {
if (property.shorthand) {
constant = false;
return;
}
const key = property.computed
? toConstant(property.key)
: b.isIdentifier(property.key)
? property.key.name
: b.isStringLiteral(property.key)
? property.key.value
: undefined;
if (!key || key[0] === '_') {
constant = false;
}
if (!constant) return;
const value = toConstant(property.value);
if (!constant) return;
result[key] = value;
} else if (b.isObjectMethod(property)) {
constant = false;
} else if (b.isSpreadProperty(property)) {
const argument = toConstant(property.argument);
if (!argument) constant = false;
if (!constant) return;
Object.assign(result, argument);
}
}
return result;
}
if (b.isParenthesizedExpression(expression)) {
return toConstant(expression.expression);
}
if (b.isRegExpLiteral(expression)) {
return new RegExp(expression.pattern, expression.flags);
}
if (b.isSequenceExpression(expression)) {
for (let i = 0; i < expression.expressions.length - 1 && constant; i++) {
toConstant(expression.expressions[i]);
}
return toConstant(
expression.expressions[expression.expressions.length - 1],
);
}
if (b.isStringLiteral(expression)) {
return expression.value;
}
// TODO: TaggedTemplateExpression
if (b.isTemplateLiteral(expression)) {
let result = '';
for (let i = 0; i < expression.quasis.length; i++) {
const quasi = expression.quasis[i];
result += quasi.value.cooked;
if (i < expression.expressions.length) {
result += '' + toConstant(expression.expressions[i]);
}
}
return result;
}
if (b.isUnaryExpression(expression)) {
const argument = toConstant(expression.argument);
if (!constant) {
return;
}
switch (expression.operator) {
case '-':
return -argument;
case '+':
return +argument;
case '!':
return !argument;
case '~':
return ~argument;
case 'typeof':
return typeof argument;
case 'void':
return void argument;
}
}
constant = false;
}
const result = toConstant(expression);
return constant ? {constant: true, result} : {constant: false};
}
function isSpreadable(value: any): boolean {
return (
typeof value === 'string' ||
Array.isArray(value) ||
(typeof Set !== 'undefined' && value instanceof Set) ||
(typeof Map !== 'undefined' && value instanceof Map)
);
}
function shallowEqual(a: any, b: any) {
if (a === b) return true;
if (a && b && typeof a === 'object' && typeof b === 'object') {
for (let key in a) {
if (a[key] !== b[key]) {
return false;
}
}
for (let key in b) {
if (a[key] !== b[key]) {
return false;
}
}
return true;
}
return false;
}
function canCallMethod(object: any, member: string): boolean {
switch (typeof object) {
case 'boolean':
switch (member) {
case 'toString':
return true;
default:
return false;
}
case 'number':
switch (member) {
case 'toExponential':
case 'toFixed':
case 'toPrecision':
case 'toString':
return true;
default:
return false;
}
case 'string':
switch (member) {
case 'charAt':
case 'charCodeAt':
case 'codePointAt':
case 'concat':
case 'endsWith':
case 'includes':
case 'indexOf':
case 'lastIndexOf':
case 'match':
case 'normalize':
case 'padEnd':
case 'padStart':
case 'repeat':
case 'replace':
case 'search':
case 'slice':
case 'split':
case 'startsWith':
case 'substr':
case 'substring':
case 'toLowerCase':
case 'toUpperCase':
case 'trim':
return true;
default:
return false;
}
default:
if (object instanceof RegExp) {
switch (member) {
case 'test':
case 'exec':
return true;
default:
return false;
}
}
return {}.hasOwnProperty.call(object, member) && member[0] !== '_';
}
}
const EMPTY_OBJECT = {};
let lastSrc = '';
let lastConstants = EMPTY_OBJECT;
let lastOptions = EMPTY_OBJECT;
let lastResult: any = null;
let lastWasConstant = false;
export function isConstant(
src: string,
constants: any = EMPTY_OBJECT,
options: BabylonOptions = EMPTY_OBJECT,
) {
if (
lastSrc === src &&
shallowEqual(lastConstants, constants) &&
shallowEqual(lastOptions, options)
) {
return lastWasConstant;
}
lastSrc = src;
lastConstants = constants;
let ast: b.Expression | void;
try {
ast = parseExpression(src, options);
} catch (ex) {
return (lastWasConstant = false);
}
const {result, constant} = expressionToConstant(ast, {constants});
lastResult = result;
return (lastWasConstant = constant);
}
export function toConstant(
src: string,
constants: any = EMPTY_OBJECT,
options: BabylonOptions = EMPTY_OBJECT,
) {
if (!isConstant(src, constants, options)) {
throw new Error(JSON.stringify(src) + ' is not constant.');
}
return lastResult;
}
export default isConstant;
module.exports = isConstant;
module.exports.default = isConstant;
module.exports.expressionToConstant = expressionToConstant;
module.exports.isConstant = isConstant;
module.exports.toConstant = toConstant;

86
node_modules/constantinople/test/index.js generated vendored Normal file
View File

@ -0,0 +1,86 @@
'use strict';
var assert = require('assert');
var constaninople = require('../');
describe('isConstant(src)', function() {
it('handles "[5 + 3 + 10]"', function() {
assert(constaninople.isConstant('[5 + 3 + 10]') === true);
});
it('handles "/[a-z]/i.test(\'a\')"', function() {
assert(constaninople.isConstant("/[a-z]/i.test('a')") === true);
});
it("handles \"{'class': [('data')]}\"", function() {
assert(constaninople.isConstant("{'class': [('data')]}") === true);
});
it('handles "Math.random()"', function() {
assert(constaninople.isConstant('Math.random()') === false);
});
it('handles "Math.random("', function() {
assert(constaninople.isConstant('Math.random(') === false);
});
it('handles "Math.floor(10.5)" with {Math: Math} as constants', function() {
assert(constaninople.isConstant('Math.floor(10.5)', {Math: Math}) === true);
});
it('handles "this.myVar"', function() {
assert(constaninople.isConstant('this.myVar') === false);
});
it('handles "(function () { while (true); return 10; }())"', function() {
assert(
constaninople.isConstant(
'(function () { while (true); return 10; }())',
) === false,
);
});
it('handles "({}).toString.constructor("console.log(1)")()"', function() {
assert(
constaninople.isConstant(
'({}).toString.constructor("console.log(1)")()',
) === false,
);
});
});
describe('toConstant(src)', function() {
it('handles "[5 + 3 + 10]"', function() {
assert.deepEqual(constaninople.toConstant('[5 + 3 + 10]'), [5 + 3 + 10]);
});
it('handles "/[a-z]/i.test(\'a\')"', function() {
assert(constaninople.toConstant("/[a-z]/i.test('a')") === true);
});
it("handles \"{'class': [('data')]}\"", function() {
assert.deepEqual(constaninople.toConstant("{'class': [('data')]}"), {
class: ['data'],
});
});
it('handles "Math.random()"', function() {
try {
constaninople.toConstant('Math.random()');
} catch (ex) {
return;
}
assert(false, 'Math.random() should result in an error');
});
it('handles "Math.random("', function() {
try {
constaninople.toConstant('Math.random(');
} catch (ex) {
return;
}
assert(false, 'Math.random( should result in an error');
});
it('handles "Math.floor(10.5)" with {Math: Math} as constants', function() {
assert(constaninople.toConstant('Math.floor(10.5)', {Math: Math}) === 10);
});
it('handles "(function () { while (true); return 10; }())"', function() {
try {
constaninople.toConstant('(function () { while (true); return 10; }())');
} catch (ex) {
return;
}
assert(
false,
'(function () { while (true); return 10; }()) should result in an error',
);
});
});

8
node_modules/constantinople/tsconfig.json generated vendored Normal file
View File

@ -0,0 +1,8 @@
{
"compilerOptions": {
"declaration": true,
"outDir": "lib",
"strict": true,
"lib": ["es2017"]
}
}