@atscript/core 0.2.15 → 0.2.17
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/dist/index.cjs +107 -26
- package/dist/index.d.ts +2 -7
- package/dist/index.mjs +107 -26
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3035,10 +3035,10 @@ const ARITHMETIC_OPS = new Set(BACKTICK_ARG_VOCABULARY.arithmeticOps);
|
|
|
3035
3035
|
//#endregion
|
|
3036
3036
|
//#region packages/core/src/module-id.ts
|
|
3037
3037
|
/**
|
|
3038
|
-
* The package of each project root (see {@link moduleId})
|
|
3039
|
-
* `package.json` files read for it and
|
|
3040
|
-
* once one of them changed (a package
|
|
3041
|
-
* documents' epoch (`checked`).
|
|
3038
|
+
* The package of each project root (see {@link moduleId}) and file directory (see
|
|
3039
|
+
* {@link packageOfFile}), by its absolute path, with the `package.json` files read for it and
|
|
3040
|
+
* their modification times (`-1`: absent) — read again once one of them changed (a package
|
|
3041
|
+
* renamed, a manifest added or removed), checked once per documents' epoch (`checked`).
|
|
3042
3042
|
*/ const packages = /* @__PURE__ */ new Map();
|
|
3043
3043
|
/**
|
|
3044
3044
|
* The id of `doc`'s module, which orders the blocks of modules at one import depth: the name of
|
|
@@ -3051,16 +3051,7 @@ const ARITHMETIC_OPS = new Set(BACKTICK_ARG_VOCABULARY.arithmeticOps);
|
|
|
3051
3051
|
*/ function moduleId(doc) {
|
|
3052
3052
|
const file = fileUriToPath(doc.id);
|
|
3053
3053
|
const root = path.default.resolve(doc.config.rootDir ?? path.default.dirname(file));
|
|
3054
|
-
const
|
|
3055
|
-
let pkg = packages.get(root);
|
|
3056
|
-
if (!pkg || pkg.checked !== epoch && pkg.manifests.some((m) => mtimeOf(m.file) !== m.mtime)) {
|
|
3057
|
-
pkg = {
|
|
3058
|
-
...packageOf(root),
|
|
3059
|
-
checked: epoch
|
|
3060
|
-
};
|
|
3061
|
-
packages.set(root, pkg);
|
|
3062
|
-
}
|
|
3063
|
-
pkg.checked = epoch;
|
|
3054
|
+
const pkg = packageAt(root);
|
|
3064
3055
|
const known = ids.get(doc);
|
|
3065
3056
|
if (known?.uri === doc.id && known.root === root && known.pkg === pkg) return known.id;
|
|
3066
3057
|
const id = `${pkg.scope}:${path.default.relative(pkg.dir, file).replaceAll("\\", "/")}`;
|
|
@@ -3073,7 +3064,34 @@ const ARITHMETIC_OPS = new Set(BACKTICK_ARG_VOCABULARY.arithmeticOps);
|
|
|
3073
3064
|
return id;
|
|
3074
3065
|
}
|
|
3075
3066
|
/** {@link moduleId} by document: valid for its URI, root and package entry. */ const ids = /* @__PURE__ */ new WeakMap();
|
|
3076
|
-
/**
|
|
3067
|
+
/**
|
|
3068
|
+
* The package holding the file at path `file`: the name and directory of the nearest
|
|
3069
|
+
* `package.json` with a `name` above it, and the file's path in it (`src/a.as`) — `undefined`
|
|
3070
|
+
* without one.
|
|
3071
|
+
*/ function packageOfFile(file) {
|
|
3072
|
+
const abs = path.default.resolve(file);
|
|
3073
|
+
const pkg = packageAt(path.default.dirname(abs));
|
|
3074
|
+
if (pkg.name === void 0) return;
|
|
3075
|
+
return {
|
|
3076
|
+
name: pkg.name,
|
|
3077
|
+
dir: pkg.dir,
|
|
3078
|
+
path: path.default.relative(pkg.dir, abs).replaceAll("\\", "/")
|
|
3079
|
+
};
|
|
3080
|
+
}
|
|
3081
|
+
/** {@link packageOf} directory `root`, cached until one of the manifests it read changes. */ function packageAt(root) {
|
|
3082
|
+
const epoch = documentsEpoch();
|
|
3083
|
+
let pkg = packages.get(root);
|
|
3084
|
+
if (!pkg || pkg.checked !== epoch && pkg.manifests.some((m) => mtimeOf(m.file) !== m.mtime)) {
|
|
3085
|
+
pkg = {
|
|
3086
|
+
...packageOf(root),
|
|
3087
|
+
checked: epoch
|
|
3088
|
+
};
|
|
3089
|
+
packages.set(root, pkg);
|
|
3090
|
+
}
|
|
3091
|
+
pkg.checked = epoch;
|
|
3092
|
+
return pkg;
|
|
3093
|
+
}
|
|
3094
|
+
/** The package of directory `root` (a project root, see {@link moduleId}). */ function packageOf(root) {
|
|
3077
3095
|
const manifests = [];
|
|
3078
3096
|
let unnamed;
|
|
3079
3097
|
for (let dir = root;; dir = path.default.dirname(dir)) {
|
|
@@ -3086,6 +3104,7 @@ const ARITHMETIC_OPS = new Set(BACKTICK_ARG_VOCABULARY.arithmeticOps);
|
|
|
3086
3104
|
const name = mtime >= 0 ? packageName(file) : void 0;
|
|
3087
3105
|
if (name) return {
|
|
3088
3106
|
scope: name,
|
|
3107
|
+
name,
|
|
3089
3108
|
dir,
|
|
3090
3109
|
manifests
|
|
3091
3110
|
};
|
|
@@ -3096,6 +3115,7 @@ const ARITHMETIC_OPS = new Set(BACKTICK_ARG_VOCABULARY.arithmeticOps);
|
|
|
3096
3115
|
const relative = path.default.relative(base, root).replaceAll("\\", "/");
|
|
3097
3116
|
return {
|
|
3098
3117
|
scope: `#${(0, crypto.createHash)("sha256").update(relative).digest("hex").slice(0, 12)}`,
|
|
3118
|
+
name: void 0,
|
|
3099
3119
|
dir: root,
|
|
3100
3120
|
manifests
|
|
3101
3121
|
};
|
|
@@ -4034,6 +4054,7 @@ function definition(pipes) {
|
|
|
4034
4054
|
return true;
|
|
4035
4055
|
}
|
|
4036
4056
|
const resolvedPipes = pipes.map((p) => typeof p === "function" ? p() : p);
|
|
4057
|
+
skipLeadingOperator(fork, opts);
|
|
4037
4058
|
const node = runPipesOnce(resolvedPipes, fork);
|
|
4038
4059
|
if (node) {
|
|
4039
4060
|
fork.accepted();
|
|
@@ -4058,9 +4079,11 @@ function definition(pipes) {
|
|
|
4058
4079
|
fork.unexpected(false, "Unexpected end of group");
|
|
4059
4080
|
break;
|
|
4060
4081
|
}
|
|
4082
|
+
const isComma = fork.$.text === ",";
|
|
4061
4083
|
fork.accepted();
|
|
4062
4084
|
fork.move();
|
|
4063
4085
|
fork.skip(opts.skip);
|
|
4086
|
+
if (isComma) skipLeadingOperator(fork, opts);
|
|
4064
4087
|
} else {
|
|
4065
4088
|
if (fork.$) fork.unexpected();
|
|
4066
4089
|
break;
|
|
@@ -4113,6 +4136,29 @@ function definition(pipes) {
|
|
|
4113
4136
|
}
|
|
4114
4137
|
};
|
|
4115
4138
|
}
|
|
4139
|
+
const LEADING_OPERATORS = ["|", "&"];
|
|
4140
|
+
/**
|
|
4141
|
+
* Step over one `|` or `&` written before the first member of a union or
|
|
4142
|
+
* intersection (a formatting style: one member per line, each starting with the
|
|
4143
|
+
* operator). It carries no meaning. An operator that no member follows (the end
|
|
4144
|
+
* of the block, or more punctuation) is left in place, so it is reported as
|
|
4145
|
+
* unexpected and the rest of the block parses as before.
|
|
4146
|
+
*/ function skipLeadingOperator(ni, opts) {
|
|
4147
|
+
const text = LEADING_OPERATORS.filter((op) => opts.sep.includes(op));
|
|
4148
|
+
if (text.length === 0) return;
|
|
4149
|
+
const ahead = ni.fork().skip(opts.skip);
|
|
4150
|
+
if (!ahead.satisfies({
|
|
4151
|
+
node: "punctuation",
|
|
4152
|
+
text
|
|
4153
|
+
})) return;
|
|
4154
|
+
const member = ahead.next(opts.skip).$;
|
|
4155
|
+
if (member && member.type !== "punctuation") {
|
|
4156
|
+
ni.unfork(ahead);
|
|
4157
|
+
ni.accepted();
|
|
4158
|
+
ni.move();
|
|
4159
|
+
ni.skip(opts.skip);
|
|
4160
|
+
}
|
|
4161
|
+
}
|
|
4116
4162
|
function unwrap(attr) {
|
|
4117
4163
|
const opts = { pipes: [] };
|
|
4118
4164
|
return {
|
|
@@ -9725,17 +9771,13 @@ var AtscriptDoc = class AtscriptDoc {
|
|
|
9725
9771
|
return messages;
|
|
9726
9772
|
}
|
|
9727
9773
|
/**
|
|
9728
|
-
* Errors for references to a type another document does not export, in definitions inlined
|
|
9729
|
-
* from that document (`extends`, an intersection member, `annotate … as …`): the generated
|
|
9730
|
-
* code of this document would have to import it from there. Checks what codegen emits (see
|
|
9731
|
-
* {@link emittedRefs}).
|
|
9732
|
-
*/ /**
|
|
9733
9774
|
* Warnings for the mutating `annotate` blocks of this document whose target another document
|
|
9734
9775
|
* declares, when the block is not reachable: the declaring document does not import this one
|
|
9735
9776
|
* (directly or not), and a document using the target does not either. A block is part of its
|
|
9736
9777
|
* target's definition, built into whatever uses the target in the same build — a build of a
|
|
9737
9778
|
* document using it without this one (another entry, the target's package built on its own)
|
|
9738
|
-
* would not have it.
|
|
9779
|
+
* would not have it. When the target and documents using it belong to another package (see
|
|
9780
|
+
* `packageOfFile`), those documents cannot import this one: they get a warning of their own.
|
|
9739
9781
|
*/ unreachableBlockMessages() {
|
|
9740
9782
|
const messages = [];
|
|
9741
9783
|
const known = /* @__PURE__ */ new Map();
|
|
@@ -9747,21 +9789,54 @@ var AtscriptDoc = class AtscriptDoc {
|
|
|
9747
9789
|
}
|
|
9748
9790
|
return hit;
|
|
9749
9791
|
};
|
|
9792
|
+
let own;
|
|
9793
|
+
let ownFound = false;
|
|
9794
|
+
const places = /* @__PURE__ */ new Map();
|
|
9795
|
+
const placeOf = (d) => {
|
|
9796
|
+
let place = places.get(d);
|
|
9797
|
+
if (!place) {
|
|
9798
|
+
if (!ownFound) {
|
|
9799
|
+
own = packageOfDoc(this);
|
|
9800
|
+
ownFound = true;
|
|
9801
|
+
}
|
|
9802
|
+
const pkg = this.id.startsWith("file://") ? packageOfDoc(d) : void 0;
|
|
9803
|
+
place = pkg && pkg.dir !== own?.dir ? {
|
|
9804
|
+
other: true,
|
|
9805
|
+
path: `${pkg.name}/${pkg.path}`
|
|
9806
|
+
} : {
|
|
9807
|
+
other: false,
|
|
9808
|
+
path: relDocPath(this.id, d.id)
|
|
9809
|
+
};
|
|
9810
|
+
places.set(d, place);
|
|
9811
|
+
}
|
|
9812
|
+
return place;
|
|
9813
|
+
};
|
|
9750
9814
|
for (const node of this.nodes) {
|
|
9751
9815
|
if (!isAnnotate(node) || !node.isMutating) continue;
|
|
9752
9816
|
const owner = this.blockTarget(node);
|
|
9753
9817
|
const target = owner?.doc;
|
|
9754
9818
|
if (!target || !owner.node || target === this || importsThis(target)) continue;
|
|
9755
9819
|
const missing = [...target.documentsUsing(owner.node)].filter((d) => d !== this && !importsThis(d));
|
|
9756
|
-
if (missing.length
|
|
9757
|
-
|
|
9758
|
-
|
|
9820
|
+
if (missing.length === 0) continue;
|
|
9821
|
+
const range = node.token("target").range;
|
|
9822
|
+
const name = owner.node.id;
|
|
9823
|
+
const declared = placeOf(target);
|
|
9824
|
+
const users = missing.map(placeOf);
|
|
9825
|
+
const local = users.filter((u) => !(declared.other && u.other));
|
|
9826
|
+
const other = users.filter((u) => declared.other && u.other);
|
|
9827
|
+
if (local.length > 0) {
|
|
9828
|
+
const from = declared.other ? "" : `${declared.path} or from `;
|
|
9759
9829
|
messages.push({
|
|
9760
9830
|
severity: 2,
|
|
9761
|
-
message: `"${
|
|
9762
|
-
range
|
|
9831
|
+
message: `"${name}" (declared in ${declared.path}) is used by ${pathList(local)} without importing this file (directly or not): this annotate applies only in builds including this file — import it from ${from}the files using "${name}"`,
|
|
9832
|
+
range
|
|
9763
9833
|
});
|
|
9764
9834
|
}
|
|
9835
|
+
if (other.length > 0) messages.push({
|
|
9836
|
+
severity: 2,
|
|
9837
|
+
message: `"${name}" (declared in ${declared.path}) is used by files of other packages (${pathList(other)}), which cannot import this file: their packages' own builds never include this annotate, and at runtime it applies to those files only if this file is loaded before they first use "${name}" — to change only your own types, annotate a type of your own (interface X extends ${name}, or annotate ${name} as X)`,
|
|
9838
|
+
range
|
|
9839
|
+
});
|
|
9765
9840
|
}
|
|
9766
9841
|
return messages;
|
|
9767
9842
|
}
|
|
@@ -10457,6 +10532,12 @@ const zeroRange = {
|
|
|
10457
10532
|
for (const part of chain) ref.addChain(token(part));
|
|
10458
10533
|
return ref;
|
|
10459
10534
|
}
|
|
10535
|
+
/** The `path`s of `items`, sorted, comma-separated. */ function pathList(items) {
|
|
10536
|
+
return items.map((u) => u.path).sort().join(", ");
|
|
10537
|
+
}
|
|
10538
|
+
/** The package of file document `doc` (see `packageOfFile`); `undefined` for any other document. */ function packageOfDoc(doc) {
|
|
10539
|
+
return doc.id.startsWith("file://") ? packageOfFile(fileUriToPath(doc.id)) : void 0;
|
|
10540
|
+
}
|
|
10460
10541
|
/** `to`'s path relative to `from` (`./b.as`), or its id when not a file. */ function relDocPath(from, to) {
|
|
10461
10542
|
try {
|
|
10462
10543
|
return `${getRelPath(from, to)}.as`;
|
package/dist/index.d.ts
CHANGED
|
@@ -2159,19 +2159,14 @@ declare class AtscriptDoc {
|
|
|
2159
2159
|
* `never` (see `StructureModel.neverWarnings`).
|
|
2160
2160
|
*/
|
|
2161
2161
|
private neverMessages;
|
|
2162
|
-
/**
|
|
2163
|
-
* Errors for references to a type another document does not export, in definitions inlined
|
|
2164
|
-
* from that document (`extends`, an intersection member, `annotate … as …`): the generated
|
|
2165
|
-
* code of this document would have to import it from there. Checks what codegen emits (see
|
|
2166
|
-
* {@link emittedRefs}).
|
|
2167
|
-
*/
|
|
2168
2162
|
/**
|
|
2169
2163
|
* Warnings for the mutating `annotate` blocks of this document whose target another document
|
|
2170
2164
|
* declares, when the block is not reachable: the declaring document does not import this one
|
|
2171
2165
|
* (directly or not), and a document using the target does not either. A block is part of its
|
|
2172
2166
|
* target's definition, built into whatever uses the target in the same build — a build of a
|
|
2173
2167
|
* document using it without this one (another entry, the target's package built on its own)
|
|
2174
|
-
* would not have it.
|
|
2168
|
+
* would not have it. When the target and documents using it belong to another package (see
|
|
2169
|
+
* `packageOfFile`), those documents cannot import this one: they get a warning of their own.
|
|
2175
2170
|
*/
|
|
2176
2171
|
private unreachableBlockMessages;
|
|
2177
2172
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -3004,10 +3004,10 @@ const ARITHMETIC_OPS = new Set(BACKTICK_ARG_VOCABULARY.arithmeticOps);
|
|
|
3004
3004
|
//#endregion
|
|
3005
3005
|
//#region packages/core/src/module-id.ts
|
|
3006
3006
|
/**
|
|
3007
|
-
* The package of each project root (see {@link moduleId})
|
|
3008
|
-
* `package.json` files read for it and
|
|
3009
|
-
* once one of them changed (a package
|
|
3010
|
-
* documents' epoch (`checked`).
|
|
3007
|
+
* The package of each project root (see {@link moduleId}) and file directory (see
|
|
3008
|
+
* {@link packageOfFile}), by its absolute path, with the `package.json` files read for it and
|
|
3009
|
+
* their modification times (`-1`: absent) — read again once one of them changed (a package
|
|
3010
|
+
* renamed, a manifest added or removed), checked once per documents' epoch (`checked`).
|
|
3011
3011
|
*/ const packages = /* @__PURE__ */ new Map();
|
|
3012
3012
|
/**
|
|
3013
3013
|
* The id of `doc`'s module, which orders the blocks of modules at one import depth: the name of
|
|
@@ -3020,16 +3020,7 @@ const ARITHMETIC_OPS = new Set(BACKTICK_ARG_VOCABULARY.arithmeticOps);
|
|
|
3020
3020
|
*/ function moduleId(doc) {
|
|
3021
3021
|
const file = fileUriToPath(doc.id);
|
|
3022
3022
|
const root = path.resolve(doc.config.rootDir ?? path.dirname(file));
|
|
3023
|
-
const
|
|
3024
|
-
let pkg = packages.get(root);
|
|
3025
|
-
if (!pkg || pkg.checked !== epoch && pkg.manifests.some((m) => mtimeOf(m.file) !== m.mtime)) {
|
|
3026
|
-
pkg = {
|
|
3027
|
-
...packageOf(root),
|
|
3028
|
-
checked: epoch
|
|
3029
|
-
};
|
|
3030
|
-
packages.set(root, pkg);
|
|
3031
|
-
}
|
|
3032
|
-
pkg.checked = epoch;
|
|
3023
|
+
const pkg = packageAt(root);
|
|
3033
3024
|
const known = ids.get(doc);
|
|
3034
3025
|
if (known?.uri === doc.id && known.root === root && known.pkg === pkg) return known.id;
|
|
3035
3026
|
const id = `${pkg.scope}:${path.relative(pkg.dir, file).replaceAll("\\", "/")}`;
|
|
@@ -3042,7 +3033,34 @@ const ARITHMETIC_OPS = new Set(BACKTICK_ARG_VOCABULARY.arithmeticOps);
|
|
|
3042
3033
|
return id;
|
|
3043
3034
|
}
|
|
3044
3035
|
/** {@link moduleId} by document: valid for its URI, root and package entry. */ const ids = /* @__PURE__ */ new WeakMap();
|
|
3045
|
-
/**
|
|
3036
|
+
/**
|
|
3037
|
+
* The package holding the file at path `file`: the name and directory of the nearest
|
|
3038
|
+
* `package.json` with a `name` above it, and the file's path in it (`src/a.as`) — `undefined`
|
|
3039
|
+
* without one.
|
|
3040
|
+
*/ function packageOfFile(file) {
|
|
3041
|
+
const abs = path.resolve(file);
|
|
3042
|
+
const pkg = packageAt(path.dirname(abs));
|
|
3043
|
+
if (pkg.name === void 0) return;
|
|
3044
|
+
return {
|
|
3045
|
+
name: pkg.name,
|
|
3046
|
+
dir: pkg.dir,
|
|
3047
|
+
path: path.relative(pkg.dir, abs).replaceAll("\\", "/")
|
|
3048
|
+
};
|
|
3049
|
+
}
|
|
3050
|
+
/** {@link packageOf} directory `root`, cached until one of the manifests it read changes. */ function packageAt(root) {
|
|
3051
|
+
const epoch = documentsEpoch();
|
|
3052
|
+
let pkg = packages.get(root);
|
|
3053
|
+
if (!pkg || pkg.checked !== epoch && pkg.manifests.some((m) => mtimeOf(m.file) !== m.mtime)) {
|
|
3054
|
+
pkg = {
|
|
3055
|
+
...packageOf(root),
|
|
3056
|
+
checked: epoch
|
|
3057
|
+
};
|
|
3058
|
+
packages.set(root, pkg);
|
|
3059
|
+
}
|
|
3060
|
+
pkg.checked = epoch;
|
|
3061
|
+
return pkg;
|
|
3062
|
+
}
|
|
3063
|
+
/** The package of directory `root` (a project root, see {@link moduleId}). */ function packageOf(root) {
|
|
3046
3064
|
const manifests = [];
|
|
3047
3065
|
let unnamed;
|
|
3048
3066
|
for (let dir = root;; dir = path.dirname(dir)) {
|
|
@@ -3055,6 +3073,7 @@ const ARITHMETIC_OPS = new Set(BACKTICK_ARG_VOCABULARY.arithmeticOps);
|
|
|
3055
3073
|
const name = mtime >= 0 ? packageName(file) : void 0;
|
|
3056
3074
|
if (name) return {
|
|
3057
3075
|
scope: name,
|
|
3076
|
+
name,
|
|
3058
3077
|
dir,
|
|
3059
3078
|
manifests
|
|
3060
3079
|
};
|
|
@@ -3065,6 +3084,7 @@ const ARITHMETIC_OPS = new Set(BACKTICK_ARG_VOCABULARY.arithmeticOps);
|
|
|
3065
3084
|
const relative = path.relative(base, root).replaceAll("\\", "/");
|
|
3066
3085
|
return {
|
|
3067
3086
|
scope: `#${createHash("sha256").update(relative).digest("hex").slice(0, 12)}`,
|
|
3087
|
+
name: void 0,
|
|
3068
3088
|
dir: root,
|
|
3069
3089
|
manifests
|
|
3070
3090
|
};
|
|
@@ -4003,6 +4023,7 @@ function definition(pipes) {
|
|
|
4003
4023
|
return true;
|
|
4004
4024
|
}
|
|
4005
4025
|
const resolvedPipes = pipes.map((p) => typeof p === "function" ? p() : p);
|
|
4026
|
+
skipLeadingOperator(fork, opts);
|
|
4006
4027
|
const node = runPipesOnce(resolvedPipes, fork);
|
|
4007
4028
|
if (node) {
|
|
4008
4029
|
fork.accepted();
|
|
@@ -4027,9 +4048,11 @@ function definition(pipes) {
|
|
|
4027
4048
|
fork.unexpected(false, "Unexpected end of group");
|
|
4028
4049
|
break;
|
|
4029
4050
|
}
|
|
4051
|
+
const isComma = fork.$.text === ",";
|
|
4030
4052
|
fork.accepted();
|
|
4031
4053
|
fork.move();
|
|
4032
4054
|
fork.skip(opts.skip);
|
|
4055
|
+
if (isComma) skipLeadingOperator(fork, opts);
|
|
4033
4056
|
} else {
|
|
4034
4057
|
if (fork.$) fork.unexpected();
|
|
4035
4058
|
break;
|
|
@@ -4082,6 +4105,29 @@ function definition(pipes) {
|
|
|
4082
4105
|
}
|
|
4083
4106
|
};
|
|
4084
4107
|
}
|
|
4108
|
+
const LEADING_OPERATORS = ["|", "&"];
|
|
4109
|
+
/**
|
|
4110
|
+
* Step over one `|` or `&` written before the first member of a union or
|
|
4111
|
+
* intersection (a formatting style: one member per line, each starting with the
|
|
4112
|
+
* operator). It carries no meaning. An operator that no member follows (the end
|
|
4113
|
+
* of the block, or more punctuation) is left in place, so it is reported as
|
|
4114
|
+
* unexpected and the rest of the block parses as before.
|
|
4115
|
+
*/ function skipLeadingOperator(ni, opts) {
|
|
4116
|
+
const text = LEADING_OPERATORS.filter((op) => opts.sep.includes(op));
|
|
4117
|
+
if (text.length === 0) return;
|
|
4118
|
+
const ahead = ni.fork().skip(opts.skip);
|
|
4119
|
+
if (!ahead.satisfies({
|
|
4120
|
+
node: "punctuation",
|
|
4121
|
+
text
|
|
4122
|
+
})) return;
|
|
4123
|
+
const member = ahead.next(opts.skip).$;
|
|
4124
|
+
if (member && member.type !== "punctuation") {
|
|
4125
|
+
ni.unfork(ahead);
|
|
4126
|
+
ni.accepted();
|
|
4127
|
+
ni.move();
|
|
4128
|
+
ni.skip(opts.skip);
|
|
4129
|
+
}
|
|
4130
|
+
}
|
|
4085
4131
|
function unwrap(attr) {
|
|
4086
4132
|
const opts = { pipes: [] };
|
|
4087
4133
|
return {
|
|
@@ -9694,17 +9740,13 @@ var AtscriptDoc = class AtscriptDoc {
|
|
|
9694
9740
|
return messages;
|
|
9695
9741
|
}
|
|
9696
9742
|
/**
|
|
9697
|
-
* Errors for references to a type another document does not export, in definitions inlined
|
|
9698
|
-
* from that document (`extends`, an intersection member, `annotate … as …`): the generated
|
|
9699
|
-
* code of this document would have to import it from there. Checks what codegen emits (see
|
|
9700
|
-
* {@link emittedRefs}).
|
|
9701
|
-
*/ /**
|
|
9702
9743
|
* Warnings for the mutating `annotate` blocks of this document whose target another document
|
|
9703
9744
|
* declares, when the block is not reachable: the declaring document does not import this one
|
|
9704
9745
|
* (directly or not), and a document using the target does not either. A block is part of its
|
|
9705
9746
|
* target's definition, built into whatever uses the target in the same build — a build of a
|
|
9706
9747
|
* document using it without this one (another entry, the target's package built on its own)
|
|
9707
|
-
* would not have it.
|
|
9748
|
+
* would not have it. When the target and documents using it belong to another package (see
|
|
9749
|
+
* `packageOfFile`), those documents cannot import this one: they get a warning of their own.
|
|
9708
9750
|
*/ unreachableBlockMessages() {
|
|
9709
9751
|
const messages = [];
|
|
9710
9752
|
const known = /* @__PURE__ */ new Map();
|
|
@@ -9716,21 +9758,54 @@ var AtscriptDoc = class AtscriptDoc {
|
|
|
9716
9758
|
}
|
|
9717
9759
|
return hit;
|
|
9718
9760
|
};
|
|
9761
|
+
let own;
|
|
9762
|
+
let ownFound = false;
|
|
9763
|
+
const places = /* @__PURE__ */ new Map();
|
|
9764
|
+
const placeOf = (d) => {
|
|
9765
|
+
let place = places.get(d);
|
|
9766
|
+
if (!place) {
|
|
9767
|
+
if (!ownFound) {
|
|
9768
|
+
own = packageOfDoc(this);
|
|
9769
|
+
ownFound = true;
|
|
9770
|
+
}
|
|
9771
|
+
const pkg = this.id.startsWith("file://") ? packageOfDoc(d) : void 0;
|
|
9772
|
+
place = pkg && pkg.dir !== own?.dir ? {
|
|
9773
|
+
other: true,
|
|
9774
|
+
path: `${pkg.name}/${pkg.path}`
|
|
9775
|
+
} : {
|
|
9776
|
+
other: false,
|
|
9777
|
+
path: relDocPath(this.id, d.id)
|
|
9778
|
+
};
|
|
9779
|
+
places.set(d, place);
|
|
9780
|
+
}
|
|
9781
|
+
return place;
|
|
9782
|
+
};
|
|
9719
9783
|
for (const node of this.nodes) {
|
|
9720
9784
|
if (!isAnnotate(node) || !node.isMutating) continue;
|
|
9721
9785
|
const owner = this.blockTarget(node);
|
|
9722
9786
|
const target = owner?.doc;
|
|
9723
9787
|
if (!target || !owner.node || target === this || importsThis(target)) continue;
|
|
9724
9788
|
const missing = [...target.documentsUsing(owner.node)].filter((d) => d !== this && !importsThis(d));
|
|
9725
|
-
if (missing.length
|
|
9726
|
-
|
|
9727
|
-
|
|
9789
|
+
if (missing.length === 0) continue;
|
|
9790
|
+
const range = node.token("target").range;
|
|
9791
|
+
const name = owner.node.id;
|
|
9792
|
+
const declared = placeOf(target);
|
|
9793
|
+
const users = missing.map(placeOf);
|
|
9794
|
+
const local = users.filter((u) => !(declared.other && u.other));
|
|
9795
|
+
const other = users.filter((u) => declared.other && u.other);
|
|
9796
|
+
if (local.length > 0) {
|
|
9797
|
+
const from = declared.other ? "" : `${declared.path} or from `;
|
|
9728
9798
|
messages.push({
|
|
9729
9799
|
severity: 2,
|
|
9730
|
-
message: `"${
|
|
9731
|
-
range
|
|
9800
|
+
message: `"${name}" (declared in ${declared.path}) is used by ${pathList(local)} without importing this file (directly or not): this annotate applies only in builds including this file — import it from ${from}the files using "${name}"`,
|
|
9801
|
+
range
|
|
9732
9802
|
});
|
|
9733
9803
|
}
|
|
9804
|
+
if (other.length > 0) messages.push({
|
|
9805
|
+
severity: 2,
|
|
9806
|
+
message: `"${name}" (declared in ${declared.path}) is used by files of other packages (${pathList(other)}), which cannot import this file: their packages' own builds never include this annotate, and at runtime it applies to those files only if this file is loaded before they first use "${name}" — to change only your own types, annotate a type of your own (interface X extends ${name}, or annotate ${name} as X)`,
|
|
9807
|
+
range
|
|
9808
|
+
});
|
|
9734
9809
|
}
|
|
9735
9810
|
return messages;
|
|
9736
9811
|
}
|
|
@@ -10426,6 +10501,12 @@ const zeroRange = {
|
|
|
10426
10501
|
for (const part of chain) ref.addChain(token(part));
|
|
10427
10502
|
return ref;
|
|
10428
10503
|
}
|
|
10504
|
+
/** The `path`s of `items`, sorted, comma-separated. */ function pathList(items) {
|
|
10505
|
+
return items.map((u) => u.path).sort().join(", ");
|
|
10506
|
+
}
|
|
10507
|
+
/** The package of file document `doc` (see `packageOfFile`); `undefined` for any other document. */ function packageOfDoc(doc) {
|
|
10508
|
+
return doc.id.startsWith("file://") ? packageOfFile(fileUriToPath(doc.id)) : void 0;
|
|
10509
|
+
}
|
|
10429
10510
|
/** `to`'s path relative to `from` (`./b.as`), or its id when not a file. */ function relDocPath(from, to) {
|
|
10430
10511
|
try {
|
|
10431
10512
|
return `${getRelPath(from, to)}.as`;
|