@cjser/jsdoc-type-pratt-parser 9.1.2-cjser.2 → 9.2.1-cjser.2
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.d.mts +2 -1
- package/dist/index.mjs +34 -30
- package/dist-cjser/index.cjs +22 -18
- package/package.json +14 -11
package/dist/index.d.mts
CHANGED
|
@@ -486,11 +486,12 @@ declare function parse(expression: string, mode: ParseMode, { range, rangeStart,
|
|
|
486
486
|
* @param expression
|
|
487
487
|
* @param modes
|
|
488
488
|
*/
|
|
489
|
-
declare function tryParse(expression: string, modes?: ParseMode[], { module, strictMode, asyncFunctionBody, classContext, range, rangeStart, loc, locStart }?: {
|
|
489
|
+
declare function tryParse(expression: string, modes?: ParseMode[], { module, strictMode, asyncFunctionBody, classContext, computedPropertyParser, range, rangeStart, loc, locStart }?: {
|
|
490
490
|
module?: boolean;
|
|
491
491
|
strictMode?: boolean;
|
|
492
492
|
asyncFunctionBody?: boolean;
|
|
493
493
|
classContext?: boolean;
|
|
494
|
+
computedPropertyParser?: (text: string, options?: any) => unknown;
|
|
494
495
|
range?: boolean;
|
|
495
496
|
rangeStart?: number;
|
|
496
497
|
loc?: boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -897,11 +897,13 @@ function createObjectParslet({ signatureGrammar, objectFieldGrammar, allowKeyTyp
|
|
|
897
897
|
if (parser.lexer.current.startOfLine) {
|
|
898
898
|
separator ??= "linebreak";
|
|
899
899
|
parser.consume(",") || parser.consume(";");
|
|
900
|
-
} else if (parser.consume(","))
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
else
|
|
904
|
-
|
|
900
|
+
} else if (parser.consume(",")) {
|
|
901
|
+
if (parser.lexer.current.startOfLine) separator = "comma-and-linebreak";
|
|
902
|
+
else separator = "comma";
|
|
903
|
+
} else if (parser.consume(";")) {
|
|
904
|
+
if (parser.lexer.current.startOfLine) separator = "semicolon-and-linebreak";
|
|
905
|
+
else separator = "semicolon";
|
|
906
|
+
} else break;
|
|
905
907
|
if (parser.lexer.current.type === "}") break;
|
|
906
908
|
}
|
|
907
909
|
result.meta.separator = separator ?? "comma";
|
|
@@ -1282,9 +1284,10 @@ function createTupleParslet({ allowQuestionMark }) {
|
|
|
1282
1284
|
};
|
|
1283
1285
|
if (parser.consume("]")) return result;
|
|
1284
1286
|
const typeList = parser.parseIntermediateType(0);
|
|
1285
|
-
if (typeList.type === "JsdocTypeParameterList")
|
|
1286
|
-
|
|
1287
|
-
|
|
1287
|
+
if (typeList.type === "JsdocTypeParameterList") {
|
|
1288
|
+
if (typeList.elements[0].type === "JsdocTypeKeyValue") result.elements = typeList.elements.map(assertPlainKeyValueResult);
|
|
1289
|
+
else result.elements = typeList.elements.map(assertRootResult);
|
|
1290
|
+
} else if (typeList.type === "JsdocTypeKeyValue") result.elements = [assertPlainKeyValueResult(typeList)];
|
|
1288
1291
|
else result.elements = [assertRootResult(typeList)];
|
|
1289
1292
|
if (!parser.consume("]")) throw new Error("Unterminated '['");
|
|
1290
1293
|
if (!allowQuestionMark && result.elements.some((e) => e.type === "JsdocTypeUnknown")) throw new Error("Question mark in tuple not allowed");
|
|
@@ -1313,9 +1316,8 @@ const inferParslet = composeParslet({
|
|
|
1313
1316
|
parsePrefix: (parser) => {
|
|
1314
1317
|
parser.consume("infer");
|
|
1315
1318
|
const element = parser.parseIntermediateType(12);
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
throw new UnexpectedTypeError(element, "A typescript infer always has to have a name.");
|
|
1319
|
+
/* c8 ignore next 3 -- c8 does not mark the exercised throw as covered */
|
|
1320
|
+
if (element.type !== "JsdocTypeName") throw new UnexpectedTypeError(element, "A typescript infer always has to have a name.");
|
|
1319
1321
|
return {
|
|
1320
1322
|
type: "JsdocTypeInfer",
|
|
1321
1323
|
element
|
|
@@ -2089,19 +2091,17 @@ function parse(expression, mode, { range = false, rangeStart, loc = false, locSt
|
|
|
2089
2091
|
locStart
|
|
2090
2092
|
});
|
|
2091
2093
|
break;
|
|
2092
|
-
case "typescript":
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
});
|
|
2104
|
-
break;
|
|
2094
|
+
case "typescript": parser = new Parser(typescriptGrammar, Lexer.create(rules, expression), void 0, {
|
|
2095
|
+
module,
|
|
2096
|
+
strictMode,
|
|
2097
|
+
asyncFunctionBody,
|
|
2098
|
+
classContext,
|
|
2099
|
+
range,
|
|
2100
|
+
rangeStart,
|
|
2101
|
+
loc,
|
|
2102
|
+
locStart,
|
|
2103
|
+
externalParsers: { computedPropertyParser }
|
|
2104
|
+
});
|
|
2105
2105
|
}
|
|
2106
2106
|
const result = parser.parse();
|
|
2107
2107
|
return assertResultIsNotReservedWord(parser, result);
|
|
@@ -2117,7 +2117,7 @@ function tryParse(expression, modes = [
|
|
|
2117
2117
|
"typescript",
|
|
2118
2118
|
"closure",
|
|
2119
2119
|
"jsdoc"
|
|
2120
|
-
], { module = true, strictMode = true, asyncFunctionBody = true, classContext = false, range, rangeStart, loc = false, locStart = {
|
|
2120
|
+
], { module = true, strictMode = true, asyncFunctionBody = true, classContext = false, computedPropertyParser, range, rangeStart, loc = false, locStart = {
|
|
2121
2121
|
column: 0,
|
|
2122
2122
|
line: 1
|
|
2123
2123
|
} } = {}) {
|
|
@@ -2128,6 +2128,7 @@ function tryParse(expression, modes = [
|
|
|
2128
2128
|
strictMode,
|
|
2129
2129
|
asyncFunctionBody,
|
|
2130
2130
|
classContext,
|
|
2131
|
+
computedPropertyParser,
|
|
2131
2132
|
range,
|
|
2132
2133
|
rangeStart,
|
|
2133
2134
|
loc,
|
|
@@ -2174,10 +2175,11 @@ function notAvailableTransform(parseResult) {
|
|
|
2174
2175
|
}
|
|
2175
2176
|
function extractSpecialParams(source) {
|
|
2176
2177
|
const result = { params: [] };
|
|
2177
|
-
for (const param of source.parameters) if (param.type === "JsdocTypeKeyValue")
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2178
|
+
for (const param of source.parameters) if (param.type === "JsdocTypeKeyValue") {
|
|
2179
|
+
if (param.key === "this") result.this = param.right;
|
|
2180
|
+
else if (param.key === "new") result.new = param.right;
|
|
2181
|
+
else result.params.push(param);
|
|
2182
|
+
} else result.params.push(param);
|
|
2181
2183
|
return result;
|
|
2182
2184
|
}
|
|
2183
2185
|
//#endregion
|
|
@@ -2275,7 +2277,9 @@ function stringifyRules({ computedPropertyStringifier } = {}) {
|
|
|
2275
2277
|
const separatorForSingleObjectField = result.meta.separatorForSingleObjectField ?? false;
|
|
2276
2278
|
const trailingPunctuation = result.meta.trailingPunctuation ?? false;
|
|
2277
2279
|
const bracketSpacing = result.meta.bracketSpacing ?? "";
|
|
2278
|
-
return `{${
|
|
2280
|
+
return `{${
|
|
2281
|
+
/* c8 ignore next -- Guard */
|
|
2282
|
+
(lbType && (separatorForSingleObjectField || result.elements.length > 1) ? `\n${result.meta.propertyIndent ?? ""}` : bracketSpacing) + result.elements.map(transform).join(result.meta.separator === "comma" ? ", " : lbType ? lbEnding + (result.meta.propertyIndent ?? "") : "; ") + (separatorForSingleObjectField && result.elements.length === 1 ? result.meta.separator === "comma" ? "," : lbType ? lbEnding : ";" : trailingPunctuation && result.meta.separator !== void 0 ? result.meta.separator.startsWith("comma") ? "," : result.meta.separator.startsWith("semicolon") ? ";" : "" : "") + (lbType && result.elements.length > 1 ? "\n" : bracketSpacing)}}`;
|
|
2279
2283
|
},
|
|
2280
2284
|
JsdocTypeOptional: (result, transform) => applyPosition(result.meta.position, transform(result.element), "="),
|
|
2281
2285
|
JsdocTypeSymbol: (result, transform) => `${result.value}(${result.element !== void 0 ? transform(result.element) : ""})`,
|
package/dist-cjser/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// packages/@cjser/jsdoc-type-pratt-parser.tmp-
|
|
19
|
+
// packages/@cjser/jsdoc-type-pratt-parser.tmp-25-1788281970041/dist/index.mjs
|
|
20
20
|
var index_exports = {};
|
|
21
21
|
__export(index_exports, {
|
|
22
22
|
catharsisTransform: () => catharsisTransform,
|
|
@@ -880,11 +880,13 @@ function createObjectParslet({ signatureGrammar, objectFieldGrammar: objectField
|
|
|
880
880
|
if (parser.lexer.current.startOfLine) {
|
|
881
881
|
separator ??= "linebreak";
|
|
882
882
|
parser.consume(",") || parser.consume(";");
|
|
883
|
-
} else if (parser.consume(","))
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
else
|
|
887
|
-
|
|
883
|
+
} else if (parser.consume(",")) {
|
|
884
|
+
if (parser.lexer.current.startOfLine) separator = "comma-and-linebreak";
|
|
885
|
+
else separator = "comma";
|
|
886
|
+
} else if (parser.consume(";")) {
|
|
887
|
+
if (parser.lexer.current.startOfLine) separator = "semicolon-and-linebreak";
|
|
888
|
+
else separator = "semicolon";
|
|
889
|
+
} else break;
|
|
888
890
|
if (parser.lexer.current.type === "}") break;
|
|
889
891
|
}
|
|
890
892
|
result.meta.separator = separator ?? "comma";
|
|
@@ -1246,9 +1248,10 @@ function createTupleParslet({ allowQuestionMark }) {
|
|
|
1246
1248
|
};
|
|
1247
1249
|
if (parser.consume("]")) return result;
|
|
1248
1250
|
const typeList = parser.parseIntermediateType(0);
|
|
1249
|
-
if (typeList.type === "JsdocTypeParameterList")
|
|
1250
|
-
|
|
1251
|
-
|
|
1251
|
+
if (typeList.type === "JsdocTypeParameterList") {
|
|
1252
|
+
if (typeList.elements[0].type === "JsdocTypeKeyValue") result.elements = typeList.elements.map(assertPlainKeyValueResult);
|
|
1253
|
+
else result.elements = typeList.elements.map(assertRootResult);
|
|
1254
|
+
} else if (typeList.type === "JsdocTypeKeyValue") result.elements = [assertPlainKeyValueResult(typeList)];
|
|
1252
1255
|
else result.elements = [assertRootResult(typeList)];
|
|
1253
1256
|
if (!parser.consume("]")) throw new Error("Unterminated '['");
|
|
1254
1257
|
if (!allowQuestionMark && result.elements.some((e) => e.type === "JsdocTypeUnknown")) throw new Error("Question mark in tuple not allowed");
|
|
@@ -1273,8 +1276,7 @@ var inferParslet = composeParslet({
|
|
|
1273
1276
|
parsePrefix: (parser) => {
|
|
1274
1277
|
parser.consume("infer");
|
|
1275
1278
|
const element = parser.parseIntermediateType(12);
|
|
1276
|
-
if (element.type !== "JsdocTypeName")
|
|
1277
|
-
throw new UnexpectedTypeError(element, "A typescript infer always has to have a name.");
|
|
1279
|
+
if (element.type !== "JsdocTypeName") throw new UnexpectedTypeError(element, "A typescript infer always has to have a name.");
|
|
1278
1280
|
return {
|
|
1279
1281
|
type: "JsdocTypeInfer",
|
|
1280
1282
|
element
|
|
@@ -2022,7 +2024,6 @@ function parse(expression, mode, { range = false, rangeStart, loc = false, locSt
|
|
|
2022
2024
|
locStart,
|
|
2023
2025
|
externalParsers: { computedPropertyParser }
|
|
2024
2026
|
});
|
|
2025
|
-
break;
|
|
2026
2027
|
}
|
|
2027
2028
|
const result = parser.parse();
|
|
2028
2029
|
return assertResultIsNotReservedWord(parser, result);
|
|
@@ -2031,7 +2032,7 @@ function tryParse(expression, modes = [
|
|
|
2031
2032
|
"typescript",
|
|
2032
2033
|
"closure",
|
|
2033
2034
|
"jsdoc"
|
|
2034
|
-
], { module: module2 = true, strictMode = true, asyncFunctionBody = true, classContext = false, range, rangeStart, loc = false, locStart = {
|
|
2035
|
+
], { module: module2 = true, strictMode = true, asyncFunctionBody = true, classContext = false, computedPropertyParser, range, rangeStart, loc = false, locStart = {
|
|
2035
2036
|
column: 0,
|
|
2036
2037
|
line: 1
|
|
2037
2038
|
} } = {}) {
|
|
@@ -2042,6 +2043,7 @@ function tryParse(expression, modes = [
|
|
|
2042
2043
|
strictMode,
|
|
2043
2044
|
asyncFunctionBody,
|
|
2044
2045
|
classContext,
|
|
2046
|
+
computedPropertyParser,
|
|
2045
2047
|
range,
|
|
2046
2048
|
rangeStart,
|
|
2047
2049
|
loc,
|
|
@@ -2082,10 +2084,11 @@ function notAvailableTransform(parseResult) {
|
|
|
2082
2084
|
}
|
|
2083
2085
|
function extractSpecialParams(source) {
|
|
2084
2086
|
const result = { params: [] };
|
|
2085
|
-
for (const param of source.parameters) if (param.type === "JsdocTypeKeyValue")
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2087
|
+
for (const param of source.parameters) if (param.type === "JsdocTypeKeyValue") {
|
|
2088
|
+
if (param.key === "this") result.this = param.right;
|
|
2089
|
+
else if (param.key === "new") result.new = param.right;
|
|
2090
|
+
else result.params.push(param);
|
|
2091
|
+
} else result.params.push(param);
|
|
2089
2092
|
return result;
|
|
2090
2093
|
}
|
|
2091
2094
|
function applyPosition(position, target, value) {
|
|
@@ -2192,7 +2195,8 @@ function stringifyRules({ computedPropertyStringifier } = {}) {
|
|
|
2192
2195
|
const separatorForSingleObjectField = result.meta.separatorForSingleObjectField ?? false;
|
|
2193
2196
|
const trailingPunctuation = result.meta.trailingPunctuation ?? false;
|
|
2194
2197
|
const bracketSpacing = result.meta.bracketSpacing ?? "";
|
|
2195
|
-
return `{${
|
|
2198
|
+
return `{${/* c8 ignore next -- Guard */
|
|
2199
|
+
(lbType && (separatorForSingleObjectField || result.elements.length > 1) ? `
|
|
2196
2200
|
${result.meta.propertyIndent ?? ""}` : bracketSpacing) + result.elements.map(transform2).join(result.meta.separator === "comma" ? ", " : lbType ? lbEnding + (result.meta.propertyIndent ?? "") : "; ") + (separatorForSingleObjectField && result.elements.length === 1 ? result.meta.separator === "comma" ? "," : lbType ? lbEnding : ";" : trailingPunctuation && result.meta.separator !== void 0 ? result.meta.separator.startsWith("comma") ? "," : result.meta.separator.startsWith("semicolon") ? ";" : "" : "") + (lbType && result.elements.length > 1 ? "\n" : bracketSpacing)}}`;
|
|
2197
2201
|
},
|
|
2198
2202
|
JsdocTypeOptional: (result, transform2) => applyPosition(result.meta.position, transform2(result.element), "="),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cjser/jsdoc-type-pratt-parser",
|
|
3
|
-
"version": "9.1
|
|
3
|
+
"version": "9.2.1-cjser.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
"test": "test"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
|
-
"test": "npm run
|
|
18
|
+
"test": "npm run tsc && npm run lint && npm run test:spec",
|
|
19
19
|
"test:spec": "mocha",
|
|
20
20
|
"test:coverage": "c8 --all npm run test:spec",
|
|
21
21
|
"test:coveralls": "c8 report --reporter=lcov && coveralls",
|
|
22
22
|
"lint": "eslint .",
|
|
23
|
-
"
|
|
23
|
+
"tsc": "tsc --noEmit",
|
|
24
|
+
"tsc:ts7": "npx -y -p typescript@^7 -c \"tsc\"",
|
|
24
25
|
"attw": "attw --pack . --profile esm-only",
|
|
25
26
|
"build": "tsdown && npm run attw",
|
|
26
27
|
"apidoc": "typedoc --options typedoc.json",
|
|
@@ -38,7 +39,8 @@
|
|
|
38
39
|
"node": "^22.22.2 || >=24.15.0"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@types/estree": "^1.0.9"
|
|
42
|
+
"@types/estree": "^1.0.9",
|
|
43
|
+
"@types/node": "^26.4.0"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
@@ -47,7 +49,6 @@
|
|
|
47
49
|
"@semantic-release/git": "^11.0.1",
|
|
48
50
|
"@types/chai": "^5.2.3",
|
|
49
51
|
"@types/mocha": "^10.0.10",
|
|
50
|
-
"@types/node": "^26.2.0",
|
|
51
52
|
"@types/sinon": "^22.0.0",
|
|
52
53
|
"@types/sinon-chai": "^4.0.0",
|
|
53
54
|
"@typescript-eslint/eslint-plugin": "^8.42.0",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"chai": "^6.2.2",
|
|
58
59
|
"coveralls": "^3.1.1",
|
|
59
60
|
"eslint": "^9.39.4",
|
|
60
|
-
"eslint-config-love": "
|
|
61
|
+
"eslint-config-love": "155.0.0",
|
|
61
62
|
"eslint-plugin-import": "^2.32.0",
|
|
62
63
|
"eslint-plugin-n": "^18.3.0",
|
|
63
64
|
"eslint-plugin-promise": "^7.3.0",
|
|
@@ -119,11 +120,11 @@
|
|
|
119
120
|
},
|
|
120
121
|
"main": "./dist-cjser/index.cjs",
|
|
121
122
|
"cjser": {
|
|
122
|
-
"sourceVersion": "9.1
|
|
123
|
+
"sourceVersion": "9.2.1",
|
|
123
124
|
"cjserVersion": 2,
|
|
124
125
|
"original": {
|
|
125
126
|
"name": "jsdoc-type-pratt-parser",
|
|
126
|
-
"version": "9.1
|
|
127
|
+
"version": "9.2.1",
|
|
127
128
|
"exports": {
|
|
128
129
|
".": "./dist/index.mjs",
|
|
129
130
|
"./package.json": "./package.json"
|
|
@@ -133,18 +134,20 @@
|
|
|
133
134
|
"url": "https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser.git"
|
|
134
135
|
},
|
|
135
136
|
"dependencies": {
|
|
136
|
-
"@types/estree": "^1.0.9"
|
|
137
|
+
"@types/estree": "^1.0.9",
|
|
138
|
+
"@types/node": "^26.4.0"
|
|
137
139
|
},
|
|
138
140
|
"files": [
|
|
139
141
|
"dist/**/*"
|
|
140
142
|
],
|
|
141
143
|
"scripts": {
|
|
142
|
-
"test": "npm run
|
|
144
|
+
"test": "npm run tsc && npm run lint && npm run test:spec",
|
|
143
145
|
"test:spec": "mocha",
|
|
144
146
|
"test:coverage": "c8 --all npm run test:spec",
|
|
145
147
|
"test:coveralls": "c8 report --reporter=lcov && coveralls",
|
|
146
148
|
"lint": "eslint .",
|
|
147
|
-
"
|
|
149
|
+
"tsc": "tsc --noEmit",
|
|
150
|
+
"tsc:ts7": "npx -y -p typescript@^7 -c \"tsc\"",
|
|
148
151
|
"attw": "attw --pack . --profile esm-only",
|
|
149
152
|
"build": "tsdown && npm run attw",
|
|
150
153
|
"apidoc": "typedoc --options typedoc.json",
|