4.0.3 • Published 2 years ago

@component-controls/follow-imports v4.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

NameTypeParentDefaultDescription
allowImportExportEverywherebooleanParserOptionsBy 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.
allowAwaitOutsideFunctionbooleanParserOptionsBy default, await use is not allowed outside of an async function. Set this to true to accept such code.
allowReturnOutsideFunctionbooleanParserOptionsBy default, a return statement at the top level raises an error. Set this to true to accept such code.
allowSuperOutsideMethodbooleanParserOptions
allowUndeclaredExportsbooleanParserOptionsBy default, exported identifiers must refer to a declared variable. Set this to true to allow export statements to reference undeclared variables.
attachCommentbooleanParserOptionsBy 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.
errorRecoverybooleanParserOptionsBy 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".
sourceFilenamestringParserOptionsCorrelate output AST nodes with their source filename. Useful when generating code and source maps from the ASTs of multiple input files.
startLinenumberParserOptionsBy 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.
pluginsParserPlugin[]ParserOptionsArray containing the plugins that you want to enable.
strictModebooleanParserOptionsShould the parser work in strict mode. Defaults to true if sourceType === 'module'. Otherwise, false.
rangesbooleanParserOptionsAdds a ranges property to each node: [node.start, node.end]
tokensbooleanParserOptionsAdds all parsed tokens to a tokens property on the File node.
createParenthesizedExpressionsbooleanParserOptionsBy 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

NameTypeParentDefaultDescription
readFileSyncfunction (file*: stringcharset*: string) => string | BufferSyncOptshow to read files synchronously (defaults to fs.readFileSync)
isFilefunction (file*: string) => booleanSyncOptsfunction to synchronously test whether a file exists
basedirstringOptsdirectory to begin resolving from (defaults to __dirname)
packageanyOptspackage.json data applicable to the module being loaded
extensionsstring | 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'])
packageFilterfunction (pkg*: anypkgfile*: string) => anyOptstransform the parsed package.json contents before looking at the "main" field
pathFilterfunction (pkg*: anypath*: stringrelativePath*: string) => stringOptstransform a path within a package
pathsstring | ReadonlyArray<string>Optsrequire.paths array to use if nothing is found on the normal node_modules recursive walk (probably don't use this)
moduleDirectorystring | ReadonlyArray<string>Optsdirectory (or directories) in which to recursively look for modules. (default to 'node_modules')
preserveSymlinksbooleanOptsif 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

NameTypeDescription
name*string
internalName*string
locSourceLocationstart*line*: numbercolumn*: numberend*line*: numbercolumn*: number
fromstringin case of export { Button } from './button-named-export'; specifies the import from statememnt
nodeany
pathany

parseFile

function

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

parameters

NameTypeDefault
filePath*string
optionsparser.ParserOptionsallowImportExportEverywhere: booleanallowAwaitOutsideFunction: booleanallowReturnOutsideFunction: booleanallowSuperOutsideMethod: booleanallowUndeclaredExports: booleanattachComment: booleanerrorRecovery: booleansourceType: "script" | "module" | "unambiguous"sourceFilename: stringstartLine: numberplugins: ParserPlugin[]strictMode: booleanranges: booleantokens: booleancreateParenthesizedExpressions: boolean
sourceCodestring
cache*booleantrue
returnsCachePropsast*type*: stringprogram*type*: stringbody*: Statement[]directives*: Directive[]sourceType*: "script" | "module"interpreter: InterpreterDirective | nullsourceFile*: stringleadingComments*: ReadonlyArray<Comment> | nullinnerComments*: ReadonlyArray<Comment> | nulltrailingComments*: ReadonlyArray<Comment> | nullstart*: number | nullend*: number | nullloc*: SourceLocation | nullrange: [number, number]extra: Record<string, unknown>comments: ((CommentBlock, CommentLine))[] | nulltokens: any[] | nullleadingComments*: ReadonlyArray<Comment> | nullinnerComments*: ReadonlyArray<Comment> | nulltrailingComments*: ReadonlyArray<Comment> | nullstart*: number | nullend*: number | nullloc*: SourceLocation | nullrange: [number, number]extra: Record<string, unknown>source*: stringimports: ImportTypesexports: ExportTypesimportAliases: Record<string, string>

extractImports

function

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

parameters

NameType
fileName*string
options*ParserOptionsallowImportExportEverywhere: booleanallowAwaitOutsideFunction: booleanallowReturnOutsideFunction: booleanallowSuperOutsideMethod: booleanallowUndeclaredExports: booleanattachComment: booleanerrorRecovery: booleansourceType: "script" | "module" | "unambiguous"sourceFilename: stringstartLine: numberplugins: ParserPlugin[]strictMode: booleanranges: booleantokens: booleancreateParenthesizedExpressions: boolean
returnsImportTypes

extractExports

function

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

parameters

NameType
fileName*string
options*ParserOptionsallowImportExportEverywhere: booleanallowAwaitOutsideFunction: booleanallowReturnOutsideFunction: booleanallowSuperOutsideMethod: booleanallowUndeclaredExports: booleanattachComment: booleanerrorRecovery: booleansourceType: "script" | "module" | "unambiguous"sourceFilename: stringstartLine: numberplugins: ParserPlugin[]strictMode: booleanranges: booleantokens: booleancreateParenthesizedExpressions: boolean
returnsExportTypes

sourceLocation

function

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

parameters

NameType
loc*SourceLocation | null
returnsSourceLocation | undefined

getASTSource

function

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

parameters

NameType
sourcestring
locSourceLocationstart*line*: numbercolumn*: numberend*line*: numbercolumn*: number
returnsstring | undefined

FollowImportType

interface

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

properties

NameType
exportedAsstring
internalNamestring
fromstring
filePathstring
importedNamestring
locSourceLocationstart*line*: numbercolumn*: numberend*line*: numbercolumn*: number
sourcestring
importedstring
importsImportTypes
nodeany
pathany

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

NameType
key*[string]: ExportType

ExportTypes

interface

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

properties

NameType
default*NamedExportTypes
named*NamedExportTypes

followImports

function

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

parameters

NameType
importName*string
filePath*string
optionstypeparserallowImportExportEverywhere: booleanallowAwaitOutsideFunction: booleanallowReturnOutsideFunction: booleanallowSuperOutsideMethod: booleanallowUndeclaredExports: booleanattachComment: booleanerrorRecovery: booleansourceType: "script" | "module" | "unambiguous"sourceFilename: stringstartLine: numberplugins: ParserPlugin[]strictMode: booleanranges: booleantokens: booleancreateParenthesizedExpressions: booleanresolverreadFileSync: function (file*: stringcharset*: string) => string | BufferisFile: function (file*: string) => booleanbasedir: stringpackage: anyextensions: string | ReadonlyArray<string>packageFilter: function (pkg*: anypkgfile*: string) => anypathFilter: function (pkg*: anypath*: stringrelativePath*: string) => stringpaths: string | ReadonlyArray<string>moduleDirectory: string | ReadonlyArray<string>preserveSymlinks: booleanresolveFile: function (importName*: stringfilePath*: string) => string | undefined
returnsFollowImportType | undefined

ImportType

interface

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

properties

NameTypeDescription
name*stringcomponent name
importedName*stringimportedName - the original named import that was aliased
from*stringimported from
typesFilestringimported from alias file name ie '/component-controls/core/store/dist/index.d.ts'
componentKeystringkey into components table

ImportTypes

interface

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

properties

NameType
key*[string]: ImportType