detype 1.0.9 → 1.0.10

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.
Files changed (3) hide show
  1. package/dist/cli.js +38 -33
  2. package/dist/index.js +6 -7
  3. package/package.json +12 -12
package/dist/cli.js CHANGED
@@ -57,7 +57,6 @@ function getDefinePropsObject(content) {
57
57
  return "";
58
58
  }
59
59
  async function transform(code, fileName, options = {}) {
60
- var _a, _b, _c, _d, _e;
61
60
  const { prettierOptions, ...removeTypeOptions } = options;
62
61
  const originalCode = code;
63
62
  const originalFileName = fileName;
@@ -66,12 +65,12 @@ async function transform(code, fileName, options = {}) {
66
65
  code = code.replaceAll("\r\n", "\n");
67
66
  if (fileName.endsWith(".vue")) {
68
67
  const parsedVue = (0, import_compiler_sfc.parse)(code);
69
- if (((_a = parsedVue.descriptor.script) == null ? void 0 : _a.lang) !== "ts" && ((_b = parsedVue.descriptor.scriptSetup) == null ? void 0 : _b.lang) !== "ts") {
68
+ if (parsedVue.descriptor.script?.lang !== "ts" && parsedVue.descriptor.scriptSetup?.lang !== "ts") {
70
69
  return originalCode;
71
70
  }
72
71
  let { script: script1, scriptSetup: script2 } = parsedVue.descriptor;
73
- const isContainsDefinePropsType = script2 == null ? void 0 : script2.content.match(/defineProps\s*</m);
74
- const isContainsDefineEmitType = script2 == null ? void 0 : script2.content.match(/defineEmits\s*</m);
72
+ const isContainsDefinePropsType = script2?.content.match(/defineProps\s*</m);
73
+ const isContainsDefineEmitType = script2?.content.match(/defineEmits\s*</m);
75
74
  if (isContainsDefinePropsType || isContainsDefineEmitType) {
76
75
  const { content } = (0, import_compiler_sfc2.compileScript)(parsedVue.descriptor, {
77
76
  id: "xxxxxxx"
@@ -80,7 +79,7 @@ async function transform(code, fileName, options = {}) {
80
79
  propsContent = getDefinePropsObject(content);
81
80
  }
82
81
  if (isContainsDefineEmitType) {
83
- emitsContent = ((_c = content.match(/\semits:\s(\[.*\]?)/m)) == null ? void 0 : _c[1]) || "";
82
+ emitsContent = content.match(/\semits:\s(\[.*\]?)/m)?.[1] || "";
84
83
  }
85
84
  }
86
85
  if (script1 && script2 && script1.loc.start.offset < script2.loc.start.offset) {
@@ -90,14 +89,14 @@ async function transform(code, fileName, options = {}) {
90
89
  code,
91
90
  fileName,
92
91
  script1,
93
- (_d = parsedVue.descriptor.template) == null ? void 0 : _d.ast,
92
+ parsedVue.descriptor.template?.ast,
94
93
  removeTypeOptions
95
94
  );
96
95
  code = await removeTypesFromVueSfcScript(
97
96
  code,
98
97
  fileName,
99
98
  script2,
100
- (_e = parsedVue.descriptor.template) == null ? void 0 : _e.ast,
99
+ parsedVue.descriptor.template?.ast,
101
100
  removeTypeOptions
102
101
  );
103
102
  } else {
@@ -273,7 +272,7 @@ var import_fast_glob = __toESM(require("fast-glob"));
273
272
  // package.json
274
273
  var package_default = {
275
274
  name: "detype",
276
- version: "1.0.9",
275
+ version: "1.0.10",
277
276
  description: "Removes TypeScript type annotations but keeps the formatting",
278
277
  main: "dist/index.js",
279
278
  bin: "detype.js",
@@ -294,27 +293,27 @@ var package_default = {
294
293
  "index.d.ts"
295
294
  ],
296
295
  dependencies: {
297
- "@babel/core": "^7.24.7",
296
+ "@babel/core": "^7.25.2",
298
297
  "@babel/preset-typescript": "^7.24.7",
299
- "@vue/compiler-dom": "^3.4.29",
300
- "@vue/compiler-sfc": "^3.4.29",
298
+ "@babel/traverse": "^7.25.3",
299
+ "@vue/compiler-dom": "^3.4.37",
300
+ "@vue/compiler-sfc": "^3.4.37",
301
301
  "@vuedx/compiler-sfc": "0.7.1",
302
302
  "@vuedx/template-ast-types": "0.7.1",
303
303
  "fast-glob": "^3.3.2",
304
- prettier: "^3.3.2",
304
+ prettier: "^3.3.3",
305
305
  "string.prototype.replaceall": "^1.0.10"
306
306
  },
307
307
  devDependencies: {
308
- "@babel/traverse": "^7.24.7",
309
- "@cyco130/eslint-config": "^3.9.1",
308
+ "@cyco130/eslint-config": "^3.9.4",
310
309
  "@types/babel__core": "^7.20.5",
311
310
  "@types/babel__traverse": "^7.20.6",
312
- "@types/node": "20.14.5",
311
+ "@types/node": "18.19.44",
313
312
  eslint: "^8.57.0",
314
- rimraf: "^5.0.7",
315
- tsup: "^8.1.0",
316
- typescript: "^5.4.5",
317
- vitest: "1.6.0"
313
+ rimraf: "^6.0.1",
314
+ tsup: "^8.2.4",
315
+ typescript: "^5.5.4",
316
+ vitest: "2.0.5"
318
317
  },
319
318
  repository: {
320
319
  type: "git",
@@ -399,14 +398,16 @@ async function cli(...args2) {
399
398
  for (const file of files) {
400
399
  const inputDir = import_node_path.default.dirname(import_node_path.default.relative(input, file));
401
400
  const outputName = inferName(file, import_node_path.default.join(output, inputDir));
402
- removeMagic ? await removeMagicCommentsFromFile(
403
- import_node_path.default.normalize(file),
404
- import_node_path.default.normalize(outputName)
405
- ) : await transformFile(
406
- import_node_path.default.normalize(file),
407
- import_node_path.default.normalize(outputName),
408
- { removeTsComments }
409
- );
401
+ if (removeMagic) {
402
+ await removeMagicCommentsFromFile(
403
+ import_node_path.default.normalize(file),
404
+ import_node_path.default.normalize(outputName)
405
+ );
406
+ } else {
407
+ await transformFile(import_node_path.default.normalize(file), import_node_path.default.normalize(outputName), {
408
+ removeTsComments
409
+ });
410
+ }
410
411
  }
411
412
  return true;
412
413
  }
@@ -437,12 +438,16 @@ async function cli(...args2) {
437
438
  if (outputDir) {
438
439
  await mkdir(import_node_path.default.normalize(outputDir), { recursive: true });
439
440
  }
440
- removeMagic ? await removeMagicCommentsFromFile(
441
- import_node_path.default.normalize(input),
442
- import_node_path.default.normalize(output)
443
- ) : await transformFile(import_node_path.default.normalize(input), import_node_path.default.normalize(output), {
444
- removeTsComments
445
- });
441
+ if (removeMagic) {
442
+ await removeMagicCommentsFromFile(
443
+ import_node_path.default.normalize(input),
444
+ import_node_path.default.normalize(output)
445
+ );
446
+ } else {
447
+ await transformFile(import_node_path.default.normalize(input), import_node_path.default.normalize(output), {
448
+ removeTsComments
449
+ });
450
+ }
446
451
  return true;
447
452
  function inferName(input2, outputDir2) {
448
453
  let output2;
package/dist/index.js CHANGED
@@ -65,7 +65,6 @@ function getDefinePropsObject(content) {
65
65
  return "";
66
66
  }
67
67
  async function transform(code, fileName, options = {}) {
68
- var _a, _b, _c, _d, _e;
69
68
  const { prettierOptions, ...removeTypeOptions } = options;
70
69
  const originalCode = code;
71
70
  const originalFileName = fileName;
@@ -74,12 +73,12 @@ async function transform(code, fileName, options = {}) {
74
73
  code = code.replaceAll("\r\n", "\n");
75
74
  if (fileName.endsWith(".vue")) {
76
75
  const parsedVue = (0, import_compiler_sfc.parse)(code);
77
- if (((_a = parsedVue.descriptor.script) == null ? void 0 : _a.lang) !== "ts" && ((_b = parsedVue.descriptor.scriptSetup) == null ? void 0 : _b.lang) !== "ts") {
76
+ if (parsedVue.descriptor.script?.lang !== "ts" && parsedVue.descriptor.scriptSetup?.lang !== "ts") {
78
77
  return originalCode;
79
78
  }
80
79
  let { script: script1, scriptSetup: script2 } = parsedVue.descriptor;
81
- const isContainsDefinePropsType = script2 == null ? void 0 : script2.content.match(/defineProps\s*</m);
82
- const isContainsDefineEmitType = script2 == null ? void 0 : script2.content.match(/defineEmits\s*</m);
80
+ const isContainsDefinePropsType = script2?.content.match(/defineProps\s*</m);
81
+ const isContainsDefineEmitType = script2?.content.match(/defineEmits\s*</m);
83
82
  if (isContainsDefinePropsType || isContainsDefineEmitType) {
84
83
  const { content } = (0, import_compiler_sfc2.compileScript)(parsedVue.descriptor, {
85
84
  id: "xxxxxxx"
@@ -88,7 +87,7 @@ async function transform(code, fileName, options = {}) {
88
87
  propsContent = getDefinePropsObject(content);
89
88
  }
90
89
  if (isContainsDefineEmitType) {
91
- emitsContent = ((_c = content.match(/\semits:\s(\[.*\]?)/m)) == null ? void 0 : _c[1]) || "";
90
+ emitsContent = content.match(/\semits:\s(\[.*\]?)/m)?.[1] || "";
92
91
  }
93
92
  }
94
93
  if (script1 && script2 && script1.loc.start.offset < script2.loc.start.offset) {
@@ -98,14 +97,14 @@ async function transform(code, fileName, options = {}) {
98
97
  code,
99
98
  fileName,
100
99
  script1,
101
- (_d = parsedVue.descriptor.template) == null ? void 0 : _d.ast,
100
+ parsedVue.descriptor.template?.ast,
102
101
  removeTypeOptions
103
102
  );
104
103
  code = await removeTypesFromVueSfcScript(
105
104
  code,
106
105
  fileName,
107
106
  script2,
108
- (_e = parsedVue.descriptor.template) == null ? void 0 : _e.ast,
107
+ parsedVue.descriptor.template?.ast,
109
108
  removeTypeOptions
110
109
  );
111
110
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "detype",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Removes TypeScript type annotations but keeps the formatting",
5
5
  "main": "dist/index.js",
6
6
  "bin": "detype.js",
@@ -9,27 +9,27 @@
9
9
  "index.d.ts"
10
10
  ],
11
11
  "dependencies": {
12
- "@babel/core": "^7.24.7",
12
+ "@babel/core": "^7.25.2",
13
13
  "@babel/preset-typescript": "^7.24.7",
14
- "@vue/compiler-dom": "^3.4.29",
15
- "@vue/compiler-sfc": "^3.4.29",
14
+ "@babel/traverse": "^7.25.3",
15
+ "@vue/compiler-dom": "^3.4.37",
16
+ "@vue/compiler-sfc": "^3.4.37",
16
17
  "@vuedx/compiler-sfc": "0.7.1",
17
18
  "@vuedx/template-ast-types": "0.7.1",
18
19
  "fast-glob": "^3.3.2",
19
- "prettier": "^3.3.2",
20
+ "prettier": "^3.3.3",
20
21
  "string.prototype.replaceall": "^1.0.10"
21
22
  },
22
23
  "devDependencies": {
23
- "@babel/traverse": "^7.24.7",
24
- "@cyco130/eslint-config": "^3.9.1",
24
+ "@cyco130/eslint-config": "^3.9.4",
25
25
  "@types/babel__core": "^7.20.5",
26
26
  "@types/babel__traverse": "^7.20.6",
27
- "@types/node": "20.14.5",
27
+ "@types/node": "18.19.44",
28
28
  "eslint": "^8.57.0",
29
- "rimraf": "^5.0.7",
30
- "tsup": "^8.1.0",
31
- "typescript": "^5.4.5",
32
- "vitest": "1.6.0"
29
+ "rimraf": "^6.0.1",
30
+ "tsup": "^8.2.4",
31
+ "typescript": "^5.5.4",
32
+ "vitest": "2.0.5"
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",