Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "src/ast/js-ast-util"

Index

Functions

addStringPropertyForObject

  • addStringPropertyForObject(expr: ObjectExpression, key: string, value: string): void
  • 给字面量的对象,添加一个字符串类型的属性

    Parameters

    • expr: ObjectExpression
    • key: string
    • value: string

    Returns void

assertArrayExpression

  • assertArrayExpression(expr: Node): assertsexpr is ArrayExpression

assertIdentifier

  • assertIdentifier(expr: Node): assertsexpr is Identifier

assertLiteral

  • assertLiteral(expr: Node): assertsexpr is Literal

assertObjectExpression

  • assertObjectExpression(expr: Node): assertsexpr is ObjectExpression

assertProperty

  • assertProperty(expr: Node): assertsexpr is Property

assertVariableDeclarator

  • assertVariableDeclarator(expr: Node): assertsexpr is VariableDeclarator

deleteMemberAssignmentsTo

  • deleteMemberAssignmentsTo(program: Program, objName: string, name: string): void

deleteMembersFromClassDeclaration

  • deleteMembersFromClassDeclaration(expr: Class, name: string): void

deletePropertiesFromObject

  • deletePropertiesFromObject(obj: ObjectExpression | ObjectPattern, name: string): void

filterByType

  • filterByType(node: Node, type: "VariableDeclaration"): VariableDeclaration[]
  • filterByType(node: Node, type: "ImportDeclaration"): ImportDeclaration[]
  • filterByType(node: Node, type: "MemberExpression"): MemberExpression[]

findDefaultExport

  • findDefaultExport(node: Program): undefined | Node
  • 获取一个源码文件的默认导出,有两种形式:

    1. module.exports = foo
    2. export foo

    Parameters

    • node: Program

    Returns undefined | Node

findESMImports

  • findESMImports(root: Node): Generator<[]>
  • 找到 root 下所有的 import 语句

    通过迭代器返回每一个 require 的 localName、moduleName、exportName。 例如:import { coo as foo } from 'bar',会 yield ["foo", "bar", "coo"]

    Parameters

    • root: Node

    Returns Generator<[]>

findExportNames

  • findExportNames(root: Program): [string, string][]
  • 找到每个 localName 对应的 exportName。

    Parameters

    • root: Program

    Returns [string, string][]

findScriptRequires

  • findScriptRequires(node: Node): Generator<[]>
  • 找到 node 下面所有的 require 语句

    通过迭代器返回每一个 require 的 localName、moduleName、exportName。 例如:let foo = require('bar').coo,会 yield ["foo", "bar", "coo"]

    Parameters

    • node: Node

    Returns Generator<[]>

getClassName

  • getClassName(node: Node): string

getConstructor

  • getConstructor(expr: Class): undefined | MethodDefinition

getLiteralValue

  • getLiteralValue(node: Node): any

getMemberAssignmentsTo

  • getMemberAssignmentsTo(program: Program, objName: string): [string, Identifier | SimpleLiteral | RegExpLiteral | Program | FunctionDeclaration | FunctionExpression | ArrowFunctionExpression | SwitchCase | CatchClause | VariableDeclarator | ExpressionStatement | BlockStatement | EmptyStatement | DebuggerStatement | WithStatement | ReturnStatement | LabeledStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | ForInStatement | ForOfStatement | VariableDeclaration | ClassDeclaration | ThisExpression | ArrayExpression | ObjectExpression | YieldExpression | UnaryExpression | UpdateExpression | BinaryExpression | AssignmentExpression | LogicalExpression | MemberExpression | ConditionalExpression | SimpleCallExpression | NewExpression | SequenceExpression | TemplateLiteral | TaggedTemplateExpression | ClassExpression | MetaProperty | AwaitExpression | ImportExpression | ChainExpression | Property | AssignmentProperty | Super | TemplateElement | SpreadElement | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | ClassBody | MethodDefinition | ImportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier][]
  • 获取整个程序里,对 objName 的属性的所有赋值

    Parameters

    • program: Program
    • objName: string

    Returns [string, Identifier | SimpleLiteral | RegExpLiteral | Program | FunctionDeclaration | FunctionExpression | ArrowFunctionExpression | SwitchCase | CatchClause | VariableDeclarator | ExpressionStatement | BlockStatement | EmptyStatement | DebuggerStatement | WithStatement | ReturnStatement | LabeledStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | ForInStatement | ForOfStatement | VariableDeclaration | ClassDeclaration | ThisExpression | ArrayExpression | ObjectExpression | YieldExpression | UnaryExpression | UpdateExpression | BinaryExpression | AssignmentExpression | LogicalExpression | MemberExpression | ConditionalExpression | SimpleCallExpression | NewExpression | SequenceExpression | TemplateLiteral | TaggedTemplateExpression | ClassExpression | MetaProperty | AwaitExpression | ImportExpression | ChainExpression | Property | AssignmentProperty | Super | TemplateElement | SpreadElement | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | ClassBody | MethodDefinition | ImportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier][]

getMembersFromClassDeclaration

  • getMembersFromClassDeclaration(expr: Class): Generator<[]>
  • 从 Class 节点,获得它的所有属性的 key(字符串)和 value(AST 节点)

    Parameters

    • expr: Class

    Returns Generator<[]>

getPropertiesFromObject

  • getPropertiesFromObject(obj: ObjectExpression | ObjectPattern): Generator<[]>

getPropertyFromObject

  • getPropertyFromObject(obj: ObjectExpression | ObjectPattern, propertyName: string): Node | undefined
  • Parameters

    • obj: ObjectExpression | ObjectPattern
    • propertyName: string

    Returns Node | undefined

getRequireSpecifier

  • getRequireSpecifier(node: Node): string

getStringArrayValue

  • getStringArrayValue(expr: Node): any[]

getStringValue

isArrayExpression

  • isArrayExpression(expr: Node): expr is ArrayExpression

isAssignmentExpression

  • isAssignmentExpression(expr: Node): expr is AssignmentExpression

isBinaryExpression

  • isBinaryExpression(expr: Node): expr is BinaryExpression

isCallExpression

  • isCallExpression(expr: Node): expr is CallExpression

isClass

  • isClass(node: Node): node is Class

isClassDeclaration

  • isClassDeclaration(expr: Node): expr is ClassDeclaration

isClassExpression

  • isClassExpression(expr: Node): expr is ClassExpression

isExportDefaultDeclaration

  • isExportDefaultDeclaration(node: Node): node is ExportDefaultDeclaration

isExportsMemberExpression

  • isExportsMemberExpression(expr: Pattern): boolean

isExpressionStatement

  • isExpressionStatement(expr: Node): expr is ExpressionStatement

isIdentifier

  • isIdentifier(expr: Node): expr is Identifier

isImportDefaultSpecifier

  • isImportDefaultSpecifier(expr: Node): expr is ImportDefaultSpecifier

isImportSpecifier

  • isImportSpecifier(expr: Node): expr is ImportSpecifier

isLiteral

  • isLiteral(expr: Node): expr is Literal

isMemberAssignment

  • isMemberAssignment(expr: Pattern): boolean

isMemberExpression

  • isMemberExpression(expr: Node): expr is MemberExpression

isModuleExports

  • isModuleExports(node: Node): boolean

isObjectExpression

  • isObjectExpression(expr: Node): expr is ObjectExpression

isObjectPattern

  • isObjectPattern(expr: Node): expr is ObjectPattern

isProgram

  • isProgram(node: Node): node is Program

isProperty

  • isProperty(expr: Node): expr is Property

isRequire

  • isRequire(node: Node): node is CallExpression

isRequireSpecifier

  • isRequireSpecifier(node: Expression, spec: string): boolean

isTemplateLiteral

  • isTemplateLiteral(expr: Node): expr is TemplateLiteral

isThisExpression

  • isThisExpression(expr: Node): expr is ThisExpression

isVariableDeclaration

  • isVariableDeclaration(expr: Node): expr is VariableDeclaration

isVariableDeclarator

  • isVariableDeclarator(expr: Node): expr is VariableDeclarator

location

  • location(node: Node): string

Object literals

Const OPERATORS

OPERATORS: object

+

  • +(l: any, r: any): any

Generated using TypeDoc