@travetto/transformer 5.0.10 → 5.0.11

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 ArcSine Technologies
3
+ Copyright (c) 2020 ArcSine Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/transformer",
3
- "version": "5.0.10",
3
+ "version": "5.0.11",
4
4
  "description": "Functionality for AST transformations, with transformer registration, and general utils",
5
5
  "keywords": [
6
6
  "typescript",
@@ -24,9 +24,9 @@
24
24
  "directory": "module/transformer"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/manifest": "^5.0.9",
28
- "tslib": "^2.8.0",
29
- "typescript": "^5.6.3"
27
+ "@travetto/manifest": "^5.0.10",
28
+ "tslib": "^2.8.1",
29
+ "typescript": "^5.7.2"
30
30
  },
31
31
  "travetto": {
32
32
  "displayName": "Transformation",
package/src/importer.ts CHANGED
@@ -126,8 +126,8 @@ export class ImportManager {
126
126
  }
127
127
 
128
128
  // Allow for node classes to be imported directly
129
- if (/@types\/node/.test(file)) {
130
- file = PackageUtil.resolveImport(file.replace(/.*@types\/node\//, '').replace(D_OR_D_TS_EXT_RE, ''));
129
+ if (/@types\/node\//.test(file)) {
130
+ file = PackageUtil.resolveImport(file.split('@types/node/')[1].replace(D_OR_D_TS_EXT_RE, ''));
131
131
  }
132
132
 
133
133
  if (!D_OR_D_TS_EXT_RE.test(file) && !this.#newImports.has(file)) {
@@ -52,7 +52,8 @@ export class LiteralUtil {
52
52
  } else if (typeof val === 'string') {
53
53
  val = factory.createStringLiteral(val);
54
54
  } else if (typeof val === 'number') {
55
- val = factory.createNumericLiteral(val);
55
+ const res = factory.createNumericLiteral(Math.abs(val));
56
+ val = val < 0 ? factory.createPrefixMinus(res) : res;
56
57
  } else if (typeof val === 'boolean') {
57
58
  val = val ? factory.createTrue() : factory.createFalse();
58
59
  } else if (val instanceof RegExp) {
@@ -107,6 +108,13 @@ export class LiteralUtil {
107
108
  } else {
108
109
  return parseInt(txt, 10);
109
110
  }
111
+ } else if (ts.isPrefixUnaryExpression(val) && val.operator === ts.SyntaxKind.MinusToken && ts.isNumericLiteral(val.operand)) {
112
+ const txt = val.operand.text;
113
+ if (txt.includes('.')) {
114
+ return -parseFloat(txt);
115
+ } else {
116
+ return -parseInt(txt, 10);
117
+ }
110
118
  } else if (val.kind === ts.SyntaxKind.FalseKeyword) {
111
119
  return false;
112
120
  } else if (val.kind === ts.SyntaxKind.TrueKeyword) {