ts-const-value-transformer 0.8.0 → 0.8.1

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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.8.1
4
+
5
+ - Fix to parenthesize expression with multi-line
6
+ - Reduce mappings to only have position changings
7
+ - Minor changes in development environment
8
+
3
9
  ## v0.8.0
4
10
 
5
11
  - Add `cacheResult` option (enable by default but disable by default for webpack loader)
@@ -174,10 +174,17 @@ function visitNodeAndReplaceIfNeeded(node, parent, sourceFile, program, options,
174
174
  else {
175
175
  return node;
176
176
  }
177
- const result = ts.addSyntheticTrailingComment(newNode, ts.SyntaxKind.MultiLineCommentTrivia, ` ${node.getText(sourceFile)} `);
177
+ const originalSource = node.getText(sourceFile);
178
+ const comment = ` ${originalSource.replace(/\/\*/g, ' *').replace(/\*\//g, '* ')} `;
179
+ let result = ts.addSyntheticTrailingComment(newNode, ts.SyntaxKind.MultiLineCommentTrivia, comment);
180
+ newSource = `${newSource} /*${comment}*/`;
181
+ if (/[\r\n]/m.test(originalSource)) {
182
+ result = ts.factory.createParenthesizedExpression(result);
183
+ newSource = `(${newSource})`;
184
+ }
178
185
  ts.setTextRange(result, node);
179
186
  result[SYMBOL_ORIGINAL_NODE_DATA] = [
180
- node.getText(sourceFile),
187
+ originalSource,
181
188
  newSource,
182
189
  node.pos,
183
190
  node.end,
@@ -438,13 +445,7 @@ function printSourceImpl(tsInstance, sourceFile, originalSourceName, mapGenerato
438
445
  function printNode(tsInstance, baseSource, sourceFile, node, posContext, originalSourceName, mapGenerator) {
439
446
  const originalNodeData = node[SYMBOL_ORIGINAL_NODE_DATA];
440
447
  if (originalNodeData) {
441
- let result = originalNodeData[1];
442
- const comments = tsInstance.getSyntheticTrailingComments(node);
443
- if (comments) {
444
- for (const comment of comments) {
445
- result += ` /*${comment.text}*/`;
446
- }
447
- }
448
+ const result = originalNodeData[1];
448
449
  const old = originalNodeData[0];
449
450
  const oldFull = baseSource.substring(originalNodeData[2], originalNodeData[3]);
450
451
  const i = oldFull.lastIndexOf(old);
@@ -452,22 +453,12 @@ function printNode(tsInstance, baseSource, sourceFile, node, posContext, origina
452
453
  const newText = i < 0
453
454
  ? result
454
455
  : oldFull.substring(0, i) + result + oldFull.substring(i + old.length);
455
- if (mapGenerator) {
456
- if (posContext.pos < node.pos) {
457
- addMappingForCurrent();
458
- }
459
- posContext.pos = node.pos;
460
- if (leadingUnchanged > 0) {
461
- addMappingForCurrent();
462
- }
463
- posContext.pos = node.pos + leadingUnchanged;
464
- addMappingForCurrent(old);
465
- }
456
+ posContext.pos = node.pos + leadingUnchanged;
457
+ addMappingForCurrent(old);
466
458
  posContext.diff += result.length - old.length;
467
459
  posContext.pos += old.length;
468
460
  addMappingForCurrent();
469
461
  posContext.pos = node.end;
470
- addMappingForCurrent();
471
462
  return newText;
472
463
  }
473
464
  let output = '';
@@ -479,14 +470,12 @@ function printNode(tsInstance, baseSource, sourceFile, node, posContext, origina
479
470
  if (child.pos > node.pos) {
480
471
  const text = baseSource.substring(node.pos, child.pos);
481
472
  output += text;
482
- addMappingForCurrent();
483
473
  posContext.pos = child.pos;
484
474
  }
485
475
  }
486
476
  else if (child.pos > lastChildPos) {
487
477
  const text = baseSource.substring(lastChildPos, child.pos);
488
478
  output += text;
489
- addMappingForCurrent();
490
479
  posContext.pos = child.pos;
491
480
  }
492
481
  output += printNode(tsInstance, baseSource, sourceFile, child, posContext, originalSourceName, mapGenerator);
@@ -495,29 +484,19 @@ function printNode(tsInstance, baseSource, sourceFile, node, posContext, origina
495
484
  }, void 0);
496
485
  if (!headPrinted) {
497
486
  output = baseSource.substring(node.pos, node.end);
498
- addMappingForCurrent();
499
487
  posContext.pos = node.end;
500
488
  }
501
489
  else if (lastChildPos < node.end) {
502
490
  const text = baseSource.substring(lastChildPos, node.end);
503
491
  output += text;
504
- addMappingForCurrent();
505
492
  posContext.pos = node.end;
506
493
  }
507
- addMappingForCurrent();
508
494
  return output;
509
495
  function addMappingForCurrent(name) {
510
496
  const original = positionToLineAndColumn(sourceFile, posContext.pos, 0);
511
497
  if (original.line !== posContext.lastLine) {
512
498
  posContext.diff = 0;
513
499
  posContext.lastLine = original.line;
514
- if (mapGenerator && original.column > 0) {
515
- mapGenerator.addMapping({
516
- original: { line: original.line, column: 0 },
517
- generated: { line: original.line, column: 0 },
518
- source: originalSourceName,
519
- });
520
- }
521
500
  }
522
501
  if (mapGenerator) {
523
502
  mapGenerator.addMapping({
@@ -1,2 +1,2 @@
1
- declare const _default: "0.8.0";
1
+ declare const _default: "0.8.1";
2
2
  export default _default;
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export default '0.8.0';
1
+ export default '0.8.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-const-value-transformer",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "engines": {
5
5
  "node": ">=20.19.3"
6
6
  },
@@ -90,10 +90,13 @@
90
90
  "version": "node ./tools/updateVersion.mjs ./src/main/version.mts && git add -A ./src/main/version.mts"
91
91
  },
92
92
  "devDependencies": {
93
+ "@babel/preset-typescript": "^7.28.5",
94
+ "@swc/core": "^1.15.10",
93
95
  "@types/jest": "^30.0.0",
94
96
  "@types/node": "~20.19.22",
95
97
  "@typescript-eslint/eslint-plugin": "^8.48.0",
96
98
  "@typescript-eslint/parser": "^8.48.0",
99
+ "babel-loader": "^10.0.0",
97
100
  "eslint": "^9.39.1",
98
101
  "eslint-config-prettier": "^10.1.8",
99
102
  "eslint-plugin-import-x": "^4.16.1",
@@ -103,6 +106,7 @@
103
106
  "memfs": "^4.51.0",
104
107
  "neostandard": "^0.12.2",
105
108
  "prettier": "^3.6.2",
109
+ "swc-loader": "^0.2.7",
106
110
  "ts-jest": "^29.4.5",
107
111
  "ts-loader": "^9.5.4",
108
112
  "ts-patch": "^3.3.0",