From ea083cbee341bb2ea867cf253d5aee34d02562dc Mon Sep 17 00:00:00 2001 From: bhsd <2545473905@qq.com> Date: Mon, 20 Nov 2023 23:22:54 +0800 Subject: [PATCH] style: adjust module resolution --- .github/dependabot.yml | 1 + index.ts | 4 ++-- internal.ts | 10 +++++----- parser/braces.ts | 2 +- parser/commentAndExt.ts | 2 +- parser/converter.ts | 2 +- parser/externalLinks.ts | 2 +- parser/html.ts | 2 +- parser/links.ts | 2 +- parser/list.ts | 2 +- parser/magicLinks.ts | 2 +- parser/quotes.ts | 2 +- parser/table.ts | 4 ++-- src/arg.ts | 2 +- src/atom.ts | 2 +- src/attribute.ts | 2 +- src/attributes.ts | 2 +- src/converter.ts | 2 +- src/converterFlags.ts | 2 +- src/converterRule.ts | 2 +- src/extLink.ts | 2 +- src/gallery.ts | 2 +- src/heading.ts | 2 +- src/hidden.ts | 2 +- src/html.ts | 2 +- src/imageParameter.ts | 2 +- src/imagemap.ts | 2 +- src/imagemapLink.ts | 4 ++-- src/link/base.ts | 2 +- src/link/category.ts | 2 +- src/link/galleryImage.ts | 2 +- src/magicLink.ts | 2 +- src/nested.ts | 2 +- src/nowiki/base.ts | 10 +++++++++- src/nowiki/comment.ts | 2 +- src/onlyinclude.ts | 2 +- src/paramTag/index.ts | 2 +- src/paramTag/inputbox.ts | 4 ++-- tsconfig.json | 2 -- 39 files changed, 54 insertions(+), 47 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e55151541..6f80f0543 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,6 +9,7 @@ updates: directory: "/" # Location of package manifests schedule: interval: "monthly" + target-branch: "browser" assignees: - "bhsd-harry" commit-message: diff --git a/index.ts b/index.ts index 2bd578a6e..039fb7de0 100644 --- a/index.ts +++ b/index.ts @@ -296,7 +296,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); this.run(() => { @@ -313,7 +313,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 6b7fe6d82..556cc999c 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 ebb7aa0c2..d58a7a80e 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 e9a04424e..856745f69 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 9e59caabd..41c5e65e0 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 e95331f1a..45bad1b0a 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 35a98e22c..58f56dd59 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 96d92d665..348fc4bad 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 42b98bc1a..8a6f257d4 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 9580ae441..dfad6ad97 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 9ec305fc1..6d33fc2ec 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 ecac17d5a..3a22762e6 100644 --- a/src/arg.ts +++ b/src/arg.ts @@ -1,7 +1,7 @@ import {text, noWrap} 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 a1a5a4f1e..82860ac52 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 31d334c70..53e9ac5b1 100644 --- a/src/attribute.ts +++ b/src/attribute.ts @@ -2,7 +2,7 @@ import {generateForChild} from '../util/lint'; import {noWrap, removeComment} from '../util/string'; import {fixed} from '../mixin/fixed'; 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 380f2c4c3..32a0733d2 100644 --- a/src/attributes.ts +++ b/src/attributes.ts @@ -1,7 +1,7 @@ import {generateForSelf, generateForChild} from '../util/lint'; import {toCase, normalizeSpace, text, 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 4e13f24bf..733cdd10b 100644 --- a/src/converter.ts +++ b/src/converter.ts @@ -1,6 +1,6 @@ import {text, print} 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 9c42983cd..243fe8d6d 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 0e8aa9704..3b237e7f7 100644 --- a/src/converterRule.ts +++ b/src/converterRule.ts @@ -1,7 +1,7 @@ import {undo} from '../util/debug'; import {noWrap} from '../util/string'; 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 34b947332..f9e9aabe5 100644 --- a/src/extLink.ts +++ b/src/extLink.ts @@ -1,6 +1,6 @@ import {noWrap, normalizeSpace} from '../util/string'; 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 9234d8a90..297794cbd 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 57b8f3f0c..f4bf873fa 100644 --- a/src/heading.ts +++ b/src/heading.ts @@ -2,7 +2,7 @@ import {generateForSelf} from '../util/lint'; import {fixed} from '../mixin/fixed'; import {sol} from '../mixin/sol'; 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 ffaf82f60..acd1a6e6d 100644 --- a/src/hidden.ts +++ b/src/hidden.ts @@ -1,6 +1,6 @@ import {hidden} from '../mixin/hidden'; import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; /** 不可见的节点 */ export class HiddenToken extends hidden(Token) { diff --git a/src/html.ts b/src/html.ts index 0bf17bc18..1c4138b5e 100644 --- a/src/html.ts +++ b/src/html.ts @@ -3,7 +3,7 @@ import {noWrap} from '../util/string'; import {fixed} from '../mixin/fixed'; import {attributesParent} from '../mixin/attributesParent'; 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 10fd26948..b61eda7cf 100644 --- a/src/imageParameter.ts +++ b/src/imageParameter.ts @@ -1,7 +1,7 @@ import {text, noWrap, print, 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 {AstNodes, AstText, AtomToken, FileToken} from '../internal'; diff --git a/src/imagemap.ts b/src/imagemap.ts index b46641915..ed7fd4a43 100644 --- a/src/imagemap.ts +++ b/src/imagemap.ts @@ -1,7 +1,7 @@ import {generateForSelf, generateForChild} from '../util/lint'; import {singleLine} from '../mixin/singleLine'; 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 2d8b2e12e..461f54cef 100644 --- a/src/imagemapLink.ts +++ b/src/imagemapLink.ts @@ -1,9 +1,9 @@ import {fixed} from '../mixin/fixed'; import {singleLine} from '../mixin/singleLine'; 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 {Title} from '../lib/title'; import type {AstText, ImagemapToken} from '../internal'; diff --git a/src/link/base.ts b/src/link/base.ts index d4faeb396..404c10e11 100644 --- a/src/link/base.ts +++ b/src/link/base.ts @@ -2,7 +2,7 @@ import {generateForChild} from '../../util/lint'; import {noWrap} from '../../util/string'; import {undo} from '../../util/debug'; import * as Parser from '../../index'; -import {Token} from '..'; +import {Token} from '../index'; import {AtomToken} from '../atom'; import type {LintError} from '../../index'; import type {Title} from '../../lib/title'; diff --git a/src/link/category.ts b/src/link/category.ts index 3e36f6de3..05d862b96 100644 --- a/src/link/category.ts +++ b/src/link/category.ts @@ -1,6 +1,6 @@ import {decodeHtml} from '../../util/string'; import * as Parser from '../../index'; -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 9be472f42..14b9f729a 100644 --- a/src/link/galleryImage.ts +++ b/src/link/galleryImage.ts @@ -2,7 +2,7 @@ import {generateForSelf} from '../../util/lint'; import {undo} from '../../util/debug'; import {singleLine} from '../../mixin/singleLine'; import * as Parser from '../../index'; -import {Token} from '..'; +import {Token} from '../index'; import {FileToken} from './file'; import type {Title} from '../../lib/title'; import type {LintError} from '../../index'; diff --git a/src/magicLink.ts b/src/magicLink.ts index 851c1ed81..ec596c5b0 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'; import type {ParameterToken} from './parameter'; diff --git a/src/nested.ts b/src/nested.ts index 211dbb925..04db25165 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 483c95179..253db0b7b 100644 --- a/src/nowiki/base.ts +++ b/src/nowiki/base.ts @@ -1,6 +1,6 @@ import {fixed} from '../../mixin/fixed'; import * as Parser from '../../index'; -import {Token} from '..'; +import {Token} from '../index'; import type {AstText} from '../../lib/text'; declare type NowikiTypes = 'ext-inner' @@ -25,6 +25,14 @@ export abstract class NowikiBaseToken extends fixed(Token) { abstract override get lastChild(): AstText; abstract override get lastElementChild(): undefined; + /** + * @param wikitext default: `''` + * @browser + */ + constructor(wikitext = '', config = Parser.getConfig(), accum: Token[] = []) { + super(wikitext, config, accum); + } + /** @override */ override cloneNode(this: this & {constructor: new (...args: any[]) => unknown}): this { const {constructor, firstChild: {data}, type} = this, diff --git a/src/nowiki/comment.ts b/src/nowiki/comment.ts index 9d1e798aa..aa4c16efa 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 5f76e999a..1c1a7ab40 100644 --- a/src/onlyinclude.ts +++ b/src/onlyinclude.ts @@ -1,5 +1,5 @@ import * as Parser from '../index'; -import {Token} from '.'; +import {Token} from './index'; /** * 嵌入时的`` diff --git a/src/paramTag/index.ts b/src/paramTag/index.ts index d534982bd..2dccb7373 100644 --- a/src/paramTag/index.ts +++ b/src/paramTag/index.ts @@ -1,7 +1,7 @@ import {generateForChild} from '../../util/lint'; import {singleLine} from '../../mixin/singleLine'; 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 ffaad408b..9ca181edf 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,