jsii 5.9.29-dev.0 → 5.9.29
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/README.md +53 -2
- package/lib/assembler.js +0 -4
- package/lib/assembler.js.map +1 -1
- package/lib/compiler.js +4 -1
- package/lib/compiler.js.map +1 -1
- package/lib/directives.d.ts +2 -0
- package/lib/directives.js +13 -1
- package/lib/directives.js.map +1 -1
- package/lib/jsii-diagnostic.d.ts +8 -0
- package/lib/jsii-diagnostic.js +17 -0
- package/lib/jsii-diagnostic.js.map +1 -1
- package/lib/literate.js +1 -1
- package/lib/literate.js.map +1 -1
- package/lib/main.js +6 -5
- package/lib/main.js.map +1 -1
- package/lib/utils.d.ts +4 -0
- package/lib/utils.js +42 -4
- package/lib/utils.js.map +1 -1
- package/lib/validator.js +19 -13
- package/lib/validator.js.map +1 -1
- package/lib/version.d.ts +2 -2
- package/lib/version.js +2 -2
- package/lib/version.js.map +1 -1
- package/lib/warnings.d.ts +16 -5
- package/lib/warnings.js +86 -6
- package/lib/warnings.js.map +1 -1
- package/package.json +1 -1
package/lib/warnings.js
CHANGED
|
@@ -1,11 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.silencedWarnings = void 0;
|
|
4
|
+
exports.parseWarningCodes = parseWarningCodes;
|
|
5
|
+
exports.isSilenced = isSilenced;
|
|
6
|
+
const ts = require("typescript");
|
|
7
|
+
const directives_1 = require("./directives");
|
|
8
|
+
const jsii_diagnostic_1 = require("./jsii-diagnostic");
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
6
|
-
* enabled, and can be silenced through the --silence-warning option.
|
|
10
|
+
* Set of silenced warning codes (numeric JSII codes).
|
|
7
11
|
*/
|
|
8
|
-
exports.
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
exports.silencedWarnings = new Set();
|
|
13
|
+
/**
|
|
14
|
+
* Parse a user-provided warning identifier into numeric JSII codes.
|
|
15
|
+
* Accepts: "JSII5019", "5019", or a diagnostic name / partial name.
|
|
16
|
+
*
|
|
17
|
+
* A name containing `/` must match a full diagnostic name exactly.
|
|
18
|
+
* A name without `/` matches any diagnostic whose category or specific
|
|
19
|
+
* name equals the input (e.g. "reserved-word" or "language-compatibility").
|
|
20
|
+
*/
|
|
21
|
+
function parseWarningCodes(input) {
|
|
22
|
+
// JSII<number> format
|
|
23
|
+
const jsiiMatch = /^JSII(\d+)$/i.exec(input);
|
|
24
|
+
if (jsiiMatch) {
|
|
25
|
+
return [parseInt(jsiiMatch[1], 10)];
|
|
26
|
+
}
|
|
27
|
+
// Plain number
|
|
28
|
+
const num = parseInt(input, 10);
|
|
29
|
+
if (String(num) === input) {
|
|
30
|
+
return [num];
|
|
31
|
+
}
|
|
32
|
+
// Name-based lookup
|
|
33
|
+
const matches = jsii_diagnostic_1.Code.lookupByPartialName(input);
|
|
34
|
+
if (matches.length > 0) {
|
|
35
|
+
return matches.map((c) => c.code);
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Unknown warning "${input}". Expected a JSII code (e.g. JSII5018), a number (e.g. 5018), or a diagnostic name (e.g. reserved-word, language-compatibility/reserved-word, language-compatibility).`);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if a diagnostic is a silenced warning (globally or inline).
|
|
41
|
+
*/
|
|
42
|
+
function isSilenced(diagnostic) {
|
|
43
|
+
if (diagnostic.category !== ts.DiagnosticCategory.Warning) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (!jsii_diagnostic_1.JsiiDiagnostic.isJsiiDiagnostic(diagnostic)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (exports.silencedWarnings.has(diagnostic.jsiiCode)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return isInlineSuppressed(diagnostic);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Check if a diagnostic is suppressed inline via a `@jsii suppress` directive.
|
|
56
|
+
*
|
|
57
|
+
* Diagnostics reference a source position (typically the name identifier of a
|
|
58
|
+
* declaration), but JSDoc tags are attached to the enclosing declaration node,
|
|
59
|
+
* not the identifier. We therefore start at the token at the diagnostic
|
|
60
|
+
* position and walk up the AST, checking each ancestor for `@jsii suppress`
|
|
61
|
+
* directives. This means a directive on a class suppresses matching warnings
|
|
62
|
+
* on all its members.
|
|
63
|
+
*/
|
|
64
|
+
function isInlineSuppressed(diagnostic) {
|
|
65
|
+
if (diagnostic.file == null || diagnostic.start == null) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
// `getTokenAtPosition` is exported from the `typescript` module but is not
|
|
69
|
+
// included in the public type declarations. It has been stable since TS 2.0
|
|
70
|
+
// and is used extensively by the language service. We cast through `any` to
|
|
71
|
+
// access it. Internally it descends through `node.getChildren()` to find the
|
|
72
|
+
// deepest node at a given position.
|
|
73
|
+
const getTokenAtPosition = ts.getTokenAtPosition;
|
|
74
|
+
let current = getTokenAtPosition(diagnostic.file, diagnostic.start);
|
|
75
|
+
while (current) {
|
|
76
|
+
const directives = directives_1.Directives.of(current, () => { });
|
|
77
|
+
for (const code of directives.suppressions) {
|
|
78
|
+
try {
|
|
79
|
+
if (parseWarningCodes(code).includes(diagnostic.jsiiCode)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Unknown code — ignore
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
current = current.parent;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
11
91
|
//# sourceMappingURL=warnings.js.map
|
package/lib/warnings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"warnings.js","sourceRoot":"","sources":["../src/warnings.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"warnings.js","sourceRoot":"","sources":["../src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C,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,kBAAkB,CAAC,UAAU,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,kBAAkB,CAAC,UAA0B;IACpD,IAAI,UAAU,CAAC,IAAI,IAAI,IAAI,IAAI,UAAU,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;QACxD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2EAA2E;IAC3E,4EAA4E;IAC5E,4EAA4E;IAC5E,6EAA6E;IAC7E,oCAAoC;IACpC,MAAM,kBAAkB,GAAiD,EAAU,CAAC,kBAAkB,CAAC;IACvG,IAAI,OAAO,GAAwB,kBAAkB,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IACzF,OAAO,OAAO,EAAE,CAAC;QACf,MAAM,UAAU,GAAG,uBAAU,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACpD,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC;YAC3C,IAAI,CAAC;gBACH,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC1D,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,wBAAwB;YAC1B,CAAC;QACH,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAC3B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import * as ts from 'typescript';\n\nimport { Directives } from './directives';\nimport { Code, JsiiDiagnostic } from './jsii-diagnostic';\n\n/**\n * Set of silenced warning codes (numeric JSII codes).\n */\nexport const silencedWarnings = new Set<number>();\n\n/**\n * Parse a user-provided warning identifier into numeric JSII codes.\n * Accepts: \"JSII5019\", \"5019\", or a diagnostic name / partial name.\n *\n * A name containing `/` must match a full diagnostic name exactly.\n * A name without `/` matches any diagnostic whose category or specific\n * name equals the input (e.g. \"reserved-word\" or \"language-compatibility\").\n */\nexport function parseWarningCodes(input: string): number[] {\n // JSII<number> format\n const jsiiMatch = /^JSII(\\d+)$/i.exec(input);\n if (jsiiMatch) {\n return [parseInt(jsiiMatch[1], 10)];\n }\n\n // Plain number\n const num = parseInt(input, 10);\n if (String(num) === input) {\n return [num];\n }\n\n // Name-based lookup\n const matches = Code.lookupByPartialName(input);\n if (matches.length > 0) {\n return matches.map((c) => c.code);\n }\n\n throw new Error(\n `Unknown warning \"${input}\". Expected a JSII code (e.g. JSII5018), a number (e.g. 5018), or a diagnostic name (e.g. reserved-word, language-compatibility/reserved-word, language-compatibility).`,\n );\n}\n\n/**\n * Check if a diagnostic is a silenced warning (globally or inline).\n */\nexport function isSilenced(diagnostic: ts.Diagnostic): boolean {\n if (diagnostic.category !== ts.DiagnosticCategory.Warning) {\n return false;\n }\n if (!JsiiDiagnostic.isJsiiDiagnostic(diagnostic)) {\n return false;\n }\n if (silencedWarnings.has(diagnostic.jsiiCode)) {\n return true;\n }\n return isInlineSuppressed(diagnostic);\n}\n\n/**\n * Check if a diagnostic is suppressed inline via a `@jsii suppress` directive.\n *\n * Diagnostics reference a source position (typically the name identifier of a\n * declaration), but JSDoc tags are attached to the enclosing declaration node,\n * not the identifier. We therefore start at the token at the diagnostic\n * position and walk up the AST, checking each ancestor for `@jsii suppress`\n * directives. This means a directive on a class suppresses matching warnings\n * on all its members.\n */\nfunction isInlineSuppressed(diagnostic: JsiiDiagnostic): boolean {\n if (diagnostic.file == null || diagnostic.start == null) {\n return false;\n }\n\n // `getTokenAtPosition` is exported from the `typescript` module but is not\n // included in the public type declarations. It has been stable since TS 2.0\n // and is used extensively by the language service. We cast through `any` to\n // access it. Internally it descends through `node.getChildren()` to find the\n // deepest node at a given position.\n const getTokenAtPosition: (sf: ts.SourceFile, pos: number) => ts.Node = (ts as any).getTokenAtPosition;\n let current: ts.Node | undefined = getTokenAtPosition(diagnostic.file, diagnostic.start);\n while (current) {\n const directives = Directives.of(current, () => {});\n for (const code of directives.suppressions) {\n try {\n if (parseWarningCodes(code).includes(diagnostic.jsiiCode)) {\n return true;\n }\n } catch {\n // Unknown code — ignore\n }\n }\n current = current.parent;\n }\n return false;\n}\n"]}
|