Socket
Socket
Sign inDemoInstall

@angular/tsc-wrapped

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@angular/tsc-wrapped - npm Package Compare versions

Comparing version 5.0.0-beta.0 to 5.0.0-beta.1

README.md

4

package.json
{
"name": "@angular/tsc-wrapped",
"version": "5.0.0-beta.0",
"version": "5.0.0-beta.1",
"description": "Wraps the tsc CLI, allowing extensions.",
"homepage": "https://github.com/angular/angular/blob/master/tools/@angular/tsc-wrapped",
"homepage": "https://github.com/angular/angular/blob/master/packages/tsc-wrapped",
"bugs": "https://github.com/angular/angular/issues",

@@ -7,0 +7,0 @@ "contributors": [

@@ -16,3 +16,3 @@ import * as ts from 'typescript';

export interface MetadataBundlerHost {
getMetadataFor(moduleName: string): ModuleMetadata;
getMetadataFor(moduleName: string): ModuleMetadata | undefined;
}

@@ -61,3 +61,3 @@ export declare class MetadataBundler {

constructor(host: ts.CompilerHost);
getMetadataFor(fileName: string): ModuleMetadata;
getMetadataFor(fileName: string): ModuleMetadata | undefined;
}

@@ -206,2 +206,3 @@ "use strict";

if (symbol.reexport) {
// symbol.declaration is guarenteed to be defined during the phase this method is called.
var declaration = symbol.declaration;

@@ -232,5 +233,7 @@ var module_1 = declaration.module;

MetadataBundler.prototype.convertSymbol = function (symbol) {
// canonicalSymbol is ensured to be defined before this is called.
var canonicalSymbol = symbol.canonicalSymbol;
if (!canonicalSymbol.referenced) {
canonicalSymbol.referenced = true;
// declaration is ensured to be definded before this method is called.
var declaration = canonicalSymbol.declaration;

@@ -237,0 +240,0 @@ var module_2 = this.getMetadata(declaration.module);

@@ -9,5 +9,5 @@ /**

export declare class CliOptions {
basePath: string;
basePath: string | null;
constructor({basePath}: {
basePath?: string;
basePath?: string | null;
});

@@ -26,13 +26,13 @@ }

export declare class NgcCliOptions extends CliOptions {
i18nFormat: string;
i18nFile: string;
locale: string;
missingTranslation: string;
i18nFormat: string | null;
i18nFile: string | null;
locale: string | null;
missingTranslation: string | null;
constructor({i18nFormat, i18nFile, locale, missingTranslation, basePath}: {
i18nFormat?: string;
i18nFile?: string;
locale?: string;
missingTranslation?: string;
basePath?: string;
i18nFormat?: string | null;
i18nFile?: string | null;
locale?: string | null;
missingTranslation?: string | null;
basePath?: string | null;
});
}

@@ -38,3 +38,3 @@ /**

*/
getMetadata(sourceFile: ts.SourceFile, strict?: boolean): ModuleMetadata;
getMetadata(sourceFile: ts.SourceFile, strict?: boolean): ModuleMetadata | undefined;
}

@@ -53,3 +53,3 @@ "use strict";

var metadata;
var exports;
var exports = undefined;
function objFromDecorator(decoratorNode) {

@@ -66,3 +66,3 @@ return evaluator.evaluateNode(decoratorNode.expression);

function maybeGetSimpleFunction(functionDeclaration) {
if (functionDeclaration.name.kind == ts.SyntaxKind.Identifier) {
if (functionDeclaration.name && functionDeclaration.name.kind == ts.SyntaxKind.Identifier) {
var nameNode = functionDeclaration.name;

@@ -233,2 +233,3 @@ var functionName = nameNode.text;

if (!moduleSpecifier) {
// If there is a module specifier there is also an exportClause
exportClause.elements.forEach(function (spec) {

@@ -242,6 +243,8 @@ var exportedAs = spec.name.text;

});
var isExportedIdentifier = function (identifier) { return exportMap.has(identifier.text); };
var isExportedIdentifier = function (identifier) {
return identifier && exportMap.has(identifier.text);
};
var isExported = function (node) { return isExport(node) || isExportedIdentifier(node.name); };
var exportedIdentifierName = function (identifier) {
return exportMap.get(identifier.text) || identifier.text;
return identifier && (exportMap.get(identifier.text) || identifier.text);
};

@@ -325,5 +328,8 @@ var exportedName = function (node) { return exportedIdentifierName(node.name); };

if (isExported(classDeclaration)) {
if (!metadata)
metadata = {};
metadata[exportedName(classDeclaration)] = classMetadataOf(classDeclaration);
var name_4 = exportedName(classDeclaration);
if (name_4) {
if (!metadata)
metadata = {};
metadata[name_4] = classMetadataOf(classDeclaration);
}
}

@@ -336,5 +342,8 @@ }

if (interfaceDeclaration.name && isExported(interfaceDeclaration)) {
if (!metadata)
metadata = {};
metadata[exportedName(interfaceDeclaration)] = { __symbolic: 'interface' };
var name_5 = exportedName(interfaceDeclaration);
if (name_5) {
if (!metadata)
metadata = {};
metadata[name_5] = { __symbolic: 'interface' };
}
}

@@ -347,8 +356,10 @@ break;

if (isExported(functionDeclaration) && functionDeclaration.name) {
if (!metadata)
metadata = {};
var name_4 = exportedName(functionDeclaration);
var name_6 = exportedName(functionDeclaration);
var maybeFunc = maybeGetSimpleFunction(functionDeclaration);
metadata[name_4] =
maybeFunc ? recordEntry(maybeFunc.func, node) : { __symbolic: 'function' };
if (name_6) {
if (!metadata)
metadata = {};
metadata[name_6] =
maybeFunc ? recordEntry(maybeFunc.func, node) : { __symbolic: 'function' };
}
}

@@ -372,7 +383,7 @@ break;

}
var name_5 = undefined;
var name_7 = undefined;
if (member.name.kind == ts.SyntaxKind.Identifier) {
var identifier = member.name;
name_5 = identifier.text;
enumValueHolder[name_5] = enumValue;
name_7 = identifier.text;
enumValueHolder[name_7] = enumValue;
writtenMembers++;

@@ -383,3 +394,3 @@ }

}
else if (name_5) {
else if (name_7) {
nextDefaultValue = {

@@ -390,3 +401,3 @@ __symbolic: 'binary',

__symbolic: 'select',
expression: recordEntry({ __symbolic: 'reference', name: enumName }, node), name: name_5
expression: recordEntry({ __symbolic: 'reference', name: enumName }, node), name: name_7
}

@@ -401,5 +412,7 @@ };

if (writtenMembers) {
if (!metadata)
metadata = {};
metadata[enumName] = recordEntry(enumValueHolder, node);
if (enumName) {
if (!metadata)
metadata = {};
metadata[enumName] = recordEntry(enumValueHolder, node);
}
}

@@ -423,5 +436,8 @@ }

isExportedIdentifier(nameNode)) {
if (!metadata)
metadata = {};
metadata[exportedIdentifierName(nameNode)] = recordEntry(varValue, node);
var name_8 = exportedIdentifierName(nameNode);
if (name_8) {
if (!metadata)
metadata = {};
metadata[name_8] = recordEntry(varValue, node);
}
exported = true;

@@ -454,9 +470,9 @@ }

case ts.SyntaxKind.Identifier:
var name_6 = nameNode;
var varValue = errorSym('Destructuring not supported', name_6);
locals.define(name_6.text, varValue);
var name_9 = nameNode;
var varValue = errorSym('Destructuring not supported', name_9);
locals.define(name_9.text, varValue);
if (isExport(node)) {
if (!metadata)
metadata = {};
metadata[name_6.text] = varValue;
metadata[name_9.text] = varValue;
}

@@ -663,5 +679,5 @@ break;

var element = _a[_i];
var name_7 = element.name;
if (name_7) {
addNamesOf(name_7);
var name_10 = element.name;
if (name_10) {
addNamesOf(name_10);
}

@@ -668,0 +684,0 @@ }

@@ -11,3 +11,3 @@ import * as ts from 'typescript';

constructor(delegate: ts.CompilerHost);
getSourceFile: (fileName: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void) => ts.SourceFile;
getSourceFile: (fileName: string, languageVersion: ts.ScriptTarget, onError?: ((message: string) => void) | undefined) => ts.SourceFile;
getCancellationToken: () => ts.CancellationToken;

@@ -47,4 +47,4 @@ getDefaultLibFileName: (options: ts.CompilerOptions) => string;

readFile: (fileName: string) => string;
getSourceFile: (fileName: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void) => ts.SourceFile;
getSourceFile: (fileName: string, languageVersion: ts.ScriptTarget, onError?: ((message: string) => void) | undefined) => ts.SourceFile;
writeFile: ts.WriteFileCallback;
}

@@ -106,3 +106,3 @@ "use strict";

if (/\.js$/.test(emitFilePath)) {
var path_2 = emitFilePath.replace(/*DTS*/ /\.js$/, '.metadata.json');
var path = emitFilePath.replace(/*DTS*/ /\.js$/, '.metadata.json');
// Beginning with 2.1, TypeScript transforms the source tree before emitting it.

@@ -121,3 +121,3 @@ // We need the original, unmodified, tree which might be several levels back

var metadataText = JSON.stringify(metadatas);
fs_1.writeFileSync(path_2, metadataText, { encoding: 'utf-8' });
fs_1.writeFileSync(path, metadataText, { encoding: 'utf-8' });
}

@@ -154,3 +154,3 @@ }

var metadataName = fileName.replace(DTS, '.metadata.json');
fs_1.writeFileSync(metadataName, _this.indexMetadata, 'utf8');
fs_1.writeFileSync(metadataName, _this.indexMetadata, { encoding: 'utf8' });
}

@@ -157,0 +157,0 @@ };

@@ -35,3 +35,3 @@ /**

constructor(symbols: Symbols, nodeMap: Map<MetadataEntry, ts.Node>, options?: CollectorOptions);
nameOf(node: ts.Node): string | MetadataError;
nameOf(node: ts.Node | undefined): string | MetadataError;
/**

@@ -38,0 +38,0 @@ * Returns true if the expression represented by `node` can be folded into a literal expression.

@@ -56,3 +56,3 @@ "use strict";

function errorSymbol(message, node, context, sourceFile) {
var result;
var result = undefined;
if (node) {

@@ -86,6 +86,6 @@ sourceFile = sourceFile || getSourceFileOfNode(node);

Evaluator.prototype.nameOf = function (node) {
if (node.kind == ts.SyntaxKind.Identifier) {
if (node && node.kind == ts.SyntaxKind.Identifier) {
return node.text;
}
var result = this.evaluateNode(node);
var result = node && this.evaluateNode(node);
if (schema_1.isMetadataError(result) || typeof result === 'string') {

@@ -95,3 +95,3 @@ return result;

else {
return errorSymbol('Name expected', node, { received: node.getText() });
return errorSymbol('Name expected', node, { received: (node && node.getText()) || '<missing>' });
}

@@ -297,5 +297,5 @@ };

}
var args_1 = arrayOrEmpty(callExpression.arguments).map(function (arg) { return _this.evaluateNode(arg); });
if (!this.options.verboseInvalidExpression && args_1.some(schema_1.isMetadataError)) {
return args_1.find(schema_1.isMetadataError);
var args = arrayOrEmpty(callExpression.arguments).map(function (arg) { return _this.evaluateNode(arg); });
if (!this.options.verboseInvalidExpression && args.some(schema_1.isMetadataError)) {
return args.find(schema_1.isMetadataError);
}

@@ -307,3 +307,3 @@ if (this.isFoldable(callExpression)) {

return arrayValue;
return arrayValue.concat(args_1[0]);
return arrayValue.concat(args[0]);
}

@@ -314,3 +314,3 @@ }

arrayOrEmpty(callExpression.arguments).length === 1) {
return recordEntry(args_1[0], node);
return recordEntry(args[0], node);
}

@@ -322,4 +322,4 @@ var expression = this.evaluateNode(callExpression.expression);

var result = { __symbolic: 'call', expression: expression };
if (args_1 && args_1.length) {
result.arguments = args_1;
if (args && args.length) {
result.arguments = args;
}

@@ -415,6 +415,6 @@ return recordEntry(result, node);

typeReferenceNode.typeArguments && typeReferenceNode.typeArguments.length) {
var args_2 = typeReferenceNode.typeArguments.map(function (element) { return _this.evaluateNode(element); });
var args_1 = typeReferenceNode.typeArguments.map(function (element) { return _this.evaluateNode(element); });
// TODO: Remove typecast when upgraded to 2.0 as it will be corretly inferred.
// Some versions of 1.9 do not infer this correctly.
typeReference.arguments = args_2;
typeReference.arguments = args_1;
}

@@ -634,3 +634,3 @@ return recordEntry(typeReference, node);

}
var empty = [];
var empty = ts.createNodeArray();
function arrayOrEmpty(v) {

@@ -637,0 +637,0 @@ return v || empty;

@@ -164,9 +164,9 @@ "use strict";

if (require.main === module) {
var args_1 = process.argv.slice(2);
var _a = ts.parseCommandLine(args_1), options = _a.options, errors = _a.errors;
var args = process.argv.slice(2);
var _a = ts.parseCommandLine(args), options = _a.options, errors = _a.errors;
tsc_1.check(errors);
var project = options.project || '.';
// TODO(alexeagle): command line should be TSC-compatible, remove "CliOptions" here
var cliOptions = new cli_options_1.CliOptions(require('minimist')(args_1));
main(project, cliOptions, null, options)
var cliOptions = new cli_options_1.CliOptions(require('minimist')(args));
main(project, cliOptions, undefined, options)
.then(function (exitCode) { return process.exit(exitCode); })

@@ -173,0 +173,0 @@ .catch(function (e) {

@@ -55,3 +55,3 @@ /**

__symbolic: 'constructor' | 'method';
parameterDecorators?: (MetadataSymbolicExpression | MetadataError)[][];
parameterDecorators?: ((MetadataSymbolicExpression | MetadataError)[] | undefined)[];
}

@@ -61,3 +61,3 @@ export declare function isMethodMetadata(value: any): value is MethodMetadata;

__symbolic: 'constructor';
parameters?: (MetadataSymbolicExpression | MetadataError | null)[];
parameters?: (MetadataSymbolicExpression | MetadataError | null | undefined)[];
}

@@ -72,3 +72,3 @@ export declare function isConstructorMetadata(value: any): value is ConstructorMetadata;

export declare function isFunctionMetadata(value: any): value is FunctionMetadata;
export declare type MetadataValue = string | number | boolean | MetadataObject | MetadataArray | MetadataSymbolicExpression | MetadataError;
export declare type MetadataValue = string | number | boolean | undefined | null | MetadataObject | MetadataArray | MetadataSymbolicExpression | MetadataError;
export interface MetadataObject {

@@ -75,0 +75,0 @@ [name: string]: MetadataValue;

@@ -49,18 +49,19 @@ "use strict";

var externalReference = importEqualsDeclaration.moduleReference;
// An `import <identifier> = require(<module-specifier>);
if (!externalReference.expression.parent) {
// The `parent` field of a node is set by the TypeScript binder (run as
// part of the type checker). Setting it here allows us to call `getText()`
// even if the `SourceFile` was not type checked (which looks for `SourceFile`
// in the parent chain). This doesn't damage the node as the binder unconditionally
// sets the parent.
externalReference.expression.parent = externalReference;
externalReference.parent = _this.sourceFile;
if (externalReference.expression) {
// An `import <identifier> = require(<module-specifier>);
if (!externalReference.expression.parent) {
// The `parent` field of a node is set by the TypeScript binder (run as
// part of the type checker). Setting it here allows us to call `getText()`
// even if the `SourceFile` was not type checked (which looks for `SourceFile`
// in the parent chain). This doesn't damage the node as the binder unconditionally
// sets the parent.
externalReference.expression.parent = externalReference;
externalReference.parent = _this.sourceFile;
}
var from_1 = stripQuotes(externalReference.expression.getText());
symbols.set(importEqualsDeclaration.name.text, { __symbolic: 'reference', module: from_1 });
break;
}
var from_1 = stripQuotes(externalReference.expression.getText());
symbols.set(importEqualsDeclaration.name.text, { __symbolic: 'reference', module: from_1 });
}
else {
symbols.set(importEqualsDeclaration.name.text, { __symbolic: 'error', message: "Unsupported import syntax" });
}
symbols.set(importEqualsDeclaration.name.text, { __symbolic: 'error', message: "Unsupported import syntax" });
break;

@@ -67,0 +68,0 @@ case ts.SyntaxKind.ImportDeclaration:

@@ -26,4 +26,4 @@ import * as ts from 'typescript';

export declare function formatDiagnostics(diags: ts.Diagnostic[]): string;
export declare function check(diags: ts.Diagnostic[]): void;
export declare function validateAngularCompilerOptions(options: AngularCompilerOptions): ts.Diagnostic[];
export declare function check(diags: ts.Diagnostic[] | undefined): void;
export declare function validateAngularCompilerOptions(options: AngularCompilerOptions): ts.Diagnostic[] | undefined;
export declare class Tsc implements CompilerInterface {

@@ -33,3 +33,3 @@ private readFile;

private parseConfigHost;
constructor(readFile?: (path: string, encoding?: string) => string, readDirectory?: (path: string, extensions?: string[], exclude?: string[], include?: string[]) => string[]);
constructor(readFile?: (path: string, encoding?: string | undefined) => string, readDirectory?: (path: string, extensions?: string[] | undefined, exclude?: string[] | undefined, include?: string[] | undefined) => string[]);
readConfiguration(project: string | VinylFile, basePath: string, existingOptions?: ts.CompilerOptions): {

@@ -36,0 +36,0 @@ parsed: ts.ParsedCommandLine;

@@ -10,3 +10,3 @@ import { MetadataBundlerHost } from '../src/bundler';

constructor(dirName: string, directory: Directory);
getMetadataFor(moduleName: string): ModuleMetadata;
getMetadataFor(moduleName: string): ModuleMetadata | undefined;
}

@@ -13,0 +13,0 @@ export declare const SIMPLE_LIBRARY: {

@@ -46,6 +46,6 @@ "use strict";

var consts = program.getSourceFile('consts.ts');
expect(evaluator.isFoldable(typescript_mocks_1.findVar(consts, 'someName').initializer)).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVar(consts, 'someBool').initializer)).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVar(consts, 'one').initializer)).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVar(consts, 'two').initializer)).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVarInitializer(consts, 'someName'))).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVarInitializer(consts, 'someBool'))).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVarInitializer(consts, 'one'))).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVarInitializer(consts, 'two'))).toBeTruthy();
});

@@ -58,15 +58,15 @@ it('should be able to fold expressions with foldable references', function () {

symbols.define('two', 2);
expect(evaluator.isFoldable(typescript_mocks_1.findVar(expressions, 'three').initializer)).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVar(expressions, 'four').initializer)).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVarInitializer(expressions, 'three'))).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVarInitializer(expressions, 'four'))).toBeTruthy();
symbols.define('three', 3);
symbols.define('four', 4);
expect(evaluator.isFoldable(typescript_mocks_1.findVar(expressions, 'obj').initializer)).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVar(expressions, 'arr').initializer)).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVarInitializer(expressions, 'obj'))).toBeTruthy();
expect(evaluator.isFoldable(typescript_mocks_1.findVarInitializer(expressions, 'arr'))).toBeTruthy();
});
it('should be able to evaluate literal expressions', function () {
var consts = program.getSourceFile('consts.ts');
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(consts, 'someName').initializer)).toBe('some-name');
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(consts, 'someBool').initializer)).toBe(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(consts, 'one').initializer)).toBe(1);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(consts, 'two').initializer)).toBe(2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(consts, 'someName'))).toBe('some-name');
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(consts, 'someBool'))).toBe(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(consts, 'one'))).toBe(1);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(consts, 'two'))).toBe(2);
});

@@ -79,38 +79,37 @@ it('should be able to evaluate expressions', function () {

symbols.define('two', 2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'three').initializer)).toBe(3);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'three'))).toBe(3);
symbols.define('three', 3);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'four').initializer)).toBe(4);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'four'))).toBe(4);
symbols.define('four', 4);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'obj').initializer))
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'obj')))
.toEqual({ one: 1, two: 2, three: 3, four: 4 });
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'arr').initializer)).toEqual([1, 2, 3, 4]);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bTrue').initializer)).toEqual(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bFalse').initializer)).toEqual(false);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bAnd').initializer)).toEqual(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bOr').initializer)).toEqual(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'nDiv').initializer)).toEqual(2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'nMod').initializer)).toEqual(1);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bLOr').initializer)).toEqual(false || true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bLAnd').initializer)).toEqual(true && true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bBOr').initializer)).toEqual(0x11 | 0x22);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bBAnd').initializer)).toEqual(0x11 & 0x03);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bXor').initializer)).toEqual(0x11 ^ 0x21);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bEqual').initializer))
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'arr'))).toEqual([1, 2, 3, 4]);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bTrue'))).toEqual(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bFalse'))).toEqual(false);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bAnd'))).toEqual(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bOr'))).toEqual(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'nDiv'))).toEqual(2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'nMod'))).toEqual(1);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bLOr'))).toEqual(false || true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bLAnd'))).toEqual(true && true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bBOr'))).toEqual(0x11 | 0x22);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bBAnd'))).toEqual(0x11 & 0x03);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bXor'))).toEqual(0x11 ^ 0x21);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bEqual')))
.toEqual(1 == '1');
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bNotEqual').initializer))
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bNotEqual')))
.toEqual(1 != '1');
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bIdentical').initializer))
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bIdentical')))
.toEqual(1 === '1');
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bNotIdentical').initializer))
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bNotIdentical')))
.toEqual(1 !== '1');
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bLessThan').initializer)).toEqual(1 < 2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bGreaterThan').initializer)).toEqual(1 > 2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bLessThanEqual').initializer))
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bLessThan'))).toEqual(1 < 2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bGreaterThan'))).toEqual(1 > 2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bLessThanEqual')))
.toEqual(1 <= 2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bGreaterThanEqual').initializer))
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bGreaterThanEqual')))
.toEqual(1 >= 2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bShiftLeft').initializer)).toEqual(1 << 2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bShiftRight').initializer))
.toEqual(-1 >> 2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'bShiftRightU').initializer))
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bShiftLeft'))).toEqual(1 << 2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bShiftRight'))).toEqual(-1 >> 2);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'bShiftRightU')))
.toEqual(-1 >>> 2);

@@ -120,5 +119,5 @@ });

var expressions = program.getSourceFile('expressions.ts');
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'recursiveA').initializer))
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'recursiveA')))
.toEqual({ __symbolic: 'reference', name: 'recursiveB' });
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(expressions, 'recursiveB').initializer))
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(expressions, 'recursiveB')))
.toEqual({ __symbolic: 'reference', name: 'recursiveA' });

@@ -128,9 +127,9 @@ });

var const_expr = program.getSourceFile('const_expr.ts');
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(const_expr, 'bTrue').initializer)).toEqual(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(const_expr, 'bFalse').initializer)).toEqual(false);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(const_expr, 'bTrue'))).toEqual(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(const_expr, 'bFalse'))).toEqual(false);
});
it('should resolve a forwardRef', function () {
var forwardRef = program.getSourceFile('forwardRef.ts');
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(forwardRef, 'bTrue').initializer)).toEqual(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(forwardRef, 'bFalse').initializer)).toEqual(false);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(forwardRef, 'bTrue'))).toEqual(true);
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(forwardRef, 'bFalse'))).toEqual(false);
});

@@ -141,3 +140,3 @@ it('should return new expressions', function () {

var newExpression = program.getSourceFile('newExpression.ts');
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(newExpression, 'someValue').initializer)).toEqual({
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(newExpression, 'someValue'))).toEqual({
__symbolic: 'new',

@@ -147,3 +146,3 @@ expression: { __symbolic: 'reference', name: 'Value', module: './classes' },

});
expect(evaluator.evaluateNode(typescript_mocks_1.findVar(newExpression, 'complex').initializer)).toEqual({
expect(evaluator.evaluateNode(typescript_mocks_1.findVarInitializer(newExpression, 'complex'))).toEqual({
__symbolic: 'new',

@@ -150,0 +149,0 @@ expression: { __symbolic: 'reference', name: 'Value', module: './classes' },

@@ -167,3 +167,3 @@ "use strict";

var out = readOut('js.map');
expect(out).toContain('"sources":["other_test.ts"]');
expect(out).toContain('"sources":["other_test.ts","../test.ts"]');
done();

@@ -184,3 +184,3 @@ })

var out = readOut('js.map');
expect(out).toContain('"sources":["other_test.ts"]');
expect(out).toContain('"sources":["other_test.ts","../test.ts"]');
done();

@@ -187,0 +187,0 @@ })

@@ -14,3 +14,3 @@ import * as ts from 'typescript';

getScriptVersion(fileName: string): string;
getScriptSnapshot(fileName: string): ts.IScriptSnapshot;
getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined;
getCurrentDirectory(): string;

@@ -79,6 +79,7 @@ getDefaultLibFileName(options: ts.CompilerOptions): string;

export declare function allChildren<T>(node: ts.Node, cb: (node: ts.Node) => T): T;
export declare function findClass(sourceFile: ts.SourceFile, name: string): ts.ClassDeclaration;
export declare function findVar(sourceFile: ts.SourceFile, name: string): ts.VariableDeclaration;
export declare function findClass(sourceFile: ts.SourceFile, name: string): ts.ClassDeclaration | undefined;
export declare function findVar(sourceFile: ts.SourceFile, name: string): ts.VariableDeclaration | undefined;
export declare function findVarInitializer(sourceFile: ts.SourceFile, name: string): ts.Expression;
export declare function isClass(node: ts.Node): node is ts.ClassDeclaration;
export declare function isNamed(node: ts.Node, name: string): node is ts.Identifier;
export declare function isNamed(node: ts.Node | undefined, name: string): node is ts.Identifier;
export declare function isVar(node: ts.Node): node is ts.VariableDeclaration;

@@ -197,2 +197,8 @@ "use strict";

exports.findVar = findVar;
function findVarInitializer(sourceFile, name) {
var v = findVar(sourceFile, name);
expect(v && v.initializer).toBeDefined();
return v.initializer;
}
exports.findVarInitializer = findVarInitializer;
function isClass(node) {

@@ -203,3 +209,3 @@ return node.kind === ts.SyntaxKind.ClassDeclaration;

function isNamed(node, name) {
return node.kind === ts.SyntaxKind.Identifier && node.text === name;
return !!node && node.kind === ts.SyntaxKind.Identifier && node.text === name;
}

@@ -206,0 +212,0 @@ exports.isNamed = isNamed;

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

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

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

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