diff --git a/index.ts b/index.ts index c14e5edda..c5ba7dace 100644 --- a/index.ts +++ b/index.ts @@ -122,7 +122,7 @@ const Parser: Parser = { if (halfParsed) { return new Title(title, defaultNs, config, decode, selfLink); } - const {Token}: typeof import('./src') = require('./src'); + const {Token}: typeof import('./src/index') = require('./src/index'); const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink); return titleObj; @@ -130,7 +130,7 @@ const Parser: Parser = { /** @implements */ parse(wikitext, include, maxStage = Parser.MAX_STAGE, config = Parser.getConfig()) { - const {Token}: typeof import('./src') = require('./src'); + const {Token}: typeof import('./src/index') = require('./src/index'); let token: Token; this.run(() => { token = new Token(wikitext.replace(/[\0\x7F]/gu, ''), config); diff --git a/internal.ts b/internal.ts index 1c1aa8e14..594b1c90f 100644 --- a/internal.ts +++ b/internal.ts @@ -4,7 +4,7 @@ export type { } from './lib/node'; export type * from './lib/text'; // export type * from './lib/element'; -export type * from './src'; +export type * from './src/index'; export type * from './src/onlyinclude'; // export type * from './src/nowiki/base'; export type * from './src/nowiki/noinclude'; @@ -26,11 +26,11 @@ export type * from './src/html'; export type {TdToken} from './src/table/td'; // export type {TrBaseToken} from './src/table/trBase'; export type * from './src/table/tr'; -export type * from './src/table'; +export type * from './src/table/index'; export type * from './src/nowiki/hr'; export type * from './src/nowiki/doubleUnderscore'; // export type * from './src/link/base'; -export type * from './src/link'; +export type * from './src/link/index'; export type * from './src/link/category'; export type * from './src/imageParameter'; export type * from './src/link/file'; @@ -43,9 +43,9 @@ export type * from './src/nowiki/list'; export type * from './src/converterFlags'; export type * from './src/converterRule'; export type * from './src/converter'; -export type * from './src/nowiki'; +export type * from './src/nowiki/index'; export type * from './src/pre'; -export type * from './src/paramTag'; +export type * from './src/paramTag/index'; export type * from './src/paramTag/inputbox'; export type * from './src/nested'; export type * from './src/gallery'; diff --git a/parser/braces.ts b/parser/braces.ts index 4349f1b0b..f590f2bec 100644 --- a/parser/braces.ts +++ b/parser/braces.ts @@ -3,7 +3,7 @@ import * as Parser from '../index'; import {HeadingToken} from '../src/heading'; import {TranscludeToken} from '../src/transclude'; import {ArgToken} from '../src/arg'; -import type {Token} from '../src'; +import type {Token} from '../src/index'; /** * 解析花括号 diff --git a/parser/commentAndExt.ts b/parser/commentAndExt.ts index ba8638217..617576255 100644 --- a/parser/commentAndExt.ts +++ b/parser/commentAndExt.ts @@ -4,7 +4,7 @@ import {NoincludeToken} from '../src/nowiki/noinclude'; import {IncludeToken} from '../src/tagPair/include'; import {ExtToken} from '../src/tagPair/ext'; import {CommentToken} from '../src/nowiki/comment'; -import type {Token} from '../src'; +import type {Token} from '../src/index'; /** * 解析HTML注释和扩展标签 diff --git a/parser/converter.ts b/parser/converter.ts index 1518295c4..92e6ffabe 100644 --- a/parser/converter.ts +++ b/parser/converter.ts @@ -1,6 +1,6 @@ import * as Parser from '../index'; import {ConverterToken} from '../src/converter'; -import type {Token} from '../src'; +import type {Token} from '../src/index'; /** * 解析语言变体转换 diff --git a/parser/externalLinks.ts b/parser/externalLinks.ts index dac3ef904..d21bb829e 100644 --- a/parser/externalLinks.ts +++ b/parser/externalLinks.ts @@ -1,7 +1,7 @@ import {extUrlChar, extUrlCharFirst} from '../util/string'; import * as Parser from '../index'; import {ExtLinkToken} from '../src/extLink'; -import type {Token} from '../src'; +import type {Token} from '../src/index'; /** * 解析外部链接 diff --git a/parser/html.ts b/parser/html.ts index e03c26670..7a1e25089 100644 --- a/parser/html.ts +++ b/parser/html.ts @@ -1,7 +1,7 @@ import * as Parser from '../index'; import {AttributesToken} from '../src/attributes'; import {HtmlToken} from '../src/html'; -import type {Token} from '../src'; +import type {Token} from '../src/index'; /** * 解析HTML标签 diff --git a/parser/links.ts b/parser/links.ts index bf303c282..3ed136f4d 100644 --- a/parser/links.ts +++ b/parser/links.ts @@ -1,5 +1,5 @@ import * as Parser from '../index'; -import {LinkToken} from '../src/link'; +import {LinkToken} from '../src/link/index'; import {FileToken} from '../src/link/file'; import {CategoryToken} from '../src/link/category'; import type {Token} from '../internal'; diff --git a/parser/list.ts b/parser/list.ts index 0897f3ff5..19bb8b425 100644 --- a/parser/list.ts +++ b/parser/list.ts @@ -1,7 +1,7 @@ import * as Parser from '../index'; import {ListToken} from '../src/nowiki/list'; import {DdToken} from '../src/nowiki/dd'; -import type {Token} from '../src'; +import type {Token} from '../src/index'; /** * 解析列表 diff --git a/parser/magicLinks.ts b/parser/magicLinks.ts index 225220d3b..528debf9a 100644 --- a/parser/magicLinks.ts +++ b/parser/magicLinks.ts @@ -1,7 +1,7 @@ import {extUrlChar, extUrlCharFirst} from '../util/string'; import * as Parser from '../index'; import {MagicLinkToken} from '../src/magicLink'; -import type {Token} from '../src'; +import type {Token} from '../src/index'; /** * 解析自由外链 diff --git a/parser/quotes.ts b/parser/quotes.ts index 35458ecae..671e6754b 100644 --- a/parser/quotes.ts +++ b/parser/quotes.ts @@ -1,6 +1,6 @@ import * as Parser from '../index'; import {QuoteToken} from '../src/nowiki/quote'; -import type {Token} from '../src'; +import type {Token} from '../src/index'; /** * 解析单引号 diff --git a/parser/table.ts b/parser/table.ts index dfc25afe5..99515c31e 100644 --- a/parser/table.ts +++ b/parser/table.ts @@ -1,6 +1,6 @@ import * as Parser from '../index'; -import {Token} from '../src'; -import {TableToken} from '../src/table'; +import {Token} from '../src/index'; +import {TableToken} from '../src/table/index'; import {TrToken} from '../src/table/tr'; import {TdToken} from '../src/table/td'; import {DdToken} from '../src/nowiki/dd'; diff --git a/src/arg.ts b/src/arg.ts index 331b9dfd5..d829c3c80 100644 --- a/src/arg.ts +++ b/src/arg.ts @@ -1,7 +1,7 @@ import {text} from '../util/string'; import {generateForSelf, generateForChild} from '../util/lint'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {AtomToken} from './atom'; import {HiddenToken} from './hidden'; import type {LintError} from '../index'; diff --git a/src/atom.ts b/src/atom.ts index 5ebf0ce02..a909425f9 100644 --- a/src/atom.ts +++ b/src/atom.ts @@ -1,5 +1,5 @@ import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; declare type AtomTypes = 'arg-name' | 'attr-key' diff --git a/src/attribute.ts b/src/attribute.ts index 161a68744..cc7c3827b 100644 --- a/src/attribute.ts +++ b/src/attribute.ts @@ -1,7 +1,7 @@ import {generateForChild} from '../util/lint'; import {removeComment} from '../util/string'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {AtomToken} from './atom'; import type {LintError, Config} from '../index'; import type {AttributesToken} from '../internal'; diff --git a/src/attributes.ts b/src/attributes.ts index 1e7bc364f..d614e229d 100644 --- a/src/attributes.ts +++ b/src/attributes.ts @@ -1,7 +1,7 @@ import {generateForSelf, generateForChild} from '../util/lint'; import {removeComment} from '../util/string'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {AtomToken} from './atom'; import {AttributeToken} from './attribute'; import type {LintError} from '../index'; diff --git a/src/converter.ts b/src/converter.ts index c7f777d92..4dff2c477 100644 --- a/src/converter.ts +++ b/src/converter.ts @@ -1,6 +1,6 @@ import {text} from '../util/string'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {ConverterFlagsToken} from './converterFlags'; import {ConverterRuleToken} from './converterRule'; diff --git a/src/converterFlags.ts b/src/converterFlags.ts index beaeeb74a..e7fe3a107 100644 --- a/src/converterFlags.ts +++ b/src/converterFlags.ts @@ -1,6 +1,6 @@ import {generateForChild} from '../util/lint'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {AtomToken} from './atom'; import type {LintError} from '../index'; import type {ConverterToken, ConverterRuleToken} from '../internal'; diff --git a/src/converterRule.ts b/src/converterRule.ts index 51ffd9a62..57c2741fc 100644 --- a/src/converterRule.ts +++ b/src/converterRule.ts @@ -1,5 +1,5 @@ import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {AtomToken} from './atom'; import type {ConverterToken, ConverterFlagsToken} from '../internal'; diff --git a/src/extLink.ts b/src/extLink.ts index f3a427c7e..8c54d8860 100644 --- a/src/extLink.ts +++ b/src/extLink.ts @@ -1,5 +1,5 @@ import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {MagicLinkToken} from './magicLink'; /** diff --git a/src/gallery.ts b/src/gallery.ts index 4549bcf21..723fe6e4a 100644 --- a/src/gallery.ts +++ b/src/gallery.ts @@ -1,5 +1,5 @@ import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {GalleryImageToken} from './link/galleryImage'; import {HiddenToken} from './hidden'; import type {LintError} from '../index'; diff --git a/src/heading.ts b/src/heading.ts index e781ada2a..e96fe7fc1 100644 --- a/src/heading.ts +++ b/src/heading.ts @@ -1,6 +1,6 @@ import {generateForSelf} from '../util/lint'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {SyntaxToken} from './syntax'; import type {LintError} from '../index'; diff --git a/src/hidden.ts b/src/hidden.ts index 9d2bfea3c..43bff8abb 100644 --- a/src/hidden.ts +++ b/src/hidden.ts @@ -1,5 +1,5 @@ import {hidden} from '../mixin/hidden'; -import {Token} from '.'; +import {Token} from './index'; /** 不可见的节点 */ export class HiddenToken extends hidden(Token) { diff --git a/src/html.ts b/src/html.ts index e19ac7f63..df70f22cf 100644 --- a/src/html.ts +++ b/src/html.ts @@ -1,7 +1,7 @@ import {generateForSelf} from '../util/lint'; import {noWrap} from '../util/string'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import type {LintError} from '../index'; import type {AttributesToken, TranscludeToken} from '../internal'; diff --git a/src/imageParameter.ts b/src/imageParameter.ts index 952672972..17e09f0e2 100644 --- a/src/imageParameter.ts +++ b/src/imageParameter.ts @@ -1,7 +1,7 @@ import {extUrlChar, extUrlCharFirst} from '../util/string'; import {generateForSelf} from '../util/lint'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import type {LintError, Config} from '../index'; import type {Title} from '../lib/title'; import type {AtomToken, FileToken} from '../internal'; diff --git a/src/imagemap.ts b/src/imagemap.ts index cbf8d2781..433edcfac 100644 --- a/src/imagemap.ts +++ b/src/imagemap.ts @@ -1,6 +1,6 @@ import {generateForSelf, generateForChild} from '../util/lint'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {NoincludeToken} from './nowiki/noinclude'; import {GalleryImageToken} from './link/galleryImage'; import {ImagemapLinkToken} from './imagemapLink'; diff --git a/src/imagemapLink.ts b/src/imagemapLink.ts index 8135587e3..a1da7cb7d 100644 --- a/src/imagemapLink.ts +++ b/src/imagemapLink.ts @@ -1,7 +1,7 @@ import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {NoincludeToken} from './nowiki/noinclude'; -import {LinkToken} from './link'; +import {LinkToken} from './link/index'; import {ExtLinkToken} from './extLink'; import type {AstText, ImagemapToken} from '../internal'; diff --git a/src/link/base.ts b/src/link/base.ts index 8a2aad60a..24aa2f321 100644 --- a/src/link/base.ts +++ b/src/link/base.ts @@ -1,6 +1,6 @@ import {generateForChild} from '../../util/lint'; import * as Parser from '../../index'; -import {Token} from '..'; +import {Token} from '../index'; import {AtomToken} from '../atom'; import type {LintError} from '../../index'; diff --git a/src/link/category.ts b/src/link/category.ts index 8649d24db..a863213ba 100644 --- a/src/link/category.ts +++ b/src/link/category.ts @@ -1,4 +1,4 @@ -import {LinkToken} from '.'; +import {LinkToken} from './index'; /** 分类 */ // @ts-expect-error not implementing all abstract methods diff --git a/src/link/galleryImage.ts b/src/link/galleryImage.ts index 12a9929e2..4184516bb 100644 --- a/src/link/galleryImage.ts +++ b/src/link/galleryImage.ts @@ -1,6 +1,6 @@ import {generateForSelf} from '../../util/lint'; import * as Parser from '../../index'; -import {Token} from '..'; +import {Token} from '../index'; import {FileToken} from './file'; import type {LintError} from '../../index'; diff --git a/src/magicLink.ts b/src/magicLink.ts index caacafd34..40c5b603a 100644 --- a/src/magicLink.ts +++ b/src/magicLink.ts @@ -1,6 +1,6 @@ import {generateForChild} from '../util/lint'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import type {LintError} from '../index'; /** diff --git a/src/nested.ts b/src/nested.ts index 4cd4454e9..af2c0a670 100644 --- a/src/nested.ts +++ b/src/nested.ts @@ -1,6 +1,6 @@ import {generateForChild} from '../util/lint'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; import {ExtToken} from './tagPair/ext'; import {NoincludeToken} from './nowiki/noinclude'; import {CommentToken} from './nowiki/comment'; diff --git a/src/nowiki/base.ts b/src/nowiki/base.ts index 483673e04..8ccdb1f50 100644 --- a/src/nowiki/base.ts +++ b/src/nowiki/base.ts @@ -1,4 +1,5 @@ -import {Token} from '..'; +import * as Parser from '../../index'; +import {Token} from '../index'; import type {AstText} from '../../lib/text'; declare type NowikiTypes = 'ext-inner' @@ -19,4 +20,12 @@ export abstract class NowikiBaseToken extends Token { declare childNodes: [AstText]; abstract override get firstChild(): AstText; abstract override get lastChild(): AstText; + + /** + * @param wikitext default: `''` + * @browser + */ + constructor(wikitext = '', config = Parser.getConfig(), accum: Token[] = []) { + super(wikitext, config, accum); + } } diff --git a/src/nowiki/comment.ts b/src/nowiki/comment.ts index 80b382eb7..1f8b1a20e 100644 --- a/src/nowiki/comment.ts +++ b/src/nowiki/comment.ts @@ -3,7 +3,7 @@ import {hidden} from '../../mixin/hidden'; import * as Parser from '../../index'; import {NowikiBaseToken} from './base'; import type {LintError} from '../../index'; -import type {Token} from '..'; +import type {Token} from '../index'; /** HTML注释,不可见 */ // @ts-expect-error not implementing all abstract methods diff --git a/src/onlyinclude.ts b/src/onlyinclude.ts index e0b9db5b9..4f2421df9 100644 --- a/src/onlyinclude.ts +++ b/src/onlyinclude.ts @@ -1,4 +1,4 @@ -import {Token} from '.'; +import {Token} from './index'; /** * 嵌入时的`` diff --git a/src/paramTag/index.ts b/src/paramTag/index.ts index 98b683697..a111fb7e5 100644 --- a/src/paramTag/index.ts +++ b/src/paramTag/index.ts @@ -1,6 +1,6 @@ import {generateForChild} from '../../util/lint'; import * as Parser from '../../index'; -import {Token} from '..'; +import {Token} from '../index'; import {AtomToken} from '../atom'; import type {LintError} from '../../index'; import type {AttributesToken, ExtToken} from '../../internal'; diff --git a/src/paramTag/inputbox.ts b/src/paramTag/inputbox.ts index fc1a3cdbb..5d31c6db2 100644 --- a/src/paramTag/inputbox.ts +++ b/src/paramTag/inputbox.ts @@ -1,7 +1,7 @@ import {parseBraces} from '../../parser/braces'; import * as Parser from '../../index'; -import {ParamTagToken} from '.'; -import type {Token} from '..'; +import {ParamTagToken} from './index'; +import type {Token} from '../index'; /** `` */ // @ts-expect-error not implementing all abstract methods diff --git a/tsconfig.json b/tsconfig.json index 7bff5517b..f0cb4850e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,8 +11,6 @@ "index.ts" ], "compilerOptions": { - "allowJs": true, - "checkJs": true, "target": "esnext", "module": "CommonJS", "declaration": true,