rolldown-plugin-dts 0.23.0 → 0.23.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/dist/index.mjs +18 -8
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -94,12 +94,17 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
function transform(code, id) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
let file;
|
|
98
|
+
try {
|
|
99
|
+
file = parse(code, {
|
|
100
|
+
plugins: [["typescript", { dts: true }], "decoratorAutoAccessors"],
|
|
101
|
+
sourceType: "module",
|
|
102
|
+
errorRecovery: true,
|
|
103
|
+
createParenthesizedExpressions: true
|
|
104
|
+
});
|
|
105
|
+
} catch (error) {
|
|
106
|
+
throw new Error(`Failed to parse ${id}. This may be caused by a syntax error in the declaration file or a bug in the plugin. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts\n${error}`, { cause: error });
|
|
107
|
+
}
|
|
103
108
|
const { program, comments } = file;
|
|
104
109
|
const typeOnlyIds = [];
|
|
105
110
|
const identifierMap = Object.create(null);
|
|
@@ -216,7 +221,12 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
216
221
|
const ids = typeOnlyMap.get(module);
|
|
217
222
|
if (ids) typeOnlyIds.push(...ids);
|
|
218
223
|
}
|
|
219
|
-
|
|
224
|
+
let file;
|
|
225
|
+
try {
|
|
226
|
+
file = parse(code, { sourceType: "module" });
|
|
227
|
+
} catch (error) {
|
|
228
|
+
throw new Error(`Failed to parse generated code for chunk ${chunk.fileName}. This may be caused by a bug in the plugin. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts\n${error}`, { cause: error });
|
|
229
|
+
}
|
|
220
230
|
const { program } = file;
|
|
221
231
|
program.body = patchTsNamespace(program.body);
|
|
222
232
|
program.body = patchReExport(program.body);
|
|
@@ -391,7 +401,7 @@ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
|
|
|
391
401
|
}
|
|
392
402
|
function importNamespace(node, imported, source, namespaceStmts, identifierMap) {
|
|
393
403
|
const sourceText = source.value.replaceAll(/\W/g, "_");
|
|
394
|
-
const localName = isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`;
|
|
404
|
+
const localName = `_$${isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`}`;
|
|
395
405
|
let local = t.identifier(localName);
|
|
396
406
|
if (namespaceStmts.has(source.value)) local = namespaceStmts.get(source.value).local;
|
|
397
407
|
else namespaceStmts.set(source.value, {
|