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.4.1 to 1.4.2

6

CHANGELOG.md

@@ -1,3 +0,7 @@

### 1.4.1 202-05-08
### 1.4.2 2020-05-10
- Reorder same-named declarations.
### 1.4.1 2020-05-08
- Add support for `export * as foo` declarations.

@@ -4,0 +8,0 @@

@@ -929,14 +929,15 @@ 'use strict';

const name = id.getText();
// rollup has problems with functions that are defined twice. For overrides,
// we can just reuse the already declared function, since overrides are
// supposed to be declared close to each other…
// if they are not close to each other, we do have a problem -_-
let scope = this.declarations.get(name);
if (!scope) {
scope = new DeclarationScope({ id, range, transformer: this });
// We have re-ordered and grouped declarations in `reorderStatements`,
// so we can assume same-name statements are next to each other, so we just
// bump the `end` range.
const scope = new DeclarationScope({ id, range, transformer: this });
const existingScope = this.declarations.get(name);
if (existingScope) {
existingScope.declaration.end = range.end;
}
else {
this.pushStatement(scope.declaration);
this.declarations.set(name, scope);
}
scope.declaration.end = range.end;
return scope;
return existingScope || scope;
}

@@ -1138,2 +1139,65 @@ convertStatement(node) {

/**
* Reorder Statements and group them by name.
*
* In JS, there is a 1:1 relationship between *names* and declarations.
*
* In TS however, one *name* can consist of multiple declarations.
*
* Examples are function overrides, and the fact that there is a difference
* between *types* and *values*, which can have the same *name*, but obviously
* different declarations.
*/
function reorderStatements(sourceFile) {
var _a, _b;
// Some statements, such as import/export, etc do not have `names`, but we
// want to render them. So we just assign random names to them, and since
// JS Map iteration works in insertion order, things will work out just fine.
// Additionally, we use the special `"0"` name for things that we want to
// just remove from the code and not render at all.
let nameless = 0;
const names = new Map();
let needsReorder = false;
for (const stmt of sourceFile.statements) {
const name = (_a = getName(stmt)) !== null && _a !== void 0 ? _a : String(++nameless);
if (names.has(name)) {
(_b = names.get(name)) === null || _b === void 0 ? void 0 : _b.push(stmt);
needsReorder = true;
}
else {
names.set(name, [stmt]);
}
}
// avoid re-parsing if there is nothing to re-order
if (!names.has("0") && !needsReorder) {
return sourceFile;
}
names.delete("0");
let input = sourceFile.getFullText();
let code = "";
for (const group of names.values()) {
for (const stmt of group) {
code += input.slice(stmt.pos, stmt.end);
}
}
return ts.createSourceFile(sourceFile.fileName, code, ts.ScriptTarget.Latest, true);
}
function getName(node) {
var _a;
if (ts.isEnumDeclaration(node) ||
ts.isFunctionDeclaration(node) ||
ts.isInterfaceDeclaration(node) ||
ts.isClassDeclaration(node) ||
ts.isTypeAliasDeclaration(node)) {
return (_a = node.name) === null || _a === void 0 ? void 0 : _a.getText();
}
if (ts.isVariableStatement(node)) {
const { declarations } = node.declarationList;
if (declarations.length !== 0 && ts.isIdentifier(declarations[0].name)) {
return declarations[0].name.getText();
}
}
return undefined;
}
const tsx = /\.tsx?$/;

@@ -1171,2 +1235,3 @@ const plugin = (options = {}) => {

function transformFile(input) {
input = reorderStatements(input);
let code = input.getFullText();

@@ -1173,0 +1238,0 @@ const transformer = new Transformer(input);

2

package.json
{
"name": "rollup-plugin-dts",
"version": "1.4.1",
"version": "1.4.2",
"description": "An experiment to generate .d.ts rollup files",

@@ -5,0 +5,0 @@ "keywords": [

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