@n8n/tournament
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -10,2 +10,3 @@ "use strict"; | ||
const v = ast_types_1.builders.identifier('v'); | ||
const shouldAlwaysWrapList = ['window', 'global', 'this']; | ||
const shouldWrapInTry = (node) => { | ||
@@ -22,2 +23,10 @@ let shouldWrap = false; | ||
}, | ||
visitIdentifier(path) { | ||
if (shouldAlwaysWrapList.includes(path.node.name)) { | ||
shouldWrap = true; | ||
return false; | ||
} | ||
this.traverse(path); | ||
return; | ||
}, | ||
}); | ||
@@ -108,5 +117,3 @@ return shouldWrap; | ||
const newProg = ast_types_1.builders.program([ | ||
ast_types_1.builders.variableDeclaration('var', [ | ||
ast_types_1.builders.variableDeclarator(ast_types_1.builders.identifier('global'), ast_types_1.builders.objectExpression([])), | ||
]), | ||
ast_types_1.builders.variableDeclaration('var', [ast_types_1.builders.variableDeclarator(VariablePolyfill_1.globalIdentifier, ast_types_1.builders.objectExpression([]))]), | ||
]); | ||
@@ -113,0 +120,0 @@ let dataNode = ast_types_1.builders.thisExpression(); |
import type { ExpressionAnalysis } from './ExpressionBuilder'; | ||
import type { ExpressionEvaluatorClass } from './Evaluator'; | ||
export type { TmplDifference } from './Analysis'; | ||
export type { ExpressionEvaluator, ExpressionEvaluatorClass } from './Evaluator'; | ||
export type ReturnValue = string | null | (() => unknown); | ||
@@ -7,8 +9,8 @@ export declare class Tournament { | ||
private _dataNodeName; | ||
private _codeCache; | ||
constructor(errorHandler?: (error: Error) => void, _dataNodeName?: string); | ||
private evaluator; | ||
constructor(errorHandler?: (error: Error) => void, _dataNodeName?: string, Evaluator?: ExpressionEvaluatorClass); | ||
setEvaluator(Evaluator: ExpressionEvaluatorClass): void; | ||
getExpressionCode(expr: string): [string, ExpressionAnalysis]; | ||
tmplDiff(expr: string): import("./Analysis").TmplDifference; | ||
private getFunction; | ||
execute(expr: string, data: unknown): ReturnValue; | ||
} |
@@ -6,9 +6,13 @@ "use strict"; | ||
const Analysis_1 = require("./Analysis"); | ||
const FunctionEvaluator_1 = require("./FunctionEvaluator"); | ||
const DATA_NODE_NAME = '___n8n_data'; | ||
class Tournament { | ||
constructor(errorHandler = () => { }, _dataNodeName = DATA_NODE_NAME) { | ||
constructor(errorHandler = () => { }, _dataNodeName = DATA_NODE_NAME, Evaluator = FunctionEvaluator_1.FunctionEvaluator) { | ||
this.errorHandler = errorHandler; | ||
this._dataNodeName = _dataNodeName; | ||
this._codeCache = {}; | ||
this.setEvaluator(Evaluator); | ||
} | ||
setEvaluator(Evaluator) { | ||
this.evaluator = new Evaluator(this); | ||
} | ||
getExpressionCode(expr) { | ||
@@ -20,11 +24,2 @@ return (0, ExpressionBuilder_1.getExpressionCode)(expr, this._dataNodeName); | ||
} | ||
getFunction(expr) { | ||
if (expr in this._codeCache) { | ||
return this._codeCache[expr]; | ||
} | ||
const [code, analysis] = this.getExpressionCode(expr); | ||
const func = new Function('E', code + ';'); | ||
this._codeCache[expr] = [func, analysis]; | ||
return [func, analysis]; | ||
} | ||
execute(expr, data) { | ||
@@ -34,4 +29,3 @@ if (!expr) { | ||
} | ||
const fn = this.getFunction(expr)[0]; | ||
return fn.call(data, this.errorHandler); | ||
return this.evaluator.evaluate(expr, data); | ||
} | ||
@@ -38,0 +32,0 @@ } |
import type { types } from 'recast'; | ||
import type { StatementKind } from 'ast-types/lib/gen/kinds'; | ||
import type { namedTypes } from 'ast-types'; | ||
export declare const globalIdentifier: namedTypes.Identifier; | ||
export type DataNode = namedTypes.ThisExpression | namedTypes.Identifier; | ||
export declare const jsVariablePolyfill: (ast: types.namedTypes.File, dataNode: DataNode) => StatementKind[] | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.jsVariablePolyfill = void 0; | ||
exports.jsVariablePolyfill = exports.globalIdentifier = void 0; | ||
const recast_1 = require("recast"); | ||
@@ -10,5 +10,5 @@ const ast_types_1 = require("ast-types"); | ||
} | ||
const globalIdentifier = ast_types_1.builders.identifier(typeof window !== 'object' ? 'global' : 'window'); | ||
exports.globalIdentifier = ast_types_1.builders.identifier(typeof window !== 'object' ? 'global' : 'window'); | ||
const buildGlobalSwitch = (node, dataNode) => { | ||
return ast_types_1.builders.memberExpression(ast_types_1.builders.conditionalExpression(ast_types_1.builders.binaryExpression('in', ast_types_1.builders.literal(node.name), dataNode), dataNode, globalIdentifier), ast_types_1.builders.identifier(node.name)); | ||
return ast_types_1.builders.memberExpression(ast_types_1.builders.conditionalExpression(ast_types_1.builders.binaryExpression('in', ast_types_1.builders.literal(node.name), dataNode), dataNode, exports.globalIdentifier), ast_types_1.builders.identifier(node.name)); | ||
}; | ||
@@ -25,2 +25,3 @@ const isInScope = (path) => { | ||
}; | ||
const polyfillExceptions = ['this', 'window', 'global']; | ||
const polyfillVar = (path, dataNode, force = false) => { | ||
@@ -32,2 +33,5 @@ if (!force) { | ||
} | ||
if (polyfillExceptions.includes(path.node.name)) { | ||
return; | ||
} | ||
path.replace(buildGlobalSwitch(path.node, dataNode)); | ||
@@ -77,180 +81,177 @@ }; | ||
const jsVariablePolyfill = (ast, dataNode) => { | ||
try { | ||
(0, recast_1.visit)(ast, { | ||
visitIdentifier(path) { | ||
this.traverse(path); | ||
const parent = path.parent.node; | ||
if (Constants_1.EXEMPT_IDENTIFIER_LIST.includes(path.node.name)) { | ||
return; | ||
} | ||
switch (parent.type) { | ||
case 'AssignmentPattern': | ||
case 'Property': | ||
case 'MemberExpression': | ||
case 'OptionalMemberExpression': | ||
case 'VariableDeclarator': | ||
if (!customPatches[parent.type]) { | ||
throw new Error(`Couldn\'t find custom patcher for parent type: ${parent.type}`); | ||
} | ||
customPatches[parent.type](path, parent, dataNode); | ||
break; | ||
case 'BinaryExpression': | ||
case 'UnaryExpression': | ||
case 'ArrayExpression': | ||
case 'AssignmentExpression': | ||
case 'SequenceExpression': | ||
case 'YieldExpression': | ||
case 'UpdateExpression': | ||
case 'LogicalExpression': | ||
case 'ConditionalExpression': | ||
case 'NewExpression': | ||
case 'CallExpression': | ||
case 'OptionalCallExpression': | ||
case 'TaggedTemplateExpression': | ||
case 'TemplateLiteral': | ||
case 'AwaitExpression': | ||
case 'ImportExpression': | ||
case 'ForStatement': | ||
case 'IfStatement': | ||
case 'WhileStatement': | ||
case 'ForInStatement': | ||
case 'ForOfStatement': | ||
case 'SwitchStatement': | ||
case 'ReturnStatement': | ||
case 'DoWhileStatement': | ||
case 'ExpressionStatement': | ||
case 'ForAwaitStatement': | ||
case 'ThrowStatement': | ||
case 'WithStatement': | ||
case 'TupleExpression': | ||
polyfillVar(path, dataNode); | ||
break; | ||
case 'Super': | ||
case 'Identifier': | ||
case 'ArrowFunctionExpression': | ||
case 'FunctionDeclaration': | ||
case 'FunctionExpression': | ||
case 'ThisExpression': | ||
case 'ObjectExpression': | ||
case 'MetaProperty': | ||
case 'ChainExpression': | ||
case 'PrivateName': | ||
case 'ParenthesizedExpression': | ||
case 'Import': | ||
case 'VariableDeclaration': | ||
case 'CatchClause': | ||
case 'BlockStatement': | ||
case 'TryStatement': | ||
case 'EmptyStatement': | ||
case 'LabeledStatement': | ||
case 'BreakStatement': | ||
case 'ContinueStatement': | ||
case 'DebuggerStatement': | ||
case 'ImportDeclaration': | ||
case 'ExportDeclaration': | ||
case 'ExportAllDeclaration': | ||
case 'ExportDefaultDeclaration': | ||
case 'Noop': | ||
case 'ClassMethod': | ||
case 'ClassPrivateMethod': | ||
case 'RestElement': | ||
case 'ArrayPattern': | ||
case 'ObjectPattern': | ||
case 'ClassExpression': | ||
case 'RecordExpression': | ||
case 'V8IntrinsicIdentifier': | ||
case 'TopicReference': | ||
case 'MethodDefinition': | ||
case 'ClassDeclaration': | ||
case 'ClassProperty': | ||
case 'StaticBlock': | ||
case 'ClassBody': | ||
case 'ExportNamedDeclaration': | ||
case 'ClassPrivateProperty': | ||
case 'ClassAccessorProperty': | ||
case 'PropertyPattern': | ||
break; | ||
case 'SpreadElementPattern': | ||
case 'SpreadPropertyPattern': | ||
case 'ClassPropertyDefinition': | ||
break; | ||
case 'DeclareClass': | ||
case 'DeclareModule': | ||
case 'DeclareVariable': | ||
case 'DeclareFunction': | ||
case 'DeclareInterface': | ||
case 'DeclareTypeAlias': | ||
case 'DeclareOpaqueType': | ||
case 'DeclareModuleExports': | ||
case 'DeclareExportDeclaration': | ||
case 'DeclareExportAllDeclaration': | ||
case 'InterfaceDeclaration': | ||
case 'TypeAlias': | ||
case 'OpaqueType': | ||
case 'EnumDeclaration': | ||
case 'TypeCastExpression': | ||
break; | ||
case 'TSAsExpression': | ||
case 'TSTypeParameter': | ||
case 'TSTypeAssertion': | ||
case 'TSDeclareMethod': | ||
case 'TSIndexSignature': | ||
case 'TSDeclareFunction': | ||
case 'TSMethodSignature': | ||
case 'TSEnumDeclaration': | ||
case 'TSExportAssignment': | ||
case 'TSNonNullExpression': | ||
case 'TSPropertySignature': | ||
case 'TSModuleDeclaration': | ||
case 'TSParameterProperty': | ||
case 'TSTypeCastExpression': | ||
case 'TSSatisfiesExpression': | ||
case 'TSTypeAliasDeclaration': | ||
case 'TSInterfaceDeclaration': | ||
case 'TSImportEqualsDeclaration': | ||
case 'TSExternalModuleReference': | ||
case 'TSInstantiationExpression': | ||
case 'TSTypeParameterDeclaration': | ||
case 'TSCallSignatureDeclaration': | ||
case 'TSNamespaceExportDeclaration': | ||
case 'TSConstructSignatureDeclaration': | ||
break; | ||
case 'DirectiveLiteral': | ||
case 'StringLiteral': | ||
case 'NumericLiteral': | ||
case 'BigIntLiteral': | ||
case 'NullLiteral': | ||
case 'Literal': | ||
case 'RegExpLiteral': | ||
case 'BooleanLiteral': | ||
case 'DecimalLiteral': | ||
break; | ||
case 'DoExpression': | ||
case 'BindExpression': | ||
break; | ||
case 'JSXIdentifier': | ||
case 'JSXText': | ||
case 'JSXElement': | ||
case 'JSXFragment': | ||
case 'JSXMemberExpression': | ||
case 'JSXExpressionContainer': | ||
break; | ||
case 'ComprehensionExpression': | ||
case 'GeneratorExpression': | ||
polyfillVar(path, dataNode); | ||
break; | ||
default: | ||
assertNever(parent); | ||
break; | ||
} | ||
}, | ||
}); | ||
return ast.program.body; | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
return undefined; | ||
(0, recast_1.visit)(ast, { | ||
visitImportExpression(_path) { | ||
throw new Error('Imports are not supported'); | ||
}, | ||
visitIdentifier(path) { | ||
this.traverse(path); | ||
const parent = path.parent.node; | ||
if (Constants_1.EXEMPT_IDENTIFIER_LIST.includes(path.node.name)) { | ||
return; | ||
} | ||
switch (parent.type) { | ||
case 'AssignmentPattern': | ||
case 'Property': | ||
case 'MemberExpression': | ||
case 'OptionalMemberExpression': | ||
case 'VariableDeclarator': | ||
if (!customPatches[parent.type]) { | ||
throw new Error(`Couldn\'t find custom patcher for parent type: ${parent.type}`); | ||
} | ||
customPatches[parent.type](path, parent, dataNode); | ||
break; | ||
case 'BinaryExpression': | ||
case 'UnaryExpression': | ||
case 'ArrayExpression': | ||
case 'AssignmentExpression': | ||
case 'SequenceExpression': | ||
case 'YieldExpression': | ||
case 'UpdateExpression': | ||
case 'LogicalExpression': | ||
case 'ConditionalExpression': | ||
case 'NewExpression': | ||
case 'CallExpression': | ||
case 'OptionalCallExpression': | ||
case 'TaggedTemplateExpression': | ||
case 'TemplateLiteral': | ||
case 'AwaitExpression': | ||
case 'ImportExpression': | ||
case 'ForStatement': | ||
case 'IfStatement': | ||
case 'WhileStatement': | ||
case 'ForInStatement': | ||
case 'ForOfStatement': | ||
case 'SwitchStatement': | ||
case 'ReturnStatement': | ||
case 'DoWhileStatement': | ||
case 'ExpressionStatement': | ||
case 'ForAwaitStatement': | ||
case 'ThrowStatement': | ||
case 'WithStatement': | ||
case 'TupleExpression': | ||
polyfillVar(path, dataNode); | ||
break; | ||
case 'Super': | ||
case 'Identifier': | ||
case 'ArrowFunctionExpression': | ||
case 'FunctionDeclaration': | ||
case 'FunctionExpression': | ||
case 'ThisExpression': | ||
case 'ObjectExpression': | ||
case 'MetaProperty': | ||
case 'ChainExpression': | ||
case 'PrivateName': | ||
case 'ParenthesizedExpression': | ||
case 'Import': | ||
case 'VariableDeclaration': | ||
case 'CatchClause': | ||
case 'BlockStatement': | ||
case 'TryStatement': | ||
case 'EmptyStatement': | ||
case 'LabeledStatement': | ||
case 'BreakStatement': | ||
case 'ContinueStatement': | ||
case 'DebuggerStatement': | ||
case 'ImportDeclaration': | ||
case 'ExportDeclaration': | ||
case 'ExportAllDeclaration': | ||
case 'ExportDefaultDeclaration': | ||
case 'Noop': | ||
case 'ClassMethod': | ||
case 'ClassPrivateMethod': | ||
case 'RestElement': | ||
case 'ArrayPattern': | ||
case 'ObjectPattern': | ||
case 'ClassExpression': | ||
case 'RecordExpression': | ||
case 'V8IntrinsicIdentifier': | ||
case 'TopicReference': | ||
case 'MethodDefinition': | ||
case 'ClassDeclaration': | ||
case 'ClassProperty': | ||
case 'StaticBlock': | ||
case 'ClassBody': | ||
case 'ExportNamedDeclaration': | ||
case 'ClassPrivateProperty': | ||
case 'ClassAccessorProperty': | ||
case 'PropertyPattern': | ||
break; | ||
case 'SpreadElementPattern': | ||
case 'SpreadPropertyPattern': | ||
case 'ClassPropertyDefinition': | ||
break; | ||
case 'DeclareClass': | ||
case 'DeclareModule': | ||
case 'DeclareVariable': | ||
case 'DeclareFunction': | ||
case 'DeclareInterface': | ||
case 'DeclareTypeAlias': | ||
case 'DeclareOpaqueType': | ||
case 'DeclareModuleExports': | ||
case 'DeclareExportDeclaration': | ||
case 'DeclareExportAllDeclaration': | ||
case 'InterfaceDeclaration': | ||
case 'TypeAlias': | ||
case 'OpaqueType': | ||
case 'EnumDeclaration': | ||
case 'TypeCastExpression': | ||
break; | ||
case 'TSAsExpression': | ||
case 'TSTypeParameter': | ||
case 'TSTypeAssertion': | ||
case 'TSDeclareMethod': | ||
case 'TSIndexSignature': | ||
case 'TSDeclareFunction': | ||
case 'TSMethodSignature': | ||
case 'TSEnumDeclaration': | ||
case 'TSExportAssignment': | ||
case 'TSNonNullExpression': | ||
case 'TSPropertySignature': | ||
case 'TSModuleDeclaration': | ||
case 'TSParameterProperty': | ||
case 'TSTypeCastExpression': | ||
case 'TSSatisfiesExpression': | ||
case 'TSTypeAliasDeclaration': | ||
case 'TSInterfaceDeclaration': | ||
case 'TSImportEqualsDeclaration': | ||
case 'TSExternalModuleReference': | ||
case 'TSInstantiationExpression': | ||
case 'TSTypeParameterDeclaration': | ||
case 'TSCallSignatureDeclaration': | ||
case 'TSNamespaceExportDeclaration': | ||
case 'TSConstructSignatureDeclaration': | ||
break; | ||
case 'DirectiveLiteral': | ||
case 'StringLiteral': | ||
case 'NumericLiteral': | ||
case 'BigIntLiteral': | ||
case 'NullLiteral': | ||
case 'Literal': | ||
case 'RegExpLiteral': | ||
case 'BooleanLiteral': | ||
case 'DecimalLiteral': | ||
break; | ||
case 'DoExpression': | ||
case 'BindExpression': | ||
break; | ||
case 'JSXIdentifier': | ||
case 'JSXText': | ||
case 'JSXElement': | ||
case 'JSXFragment': | ||
case 'JSXMemberExpression': | ||
case 'JSXExpressionContainer': | ||
break; | ||
case 'ComprehensionExpression': | ||
case 'GeneratorExpression': | ||
polyfillVar(path, dataNode); | ||
break; | ||
default: | ||
assertNever(parent); | ||
break; | ||
} | ||
}, | ||
}); | ||
return ast.program.body; | ||
}; | ||
exports.jsVariablePolyfill = jsVariablePolyfill; | ||
//# sourceMappingURL=VariablePolyfill.js.map |
{ | ||
"name": "@n8n/tournament", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Output compatible rewrite of riot tmpl", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -8,3 +8,3 @@ import type { namedTypes } from 'ast-types'; | ||
import type { ExpressionKind, StatementKind } from 'ast-types/lib/gen/kinds'; | ||
import { jsVariablePolyfill } from './VariablePolyfill'; | ||
import { globalIdentifier, jsVariablePolyfill } from './VariablePolyfill'; | ||
import type { DataNode } from './VariablePolyfill'; | ||
@@ -179,5 +179,3 @@ import { splitExpression } from './ExpressionSplitter'; | ||
const newProg = b.program([ | ||
b.variableDeclaration('var', [ | ||
b.variableDeclarator(b.identifier('global'), b.objectExpression([])), | ||
]), | ||
b.variableDeclaration('var', [b.variableDeclarator(globalIdentifier, b.objectExpression([]))]), | ||
]); | ||
@@ -184,0 +182,0 @@ |
@@ -14,3 +14,3 @@ import type { types } from 'recast'; | ||
const globalIdentifier = b.identifier( | ||
export const globalIdentifier = b.identifier( | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
@@ -117,201 +117,199 @@ // @ts-ignore | ||
): StatementKind[] | undefined => { | ||
try { | ||
visit(ast, { | ||
visitIdentifier(path) { | ||
this.traverse(path); | ||
const parent: ParentKind = path.parent.node; | ||
visit(ast, { | ||
visitImportExpression(_path) { | ||
throw new Error('Imports are not supported'); | ||
}, | ||
visitIdentifier(path) { | ||
this.traverse(path); | ||
const parent: ParentKind = path.parent.node; | ||
// This is for tmpl compat | ||
if (EXEMPT_IDENTIFIER_LIST.includes(path.node.name)) { | ||
return; | ||
} | ||
// This is for tmpl compat | ||
if (EXEMPT_IDENTIFIER_LIST.includes(path.node.name)) { | ||
return; | ||
} | ||
switch (parent.type) { | ||
case 'AssignmentPattern': | ||
case 'Property': | ||
case 'MemberExpression': | ||
case 'OptionalMemberExpression': | ||
case 'VariableDeclarator': | ||
if (!customPatches[parent.type]) { | ||
throw new Error(`Couldn\'t find custom patcher for parent type: ${parent.type}`); | ||
} | ||
customPatches[parent.type]!(path, parent, dataNode); | ||
break; | ||
case 'BinaryExpression': | ||
case 'UnaryExpression': | ||
case 'ArrayExpression': | ||
case 'AssignmentExpression': | ||
case 'SequenceExpression': | ||
case 'YieldExpression': | ||
case 'UpdateExpression': | ||
case 'LogicalExpression': | ||
case 'ConditionalExpression': | ||
case 'NewExpression': | ||
case 'CallExpression': | ||
case 'OptionalCallExpression': | ||
case 'TaggedTemplateExpression': | ||
case 'TemplateLiteral': | ||
case 'AwaitExpression': | ||
case 'ImportExpression': | ||
case 'ForStatement': | ||
case 'IfStatement': | ||
case 'WhileStatement': | ||
case 'ForInStatement': | ||
case 'ForOfStatement': | ||
case 'SwitchStatement': | ||
case 'ReturnStatement': | ||
case 'DoWhileStatement': | ||
case 'ExpressionStatement': | ||
case 'ForAwaitStatement': | ||
case 'ThrowStatement': | ||
case 'WithStatement': | ||
case 'TupleExpression': | ||
polyfillVar(path, dataNode); | ||
break; | ||
switch (parent.type) { | ||
case 'AssignmentPattern': | ||
case 'Property': | ||
case 'MemberExpression': | ||
case 'OptionalMemberExpression': | ||
case 'VariableDeclarator': | ||
if (!customPatches[parent.type]) { | ||
throw new Error(`Couldn\'t find custom patcher for parent type: ${parent.type}`); | ||
} | ||
customPatches[parent.type]!(path, parent, dataNode); | ||
break; | ||
case 'BinaryExpression': | ||
case 'UnaryExpression': | ||
case 'ArrayExpression': | ||
case 'AssignmentExpression': | ||
case 'SequenceExpression': | ||
case 'YieldExpression': | ||
case 'UpdateExpression': | ||
case 'LogicalExpression': | ||
case 'ConditionalExpression': | ||
case 'NewExpression': | ||
case 'CallExpression': | ||
case 'OptionalCallExpression': | ||
case 'TaggedTemplateExpression': | ||
case 'TemplateLiteral': | ||
case 'AwaitExpression': | ||
case 'ImportExpression': | ||
case 'ForStatement': | ||
case 'IfStatement': | ||
case 'WhileStatement': | ||
case 'ForInStatement': | ||
case 'ForOfStatement': | ||
case 'SwitchStatement': | ||
case 'ReturnStatement': | ||
case 'DoWhileStatement': | ||
case 'ExpressionStatement': | ||
case 'ForAwaitStatement': | ||
case 'ThrowStatement': | ||
case 'WithStatement': | ||
case 'TupleExpression': | ||
polyfillVar(path, dataNode); | ||
break; | ||
// Do nothing | ||
case 'Super': | ||
case 'Identifier': | ||
case 'ArrowFunctionExpression': | ||
case 'FunctionDeclaration': | ||
case 'FunctionExpression': | ||
case 'ThisExpression': | ||
case 'ObjectExpression': | ||
case 'MetaProperty': | ||
case 'ChainExpression': | ||
case 'PrivateName': | ||
case 'ParenthesizedExpression': | ||
case 'Import': | ||
case 'VariableDeclaration': | ||
case 'CatchClause': | ||
case 'BlockStatement': | ||
case 'TryStatement': | ||
case 'EmptyStatement': | ||
case 'LabeledStatement': | ||
case 'BreakStatement': | ||
case 'ContinueStatement': | ||
case 'DebuggerStatement': | ||
case 'ImportDeclaration': | ||
case 'ExportDeclaration': | ||
case 'ExportAllDeclaration': | ||
case 'ExportDefaultDeclaration': | ||
case 'Noop': | ||
case 'ClassMethod': | ||
case 'ClassPrivateMethod': | ||
case 'RestElement': | ||
case 'ArrayPattern': | ||
case 'ObjectPattern': | ||
case 'ClassExpression': | ||
case 'RecordExpression': | ||
case 'V8IntrinsicIdentifier': | ||
case 'TopicReference': | ||
case 'MethodDefinition': | ||
case 'ClassDeclaration': | ||
case 'ClassProperty': | ||
case 'StaticBlock': | ||
case 'ClassBody': | ||
case 'ExportNamedDeclaration': | ||
case 'ClassPrivateProperty': | ||
case 'ClassAccessorProperty': | ||
case 'PropertyPattern': | ||
break; | ||
// Do nothing | ||
case 'Super': | ||
case 'Identifier': | ||
case 'ArrowFunctionExpression': | ||
case 'FunctionDeclaration': | ||
case 'FunctionExpression': | ||
case 'ThisExpression': | ||
case 'ObjectExpression': | ||
case 'MetaProperty': | ||
case 'ChainExpression': | ||
case 'PrivateName': | ||
case 'ParenthesizedExpression': | ||
case 'Import': | ||
case 'VariableDeclaration': | ||
case 'CatchClause': | ||
case 'BlockStatement': | ||
case 'TryStatement': | ||
case 'EmptyStatement': | ||
case 'LabeledStatement': | ||
case 'BreakStatement': | ||
case 'ContinueStatement': | ||
case 'DebuggerStatement': | ||
case 'ImportDeclaration': | ||
case 'ExportDeclaration': | ||
case 'ExportAllDeclaration': | ||
case 'ExportDefaultDeclaration': | ||
case 'Noop': | ||
case 'ClassMethod': | ||
case 'ClassPrivateMethod': | ||
case 'RestElement': | ||
case 'ArrayPattern': | ||
case 'ObjectPattern': | ||
case 'ClassExpression': | ||
case 'RecordExpression': | ||
case 'V8IntrinsicIdentifier': | ||
case 'TopicReference': | ||
case 'MethodDefinition': | ||
case 'ClassDeclaration': | ||
case 'ClassProperty': | ||
case 'StaticBlock': | ||
case 'ClassBody': | ||
case 'ExportNamedDeclaration': | ||
case 'ClassPrivateProperty': | ||
case 'ClassAccessorProperty': | ||
case 'PropertyPattern': | ||
break; | ||
// I can't seem to figure out what causes these | ||
case 'SpreadElementPattern': | ||
case 'SpreadPropertyPattern': | ||
case 'ClassPropertyDefinition': | ||
break; | ||
// I can't seem to figure out what causes these | ||
case 'SpreadElementPattern': | ||
case 'SpreadPropertyPattern': | ||
case 'ClassPropertyDefinition': | ||
break; | ||
// Flow types | ||
case 'DeclareClass': | ||
case 'DeclareModule': | ||
case 'DeclareVariable': | ||
case 'DeclareFunction': | ||
case 'DeclareInterface': | ||
case 'DeclareTypeAlias': | ||
case 'DeclareOpaqueType': | ||
case 'DeclareModuleExports': | ||
case 'DeclareExportDeclaration': | ||
case 'DeclareExportAllDeclaration': | ||
case 'InterfaceDeclaration': | ||
case 'TypeAlias': | ||
case 'OpaqueType': | ||
case 'EnumDeclaration': | ||
case 'TypeCastExpression': | ||
break; | ||
// Flow types | ||
case 'DeclareClass': | ||
case 'DeclareModule': | ||
case 'DeclareVariable': | ||
case 'DeclareFunction': | ||
case 'DeclareInterface': | ||
case 'DeclareTypeAlias': | ||
case 'DeclareOpaqueType': | ||
case 'DeclareModuleExports': | ||
case 'DeclareExportDeclaration': | ||
case 'DeclareExportAllDeclaration': | ||
case 'InterfaceDeclaration': | ||
case 'TypeAlias': | ||
case 'OpaqueType': | ||
case 'EnumDeclaration': | ||
case 'TypeCastExpression': | ||
break; | ||
// Typescript types | ||
case 'TSAsExpression': | ||
case 'TSTypeParameter': | ||
case 'TSTypeAssertion': | ||
case 'TSDeclareMethod': | ||
case 'TSIndexSignature': | ||
case 'TSDeclareFunction': | ||
case 'TSMethodSignature': | ||
case 'TSEnumDeclaration': | ||
case 'TSExportAssignment': | ||
case 'TSNonNullExpression': | ||
case 'TSPropertySignature': | ||
case 'TSModuleDeclaration': | ||
case 'TSParameterProperty': | ||
case 'TSTypeCastExpression': | ||
case 'TSSatisfiesExpression': | ||
case 'TSTypeAliasDeclaration': | ||
case 'TSInterfaceDeclaration': | ||
case 'TSImportEqualsDeclaration': | ||
case 'TSExternalModuleReference': | ||
case 'TSInstantiationExpression': | ||
case 'TSTypeParameterDeclaration': | ||
case 'TSCallSignatureDeclaration': | ||
case 'TSNamespaceExportDeclaration': | ||
case 'TSConstructSignatureDeclaration': | ||
break; | ||
// Typescript types | ||
case 'TSAsExpression': | ||
case 'TSTypeParameter': | ||
case 'TSTypeAssertion': | ||
case 'TSDeclareMethod': | ||
case 'TSIndexSignature': | ||
case 'TSDeclareFunction': | ||
case 'TSMethodSignature': | ||
case 'TSEnumDeclaration': | ||
case 'TSExportAssignment': | ||
case 'TSNonNullExpression': | ||
case 'TSPropertySignature': | ||
case 'TSModuleDeclaration': | ||
case 'TSParameterProperty': | ||
case 'TSTypeCastExpression': | ||
case 'TSSatisfiesExpression': | ||
case 'TSTypeAliasDeclaration': | ||
case 'TSInterfaceDeclaration': | ||
case 'TSImportEqualsDeclaration': | ||
case 'TSExternalModuleReference': | ||
case 'TSInstantiationExpression': | ||
case 'TSTypeParameterDeclaration': | ||
case 'TSCallSignatureDeclaration': | ||
case 'TSNamespaceExportDeclaration': | ||
case 'TSConstructSignatureDeclaration': | ||
break; | ||
// Literals that can't contain an identifier | ||
case 'DirectiveLiteral': | ||
case 'StringLiteral': | ||
case 'NumericLiteral': | ||
case 'BigIntLiteral': | ||
case 'NullLiteral': | ||
case 'Literal': | ||
case 'RegExpLiteral': | ||
case 'BooleanLiteral': | ||
case 'DecimalLiteral': | ||
break; | ||
// Literals that can't contain an identifier | ||
case 'DirectiveLiteral': | ||
case 'StringLiteral': | ||
case 'NumericLiteral': | ||
case 'BigIntLiteral': | ||
case 'NullLiteral': | ||
case 'Literal': | ||
case 'RegExpLiteral': | ||
case 'BooleanLiteral': | ||
case 'DecimalLiteral': | ||
break; | ||
// Proposals that are stage 0 or 1 | ||
case 'DoExpression': | ||
case 'BindExpression': | ||
break; | ||
// Proposals that are stage 0 or 1 | ||
case 'DoExpression': | ||
case 'BindExpression': | ||
break; | ||
// JSX stuff. We don't support this so just do nothing. | ||
case 'JSXIdentifier': | ||
case 'JSXText': | ||
case 'JSXElement': | ||
case 'JSXFragment': | ||
case 'JSXMemberExpression': | ||
case 'JSXExpressionContainer': | ||
break; | ||
// JSX stuff. We don't support this so just do nothing. | ||
case 'JSXIdentifier': | ||
case 'JSXText': | ||
case 'JSXElement': | ||
case 'JSXFragment': | ||
case 'JSXMemberExpression': | ||
case 'JSXExpressionContainer': | ||
break; | ||
// I _think_ these are obsolete features proposed as part of ECMAScript 7. | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features#legacy_generator_and_iterator | ||
case 'ComprehensionExpression': | ||
case 'GeneratorExpression': | ||
polyfillVar(path, dataNode); | ||
break; | ||
// I _think_ these are obsolete features proposed as part of ECMAScript 7. | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features#legacy_generator_and_iterator | ||
case 'ComprehensionExpression': | ||
case 'GeneratorExpression': | ||
polyfillVar(path, dataNode); | ||
break; | ||
default: | ||
// This is a simple type guard that guarantees we haven't missed | ||
// a case. It'll result in a type error at compile time. | ||
assertNever(parent); | ||
break; | ||
} | ||
}, | ||
}); | ||
default: | ||
// This is a simple type guard that guarantees we haven't missed | ||
// a case. It'll result in a type error at compile time. | ||
assertNever(parent); | ||
break; | ||
} | ||
}, | ||
}); | ||
return ast.program.body as StatementKind[]; | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
return undefined; | ||
return ast.program.body as StatementKind[]; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
132349
44
1872
0