detype 2.0.3 → 2.0.4

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