Socket
Socket
Sign inDemoInstall

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 0.2.0 to 0.2.1

build/definitions/cli_support.d.ts

22

.vscode/launch.json

@@ -24,4 +24,26 @@ {

"outDir": "${workspaceRoot}/build"
},
{
"name": "Run file based tests",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/.bin/_mocha",
"args": [
"--colors",
"--timeout=0",
"./build/test/tsickle_test.js"
],
"cwd": "${workspaceRoot}",
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"console": "internalConsole",
"sourceMaps": true,
"outDir": "${workspaceRoot}/build"
}
]
}

8

.vscode/settings.json
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"**/.git": true,
"build/": true
"node_modules/": true
}
}
"typescript.tsdk": "/Users/alexeagle/Projects/tsickle/node_modules/typescript/lib"
}

@@ -197,3 +197,5 @@ /**

this.emit("/** @nocollapse */\n");
this.emit("static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [\n");
// ctorParameters may contain forward references in the type: field, so wrap in a function
// closure
this.emit("static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n");
for (var _b = 0, _c = this.ctorParameters || []; _b < _c.length; _b++) {

@@ -200,0 +202,0 @@ var param = _c[_b];

@@ -64,3 +64,8 @@ /**

else {
this.emit("var module = {id: '" + moduleId + "'};");
// The `exports = {}` serves as a default export to disable Closure Compiler's error checking
// for mutable exports. That's OK because TS compiler makes sure that consuming code always
// accesses exports through the module object, so mutable exports work.
// It is only inserted in ES6 because we strip `.default` accesses in ES5 mode, which breaks
// when assigning an `exports = {}` object and then later accessing it.
this.emit(" exports = {}; var module = {id: '" + moduleId + "'};");
}

@@ -228,4 +233,7 @@ var pos = 0;

this.namespaceImports.add(varName);
this.emit("var " + varName + " = goog.require('" + modName + "');");
if (!this.moduleVariables.has(modName)) {
if (this.moduleVariables.has(modName)) {
this.emit("var " + varName + " = " + this.moduleVariables.get(modName) + ";");
}
else {
this.emit("var " + varName + " = goog.require('" + modName + "');");
this.moduleVariables.set(modName, varName);

@@ -232,0 +240,0 @@ }

@@ -166,3 +166,3 @@ /**

else {
tags[tags.length - 1].text += ' ' + line.trim();
tags[tags.length - 1].text += '\n ' + line.trim();
}

@@ -169,0 +169,0 @@ }

@@ -282,3 +282,3 @@ /**

/** Emits a type annotation in JSDoc, or {?} if the type is unavailable. */
ClosureRewriter.prototype.emitJSDocType = function (node, additionalDocTag) {
ClosureRewriter.prototype.emitJSDocType = function (node, additionalDocTag, type) {
this.emit(' /**');

@@ -288,3 +288,3 @@ if (additionalDocTag) {

}
this.emit(" @type {" + this.typeToClosure(node) + "} */");
this.emit(" @type {" + this.typeToClosure(node, type) + "} */");
};

@@ -303,2 +303,3 @@ /**

var _this = this;
if (destructuring === void 0) { destructuring = false; }
if (this.options.untyped) {

@@ -313,3 +314,3 @@ return '?';

translator.warn = function (msg) { return _this.debugWarn(context, msg); };
return translator.translate(type, destructuring);
return translator.translate(type, true);
};

@@ -490,2 +491,4 @@ /**

// around this by using two parens. See test_files/coerce.*.
// TODO: the comment is currently dropped from pure assignments due to
// https://github.com/Microsoft/TypeScript/issues/9873
this.emit('((');

@@ -495,2 +498,18 @@ this.writeNode(node);

return true;
case ts.SyntaxKind.NonNullExpression:
var nnexpr = node;
var type = this.program.getTypeChecker().getTypeAtLocation(nnexpr.expression);
if (type.flags & ts.TypeFlags.Union) {
var nonNullUnion = type
.types.filter(function (t) { return (t.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined)) === 0; });
var typeCopy = Object.assign({}, type);
typeCopy.types = nonNullUnion;
type = typeCopy;
}
this.emitJSDocType(nnexpr, undefined, type);
// See comment above.
this.emit('((');
this.writeNode(nnexpr.expression);
this.emit('))');
return true;
default:

@@ -611,4 +630,9 @@ break;

}
this.writeRange(classDecl.getFullStart(), classDecl.getStart());
this.emit(jsdoc.toString(jsDoc));
if (jsDoc.length === 0) {
this.writeRange(classDecl.getFullStart(), classDecl.getStart());
}
else {
this.emit('\n');
this.emit(jsdoc.toString(jsDoc));
}
if (classDecl.members.length > 0) {

@@ -627,4 +651,4 @@ // We must visit all members individually, to strip out any

}
this.writeNode(classDecl.getLastToken());
this.emitTypeAnnotationsHelper(classDecl);
this.writeNode(classDecl.getLastToken());
return true;

@@ -698,3 +722,3 @@ };

var className = rewriter_1.getIdentifierText(classDecl.name);
this.emit('\n\n static _tsickle_typeAnnotationsHelper() {\n');
this.emit("\n\nfunction " + className + "_tsickle_Closure_declarations() {\n");
staticProps.forEach(function (p) { return _this.visitProperty([className], p); });

@@ -704,3 +728,3 @@ var memberNamespace = [className, 'prototype'];

paramProps.forEach(function (p) { return _this.visitProperty(memberNamespace, p); });
this.emit(' }\n');
this.emit("}\n");
};

@@ -750,6 +774,14 @@ Annotator.prototype.propertyName = function (prop) {

// Write a Closure typedef, which involves an unused "var" declaration.
// Note: in the case of an export, we cannot emit a literal "var" because
// TypeScript drops exports that are never assigned to (and Closure
// requires us to not assign to typedef exports). Instead, emit the
// "exports.foo;" line directly in that case.
this.emit("\n/** @typedef {" + this.typeToClosure(node) + "} */\n");
if (node.flags & ts.NodeFlags.Export)
this.emit('export ');
this.emit("var " + node.name.getText() + ": void;\n");
if (node.flags & ts.NodeFlags.Export) {
this.emit('exports.');
}
else {
this.emit('var ');
}
this.emit(node.name.getText() + ";\n");
};

@@ -756,0 +788,0 @@ /** Processes an EnumDeclaration or returns false for ordinary processing. */

@@ -35,44 +35,36 @@ /**

function typeToDebugString(type) {
var debugString = "flags:0x" + type.flags.toString(16);
var basicTypes = [
ts.TypeFlags.Any, ts.TypeFlags.String,
ts.TypeFlags.Number, ts.TypeFlags.Boolean,
ts.TypeFlags.Void, ts.TypeFlags.Undefined,
ts.TypeFlags.Null, ts.TypeFlags.Enum,
ts.TypeFlags.StringLiteral, ts.TypeFlags.BooleanLiteral,
ts.TypeFlags.NumberLiteral, ts.TypeFlags.EnumLiteral,
ts.TypeFlags.TypeParameter, ts.TypeFlags.Class,
ts.TypeFlags.Interface, ts.TypeFlags.Reference,
ts.TypeFlags.Tuple, ts.TypeFlags.Union,
ts.TypeFlags.Intersection, ts.TypeFlags.Anonymous,
ts.TypeFlags.Instantiated, ts.TypeFlags.ESSymbol,
ts.TypeFlags.ThisType, ts.TypeFlags.ObjectLiteralPatternWithComputedProperties,
ts.TypeFlags.Any,
ts.TypeFlags.String,
ts.TypeFlags.Number,
ts.TypeFlags.Boolean,
ts.TypeFlags.Enum,
ts.TypeFlags.StringLiteral,
ts.TypeFlags.NumberLiteral,
ts.TypeFlags.BooleanLiteral,
ts.TypeFlags.EnumLiteral,
ts.TypeFlags.ESSymbol,
ts.TypeFlags.Void,
ts.TypeFlags.Undefined,
ts.TypeFlags.Null,
ts.TypeFlags.Never,
ts.TypeFlags.TypeParameter,
ts.TypeFlags.Class,
ts.TypeFlags.Interface,
ts.TypeFlags.Reference,
ts.TypeFlags.Tuple,
ts.TypeFlags.Union,
ts.TypeFlags.Intersection,
ts.TypeFlags.Anonymous,
ts.TypeFlags.Instantiated,
ts.TypeFlags.ThisType,
ts.TypeFlags.ObjectLiteralPatternWithComputedProperties,
];
var names = [];
for (var _i = 0, basicTypes_1 = basicTypes; _i < basicTypes_1.length; _i++) {
var flag = basicTypes_1[_i];
if ((type.flags & flag) !== 0) {
names.push(ts.TypeFlags[flag]);
debugString += " " + ts.TypeFlags[flag];
}
}
// combinedTypes are TypeFlags that represent combined values.
// For example, NumberLike = Number|Enum.
var combinedTypes = [
ts.TypeFlags.StringLike,
ts.TypeFlags.NumberLike,
ts.TypeFlags.ObjectType,
ts.TypeFlags.UnionOrIntersection,
ts.TypeFlags.StructuredType,
];
var features = [];
for (var _a = 0, combinedTypes_1 = combinedTypes; _a < combinedTypes_1.length; _a++) {
var flag = combinedTypes_1[_a];
if ((type.flags & flag) !== 0) {
features.push(ts.TypeFlags[flag]);
}
}
var debugString = "flags:0x" + type.flags.toString(16);
debugString += ' ' + names.join(' ');
if (features.length > 0) {
debugString += " features:" + features.join(',');
}
if (type.symbol && type.symbol.name !== '__type') {

@@ -88,4 +80,43 @@ debugString += " symbol.name:" + JSON.stringify(type.symbol.name);

function symbolToDebugString(sym) {
var debugString = JSON.stringify(sym.name) + " " + sym.flags.toString(16);
return "{sym: " + debugString + "}";
var debugString = JSON.stringify(sym.name) + " flags:0x" + sym.flags.toString(16);
var symbolFlags = [
ts.SymbolFlags.FunctionScopedVariable,
ts.SymbolFlags.BlockScopedVariable,
ts.SymbolFlags.Property,
ts.SymbolFlags.EnumMember,
ts.SymbolFlags.Function,
ts.SymbolFlags.Class,
ts.SymbolFlags.Interface,
ts.SymbolFlags.ConstEnum,
ts.SymbolFlags.RegularEnum,
ts.SymbolFlags.ValueModule,
ts.SymbolFlags.NamespaceModule,
ts.SymbolFlags.TypeLiteral,
ts.SymbolFlags.ObjectLiteral,
ts.SymbolFlags.Method,
ts.SymbolFlags.Constructor,
ts.SymbolFlags.GetAccessor,
ts.SymbolFlags.SetAccessor,
ts.SymbolFlags.Signature,
ts.SymbolFlags.TypeParameter,
ts.SymbolFlags.TypeAlias,
ts.SymbolFlags.ExportValue,
ts.SymbolFlags.ExportType,
ts.SymbolFlags.ExportNamespace,
ts.SymbolFlags.Alias,
ts.SymbolFlags.Instantiated,
ts.SymbolFlags.Merged,
ts.SymbolFlags.Transient,
ts.SymbolFlags.Prototype,
ts.SymbolFlags.SyntheticProperty,
ts.SymbolFlags.Optional,
ts.SymbolFlags.ExportStar,
];
for (var _i = 0, symbolFlags_1 = symbolFlags; _i < symbolFlags_1.length; _i++) {
var flag = symbolFlags_1[_i];
if ((sym.flags & flag) !== 0) {
debugString += " " + ts.SymbolFlags[flag];
}
}
return debugString;
}

@@ -155,3 +186,2 @@ exports.symbolToDebugString = symbolToDebugString;

var _this = this;
if (notNull === void 0) { notNull = false; }
// NOTE: type.flags is a single value for primitive types, but sometimes a

@@ -197,3 +227,3 @@ // bitwise 'or' of some values for more complex types. We use a switch

}
return this.symbolToString(type.symbol);
return notNullPrefix + this.symbolToString(type.symbol);
}

@@ -221,3 +251,3 @@ else if (type.flags & ts.TypeFlags.Interface) {

}
return this.symbolToString(type.symbol);
return notNullPrefix + this.symbolToString(type.symbol);
}

@@ -241,7 +271,7 @@ else if (type.flags & ts.TypeFlags.Reference) {

}
typeStr += notNullPrefix + this.translate(referenceType.target);
typeStr += this.translate(referenceType.target, notNull);
}
if (referenceType.typeArguments) {
var params = referenceType.typeArguments.map(function (t) { return _this.translate(t, notNull); });
typeStr += isTuple ? "Array" : "<" + params.join(', ') + ">";
var params = referenceType.typeArguments.map(function (t) { return _this.translate(t, true); });
typeStr += isTuple ? notNullPrefix + "Array" : "<" + params.join(', ') + ">";
}

@@ -260,3 +290,3 @@ return typeStr;

if (type.symbol.flags === ts.SymbolFlags.TypeLiteral) {
return notNullPrefix + this.translateTypeLiteral(type);
return this.translateTypeLiteral(type, notNull);
}

@@ -275,3 +305,3 @@ else if (type.symbol.flags === ts.SymbolFlags.Function ||

var unionType = type;
var parts_1 = unionType.types.map(function (t) { return _this.translate(t); });
var parts_1 = unionType.types.map(function (t) { return _this.translate(t, true); });
// In union types that include boolean literal and other literals can

@@ -287,3 +317,9 @@ // end up repeating the same closure type. For example: true | boolean

};
TypeTranslator.prototype.translateTypeLiteral = function (type) {
/**
* translateTypeLiteral translates a ts.SymbolFlags.TypeLiteral type, which
* is the anonymous type encountered in e.g.
* let x: {a: number};
*/
TypeTranslator.prototype.translateTypeLiteral = function (type, notNull) {
var notNullPrefix = notNull ? '!' : '';
// Avoid infinite loops on recursive types.

@@ -304,2 +340,12 @@ // It would be nice to just emit the name of the recursive type here,

}
// special-case construct signatures.
var ctors = type.getConstructSignatures();
if (ctors.length) {
// TODO(martinprobst): this does not support additional properties defined on constructors
// (not expressible in Closure), nor multiple constructors (same).
var params = this.convertParams(ctors[0]);
var paramsStr = params.length ? (', ' + params.join(', ')) : '';
var constructedType = this.translate(ctors[0].getReturnType(), false);
return "function(new: " + constructedType + paramsStr + "): ?";
}
for (var _i = 0, _a = Object.keys(type.symbol.members); _i < _a.length; _i++) {

@@ -316,7 +362,4 @@ var field = _a[_i];

var member = type.symbol.members[field];
var isOptional = member.flags & ts.SymbolFlags.Optional;
var memberType = this.translate(this.typeChecker.getTypeOfSymbolAtLocation(member, this.node));
if (isOptional) {
memberType = "(" + memberType + "|undefined)";
}
// optional members are handled by the type including |undefined in a union type.
var memberType = this.translate(this.typeChecker.getTypeOfSymbolAtLocation(member, this.node), true);
fields.push(field + ": " + memberType);

@@ -344,5 +387,5 @@ }

this.warn('unknown index key type');
return "Object<?,?>";
return notNullPrefix + "Object<?,?>";
}
return "Object<" + keyType + "," + this.translate(valType) + ">";
return notNullPrefix + ("Object<" + keyType + "," + this.translate(valType, true) + ">");
}

@@ -352,3 +395,3 @@ else if (!callable && !indexable) {

// TODO(evanm): revisit this if it is a problem.
return 'Object';
return notNullPrefix + 'Object';
}

@@ -365,9 +408,5 @@ }

TypeTranslator.prototype.signatureToClosure = function (sig) {
var params = [];
for (var _i = 0, _a = sig.parameters; _i < _a.length; _i++) {
var param = _a[_i];
params.push(this.translate(this.typeChecker.getTypeOfSymbolAtLocation(param, this.node)));
}
var params = this.convertParams(sig);
var typeStr = "function(" + params.join(', ') + ")";
var retType = this.translate(this.typeChecker.getReturnTypeOfSignature(sig));
var retType = this.translate(this.typeChecker.getReturnTypeOfSignature(sig), true);
if (retType) {

@@ -378,2 +417,9 @@ typeStr += ": " + retType;

};
TypeTranslator.prototype.convertParams = function (sig) {
var _this = this;
return sig.parameters.map(function (param) {
var paramType = _this.typeChecker.getTypeOfSymbolAtLocation(param, _this.node);
return _this.translate(paramType, true);
});
};
TypeTranslator.prototype.warn = function (msg) {

@@ -380,0 +426,0 @@ // By default, warn() does nothing. The caller will overwrite this

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

@@ -34,3 +34,3 @@ "main": "build/src/tsickle.js",

"glob": "^7.0.0",
"google-closure-compiler": "^20160315.2.0",
"google-closure-compiler": "^20161024.1.0",
"gulp": "^3.8.11",

@@ -37,0 +37,0 @@ "gulp-clang-format": "^1.0.22",

@@ -72,3 +72,8 @@ # Tsickle - TypeScript to Closure Annotator [![Build Status](https://travis-ci.org/angular/tsickle.svg?branch=master)](https://travis-ci.org/angular/tsickle)

### Environment variables
Export the environment variable `UPDATE_GOLDENS=1` to have the test suite
rewrite the golden files when you run it.
Export the environment variable `TEST_FILTER`, a regex, to limit the end-to-end
tests (found in `test_files/...`) run tests with a name matching the regex.

@@ -209,4 +209,6 @@ /**

this.emit(`/** @nocollapse */\n`);
// ctorParameters may contain forward references in the type: field, so wrap in a function
// closure
this.emit(
`static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [\n`);
`static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n`);
for (let param of this.ctorParameters || []) {

@@ -213,0 +215,0 @@ if (!param) {

@@ -66,3 +66,8 @@ /**

} else {
this.emit(`var module = {id: '${moduleId}'};`);
// The `exports = {}` serves as a default export to disable Closure Compiler's error checking
// for mutable exports. That's OK because TS compiler makes sure that consuming code always
// accesses exports through the module object, so mutable exports work.
// It is only inserted in ES6 because we strip `.default` accesses in ES5 mode, which breaks
// when assigning an `exports = {}` object and then later accessing it.
this.emit(` exports = {}; var module = {id: '${moduleId}'};`);
}

@@ -230,4 +235,6 @@

if (isNamespaceImport) this.namespaceImports.add(varName);
this.emit(`var ${varName} = goog.require('${modName}');`);
if (!this.moduleVariables.has(modName)) {
if (this.moduleVariables.has(modName)) {
this.emit(`var ${varName} = ${this.moduleVariables.get(modName)};`);
} else {
this.emit(`var ${varName} = goog.require('${modName}');`);
this.moduleVariables.set(modName, varName);

@@ -234,0 +241,0 @@ }

@@ -187,3 +187,3 @@ /**

} else {
tags[tags.length - 1].text += ' ' + line.trim();
tags[tags.length - 1].text += '\n ' + line.trim();
}

@@ -190,0 +190,0 @@ }

@@ -313,3 +313,3 @@ /**

/** Emits a type annotation in JSDoc, or {?} if the type is unavailable. */
emitJSDocType(node: ts.Node, additionalDocTag?: string) {
emitJSDocType(node: ts.Node, additionalDocTag?: string, type?: ts.Type) {
this.emit(' /**');

@@ -319,3 +319,3 @@ if (additionalDocTag) {

}
this.emit(` @type {${this.typeToClosure(node)}} */`);
this.emit(` @type {${this.typeToClosure(node, type)}} */`);
}

@@ -333,3 +333,3 @@

*/
typeToClosure(context: ts.Node, type?: ts.Type, destructuring?: boolean): string {
typeToClosure(context: ts.Node, type?: ts.Type, destructuring = false): string {
if (this.options.untyped) {

@@ -345,3 +345,3 @@ return '?';

translator.warn = msg => this.debugWarn(context, msg);
return translator.translate(type, destructuring);
return translator.translate(type, true);
}

@@ -539,2 +539,4 @@

// around this by using two parens. See test_files/coerce.*.
// TODO: the comment is currently dropped from pure assignments due to
// https://github.com/Microsoft/TypeScript/issues/9873
this.emit('((');

@@ -544,2 +546,20 @@ this.writeNode(node);

return true;
case ts.SyntaxKind.NonNullExpression:
const nnexpr = node as ts.NonNullExpression;
let type = this.program.getTypeChecker().getTypeAtLocation(nnexpr.expression);
if (type.flags & ts.TypeFlags.Union) {
const nonNullUnion =
(type as ts.UnionType)
.types.filter(
t => (t.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined)) === 0);
const typeCopy = Object.assign({}, type as ts.UnionType);
typeCopy.types = nonNullUnion;
type = typeCopy;
}
this.emitJSDocType(nnexpr, undefined, type);
// See comment above.
this.emit('((');
this.writeNode(nnexpr.expression);
this.emit('))');
return true;
default:

@@ -666,4 +686,8 @@ break;

}
this.writeRange(classDecl.getFullStart(), classDecl.getStart());
this.emit(jsdoc.toString(jsDoc));
if (jsDoc.length === 0) {
this.writeRange(classDecl.getFullStart(), classDecl.getStart());
} else {
this.emit('\n');
this.emit(jsdoc.toString(jsDoc));
}
if (classDecl.members.length > 0) {

@@ -680,4 +704,4 @@ // We must visit all members individually, to strip out any

}
this.writeNode(classDecl.getLastToken());
this.emitTypeAnnotationsHelper(classDecl);
this.writeNode(classDecl.getLastToken());
return true;

@@ -751,3 +775,3 @@ }

this.emit('\n\n static _tsickle_typeAnnotationsHelper() {\n');
this.emit(`\n\nfunction ${className}_tsickle_Closure_declarations() {\n`);
staticProps.forEach(p => this.visitProperty([className], p));

@@ -757,3 +781,3 @@ let memberNamespace = [className, 'prototype'];

paramProps.forEach((p) => this.visitProperty(memberNamespace, p));
this.emit(' }\n');
this.emit(`}\n`);
}

@@ -804,5 +828,13 @@

// Write a Closure typedef, which involves an unused "var" declaration.
// Note: in the case of an export, we cannot emit a literal "var" because
// TypeScript drops exports that are never assigned to (and Closure
// requires us to not assign to typedef exports). Instead, emit the
// "exports.foo;" line directly in that case.
this.emit(`\n/** @typedef {${this.typeToClosure(node)}} */\n`);
if (node.flags & ts.NodeFlags.Export) this.emit('export ');
this.emit(`var ${node.name.getText()}: void;\n`);
if (node.flags & ts.NodeFlags.Export) {
this.emit('exports.');
} else {
this.emit('var ');
}
this.emit(`${node.name.getText()};\n`);
}

@@ -809,0 +841,0 @@

@@ -37,45 +37,37 @@ /**

export function typeToDebugString(type: ts.Type): string {
let debugString = `flags:0x${type.flags.toString(16)}`;
const basicTypes: ts.TypeFlags[] = [
ts.TypeFlags.Any, ts.TypeFlags.String,
ts.TypeFlags.Number, ts.TypeFlags.Boolean,
ts.TypeFlags.Void, ts.TypeFlags.Undefined,
ts.TypeFlags.Null, ts.TypeFlags.Enum,
ts.TypeFlags.StringLiteral, ts.TypeFlags.BooleanLiteral,
ts.TypeFlags.NumberLiteral, ts.TypeFlags.EnumLiteral,
ts.TypeFlags.TypeParameter, ts.TypeFlags.Class,
ts.TypeFlags.Interface, ts.TypeFlags.Reference,
ts.TypeFlags.Tuple, ts.TypeFlags.Union,
ts.TypeFlags.Intersection, ts.TypeFlags.Anonymous,
ts.TypeFlags.Instantiated, ts.TypeFlags.ESSymbol,
ts.TypeFlags.ThisType, ts.TypeFlags.ObjectLiteralPatternWithComputedProperties,
ts.TypeFlags.Any,
ts.TypeFlags.String,
ts.TypeFlags.Number,
ts.TypeFlags.Boolean,
ts.TypeFlags.Enum,
ts.TypeFlags.StringLiteral,
ts.TypeFlags.NumberLiteral,
ts.TypeFlags.BooleanLiteral,
ts.TypeFlags.EnumLiteral,
ts.TypeFlags.ESSymbol,
ts.TypeFlags.Void,
ts.TypeFlags.Undefined,
ts.TypeFlags.Null,
ts.TypeFlags.Never,
ts.TypeFlags.TypeParameter,
ts.TypeFlags.Class,
ts.TypeFlags.Interface,
ts.TypeFlags.Reference,
ts.TypeFlags.Tuple,
ts.TypeFlags.Union,
ts.TypeFlags.Intersection,
ts.TypeFlags.Anonymous,
ts.TypeFlags.Instantiated,
ts.TypeFlags.ThisType,
ts.TypeFlags.ObjectLiteralPatternWithComputedProperties,
];
let names: string[] = [];
for (let flag of basicTypes) {
if ((type.flags & flag) !== 0) {
names.push(ts.TypeFlags[flag]);
debugString += ` ${ts.TypeFlags[flag]}`;
}
}
// combinedTypes are TypeFlags that represent combined values.
// For example, NumberLike = Number|Enum.
const combinedTypes: ts.TypeFlags[] = [
ts.TypeFlags.StringLike,
ts.TypeFlags.NumberLike,
ts.TypeFlags.ObjectType,
ts.TypeFlags.UnionOrIntersection,
ts.TypeFlags.StructuredType,
];
let features: string[] = [];
for (let flag of combinedTypes) {
if ((type.flags & flag) !== 0) {
features.push(ts.TypeFlags[flag]);
}
}
let debugString = `flags:0x${type.flags.toString(16)}`;
debugString += ' ' + names.join(' ');
if (features.length > 0) {
debugString += ` features:${features.join(',')}`;
}
if (type.symbol && type.symbol.name !== '__type') {

@@ -93,4 +85,44 @@ debugString += ` symbol.name:${JSON.stringify(type.symbol.name)}`;

export function symbolToDebugString(sym: ts.Symbol): string {
let debugString = `${JSON.stringify(sym.name)} ${sym.flags.toString(16)}`;
return `{sym: ${debugString}}`;
let debugString = `${JSON.stringify(sym.name)} flags:0x${sym.flags.toString(16)}`;
const symbolFlags = [
ts.SymbolFlags.FunctionScopedVariable,
ts.SymbolFlags.BlockScopedVariable,
ts.SymbolFlags.Property,
ts.SymbolFlags.EnumMember,
ts.SymbolFlags.Function,
ts.SymbolFlags.Class,
ts.SymbolFlags.Interface,
ts.SymbolFlags.ConstEnum,
ts.SymbolFlags.RegularEnum,
ts.SymbolFlags.ValueModule,
ts.SymbolFlags.NamespaceModule,
ts.SymbolFlags.TypeLiteral,
ts.SymbolFlags.ObjectLiteral,
ts.SymbolFlags.Method,
ts.SymbolFlags.Constructor,
ts.SymbolFlags.GetAccessor,
ts.SymbolFlags.SetAccessor,
ts.SymbolFlags.Signature,
ts.SymbolFlags.TypeParameter,
ts.SymbolFlags.TypeAlias,
ts.SymbolFlags.ExportValue,
ts.SymbolFlags.ExportType,
ts.SymbolFlags.ExportNamespace,
ts.SymbolFlags.Alias,
ts.SymbolFlags.Instantiated,
ts.SymbolFlags.Merged,
ts.SymbolFlags.Transient,
ts.SymbolFlags.Prototype,
ts.SymbolFlags.SyntheticProperty,
ts.SymbolFlags.Optional,
ts.SymbolFlags.ExportStar,
];
for (const flag of symbolFlags) {
if ((sym.flags & flag) !== 0) {
debugString += ` ${ts.SymbolFlags[flag]}`;
}
}
return debugString;
}

@@ -158,3 +190,3 @@

*/
translate(type: ts.Type, notNull = false): string {
translate(type: ts.Type, notNull: boolean): string {
// See the function `buildTypeDisplay` in the TypeScript compiler source

@@ -205,3 +237,3 @@ // for guidance on a similar operation.

}
return this.symbolToString(type.symbol);
return notNullPrefix + this.symbolToString(type.symbol);
} else if (type.flags & ts.TypeFlags.Interface) {

@@ -228,3 +260,3 @@ // Note: ts.InterfaceType has a typeParameters field, but that

}
return this.symbolToString(type.symbol);
return notNullPrefix + this.symbolToString(type.symbol);
} else if (type.flags & ts.TypeFlags.Reference) {

@@ -249,7 +281,7 @@ // A reference to another type, e.g. Array<number> refers to Array.

}
typeStr += notNullPrefix + this.translate(referenceType.target);
typeStr += this.translate(referenceType.target, notNull);
}
if (referenceType.typeArguments) {
let params = referenceType.typeArguments.map(t => this.translate(t, notNull));
typeStr += isTuple ? `Array` : `<${params.join(', ')}>`;
let params = referenceType.typeArguments.map(t => this.translate(t, true));
typeStr += isTuple ? notNullPrefix + `Array` : `<${params.join(', ')}>`;
}

@@ -268,3 +300,3 @@ return typeStr;

if (type.symbol.flags === ts.SymbolFlags.TypeLiteral) {
return notNullPrefix + this.translateTypeLiteral(type);
return this.translateTypeLiteral(type, notNull);
} else if (

@@ -282,3 +314,3 @@ type.symbol.flags === ts.SymbolFlags.Function ||

let unionType = type as ts.UnionType;
let parts = unionType.types.map(t => this.translate(t));
let parts = unionType.types.map(t => this.translate(t, true));
// In union types that include boolean literal and other literals can

@@ -295,3 +327,9 @@ // end up repeating the same closure type. For example: true | boolean

private translateTypeLiteral(type: ts.Type): string {
/**
* translateTypeLiteral translates a ts.SymbolFlags.TypeLiteral type, which
* is the anonymous type encountered in e.g.
* let x: {a: number};
*/
private translateTypeLiteral(type: ts.Type, notNull: boolean): string {
const notNullPrefix = notNull ? '!' : '';
// Avoid infinite loops on recursive types.

@@ -312,2 +350,14 @@ // It would be nice to just emit the name of the recursive type here,

}
// special-case construct signatures.
const ctors = type.getConstructSignatures();
if (ctors.length) {
// TODO(martinprobst): this does not support additional properties defined on constructors
// (not expressible in Closure), nor multiple constructors (same).
const params = this.convertParams(ctors[0]);
const paramsStr = params.length ? (', ' + params.join(', ')) : '';
const constructedType = this.translate(ctors[0].getReturnType(), false);
return `function(new: ${constructedType}${paramsStr}): ?`;
}
for (let field of Object.keys(type.symbol.members)) {

@@ -323,8 +373,5 @@ switch (field) {

let member = type.symbol.members[field];
let isOptional = member.flags & ts.SymbolFlags.Optional;
// optional members are handled by the type including |undefined in a union type.
let memberType =
this.translate(this.typeChecker.getTypeOfSymbolAtLocation(member, this.node));
if (isOptional) {
memberType = `(${memberType}|undefined)`;
}
this.translate(this.typeChecker.getTypeOfSymbolAtLocation(member, this.node), true);
fields.push(`${field}: ${memberType}`);

@@ -352,9 +399,9 @@ }

this.warn('unknown index key type');
return `Object<?,?>`;
return notNullPrefix + `Object<?,?>`;
}
return `Object<${keyType},${this.translate(valType)}>`;
return notNullPrefix + `Object<${keyType},${this.translate(valType, true)}>`;
} else if (!callable && !indexable) {
// Special-case the empty object {} because Closure doesn't like it.
// TODO(evanm): revisit this if it is a problem.
return 'Object';
return notNullPrefix + 'Object';
}

@@ -374,9 +421,6 @@ }

private signatureToClosure(sig: ts.Signature): string {
let params: string[] = [];
for (let param of sig.parameters) {
params.push(this.translate(this.typeChecker.getTypeOfSymbolAtLocation(param, this.node)));
}
let params = this.convertParams(sig);
let typeStr = `function(${params.join(', ')})`;
let retType = this.translate(this.typeChecker.getReturnTypeOfSignature(sig));
let retType = this.translate(this.typeChecker.getReturnTypeOfSignature(sig), true);
if (retType) {

@@ -389,2 +433,9 @@ typeStr += `: ${retType}`;

private convertParams(sig: ts.Signature): string[] {
return sig.parameters.map(param => {
let paramType = this.typeChecker.getTypeOfSymbolAtLocation(param, this.node);
return this.translate(paramType, true);
});
}
warn(msg: string) {

@@ -391,0 +442,0 @@ // By default, warn() does nothing. The caller will overwrite this

@@ -17,3 +17,3 @@ goog.module('test_files.abstract.abstract');var module = module || {id: 'test_files/abstract/abstract.js'};/**

* @abstract
* @param {Array<number>} x
* @param {!Array<number>} x
* @return {void}

@@ -56,3 +56,3 @@ */

/**
* @param {Array<number>} x
* @param {!Array<number>} x
* @return {void}

@@ -70,2 +70,2 @@ */

}
let /** @type {Base} */ x = new Derived();
let /** @type {!Base} */ x = new Derived();

@@ -0,1 +1,2 @@

/**

@@ -17,3 +18,3 @@ * @abstract

* @abstract
* @param {Array<number>} x
* @param {!Array<number>} x
* @return {void}

@@ -57,3 +58,3 @@ */

/**
* @param {Array<number>} x
* @param {!Array<number>} x
* @return {void}

@@ -72,2 +73,2 @@ */

let /** @type {Base} */ x: Base = new Derived();
let /** @type {!Base} */ x: Base = new Derived();

@@ -16,9 +16,9 @@ goog.module('test_files.basic.untyped.basic.untyped');var module = module || {id: 'test_files/basic.untyped/basic.untyped.js'};/**

}
static _tsickle_typeAnnotationsHelper() {
/** @type {?} */
Foo.prototype.field;
/** @type {?} */
Foo.prototype.ctorArg;
}
}
function Foo_tsickle_Closure_declarations() {
/** @type {?} */
Foo.prototype.field;
/** @type {?} */
Foo.prototype.ctorArg;
}
// These two declarations should not have a @type annotation,

@@ -28,3 +28,3 @@ // regardless of untyped.

// With a type annotation:
let { a, b } = { a: null, b: null };
let { a, b } = { a: '', b: 0 };
})();

@@ -31,0 +31,0 @@ (function () {

@@ -19,7 +19,7 @@ // This test is just a random collection of typed code, to

// With a type annotation:
let {a, b}: {a:string, b:number} = {a:null, b:null};
let {a, b}: {a: string, b: number} = {a: '', b: 0};
})();
(function() {
// Without a type annotation:
let {a, b} = {a:null, b:null};
let {a, b} = {a: null, b: null};
})();

@@ -18,4 +18,5 @@

}
}
static _tsickle_typeAnnotationsHelper() {
function Foo_tsickle_Closure_declarations() {
/** @type {?} */

@@ -25,6 +26,5 @@ Foo.prototype.field;

Foo.prototype.ctorArg;
}
}
// These two declarations should not have a @type annotation,

@@ -34,7 +34,7 @@ // regardless of untyped.

// With a type annotation:
let {a, b}: {a:string, b:number} = {a:null, b:null};
let {a, b}: {a: string, b: number} = {a: '', b: 0};
})();
(function() {
// Without a type annotation:
let {a, b} = {a:null, b:null};
let {a, b} = {a: null, b: null};
})();
goog.module('test_files.comments.comments');var module = module || {id: 'test_files/comments/comments.js'};class Comments {
static _tsickle_typeAnnotationsHelper() {
/** @export
@type {string} */
Comments.prototype.export1;
/** @type {string} */
Comments.prototype.export2;
/** @type {number} */
Comments.prototype.nodoc1;
/** @type {number} */
Comments.prototype.nodoc2;
/** @type {number} */
Comments.prototype.nodoc3;
/** inline jsdoc comment without type annotation
@type {number} */
Comments.prototype.jsdoc1;
/** multi-line jsdoc comment without type annotation.
@type {number} */
Comments.prototype.jsdoc2;
}
}
function Comments_tsickle_Closure_declarations() {
/** @export
@type {string} */
Comments.prototype.export1;
/** @type {string} */
Comments.prototype.export2;
/** @type {number} */
Comments.prototype.nodoc1;
/** @type {number} */
Comments.prototype.nodoc2;
/** @type {number} */
Comments.prototype.nodoc3;
/** inline jsdoc comment without type annotation
@type {number} */
Comments.prototype.jsdoc1;
/** multi-line jsdoc comment without
type annotation.
@type {number} */
Comments.prototype.jsdoc2;
}

@@ -21,4 +21,5 @@ class Comments {

jsdoc2: number;
}
static _tsickle_typeAnnotationsHelper() {
function Comments_tsickle_Closure_declarations() {
/** @export

@@ -38,7 +39,7 @@ @type {string} */

Comments.prototype.jsdoc1;
/** multi-line jsdoc comment without type annotation.
/** multi-line jsdoc comment without
type annotation.
@type {number} */
Comments.prototype.jsdoc2;
}
}
}

@@ -34,5 +34,5 @@ /**

* @param {number} c
* @param {string|Array<string>} normal_or_vertexNormals
* @param {boolean|Array<boolean>} color_or_vertexColors
* @param {number} materialIndex
* @param {(undefined|string)|(undefined|!Array<string>)} normal_or_vertexNormals
* @param {(undefined|boolean)|(undefined|!Array<boolean>)} color_or_vertexColors
* @param {(undefined|number)} materialIndex
*/

@@ -44,3 +44,3 @@ function MultipleConstructorsComplexMatrix(a, b, c, normal_or_vertexNormals, color_or_vertexColors, materialIndex) {}

* @struct
* @param {number|Array<number>} a
* @param {number|!Array<number>} a
*/

@@ -52,3 +52,3 @@ function MultipleConstructorsVariadic(a) {}

* @struct
* @param {Array<string>|Array<number>|string|number} points
* @param {!Array<string>|!Array<number>|string|number} points
*/

@@ -103,3 +103,3 @@ function MultipleConstructorsVariadicNames(points) {}

/**
* @param {string|number|Array<OverloadBigMix>|OverloadBigMix} a_or_c_or_e_or_f
* @param {string|number|!Array<!OverloadBigMix>|!OverloadBigMix} a_or_c_or_e_or_f
* @param {number} opt_b

@@ -122,3 +122,3 @@ * @return {void|number|boolean}

/**
* @param {(string|number|Array<OverloadBigMix>)} a_or_c_or_e_or_f
* @param {(string|number|!Array<!OverloadBigMix>)} a_or_c_or_e_or_f
* @param {number} opt_b

@@ -125,0 +125,0 @@ * @return {(number|boolean|void)}

@@ -87,3 +87,3 @@ /**

* @param {string} x
* @return {CodeMirror.Editor}
* @return {!CodeMirror.Editor}
*/

@@ -95,3 +95,3 @@ function CodeMirror(x) {}

* @param {string} x
* @return {CodeMirror.Editor}
* @return {!CodeMirror.Editor}
*/

@@ -98,0 +98,0 @@ function CodeMirror(y, x) {}

@@ -6,2 +6,8 @@ function decorator(a: Object, b: string) {}

function classDecorator(t: any) { return t; }
/** @Annotation */
function classAnnotation(t: any) { return t; }
class DecoratorTest {

@@ -13,2 +19,8 @@ @decorator

private y: number;
static decorators: DecoratorInvocation[] = [
{ type: classAnnotation },
];
/** @nocollapse */
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
];
static propDecorators: {[key: string]: DecoratorInvocation[]} = {

@@ -19,2 +31,7 @@ 'y': [{ type: annotationDecorator },],

@classDecorator
class DecoratedClass {
z: string;
}
interface DecoratorInvocation {

@@ -21,0 +38,0 @@ type: Function;

goog.module('test_files.decorator.decorator');var module = module || {id: 'test_files/decorator/decorator.js'};/**
* @param {Object} a
* @param {!Object} a
* @param {string} b

@@ -8,3 +8,3 @@ * @return {void}

/**
* @param {Object} a
* @param {!Object} a
* @param {string} b

@@ -14,12 +14,19 @@ * @return {void}

function annotationDecorator(a, b) { }
/**
* @param {?} t
* @return {?}
*/
function classDecorator(t) { return t; }
/**
* @param {?} t
* @return {?}
*/
function classAnnotation(t) { return t; }
class DecoratorTest {
static _tsickle_typeAnnotationsHelper() {
/** @type {Object<string,Array<DecoratorInvocation>>} */
DecoratorTest.propDecorators;
/** @type {number} */
DecoratorTest.prototype.x;
/** @type {number} */
DecoratorTest.prototype.y;
}
}
DecoratorTest.decorators = [
{ type: classAnnotation },
];
/** @nocollapse */
DecoratorTest.ctorParameters = () => [];
DecoratorTest.propDecorators = {

@@ -32,7 +39,30 @@ 'y': [{ type: annotationDecorator },],

], DecoratorTest.prototype, "x", void 0);
function DecoratorTest_tsickle_Closure_declarations() {
/** @type {!Array<!DecoratorInvocation>} */
DecoratorTest.decorators;
/** @nocollapse
@type {function(): !Array<(null|{type: ?, decorators: (undefined|!Array<!DecoratorInvocation>)})>} */
DecoratorTest.ctorParameters;
/** @type {!Object<string,!Array<!DecoratorInvocation>>} */
DecoratorTest.propDecorators;
/** @type {number} */
DecoratorTest.prototype.x;
/** @type {number} */
DecoratorTest.prototype.y;
}
let DecoratedClass = class DecoratedClass {
};
DecoratedClass = __decorate([
classDecorator,
__metadata('design:paramtypes', [])
], DecoratedClass);
function DecoratedClass_tsickle_Closure_declarations() {
/** @type {string} */
DecoratedClass.prototype.z;
}
/** @record */
function DecoratorInvocation() { }
/** @type {Function} */
/** @type {!Function} */
DecoratorInvocation.prototype.type;
/** @type {Array<?>} */
/** @type {(undefined|!Array<?>)} */
DecoratorInvocation.prototype.args;

@@ -6,2 +6,8 @@ function decorator(a: Object, b: string) {}

function classDecorator(t: any) { return t; }
/** @Annotation */
function classAnnotation(t: any) { return t; }
@classAnnotation
class DecoratorTest {

@@ -14,1 +20,6 @@ @decorator

}
@classDecorator
class DecoratedClass {
z: string;
}
/**
* @param {Object} a
* @param {!Object} a
* @param {string} b

@@ -9,3 +9,3 @@ * @return {void}

/**
* @param {Object} a
* @param {!Object} a
* @param {string} b

@@ -15,3 +15,14 @@ * @return {void}

function annotationDecorator(a: Object, b: string) {}
/**
* @param {?} t
* @return {?}
*/
function classDecorator(t: any) { return t; }
/**
* @param {?} t
* @return {?}
*/
function classAnnotation(t: any) { return t; }
class DecoratorTest {

@@ -21,8 +32,20 @@ @decorator

private y: number;
static decorators: DecoratorInvocation[] = [
{ type: classAnnotation },
];
/** @nocollapse */
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
];
static propDecorators: {[key: string]: DecoratorInvocation[]} = {
'y': [{ type: annotationDecorator },],
};
}
static _tsickle_typeAnnotationsHelper() {
/** @type {Object<string,Array<DecoratorInvocation>>} */
function DecoratorTest_tsickle_Closure_declarations() {
/** @type {!Array<!DecoratorInvocation>} */
DecoratorTest.decorators;
/** @nocollapse
@type {function(): !Array<(null|{type: ?, decorators: (undefined|!Array<!DecoratorInvocation>)})>} */
DecoratorTest.ctorParameters;
/** @type {!Object<string,!Array<!DecoratorInvocation>>} */
DecoratorTest.propDecorators;

@@ -33,10 +56,20 @@ /** @type {number} */

DecoratorTest.prototype.y;
}
}
@classDecorator
class DecoratedClass {
z: string;
}
function DecoratedClass_tsickle_Closure_declarations() {
/** @type {string} */
DecoratedClass.prototype.z;
}
/** @record */
function DecoratorInvocation() {}
/** @type {Function} */
/** @type {!Function} */
DecoratorInvocation.prototype.type;
/** @type {Array<?>} */
/** @type {(undefined|!Array<?>)} */
DecoratorInvocation.prototype.args;

@@ -43,0 +76,0 @@

goog.module('test_files.enum.enum');var module = module || {id: 'test_files/enum/enum.js'};
// Line with a missing semicolon should not break the following enum.
const /** @type {Array<?>} */ EnumTestMissingSemi = [];
const /** @type {!Array<?>} */ EnumTestMissingSemi = [];
let EnumTest1 = {};

@@ -16,4 +16,4 @@ /** @type {number} */

let /** @type {number} */ enumTestValue2 = EnumTest1['XYZ'];
let /** @type {string} */ enumNumIndex = EnumTest1[(null)];
let /** @type {number} */ enumStrIndex = EnumTest1[(null)];
let /** @type {string} */ enumNumIndex = EnumTest1[((null))];
let /** @type {number} */ enumStrIndex = EnumTest1[((null))];
/**

@@ -20,0 +20,0 @@ * @param {number} val

@@ -10,4 +10,4 @@ // Line with a missing semicolon should not break the following enum.

let enumTestValue2: EnumTest1 = EnumTest1['XYZ'];
let enumNumIndex: string = EnumTest1[null as number];
let enumStrIndex: number = EnumTest1[null as string];
let enumNumIndex: string = EnumTest1[null as any as number];
let enumStrIndex: number = EnumTest1[null as any as string];

@@ -14,0 +14,0 @@ function enumTestFunction(val: EnumTest1) {}

@@ -0,3 +1,5 @@

Warning at test_files/enum/enum.ts:2:7: unhandled type {type flags:0x2000 Never}
====
// Line with a missing semicolon should not break the following enum.
const /** @type {Array<?>} */ EnumTestMissingSemi = []
const /** @type {!Array<?>} */ EnumTestMissingSemi = []
type EnumTest1 = number;

@@ -18,4 +20,4 @@ let EnumTest1: any = {};

let /** @type {number} */ enumTestValue2: EnumTest1 = EnumTest1['XYZ'];
let /** @type {string} */ enumNumIndex: string = EnumTest1[ /** @type {number} */((null as number))];
let /** @type {number} */ enumStrIndex: number = EnumTest1[ /** @type {string} */((null as string))];
let /** @type {string} */ enumNumIndex: string = EnumTest1[ /** @type {number} */(( /** @type {?} */((null as any)) as number))];
let /** @type {number} */ enumStrIndex: number = EnumTest1[ /** @type {string} */(( /** @type {?} */((null as any)) as string))];
/**

@@ -22,0 +24,0 @@ * @param {number} val

@@ -13,3 +13,2 @@ goog.module('test_files.export.export_helper');var module = module || {id: 'test_files/export/export_helper.js'};

Bar.prototype.barField;
exports.export3 = null;
exports.export5 = 3;

@@ -8,4 +8,4 @@ // This file isn't itself a test case, but it is imported by the

export interface Bar { barField: number; }
export var export3: Bar = null;
export var export3: Bar;
export let export5 = 3;

@@ -13,4 +13,4 @@ // This file isn't itself a test case, but it is imported by the

export interface Bar { barField: number; }
export var /** @type {Bar} */ export3: Bar = null;
export var /** @type {!Bar} */ export3: Bar;
export let /** @type {number} */ export5 = 3;

@@ -10,3 +10,3 @@ goog.module('test_files.export.export');var module = module || {id: 'test_files/export/export.js'};

exports.export1 = 'wins';
var export_helper_2 = goog.require('test_files.export.export_helper');
var export_helper_2 = export_helper_1;
exports.export3 = export_helper_2.export4;

@@ -20,3 +20,3 @@ // This local should be fine to export.

// This is just an import, so export5 should still be included.
var export_helper_3 = goog.require('test_files.export.export_helper');
var export_helper_3 = export_helper_1;
const export5 = export_helper_3.export5; /* local alias for Closure JSDoc */
goog.module('test_files.fields_no_ctor.fields_no_ctor');var module = module || {id: 'test_files/fields_no_ctor/fields_no_ctor.js'};class NoCtor {
static _tsickle_typeAnnotationsHelper() {
/** @type {number} */
NoCtor.prototype.field1;
}
}
function NoCtor_tsickle_Closure_declarations() {
/** @type {number} */
NoCtor.prototype.field1;
}
class NoCtor {
field1: number;
}
static _tsickle_typeAnnotationsHelper() {
function NoCtor_tsickle_Closure_declarations() {
/** @type {number} */
NoCtor.prototype.field1;
}
}
}

@@ -18,14 +18,14 @@ goog.module('test_files.fields.fields');var module = module || {id: 'test_files/fields/fields.js'};class FieldsTest {

}
static _tsickle_typeAnnotationsHelper() {
/** @type {string} */
FieldsTest.prototype.field1;
/** @type {number} */
FieldsTest.prototype.field2;
/** @type {string} */
FieldsTest.prototype.field4;
/** @type {number} */
FieldsTest.prototype.field3;
}
}
let /** @type {FieldsTest} */ fieldsTest = new FieldsTest(3);
function FieldsTest_tsickle_Closure_declarations() {
/** @type {string} */
FieldsTest.prototype.field1;
/** @type {number} */
FieldsTest.prototype.field2;
/** @type {string} */
FieldsTest.prototype.field4;
/** @type {number} */
FieldsTest.prototype.field3;
}
let /** @type {!FieldsTest} */ fieldsTest = new FieldsTest(3);
// Ensure the type is understood by Closure.

@@ -32,0 +32,0 @@ fieldsTest.field1 = 'hi';

@@ -22,4 +22,5 @@ Warning at test_files/fields/fields.ts:22:5: unhandled anonymous type

}
}
static _tsickle_typeAnnotationsHelper() {
function FieldsTest_tsickle_Closure_declarations() {
/** @type {string} */

@@ -33,7 +34,6 @@ FieldsTest.prototype.field1;

FieldsTest.prototype.field3;
}
}
let /** @type {FieldsTest} */ fieldsTest = new FieldsTest(3);
let /** @type {!FieldsTest} */ fieldsTest = new FieldsTest(3);
// Ensure the type is understood by Closure.

@@ -40,0 +40,0 @@ fieldsTest.field1 = 'hi';

@@ -29,3 +29,3 @@ goog.module('test_files.functions.functions');var module = module || {id: 'test_files/functions/functions.js'};/**

/**
* @param {!{a: number, b: number}} __0
* @param {{a: number, b: number}} __0
* @return {void}

@@ -32,0 +32,0 @@ */

@@ -38,3 +38,3 @@ Warning at test_files/functions/functions.ts:18:1: unhandled type {type flags:0x4000 TypeParameter}

/**
* @param {!{a: number, b: number}} __0
* @param {{a: number, b: number}} __0
* @return {void}

@@ -41,0 +41,0 @@ */

@@ -8,3 +8,3 @@ goog.module('test_files.interface.interface');var module = module || {id: 'test_files/interface/interface.js'};/** @record */

/**
* @param {Point} p
* @param {!Point} p
* @return {number}

@@ -15,3 +15,3 @@ */

}
let /** @type {Point} */ p = { x: 1, y: 1 };
let /** @type {!Point} */ p = { x: 1, y: 1 };
usePoint(p);

@@ -30,3 +30,3 @@ usePoint({ x: 1, y: 1 });

*/
/** @type {string} */
/** @type {(undefined|string)} */
TrickyInterface.prototype.foobar;

@@ -13,3 +13,3 @@

/**
* @param {Point} p
* @param {!Point} p
* @return {number}

@@ -21,3 +21,3 @@ */

let /** @type {Point} */ p: Point = {x:1, y:1};
let /** @type {!Point} */ p: Point = {x:1, y:1};
usePoint(p);

@@ -36,3 +36,3 @@ usePoint({x:1, y:1});

*/
/** @type {string} */
/** @type {(undefined|string)} */
TrickyInterface.prototype.foobar;

@@ -39,0 +39,0 @@

@@ -8,9 +8,9 @@ goog.module('test_files.jsdoc_types.untyped.jsdoc_types');var module = module || {id: 'test_files/jsdoc_types.untyped/jsdoc_types.js'};/**

var module2_1 = goog.require('test_files.jsdoc_types.untyped.module2');
var module2_2 = goog.require('test_files.jsdoc_types.untyped.module2');
var module2_3 = goog.require('test_files.jsdoc_types.untyped.module2');
var module2_2 = module2_1;
var module2_3 = module2_1;
var default_1 = goog.require('test_files.jsdoc_types.untyped.default');
// Check that imported types get the proper names in JSDoc.
let /** @type {?} */ useNamespacedClass = new module1.Class();
let /** @type {?} */ useNamespacedClassAsType = null;
let /** @type {?} */ useNamespacedType = null;
let /** @type {?} */ useNamespacedClassAsType;
let /** @type {?} */ useNamespacedType;
// Should be references to the symbols in module2, perhaps via locals.

@@ -20,5 +20,5 @@ let /** @type {?} */ useLocalClass = new module2_1.ClassOne();

let /** @type {?} */ useLocalClassRenamedTwo = new module2_3.ClassTwo();
let /** @type {?} */ useLocalClassAsTypeRenamed = null;
let /** @type {?} */ useLocalInterface = null;
let /** @type {?} */ useClassWithParams = null;
let /** @type {?} */ useLocalClassAsTypeRenamed;
let /** @type {?} */ useLocalInterface;
let /** @type {?} */ useClassWithParams;
// This is purely a value; it doesn't need renaming.

@@ -28,5 +28,5 @@ let /** @type {?} */ useLocalValue = module2_1.value;

let /** @type {?} */ useDefaultClass = new default_1.default();
let /** @type {?} */ useDefaultClassAsType = null;
let /** @type {?} */ useDefaultClassAsType;
// NeverTyped should be {?}, even in typed mode.
let /** @type {?} */ useNeverTyped = null;
let /** @type {?} */ useNeverTyped2 = null;
let /** @type {?} */ useNeverTyped;
let /** @type {?} */ useNeverTyped2;

@@ -17,4 +17,4 @@ /**

let useNamespacedClass = new module1.Class();
let useNamespacedClassAsType: module1.Class = null;
let useNamespacedType: module1.Interface = null;
let useNamespacedClassAsType: module1.Class;
let useNamespacedType: module1.Interface;

@@ -25,5 +25,5 @@ // Should be references to the symbols in module2, perhaps via locals.

let useLocalClassRenamedTwo = new RenamedClassTwo();
let useLocalClassAsTypeRenamed: RenamedClassOne = null;
let useLocalInterface: Interface = null;
let useClassWithParams: ClassWithParams<number> = null;
let useLocalClassAsTypeRenamed: RenamedClassOne;
let useLocalInterface: Interface;
let useClassWithParams: ClassWithParams<number>;

@@ -35,6 +35,6 @@ // This is purely a value; it doesn't need renaming.

let useDefaultClass = new DefaultClass();
let useDefaultClassAsType: DefaultClass = null;
let useDefaultClassAsType: DefaultClass;
// NeverTyped should be {?}, even in typed mode.
let useNeverTyped: NeverTyped = null;
let useNeverTyped2: string|NeverTyped = null;
let useNeverTyped: NeverTyped;
let useNeverTyped2: string|NeverTyped;

@@ -17,4 +17,4 @@ /**

let /** @type {?} */ useNamespacedClass = new module1.Class();
let /** @type {?} */ useNamespacedClassAsType: module1.Class = null;
let /** @type {?} */ useNamespacedType: module1.Interface = null;
let /** @type {?} */ useNamespacedClassAsType: module1.Class;
let /** @type {?} */ useNamespacedType: module1.Interface;

@@ -25,5 +25,5 @@ // Should be references to the symbols in module2, perhaps via locals.

let /** @type {?} */ useLocalClassRenamedTwo = new RenamedClassTwo();
let /** @type {?} */ useLocalClassAsTypeRenamed: RenamedClassOne = null;
let /** @type {?} */ useLocalInterface: Interface = null;
let /** @type {?} */ useClassWithParams: ClassWithParams<number> = null;
let /** @type {?} */ useLocalClassAsTypeRenamed: RenamedClassOne;
let /** @type {?} */ useLocalInterface: Interface;
let /** @type {?} */ useClassWithParams: ClassWithParams<number>;

@@ -35,6 +35,6 @@ // This is purely a value; it doesn't need renaming.

let /** @type {?} */ useDefaultClass = new DefaultClass();
let /** @type {?} */ useDefaultClassAsType: DefaultClass = null;
let /** @type {?} */ useDefaultClassAsType: DefaultClass;
// NeverTyped should be {?}, even in typed mode.
let /** @type {?} */ useNeverTyped: NeverTyped = null;
let /** @type {?} */ useNeverTyped2: string|NeverTyped = null;
let /** @type {?} */ useNeverTyped: NeverTyped;
let /** @type {?} */ useNeverTyped2: string|NeverTyped;

@@ -10,10 +10,6 @@ goog.module('test_files.jsdoc_types.jsdoc_types');var module = module || {id: 'test_files/jsdoc_types/jsdoc_types.js'};/**

const value = module2_1.value; /* local alias for Closure JSDoc */
var module2_2 = goog.require('test_files.jsdoc_types.module2');
const RenamedClassOne = module2_2.ClassOne; /* local alias for Closure JSDoc */
var module2_3 = goog.require('test_files.jsdoc_types.module2');
const RenamedClassTwo = module2_3.ClassTwo; /* local alias for Closure JSDoc */
var module2_4 = goog.require('test_files.jsdoc_types.module2');
const Interface = module2_4.Interface; /* local alias for Closure JSDoc */
var module2_5 = goog.require('test_files.jsdoc_types.module2');
const ClassWithParams = module2_5.ClassWithParams; /* local alias for Closure JSDoc */
const RenamedClassOne = module2_1.ClassOne; /* local alias for Closure JSDoc */
const RenamedClassTwo = module2_1.ClassTwo; /* local alias for Closure JSDoc */
const Interface = module2_1.Interface; /* local alias for Closure JSDoc */
const ClassWithParams = module2_1.ClassWithParams; /* local alias for Closure JSDoc */
var default_1 = goog.require('test_files.jsdoc_types.default');

@@ -24,19 +20,19 @@ const DefaultClass = default_1.default; /* local alias for Closure JSDoc */

// Check that imported types get the proper names in JSDoc.
let /** @type {module1.Class} */ useNamespacedClass = new module1.Class();
let /** @type {module1.Class} */ useNamespacedClassAsType = null;
let /** @type {module1.Interface} */ useNamespacedType = null;
let /** @type {!module1.Class} */ useNamespacedClass = new module1.Class();
let /** @type {!module1.Class} */ useNamespacedClassAsType;
let /** @type {!module1.Interface} */ useNamespacedType;
// Should be references to the symbols in module2, perhaps via locals.
let /** @type {ClassOne} */ useLocalClass = new module2_1.ClassOne();
let /** @type {ClassOne} */ useLocalClassRenamed = new module2_2.ClassOne();
let /** @type {RenamedClassTwo} */ useLocalClassRenamedTwo = new module2_3.ClassTwo();
let /** @type {ClassOne} */ useLocalClassAsTypeRenamed = null;
let /** @type {Interface} */ useLocalInterface = null;
let /** @type {ClassWithParams<number>} */ useClassWithParams = null;
let /** @type {!ClassOne} */ useLocalClass = new module2_1.ClassOne();
let /** @type {!ClassOne} */ useLocalClassRenamed = new module2_1.ClassOne();
let /** @type {!RenamedClassTwo} */ useLocalClassRenamedTwo = new module2_1.ClassTwo();
let /** @type {!ClassOne} */ useLocalClassAsTypeRenamed;
let /** @type {!Interface} */ useLocalInterface;
let /** @type {!ClassWithParams<number>} */ useClassWithParams;
// This is purely a value; it doesn't need renaming.
let /** @type {number} */ useLocalValue = module2_1.value;
// Check a default import.
let /** @type {DefaultClass} */ useDefaultClass = new default_1.default();
let /** @type {DefaultClass} */ useDefaultClassAsType = null;
let /** @type {!DefaultClass} */ useDefaultClass = new default_1.default();
let /** @type {!DefaultClass} */ useDefaultClassAsType;
// NeverTyped should be {?}, even in typed mode.
let /** @type {?} */ useNeverTyped = null;
let /** @type {(string|?)} */ useNeverTyped2 = null;
let /** @type {?} */ useNeverTyped;
let /** @type {(string|?)} */ useNeverTyped2;

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

import * as module1 from './module1';
import {ClassOne, value} from './module2';
import {ClassOne as RenamedClassOne} from './module2';
import {ClassTwo as RenamedClassTwo} from './module2';
import {Interface} from './module2';
import {ClassWithParams} from './module2';
import {ClassOne, value, ClassOne as RenamedClassOne, ClassTwo as RenamedClassTwo, Interface, ClassWithParams} from './module2';
import DefaultClass from './default';

@@ -18,4 +14,4 @@ import {NeverTyped} from './nevertyped';

let useNamespacedClass = new module1.Class();
let useNamespacedClassAsType: module1.Class = null;
let useNamespacedType: module1.Interface = null;
let useNamespacedClassAsType: module1.Class;
let useNamespacedType: module1.Interface;

@@ -26,5 +22,5 @@ // Should be references to the symbols in module2, perhaps via locals.

let useLocalClassRenamedTwo = new RenamedClassTwo();
let useLocalClassAsTypeRenamed: RenamedClassOne = null;
let useLocalInterface: Interface = null;
let useClassWithParams: ClassWithParams<number> = null;
let useLocalClassAsTypeRenamed: RenamedClassOne;
let useLocalInterface: Interface;
let useClassWithParams: ClassWithParams<number>;

@@ -36,6 +32,6 @@ // This is purely a value; it doesn't need renaming.

let useDefaultClass = new DefaultClass();
let useDefaultClassAsType: DefaultClass = null;
let useDefaultClassAsType: DefaultClass;
// NeverTyped should be {?}, even in typed mode.
let useNeverTyped: NeverTyped = null;
let useNeverTyped2: string|NeverTyped = null;
let useNeverTyped: NeverTyped;
let useNeverTyped2: string|NeverTyped;

@@ -7,12 +7,8 @@ /**

import * as module1 from './module1';
import {ClassOne, value} from './module2';
import {ClassOne, value, ClassOne as RenamedClassOne, ClassTwo as RenamedClassTwo, Interface, ClassWithParams} from './module2';
const ClassOne: NeverTypeCheckMe = ClassOne; /* local alias for Closure JSDoc */
const value: NeverTypeCheckMe = value; /* local alias for Closure JSDoc */
import {ClassOne as RenamedClassOne} from './module2';
const RenamedClassOne: NeverTypeCheckMe = RenamedClassOne; /* local alias for Closure JSDoc */
import {ClassTwo as RenamedClassTwo} from './module2';
const RenamedClassTwo: NeverTypeCheckMe = RenamedClassTwo; /* local alias for Closure JSDoc */
import {Interface} from './module2';
const Interface: NeverTypeCheckMe = Interface; /* local alias for Closure JSDoc */
import {ClassWithParams} from './module2';
const ClassWithParams: NeverTypeCheckMe = ClassWithParams; /* local alias for Closure JSDoc */

@@ -25,13 +21,13 @@ import DefaultClass from './default';

// Check that imported types get the proper names in JSDoc.
let /** @type {module1.Class} */ useNamespacedClass = new module1.Class();
let /** @type {module1.Class} */ useNamespacedClassAsType: module1.Class = null;
let /** @type {module1.Interface} */ useNamespacedType: module1.Interface = null;
let /** @type {!module1.Class} */ useNamespacedClass = new module1.Class();
let /** @type {!module1.Class} */ useNamespacedClassAsType: module1.Class;
let /** @type {!module1.Interface} */ useNamespacedType: module1.Interface;
// Should be references to the symbols in module2, perhaps via locals.
let /** @type {ClassOne} */ useLocalClass = new ClassOne();
let /** @type {ClassOne} */ useLocalClassRenamed = new RenamedClassOne();
let /** @type {RenamedClassTwo} */ useLocalClassRenamedTwo = new RenamedClassTwo();
let /** @type {ClassOne} */ useLocalClassAsTypeRenamed: RenamedClassOne = null;
let /** @type {Interface} */ useLocalInterface: Interface = null;
let /** @type {ClassWithParams<number>} */ useClassWithParams: ClassWithParams<number> = null;
let /** @type {!ClassOne} */ useLocalClass = new ClassOne();
let /** @type {!ClassOne} */ useLocalClassRenamed = new RenamedClassOne();
let /** @type {!RenamedClassTwo} */ useLocalClassRenamedTwo = new RenamedClassTwo();
let /** @type {!ClassOne} */ useLocalClassAsTypeRenamed: RenamedClassOne;
let /** @type {!Interface} */ useLocalInterface: Interface;
let /** @type {!ClassWithParams<number>} */ useClassWithParams: ClassWithParams<number>;

@@ -42,7 +38,7 @@ // This is purely a value; it doesn't need renaming.

// Check a default import.
let /** @type {DefaultClass} */ useDefaultClass = new DefaultClass();
let /** @type {DefaultClass} */ useDefaultClassAsType: DefaultClass = null;
let /** @type {!DefaultClass} */ useDefaultClass = new DefaultClass();
let /** @type {!DefaultClass} */ useDefaultClassAsType: DefaultClass;
// NeverTyped should be {?}, even in typed mode.
let /** @type {?} */ useNeverTyped: NeverTyped = null;
let /** @type {(string|?)} */ useNeverTyped2: string|NeverTyped = null;
let /** @type {?} */ useNeverTyped: NeverTyped;
let /** @type {(string|?)} */ useNeverTyped2: string|NeverTyped;

@@ -20,15 +20,18 @@ goog.module('test_files.jsdoc.jsdoc');var module = module || {id: 'test_files/jsdoc/jsdoc.js'};/**

function jsDocTestBadDoc(foo) { }
/**
* Test JS doc on class.
*/
class JSDocTest {
static _tsickle_typeAnnotationsHelper() {
/** @export
@type {string} */
JSDocTest.prototype.exported;
/** @type {string} */
JSDocTest.prototype.badExport;
/** @type {string} */
JSDocTest.prototype.stringWithoutJSDoc;
/** @type {number} */
JSDocTest.prototype.typedThing;
}
}
function JSDocTest_tsickle_Closure_declarations() {
/** @export
@type {string} */
JSDocTest.prototype.exported;
/** @type {string} */
JSDocTest.prototype.badExport;
/** @type {string} */
JSDocTest.prototype.stringWithoutJSDoc;
/** @type {number} */
JSDocTest.prototype.typedThing;
}
/**

@@ -35,0 +38,0 @@ * @see This tag will be kept, because Closure allows it.

@@ -21,2 +21,6 @@ /**

/**
* Test JS doc on class.
* @madeUpTag This tag will be stripped, because Closure disallows it.
*/
class JSDocTest {

@@ -23,0 +27,0 @@ /** @export */

Warning at test_files/jsdoc/jsdoc.ts:16:1: type annotations (using {...}) are redundant with TypeScript types
Warning at test_files/jsdoc/jsdoc.ts:25:3: type annotations (using {...}) are redundant with TypeScript types
Warning at test_files/jsdoc/jsdoc.ts:30:3: @type annotations are redundant with TypeScript equivalents
Warning at test_files/jsdoc/jsdoc.ts:29:3: type annotations (using {...}) are redundant with TypeScript types
Warning at test_files/jsdoc/jsdoc.ts:34:3: @type annotations are redundant with TypeScript equivalents
====

@@ -25,3 +25,5 @@

function jsDocTestBadDoc(foo: string) {}
/**
* Test JS doc on class.
*/
class JSDocTest {

@@ -38,4 +40,5 @@ /** @export */

typedThing: number;
}
static _tsickle_typeAnnotationsHelper() {
function JSDocTest_tsickle_Closure_declarations() {
/** @export

@@ -50,5 +53,4 @@ @type {string} */

JSDocTest.prototype.typedThing;
}
}
}
/**

@@ -55,0 +57,0 @@ * @see This tag will be kept, because Closure allows it.

@@ -23,3 +23,3 @@ /**

* @param {...?} args
* @return {Element}
* @return {!Element}
*/

@@ -29,4 +29,4 @@ React.createElement = function(args) {};

/**
* @param {JSX.Element} element
* @param {HTMLElement} node
* @param {!JSX.Element} element
* @param {!HTMLElement} node
* @return {void}

@@ -33,0 +33,0 @@ */

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

goog.module('test_files.jsx.jsx');var module = module || {id: 'test_files/jsx/jsx.js'};let /** @type {JSX.Element} */ simple = React.createElement("div", null);
goog.module('test_files.jsx.jsx');var module = module || {id: 'test_files/jsx/jsx.js'};let /** @type {!JSX.Element} */ simple = React.createElement("div", null);
let /** @type {string} */ hello = 'hello';
let /** @type {JSX.Element} */ helloDiv = React.createElement("div", null,
let /** @type {!JSX.Element} */ helloDiv = React.createElement("div", null,
hello,
"hello, world",
React.createElement(Component, null));
React.render(helloDiv, document.body);
React.render(helloDiv, /** @type {!HTMLElement} */ ((document.body)));

@@ -20,6 +20,6 @@ goog.module('test_files.methods.methods');var module = module || {id: 'test_files/methods/methods.js'};class HasMethods {

set f(n) { this._f = n - 1; }
static _tsickle_typeAnnotationsHelper() {
/** @type {number} */
HasMethods.prototype._f;
}
}
function HasMethods_tsickle_Closure_declarations() {
/** @type {number} */
HasMethods.prototype._f;
}

@@ -21,8 +21,8 @@ class HasMethods {

set f(n: number) { this._f = n - 1; }
}
static _tsickle_typeAnnotationsHelper() {
function HasMethods_tsickle_Closure_declarations() {
/** @type {number} */
HasMethods.prototype._f;
}
}
}
goog.module('test_files.optional.optional');var module = module || {id: 'test_files/optional/optional.js'};/**
* @param {number} x
* @param {string=} y
* @param {(undefined|string)=} y
* @return {void}

@@ -12,3 +12,3 @@ */

* @param {string} a
* @param {string=} b
* @param {(undefined|string)=} b
*/

@@ -23,3 +23,3 @@ constructor(a, b) {

}
let /** @type {OptionalTest} */ optionalTest = new OptionalTest('a');
let /** @type {!OptionalTest} */ optionalTest = new OptionalTest('a');
optionalTest.method();
/**
* @param {number} x
* @param {string=} y
* @param {(undefined|string)=} y
* @return {void}

@@ -14,3 +14,3 @@ */

* @param {string} a
* @param {string=} b
* @param {(undefined|string)=} b
*/

@@ -25,3 +25,3 @@ constructor(a: string, b?: string) {}

let /** @type {OptionalTest} */ optionalTest = new OptionalTest('a');
let /** @type {!OptionalTest} */ optionalTest = new OptionalTest('a');
optionalTest.method();

@@ -10,9 +10,9 @@ goog.module('test_files.parameter_properties.parameter_properties');var module = module || {id: 'test_files/parameter_properties/parameter_properties.js'};class ParamProps {

}
static _tsickle_typeAnnotationsHelper() {
/** @export
@type {string} */
ParamProps.prototype.bar;
/** @type {string} */
ParamProps.prototype.bar2;
}
}
function ParamProps_tsickle_Closure_declarations() {
/** @export
@type {string} */
ParamProps.prototype.bar;
/** @type {string} */
ParamProps.prototype.bar2;
}

@@ -9,4 +9,5 @@ class ParamProps {

public bar2: string) {}
}
static _tsickle_typeAnnotationsHelper() {
function ParamProps_tsickle_Closure_declarations() {
/** @export

@@ -17,4 +18,3 @@ @type {string} */

ParamProps.prototype.bar2;
}
}
}
goog.module('test_files.static.static');var module = module || {id: 'test_files/static/static.js'};class Static {
static _tsickle_typeAnnotationsHelper() {
/** @type {number} */
Static.bar;
/** @type {number} */
Static.baz;
}
}

@@ -12,1 +6,7 @@ // This should not become a stub declaration.

Static.baz = 3;
function Static_tsickle_Closure_declarations() {
/** @type {number} */
Static.bar;
/** @type {number} */
Static.baz;
}

@@ -5,4 +5,5 @@ class Static {

private static baz: number = 3;
}
static _tsickle_typeAnnotationsHelper() {
function Static_tsickle_Closure_declarations() {
/** @type {number} */

@@ -12,4 +13,3 @@ Static.bar;

Static.baz;
}
}
}

@@ -8,7 +8,7 @@ goog.module('test_files.structural.untyped.structural.untyped');var module = module || {id: 'test_files/structural.untyped/structural.untyped.js'};// Ensure that a class is structurally equivalent to an object literal

method() { return this.field1; }
static _tsickle_typeAnnotationsHelper() {
/** @type {?} */
StructuralTest.prototype.field1;
}
}
function StructuralTest_tsickle_Closure_declarations() {
/** @type {?} */
StructuralTest.prototype.field1;
}
/**

@@ -15,0 +15,0 @@ * @param {?} st

@@ -9,9 +9,9 @@ // Ensure that a class is structurally equivalent to an object literal

method(): string { return this.field1; }
}
static _tsickle_typeAnnotationsHelper() {
function StructuralTest_tsickle_Closure_declarations() {
/** @type {?} */
StructuralTest.prototype.field1;
}
}
}
/**

@@ -18,0 +18,0 @@ * @param {?} st

@@ -12,7 +12,7 @@ goog.module('test_files.super.super');var module = module || {id: 'test_files/super/super.js'};class SuperTestBaseNoArg {

}
static _tsickle_typeAnnotationsHelper() {
/** @type {number} */
SuperTestBaseOneArg.prototype.x;
}
}
function SuperTestBaseOneArg_tsickle_Closure_declarations() {
/** @type {number} */
SuperTestBaseOneArg.prototype.x;
}
// A ctor with a parameter property.

@@ -27,7 +27,7 @@ class SuperTestDerivedParamProps extends SuperTestBaseOneArg {

}
static _tsickle_typeAnnotationsHelper() {
/** @type {string} */
SuperTestDerivedParamProps.prototype.y;
}
}
function SuperTestDerivedParamProps_tsickle_Closure_declarations() {
/** @type {string} */
SuperTestDerivedParamProps.prototype.y;
}
// A ctor with an initialized property.

@@ -39,7 +39,7 @@ class SuperTestDerivedInitializedProps extends SuperTestBaseOneArg {

}
static _tsickle_typeAnnotationsHelper() {
/** @type {string} */
SuperTestDerivedInitializedProps.prototype.y;
}
}
function SuperTestDerivedInitializedProps_tsickle_Closure_declarations() {
/** @type {string} */
SuperTestDerivedInitializedProps.prototype.y;
}
// A ctor with a super() but none of the above two details.

@@ -63,13 +63,13 @@ class SuperTestDerivedOrdinary extends SuperTestBaseOneArg {

class SuperTestDerivedInterface {
static _tsickle_typeAnnotationsHelper() {
/** @type {number} */
SuperTestDerivedInterface.prototype.foo;
}
}
function SuperTestDerivedInterface_tsickle_Closure_declarations() {
/** @type {number} */
SuperTestDerivedInterface.prototype.foo;
}
class SuperTestStaticProp extends SuperTestBaseOneArg {
static _tsickle_typeAnnotationsHelper() {
/** @type {number} */
SuperTestStaticProp.foo;
}
}
SuperTestStaticProp.foo = 3;
function SuperTestStaticProp_tsickle_Closure_declarations() {
/** @type {number} */
SuperTestStaticProp.foo;
}

@@ -10,10 +10,10 @@ class SuperTestBaseNoArg {

constructor(public x: number) {}
}
static _tsickle_typeAnnotationsHelper() {
function SuperTestBaseOneArg_tsickle_Closure_declarations() {
/** @type {number} */
SuperTestBaseOneArg.prototype.x;
}
}
// A ctor with a parameter property.

@@ -27,10 +27,10 @@ class SuperTestDerivedParamProps extends SuperTestBaseOneArg {

}
}
static _tsickle_typeAnnotationsHelper() {
function SuperTestDerivedParamProps_tsickle_Closure_declarations() {
/** @type {string} */
SuperTestDerivedParamProps.prototype.y;
}
}
// A ctor with an initialized property.

@@ -42,10 +42,10 @@ class SuperTestDerivedInitializedProps extends SuperTestBaseOneArg {

}
}
static _tsickle_typeAnnotationsHelper() {
function SuperTestDerivedInitializedProps_tsickle_Closure_declarations() {
/** @type {string} */
SuperTestDerivedInitializedProps.prototype.y;
}
}
// A ctor with a super() but none of the above two details.

@@ -81,18 +81,18 @@ class SuperTestDerivedOrdinary extends SuperTestBaseOneArg {

foo: number;
}
static _tsickle_typeAnnotationsHelper() {
function SuperTestDerivedInterface_tsickle_Closure_declarations() {
/** @type {number} */
SuperTestDerivedInterface.prototype.foo;
}
}
class SuperTestStaticProp extends SuperTestBaseOneArg {
static foo = 3;
}
static _tsickle_typeAnnotationsHelper() {
function SuperTestStaticProp_tsickle_Closure_declarations() {
/** @type {number} */
SuperTestStaticProp.foo;
}
}
}
goog.module('test_files.type_and_value.module');var module = module || {id: 'test_files/type_and_value/module.js'};
exports.TypeAndValue = 3;
class Class {
static _tsickle_typeAnnotationsHelper() {
/** @type {number} */
Class.prototype.z;
}
}
exports.Class = Class;
function Class_tsickle_Closure_declarations() {
/** @type {number} */
Class.prototype.z;
}

@@ -6,8 +6,7 @@ // TypeAndValue is both a type and a value, which is allowed in TypeScript

export class Class { z: number
export class Class { z: number }
static _tsickle_typeAnnotationsHelper() {
function Class_tsickle_Closure_declarations() {
/** @type {number} */
Class.prototype.z;
}
}
}

@@ -5,10 +5,10 @@ goog.module('test_files.type_and_value.type_and_value');var module = module || {id: 'test_files/type_and_value/type_and_value.js'};

// Use a browser built-in as both a type and a value.
let /** @type {{prototype: Document, __new: ?}} */ useBuiltInAsValue = Document;
let /** @type {Document} */ useBuiltInAsType = null;
let /** @type {function(new: Document): ?} */ useBuiltInAsValue = Document;
let /** @type {!Document} */ useBuiltInAsType;
// Use a user-defined class as both a type and a value.
let /** @type {?} */ useUserClassAsValue = conflict.Class;
let /** @type {conflict.Class} */ useUserClassAsType = null;
let /** @type {!conflict.Class} */ useUserClassAsType;
// Use a user-defined interface/value pair as both a type and a value.
let /** @type {number} */ useAsValue = conflict.TypeAndValue;
// Note: because of the conflict, we currently just use the type {?} here.
let /** @type {?} */ useAsType = null;
let /** @type {?} */ useAsType;

@@ -7,7 +7,7 @@ import * as conflict from './module';

let useBuiltInAsValue = Document;
let useBuiltInAsType: Document = null;
let useBuiltInAsType: Document;
// Use a user-defined class as both a type and a value.
let useUserClassAsValue = conflict.Class;
let useUserClassAsType: conflict.Class = null;
let useUserClassAsType: conflict.Class;

@@ -17,2 +17,2 @@ // Use a user-defined interface/value pair as both a type and a value.

// Note: because of the conflict, we currently just use the type {?} here.
let useAsType: conflict.TypeAndValue = null;
let useAsType: conflict.TypeAndValue;

@@ -9,8 +9,8 @@ Warning at test_files/type_and_value/type_and_value.ts:10:5: unhandled anonymous type

// Use a browser built-in as both a type and a value.
let /** @type {{prototype: Document, __new: ?}} */ useBuiltInAsValue = Document;
let /** @type {Document} */ useBuiltInAsType: Document = null;
let /** @type {function(new: Document): ?} */ useBuiltInAsValue = Document;
let /** @type {!Document} */ useBuiltInAsType: Document;
// Use a user-defined class as both a type and a value.
let /** @type {?} */ useUserClassAsValue = conflict.Class;
let /** @type {conflict.Class} */ useUserClassAsType: conflict.Class = null;
let /** @type {!conflict.Class} */ useUserClassAsType: conflict.Class;

@@ -20,2 +20,2 @@ // Use a user-defined interface/value pair as both a type and a value.

// Note: because of the conflict, we currently just use the type {?} here.
let /** @type {?} */ useAsType: conflict.TypeAndValue = null;
let /** @type {?} */ useAsType: conflict.TypeAndValue;
goog.module('test_files.type.type');var module = module || {id: 'test_files/type/type.js'};let /** @type {?} */ typeAny;
let /** @type {Array<?>} */ typeArr = null;
let /** @type {Array<?>} */ typeArr2 = null;
let /** @type {Array<Array<{a: ?}>>} */ typeNestedArr = null;
let /** @type {!Array<?>} */ typeArr;
let /** @type {!Array<?>} */ typeArr2;
let /** @type {!Array<!Array<{a: ?}>>} */ typeNestedArr;
let /** @type {{a: number, b: string}} */ typeObject = { a: 3, b: 'b' };
let /** @type {Object<string,number>} */ typeObject2 = null;
let /** @type {?} */ typeObject3 = null;
let /** @type {Object} */ typeObjectEmpty = null;
let /** @type {!Object<string,number>} */ typeObject2;
let /** @type {?} */ typeObject3;
let /** @type {!Object} */ typeObjectEmpty;
let /** @type {(string|boolean)} */ typeUnion = Math.random() > 0.5 ? false : '';
let /** @type {(string|boolean)} */ typeUnion2 = Math.random() > 0.5 ? false : '';
let /** @type {{optional: (boolean|undefined)}} */ typeOptionalField = {};
let /** @type {{optional: ((string|boolean)|undefined)}} */ typeOptionalUnion = {};
let /** @type {{optional: (undefined|boolean)}} */ typeOptionalField = {};
let /** @type {{optional: (undefined|string|boolean)}} */ typeOptionalUnion = {};
let /** @type {function(): void} */ typeFunc = function () { };

@@ -14,0 +14,0 @@ let /** @type {function(number, ?): string} */ typeFunc2 = function (a, b) { return ''; };

@@ -8,9 +8,9 @@ // Ensure we still understand what Array is, even when it has been

let typeAny: any;
let typeArr: Array<any> = null;
let typeArr2: any[] = null;
let typeNestedArr: {a:any}[][] = null;
let typeArr: Array<any>;
let typeArr2: any[];
let typeNestedArr: {a:any}[][];
let typeObject: {a:number, b:string} = {a:3, b:'b'};
let typeObject2: {[key:string]: number} = null;
let typeObject3: {a:number, [key:string]: number} = null;
let typeObjectEmpty: {} = null;
let typeObject2: {[key:string]: number};
let typeObject3: {a:number, [key:string]: number};
let typeObjectEmpty: {};

@@ -17,0 +17,0 @@ let typeUnion: string|boolean = Math.random() > 0.5 ? false : '';

@@ -12,14 +12,14 @@ Warning at test_files/type/type.ts:13:5: unhandled type literal

let /** @type {?} */ typeAny: any;
let /** @type {Array<?>} */ typeArr: Array<any> = null;
let /** @type {Array<?>} */ typeArr2: any[] = null;
let /** @type {Array<Array<{a: ?}>>} */ typeNestedArr: {a:any}[][] = null;
let /** @type {!Array<?>} */ typeArr: Array<any>;
let /** @type {!Array<?>} */ typeArr2: any[];
let /** @type {!Array<!Array<{a: ?}>>} */ typeNestedArr: {a:any}[][];
let /** @type {{a: number, b: string}} */ typeObject: {a:number, b:string} = {a:3, b:'b'};
let /** @type {Object<string,number>} */ typeObject2: {[key:string]: number} = null;
let /** @type {?} */ typeObject3: {a:number, [key:string]: number} = null;
let /** @type {Object} */ typeObjectEmpty: {} = null;
let /** @type {!Object<string,number>} */ typeObject2: {[key:string]: number};
let /** @type {?} */ typeObject3: {a:number, [key:string]: number};
let /** @type {!Object} */ typeObjectEmpty: {};
let /** @type {(string|boolean)} */ typeUnion: string|boolean = Math.random() > 0.5 ? false : '';
let /** @type {(string|boolean)} */ typeUnion2: (string|boolean) = Math.random() > 0.5 ? false : '';
let /** @type {{optional: (boolean|undefined)}} */ typeOptionalField: {optional?: boolean} = {};
let /** @type {{optional: ((string|boolean)|undefined)}} */ typeOptionalUnion: {optional?: string|boolean} = {};
let /** @type {{optional: (undefined|boolean)}} */ typeOptionalField: {optional?: boolean} = {};
let /** @type {{optional: (undefined|string|boolean)}} */ typeOptionalUnion: {optional?: string|boolean} = {};

@@ -26,0 +26,0 @@ let /** @type {function(): void} */ typeFunc: () => void = function() {};

@@ -7,1 +7,3 @@ goog.module('test_files.typedef.typedef');var module = module || {id: 'test_files/typedef/typedef.js'};

var Recursive;
/** @typedef {string} */
exports.ExportedType;

@@ -6,2 +6,2 @@ type MyType = number;

export type ExportedType = string;
export type ExportedType = string;
type MyType = number;
/** @typedef {number} */
var MyType: void;
var MyType;

@@ -9,3 +9,3 @@ var /** @type {number} */ y: MyType = 3;

/** @typedef {{value: number, next: ?}} */
var Recursive: void;
var Recursive;

@@ -15,2 +15,3 @@

/** @typedef {string} */
export var ExportedType: void;
exports.ExportedType;

@@ -16,8 +16,8 @@ goog.module('test_files.underscore.underscore');var module = module || {id: 'test_files/underscore/underscore.js'};// Verify that double-underscored names in various places don't get corrupted.

}
static _tsickle_typeAnnotationsHelper() {
/** @type {string} */
__Class.prototype.__member;
}
}
function __Class_tsickle_Closure_declarations() {
/** @type {string} */
__Class.prototype.__member;
}
/** @record */
function __Interface() { }

@@ -17,9 +17,9 @@ // Verify that double-underscored names in various places don't get corrupted.

}
}
static _tsickle_typeAnnotationsHelper() {
function __Class_tsickle_Closure_declarations() {
/** @type {string} */
__Class.prototype.__member;
}
}
}
/** @record */

@@ -26,0 +26,0 @@ function __Interface() {}

@@ -93,3 +93,3 @@ /**

/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
];

@@ -129,3 +129,3 @@ }`);

/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
];

@@ -148,3 +148,3 @@ }`);

/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
];

@@ -176,3 +176,3 @@ }`);

/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
];

@@ -185,3 +185,3 @@ }

/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
];

@@ -218,3 +218,3 @@ }`);

/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
{type: AbstractService, decorators: [{ type: Inject }, ]},

@@ -245,3 +245,3 @@ {type: AnEnum, decorators: [{ type: Inject, args: ['enum', ] }, ]},

/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
{type: BarService, },

@@ -269,3 +269,3 @@ null,

/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
{type: bar.BarService, decorators: [{ type: Inject, args: [param, ] }, ]},

@@ -291,3 +291,3 @@ null,

/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
{type: undefined, decorators: [{ type: Inject, args: [APP_ID, ] }, ]},

@@ -310,3 +310,3 @@ ];

/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
{type: Promise, decorators: [{ type: Inject }, ]},

@@ -331,3 +331,3 @@ ];

/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
static ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [
{type: Class, decorators: [{ type: Inject }, ]},

@@ -334,0 +334,0 @@ {type: undefined, decorators: [{ type: Inject }, ]},

@@ -30,3 +30,4 @@ /**

expectCommonJs('a.js', `console.log('hello');`, false)
.to.equal(`goog.module('a');var module = {id: 'a.js'};console.log('hello');`);
.to.equal(
`goog.module('a'); exports = {}; var module = {id: 'a.js'};console.log('hello');`);
});

@@ -101,3 +102,3 @@

`goog.module('a');var module = module || {id: 'a.js'};var tsickle_module_0_ = goog.require('req.mod');__export(tsickle_module_0_);
var mod2 = goog.require('req.mod');`);
var mod2 = tsickle_module_0_;`);
});

@@ -167,3 +168,3 @@ it('reuses an existing imported variable name', () => {

`).to.equal(`goog.module('a.b');var module = module || {id: 'a/b.js'};var foo_1 = goog.require('foo');
var foo_2 = goog.require('foo');
var foo_2 = foo_1;
foo_1.A, foo_2.B, foo_2 , foo_3.default;

@@ -170,0 +171,0 @@ `);

@@ -33,3 +33,3 @@ /**

{tagName: 'param', parameterName: 'foo'},
{tagName: 'param', parameterName: 'bar', text: 'multiple line comment'},
{tagName: 'param', parameterName: 'bar', text: 'multiple\n line comment'},
{tagName: 'return', text: 'foobar'},

@@ -36,0 +36,0 @@ {tagName: 'nosideeffects'},

@@ -26,9 +26,13 @@ /**

const consumer = new SourceMapConsumer(rawMap);
const lines = annotated.output.split('\n');
// Uncomment to debug contents:
// annotated.output.split('\n').forEach((v, i) => console.log(i + 1, v));
expect(consumer.originalPositionFor({line: 2, column: 20}).line)
// lines.forEach((v, i) => console.log(i + 1, v));
// Find class X and class Y in the output to make the test robust against code changes.
const firstClassLine = lines.findIndex(l => l.indexOf('class X') !== -1) + 1;
const secondClassLine = lines.findIndex(l => l.indexOf('class Y') !== -1) + 1;
expect(consumer.originalPositionFor({line: firstClassLine, column: 20}).line)
.to.equal(2, 'first class definition');
expect(consumer.originalPositionFor({line: 9, column: 20}).line)
expect(consumer.originalPositionFor({line: secondClassLine, column: 20}).line)
.to.equal(3, 'second class definition');
});
});

@@ -30,2 +30,3 @@ /**

outDir: '.',
strictNullChecks: true,
};

@@ -32,0 +33,0 @@

@@ -20,4 +20,4 @@ /**

let RUN_TESTS_MATCHING: RegExp|null = null;
// RUN_TESTS_MATCHING = /fields/;
const TEST_FILTER: RegExp|null =
process.env.TEST_FILTER ? new RegExp(process.env.TEST_FILTER) : null;

@@ -70,5 +70,8 @@ // If true, update all the golden .js files to be whatever tsickle

describe('golden tests', () => {
// Only run golden tests if we filter for a specific one.
const testFn = TEST_FILTER ? describe.only : describe;
testFn('golden tests', () => {
testSupport.goldenTests().forEach((test) => {
if (RUN_TESTS_MATCHING && !RUN_TESTS_MATCHING.exec(test.name)) {
if (TEST_FILTER && !TEST_FILTER.exec(test.name)) {
it.skip(test.name);

@@ -75,0 +78,0 @@ return;

@@ -8,3 +8,3 @@ {

"target": "es5",
"lib": ["es5", "es2015.collection", "es2015.iterable", "dom"],
"lib": ["es5", "es6", "es2015.collection", "es2015.iterable", "dom"],
"jsx": "react",

@@ -11,0 +11,0 @@ "types": ["node", "mocha"],

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

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

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