ts-const-value-transformer 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.8.2
4
+
5
+ - Fix to use internal functions to reduce memory usage
6
+
3
7
  ## v0.8.1
4
8
 
5
9
  - Fix to parenthesize expression with multi-line
@@ -295,24 +295,6 @@ function getNameFromElementAccessExpression(node, typeChecker) {
295
295
  }
296
296
  return null;
297
297
  }
298
- function getMemberName(m, tsInstance) {
299
- if (!m || !m.name) {
300
- return '';
301
- }
302
- const name = m.name;
303
- if (tsInstance.isIdentifier(name)) {
304
- return name.escapedText;
305
- }
306
- else if (tsInstance.isPrivateIdentifier(name)) {
307
- return name.escapedText;
308
- }
309
- else if (tsInstance.isStringLiteral(name)) {
310
- return name.text;
311
- }
312
- else {
313
- return '';
314
- }
315
- }
316
298
  function isReadonlyPropertyAccess(a, typeChecker, tsInstance) {
317
299
  const ts = tsInstance;
318
300
  const type = typeChecker.getTypeAtLocation(a.expression);
@@ -323,32 +305,36 @@ function isReadonlyPropertyAccess(a, typeChecker, tsInstance) {
323
305
  return false;
324
306
  }
325
307
  if (type.getFlags() & ts.TypeFlags.Object) {
326
- const dummyTypeNode = typeChecker.typeToTypeNode(type, a, ts.NodeBuilderFlags.NoTruncation);
327
- if (dummyTypeNode && ts.isTypeLiteralNode(dummyTypeNode)) {
328
- for (let i = 0; i < dummyTypeNode.members.length; ++i) {
329
- const m = dummyTypeNode.members[i];
330
- if (m &&
331
- getMemberName(m, ts) === memberName &&
332
- ts.isPropertySignature(m)) {
333
- if (m.modifiers?.some((m) => m.kind === ts.SyntaxKind.ReadonlyKeyword)) {
334
- return true;
335
- }
308
+ const prop = type.getProperty(memberName);
309
+ if (prop) {
310
+ // Use internal but exported function to improve memory performance
311
+ if ('getCheckFlags' in ts &&
312
+ 'CheckFlags' in ts &&
313
+ ts.CheckFlags.Readonly != null) {
314
+ const checkFlags = ts.getCheckFlags(prop);
315
+ if (checkFlags & ts.CheckFlags.Readonly) {
316
+ return true;
336
317
  }
337
318
  }
338
- }
339
- const prop = type.getProperty(memberName);
340
- if (prop && prop.declarations && prop.declarations.length > 0) {
341
- const decl = prop.declarations[0];
342
- if (ts.isPropertySignature(decl) &&
343
- decl.modifiers?.some((m) => m.kind === ts.SyntaxKind.ReadonlyKeyword)) {
344
- return true;
319
+ if ('getDeclarationModifierFlagsFromSymbol' in ts) {
320
+ const modifierFlags = ts.getDeclarationModifierFlagsFromSymbol(prop);
321
+ if (modifierFlags & ts.ModifierFlags.Readonly) {
322
+ return true;
323
+ }
345
324
  }
346
- if (ts.isVariableDeclaration(decl) &&
347
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
348
- decl.parent &&
349
- ts.isVariableDeclarationList(decl.parent) &&
350
- decl.parent.flags & ts.NodeFlags.Const) {
351
- return true;
325
+ if (prop.declarations && prop.declarations.length > 0) {
326
+ const decl = prop.declarations[0];
327
+ if (ts.isPropertySignature(decl) &&
328
+ decl.modifiers?.some((m) => m.kind === ts.SyntaxKind.ReadonlyKeyword)) {
329
+ return true;
330
+ }
331
+ if (ts.isVariableDeclaration(decl) &&
332
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
333
+ decl.parent &&
334
+ ts.isVariableDeclarationList(decl.parent) &&
335
+ decl.parent.flags & ts.NodeFlags.Const) {
336
+ return true;
337
+ }
352
338
  }
353
339
  }
354
340
  }
@@ -1,2 +1,2 @@
1
- declare const _default: "0.8.1";
1
+ declare const _default: "0.8.2";
2
2
  export default _default;
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export default '0.8.1';
1
+ export default '0.8.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-const-value-transformer",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "engines": {
5
5
  "node": ">=20.19.3"
6
6
  },