detype 2.0.3 → 2.0.5

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/dist/index.cjs CHANGED
@@ -1,281 +1,218 @@
1
- "use strict";
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
9
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
19
18
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- removeMagicComments: () => removeMagicComments,
34
- removeMagicCommentsFromFile: () => removeMagicCommentsFromFile,
35
- transform: () => transform,
36
- transformFile: () => transformFile
37
- });
38
- module.exports = __toCommonJS(index_exports);
39
-
40
- // src/transform.ts
41
- var import_core = require("@babel/core");
42
- var import_prettier = require("prettier");
43
- var import_compiler_sfc = require("@vuedx/compiler-sfc");
44
- var import_compiler_sfc2 = require("@vue/compiler-sfc");
45
- var import_template_ast_types = require("@vuedx/template-ast-types");
46
- var import_preset_typescript = __toESM(require("@babel/preset-typescript"), 1);
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ let _babel_core = require("@babel/core");
25
+ let prettier = require("prettier");
26
+ let _vuedx_compiler_sfc = require("@vuedx/compiler-sfc");
27
+ let _vue_compiler_sfc = require("@vue/compiler-sfc");
28
+ let _vuedx_template_ast_types = require("@vuedx/template-ast-types");
29
+ let _babel_preset_typescript = require("@babel/preset-typescript");
30
+ _babel_preset_typescript = __toESM(_babel_preset_typescript);
31
+ let node_fs = require("node:fs");
32
+ node_fs = __toESM(node_fs);
33
+ //#region src/transform.ts
47
34
  function getDefinePropsObject(content) {
48
- const matched = /\sprops:\s*\{/m.exec(content);
49
- if (matched) {
50
- const startContentIndex = matched.index + matched[0].length - 1;
51
- let leftBracketCount = 1;
52
- let endContentIndex = startContentIndex + 1;
53
- while (leftBracketCount) {
54
- if (content.charAt(endContentIndex) === "{") {
55
- leftBracketCount++;
56
- } else if (content.charAt(endContentIndex) === "}") {
57
- leftBracketCount--;
58
- }
59
- endContentIndex++;
60
- }
61
- return content.substring(startContentIndex, endContentIndex);
62
- }
63
- return "";
35
+ const matched = /\sprops:\s*\{/m.exec(content);
36
+ if (matched) {
37
+ const startContentIndex = matched.index + matched[0].length - 1;
38
+ let leftBracketCount = 1;
39
+ let endContentIndex = startContentIndex + 1;
40
+ while (leftBracketCount) {
41
+ if (content.charAt(endContentIndex) === "{") leftBracketCount++;
42
+ else if (content.charAt(endContentIndex) === "}") leftBracketCount--;
43
+ endContentIndex++;
44
+ }
45
+ return content.substring(startContentIndex, endContentIndex);
46
+ }
47
+ return "";
64
48
  }
49
+ /**
50
+ * Transform TypeScript code into vanilla JavaScript without affecting the formatting
51
+ * @param code Source coude
52
+ * @param fileName File name for the source
53
+ * @param options Options
54
+ */
65
55
  async function transform(code, fileName, options = {}) {
66
- const { prettierOptions, ...removeTypeOptions } = options;
67
- const originalCode = code;
68
- const originalFileName = fileName;
69
- let propsContent = "";
70
- let emitsContent = "";
71
- code = code.replaceAll("\r\n", "\n");
72
- if (fileName.endsWith(".vue")) {
73
- const parsedVue = (0, import_compiler_sfc.parse)(code);
74
- if (parsedVue.descriptor.script?.lang !== "ts" && parsedVue.descriptor.scriptSetup?.lang !== "ts") {
75
- return originalCode;
76
- }
77
- let { script: script1, scriptSetup: script2 } = parsedVue.descriptor;
78
- const isContainsDefinePropsType = script2?.content.match(/defineProps\s*</m);
79
- const isContainsDefineEmitType = script2?.content.match(/defineEmits\s*</m);
80
- if (isContainsDefinePropsType || isContainsDefineEmitType) {
81
- const { content } = (0, import_compiler_sfc2.compileScript)(parsedVue.descriptor, {
82
- id: "xxxxxxx"
83
- });
84
- if (isContainsDefinePropsType) {
85
- propsContent = getDefinePropsObject(content);
86
- }
87
- if (isContainsDefineEmitType) {
88
- emitsContent = content.match(/\semits:\s(\[.*\]?)/m)?.[1] || "";
89
- }
90
- }
91
- if (script1 && script2 && script1.loc.start.offset < script2.loc.start.offset) {
92
- [script2, script1] = [script1, script2];
93
- }
94
- code = await removeTypesFromVueSfcScript(
95
- code,
96
- fileName,
97
- script1,
98
- parsedVue.descriptor.template?.ast,
99
- removeTypeOptions
100
- );
101
- code = await removeTypesFromVueSfcScript(
102
- code,
103
- fileName,
104
- script2,
105
- parsedVue.descriptor.template?.ast,
106
- removeTypeOptions
107
- );
108
- } else {
109
- code = await removeTypes(code, fileName, removeTypeOptions);
110
- }
111
- if (propsContent) {
112
- code = code.replace("defineProps(", (str) => `${str}${propsContent}`);
113
- }
114
- if (emitsContent) {
115
- code = code.replace("defineEmits(", (str) => `${str}${emitsContent}`);
116
- }
117
- code = await (0, import_prettier.format)(code, {
118
- ...prettierOptions,
119
- filepath: originalFileName
120
- });
121
- return code;
56
+ const { prettierOptions, ...removeTypeOptions } = options;
57
+ const originalCode = code;
58
+ const originalFileName = fileName;
59
+ let propsContent = "";
60
+ let emitsContent = "";
61
+ code = code.replaceAll("\r\n", "\n");
62
+ if (fileName.endsWith(".vue")) {
63
+ const parsedVue = (0, _vuedx_compiler_sfc.parse)(code);
64
+ if (parsedVue.descriptor.script?.lang !== "ts" && parsedVue.descriptor.scriptSetup?.lang !== "ts") return originalCode;
65
+ let { script: script1, scriptSetup: script2 } = parsedVue.descriptor;
66
+ const isContainsDefinePropsType = script2?.content.match(/defineProps\s*</m);
67
+ const isContainsDefineEmitType = script2?.content.match(/defineEmits\s*</m);
68
+ if (isContainsDefinePropsType || isContainsDefineEmitType) {
69
+ const { content } = (0, _vue_compiler_sfc.compileScript)(parsedVue.descriptor, { id: "xxxxxxx" });
70
+ if (isContainsDefinePropsType) propsContent = getDefinePropsObject(content);
71
+ if (isContainsDefineEmitType) emitsContent = content.match(/\semits:\s(\[.*\]?)/m)?.[1] || "";
72
+ }
73
+ if (script1 && script2 && script1.loc.start.offset < script2.loc.start.offset) [script2, script1] = [script1, script2];
74
+ code = await removeTypesFromVueSfcScript(code, fileName, script1, parsedVue.descriptor.template?.ast, removeTypeOptions);
75
+ code = await removeTypesFromVueSfcScript(code, fileName, script2, parsedVue.descriptor.template?.ast, removeTypeOptions);
76
+ } else code = await removeTypes(code, fileName, removeTypeOptions);
77
+ if (propsContent) code = code.replace("defineProps(", (str) => `${str}${propsContent}`);
78
+ if (emitsContent) code = code.replace("defineEmits(", (str) => `${str}${emitsContent}`);
79
+ code = await (0, prettier.format)(code, {
80
+ ...prettierOptions,
81
+ filepath: originalFileName
82
+ });
83
+ return code;
122
84
  }
123
85
  async function removeTypes(code, fileName, options) {
124
- code = code.replace(
125
- /\n\n+/g,
126
- (match) => `
127
- /* @detype: empty-line=${match.length} */
128
- `
129
- );
130
- code = processMagicComments(code);
131
- const removeComments = {
132
- enter(p) {
133
- if (!p.node.leadingComments) return;
134
- for (let i = p.node.leadingComments.length - 1; i >= 0; i--) {
135
- const comment = p.node.leadingComments[i];
136
- if (code.slice(comment.end).match(/^\s*\n\s*\n/) || comment.value.includes("@detype: empty-line")) {
137
- break;
138
- }
139
- comment.value = "@detype: remove-me";
140
- }
141
- }
142
- };
143
- const babelConfig = {
144
- filename: fileName,
145
- retainLines: true,
146
- plugins: [
147
- // Plugin to remove leading comments attached to TypeScript-only constructs
148
- {
149
- name: "detype-comment-remover",
150
- visitor: {
151
- TSTypeAliasDeclaration: removeComments,
152
- TSInterfaceDeclaration: removeComments,
153
- TSDeclareFunction: removeComments,
154
- TSDeclareMethod: removeComments,
155
- TSImportType: removeComments
156
- }
157
- }
158
- ].filter(Boolean),
159
- presets: [import_preset_typescript.default],
160
- generatorOpts: {
161
- shouldPrintComment: (comment) => comment !== "@detype: remove-me" && (!options.removeTsComments || !comment.match(/^\s*(@ts-ignore|@ts-expect-error)/))
162
- }
163
- };
164
- if (options.customizeBabelConfig) {
165
- options.customizeBabelConfig(babelConfig);
166
- }
167
- const babelOutput = await (0, import_core.transformAsync)(code, babelConfig);
168
- if (!babelOutput || babelOutput.code === void 0 || babelOutput.code === null) {
169
- throw new Error("Babel error");
170
- }
171
- return babelOutput.code.replaceAll(/\n\n*/g, "\n").replace(
172
- /\/\* @detype: empty-line=([0-9]+) \*\//g,
173
- (_match, p1) => `
174
- `.repeat(p1 - 2)
175
- );
86
+ code = code.replace(/\n\n+/g, (match) => `\n/* @detype: empty-line=${match.length} */\n`);
87
+ code = processMagicComments(code);
88
+ const removeComments = { enter(p) {
89
+ if (!p.node.leadingComments) return;
90
+ for (let i = p.node.leadingComments.length - 1; i >= 0; i--) {
91
+ const comment = p.node.leadingComments[i];
92
+ if (code.slice(comment.end).match(/^\s*\n\s*\n/) || comment.value.includes("@detype: empty-line")) break;
93
+ comment.value = "@detype: remove-me";
94
+ }
95
+ } };
96
+ const babelConfig = {
97
+ filename: fileName,
98
+ retainLines: true,
99
+ plugins: [{
100
+ name: "detype-comment-remover",
101
+ visitor: {
102
+ TSTypeAliasDeclaration: removeComments,
103
+ TSInterfaceDeclaration: removeComments,
104
+ TSDeclareFunction: removeComments,
105
+ TSDeclareMethod: removeComments,
106
+ TSImportType: removeComments
107
+ }
108
+ }].filter(Boolean),
109
+ presets: [_babel_preset_typescript.default],
110
+ generatorOpts: { shouldPrintComment: (comment) => comment !== "@detype: remove-me" && (!options.removeTsComments || !comment.match(/^\s*(@ts-ignore|@ts-expect-error)/)) }
111
+ };
112
+ if (options.customizeBabelConfig) options.customizeBabelConfig(babelConfig);
113
+ const babelOutput = await (0, _babel_core.transformAsync)(code, babelConfig);
114
+ if (!babelOutput || babelOutput.code === void 0 || babelOutput.code === null) throw new Error("Babel error");
115
+ return babelOutput.code.replaceAll(/\n\n*/g, "\n").replace(/\/\* @detype: empty-line=([0-9]+) \*\//g, (_match, p1) => `\n`.repeat(p1 - 2));
176
116
  }
177
117
  async function removeTypesFromVueSfcScript(code, fileName, script, templateAst, options) {
178
- if (script === null || script.lang !== "ts") return code;
179
- if (script.setup && templateAst) {
180
- const expressions = /* @__PURE__ */ new Set();
181
- (0, import_template_ast_types.traverse)(templateAst, {
182
- enter(node) {
183
- if ((0, import_template_ast_types.isSimpleExpressionNode)(node) && !node.isStatic) {
184
- expressions.add(`[${node.content}]`);
185
- } else if ((0, import_template_ast_types.isComponentNode)(node)) {
186
- expressions.add(`[${node.tag}]`);
187
- }
188
- }
189
- });
190
- script.content += "/* @detype: remove-after-this */" + [...expressions].join(";");
191
- }
192
- let scriptCode = await removeTypes(script.content, fileName + ".ts", options);
193
- const removeAfterIndex = scriptCode.indexOf(
194
- "/* @detype: remove-after-this */"
195
- );
196
- if (removeAfterIndex >= 0) {
197
- scriptCode = scriptCode.slice(0, removeAfterIndex);
198
- }
199
- let before = code.slice(0, script.loc.start.offset);
200
- const after = code.slice(script.loc.end.offset);
201
- const matches = before.match(/\blang\s*=\s*["']ts["']/);
202
- if (matches) {
203
- const lastMatch = matches[matches.length - 1];
204
- const lastMatchIndex = before.lastIndexOf(lastMatch);
205
- before = before.slice(0, lastMatchIndex) + before.slice(lastMatchIndex + lastMatch.length);
206
- }
207
- return before + scriptCode + after;
118
+ if (script === null || script.lang !== "ts") return code;
119
+ if (script.setup && templateAst) {
120
+ const expressions = /* @__PURE__ */ new Set();
121
+ (0, _vuedx_template_ast_types.traverse)(templateAst, { enter(node) {
122
+ if ((0, _vuedx_template_ast_types.isSimpleExpressionNode)(node) && !node.isStatic) expressions.add(`[${node.content}]`);
123
+ else if ((0, _vuedx_template_ast_types.isComponentNode)(node)) expressions.add(`[${node.tag}]`);
124
+ } });
125
+ script.content += "/* @detype: remove-after-this */" + [...expressions].join(";");
126
+ }
127
+ let scriptCode = await removeTypes(script.content, fileName + ".ts", options);
128
+ const removeAfterIndex = scriptCode.indexOf("/* @detype: remove-after-this */");
129
+ if (removeAfterIndex >= 0) scriptCode = scriptCode.slice(0, removeAfterIndex);
130
+ let before = code.slice(0, script.loc.start.offset);
131
+ const after = code.slice(script.loc.end.offset);
132
+ const matches = before.match(/\blang\s*=\s*["']ts["']/);
133
+ if (matches) {
134
+ const lastMatch = matches[matches.length - 1];
135
+ const lastMatchIndex = before.lastIndexOf(lastMatch);
136
+ before = before.slice(0, lastMatchIndex) + before.slice(lastMatchIndex + lastMatch.length);
137
+ }
138
+ return before + scriptCode + after;
208
139
  }
209
140
  function processMagicComments(input) {
210
- const REPLACE_COMMENT = "// @detype: replace\n";
211
- const WITH_COMMENT = "// @detype: with\n";
212
- const END_COMMENT = "// @detype: end\n";
213
- let start = input.indexOf(REPLACE_COMMENT);
214
- while (start >= 0) {
215
- const middle = input.indexOf(WITH_COMMENT, start);
216
- if (middle < 0) return input;
217
- const middleEnd = middle + WITH_COMMENT.length;
218
- const end = input.indexOf(END_COMMENT, middleEnd);
219
- if (end < 0) return input;
220
- const endEnd = end + END_COMMENT.length;
221
- const before = input.slice(0, start);
222
- const newText = input.slice(middleEnd, end).replaceAll(/^\s*\/\//gm, "");
223
- const after = input.slice(endEnd);
224
- input = before + newText + after;
225
- start = input.indexOf(REPLACE_COMMENT, before.length + newText.length);
226
- }
227
- return input;
141
+ const REPLACE_COMMENT = "// @detype: replace\n";
142
+ const WITH_COMMENT = "// @detype: with\n";
143
+ const END_COMMENT = "// @detype: end\n";
144
+ let start = input.indexOf(REPLACE_COMMENT);
145
+ while (start >= 0) {
146
+ const middle = input.indexOf(WITH_COMMENT, start);
147
+ if (middle < 0) return input;
148
+ const middleEnd = middle + 17;
149
+ const end = input.indexOf(END_COMMENT, middleEnd);
150
+ if (end < 0) return input;
151
+ const endEnd = end + 16;
152
+ const before = input.slice(0, start);
153
+ const newText = input.slice(middleEnd, end).replaceAll(/^\s*\/\//gm, "");
154
+ const after = input.slice(endEnd);
155
+ input = before + newText + after;
156
+ start = input.indexOf(REPLACE_COMMENT, before.length + newText.length);
157
+ }
158
+ return input;
228
159
  }
160
+ /**
161
+ * Removes magic comments without performing the TS to JS transform
162
+ * @param code Source coude
163
+ * @param fileName File name for the source
164
+ * @param prettierOptions Options to pass to prettier
165
+ */
229
166
  async function removeMagicComments(code, fileName, prettierOptions) {
230
- const REPLACE_COMMENT = "// @detype: replace\n";
231
- const WITH_COMMENT = "// @detype: with\n";
232
- const END_COMMENT = "// @detype: end\n";
233
- let start = code.indexOf(REPLACE_COMMENT);
234
- let startEnd = start + REPLACE_COMMENT.length;
235
- while (start >= 0) {
236
- const middle = code.indexOf(WITH_COMMENT, start);
237
- if (middle < 0) return code;
238
- const middleEnd = middle + WITH_COMMENT.length;
239
- const end = code.indexOf(END_COMMENT, middleEnd);
240
- if (end < 0) return code;
241
- const endEnd = end + END_COMMENT.length;
242
- const before = code.slice(0, start);
243
- const keptText = code.slice(startEnd, middle);
244
- const after = code.slice(endEnd);
245
- code = before + keptText + after;
246
- start = code.indexOf(REPLACE_COMMENT, before.length + keptText.length);
247
- startEnd = start + REPLACE_COMMENT.length;
248
- }
249
- code = await (0, import_prettier.format)(code, {
250
- ...prettierOptions,
251
- filepath: fileName
252
- });
253
- return code;
167
+ const REPLACE_COMMENT = "// @detype: replace\n";
168
+ const WITH_COMMENT = "// @detype: with\n";
169
+ const END_COMMENT = "// @detype: end\n";
170
+ let start = code.indexOf(REPLACE_COMMENT);
171
+ let startEnd = start + 20;
172
+ while (start >= 0) {
173
+ const middle = code.indexOf(WITH_COMMENT, start);
174
+ if (middle < 0) return code;
175
+ const middleEnd = middle + 17;
176
+ const end = code.indexOf(END_COMMENT, middleEnd);
177
+ if (end < 0) return code;
178
+ const endEnd = end + 16;
179
+ const before = code.slice(0, start);
180
+ const keptText = code.slice(startEnd, middle);
181
+ const after = code.slice(endEnd);
182
+ code = before + keptText + after;
183
+ start = code.indexOf(REPLACE_COMMENT, before.length + keptText.length);
184
+ startEnd = start + 20;
185
+ }
186
+ code = await (0, prettier.format)(code, {
187
+ ...prettierOptions,
188
+ filepath: fileName
189
+ });
190
+ return code;
254
191
  }
255
-
256
- // src/transformFile.ts
257
- var import_node_fs = __toESM(require("fs"), 1);
258
- var import_prettier2 = require("prettier");
259
- var { readFile, writeFile } = import_node_fs.default.promises;
192
+ //#endregion
193
+ //#region src/transformFile.ts
194
+ const { readFile, writeFile } = node_fs.default.promises;
195
+ /**
196
+ * Transform the input file and write the output to another file
197
+ * @param inputFileName
198
+ * @param outputFileName
199
+ */
260
200
  async function transformFile(inputFileName, outputFileName, options = {}) {
261
- const code = await readFile(inputFileName, "utf-8");
262
- const prettierOptions = await (0, import_prettier2.resolveConfig)(inputFileName);
263
- const output = await transform(code, inputFileName, {
264
- prettierOptions,
265
- ...options
266
- });
267
- await writeFile(outputFileName, output, "utf-8");
201
+ await writeFile(outputFileName, await transform(await readFile(inputFileName, "utf-8"), inputFileName, {
202
+ prettierOptions: await (0, prettier.resolveConfig)(inputFileName),
203
+ ...options
204
+ }), "utf-8");
268
205
  }
206
+ /**
207
+ * Remove magic comments from the input file and write the output to another file
208
+ * @param inputFileName
209
+ * @param outputFileName
210
+ */
269
211
  async function removeMagicCommentsFromFile(inputFileName, outputFileName) {
270
- const code = await readFile(inputFileName, "utf-8");
271
- const prettierConfig = await (0, import_prettier2.resolveConfig)(inputFileName);
272
- const output = await removeMagicComments(code, inputFileName, prettierConfig);
273
- await writeFile(outputFileName, output, "utf-8");
212
+ await writeFile(outputFileName, await removeMagicComments(await readFile(inputFileName, "utf-8"), inputFileName, await (0, prettier.resolveConfig)(inputFileName)), "utf-8");
274
213
  }
275
- // Annotate the CommonJS export names for ESM import in node:
276
- 0 && (module.exports = {
277
- removeMagicComments,
278
- removeMagicCommentsFromFile,
279
- transform,
280
- transformFile
281
- });
214
+ //#endregion
215
+ exports.removeMagicComments = removeMagicComments;
216
+ exports.removeMagicCommentsFromFile = removeMagicCommentsFromFile;
217
+ exports.transform = transform;
218
+ exports.transformFile = transformFile;
package/dist/index.d.cts CHANGED
@@ -1,43 +1,44 @@
1
- import { Options } from 'prettier';
2
- export { Options as PrettierOptions } from 'prettier';
3
- import { TransformOptions as TransformOptions$1 } from '@babel/core';
1
+ import { Options as PrettierOptions } from "prettier";
2
+ import { TransformOptions } from "@babel/core";
4
3
 
4
+ //#region src/transform.d.ts
5
5
  interface RemoveTypeOptions {
6
- /** Whether to remove ts-ignore and ts-expect-error comments */
7
- removeTsComments?: boolean;
8
- /** Escape hatch for customizing Babel configuration */
9
- customizeBabelConfig?(config: TransformOptions$1): void;
6
+ /** Whether to remove ts-ignore and ts-expect-error comments */
7
+ removeTsComments?: boolean;
8
+ /** Escape hatch for customizing Babel configuration */
9
+ customizeBabelConfig?(config: TransformOptions): void;
10
10
  }
11
- interface TransformOptions extends RemoveTypeOptions {
12
- /** Prettier options */
13
- prettierOptions?: Options | null;
11
+ interface TransformOptions$1 extends RemoveTypeOptions {
12
+ /** Prettier options */
13
+ prettierOptions?: PrettierOptions | null;
14
14
  }
15
15
  /**
16
- * Transform TypeScript code into vanilla JavaScript without affecting the formatting
17
- * @param code Source coude
18
- * @param fileName File name for the source
19
- * @param options Options
20
- */
21
- declare function transform(code: string, fileName: string, options?: TransformOptions): Promise<string>;
16
+ * Transform TypeScript code into vanilla JavaScript without affecting the formatting
17
+ * @param code Source coude
18
+ * @param fileName File name for the source
19
+ * @param options Options
20
+ */
21
+ declare function transform(code: string, fileName: string, options?: TransformOptions$1): Promise<string>;
22
22
  /**
23
- * Removes magic comments without performing the TS to JS transform
24
- * @param code Source coude
25
- * @param fileName File name for the source
26
- * @param prettierOptions Options to pass to prettier
27
- */
28
- declare function removeMagicComments(code: string, fileName: string, prettierOptions?: Options | null): Promise<string>;
29
-
23
+ * Removes magic comments without performing the TS to JS transform
24
+ * @param code Source coude
25
+ * @param fileName File name for the source
26
+ * @param prettierOptions Options to pass to prettier
27
+ */
28
+ declare function removeMagicComments(code: string, fileName: string, prettierOptions?: PrettierOptions | null): Promise<string>;
29
+ //#endregion
30
+ //#region src/transformFile.d.ts
30
31
  /**
31
- * Transform the input file and write the output to another file
32
- * @param inputFileName
33
- * @param outputFileName
34
- */
32
+ * Transform the input file and write the output to another file
33
+ * @param inputFileName
34
+ * @param outputFileName
35
+ */
35
36
  declare function transformFile(inputFileName: string, outputFileName: string, options?: RemoveTypeOptions): Promise<void>;
36
37
  /**
37
- * Remove magic comments from the input file and write the output to another file
38
- * @param inputFileName
39
- * @param outputFileName
40
- */
38
+ * Remove magic comments from the input file and write the output to another file
39
+ * @param inputFileName
40
+ * @param outputFileName
41
+ */
41
42
  declare function removeMagicCommentsFromFile(inputFileName: string, outputFileName: string): Promise<void>;
42
-
43
- export { removeMagicComments, removeMagicCommentsFromFile, transform, transformFile };
43
+ //#endregion
44
+ export { type PrettierOptions, removeMagicComments, removeMagicCommentsFromFile, transform, transformFile };
package/dist/index.d.ts CHANGED
@@ -1,43 +1,44 @@
1
- import { Options } from 'prettier';
2
- export { Options as PrettierOptions } from 'prettier';
3
- import { TransformOptions as TransformOptions$1 } from '@babel/core';
1
+ import { TransformOptions } from "@babel/core";
2
+ import { Options as PrettierOptions } from "prettier";
4
3
 
4
+ //#region src/transform.d.ts
5
5
  interface RemoveTypeOptions {
6
- /** Whether to remove ts-ignore and ts-expect-error comments */
7
- removeTsComments?: boolean;
8
- /** Escape hatch for customizing Babel configuration */
9
- customizeBabelConfig?(config: TransformOptions$1): void;
6
+ /** Whether to remove ts-ignore and ts-expect-error comments */
7
+ removeTsComments?: boolean;
8
+ /** Escape hatch for customizing Babel configuration */
9
+ customizeBabelConfig?(config: TransformOptions): void;
10
10
  }
11
- interface TransformOptions extends RemoveTypeOptions {
12
- /** Prettier options */
13
- prettierOptions?: Options | null;
11
+ interface TransformOptions$1 extends RemoveTypeOptions {
12
+ /** Prettier options */
13
+ prettierOptions?: PrettierOptions | null;
14
14
  }
15
15
  /**
16
- * Transform TypeScript code into vanilla JavaScript without affecting the formatting
17
- * @param code Source coude
18
- * @param fileName File name for the source
19
- * @param options Options
20
- */
21
- declare function transform(code: string, fileName: string, options?: TransformOptions): Promise<string>;
16
+ * Transform TypeScript code into vanilla JavaScript without affecting the formatting
17
+ * @param code Source coude
18
+ * @param fileName File name for the source
19
+ * @param options Options
20
+ */
21
+ declare function transform(code: string, fileName: string, options?: TransformOptions$1): Promise<string>;
22
22
  /**
23
- * Removes magic comments without performing the TS to JS transform
24
- * @param code Source coude
25
- * @param fileName File name for the source
26
- * @param prettierOptions Options to pass to prettier
27
- */
28
- declare function removeMagicComments(code: string, fileName: string, prettierOptions?: Options | null): Promise<string>;
29
-
23
+ * Removes magic comments without performing the TS to JS transform
24
+ * @param code Source coude
25
+ * @param fileName File name for the source
26
+ * @param prettierOptions Options to pass to prettier
27
+ */
28
+ declare function removeMagicComments(code: string, fileName: string, prettierOptions?: PrettierOptions | null): Promise<string>;
29
+ //#endregion
30
+ //#region src/transformFile.d.ts
30
31
  /**
31
- * Transform the input file and write the output to another file
32
- * @param inputFileName
33
- * @param outputFileName
34
- */
32
+ * Transform the input file and write the output to another file
33
+ * @param inputFileName
34
+ * @param outputFileName
35
+ */
35
36
  declare function transformFile(inputFileName: string, outputFileName: string, options?: RemoveTypeOptions): Promise<void>;
36
37
  /**
37
- * Remove magic comments from the input file and write the output to another file
38
- * @param inputFileName
39
- * @param outputFileName
40
- */
38
+ * Remove magic comments from the input file and write the output to another file
39
+ * @param inputFileName
40
+ * @param outputFileName
41
+ */
41
42
  declare function removeMagicCommentsFromFile(inputFileName: string, outputFileName: string): Promise<void>;
42
-
43
- export { removeMagicComments, removeMagicCommentsFromFile, transform, transformFile };
43
+ //#endregion
44
+ export { type PrettierOptions, removeMagicComments, removeMagicCommentsFromFile, transform, transformFile };