Socket
Socket
Sign inDemoInstall

rollup-plugin-dts

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-dts - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

5

CHANGELOG.md

@@ -0,1 +1,6 @@

### 1.3.0 2020-03-11
- support rollup > 2
- correctly output `declare global` and `module "foo"` declarations.
### 1.2.1 2020-01-26

@@ -2,0 +7,0 @@

78

dist/rollup-plugin-dts.js

@@ -74,2 +74,20 @@ 'use strict';

for (const node of this.sourceFile.statements) {
const location = {
start: node.getStart(),
end: node.getEnd(),
};
// Well, this is a big hack:
// For some global `namespace` and `module` declarations, we generate
// some fake IIFE code, so rollup can correctly scan its scope.
// However, rollup will then insert bogus semicolons,
// these `EmptyStatement`s, which are a syntax error and we want to
// remove them. Well, we do that here…
if (ts.isEmptyStatement(node)) {
namespaces.unshift({
name: "",
exports: [],
location,
});
continue;
}
if (ts.isClassDeclaration(node)) {

@@ -84,3 +102,3 @@ itemTypes[node.name.getText()] = "class";

}
else if (ts.isModuleDeclaration(node)) {
else if (ts.isModuleDeclaration(node) && ts.isIdentifier(node.name)) {
itemTypes[node.name.getText()] = "namespace";

@@ -128,6 +146,3 @@ }

exports,
location: {
start: node.getStart(),
end: node.getEnd(),
},
location,
});

@@ -161,14 +176,16 @@ }

}
code += `declare namespace ${ns.name} {\n`;
code += ` export {\n`;
for (const { exportedName, localName } of ns.exports) {
if (exportedName === localName) {
code += ` ${ns.name}_${exportedName} as ${exportedName},\n`;
if (ns.name) {
code += `declare namespace ${ns.name} {\n`;
code += ` export {\n`;
for (const { exportedName, localName } of ns.exports) {
if (exportedName === localName) {
code += ` ${ns.name}_${exportedName} as ${exportedName},\n`;
}
else {
code += ` ${localName} as ${exportedName},\n`;
}
}
else {
code += ` ${localName} as ${exportedName},\n`;
}
code += ` };\n`;
code += `}`;
}
code += ` };\n`;
code += `}`;
code += codeAfter;

@@ -368,2 +385,5 @@ }

if (ts.isPropertyAccessExpression(node)) {
if (ts.isPrivateIdentifier(node.name)) {
throw new UnsupportedSyntaxError(node.name);
}
return withStartEnd({

@@ -559,2 +579,5 @@ type: "MemberExpression",

if (ts.isPropertyAccessExpression(node.expression)) {
if (ts.isPrivateIdentifier(node.name)) {
throw new UnsupportedSyntaxError(node.name);
}
return withStartEnd({

@@ -854,2 +877,5 @@ type: "MemberExpression",

if (stmt.exportClause) {
if (ts.isNamespaceExport(stmt.exportClause)) {
throw new UnsupportedSyntaxError(stmt.exportClause);
}
for (const decl of stmt.exportClause.elements) {

@@ -994,7 +1020,7 @@ const id = decl.propertyName || decl.name;

// we want to keep `declare global` augmentations, and we want to
// to pull in all the things referenced inside.
// pull in all the things referenced inside.
// so for this case, we need to figure out some way so that rollup does
// the right thing and not rename these…
const isGlobalAugmentation = node.flags & ts.NodeFlags.GlobalAugmentation;
if (isGlobalAugmentation) {
if (isGlobalAugmentation || !ts.isIdentifier(node.name)) {
const scope = this.createDeclaration(node);

@@ -1004,6 +1030,2 @@ scope.convertNamespace(node);

}
// istanbul ignore if
if (!ts.isIdentifier(node.name)) {
throw new UnsupportedSyntaxError(node, `namespace name should be an "Identifier"`);
}
this.maybeMarkAsExported(node, node.name);

@@ -1079,2 +1101,5 @@ const scope = this.createDeclaration(node, node.name);

const source = node.moduleSpecifier ? convertExpression(node.moduleSpecifier) : undefined;
if (node.exportClause && ts.isNamespaceExport(node.exportClause)) {
throw new UnsupportedSyntaxError(node.exportClause);
}
if (!node.exportClause) {

@@ -1266,6 +1291,3 @@ this.pushStatement(withStartEnd({

const fixer = new NamespaceFixer(source);
code = Array.from(typeReferences, ref => `/// <reference types="${ref}" />`).join("\n");
if (code) {
code += "\n";
}
code = writeBlock(Array.from(typeReferences, ref => `/// <reference types="${ref}" />`));
code += fixer.fix();

@@ -1276,3 +1298,9 @@ return { code, map: { mappings: "" } };

};
function writeBlock(codes) {
if (codes.length) {
return codes.join("\n") + "\n";
}
return "";
}
exports.default = plugin;
{
"name": "rollup-plugin-dts",
"version": "1.2.1",
"version": "1.3.0",
"description": "An experiment to generate .d.ts rollup files",

@@ -62,18 +62,19 @@ "keywords": [

"@types/d3-drag": "^1.2.3",
"@types/fs-extra": "^8.0.1",
"@types/jest": "^24.9.0",
"@types/node": "^12.12.25",
"@types/react": "^16.9.17",
"@types/estree": "0.0.42",
"@types/fs-extra": "^8.1.0",
"@types/jest": "^25.1.4",
"@types/node": "^13.9.0",
"@types/react": "^16.9.23",
"esm": "^3.2.25",
"fs-extra": "^8.1.0",
"jest": "^24.9.0",
"jest": "^25.1.0",
"prettier": "^1.19.1",
"react": "^16.12.0",
"rollup": "1.29.0",
"ts-jest": "^24.3.0",
"typescript": "3.7.5"
"react": "^16.13.0",
"rollup": "2.0.3",
"ts-jest": "^25.2.1",
"typescript": "3.8.3"
},
"peerDependencies": {
"rollup": "^1.29.0",
"typescript": "^3.7.5"
"rollup": "^2.0.3",
"typescript": "^3.8.3"
},

@@ -80,0 +81,0 @@ "optionalDependencies": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc