@travetto/transformer 7.0.0-rc.1 → 7.0.0-rc.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.
@@ -19,8 +19,8 @@ const isMappedType = (type: string | undefined): type is MappedType['operation']
19
19
  const getMappedFields = (type: ts.Type): string[] | undefined => {
20
20
  if (type.isStringLiteral()) {
21
21
  return [type.value];
22
- } else if (type.isUnion() && type.types.every(t => t.isStringLiteral())) {
23
- return type.types.map(t => t.value);
22
+ } else if (type.isUnion() && type.types.every(subType => subType.isStringLiteral())) {
23
+ return type.types.map(subType => subType.value);
24
24
  }
25
25
  };
26
26
 
@@ -82,7 +82,7 @@ export function TypeCategorize(resolver: TransformResolver, type: ts.Type): { ca
82
82
  try {
83
83
  const source = DeclarationUtil.getPrimaryDeclarationNode(type).getSourceFile();
84
84
  const sourceFile = source.fileName;
85
- if (sourceFile && ManifestModuleUtil.TYPINGS_EXT_RE.test(sourceFile) && !resolver.isKnownFile(sourceFile)) {
85
+ if (sourceFile && ManifestModuleUtil.TYPINGS_EXT_REGEX.test(sourceFile) && !resolver.isKnownFile(sourceFile)) {
86
86
  return { category: 'foreign', type };
87
87
  }
88
88
  } catch { }
@@ -101,7 +101,7 @@ export function TypeCategorize(resolver: TransformResolver, type: ts.Type): { ca
101
101
  const sourceFile = source.fileName;
102
102
  if (sourceFile?.includes('typescript/lib')) {
103
103
  return { category: 'literal', type };
104
- } else if (sourceFile && ManifestModuleUtil.TYPINGS_EXT_RE.test(sourceFile) && !resolver.isKnownFile(sourceFile)) {
104
+ } else if (sourceFile && ManifestModuleUtil.TYPINGS_EXT_REGEX.test(sourceFile) && !resolver.isKnownFile(sourceFile)) {
105
105
  return { category: 'foreign', type: resolvedType };
106
106
  } else if (!resolvedType.isClass()) { // Not a real type
107
107
  return { category: 'shape', type: resolvedType };
@@ -113,7 +113,7 @@ export function TypeCategorize(resolver: TransformResolver, type: ts.Type): { ca
113
113
  } else if (type.isLiteral()) {
114
114
  return { category: 'shape', type };
115
115
  } else if (objectFlags & ts.ObjectFlags.Mapped) { // Mapped types
116
- if (type.getProperties().some(x => x.declarations || x.valueDeclaration)) {
116
+ if (type.getProperties().some(property => property.declarations || property.valueDeclaration)) {
117
117
  return { category: 'mapped', type };
118
118
  }
119
119
  }
@@ -160,7 +160,7 @@ export const TypeBuilder: {
160
160
  }
161
161
  }
162
162
  if (values.length > 0) {
163
- return ({ key: 'template', template: { op: 'and', values }, ctor: String });
163
+ return ({ key: 'template', template: { operation: 'and', values }, ctor: String });
164
164
  }
165
165
  }
166
166
  }
@@ -223,11 +223,11 @@ export const TypeBuilder: {
223
223
  let undefinable = false;
224
224
  let nullable = false;
225
225
  const remainder = uType.types.filter(ut => {
226
- const u = (ut.getFlags() & (ts.TypeFlags.Undefined)) > 0;
227
- const n = (ut.getFlags() & (ts.TypeFlags.Null)) > 0;
228
- undefinable ||= u;
229
- nullable ||= n;
230
- return !(u || n);
226
+ const isUndefined = (ut.getFlags() & (ts.TypeFlags.Undefined)) > 0;
227
+ const isNull = (ut.getFlags() & (ts.TypeFlags.Null)) > 0;
228
+ undefinable ||= isUndefined;
229
+ nullable ||= isNull;
230
+ return !(isUndefined || isNull);
231
231
  });
232
232
  const name = CoreUtil.getSymbol(uType)?.getName();
233
233
  return { key: 'composition', name, undefinable, nullable, tsSubTypes: remainder, subTypes: [], operation: uType.isUnion() ? 'or' : 'and' };
@@ -247,14 +247,19 @@ export const TypeBuilder: {
247
247
  ctor: String,
248
248
  nullable: type.nullable,
249
249
  undefinable: type.undefinable,
250
- template: { op: 'or', values: subTypes.map(x => transformCast<TemplateType>(x).template!) }
250
+ template: { operation: 'or', values: subTypes.map(subType => transformCast<TemplateType>(subType).template!) }
251
251
  };
252
252
  } else if (subTypes.length === 1) {
253
253
  return { undefinable, nullable, ...first };
254
- } else if (first.key === 'literal' && subTypes.every(el => el.name === first.name)) { // We have a common
254
+ } else if (first.key === 'literal' && subTypes.every(item => item.name === first.name)) { // We have a common
255
255
  type.commonType = first;
256
- } else if (type.operation === 'and' && first.key === 'shape' && subTypes.every(el => el.key === 'shape')) { // All shapes
257
- return { importName: first.importName, name: first.name, key: 'shape', fieldTypes: subTypes.reduce((acc, x) => ({ ...acc, ...x.fieldTypes }), {}) };
256
+ } else if (type.operation === 'and' && first.key === 'shape' && subTypes.every(item => item.key === 'shape')) { // All shapes
257
+ return {
258
+ importName: first.importName,
259
+ name: first.name,
260
+ key: 'shape',
261
+ fieldTypes: subTypes.reduce((map, subType) => ({ ...map, ...subType.fieldTypes }), {})
262
+ };
258
263
  }
259
264
  return type;
260
265
  }
@@ -266,8 +271,8 @@ export const TypeBuilder: {
266
271
  let operation: string | undefined;
267
272
  let name: string | undefined;
268
273
 
269
- const decls = DeclarationUtil.getDeclarations(type).filter(x => ts.isTypeAliasDeclaration(x));
270
- const ref = decls[0]?.type;
274
+ const declarations = DeclarationUtil.getDeclarations(type).filter(declaration => ts.isTypeAliasDeclaration(declaration));
275
+ const ref = declarations[0]?.type;
271
276
 
272
277
  if (ref && ts.isTypeReferenceNode(ref) && ref.typeArguments && ref.typeArguments.length > 0) {
273
278
  const [first, second] = ref.typeArguments;
@@ -298,20 +303,20 @@ export const TypeBuilder: {
298
303
  const name = CoreUtil.getSymbol(context?.alias ?? type)?.getName();
299
304
  const importName = resolver.getTypeImportName(type) ?? '<unknown>';
300
305
  const tsTypeArguments = resolver.getAllTypeArguments(type);
301
- const props = resolver.getPropertiesOfType(type);
302
- if (props.length === 0) {
306
+ const properties = resolver.getPropertiesOfType(type);
307
+ if (properties.length === 0) {
303
308
  return { key: 'literal', name: 'Object', ctor: Object, importName };
304
309
  }
305
310
 
306
- for (const member of props) {
307
- const dec = DeclarationUtil.getPrimaryDeclarationNode(member);
308
- if (DeclarationUtil.isPublic(dec)) { // If public
309
- const memberType = resolver.getType(dec);
311
+ for (const member of properties) {
312
+ const decorator = DeclarationUtil.getPrimaryDeclarationNode(member);
313
+ if (DeclarationUtil.isPublic(decorator)) { // If public
314
+ const memberType = resolver.getType(decorator);
310
315
  if (
311
316
  !member.getName().includes('@') && // if not a symbol
312
317
  !memberType.getCallSignatures().length // if not a function
313
318
  ) {
314
- if ((ts.isPropertySignature(dec) || ts.isPropertyDeclaration(dec)) && !!dec.questionToken) {
319
+ if ((ts.isPropertySignature(decorator) || ts.isPropertyDeclaration(decorator)) && !!decorator.questionToken) {
315
320
  Object.defineProperty(memberType, UNDEFINED, { value: true });
316
321
  }
317
322
  tsFieldTypes[member.getName()] = memberType;
@@ -333,7 +338,7 @@ export const TypeBuilder: {
333
338
  // Resolving relative to source file
334
339
  if (!importName || importName.startsWith('.')) {
335
340
  const rawSourceFile: string = DeclarationUtil.getDeclarations(type)
336
- ?.find(x => ts.getAllJSDocTags(x, (t): t is ts.JSDocTag => t.tagName.getText() === 'concrete').length)
341
+ ?.find(declaration => ts.getAllJSDocTags(declaration, (node): node is ts.JSDocTag => node.tagName.getText() === 'concrete').length)
337
342
  ?.getSourceFile().fileName ?? '';
338
343
 
339
344
  if (!importName || importName === '.') {
@@ -346,8 +351,9 @@ export const TypeBuilder: {
346
351
 
347
352
  // Convert name to $Concrete suffix if not provided
348
353
  if (!name) {
349
- const [decl] = DeclarationUtil.getDeclarations(type).filter(x => ts.isInterfaceDeclaration(x) || ts.isTypeAliasDeclaration(x));
350
- name = `${decl.name.text}$Concrete`;
354
+ const [primaryDeclaration] = DeclarationUtil.getDeclarations(type)
355
+ .filter(declaration => ts.isInterfaceDeclaration(declaration) || ts.isTypeAliasDeclaration(declaration));
356
+ name = `${primaryDeclaration.name.text}$Concrete`;
351
357
  }
352
358
 
353
359
  return { key: 'managed', name, importName };
@@ -4,12 +4,12 @@ export class CoerceUtil {
4
4
  /**
5
5
  * Is a value a plain JS object, created using {}
6
6
  */
7
- static #isPlainObject(obj: unknown): obj is Record<string, unknown> {
8
- return typeof obj === 'object' // separate from primitives
9
- && obj !== undefined
10
- && obj !== null // is obvious
11
- && obj.constructor === Object // separate instances (Array, DOM, ...)
12
- && Object.prototype.toString.call(obj) === '[object Object]'; // separate build-in like Math
7
+ static #isPlainObject(value: unknown): value is Record<string, unknown> {
8
+ return typeof value === 'object' // separate from primitives
9
+ && value !== undefined
10
+ && value !== null // is obvious
11
+ && value.constructor === Object // separate instances (Array, DOM, ...)
12
+ && Object.prototype.toString.call(value) === '[object Object]'; // separate build-in like Math
13
13
  }
14
14
 
15
15
  /**
@@ -73,10 +73,10 @@ export class SimpleResolver implements TransformResolver {
73
73
 
74
74
  /**
75
75
  * Get type from element
76
- * @param el
76
+ * @param value
77
77
  */
78
- getType(el: ts.Type | ts.Node): ts.Type {
79
- return 'getSourceFile' in el ? this.#tsChecker.getTypeAtLocation(el) : el;
78
+ getType(value: ts.Type | ts.Node): ts.Type {
79
+ return 'getSourceFile' in value ? this.#tsChecker.getTypeAtLocation(value) : value;
80
80
  }
81
81
 
82
82
  /**
@@ -106,7 +106,8 @@ export class SimpleResolver implements TransformResolver {
106
106
  * Get list of properties
107
107
  */
108
108
  getPropertiesOfType(type: ts.Type): ts.Symbol[] {
109
- return this.#tsChecker.getPropertiesOfType(type).filter(x => x.getName() !== '__proto__' && x.getName() !== 'prototype');
109
+ return this.#tsChecker.getPropertiesOfType(type)
110
+ .filter(property => property.getName() !== '__proto__' && property.getName() !== 'prototype');
110
111
  }
111
112
 
112
113
  /**
@@ -161,11 +162,11 @@ export class SimpleResolver implements TransformResolver {
161
162
 
162
163
  try {
163
164
  return resolve(this.getType(node));
164
- } catch (err) {
165
- if (!(err instanceof Error)) {
166
- throw err;
165
+ } catch (error) {
166
+ if (!(error instanceof Error)) {
167
+ throw error;
167
168
  }
168
- console.error(`Unable to resolve type in ${importName}`, err.stack);
169
+ console.error(`Unable to resolve type in ${importName}`, error.stack);
169
170
  return { key: 'literal', ctor: Object, name: 'object' };
170
171
  }
171
172
  }
package/src/state.ts CHANGED
@@ -15,16 +15,16 @@ import { CoreUtil } from './util/core.ts';
15
15
  import { LiteralUtil } from './util/literal.ts';
16
16
  import { SystemUtil } from './util/system.ts';
17
17
 
18
- function hasOriginal(n: ts.Node): n is ts.Node & { original: ts.Node } {
19
- return !!n && !n.parent && 'original' in n && !!n.original;
18
+ function hasOriginal(node: ts.Node): node is ts.Node & { original: ts.Node } {
19
+ return !!node && !node.parent && 'original' in node && !!node.original;
20
20
  }
21
21
 
22
- function hasEscapedName(n: ts.Node): n is ts.Node & { name: { escapedText: string } } {
23
- return !!n && 'name' in n && typeof n.name === 'object' && !!n.name && 'escapedText' in n.name && !!n.name.escapedText;
22
+ function hasEscapedName(node: ts.Node): node is ts.Node & { name: { escapedText: string } } {
23
+ return !!node && 'name' in node && typeof node.name === 'object' && !!node.name && 'escapedText' in node.name && !!node.name.escapedText;
24
24
  }
25
25
 
26
- function isRedefinableDeclaration(x: ts.Node): x is ts.InterfaceDeclaration | ts.ClassDeclaration | ts.FunctionDeclaration {
27
- return ts.isFunctionDeclaration(x) || ts.isClassDeclaration(x) || ts.isInterfaceDeclaration(x);
26
+ function isRedefinableDeclaration(node: ts.Node): node is ts.InterfaceDeclaration | ts.ClassDeclaration | ts.FunctionDeclaration {
27
+ return ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node) || ts.isInterfaceDeclaration(node);
28
28
  }
29
29
 
30
30
  const FOREIGN_TYPE_REGISTRY_FILE = '@travetto/runtime/src/function';
@@ -35,7 +35,7 @@ const FOREIGN_TYPE_REGISTRY_FILE = '@travetto/runtime/src/function';
35
35
  export class TransformerState implements State {
36
36
  #resolver: SimpleResolver;
37
37
  #imports: ImportManager;
38
- #modIdent: ts.Identifier;
38
+ #moduleIdentifier: ts.Identifier;
39
39
  #manifestIndex: ManifestIndex;
40
40
  #syntheticIdentifiers = new Map<string, ts.Identifier>();
41
41
  #decorators = new Map<string, ts.PropertyAccessExpression>();
@@ -93,8 +93,8 @@ export class TransformerState implements State {
93
93
  const resolved = this.resolveType(node);
94
94
  if (resolved.key !== 'managed') {
95
95
  const file = node.getSourceFile().fileName;
96
- const src = this.#resolver.getFileImportName(file);
97
- throw new Error(`Unable to import non-external type: ${node.getText()} ${resolved.key}: ${src}`);
96
+ const source = this.#resolver.getFileImportName(file);
97
+ throw new Error(`Unable to import non-external type: ${node.getText()} ${resolved.key}: ${source}`);
98
98
  }
99
99
  return resolved;
100
100
  }
@@ -136,9 +136,9 @@ export class TransformerState implements State {
136
136
  */
137
137
  readDocTagList(node: ts.Declaration, name: string): string[] {
138
138
  return this.readDocTag(node, name)
139
- .flatMap(x => x.split(/\s*,\s*/g))
140
- .map(x => x.replace(/`/g, ''))
141
- .filter(x => !!x);
139
+ .flatMap(tag => tag.split(/\s*,\s*/g))
140
+ .map(tag => tag.replace(/`/g, ''))
141
+ .filter(tag => !!tag);
142
142
  }
143
143
 
144
144
  /**
@@ -147,8 +147,8 @@ export class TransformerState implements State {
147
147
  importDecorator(pth: string, name: string): ts.PropertyAccessExpression | undefined {
148
148
  if (!this.#decorators.has(`${pth}:${name}`)) {
149
149
  const ref = this.#imports.importFile(pth);
150
- const ident = this.factory.createIdentifier(name);
151
- this.#decorators.set(name, this.factory.createPropertyAccessExpression(ref.ident, ident));
150
+ const identifier = this.factory.createIdentifier(name);
151
+ this.#decorators.set(name, this.factory.createPropertyAccessExpression(ref.identifier, identifier));
152
152
  }
153
153
  return this.#decorators.get(name);
154
154
  }
@@ -164,22 +164,22 @@ export class TransformerState implements State {
164
164
  /**
165
165
  * Read a decorator's metadata
166
166
  */
167
- getDecoratorMeta(dec: ts.Decorator): DecoratorMeta | undefined {
168
- const ident = DecoratorUtil.getDecoratorIdent(dec);
169
- const type = this.#resolver.getType(ident);
170
- const decl = DeclarationUtil.getOptionalPrimaryDeclarationNode(type);
171
- const src = decl?.getSourceFile().fileName;
172
- const mod = src ? this.#resolver.getFileImportName(src, true) : undefined;
167
+ getDecoratorMeta(decorator: ts.Decorator): DecoratorMeta | undefined {
168
+ const identifier = DecoratorUtil.getDecoratorIdentifier(decorator);
169
+ const type = this.#resolver.getType(identifier);
170
+ const declaration = DeclarationUtil.getOptionalPrimaryDeclarationNode(type);
171
+ const source = declaration?.getSourceFile().fileName;
172
+ const mod = source ? this.#resolver.getFileImportName(source, true) : undefined;
173
173
  const file = this.#manifestIndex.getFromImport(mod ?? '')?.outputFile;
174
174
  const targets = DocUtil.readAugments(type);
175
175
  const example = DocUtil.readExample(type);
176
176
  const module = file ? mod : undefined;
177
- const name = ident ?
178
- ident.escapedText?.toString()! :
177
+ const name = identifier ?
178
+ identifier.escapedText?.toString()! :
179
179
  undefined;
180
180
 
181
- if (ident && name) {
182
- return { dec, ident, file, module, targets, name, options: example };
181
+ if (identifier && name) {
182
+ return { decorator, identifier, file, module, targets, name, options: example };
183
183
  }
184
184
  }
185
185
 
@@ -188,8 +188,8 @@ export class TransformerState implements State {
188
188
  */
189
189
  getDecoratorList(node: ts.Node): DecoratorMeta[] {
190
190
  return ts.canHaveDecorators(node) ? (ts.getDecorators(node) ?? [])
191
- .map(dec => this.getDecoratorMeta(dec))
192
- .filter(x => !!x) : [];
191
+ .map(decorator => this.getDecoratorMeta(decorator))
192
+ .filter(meta => !!meta) : [];
193
193
  }
194
194
 
195
195
  /**
@@ -201,26 +201,26 @@ export class TransformerState implements State {
201
201
 
202
202
  /**
203
203
  * Register statement for inclusion in final output
204
- * @param stmt
204
+ * @param added
205
205
  * @param before
206
206
  */
207
207
  addStatements(added: ts.Statement[], before?: ts.Node | number): void {
208
- const stmts = this.source.statements.slice(0);
209
- let idx = stmts.length + 1000;
208
+ const statements = this.source.statements.slice(0);
209
+ let idx = statements.length + 1000;
210
210
 
211
211
  if (before && typeof before !== 'number') {
212
- let n = before;
213
- if (hasOriginal(n)) {
214
- n = n.original;
212
+ let node = before;
213
+ if (hasOriginal(node)) {
214
+ node = node.original;
215
215
  }
216
- while (n && !ts.isSourceFile(n.parent) && n !== n.parent) {
217
- n = n.parent;
216
+ while (node && !ts.isSourceFile(node.parent) && node !== node.parent) {
217
+ node = node.parent;
218
218
  }
219
- if (!ts.isStatement(n)) {
219
+ if (!ts.isStatement(node)) {
220
220
  throw new Error('Unable to find statement at top level');
221
221
  }
222
- if (n && ts.isSourceFile(n.parent) && stmts.indexOf(n) >= 0) {
223
- idx = stmts.indexOf(n) - 1;
222
+ if (node && ts.isSourceFile(node.parent) && statements.indexOf(node) >= 0) {
223
+ idx = statements.indexOf(node) - 1;
224
224
  }
225
225
  } else if (before !== undefined) {
226
226
  idx = before;
@@ -241,21 +241,21 @@ export class TransformerState implements State {
241
241
  /**
242
242
  * From literal
243
243
  */
244
- fromLiteral<T extends ts.Expression>(val: T): T;
245
- fromLiteral(val: undefined): ts.Identifier;
246
- fromLiteral(val: null): ts.NullLiteral;
247
- fromLiteral(val: object): ts.ObjectLiteralExpression;
248
- fromLiteral(val: unknown[]): ts.ArrayLiteralExpression;
249
- fromLiteral(val: string | boolean | number): ts.LiteralExpression;
250
- fromLiteral(val: unknown): ts.Node {
251
- return LiteralUtil.fromLiteral(this.factory, val!);
244
+ fromLiteral<T extends ts.Expression>(value: T): T;
245
+ fromLiteral(value: undefined): ts.Identifier;
246
+ fromLiteral(value: null): ts.NullLiteral;
247
+ fromLiteral(value: object): ts.ObjectLiteralExpression;
248
+ fromLiteral(value: unknown[]): ts.ArrayLiteralExpression;
249
+ fromLiteral(value: string | boolean | number): ts.LiteralExpression;
250
+ fromLiteral(value: unknown): ts.Node {
251
+ return LiteralUtil.fromLiteral(this.factory, value!);
252
252
  }
253
253
 
254
254
  /**
255
255
  * Extend
256
256
  */
257
- extendObjectLiteral(src: object | ts.Expression, ...rest: (object | ts.Expression)[]): ts.ObjectLiteralExpression {
258
- return LiteralUtil.extendObjectLiteral(this.factory, src, ...rest);
257
+ extendObjectLiteral(source: object | ts.Expression, ...rest: (object | ts.Expression)[]): ts.ObjectLiteralExpression {
258
+ return LiteralUtil.extendObjectLiteral(this.factory, source, ...rest);
259
259
  }
260
260
 
261
261
  /**
@@ -268,8 +268,8 @@ export class TransformerState implements State {
268
268
  /**
269
269
  * Create a static field for a class
270
270
  */
271
- createStaticField(name: string, val: ts.Expression): ts.PropertyDeclaration {
272
- return CoreUtil.createStaticField(this.factory, name, val);
271
+ createStaticField(name: string, value: ts.Expression): ts.PropertyDeclaration {
272
+ return CoreUtil.createStaticField(this.factory, name, value);
273
273
  }
274
274
 
275
275
  /**
@@ -284,17 +284,17 @@ export class TransformerState implements State {
284
284
  * Get filename identifier, regardless of module system
285
285
  */
286
286
  getModuleIdentifier(): ts.Expression {
287
- if (this.#modIdent === undefined) {
288
- this.#modIdent = this.factory.createUniqueName('mod');
287
+ if (this.#moduleIdentifier === undefined) {
288
+ this.#moduleIdentifier = this.factory.createUniqueName('mod');
289
289
  const entry = this.#resolver.getFileImport(this.source.fileName);
290
- const decl = this.factory.createVariableDeclaration(this.#modIdent, undefined, undefined,
290
+ const declaration = this.factory.createVariableDeclaration(this.#moduleIdentifier, undefined, undefined,
291
291
  this.fromLiteral([entry?.module, entry?.relativeFile ?? ''])
292
292
  );
293
293
  this.addStatements([
294
- this.factory.createVariableStatement([], this.factory.createVariableDeclarationList([decl]))
294
+ this.factory.createVariableStatement([], this.factory.createVariableDeclarationList([declaration]))
295
295
  ], -1);
296
296
  }
297
- return this.#modIdent;
297
+ return this.#moduleIdentifier;
298
298
  }
299
299
 
300
300
  /**
@@ -309,7 +309,7 @@ export class TransformerState implements State {
309
309
  mod = typeof mod === 'string' ? mod : mod[ModuleNameSymbol]!;
310
310
  const target = `${mod}:${name}`;
311
311
  const list = this.getDecoratorList(node);
312
- return list.find(x => x.targets?.includes(target) && (!module || x.name === name && x.module === module))?.dec;
312
+ return list.find(meta => meta.targets?.includes(target) && (!module || meta.name === name && meta.module === module))?.decorator;
313
313
  }
314
314
 
315
315
  /**
@@ -379,14 +379,14 @@ export class TransformerState implements State {
379
379
  findMethodByName(cls: ts.ClassLikeDeclaration | ts.Type, method: string): ts.MethodDeclaration | undefined {
380
380
  if ('getSourceFile' in cls) {
381
381
  return cls.members.find(
382
- (m): m is ts.MethodDeclaration => ts.isMethodDeclaration(m) && ts.isIdentifier(m.name) && m.name.escapedText === method
382
+ (value): value is ts.MethodDeclaration => ts.isMethodDeclaration(value) && ts.isIdentifier(value.name) && value.name.escapedText === method
383
383
  );
384
384
  } else {
385
- const props = this.#resolver.getPropertiesOfType(cls);
386
- for (const prop of props) {
387
- const decl = prop.declarations?.[0];
388
- if (decl && prop.escapedName === method && ts.isMethodDeclaration(decl)) {
389
- return decl;
385
+ const properties = this.#resolver.getPropertiesOfType(cls);
386
+ for (const property of properties) {
387
+ const declaration = property.declarations?.[0];
388
+ if (declaration && property.escapedName === method && ts.isMethodDeclaration(declaration)) {
389
+ return declaration;
390
390
  }
391
391
  }
392
392
  }
@@ -403,13 +403,13 @@ export class TransformerState implements State {
403
403
  /**
404
404
  * Produce a foreign target type
405
405
  */
406
- getForeignTarget(ret: ForeignType): ts.Expression {
406
+ getForeignTarget(type: ForeignType): ts.Expression {
407
407
  const file = this.importFile(FOREIGN_TYPE_REGISTRY_FILE);
408
408
  return this.factory.createCallExpression(this.createAccess(
409
- file.ident,
409
+ file.identifier,
410
410
  this.factory.createIdentifier('foreignType'),
411
411
  ), [], [
412
- this.fromLiteral(`${ret.source.split('node_modules/')[1]}+${ret.name}`)
412
+ this.fromLiteral(`${type.source.split('node_modules/')[1]}+${type.name}`)
413
413
  ]);
414
414
  }
415
415
 
@@ -425,8 +425,8 @@ export class TransformerState implements State {
425
425
  return this.getForeignTarget(type);
426
426
  } else {
427
427
  const file = node.getSourceFile().fileName;
428
- const src = this.getFileImportName(file);
429
- throw new Error(`Unable to import non-external type: ${node.getText()} ${type.key}: ${src}`);
428
+ const source = this.getFileImportName(file);
429
+ throw new Error(`Unable to import non-external type: ${node.getText()} ${type.key}: ${source}`);
430
430
  }
431
431
  }
432
432
 
@@ -435,7 +435,7 @@ export class TransformerState implements State {
435
435
  */
436
436
  getApparentTypeOfField(value: ts.Type, field: string): AnyType | undefined {
437
437
  const checker = this.#resolver.getChecker();
438
- const props = checker.getApparentType(value).getApparentProperties().find(x => x.escapedName === field);
439
- return props ? this.resolveType(checker.getTypeOfSymbol(props)) : undefined;
438
+ const properties = checker.getApparentType(value).getApparentProperties().find(property => property.escapedName === field);
439
+ return properties ? this.resolveType(checker.getTypeOfSymbol(properties)) : undefined;
440
440
  }
441
441
  }
@@ -22,13 +22,13 @@ export interface DeclDocumentation {
22
22
  */
23
23
  export type Import = {
24
24
  path: string;
25
- ident: ts.Identifier;
26
- stmt?: ts.ImportDeclaration;
25
+ identifier: ts.Identifier;
26
+ statement?: ts.ImportDeclaration;
27
27
  };
28
28
 
29
29
  /** Template Literal Types */
30
30
  export type TemplateLiteralPart = string | NumberConstructor | StringConstructor | BooleanConstructor;
31
- export type TemplateLiteral = { op: 'and' | 'or', values: (TemplateLiteralPart | TemplateLiteral)[] };
31
+ export type TemplateLiteral = { operation: 'and' | 'or', values: (TemplateLiteralPart | TemplateLiteral)[] };
32
32
 
33
33
  export function transformCast<T>(input: unknown): T {
34
34
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
@@ -4,8 +4,8 @@ import ts from 'typescript';
4
4
  * Decorator metadata
5
5
  */
6
6
  export type DecoratorMeta = {
7
- dec: ts.Decorator;
8
- ident: ts.Identifier;
7
+ decorator: ts.Decorator;
8
+ identifier: ts.Identifier;
9
9
  module?: string;
10
10
  file?: string;
11
11
  targets?: string[];
@@ -18,7 +18,7 @@ export type State = {
18
18
  importName: string;
19
19
  added: Map<number, ts.Statement[]>;
20
20
  getDecoratorList(node: ts.Node): DecoratorMeta[];
21
- finalize(src: ts.SourceFile): ts.SourceFile;
21
+ finalize(source: ts.SourceFile): ts.SourceFile;
22
22
  };
23
23
 
24
24
  export type TransformPhase = 'before' | 'after';
package/src/util/core.ts CHANGED
@@ -8,25 +8,24 @@ export class CoreUtil {
8
8
  /**
9
9
  * See if inbound node has an original property
10
10
  */
11
- static hasOriginal(o: ts.Node): o is (ts.Node & { original: ts.Node }) {
12
- return 'original' in o && !!o.original;
11
+ static hasOriginal(value: ts.Node): value is (ts.Node & { original: ts.Node }) {
12
+ return 'original' in value && !!value.original;
13
13
  }
14
14
 
15
15
  /**
16
16
  * See if type has target
17
17
  */
18
- static hasTarget(o: ts.Type): o is (ts.Type & { target: ts.Type }) {
19
- return 'target' in o && !!o.target;
18
+ static hasTarget(value: ts.Type): value is (ts.Type & { target: ts.Type }) {
19
+ return 'target' in value && !!value.target;
20
20
  }
21
21
 
22
22
  /**
23
23
  * Get code range of node
24
- * @param m
25
24
  */
26
- static getRangeOf<T extends ts.Node>(source: ts.SourceFile, o: T | undefined): [start: number, end: number] | undefined {
27
- if (o && o.pos >= 0) {
28
- const start = ts.getLineAndCharacterOfPosition(source, o.getStart(source));
29
- const end = ts.getLineAndCharacterOfPosition(source, o.getEnd());
25
+ static getRangeOf<T extends ts.Node>(source: ts.SourceFile, value: T | undefined): [start: number, end: number] | undefined {
26
+ if (value && value.pos >= 0) {
27
+ const start = ts.getLineAndCharacterOfPosition(source, value.getStart(source));
28
+ const end = ts.getLineAndCharacterOfPosition(source, value.getEnd());
30
29
  return [start.line + 1, end.line + 1];
31
30
  }
32
31
  }
@@ -34,7 +33,10 @@ export class CoreUtil {
34
33
  /**
35
34
  * Find the primary argument of a call expression, or decorator.
36
35
  */
37
- static findArgument<T extends ts.Expression = ts.Expression>(node: ts.CallExpression | undefined, pred: (x: ts.Expression) => x is T): T | undefined {
36
+ static findArgument<T extends ts.Expression = ts.Expression>(
37
+ node: ts.CallExpression | undefined,
38
+ pred: (expr: ts.Expression) => expr is T
39
+ ): T | undefined {
38
40
  if (node && node.arguments && node.arguments.length) {
39
41
  return node.arguments.find(pred);
40
42
  }
@@ -52,10 +54,10 @@ export class CoreUtil {
52
54
  /**
53
55
  * Create a static field for a class
54
56
  */
55
- static createStaticField(factory: ts.NodeFactory, name: string, val: ts.Expression): ts.PropertyDeclaration {
57
+ static createStaticField(factory: ts.NodeFactory, name: string, value: ts.Expression): ts.PropertyDeclaration {
56
58
  return factory.createPropertyDeclaration(
57
59
  [factory.createToken(ts.SyntaxKind.StaticKeyword)],
58
- name, undefined, undefined, val
60
+ name, undefined, undefined, value
59
61
  );
60
62
  }
61
63
 
@@ -74,12 +76,12 @@ export class CoreUtil {
74
76
 
75
77
  /**
76
78
  * Updates source
77
- * @param src
79
+ * @param source
78
80
  * @param statements
79
81
  */
80
- static updateSource(factory: ts.NodeFactory, src: ts.SourceFile, statements: ts.NodeArray<ts.Statement> | ts.Statement[]): ts.SourceFile {
82
+ static updateSource(factory: ts.NodeFactory, source: ts.SourceFile, statements: ts.NodeArray<ts.Statement> | ts.Statement[]): ts.SourceFile {
81
83
  return factory.updateSourceFile(
82
- src, statements, src.isDeclarationFile, src.referencedFiles, src.typeReferenceDirectives, src.hasNoDefaultLib
84
+ source, statements, source.isDeclarationFile, source.referencedFiles, source.typeReferenceDirectives, source.hasNoDefaultLib
83
85
  );
84
86
  }
85
87
 
@@ -96,9 +98,9 @@ export class CoreUtil {
96
98
  first = factory.createIdentifier(first);
97
99
  }
98
100
  return items.reduce<ts.Expression>(
99
- (acc, p) => typeof p === 'number' ?
100
- factory.createElementAccessExpression(acc, p) :
101
- factory.createPropertyAccessExpression(acc, p),
101
+ (expr, value) => typeof value === 'number' ?
102
+ factory.createElementAccessExpression(expr, value) :
103
+ factory.createPropertyAccessExpression(expr, value),
102
104
  factory.createPropertyAccessExpression(first, second)
103
105
  );
104
106
  }
@@ -111,7 +113,7 @@ export class CoreUtil {
111
113
  factory.createCallExpression(
112
114
  name,
113
115
  undefined,
114
- contents.filter(x => !!x)
116
+ contents.filter(expr => !!expr)
115
117
  )
116
118
  );
117
119
  }