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 +4 -0
- package/dist/transform.mjs +27 -41
- package/dist/version.d.mts +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/transform.mjs
CHANGED
|
@@ -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
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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 (
|
|
347
|
-
|
|
348
|
-
decl
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|
}
|
package/dist/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "0.8.
|
|
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
|
+
export default '0.8.2';
|