@travetto/runtime 8.0.0-alpha.19 → 8.0.0-alpha.20

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/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Readable } from 'node:stream';
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ // biome-ignore lint/suspicious/noExplicitAny: This is the any reference we use explicitly
4
4
  export type Any = any;
5
5
 
6
6
  export type AnyMap = { [key: string]: Any };
@@ -20,30 +20,32 @@ export type NumericLikeIntrinsic = Date | NumericPrimitive;
20
20
  export type IntrinsicType = Primitive | Date | ArrayBuffer | Uint8Array | Uint16Array | Uint32Array | Readable | Buffer | Blob | File;
21
21
 
22
22
  export type DeepPartial<T> = {
23
- [P in keyof T]?: (T[P] extends (IntrinsicType | undefined) ? (T[P] | undefined) :
24
- (T[P] extends Any[] ? (DeepPartial<T[P][number]> | null | undefined)[] : DeepPartial<T[P]>));
23
+ [P in keyof T]?: T[P] extends IntrinsicType | undefined
24
+ ? T[P] | undefined
25
+ : T[P] extends Any[]
26
+ ? (DeepPartial<T[P][number]> | null | undefined)[]
27
+ : DeepPartial<T[P]>;
25
28
  };
26
29
 
27
30
  export type ValidFields<T, I> = {
28
- [K in keyof T]:
29
- (T[K] extends (Primitive | I | undefined) ? K :
30
- (T[K] extends (Function | undefined) ? never :
31
- K))
31
+ [K in keyof T]: T[K] extends Primitive | I | undefined ? K : T[K] extends Function | undefined ? never : K;
32
32
  }[keyof T];
33
33
 
34
34
  export type RetainIntrinsicFields<T> = Pick<T, ValidFields<T, IntrinsicType>>;
35
35
 
36
- export type KeyPaths<T, PrimitiveType = IntrinsicType | IntrinsicType[], PREFIX extends string = '', SEP extends string = '.'> =
37
- { [K in keyof T]:
38
- (K extends string ? (
39
- (T[K] extends (IntrinsicType[] | IntrinsicType | undefined) ?
40
- (T[K] extends PrimitiveType ? `${PREFIX}${K}` : never) : (
41
- (T[K] extends Any[] ?
42
- KeyPaths<T[K][number], PrimitiveType, `${K}${SEP}`, SEP> :
43
- (T[K] extends object ? KeyPaths<T[K], PrimitiveType, `${K}${SEP}`, SEP> : never))
44
- )
45
- )) : never)
46
- }[keyof T];
36
+ export type KeyPaths<T, PrimitiveType = IntrinsicType | IntrinsicType[], PREFIX extends string = '', SEP extends string = '.'> = {
37
+ [K in keyof T]: K extends string
38
+ ? T[K] extends IntrinsicType[] | IntrinsicType | undefined
39
+ ? T[K] extends PrimitiveType
40
+ ? `${PREFIX}${K}`
41
+ : never
42
+ : T[K] extends Any[]
43
+ ? KeyPaths<T[K][number], PrimitiveType, `${K}${SEP}`, SEP>
44
+ : T[K] extends object
45
+ ? KeyPaths<T[K], PrimitiveType, `${K}${SEP}`, SEP>
46
+ : never
47
+ : never;
48
+ }[keyof T];
47
49
 
48
50
  export const TypedObject: {
49
51
  keys<T = unknown, K extends keyof T = keyof T & string>(value: T): K[];
@@ -52,11 +54,9 @@ export const TypedObject: {
52
54
  assign<T extends {}, U extends T>(target: T, ...sources: U[]): U;
53
55
  } & ObjectConstructor = Object;
54
56
 
55
- export const safeAssign = <T extends {}, U extends {}>(target: T, ...sources: U[]): T & U =>
56
- Object.assign(target, ...sources);
57
+ export const safeAssign = <T extends {}, U extends {}>(target: T, ...sources: U[]): T & U => Object.assign(target, ...sources);
57
58
 
58
59
  export function castTo<T>(input: unknown): T {
59
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
60
60
  return input as T;
61
61
  }
62
62
 
@@ -66,16 +66,20 @@ export const asFull = <T>(input: Partial<T>): T => castTo(input);
66
66
  export const asConstructable = <Z = unknown>(input: Class | unknown): { constructor: Class<Z> } => castTo(input);
67
67
 
68
68
  export function classConstruct<T>(cls: Class<T>, args: unknown[] = []): ClassInstance<T> {
69
- const cons: { new(..._args: Any[]): T } = castTo(cls);
69
+ const cons: { new (..._args: Any[]): T } = castTo(cls);
70
70
  return castTo(new cons(...args));
71
71
  }
72
72
 
73
- export const hasFunction = <T>(key: keyof T) => (value: unknown): value is T =>
74
- typeof value === 'object' && value !== null && typeof value[castKey(key)] === 'function';
73
+ export const hasFunction =
74
+ <T>(key: keyof T) =>
75
+ (value: unknown): value is T =>
76
+ typeof value === 'object' && value !== null && typeof value[castKey(key)] === 'function';
75
77
 
76
78
  export const hasToJSON = hasFunction<{ toJSON(): object }>('toJSON');
77
79
 
80
+ // biome-ignore lint/complexity/noUselessTypeConstraint: Unknown behaves slightly differently when being used for an inferred type
78
81
  export function toConcrete<T extends unknown>(): Class<T> {
82
+ // biome-ignore lint/complexity/noArguments: We want to use arguments here
79
83
  return arguments[0];
80
84
  }
81
85
 
@@ -91,4 +95,4 @@ export function getParentClass(cls: Class): Class | undefined {
91
95
  * Get the class from an instance or class
92
96
  */
93
97
  export const getClass = <T = unknown>(value: ClassInstance | Class): Class<T> =>
94
- 'Ⲑid' in value ? castTo(value) : asConstructable<T>(value).constructor;
98
+ 'Ⲑid' in value ? castTo(value) : asConstructable<T>(value).constructor;
package/src/util.ts CHANGED
@@ -1,20 +1,21 @@
1
1
  import timers from 'node:timers/promises';
2
+
2
3
  import { path } from '@travetto/manifest';
3
4
 
4
5
  import { castTo } from './types.ts';
5
6
 
6
7
  type MapFn<T, U> = (value: T, i: number) => U | Promise<U>;
7
- type StackFrame = { message: string, filename: string, line: number, column: number };
8
+ type StackFrame = { message: string; filename: string; line: number; column: number };
8
9
 
9
- const STACK_POSITION_PATTERN = /[(]\s{0,5}(?<filename>[^()]{1,1000}[.]([cm]?[jt]s))([:](?<line>\d{1,10}))?([:](?<column>\d{1,10}))?\s{0,5}[)]/;
10
+ const STACK_POSITION_PATTERN =
11
+ /[(]\s{0,5}(?<filename>[^()]{1,1000}[.]([cm]?[jt]s))([:](?<line>\d{1,10}))?([:](?<column>\d{1,10}))?\s{0,5}[)]/;
10
12
 
11
13
  /**
12
14
  * Grab bag of common utilities
13
15
  */
14
16
  export class Util {
15
-
16
17
  static #match<T, K extends unknown[]>(
17
- rules: { value: T, positive: boolean }[],
18
+ rules: { value: T; positive: boolean }[],
18
19
  compare: (rule: T, ...compareInput: K) => boolean,
19
20
  unmatchedValue: boolean,
20
21
  ...input: K
@@ -28,14 +29,14 @@ export class Util {
28
29
  }
29
30
 
30
31
  static #allowDenyRuleInput<T>(
31
- rule: (string | T | [value: T, positive: boolean] | [value: T]),
32
+ rule: string | T | [value: T, positive: boolean] | [value: T],
32
33
  convert: (inputRule: string) => T
33
- ): { value: T, positive: boolean } {
34
- return typeof rule === 'string' ?
35
- { value: convert(rule.replace(/^!/, '')), positive: !rule.startsWith('!') } :
36
- Array.isArray(rule) ?
37
- { value: rule[0], positive: rule[1] ?? true } :
38
- { value: rule, positive: true };
34
+ ): { value: T; positive: boolean } {
35
+ return typeof rule === 'string'
36
+ ? { value: convert(rule.replace(/^!/, '')), positive: !rule.startsWith('!') }
37
+ : Array.isArray(rule)
38
+ ? { value: rule[0], positive: rule[1] ?? true }
39
+ : { value: rule, positive: true };
39
40
  }
40
41
 
41
42
  /**
@@ -44,10 +45,9 @@ export class Util {
44
45
  */
45
46
  static uuid(length: number = 32): string {
46
47
  const bytes = crypto.getRandomValues(new Uint8Array(Math.ceil(length / 2)));
47
- if (length === 32) { // Make valid uuid-v4
48
- // eslint-disable-next-line no-bitwise
48
+ if (length === 32) {
49
+ // Make valid uuid-v4
49
50
  bytes[6] = (bytes[6] & 0x0f) | 0x40;
50
- // eslint-disable-next-line no-bitwise
51
51
  bytes[8] = (bytes[8] & 0x3f) | 0x80;
52
52
  }
53
53
  return bytes.toHex().substring(0, length);
@@ -59,7 +59,7 @@ export class Util {
59
59
  static mapAsyncIterable<T, U, V, W>(source: AsyncIterable<T>, fn1: MapFn<T, U>, fn2: MapFn<U, V>, fn3: MapFn<V, W>): AsyncIterable<W>;
60
60
  static mapAsyncIterable<T, U, V>(source: AsyncIterable<T>, fn1: MapFn<T, U>, fn2: MapFn<U, V>): AsyncIterable<V>;
61
61
  static mapAsyncIterable<T, U>(source: AsyncIterable<T>, fn: MapFn<T, U>): AsyncIterable<U>;
62
- static async * mapAsyncIterable<T>(input: AsyncIterable<T>, ...fns: MapFn<unknown, unknown>[]): AsyncIterable<unknown> {
62
+ static async *mapAsyncIterable<T>(input: AsyncIterable<T>, ...fns: MapFn<unknown, unknown>[]): AsyncIterable<unknown> {
63
63
  let idx = -1;
64
64
  for await (const item of input) {
65
65
  if (item !== undefined) {
@@ -77,14 +77,14 @@ export class Util {
77
77
  * Non-blocking timeout
78
78
  */
79
79
  static nonBlockingTimeout(time: number): Promise<void> {
80
- return timers.setTimeout(time, undefined, { ref: false }).catch(() => { });
80
+ return timers.setTimeout(time, undefined, { ref: false }).catch(() => {});
81
81
  }
82
82
 
83
83
  /**
84
84
  * Blocking timeout
85
85
  */
86
86
  static blockingTimeout(time: number): Promise<void> {
87
- return timers.setTimeout(time, undefined, { ref: true }).catch(() => { });
87
+ return timers.setTimeout(time, undefined, { ref: true }).catch(() => {});
88
88
  }
89
89
 
90
90
  /**
@@ -104,16 +104,14 @@ export class Util {
104
104
  compare: (rule: T, ...compareInput: K) => boolean,
105
105
  cacheKey?: (...keyInput: K) => string
106
106
  ): (...input: K) => boolean {
107
-
108
- const rawRules = (Array.isArray(rules) ? rules : rules.split(/,/g).map(rule => rule.trim()));
107
+ const rawRules = Array.isArray(rules) ? rules : rules.split(/,/g).map(rule => rule.trim());
109
108
  const convertedRules = rawRules.map(rule => this.#allowDenyRuleInput(rule, convert));
110
109
  const unmatchedValue = !convertedRules.some(rule => rule.positive);
111
110
 
112
111
  if (convertedRules.length) {
113
112
  if (cacheKey) {
114
113
  const cache: Record<string, boolean> = {};
115
- return (...input: K) =>
116
- cache[cacheKey(...input)] ??= this.#match(convertedRules, compare, unmatchedValue, ...input);
114
+ return (...input: K) => (cache[cacheKey(...input)] ??= this.#match(convertedRules, compare, unmatchedValue, ...input));
117
115
  } else {
118
116
  return (...input: K) => this.#match(convertedRules, compare, unmatchedValue, ...input);
119
117
  }
@@ -133,7 +131,7 @@ export class Util {
133
131
  .split('\n')
134
132
  .map(frameText => {
135
133
  const match = STACK_POSITION_PATTERN.exec(frameText);
136
- if (!match || !match.groups) {
134
+ if (!match?.groups) {
137
135
  return undefined;
138
136
  }
139
137
  const { filename, line, column } = match.groups;
package/src/watch.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { CompilerEventPayload, CompilerEventType } from '@travetto/compiler';
2
2
 
3
3
  import { RuntimeError } from './error.ts';
4
- import { Util } from './util.ts';
5
4
  import { RuntimeIndex } from './manifest-index.ts';
6
5
  import { ShutdownManager, type ShutdownReason } from './shutdown.ts';
7
6
  import { castTo } from './types.ts';
7
+ import { Util } from './util.ts';
8
8
 
9
9
  type RetryRunState = {
10
10
  iteration: number;
@@ -17,25 +17,25 @@ type RetryRunConfig = {
17
17
  maxRetries: number;
18
18
  maxRetryWindow: number;
19
19
  signal?: AbortSignal;
20
- onRetry: (state: RetryRunState, config: RetryRunConfig) => (unknown | Promise<unknown>);
20
+ onRetry: (state: RetryRunState, config: RetryRunConfig) => unknown | Promise<unknown>;
21
21
  };
22
22
 
23
23
  /**
24
24
  * Utilities for watching resources
25
25
  */
26
26
  export class WatchUtil {
27
-
28
27
  /** Compute the delay before restarting */
29
28
  static computeRestartDelay(state: RetryRunState, config: RetryRunConfig): number {
30
- return state.result === 'error'
31
- ? config.maxRetryWindow / (config.maxRetries + 1)
32
- : 10;
29
+ return state.result === 'error' ? config.maxRetryWindow / (config.maxRetries + 1) : 10;
33
30
  }
34
31
 
35
32
  /**
36
33
  * Run with restart capability
37
34
  */
38
- static async runWithRetry(run: (state: RetryRunState & { signal: AbortSignal }) => Promise<ShutdownReason>, options?: Partial<RetryRunConfig>): Promise<void> {
35
+ static async runWithRetry(
36
+ run: (state: RetryRunState & { signal: AbortSignal }) => Promise<ShutdownReason>,
37
+ options?: Partial<RetryRunConfig>
38
+ ): Promise<void> {
39
39
  let retryExhausted = false;
40
40
 
41
41
  const state: RetryRunState = {
@@ -48,10 +48,9 @@ export class WatchUtil {
48
48
  maxRetryWindow: 10 * 1000,
49
49
  maxRetries: 10,
50
50
  onRetry: () => Util.nonBlockingTimeout(this.computeRestartDelay(state, config)),
51
- ...options,
51
+ ...options
52
52
  };
53
53
 
54
-
55
54
  outer: while (!ShutdownManager.signal.aborted && !retryExhausted) {
56
55
  if (state.iteration > 0) {
57
56
  await config.onRetry(state, config);
@@ -59,15 +58,18 @@ export class WatchUtil {
59
58
 
60
59
  state.result = await run({ ...state, signal: ShutdownManager.signal }).catch(() => 'error' as const);
61
60
  switch (state.result) {
62
- case 'quit': break outer;
63
- case 'error': state.errorIterations += 1; break;
61
+ case 'quit':
62
+ break outer;
63
+ case 'error':
64
+ state.errorIterations += 1;
65
+ break;
64
66
  case 'restart': {
65
67
  state.startTime = Date.now();
66
68
  state.errorIterations = 0;
67
69
  }
68
70
  }
69
71
 
70
- retryExhausted = (state.errorIterations >= config.maxRetries) || (Date.now() - state.startTime >= config.maxRetryWindow);
72
+ retryExhausted = state.errorIterations >= config.maxRetries || Date.now() - state.startTime >= config.maxRetryWindow;
71
73
  state.iteration += 1;
72
74
  }
73
75
 
@@ -81,25 +83,27 @@ export class WatchUtil {
81
83
  type: K,
82
84
  onChange: (input: T) => unknown,
83
85
  filter?: (input: T) => boolean,
84
- options?: Partial<RetryRunConfig>,
86
+ options?: Partial<RetryRunConfig>
85
87
  ): Promise<void> {
86
88
  const { CompilerClient } = await import('@travetto/compiler/src/server/client.ts');
87
89
  const client = new CompilerClient(RuntimeIndex.manifest, {
88
90
  debug: (...args: unknown[]): void => console.debug(...args),
89
91
  info: (...args: unknown[]): void => console.info(...args),
90
92
  warn: (...args: unknown[]): void => console.warn(...args),
91
- error: (...args: unknown[]): void => console.error(...args),
93
+ error: (...args: unknown[]): void => console.error(...args)
92
94
  });
93
95
 
94
96
  // pre-check
95
- if (!await client.isWatching()) { // If we get here, without a watch
97
+ if (!(await client.isWatching())) {
98
+ // If we get here, without a watch
96
99
  throw new RuntimeError('Compile Server is not running');
97
100
  }
98
101
 
99
102
  void this.runWithRetry(async ({ signal }) => {
100
103
  await client.waitForState(['watch-start'], undefined, signal);
101
104
 
102
- if (!await client.isWatching()) { // If we get here, without a watch
105
+ if (!(await client.isWatching())) {
106
+ // If we get here, without a watch
103
107
  return 'error';
104
108
  } else {
105
109
  for await (const event of client.fetchEvents(type, { signal, enforceIteration: true })) {
@@ -111,4 +115,4 @@ export class WatchUtil {
111
115
  }
112
116
  }, options);
113
117
  }
114
- }
118
+ }
package/support/patch.js CHANGED
@@ -7,16 +7,23 @@ if (process.env.NODE_ENV !== 'production') {
7
7
  }
8
8
 
9
9
  // polyfills
10
- if (!globalThis.Temporal) { // For anyone that doesn't have it
10
+ if (!globalThis.Temporal) {
11
+ // For anyone that doesn't have it
11
12
  void import('temporal-polyfill-lite/global');
12
13
  }
13
14
 
14
15
  Map.prototype.getOrInsert ??= function (key, value) {
15
- return (this.has(key) || this.set(key, value), this.get(key));
16
+ if (!this.has(key)) {
17
+ this.set(key, value);
18
+ }
19
+ return this.get(key);
16
20
  };
17
21
 
18
22
  Map.prototype.getOrInsertComputed ??= function (key, compute) {
19
- return (this.has(key) || this.set(key, compute()), this.get(key));
23
+ if (!this.has(key)) {
24
+ this.set(key, compute());
25
+ }
26
+ return this.get(key);
20
27
  };
21
28
 
22
29
  // Allow for the throwIfNoEntry if on a version of node that is less than 25.7
@@ -27,7 +34,7 @@ if (majorVersion < 25 || (majorVersion === 25 && minorVersion < 7)) {
27
34
  value: (...args) => {
28
35
  const out = og.call(fs, ...args);
29
36
  if (typeof args[1] === 'object' && args[1].throwIfNoEntry === false) {
30
- return out.catch(() => { });
37
+ return out.catch(() => {});
31
38
  }
32
39
  return out;
33
40
  }
@@ -1,7 +1,8 @@
1
1
  import ts from 'typescript';
2
2
 
3
3
  import { CoreUtil, type Import, SystemUtil, type TransformerState } from '@travetto/transformer';
4
- import { type FunctionMetadataTag } from '../../src/function.ts';
4
+
5
+ import type { FunctionMetadataTag } from '../../src/function.ts';
5
6
 
6
7
  const RegisterImportSymbol = Symbol();
7
8
 
@@ -13,7 +14,6 @@ interface MetadataInfo {
13
14
  * Utils for registering function/class metadata at compile time
14
15
  */
15
16
  export class MetadataRegistrationUtil {
16
-
17
17
  static REGISTER_IMPORT = '@travetto/runtime/src/function.ts';
18
18
  static REGISTER_FN = 'registerFunction';
19
19
 
@@ -41,7 +41,8 @@ export class MetadataRegistrationUtil {
41
41
  /**
42
42
  * Register metadata on a function
43
43
  */
44
- static registerFunction(state: TransformerState & MetadataInfo,
44
+ static registerFunction(
45
+ state: TransformerState & MetadataInfo,
45
46
  node: ts.FunctionDeclaration | ts.FunctionExpression,
46
47
  source?: ts.FunctionDeclaration | ts.FunctionExpression | ts.InterfaceDeclaration | ts.TypeAliasDeclaration
47
48
  ): void {
@@ -52,11 +53,7 @@ export class MetadataRegistrationUtil {
52
53
  const metadata = state.factory.createCallExpression(
53
54
  state.createAccess(state[RegisterImportSymbol].identifier, this.REGISTER_FN),
54
55
  [],
55
- [
56
- state.createIdentifier(node.name!.text),
57
- state.getModuleIdentifier(),
58
- state.fromLiteral(tag),
59
- ]
56
+ [state.createIdentifier(node.name!.text), state.getModuleIdentifier(), state.fromLiteral(tag)]
60
57
  );
61
58
  state.addStatements([state.factory.createExpressionStatement(metadata)]);
62
59
  }
@@ -65,10 +62,11 @@ export class MetadataRegistrationUtil {
65
62
  * Register metadata on a class
66
63
  */
67
64
  static registerClass(
68
- state: TransformerState & MetadataInfo, node: ts.ClassDeclaration,
69
- cls: FunctionMetadataTag, methods?: Record<string, FunctionMetadataTag>
65
+ state: TransformerState & MetadataInfo,
66
+ node: ts.ClassDeclaration,
67
+ cls: FunctionMetadataTag,
68
+ methods?: Record<string, FunctionMetadataTag>
70
69
  ): ts.ClassDeclaration {
71
-
72
70
  state[RegisterImportSymbol] ??= state.importFile(this.REGISTER_IMPORT);
73
71
 
74
72
  const name = node.name?.escapedText.toString() ?? '';
@@ -81,24 +79,13 @@ export class MetadataRegistrationUtil {
81
79
  state.getModuleIdentifier(),
82
80
  state.fromLiteral(cls),
83
81
  state.extendObjectLiteral(methods ?? {}),
84
- state.fromLiteral(CoreUtil.isAbstract(node)),
82
+ state.fromLiteral(CoreUtil.isAbstract(node))
85
83
  ]
86
84
  );
87
85
 
88
- return state.factory.updateClassDeclaration(
89
- node,
90
- node.modifiers,
91
- node.name,
92
- node.typeParameters,
93
- node.heritageClauses,
94
- [
95
- state.factory.createClassStaticBlockDeclaration(
96
- state.factory.createBlock([
97
- state.factory.createExpressionStatement(metadata)
98
- ])
99
- ),
100
- ...node.members
101
- ]
102
- );
86
+ return state.factory.updateClassDeclaration(node, node.modifiers, node.name, node.typeParameters, node.heritageClauses, [
87
+ state.factory.createClassStaticBlockDeclaration(state.factory.createBlock([state.factory.createExpressionStatement(metadata)])),
88
+ ...node.members
89
+ ]);
103
90
  }
104
- }
91
+ }
@@ -1,6 +1,6 @@
1
1
  import ts from 'typescript';
2
2
 
3
- import { type TransformerState, TransformerHandler } from '@travetto/transformer';
3
+ import { TransformerHandler, type TransformerState } from '@travetto/transformer';
4
4
 
5
5
  import { MetadataRegistrationUtil } from './transformer/metadata.ts';
6
6
 
@@ -10,7 +10,6 @@ const SRC = '@travetto/runtime/src/types.ts';
10
10
  * Providing support for concrete types
11
11
  */
12
12
  export class ConcreteTransformer {
13
-
14
13
  static {
15
14
  TransformerHandler(this, this.onInterface, 'before', 'interface');
16
15
  TransformerHandler(this, this.onTypeAlias, 'before', 'type');
@@ -25,24 +24,23 @@ export class ConcreteTransformer {
25
24
  const final = typeof name === 'string' ? name : name.getText();
26
25
 
27
26
  const declaration = state.factory.createFunctionDeclaration(
28
- // eslint-disable-next-line no-bitwise
29
27
  state.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Export | ts.ModifierFlags.Const),
30
- undefined, `${final}$Concrete`, [], [], undefined,
28
+ undefined,
29
+ `${final}$Concrete`,
30
+ [],
31
+ [],
32
+ undefined,
31
33
  state.factory.createBlock([])
32
34
  );
33
35
 
34
36
  state.addStatements([
35
37
  declaration,
36
38
  state.factory.createExpressionStatement(
37
- state.factory.createCallExpression(
38
- state.createAccess('Object', 'defineProperty'),
39
- undefined,
40
- [
41
- declaration.name!,
42
- state.fromLiteral('name'),
43
- state.fromLiteral({ value: final })
44
- ]
45
- )
39
+ state.factory.createCallExpression(state.createAccess('Object', 'defineProperty'), undefined, [
40
+ declaration.name!,
41
+ state.fromLiteral('name'),
42
+ state.fromLiteral({ value: final })
43
+ ])
46
44
  )
47
45
  ]);
48
46
 
@@ -72,19 +70,19 @@ export class ConcreteTransformer {
72
70
  }
73
71
 
74
72
  static onToConcreteCall(state: TransformerState, node: ts.CallExpression): typeof node {
75
- if (ts.isIdentifier(node.expression) && node.expression.text === 'toConcrete' && node.typeArguments?.length && node.arguments.length === 0) {
73
+ if (
74
+ ts.isIdentifier(node.expression) &&
75
+ node.expression.text === 'toConcrete' &&
76
+ node.typeArguments?.length &&
77
+ node.arguments.length === 0
78
+ ) {
76
79
  const type = state.resolveType(node.expression);
77
80
  if ('importName' in type && type.importName === SRC) {
78
81
  const [target] = node.typeArguments;
79
- return state.factory.updateCallExpression(
80
- node,
81
- node.expression,
82
- node.typeArguments,
83
- [state.getConcreteType(target)]
84
- );
82
+ return state.factory.updateCallExpression(node, node.expression, node.typeArguments, [state.getConcreteType(target)]);
85
83
  }
86
84
  }
87
85
 
88
86
  return node;
89
87
  }
90
- }
88
+ }
@@ -1,11 +1,11 @@
1
1
  import ts from 'typescript';
2
2
 
3
- import { type TransformerState, LiteralUtil, TransformerHandler } from '@travetto/transformer';
3
+ import { LiteralUtil, TransformerHandler, type TransformerState } from '@travetto/transformer';
4
4
 
5
5
  const CONSOLE_IMPORT = '@travetto/runtime/src/console.ts';
6
6
 
7
7
  type CustomState = TransformerState & {
8
- scope: { type: 'method' | 'class' | 'function', name: string }[];
8
+ scope: { type: 'method' | 'class' | 'function'; name: string }[];
9
9
  imported?: ts.Identifier;
10
10
  };
11
11
 
@@ -21,7 +21,6 @@ const VALID_LEVELS: Record<string, string> = {
21
21
  * Logging support with code-location aware messages.
22
22
  */
23
23
  export class ConsoleLogTransformer {
24
-
25
24
  static {
26
25
  TransformerHandler(this, this.startClassForLog, 'before', 'class');
27
26
  TransformerHandler(this, this.leaveClassForLog, 'after', 'class');
@@ -91,23 +90,18 @@ export class ConsoleLogTransformer {
91
90
  const level = name.escapedText!;
92
91
 
93
92
  if (VALID_LEVELS[level]) {
94
- const identifier = state.imported ??= state.importFile(CONSOLE_IMPORT).identifier;
95
- return state.factory.updateCallExpression(
96
- node,
97
- state.createAccess(identifier, 'log'),
98
- node.typeArguments,
99
- [
100
- LiteralUtil.fromLiteral(state.factory, {
101
- level: state.factory.createStringLiteral(VALID_LEVELS[level]),
102
- import: state.getModuleIdentifier(),
103
- line: state.source.getLineAndCharacterOfPosition(node.getStart(state.source)).line + 1,
104
- scope: state.scope?.map(part => part.name).join(':'),
105
- args: node.arguments.slice(0)
106
- }),
107
- ]
108
- );
93
+ const identifier = (state.imported ??= state.importFile(CONSOLE_IMPORT).identifier);
94
+ return state.factory.updateCallExpression(node, state.createAccess(identifier, 'log'), node.typeArguments, [
95
+ LiteralUtil.fromLiteral(state.factory, {
96
+ level: state.factory.createStringLiteral(VALID_LEVELS[level]),
97
+ import: state.getModuleIdentifier(),
98
+ line: state.source.getLineAndCharacterOfPosition(node.getStart(state.source)).line + 1,
99
+ scope: state.scope?.map(part => part.name).join(':'),
100
+ args: node.arguments.slice(0)
101
+ })
102
+ ]);
109
103
  } else {
110
104
  return node;
111
105
  }
112
106
  }
113
- }
107
+ }
@@ -1,6 +1,6 @@
1
1
  import type ts from 'typescript';
2
2
 
3
- import { type TransformerState, CoreUtil, TransformerHandler } from '@travetto/transformer';
3
+ import { CoreUtil, TransformerHandler, type TransformerState } from '@travetto/transformer';
4
4
 
5
5
  const DebugSymbol = Symbol();
6
6
 
@@ -15,7 +15,6 @@ interface DebugState {
15
15
  * Add debugger-optional statement to methods that should be debuggable
16
16
  */
17
17
  export class DebugEntryTransformer {
18
-
19
18
  static {
20
19
  TransformerHandler(this, this.debugOnEntry, 'before', 'method', ['DebugBreak']);
21
20
  }
@@ -26,7 +25,8 @@ export class DebugEntryTransformer {
26
25
  state[DebugSymbol] = CoreUtil.createAccess(state.factory, imp, 'tryDebugger');
27
26
  }
28
27
 
29
- return state.factory.updateMethodDeclaration(node,
28
+ return state.factory.updateMethodDeclaration(
29
+ node,
30
30
  node.modifiers,
31
31
  node.asteriskToken,
32
32
  node.name,
@@ -34,11 +34,15 @@ export class DebugEntryTransformer {
34
34
  node.typeParameters,
35
35
  node.parameters,
36
36
  node.type,
37
- node.body ? state.factory.updateBlock(node.body, [
38
- state.factory.createIfStatement(state[DebugSymbol]!,
39
- state.factory.createExpressionStatement(state.factory.createIdentifier('debugger'))),
40
- ...node.body.statements
41
- ]) : node.body
37
+ node.body
38
+ ? state.factory.updateBlock(node.body, [
39
+ state.factory.createIfStatement(
40
+ state[DebugSymbol]!,
41
+ state.factory.createExpressionStatement(state.factory.createIdentifier('debugger'))
42
+ ),
43
+ ...node.body.statements
44
+ ])
45
+ : node.body
42
46
  );
43
47
  }
44
- }
48
+ }
@@ -6,7 +6,6 @@ import { TransformerHandler, type TransformerState } from '@travetto/transformer
6
6
  * Dynamic Import Transformer
7
7
  */
8
8
  export class DynamicImportTransformer {
9
-
10
9
  static {
11
10
  TransformerHandler(this, this.onCall, 'before', 'call');
12
11
  }
@@ -25,4 +24,4 @@ export class DynamicImportTransformer {
25
24
  }
26
25
  return node;
27
26
  }
28
- }
27
+ }