@component-controls/follow-imports
TypeScript icon, indicating that this package has built-in type declarations

4.0.3 • Public • Published

Table of contents

Overview

follow file imports using pabel ast parsing to find the file where an imported keyword was exported from (and is defined in).

Installation

$ npm install @component-controls/follow-imports --save-dev

API

defaultParserOptions

interface

defined in @component-controls/follow-imports/misc/follow-imports/src/consts.ts

properties

Name Type Parent Default Description
allowImportExportEverywhere boolean ParserOptions By default, import and export declarations can only appear at a program's top level. Setting this option to true allows them anywhere where a statement is allowed.
allowAwaitOutsideFunction boolean ParserOptions By default, await use is not allowed outside of an async function. Set this to true to accept such code.
allowReturnOutsideFunction boolean ParserOptions By default, a return statement at the top level raises an error. Set this to true to accept such code.
allowSuperOutsideMethod boolean ParserOptions
allowUndeclaredExports boolean ParserOptions By default, exported identifiers must refer to a declared variable. Set this to true to allow export statements to reference undeclared variables.
attachComment boolean ParserOptions By default, Babel attaches comments to adjacent AST nodes. When this option is set to false, comments are not attached. It can provide up to 30% performance improvement when the input code has many comments.
errorRecovery boolean ParserOptions By default, Babel always throws an error when it finds some invalid code. When this option is set to true, it will store the parsing error and try to continue parsing the invalid input file.
sourceType "script" | "module" | "unambiguous" ParserOptions "module" Indicate the mode the code should be parsed in. Can be one of "script", "module", or "unambiguous". Defaults to "script". "unambiguous" will make @babel/parser attempt to guess, based on the presence of ES6 import or export statements. Files with ES6 imports and exports are considered "module" and are otherwise "script".
sourceFilename string ParserOptions Correlate output AST nodes with their source filename. Useful when generating code and source maps from the ASTs of multiple input files.
startLine number ParserOptions By default, the first line of code parsed is treated as line 1. You can provide a line number to alternatively start with. Useful for integration with other source tools.
plugins ParserPlugin[] ParserOptions Array containing the plugins that you want to enable.
strictMode boolean ParserOptions Should the parser work in strict mode. Defaults to true if sourceType === 'module'. Otherwise, false.
ranges boolean ParserOptions Adds a ranges property to each node: [node.start, node.end]
tokens boolean ParserOptions Adds all parsed tokens to a tokens property on the File node.
createParenthesizedExpressions boolean ParserOptions By default, the parser adds information about parentheses by setting extra.parenthesized to true as needed. When this option is true the parser creates ParenthesizedExpression AST nodes instead of using the extra property.

defaultResolveOptions

interface

defined in @component-controls/follow-imports/misc/follow-imports/src/consts.ts

extends

Opts

properties

Name Type Parent Default Description
readFileSync function (
file*: string
charset*: string
) => string | Buffer
SyncOpts how to read files synchronously (defaults to fs.readFileSync)
isFile function (
file*: string
) => boolean
SyncOpts function to synchronously test whether a file exists
basedir string Opts directory to begin resolving from (defaults to __dirname)
package any Opts package.json data applicable to the module being loaded
extensions string | ReadonlyArray<string> Opts [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object] array of file extensions to search in order (defaults to ['.js'])
packageFilter function (
pkg*: any
pkgfile*: string
) => any
Opts transform the parsed package.json contents before looking at the "main" field
pathFilter function (
pkg*: any
path*: string
relativePath*: string
) => string
Opts transform a path within a package
paths string | ReadonlyArray<string> Opts require.paths array to use if nothing is found on the normal node_modules recursive walk (probably don't use this)
moduleDirectory string | ReadonlyArray<string> Opts directory (or directories) in which to recursively look for modules. (default to 'node_modules')
preserveSymlinks boolean Opts if true, doesn't resolve basedir to real path before resolving. This is the way Node resolves dependencies when executed with the --preserve-symlinks flag. Note: this property is currently true by default but it will be changed to false in the next major version because Node's resolution algorithm does not preserve symlinks by default.

ExportType

interface

defined in @component-controls/follow-imports/misc/follow-imports/src/consts.ts

properties

Name Type Description
name* string
internalName* string
loc
SourceLocation
start*
line*: number
column*: number
end*
line*: number
column*: number
from string in case of export { Button } from './button-named-export'; specifies the import from statememnt
node any
path any

parseFile

function

defined in @component-controls/follow-imports/misc/follow-imports/src/ast_store.ts

parameters

Name Type Default
filePath* string
options
parser.ParserOptions
allowImportExportEverywhere: boolean
allowAwaitOutsideFunction: boolean
allowReturnOutsideFunction: boolean
allowSuperOutsideMethod: boolean
allowUndeclaredExports: boolean
attachComment: boolean
errorRecovery: boolean
sourceType: "script" | "module" | "unambiguous"
sourceFilename: string
startLine: number
plugins: ParserPlugin[]
strictMode: boolean
ranges: boolean
tokens: boolean
createParenthesizedExpressions: boolean
sourceCode string
cache* boolean true
returns
CacheProps
ast*
type*: string
program*
type*: string
body*: Statement[]
directives*: Directive[]
sourceType*: "script" | "module"
interpreter: InterpreterDirective | null
sourceFile*: string
leadingComments*: ReadonlyArray<Comment> | null
innerComments*: ReadonlyArray<Comment> | null
trailingComments*: ReadonlyArray<Comment> | null
start*: number | null
end*: number | null
loc*: SourceLocation | null
range: [number, number]
extra: Record<string, unknown>
comments: ((CommentBlock, CommentLine))[] | null
tokens: any[] | null
leadingComments*: ReadonlyArray<Comment> | null
innerComments*: ReadonlyArray<Comment> | null
trailingComments*: ReadonlyArray<Comment> | null
start*: number | null
end*: number | null
loc*: SourceLocation | null
range: [number, number]
extra: Record<string, unknown>
source*: string
imports: ImportTypes
exports: ExportTypes
importAliases: Record<string, string>

extractImports

function

defined in @component-controls/follow-imports/misc/follow-imports/src/extract-imports.ts

parameters

Name Type
fileName* string
options*
ParserOptions
allowImportExportEverywhere: boolean
allowAwaitOutsideFunction: boolean
allowReturnOutsideFunction: boolean
allowSuperOutsideMethod: boolean
allowUndeclaredExports: boolean
attachComment: boolean
errorRecovery: boolean
sourceType: "script" | "module" | "unambiguous"
sourceFilename: string
startLine: number
plugins: ParserPlugin[]
strictMode: boolean
ranges: boolean
tokens: boolean
createParenthesizedExpressions: boolean
returns ImportTypes

extractExports

function

defined in @component-controls/follow-imports/misc/follow-imports/src/extract-exports.ts

parameters

Name Type
fileName* string
options*
ParserOptions
allowImportExportEverywhere: boolean
allowAwaitOutsideFunction: boolean
allowReturnOutsideFunction: boolean
allowSuperOutsideMethod: boolean
allowUndeclaredExports: boolean
attachComment: boolean
errorRecovery: boolean
sourceType: "script" | "module" | "unambiguous"
sourceFilename: string
startLine: number
plugins: ParserPlugin[]
strictMode: boolean
ranges: boolean
tokens: boolean
createParenthesizedExpressions: boolean
returns ExportTypes

sourceLocation

function

defined in @component-controls/follow-imports/misc/follow-imports/src/source-location.ts

parameters

Name Type
loc* SourceLocation | null
returns SourceLocation | undefined

getASTSource

function

defined in @component-controls/follow-imports/misc/follow-imports/src/source.ts

parameters

Name Type
source string
loc
SourceLocation
start*
line*: number
column*: number
end*
line*: number
column*: number
returns string | undefined

FollowImportType

interface

defined in @component-controls/follow-imports/misc/follow-imports/src/index.ts

properties

Name Type
exportedAs string
internalName string
from string
filePath string
importedName string
loc
SourceLocation
start*
line*: number
column*: number
end*
line*: number
column*: number
source string
imported string
imports ImportTypes
node any
path any

EXPORT_ALL

string = "*"

defined in @component-controls/follow-imports/misc/follow-imports/src/consts.ts

EXPORT_DEFAULT

string = "default"

defined in @component-controls/follow-imports/misc/follow-imports/src/consts.ts

IMPORT_NAMESPACE

string = "namespace"

defined in @component-controls/follow-imports/misc/follow-imports/src/consts.ts

NamedExportTypes

interface

defined in @component-controls/follow-imports/misc/follow-imports/src/consts.ts

properties

Name Type
key* [string]: ExportType

ExportTypes

interface

defined in @component-controls/follow-imports/misc/follow-imports/src/consts.ts

properties

Name Type
default* NamedExportTypes
named* NamedExportTypes

followImports

function

defined in @component-controls/follow-imports/misc/follow-imports/src/index.ts

parameters

Name Type
importName* string
filePath* string
options
type
parser
allowImportExportEverywhere: boolean
allowAwaitOutsideFunction: boolean
allowReturnOutsideFunction: boolean
allowSuperOutsideMethod: boolean
allowUndeclaredExports: boolean
attachComment: boolean
errorRecovery: boolean
sourceType: "script" | "module" | "unambiguous"
sourceFilename: string
startLine: number
plugins: ParserPlugin[]
strictMode: boolean
ranges: boolean
tokens: boolean
createParenthesizedExpressions: boolean
resolver
readFileSync: function (
file*: string
charset*: string
) => string | Buffer
isFile: function (
file*: string
) => boolean
basedir: string
package: any
extensions: string | ReadonlyArray<string>
packageFilter: function (
pkg*: any
pkgfile*: string
) => any
pathFilter: function (
pkg*: any
path*: string
relativePath*: string
) => string
paths: string | ReadonlyArray<string>
moduleDirectory: string | ReadonlyArray<string>
preserveSymlinks: boolean
resolveFile: function (
importName*: string
filePath*: string
) => string | undefined
returns FollowImportType | undefined

ImportType

interface

defined in @component-controls/follow-imports/misc/follow-imports/src/consts.ts

properties

Name Type Description
name* string component name
importedName* string importedName - the original named import that was aliased
from* string imported from
typesFile string imported from alias file name ie '/component-controls/core/store/dist/index.d.ts'
componentKey string key into components table

ImportTypes

interface

defined in @component-controls/follow-imports/misc/follow-imports/src/consts.ts

properties

Name Type
key* [string]: ImportType

Readme

Keywords

Package Sidebar

Install

npm i @component-controls/follow-imports

Weekly Downloads

4

Version

4.0.3

License

MIT

Unpacked Size

115 kB

Total Files

12

Last publish

Collaborators

  • atanasster