UNPKG

js-ast-parser

Version:
76 lines 3.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getStringDefinitions = exports.getRegExpDefinitions = exports.getFunctionDefinitions = exports.getObjectDefinitions = exports.getArrayDefininitons = exports.getGlobalDefinitions = exports.ObjectDefinitions = exports.getConsoleDefinition = exports.DefinitionCode = void 0; const IdentifierLiteralExpression_1 = require("../expression/IdentifierLiteralExpression"); const Definition_1 = require("./Definition"); const globalDefinitions = [ 'function', 'if', 'else', 'for', 'while', 'do', 'catch', 'class', 'asyn', 'await', 'switch', 'let', 'var', 'const', 'window', 'true', 'try', 'false', 'null', 'undefined', 'return', 'continue', 'break', 'default', 'require', '__dirname', { identifier: new IdentifierLiteralExpression_1.IdentifierLiteralExpression({ value: 'console', loc: {} }), props: [ ...Object.keys(console) ] }, { identifier: new IdentifierLiteralExpression_1.IdentifierLiteralExpression({ value: 'document', loc: {} }), props: [ 'querySelector', 'querySelectorAll', 'createElement', 'createEvent', 'getElementById', 'getElementsByClassName', 'getElementsByTagName' ] }, { identifier: new IdentifierLiteralExpression_1.IdentifierLiteralExpression({ value: 'module', loc: {} }), props: [ 'exports' ] } ]; exports.DefinitionCode = { ConstVariable: 0b1, Variable: 0b1 << 1, ImportSpecifier: 0b1 << 2, FunctionDeclaration: 0b1 << 3, ClassDeclaration: 0b1 << 4, Property: 0b1 << 5, Method: 0b1 << 6 }; function getConsoleDefinition(scope) { let identifier = new IdentifierLiteralExpression_1.IdentifierLiteralExpression({ value: 'console', loc: {} }); return new Definition_1.Definition(identifier, 'Variable', exports.DefinitionCode.Variable, scope); } exports.getConsoleDefinition = getConsoleDefinition; exports.ObjectDefinitions = []; function getGlobalDefinitions(scope, definitions) { return (definitions || globalDefinitions).map(item => { if (typeof item === 'string') { return new Definition_1.Definition(new IdentifierLiteralExpression_1.IdentifierLiteralExpression({ value: item, loc: {} }), 'Variable', exports.DefinitionCode.Variable, scope); } else { let definition = new Definition_1.Definition(item.identifier, 'Variable', exports.DefinitionCode.Variable, scope); definition.definitions = getGlobalDefinitions(scope, item.props); return definition; } }); } exports.getGlobalDefinitions = getGlobalDefinitions; function getArrayDefininitons() { return []; } exports.getArrayDefininitons = getArrayDefininitons; function getObjectDefinitions() { return []; } exports.getObjectDefinitions = getObjectDefinitions; function getFunctionDefinitions() { return []; } exports.getFunctionDefinitions = getFunctionDefinitions; function getRegExpDefinitions() { return []; } exports.getRegExpDefinitions = getRegExpDefinitions; function getStringDefinitions() { return []; } exports.getStringDefinitions = getStringDefinitions; //# sourceMappingURL=constance.js.map