Skip to content

Commit

Permalink
Merge pull request #1 from SlicedSilver/upgrade-ts-v5
Browse files Browse the repository at this point in the history
Upgrade Typescript to v5
  • Loading branch information
timocov authored May 20, 2024
2 parents 9e8d742 + 8a639b8 commit e44f264
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "ts-transformer-strip-const-enums",
"version": "1.0.1",
"version": "2.0.0",
"description": "A TypeScript custom transformer which strips const enums if preserveConstEnums is enabled and const enum isn't exported",
"main": "dist/transformer.js",
"repository": {
Expand All @@ -26,19 +26,19 @@
},
"homepage": "https://github.com/timocov/ts-transformer-strip-const-enums",
"peerDependencies": {
"typescript": ">=3.0.0"
"typescript": ">=5.0.0"
},
"devDependencies": {
"@types/chai": "~4.2.11",
"@types/mocha": "~7.0.2",
"@types/node": "~13.13.4",
"chai": "~4.2.0",
"mocha": "~7.1.2",
"@types/chai": "~4.3.16",
"@types/mocha": "~10.0.6",
"@types/node": "~20.12.12",
"chai": "~5.1.1",
"mocha": "~10.4.0",
"npm-run-all": "~4.1.5",
"rimraf": "~3.0.2",
"ts-node": "~8.10.1",
"rimraf": "~5.0.7",
"ts-node": "~10.9.2",
"tslint": "~6.1.2",
"typescript": "~3.8.3"
"typescript": "~5.4.5"
},
"scripts": {
"clean": "rimraf lib/ dist/",
Expand Down
6 changes: 3 additions & 3 deletions src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ function createTransformerFactory(program: ts.Program, options?: Partial<Options
return result.map((symbol: ts.Symbol) => getActualSymbol(symbol));
}

function hasModifier(node: ts.Node, modifier: ts.SyntaxKind): boolean {
return node.modifiers !== undefined && node.modifiers.some((mod: ts.Modifier) => mod.kind === modifier);
function hasModifier(node: ts.EnumDeclaration, modifier: ts.SyntaxKind): boolean {
return node.modifiers !== undefined && node.modifiers.some((mod: ts.ModifierLike) => mod.kind === modifier);
}

if (!compilerOptions.preserveConstEnums) {
Expand Down Expand Up @@ -112,7 +112,7 @@ function createTransformerFactory(program: ts.Program, options?: Partial<Options
const isExportedFromSourceFile = getExportsForSourceFile(node.getSourceFile()).includes(enumSymbol);
const isExportedFromEntries = fullOptions.entrySourceFiles.length === 0 || allExports.has(enumSymbol);
if (!isExportedFromSourceFile || !isExportedFromEntries) {
return ts.createEmptyStatement();
return ts.factory.createEmptyStatement();
}

return node;
Expand Down
7 changes: 4 additions & 3 deletions tests/test-cases/simple/output.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.doSomething = exports.ExportedEnum = exports.ExportedConstEnum = void 0;
;
var ExportedConstEnum;
(function (ExportedConstEnum) {
ExportedConstEnum[ExportedConstEnum["First"] = 0] = "First";
})(ExportedConstEnum = exports.ExportedConstEnum || (exports.ExportedConstEnum = {}));
})(ExportedConstEnum || (exports.ExportedConstEnum = ExportedConstEnum = {}));
var NonExportedEnum;
(function (NonExportedEnum) {
NonExportedEnum[NonExportedEnum["First"] = 0] = "First";
})(NonExportedEnum || (NonExportedEnum = {}));
var ExportedEnum;
(function (ExportedEnum) {
ExportedEnum[ExportedEnum["First"] = 0] = "First";
})(ExportedEnum = exports.ExportedEnum || (exports.ExportedEnum = {}));
})(ExportedEnum || (exports.ExportedEnum = ExportedEnum = {}));
function doSomething() {
console.log(0 /* First */, 0 /* First */, NonExportedEnum.First, ExportedEnum.First);
console.log(0 /* NonExportedConstEnum.First */, 0 /* ExportedConstEnum.First */, NonExportedEnum.First, ExportedEnum.First);
}
exports.doSomething = doSomething;

0 comments on commit e44f264

Please sign in to comment.