Skip to main content
Version: 2.x.x

@yozora/tokenizer-ecma-import

Npm VersionNpm DownloadNpm LicenseModule formats: cjs, esmNode.js VersionTested with JestCode Style: prettier

github flavor markdown spec

@yozora/tokenizer-ecma-import parse ECMAScript import statement. It should be noted that only single-line import statements are supported. in addition * as and type import are not support. For example, the following import statements are supported:

import '@yozora/parser'
import Parser from '@yozora/parser'
import Parser, { YozoraParserProps } from '@yozora/parser'
import { YozoraParserProps } from '@yozora/parser'
import { YozoraParser, YozoraParser as Parser } from '@yozora/parser'

And here is the not supported case:

import * as Parser '@yozora/parser'
import {
Parser
} from '@yozora/parser'

Install

npm install --save @yozora/tokenizer-ecma-import

Usage

tip

@yozora/tokenizer-ecma-import has been integrated into @yozora/parser, so you can use YozoraParser directly.

import YozoraParser from '@yozora/parser'

const parser = new YozoraParser()

// parse source markdown content
parser.parse(`
import { Parser } from '@yozora/parser'
import { Button } from '@mui/material'
import Markdown from '@yozora/react-markdown'
`)

Options

NameTypeRequiredDefault
namestringfalse"@yozora/tokenizer-ecma-import"
prioritynumberfalseTokenizerPriority.ATOMIC
  • name: The unique name of the tokenizer, used to bind the token it generates, to determine the tokenizer that should be called in each life cycle of the token in the entire matching / parsing phase.

  • priority: Priority of the tokenizer, determine the order of processing, high priority priority execution. interruptable. In addition, in the match-block stage, a high-priority tokenizer can interrupt the matching process of a low-priority tokenizer.

Types

/**
* import { YozoraParserProps, YozoraParser as Parser } from '@yozora/parser'
* ==> [
* { src: 'YozoraParserProps', alias: null },
* { src: 'YozoraParser', alias: 'Parser' },
* ]
*/
export interface EcmaImportNamedImport {
src: string
alias: string | null
}

/**
* import Parser from '@yozora/parser'
* import Parser, { YozoraParserProps } from '@yozora/parser'
* import { YozoraParserProps } from '@yozora/parser'
* import { YozoraParser as Parser } from '@yozora/parser'
*/
export interface EcmaImport extends Node<EcmaImportType> {
/**
* import Parser from '@yozora/parser'
* ==> { moduleName: '@yozora/parser' }
*/
moduleName: string
/**
* import Parser, { YozoraParserProps } from '@yozora/parser'
* ==> { defaultImport: 'Parser' }
*/
defaultImport: string | null
/**
* import { YozoraParserProps, YozoraParser as Parser } from '@yozora/parser'
* ==> {
* namedImports: [
* { src: 'YozoraParserProps', alias: null },
* { src: 'YozoraParser', alias: 'Parser' },
* ]
* }
*/
namedImports: EcmaImportNamedImport[]
}

Live Examples

  • Basic.