🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

tsickle

Package Overview
Dependencies
Maintainers
2
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsickle - npm Package Compare versions

Comparing version

to
0.21.5

8

build/definitions/tsickle_compiler_host.d.ts

@@ -118,2 +118,10 @@ import * as ts from 'typescript';

getCanonicalFileName(fileName: string): string;
getCancellationToken: (() => ts.CancellationToken) | undefined;
getDefaultLibLocation: (() => string) | undefined;
resolveModuleNames: ((moduleNames: string[], containingFile: string) => ts.ResolvedModule[]) | undefined;
resolveTypeReferenceDirectives: ((typeReferenceDirectiveNames: string[], containingFile: string) => ts.ResolvedTypeReferenceDirective[]) | undefined;
getEnvironmentVariable: ((name: string) => string) | undefined;
trace: ((s: string) => void) | undefined;
directoryExists: ((directoryName: string) => boolean) | undefined;
realpath: ((path: string) => string) | undefined;
}

32

build/src/jsdoc.js

@@ -241,12 +241,19 @@ /**

var texts = new Set();
// If any of the tags are optional/rest, then the merged output is optional/rest.
var optional = false;
var restParam = false;
for (var _i = 0, tags_2 = tags; _i < tags_2.length; _i++) {
var tag = tags_2[_i];
if (tag.tagName)
tagNames.add(tag.tagName);
if (tag.parameterName)
parameterNames.add(tag.parameterName);
if (tag.type)
types.add(tag.type);
if (tag.text)
texts.add(tag.text);
var tag_1 = tags_2[_i];
if (tag_1.tagName)
tagNames.add(tag_1.tagName);
if (tag_1.parameterName)
parameterNames.add(tag_1.parameterName);
if (tag_1.type)
types.add(tag_1.type);
if (tag_1.text)
texts.add(tag_1.text);
if (tag_1.optional)
optional = true;
if (tag_1.restParam)
restParam = true;
}

@@ -260,3 +267,8 @@ if (tagNames.size !== 1) {

var text = texts.size > 0 ? Array.from(texts).join(' / ') : undefined;
return { tagName: tagName, parameterName: parameterName, type: type, text: text };
var tag = { tagName: tagName, parameterName: parameterName, type: type, text: text };
if (optional)
tag.optional = true;
if (restParam)
tag.restParam = true;
return tag;
}

@@ -263,0 +275,0 @@ exports.merge = merge;

@@ -45,2 +45,29 @@ "use strict";

this.tsickleSourceMaps = new Map();
// ts.CompilerHost includes a bunch of optional methods. If they're
// present on the delegate host, we want to delegate them.
if (this.delegate.getCancellationToken) {
this.getCancellationToken = this.delegate.getCancellationToken.bind(this.delegate);
}
if (this.delegate.getDefaultLibLocation) {
this.getDefaultLibLocation = this.delegate.getDefaultLibLocation.bind(this.delegate);
}
if (this.delegate.resolveModuleNames) {
this.resolveModuleNames = this.delegate.resolveModuleNames.bind(this.delegate);
}
if (this.delegate.resolveTypeReferenceDirectives) {
this.resolveTypeReferenceDirectives =
this.delegate.resolveTypeReferenceDirectives.bind(this.delegate);
}
if (this.delegate.getEnvironmentVariable) {
this.getEnvironmentVariable = this.delegate.getEnvironmentVariable.bind(this.delegate);
}
if (this.delegate.trace) {
this.trace = this.delegate.trace.bind(this.delegate);
}
if (this.delegate.directoryExists) {
this.directoryExists = this.delegate.directoryExists.bind(this.delegate);
}
if (this.delegate.realpath) {
this.delegate.realpath = this.delegate.realpath.bind(this.delegate);
}
}

@@ -96,3 +123,7 @@ /**

TsickleCompilerHost.prototype.stripAndStoreExistingSourceMap = function (sourceFile) {
if (sourceMapUtils.containsInlineSourceMap(sourceFile.text)) {
// Because tsc doesn't have strict null checks, it can pass us an
// undefined sourceFile, but we can't acknowledge that it does, because
// we have to comply with their interface, which doesn't allow
// undefined as far as we're concerned
if (sourceFile && sourceMapUtils.containsInlineSourceMap(sourceFile.text)) {
var sourceMapJson = sourceMapUtils.extractInlineSourceMap(sourceFile.text);

@@ -99,0 +130,0 @@ var sourceMap_1 = sourceMapUtils.sourceMapTextToGenerator(sourceMapJson);

@@ -223,20 +223,25 @@ /**

// Merge the JSDoc tags for each overloaded parameter.
// Ensure each parameter has a unique name; the merging process can otherwise
// accidentally generate the same parameter name twice.
var paramNames = new Set();
var foundOptional = false;
for (var i = 0; i < maxArgsCount; i++) {
var paramTag = jsdoc.merge(paramTags[i]);
// If any overload marks this param as a ..., mark it ... in the
// merged output.
if (paramTags[i].find(function (t) { return t.restParam === true; }) !== undefined) {
paramTag.restParam = true;
if (paramNames.has(paramTag.parameterName)) {
paramTag.parameterName += i.toString();
}
// If any overload marks this param optional, mark it optional in the
// merged output. Also mark parameters following optional as optional,
paramNames.add(paramTag.parameterName);
// If the tag is optional, mark parameters following optional as optional,
// even if they are not, since Closure restricts this, see
// https://github.com/google/closure-compiler/issues/2314
var optional = paramTags[i].find(function (t) { return t.optional === true; }) !== undefined || foundOptional;
if (!paramTag.restParam && (optional || i >= minArgsCount)) {
if (!paramTag.restParam && (paramTag.optional || foundOptional || i >= minArgsCount)) {
foundOptional = true;
paramTag.type += '=';
paramTag.optional = true;
}
newDoc.push(paramTag);
if (paramTag.restParam) {
// Cannot have any parameters after a rest param.
// Just dump the remaining parameters.
break;
}
}

@@ -1041,30 +1046,35 @@ // Merge the JSDoc tags for each overloaded return.

case ts.SyntaxKind.Identifier:
{
// E.g. "declare namespace foo {"
var name_6 = rewriter_1.getIdentifierText(decl.name);
if (name_6 === undefined)
break;
if (this.isFirstDeclaration(decl)) {
this.emit('/** @const */\n');
this.writeExternsVariable(name_6, namespace, '{}');
}
if (decl.body)
this.visit(decl.body, namespace.concat(name_6));
// E.g. "declare namespace foo {"
var name_6 = rewriter_1.getIdentifierText(decl.name);
if (name_6 === undefined)
break;
if (this.isFirstDeclaration(decl)) {
this.emit('/** @const */\n');
this.writeExternsVariable(name_6, namespace, '{}');
}
if (decl.body)
this.visit(decl.body, namespace.concat(name_6));
break;
case ts.SyntaxKind.StringLiteral:
{
// E.g. "declare module 'foo' {" (note the quotes).
// We still want to emit externs for this module, but
// Closure doesn't really provide a mechanism for
// module-scoped externs. For now, ignore the enclosing
// namespace (because this is declaring a top-level module)
// and emit into a fake namespace.
namespace = ['tsickle_declare_module'];
var name_7 = decl.name.text;
this.emit('/** @const */\n');
this.writeExternsVariable(name_7, namespace, '{}');
if (decl.body)
this.visit(decl.body, namespace.concat(name_7));
}
// E.g. "declare module 'foo' {" (note the quotes).
// We still want to emit externs for this module, but
// Closure doesn't really provide a mechanism for
// module-scoped externs. For now, ignore the enclosing
// namespace (because this is declaring a top-level module)
// and emit into a fake namespace.
// Declare the top-level "tsickle_declare_module".
this.emit('/** @const */\n');
this.writeExternsVariable('tsickle_declare_module', [], '{}');
namespace = ['tsickle_declare_module'];
// Declare the inner "tsickle_declare_module.foo".
var importName = decl.name.text;
this.emit("// Derived from: declare module \"" + importName + "\"\n");
// We also don't care about the actual name of the module ("foo"
// in the above example), except that we want it to not conflict.
importName = importName.replace(/[^A-Za-z]/g, '_');
this.emit('/** @const */\n');
this.writeExternsVariable(importName, namespace, '{}');
// Declare the contents inside the "tsickle_declare_module.foo".
if (decl.body)
this.visit(decl.body, namespace.concat(importName));
break;

@@ -1088,4 +1098,4 @@ default:

var fnDecl = node;
var name_8 = fnDecl.name;
if (!name_8) {
var name_7 = fnDecl.name;
if (!name_7) {
this.error(fnDecl, 'anonymous function in externs');

@@ -1095,3 +1105,3 @@ break;

// Gather up all overloads of this function.
var sym = this.program.getTypeChecker().getSymbolAtLocation(name_8);
var sym = this.program.getTypeChecker().getSymbolAtLocation(name_7);
var decls = sym.declarations.filter(function (d) { return d.kind ===

@@ -1103,3 +1113,3 @@ ts.SyntaxKind.FunctionDeclaration; });

var params = this.emitFunctionType(decls);
this.writeExternsFunction(name_8.getText(), params, namespace);
this.writeExternsFunction(name_7.getText(), params, namespace);
break;

@@ -1230,8 +1240,8 @@ case ts.SyntaxKind.VariableStatement:

if (decl.name.kind === ts.SyntaxKind.Identifier) {
var name_9 = rewriter_1.getIdentifierText(decl.name);
if (exports.closureExternsBlacklist.indexOf(name_9) >= 0)
var name_8 = rewriter_1.getIdentifierText(decl.name);
if (exports.closureExternsBlacklist.indexOf(name_8) >= 0)
return;
this.emitJSDocType(decl);
this.emit('\n');
this.writeExternsVariable(name_9, namespace);
this.writeExternsVariable(name_8, namespace);
}

@@ -1238,0 +1248,0 @@ else {

{
"name": "tsickle",
"version": "0.21.4",
"version": "0.21.5",
"description": "Transpile TypeScript code to JavaScript with Closure annotations.",

@@ -5,0 +5,0 @@ "main": "build/src/tsickle.js",

@@ -261,2 +261,5 @@ /**

let texts = new Set<string>();
// If any of the tags are optional/rest, then the merged output is optional/rest.
let optional = false;
let restParam = false;
for (const tag of tags) {

@@ -267,2 +270,4 @@ if (tag.tagName) tagNames.add(tag.tagName);

if (tag.text) texts.add(tag.text);
if (tag.optional) optional = true;
if (tag.restParam) restParam = true;
}

@@ -278,3 +283,6 @@

const text = texts.size > 0 ? Array.from(texts).join(' / ') : undefined;
return {tagName, parameterName, type, text};
let tag: Tag = {tagName, parameterName, type, text};
if (optional) tag.optional = true;
if (restParam) tag.restParam = true;
return tag;
}

@@ -108,3 +108,31 @@ import * as path from 'path';

private delegate: ts.CompilerHost, private tscOptions: ts.CompilerOptions,
private options: Options, private environment: TsickleHost) {}
private options: Options, private environment: TsickleHost) {
// ts.CompilerHost includes a bunch of optional methods. If they're
// present on the delegate host, we want to delegate them.
if (this.delegate.getCancellationToken) {
this.getCancellationToken = this.delegate.getCancellationToken!.bind(this.delegate);
}
if (this.delegate.getDefaultLibLocation) {
this.getDefaultLibLocation = this.delegate.getDefaultLibLocation!.bind(this.delegate);
}
if (this.delegate.resolveModuleNames) {
this.resolveModuleNames = this.delegate.resolveModuleNames!.bind(this.delegate);
}
if (this.delegate.resolveTypeReferenceDirectives) {
this.resolveTypeReferenceDirectives =
this.delegate.resolveTypeReferenceDirectives!.bind(this.delegate);
}
if (this.delegate.getEnvironmentVariable) {
this.getEnvironmentVariable = this.delegate.getEnvironmentVariable!.bind(this.delegate);
}
if (this.delegate.trace) {
this.trace = this.delegate.trace!.bind(this.delegate);
}
if (this.delegate.directoryExists) {
this.directoryExists = this.delegate.directoryExists!.bind(this.delegate);
}
if (this.delegate.realpath) {
this.delegate.realpath = this.delegate.realpath!.bind(this.delegate);
}
}

@@ -173,3 +201,7 @@ /**

stripAndStoreExistingSourceMap(sourceFile: ts.SourceFile): ts.SourceFile {
if (sourceMapUtils.containsInlineSourceMap(sourceFile.text)) {
// Because tsc doesn't have strict null checks, it can pass us an
// undefined sourceFile, but we can't acknowledge that it does, because
// we have to comply with their interface, which doesn't allow
// undefined as far as we're concerned
if (sourceFile && sourceMapUtils.containsInlineSourceMap(sourceFile.text)) {
const sourceMapJson = sourceMapUtils.extractInlineSourceMap(sourceFile.text);

@@ -323,3 +355,2 @@ const sourceMap = sourceMapUtils.sourceMapTextToGenerator(sourceMapJson);

// Delegate everything else to the original compiler host.
fileExists(fileName: string): boolean {

@@ -356,2 +387,15 @@ return this.delegate.fileExists(fileName);

}
// Optional delegated methods, see constructor
public getCancellationToken: (() => ts.CancellationToken)|undefined;
public getDefaultLibLocation: (() => string)|undefined;
public resolveModuleNames:
((moduleNames: string[], containingFile: string) => ts.ResolvedModule[])|undefined;
public resolveTypeReferenceDirectives:
((typeReferenceDirectiveNames: string[],
containingFile: string) => ts.ResolvedTypeReferenceDirective[])|undefined;
public getEnvironmentVariable: ((name: string) => string)|undefined;
public trace: ((s: string) => void)|undefined;
public directoryExists: ((directoryName: string) => boolean)|undefined;
public realpath: ((path: string) => string)|undefined;
}

@@ -234,20 +234,25 @@ /**

// Merge the JSDoc tags for each overloaded parameter.
// Ensure each parameter has a unique name; the merging process can otherwise
// accidentally generate the same parameter name twice.
let paramNames = new Set();
let foundOptional = false;
for (let i = 0; i < maxArgsCount; i++) {
let paramTag = jsdoc.merge(paramTags[i]);
// If any overload marks this param as a ..., mark it ... in the
// merged output.
if (paramTags[i].find(t => t.restParam === true) !== undefined) {
paramTag.restParam = true;
if (paramNames.has(paramTag.parameterName)) {
paramTag.parameterName += i.toString();
}
// If any overload marks this param optional, mark it optional in the
// merged output. Also mark parameters following optional as optional,
paramNames.add(paramTag.parameterName);
// If the tag is optional, mark parameters following optional as optional,
// even if they are not, since Closure restricts this, see
// https://github.com/google/closure-compiler/issues/2314
const optional = paramTags[i].find(t => t.optional === true) !== undefined || foundOptional;
if (!paramTag.restParam && (optional || i >= minArgsCount)) {
if (!paramTag.restParam && (paramTag.optional || foundOptional || i >= minArgsCount)) {
foundOptional = true;
paramTag.type += '=';
paramTag.optional = true;
}
newDoc.push(paramTag);
if (paramTag.restParam) {
// Cannot have any parameters after a rest param.
// Just dump the remaining parameters.
break;
}
}

@@ -1079,3 +1084,3 @@

switch (decl.name.kind) {
case ts.SyntaxKind.Identifier: {
case ts.SyntaxKind.Identifier:
// E.g. "declare namespace foo {"

@@ -1089,4 +1094,4 @@ let name = getIdentifierText(decl.name as ts.Identifier);

if (decl.body) this.visit(decl.body, namespace.concat(name));
} break;
case ts.SyntaxKind.StringLiteral: {
break;
case ts.SyntaxKind.StringLiteral:
// E.g. "declare module 'foo' {" (note the quotes).

@@ -1098,8 +1103,20 @@ // We still want to emit externs for this module, but

// and emit into a fake namespace.
// Declare the top-level "tsickle_declare_module".
this.emit('/** @const */\n');
this.writeExternsVariable('tsickle_declare_module', [], '{}');
namespace = ['tsickle_declare_module'];
let name = (decl.name as ts.StringLiteral).text;
// Declare the inner "tsickle_declare_module.foo".
let importName = (decl.name as ts.StringLiteral).text;
this.emit(`// Derived from: declare module "${importName}"\n`);
// We also don't care about the actual name of the module ("foo"
// in the above example), except that we want it to not conflict.
importName = importName.replace(/[^A-Za-z]/g, '_');
this.emit('/** @const */\n');
this.writeExternsVariable(name, namespace, '{}');
if (decl.body) this.visit(decl.body, namespace.concat(name));
} break;
this.writeExternsVariable(importName, namespace, '{}');
// Declare the contents inside the "tsickle_declare_module.foo".
if (decl.body) this.visit(decl.body, namespace.concat(importName));
break;
default:

@@ -1106,0 +1123,0 @@ this.errorUnimplementedKind(decl.name, 'externs generation of namespace');

@@ -6,3 +6,2 @@ {

"declaration": true,
"noImplicitAny": true,
"noEmitOnError": true,

@@ -13,2 +12,6 @@ "target": "es5",

"types": ["node", "mocha"],
"noImplicitAny": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"strictNullChecks": true

@@ -15,0 +18,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet