@cjser/jsdoc-type-pratt-parser 9.1.1-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 -28
- package/dist-cjser/index.cjs +22 -17
- 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,6 +1316,7 @@ const inferParslet = composeParslet({
|
|
|
1313
1316
|
parsePrefix: (parser) => {
|
|
1314
1317
|
parser.consume("infer");
|
|
1315
1318
|
const element = parser.parseIntermediateType(12);
|
|
1319
|
+
/* c8 ignore next 3 -- c8 does not mark the exercised throw as covered */
|
|
1316
1320
|
if (element.type !== "JsdocTypeName") throw new UnexpectedTypeError(element, "A typescript infer always has to have a name.");
|
|
1317
1321
|
return {
|
|
1318
1322
|
type: "JsdocTypeInfer",
|
|
@@ -1670,7 +1674,7 @@ const conditionalParslet = composeParslet({
|
|
|
1670
1674
|
parser.consume("extends");
|
|
1671
1675
|
const extendsType = assertRootResult(parser.parseType(13));
|
|
1672
1676
|
parser.consume("?");
|
|
1673
|
-
const trueType = parser.parseType(
|
|
1677
|
+
const trueType = parser.parseType(3);
|
|
1674
1678
|
parser.consume(":");
|
|
1675
1679
|
return {
|
|
1676
1680
|
type: "JsdocTypeConditional",
|
|
@@ -2087,19 +2091,17 @@ function parse(expression, mode, { range = false, rangeStart, loc = false, locSt
|
|
|
2087
2091
|
locStart
|
|
2088
2092
|
});
|
|
2089
2093
|
break;
|
|
2090
|
-
case "typescript":
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
});
|
|
2102
|
-
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
|
+
});
|
|
2103
2105
|
}
|
|
2104
2106
|
const result = parser.parse();
|
|
2105
2107
|
return assertResultIsNotReservedWord(parser, result);
|
|
@@ -2115,7 +2117,7 @@ function tryParse(expression, modes = [
|
|
|
2115
2117
|
"typescript",
|
|
2116
2118
|
"closure",
|
|
2117
2119
|
"jsdoc"
|
|
2118
|
-
], { 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 = {
|
|
2119
2121
|
column: 0,
|
|
2120
2122
|
line: 1
|
|
2121
2123
|
} } = {}) {
|
|
@@ -2126,6 +2128,7 @@ function tryParse(expression, modes = [
|
|
|
2126
2128
|
strictMode,
|
|
2127
2129
|
asyncFunctionBody,
|
|
2128
2130
|
classContext,
|
|
2131
|
+
computedPropertyParser,
|
|
2129
2132
|
range,
|
|
2130
2133
|
rangeStart,
|
|
2131
2134
|
loc,
|
|
@@ -2172,10 +2175,11 @@ function notAvailableTransform(parseResult) {
|
|
|
2172
2175
|
}
|
|
2173
2176
|
function extractSpecialParams(source) {
|
|
2174
2177
|
const result = { params: [] };
|
|
2175
|
-
for (const param of source.parameters) if (param.type === "JsdocTypeKeyValue")
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
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);
|
|
2179
2183
|
return result;
|
|
2180
2184
|
}
|
|
2181
2185
|
//#endregion
|
|
@@ -2273,7 +2277,9 @@ function stringifyRules({ computedPropertyStringifier } = {}) {
|
|
|
2273
2277
|
const separatorForSingleObjectField = result.meta.separatorForSingleObjectField ?? false;
|
|
2274
2278
|
const trailingPunctuation = result.meta.trailingPunctuation ?? false;
|
|
2275
2279
|
const bracketSpacing = result.meta.bracketSpacing ?? "";
|
|
2276
|
-
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)}}`;
|
|
2277
2283
|
},
|
|
2278
2284
|
JsdocTypeOptional: (result, transform) => applyPosition(result.meta.position, transform(result.element), "="),
|
|
2279
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");
|
|
@@ -1613,7 +1616,7 @@ var conditionalParslet = composeParslet({
|
|
|
1613
1616
|
parser.consume("extends");
|
|
1614
1617
|
const extendsType = assertRootResult(parser.parseType(13));
|
|
1615
1618
|
parser.consume("?");
|
|
1616
|
-
const trueType = parser.parseType(
|
|
1619
|
+
const trueType = parser.parseType(3);
|
|
1617
1620
|
parser.consume(":");
|
|
1618
1621
|
return {
|
|
1619
1622
|
type: "JsdocTypeConditional",
|
|
@@ -2021,7 +2024,6 @@ function parse(expression, mode, { range = false, rangeStart, loc = false, locSt
|
|
|
2021
2024
|
locStart,
|
|
2022
2025
|
externalParsers: { computedPropertyParser }
|
|
2023
2026
|
});
|
|
2024
|
-
break;
|
|
2025
2027
|
}
|
|
2026
2028
|
const result = parser.parse();
|
|
2027
2029
|
return assertResultIsNotReservedWord(parser, result);
|
|
@@ -2030,7 +2032,7 @@ function tryParse(expression, modes = [
|
|
|
2030
2032
|
"typescript",
|
|
2031
2033
|
"closure",
|
|
2032
2034
|
"jsdoc"
|
|
2033
|
-
], { 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 = {
|
|
2034
2036
|
column: 0,
|
|
2035
2037
|
line: 1
|
|
2036
2038
|
} } = {}) {
|
|
@@ -2041,6 +2043,7 @@ function tryParse(expression, modes = [
|
|
|
2041
2043
|
strictMode,
|
|
2042
2044
|
asyncFunctionBody,
|
|
2043
2045
|
classContext,
|
|
2046
|
+
computedPropertyParser,
|
|
2044
2047
|
range,
|
|
2045
2048
|
rangeStart,
|
|
2046
2049
|
loc,
|
|
@@ -2081,10 +2084,11 @@ function notAvailableTransform(parseResult) {
|
|
|
2081
2084
|
}
|
|
2082
2085
|
function extractSpecialParams(source) {
|
|
2083
2086
|
const result = { params: [] };
|
|
2084
|
-
for (const param of source.parameters) if (param.type === "JsdocTypeKeyValue")
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
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);
|
|
2088
2092
|
return result;
|
|
2089
2093
|
}
|
|
2090
2094
|
function applyPosition(position, target, value) {
|
|
@@ -2191,7 +2195,8 @@ function stringifyRules({ computedPropertyStringifier } = {}) {
|
|
|
2191
2195
|
const separatorForSingleObjectField = result.meta.separatorForSingleObjectField ?? false;
|
|
2192
2196
|
const trailingPunctuation = result.meta.trailingPunctuation ?? false;
|
|
2193
2197
|
const bracketSpacing = result.meta.bracketSpacing ?? "";
|
|
2194
|
-
return `{${
|
|
2198
|
+
return `{${/* c8 ignore next -- Guard */
|
|
2199
|
+
(lbType && (separatorForSingleObjectField || result.elements.length > 1) ? `
|
|
2195
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)}}`;
|
|
2196
2201
|
},
|
|
2197
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.
|
|
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.
|
|
123
|
+
"sourceVersion": "9.2.1",
|
|
123
124
|
"cjserVersion": 2,
|
|
124
125
|
"original": {
|
|
125
126
|
"name": "jsdoc-type-pratt-parser",
|
|
126
|
-
"version": "9.
|
|
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",
|