Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@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 0.2.2 to 0.3.0

src/cli_options.d.ts

1

index.d.ts
export { MetadataWriterHost, TsickleHost } from './src/compiler_host';
export { CodegenExtension, main } from './src/main';
export { default as AngularCompilerOptions } from './src/options';
export * from './src/cli_options';
export * from './src/collector';
export * from './src/schema';

@@ -10,4 +10,5 @@ "use strict";

exports.main = main_1.main;
__export(require('./src/cli_options'));
__export(require('./src/collector'));
__export(require('./src/schema'));
//# sourceMappingURL=index.js.map

6

package.json
{
"name": "@angular/tsc-wrapped",
"version": "0.2.2",
"version": "0.3.0",
"description": "Wraps the tsc CLI, allowing extensions.",

@@ -14,7 +14,7 @@ "homepage": "https://github.com/angular/angular/tree/master/tools/tsc-wrapped",

"dependencies": {
"tsickle": "0.1.6"
"tsickle": "^0.1.7"
},
"peerDependencies": {
"typescript": "^1.9.0-dev"
"typescript": "^2.0.2"
}
}

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

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

@@ -16,5 +16,7 @@ "use strict";

*/
MetadataCollector.prototype.getMetadata = function (sourceFile) {
MetadataCollector.prototype.getMetadata = function (sourceFile, strict) {
if (strict === void 0) { strict = false; }
var locals = new symbols_1.Symbols(sourceFile);
var evaluator = new evaluator_1.Evaluator(locals);
var nodeMap = new Map();
var evaluator = new evaluator_1.Evaluator(locals, nodeMap);
var metadata;

@@ -25,2 +27,6 @@ var exports;

}
function recordEntry(entry, node) {
nodeMap.set(entry, node);
return entry;
}
function errorSym(message, node, context) {

@@ -48,3 +54,3 @@ return evaluator_1.errorSymbol(message, node, context, sourceFile);

}
return { func: func, name: functionName };
return recordEntry({ func: func, name: functionName }, functionDeclaration);
}

@@ -175,5 +181,6 @@ }

}
return result.decorators || members || statics ? result : undefined;
return result.decorators || members || statics ? recordEntry(result, classDeclaration) :
undefined;
}
// Predeclare classes
// Predeclare classes and functions
ts.forEachChild(sourceFile, function (node) {

@@ -191,2 +198,10 @@ switch (node.kind) {

break;
case ts.SyntaxKind.FunctionDeclaration:
if (!(node.flags & ts.NodeFlags.Export)) {
// Report references to this function as an error.
var functionDeclaration = node;
var nameNode = functionDeclaration.name;
locals.define(nameNode.text, errorSym('Reference to a non-exported function', nameNode, { name: nameNode.text }));
}
break;
}

@@ -230,4 +245,4 @@ });

// names substitution will be performed by the StaticReflector.
var functionDeclaration = node;
if (node.flags & ts.NodeFlags.Export) {
var functionDeclaration = node;
var maybeFunc = maybeGetSimpleFunction(functionDeclaration);

@@ -237,52 +252,54 @@ if (maybeFunc) {

metadata = {};
metadata[maybeFunc.name] = maybeFunc.func;
metadata[maybeFunc.name] = recordEntry(maybeFunc.func, node);
}
}
// Otherwise don't record the function.
break;
case ts.SyntaxKind.EnumDeclaration:
var enumDeclaration = node;
var enumValueHolder = {};
var enumName = enumDeclaration.name.text;
var nextDefaultValue = 0;
var writtenMembers = 0;
for (var _i = 0, _a = enumDeclaration.members; _i < _a.length; _i++) {
var member = _a[_i];
var enumValue = void 0;
if (!member.initializer) {
enumValue = nextDefaultValue;
if (node.flags & ts.NodeFlags.Export) {
var enumDeclaration = node;
var enumValueHolder = {};
var enumName = enumDeclaration.name.text;
var nextDefaultValue = 0;
var writtenMembers = 0;
for (var _i = 0, _a = enumDeclaration.members; _i < _a.length; _i++) {
var member = _a[_i];
var enumValue = void 0;
if (!member.initializer) {
enumValue = nextDefaultValue;
}
else {
enumValue = evaluator.evaluateNode(member.initializer);
}
var name_4 = undefined;
if (member.name.kind == ts.SyntaxKind.Identifier) {
var identifier = member.name;
name_4 = identifier.text;
enumValueHolder[name_4] = enumValue;
writtenMembers++;
}
if (typeof enumValue === 'number') {
nextDefaultValue = enumValue + 1;
}
else if (name_4) {
nextDefaultValue = {
__symbolic: 'binary',
operator: '+',
left: {
__symbolic: 'select',
expression: recordEntry({ __symbolic: 'reference', name: enumName }, node), name: name_4
}
};
}
else {
nextDefaultValue =
recordEntry(errorSym('Unsuppported enum member name', member.name), node);
}
;
}
else {
enumValue = evaluator.evaluateNode(member.initializer);
if (writtenMembers) {
if (!metadata)
metadata = {};
metadata[enumName] = recordEntry(enumValueHolder, node);
}
var name_4 = undefined;
if (member.name.kind == ts.SyntaxKind.Identifier) {
var identifier = member.name;
name_4 = identifier.text;
enumValueHolder[name_4] = enumValue;
writtenMembers++;
}
if (typeof enumValue === 'number') {
nextDefaultValue = enumValue + 1;
}
else if (name_4) {
nextDefaultValue = {
__symbolic: 'binary',
operator: '+',
left: {
__symbolic: 'select',
expression: { __symbolic: 'reference', name: enumName }, name: name_4
}
};
}
else {
nextDefaultValue = errorSym('Unsuppported enum member name', member.name);
}
;
}
if (writtenMembers) {
if (!metadata)
metadata = {};
metadata[enumName] = enumValueHolder;
}
break;

@@ -299,3 +316,3 @@ case ts.SyntaxKind.VariableStatement:

else {
varValue = errorSym('Variable not initialized', nameNode);
varValue = recordEntry(errorSym('Variable not initialized', nameNode), nameNode);
}

@@ -307,3 +324,3 @@ var exported = false;

metadata = {};
metadata[nameNode.text] = varValue;
metadata[nameNode.text] = recordEntry(varValue, node);
exported = true;

@@ -315,3 +332,8 @@ }

else if (!exported) {
locals.define(nameNode.text, errorSym('Reference to a local symbol', nameNode, { name: nameNode.text }));
if (varValue && !schema_1.isMetadataError(varValue)) {
locals.define(nameNode.text, recordEntry(varValue, node));
}
else {
locals.define(nameNode.text, recordEntry(errorSym('Reference to a local symbol', nameNode, { name: nameNode.text }), node));
}
}

@@ -361,2 +383,5 @@ }

metadata = {};
else if (strict) {
validateMetadata(sourceFile, nodeMap, metadata);
}
var result = { __symbolic: 'module', version: schema_1.VERSION, metadata: metadata };

@@ -371,2 +396,138 @@ if (exports)

exports.MetadataCollector = MetadataCollector;
// This will throw if the metadata entry given contains an error node.
function validateMetadata(sourceFile, nodeMap, metadata) {
var locals = new Set(['Array', 'Object', 'Set', 'Map', 'string', 'number', 'any']);
function validateExpression(expression) {
if (!expression) {
return;
}
else if (Array.isArray(expression)) {
expression.forEach(validateExpression);
}
else if (typeof expression === 'object' && !expression.hasOwnProperty('__symbolic')) {
Object.getOwnPropertyNames(expression).forEach(function (v) { return validateExpression(expression[v]); });
}
else if (schema_1.isMetadataError(expression)) {
reportError(expression);
}
else if (schema_1.isMetadataGlobalReferenceExpression(expression)) {
if (!locals.has(expression.name)) {
var reference = metadata[expression.name];
if (reference) {
validateExpression(reference);
}
}
}
else if (schema_1.isFunctionMetadata(expression)) {
validateFunction(expression);
}
else if (schema_1.isMetadataSymbolicExpression(expression)) {
switch (expression.__symbolic) {
case 'binary':
var binaryExpression = expression;
validateExpression(binaryExpression.left);
validateExpression(binaryExpression.right);
break;
case 'call':
case 'new':
var callExpression = expression;
validateExpression(callExpression.expression);
if (callExpression.arguments)
callExpression.arguments.forEach(validateExpression);
break;
case 'index':
var indexExpression = expression;
validateExpression(indexExpression.expression);
validateExpression(indexExpression.index);
break;
case 'pre':
var prefixExpression = expression;
validateExpression(prefixExpression.operand);
break;
case 'select':
var selectExpression = expression;
validateExpression(selectExpression.expression);
break;
case 'spread':
var spreadExpression = expression;
validateExpression(spreadExpression.expression);
break;
case 'if':
var ifExpression = expression;
validateExpression(ifExpression.condition);
validateExpression(ifExpression.elseExpression);
validateExpression(ifExpression.thenExpression);
break;
}
}
}
function validateMember(member) {
if (member.decorators) {
member.decorators.forEach(validateExpression);
}
if (schema_1.isMethodMetadata(member) && member.parameterDecorators) {
member.parameterDecorators.forEach(validateExpression);
}
if (schema_1.isConstructorMetadata(member) && member.parameters) {
member.parameters.forEach(validateExpression);
}
}
function validateClass(classData) {
if (classData.decorators) {
classData.decorators.forEach(validateExpression);
}
if (classData.members) {
Object.getOwnPropertyNames(classData.members)
.forEach(function (name) { return classData.members[name].forEach(validateMember); });
}
}
function validateFunction(functionDeclaration) {
if (functionDeclaration.value) {
var oldLocals = locals;
if (functionDeclaration.parameters) {
locals = new Set(oldLocals.values());
if (functionDeclaration.parameters)
functionDeclaration.parameters.forEach(function (n) { return locals.add(n); });
}
validateExpression(functionDeclaration.value);
locals = oldLocals;
}
}
function shouldReportNode(node) {
if (node) {
var nodeStart = node.getStart();
return !(node.pos != nodeStart &&
sourceFile.text.substring(node.pos, nodeStart).indexOf('@dynamic') >= 0);
}
return true;
}
function reportError(error) {
var node = nodeMap.get(error);
if (shouldReportNode(node)) {
var lineInfo = error.line != undefined ?
error.character != undefined ? ":" + (error.line + 1) + ":" + (error.character + 1) :
":" + (error.line + 1) :
'';
throw new Error("" + sourceFile.fileName + lineInfo + ": Metadata collected contains an error that will be reported at runtime: " + expandedMessage(error) + ".\n " + JSON.stringify(error));
}
}
Object.getOwnPropertyNames(metadata).forEach(function (name) {
var entry = metadata[name];
try {
if (schema_1.isClassMetadata(entry)) {
validateClass(entry);
}
}
catch (e) {
var node = nodeMap.get(entry);
if (shouldReportNode(node)) {
if (node) {
var _a = sourceFile.getLineAndCharacterOfPosition(node.getStart()), line = _a.line, character = _a.character;
throw new Error(sourceFile.fileName + ":" + (line + 1) + ":" + (character + 1) + ": Error encountered in metadata generated for exported symbol '" + name + "': \n " + e.message);
}
throw new Error("Error encountered in metadata generated for exported symbol " + name + ": \n " + e.message);
}
}
});
}
// Collect parameter names from a function.

@@ -394,2 +555,29 @@ function namesOf(parameters) {

}
function expandedMessage(error) {
switch (error.message) {
case 'Reference to non-exported class':
if (error.context && error.context.className) {
return "Reference to a non-exported class " + error.context.className + ". Consider exporting the class";
}
break;
case 'Variable not initialized':
return 'Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler';
case 'Destructuring not supported':
return 'Referencing an exported destructured variable or constant is not supported by the template compiler. Consider simplifying this to avoid destructuring';
case 'Could not resolve type':
if (error.context && error.context.typeName) {
return "Could not resolve type " + error.context.typeName;
}
break;
case 'Function call not supported':
var prefix = error.context && error.context.name ? "Calling function '" + error.context.name + "', f" : 'F';
return prefix +
'unction calls are not supported. Consider replacing the function or lambda with a reference to an exported function';
case 'Reference to a local symbol':
if (error.context && error.context.name) {
return "Reference to a local (non-exported) symbol '" + error.context.name + "'. Consider exporting the symbol";
}
}
return error.message;
}
//# sourceMappingURL=collector.js.map
import * as ts from 'typescript';
import NgOptions from './options';
/**

@@ -15,2 +16,3 @@ * Implementation of CompilerHost that forwards all methods to another instance.

getCurrentDirectory: () => string;
getDirectories: (path: string) => string[];
getCanonicalFileName: (fileName: string) => string;

@@ -33,6 +35,7 @@ useCaseSensitiveFileNames: () => boolean;

private program;
private ngOptions;
private metadataCollector;
constructor(delegate: ts.CompilerHost, program: ts.Program);
constructor(delegate: ts.CompilerHost, program: ts.Program, ngOptions: NgOptions);
private writeMetadata(emitFilePath, sourceFile);
writeFile: ts.WriteFileCallback;
}

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

this.getCurrentDirectory = function () { return _this.delegate.getCurrentDirectory(); };
this.getDirectories = function (path) {
return _this.delegate.getDirectories ? _this.delegate.getDirectories(path) : [];
};
this.getCanonicalFileName = function (fileName) { return _this.delegate.getCanonicalFileName(fileName); };

@@ -76,6 +79,7 @@ this.useCaseSensitiveFileNames = function () { return _this.delegate.useCaseSensitiveFileNames(); };

__extends(MetadataWriterHost, _super);
function MetadataWriterHost(delegate, program) {
function MetadataWriterHost(delegate, program, ngOptions) {
var _this = this;
_super.call(this, delegate);
this.program = program;
this.ngOptions = ngOptions;
this.metadataCollector = new collector_1.MetadataCollector();

@@ -109,3 +113,3 @@ this.writeFile = function (fileName, data, writeByteOrderMark, onError, sourceFiles) {

var path_1 = emitFilePath.replace(/*DTS*/ /\.js$/, '.metadata.json');
var metadata = this.metadataCollector.getMetadata(sourceFile);
var metadata = this.metadataCollector.getMetadata(sourceFile, !!this.ngOptions.strictMetadataEmit);
if (metadata && metadata.metadata) {

@@ -112,0 +116,0 @@ var metadataText = JSON.stringify(metadata);

import * as ts from 'typescript';
import { MetadataError, MetadataValue } from './schema';
import { MetadataEntry, MetadataError, MetadataValue } from './schema';
import { Symbols } from './symbols';

@@ -24,3 +24,4 @@ export declare function isPrimitive(value: any): boolean;

private symbols;
constructor(symbols: Symbols);
private nodeMap;
constructor(symbols: Symbols, nodeMap: Map<MetadataEntry, ts.Node>);
nameOf(node: ts.Node): string | MetadataError;

@@ -27,0 +28,0 @@ /**

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

if (sourceFile) {
var _a = ts.getLineAndCharacterOfPosition(sourceFile, node.pos), line = _a.line, character = _a.character;
var _a = ts.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile)), line = _a.line, character = _a.character;
result = { __symbolic: 'error', message: message, line: line, character: character };

@@ -70,4 +70,5 @@ }

var Evaluator = (function () {
function Evaluator(symbols) {
function Evaluator(symbols, nodeMap) {
this.symbols = symbols;
this.nodeMap = nodeMap;
}

@@ -186,3 +187,8 @@ Evaluator.prototype.nameOf = function (node) {

var _this = this;
var t = this;
var error;
function recordEntry(entry, node) {
t.nodeMap.set(entry, node);
return entry;
}
switch (node.kind) {

@@ -243,3 +249,3 @@ case ts.SyntaxKind.ObjectLiteralExpression:

var spreadExpression = this.evaluateNode(spread.expression);
return { __symbolic: 'spread', expression: spreadExpression };
return recordEntry({ __symbolic: 'spread', expression: spreadExpression }, node);
case ts.SyntaxKind.CallExpression:

@@ -251,3 +257,3 @@ var callExpression = node;

var arrowFunction = firstArgument;
return this.evaluateNode(arrowFunction.body);
return recordEntry(this.evaluateNode(arrowFunction.body), node);
}

@@ -269,7 +275,7 @@ }

if (isCallOf(callExpression, 'CONST_EXPR') && callExpression.arguments.length === 1) {
return args_1[0];
return recordEntry(args_1[0], node);
}
var expression = this.evaluateNode(callExpression.expression);
if (schema_1.isMetadataError(expression)) {
return expression;
return recordEntry(expression, node);
}

@@ -280,3 +286,3 @@ var result = { __symbolic: 'call', expression: expression };

}
return result;
return recordEntry(result, node);
case ts.SyntaxKind.NewExpression:

@@ -286,7 +292,7 @@ var newExpression = node;

if (newArgs.some(schema_1.isMetadataError)) {
return newArgs.find(schema_1.isMetadataError);
return recordEntry(newArgs.find(schema_1.isMetadataError), node);
}
var newTarget = this.evaluateNode(newExpression.expression);
if (schema_1.isMetadataError(newTarget)) {
return newTarget;
return recordEntry(newTarget, node);
}

@@ -297,3 +303,3 @@ var call = { __symbolic: 'new', expression: newTarget };

}
return call;
return recordEntry(call, node);
case ts.SyntaxKind.PropertyAccessExpression: {

@@ -303,7 +309,7 @@ var propertyAccessExpression = node;

if (schema_1.isMetadataError(expression_1)) {
return expression_1;
return recordEntry(expression_1, node);
}
var member = this.nameOf(propertyAccessExpression.name);
if (schema_1.isMetadataError(member)) {
return member;
return recordEntry(member, node);
}

@@ -315,5 +321,5 @@ if (expression_1 && this.isFoldable(propertyAccessExpression.expression))

// in the module
return { __symbolic: 'reference', module: expression_1.module, name: member };
return recordEntry({ __symbolic: 'reference', module: expression_1.module, name: member }, node);
}
return { __symbolic: 'select', expression: expression_1, member: member };
return recordEntry({ __symbolic: 'select', expression: expression_1, member: member }, node);
}

@@ -324,7 +330,7 @@ case ts.SyntaxKind.ElementAccessExpression: {

if (schema_1.isMetadataError(expression_2)) {
return expression_2;
return recordEntry(expression_2, node);
}
var index = this.evaluateNode(elementAccessExpression.argumentExpression);
if (schema_1.isMetadataError(expression_2)) {
return expression_2;
return recordEntry(expression_2, node);
}

@@ -334,3 +340,3 @@ if (this.isFoldable(elementAccessExpression.expression) &&

return expression_2[index];
return { __symbolic: 'index', expression: expression_2, index: index };
return recordEntry({ __symbolic: 'index', expression: expression_2, index: index }, node);
}

@@ -343,3 +349,3 @@ case ts.SyntaxKind.Identifier:

// Encode as a global reference. StaticReflector will check the reference.
return { __symbolic: 'reference', name: name_2 };
return recordEntry({ __symbolic: 'reference', name: name_2 }, node);
}

@@ -355,5 +361,7 @@ return reference;

if (schema_1.isMetadataModuleReferenceExpression(left_1)) {
return {
__symbolic: 'reference', module: left_1.module, name: qualifiedName.right.text
};
return recordEntry({
__symbolic: 'reference',
module: left_1.module,
name: qualifiedName.right.text
}, node);
}

@@ -367,5 +375,5 @@ // Record a type reference to a declared type as a select.

if (schema_1.isMetadataError(symbol) || schema_1.isMetadataSymbolicReferenceExpression(symbol)) {
return symbol;
return recordEntry(symbol, node);
}
return errorSymbol('Could not resolve type', node, { typeName: identifier_1.text });
return recordEntry(errorSymbol('Could not resolve type', node, { typeName: identifier_1.text }), node);
}

@@ -375,3 +383,3 @@ };

if (schema_1.isMetadataError(typeReference)) {
return typeReference;
return recordEntry(typeReference, node);
}

@@ -385,3 +393,3 @@ if (!schema_1.isMetadataModuleReferenceExpression(typeReference) &&

}
return typeReference;
return recordEntry(typeReference, node);
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:

@@ -394,16 +402,16 @@ return node.text;

case ts.SyntaxKind.AnyKeyword:
return { __symbolic: 'reference', name: 'any' };
return recordEntry({ __symbolic: 'reference', name: 'any' }, node);
case ts.SyntaxKind.StringKeyword:
return { __symbolic: 'reference', name: 'string' };
return recordEntry({ __symbolic: 'reference', name: 'string' }, node);
case ts.SyntaxKind.NumberKeyword:
return { __symbolic: 'reference', name: 'number' };
return recordEntry({ __symbolic: 'reference', name: 'number' }, node);
case ts.SyntaxKind.BooleanKeyword:
return { __symbolic: 'reference', name: 'boolean' };
return recordEntry({ __symbolic: 'reference', name: 'boolean' }, node);
case ts.SyntaxKind.ArrayType:
var arrayTypeNode = node;
return {
return recordEntry({
__symbolic: 'reference',
name: 'Array',
arguments: [this.evaluateNode(arrayTypeNode.elementType)]
};
}, node);
case ts.SyntaxKind.NullKeyword:

@@ -453,3 +461,3 @@ return null;

}
return { __symbolic: 'pre', operator: operatorText, operand: operand };
return recordEntry({ __symbolic: 'pre', operator: operatorText, operand: operand }, node);
case ts.SyntaxKind.BinaryExpression:

@@ -505,3 +513,3 @@ var binaryExpression = node;

}
return {
return recordEntry({
__symbolic: 'binop',

@@ -511,3 +519,3 @@ operator: binaryExpression.operatorToken.getText(),

right: right
};
}, node);
}

@@ -523,8 +531,8 @@ break;

}
return { __symbolic: 'if', condition: condition, thenExpression: thenExpression, elseExpression: elseExpression };
return recordEntry({ __symbolic: 'if', condition: condition, thenExpression: thenExpression, elseExpression: elseExpression }, node);
case ts.SyntaxKind.FunctionExpression:
case ts.SyntaxKind.ArrowFunction:
return errorSymbol('Function call not supported', node);
return recordEntry(errorSymbol('Function call not supported', node), node);
}
return errorSymbol('Expression form not supported', node);
return recordEntry(errorSymbol('Expression form not supported', node), node);
};

@@ -531,0 +539,0 @@ return Evaluator;

import * as ts from 'typescript';
import NgOptions from './options';
export declare type CodegenExtension = (ngOptions: NgOptions, program: ts.Program, host: ts.CompilerHost) => Promise<void>;
export declare function main(project: string, basePath?: string, codegen?: CodegenExtension): Promise<any>;
import { CliOptions } from './cli_options';
export declare type CodegenExtension = (ngOptions: NgOptions, cliOptions: CliOptions, program: ts.Program, host: ts.CompilerHost) => Promise<void>;
export declare function main(project: string, cliOptions: CliOptions, codegen?: CodegenExtension): Promise<any>;

@@ -7,3 +7,4 @@ "use strict";

var compiler_host_1 = require('./compiler_host');
function main(project, basePath, codegen) {
var cli_options_1 = require('./cli_options');
function main(project, cliOptions, codegen) {
try {

@@ -15,3 +16,3 @@ var projectDir = project;

// file names in tsconfig are resolved relative to this absolute path
basePath = path.join(process.cwd(), basePath || projectDir);
var basePath = path.resolve(process.cwd(), cliOptions.basePath || projectDir);
// read the configuration options from wherever you store them

@@ -21,2 +22,6 @@ var _a = tsc_1.tsc.readConfiguration(project, basePath), parsed_1 = _a.parsed, ngOptions_1 = _a.ngOptions;

var host_1 = ts.createCompilerHost(parsed_1.options, true);
// HACK: patch the realpath to solve symlink issue here:
// https://github.com/Microsoft/TypeScript/issues/9552
// todo(misko): remove once facade symlinks are removed
host_1.realpath = function (path) { return path; };
var program_1 = ts.createProgram(parsed_1.fileNames, parsed_1.options, host_1);

@@ -28,3 +33,3 @@ var errors = program_1.getOptionsDiagnostics();

}
return codegen(ngOptions_1, program_1, host_1).then(function () {
return codegen(ngOptions_1, cliOptions, program_1, host_1).then(function () {
// Create a new program since codegen files were created after making the old program

@@ -42,3 +47,3 @@ var newProgram = ts.createProgram(parsed_1.fileNames, parsed_1.options, host_1, program_1);

// in the standard emit.
var metadataWriter = new compiler_host_1.MetadataWriterHost(host_1, newProgram);
var metadataWriter = new compiler_host_1.MetadataWriterHost(host_1, newProgram, ngOptions_1);
tsc_1.tsc.emit(metadataWriter, newProgram);

@@ -56,5 +61,5 @@ }

var args_1 = require('minimist')(process.argv.slice(2));
main(args_1.p || args_1.project || '.', args_1.basePath)
.then(function (exitCode) { return process.exit(exitCode); })
.catch(function (e) {
var project = args_1.p || args_1.project || '.';
var cliOptions = new cli_options_1.CliOptions(args_1);
main(project, cliOptions).then(function (exitCode) { return process.exit(exitCode); }).catch(function (e) {
console.error(e.stack);

@@ -61,0 +66,0 @@ console.error('Compilation failed');

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

skipMetadataEmit: boolean;
strictMetadataEmit: boolean;
skipTemplateCodegen: boolean;
generateCodeForLibraries?: boolean;
trace: boolean;

@@ -9,0 +11,0 @@ debug?: boolean;

export declare const VERSION: number;
export declare type MetadataEntry = ClassMetadata | FunctionMetadata | MetadataValue;
export interface ModuleMetadata {

@@ -7,3 +8,3 @@ __symbolic: 'module';

metadata: {
[name: string]: (ClassMetadata | FunctionMetadata | MetadataValue);
[name: string]: MetadataEntry;
};

@@ -40,3 +41,3 @@ }

}
export declare function isMethodMetadata(value: any): value is MemberMetadata;
export declare function isMethodMetadata(value: any): value is MethodMetadata;
export interface ConstructorMetadata extends MethodMetadata {

@@ -43,0 +44,0 @@ __symbolic: 'constructor';

@@ -80,16 +80,16 @@ // Metadata Schema

function isMetadataGlobalReferenceExpression(value) {
return isMetadataSymbolicReferenceExpression(value) && value.name && !value.module;
return value && value.name && !value.module && isMetadataSymbolicReferenceExpression(value);
}
exports.isMetadataGlobalReferenceExpression = isMetadataGlobalReferenceExpression;
function isMetadataModuleReferenceExpression(value) {
return isMetadataSymbolicReferenceExpression(value) && value.module && !value.name &&
!value.default;
return value && value.module && !value.name && !value.default &&
isMetadataSymbolicReferenceExpression(value);
}
exports.isMetadataModuleReferenceExpression = isMetadataModuleReferenceExpression;
function isMetadataImportedSymbolReferenceExpression(value) {
return isMetadataSymbolicReferenceExpression(value) && value.module && !!value.name;
return value && value.module && !!value.name && isMetadataSymbolicReferenceExpression(value);
}
exports.isMetadataImportedSymbolReferenceExpression = isMetadataImportedSymbolReferenceExpression;
function isMetadataImportDefaultReference(value) {
return isMetadataSymbolicReferenceExpression(value) && value.module && value.default;
return value.module && value.default && isMetadataSymbolicReferenceExpression(value);
}

@@ -96,0 +96,0 @@ exports.isMetadataImportDefaultReference = isMetadataImportDefaultReference;

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

private basePath;
constructor(readFile?: (path: string, encoding?: string) => string, readDirectory?: (path: string, extension?: string, exclude?: string[]) => string[]);
constructor(readFile?: (path: string, encoding?: string) => string, readDirectory?: (path: string, extensions?: string[], exclude?: string[], include?: string[]) => string[]);
readConfiguration(project: string, basePath: string): {

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

"use strict";
var fs_1 = require('fs');
var path = require('path');

@@ -54,4 +55,13 @@ var ts = require('typescript');

check([error]);
this.parsed =
ts.parseJsonConfigFileContent(config, { readDirectory: this.readDirectory }, basePath);
// Do not inline `host` into `parseJsonConfigFileContent` until after
// g3 is updated to the latest TypeScript.
// The issue is that old typescript only has `readDirectory` while
// the newer TypeScript has additional `useCaseSensitiveFileNames` and
// `fileExists`. Inlining will trigger an error of extra parameters.
var host = {
useCaseSensitiveFileNames: true,
fileExists: fs_1.existsSync,
readDirectory: this.readDirectory
};
this.parsed = ts.parseJsonConfigFileContent(config, host, basePath);
check(this.parsed.errors);

@@ -58,0 +68,0 @@ // Default codegen goes to the current directory

@@ -24,2 +24,6 @@ "use strict";

'local-symbol-ref.ts',
'local-function-ref.ts',
'local-symbol-ref-func.ts',
'local-symbol-ref-func-dynamic.ts',
'private-enum.ts',
're-exports.ts',

@@ -196,6 +200,6 @@ 'static-field-reference.ts',

a: { __symbolic: 'error', message: 'Destructuring not supported', line: 1, character: 16 },
b: { __symbolic: 'error', message: 'Destructuring not supported', line: 1, character: 18 },
b: { __symbolic: 'error', message: 'Destructuring not supported', line: 1, character: 19 },
c: { __symbolic: 'error', message: 'Destructuring not supported', line: 2, character: 16 },
d: { __symbolic: 'error', message: 'Destructuring not supported', line: 2, character: 18 },
e: { __symbolic: 'error', message: 'Variable not initialized', line: 3, character: 14 }
d: { __symbolic: 'error', message: 'Destructuring not supported', line: 2, character: 19 },
e: { __symbolic: 'error', message: 'Variable not initialized', line: 3, character: 15 }
}

@@ -213,4 +217,4 @@ });

message: 'Reference to non-exported class',
line: 1,
character: 45,
line: 3,
character: 4,
context: { className: 'Foo' }

@@ -302,2 +306,10 @@ });

});
it('should ignore a non-export enum', function () {
var enumSource = program.getSourceFile('/private-enum.ts');
var metadata = collector.getMetadata(enumSource);
var publicEnum = metadata.metadata['PublicEnum'];
var privateEnum = metadata.metadata['PrivateEnum'];
expect(publicEnum).toEqual({ a: 0, b: 1, c: 2 });
expect(privateEnum).toBeUndefined();
});
it('should be able to collect enums initialized from consts', function () {

@@ -346,3 +358,3 @@ var enumSource = program.getSourceFile('/exported-enum.ts');

__symbolic: 'select',
expression: { __symbolic: 'reference', module: './static-method.ts', name: 'MyModule' },
expression: { __symbolic: 'reference', module: './static-method', name: 'MyModule' },
member: 'with'

@@ -377,3 +389,3 @@ },

__symbolic: 'select',
expression: { __symbolic: 'reference', module: './static-field.ts', name: 'MyModule' },
expression: { __symbolic: 'reference', module: './static-field', name: 'MyModule' },
member: 'VALUE'

@@ -442,3 +454,3 @@ }

{ from: './static-field', export: ['MyModule'] },
{ from: './static-field-reference.ts', export: [{ name: 'Foo', as: 'OtherModule' }] },
{ from: './static-field-reference', export: [{ name: 'Foo', as: 'OtherModule' }] },
{ from: 'angular2/core' }

@@ -455,3 +467,3 @@ ]);

line: 3,
character: 9,
character: 8,
context: { name: 'REQUIRED' }

@@ -469,2 +481,56 @@ },

});
it('should collect an error symbol if collecting a reference to a non-exported function', function () {
var source = program.getSourceFile('/local-function-ref.ts');
var metadata = collector.getMetadata(source);
expect(metadata.metadata).toEqual({
REQUIRED_VALIDATOR: {
__symbolic: 'error',
message: 'Reference to a non-exported function',
line: 3,
character: 13,
context: { name: 'required' }
},
SomeComponent: {
__symbolic: 'class',
decorators: [{
__symbolic: 'call',
expression: { __symbolic: 'reference', module: 'angular2/core', name: 'Component' },
arguments: [{ providers: [{ __symbolic: 'reference', name: 'REQUIRED_VALIDATOR' }] }]
}]
}
});
});
it('should collect an error for a simple function that references a local variable', function () {
var source = program.getSourceFile('/local-symbol-ref-func.ts');
var metadata = collector.getMetadata(source);
expect(metadata.metadata).toEqual({
foo: {
__symbolic: 'function',
parameters: ['index'],
value: {
__symbolic: 'error',
message: 'Reference to a local symbol',
line: 1,
character: 8,
context: { name: 'localSymbol' }
}
}
});
});
describe('in strict mode', function () {
it('should throw if an error symbol is collecting a reference to a non-exported symbol', function () {
var source = program.getSourceFile('/local-symbol-ref.ts');
expect(function () { return collector.getMetadata(source, true); }).toThrowError(/Reference to a local symbol/);
});
it('should throw if an error if collecting a reference to a non-exported function', function () {
var source = program.getSourceFile('/local-function-ref.ts');
expect(function () { return collector.getMetadata(source, true); })
.toThrowError(/Reference to a non-exported function/);
});
it('should throw for references to unexpected types', function () {
var unsupported1 = program.getSourceFile('/unsupported-2.ts');
expect(function () { return collector.getMetadata(unsupported1, true); })
.toThrowError(/Reference to non-exported class/);
});
});
});

@@ -500,8 +566,11 @@ // TODO: Do not use \` in a template literal as it confuses clang-format

'static-method-with-default.ts': "\n import {Injectable} from 'angular2/core';\n\n @Injectable()\n export class MyModule {\n static with(comp: any, foo: boolean = true, bar: boolean = false): any[] {\n return [\n MyModule,\n foo ? { provider: 'a', useValue: comp } : {provider: 'b', useValue: comp},\n bar ? { provider: 'c', useValue: comp } : {provider: 'd', useValue: comp}\n ];\n }\n }\n ",
'static-method-call.ts': "\n import {Component} from 'angular2/core';\n import {MyModule} from './static-method.ts';\n\n @Component({\n providers: MyModule.with('a')\n })\n export class Foo { }\n ",
'static-method-call.ts': "\n import {Component} from 'angular2/core';\n import {MyModule} from './static-method';\n\n @Component({\n providers: MyModule.with('a')\n })\n export class Foo { }\n ",
'static-field.ts': "\n import {Injectable} from 'angular2/core';\n\n @Injectable()\n export class MyModule {\n static VALUE = 'Some string';\n }\n ",
'static-field-reference.ts': "\n import {Component} from 'angular2/core';\n import {MyModule} from './static-field.ts';\n\n @Component({\n providers: [ { provide: 'a', useValue: MyModule.VALUE } ]\n })\n export class Foo { }\n ",
'static-field-reference.ts': "\n import {Component} from 'angular2/core';\n import {MyModule} from './static-field';\n\n @Component({\n providers: [ { provide: 'a', useValue: MyModule.VALUE } ]\n })\n export class Foo { }\n ",
'static-method-with-if.ts': "\n import {Injectable} from 'angular2/core';\n\n @Injectable()\n export class MyModule {\n static with(cond: boolean): any[] {\n return [\n MyModule,\n { provider: 'a', useValue: cond ? '1' : '2' }\n ];\n }\n }\n ",
're-exports.ts': "\n export {MyModule} from './static-field';\n export {Foo as OtherModule} from './static-field-reference.ts';\n export * from 'angular2/core';\n ",
'local-symbol-ref.ts': "\n import {Component, Validators} from 'angular2/core';\n\n const REQUIRED = Validators.required;\n\n export const REQUIRED_VALIDATOR: any = {\n provide: 'SomeToken',\n useValue: REQUIRED,\n multi: true\n };\n\n @Component({\n providers: [REQUIRED_VALIDATOR]\n })\n export class SomeComponent {}\n ",
're-exports.ts': "\n export {MyModule} from './static-field';\n export {Foo as OtherModule} from './static-field-reference';\n export * from 'angular2/core';\n ",
'local-symbol-ref.ts': "\n import {Component, Validators} from 'angular2/core';\n\n var REQUIRED;\n\n export const REQUIRED_VALIDATOR: any = {\n provide: 'SomeToken',\n useValue: REQUIRED,\n multi: true\n };\n\n @Component({\n providers: [REQUIRED_VALIDATOR]\n })\n export class SomeComponent {}\n ",
'private-enum.ts': "\n export enum PublicEnum { a, b, c }\n enum PrivateEnum { e, f, g }\n ",
'local-function-ref.ts': "\n import {Component, Validators} from 'angular2/core';\n\n function required() {}\n\n export const REQUIRED_VALIDATOR: any = {\n provide: 'SomeToken',\n useValue: required,\n multi: true\n };\n\n @Component({\n providers: [REQUIRED_VALIDATOR]\n })\n export class SomeComponent {}\n ",
'local-symbol-ref-func.ts': "\n var localSymbol: any[];\n\n export function foo(index: number): string {\n return localSymbol[index];\n }\n ",
'node_modules': {

@@ -508,0 +577,0 @@ 'angular2': {

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

symbols = new symbols_1.Symbols(null);
evaluator = new evaluator_1.Evaluator(symbols);
evaluator = new evaluator_1.Evaluator(symbols, new Map());
});

@@ -127,3 +127,3 @@ it('should not have typescript errors in test data', function () {

symbols.define('Value', { __symbolic: 'reference', module: './classes', name: 'Value' });
evaluator = new evaluator_1.Evaluator(symbols);
evaluator = new evaluator_1.Evaluator(symbols, new Map());
var newExpression = program.getSourceFile('newExpression.ts');

@@ -154,3 +154,3 @@ expect(evaluator.evaluateNode(typescript_mocks_1.findVar(newExpression, 'someValue').initializer)).toEqual({

expect(evaluator.evaluateNode(fDecl.initializer))
.toEqual({ __symbolic: 'error', message: 'Function call not supported', line: 1, character: 11 });
.toEqual({ __symbolic: 'error', message: 'Function call not supported', line: 1, character: 12 });
var eDecl = typescript_mocks_1.findVar(errors, 'e');

@@ -161,3 +161,3 @@ expect(evaluator.evaluateNode(eDecl.type)).toEqual({

line: 2,
character: 10,
character: 11,
context: { typeName: 'NotFound' }

@@ -170,3 +170,3 @@ });

line: 3,
character: 13,
character: 14,
context: { received: '1' }

@@ -179,3 +179,3 @@ });

line: 4,
character: 11
character: 12
});

@@ -182,0 +182,0 @@ });

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

var fs = require('fs');
var path = require('path');
var ts = require('typescript');

@@ -33,3 +32,3 @@ var Host = (function () {

Host.prototype.getFileContent = function (fileName) {
var names = fileName.split(path.sep);
var names = fileName.split('/');
if (names[names.length - 1] === 'lib.d.ts') {

@@ -36,0 +35,0 @@ return fs.readFileSync(ts.getDefaultLibFilePath(this.getCompilationSettings()), 'utf8');

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