@descent-vtt/spec-brief 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +1 -1
- package/dist/glob.d.ts +7 -2
- package/dist/glob.js +8 -12
- package/dist/glob.js.map +1 -1
- package/dist/vendor/spec-core/markdown/links.js +15 -2
- package/dist/vendor/spec-core/markdown/links.js.map +1 -1
- package/dist/vendor/spec-core/markdown/tables.js +3 -0
- package/dist/vendor/spec-core/markdown/tables.js.map +1 -1
- package/dist/vendor/spec-core/pattern/automaton.d.ts +15 -2
- package/dist/vendor/spec-core/pattern/automaton.js +21 -2
- package/dist/vendor/spec-core/pattern/automaton.js.map +1 -1
- package/dist/vendor/spec-core/pattern/charset.d.ts +5 -1
- package/dist/vendor/spec-core/pattern/charset.js +8 -1
- package/dist/vendor/spec-core/pattern/charset.js.map +1 -1
- package/dist/vendor/spec-core/pattern/glob.d.ts +14 -3
- package/dist/vendor/spec-core/pattern/glob.js +55 -16
- package/dist/vendor/spec-core/pattern/glob.js.map +1 -1
- package/dist/vendor/spec-core/text/lines.js +10 -0
- package/dist/vendor/spec-core/text/lines.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
Notable changes, newest first. Versions follow [semver](https://semver.org).
|
|
4
4
|
|
|
5
|
+
## 0.2.5
|
|
6
|
+
|
|
7
|
+
spec-core at f9ce375. A trailing `/` on a brace alternative means that
|
|
8
|
+
directory's contents, as one written alone does: `{src/newmod/,lib}` scopes
|
|
9
|
+
what `src/newmod/` and `lib` scope, so a collision inside a directory the
|
|
10
|
+
round creates is no longer missed.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- spec-core at f9ce375. Its glob reads a trailing `/` on a brace
|
|
15
|
+
alternative as it reads one on the whole pattern. In a scope,
|
|
16
|
+
`{src/newmod/,lib}` covers `src/newmod/index.ts` and not `src/newmod`,
|
|
17
|
+
whatever the tree holds. `src/newmod` was a literal read from the tree,
|
|
18
|
+
and while the tree did not hold the directory, or with no tree, it
|
|
19
|
+
covered only a file of that name: `matrix` missed a collision with a
|
|
20
|
+
brief writing `src/newmod/index.ts`, which it now reports, and `schedule`
|
|
21
|
+
now keeps the two briefs apart. A directory the tree holds reads as
|
|
22
|
+
before.
|
|
23
|
+
- `literal-read-as-file` no longer names what a trailing `/` says is a
|
|
24
|
+
directory: `{src/newmod/,lib}` in a tree holding neither names `lib`
|
|
25
|
+
alone, where it named `src/newmod` and `lib`. A pattern left with no
|
|
26
|
+
bare name to place, `{src/newmod/,docs/new.md}` in a tree holding
|
|
27
|
+
neither, is `glob-matches-nothing`'s, as `src/newmod/` alone is, where it
|
|
28
|
+
was noted for `src/newmod`.
|
|
29
|
+
- `archive`, which reads a literal as either, no longer takes a changed file
|
|
30
|
+
at `build` itself as inside `{build/,Makefile}`, protected or in scope, as
|
|
31
|
+
it never took one inside `build/`.
|
|
32
|
+
- In the library, `parseGlob(...).glob.literals` leaves out an alternative
|
|
33
|
+
written with a trailing `/`, and the base `globBases` gives for
|
|
34
|
+
`{src/newmod/,lib}` is `src/newmod` whatever the tree holds, where it was
|
|
35
|
+
`src` while the tree did not hold the directory.
|
|
36
|
+
|
|
5
37
|
## 0.2.4
|
|
6
38
|
|
|
7
39
|
spec-core at 65ef842. Archival rewrites a link reference definition only
|
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ Work put off for later is a brief too, with `status: deferred` and a `trigger` n
|
|
|
52
52
|
|
|
53
53
|
The id comes from the file name (`012_rotate-session-tokens.md`) or from an `id` field. `affectedFiles` is the scope the round may write; `protectedFiles` is what it is not empowered to change, and archival refuses a round that changed it. Protection wins: what a round may write is `affectedFiles` less `protectedFiles`, so "all of `src/` but the schema" is `affectedFiles: [src/**]` with `protectedFiles: [src/db/schema.ts]`.
|
|
54
54
|
|
|
55
|
-
Scopes are globs in spec-core's `path` dialect, the one every spec-\* tool reads: `*`, `?`, `[a-z]` and `{a,b}` within a name, `**` for any number of directories, compared case-sensitively on every host. `**` is a whole segment: `docs/**.md` is refused, since tools read it three ways - write `docs/**/*.md` for any depth, or `docs/*.md` for one level. Parentheses are literal, `C++(notes).md`, unless a group holds a `|`: an extended glob such as `+(a|b)` is refused, and written `{a,b}`. A trailing `/**` or `/` is a directory's contents - at least one name below it, never the directory itself
|
|
55
|
+
Scopes are globs in spec-core's `path` dialect, the one every spec-\* tool reads: `*`, `?`, `[a-z]` and `{a,b}` within a name, `**` for any number of directories, compared case-sensitively on every host. `**` is a whole segment: `docs/**.md` is refused, since tools read it three ways - write `docs/**/*.md` for any depth, or `docs/*.md` for one level. Parentheses are literal, `C++(notes).md`, unless a group holds a `|`: an extended glob such as `+(a|b)` is refused, and written `{a,b}`. A trailing `/**` or `/` is a directory's contents - at least one name below it, never the directory itself - on a brace alternative as on the whole pattern: `{src/,lib}` is `src/` or `lib`. A path with no glob syntax is read from the tree: a file the tree holds is that file, a directory it holds is everything beneath it, and a path it does not hold yet is a file unless it ends in `/`. Write `src/newmod/` for a directory the round creates; `lint` notes a bare `src/newmod` it cannot place.
|
|
56
56
|
|
|
57
57
|
## Commands
|
|
58
58
|
|
package/dist/glob.d.ts
CHANGED
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
* The tree, not the spelling, knows that `Dockerfile` is a file and
|
|
18
18
|
* `docs/v1.2` a directory (ADR-0005, amended 2026-09-26).
|
|
19
19
|
* - A trailing `/**` is at least one segment, so `docs/**` is the directory's
|
|
20
|
-
* contents and a collision witness is always a file.
|
|
20
|
+
* contents and a collision witness is always a file. A trailing `/` means
|
|
21
|
+
* the same on a brace alternative as on the whole pattern: `{src/,lib}` is
|
|
22
|
+
* `src/` or `lib`, and the tree is asked about `lib` alone.
|
|
21
23
|
*
|
|
22
24
|
* Nothing here compiles to a `RegExp`. Matching costs at most the pattern's
|
|
23
25
|
* size times the path's length, and a question about two scopes that cannot be
|
|
@@ -34,7 +36,10 @@ export interface Glob {
|
|
|
34
36
|
readonly source: string;
|
|
35
37
|
/** The compiled pattern: spec-core's `path` dialect, case-sensitive. */
|
|
36
38
|
readonly compiled: CoreGlob;
|
|
37
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Each path the pattern names with no glob syntax and no trailing `/`, one
|
|
41
|
+
* per brace alternative; empty when it has none.
|
|
42
|
+
*/
|
|
38
43
|
readonly literals: readonly Literal[];
|
|
39
44
|
}
|
|
40
45
|
export type GlobParse = {
|
package/dist/glob.js
CHANGED
|
@@ -17,13 +17,15 @@
|
|
|
17
17
|
* The tree, not the spelling, knows that `Dockerfile` is a file and
|
|
18
18
|
* `docs/v1.2` a directory (ADR-0005, amended 2026-09-26).
|
|
19
19
|
* - A trailing `/**` is at least one segment, so `docs/**` is the directory's
|
|
20
|
-
* contents and a collision witness is always a file.
|
|
20
|
+
* contents and a collision witness is always a file. A trailing `/` means
|
|
21
|
+
* the same on a brace alternative as on the whole pattern: `{src/,lib}` is
|
|
22
|
+
* `src/` or `lib`, and the tree is asked about `lib` alone.
|
|
21
23
|
*
|
|
22
24
|
* Nothing here compiles to a `RegExp`. Matching costs at most the pattern's
|
|
23
25
|
* size times the path's length, and a question about two scopes that cannot be
|
|
24
26
|
* answered within the search's budget answers `undecided`, never a guess.
|
|
25
27
|
*/
|
|
26
|
-
import {
|
|
28
|
+
import { globCovers as coreCovers, globWitness as coreWitness, isGlobSyntax, parseGlob as coreParse, WITNESS_BUDGET, } from './vendor/spec-core/pattern/index.js';
|
|
27
29
|
import { segments } from './vendor/spec-core/path/index.js';
|
|
28
30
|
export { isGlobSyntax, WITNESS_BUDGET };
|
|
29
31
|
/** Parses a scope pattern, or says why it cannot. */
|
|
@@ -40,16 +42,10 @@ export function parseGlob(source, options = {}) {
|
|
|
40
42
|
literals.push({ path, reading });
|
|
41
43
|
return reading;
|
|
42
44
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
// Too many states is a pattern nobody meant; anything else is a defect to surface.
|
|
49
|
-
if (error instanceof AutomatonTooLarge)
|
|
50
|
-
return { ok: false, error: error.message };
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
45
|
+
// A pattern too large to compile is refused by the core, with its reason,
|
|
46
|
+
// as a malformed one is; what the reading throws is a defect, and passes on.
|
|
47
|
+
const parsed = coreParse(pattern, { dialect: 'path', caseSensitive: true, literal });
|
|
48
|
+
return parsed.ok ? { ok: true, glob: { source, compiled: parsed.glob, literals } } : parsed;
|
|
53
49
|
}
|
|
54
50
|
/**
|
|
55
51
|
* Whether a path matches. The path is read as a repository path: empty and
|
package/dist/glob.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EACL,iBAAiB,EACjB,UAAU,IAAI,UAAU,EACxB,WAAW,IAAI,WAAW,EAC1B,YAAY,EACZ,SAAS,IAAI,SAAS,EAGtB,cAAc,GAEf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAuB,cAAc,EAAgB,CAAC;AA4B3E,qDAAqD;AACrD,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,OAAO,GAAiB,EAAE;IAClE,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,iEAAiE,EAAE,CAAC;IAC5H,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,wEAAwE,EAAE,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G;AACH,MAAM,UAAU,SAAS,CAAC,KAA+B;IACvD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["/**\n * Scopes as globs: spec-core's `path` dialect, read the way spec-brief reads a\n * brief.\n *\n * The syntax, the automaton and the witness search are spec-core's, copied\n * into `src/vendor/` and verified by hash, so the family's tools read one\n * pattern the same way (spec-core ADR-0003). What is decided here is what\n * spec-brief adds around it:\n *\n * - A pattern is relative to the repository root, so a leading `/` is refused\n * rather than rooted at the filesystem; and a list entry's `!` has no list to\n * belong to in a scope, so it is refused rather than read.\n * - Paths compare case-sensitively on every host, as git's do.\n * - A path with no glob syntax is read as the tree reads it: a file the tree\n * holds is that file, a directory it holds is everything beneath it, and a\n * path it does not hold is a file, unless it is written with a trailing `/`.\n * The tree, not the spelling, knows that `Dockerfile` is a file and\n * `docs/v1.2` a directory (ADR-0005, amended 2026-09-26).\n * - A trailing `/**` is at least one segment, so `docs/**` is the directory's\n * contents and a collision witness is always a file.\n *\n * Nothing here compiles to a `RegExp`. Matching costs at most the pattern's\n * size times the path's length, and a question about two scopes that cannot be\n * answered within the search's budget answers `undecided`, never a guess.\n */\n\nimport {\n AutomatonTooLarge,\n globCovers as coreCovers,\n globWitness as coreWitness,\n isGlobSyntax,\n parseGlob as coreParse,\n type Glob as CoreGlob,\n type LiteralReading,\n WITNESS_BUDGET,\n type Witness,\n} from './vendor/spec-core/pattern/index.js';\nimport { segments } from './vendor/spec-core/path/index.js';\n\nexport { isGlobSyntax, type LiteralReading, WITNESS_BUDGET, type Witness };\n\n/** A literal path a pattern names, and how it was read. */\nexport interface Literal {\n readonly path: string;\n readonly reading: LiteralReading;\n}\n\nexport interface Glob {\n readonly source: string;\n /** The compiled pattern: spec-core's `path` dialect, case-sensitive. */\n readonly compiled: CoreGlob;\n /** Each path the pattern names with no glob syntax, one per brace alternative; empty when it has none. */\n readonly literals: readonly Literal[];\n}\n\nexport type GlobParse = { readonly ok: true; readonly glob: Glob } | { readonly ok: false; readonly error: string };\n\nexport interface ParseOptions {\n /**\n * How a path with no glob syntax is read: `file`, that path alone;\n * `directory`, everything beneath it; `either`, both. A function is asked\n * per literal path, as {@link readingIn} answers for a tree. `file` when\n * unset: a path nothing says is a directory is not read as one.\n */\n readonly literal?: LiteralReading | ((path: string) => LiteralReading) | undefined;\n}\n\n/** Parses a scope pattern, or says why it cannot. */\nexport function parseGlob(source: string, options: ParseOptions = {}): GlobParse {\n const pattern = source.trim();\n if (pattern.startsWith('!')) return { ok: false, error: 'negated patterns are not supported; narrow the positive pattern' };\n if (pattern.startsWith('/')) return { ok: false, error: 'a pattern is relative to the repository root and cannot start with \"/\"' };\n const given = options.literal ?? 'file';\n const literals: Literal[] = [];\n const literal = (path: string): LiteralReading => {\n const reading = typeof given === 'function' ? given(path) : given;\n literals.push({ path, reading });\n return reading;\n };\n try {\n const parsed = coreParse(pattern, { dialect: 'path', caseSensitive: true, literal });\n return parsed.ok ? { ok: true, glob: { source, compiled: parsed.glob, literals } } : parsed;\n } catch (error) {\n // Too many states is a pattern nobody meant; anything else is a defect to surface.\n if (error instanceof AutomatonTooLarge) return { ok: false, error: error.message };\n throw error;\n }\n}\n\n/**\n * Whether a path matches. The path is read as a repository path: empty and\n * `.` segments are dropped, so `./src//a.ts` is `src/a.ts`.\n */\nexport function matchGlob(glob: Glob, path: string): boolean {\n const canonical = segments(path).join('/');\n return canonical !== '' && glob.compiled.match(canonical);\n}\n\n/**\n * A shortest path every glob in `include` matches and none in `exclude` does,\n * `none` as a proof that there is no such path, or `undecided` when the search\n * met its budget first.\n */\nexport function globWitness(include: readonly Glob[], exclude: readonly Glob[] = [], budget: number = WITNESS_BUDGET): Witness {\n return coreWitness(\n include.map((g) => g.compiled),\n exclude.map((g) => g.compiled),\n budget,\n );\n}\n\n/** Whether every path `inner` matches is matched by one of `outer`, or `undecided`. */\nexport function globCovers(outer: readonly Glob[], inner: Glob, budget: number = WITNESS_BUDGET): boolean | 'undecided' {\n return coreCovers(\n outer.map((g) => g.compiled),\n inner.compiled,\n budget,\n );\n}\n\n/**\n * A path both globs match, or `null` when there is none: the 0.1 interface,\n * kept for the library's callers. It cannot say `undecided`, so a search that\n * meets its budget throws; {@link globWitness} answers in three ways.\n */\nexport function intersectGlobs(a: Glob, b: Glob, budget: number = WITNESS_BUDGET): string | null {\n const witness = globWitness([a, b], [], budget);\n if (witness.kind === 'undecided') {\n throw new Error(`whether \"${a.source}\" and \"${b.source}\" meet is undecided within the search's budget`);\n }\n return witness.kind === 'found' ? witness.path : null;\n}\n\n/**\n * The directories a walk must enter to find every match, one per brace\n * alternative: the leading literal segments, or a literal file's directory.\n * `''` for an alternative that can match at the root.\n */\nexport function globBases(glob: Glob): readonly string[] {\n return glob.compiled.bases;\n}\n\n/** The first of {@link globBases}: the 0.1 interface, kept for the library's callers. */\nexport function globBase(glob: Glob): string {\n // One base per alternative, and a pattern has at least one.\n return glob.compiled.bases[0] as string;\n}\n\n/** A name with an extension, `login.ts` or `.eslintrc.json`, and not a dot-name such as `.github`. */\nexport function hasExtension(name: string): boolean {\n return /.\\.[^.]+$/.test(name);\n}\n\n/** The files a tree holds, and every directory above one. */\nexport interface Tree {\n readonly files: ReadonlySet<string>;\n readonly directories: ReadonlySet<string>;\n}\n\nconst trees = new WeakMap<readonly string[], Tree>();\n\n/** The tree a list of files describes. Built once per list, which every brief of a run shares. */\nexport function treeOf(files: readonly string[]): Tree {\n const known = trees.get(files);\n if (known !== undefined) return known;\n const directories = new Set<string>();\n for (const file of files) {\n for (let slash = file.indexOf('/'); slash !== -1; slash = file.indexOf('/', slash + 1)) directories.add(file.slice(0, slash));\n }\n const tree = { files: new Set(files), directories };\n trees.set(files, tree);\n return tree;\n}\n\n/** What the tree holds at a path: a file, a directory, or nothing. */\nexport function held(tree: Tree, path: string): 'file' | 'directory' | null {\n if (tree.files.has(path)) return 'file';\n return tree.directories.has(path) ? 'directory' : null;\n}\n\n/**\n * How a tree reads a literal path: a directory it holds is a directory, and\n * anything else is a file. Without a tree nothing is known to be a directory,\n * so every literal is a file; a trailing `/` says otherwise, and never reaches\n * this question.\n */\nexport function readingIn(files: readonly string[] | null): (path: string) => LiteralReading {\n if (files === null) return () => 'file';\n const tree = treeOf(files);\n return (path) => (held(tree, path) === 'directory' ? 'directory' : 'file');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EACL,UAAU,IAAI,UAAU,EACxB,WAAW,IAAI,WAAW,EAC1B,YAAY,EACZ,SAAS,IAAI,SAAS,EAGtB,cAAc,GAEf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAuB,cAAc,EAAgB,CAAC;AA+B3E,qDAAqD;AACrD,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,OAAO,GAAiB,EAAE;IAClE,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,iEAAiE,EAAE,CAAC;IAC5H,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,wEAAwE,EAAE,CAAC;IACnI,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC;IACx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,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["/**\n * Scopes as globs: spec-core's `path` dialect, read the way spec-brief reads a\n * brief.\n *\n * The syntax, the automaton and the witness search are spec-core's, copied\n * into `src/vendor/` and verified by hash, so the family's tools read one\n * pattern the same way (spec-core ADR-0003). What is decided here is what\n * spec-brief adds around it:\n *\n * - A pattern is relative to the repository root, so a leading `/` is refused\n * rather than rooted at the filesystem; and a list entry's `!` has no list to\n * belong to in a scope, so it is refused rather than read.\n * - Paths compare case-sensitively on every host, as git's do.\n * - A path with no glob syntax is read as the tree reads it: a file the tree\n * holds is that file, a directory it holds is everything beneath it, and a\n * path it does not hold is a file, unless it is written with a trailing `/`.\n * The tree, not the spelling, knows that `Dockerfile` is a file and\n * `docs/v1.2` a directory (ADR-0005, amended 2026-09-26).\n * - A trailing `/**` is at least one segment, so `docs/**` is the directory's\n * contents and a collision witness is always a file. A trailing `/` means\n * the same on a brace alternative as on the whole pattern: `{src/,lib}` is\n * `src/` or `lib`, and the tree is asked about `lib` alone.\n *\n * Nothing here compiles to a `RegExp`. Matching costs at most the pattern's\n * size times the path's length, and a question about two scopes that cannot be\n * answered within the search's budget answers `undecided`, never a guess.\n */\n\nimport {\n globCovers as coreCovers,\n globWitness as coreWitness,\n isGlobSyntax,\n parseGlob as coreParse,\n type Glob as CoreGlob,\n type LiteralReading,\n WITNESS_BUDGET,\n type Witness,\n} from './vendor/spec-core/pattern/index.js';\nimport { segments } from './vendor/spec-core/path/index.js';\n\nexport { isGlobSyntax, type LiteralReading, WITNESS_BUDGET, type Witness };\n\n/** A literal path a pattern names, and how it was read. */\nexport interface Literal {\n readonly path: string;\n readonly reading: LiteralReading;\n}\n\nexport interface Glob {\n readonly source: string;\n /** The compiled pattern: spec-core's `path` dialect, case-sensitive. */\n readonly compiled: CoreGlob;\n /**\n * Each path the pattern names with no glob syntax and no trailing `/`, one\n * per brace alternative; empty when it has none.\n */\n readonly literals: readonly Literal[];\n}\n\nexport type GlobParse = { readonly ok: true; readonly glob: Glob } | { readonly ok: false; readonly error: string };\n\nexport interface ParseOptions {\n /**\n * How a path with no glob syntax is read: `file`, that path alone;\n * `directory`, everything beneath it; `either`, both. A function is asked\n * per literal path, as {@link readingIn} answers for a tree. `file` when\n * unset: a path nothing says is a directory is not read as one.\n */\n readonly literal?: LiteralReading | ((path: string) => LiteralReading) | undefined;\n}\n\n/** Parses a scope pattern, or says why it cannot. */\nexport function parseGlob(source: string, options: ParseOptions = {}): GlobParse {\n const pattern = source.trim();\n if (pattern.startsWith('!')) return { ok: false, error: 'negated patterns are not supported; narrow the positive pattern' };\n if (pattern.startsWith('/')) return { ok: false, error: 'a pattern is relative to the repository root and cannot start with \"/\"' };\n const given = options.literal ?? 'file';\n const literals: Literal[] = [];\n const literal = (path: string): LiteralReading => {\n const reading = typeof given === 'function' ? given(path) : given;\n literals.push({ path, reading });\n return reading;\n };\n // A pattern too large to compile is refused by the core, with its reason,\n // as a malformed one is; what the reading throws is a defect, and passes on.\n const parsed = coreParse(pattern, { dialect: 'path', caseSensitive: true, literal });\n return parsed.ok ? { ok: true, glob: { source, compiled: parsed.glob, literals } } : parsed;\n}\n\n/**\n * Whether a path matches. The path is read as a repository path: empty and\n * `.` segments are dropped, so `./src//a.ts` is `src/a.ts`.\n */\nexport function matchGlob(glob: Glob, path: string): boolean {\n const canonical = segments(path).join('/');\n return canonical !== '' && glob.compiled.match(canonical);\n}\n\n/**\n * A shortest path every glob in `include` matches and none in `exclude` does,\n * `none` as a proof that there is no such path, or `undecided` when the search\n * met its budget first.\n */\nexport function globWitness(include: readonly Glob[], exclude: readonly Glob[] = [], budget: number = WITNESS_BUDGET): Witness {\n return coreWitness(\n include.map((g) => g.compiled),\n exclude.map((g) => g.compiled),\n budget,\n );\n}\n\n/** Whether every path `inner` matches is matched by one of `outer`, or `undecided`. */\nexport function globCovers(outer: readonly Glob[], inner: Glob, budget: number = WITNESS_BUDGET): boolean | 'undecided' {\n return coreCovers(\n outer.map((g) => g.compiled),\n inner.compiled,\n budget,\n );\n}\n\n/**\n * A path both globs match, or `null` when there is none: the 0.1 interface,\n * kept for the library's callers. It cannot say `undecided`, so a search that\n * meets its budget throws; {@link globWitness} answers in three ways.\n */\nexport function intersectGlobs(a: Glob, b: Glob, budget: number = WITNESS_BUDGET): string | null {\n const witness = globWitness([a, b], [], budget);\n if (witness.kind === 'undecided') {\n throw new Error(`whether \"${a.source}\" and \"${b.source}\" meet is undecided within the search's budget`);\n }\n return witness.kind === 'found' ? witness.path : null;\n}\n\n/**\n * The directories a walk must enter to find every match, one per brace\n * alternative: the leading literal segments, or a literal file's directory.\n * `''` for an alternative that can match at the root.\n */\nexport function globBases(glob: Glob): readonly string[] {\n return glob.compiled.bases;\n}\n\n/** The first of {@link globBases}: the 0.1 interface, kept for the library's callers. */\nexport function globBase(glob: Glob): string {\n // One base per alternative, and a pattern has at least one.\n return glob.compiled.bases[0] as string;\n}\n\n/** A name with an extension, `login.ts` or `.eslintrc.json`, and not a dot-name such as `.github`. */\nexport function hasExtension(name: string): boolean {\n return /.\\.[^.]+$/.test(name);\n}\n\n/** The files a tree holds, and every directory above one. */\nexport interface Tree {\n readonly files: ReadonlySet<string>;\n readonly directories: ReadonlySet<string>;\n}\n\nconst trees = new WeakMap<readonly string[], Tree>();\n\n/** The tree a list of files describes. Built once per list, which every brief of a run shares. */\nexport function treeOf(files: readonly string[]): Tree {\n const known = trees.get(files);\n if (known !== undefined) return known;\n const directories = new Set<string>();\n for (const file of files) {\n for (let slash = file.indexOf('/'); slash !== -1; slash = file.indexOf('/', slash + 1)) directories.add(file.slice(0, slash));\n }\n const tree = { files: new Set(files), directories };\n trees.set(files, tree);\n return tree;\n}\n\n/** What the tree holds at a path: a file, a directory, or nothing. */\nexport function held(tree: Tree, path: string): 'file' | 'directory' | null {\n if (tree.files.has(path)) return 'file';\n return tree.directories.has(path) ? 'directory' : null;\n}\n\n/**\n * How a tree reads a literal path: a directory it holds is a directory, and\n * anything else is a file. Without a tree nothing is known to be a directory,\n * so every literal is a file; a trailing `/` says otherwise, and never reaches\n * this question.\n */\nexport function readingIn(files: readonly string[] | null): (path: string) => LiteralReading {\n if (files === null) return () => 'file';\n const tree = treeOf(files);\n return (path) => (held(tree, path) === 'directory' ? 'directory' : 'file');\n}\n"]}
|
|
@@ -251,7 +251,10 @@ function readBrackets(layout, definitions, defined) {
|
|
|
251
251
|
// structure mask blanks, so those two tests shape the runs and change no
|
|
252
252
|
// link. A definition's line is no paragraph's: it holds a label, a
|
|
253
253
|
// destination and a title, none of them a link, and the text after it is a
|
|
254
|
-
// paragraph of its own, whose brackets pair with nothing before it.
|
|
254
|
+
// paragraph of its own, whose brackets pair with nothing before it. Past
|
|
255
|
+
// the last line there is no line, and `continues` holds nothing there, so
|
|
256
|
+
// no run reaches past it: the loop below could take one step more, and the
|
|
257
|
+
// test for a line that is not there could go.
|
|
255
258
|
const inParagraph = (i) => {
|
|
256
259
|
const line = lines[i];
|
|
257
260
|
return line !== undefined && isMarkdown(line) && !line.blank && !defined.has(i + 1);
|
|
@@ -393,6 +396,8 @@ function readBrackets(layout, definitions, defined) {
|
|
|
393
396
|
// when a pair lies inside it, or more than 999 characters; one that is
|
|
394
397
|
// not leaves the first bracket to be read as a shortcut.
|
|
395
398
|
const refClose = pairs.get(close + 1);
|
|
399
|
+
// With no second bracket the length is NaN and the comparison false,
|
|
400
|
+
// so the first test only narrows the type.
|
|
396
401
|
if (refClose !== undefined && refClose - close - 2 <= MAX_LABEL && !brackets.nested.has(close + 1)) {
|
|
397
402
|
// `[text][]` is read through its text; `[text][label]` through its label.
|
|
398
403
|
const collapsed = text.slice(close + 2, refClose).trim() === '';
|
|
@@ -425,6 +430,8 @@ function readBrackets(layout, definitions, defined) {
|
|
|
425
430
|
const link = passed ? null : bracket(at, at, image, line);
|
|
426
431
|
reach.push(Math.max(reach[reach.length - 1], link === null ? from : link.end));
|
|
427
432
|
const around = brackets.outer.get(at);
|
|
433
|
+
// `holding` is asked only about offsets, so the first test only
|
|
434
|
+
// narrows the type.
|
|
428
435
|
if (around !== undefined && (holding.has(at) || (link !== null && !image)))
|
|
429
436
|
holding.add(around);
|
|
430
437
|
}
|
|
@@ -434,7 +441,10 @@ function readBrackets(layout, definitions, defined) {
|
|
|
434
441
|
// `textEnd` is -1 or a `]` that closes a `[`, so never 0, and the `]` is
|
|
435
442
|
// read as no link. Leaving one step later, past it, resumes at the same
|
|
436
443
|
// place, or ends the paragraph where a shortcut link ended it anyway: the
|
|
437
|
-
// test below reads the same with `textEnd > 0` or `at > textEnd
|
|
444
|
+
// test below reads the same with `textEnd > 0` or `at > textEnd`, and so
|
|
445
|
+
// does the one further into the loop with `textEnd > 0`. `resume` is read
|
|
446
|
+
// only while `textEnd` is set, and the two are set together, so its first
|
|
447
|
+
// value is never read.
|
|
438
448
|
let textEnd = -1;
|
|
439
449
|
let resume = -1;
|
|
440
450
|
while (at < to) {
|
|
@@ -475,6 +485,9 @@ function readBrackets(layout, definitions, defined) {
|
|
|
475
485
|
if (!link.image && link.form !== 'wiki') {
|
|
476
486
|
textEnd = pairs.get(at);
|
|
477
487
|
resume = link.end;
|
|
488
|
+
// Into the text. A step back instead reads the character before
|
|
489
|
+
// the `[`, which opens nothing there - it opened no link before
|
|
490
|
+
// this one, or it is escaped - and comes back here.
|
|
478
491
|
at += 1;
|
|
479
492
|
}
|
|
480
493
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/markdown/links.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAe,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,UA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E,KAAK,EAAE,IAAI,CAAC,IAAI,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;YAC7E,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;gBACjB,sEAAsE;gBACtE,kCAAkC;gBAClC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,OAAO,EAAE,CAAC;oBAC/E,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACf,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC;gBAChB,CAAC;qBAAM,CAAC;oBACN,EAAE,IAAI,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;iBAAM,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;gBACzB,EAAE,IAAI,CAAC,CAAC;YACV,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACf,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;oBACxC,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAW,CAAC;oBAClC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;oBAClB,EAAE,IAAI,CAAC,CAAC;gBACV,CAAC;qBAAM,CAAC;oBACN,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC;gBAChB,CAAC;YACH,CAAC;QACH,CAAC;QACD,KAAK,GAAG,IAAI,CAAC;IACf,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * Links, images and reference definitions, read from the structure mask so\n * that nothing in code or a comment is one.\n *\n * Six forms: inline `[text](dest \"title\")`, full and collapsed reference\n * `[text][label]` and `[label][]`, shortcut `[label]`, autolink `<https://x>`,\n * wiki `[[target|text]]`, and the definition `[label]: dest` the reference\n * forms are read through. Each may be an image, written with a leading `!`.\n * A link's text is read again for images, which CommonMark renders there - a\n * badge wrapped in a link has two destinations - and for nothing else; each\n * is listed after the link it lies in.\n *\n * Links may not contain links, as CommonMark has it: in\n * `[a [b](inner.md) c](outer.md)` the inner pair is the link, and the outer\n * brackets and `(outer.md)` are text. So before a paragraph is read its pairs\n * are read innermost first, as CommonMark reads them, to learn which `[`\n * holds a link at any depth.\n *\n * Brackets are paired once per paragraph with a stack, and the tables that\n * say where a destination or a title ends are built once per paragraph, so\n * no bracket searches the text again for its partner. A document of nothing\n * but brackets costs its length.\n *\n * A paragraph ends at `to`, and the character there is a line terminator,\n * which no loop here acts on; nor is any lookup made at the first three\n * offsets of a paragraph, before the shortest `[](` could end. Mutants that\n * move a bound onto those places change no answer, and are equivalent.\n */\n\nimport { inRanges, mergeRanges } from '../text/index.js';\nimport { isMarkdown, isSpaceOrTab, leadOffset, visibleLead, type Layout } from './layout.js';\nimport { atxLevel, isThematicBreak, listMarker } from './syntax.js';\nimport type { Heading, Link, ScannedLine } from './types.js';\n\nconst BANG = 33;\nconst DOUBLE_QUOTE = 34;\nconst SINGLE_QUOTE = 39;\nconst OPEN_PAREN = 40;\nconst CLOSE_PAREN = 41;\nconst LESS_THAN = 60;\nconst GREATER_THAN = 62;\nconst OPEN_BRACKET = 91;\nconst BACKSLASH = 92;\nconst CLOSE_BRACKET = 93;\nconst LF = 10;\nconst CR = 13;\n\n/** CommonMark: a link label holds at most 999 characters. */\nconst MAX_LABEL = 999;\n\n/**\n * A label holds no bracket but an escaped one. Its two alternatives never\n * start on the same character, so a label is read without backtracking.\n */\nconst DEFINITION = /^ {0,3}\\[(?!\\^)((?:[^[\\]\\\\]|\\\\.)+)\\]:[ \\t]*(<[^<>]*>|\\S+)/;\n/** What may follow a definition's destination: nothing, or a title after whitespace. */\nconst TITLE_ONLY = /^(?:[ \\t]+(?:\"[^\"]*\"|'[^']*'|\\([^)]*\\)))?[ \\t]*$/;\nconst AUTOLINK = /<((?:https?|ftp|mailto):[^<>\\s]+)>/g;\n\ninterface Definition {\n readonly target: string;\n readonly targetStart: number;\n readonly targetEnd: number;\n}\n\nexport function findLinks(layout: Layout, headings: readonly Heading[]): Link[] {\n const definitions = new Map<string, Definition>();\n const defined = readDefinitions(layout, headings, definitions);\n const bracketed = readBrackets(layout, definitions, new Set(defined.map((d) => d.line)));\n // `<https://x>` as a link's destination or text is part of that link.\n const taken = mergeRanges([...defined, ...bracketed]);\n const autolinks = readAutolinks(layout).filter((link) => !inRanges(taken, link.start));\n return [...defined, ...bracketed, ...autolinks].sort((a, b) => a.start - b.start);\n}\n\n/**\n * How labels compare: trimmed, whitespace collapsed, and case folded as\n * CommonMark's reference implementations fold it, down and then up, so that\n * `ẞ` and `SS` are one label.\n */\nfunction normalizeLabel(label: string): string {\n return label.trim().replace(/\\s+/g, ' ').toLowerCase().toUpperCase();\n}\n\n/**\n * Definitions come first: the reference forms are read through them, and a\n * definition is conventionally written at the foot of the file, after the\n * links that use it. The first definition of a label wins.\n *\n * `[Note]: this matters` is prose that looks like one, so a definition has\n * nothing after its destination but a title. `[^1]: text` is a footnote.\n *\n * A definition cannot interrupt a paragraph, as CommonMark has it: one\n * written on the line under a paragraph's text is that text. It opens a\n * paragraph, or follows a definition that did.\n */\nfunction readDefinitions(layout: Layout, headings: readonly Heading[], definitions: Map<string, Definition>): Link[] {\n const { text, structure, lines, continues } = layout;\n const closed = closingLines(layout, headings);\n const out: Link[] = [];\n for (const line of lines) {\n if (!isMarkdown(line) || !visibleLead(layout, line)) continue;\n const masked = structure.slice(line.contentStart, line.end);\n const match = DEFINITION.exec(masked);\n if (match === null || !TITLE_ONLY.test(masked.slice(match[0].length))) continue;\n // Under a definition the paragraph holds nothing else yet. `continues`\n // holds no first line, so there is a line above whenever it is asked about.\n const follows = out[out.length - 1]?.line === line.line - 1;\n if (!follows && continues.has(line.line) && paragraphOpen(lines[line.line - 2] as ScannedLine, closed)) continue;\n const between = (match[1] as string).length;\n const start = line.contentStart + match[0].indexOf('[');\n const label = text.slice(start + 1, start + 1 + between).trim();\n if (label.length === 0 || between > MAX_LABEL) continue;\n const written = match[2] as string;\n const end = line.contentStart + match[0].length;\n const angle = written.charCodeAt(0) === LESS_THAN ? 1 : 0;\n const targetStart = end - written.length + angle;\n const targetEnd = end - angle;\n const target = text.slice(targetStart, targetEnd);\n const key = normalizeLabel(label);\n if (!definitions.has(key)) definitions.set(key, { target, targetStart, targetEnd });\n out.push({ form: 'definition', image: false, text: label, target, label, start, end, targetStart, targetEnd, line: line.line });\n }\n return out;\n}\n\n/**\n * The lines after which no paragraph is open, though the line under one\n * would go on with a paragraph written there: the last line of a heading,\n * and of an HTML block a comment opens. Such a block starts where a comment\n * opens a line, after at most three columns, and ends on the line the\n * comment closes on.\n */\nfunction closingLines(layout: Layout, headings: readonly Heading[]): Set<number> {\n const closed = new Set<number>();\n for (const heading of headings) closed.add(heading.endLine);\n for (const comment of layout.comments) {\n const opened = layout.lines[comment.line - 1] as ScannedLine;\n if (opened.indent <= 3 && comment.start === leadOffset(opened)) closed.add(layout.index.positionAt(comment.end).line);\n }\n return closed;\n}\n\n/**\n * Whether a paragraph is open after a line, for the line under it to go on\n * with. None is after a blank line, code, a thematic break or a closing\n * line, and none is open in a list item whose marker has nothing after it,\n * or a heading or a thematic break.\n */\nfunction paragraphOpen(line: ScannedLine, closed: ReadonlySet<number>): boolean {\n if (!isMarkdown(line) || line.blank || closed.has(line.line) || isThematicBreak(line.content)) return false;\n const marker = listMarker(line.content);\n if (marker === null) return true;\n // The marker takes every space after it, so what is left is empty or text.\n const rest = line.content.slice(marker.offset + marker.width);\n return rest.length > 0 && atxLevel(rest) === 0 && !isThematicBreak(rest);\n}\n\nfunction readAutolinks(layout: Layout): Link[] {\n const out: Link[] = [];\n for (const match of layout.structure.matchAll(AUTOLINK)) {\n const start = match.index;\n const end = start + match[0].length;\n out.push({\n form: 'autolink',\n image: false,\n text: '',\n target: match[1] as string,\n label: null,\n start,\n end,\n targetStart: start + 1,\n targetEnd: end - 1,\n line: layout.index.positionAt(start).line,\n });\n }\n return out;\n}\n\n/** The brackets of a paragraph, `[` paired with `]` as a stack pairs them, escaped ones skipped. */\ninterface Brackets {\n /** Each `[` a `]` closes, to that `]`, in the order of the `]`s: every pair after the pairs inside it. */\n readonly pairs: Map<number, number>;\n /** Each paired `[` to the `[` still open around it, where there is one. */\n readonly outer: Map<number, number>;\n /** Each paired `[` to how many pairs had closed when it opened: the pairs wholly before it. */\n readonly before: Map<number, number>;\n /** Every `[` written after an unescaped `!`: an image's. */\n readonly images: Set<number>;\n /** Every `[` with a pair inside it: those whose text holds an unescaped bracket. */\n readonly nested: Set<number>;\n}\n\nfunction pairBrackets(structure: string, from: number, to: number): Brackets {\n const brackets: Brackets = { pairs: new Map(), outer: new Map(), before: new Map(), images: new Set(), nested: new Set() };\n const { pairs } = brackets;\n const open: { readonly at: number; readonly before: number }[] = [];\n let escaped = -1;\n for (let at = from; at < to; at += 1) {\n const ch = structure.charCodeAt(at);\n if (ch === BACKSLASH) {\n escaped = at + 1;\n at += 1;\n } else if (ch === OPEN_BRACKET) {\n open.push({ at, before: pairs.size });\n if (structure.charCodeAt(at - 1) === BANG && escaped !== at - 1) brackets.images.add(at);\n } else if (ch === CLOSE_BRACKET) {\n // A `]` with nothing to close pairs with nothing; recorded under\n // `undefined` it would not be found either, so this test changes no\n // answer, only what the maps hold.\n const opened = open.pop();\n if (opened !== undefined) {\n pairs.set(opened.at, at);\n brackets.before.set(opened.at, opened.before);\n const around = open[open.length - 1];\n if (around !== undefined) {\n brackets.outer.set(opened.at, around.at);\n brackets.nested.add(around.at);\n }\n }\n }\n }\n return brackets;\n}\n\n/**\n * For every offset of a paragraph, where what starts there ends, or the end\n * of the paragraph when nothing does: a bare destination at the next space or\n * control character, or at the first `)` its own parentheses leave unmatched;\n * a title at its next unescaped closing quote or parenthesis. Filled from the\n * right in one pass, so every lookup is a read.\n */\ninterface Ends {\n readonly space: Int32Array;\n readonly paren: Int32Array;\n readonly doubleQuote: Int32Array;\n readonly singleQuote: Int32Array;\n readonly closeParen: Int32Array;\n readonly openParen: Int32Array;\n}\n\nfunction endsOf(structure: string, from: number, to: number): Ends {\n const length = to - from;\n const escaped = new Uint8Array(length + 1);\n for (let x = 0; x < length; x += 1) {\n if (escaped[x] === 0 && structure.charCodeAt(from + x) === BACKSLASH) escaped[x + 1] = 1;\n }\n // Two past the last offset: a `(` whose `)` is the paragraph's last\n // character looks one further for the next unmatched `)`, and finds none.\n const make = (): Int32Array => new Int32Array(length + 2).fill(to);\n const ends: Ends = { space: make(), paren: make(), doubleQuote: make(), singleQuote: make(), closeParen: make(), openParen: make() };\n for (let x = length - 1; x >= 0; x -= 1) {\n const at = from + x;\n const ch = structure.charCodeAt(at);\n const plain = escaped[x] === 0;\n ends.space[x] = ch <= 32 || ch === 127 ? at : (ends.space[x + 1] as number);\n // From a `(`, the first unmatched `)` is the first one after the `)` that\n // closes it, which is the first unmatched `)` after the `(`.\n const unmatched = ends.paren[x + 1] as number;\n if (plain && ch === CLOSE_PAREN) ends.paren[x] = at;\n else if (plain && ch === OPEN_PAREN) ends.paren[x] = ends.paren[unmatched + 1 - from] as number;\n else ends.paren[x] = unmatched;\n ends.doubleQuote[x] = plain && ch === DOUBLE_QUOTE ? at : (ends.doubleQuote[x + 1] as number);\n ends.singleQuote[x] = plain && ch === SINGLE_QUOTE ? at : (ends.singleQuote[x + 1] as number);\n ends.closeParen[x] = plain && ch === CLOSE_PAREN ? at : (ends.closeParen[x + 1] as number);\n ends.openParen[x] = plain && ch === OPEN_PAREN ? at : (ends.openParen[x + 1] as number);\n }\n return ends;\n}\n\ninterface Destination {\n readonly targetStart: number;\n readonly targetEnd: number;\n /** Offset just past the closing `)`. */\n readonly end: number;\n}\n\n/**\n * The bracket forms, a paragraph at a time. A paragraph here is a run of\n * Markdown lines, none blank or a definition, each continuing the one above:\n * a bracket never pairs across a blank line, a heading, a definition, or the\n * start of another block.\n */\nfunction readBrackets(layout: Layout, definitions: ReadonlyMap<string, Definition>, defined: ReadonlySet<number>): Link[] {\n const { lines, continues, structure, text } = layout;\n const out: Link[] = [];\n // The first `]]` at or after the last place one was looked for; the cursor\n // only moves forward, so each is found once.\n let doubleClose = -2;\n\n const lookup = (from: number, to: number): Definition | undefined =>\n to - from > MAX_LABEL ? undefined : definitions.get(normalizeLabel(text.slice(from, to)));\n\n // A blank or code line let into a paragraph would bring only characters the\n // structure mask blanks, so those two tests shape the runs and change no\n // link. A definition's line is no paragraph's: it holds a label, a\n // destination and a title, none of them a link, and the text after it is a\n // paragraph of its own, whose brackets pair with nothing before it.\n const inParagraph = (i: number): boolean => {\n const line = lines[i];\n return line !== undefined && isMarkdown(line) && !line.blank && !defined.has(i + 1);\n };\n\n for (let first = 0; first < lines.length; first += 1) {\n if (!inParagraph(first)) continue;\n let last = first;\n while (inParagraph(last + 1) && continues.has(last + 2)) last += 1;\n const from = (lines[first] as ScannedLine).start;\n const to = (lines[last] as ScannedLine).end;\n const brackets = pairBrackets(structure, from, to);\n const { pairs } = brackets;\n // Each `[` with a link inside it, at any depth.\n const holding = new Set<number>();\n let ends: Ends | null = null;\n\n // Spaces and tabs, and at most one line ending inside the paragraph. The\n // character at `to` ends the paragraph's last line and is none of these.\n const skipSpace = (start: number): number => {\n let at = start;\n while (isSpaceOrTab(structure, at)) at += 1;\n if (at < to) {\n if (structure.charCodeAt(at) === CR) at += 1;\n if (structure.charCodeAt(at) === LF) at += 1;\n while (isSpaceOrTab(structure, at)) at += 1;\n }\n return at;\n };\n\n const destination = (open: number): Destination | null => {\n const at = skipSpace(open);\n let targetStart: number;\n let targetEnd: number;\n let after: number;\n if (structure.charCodeAt(at) === LESS_THAN) {\n // `<dest>`: no line ending and no unescaped `<` inside.\n let close = at + 1;\n for (;;) {\n if (close >= to) return null;\n const ch = structure.charCodeAt(close);\n if (ch === GREATER_THAN) break;\n if (ch === LESS_THAN || ch === LF || ch === CR) return null;\n close += ch === BACKSLASH ? 2 : 1;\n }\n targetStart = at + 1;\n targetEnd = close;\n after = close + 1;\n } else {\n ends ??= endsOf(structure, from, to);\n const space = ends.space[at - from] as number;\n const paren = ends.paren[at - from] as number;\n targetStart = at;\n // The two are equal only when neither is found, at `to`.\n targetEnd = paren < space ? paren : space;\n after = targetEnd;\n // An empty destination points nowhere a reader can follow.\n if (targetEnd === at) return null;\n }\n let k = skipSpace(after);\n if (structure.charCodeAt(k) === CLOSE_PAREN) return { targetStart, targetEnd, end: k + 1 };\n // A title is separated from the destination by whitespace, and quoted.\n if (k === after) return null;\n ends ??= endsOf(structure, from, to);\n const x = k + 1 - from;\n const quote = structure.charCodeAt(k);\n let close: number;\n if (quote === DOUBLE_QUOTE) close = ends.doubleQuote[x] as number;\n else if (quote === SINGLE_QUOTE) close = ends.singleQuote[x] as number;\n // A title in parentheses may not hold an unescaped `(`.\n else if (quote === OPEN_PAREN) close = (ends.openParen[x] as number) < (ends.closeParen[x] as number) ? to : (ends.closeParen[x] as number);\n else return null;\n // Equal ends are `to`, where the title fails either way. Past `to` the\n // next line opens a block of its own, and none opens with `)`.\n if (close === to) return null;\n k = skipSpace(close + 1);\n return structure.charCodeAt(k) === CLOSE_PAREN ? { targetStart, targetEnd, end: k + 1 } : null;\n };\n\n const wiki = (at: number, start: number, image: boolean, line: ScannedLine): Link | null => {\n if (structure.charCodeAt(at + 1) !== OPEN_BRACKET) return null;\n if (doubleClose !== -1 && doubleClose < at + 2) doubleClose = structure.indexOf(']]', at + 2);\n const close = doubleClose;\n if (close < 0 || close + 2 > line.end) return null;\n const inner = text.slice(at + 2, close);\n const written = inner.trim();\n const pipe = written.indexOf('|');\n const target = (pipe < 0 ? written : written.slice(0, pipe)).trim();\n // `[[ ]]` and `[[|text]]` name nothing to link to.\n if (target.length === 0) return null;\n const targetStart = at + 2 + inner.length - inner.trimStart().length;\n return {\n form: 'wiki',\n image,\n text: written,\n target,\n label: null,\n start,\n end: close + 2,\n targetStart,\n targetEnd: targetStart + target.length,\n line: line.line,\n };\n };\n\n const bracket = (at: number, start: number, image: boolean, line: ScannedLine): Link | null => {\n const close = pairs.get(at);\n // A link holding a link is text; an image holding one is still an image.\n if (close === undefined || (!image && holding.has(at))) return null;\n const label = (): string => text.slice(at + 1, close).trim();\n if (structure.charCodeAt(close + 1) === OPEN_PAREN) {\n const dest = destination(close + 2);\n if (dest !== null) {\n const target = text.slice(dest.targetStart, dest.targetEnd);\n return { form: 'inline', image, text: label(), target, label: null, start, line: line.line, ...dest };\n }\n } else {\n // Only a `[` is paired, so a second bracket follows exactly when this\n // finds one. It is a label unless it holds a bracket, which it does\n // when a pair lies inside it, or more than 999 characters; one that is\n // not leaves the first bracket to be read as a shortcut.\n const refClose = pairs.get(close + 1);\n if (refClose !== undefined && refClose - close - 2 <= MAX_LABEL && !brackets.nested.has(close + 1)) {\n // `[text][]` is read through its text; `[text][label]` through its label.\n const collapsed = text.slice(close + 2, refClose).trim() === '';\n const found = collapsed ? lookup(at + 1, close) : lookup(close + 2, refClose);\n if (found === undefined) return null;\n const written = collapsed ? label() : text.slice(close + 2, refClose).trim();\n return { form: 'reference', image, text: label(), label: written, start, end: refClose + 1, line: line.line, ...found };\n }\n }\n // `[text](not a destination)` is a shortcut followed by text, as CommonMark reads it.\n const found = lookup(at + 1, close);\n if (found === undefined) return null;\n return { form: 'shortcut', image, text: label(), label: label(), start, end: close + 1, line: line.line, ...found };\n };\n\n const lineAt = (at: number): ScannedLine => lines[layout.index.positionAt(at).line - 1] as ScannedLine;\n\n // CommonMark reads each pair at its `]`, so the pairs inside a `[` are\n // read before it, and a link among them makes it text, and every `[`\n // open around it: the pairs come innermost first, and fill `holding` on\n // the way out. An image among them does not; a link may hold one. What a\n // link or an image reads past its `]` - a destination, a title, a second\n // label - is not read for links again: `reach` is the furthest any of the\n // first so many pairs read to, and a `[` short of it opens nothing.\n const reach = [from];\n for (const at of pairs.keys()) {\n const line = lineAt(at);\n const image = brackets.images.has(at);\n const passed = (reach[brackets.before.get(at) as number] as number) > at;\n const link = passed ? null : bracket(at, at, image, line);\n reach.push(Math.max(reach[reach.length - 1] as number, link === null ? from : link.end));\n const around = brackets.outer.get(at);\n if (around !== undefined && (holding.has(at) || (link !== null && !image))) holding.add(around);\n }\n\n let at = from;\n // Inside a link's text, up to its `]`, where CommonMark reads an image -\n // a badge wrapped in a link - but no other link; then on past the link.\n // `textEnd` is -1 or a `]` that closes a `[`, so never 0, and the `]` is\n // read as no link. Leaving one step later, past it, resumes at the same\n // place, or ends the paragraph where a shortcut link ended it anyway: the\n // test below reads the same with `textEnd > 0` or `at > textEnd`.\n let textEnd = -1;\n let resume = -1;\n while (at < to) {\n if (textEnd >= 0 && at >= textEnd) {\n at = resume;\n textEnd = -1;\n continue;\n }\n const ch = structure.charCodeAt(at);\n if (ch === BACKSLASH) {\n at += 2;\n continue;\n }\n if (ch !== OPEN_BRACKET) {\n at += 1;\n continue;\n }\n const line = lineAt(at);\n const image = brackets.images.has(at);\n const start = image ? at - 1 : at;\n const link = wiki(at, start, image, line) ?? bracket(at, start, image, line);\n if (textEnd >= 0) {\n // An image that closes inside the text; its own text is alt text, and\n // holds nothing a reader follows.\n if (link !== null && link.image && link.form !== 'wiki' && link.end <= textEnd) {\n out.push(link);\n at = link.end;\n } else {\n at += 1;\n }\n } else if (link === null) {\n at += 1;\n } else {\n out.push(link);\n if (!link.image && link.form !== 'wiki') {\n textEnd = pairs.get(at) as number;\n resume = link.end;\n at += 1;\n } else {\n at = link.end;\n }\n }\n }\n first = last;\n }\n return out;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"links.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/markdown/links.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAe,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,eAAe,EAA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","sourcesContent":["/**\n * Links, images and reference definitions, read from the structure mask so\n * that nothing in code or a comment is one.\n *\n * Six forms: inline `[text](dest \"title\")`, full and collapsed reference\n * `[text][label]` and `[label][]`, shortcut `[label]`, autolink `<https://x>`,\n * wiki `[[target|text]]`, and the definition `[label]: dest` the reference\n * forms are read through. Each may be an image, written with a leading `!`.\n * A link's text is read again for images, which CommonMark renders there - a\n * badge wrapped in a link has two destinations - and for nothing else; each\n * is listed after the link it lies in.\n *\n * Links may not contain links, as CommonMark has it: in\n * `[a [b](inner.md) c](outer.md)` the inner pair is the link, and the outer\n * brackets and `(outer.md)` are text. So before a paragraph is read its pairs\n * are read innermost first, as CommonMark reads them, to learn which `[`\n * holds a link at any depth.\n *\n * Brackets are paired once per paragraph with a stack, and the tables that\n * say where a destination or a title ends are built once per paragraph, so\n * no bracket searches the text again for its partner. A document of nothing\n * but brackets costs its length.\n *\n * A paragraph ends at `to`, and the character there is a line terminator,\n * which no loop here acts on; nor is any lookup made at the first three\n * offsets of a paragraph, before the shortest `[](` could end. Mutants that\n * move a bound onto those places change no answer, and are equivalent.\n */\n\nimport { inRanges, mergeRanges } from '../text/index.js';\nimport { isMarkdown, isSpaceOrTab, leadOffset, visibleLead, type Layout } from './layout.js';\nimport { atxLevel, isThematicBreak, listMarker } from './syntax.js';\nimport type { Heading, Link, ScannedLine } from './types.js';\n\nconst BANG = 33;\nconst DOUBLE_QUOTE = 34;\nconst SINGLE_QUOTE = 39;\nconst OPEN_PAREN = 40;\nconst CLOSE_PAREN = 41;\nconst LESS_THAN = 60;\nconst GREATER_THAN = 62;\nconst OPEN_BRACKET = 91;\nconst BACKSLASH = 92;\nconst CLOSE_BRACKET = 93;\nconst LF = 10;\nconst CR = 13;\n\n/** CommonMark: a link label holds at most 999 characters. */\nconst MAX_LABEL = 999;\n\n/**\n * A label holds no bracket but an escaped one. Its two alternatives never\n * start on the same character, so a label is read without backtracking.\n */\nconst DEFINITION = /^ {0,3}\\[(?!\\^)((?:[^[\\]\\\\]|\\\\.)+)\\]:[ \\t]*(<[^<>]*>|\\S+)/;\n/** What may follow a definition's destination: nothing, or a title after whitespace. */\nconst TITLE_ONLY = /^(?:[ \\t]+(?:\"[^\"]*\"|'[^']*'|\\([^)]*\\)))?[ \\t]*$/;\nconst AUTOLINK = /<((?:https?|ftp|mailto):[^<>\\s]+)>/g;\n\ninterface Definition {\n readonly target: string;\n readonly targetStart: number;\n readonly targetEnd: number;\n}\n\nexport function findLinks(layout: Layout, headings: readonly Heading[]): Link[] {\n const definitions = new Map<string, Definition>();\n const defined = readDefinitions(layout, headings, definitions);\n const bracketed = readBrackets(layout, definitions, new Set(defined.map((d) => d.line)));\n // `<https://x>` as a link's destination or text is part of that link.\n const taken = mergeRanges([...defined, ...bracketed]);\n const autolinks = readAutolinks(layout).filter((link) => !inRanges(taken, link.start));\n return [...defined, ...bracketed, ...autolinks].sort((a, b) => a.start - b.start);\n}\n\n/**\n * How labels compare: trimmed, whitespace collapsed, and case folded as\n * CommonMark's reference implementations fold it, down and then up, so that\n * `ẞ` and `SS` are one label.\n */\nfunction normalizeLabel(label: string): string {\n return label.trim().replace(/\\s+/g, ' ').toLowerCase().toUpperCase();\n}\n\n/**\n * Definitions come first: the reference forms are read through them, and a\n * definition is conventionally written at the foot of the file, after the\n * links that use it. The first definition of a label wins.\n *\n * `[Note]: this matters` is prose that looks like one, so a definition has\n * nothing after its destination but a title. `[^1]: text` is a footnote.\n *\n * A definition cannot interrupt a paragraph, as CommonMark has it: one\n * written on the line under a paragraph's text is that text. It opens a\n * paragraph, or follows a definition that did.\n */\nfunction readDefinitions(layout: Layout, headings: readonly Heading[], definitions: Map<string, Definition>): Link[] {\n const { text, structure, lines, continues } = layout;\n const closed = closingLines(layout, headings);\n const out: Link[] = [];\n for (const line of lines) {\n if (!isMarkdown(line) || !visibleLead(layout, line)) continue;\n const masked = structure.slice(line.contentStart, line.end);\n const match = DEFINITION.exec(masked);\n if (match === null || !TITLE_ONLY.test(masked.slice(match[0].length))) continue;\n // Under a definition the paragraph holds nothing else yet. `continues`\n // holds no first line, so there is a line above whenever it is asked about.\n const follows = out[out.length - 1]?.line === line.line - 1;\n if (!follows && continues.has(line.line) && paragraphOpen(lines[line.line - 2] as ScannedLine, closed)) continue;\n const between = (match[1] as string).length;\n const start = line.contentStart + match[0].indexOf('[');\n const label = text.slice(start + 1, start + 1 + between).trim();\n if (label.length === 0 || between > MAX_LABEL) continue;\n const written = match[2] as string;\n const end = line.contentStart + match[0].length;\n const angle = written.charCodeAt(0) === LESS_THAN ? 1 : 0;\n const targetStart = end - written.length + angle;\n const targetEnd = end - angle;\n const target = text.slice(targetStart, targetEnd);\n const key = normalizeLabel(label);\n if (!definitions.has(key)) definitions.set(key, { target, targetStart, targetEnd });\n out.push({ form: 'definition', image: false, text: label, target, label, start, end, targetStart, targetEnd, line: line.line });\n }\n return out;\n}\n\n/**\n * The lines after which no paragraph is open, though the line under one\n * would go on with a paragraph written there: the last line of a heading,\n * and of an HTML block a comment opens. Such a block starts where a comment\n * opens a line, after at most three columns, and ends on the line the\n * comment closes on.\n */\nfunction closingLines(layout: Layout, headings: readonly Heading[]): Set<number> {\n const closed = new Set<number>();\n for (const heading of headings) closed.add(heading.endLine);\n for (const comment of layout.comments) {\n const opened = layout.lines[comment.line - 1] as ScannedLine;\n if (opened.indent <= 3 && comment.start === leadOffset(opened)) closed.add(layout.index.positionAt(comment.end).line);\n }\n return closed;\n}\n\n/**\n * Whether a paragraph is open after a line, for the line under it to go on\n * with. None is after a blank line, code, a thematic break or a closing\n * line, and none is open in a list item whose marker has nothing after it,\n * or a heading or a thematic break.\n */\nfunction paragraphOpen(line: ScannedLine, closed: ReadonlySet<number>): boolean {\n if (!isMarkdown(line) || line.blank || closed.has(line.line) || isThematicBreak(line.content)) return false;\n const marker = listMarker(line.content);\n if (marker === null) return true;\n // The marker takes every space after it, so what is left is empty or text.\n const rest = line.content.slice(marker.offset + marker.width);\n return rest.length > 0 && atxLevel(rest) === 0 && !isThematicBreak(rest);\n}\n\nfunction readAutolinks(layout: Layout): Link[] {\n const out: Link[] = [];\n for (const match of layout.structure.matchAll(AUTOLINK)) {\n const start = match.index;\n const end = start + match[0].length;\n out.push({\n form: 'autolink',\n image: false,\n text: '',\n target: match[1] as string,\n label: null,\n start,\n end,\n targetStart: start + 1,\n targetEnd: end - 1,\n line: layout.index.positionAt(start).line,\n });\n }\n return out;\n}\n\n/** The brackets of a paragraph, `[` paired with `]` as a stack pairs them, escaped ones skipped. */\ninterface Brackets {\n /** Each `[` a `]` closes, to that `]`, in the order of the `]`s: every pair after the pairs inside it. */\n readonly pairs: Map<number, number>;\n /** Each paired `[` to the `[` still open around it, where there is one. */\n readonly outer: Map<number, number>;\n /** Each paired `[` to how many pairs had closed when it opened: the pairs wholly before it. */\n readonly before: Map<number, number>;\n /** Every `[` written after an unescaped `!`: an image's. */\n readonly images: Set<number>;\n /** Every `[` with a pair inside it: those whose text holds an unescaped bracket. */\n readonly nested: Set<number>;\n}\n\nfunction pairBrackets(structure: string, from: number, to: number): Brackets {\n const brackets: Brackets = { pairs: new Map(), outer: new Map(), before: new Map(), images: new Set(), nested: new Set() };\n const { pairs } = brackets;\n const open: { readonly at: number; readonly before: number }[] = [];\n let escaped = -1;\n for (let at = from; at < to; at += 1) {\n const ch = structure.charCodeAt(at);\n if (ch === BACKSLASH) {\n escaped = at + 1;\n at += 1;\n } else if (ch === OPEN_BRACKET) {\n open.push({ at, before: pairs.size });\n if (structure.charCodeAt(at - 1) === BANG && escaped !== at - 1) brackets.images.add(at);\n } else if (ch === CLOSE_BRACKET) {\n // A `]` with nothing to close pairs with nothing; recorded under\n // `undefined` it would not be found either, so this test changes no\n // answer, only what the maps hold.\n const opened = open.pop();\n if (opened !== undefined) {\n pairs.set(opened.at, at);\n brackets.before.set(opened.at, opened.before);\n const around = open[open.length - 1];\n if (around !== undefined) {\n brackets.outer.set(opened.at, around.at);\n brackets.nested.add(around.at);\n }\n }\n }\n }\n return brackets;\n}\n\n/**\n * For every offset of a paragraph, where what starts there ends, or the end\n * of the paragraph when nothing does: a bare destination at the next space or\n * control character, or at the first `)` its own parentheses leave unmatched;\n * a title at its next unescaped closing quote or parenthesis. Filled from the\n * right in one pass, so every lookup is a read.\n */\ninterface Ends {\n readonly space: Int32Array;\n readonly paren: Int32Array;\n readonly doubleQuote: Int32Array;\n readonly singleQuote: Int32Array;\n readonly closeParen: Int32Array;\n readonly openParen: Int32Array;\n}\n\nfunction endsOf(structure: string, from: number, to: number): Ends {\n const length = to - from;\n const escaped = new Uint8Array(length + 1);\n for (let x = 0; x < length; x += 1) {\n if (escaped[x] === 0 && structure.charCodeAt(from + x) === BACKSLASH) escaped[x + 1] = 1;\n }\n // Two past the last offset: a `(` whose `)` is the paragraph's last\n // character looks one further for the next unmatched `)`, and finds none.\n const make = (): Int32Array => new Int32Array(length + 2).fill(to);\n const ends: Ends = { space: make(), paren: make(), doubleQuote: make(), singleQuote: make(), closeParen: make(), openParen: make() };\n for (let x = length - 1; x >= 0; x -= 1) {\n const at = from + x;\n const ch = structure.charCodeAt(at);\n const plain = escaped[x] === 0;\n ends.space[x] = ch <= 32 || ch === 127 ? at : (ends.space[x + 1] as number);\n // From a `(`, the first unmatched `)` is the first one after the `)` that\n // closes it, which is the first unmatched `)` after the `(`.\n const unmatched = ends.paren[x + 1] as number;\n if (plain && ch === CLOSE_PAREN) ends.paren[x] = at;\n else if (plain && ch === OPEN_PAREN) ends.paren[x] = ends.paren[unmatched + 1 - from] as number;\n else ends.paren[x] = unmatched;\n ends.doubleQuote[x] = plain && ch === DOUBLE_QUOTE ? at : (ends.doubleQuote[x + 1] as number);\n ends.singleQuote[x] = plain && ch === SINGLE_QUOTE ? at : (ends.singleQuote[x + 1] as number);\n ends.closeParen[x] = plain && ch === CLOSE_PAREN ? at : (ends.closeParen[x + 1] as number);\n ends.openParen[x] = plain && ch === OPEN_PAREN ? at : (ends.openParen[x + 1] as number);\n }\n return ends;\n}\n\ninterface Destination {\n readonly targetStart: number;\n readonly targetEnd: number;\n /** Offset just past the closing `)`. */\n readonly end: number;\n}\n\n/**\n * The bracket forms, a paragraph at a time. A paragraph here is a run of\n * Markdown lines, none blank or a definition, each continuing the one above:\n * a bracket never pairs across a blank line, a heading, a definition, or the\n * start of another block.\n */\nfunction readBrackets(layout: Layout, definitions: ReadonlyMap<string, Definition>, defined: ReadonlySet<number>): Link[] {\n const { lines, continues, structure, text } = layout;\n const out: Link[] = [];\n // The first `]]` at or after the last place one was looked for; the cursor\n // only moves forward, so each is found once.\n let doubleClose = -2;\n\n const lookup = (from: number, to: number): Definition | undefined =>\n to - from > MAX_LABEL ? undefined : definitions.get(normalizeLabel(text.slice(from, to)));\n\n // A blank or code line let into a paragraph would bring only characters the\n // structure mask blanks, so those two tests shape the runs and change no\n // link. A definition's line is no paragraph's: it holds a label, a\n // destination and a title, none of them a link, and the text after it is a\n // paragraph of its own, whose brackets pair with nothing before it. Past\n // the last line there is no line, and `continues` holds nothing there, so\n // no run reaches past it: the loop below could take one step more, and the\n // test for a line that is not there could go.\n const inParagraph = (i: number): boolean => {\n const line = lines[i];\n return line !== undefined && isMarkdown(line) && !line.blank && !defined.has(i + 1);\n };\n\n for (let first = 0; first < lines.length; first += 1) {\n if (!inParagraph(first)) continue;\n let last = first;\n while (inParagraph(last + 1) && continues.has(last + 2)) last += 1;\n const from = (lines[first] as ScannedLine).start;\n const to = (lines[last] as ScannedLine).end;\n const brackets = pairBrackets(structure, from, to);\n const { pairs } = brackets;\n // Each `[` with a link inside it, at any depth.\n const holding = new Set<number>();\n let ends: Ends | null = null;\n\n // Spaces and tabs, and at most one line ending inside the paragraph. The\n // character at `to` ends the paragraph's last line and is none of these.\n const skipSpace = (start: number): number => {\n let at = start;\n while (isSpaceOrTab(structure, at)) at += 1;\n if (at < to) {\n if (structure.charCodeAt(at) === CR) at += 1;\n if (structure.charCodeAt(at) === LF) at += 1;\n while (isSpaceOrTab(structure, at)) at += 1;\n }\n return at;\n };\n\n const destination = (open: number): Destination | null => {\n const at = skipSpace(open);\n let targetStart: number;\n let targetEnd: number;\n let after: number;\n if (structure.charCodeAt(at) === LESS_THAN) {\n // `<dest>`: no line ending and no unescaped `<` inside.\n let close = at + 1;\n for (;;) {\n if (close >= to) return null;\n const ch = structure.charCodeAt(close);\n if (ch === GREATER_THAN) break;\n if (ch === LESS_THAN || ch === LF || ch === CR) return null;\n close += ch === BACKSLASH ? 2 : 1;\n }\n targetStart = at + 1;\n targetEnd = close;\n after = close + 1;\n } else {\n ends ??= endsOf(structure, from, to);\n const space = ends.space[at - from] as number;\n const paren = ends.paren[at - from] as number;\n targetStart = at;\n // The two are equal only when neither is found, at `to`.\n targetEnd = paren < space ? paren : space;\n after = targetEnd;\n // An empty destination points nowhere a reader can follow.\n if (targetEnd === at) return null;\n }\n let k = skipSpace(after);\n if (structure.charCodeAt(k) === CLOSE_PAREN) return { targetStart, targetEnd, end: k + 1 };\n // A title is separated from the destination by whitespace, and quoted.\n if (k === after) return null;\n ends ??= endsOf(structure, from, to);\n const x = k + 1 - from;\n const quote = structure.charCodeAt(k);\n let close: number;\n if (quote === DOUBLE_QUOTE) close = ends.doubleQuote[x] as number;\n else if (quote === SINGLE_QUOTE) close = ends.singleQuote[x] as number;\n // A title in parentheses may not hold an unescaped `(`.\n else if (quote === OPEN_PAREN) close = (ends.openParen[x] as number) < (ends.closeParen[x] as number) ? to : (ends.closeParen[x] as number);\n else return null;\n // Equal ends are `to`, where the title fails either way. Past `to` the\n // next line opens a block of its own, and none opens with `)`.\n if (close === to) return null;\n k = skipSpace(close + 1);\n return structure.charCodeAt(k) === CLOSE_PAREN ? { targetStart, targetEnd, end: k + 1 } : null;\n };\n\n const wiki = (at: number, start: number, image: boolean, line: ScannedLine): Link | null => {\n if (structure.charCodeAt(at + 1) !== OPEN_BRACKET) return null;\n if (doubleClose !== -1 && doubleClose < at + 2) doubleClose = structure.indexOf(']]', at + 2);\n const close = doubleClose;\n if (close < 0 || close + 2 > line.end) return null;\n const inner = text.slice(at + 2, close);\n const written = inner.trim();\n const pipe = written.indexOf('|');\n const target = (pipe < 0 ? written : written.slice(0, pipe)).trim();\n // `[[ ]]` and `[[|text]]` name nothing to link to.\n if (target.length === 0) return null;\n const targetStart = at + 2 + inner.length - inner.trimStart().length;\n return {\n form: 'wiki',\n image,\n text: written,\n target,\n label: null,\n start,\n end: close + 2,\n targetStart,\n targetEnd: targetStart + target.length,\n line: line.line,\n };\n };\n\n const bracket = (at: number, start: number, image: boolean, line: ScannedLine): Link | null => {\n const close = pairs.get(at);\n // A link holding a link is text; an image holding one is still an image.\n if (close === undefined || (!image && holding.has(at))) return null;\n const label = (): string => text.slice(at + 1, close).trim();\n if (structure.charCodeAt(close + 1) === OPEN_PAREN) {\n const dest = destination(close + 2);\n if (dest !== null) {\n const target = text.slice(dest.targetStart, dest.targetEnd);\n return { form: 'inline', image, text: label(), target, label: null, start, line: line.line, ...dest };\n }\n } else {\n // Only a `[` is paired, so a second bracket follows exactly when this\n // finds one. It is a label unless it holds a bracket, which it does\n // when a pair lies inside it, or more than 999 characters; one that is\n // not leaves the first bracket to be read as a shortcut.\n const refClose = pairs.get(close + 1);\n // With no second bracket the length is NaN and the comparison false,\n // so the first test only narrows the type.\n if (refClose !== undefined && refClose - close - 2 <= MAX_LABEL && !brackets.nested.has(close + 1)) {\n // `[text][]` is read through its text; `[text][label]` through its label.\n const collapsed = text.slice(close + 2, refClose).trim() === '';\n const found = collapsed ? lookup(at + 1, close) : lookup(close + 2, refClose);\n if (found === undefined) return null;\n const written = collapsed ? label() : text.slice(close + 2, refClose).trim();\n return { form: 'reference', image, text: label(), label: written, start, end: refClose + 1, line: line.line, ...found };\n }\n }\n // `[text](not a destination)` is a shortcut followed by text, as CommonMark reads it.\n const found = lookup(at + 1, close);\n if (found === undefined) return null;\n return { form: 'shortcut', image, text: label(), label: label(), start, end: close + 1, line: line.line, ...found };\n };\n\n const lineAt = (at: number): ScannedLine => lines[layout.index.positionAt(at).line - 1] as ScannedLine;\n\n // CommonMark reads each pair at its `]`, so the pairs inside a `[` are\n // read before it, and a link among them makes it text, and every `[`\n // open around it: the pairs come innermost first, and fill `holding` on\n // the way out. An image among them does not; a link may hold one. What a\n // link or an image reads past its `]` - a destination, a title, a second\n // label - is not read for links again: `reach` is the furthest any of the\n // first so many pairs read to, and a `[` short of it opens nothing.\n const reach = [from];\n for (const at of pairs.keys()) {\n const line = lineAt(at);\n const image = brackets.images.has(at);\n const passed = (reach[brackets.before.get(at) as number] as number) > at;\n const link = passed ? null : bracket(at, at, image, line);\n reach.push(Math.max(reach[reach.length - 1] as number, link === null ? from : link.end));\n const around = brackets.outer.get(at);\n // `holding` is asked only about offsets, so the first test only\n // narrows the type.\n if (around !== undefined && (holding.has(at) || (link !== null && !image))) holding.add(around);\n }\n\n let at = from;\n // Inside a link's text, up to its `]`, where CommonMark reads an image -\n // a badge wrapped in a link - but no other link; then on past the link.\n // `textEnd` is -1 or a `]` that closes a `[`, so never 0, and the `]` is\n // read as no link. Leaving one step later, past it, resumes at the same\n // place, or ends the paragraph where a shortcut link ended it anyway: the\n // test below reads the same with `textEnd > 0` or `at > textEnd`, and so\n // does the one further into the loop with `textEnd > 0`. `resume` is read\n // only while `textEnd` is set, and the two are set together, so its first\n // value is never read.\n let textEnd = -1;\n let resume = -1;\n while (at < to) {\n if (textEnd >= 0 && at >= textEnd) {\n at = resume;\n textEnd = -1;\n continue;\n }\n const ch = structure.charCodeAt(at);\n if (ch === BACKSLASH) {\n at += 2;\n continue;\n }\n if (ch !== OPEN_BRACKET) {\n at += 1;\n continue;\n }\n const line = lineAt(at);\n const image = brackets.images.has(at);\n const start = image ? at - 1 : at;\n const link = wiki(at, start, image, line) ?? bracket(at, start, image, line);\n if (textEnd >= 0) {\n // An image that closes inside the text; its own text is alt text, and\n // holds nothing a reader follows.\n if (link !== null && link.image && link.form !== 'wiki' && link.end <= textEnd) {\n out.push(link);\n at = link.end;\n } else {\n at += 1;\n }\n } else if (link === null) {\n at += 1;\n } else {\n out.push(link);\n if (!link.image && link.form !== 'wiki') {\n textEnd = pairs.get(at) as number;\n resume = link.end;\n // Into the text. A step back instead reads the character before\n // the `[`, which opens nothing there - it opened no link before\n // this one, or it is escaped - and comes back here.\n at += 1;\n } else {\n at = link.end;\n }\n }\n }\n first = last;\n }\n return out;\n}\n"]}
|
|
@@ -29,6 +29,9 @@ export function findTables(layout, atx) {
|
|
|
29
29
|
return layout.covered.has(line.line) || heading.has(line.line) ? null : line;
|
|
30
30
|
};
|
|
31
31
|
const out = [];
|
|
32
|
+
// A header needs a line under it. `row` answers null for a line past the
|
|
33
|
+
// last, so a bound that lets `i` reach one or two further finds the same
|
|
34
|
+
// tables.
|
|
32
35
|
for (let i = 0; i + 1 < lines.length; i += 1) {
|
|
33
36
|
const header = row(i);
|
|
34
37
|
const delimiter = row(i + 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/markdown/tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AAGlE,MAAM,IAAI,GAAG,GAAG,CAAC;AACjB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,cAAc,GAAG,UAAU,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,GAAqC;IAC9E,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACzB,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,qEAAqE;IACrE,wDAAwD;IACxD,MAAM,GAAG,GAAG,CAAC,CAAS,EAAsB,EAAE;QAC5C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,UAAU,C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E,CAAC;IAC9B,2EAA2E;IAC3E,IAAI,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,KAAK,EAAa,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC;IACjG,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QACtC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,2EAA2E;IAC3E,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7F,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,IAAI,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW;IACpD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC;IACpD,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AAC1F,CAAC","sourcesContent":["/**\n * GFM pipe tables, with an offset for every cell.\n *\n * Cell offsets are the point: a register kept as a table needs findings that\n * name the cell declaring a relation, not the row and not the file. Rows are\n * split on the structure mask, so a pipe inside a code span or a comment\n * cannot invent a column, and the text of each cell comes from the original.\n *\n * Reading one line past the last, or one character past a line's end, finds\n * no row and no pipe, so mutants that move those bounds are equivalent.\n */\n\nimport { isMarkdown, leadOffset, type Layout } from './layout.js';\nimport type { Heading, ScannedLine, Table, TableCell, TableRow } from './types.js';\n\nconst PIPE = 124;\nconst BACKSLASH = 92;\nconst DELIMITER_CELL = /^:?-+:?$/;\n\n/**\n * A header line, a delimiter row with as many cells, and the rows under them\n * up to a line that is blank, holds no pipe, or is not Markdown.\n */\nexport function findTables(layout: Layout, atx: readonly Pick<Heading, 'line'>[]): Table[] {\n const { lines } = layout;\n const heading = new Set(atx.map((h) => h.line));\n // A line starting in a comment is not a row, and neither is one that\n // continues a code span or comment from the line above.\n const row = (i: number): ScannedLine | null => {\n const line = lines[i];\n if (line === undefined || !isMarkdown(line) || line.blank || line.comment) return null;\n return layout.covered.has(line.line) || heading.has(line.line) ? null : line;\n };\n\n const out: Table[] = [];\n for (let i = 0; i + 1 < lines.length; i += 1) {\n const header = row(i);\n const delimiter = row(i + 1);\n if (header === null || delimiter === null) continue;\n const headers = splitRow(layout, header);\n if (headers.length === 0) continue;\n const marks = splitRow(layout, delimiter);\n if (marks.length !== headers.length || !marks.every((cell) => DELIMITER_CELL.test(cell.text))) continue;\n\n const rows: TableRow[] = [];\n let last = delimiter;\n for (let line = row(i + 2); line !== null; line = row(line.line)) {\n const cells = splitRow(layout, line);\n if (cells.length === 0) break;\n rows.push({ cells, start: line.contentStart, end: line.end, line: line.line });\n last = line;\n }\n out.push({ start: header.contentStart, end: last.end, line: header.line, endLine: last.line, headers, rows });\n i = last.line - 1;\n }\n return out;\n}\n\n/** Splits a row into cells, keeping each cell's offsets. A row without a pipe has none. */\nfunction splitRow(layout: Layout, line: ScannedLine): TableCell[] {\n const { text, structure } = layout;\n const bounds: number[] = [];\n for (let at = line.contentStart; at < line.end; at += 1) {\n // A pipe escaped with a backslash is content, not a column edge.\n if (structure.charCodeAt(at) === PIPE && text.charCodeAt(at - 1) !== BACKSLASH) bounds.push(at);\n }\n if (bounds.length === 0) return [];\n\n const cells: TableCell[] = [];\n // A pipe opening the row is a border, not the edge of an empty first cell.\n let cursor = bounds[0] === leadOffset(line) ? (bounds.shift() as number) + 1 : line.contentStart;\n for (const bound of bounds) {\n cells.push(cell(text, cursor, bound));\n cursor = bound + 1;\n }\n // What follows the last pipe is a cell unless the row ended with a border.\n if (text.slice(cursor, line.end).trim().length > 0) cells.push(cell(text, cursor, line.end));\n return cells;\n}\n\nfunction cell(text: string, start: number, end: number): TableCell {\n const raw = text.slice(start, end);\n const leading = raw.length - raw.trimStart().length;\n const trimmed = raw.trim();\n return { text: trimmed, start: start + leading, end: start + leading + trimmed.length };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/markdown/tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AAGlE,MAAM,IAAI,GAAG,GAAG,CAAC;AACjB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,cAAc,GAAG,UAAU,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,GAAqC;IAC9E,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACzB,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,qEAAqE;IACrE,wDAAwD;IACxD,MAAM,GAAG,GAAG,CAAC,CAAS,EAAsB,EAAE;QAC5C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO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,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,KAAK,EAAa,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC;IACjG,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QACtC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,2EAA2E;IAC3E,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7F,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,IAAI,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW;IACpD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC;IACpD,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AAC1F,CAAC","sourcesContent":["/**\n * GFM pipe tables, with an offset for every cell.\n *\n * Cell offsets are the point: a register kept as a table needs findings that\n * name the cell declaring a relation, not the row and not the file. Rows are\n * split on the structure mask, so a pipe inside a code span or a comment\n * cannot invent a column, and the text of each cell comes from the original.\n *\n * Reading one line past the last, or one character past a line's end, finds\n * no row and no pipe, so mutants that move those bounds are equivalent.\n */\n\nimport { isMarkdown, leadOffset, type Layout } from './layout.js';\nimport type { Heading, ScannedLine, Table, TableCell, TableRow } from './types.js';\n\nconst PIPE = 124;\nconst BACKSLASH = 92;\nconst DELIMITER_CELL = /^:?-+:?$/;\n\n/**\n * A header line, a delimiter row with as many cells, and the rows under them\n * up to a line that is blank, holds no pipe, or is not Markdown.\n */\nexport function findTables(layout: Layout, atx: readonly Pick<Heading, 'line'>[]): Table[] {\n const { lines } = layout;\n const heading = new Set(atx.map((h) => h.line));\n // A line starting in a comment is not a row, and neither is one that\n // continues a code span or comment from the line above.\n const row = (i: number): ScannedLine | null => {\n const line = lines[i];\n if (line === undefined || !isMarkdown(line) || line.blank || line.comment) return null;\n return layout.covered.has(line.line) || heading.has(line.line) ? null : line;\n };\n\n const out: Table[] = [];\n // A header needs a line under it. `row` answers null for a line past the\n // last, so a bound that lets `i` reach one or two further finds the same\n // tables.\n for (let i = 0; i + 1 < lines.length; i += 1) {\n const header = row(i);\n const delimiter = row(i + 1);\n if (header === null || delimiter === null) continue;\n const headers = splitRow(layout, header);\n if (headers.length === 0) continue;\n const marks = splitRow(layout, delimiter);\n if (marks.length !== headers.length || !marks.every((cell) => DELIMITER_CELL.test(cell.text))) continue;\n\n const rows: TableRow[] = [];\n let last = delimiter;\n for (let line = row(i + 2); line !== null; line = row(line.line)) {\n const cells = splitRow(layout, line);\n if (cells.length === 0) break;\n rows.push({ cells, start: line.contentStart, end: line.end, line: line.line });\n last = line;\n }\n out.push({ start: header.contentStart, end: last.end, line: header.line, endLine: last.line, headers, rows });\n i = last.line - 1;\n }\n return out;\n}\n\n/** Splits a row into cells, keeping each cell's offsets. A row without a pipe has none. */\nfunction splitRow(layout: Layout, line: ScannedLine): TableCell[] {\n const { text, structure } = layout;\n const bounds: number[] = [];\n for (let at = line.contentStart; at < line.end; at += 1) {\n // A pipe escaped with a backslash is content, not a column edge.\n if (structure.charCodeAt(at) === PIPE && text.charCodeAt(at - 1) !== BACKSLASH) bounds.push(at);\n }\n if (bounds.length === 0) return [];\n\n const cells: TableCell[] = [];\n // A pipe opening the row is a border, not the edge of an empty first cell.\n let cursor = bounds[0] === leadOffset(line) ? (bounds.shift() as number) + 1 : line.contentStart;\n for (const bound of bounds) {\n cells.push(cell(text, cursor, bound));\n cursor = bound + 1;\n }\n // What follows the last pipe is a cell unless the row ended with a border.\n if (text.slice(cursor, line.end).trim().length > 0) cells.push(cell(text, cursor, line.end));\n return cells;\n}\n\nfunction cell(text: string, start: number, end: number): TableCell {\n const raw = text.slice(start, end);\n const leading = raw.length - raw.trimStart().length;\n const trimmed = raw.trim();\n return { text: trimmed, start: start + leading, end: start + leading + trimmed.length };\n}\n"]}
|
|
@@ -46,10 +46,22 @@ interface Hole {
|
|
|
46
46
|
* matched slowly.
|
|
47
47
|
*/
|
|
48
48
|
export declare const MAX_STATES = 65536;
|
|
49
|
+
/**
|
|
50
|
+
* Thrown by the builder past {@link MAX_STATES}. `parseGlob` answers it as a
|
|
51
|
+
* refusal and `compileGlob` as a `GlobError`, so no function the pattern
|
|
52
|
+
* module exports lets it out; it stays exported for callers written when
|
|
53
|
+
* `parseGlob` did.
|
|
54
|
+
*/
|
|
49
55
|
export declare class AutomatonTooLarge extends Error {
|
|
50
56
|
constructor();
|
|
51
57
|
}
|
|
52
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Thompson's construction, one fragment at a time.
|
|
60
|
+
*
|
|
61
|
+
* An arrow written as -1 is a hole that `patch` aims before `finish` returns,
|
|
62
|
+
* or one nothing follows: a CHAR's second and both of a MATCH's. What it
|
|
63
|
+
* starts as is never read, so any other start gives the same automaton.
|
|
64
|
+
*/
|
|
53
65
|
export declare class Builder {
|
|
54
66
|
private readonly kinds;
|
|
55
67
|
private readonly first;
|
|
@@ -78,7 +90,8 @@ export declare class Builder {
|
|
|
78
90
|
* A reusable matcher over one automaton.
|
|
79
91
|
*
|
|
80
92
|
* Holds its buffers between subjects; it is not reentrant, and nothing needs
|
|
81
|
-
* it to be - matching calls out to nothing.
|
|
93
|
+
* it to be - matching calls out to nothing. `test` empties each buffer before
|
|
94
|
+
* it reads one, so what a buffer starts with is never read.
|
|
82
95
|
*/
|
|
83
96
|
export declare class Matcher {
|
|
84
97
|
private readonly automaton;
|
|
@@ -29,13 +29,25 @@ const MATCH = 3;
|
|
|
29
29
|
* matched slowly.
|
|
30
30
|
*/
|
|
31
31
|
export const MAX_STATES = 65_536;
|
|
32
|
+
/**
|
|
33
|
+
* Thrown by the builder past {@link MAX_STATES}. `parseGlob` answers it as a
|
|
34
|
+
* refusal and `compileGlob` as a `GlobError`, so no function the pattern
|
|
35
|
+
* module exports lets it out; it stays exported for callers written when
|
|
36
|
+
* `parseGlob` did.
|
|
37
|
+
*/
|
|
32
38
|
export class AutomatonTooLarge extends Error {
|
|
33
39
|
constructor() {
|
|
34
40
|
super(`the pattern compiles to more than ${MAX_STATES} states`);
|
|
35
41
|
this.name = 'AutomatonTooLarge';
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Thompson's construction, one fragment at a time.
|
|
46
|
+
*
|
|
47
|
+
* An arrow written as -1 is a hole that `patch` aims before `finish` returns,
|
|
48
|
+
* or one nothing follows: a CHAR's second and both of a MATCH's. What it
|
|
49
|
+
* starts as is never read, so any other start gives the same automaton.
|
|
50
|
+
*/
|
|
39
51
|
export class Builder {
|
|
40
52
|
kinds = [];
|
|
41
53
|
first = [];
|
|
@@ -70,6 +82,10 @@ export class Builder {
|
|
|
70
82
|
}
|
|
71
83
|
/** Each fragment after the one before it. */
|
|
72
84
|
sequence(parts) {
|
|
85
|
+
// A glob never asks for an empty sequence, nor below for an empty
|
|
86
|
+
// alternation: a segment holds a token, a pattern an alternative. The two
|
|
87
|
+
// guards change no answer the module gives; they meet a misuse where it
|
|
88
|
+
// happens rather than in whatever reads the fragment next.
|
|
73
89
|
if (parts.length === 0)
|
|
74
90
|
return this.empty();
|
|
75
91
|
let current = parts[0];
|
|
@@ -151,7 +167,8 @@ function close(automaton, stack, visited, stamp, into) {
|
|
|
151
167
|
* A reusable matcher over one automaton.
|
|
152
168
|
*
|
|
153
169
|
* Holds its buffers between subjects; it is not reentrant, and nothing needs
|
|
154
|
-
* it to be - matching calls out to nothing.
|
|
170
|
+
* it to be - matching calls out to nothing. `test` empties each buffer before
|
|
171
|
+
* it reads one, so what a buffer starts with is never read.
|
|
155
172
|
*/
|
|
156
173
|
export class Matcher {
|
|
157
174
|
automaton;
|
|
@@ -187,6 +204,8 @@ export class Matcher {
|
|
|
187
204
|
this.stack.push(automaton.first[state]);
|
|
188
205
|
close(automaton, this.stack, this.visited, this.stamp, this.next);
|
|
189
206
|
}
|
|
207
|
+
// With no live state the rest of the subject changes nothing, and the
|
|
208
|
+
// answer is false either way; this only stops early.
|
|
190
209
|
if (this.next.length === 0)
|
|
191
210
|
return false;
|
|
192
211
|
const spent = this.live;
|