jsii 6.0.22-dev.0 → 7.1.0-dev.1
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/lib/assembler.d.ts +254 -196
- package/lib/assembler.js +2105 -2327
- package/lib/assembler.js.map +1 -1
- package/lib/case.js.map +1 -1
- package/lib/common/find-utils.js.map +1 -1
- package/lib/common/index.d.ts +1 -1
- package/lib/common/index.js +2 -1
- package/lib/common/index.js.map +1 -1
- package/lib/common/symbol-id.d.ts +23 -4
- package/lib/common/symbol-id.js +13 -9
- package/lib/common/symbol-id.js.map +1 -1
- package/lib/compiler-host.d.ts +60 -0
- package/lib/compiler-host.js +201 -0
- package/lib/compiler-host.js.map +1 -0
- package/lib/compiler.d.ts +74 -62
- package/lib/compiler.js +332 -254
- package/lib/compiler.js.map +1 -1
- package/lib/diagnostic.d.ts +34 -0
- package/lib/diagnostic.js +141 -0
- package/lib/diagnostic.js.map +1 -0
- package/lib/emitter.d.ts +40 -10
- package/lib/emitter.js +188 -0
- package/lib/emitter.js.map +1 -1
- package/lib/helpers.d.ts +1 -1
- package/lib/helpers.js +2 -2
- package/lib/helpers.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/jsii-diagnostic.d.ts +27 -22
- package/lib/jsii-diagnostic.js +22 -38
- package/lib/jsii-diagnostic.js.map +1 -1
- package/lib/literate.js.map +1 -1
- package/lib/main.js +3 -2
- package/lib/main.js.map +1 -1
- package/lib/project-info.d.ts +23 -4
- package/lib/project-info.js +5 -5
- package/lib/project-info.js.map +1 -1
- package/lib/support-types.d.ts +2 -0
- package/lib/support-types.js +3 -0
- package/lib/support-types.js.map +1 -0
- package/lib/support.js.map +1 -1
- package/lib/tsconfig/compiler-options.d.ts +12 -46
- package/lib/tsconfig/compiler-options.js +45 -87
- package/lib/tsconfig/compiler-options.js.map +1 -1
- package/lib/tsconfig/index.d.ts +24 -5
- package/lib/tsconfig/index.js.map +1 -1
- package/lib/tsconfig/read.d.ts +15 -0
- package/lib/tsconfig/read.js +196 -0
- package/lib/tsconfig/read.js.map +1 -0
- package/lib/tsconfig/rule-set-format.js.map +1 -1
- package/lib/tsconfig/rulesets/configurable-options.js.map +1 -1
- package/lib/tsconfig/rulesets/deprecated-options.js.map +1 -1
- package/lib/tsconfig/rulesets/generated.public.js.map +1 -1
- package/lib/tsconfig/rulesets/incompatible-options.js.map +1 -1
- package/lib/tsconfig/rulesets/jsii-configured-options.js.map +1 -1
- package/lib/tsconfig/rulesets/minimal.public.js.map +1 -1
- package/lib/tsconfig/rulesets/strict-family-options.js.map +1 -1
- package/lib/tsconfig/rulesets/strict.public.js.map +1 -1
- package/lib/tsconfig/tsconfig-validator.js +2 -50
- package/lib/tsconfig/tsconfig-validator.js.map +1 -1
- package/lib/tsconfig/validator.js.map +1 -1
- package/lib/type-analysis.js.map +1 -1
- package/lib/type-reference.js.map +1 -1
- package/lib/type-visitor.js.map +1 -1
- package/lib/utils.d.ts +6 -6
- package/lib/utils.js +8 -13
- package/lib/utils.js.map +1 -1
- package/lib/version.d.ts +3 -3
- package/lib/version.js +4 -4
- package/lib/version.js.map +1 -1
- package/lib/warnings.d.ts +2 -2
- package/lib/warnings.js +3 -77
- package/lib/warnings.js.map +1 -1
- package/package.json +15 -11
- package/scripts/ts7-compare-jsii.mjs +101 -0
- package/lib/directives.d.ts +0 -24
- package/lib/directives.js +0 -139
- package/lib/directives.js.map +0 -1
- package/lib/docs.d.ts +0 -64
- package/lib/docs.js +0 -293
- package/lib/docs.js.map +0 -1
- package/lib/node-bindings.d.ts +0 -19
- package/lib/node-bindings.js +0 -49
- package/lib/node-bindings.js.map +0 -1
- package/lib/reserved-words.d.ts +0 -6
- package/lib/reserved-words.js +0 -258
- package/lib/reserved-words.js.map +0 -1
- package/lib/sets.d.ts +0 -16
- package/lib/sets.js +0 -41
- package/lib/sets.js.map +0 -1
- package/lib/transforms/deprecated-remover.d.ts +0 -44
- package/lib/transforms/deprecated-remover.js +0 -545
- package/lib/transforms/deprecated-remover.js.map +0 -1
- package/lib/transforms/deprecation-warnings.d.ts +0 -37
- package/lib/transforms/deprecation-warnings.js +0 -616
- package/lib/transforms/deprecation-warnings.js.map +0 -1
- package/lib/transforms/runtime-info.d.ts +0 -39
- package/lib/transforms/runtime-info.js +0 -128
- package/lib/transforms/runtime-info.js.map +0 -1
- package/lib/transforms/utils.d.ts +0 -11
- package/lib/transforms/utils.js +0 -31
- package/lib/transforms/utils.js.map +0 -1
- package/lib/type-tracker.d.ts +0 -13
- package/lib/type-tracker.js +0 -67
- package/lib/type-tracker.js.map +0 -1
- package/lib/validator.d.ts +0 -19
- package/lib/validator.js +0 -602
- package/lib/validator.js.map +0 -1
|
@@ -1,616 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.DeprecationWarningsInjector = exports.WARNINGSCODE_FILE_NAME = void 0;
|
|
37
|
-
const fs = __importStar(require("node:fs"));
|
|
38
|
-
const path = __importStar(require("node:path"));
|
|
39
|
-
const spec = __importStar(require("@jsii/spec"));
|
|
40
|
-
const ts = __importStar(require("typescript"));
|
|
41
|
-
const symbol_id_1 = require("../common/symbol-id");
|
|
42
|
-
exports.WARNINGSCODE_FILE_NAME = '.warnings.jsii.js';
|
|
43
|
-
const WARNING_FUNCTION_NAME = 'print';
|
|
44
|
-
const PARAMETER_NAME = 'p';
|
|
45
|
-
const FOR_LOOP_ITEM_NAME = 'o';
|
|
46
|
-
const NAMESPACE = 'jsiiDeprecationWarnings';
|
|
47
|
-
const VISITED_OBJECTS_SET_NAME = 'visitedObjects';
|
|
48
|
-
const DEPRECATION_ERROR = 'DeprecationError';
|
|
49
|
-
const GET_PROPERTY_DESCRIPTOR = 'getPropertyDescriptor';
|
|
50
|
-
const VALIDATORS_OBJ = 'VALIDATORS';
|
|
51
|
-
class DeprecationWarningsInjector {
|
|
52
|
-
typeChecker;
|
|
53
|
-
typeTracker;
|
|
54
|
-
transformers = {
|
|
55
|
-
before: [],
|
|
56
|
-
};
|
|
57
|
-
shouldRenderValidatorCache = {};
|
|
58
|
-
validatorCacheSeenSet = new Set();
|
|
59
|
-
constructor(typeChecker, typeTracker) {
|
|
60
|
-
this.typeChecker = typeChecker;
|
|
61
|
-
this.typeTracker = typeTracker;
|
|
62
|
-
}
|
|
63
|
-
process(assembly, projectInfo) {
|
|
64
|
-
const projectRoot = projectInfo.projectRoot;
|
|
65
|
-
const validationFunctions = [];
|
|
66
|
-
const types = assembly.types ?? {};
|
|
67
|
-
for (const type of Object.values(types)) {
|
|
68
|
-
const fnStatements = this.generateTypeValidation(type, assembly, projectInfo, types);
|
|
69
|
-
if (fnStatements.length === 0) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
const paramValue = ts.factory.createParameterDeclaration(undefined, undefined, PARAMETER_NAME);
|
|
73
|
-
const functionName = fnName(type.fqn);
|
|
74
|
-
const functionExpr = ts.factory.createFunctionExpression(undefined, undefined, ts.factory.createIdentifier(functionName), [], [paramValue], undefined, createFunctionBlock(fnStatements));
|
|
75
|
-
validationFunctions.push(ts.factory.createPropertyAssignment(functionName, functionExpr));
|
|
76
|
-
}
|
|
77
|
-
const fileStatements = [];
|
|
78
|
-
fileStatements.push(ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList([
|
|
79
|
-
ts.factory.createVariableDeclaration(VALIDATORS_OBJ, undefined, undefined, ts.factory.createObjectLiteralExpression(validationFunctions)),
|
|
80
|
-
], ts.NodeFlags.Const)));
|
|
81
|
-
this.transformers = {
|
|
82
|
-
before: [
|
|
83
|
-
(context) => {
|
|
84
|
-
const transformer = new Transformer(this.typeChecker, context, projectRoot, this.buildTypeIndex(assembly), assembly);
|
|
85
|
-
return transformer.transform.bind(transformer);
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
};
|
|
89
|
-
generateWarningsFile(projectRoot, fileStatements);
|
|
90
|
-
}
|
|
91
|
-
get customTransformers() {
|
|
92
|
-
return this.transformers;
|
|
93
|
-
}
|
|
94
|
-
buildTypeIndex(assembly) {
|
|
95
|
-
const result = new Map();
|
|
96
|
-
for (const type of Object.values(assembly.types ?? {})) {
|
|
97
|
-
const symbolId = type.symbolId;
|
|
98
|
-
if (symbolId) {
|
|
99
|
-
result.set(symbolId, type);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Whether the validator for the given type should be rendered
|
|
106
|
-
*
|
|
107
|
-
* A validator should be rendered if:
|
|
108
|
-
*
|
|
109
|
-
* - It contains any deprecated members (base case).
|
|
110
|
-
* - It references any other types whose validators should be rendered.
|
|
111
|
-
* - It inherits from other types whose validators should be rendered.
|
|
112
|
-
* - It references types that reference this type (recursive types).
|
|
113
|
-
* - It references types from another assembly.
|
|
114
|
-
*
|
|
115
|
-
* For the last one we technically return `true`, indicating that a validator
|
|
116
|
-
* *should* be rendered, but when we get to rendering no statements are
|
|
117
|
-
* actually produced and the validator function is never rendered. This was
|
|
118
|
-
* pre-existing behavior that I didn't change because introducing calls into
|
|
119
|
-
* other assemblies out of the blue introduces risk.
|
|
120
|
-
*/
|
|
121
|
-
shouldRenderValidator(type, assembly) {
|
|
122
|
-
if (this.shouldRenderValidatorCache[type.fqn] !== undefined) {
|
|
123
|
-
return this.shouldRenderValidatorCache[type.fqn];
|
|
124
|
-
}
|
|
125
|
-
if (this.validatorCacheSeenSet.has(type.fqn)) {
|
|
126
|
-
// To be safe we need to say this is true.
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
if (!type.fqn.startsWith(`${assembly.name}.`)) {
|
|
130
|
-
// Foreign type, always check
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
this.validatorCacheSeenSet.add(type.fqn);
|
|
134
|
-
this.shouldRenderValidatorCache[type.fqn] = calculate.call(this);
|
|
135
|
-
this.validatorCacheSeenSet.delete(type.fqn);
|
|
136
|
-
return this.shouldRenderValidatorCache[type.fqn];
|
|
137
|
-
function calculate() {
|
|
138
|
-
if (spec.isDeprecated(type)) {
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
if (spec.isEnumType(type)) {
|
|
142
|
-
return (type.members ?? []).some(spec.isDeprecated);
|
|
143
|
-
}
|
|
144
|
-
if (spec.isInterfaceType(type) && type.datatype) {
|
|
145
|
-
for (const prop of type.properties ?? []) {
|
|
146
|
-
if (spec.isDeprecated(prop)) {
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
const typesToInspect = spec.isCollectionTypeReference(prop.type)
|
|
150
|
-
? [prop.type.collection.elementtype]
|
|
151
|
-
: spec.isUnionTypeReference(prop.type)
|
|
152
|
-
? prop.type.union.types
|
|
153
|
-
: [prop.type];
|
|
154
|
-
for (const typeToInspect of typesToInspect) {
|
|
155
|
-
if (!spec.isNamedTypeReference(typeToInspect)) {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
// Is from a different assembly?
|
|
159
|
-
const typeObj = findType2(typeToInspect.fqn, assembly);
|
|
160
|
-
if (typeObj === 'other-assembly') {
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
if (this.shouldRenderValidator(typeObj, assembly)) {
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
for (const interfaceName of type.interfaces ?? []) {
|
|
169
|
-
const typeObj = findType2(interfaceName, assembly);
|
|
170
|
-
if (typeObj === 'other-assembly') {
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
|
-
if (this.shouldRenderValidator(typeObj, assembly)) {
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
generateTypeValidation(type, assembly, projectInfo, types) {
|
|
182
|
-
if (!this.shouldRenderValidator(type, assembly)) {
|
|
183
|
-
return [];
|
|
184
|
-
}
|
|
185
|
-
const statements = [];
|
|
186
|
-
let isEmpty = true;
|
|
187
|
-
// This will add the parameter to the set of visited objects, to prevent infinite recursion
|
|
188
|
-
statements.push(ts.factory.createExpressionStatement(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(VISITED_OBJECTS_SET_NAME), 'add'), undefined, [ts.factory.createIdentifier(PARAMETER_NAME)])));
|
|
189
|
-
const tryStatements = [];
|
|
190
|
-
if (spec.isDeprecated(type) && spec.isEnumType(type)) {
|
|
191
|
-
// The type is deprecated
|
|
192
|
-
tryStatements.push(createWarningFunctionCall(type.fqn, type.docs?.deprecated));
|
|
193
|
-
isEmpty = false;
|
|
194
|
-
}
|
|
195
|
-
if (spec.isEnumType(type) && type.locationInModule?.filename) {
|
|
196
|
-
// Check for deprecated enum members
|
|
197
|
-
//
|
|
198
|
-
// We need to compare to the value of the deprecated enum. We can do that in one of 2 ways:
|
|
199
|
-
//
|
|
200
|
-
// - Compare against `require('./actual-file').EnumType.SOME_ENUM_MEMBER`
|
|
201
|
-
// - Look up the enum member value and compare against `'some-enum-member'`.
|
|
202
|
-
//
|
|
203
|
-
// The first one introduces a circular dependency between this file and `actual-file.js`, so we
|
|
204
|
-
// will go with the second.
|
|
205
|
-
//
|
|
206
|
-
// One complication: two enum members can have the same value (shouldn't, but can!) where
|
|
207
|
-
// one symbolic name is deprecated but the other isn't. In that case we don't treat it as deprecated.
|
|
208
|
-
const memDecls = this.typeTracker.getEnumMembers(type.fqn);
|
|
209
|
-
const nonDeprecatedValues = new Set((type.members ?? [])
|
|
210
|
-
.filter((m) => !spec.isDeprecated(m))
|
|
211
|
-
.map((m) => this.typeChecker.getConstantValue(memDecls[m.name])));
|
|
212
|
-
const deprecatedMembers = (type.members ?? []).filter(spec.isDeprecated);
|
|
213
|
-
for (const member of deprecatedMembers) {
|
|
214
|
-
const constantValue = this.typeChecker.getConstantValue(memDecls[member.name]);
|
|
215
|
-
if (nonDeprecatedValues.has(constantValue)) {
|
|
216
|
-
// Collission with non-deprecated enum member
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
const condition = ts.factory.createBinaryExpression(ts.factory.createIdentifier(PARAMETER_NAME), ts.SyntaxKind.EqualsEqualsEqualsToken, typeof constantValue === 'string'
|
|
220
|
-
? ts.factory.createStringLiteral(constantValue)
|
|
221
|
-
: ts.factory.createNumericLiteral(constantValue));
|
|
222
|
-
tryStatements.push(createWarningFunctionCall(`${type.fqn}#${member.name}`, member.docs?.deprecated, condition));
|
|
223
|
-
isEmpty = false;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
else if (spec.isInterfaceType(type) && type.datatype) {
|
|
227
|
-
const { statementsByProp, excludedProps } = this.processInterfaceType(type, types, assembly, projectInfo, undefined, undefined);
|
|
228
|
-
for (const [name, statement] of statementsByProp.entries()) {
|
|
229
|
-
if (!excludedProps.has(name)) {
|
|
230
|
-
tryStatements.push(statement);
|
|
231
|
-
isEmpty = false;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
statements.push(ts.factory.createTryStatement(ts.factory.createBlock(tryStatements), undefined, ts.factory.createBlock([
|
|
236
|
-
ts.factory.createExpressionStatement(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(VISITED_OBJECTS_SET_NAME), 'delete'), undefined, [ts.factory.createIdentifier(PARAMETER_NAME)])),
|
|
237
|
-
])));
|
|
238
|
-
return isEmpty ? [] : statements;
|
|
239
|
-
}
|
|
240
|
-
processInterfaceType(type, types, assembly, projectInfo, statementsByProp = new Map(), excludedProps = new Set()) {
|
|
241
|
-
for (const prop of Object.values(type.properties ?? {})) {
|
|
242
|
-
const fqn = `${type.fqn}#${prop.name}`;
|
|
243
|
-
if (spec.isDeprecated(prop) || spec.isDeprecated(type)) {
|
|
244
|
-
// If the property individually is deprecated, or the entire type is deprecated
|
|
245
|
-
const deprecatedDocs = prop.docs?.deprecated ?? type.docs?.deprecated;
|
|
246
|
-
const statement = createWarningFunctionCall(fqn, deprecatedDocs, ts.factory.createBinaryExpression(ts.factory.createStringLiteral(prop.name), ts.SyntaxKind.InKeyword, ts.factory.createIdentifier(PARAMETER_NAME)), undefined);
|
|
247
|
-
statementsByProp.set(prop.name, statement);
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
/* If a prop is not deprecated, we don't want to generate a warning for it,
|
|
251
|
-
even if another property with the same name is deprecated in another
|
|
252
|
-
super-interface. */
|
|
253
|
-
excludedProps.add(prop.name);
|
|
254
|
-
}
|
|
255
|
-
if (spec.isNamedTypeReference(prop.type) && Object.keys(types).includes(prop.type.fqn)) {
|
|
256
|
-
if (this.shouldRenderValidator(types[prop.type.fqn], assembly)) {
|
|
257
|
-
const functionName = importedFunctionName(prop.type.fqn, assembly, projectInfo);
|
|
258
|
-
if (functionName) {
|
|
259
|
-
const statement = createTypeHandlerCall(functionName, `${PARAMETER_NAME}.${prop.name}`);
|
|
260
|
-
statementsByProp.set(`${prop.name}_`, statement);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
else if (spec.isCollectionTypeReference(prop.type) &&
|
|
265
|
-
spec.isNamedTypeReference(prop.type.collection.elementtype)) {
|
|
266
|
-
const functionName = importedFunctionName(prop.type.collection.elementtype.fqn, assembly, projectInfo);
|
|
267
|
-
if (functionName) {
|
|
268
|
-
const statement = createTypeHandlerCall(functionName, `${PARAMETER_NAME}.${prop.name}`, prop.type.collection.kind);
|
|
269
|
-
statementsByProp.set(`${prop.name}_`, statement);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
else if (spec.isUnionTypeReference(prop.type) &&
|
|
273
|
-
spec.isNamedTypeReference(prop.type.union.types[0]) &&
|
|
274
|
-
Object.keys(types).includes(prop.type.union.types[0].fqn)) {
|
|
275
|
-
const functionName = importedFunctionName(prop.type.union.types[0].fqn, assembly, projectInfo);
|
|
276
|
-
if (functionName) {
|
|
277
|
-
const statement = createTypeHandlerCall(functionName, `${PARAMETER_NAME}.${prop.name}`);
|
|
278
|
-
statementsByProp.set(`${prop.name}_`, statement);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
// We also generate calls to all the supertypes
|
|
283
|
-
for (const interfaceName of type.interfaces ?? []) {
|
|
284
|
-
const assemblies = projectInfo.dependencyClosure.concat(assembly);
|
|
285
|
-
const superType = findType(interfaceName, assemblies);
|
|
286
|
-
if (superType.type) {
|
|
287
|
-
this.processInterfaceType(superType.type, types, assembly, projectInfo, statementsByProp, excludedProps);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return { statementsByProp, excludedProps };
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
exports.DeprecationWarningsInjector = DeprecationWarningsInjector;
|
|
294
|
-
function fnName(fqn) {
|
|
295
|
-
return fqn.replace(/[^\w\d]/g, '_');
|
|
296
|
-
}
|
|
297
|
-
function createFunctionBlock(statements) {
|
|
298
|
-
if (statements.length > 0) {
|
|
299
|
-
const validation = ts.factory.createIfStatement(ts.factory.createBinaryExpression(ts.factory.createIdentifier(PARAMETER_NAME), ts.SyntaxKind.EqualsEqualsToken, ts.factory.createNull()), ts.factory.createReturnStatement());
|
|
300
|
-
return ts.factory.createBlock([validation, ...statements], true);
|
|
301
|
-
}
|
|
302
|
-
return ts.factory.createBlock([], true);
|
|
303
|
-
}
|
|
304
|
-
function createWarningFunctionCall(fqn, message = '', condition, includeNamespace = false) {
|
|
305
|
-
const functionName = includeNamespace ? `${NAMESPACE}.${WARNING_FUNCTION_NAME}` : WARNING_FUNCTION_NAME;
|
|
306
|
-
const mainStatement = ts.factory.createExpressionStatement(ts.factory.createCallExpression(ts.factory.createIdentifier(functionName), undefined, [
|
|
307
|
-
ts.factory.createStringLiteral(fqn),
|
|
308
|
-
ts.factory.createStringLiteral(message),
|
|
309
|
-
]));
|
|
310
|
-
return condition ? ts.factory.createIfStatement(condition, mainStatement) : mainStatement;
|
|
311
|
-
}
|
|
312
|
-
function generateWarningsFile(projectRoot, validatorStatements) {
|
|
313
|
-
const functionText = `function ${WARNING_FUNCTION_NAME}(name, deprecationMessage) {
|
|
314
|
-
if (ALREADY_WARNED.has(name)) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
ALREADY_WARNED.add(name);
|
|
318
|
-
|
|
319
|
-
const deprecated = process.env.JSII_DEPRECATED;
|
|
320
|
-
const deprecationMode = ['warn', 'fail', 'quiet'].includes(deprecated) ? deprecated : 'warn';
|
|
321
|
-
const message = \`\${name} is deprecated, and will be removed in the next major release.\\n \${deprecationMessage.trim()}\`;
|
|
322
|
-
switch (deprecationMode) {
|
|
323
|
-
case "fail":
|
|
324
|
-
throw new ${DEPRECATION_ERROR}(message);
|
|
325
|
-
case "warn":
|
|
326
|
-
console.warn("[WARNING]", message);
|
|
327
|
-
break;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
const ALREADY_WARNED = new Set();
|
|
332
|
-
|
|
333
|
-
function ${GET_PROPERTY_DESCRIPTOR}(obj, prop) {
|
|
334
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, prop);
|
|
335
|
-
if (descriptor) {
|
|
336
|
-
return descriptor;
|
|
337
|
-
}
|
|
338
|
-
const proto = Object.getPrototypeOf(obj);
|
|
339
|
-
const prototypeDescriptor = proto && getPropertyDescriptor(proto, prop);
|
|
340
|
-
if (prototypeDescriptor) {
|
|
341
|
-
return prototypeDescriptor;
|
|
342
|
-
}
|
|
343
|
-
return {};
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const ${VISITED_OBJECTS_SET_NAME} = new Set();
|
|
347
|
-
|
|
348
|
-
class ${DEPRECATION_ERROR} extends Error {
|
|
349
|
-
constructor(...args) {
|
|
350
|
-
super(...args);
|
|
351
|
-
Object.defineProperty(this, 'name', {
|
|
352
|
-
configurable: false,
|
|
353
|
-
enumerable: true,
|
|
354
|
-
value: '${DEPRECATION_ERROR}',
|
|
355
|
-
writable: false,
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
function nop() {
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
module.exports = new Proxy({}, {
|
|
364
|
-
get(target, prop, receiver) {
|
|
365
|
-
if (prop === '${WARNING_FUNCTION_NAME}') return ${WARNING_FUNCTION_NAME};
|
|
366
|
-
if (prop === '${GET_PROPERTY_DESCRIPTOR}') return ${GET_PROPERTY_DESCRIPTOR};
|
|
367
|
-
if (prop === '${DEPRECATION_ERROR}') return ${DEPRECATION_ERROR};
|
|
368
|
-
|
|
369
|
-
return ${VALIDATORS_OBJ}[prop] ?? nop;
|
|
370
|
-
},
|
|
371
|
-
});
|
|
372
|
-
`;
|
|
373
|
-
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
374
|
-
const resultFile = ts.createSourceFile(path.join(projectRoot, exports.WARNINGSCODE_FILE_NAME), functionText, ts.ScriptTarget.Latest, false, ts.ScriptKind.JS);
|
|
375
|
-
const declarations = validatorStatements.map((st) => printer.printNode(ts.EmitHint.Unspecified, st, resultFile));
|
|
376
|
-
const content = declarations.concat(printer.printFile(resultFile)).join('\n');
|
|
377
|
-
fs.writeFileSync(path.join(projectRoot, exports.WARNINGSCODE_FILE_NAME), content);
|
|
378
|
-
}
|
|
379
|
-
class Transformer {
|
|
380
|
-
typeChecker;
|
|
381
|
-
context;
|
|
382
|
-
projectRoot;
|
|
383
|
-
typeIndex;
|
|
384
|
-
assembly;
|
|
385
|
-
warningCallsWereInjected = false;
|
|
386
|
-
constructor(typeChecker, context, projectRoot, typeIndex, assembly) {
|
|
387
|
-
this.typeChecker = typeChecker;
|
|
388
|
-
this.context = context;
|
|
389
|
-
this.projectRoot = projectRoot;
|
|
390
|
-
this.typeIndex = typeIndex;
|
|
391
|
-
this.assembly = assembly;
|
|
392
|
-
}
|
|
393
|
-
transform(node) {
|
|
394
|
-
this.warningCallsWereInjected = false;
|
|
395
|
-
const result = this.visitEachChild(node);
|
|
396
|
-
if (ts.isSourceFile(result) && this.warningCallsWereInjected) {
|
|
397
|
-
const importDir = path.relative(path.dirname(result.fileName), this.projectRoot);
|
|
398
|
-
const importPath = importDir.startsWith('..')
|
|
399
|
-
? unixPath(path.join(importDir, exports.WARNINGSCODE_FILE_NAME))
|
|
400
|
-
: `./${exports.WARNINGSCODE_FILE_NAME}`;
|
|
401
|
-
return ts.factory.updateSourceFile(result, [
|
|
402
|
-
createRequireStatement(NAMESPACE, importPath),
|
|
403
|
-
...result.statements,
|
|
404
|
-
]);
|
|
405
|
-
}
|
|
406
|
-
return result;
|
|
407
|
-
}
|
|
408
|
-
visitEachChild(node) {
|
|
409
|
-
return ts.visitEachChild(node, this.visitor.bind(this), this.context);
|
|
410
|
-
}
|
|
411
|
-
visitor(node) {
|
|
412
|
-
if (ts.isMethodDeclaration(node) && node.body != null) {
|
|
413
|
-
const statements = this.getStatementsForDeclaration(node);
|
|
414
|
-
this.warningCallsWereInjected = this.warningCallsWereInjected || statements.length > 0;
|
|
415
|
-
return ts.factory.updateMethodDeclaration(node, node.modifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, ts.factory.updateBlock(node.body, [
|
|
416
|
-
...wrapWithRethrow(statements, ts.factory.createPropertyAccessExpression(ts.factory.createThis(), node.name.getText(node.getSourceFile()))),
|
|
417
|
-
...node.body.statements,
|
|
418
|
-
]));
|
|
419
|
-
}
|
|
420
|
-
else if (ts.isGetAccessorDeclaration(node) && node.body != null) {
|
|
421
|
-
const statements = this.getStatementsForDeclaration(node);
|
|
422
|
-
this.warningCallsWereInjected = this.warningCallsWereInjected || statements.length > 0;
|
|
423
|
-
return ts.factory.updateGetAccessorDeclaration(node, node.modifiers, node.name, node.parameters, node.type, ts.factory.updateBlock(node.body, [
|
|
424
|
-
...wrapWithRethrow(statements, ts.factory.createPropertyAccessExpression(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(NAMESPACE), GET_PROPERTY_DESCRIPTOR), undefined, [ts.factory.createThis(), ts.factory.createStringLiteral(node.name.getText(node.getSourceFile()))]), 'get')),
|
|
425
|
-
...node.body.statements,
|
|
426
|
-
]));
|
|
427
|
-
}
|
|
428
|
-
else if (ts.isSetAccessorDeclaration(node) && node.body != null) {
|
|
429
|
-
const statements = this.getStatementsForDeclaration(node);
|
|
430
|
-
this.warningCallsWereInjected = this.warningCallsWereInjected || statements.length > 0;
|
|
431
|
-
return ts.factory.updateSetAccessorDeclaration(node, node.modifiers, node.name, node.parameters, ts.factory.updateBlock(node.body, [
|
|
432
|
-
...wrapWithRethrow(statements, ts.factory.createPropertyAccessExpression(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(NAMESPACE), GET_PROPERTY_DESCRIPTOR), undefined, [ts.factory.createThis(), ts.factory.createStringLiteral(node.name.getText(node.getSourceFile()))]), 'set')),
|
|
433
|
-
...node.body.statements,
|
|
434
|
-
]));
|
|
435
|
-
}
|
|
436
|
-
else if (ts.isConstructorDeclaration(node) && node.body != null) {
|
|
437
|
-
const statements = this.getStatementsForDeclaration(node);
|
|
438
|
-
this.warningCallsWereInjected = this.warningCallsWereInjected || statements.length > 0;
|
|
439
|
-
return ts.factory.updateConstructorDeclaration(node, node.modifiers, node.parameters, ts.factory.updateBlock(node.body, insertStatements(node.body, wrapWithRethrow(statements, node.parent.name))));
|
|
440
|
-
}
|
|
441
|
-
return this.visitEachChild(node);
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* @param getOrSet for property accessors, determines which of the getter or
|
|
445
|
-
* setter should be used to get the caller function value.
|
|
446
|
-
*/
|
|
447
|
-
getStatementsForDeclaration(node) {
|
|
448
|
-
const klass = node.parent;
|
|
449
|
-
const classSymbolId = (0, symbol_id_1.symbolIdentifier)(this.typeChecker, this.typeChecker.getTypeAtLocation(klass).symbol);
|
|
450
|
-
if (classSymbolId && this.typeIndex.has(classSymbolId)) {
|
|
451
|
-
const classType = this.typeIndex.get(classSymbolId);
|
|
452
|
-
if (ts.isConstructorDeclaration(node)) {
|
|
453
|
-
const initializer = classType?.initializer;
|
|
454
|
-
if (initializer) {
|
|
455
|
-
return this.getStatements(classType, initializer);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
const methods = classType?.methods ?? [];
|
|
459
|
-
const method = methods.find((m) => m.name === node.name?.getText());
|
|
460
|
-
if (method) {
|
|
461
|
-
return this.getStatements(classType, method);
|
|
462
|
-
}
|
|
463
|
-
const properties = classType?.properties ?? [];
|
|
464
|
-
const property = properties.find((p) => p.name === node.name?.getText());
|
|
465
|
-
if (property) {
|
|
466
|
-
return createWarningStatementForElement(property, classType);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
return [];
|
|
470
|
-
}
|
|
471
|
-
getStatements(classType, method) {
|
|
472
|
-
const statements = createWarningStatementForElement(method, classType);
|
|
473
|
-
for (const parameter of Object.values(method.parameters ?? {})) {
|
|
474
|
-
const parameterType = this.assembly.types && spec.isNamedTypeReference(parameter.type)
|
|
475
|
-
? this.assembly.types[parameter.type.fqn]
|
|
476
|
-
: undefined;
|
|
477
|
-
if (parameterType) {
|
|
478
|
-
const functionName = `${NAMESPACE}.${fnName(parameterType.fqn)}`;
|
|
479
|
-
statements.push(ts.factory.createExpressionStatement(ts.factory.createCallExpression(ts.factory.createIdentifier(functionName), undefined, [
|
|
480
|
-
ts.factory.createIdentifier(parameter.name),
|
|
481
|
-
])));
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return statements;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
function findType2(fqn, assembly) {
|
|
488
|
-
// Is from a different assembly?
|
|
489
|
-
if (!fqn.startsWith(`${assembly.name}.`)) {
|
|
490
|
-
return 'other-assembly';
|
|
491
|
-
}
|
|
492
|
-
const type = (assembly.types ?? {})[fqn];
|
|
493
|
-
if (!type) {
|
|
494
|
-
throw new Error(`Could not find type in same assembly: ${fqn}`);
|
|
495
|
-
}
|
|
496
|
-
return type;
|
|
497
|
-
}
|
|
498
|
-
function createWarningStatementForElement(element, classType) {
|
|
499
|
-
if (spec.isDeprecated(element)) {
|
|
500
|
-
const elementName = element.name;
|
|
501
|
-
const fqn = elementName ? `${classType.fqn}#${elementName}` : classType.fqn;
|
|
502
|
-
const message = element.docs?.deprecated ?? classType.docs?.deprecated;
|
|
503
|
-
return [createWarningFunctionCall(fqn, message, undefined, true)];
|
|
504
|
-
}
|
|
505
|
-
return [];
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* Inserts a list of statements in the correct position inside a block of statements.
|
|
509
|
-
* If there is a `super` call, It inserts the statements just after it. Otherwise,
|
|
510
|
-
* insert the statements right at the beginning of the block.
|
|
511
|
-
*/
|
|
512
|
-
function insertStatements(block, newStatements) {
|
|
513
|
-
function splicePoint(statement) {
|
|
514
|
-
if (statement == null) {
|
|
515
|
-
return 0;
|
|
516
|
-
}
|
|
517
|
-
let isSuper = false;
|
|
518
|
-
statement.forEachChild((node) => {
|
|
519
|
-
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.SuperKeyword) {
|
|
520
|
-
isSuper = true;
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
return isSuper ? 1 : 0;
|
|
524
|
-
}
|
|
525
|
-
const result = [...block.statements];
|
|
526
|
-
result.splice(splicePoint(block.statements[0]), 0, ...newStatements);
|
|
527
|
-
return ts.factory.createNodeArray(result);
|
|
528
|
-
}
|
|
529
|
-
function createRequireStatement(name, importPath) {
|
|
530
|
-
return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList([
|
|
531
|
-
ts.factory.createVariableDeclaration(name, undefined, undefined, ts.factory.createCallExpression(ts.factory.createIdentifier('require'), undefined, [
|
|
532
|
-
ts.factory.createStringLiteral(importPath),
|
|
533
|
-
])),
|
|
534
|
-
], ts.NodeFlags.Const));
|
|
535
|
-
}
|
|
536
|
-
/**
|
|
537
|
-
* Returns a ready-to-used function name (including a `require`, if necessary)
|
|
538
|
-
*/
|
|
539
|
-
function importedFunctionName(typeName, assembly, projectInfo) {
|
|
540
|
-
const assemblies = projectInfo.dependencyClosure.concat(assembly);
|
|
541
|
-
const { type, moduleName } = findType(typeName, assemblies);
|
|
542
|
-
if (type) {
|
|
543
|
-
return moduleName !== assembly.name
|
|
544
|
-
? `require("${moduleName}/${exports.WARNINGSCODE_FILE_NAME}").${fnName(type.fqn)}`
|
|
545
|
-
: `module.exports.${fnName(type.fqn)}`;
|
|
546
|
-
}
|
|
547
|
-
return undefined;
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* Find the type and module name in an array of assemblies
|
|
551
|
-
* matching a given type name
|
|
552
|
-
*/
|
|
553
|
-
function findType(typeName, assemblies) {
|
|
554
|
-
for (const asm of assemblies) {
|
|
555
|
-
if (asm.metadata?.jsii?.compiledWithDeprecationWarnings) {
|
|
556
|
-
const types = asm.types ?? {};
|
|
557
|
-
for (const name of Object.keys(types)) {
|
|
558
|
-
if (typeName === name) {
|
|
559
|
-
return { type: types[name], moduleName: asm.name };
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
return {};
|
|
565
|
-
}
|
|
566
|
-
function createTypeHandlerCall(functionName, parameter, collectionKind) {
|
|
567
|
-
switch (collectionKind) {
|
|
568
|
-
case spec.CollectionKind.Array:
|
|
569
|
-
return ts.factory.createIfStatement(ts.factory.createBinaryExpression(ts.factory.createIdentifier(parameter), ts.SyntaxKind.ExclamationEqualsToken, ts.factory.createNull()), ts.factory.createForOfStatement(undefined, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(FOR_LOOP_ITEM_NAME)], ts.NodeFlags.Const), ts.factory.createIdentifier(parameter), createTypeHandlerCall(functionName, FOR_LOOP_ITEM_NAME)));
|
|
570
|
-
case spec.CollectionKind.Map:
|
|
571
|
-
return ts.factory.createIfStatement(ts.factory.createBinaryExpression(ts.factory.createIdentifier(parameter), ts.SyntaxKind.ExclamationEqualsToken, ts.factory.createNull()), ts.factory.createForOfStatement(undefined, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(FOR_LOOP_ITEM_NAME)], ts.NodeFlags.Const), ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('Object'), 'values'), undefined, [ts.factory.createIdentifier(parameter)]), createTypeHandlerCall(functionName, FOR_LOOP_ITEM_NAME)));
|
|
572
|
-
case undefined:
|
|
573
|
-
return ts.factory.createIfStatement(ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.ExclamationToken, ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(VISITED_OBJECTS_SET_NAME), ts.factory.createIdentifier('has')), undefined, [ts.factory.createIdentifier(parameter)])), ts.factory.createExpressionStatement(ts.factory.createCallExpression(ts.factory.createIdentifier(functionName), undefined, [
|
|
574
|
-
ts.factory.createIdentifier(parameter),
|
|
575
|
-
])));
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
// We try-then-rethrow exceptions to avoid runtimes displaying an uncanny wall of text if the place
|
|
579
|
-
// where the error was thrown is webpacked. For example, jest somehow manages to capture the throw
|
|
580
|
-
// location and renders the source line (which may be the whole file) when bundled.
|
|
581
|
-
function wrapWithRethrow(statements, caller) {
|
|
582
|
-
if (statements.length === 0) {
|
|
583
|
-
return statements;
|
|
584
|
-
}
|
|
585
|
-
return [
|
|
586
|
-
ts.factory.createTryStatement(ts.factory.createBlock(statements), ts.factory.createCatchClause(ts.factory.createVariableDeclaration('error'), ts.factory.createBlock([
|
|
587
|
-
// If this is a DeprecationError, trim its stack trace to surface level before re-throwing,
|
|
588
|
-
// so we don't carry out possibly confusing frames from injected code. That can be toggled
|
|
589
|
-
// off by setting JSII_DEBUG=1, so we can also diagnose in-injected code faults.
|
|
590
|
-
ts.factory.createIfStatement(ts.factory.createBinaryExpression(ts.factory.createBinaryExpression(ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('process'), 'env'), 'JSII_DEBUG'), ts.SyntaxKind.ExclamationEqualsEqualsToken, ts.factory.createStringLiteral('1')), ts.SyntaxKind.AmpersandAmpersandToken, ts.factory.createBinaryExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('error'), 'name'), ts.SyntaxKind.EqualsEqualsEqualsToken, ts.factory.createStringLiteral(DEPRECATION_ERROR))), ts.factory.createBlock([
|
|
591
|
-
ts.factory.createExpressionStatement(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('Error'), 'captureStackTrace'), undefined, [ts.factory.createIdentifier('error'), caller])),
|
|
592
|
-
])),
|
|
593
|
-
ts.factory.createThrowStatement(ts.factory.createIdentifier('error')),
|
|
594
|
-
])), undefined),
|
|
595
|
-
];
|
|
596
|
-
}
|
|
597
|
-
/**
|
|
598
|
-
* Force a path to be UNIXy (use `/` as a separator)
|
|
599
|
-
*
|
|
600
|
-
* `path.join()` etc. will use the system-dependent path separator (either `/` or `\`
|
|
601
|
-
* depending on your platform).
|
|
602
|
-
*
|
|
603
|
-
* However, if we actually emit the path-dependent separator to the `.js` files, then
|
|
604
|
-
* files compiled with jsii on Windows cannot be used on any other platform. That seems
|
|
605
|
-
* like an unnecessary restriction, especially since a `/` will work fine on Windows,
|
|
606
|
-
* so make sure to always emit `/`.
|
|
607
|
-
*
|
|
608
|
-
* TSC itself always strictly emits `/` (or at least, emits the same what you put in).
|
|
609
|
-
*/
|
|
610
|
-
function unixPath(filePath) {
|
|
611
|
-
if (path.sep === '\\') {
|
|
612
|
-
return filePath.replace(/\\/g, '/');
|
|
613
|
-
}
|
|
614
|
-
return filePath;
|
|
615
|
-
}
|
|
616
|
-
//# sourceMappingURL=deprecation-warnings.js.map
|